set_tile_map_xy_compat.s (2426B)
1 .include "global.s" 2 3 .globl .vdp_shift 4 5 .title "VRAM utilities" 6 .module VRAMUtils 7 8 .ez80 9 10 .area _INITIALIZED 11 12__map_tile_offset:: 13 .ds 0x01 14 15 .area _INITIALIZER 16 17 .db 0x00 18 19 .area _HOME 20 21 ;; Set background tile table from (BC) at XY = DE of size WH = HL 22.set_tile_map_xy_compat:: 23 push hl 24 ld hl, #.VDP_TILEMAP 25 26 ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) 27.set_tile_map_xy_tt_compat:: 28 push bc ; Store source 29 30 ld a, d 31 rrca ; rrca(2) == rlca(6) 32 rrca 33 ld d, a 34 and #0x07 35 add h 36 ld b, a 37 ld a, #0xC0 38 and d 39 sla e 40 add e 41 ld hl, #.vdp_shift 42 add (hl) 43 ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) 44 45 ld a, b 46 cp #>(.VDP_TILEMAP+0x0700) 47 jr c, 5$ 48 ld b, #>.VDP_TILEMAP 495$: 50 pop hl ; HL = source 51 pop de ; DE = HW 52 push ix ; save IX 53 push de ; store HW 54 ld ixh, b 55 ld ixl, c 56 push ix ; store dest 57 58 DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT 59 601$: ; copy H rows 61 VDP_WRITE_CMD ixh, ixl 62 ld c, #.VDP_DATA 632$: ; copy W tiles 64 ld a, (__map_tile_offset) 65 add (hl) 66 out (c), a 67 inc hl 68 dec b 69 jr 8$ ; delay 708$: 71 in a, (c) ; skip next byte 72 73 ld a, ixl 74 and #0x3F 75 inc a 76 inc a 77 bit 6, a 78 jp z, 3$ 79 and #0x3F 80 ld b, a 81 ld a, ixl 82 and #0xC0 83 or b 84 ld ixl, a 85 VDP_WRITE_CMD ixh, ixl 86 dec e 87 jp nz, 2$ 88 jp 7$ 893$: 90 inc ixl 91 inc ixl 92 dec e 93 jp nz, 2$ 947$: 95 pop ix 96 pop de 97 98 dec d 99 jr z, 6$ 100 101 push de 102 103 ld bc, #0x40 104 add ix, bc 105 ld a, ixh 106 cp #>(.VDP_TILEMAP+0x0700) 107 jp c, 4$ 108 ld ixh, #>.VDP_TILEMAP 1094$: 110 push ix 111 jp 1$ 1126$: 113 ENABLE_VBLANK_COPY ; switch ON copy shadow SAT 114 pop ix ; restore IX 115 ret