-
Notifications
You must be signed in to change notification settings - Fork 1
/
md201702.asm
1492 lines (1218 loc) · 25.7 KB
/
md201702.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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
; MD201702
;
; Code and graphics by T.M.R/Cosine
; Music by Odie/Cosine
; Select an output filename
!to "md201702.prg",cbm
; Yank in binary data
* = $2900
music !binary "data/sporting_chance.prg",,2
* = $4800
!binary "data/copyright.chr"
* = $4c00
!binary "data/ninja_gaiden.chr"
; Constants
rstr1p = $00
rstr2p = $2c
rstr3p = $7c
rstr4p = $c8
rstr5p = $f1
bg_colour = $0c
bg_colour_m = bg_colour+(bg_colour*$10)
; Labels
rn = $50
sync = $51
rt_store_1 = $52
rt_store_2 = $53
scroll_x = $54
scroll_spd = $55
cos_at_1 = $56 ; for the FLI effect
cos_speed_1 = $57
preset_tmr = $58 ; two bytes used
colour_cnt = $5a
cos_at_2 = $5c ; for the logos
cos_speed_2 = $02 ; constant
cos_offset_2 = $30 ; constant
cos_at_3 = $5d ; for the logos
cos_speed_3 = $03 ; constant
cos_offset_3 = $43 ; constant
cos_at_4 = $5e ; for the logos
cos_speed_4 = $fe ; constant
cos_offset_4 = $e0 ; constant
cos_work_2 = $60 ; two bytes used
cos_work_3 = $62 ; two bytes used
cos_work_4 = $64 ; two bytes used
logo_d016_m1 = $66
logo_d018_m1 = $67
logo_d021_m1 = $68
logo_d022_m1 = $69
logo_d023_m1 = $6a
logo_d016_m2 = $6b
logo_d018_m2 = $6c
logo_d021_m2 = $6d
logo_d022_m2 = $6e
logo_d023_m2 = $6f
logo_d016_m3 = $70
logo_d018_m3 = $71
logo_d021_m3 = $72
logo_d022_m3 = $73
logo_d023_m3 = $74
cos_offsets = $80 ; $21 bytes long
fli_colours = $6004 ; start of the effect's colour RAM
colour_table_1 = $ce00
colour_table_2 = $cf00
; Entry point at $8000
* = $8000
entry sei
lda #$35
sta $01
lda #<nmi
sta $fffa
lda #>nmi
sta $fffb
lda #<int
sta $fffe
lda #>int
sta $ffff
lda #$7f
sta $dc0d
sta $dd0d
lda $dc0d
lda $dd0d
lda #rstr1p
sta $d012
lda #$0b
sta $d011
lda #$01
sta $d019
sta $d01a
; Reset screen colours
ldx #$00
lda #$0b
set_colours sta $d800,x
sta $d900,x
sta $da00,x
sta $dae8,x
inx
bne set_colours
; Reset the FLI colours
ldx #$00
lda #bg_colour_m
set_fli_cols sta $6000,x
sta $6400,x
sta $6800,x
sta $6c00,x
sta $7000,x
sta $7400,x
sta $7800,x
sta $7c00,x
sta $d800,x
inx
cpx #$a0
bne set_fli_cols
; Build the FLI effect bitmap
ldx #$00
lda #%01001000 ; skinny splits
; lda #%01011010 ; chunky splits
bitmap_build sta $4020,x
sta $4168,x
sta $42b0,x
sta $43f8,x
inx
cpx #$e0
bne bitmap_build
; Set up the scrolling message's space on screen
ldx #$00
scroll_init lda #$80
sta $5fc0,x
lda scroll_cols,x
sta $dbc0,x
inx
cpx #$27
bne scroll_init
; Clear zero page workspaces
ldx #$50
lda #$00
zp_nuke sta $00,x
inx
bne zp_nuke
lda #$01
sta rn
; Set up the first FLI effect preset
jsr preset_reset
jsr preset_fetch
; Wipe the FLI colour tables
ldx #$00
fli_col_nuke lda #bg_colour
sta colour_table_1,x
lda #(bg_colour*$10)
sta colour_table_2,x
inx
bne fli_col_nuke
; Rest the scrolling message
jsr reset
lda #$03
sta scroll_spd
; Initialise the music
lda #$00
jsr music+$00
cli
; Small delay before the FLI effect starts
ldx #$32
start_wait jsr sync_wait
dex
bne start_wait
; Update the FLI effect until a new preset needs fetching
main_loop jsr sync_wait
jsr fli_update
; Update the colour tables and counter
ldx colour_cnt
lda colour_table,x
sta colour_table_1,x
asl
asl
asl
asl
sta colour_table_2,x
inx
stx colour_cnt
; Check to see if a new preset is needed
ldx preset_tmr+$00
dex
cpx #$ff
bne *+$04
dec preset_tmr+$01
stx preset_tmr+$00
txa
ora preset_tmr+$01
beq preset_call
jmp main_loop
; A new effect preset is needed so...
preset_call ldx #$00
stx colour_cnt
; Update the FLI effect until the colours are cleared out
main_loop_2 jsr fli_update
ldx colour_cnt
lda #bg_colour
sta colour_table_1,x
lda #(bg_colour*$10)
sta colour_table_2,x
inx
stx colour_cnt
cpx #$c0
bne main_loop_2
; Fetch a new preset and jump back to the start up wait
jsr preset_fetch
jmp main_loop
; Unrolled code to update the FLI effect
fli_update lda cos_at_1
clc
adc cos_speed_1
sta cos_at_1
tax
!set column_cnt=$00
!do {
txa
clc
adc cos_offsets+$00+(column_cnt*$02)
tax
lda fli_cosinus,x
sta rt_store_1
txa
clc
adc cos_offsets+$01+(column_cnt*$02)
tax
stx rt_store_2
ldy fli_cosinus,x
ldx rt_store_1
!set line_cnt=$00
!do {
lda colour_table_1+$00+(line_cnt*$08),y
ora colour_table_2+$00+(line_cnt*$08),x
sta fli_colours+$0000+(line_cnt*$29)+(column_cnt)
lda colour_table_1+$01+(line_cnt*$08),y
ora colour_table_2+$01+(line_cnt*$08),x
sta fli_colours+$0400+(line_cnt*$29)+(column_cnt)
lda colour_table_1+$02+(line_cnt*$08),y
ora colour_table_2+$02+(line_cnt*$08),x
sta fli_colours+$0800+(line_cnt*$29)+(column_cnt)
lda colour_table_1+$03+(line_cnt*$08),y
ora colour_table_2+$03+(line_cnt*$08),x
sta fli_colours+$0c00+(line_cnt*$29)+(column_cnt)
lda colour_table_1+$04+(line_cnt*$08),y
ora colour_table_2+$04+(line_cnt*$08),x
sta fli_colours+$1000+(line_cnt*$29)+(column_cnt)
lda colour_table_1+$05+(line_cnt*$08),y
ora colour_table_2+$05+(line_cnt*$08),x
sta fli_colours+$1400+(line_cnt*$29)+(column_cnt)
lda colour_table_1+$06+(line_cnt*$08),y
ora colour_table_2+$06+(line_cnt*$08),x
sta fli_colours+$1800+(line_cnt*$29)+(column_cnt)
!if line_cnt<$03 {
lda colour_table_1+$07+(line_cnt*$08),y
ora colour_table_2+$07+(line_cnt*$08),x
sta fli_colours+$1c00+(line_cnt*$29)+(column_cnt)
}
!set line_cnt=line_cnt+$01
} until line_cnt=$04
ldx rt_store_2
!set column_cnt=column_cnt+$01
} until column_cnt=$1c
rts
; Reset the scrolling message
reset lda #<scroll_text
sta mread+$01
lda #>scroll_text
sta mread+$02
rts
; Read a block of preset data for the FLI effect ($80 is a "wrap" byte)
preset_fetch ldx #$00
pf_loop jsr preset_mread
sta cos_offsets,x
inx
cpx #$38
bne pf_loop
; Fetch the preset speed
jsr preset_mread
sta cos_speed_1
; Set the preset timer
lda #$00
sta preset_tmr+$00
lda #$03
sta preset_tmr+$01
rts
; FLI preset reader self mod code
preset_mread lda preset_data
cmp #$80
bne preset_okay
jsr preset_reset
jmp preset_mread
preset_okay inc preset_mread+$01
bne *+$05
inc preset_mread+$02
rts
; Reset the FLI preset reader's self mod code
preset_reset lda #<preset_data
sta preset_mread+$01
lda #>preset_data
sta preset_mread+$02
rts
; Runtime sync wait
sync_wait lda #$00
sta sync
cmp sync
beq *-$02
rts
; IRQ interrupt
int pha
txa
pha
tya
pha
lda $d019
and #$01
sta $d019
bne ya
jmp ea31
ya lda rn
cmp #$02
bne *+$05
jmp rout2
cmp #$03
bne *+$05
jmp rout3
cmp #$04
bne *+$05
jmp rout4
cmp #$05
bne *+$05
jmp rout5
; Raster split 1
rout1 lda #bg_colour
sta $d020
sta $d021
lda #$3b
sta $d011
lda #$10
sta $d016
lda #$80
sta $d018
lda #$c6
sta $dd00
; Play the music
jsr music+$03
; Set up for the next interrupt
lda #$02
sta rn
lda #rstr2p
sta $d012
jmp ea31
* = ((*/$100)+$01)*$100
; Raster split 2
rout2 nop
nop
nop
nop
nop
bit $ea
lda $d012
cmp #rstr2p+$01
bne *+$02
; sta $d020
ldx #$0a
dex
bne *-$01
nop
nop
lda $d012
cmp #rstr2p+$02
bne *+$02
; sta $d020
ldx #$0a
dex
bne *-$01
nop
lda $d012
cmp #rstr2p+$03
bne *+$02
; sta $d020
ldx #$0a
dex
bne *-$01
nop
lda $d012
cmp #rstr2p+$04
bne *+$02
; sta $d020
ldx #$0a
dex
bne *-$01
bit $ea
nop
lda $d012
cmp #rstr2p+$05
bne *+$02
; sta $d020
nop
nop
nop
ldx #$09
dex
bne *-$01
nop
lda $d012
cmp #rstr2p+$06
bne *+$02
; sta $d020
; FLI - first character line
ldx #$0e
dex
bne *-$01
bit $ea
ldx #$3c
ldy #$90
lda #$11
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3d
ldy #$a0
lda #$12
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3e
ldy #$b0
lda #$13
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3f
ldy #$c0
lda #$14
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$38
ldy #$d0
lda #$15
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$39
ldy #$e0
lda #$16
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3a
ldy #$f0
lda #$17
sta $d016
sty $d018
stx $d011
bit $ea
nop
; FLI - second and third character lines
!set line_cnt=$00
!do {
ldx #$3b
ldy #$80
lda #$10
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3c
ldy #$90
lda #$11
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3d
ldy #$a0
lda #$12
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3e
ldy #$b0
lda #$13
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3f
ldy #$c0
lda #$14
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$38
ldy #$d0
lda #$15
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$39
ldy #$e0
lda #$16
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3a
ldy #$f0
lda #$17
sta $d016
sty $d018
stx $d011
bit $ea
nop
!set line_cnt=line_cnt+$01
} until line_cnt=$02
; FLI - last character line
ldx #$3b
ldy #$80
lda #$10
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3c
ldy #$90
lda #$11
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3d
ldy #$a0
lda #$12
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3e
ldy #$b0
lda #$13
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$3f
ldy #$c0
lda #$14
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$38
ldy #$d0
lda #$15
sta $d016
sty $d018
stx $d011
bit $ea
nop
ldx #$39
ldy #$e0
lda #$16
sta $d016
sty $d018
stx $d011
; Set a few video registers for the logos
lda #$7b
sta $d011
lda logo_d016_m1
sta $d016
lda logo_d018_m1
sta $d018
lda logo_d021_m1
sta $d021
lda logo_d022_m1
sta $d022
lda logo_d023_m1
sta $d023
ldx #$04
dex
bne *-$01
lda #$5b
sta $d011
; Set up for the next interrupt
lda #rstr3p
sta $d012
lda #$03
sta rn
; Tell the runtime code to get going
lda #$01
sta sync
jmp ea31
; Raster split 3
rout3 lda logo_d016_m2
sta $d016
lda logo_d018_m2
sta $d018
lda logo_d021_m2
sta $d021
lda logo_d022_m2
sta $d022
lda logo_d023_m2
sta $d023
; Set up for the next interrupt
lda #rstr4p
sta $d012
lda #$04
sta rn
jmp ea31
; Raster split 4
rout4 lda logo_d016_m3
sta $d016
lda logo_d018_m3
sta $d018
lda logo_d021_m3
sta $d021
lda logo_d022_m3
sta $d022
lda logo_d023_m3
sta $d023
; Update the scrolling message
ldy scroll_spd
scroll_loop ldx scroll_x
inx
cpx #$08
bne scr_xb
ldx #$00
mover lda $5fc1,x
sta $5fc0,x
inx
cpx #$27
bne mover
mread lda scroll_text
bne okay
jsr reset
jmp mread
; Check for a speed command
okay cmp #$80
bcc okay_2
and #$0f
sta scroll_spd
lda #$00
; Write the byte to the scroller
okay_2 ora #$80
sta $5fe6
inc mread+$01
bne *+$05
inc mread+$02
ldx #$00
scr_xb stx scroll_x
dey
bne scroll_loop
; Set up for the next interrupt
lda #rstr5p
sta $d012
lda #$05
sta rn
jmp ea31
; Raster split 5
rout5 lda #$7b
sta $d011
lda #bg_colour
sta $d021
lda scroll_x
eor #$07
sta $d016
lda #$72
sta $d018
ldx #$08
dex
bne *-$01
lda #$1b
sta $d011
; Update the logo positions
lda #$00
sta cos_work_2+$01
sta cos_work_3+$01
sta cos_work_4+$01
lda cos_at_2
clc
adc #cos_speed_2
sta cos_at_2
tax
lda fli_cosinus,x
sta cos_work_2+$00
txa
clc
adc #cos_offset_2
tax
lda fli_cosinus,x
sta cos_work_3+$00
txa
clc
adc #cos_offset_2
tax
lda fli_cosinus,x
sta cos_work_4+$00
lda cos_at_3
clc
adc #cos_speed_3
sta cos_at_3
tax
lda fli_cosinus,x
clc
adc cos_work_2+$00
bcc *+$04
inc cos_work_2+$01
sta cos_work_2+$00
txa
clc
adc #cos_offset_3
tax
lda fli_cosinus,x
clc
adc cos_work_3+$00
bcc *+$04
inc cos_work_3+$01
sta cos_work_3+$00
txa
clc
adc #cos_offset_3
tax
lda fli_cosinus,x
clc
adc cos_work_4+$00
bcc *+$04
inc cos_work_4+$01
sta cos_work_4+$00
lda cos_at_4
clc
adc #cos_speed_4
sta cos_at_4
tax
lda fli_cosinus,x
clc
adc cos_work_2+$00
bcc *+$04
inc cos_work_2+$01
sta cos_work_2+$00
txa
clc
adc #cos_offset_4
tax
lda fli_cosinus,x
clc
adc cos_work_3+$00
bcc *+$04
inc cos_work_3+$01
sta cos_work_3+$00
txa
clc
adc #cos_offset_4
tax
lda fli_cosinus,x
clc
adc cos_work_4+$00
bcc *+$04
inc cos_work_4+$01
sta cos_work_4+$00
; Decode first row of logo positions
lda cos_work_2+$00
and #$07
eor #$07
sta logo_d016_m1
lsr cos_work_2+$01
ror cos_work_2+$00
lsr cos_work_2+$01
ror cos_work_2+$00
lsr cos_work_2+$01
ror cos_work_2+$00