-
Notifications
You must be signed in to change notification settings - Fork 1
/
roto.inc
1051 lines (938 loc) · 24.2 KB
/
roto.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
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
.filenamespace roto
.import source "pseudocommands.inc"
.import source "delay.inc"
.import source "bit.inc"
.import source "agsp.inc"
.import source "generate.inc"
.import source "init.inc"
.import source "timers.inc"
.import source "gencol.inc"
.import source "genchr.inc"
.import source "music.inc"
.const CRUNCH_MAX = 26
.const HEIGHT = 15
.const BITADD = 1 // TODO: try different values for this
.const NUM_ANGLES = 16
.const FADEOUT_TIME = $b0 + $26
.const SIZE_OF_ONE_INTERPOLATE_BLOCK = 6
.const BITMAP_SPEEDCODE_LENGTH = 26+25+25
.const SIZE_OF_ONE_BITMAP_WRITE_BLOCK = 53
.const FADEOUT = true
.errorif (<COLORIZE_LOOP_END) != 0, "Need colorize loop to end on a page boundary"
.errorif COLORIZE_LOOP_END >= BITMAP && COLORIZE_LOOP_END < BITMAP + $2000, "colorize loop extends into bitmap"
.segment RotoZeroPage [start=ZP_START, min=ZP_START, max=$ff, hide]
@crunch_start: .byte CRUNCH_MAX
pos_in_colorize_lo: .byte <(COLORIZE_LOOP_START + 39 * SIZE_OF_ONE_COLOR_BLOCK)
pos_in_colorize_hi: .byte >(COLORIZE_LOOP_START + 39 * SIZE_OF_ONE_COLOR_BLOCK)
colorize_rts: .word COLORIZE_LOOP_START + 40*HEIGHT*SIZE_OF_ONE_COLOR_BLOCK
xadd: .byte 8*23
row: .byte 26
save_a: .byte 0
save_x: .byte 0
save_y: .byte 0
tmp: .byte 0
tex_x_lo: .byte 0
tex_y_lo: .byte 0
tex_x: .fill HEIGHT, $30
tex_y: .fill HEIGHT, 0
tex_lo: .fill HEIGHT, 0
chars: .fill HEIGHT, 0
hi_nibble_0: .fill HEIGHT, 0
activation: .byte 0
texture_extra_bit: .byte 0 // 0 or $20
angle_256_lo: .byte 0
angle_256_hi: .byte 0
starting_angle: .byte 0, $20, -12
//angle_bits_lo: .byte 0 // ll000000
angle_bits_hi: .byte 0 // 000000hh
offset: .byte 0
// TODO: reuse some other zp addr
write_bitmap_rts: .word 0
black_dest1: .word COLRAM+$0370
black_dest2: .word $db70
texture_x_shift: .byte $20
slope_x: .byte 0
slope_y: .byte 0
br_x: .byte 0
br_y: .byte 0
xc0_ptr: .word 0
xc1_ptr: .word 0
xc2_ptr: .word 0
yc0_ptr: .word 0
yc1_ptr: .word 0
yc2_ptr: .word 0
colorize_loop_addr: .word COLORIZE_LOOP_START
// For patching write_bitmap_loop
bitmap_src_lo: .byte <BITMAP
bitmap_src_hi: .byte >BITMAP
bitmap_dest_lo: .byte <write_bitmap_loop
bitmap_dest_hi: .byte >write_bitmap_loop
clearpos: .word BITMAP
adelta: .byte 0
zp_jmp0: jmp jsr0:COLORIZE_LOOP_START
colorize_template:
.for (var i = 0; i < 1; i++) {
entry:
// 15 bytes, 20 cycles
.label col1 = * + 1
lda $ff00, x
.label col2 = * + 1
ora $ff00, x
.label store1 = * + 1
sta.abs COLRAM+i
.label col3 = * + 1
lda $ff00, x
.label store2 = * + 1
sta $d800 + i
.errorif (*) - entry != SIZE_OF_ONE_COLOR_BLOCK, "Expected colorize loop to be " + SIZE_OF_ONE_COLOR_BLOCK + " bytes"
}
colorize_loop_tail:
.const TAIL_SIZE = 3
jmp COLORIZE_LOOP_START
.label block_lo = *+0
.label block_hi = *+1
.fill HEIGHT*2, 0
// --------------------------------------------------------------------
// Colorize loop (generator)
// --------------------------------------------------------------------
.macro GENERATE_COLORIZE_LOOP() {
ldx #$00
one_block:
ldy #SIZE_OF_ONE_COLOR_BLOCK + TAIL_SIZE - 1
!:
lda colorize_template, y
sta (colorize_loop_addr), y
dey
bpl !-
inc.zp colorize_template[0].store1+0
inc.zp colorize_template[0].store2+0
bne noc1
inc.zp colorize_template[0].store1+1
inc.zp colorize_template[0].store2+1
noc1:
lda.zp colorize_loop_addr+0
clc
adc #SIZE_OF_ONE_COLOR_BLOCK
sta.zp colorize_loop_addr+0
lda.zp colorize_loop_addr+1
adc #$00
sta.zp colorize_loop_addr+1
cmp #>COLORIZE_LOOP_END
bne one_block
}
// --------------------------------------------------------------------
// Init
// --------------------------------------------------------------------
.segment Code
@roto_entry:
GENERATE_ROTO_TABLES() // also clears d015, d020, d021
GENERATE_TEXTURE()
GENERATE_SINCOS()
ldx #ZP_START
!:
lda roto_zp-ZP_START, x
sta $00, x
inx
bne !-
stx vsppos
inc roto_zp + (activation - ZP_START)
GENERATE_COLORIZE_LOOP()
// Patch bitreverse loops
// TODO: only do this if we haven't, yet?
ldx #$00
ldy #HEIGHT-2
!:
lda bitreverse_lookup, y
sta br_x_loop+1, x
sta br_y_loop+1, x
txa
axs #-SIZE_OF_ONE_INTERPOLATE_BLOCK
dey
bpl !-
// Patch write_bitmap_loop
ldx #$00
patch_bitmap_loop:
clc
lda bitmap_src_lo
ldy #(write_bitmap_loop[0].dest0 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest1 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest2 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest3 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest4 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest5 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest6 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
ldy #(write_bitmap_loop[0].dest7 - write_bitmap_loop[0].entry)
sta (bitmap_dest_lo), y
adc #$01
lda bitmap_src_hi
ldy #(write_bitmap_loop[0].dest0 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest1 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest2 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest3 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest4 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest5 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest6 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
ldy #(write_bitmap_loop[0].dest7 - write_bitmap_loop[0].entry + 1)
sta (bitmap_dest_lo), y
// pos+BITMAP in bitmap_src_lo/bitmap_src_hi
lda bitmap_src_lo
clc
adc #$40
sta bitmap_src_lo
lda bitmap_src_hi
adc #$01
and #$1f
ora #>BITMAP
cmp #>(BITMAP+$1fc0)
bne not_1fc0
ldy bitmap_src_lo
cpy #<(BITMAP+$1fc0)
bne not_1fc0
sty bitmap_src_lo
lda #>(BITMAP-$40)
not_1fc0:
sta bitmap_src_hi
lda bitmap_dest_lo
sta write_bitmap_lo, x
clc
adc #SIZE_OF_ONE_BITMAP_WRITE_BLOCK
sta bitmap_dest_lo
lda bitmap_dest_hi
sta write_bitmap_hi, x
adc #$00
sta bitmap_dest_hi
inx
cpx #BITMAP_SPEEDCODE_LENGTH
bne_far patch_bitmap_loop
nopatch:
lda #$83
sta $dd0d // enable upper/lower border interrupt
ldx activation
lda starting_angle, x
sta angle_256_hi
// TODO: can we do this as part of patch_bitmap_loop?
ldx #$20
lda #$00
tay
!:
sta (clearpos), y
iny
bne !-
inc clearpos+1
dex
bne !-
lda #$02
sta $dd00
lda #$80
sta $d018
lda #$18
sta $d016
lda #$36
sta $d012
lda #$3f
sta $d011
sta zp_d011
ldx #<irq
ldy #>irq
stx $fffe
sty $ffff
lda #$01
sta $d01a
sta $d019
cli
delay_loop:
bne *
.align 256
// --------------------------------------------------------------------
// IRQ
// --------------------------------------------------------------------
irq:
sta save_a
stx save_x
sty save_y
lda #$1e
sec
sbc $dc06
// A in 1..8
sta * + 4
branch:
bpl * + 2
.byte $c2, $c2
.byte $c2, $c2
.byte $c2, $c2
.byte $c2, $04
.byte $ea
.errorif (>branch) != (>*), "page crossing in dejitter"
DELAY(4)
AGSP(7, CRUNCH_MAX, $78, $38)
no_agsp:
INC_VSP(CRUNCH_MAX)
// --------------------------------------------------------------------
// Animation
// --------------------------------------------------------------------
lda #$00
ldx activation
bne anim_one_or_two
anim_zero:
// --------------------------------------------------------------------
// Animation 0
// --------------------------------------------------------------------
sta br_x
sta slope_x
// music timer = $0026
lax music_lo
asl
asl
asl
tay
ror
cpx #FADEOUT_TIME
bpl !+
// clc
sbc #FADEOUT_TIME - $80 - 1
adc music_lo
!:
asl
eor #$80
tax
lda sin_table, x
clc
adc sin_table, y
ror
sta tmp
lsr
lsr
lsr
lsr
lsr
sec
sbc #$11
sta tex_y+0
lda #$08
sta slope_y
lda tmp
eor #$ff
sta br_y
lsr tmp
lsr tmp
lsr tmp
lsr tmp
lsr tmp
lsr tmp
// tmp = 1 during fadein, 0-3 during wave
lda #FADEOUT_TIME * 8 - 8
ldx music_lo
cpx #FADEOUT_TIME
bcc no_fadeout
ldx #FADEOUT_TIME-1
no_fadeout:
txa
// clc
sbc #$04
asl
asl
asl
ora tmp
sta tex_x+0
lda #$00
ror
ror
ror
sta texture_extra_bit
jmp anim_done
// --------------------------------------------------------------------
// Animation 1
// --------------------------------------------------------------------
anim_one_or_two:
dex
bne anim_two
anim_one:
// music timer = $0400
sta slope_x
sta slope_y
lda music_lo
asl
asl
tay
lda sin_table, y
lsr
lsr
lsr
clc
adc #$58
sta br_x
sta br_y
jmp shift_slope_and_add_to_tex
// --------------------------------------------------------------------
// Animation 2
// --------------------------------------------------------------------
anim_two:
// music timer = $0800
ldx music_hi
cpx #$09
bcc look_up_sin
cpx #$0b
bne not_b
lda music_lo
cmp #$f8
bcs nofadeout
not_b:
cpx #$0c
bcc noplasma
beq plasma
ldx music_lo
cpx #$30
bcc incplasma
bpl to_anim_done
sta zp_d011
to_anim_done:
jmp anim_done
plasma:
ldx music_lo
cpx #$c0
bcc nofadeout
.if (FADEOUT) {
sta CHARSET+$0000, x
sta CHARSET+$0100, x
sta CHARSET+$0200, x
sta CHARSET+$0300, x
sta CHARSET+$0400, x
sta CHARSET+$0500, x
sta CHARSET+$0600, x
sta CHARSET+$0700, x
}
nofadeout:
lda #$fe
cpx #$a0
bcc !+
incplasma:
lda #$ff
!:
sta.zp adelta
anc #$80
always_bne add_to_angle
noplasma:
lda angle_256_hi
bpl !+
eor #$ff
!: asl
clc
adc #$20
bcc add_to_angle
lda #$ff
add_to_angle:
adc angle_256_lo
sta angle_256_lo
lda angle_256_hi
adc.zp adelta
sta angle_256_hi
look_up_sin:
ldx angle_256_hi
ldy #$00
lda sin_table, x
eor #$80
sta br_x
bpl !+
ldy #$ff
!:
sty slope_x
ldy #$00
lda sin_table+64, x
eor #$80
sta br_y
bpl !+
ldy #$ff
!:
sty slope_y
shift_slope_and_add_to_tex:
lda slope_x
asl br_x
rol
asl br_x
rol
asl br_x
rol
asl br_x
rol
sta slope_x
lda slope_y
asl br_y
rol
asl br_y
rol
asl br_y
rol
asl br_y
rol
sta slope_y
lda tex_y_lo
sec
sbc br_x
sta tex_y_lo
lda tex_y+0
sbc slope_x
sta tex_y+0
lda tex_x_lo
clc
adc br_y
sta tex_x_lo
lda tex_x+0
adc slope_y
sta tex_x+0
anim_done:
// --------------------------------------------------------------------
// Compute the locations we'll patch in the coloring code.
// --------------------------------------------------------------------
compute_locations:
lda pos_in_colorize_lo
ldx pos_in_colorize_hi
clc
adc #SIZE_OF_ONE_COLOR_BLOCK
sta pos_in_colorize_lo
bcc !+
ldy inc_block_hi, x
ldx identity, y // only uses first 64 bytes
clc
!:
stx pos_in_colorize_hi
x_loop:
.for (var i = 0; i < HEIGHT / 2; i++) {
entry:
sta block_lo+i*4+0
stx block_hi+i*4+0
adc #SIZE_OF_ONE_COLOR_BLOCK * 40 // 600 ($258)
bcc !+
ldy add40_sec, x
clc
always_bcc store_y
!:
ldy add40_clc, x
store_y:
sta block_lo+i*4+2
sty block_hi+i*4+2
.if (i < HEIGHT / 2 - 1) {
adc #SIZE_OF_ONE_COLOR_BLOCK * 40
bcc !+
ldx add40_sec, y
clc
always_bcc tail
!:
ldx add40_clc, y
}
tail:
}
// --------------------------------------------------------------------
// Interpolate positions in texture.
// --------------------------------------------------------------------
ldy br_x
lda tex_x+0
br_x_loop:
.for (var i = 0; i < HEIGHT - 1; i++) {
entry:
cpy #$00 // bitreverse(i+BITADD) (filled in during init)
adc slope_x
sta tex_x+i+1
.errorif (*) - entry != SIZE_OF_ONE_INTERPOLATE_BLOCK, "size error"
}
ldy br_y
lda tex_y+0
br_y_loop:
.for (var i = 0; i < HEIGHT - 1; i++) {
entry:
cpy #$00 // bitreverse(i+BITADD) (filled in during init)
adc slope_y
sta tex_y+i+1
.errorif (*) - entry != SIZE_OF_ONE_INTERPOLATE_BLOCK, "size error"
}
// --------------------------------------------------------------------
// Compute angle
// --------------------------------------------------------------------
anc #$00
sta angle_bits_hi
lda angle_256_hi
and #$f0
eor #$ff
adc #$01
asl
rol angle_bits_hi
asl
rol angle_bits_hi
ora #$3f
tax // angle_bits_lo
ldy angle_bits_hi
lda xc0_table, y
sta xc0_ptr+1
lda xc1_table, y
sta xc1_ptr+1
lda xc2_table, y
sta xc2_ptr+1
lda yc0_table, y
sta yc0_ptr+1
lda yc1_table, y
sta yc1_ptr+1
lda yc2_table, y
sta yc2_ptr+1
tya
asl
clc
adc #<char_compute_hi
sta jmp0
// --------------------------------------------------------------------
// Compute the chars
// --------------------------------------------------------------------
// x = angle_bits_lo
jmp jmp0:(char_compute_hi)
char_compute_hi:
.word compute_chars[0].loop
.word compute_chars[1].loop
.word compute_chars[2].loop
.word compute_chars[3].loop
.errorif (>*) != >char_compute_hi, "page break in jump table"
compute_chars:
.for (var anglehi = 0; anglehi < 4; anglehi++) {
.var x_table
.var y_table
.if (anglehi == 0) {
.eval x_table = tex_x_to_char_bits
.eval y_table = tex_y_to_char_bits
}
.if (anglehi == 1) {
.eval x_table = tex_y_to_char_bits_inverted
.eval y_table = tex_x_to_char_bits
}
.if (anglehi == 2) {
.eval x_table = tex_x_to_char_bits_inverted
.eval y_table = tex_y_to_char_bits_inverted
}
.if (anglehi == 3) {
.eval x_table = tex_y_to_char_bits
.eval y_table = tex_x_to_char_bits_inverted
}
loop:
.for (var i = 0; i < HEIGHT; i++) {
entry:
// 22 cycles
ldy tex_x+i
lda texture_lo, y
ora texture_extra_bit
sta tex_lo+i
// TODO: make the above into a separate loop, and x_table and y_table into ptrs?
lda x_table, y
ldy tex_y+i
ora y_table, y
sax chars+i // and with angle
lda texture_hi_nibble, y
sta.zp hi_nibble_0+i
}
jmp continue
}
continue:
// --------------------------------------------------------------------
// Add color lookup to positions
// --------------------------------------------------------------------
.const COL1 = colorize_template[0].col1 - colorize_template[0].entry
.const COL2 = colorize_template[0].col2 - colorize_template[0].entry
.const COL3 = colorize_template[0].col3 - colorize_template[0].entry
clc
.for (var i = 0; i < HEIGHT; i++) {
entry:
// col 0 x
ldy chars+i
lax (yc0_ptr), y
lda (xc0_ptr), y
adc tex_lo+i
ldy #COL1+0
sta (block_lo+i*2), y
// col 0 y
txa
adc hi_nibble_0+i
ldy #COL1+1
sta (block_lo+i*2), y
// col 1 x
ldy chars+i
lax (yc1_ptr), y
lda (xc1_ptr), y
adc tex_lo+i
ldy #COL2+0
sta (block_lo+i*2), y
// col 1 y
txa
adc hi_nibble_0+i
iny
sta (block_lo+i*2), y
// col 2 x
ldy chars+i
lax (yc2_ptr), y
lda (xc2_ptr), y
adc tex_lo+i
ldy #COL3+0
sta (block_lo+i*2), y
// col 2 y
txa
adc hi_nibble_0+i
iny
sta (block_lo+i*2), y
}
// --------------------------------------------------------------------
// Colorize the bitmap
// --------------------------------------------------------------------
colorize:
clc
lda jsr0+0
adc #SIZE_OF_ONE_COLOR_BLOCK
sta jsr0+0
bcc !+
lda #>COLORIZE_LOOP_END
// sec
isc jsr0+1
bne to_clc
lda #>COLORIZE_LOOP_START
sta jsr0+1
to_clc:
clc
!:
ldy #$00
lda #LDA_ABSX
sta (colorize_rts), y
lda colorize_rts+0
// clc
adc #SIZE_OF_ONE_COLOR_BLOCK
sta colorize_rts+0
bcc !+
lda #>COLORIZE_LOOP_END
// sec
isc colorize_rts+1
bne !+
lda #>COLORIZE_LOOP_START
sta colorize_rts+1
!:
lda #RTS
sta (colorize_rts), y
ldx texture_x_shift
jsr zp_jmp0
dex_colors:
dex
lda #$3f
ldy activation
beq !+
lsr
!:
sax texture_x_shift
// --------------------------------------------------------------------
// Color one char black
// --------------------------------------------------------------------
black:
lax #$00
sta (black_dest1, x)
sta (black_dest2, x)
inc black_dest1+0
inc black_dest2+0
bne !+
inc black_dest1+1
lda #>($d800+$0400)
sec
isc black_dest2+1
bne !+
lda #>COLRAM
sta black_dest1+1
lda #>($d800)
sta black_dest2+1
!:
// --------------------------------------------------------------------
// Rewrite the bitmap data of the rightmost row.
// --------------------------------------------------------------------
write_bitmap:
lda xadd
clc
adc #8
cmp #24*8 // triggers on first frame
bne no_row_change
ldy row
lda xadd_for_row, y
pha
lax next_row, y
sta row
eor #$ff
sta offset
lda write_bitmap_lo, x
sta jsr1+0
lda write_bitmap_hi, x
sta jsr1+1
lda write_bitmap_lo+HEIGHT, x
sta write_bitmap_rts+0
lda write_bitmap_hi+HEIGHT, x
sta write_bitmap_rts+1
pla
no_row_change:
sta xadd
ldy #$00
lda #RTS
sta (write_bitmap_rts), y
//PRINT("{row} {xadd}")
ldy xadd
jsr jsr1:$ffff
ldy #$00
lda #LDX_ZP
sta (write_bitmap_rts), y
irq_end:
asl $d019
lda save_a
ldx save_x
ldy save_y
rti
write_bitmap_loop:
.for (var i = 0; i < BITMAP_SPEEDCODE_LENGTH; i++) {
entry:
ldx.zp offset
lda.zp (chars+i+1)&$ff, x
tax
.var pos = (i * $140) & $1fff
.if (pos == $1fc0) {
.errorif i != 51, "internal error"
// Use the fact that y is always >= 64 for rows >=26+25.
.eval pos = $1fc0-$2000
}
.eval pos += BITMAP
.eval pos = 0 // we fill this in during init
lda chardata0, x
.label dest0 = * + 1
sta.abs $0000, y
lda chardata1, x
.label dest1 = * + 1
sta.abs $0000, y
lda chardata2, x
.label dest2 = * + 1
sta.abs $0000, y
lda chardata3, x
.label dest3 = * + 1
sta.abs $0000, y
lda chardata4, x
.label dest4 = * + 1
sta.abs $0000, y
lda chardata5, x
.label dest5 = * + 1
sta.abs $0000, y
lda chardata6, x
.label dest6 = * + 1
sta.abs $0000, y
lda chardata7, x
.label dest7 = * + 1
sta.abs $0000, y
.errorif (*) - entry != SIZE_OF_ONE_BITMAP_WRITE_BLOCK, "size error"
}
rts
// --------------------------------------------------------------------
// Tables
// --------------------------------------------------------------------
.segment Tables
roto_zp:
.segmentout [segments="RotoZeroPage"]
xc0_table: .byte >col0_x_80
.byte >col0_iy_80
.byte >col0_ix_80
.byte >col0_y_80
xc1_table: .byte >col1_x_00
.byte >col1_iy_00
.byte >col1_ix_00
.byte >col1_y_00
xc2_table: .byte >col2_x_00
.byte >col2_iy_00
.byte >col2_ix_00
.byte >col2_y_00
yc0_table: .byte >col0_y_00
.byte >col0_x_00
.byte >col0_iy_00
.byte >col0_ix_00
yc1_table: .byte >col1_y_00
.byte >col1_x_00
.byte >col1_iy_00
.byte >col1_ix_00
yc2_table: .byte >col2_y_00
.byte >col2_x_00
.byte >col2_iy_00
.byte >col2_ix_00
.function NEXT_ROW(row) {
.var up = row < 26
.var down = row >= 26
.if (up) {
.if (row == 25) {
.return 0
} else {
.return row + 26 // 0 -> 1040 (= 16 mod 1024)
}
} else {
.return row - 25 // 1040 -> 40
}
}
next_row:
.fill 26+26, NEXT_ROW(i)
xadd_for_row:
.fill 26+26, (i < 26 && i != 25) ? 8*8 : 0*8
bitreverse_lookup:
//.fill HEIGHT, bitreverse(i+BITADD)
.fill HEIGHT-1, bitreverse(HEIGHT-1-1-i)+BITADD