cscg22-gearboy

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

sms_set_2bpp_data.s (2449B)


      1        .include        "global.s"
      2
      3        .title  "VRAM utilities"
      4        .module VRAMUtils
      5
      6        .ez80
      7
      8        .area   _INITIALIZED
      9__current_2bpp_palette::
     10        .ds     0x02
     11
     12        .area   _INITIALIZER
     13        .dw     0b0011001000010000
     14
     15        .area   _HOME
     16
     17; void set_tile_2bpp_data(uint16_t start, uint16_t ntiles, const void *src, uint16_t palette) __z88dk_callee __preserves_regs(iyh,iyl);
     18_set_tile_2bpp_data::
     19        pop de                  ; pop ret address
     20        pop hl
     21                
     22        add hl, hl
     23        add hl, hl
     24        add hl, hl
     25        add hl, hl
     26        add hl, hl
     27        
     28        ld bc, #.VDP_VRAM
     29        add hl, bc
     30                
     31        DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     32
     33        VDP_WRITE_CMD h, l
     34
     35        ex de, hl               ; hl = ret
     36
     37        pop bc                  ; bc = ntiles
     38        pop de                  ; de = src
     39        ex (sp), hl             ; hl = palette
     40
     41        ex de, hl
     42
     43        inc b
     44        inc c
     45        push ix
     46        push iy
     47        ld iy, #-4
     48        add iy, sp
     49        ld sp, iy        
     50        push bc
     51        jr 2$
     52        
     531$:
     54        ex (sp), hl
     55
     56        ld ixh, #8
     576$:
     58        ld c, (hl)
     59        inc hl
     60        ld b, (hl)
     61        inc hl
     62
     63        ld ixl, #8
     645$:
     65        xor a
     66        srl b
     67        rla
     68        srl c
     69        rla
     70
     71        push de                 ; save palette
     72
     73        inc a
     74        dec a
     75        jr nz, 10$
     76        ; zero
     77        ld a, e
     78        jr 13$
     7910$:
     80        dec a
     81        jr nz, 11$
     82        ; one
     83        ld a, e
     84        jr 14$
     8511$:
     86        dec a
     87        jr nz, 12$
     88        ; two
     89        ld a, d
     90        jr 13$
     9112$:
     92        ;three
     93        ld a, d
     9414$:
     95        rra
     96        rra
     97        rra
     98        rra
     9913$:
    100        and #0x0F
    101
    102        rra
    103        rr 0 (iy)
    104        rra
    105        rr 1 (iy)
    106        rra
    107        rr 2 (iy)
    108        rra
    109        rr 3 (iy)
    110
    111        pop de                  ; restore palette
    112
    113        dec ixl
    114        jr nz, 5$
    115
    116        ld a, 0 (iy)
    117        out (.VDP_DATA), a
    118        ld a, 1 (iy)
    119        out (.VDP_DATA), a
    120        ld a, 2 (iy)
    121        out (.VDP_DATA), a
    122        ld a, 3 (iy)
    123        out (.VDP_DATA), a
    124
    125        dec ixh
    126        jr nz, 6$
    1272$:
    128        ex (sp), hl
    129
    130        dec l
    131        jr  nz, 1$
    132
    133        dec h
    134        jr  nz, 1$
    135
    136        ld iy, #6
    137        add iy, sp
    138        ld sp, iy
    139        pop iy
    140        pop ix
    141
    142        ENABLE_VBLANK_COPY        ; switch ON copy shadow SAT
    143
    144        ret