-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.asm
1209 lines (1139 loc) · 21.8 KB
/
utils.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
;============================================================
; Copies b words from the memory locations pointed to
; by hl to the chunk of memory at de
CopyContainCoords:
ld a,(hl)
inc hl
push hl
ld h,(hl)
ld l,a
ld a,(hl)
ld (de),a
inc hl
inc de
ld a,(hl)
ld (de),a
pop hl
inc de
inc hl
djnz CopyContainCoords
ret
;============================================================
TrashRAM_SwapIn:
ld a,TRASHABLE_RAM_PAGE | $80 ;RAM page to trash with a buffer
jr AltRAM_SwapIn
TraceCoordBackRAM_SwapIn:
ld a,TRACE_COORD_RAM_PAGE | $80 ;RAM page to trash with a buffer
AltRAM_SwapIn:
push af
di
in a,($27)
ld (high_bank_mask),a
ld a,(16384 - trash_ram_fill)/64
out ($27),a
in a,(5)
ld (high_bank_page),a
pop af
out (5),a
ret
TrashRAM_SwapOut:
TraceCoordBackRAM_SwapOut:
ld a,(high_bank_page) ;Don't need to worry about port $D/E/F because
out (5),a ;$C000-$FFFF can only hold RAM pages
ld a,(high_bank_mask)
out ($27),a
ei
ret
ColorLine_RetPopBCDEHL:
pop bc
pop de
pop hl
ret
ColorLine:
; de = x0, bc = y0, hl = x1, ix = y1, iy = colour
;
; Check for fully-offscreen lines: X or Y are both < pxlMinY, or X or Y are both > 320/240.
ld a,h
and d
and $80 ;bit 7,a
ret nz ; h and d are both negative
; Since we know hl and de are positive, we can add them.
push hl
push de
push bc
ld bc,320
or a
sbc hl,bc
jr c,ColorLine_NotOffscreenX
ex de,hl
sbc hl,bc
jr nc,ColorLine_RetPopBCDEHL
ColorLine_NotOffscreenX:
pop hl
; Check if ys are both offscreen
push hl
push ix
pop de
ld bc,(pxlMaxY)
@:
or a
sbc hl,bc
add hl,bc
jr c,ColorLine_NotOffBottomY
ex de,hl
sbc hl,bc
add hl,bc
jr nc,ColorLine_RetPopBCDEHL
ColorLine_NotOffBottomY:
ld bc,(PxlMinY)
or a
sbc hl,bc
ex de,hl
or a
sbc hl,bc
ld a,h
and d
and $80 ;bit 7,a
pop bc
pop de
pop hl
ret nz
ColorLine_Override:
ld (lineColour),iy
ld a,1
ld (xyinc+0),a
ld (xyinc+1),a ; x/y inc
ld (xstart),de ; de = x0, hl = x1
; Figure out the increments
ld a,h
xor $80
ld h,a
ld a,d
xor $80
ld d,a
or a
sbc hl,de
ld e,l
ld d,h ; de = (x1 - x0)
jr nc,$+13
ld a,-1
ld (xyinc+0),a ; x inc
xor a
sub e
ld e,a
sbc a,a
sub d
ld d,a ; de = -(x1 - x0)
ld (ystart),bc ; bc = y0, ix = y1
push ix
pop hl
ld a,h
xor $80
ld h,a
ld a,b
xor $80
ld b,a
or a
sbc hl,bc
ld c,l
ld b,h ; bc = (y1 - y0)
jr nc,{@}
ld a,-1
ld (xyinc+1),a ; y inc
xor a
sub c
ld c,a
sbc a,a
sub b
ld b,a ; bc = -(y1 - y0)
@: ld l,e
ld h,d
push bc
ld a,h
xor $80
ld h,a
ld a,b
xor $80
ld b,a
or a
sbc hl,bc
pop bc
ld hl,0 ; error
jp c,ColorLine_y
ColorLine_x:
push de
pop ix
inc ix
ColorLine_Loop_x:
push hl
push de
push bc
ld hl,(xstart)
ld de,(ystart)
call ColorPixel
ld a,(xyinc+0)
ld c,a
rlca
sbc a,a
ld b,a
add hl,bc
ld (xstart),hl
pop bc
pop de
pop hl
add hl,bc
or a
sbc hl,de
add hl,de
jr c,$+23
or a
sbc hl,de
push bc
ld a,(xyinc+1)
ld c,a
rlca
sbc a,a
ld b,a
push hl
ld hl,(ystart)
add hl,bc
ld (ystart),hl
pop hl
pop bc
dec ix
ld a,ixl
or ixh
jr nz,ColorLine_Loop_x
ret
ColorLine_y:
push de
ld e,c
ld d,b
pop bc
push de
pop ix
inc ix
ColorLine_Loop_y:
push hl
push de
push bc
ld hl,(xstart)
ld de,(ystart)
call ColorPixel
ld a,(xyinc+1)
ld c,a
rlca
sbc a,a
ld b,a
ex de,hl
add hl,bc
ld (ystart),hl
pop bc
pop de
pop hl
add hl,bc
or a
sbc hl,de
add hl,de
jr c,$+23
or a
sbc hl,de
push bc
ld a,(xyinc+0)
ld c,a
rlca
sbc a,a
ld b,a
push hl
ld hl,(xstart)
add hl,bc
ld (xstart),hl
pop hl
pop bc
dec ix
ld a,ixl
or ixh
jr nz,ColorLine_Loop_y
ret
ColorPixel:
; hl = x, de = y, (lineColour) = colour
; needs re-writing
;
bit 7,h
ret nz
ex de,hl
ld bc,(pxlMinY)
or a
sbc hl,bc
add hl,bc
ex de,hl
ret c
ld bc,320
or a
sbc hl,bc
add hl,bc
ret nc ; return if offscreen
ex de,hl
ld bc,(pxlMaxY)
@:
or a
sbc hl,bc
add hl,bc
ex de,hl
ret nc ; return if offscreen
push de
push hl
ld a,$52
call setLCDRegister_SaveC ; v-addr-start (x-start)
ld a,$21
call setLCDRegister_SaveC ; x pos
ld a,$53
call setLCDRegister_SaveC ; v-addr-end (x-end)
ex de,hl
ld a,$50
call setLCDRegister_SaveC ; h-addr-start (y-start)
ld a,$20
call setLCDRegister_SaveC ; y pos
inc hl
ld a,$51
call setLCDRegister_SaveC ; h-addr-end (y-end)
ld a,$22
out ($10),a \ out ($10),a ; write data to GRAM
ld a,(lineColour+1) \ out ($11),a
ld a,(lineColour+0) \ out ($11),a
pop hl
pop de
ret
setLCDRegister_SaveC:
; a = register
; hl = value
out ($10),a
out ($10),a
ld a,h
out ($11),a
ld a,l
out ($11),a
ret
DisplayOrg:
ld a,3 ; adjust origin drawing mode
ld hl,$1038
call Write_Display_Control
jr Full_Window
DisplayNormal:
ld a,3 ; normal drawing mode
ld hl,$10B8
call Write_Display_Control
Full_Window:
ld a,$50 ; Set minimum Y
ld hl,0
call Write_Display_Control
inc a ; Set maximum Y
ld l,239
call Write_Display_Control
ld hl,0 ; Set minimum X
inc a
call Write_Display_Control
inc a ; Set maximum X
ld hl,319
; Write HL to display register A (trashes c)
Write_Display_Control:
out ($10),a
out ($10),a
ld c,$11
out (c),h
out (c),l
ret
;############## Clear the screen (in black, of course!)
PutsColored:
call SetTextColors
set textEraseBelow,(iy+textFlags)
set 4,(iy+$4a) ; Puts should listen to colored text
PutSApp:
ld a,(hl)
inc hl
or a
ret z
bcall(_PutMap)
ld a,(curCol)
inc a
ld (curCol),a
cp 26
jr nz,PutSApp
xor a
ld (curCol),a
ld a,(curRow)
cp 9
jr z,PutSApp
inc a
ld (curRow),a
jr PutSApp
DrawSprite_OffscreenCheck_WithYBounds:
push de
ld de,(PxlMinY)
call cphlde
jr c,DrawSprite_OffscreenCheck_WithYBounds_Abort
ld de,(PxlMaxY)
call cphlde
jr nc,DrawSprite_OffscreenCheck_WithYBounds_Abort
pop de
jr DrawSprite_OffscreenCheck
DrawSprite_OffscreenCheck_WithYBounds_Abort:
pop de
scf
ret
DrawSprite_OffscreenCheck: ;Re-used by all DrawSprite routines
push bc
ld b,0
ld c,(ix)
push bc
ld c,(ix+1)
call RectWindow ;Lowers the stack level; ix is still intact
jp c,Abort_1
ld b,(ix+1)
cp b
jp nz,Abort_1
ld a,(ix)
cp c
jp nz,Abort_1
ld a,d
or e
push ix
pop de
pop ix
ret nz ;X clipped
ld a,h
or l
ret nz ;Y clipped
DrawSprite_SetDataMode:
ld a,$22
out ($10),a
out ($10),a
xor a
ret
DrawSprite_CheckAndLoad:
ld bc,240
call cphlbc ;Check Y coordinate
ret nc
ld bc,320
ex de,hl
call cphlbc ;Check X coordinate
ret nc
ex de,hl
ld c,(ix)
inc ix
ld b,(ix)
inc ix
scf ;Set carry flag!
ret
;de=x, hl=y
;ix->sprite (.db width, height \ .db bitpacked_padded_rows)
DrawSprite_16Bit:
call DrawSprite_OffscreenCheck_WithYBounds ; hl, ix no longer needed after this
ld a,(de)
ld c,a ;Store width in save buffer and c
inc de
ld a,(de)
ld b,a ;Store height in save buffer and b
inc de
ex de,hl
Draw_Sprite_16Bit_Outer:
push bc
ld b,c
sla b
ld c,$11 ;7
otir
pop bc ;10
djnz Draw_Sprite_16Bit_Outer ;13 if jump taken
ret
DrawSprite_1Bit_SaveBuf:
;bc->palette, de=x, hl=y, iy->save buffer
;ix->sprite (.db width, height \ .db bitpacked_padded_rows)
; Must check that coordinates are not offscreen manually!
push bc
call DrawSprite_OffscreenCheck_WithYBounds ; hl no longer needed after this
pop hl
ret c
ret nz ;DrawSprite_OffscreenCheck returns z on success
ld a,(de)
ld (iy),a
ld c,a ;Store width in save buffer and c
inc de
inc iy
ld a,(de)
ld (iy),a
ld b,a ;Store height in save buffer and b
inc de
inc iy
Draw_Sprite_1Bit_PackedLoop:
push bc
ld b,c
ld c,1
Draw_Sprite_1Bit_PackedLine:
dec c
jr nz,Draw_Sprite_1Bit_PackedLine_Bit_NoNewByte
ld a,(de)
inc de
ld c,8
Draw_Sprite_1Bit_PackedLine_Bit_NoNewByte:
push af
in a,($11)
in a,($11)
in a,($11)
ld (iy),a
inc iy
in a,($11)
ld (iy),a
inc iy
pop af
rlc a
push ix
pop hl
bit 0,a
jr z,Draw_Sprite_1Bit_PackedLine_BitLow
inc hl
inc hl
Draw_Sprite_1Bit_PackedLine_BitLow:
push bc ;10
ld c,$11 ;7
outi ;16
outi ;16
pop bc ;10
djnz Draw_Sprite_1Bit_PackedLine ;13 if jump taken
pop bc ;10
djnz Draw_Sprite_1Bit_PackedLoop ;13 if jump taken
ret
#ifdef false
;OLD: ix -> palette, b = x, l = y, de -> sprite
;NEW: de=x, hl=y,
;NEW: ix=sprite (.dw palette \ .db width, height \ .db bitpacked_padded_rows)
DrawSprite_2Bit:
call DrawSprite_CheckAndLoad
ret nc
;IMPORTANT NOTE: DrawSprite_2Bit_Pal skips the X/Y validity check
DrawSprite_2Bit_Pal:
;bc=palette, de=x, hl=y,
;ix=sprite (.db width, height \ .db bitpacked_padded_rows)
call DrawSprite_OffscreenCheck
ret c
ret nz ;DrawSprite_OffscreenCheck returns z on success
ld a,(de)
ld c,a
dec c
srl c
srl c
; srl c
inc c
inc de
ld a,(de)
ld b,a
inc de
Draw_Sprite_2Bit_PackedLoop:
push bc
ld b,c
Draw_Sprite_2Bit_PackedLine:
push bc ;11
ld a,(de) ;7
rra ;4
rra ;4
rra ;4
rra ;4
rra ;4
and %110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
ld a,(de) ;7
rra ;4
rra ;4
rra ;4
and %110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
ld a,(de) ;7
rra ;4
and %110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
ld a,(de) ;7
rla ;4
and %110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
inc de ;6
pop bc ;10
djnz Draw_Sprite_2Bit_PackedLine ;13 if jump taken
pop bc ;10
djnz Draw_Sprite_2Bit_PackedLoop ;13 if jump taken
ret
#endif
;OLD: ix -> palette, b = x, l = y, de -> sprite
;NEW: de=x, hl=y,
;NEW: ix=sprite (.dw palette \ .db width, height \ .db bitpacked_padded_rows)
DrawSprite_4Bit:
call DrawSprite_CheckAndLoad
ret nc
;IMPORTANT NOTE: DrawSprite_4Bit_Pal skips the X/Y validity check
DrawSprite_4Bit_Pal:
;bc=palette, de=x, hl=y,
;ix=sprite (.db width, height \ .db bitpacked_padded_rows)
call DrawSprite_OffscreenCheck
ret c
ret nz ;DrawSprite_OffscreenCheck returns z on success
ld a,(de)
ld c,a
dec c
srl c
; srl c
; srl c
inc c
inc de
ld a,(de)
ld b,a
inc de
DrawSprite_4Bit_PackedLoop:
push bc
ld b,c
DrawSprite_4Bit_PackedLine:
push bc ;11
ld a,(de) ;7
rra ;4
rra ;4
rra ;4
and %11110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
ld a,(de) ;7
rla ;4
and %11110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
inc de ;6
pop bc ;10
djnz DrawSprite_4Bit_PackedLine ;13 if jump taken
pop bc ;10
djnz DrawSprite_4Bit_PackedLoop ;13 if jump taken
ret
;OLD: ix -> palette, b = x, l = y, de -> sprite
;NEW: de=x, hl=y,
;NEW: ix=sprite (.dw palette \ .db width, height \ .db bitpacked_padded_rows)
DrawSprite_4Bit_Enlarge:
call DrawSprite_CheckAndLoad
ret nc
;IMPORTANT NOTE: DrawSprite_4Bit_Enlarge_Pal skips the X/Y validity check
DrawSprite_4Bit_Enlarge_Pal:
;bc=palette, de=x, hl=y,
;ix=sprite (.db width, height \ .db bitpacked_padded_rows)
call DrawSprite_OffscreenCheck
ret c
ret nz ;DrawSprite_OffscreenCheck returns z on success
ld a,(de)
ld c,a
dec c
srl c
srl c
; srl c
inc c
inc de
ld a,(de)
ld b,a
inc de
DrawSprite_4Bit_Enlarge_PackedLoop:
push bc
push de
call DrawSprite_4Bit_Enlarge_PackedLine_Sub
pop de
call DrawSprite_4Bit_Enlarge_PackedLine_Sub
pop bc ;10
dec b
djnz DrawSprite_4Bit_Enlarge_PackedLoop ;13 if jump taken
ret
DrawSprite_4Bit_Enlarge_PackedLine_Sub:
ld b,c
DrawSprite_4Bit_Enlarge_PackedLine:
push bc ;11
ld a,(de) ;7
rra ;4
rra ;4
rra ;4
and %11110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outd ;16 ;First pixel copy
outi ;16
outi ;16 ;Second pixel copy
ld a,(de) ;7
rla ;4
and %11110 ;7
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
ld c,$11
outi ;16
outd ;16 ;First pixel copy
outi ;16
outi ;16 ;Second pixel copy
inc de ;6
pop bc ;10
djnz DrawSprite_4Bit_Enlarge_PackedLine ;13 if jump taken
ret
;OLD: ix -> palette, b = x, l = y, de -> sprite
;NEW: de=x, hl=y,
;NEW: ix=sprite (.dw palette \ .db width, height \ .db bitpacked_padded_rows)
DrawSprite_8Bit:
call DrawSprite_CheckAndLoad
ret nc
;IMPORTANT NOTE: DrawSprite_8Bit_Pal skips the X/Y validity check
DrawSprite_8Bit_Pal:
;bc=palette, de=x, hl=y,
;ix=sprite (.db width, height \ .db bitpacked_padded_rows)
ld a,b
or c
jr z,DrawSprite_8Bit_DefaultPal
call DrawSprite_OffscreenCheck
ret c
ret nz ;DrawSprite_OffscreenCheck returns z on success
ld a,(de)
ld c,a
; dec c
; srl c
; srl c
; srl c
; inc c
inc de
ld a,(de)
ld b,a
inc de
DrawSprite_8Bit_PackedLoop:
push bc
ld b,c
DrawSprite_8Bit_PackedLine:
push bc ;11
ld a,(de) ;7
cp $57 ;transparent
jr z,DrawSprite_8Bit_PackedLine_Trans
push ix ;11
pop hl ;10
ld c,a ;4
ld b,0 ;7
add hl,bc ;11
add hl,bc ;11
ld c,$11
outi ;16
outi ;16
DrawSprite_8Bit_PackedLine_Continue:
inc de ;6
pop bc ;10
djnz DrawSprite_8Bit_PackedLine ;13 if jump taken
pop bc ;10
djnz DrawSprite_8Bit_PackedLoop ;13 if jump taken
ret
DrawSprite_8Bit_PackedLine_Trans:
ld c,$11
in h,(c)
in l,(c)
in h,(c)
in l,(c)
out (c),h
out (c),l
jr DrawSprite_8Bit_PackedLine_Continue
DrawSprite_8Bit_DefaultPal:
call DrawSprite_OffscreenCheck
ret c
ret nz ;DrawSprite_OffscreenCheck returns z on success
ld a,(de)
ld c,a
; dec c
; srl c
; srl c
; srl c
; inc c
inc de
ld a,(de)
ld b,a
inc de
DrawSprite_8Bit_DefaultPal_PackedLoop:
push bc
ld b,c
DrawSprite_8Bit_DefaultPal_PackedLine:
push bc ;11
ld a,(de) ;7
cp $57
jr z,DrawSprite_8Bit_DefaultPal_PackedLine_Trans
ld c,$11
out (c),a
out (c),a
DrawSprite_8Bit_DefaultPal_PackedLine_Continue:
inc de ;6
pop bc ;10
djnz DrawSprite_8Bit_DefaultPal_PackedLine ;13 if jump taken
pop bc ;10
djnz DrawSprite_8Bit_DefaultPal_PackedLoop ;13 if jump taken
ret
DrawSprite_8Bit_DefaultPal_PackedLine_Trans:
ld c,$11
in h,(c)
in l,(c)
in h,(c)
in l,(c)
out (c),h
out (c),l
jr DrawSprite_8Bit_DefaultPal_PackedLine_Continue
RectWindow:
;bc=height, de=x, hl=y, (sp)=ret, (sp+2)=width
ex (sp),hl
pop af
ex (sp),hl
push bc
push af
ld a,$21*2
ld bc,320
call RectWindow_1
pop de
ex (sp),hl
push bc
ld a,$20*2
ld bc,240
call RectWindow_1
ld a,l
or h
ld a,c
Abort_2:
pop bc
Abort_1:
pop de
ret
;a=clipped height, bc=clipped width, de=x feedback, hl=y feedback
RectWindow_1:
;a=aport*2, bc=sdim, de=p1, hl=rdim
; DEF: aport=GRAM horizontal/vertical address set port ($20 or $21),
; sdim=screen dimension (240 or 320), rdim=rectangle dimension (height
; or width), p1=rectangle start (y1 or x1)
dec hl
add hl,de
rra ;rotate carry into bit 7, set if rdim+p1-1 carried
ex de,hl
push hl
or a
sbc hl,bc
add hl,bc
jr c,RectWindow_1_P1Ok
ld l,a
and h ;The things we care about are the bit 7s here
jp p,Abort_4 ;Abort if bit 7 of a and h are nonzero
ld a,l
sbc hl,hl
RectWindow_1_P1Ok:
and $7F
call setLCDRegister_SaveC_SaveA
add a,8
add a,a
call setLCDRegister_SaveC_SaveA
ex de,hl
dec c
sbc hl,bc
jr c,RectWindow_1_P2Ok
sbc hl,hl
RectWindow_1_P2Ok:
add hl,bc
add a,1
call setLCDRegister_SaveC
inc hl
sbc hl,de
ld b,h
ld c,l
pop hl
sbc hl,de
ret
;a=weport, bc=clipped rdim, de=clipped p1, hl=p1 feedback
Abort_4:
scf
pop bc
Abort_3:
pop bc
jp Abort_2
setLCDRegister_SaveC_SaveA:
push af
out ($10),a \ out ($10),a
ld a,h \ out ($11),a
ld a,l \ out ($11),a
pop af
ret
GetCurrentPage:
push bc
in a,($0E)
rrca
and $80
ld b,a
in a,($06)
or b
pop bc
ret
VPutsColored:
call SetTextColors
VPutSApp: ;display text in small font
ld a,(hl)
inc hl
inc a
dec a ;use inc and dec to preserve carry
ret z
push hl
push de
bcall(_VPutMap)
pop de
pop hl
jr VPutSApp
VPutSAppN: ;display text in small font
push bc
ld a,(hl)
inc hl
push hl
push de
bcall(_VPutMap)
pop de
pop hl
pop bc
djnz VPutSAppN
ret
;--------------------------------------------------
ResetColors:
ld de,COLOR_BLACK
ld bc,COLOR_WHITE
SetTextColors:
ld (drawBGColor),bc
ld (textBGColor),bc
ld (drawFGColor),de