-
Notifications
You must be signed in to change notification settings - Fork 10
/
screen.s
1208 lines (1161 loc) · 39.5 KB
/
screen.s
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
SCROLLSPLIT = 11
SCRCENTER_X = 19
SCRCENTER_Y = SCROLLROWS-9
CI_GROUND = 1 ;Char info bits
CI_OBSTACLE = 2
CI_CLIMB = 4
CI_WATER = 8
CI_SHELF = 16
CI_NOPATH = 16
CI_NOSPAWN = 32
CI_SLOPE1 = 32
CI_SLOPE2 = 64
CI_SLOPE3 = 128
GAMESCR1_D018 = $da
GAMESCR2_D018 = $ca
TEXTSCR_D018 = $d8
PANEL_D018 = $88
PANELROW = 22
; Perform scrolling logic
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y
ScrollLogic: inc scrollWorkFlag ;ScrollWork will be needed
lda scrAdd ;If speed is zero, look out
beq SL_GetNewSpeed ;for a new speed-setting
clc
adc scrCounter ;Update workcounter
sta scrCounter
tax
lda scrollX ;Update finescroll-counters
adc scrollCSX ;(let them wrap)
and #$07
sta scrollX
lda scrollY
clc
adc scrollCSY
and #$07
sta scrollY ;Then check workcounter
cpx #$08 ;If it's >7 then this scrolling
bcs SL_GetNewSpeed ;is ready
cpx #$04
bne SL_CalcSprSub2
SL_SwapScreen: lda screen
eor #$01
sta screen
SL_NewMapPos: lda blockX
sta SL_CSSBlockX+1
lda blockY
sta SL_CSSBlockY+1
lda mapX
sta SL_CSSMapX+1
lda mapY
sta SL_CSSMapY+1
SL_CalcSprSub2: jmp SL_CalcSprSub
SL_GetNewSpeed: lda #$00 ;Reset the workcounter
sta scrCounter
ldx #$04 ;Reset shift direction (center)
lda scrollSX ;Get the requested speed
sta scrollCSX
beq SL_XDone
bmi SL_XNeg
SL_XPos: lda mapX ;Are we on the edge of map?
clc ;(right)
adc #$0a
cmp limitR
bcc SL_XPosOk
lda blockX
cmp #$01
bcs SL_XZero
SL_XPosOk: lda blockX ;Update block & map-coords
adc #$01
cmp #$04
and #$03
sta blockX
bcc SL_XPosOk2
inc mapX
SL_XPosOk2: lda #$04
sta scrollX
inx
bpl SL_XDone
SL_XNeg: lda blockX ;Are we on the edge of map?
bne SL_XNegOk ;(left)
lda mapX
cmp limitL
beq SL_XZero
SL_XNegOk: lda #$03
dec blockX ;Update block & map-coords
bpl SL_XNegOk2
sta blockX
dec mapX
SL_XNegOk2: sta scrollX
dex
bpl SL_XDone
SL_XZero: lda #$00
sta scrollCSX
SL_XDone: stx SW_ColorShiftDir+1
lda scrollSY
sta scrollCSY
beq SL_YDone
bmi SL_YNeg
SL_YPos: lda mapY ;Are we on the edge of map?
clc ;(bottom)
adc #$06
cmp limitD
bcc SL_YPosOk
lda blockY
cmp #$02
bcs SL_YZero
SL_YPosOk: lda blockY ;Update block & map-coords
adc #$01
cmp #$04
and #$03
sta blockY
bcc SL_YPosOk2
inc mapY
SL_YPosOk2: lda #$04
sta scrollY
inx
inx
inx
bpl SL_YDone
SL_YNeg: lda mapY ;Are we on the edge of map?
cmp limitU ;(top)
bcc SL_YZero
bne SL_YNegOk
lda blockY
beq SL_YZero
SL_YNegOk: lda #$03
dec blockY ;Update block & map-coords
bpl SL_YNegOk2
sta blockY
dec mapY
SL_YNegOk2: sta scrollY
dex
dex
dex
bpl SL_YDone
SL_YZero: lda #$00
sta scrollCSY
SL_YDone: stx SW_ShiftDir+1
ldy screen ;Update scrollwork jumps now
lda screenBaseTbl,y
eor #$04
sta SW_DrawColorsUpLoop+2
sta SW_DrawColorsUpLdx2+2
sta SW_DrawColorsUpLdx3+2
clc
adc #$01
sta SW_DrawColorsRLoop+2
sta SW_DrawColorsRLdx2+2
sta SW_DrawColorsRLdx3+2
adc #$02
sta SW_DrawColorsDownLoop+2
sta SW_DrawColorsDownLdx2+2
sta SW_DrawColorsDownLdx3+2
lda screenJumpTblLo,y
sta SW_ScreenJump+1
lda screenJumpTblHi,y
sta SW_ScreenJump+2
lda colorJumpTblLo,x
sta SW_ColorJump+1
lda colorJumpTblHi,x
sta SW_ColorJump+2
SL_DetermineSpeed:
lda scrollCSX ;Get absolute X-speed
bpl SL_XPos2
eor #$ff ;C=0 here
adc #$01
SL_XPos2: tax
sta scrAdd
lda scrollCSY ;Then absolute Y-speed
bpl SL_YPos2
clc
eor #$ff
adc #$01
SL_YPos2: tay
cmp scrAdd ;Use the higher speed
bcc SL_ScrAddYNotHigher
sta scrAdd
SL_ScrAddYNotHigher:
lda scrAdd
cmp #$02 ;If speed 2, then must use that on both axes
bcc SL_ScrAddOk
cpx #$01
bne SL_XSpeedOk
asl scrollCSX
SL_XSpeedOk: cpy #$01
bne SL_ScrAddOk
asl scrollCSY
SL_ScrAddOk:
SL_CalcSprSub: lda scrollY
clc
adc shakeScreen
cmp #$08
bcc SL_ShakeNotOver
lda #$07
SL_ShakeNotOver:sta SL_CSSScrollY+1
SL_CSSBlockX: lda #$00
asl
asl
asl
ora scrollX
asl
asl
asl
sec
sbc #<(31*8)
sta DA_SprSubXL+1
SL_CSSMapX: lda #$00
sbc #(>(31*8))+1
sta DA_SprSubXH+1
SL_CSSBlockY: lda #$00
asl
asl
asl
SL_CSSScrollY: ora #$00
asl
asl
asl
sec
sbc #<(54*8)
sta DA_SprSubYL+1
SL_CSSMapY: lda #$00
sbc #(>(54*8))
sta DA_SprSubYH+1
WF_Done: rts
; Re-enable raster interrupts, wait for new frame indicator and perform scrollwork
;
; Parameters: A Bit pattern to wait to clear
; Returns: -
; Modifies: A,X,Y,temp1-temp5,temp8
WaitFrame: sta temp8
lda #$01 ;If raster interrupts would not be enabled, the program
sta $d01a ;would wait forever
WF_Loop: lda newFrame
and temp8
beq WF_Done
lda scrCounter ;Can not perform scrollwork early if colorshift
cmp #$04
beq WF_Loop
jsr ScrollWork
jmp WF_Loop
; Sort sprites, set new frame to be displayed and perform scrollwork
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp1-temp8
if sprOrder < MAX_SPR+1 ;Ensure that a zeropage addressing trick works
err
endif
UpdateFrame: if SHOW_SPRITESORT_TIME > 0
lda #$0a
sta $d020
endif
lda firstSortSpr ;Switch sprite doublebuffer side
eor #MAX_SPR
sta firstSortSpr
ldx #$00
stx temp6 ;D010 bits for first IRQ
txa
SSpr_Loop1: ldy sprOrder,x ;Check for coordinates being in order
cmp sprY,y
beq SSpr_NoSwap2
bcc SSpr_NoSwap1
stx temp1 ;If not in order, begin insertion loop
sty temp2
lda sprY,y
ldy sprOrder-1,x
sty sprOrder,x
dex
beq SSpr_SwapDone1
SSpr_Swap1: ldy sprOrder-1,x
sty sprOrder,x
cmp sprY,y
bcs SSpr_SwapDone1
dex
bne SSpr_Swap1
SSpr_SwapDone1: ldy temp2
sty sprOrder,x
ldx temp1
ldy sprOrder,x
SSpr_NoSwap1: lda sprY,y
SSpr_NoSwap2: inx
cpx #MAX_SPR
bne SSpr_Loop1
if SHOW_SPRITESORT_TIME > 0
lda #$00
sta $d020
endif
lda #$80 ;Wait until last set sprites have displayed
sta PSfx_LastSfx+1 ;Reset last sound played
jsr WaitFrame ;and the second doublebuffer half is free
lda #<sprOrder
sec
sbc firstSortSpr
sta SSpr_CopyLoop1+1
ldy firstSortSpr
tya
adc #8-1 ;C=1
sta SSpr_CopyLoop1End+1 ;Set endpoint for first copyloop
bpl SSpr_CopyLoop1
SSpr_CopyLoop1Skip:
inc SSpr_CopyLoop1+1
SSpr_CopyLoop1: ldx sprOrder,y
lda sprY,x ;If reach the maximum Y-coord endmark, all done
cmp #MAX_SPRY
bcs SSpr_CopyLoop1Done
sta sortSprY,y
lda sprC,x ;Check invisibility / flicker
bmi SSpr_CopyLoop1Skip
sta sortSprC,y
lda sprF,x
sta sortSprF,y
lda sprXL,x
sta sortSprX,y
lda sprXH,x
beq SSpr_CopyLoop1MsbLow
lda temp6
ora sprOrTbl,y
sta temp6
SSpr_CopyLoop1MsbLow:
iny
SSpr_CopyLoop1End:
cpy #$00
bcc SSpr_CopyLoop1
lda temp6
sta sortSprD010-1,y
lda sortSprC-1,y ;Make first IRQ endmark
ora #$80
sta sortSprC-1,y
lda SSpr_CopyLoop1+1 ;Copy sortindex from first copyloop
sta SSpr_CopyLoop2+1 ;to second
bcs SSpr_CopyLoop2
SSpr_CopyLoop1Done:
lda temp6
sta sortSprD010-1,y
sty temp7 ;Store sorted sprite end index
cpy firstSortSpr ;Any sprites at all?
bne SSpr_EndMark ;Make first (and final) IRQ endmask
SSpr_NoSprites: jmp SSpr_AllDone
SSpr_CopyLoop2Skip:
inc SSpr_CopyLoop2+1
SSpr_CopyLoop2: ldx sprOrder,y
lda sprY,x
cmp #MAX_SPRY
bcs SSpr_CopyLoop2Done
sta sortSprY,y
sbc #21-1
cmp sortSprY-8,y ;Check for physical sprite overlap
bcc SSpr_CopyLoop2Skip
lda sprC,x ;Check invisibility / flicker
bmi SSpr_CopyLoop2Skip
sta sortSprC,y
lda sprF,x
sta sortSprF,y
lda sprXL,x
sta sortSprX,y
lda sprXH,x
beq SSpr_CopyLoop2MsbLow
lda sortSprD010-1,y
ora sprOrTbl,y
bne SSpr_CopyLoop2MsbDone
SSpr_CopyLoop2MsbLow:
lda sortSprD010-1,y
and sprAndTbl,y
SSpr_CopyLoop2MsbDone:
sta sortSprD010,y
iny
bne SSpr_CopyLoop2
SSpr_CopyLoop2Done:
sty temp7 ;Store sorted sprite end index
ldy SSpr_CopyLoop1End+1 ;Go back to the second IRQ start
cpy temp7
beq SSpr_FinalEndMark
SSpr_IrqLoop: sty temp2 ;Store IRQ startindex
lda sortSprY,y ;C=0 here
sbc #21+12-1 ;First sprite of IRQ: store the Y-coord
sta SSpr_IrqYCmp1+1 ;compare values
adc #21+12+6-1
sta SSpr_IrqYCmp2+1
SSpr_IrqSprLoop:iny
cpy temp7
bcs SSpr_IrqDone
lda sortSprY-8,y ;Add next sprite to this IRQ?
SSpr_IrqYCmp1: cmp #$00 ;(try to add as many as possible while
bcc SSpr_IrqSprLoop ;avoiding glitches)
lda sortSprY,y
SSpr_IrqYCmp2: cmp #$00
bcc SSpr_IrqSprLoop
SSpr_IrqDone: tya
sbc temp2
tax
lda sprIrqAdvanceTbl-1,x
ldx temp2
adc sortSprY,x
sta sprIrqLine-1,x ;Store IRQ start line (with advance)
SSpr_EndMark: lda sortSprC-1,y ;Make IRQ endmark
ora #$80
sta sortSprC-1,y
cpy temp7 ;Sprites left?
bcc SSpr_IrqLoop
SSpr_FinalEndMark:
lda #$00 ;Make final endmark
sta sprIrqLine-1,y
SSpr_AllDone: lda #$ff ;Wait for previous frameupdate to finish
jsr WaitFrame
lda scrCounter ;Is it the colorshift? (needs special timing)
cmp #$04
beq UF_WaitColorShift
UF_WaitNormal: lda $d011 ;If no colorshift, just need to make sure we
bmi UF_WaitDone ;are not late from the frameupdate
lda $d012
cmp #IRQ1_LINE+$02
bcs UF_WaitDone
cmp #IRQ1_LINE-$05
bcs UF_WaitNormal
UF_WaitColorShift:
lda $d011
bmi UF_WaitColorShift
lda $d012 ;Wait until we are near the scorescreen split
cmp #IRQ3_LINE-SCROLLSPLIT*8+14
bcc UF_WaitColorShift
UF_ColorShiftLateCheck:
cmp #IRQ3_LINE+$18
bcs UF_WaitColorShift
UF_WaitDone: lda scrollX ;Copy scrolling and screen number
eor #$17
sta Irq1_ScrollX+1
lda SL_CSSScrollY+1
eor #$17
sta Irq1_ScrollY+1
ldx screen
lda d018Tbl,x
sta Irq1_Screen+1
cpx #$02 ;If textscreen or split mode, do not show sprites
bcc UF_ShowSprites
lda #$00
beq UF_NoSprites2
UF_ShowSprites: lda screenFrameTbl,x
sta Irq1_ScreenFrame+1
lda temp7 ;Check which sprites are on
tay
sec
sbc firstSortSpr
cmp #$09
bcc UF_NotMoreThan8
lda #$08
UF_NotMoreThan8:tax
lda d015Tbl,x
UF_NoSprites2: sta Irq1_D015+1
beq UF_NoSprites
ldx firstSortSpr ;Find out sprite Y-range for the fastloader
stx Irq1_FirstSortSpr+1
lda sortSprY,x ;(where to avoid the timed data transfer)
sec
sbc #$04
sta Irq1_MinSprY+1
lda sortSprY-1,y
adc #22
UF_NoSprites: sta Irq1_MaxSprY+1
dec newFrame ;$ff = process new frame
; Shift the screen memory, draw new blocks or shift colors according to the
; scrolling progress (scrCounter)
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp1-temp5
ScrollWork: lda scrollWorkFlag ;Already called this frame?
beq SW_NoWork
dec scrollWorkFlag
if SHOW_SCROLLWORK_TIME > 0
lda #$03
sta $d020
jsr SW_Decision
lda #$00
sta $d020
rts
endif
SW_Decision: lda scrCounter
beq SW_ShiftScreen
cmp #$04
beq SW_ShiftColors
cmp #$02
beq SW_DrawBlocks
SW_NoWork: rts
SW_ShiftScreen: lda scrAdd ;When not scrolling, scrCounter remains at 0
beq SW_NoWork ;so check speed to not shift unnecessarily
SW_ShiftDir: ldx #$04
ldy shiftSrcTbl,x
lda shiftOffsetTbl,x
clc
SW_ScreenJump: jmp SW_NoWork
SW_ShiftColors:
SW_ColorShiftDir:
ldx #$00
stx temp1
SW_ColorJump: jmp SW_NoWork
SW_DrawBlocks: lda scrollCSX
beq SW_DBXDone
bmi SW_DBLeft
SW_DBRight: jsr SW_DrawRight
beq SW_DBXDone ;Z=1 always here
SW_DBLeft: jsr SW_DrawLeft
SW_DBXDone: lda scrollCSY
beq SW_NoWork
bmi SW_DBUp
SW_DBDown: jmp SW_DrawDown
SW_DBUp: jmp SW_DrawUp
; Screen shifting routines
SW_Shift1: adc #<SW_Shift1Loop
sta SW_Shift1Jump+1
if (SW_Shift1Loop & $ff) > $f9
lda #>SW_Shift1Loop
adc #$00
sta SW_Shift1Jump+2
endif
lda shiftEndTbl,x
sta SW_Shift1EndCmp+1
lda shiftDestTbl,x
tax
jmp SW_Shift1Jump
SW_Shift1Loop: ;Screen shift routine:
N set 0 ;From screen1 to screen2
repeat SCROLLROWS
lda screen1-40+N*40,y
sta screen2-40+N*40,x
N set N+1
repend
iny
inx
SW_Shift1EndCmp:cpx #$00
bcs SW_Shift1Done
SW_Shift1Jump: jmp SW_Shift1Loop
SW_Shift1Done: rts
SW_Shift2: adc #<SW_Shift2Loop
sta SW_Shift2Jump+1
if (SW_Shift2Loop & $ff) > $f9
lda #>SW_Shift2Loop
adc #$00
sta SW_Shift2Jump+2
endif
lda shiftEndTbl,x
sta SW_Shift2EndCmp+1
lda shiftDestTbl,x
tax
jmp SW_Shift2Jump
SW_Shift2Loop: ;Screen shift routine:
N set 0 ;From screen 2to screen1
repeat SCROLLROWS
lda screen2-40+N*40,y
sta screen1-40+N*40,x
N set N+1
repend
iny
inx
SW_Shift2EndCmp:cpx #$00
bcs SW_Shift2Done
SW_Shift2Jump: jmp SW_Shift2Loop
SW_Shift2Done: rts
; Color shifting routines
SW_ShiftColorsUp:
lda colorYTbl-3,x
sta SW_ShiftColorsUpTopIny
sta SW_ShiftColorsUpBottomIny
lda colorXTbl-3,x
sta SW_ShiftColorsUpTopInx
sta SW_ShiftColorsUpBottomInx
lda colorEndTbl-3,x
sta SW_ShiftColorsUpTopCpx+1
sta SW_ShiftColorsUpBottomCpx+1
ldy colorDestTbl-3,x
lda colorSrcTbl-3,x
tax
SW_ShiftColorsUpTopLoop:
N set SCROLLSPLIT-1
repeat SCROLLSPLIT
lda colors+N*40,x
sta colors+40+N*40,y
N set N-1
repend
SW_ShiftColorsUpTopIny:
iny
SW_ShiftColorsUpTopInx:
inx
SW_ShiftColorsUpTopCpx:
cpx #$00
bne SW_ShiftColorsUpTopLoop
jsr SW_DrawColorsUp
ldx temp1
ldy colorSideTbl-3,x
jsr SW_DrawColorsHorizTop
ldx temp1
ldy colorDestTbl-3,x
lda colorSrcTbl-3,x
tax
SW_ShiftColorsUpBottomLoop:
N set SCROLLROWS-2
repeat SCROLLROWS-SCROLLSPLIT-2
lda colors+N*40,x
sta colors+40+N*40,y
N set N-1
repend
SW_ShiftColorsUpBottomIny:
iny
SW_ShiftColorsUpBottomInx:
inx
SW_ShiftColorsUpBottomCpx:
cpx #$00
bne SW_ShiftColorsUpBottomLoop
ldy #12 ;Reconstruct the colors that are lost at
SW_DrawColorsRLoop: ;the scroll split
ldx screen1+SCROLLSPLIT*40+40,y
lda charColors,x
sta colors+SCROLLSPLIT*40+40,y
SW_DrawColorsRLdx2:
ldx screen1+SCROLLSPLIT*40+40+13,y
lda charColors,x
sta colors+SCROLLSPLIT*40+40+13,y
SW_DrawColorsRLdx3:
ldx screen1+SCROLLSPLIT*40+40+26,y
lda charColors,x
sta colors+SCROLLSPLIT*40+40+26,y
dey
bpl SW_DrawColorsRLoop
ldx temp1
ldy colorSideTbl-3,x
SW_DrawColorsHorizBottom:
bmi SW_DCHB_Skip
clc
lda screen
bne SW_DCHB2
SW_DCHB1: ldx screen1+SCROLLSPLIT*40,y
lda charColors,x
sta colors+SCROLLSPLIT*40,y
SW_DCHB1_Loop: ldx screen1+SCROLLSPLIT*40+40,y
lda charColors,x
sta colors+SCROLLSPLIT*40+40,y
ldx screen1+SCROLLSPLIT*40+6*40,y
lda charColors,x
sta colors+SCROLLSPLIT*40+6*40,y
tya
adc #40
tay
cpy #5*40
bcc SW_DCHB1_Loop
SW_DCHB_Skip: rts
SW_DCHB2: ldx screen2+SCROLLSPLIT*40,y
lda charColors,x
sta colors+SCROLLSPLIT*40,y
SW_DCHB2_Loop: ldx screen2+SCROLLSPLIT*40+40,y
lda charColors,x
sta colors+SCROLLSPLIT*40+40,y
ldx screen2+SCROLLSPLIT*40+6*40,y
lda charColors,x
sta colors+SCROLLSPLIT*40+6*40,y
tya
adc #40
tay
cpy #5*40
bcc SW_DCHB2_Loop
rts
SW_ShiftColorsHoriz:
lda colorYTbl-3,x
sta SW_ShiftColorsHorizTopIny
sta SW_ShiftColorsHorizBottomIny
lda colorXTbl-3,x
sta SW_ShiftColorsHorizTopInx
sta SW_ShiftColorsHorizBottomInx
lda colorEndTbl-3,x
sta SW_ShiftColorsHorizTopCpx+1
sta SW_ShiftColorsHorizBottomCpx+1
ldy colorDestTbl-3,x
lda colorSrcTbl-3,x
tax
SW_ShiftColorsHorizTopLoop:
N set 0
repeat SCROLLSPLIT
lda colors+N*40,x
sta colors+N*40,y
N set N+1
repend
SW_ShiftColorsHorizTopIny:
iny
SW_ShiftColorsHorizTopInx:
inx
SW_ShiftColorsHorizTopCpx:
cpx #$00
bne SW_ShiftColorsHorizTopLoop
ldx temp1
ldy colorSideTbl-3,x
jsr SW_DrawColorsHorizTop
ldx temp1
ldy colorDestTbl-3,x
lda colorSrcTbl-3,x
tax
SW_ShiftColorsHorizBottomLoop:
N set SCROLLSPLIT
repeat SCROLLROWS-SCROLLSPLIT
lda colors+N*40,x
sta colors+N*40,y
N set N+1
repend
SW_ShiftColorsHorizBottomIny:
iny
SW_ShiftColorsHorizBottomInx:
inx
SW_ShiftColorsHorizBottomCpx:
cpx #$00
bne SW_ShiftColorsHorizBottomLoop
ldx temp1
ldy colorSideTbl-3,x
jmp SW_DrawColorsHorizBottom
SW_ShiftColorsDown:
lda colorYTbl-3,x
sta SW_ShiftColorsDownTopIny
sta SW_ShiftColorsDownBottomIny
lda colorXTbl-3,x
sta SW_ShiftColorsDownTopInx
sta SW_ShiftColorsDownBottomInx
lda colorEndTbl-3,x
sta SW_ShiftColorsDownTopCpx+1
sta SW_ShiftColorsDownBottomCpx+1
ldy colorDestTbl-3,x
lda colorSrcTbl-3,x
tax
SW_ShiftColorsDownTopLoop:
N set 0
repeat SCROLLSPLIT
lda colors+40+N*40,x
sta colors+N*40,y
N set N+1
repend
SW_ShiftColorsDownTopIny:
iny
SW_ShiftColorsDownTopInx:
inx
SW_ShiftColorsDownTopCpx:
cpx #$00
bne SW_ShiftColorsDownTopLoop
ldx temp1
ldy colorSideTbl-3,x
jsr SW_DrawColorsHorizTop
ldx temp1
ldy colorDestTbl-3,x
lda colorSrcTbl-3,x
tax
SW_ShiftColorsDownBottomLoop:
N set SCROLLSPLIT
repeat SCROLLROWS-SCROLLSPLIT-1
lda colors+40+N*40,x
sta colors+N*40,y
N set N+1
repend
SW_ShiftColorsDownBottomIny:
iny
SW_ShiftColorsDownBottomInx:
inx
SW_ShiftColorsDownBottomCpx:
cpx #$00
bne SW_ShiftColorsDownBottomLoop
ldx temp1
ldy colorSideTbl-3,x
jsr SW_DrawColorsHorizBottom
jmp SW_DrawColorsDown
SW_DrawColorsHorizTop:
bmi SW_DCHT_Skip
clc
lda screen
bne SW_DCHT2
SW_DCHT1: ldx screen1,y
lda charColors,x
sta colors,y
SW_DCHT1_Loop: ldx screen1+40,y
lda charColors,x
sta colors+40,y
ldx screen1+6*40,y
lda charColors,x
sta colors+6*40,y
tya
adc #40
tay
cpy #5*40
bcc SW_DCHT1_Loop
SW_DCHT_Skip: rts
SW_DCHT2: ldx screen2,y
lda charColors,x
sta colors,y
SW_DCHT2_Loop: ldx screen2+40,y
lda charColors,x
sta colors+40,y
ldx screen2+6*40,y
lda charColors,x
sta colors+6*40,y
tya
adc #40
tay
cpy #5*40
bcc SW_DCHT2_Loop
rts
SW_DrawColorsUp:ldy #12
SW_DrawColorsUpLoop:
ldx screen1,y
lda charColors,x
sta colors,y
SW_DrawColorsUpLdx2:
ldx screen1+13,y
lda charColors,x
sta colors+13,y
SW_DrawColorsUpLdx3:
ldx screen1+26,y
lda charColors,x
sta colors+26,y
dey
bpl SW_DrawColorsUpLoop
rts
SW_DrawColorsDown:
ldy #12
SW_DrawColorsDownLoop:
ldx screen1+SCROLLROWS*40-40,y
lda charColors,x
sta colors+SCROLLROWS*40-40,y
SW_DrawColorsDownLdx2:
ldx screen1+SCROLLROWS*40-40+13,y
lda charColors,x
sta colors+SCROLLROWS*40-40+13,y
SW_DrawColorsDownLdx3:
ldx screen1+SCROLLROWS*40-40+26,y
lda charColors,x
sta colors+SCROLLROWS*40-40+26,y
dey
bpl SW_DrawColorsDownLoop
rts
; New blocks drawing routines
SW_DrawRight: lda blockX
clc
adc #$02
cmp #$04
and #$03
sta temp1
lda mapX
adc #$09
ldy #38
bne SWDL_Common
SW_DrawLeft: lda blockX
sta temp1
lda mapX
ldy #$00
SWDL_Common: sty SWDL_Sta+1
sta SWDL_MapX+1
lda mapY
sta SWDL_MapY+1
lda screen
eor #$01
tax
lda screenBaseTbl,x
sta SWDL_Sta+2
lda blockY
asl
asl
ora temp1
ldx #$00
SWDL_GetBlock: sta temp2
SWDL_MapY: ldy #$00
lda mapTblHi,y
beq SWDL_Outside
sta temp4
lda mapTblLo,y
sta temp3
SWDL_MapX: ldy #$00
lda (temp3),y
SWDL_Outside: tay
lda blkTblLo,y
sta SWDL_Lda+1
lda blkTblHi,y
sta SWDL_Lda+2
ldy temp2
SWDL_Lda: lda $1000,y
SWDL_Sta: sta $1000,x
SWDL_EndCmp: cpx #<((SCROLLROWS-1)*40)
beq SWDL_Ready
txa
clc
adc #40
tax
bcc SWDL_Not2
inc SWDL_Sta+2
SWDL_Not2: lda blockDownTbl,y
tay
bpl SWDL_Lda
SWDL_Block: inc SWDL_MapY+1
lda temp1
bpl SWDL_GetBlock
SWDL_Ready: rts
SW_DrawDown: ldy #<(screen1+SCROLLROWS*40-40)
sty SWDU_Sta+1
ldy #>(SCROLLROWS*40-40)
lda mapY
clc
adc #$05
tax
lda blockY
adc #$01
cmp #$04
bcc SWDU_Common
and #$03
inx
bcs SWDU_Common
SW_DrawUp: ldy #$00
sty SWDU_Sta+1
ldx mapY
lda blockY
SWDU_Common: asl
asl
ora blockX
sta temp2
lda mapTblLo,x
sta temp3
lda mapTblHi,x
sta temp4
sta SWDU_GetBlock+1
lda screen
eor #$01
tax
tya
ora screenBaseTbl,x
sta SWDU_Sta+2
ldx #$00
ldy mapX
SWDU_GetBlock: lda #$00
beq SWDU_Outside
lda (temp3),y
SWDU_Outside: iny
sty temp5
tay
lda blkTblLo,y
sta SWDU_Lda+1
lda blkTblHi,y
sta SWDU_Lda+2
ldy temp2
SWDU_Lda: lda $1000,y
SWDU_Sta: sta screen1,x
inx
cpx #39
bcs SWDU_Ready
lda blockRightTbl,y
tay
bpl SWDU_Lda
and #$0f
sta temp2
ldy temp5
jmp SWDU_GetBlock
SWDU_Ready: rts
; Redraw screen fully and center scrolling
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp1-temp7
RedrawScreen: jsr BlankScreen
ldy #$00
sty scrollWorkFlag ;Scrollwork not needed after redraw
sty screen
ldx blockX