-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathflappylarus.s
330 lines (290 loc) · 3.94 KB
/
flappylarus.s
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
;Flappy Larus constants and variables
GRAVITY = 160
debounce_flag = mode
loopcounter = runpnt
random = rxcnt
loopcounter2 = runpnt+1
gamespeed = txcnt
obstaclecnt = stringp
obstacleh = stringp+1
score = halt-1
initgame:
jsr ssd1306_clear
lda #6
sta gamespeed
sta loopcounter2
lda #0
sta score
sta loopcounter
lda #8
sta obstaclecnt
restart:
lda #0
sta scroll
lda #$40
ora tflags
sta tflags
lda #0
sta cursor
jsr setcursor
lda #'8' ; Cloud
jsr ssd1306_sendchar
lda #$11
sta cursor
jsr setcursor2
lda #'8' ; Cloud
jsr ssd1306_sendchar
lda #$31
sta cursor
jsr setcursor2
lda #'8' ; Cloud
jsr ssd1306_sendchar
lda #$40
sta cursor
jsr setcursor2
lda #'8' ; Cloud
jsr ssd1306_sendchar
lda #$61
sta cursor
jsr setcursor2
lda #'8' ; Cloud
jsr ssd1306_sendchar
lda #$67
sta cursor
jsr setcursor
lda #'E'
jsr ssd1306_sendchar
jsr delay_long
waitforflap:
bit DRB
bvs waitforflap
rts
checkstate:
jsr checkfall
jsr checkbounds2
bcc gameover
jsr checkflap
jsr checkbounds2
bcc gameover
lda READTDI ; Try to grab a somewhat random value depending on what the timer is at
sta random
sec
rts
gameover:
rts
checkfall:
lda READTDI ; Time to fall?
bne notyet
; Fall one position
dec cursor
jsr setcursor
lda #' '
jsr ssd1306_sendchar
lda #'E'
jsr ssd1306_sendchar
; Reset timer
lda #GRAVITY
sta WTD1KDI ; Gravity timer
notyet:
rts
checkbounds2:
lda #$80
sec
sbc scroll
asl ; Convert scroll offset to cursor count - units. 8 << 2 == 16 == Second line
clc
adc cursor
and #$7F ; Throw away only the top bit since scroll offset might have it set
cmp #$70
bcs gameover2
cmp #$5F
bcc gameover2
sec ; Return C = 1
rts
gameover2:
clc ; Return C = 0 to indicate gameover
rts
checkcollision2:
lda #$80
sec
sbc scroll
asl ; Convert scroll offset to cursor count - units. 8 << 2 == 16 == Second line
clc
adc cursor
and #$7F ; Throw away only the top bit since scroll offset might have it set
pha
sec
sbc obstacleh
cmp #$60
bcc gameover3
pla
clc
adc #16
sec
sbc #4
sbc obstacleh
cmp #$70
bcs gameover3
sec ; Return C = 1
rts
gameover3:
clc ; Return C = 0 to indicate gameover
rts
clearcursor:
;Clear current cursor position
dec cursor
jsr setcursor
lda #' '
jsr ssd1306_sendchar
rts
checkflap:
getinput:
bit DRB
bvs notpressed
lda debounce_flag
bne debounce
lda #1 ; Only one flap per press, so we set a flag we already flappeds
sta debounce_flag
jsr clearcursor
; Draw Larus
lda cursor
sec
sbc #2
sta cursor
jsr setcursor2
lda #'|'
jsr ssd1306_sendchar
lda #255
sta WTD1KDI ; Gravity timer
bne debounce
notpressed:
lda #0
sta debounce_flag
debounce:
rts
makeobstacle:
lda cursor
pha
lda #$70
sta cursor
jsr setcursor
clc ; Write
jsr i2c_start
lda #$40 ; Co bit 0, D/C 1
sta outb
jsr i2cbyteout
lda random
and #$07
pha
asl
asl
asl
tay
hitboxes:
lda #$ff
sta outb
jsr i2cbyteout
dey
bne hitboxes
ldy #32
opening:
jsr i2cbyteout
dey
bne opening
pla
sta obstacleh
lda #16
sbc #4 ; Opening
sbc obstacleh ; First hitboxes
asl
asl
asl
tay
hitboxes2:
lda #$ff
sta outb
jsr i2cbyteout
dey
bne hitboxes2
jsr i2c_stop
pla
sta cursor
jsr setcursor
rts
flappylarus:
jsr initgame
gameloop:
jsr checkstate
bcc flappylarus ; Game over
dec loopcounter
bne notyetx
dec loopcounter2
bne notyetx
jsr clearscore
jsr ssd1306_scrollup_noclear
jsr clearcursor
lda cursor
sec
sbc #17
sta cursor
jsr setcursor2
lda #'E'
jsr ssd1306_sendchar
jsr printscore
lda obstaclecnt
sec
sbc #1
sta obstaclecnt
beq clearobstacle
cmp #7
beq drawobstacle
cmp #2
beq checkcollision
bne nexttick
drawobstacle:
jsr makeobstacle
bcc nexttick
clearobstacle:
;later
lda #8
sta obstaclecnt
bne nexttick
checkcollision:
jsr checkcollision2
bcc flappylarus ; Game Over
inc score
nexttick:
lda gamespeed
sta loopcounter2
lda cursor
notyetx:
jmp gameloop
rts ; Never get here
printscore:
lda cursor
pha
and #$f0
adc #$1d
sta cursor
jsr setcursor2
lda score
jsr printbyte
pla
sta cursor
jsr setcursor2
rts
clearscore:
lda cursor
pha
and #$f0
adc #$1c
sta cursor
jsr setcursor2
lda #' '
jsr ssd1306_sendchar
lda #' '
jsr ssd1306_sendchar
pla
sta cursor
jsr setcursor2
rts