gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/sm83/fill_rect.s
1 .include "global.s"
2
3 .area _HOME
4
5 .fill_rect_wtt::
6 PUSH HL
7 LDH A,(.LCDC)
8 AND #LCDCF_WIN9C00
9 JR Z,.is98
10 JR .is9c
11 ;; Initialize background tile table with B
12 .fill_rect_btt::
13 PUSH HL
14 LDH A,(.LCDC)
15 AND #LCDCF_BG9C00
16 JR NZ,.is9c
17 .is98:
18 LD H, #0x98 ; HL = origin
19 JR .fill_rect
20 .is9c:
21 LD H, #0x9C ; HL = origin
22
23 ;; fills rectangle area with tile B at XY = DE, size WH on stack, to vram from address (H << 8)
24 .fill_rect:
25 ld l, d
26 swap e
27 ld a, e
28 res 0, e
29 and #1
30 ld d, a
31 add hl, de
32 add hl, de ; dest HL = (H << 8) + 0x20 * Y + X
33
34 pop de ; DE = WH
35 ld c, d ; C = W
36 0$:
37 push hl ; store dest
38 1$: ; Copy W tiles
39 WAIT_STAT
40 ld (hl), b
41
42 ; inc dest and wrap around
43 inc l
44 ld a, l
45 and #0x1F
46 jr nz, 2$
47 ld a, l
48 sub #0x20
49 ld l, a
50 2$:
51 dec d
52 jr nz, 1$
53
54 pop hl
55
56 dec e
57 ret z
58
59 ld d, c ; D = W
60
61 ; next row and wrap around
62 ld a, l
63 add #0x20
64 ld l, a
65 jr nc, 0$
66 ld a, h
67 rrca
68 rrca
69 add #0x40
70 rlca
71 rlca
72 ld h, a
73
74 jr 0$
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.