sms_fill_rect_xy_compat.s (2190B)
1 .include "global.s" 2 3 .globl .vdp_shift 4 5 .title "VRAM utilities" 6 .module VRAMUtils 7 8 .ez80 9 10 .area _HOME 11 12 ;; Set background tile table from (BC) at XY = DE of size WH = HL 13.fill_rect_xy_compat:: 14 push hl 15 ld hl, #.VDP_TILEMAP 16 17 ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) 18.fill_rect_xy_tt_compat:: 19 push bc ; Store source 20 21 ld a, d 22 rrca ; rrca(2) == rlca(6) 23 rrca 24 ld d, a 25 and #0x07 26 add h 27 ld b, a 28 ld a, #0xC0 29 and d 30 sla e 31 add e 32 ld hl, #.vdp_shift 33 add (hl) 34 ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) 35 36 ld a, b 37 cp #>(.VDP_TILEMAP+0x0700) 38 jr c, 5$ 39 ld b, #>.VDP_TILEMAP 405$: 41 pop hl ; HL = source 42 pop de ; DE = HW 43 push ix ; save IX 44 push de ; store HW 45 ld ixh, b 46 ld ixl, c 47 push ix ; store dest 48 49 DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT 50 511$: ; copy H rows 52 VDP_WRITE_CMD ixh, ixl 53 ld c, #.VDP_DATA 542$: ; copy W tiles 55 out (c), l 56 VDP_DELAY 57 in a, (c) ; skip next byte 58 59 ld a, ixl 60 and #0x3F 61 inc a 62 inc a 63 bit 6, a 64 jp z, 3$ 65 and #0x3F 66 ld b, a 67 ld a, ixl 68 and #0xC0 69 or b 70 ld ixl, a 71 VDP_WRITE_CMD ixh, ixl 72 dec e 73 jp nz, 2$ 74 jp 7$ 753$: 76 inc ixl 77 inc ixl 78 dec e 79 jp nz, 2$ 807$: 81 pop ix 82 pop de 83 84 dec d 85 jr z, 6$ 86 87 push de 88 89 ld bc, #0x40 90 add ix, bc 91 ld a, ixh 92 cp #>(.VDP_TILEMAP+0x0700) 93 jp c, 4$ 94 ld ixh, #>.VDP_TILEMAP 954$: 96 push ix 97 jp 1$ 986$: 99 ENABLE_VBLANK_COPY ; switch ON copy shadow SAT 100 pop ix ; restore IX 101 ret