/
clonetro.asm
1203 lines (1014 loc) · 21.1 KB
/
clonetro.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
;
; CLONETRO
;
; Code and graphics by TMR
; Music by Odie
; A written-from-scratch mashup of various C64 crack intros from
; Jewels, Yeti Factories, Ikari and the Dynamic Duo. Coded for
; C64CrapDebunk.Wordpress.com and the 2016 iteration of Laxity's
; CSDb Intro Competition.
; Notes: this source is formatted for the ACME cross assembler from
; http://sourceforge.net/projects/acme-crossass/
; Compression is handled with Exomizer 2 which can be downloaded at
; http://hem.bredband.net/magli143/exo/
; build.bat will call both to create an assembled file and then the
; crunched release version.
; Memory Map
; $0800 - $0dff character graphics
; $0e00 - $0fff sprites
; $1000 - $1bff music
; $1c00 - $1fff precalcuated grid data
; $2000 - $23ff scroll character set
; $2400 - $27ff screen RAM
; $2800 - $3fff program code/data
; Select an output filename
!to "clonetro.prg",cbm
; Pull in the binary data
* = $0800
!binary "binary\graphics.chr"
* = $0e00
!binary "binary\sprites.spr"
* = $1000
music !binary "binary\cosine_intro_v2.prg",,2
* = $1c00
grid_data !binary "binary\grids.raw"
* = $2000
!binary "binary\plain_font_16x8.chr"
* = $2400
screen_data !binary "binary\screen.raw"
; Raster split positions
raster_1_pos = $00
raster_2_pos = $49
raster_3_pos = $89
raster_4_pos = $9c
; Label assignments
raster_num = $50
colour_timer = $51 ; two bytes used
colour_read_1 = $52 ; two bytes used
colour_read_2 = $54 ; two bytes used
logo_wash_count = $56
scrl_wash_count = $57
scroll_pos = $58 ; two bytes used
scroll_x = $5a
scroll_count = $5b
grid_read_1 = $5c ; two bytes used
grid_read_2 = $5e ; two bytes used
grid_x1 = $60
grid_y1 = $61
grid_x2 = $62
grid_y2 = $63
grid_dir = $64
grid_timer_x1 = $65
grid_timer_y1 = $66
grid_timer_x2 = $67
grid_timer_y2 = $68
sine_at_1 = $69
sine_at_2 = $6a
sine_at_3 = $6b
sine_speed_1 = $6c
sine_speed_2 = $6d
sine_speed_3 = $6e
anim_timer = $6f
scroll_line = $25e0
scroll_col_line = scroll_line+$b400
grid_work_lf = $0de0
grid_work_rt = $0df0
; Entry point for the code
* = $2800
; Stop interrupts, disable the ROMS and set up NMI and IRQ interrupt pointers
code_start sei
lda #$35
sta $01
lda #<nmi_int
sta $fffa
lda #>nmi_int
sta $fffb
lda #<irq_int
sta $fffe
lda #>irq_int
sta $ffff
; Set the VIC-II up for a raster IRQ interrupt
lda #$7f
sta $dc0d
sta $dd0d
lda $dc0d
lda $dd0d
lda #raster_1_pos
sta $d012
lda #$1b
sta $d011
lda #$01
sta $d019
sta $d01a
; Draw the grid area into what will become the screen RAM
ldx #$00
grid_draw lda #$bc
sta screen_data+$259,x
sta screen_data+$2a9,x
sta screen_data+$2f9,x
sta screen_data+$349,x
sta screen_data+$399,x
clc
adc #$01
sta screen_data+$281,x
sta screen_data+$2d1,x
sta screen_data+$321,x
sta screen_data+$371,x
inx
clc
adc #$01
sta screen_data+$259,x
sta screen_data+$2a9,x
sta screen_data+$2f9,x
sta screen_data+$349,x
sta screen_data+$399,x
clc
adc #$01
sta screen_data+$281,x
sta screen_data+$2d1,x
sta screen_data+$321,x
sta screen_data+$371,x
inx
cpx #$24
bne grid_draw
; Set the colour for the screen at $2400
ldx #$00
colour_set ldy screen_data+$000,x
lda colour_decode,y
sta $d800,x
ldy screen_data+$100,x
lda colour_decode,y
sta $d900,x
ldy screen_data+$200,x
lda colour_decode,y
sta $da00,x
ldy screen_data+$2e8,x
lda colour_decode,y
sta $dae8,x
inx
bne colour_set
; Colour in the logo
ldx #$00
lda #$08
logo_col_set sta $d87c,x
sta $d8a4,x
sta $d8cc,x
sta $d8f4,x
sta $d91c,x
inx
cpx #$1e
bne logo_col_set
; Set up the line for the scroller
ldx #$00
scroll_col_set lda #$06
sta $d9b8,x
sta $da08,x
lda #$00
sta $d9e0,x
inx
cpx #$28
bne scroll_col_set
; Add some colour for the grid
ldx #$00
lda #$0b
grid_col_draw sta $da59,x
sta $da81,x
sta $daa9,x
sta $dad1,x
sta $daf9,x
sta $db21,x
sta $db49,x
sta $db71,x
sta $db99,x
inx
cpx #$24
bne grid_col_draw
; Set up the music driver
ldx #$00
txa
tay
jsr music+$00
; Initialise our own labels
ldx #$00
lda #$00
clear_zp sta raster_num,x
inx
cpx #$20
bne clear_zp
lda #$01
sta raster_num
lda #<split_cols_1
sta colour_read_1+$00
lda #>split_cols_1
sta colour_read_1+$01
lda #<split_cols_2
sta colour_read_2+$00
lda #>split_cols_2
sta colour_read_2+$01
lda #$20
sta logo_wash_count
lda #$6a
sta grid_dir
lda #$00
sta sine_at_1
sta sine_at_2
sta sine_at_3
lda #$03
sta sine_speed_1
lda #$01
sta sine_speed_2
lda #$02
sta sine_speed_3
; Reset the scroller
jsr scroll_reset
lda #$e0
sta scroll_count
; Restart the interrupts
cli
; Infinite loop to check for space being pressed
space_loop lda $dc01
cmp #$ef
bne space_loop
; Stop the interrupts, switch off the screen and zero the volume
sei
lda #$0b
sta $d011
lda #$00
sta $d020
sta $d418
; Bank in the ROMs and reset the C64
lda #$37
sta $01
jmp $fce2
; IRQ interrupt handler
irq_int pha
txa
pha
tya
pha
lda $d019
and #$01
sta $d019
bne int_go
jmp irq_exit
; An interrupt has triggered
int_go lda raster_num
cmp #$02
bne *+$05
jmp irq_rout2
cmp #$03
bne *+$05
jmp irq_rout3
cmp #$04
bne *+$05
jmp irq_rout4
; Raster split 1
irq_rout1 lda #$06
sta $d020
lda #$0e
sta $d021
lda #$03
sta $d022
lda #$0d
sta $d023
lda #$17
sta $d016
lda #$92
sta $d018
; Set up the hardware sprites as an underlay for the scroller
lda #$ff
sta $d015
sta $d01b
sta $d01c
sta $d01d
ldx #$00
lda underlay_x
set_sprite_x1 sta $d000,x
clc
adc #$30
inx
inx
cpx #$0e
bne set_sprite_x1
lda #$40
ldy $d00a
cpy #$80
bcs *+$04
lda #$60
sta $d010
ldx #$00
lda #$8c
set_sprite_y1 sta $d001,x
inx
inx
cpx #$0e
bne set_sprite_y1
ldx #$00
lda #$80
set_sprite_dp1 lda underlay_dp
sta $27f8,x
lda #$0f
sta $d027,x
inx
cpx #$07
bne set_sprite_dp1
lda #$0c
sta $d025
lda #$01
sta $d026
; Update the colour for the C64CD logo
ldx #$00
logo_wash lda $d87d,x
sta $d87c,x
sta $d8a4,x
sta $d8cc,x
sta $d8f4,x
sta $d91c,x
inx
cpx #$1d
bne logo_wash
inc logo_wash_count
ldx logo_wash_count
cpx #$20
bcc *+$04
ldx #$1f
lda wash_colours,x
ora #$08
sta $d899
sta $d8c1
sta $d8e9
sta $d911
sta $d939
; Move the scroller's colour RAM to the right
ldx #$26
scroll_col_wash lda scroll_col_line+$00,x
sta scroll_col_line+$01,x
dex
cpx #$ff
bne scroll_col_wash
ldx scrl_wash_count
inx
cpx #$59
bcc *+$04
ldx #$00
stx scrl_wash_count
cpx #$20
bcc *+$04
ldx #$00
lda scroll_wash_col,x
sta scroll_col_line
; Set interrupt handler for split 2
lda #$02
sta raster_num
lda #raster_2_pos
sta $d012
; Exit IRQ interrupt
jmp irq_exit
; Skip to the next page boundary so the timing doesn't get mangled!
* = ((*/$100)+1)*$100
; Raster split 2
irq_rout2 ldx #$0e
dex
bne *-$01
; Colour splitter for the C64CD logo
ldy #$00
splitter_1 lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$08
dex
bne *-$01
nop
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$08
dex
bne *-$01
nop
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$08
dex
bne *-$01
nop
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$08
dex
bne *-$01
nop
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$08
dex
bne *-$01
nop
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$08
dex
bne *-$01
nop
lda (colour_read_1),y
sta $d022
lda (colour_read_2),y
sta $d023
iny
ldx #$07
dex
bne *-$01
cpy #$28
beq *+$05
jmp splitter_1
lda #$03
sta $d022
lda #$0d
sta $d023
; Update the colour positions
lda colour_timer
eor #$01
and #$01
sta colour_timer
beq colour_update_2
colour_update_1 ldx colour_read_1
inx
cpx #$40
bne *+$04
ldx #$00
stx colour_read_1
jmp colour_upd_out
colour_update_2 ldx colour_read_2
dex
cpx #$7f
bne *+$04
ldx #$8f
stx colour_read_2
; Update the underlay sprites
colour_upd_out ldx underlay_x
dex
cpx #$ff
bne ux_xb
lda underlay_dp
eor #$01
sta underlay_dp
ldx #$17
ux_xb stx underlay_x
; Set interrupt handler for split 3
lda #$03
sta raster_num
lda #raster_3_pos
sta $d012
jmp irq_exit
; Raster split 3
irq_rout3 ldx #$0e
dex
bne *-$01
lda scroll_x
and #$03
eor #$03
asl
sta $d016
lda #$98
sta $d018
lda #$0b
sta $d021
; Set interrupt handler for split 4
lda #$04
sta raster_num
lda #raster_4_pos
sta $d012
jmp irq_exit
; Raster split 4
irq_rout4 ldx #$03
dex
bne *-$01
lda #$0b
sta $d022
lda #$0e
sta $d023
lda #$0d
sta $d021
lda #$17
sta $d016
lda #$92
sta $d018
; Relocate the sprites for the lower box
ldx #$00
ldy #$00
set_sprites lda sprite_x,x
clc
adc #$6c
sta $d000,y
lda sprite_y,x
clc
adc #$aa
sta $d001,y
lda sprite_cols,x
sta $d027,x
lda sprite_dps,x
sta $27f8,x
iny
iny
inx
cpx #$08
bne set_sprites
lda #$09
sta $d025
lda #$01
sta $d026
lda #$00
sta $d010
sta $d01d
; Wait until the upper edge of the frame for a colour change
lda #$a9
col_wait_1 cmp $d012
bne *-$05
lda #$00
sta $d021
; Move scrolling message
ldx scroll_x
inx
cpx #$04
bne scr_xb
; Move the text line
ldx #$00
scroll_mover lda scroll_line+$01,x
sta scroll_line+$00,x
inx
cpx #$27
bne scroll_mover
ldx scroll_count
inx
cpx #$02
bne sc_skip
; Copy a new character to the scroller
ldy #$00
scroll_mread lda (scroll_pos),y
bne scroll_okay
jsr scroll_reset
jmp scroll_mread
scroll_okay asl
sta scroll_line+$26
clc
adc #$01
sta scroll_line+$27
; Nudge the scroller onto the next character
inc scroll_pos+$00
bne *+$04
inc scroll_pos+$01
ldx #$00
sc_skip stx scroll_count
ldx #$00
scr_xb stx scroll_x
; Work out the sprite positions for the next frame
lda sine_at_1
clc
adc sine_speed_1
sta sine_at_1
lda sine_at_2
clc
adc sine_speed_2
sta sine_at_2
lda sine_at_3
clc
adc sine_speed_3
sta sine_at_3
ldx #$00
ldy sine_at_1
sine_x_gen_1 lda sprite_x_sinus,y
sta sprite_x,x
tya
clc
adc #$25
tay
inx
cpx #$08
bne sine_x_gen_1
ldx #$00
ldy sine_at_2
sine_x_gen_2 lda sprite_x_sinus,y
clc
adc sprite_x,x
sta sprite_x,x
tya
clc
adc #$1b
tay
inx
cpx #$08
bne sine_x_gen_2
ldx #$00
ldy sine_at_3
sine_y_gen_1 lda sprite_y_sinus,y
sta sprite_y,x
tya
clc
adc #$1d
tay
inx
cpx #$08
bne sine_y_gen_1
; Play the music
jsr music+$03
; Wait until the lower edge of the frame for colour changes
lda #$f3
cmp $d012
bne *-$05
lda #$0d
sta $d021
ldx #$20
dex
bne *-$01
lda #$00
sta $d021
; Check to see if the grids need to change direction
ldx #$00
grid_upd_loop lda grid_timer_x1,x
clc
adc #$01
cmp grid_max_vals,x
bne gtx1_xb
lda grid_dir
eor grid_joy_masks,x
sta grid_dir
lda #$00
gtx1_xb sta grid_timer_x1,x
inx
cpx #$04
bne grid_upd_loop
; Update the grid positions
lda grid_dir
grid_1_up lsr
bcc *+$04
dec grid_y1
grid_1_down lsr
bcc *+$04
inc grid_y1
grid_1_left lsr
bcc *+$04
dec grid_x1
grid_1_right lsr
bcc *+$04
inc grid_x1
grid_2_up lsr
bcc *+$04
dec grid_y2
grid_2_down lsr
bcc *+$04
inc grid_y2
grid_2_left lsr
bcc *+$04
dec grid_x2
grid_2_right lsr
bcc *+$04
inc grid_x2
; Render the lower grid
lda grid_x1
lsr
and #$07
sta grid_read_1+$00
lda #$00
asl grid_read_1+$00
rol
asl grid_read_1+$00
rol
asl grid_read_1+$00
rol
asl grid_read_1+$00
rol
clc
adc #>grid_data+$00
sta grid_read_1+$01
lda grid_y1
and #$0f
tax
ldy #$00
grid_copy_l1 lda (grid_read_1),y
sta grid_work_lf,x
inx
cpx #$10
bne *+$04
ldx #$00
iny
cpy #$10
bne grid_copy_l1
lda grid_y1
and #$0f
tax
ldy #$80
grid_copy_r1 lda (grid_read_1),y
sta grid_work_rt,x
inx
cpx #$10
bne *+$04
ldx #$00
iny
cpy #$90
bne grid_copy_r1
; Render the upper grid
lda grid_x2
lsr
and #$07
sta grid_read_1+$00
lda #$00
asl grid_read_1+$00
rol
asl grid_read_1+$00
rol
asl grid_read_1+$00
rol
asl grid_read_1+$00
rol
clc
adc #>(grid_data+$100)
sta grid_read_1+$01
clc
adc #$01
sta grid_read_2+$01
lda grid_read_1+$00
sta grid_read_2+$00
lda grid_y2
and #$0f
tax
ldy #$00
grid_copy_l2 lda grid_work_lf,x
and (grid_read_2),y
ora (grid_read_1),y
sta grid_work_lf,x
inx
cpx #$10
bne *+$04
ldx #$00
iny
cpy #$10
bne grid_copy_l2
lda grid_y2
and #$0f
tax
ldy #$80
grid_copy_r2 lda grid_work_rt,x
and (grid_read_2),y
ora (grid_read_1),y
sta grid_work_rt,x
inx
cpx #$10
bne *+$04
ldx #$00
iny
cpy #$90
bne grid_copy_r2
; Update the sprite animations if need be
ldx anim_timer
inx
cpx #$03
bne at_xb
ldx #$00
anim_update lda sprite_dps,x
clc
adc #$01
cmp #$3e
bne *+$04
lda #$38
sta sprite_dps,x
inx
cpx #$08
bne anim_update
ldx #$00
at_xb stx anim_timer
; Set interrupt handler for split 1
lda #$01
sta raster_num
lda #raster_1_pos
sta $d012
; Restore registers and exit IRQ interrupt
irq_exit pla
tay
pla
tax
pla
nmi_int rti
; Subroutine to reset the scrolling message
scroll_reset lda #<scroll_text
sta scroll_pos+$00
lda #>scroll_text
sta scroll_pos+$01
rts
; Colour data for the screen (each character has a fixed colour)
colour_decode !byte $0e,$0c,$0e,$0e,$0e,$0e,$0e,$0c
!byte $0e,$0e,$0e,$0e,$0e,$0e,$0c,$0c
!byte $0e,$0e,$0e,$0e,$0c,$0e,$0e,$0e
!byte $0c,$0c,$0c,$0c,$0c,$0e,$0c,$0c
!byte $0c,$0b,$0c,$01,$0c,$0c,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
!byte $0c,$0b,$0c,$0c,$0c,$0c,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0e,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
!byte $0c,$0c,$0c,$0e,$0b,$0b,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0b,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0b
!byte $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0e
!byte $0e,$0e,$0c,$0b,$0b,$0b,$0b,$0b
!byte $0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b
!byte $0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b
!byte $0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b
; Raster colour tables for the C64CD logo