-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.asm
338 lines (302 loc) · 8.99 KB
/
input.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
latchController:
lda #$01
sta controller1
lda #$00
sta controller1
lda buttons
sta oldButtons
ldx #$08
@loop
lda controller1
lsr
rol buttons
dex
bne @loop
latchControllerDone:
rts
SCREEN_TOP = $10
SCREEN_BOTTOM = $C0
SCREEN_LEFT = $09
SCREEN_RIGHT = $F0
facingUp = $08
facingDown = $04
facingLeft = $02
facingRight = $01
readA:
lda buttons
and #%10000000 ; If A button is not pressed then we're done
beq readAdone
lda oldButtons
and #%10000000 ; If A button is pressed and was also pressed last frame then we're done
bne readAdone
lda #$00
sta itemNo ; Else initialize itemNo counter
jsr checkItems ; and check items for collision
readAdone:
rts
readB:
lda buttons
and #%01000000 ; If B button is not pressed then we're done
beq readBdone
lda oldButtons
and #%01000000 ; If B button is pressed and was also pressed last frame then we're done
bne readBdone
readBdone:
rts
readUp:
lda buttons
and #%00001000 ; If Up is not pressed then we're done
beq readUpDone
lda oldButtons
and #%00001000 ; If Up is pressed and was pressed last frame then we're done
bne @skip
lda #$FF
sta frameCounter ; Else initialize frameCounter for movement animation in new direction
@skip
lda playerY
cmp #SCREEN_TOP
bcc checkNametableUp ; If (playerY <= SCREEN_TOP) nametable -= #$10;
lda #$00
sta downIsPressed ; Else clear other directions
sta leftIsPressed
sta rightIsPressed
lda #$01
sta upIsPressed ; Set upIsPressed flag, animation enable flag, and player direction
sta animationEnable
lda #facingUp
sta playerDir
ldx #$03
stx animConstNumber
inx
stx animConstNumber+1
inx
stx animConstNumber+2 ; Load constants for player animation frames
rts ; Done
checkNametableUp:
lda nametable
sec
sbc #$10
sta nametable ; nametable -= #$10
inc needDraw ; set needDraw flag and change gameState
lda #$00
sta gameState
lda #SCREEN_BOTTOM
sta playerY ; Move player to other side of screen
readUpDone:
rts
readDown:
lda buttons
and #%00000100 ; If Right is not pressed we're done
beq readDownDone
lda oldButtons
and #%00000100 ; If Right is pressed and was pressed last frame then we're done
bne @skip
lda #$FF
sta frameCounter ; Else initialize frame counter for movement animation in new direction
@skip
lda playerY
cmp #SCREEN_BOTTOM
bcs checkNametableDown ; If (playerY >= SCREEN_BOTTOM) nametable += #$10;
lda #$00
sta upIsPressed ; Else clear other directions
sta leftIsPressed
sta rightIsPressed
lda #$01
sta downIsPressed ; Set downIsPressed flag, animationEnable flag, and player direction
sta animationEnable
lda #facingDown
sta playerDir
ldx #$00
stx animConstNumber
inx
stx animConstNumber+1
inx
stx animConstNumber+2 ; Load constants for player animation frames
rts ; Done
checkNametableDown:
lda nametable
clc
adc #$10
sta nametable ; nametable += #$10
inc needDraw ; Set needDraw flag and change gamestate
lda #$00
sta gameState
lda #SCREEN_TOP
sta playerY ; Move player to other side of screen
readDownDone:
rts
readLeft:
lda buttons
and #%00000010 ; If left is not pressed then we're done
beq readLeftDone
lda oldButtons
and #%00000010 ; If left is pressed and was pressed last frame then we're done
bne @skip
lda #$FF
sta frameCounter ; Else initialize frame counter for movement animation in new direction
@skip
lda playerX ; If (playerX <= SCREEN_LEFT) nametable -= #$01;
cmp #SCREEN_LEFT
bcc checkNametableLeft
lda #$00
sta upIsPressed
sta downIsPressed
sta rightIsPressed ; Else clear other directions
lda #$01
sta leftIsPressed ; Set leftIsPressed flag, animationEnable flag, and player direction
sta animationEnable
lda #facingLeft
sta playerDir
ldx #$06
stx animConstNumber
inx
stx animConstNumber+1
inx
stx animConstNumber+2 ; Load constants for player animation frames
rts ; Done
checkNametableLeft:
dec nametable ; nametable -= #$01
inc needDraw ; Set needDraw flag and change gameState
lda #$00
sta gameState
lda #SCREEN_RIGHT
sta playerX ; Move player to other side of screen
readLeftDone:
rts
readRight:
lda buttons
and #%00000001 ; If Right is not pressed then we're done
beq readRightDone
lda oldButtons
and #%00000001 ; If Right is pressed and was pressed last frame then we're done
bne @skip
lda #$FF
sta frameCounter ; Initialize frame counter for movement animation in new direction
@skip
lda playerX ; If (playerX >= SCREEN_RIGHT) nametable += 1;
cmp #SCREEN_RIGHT
bcs checkNametableRight
lda #$00
sta upIsPressed
sta downIsPressed
sta leftIsPressed ; Else clear other directions
lda #$01
sta rightIsPressed ; Set rightIsPressed flag, animationEnable flag, and player direction
sta animationEnable
lda #facingRight
sta playerDir
ldx #$09
stx animConstNumber
inx
stx animConstNumber+1
inx
stx animConstNumber+2 ; Load constants for player animation frames
rts ; Done
checkNametableRight
inc nametable ; nametable += 1
inc needDraw ; Set needDraw flag and change gameState
lda #$00
sta gameState
lda #SCREEN_LEFT
sta playerX ; Move player to other side of the screen
readRightDone:
rts
moveUp:
lda upIsPressed
beq moveUpDone
lda leftIsPressed
bne moveUpDone ; If Up is not pressed or anything other than Up is pressed then skip
lda rightIsPressed
bne moveUpDone
lda playerSpeed+1 ; Otherwise calculate playerSpeed and add it to playerY
sec
sbc #$00;40
sta playerSpeed+1
lda playerY
sbc playerSpeed
sta playerY
jsr checkCollision ; Check for collision with background
lda #$00
sta upIsPressed ; And clear upIsPressed flag
moveUpDone:
rts
moveDown:
lda downIsPressed
beq moveDownDone
lda leftIsPressed
bne moveDownDone ; If Down is not pressed or anything other than Down is pressed then skip
lda rightIsPressed
bne moveDownDone
lda playerSpeed+1 ; Otherwise calculate playerSpeed and subtract it from playerY
clc
adc #$00;40
sta playerSpeed+1
lda playerY
adc playerSpeed
sta playerY
jsr checkCollision ; Check for collision with background
lda #$00
sta downIsPressed ; And clear downIsPressed flag
moveDownDone:
rts
moveLeft:
lda leftIsPressed
beq moveLeftDone
lda upIsPressed
bne moveLeftDone ; If Left is not pressed or anything other than Left is pressed then skip
lda downIsPressed
bne moveLeftDone
lda playerSpeed+1 ; Otherwise calculate playerSpeed and add it to playerX
sec
sbc #$00;40
sta playerSpeed+1
lda playerX
sbc playerSpeed
sta playerX
jsr checkCollision ; Check for collision with background
lda #$00
sta leftIsPressed ; And clear leftIsPressed flag
moveLeftDone:
rts
moveRight:
lda rightIsPressed
beq moveRightDone
lda upIsPressed
bne moveRightDone ; If Right is not pressed or anything other than Right is pressed then skip
lda downIsPressed
bne moveRightDone ; Otherwitse calculate playerSpeed and subtract it from playerX
lda playerSpeed+1
clc
adc #$00;40
sta playerSpeed+1
lda playerX
adc playerSpeed
sta playerX
jsr checkCollision ; Check for collision with background
lda #$00
sta rightIsPressed ; And clear rightIsPressed flag
moveRightDone:
rts
updateSpriteLoc: ; Moves all sprites relative to the X/Y position of the origin sprite
lda playerY ; so only one X/Y location needs to be tracked.
sta spriteRAM+0
clc
adc #$08
sta spriteRAM+4
sta spriteRAM+8
clc
adc #$08
sta spriteRAM+12
sta spriteRAM+16
lda playerX
sta spriteRAM+3
sec
sbc #$04
sta spriteRAM+7
sta spriteRAM+15
clc
adc #$08
sta spriteRAM+11
sta spriteRAM+19
updateSpriteLocDone:
rts