This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
up-xmas2021.asm
518 lines (397 loc) · 11.4 KB
/
up-xmas2021.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
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
org #1200
SCREEN_WIDTH = 40
SCREEN_HEIGHT = 25
hblnk = 0xe008
vblnk = 0xe002
include "monitor.asm"
include "decrunch/dzx0_fast.asm"
macro wait_vbl ; wait for vblank
ld hl, vblnk
ld a, 0x7f
@wait0:
cp (hl)
jp nc, @wait0
@wait1:
cp (hl)
jp c, @wait1
mend
;----------------------------------------------------------------------------------------------------------------------
main: ; main entry point
di
im 1
call fill_screen
PRESS_SPACE_OFFSET = 12*SCREEN_WIDTH + SCREEN_WIDTH/2 - 12
ld hl, press_space ; display "press space" message.
ld de, 0xd000+PRESS_SPACE_OFFSET
ld bc, 24
ldir
ld hl, 0xd800+PRESS_SPACE_OFFSET
ld (hl), 0xF2
ld de, 0xd801+PRESS_SPACE_OFFSET
ld bc, 23
ldir
wait_key: ; wait for space to be pressed.
ld hl, 0xe000
ld (hl), 0xf6
inc hl
bit 4,(hl)
jp nz, wait_key
out (0xe0), a ; allocates RAM to $0000-$0fff
; the monitor will be unavailable and all the IRQ jump addresses
; are right in the area where the frame are unpacked...
; the unpacked frame is stored from 0x0000 to 0x07d0
; the copy to vram routine is stored from 0x0800 to 0x0e12
; setup vram copy routine to RAM
ld hl, copy_line ; d000
ld de, 0x840
ld bc, copy_line.end - copy_line
ldir
ld ix, 0xd000+10
ld iy, 0xd800+10
ld (copy_line.begin+2), iy
ld hl, copy_line.begin ; d800
ld bc, copy_line.end - copy_line.begin
ldir
ld a, 24
.l1:
ld bc, 40
add ix, bc
add iy, bc
ld (copy_line.begin+2), ix
ld hl, copy_line.begin ; d000
ld bc, copy_line.end - copy_line.begin
ldir
ld (copy_line.begin+2), iy
ld hl, copy_line.begin ; d800
ld bc, copy_line.end - copy_line.begin
ldir
dec a
jp nz, .l1
ld hl, copy_line.end ; copy stack pointer backup and return
ld bc, 4
ldir
ld hl, song
xor a
call PLY_LW_Init
ld hl, irq_call
ld de, 0x0038
ld bc, 3
ldir
ld hl, 0xe007 ;Counter 2.
ld (hl), 0xb0
dec hl
ld (hl),1
ld (hl),0
ld hl, 0xe007 ; 100 Hz (plays the music at 50hz).
ld (hl), 0x74
ld hl, 0xe005
ld (hl), 156
ld (hl), 0
ld hl, 0xe008 ; Sound on
ld (hl), 0x01
ei
start:
ld hl, scroller
call load_frame
@scroll.0:
call big_scroll_init
@scroll.1:
call big_scroll_update
ld a, (scroll_chr_index+1)
cp 0xff
jp nz, @scroll.1
; ball
ld hl, ball.lo
ld (frame_update.lo), hl
ld hl, ball.hi
ld (frame_update.hi), hl
ld hl, ball_12
ld (frame_src), hl
ld a, l
ld (frame_reset.lo), a
ld a, h
ld (frame_reset.hi), a
ld a, 11
ld (anim.frame_count), a
ld c, 16
call anim_play
; scroller 2
ld hl, scroll_txt.1
ld (big_scroll_txt), hl
ld hl, scroller
call load_frame
@scroll.2:
call big_scroll_init
@scroll.3:
call big_scroll_update
ld a, (scroll_chr_index+1)
cp 0xff
jp nz, @scroll.3
; santa
ld hl, frame.lo
ld (frame_update.lo), hl
ld hl, frame.hi
ld (frame_update.hi), hl
ld hl, frame_6
ld (frame_src), hl
ld a, l
ld (frame_reset.lo), a
ld a, h
ld (frame_reset.hi), a
ld a, 5
ld (anim.frame_count), a
ld c, 24
call anim_play
; tunnel
ld hl, tunnel.lo
ld (frame_update.lo), hl
ld hl, tunnel.hi
ld (frame_update.hi), hl
ld hl, tunnel_12
ld (frame_src), hl
ld a, l
ld (frame_reset.lo), a
ld a, h
ld (frame_reset.hi), a
ld a, 11
ld (anim.frame_count), a
ld c, 20
call anim_play
call PLY_LW_Stop ; stop music
ld hl, 0xe008 ; Sound off
ld (hl), 0x00
di ; deactivate interrupts
call fill_screen
ld hl, flip_tape
ld de, 0xd000+(12*SCREEN_WIDTH + (SCREEN_WIDTH-36)/2)
ld bc, 36
ldir
out (0xe2), a ; restore monitor
ld sp, 0x10F0 ; restore stack pointer
ld de, 0x0e10
ld (monitor_DSPXY), de
jp monitor_LOAD
;----------------------------------------------------------------------------------------------------------------------
fill_screen:
ld (@transition_sp_save), sp ; save stack pointer (should be useless as we can deduce/hardcode it)
@fill_screen: ; pull down a red curtain on screen
ld iy, SCREEN_HEIGHT ; at each vbl will update the current line with a different character until the
ld ix, 0xd000+SCREEN_WIDTH ; the line is "full". We'll then proceed to the next one until the screen is completly filled.
@fill_screen.loop
ld bc, 0
@fill_line:
wait_vbl
ld sp, ix ; we'll fill the line by pushing a char to the char vram.
ld hl, histogram.attr ; A = histogram.attr[bc]
add hl, bc
ld a, (hl)
ld h, a
ld l, a
repeat SCREEN_WIDTH/2 ; we push 2 bytes each time
push hl
rend
ld hl, 0x800+SCREEN_WIDTH ; do the same with color vram
add hl, sp
ld sp, hl
@fill_color equ $+1
ld hl, histogram.color ; a = histogram.color[bc]
add hl, bc
ld a, (hl)
ld h, a
ld l, a
repeat SCREEN_WIDTH/2
push hl
rend
inc c ; we'll repeat this until the char is full.
ld a, 7
cp c
jp nz, @fill_line
ld de,SCREEN_WIDTH ; jump to the next line
add ix,de
dec iyl
jp nz, @fill_screen.loop ; we are done.
@transition_sp_save equ $+1 ; restore stack pointer (may be useless and can be hardocded).
ld sp, 0x0000
ret
histogram.color:
defb 0x21,0x21,0x21,0x12,0x12,0x12,0xf2
histogram.attr:
defb 0x70,0x36,0x7a,0x7e,0x3e,0x3c,0x00
;----------------------------------------------------------------------------------------------------------------------
; copy a line from 0x0000-0xffff to VRAM (char or color)
copy_line:
ld ix, 0x0040
copy_line.begin:
ld iy, 0xd000+10
ld b, 4
l0:
di
ld sp, ix
pop hl
pop de
exx
pop hl
pop bc
pop de
ld sp, iy
push de
push bc
push hl
exx
push de
push hl
ld sp, 0x10ea
ei
ld de, 10
add iy, de
add ix, de
djnz l0
copy_line.end: ; we can hardcode stack return address
ret
;----------------------------------------------------------------------------------------------------------------------
press_space:
defb 0x82,0x83,0x84,0xb3,0xA0,0x00,0x10,0x12,0x05,0x13,0x13,0x00,0x00,0x13,0x10,0x01,0x03,0x05,0x00,0xA0,0xb3,0x84,0x83,0x82
flip_tape:
defb 0x82,0x83,0x84,0xb3,0xA0,0x00,0x06,0x0c,0x09,0x10,0x00,0x14,0x01,0x10,0x05,0x00,0x01,0x0e,0x04,0x00,0x10,0x12,0x05,0x13,0x13,0x00,0x10,0x0c,0x01,0x19,0x00,0xA0,0xb3,0x84,0x83,0x82
;----------------------------------------------------------------------------------------------------------------------
repeat 12,cnt
ball_{cnt}:
inczx0 "_data/anim/ball/Frame_{cnt}.bin"
rend
ball.lo:
repeat 12,cnt,12,-1
defb lo(ball_{cnt})
rend
ball.hi:
repeat 12,cnt,12,-1
defb hi(ball_{cnt})
rend
;----------------------------------------------------------------------------------------------------------------------
repeat 12,cnt
tunnel_{cnt}:
inczx0 "_data/anim/tunnel/Frame_{cnt}.bin"
rend
tunnel.lo:
repeat 12,cnt,12,-1
defb lo(tunnel_{cnt})
rend
tunnel.hi:
repeat 12,cnt,12,-1
defb hi(tunnel_{cnt})
rend
;----------------------------------------------------------------------------------------------------------------------
repeat 6,cnt
frame_{cnt}:
inczx0 "_data/anim/santa/Frame_{cnt}.bin"
rend
frame.lo:
repeat 6,cnt,6,-1
defb lo(frame_{cnt})
rend
frame.hi:
repeat 6,cnt,6,-1
defb hi(frame_{cnt})
rend
;----------------------------------------------------------------------------------------------------------------------
scroller:
inczx0 "_data/anim/scroller/Frame_7.bin"
;----------------------------------------------------------------------------------------------------------------------
include "big_scroll.asm"
;----------------------------------------------------------------------------------------------------------------------
org #c340
;----------------------------------------------------------------------------------------------------------------------
; ZX0 depacking
decrunch:
DecompressZX0 (void)
ret
;----------------------------------------------------------------------------------------------------------------------
anim_play:
anim.frame_count equ $+1
ld b, 5
play.1:
push bc
frame_src equ $+1
ld hl, frame_6
ld de, 0x0040
call decrunch
frame_delay: equ $+1
ld b, 3
@wait:
wait_vbl
djnz @wait
call 0x840 ; copy frame to VRAM
pop bc
xor a ; fetch next compressed frame
ld d,a
ld e,b
frame_update.lo equ $+1
ld hl, frame.lo
add hl, de
ld a, (hl)
ld (frame_src), a
frame_update.hi equ $+1
ld hl, frame.hi
add hl, de
ld a, (hl)
ld (frame_src+1), a ; frame_src += frame[b]
djnz play.1
frame_reset.lo equ $+1 ; reset source pointer
ld a, lo(frame_6)
ld (frame_src), a
frame_reset.hi equ $+1
ld a, hi(frame_6)
ld (frame_src+1), a
dec c
jp nz, anim_play
ret
;----------------------------------------------------------------------------------------------------------------------
load_frame: ; load a single frame
push bc
ld de, 0x0040
call decrunch ; unpack frame
wait_vbl ; wait for vblnk
call 0x840 ; copy frame to VRAM
pop bc
ret
;----------------------------------------------------------------------------------------------------------------------
irq_call:
jp _irq_vector
_irq_vector: ; timer irq vector.
di
push af ; ... this makes santa sad...
push hl
push bc
push de
push ix
push iy
exx
push af
push hl
push bc
push de
push ix
push iy
ld hl, 0xe006
ld a,1
ld (hl), a
xor a
ld (hl), a
call PLY_LW_Play
pop iy
pop ix
pop de
pop bc
pop hl
pop af
exx
pop iy
pop ix
pop de
pop bc
pop hl
pop af
ei
reti
player: include "PlayerLightweight_SHARPMZ700.asm"
include "data/music_playerconfig.asm"
song: include "data/music.asm"