-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_fli.inc
503 lines (451 loc) · 15.6 KB
/
s_fli.inc
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
; =============================================================================
; A scroller, lower area is covered by a "water" effect with mirror
; (C) by Jens Ch. Restemeier, <XXXXXXXXXXXX>
; =============================================================================
drw_fli:
; hide cursor
ld hl,0c000h ; sprite-table
ld a, 0 ; Y
ld (hl),a
call display_off
call default_init
; init color-palette for GB-Color
ld a,0
ld hl,gray_pal
call set_bg_pal
ld a,1
ld hl,red_pal
call set_bg_pal
ld a,0
ld hl,gold_pal
call set_ob_pal
ldh a, (EN_COLOR & 0FFh)
or a
call z, set_gray
; setup irq handler
ld a,001000000b ; enable FLI IRQ
ldh (STAT & 0ffh),a
ld a,000000111b ; enable VBLANK, Timer and FLI IRQ
ldh (IE & 0ffh),a
; enable 8x16 sprites
ld hl, LCDC
set 2, (hl)
di
ld de, fli_irq
ld hl, IRQ_HANDLER
ld a, d
ldi (hl), a
ld (hl), e
ei
xor a
ldh (tabidx & 0FFh),a
ldh (textpos & 0FFh),a
ldh ((textpos+1) & 0FFh),a
ld a,(lyc_table)
ld (LYC), a
ld a, 1
ldh (speed & 0FFh),a
; display ducky...
ld hl,0c000h
ld a, 112
ldi (hl),a
ld a, 100
ldi (hl),a
ld a, 8
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 112
ldi (hl),a
ld a, 108
ldi (hl),a
ld a, 10
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 128
ldi (hl),a
ld a, 100
ldi (hl),a
ld a, 12
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 128
ldi (hl),a
ld a, 108
ldi (hl),a
ld a, 14
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 112
ldi (hl),a
ld a, 116
ldi (hl),a
ld a, 16
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 112
ldi (hl),a
ld a, 124
ldi (hl),a
ld a, 18
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 128
ldi (hl),a
ld a, 116
ldi (hl),a
ld a, 20
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 128
ldi (hl),a
ld a, 124
ldi (hl),a
ld a, 22
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 128
ldi (hl),a
ld a, 130
ldi (hl),a
ld a, 4
ldi (hl),a
ld a, 00000000b
ldi (hl),a
ld a, 128
ldi (hl),a
ld a, 138
ldi (hl),a
ld a, 6
ldi (hl),a
ld a, 00000000b
ldi (hl),a
call display_on
; first state
ld a,15
ldh (SCREEN & 0FFh),a
ret
s1_fli:
; check buttons
ld a,18
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 009h ; if Start or 'A'
ret nz
ld a,17
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 040h ; if up
ret nz
ld a,15 ; otherwise stay here
ldh (SCREEN & 0FFh),a
; Do the scroller "down"
ldh a, (speed & 0FFh)
dec a
ldh (speed & 0FFh),a
ret nz
ld a, 4
ldh (speed & 0FFh),a
; scroll position
ld hl, textpos
ld e,(hl)
inc hl
ld d,(hl)
ld a,e
cp (((((e_scroll_1 - s_scroll_1)/32)*8)+40) & 255)
jr nz, s1fl2
ld a, d
cp (((((e_scroll_1 - s_scroll_1)/32)*8)+40) / 256)
; if we are at the end of the scroller, stop scrolling
ret z
s1fl2: inc de
ld (hl),d
dec hl
ld (hl),e
ld a,e
and 007h
ret nz
; calculate the screen-position into "hl"
ldh a, (textpos & 0FFh)
sra a ; a / 8
sra a
sra a
add a,13 ; invisible area
and 31 ; wrap-around at 32 lines
ld c,a ; bc*32
ld b,0
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld l, c
ld a, 098h
add a, b
ld h,a
; calculate the source-address into "de"
ld bc, textpos
ld a,(bc)
ld e,a
inc bc
ld a,(bc)
ld d,a
sra d ; de / 8
rr e
sra d
rr e
sra d
rr e
ld a,e
cp ((e_scroll_1 - s_scroll_1)/32)
jp nc, sf_do_fill
sla e ; de * 32
rl d
sla e
rl d
sla e
rl d
sla e
rl d
sla e
rl d
; add source of text
ld a,s_scroll_1 & 0FFh
add a,e
ld e,a
ld a,s_scroll_1 / 256
adc a,d
ld d,a
; now copy 20 bytes from de to hl
sf_do_copy:
ld c,20
sf1la: ldh a,(STAT & 0FFh) ; wait for h/vblank
and 010b
jr z, sf1la
sf1lb: ldh a,(STAT & 0FFh) ; wait for h/vblank
and 010b
jr nz, sf1lb
ld a,(de)
ldi (hl),a
inc de
dec c
jr nz, sf1la
ret
sf_do_fill:
ld c,20
sf2la: ldh a,(STAT & 0FFh) ; wait for h/vblank
and 010b
jr z, sf2la
sf2lb: ldh a,(STAT & 0FFh) ; wait for h/vblank
and 010b
jr nz, sf2lb
xor a
ldi (hl),a
inc de
dec c
jr nz, sf2la
ret
s2_fli:
; check buttons
ld a,18
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 009h ; if Start or 'A'
ret nz
ld a,17
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 080h ; if up
ret nz
ld a,16 ; otherwise stay here
ldh (SCREEN & 0FFh),a
; Do the scroller "up"
ldh a, (speed & 0FFh)
dec a
ldh (speed & 0FFh),a
ret nz
ld a, 4
ldh (speed & 0FFh),a
; scroll position
ld hl, textpos
ld e,(hl)
inc hl
ld d,(hl)
ld a,e
or a
jr nz, s2fl2
ld a, d
or a
; if we are at the beginning of the scroller, stop scrolling
ret z
s2fl2: dec de
ld (hl),d
dec hl
ld (hl),e
ld a,e
and 007h
ret nz
; calculate the screen-position into "hl"
ldh a, (textpos & 0FFh)
sra a ; a / 8
sra a
sra a
add a,-1 ; invisible area
and 31 ; wrap-around at 32 lines
ld c,a ; bc*32
ld b,0
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld l, c
ld a, 098h
add a, b
ld h,a
; calculate the source-address into "de"
ld bc, textpos
ld a,(bc)
ld e,a
inc bc
ld a,(bc)
ld d,a
sra d ; de / 8
rr e
sra d
rr e
sra d
rr e
ld a,e
sub 14
ld e,a
ld a,d
sbc a,0
ld d,a
bit 7,e ; do we have a negative result ?
jp nz, sf_do_fill
sla e ; de * 32
rl d
sla e
rl d
sla e
rl d
sla e
rl d
sla e
rl d
; add source of text
ld a,s_scroll_1 & 0FFh
add a,e
ld e,a
ld a,s_scroll_1 / 256
adc a,d
ld d,a
jp sf_do_copy
s3_fli:
; check buttons
ld a,18
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 009h ; if Start or 'A'
ret nz
ld a,16
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 040h ; if up
ret nz
ld a,15
ldh (SCREEN & 0FFh),a
ldh a,(JOY_TIPP & 0ffh)
and 080h ; if down
ret nz
ld a,17 ; otherwise stay here
ldh (SCREEN & 0FFh),a
ret
fli_irq:
ld hl, bgp_table ; Set BGP for this line
ldh a, (tabidx & 0ffh)
add a,l
ld l,a
ld a,h
adc a,0
ld h,a
ld a,(hl)
ldh (BGP & 0FFh), a
ld hl, scx_table ; Set SCX for this line
ldh a, (tabidx & 0ffh)
add a,l
ld l,a
ld a,h
adc a,0
ld h,a
ld a,(hl)
ldh (SCX & 0FFh), a
ld hl, scy_table ; Set SCY for this line
ldh a, (tabidx & 0ffh)
add a,l
ld l,a
ld a,h
adc a,0
ld h,a
ldh a, (textpos & 0FFh)
add a,(hl)
ldh (SCY & 0FFh), a
ld hl, bgc_table ; set gb-color bg
ldh a, (tabidx & 0ffh)
sla a ; should be <128
add a,l
ld l,a
ld a,h
adc a,0
ld h,a
ld a,010000000b
ldh (BCPS & 0FFh), a
ldi a,(hl)
ldh (BCPD & 0FFh), a
ldi a,(hl)
ldh (BCPD & 0FFh), a
ld hl, lyc_table ; configure next FLI
ldh a, (tabidx & 0ffh)
inc a
cp (lyc_table_end-lyc_table)
jr nz, fi_j1
xor a
fi_j1: ldh (tabidx & 0ffh),a
add a,l
ld l,a
ld a,h
adc a,0
ld h,a
ld a,(hl)
ldh (LYC & 0FFh), a
ret
; table with positions of Y-irqs and SCX values
lyc_table:
.byte 0, 1, 3, 5, 95,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144
lyc_table_end:
scx_table:
.byte 0, 0, 0, 0, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1
scy_table:
.byte 0, 0, 0, 0, 0, -4, -8,-12,-16,-20,-24,-28,-32,-36,-40,-44,-48,-52,-56,-60,-64,-68,-72,-76,-80,-84,-88,-92
bgp_table:
.byte 000h,054h,0A4h,0e4h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h,0e5h
bgc_table:
.word 00000h,0294ah,05294h,07fffh,07c00h,07800h,07400h,07000h,06c00h,06800h,06400h,06000h,05c00h,05800h,05400h,05000h,04c00h,04800h,04400h,04000h,03c00h,03800h,03400h,03000h,02c00h,02800h,0,0