-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
158 lines (139 loc) · 3.95 KB
/
main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
!TO "DISPLAYCHARPADBINARIES.PRG,CBM
; 10 SYS (2304)
*=$0801
BYTE $0E, $08, $0A, $00, $9E, $20, $28, $32
BYTE $33, $30, $34, $29, $00, $00, $00
*=$0900
jsr init_screen
jsr init_map
jsr init_char_color
jsr print_ui
jsr init_sprites
main_loop
jsr wait_routine
jsr fly_eaten
jsr switch_sprite_fly
jsr fly_update_position
jsr CHECK_PLR_COLLISION
jsr perform_jump
jsr perform_fall
jsr scan_joystick
jmp main_loop
; main application rountine
init_screen
sei
lda #$37
sta $01
lda #$18
sta SCREEN_CTRL ;Screen Multicolour mode enabled
sta MEMORY_SETUP ;Charset mode set to display custom char $2000-$2800
lda #$00 ;Set colour black
sta BORDER_COLOR ;to border
lda #$07
sta EXTRA_BACKGROUND1 ;Char Multicolour 1
lda #$01
sta EXTRA_BACKGROUND2 ;Char Multicolour 2
lda #$09
sta EXTRA_BACKGROUND3 ;Char Multicolour 3
lda #$03
sta BACKGROUND_COLOR ;Char Multicolour 3
rts
;Draw main screen from matrix -
;NOTE max 256 chars per location ($0400-$04FF, $0500-$05ff,
;$0600,$06ff,$0700,$07e8)
init_map
ldx #$00
drawscrn
lda matrix,X ;Get data from map
sta $0400,X ;Put data into SCREEN RAM
lda matrix+$100,X ;Fetch the next 256 bytes of data from binary
sta $0500,X ;Store the next 256 bytes to screen
lda matrix+$200,X ;... and so on
sta $0600,X
lda matrix+$2E8,X
sta $06E8,X
inx ;Increment accumulator until 256 bytes read
bne drawscrn
rts
;Draw attributes from 256 bytes attribs table and place these to SCREEN RAM
init_char_color
ldx #$00
paintcols
ldy SCREEN_RAM,X ;Read screen position
lda attribs,Y ;Read attributes table
sta $D800,X ;Store to COLOUR RAM
ldy SCREEN_RAM + $100,X ;Read next 256 screen positions
lda attribs,Y ;Store to COLOUR RAM + $100
sta $D900,X ;... and so on
ldy SCREEN_RAM + $200,X
lda attribs,Y
sta $DA00,X
ldy $06E8,X
lda ATTRIBS,Y
sta $DAE8,X
inx ;Increment accumulator until 256 bytes read
bne paintcols
rts
score_string text 'PUNTEGGIO: 0000'
print_ui
ldx #$00
loop_text
lda score_string,x
sta SCREEN_RAM,x
inx
cpx #$0f
bne loop_text
ldx #$00
loop_color
lda #$00
sta $d800,x
inx
cpx #$0f
bne loop_color
rts
update_score
tay
update_score_impl
inc SCREEN_RAM+$0e
lda SCREEN_RAM+$0e
cmp #$3a ; >9? (the #0 in the charset is $30,up to $39 for the #9)
bne done ; if not, stop
lda #$30 ; else reset last digit to "0" ($30)
sta SCREEN_RAM+$0e
inc SCREEN_RAM+$0d ; increase left digit
lda SCREEN_RAM+$0d ; start again with the other digit
cmp #$3a
bne done
lda #$30
sta SCREEN_RAM+$0d
inc SCREEN_RAM+$0c
lda SCREEN_RAM+$0c
cmp #$3a
bne done
lda #$30
sta SCREEN_RAM+$0c
inc SCREEN_RAM+$0b
done
dey
cpy #$00
bne update_score_impl
rts
; Resources and includes
*=$2000
incbin "resources/charset.bin"
*=$2800
matrix
incbin "resources/map_1.bin"
*=$2c00
attribs
incbin "resources/cols.bin"
*=$3000
incbin "resources/frog.spt",1,2, true
incbin "resources/fly.spt",1,7, true
IncAsm "label.asm"
IncAsm "sprites.asm"
IncAsm "frog.asm"
IncAsm "fly.asm"
IncAsm "collision.asm"
IncAsm "joystick.asm"
IncAsm "routine.asm"