gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/z80/set_tile_map_xy_compat.s
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 a, (_shadow_VDP_R2)
25 rlca
26 rlca
27 and #0b01111000
28 ld h, a
29 ld l, #0
30
31 ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
32 .set_tile_map_xy_tt_compat::
33 ld a, h
34 ld iyh, a
35 push bc ; Store source
36
37 ld a, d
38 rrca ; rrca(2) == rlca(6)
39 rrca
40 ld d, a
41 and #0x07
42 add h
43 ld b, a
44 ld a, #0xC0
45 and d
46 sla e
47 add e
48 ld hl, #.vdp_shift
49 add (hl)
50 ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
51
52 ld a, b
53 and #0b00000111
54 or iyh
55 ld b, a
56
57 DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT
58
59 pop hl ; HL = source
60 pop de ; DE = HW
61 push ix ; save IX
62 push de ; store HW
63 ld ixh, b
64 ld ixl, c
65 push ix ; store dest
66
67 1$: ; copy H rows
68 VDP_WRITE_CMD ixh, ixl
69 ld c, #.VDP_DATA
70 2$: ; copy W tiles
71 ld a, (__map_tile_offset)
72 add (hl)
73 out (c), a
74 inc hl
75 dec b
76 jr 8$ ; delay
77 8$:
78 in a, (c) ; skip next byte
79
80 ld a, ixl
81 and #0x3F
82 inc a
83 inc a
84 bit 6, a
85 jp z, 3$
86 and #0x3F
87 ld b, a
88 ld a, ixl
89 and #0xC0
90 or b
91 ld ixl, a
92 VDP_WRITE_CMD ixh, ixl
93 dec e
94 jp nz, 2$
95 jp 7$
96 3$:
97 inc ixl
98 inc ixl
99 dec e
100 jp nz, 2$
101 7$:
102 pop ix
103 pop de
104
105 dec d
106 jr z, 6$
107
108 push de
109
110 ld bc, #0x40
111 add ix, bc
112
113 ld a, ixh
114 and #0b00000111
115 cp #0x07
116 jp nz, 9$
117 xor a
118 9$:
119 or iyh
120 ld ixh, a
121
122 push ix
123 jp 1$
124 6$:
125 ENABLE_VBLANK_COPY ; switch ON copy shadow SAT
126 pop ix ; restore IX
127 ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.