gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit a2de13022eb11ba1f2d9290f509c2cc0bbb1616e parent c2a4e9c4ee95b69bd906997a0fc30c1834695985 Author: Toxa <untoxa@mail.ru> Date: Thu, 11 Sep 2025 15:03:44 +0300 GB, SMS, MSX: include ZX0 decompressor into the library Diffstat:
| M | gbdk-lib/include/gbdk/gbdecompress.h | 2 | +- |
| M | gbdk-lib/include/gbdk/rledecompress.h | 2 | +- |
| A | gbdk-lib/include/gbdk/zx0decompress.h | 11 | +++++++++++ |
| M | gbdk-lib/libc/targets/sm83/ap/Makefile | 1 | + |
| M | gbdk-lib/libc/targets/sm83/duck/Makefile | 1 | + |
| M | gbdk-lib/libc/targets/sm83/gb/Makefile | 1 | + |
| A | gbdk-lib/libc/targets/sm83/zx0_decompress.s | 121 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/z80/gg/Makefile | 1 | + |
| M | gbdk-lib/libc/targets/z80/msxdos/Makefile | 3 | +++ |
| M | gbdk-lib/libc/targets/z80/sms/Makefile | 1 | + |
| A | gbdk-lib/libc/targets/z80/zx0_decompress.s | 67 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 files changed, 209 insertions(+), 2 deletions(-)
diff --git a/gbdk-lib/include/gbdk/gbdecompress.h b/gbdk-lib/include/gbdk/gbdecompress.h @@ -3,7 +3,7 @@ #if defined(__TARGET_gb) || defined(__TARGET_ap) || defined(__TARGET_duck) #include <gb/gbdecompress.h> -#elif defined(__TARGET_sms) || defined(__TARGET_gg) +#elif defined(__TARGET_sms) || defined(__TARGET_gg) || defined(__TARGET_msx) #include <sms/gbdecompress.h> #else #error Unrecognized port diff --git a/gbdk-lib/include/gbdk/rledecompress.h b/gbdk-lib/include/gbdk/rledecompress.h @@ -38,7 +38,7 @@ uint8_t rle_init(void * data); @see rle_init */ uint8_t rle_decompress(void * dest, uint8_t len); -#elif defined(__TARGET_sms) || defined(__TARGET_gg) +#elif defined(__TARGET_sms) || defined(__TARGET_gg) || defined(__TARGET_msx) uint8_t rle_init(void * data) Z88DK_FASTCALL; uint8_t rle_decompress(void * dest, uint8_t len) Z88DK_CALLEE; #else diff --git a/gbdk-lib/include/gbdk/zx0decompress.h b/gbdk-lib/include/gbdk/zx0decompress.h @@ -0,0 +1,10 @@ +#ifndef __ZX0DECOMPRESS_H_INCLUDE +#define __ZX0DECOMPRESS_H_INCLUDE + +#if defined(__TARGET_gb) || defined(__TARGET_ap) || defined(__TARGET_duck) || defined(__TARGET_sms) || defined(__TARGET_gg) || defined(__TARGET_msx) + +void zx0_decompress(void * sour, void * dest); + +#endif + +#endif + diff --git a/gbdk-lib/libc/targets/sm83/ap/Makefile b/gbdk-lib/libc/targets/sm83/ap/Makefile @@ -34,6 +34,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_tile_submap.s set_win_tile_submap.s \ gb_decompress.s gb_decompress_tiles.s \ rle_decompress.s \ + zx0_decompress.s \ hblankcpy.s \ heap.s \ sfr.s \ diff --git a/gbdk-lib/libc/targets/sm83/duck/Makefile b/gbdk-lib/libc/targets/sm83/duck/Makefile @@ -35,6 +35,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_tile_submap.s set_win_tile_submap.s \ gb_decompress.s gb_decompress_tiles.s \ rle_decompress.s \ + zx0_decompress.s \ hblankcpy.s \ heap.s \ sfr.s \ diff --git a/gbdk-lib/libc/targets/sm83/gb/Makefile b/gbdk-lib/libc/targets/sm83/gb/Makefile @@ -34,6 +34,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_tile_submap.s set_win_tile_submap.s \ gb_decompress.s gb_decompress_tiles.s \ rle_decompress.s \ + zx0_decompress.s \ hblankcpy.s \ heap.s \ sfr.s \ diff --git a/gbdk-lib/libc/targets/sm83/zx0_decompress.s b/gbdk-lib/libc/targets/sm83/zx0_decompress.s @@ -0,0 +1,121 @@ +; ----------------------------------------------------------------------------- +; ZX0 decoder by Einar Saukas & Urusergi +; GBZ80 version by Tony Pavlov +; ----------------------------------------------------------------------------- + + .title "ZX0 Decompress" + .module ZX0Decompress + + .area _HRAM + +dzx0_temp:: + .ds 0x01 + + .area _CODE + +.macro EX_SP_HL + push de + ld a, l + ld d, h + ldhl sp, #2 + ld e, (hl) + ld (hl+), a + ld a, (hl) + ld (hl), d + ld h, a + ld l, e + pop de +.endm + +; ----------------------------------------------------------------------------- +; Parameters for the SDCC UNZX0() function: +; DE: source address (compressed data) +; BC: destination address (decompressing) +; ----------------------------------------------------------------------------- +_zx0_decompress:: + ld h, d + ld l, e + ld d, b + ld e, c + +; ----------------------------------------------------------------------------- +; Parameters: +; HL: source address (compressed data) +; DE: destination address (decompressing) +; ----------------------------------------------------------------------------- +dzx0_standard:: + ld bc, #0xffff ; preserve default offset 1 + push bc + inc bc + ld a, #0x80 +dzx0s_literals: + call dzx0s_elias ; obtain length + ldh (dzx0_temp), a + call dzx0_ldir ; copy literals + ldh a, (dzx0_temp) + add a, a ; copy from last offset or new offset? + jr c, dzx0s_new_offset + call dzx0s_elias ; obtain length +dzx0s_copy: + ldh (dzx0_temp), a + EX_SP_HL ; preserve source, restore offset + push hl ; preserve offset + add hl, de ; calculate destination - offset + call dzx0_ldir ; copy from offset + pop hl ; restore offset + EX_SP_HL ; preserve offset, restore source + ldh a, (dzx0_temp) + add a, a ; copy from literals or new offset? + jr nc, dzx0s_literals +dzx0s_new_offset: + pop bc ; discard last offset + ld c, #0xfe ; prepare negative offset + call dzx0s_elias_loop ; obtain offset MSB + inc c + ret z ; check end marker + ld b, c + ld c, (hl) ; obtain offset LSB + inc hl + rr b ; last offset bit becomes first length bit + rr c + push bc ; preserve new offset + ld bc, #1 ; obtain length + call nc, dzx0s_elias_backtrack + inc bc + jr dzx0s_copy +dzx0s_elias: + inc c ; interlaced Elias gamma coding +dzx0s_elias_loop: + add a, a + jr nz, dzx0s_elias_skip + ld a, (hl+) ; load another group of 8 bits + rla +dzx0s_elias_skip: + ret c +dzx0s_elias_backtrack: + add a, a + rl c + rl b + jr dzx0s_elias_loop +dzx0_ldir: + srl b + rr c + inc b + inc c + jr c, 0$ + jr 1$ +2$: + ld a, (hl+) + ld (de), a + inc de +0$: + ld a, (hl+) + ld (de), a + inc de +1$: + dec c + jr nz, 2$ + dec b + jr nz, 2$ + ret +; ----------------------------------------------------------------------------- diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -31,6 +31,7 @@ ASSRC = set_interrupts.s \ far_ptr.s \ gb_decompress.s \ rle_decompress.s \ + zx0_decompress.s \ heap.s \ __sdcc_bcall.s \ crt0.s diff --git a/gbdk-lib/libc/targets/z80/msxdos/Makefile b/gbdk-lib/libc/targets/z80/msxdos/Makefile @@ -23,6 +23,9 @@ ASSRC = set_interrupts.s \ memset_small.s \ far_ptr.s \ color.s \ + gb_decompress.s \ + rle_decompress.s \ + zx0_decompress.s \ heap.s \ __sdcc_bcall.s __sdcc_bcall_abc.s \ crt0.s diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -31,6 +31,7 @@ ASSRC = set_interrupts.s \ far_ptr.s \ gb_decompress.s \ rle_decompress.s \ + zx0_decompress.s \ heap.s \ __sdcc_bcall.s \ crt0.s diff --git a/gbdk-lib/libc/targets/z80/zx0_decompress.s b/gbdk-lib/libc/targets/z80/zx0_decompress.s @@ -0,0 +1,67 @@ +; ----------------------------------------------------------------------------- +; ZX0 decoder by Einar Saukas & Urusergi +; "Standard" version (68 bytes only) +; ----------------------------------------------------------------------------- +; Parameters: +; HL: source address (compressed data) +; DE: destination address (decompressing) +; ----------------------------------------------------------------------------- + + .title "ZX0 Decompress" + .module ZX0Decompress + + .area _CODE + +_zx0_decompress:: +dzx0_standard: + ld bc, #0xffff ; preserve default offset 1 + push bc + inc bc + ld a, #0x80 +dzx0s_literals: + call dzx0s_elias ; obtain length + ldir ; copy literals + add a, a ; copy from last offset or new offset? + jr c, dzx0s_new_offset + call dzx0s_elias ; obtain length +dzx0s_copy: + ex (sp), hl ; preserve source, restore offset + push hl ; preserve offset + add hl, de ; calculate destination - offset + ldir ; copy from offset + pop hl ; restore offset + ex (sp), hl ; preserve offset, restore source + add a, a ; copy from literals or new offset? + jr nc, dzx0s_literals +dzx0s_new_offset: + pop bc ; discard last offset + ld c, #0xfe ; prepare negative offset + call dzx0s_elias_loop ; obtain offset MSB + inc c + ret z ; check end marker + ld b, c + ld c, (hl) ; obtain offset LSB + inc hl + rr b ; last offset bit becomes first length bit + rr c + push bc ; preserve new offset + ld bc, #1 ; obtain length + call nc, dzx0s_elias_backtrack + inc bc + jr dzx0s_copy +dzx0s_elias: + inc c ; interlaced Elias gamma coding +dzx0s_elias_loop: + add a, a + jr nz, dzx0s_elias_skip + ld a, (hl) ; load another group of 8 bits + inc hl + rla +dzx0s_elias_skip: + ret c +dzx0s_elias_backtrack: + add a, a + rl c + rl b + jr dzx0s_elias_loop +; -----------------------------------------------------------------------------
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.