cscg22-gearboy

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

set_1bit_data.s (1703B)


      1        .include        "global.s"
      2
      3        .globl __current_1bpp_colors
      4
      5        .area   _HOME
      6
      7_set_bkg_1bpp_data::
      8_set_win_1bpp_data::
      9        ld d, #0x90
     10        ldh a, (.LCDC)
     11        and #LCDCF_BG8000
     12        jr z, .copy_1bpp_tiles
     13_set_sprite_1bpp_data::
     14        ld d, #0x80
     15.copy_1bpp_tiles:
     16        push bc
     17
     18        lda hl, 4(sp)
     19        ld a, (hl+) ; ID of 1st tile
     20        ld e, a
     21        ld a, (hl+) ; Nb of tiles
     22        ld c, a
     23        ld a, (hl+) ; Src ptr
     24        ld h, (hl)
     25        ld l, a
     26        
     27        ; Compute dest ptr
     28        swap e ; *16 (size of a tile)
     29        ld a, e
     30        and #0x0F ; Get high bits
     31        add d ; Add base offset of target tile "block"
     32        ld d, a
     33        ld a, e
     34        and #0xF0 ; Get low bits only
     35        ld e, a
     36
     37        push de
     38        ld d, h
     39        ld e, l
     40        pop hl
     41
     421$:
     43        ; Wrap from past $97FF to $8800 onwards
     44        ; This can be reduced to "bit 4 must be clear if bit 3 is set"
     45        bit 3, h
     46        jr z, 2$
     47        res 4, h
     482$:
     49        ld b, #8
     503$:
     51        push bc
     52        ld a, (de)     ; a == bits
     53        inc de
     54        push de
     55        push hl
     56
     57        ld hl, #__current_1bpp_colors
     58        ld c, (hl)
     59        inc hl
     60        ld h, (hl)
     61        ld l, c         ; L ==.fg_colour, H == .bg_colour
     62
     63        ld e, #8
     648$:
     65        rra
     66        jr c, 7$
     67        ld d, h
     68        jr 9$
     697$:
     70        ld d, l
     719$:
     72        srl d
     73        rr c
     74        srl d
     75        rr b
     76
     77        dec e
     78        jr nz, 8$
     79
     80        pop hl
     81
     82        WAIT_STAT
     83        ld (hl), c
     84        inc l
     85        ld (hl), b
     86        inc hl
     87
     88        pop de
     89        pop bc
     90
     91        dec b
     92        jr nz, 3$
     93
     94        dec c
     95        jr nz, 1$
     96
     97        pop bc
     98        ret