cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

coords_to_address.s (978B)


      1        .include        "global.s"
      2
      3        .title  "VRAM utilities"
      4        .module VRAMUtils
      5
      6        .area   _HOME
      7
      8; translate coords in DE and given base in BC into address in DE
      9.coords_to_address::
     10        ld a, d
     11        add #.SCREEN_Y_OFS
     12        ld d, a
     13        xor a
     14        FAST_MOD8 d #28
     15        ld d, a
     16
     17        ld a, e
     18        add #.SCREEN_X_OFS
     19        and #0x1f
     20        ld e, a         
     21
     22        ld a, d
     23        rrca                    ; rrca(2) == rlca(6)
     24        rrca 
     25        ld d, a
     26        and #0x07
     27        add b
     28        ld b, a
     29        ld a, #0xC0
     30        and d
     31        sla e
     32        add e
     33        ld e, a
     34        ld d, b                 ; dest DE = BC + ((0x20 * Y) * 2) + (X * 2)
     35
     36        ret
     37
     38; uint8_t * get_bkg_xy_addr(uint8_t x, uint8_t y) __z88dk_callee __preserves_regs(iyh, iyl);
     39
     40_get_bkg_xy_addr::
     41        pop hl
     42        ex (sp), hl
     43        ex de, hl
     44        ld bc, #.VDP_TILEMAP
     45        call .coords_to_address 
     46        ex de, hl
     47        ret