git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/targets/sm83/gb_decompress_tiles.s

      1 ; GB-Decompress tiledata directly to VRAM
      2 ; Compatible with GBTD
      3 
      4         .include        "global.s"
      5 
      6         .title  "GB Decompress"
      7         .module GBDecompress
      8 
      9 .macro WRAP_VRAM regH, ?loc
     10         bit     3, regH
     11         jr      z, loc
     12         res     4, regH
     13 loc:
     14 .endm
     15 
     16 .macro UNWRAP_VRAM regH, ?loc
     17         bit     3, regH
     18         jr      nz, loc
     19         set     4, regH
     20 loc:
     21 .endm
     22 
     23 
     24         .area _CODE
     25 
     26 _gb_decompress_bkg_data::
     27 _gb_decompress_win_data::
     28         ld      b, #0x90
     29         ld      hl, #.LCDC
     30         bit     LCDCF_B_BG8000, (hl)
     31         jr      nz, .load_params
     32 _gb_decompress_sprite_data::
     33         ld      b, #0x80
     34 
     35 .load_params:
     36         ld      h, d
     37         ld      l, e
     38 
     39         ; Compute dest ptr
     40         swap    a       ; *16 (size of a tile)
     41         ld      e, a
     42         and     #0x0F   ; Get high bits
     43         add     b       ; Add base offset of target tile "block"
     44         ld      d, a
     45         ld      a, e
     46         and     #0xF0   ; Get low bits only
     47         ld      e, a
     48         WRAP_VRAM d
     49 
     50 ; hl = source; de = dest
     51 gb_decompress_vram::
     52         push    de
     53 1$:
     54         ld      a,(hl+) ; load command
     55         or      a
     56         jp      z,9$    ; exit, if last byte
     57         bit     7,a
     58         jr      nz,5$   ; string functions
     59         bit     6,a
     60         jr      nz,3$
     61         ; RLE byte
     62         and     #63     ; calc counter
     63         inc     a
     64         ld      c,a
     65         ld      a,(hl+)
     66         ld      b,a
     67 2$:
     68         WAIT_STAT
     69         ld      a,b
     70         ld      (de),a
     71         inc     de
     72         WRAP_VRAM d
     73         dec     c
     74         jr      nz,2$
     75         jr      1$      ; next command
     76 
     77 3$:                     ; RLE word
     78         and     #63
     79         inc     a
     80         ld      c, a
     81         ld      a,(hl+)
     82         ld      b, a
     83 4$:
     84         WAIT_STAT
     85         ld      a,b     ; store word
     86         ld      (de),a
     87         inc     de
     88         WRAP_VRAM d
     89         WAIT_STAT
     90         ld      a,(hl)
     91         ld      (de),a
     92         inc     de
     93         WRAP_VRAM d
     94         dec     c
     95         jr      nz,4$
     96         inc     hl
     97         jr      1$      ; next command
     98 
     99 5$:
    100         bit     6,a
    101         jr      nz,7$
    102 
    103 6$:                     ; string repeat
    104         and     a,#63
    105         inc     a
    106         push    hl
    107 
    108         ld      c,(hl)
    109         inc     hl
    110         ld      b,(hl)
    111 
    112         ldhl    sp,#3
    113         bit     4,(hl)  ; check start address was above 0x9000
    114         jr      z, 11$
    115 
    116         ld      h,d
    117         ld      l,e
    118         add     hl,bc
    119         UNWRAP_VRAM h
    120         jr      12$
    121 11$:
    122         ld      h,d
    123         ld      l,e
    124         add     hl,bc
    125 12$:
    126         ld      c,a
    127 
    128 14$:
    129         WAIT_STAT
    130         ld      a,(hl+)
    131         ld      (de),a
    132         WRAP_VRAM h
    133         inc     de
    134         WRAP_VRAM d
    135         dec     c
    136         jr      nz, 14$
    137 
    138         pop     hl
    139         inc     hl
    140         inc     hl
    141         jp      1$      ; next command
    142 
    143 7$:                     ; string copy
    144         and     #63
    145         inc     a
    146         ld      c,a
    147 15$:
    148         WAIT_STAT
    149         ld      a,(hl+)
    150         ld      (de),a
    151         inc     de
    152         WRAP_VRAM d
    153         dec     c
    154         jr      nz, 15$
    155 
    156         jp      1$      ; next command
    157 9$:
    158         pop     de
    159         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.