gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/z80/sms_fill_rect_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 _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 a, (_shadow_VDP_R2)
16 rlca
17 rlca
18 and #0b01111000
19 ld h, a
20 ld l, #0
21
22 ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
23 .fill_rect_xy_tt_compat::
24 ld a, h
25 ld iyh, a
26 push bc ; Store source
27
28 ld a, d
29 rrca ; rrca(2) == rlca(6)
30 rrca
31 ld d, a
32 and #0x07
33 add h
34 ld b, a
35 ld a, #0xC0
36 and d
37 sla e
38 add e
39 ld hl, #.vdp_shift
40 add (hl)
41 ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
42
43 ld a, b
44 and #0b00000111
45 or iyh
46 ld b, a
47
48 DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT
49
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 1$: ; copy H rows
59 VDP_WRITE_CMD ixh, ixl
60 ld c, #.VDP_DATA
61 2$: ; copy W tiles
62 out (c), l
63 VDP_DELAY
64 in a, (c) ; skip next byte
65
66 ld a, ixl
67 and #0x3F
68 inc a
69 inc a
70 bit 6, a
71 jp z, 3$
72 and #0x3F
73 ld b, a
74 ld a, ixl
75 and #0xC0
76 or b
77 ld ixl, a
78 VDP_WRITE_CMD ixh, ixl
79 dec e
80 jp nz, 2$
81 jp 7$
82 3$:
83 inc ixl
84 inc ixl
85 dec e
86 jp nz, 2$
87 7$:
88 pop ix
89 pop de
90
91 dec d
92 jr z, 6$
93
94 push de
95
96 ld bc, #0x40
97 add ix, bc
98
99 ld a, ixh
100 and #0b00000111
101 cp #0x07
102 jp nz, 8$
103 xor a
104 8$:
105 or iyh
106 ld ixh, a
107
108 push ix
109 jp 1$
110 6$:
111 ENABLE_VBLANK_COPY ; switch ON copy shadow SAT
112 pop ix ; restore IX
113 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.