-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.asm
323 lines (274 loc) · 4.93 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
ControlInput: subroutine
lda pad
and padedge
and #$20
beq .lvlend
ldx lvl
inx
stx func0
jsr FindLevel
ldx #SEQ_JUMPLVL
jsr PlaySequence
.lvlend
lda pad
and padedge
and #$10
beq .pauseend
lda loop
eor #$1
sta loop
tax
jsr PlaySequence
.pauseend
rts
MenuInput: subroutine
ldx select
lda pad
and padedge
sta tmp0
and #$4
beq .nUp
dex
bpl .nmin
inx
.nmin
.nUp lda tmp0
and #$8
beq .nDown
inx
cpx #MENU_ITEMS
bcc .nmax
dex
.nmax
.nDown
stx select
.navigatedone
lda select
cmp #$2
bne .worlddone
lda tmp0
and #$3
beq .nchange
lda world
eor #1
sta world
.nchange
.worlddone
bit tmp0
bpl .nenter
lda select
bne .nspeed
; speedrun selected
rts
.nspeed
cmp #$1
bne .ncode
; code selected
rts
.ncode
; new game selected
lda #LEVEL_HEAD
sta lvlptr+1
ldx #0
stx lvlptr
stx lvl
stx state
inx
inx
jsr PlaySequence
rts
.nenter
rts
PlayInput: subroutine
lda #0
sta ax2
sta ax1
sta ax0
lda #~(FLG_WALK | FLG_JUST_JUMPED)
and flags
sta flags
;; Walking
lda #2
bit pad
beq NotLeft
PressedLeft: subroutine
bit flags
bvs .air
.ground
lda #<(-WALK_ACCEL)
sta ax2
lda #>(-WALK_ACCEL)
sta ax1
lda #>((-WALK_ACCEL)>>8)
sta ax0
bvc .done
.air
; if leftward speed is above limit, further acceleration is not allowed
lda vx0
bpl .accel
cmp #>(-AIR_ACCEL_LIMIT>>8)
bcs .accel
bne .done
lda vx1
cmp #>(-AIR_ACCEL_LIMIT)
bcs .accel
bne .done
lda vx2
cmp #<(-AIR_ACCEL_LIMIT)
bcc .done
.accel
lda #<(-AIR_ACCEL)
sta ax2
lda #>(-AIR_ACCEL)
sta ax1
lda #>(-AIR_ACCEL>>8)
sta ax0
.done
jmp SetWalkFlag
NotLeft
lda #1
bit pad
beq NotRight
PressedRight: subroutine
bit flags
bvs .air
.ground
lda #<(WALK_ACCEL)
sta ax2
lda #>(WALK_ACCEL)
sta ax1
lda #>(WALK_ACCEL>>8)
sta ax0
bvc .done
.air
; if rightward speed is above limit, further acceleration is not allowed
lda vx0
bmi .accel
cmp #>(AIR_ACCEL_LIMIT>>8)
bcc .accel
bne .done
lda vx1
cmp #>(AIR_ACCEL_LIMIT)
bcc .accel
bne .done
lda vx2
cmp #<(AIR_ACCEL_LIMIT)
bcs .done
.accel
lda #<(AIR_ACCEL)
sta ax2
lda #>(AIR_ACCEL)
sta ax1
lda #>(AIR_ACCEL>>8)
sta ax0
.done
SetWalkFlag: subroutine
lda #FLG_HMOVE | FLG_WALK
ora flags
sta flags
NotRight
lda pad
and padedge
and #%00000001
beq .nright
lda flags+BACKUP_OFFSET
and #FLG_HMOVE_DIR
beq .nright
bne .rotate
.nright
lda pad
and padedge
and #%00000010
beq .nrotate
lda flags+BACKUP_OFFSET
and #FLG_HMOVE_DIR
bne .nrotate
.rotate
lda #$8
sta frame
lda #6
sta ftimer
.nrotate
; 1- Are we trying to jump?
; how long is it been since pressed jump? (0-window and then inf)
lda pad
and padedge
bpl .nedge
ldx #0
beq .change
.nedge
ldx jbuffer
inx
beq .nchange
cpx #BUFFER_WINDOW
bcc .change
ldx #$ff
.change
stx jbuffer
.nchange
ldx jbuffer
inx
beq .jstartdone
lda #FLG_CEIL
bit flags
bne .jstartdone
ldx coyote
cpx #COYOTE_TIME
lda #$81
bcc .jstart
.nground
lda coyote
and #$1
beq .jstartdone
lda #$80
.jstart
sta coyote
ldx #0
stx jtimer
dex
stx jbuffer
lda #FLG_JUMPING
ora flags
sta flags
.jstartdone
; 0- are we already in a jump? update the timer
lda pad
eor #$ff
and padedge ; negative edge?
bmi .jumpend
lda jtimer
cmp #MAX_JUMP
beq .jumpend
jmp .njumpend
.jumpend
lda #$f7
and flags
sta flags
.njumpend
lda #$8
bit flags
beq .njumping
inc jtimer
.njumping
;; Hooking
bit flags
bvc .hookend
bpl .nrelease
lda pad
eor #$ff
and #$40
beq .nrelease
; release
jsr Release
jmp .hookend
.nrelease
; attach
lda pad
and padedge
and #$40
beq .hookend
lda hookidx
bmi .hookend
jsr Attach
.hookend
rts