gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/z80/coords_to_address.s
1 .include "global.s"
2
3 .title "VRAM utilities"
4 .module VRAMUtils
5
6 .area _HOME
7
8 ; uint8_t * get_bkg_xy_addr(uint8_t x, uint8_t y) __preserves_regs(iyh, iyl);
9
10 _get_bkg_xy_addr::
11 ld d, l
12 ld e, a
13
14 ; translate coords in DE into address in DE
15 .coords_to_address::
16 ld a, (_shadow_VDP_R2)
17 rlca
18 rlca
19 and #0b01111000
20 ld b, a
21
22 ld a, d
23 add #.SCREEN_Y_OFS
24 ld d, a
25 xor a
26 ld c, a
27 FAST_MOD8 d #28
28 ld d, a
29
30 ld a, e
31 add #.SCREEN_X_OFS
32 and #0x1f
33 ld e, a
34
35 ld a, d
36 rrca ; rrca(2) == rlca(6)
37 rrca
38 ld d, a
39 and #0x07
40 add b
41 ld b, a
42 ld a, #0xC0
43 and d
44 sla e
45 add e
46 ld e, a
47 ld d, b ; dest DE = BC + ((0x20 * Y) * 2) + (X * 2)
48
49 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.