From d1245c7d6a700c514c34c4da5d7eea4f868d479b Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Fri, 21 Jun 2019 17:39:50 +0200 Subject: [PATCH] Fix small typo in z80 depackers --- asm/z80/unlzs | 69 ++++++++++++++++++++++++++++++++++++ asm/z80/unlzsa2_small_v1.asm | 2 +- asm/z80/unlzsa_fast_v1.asm | 2 +- asm/z80/unlzsa_small_v1.asm | 2 +- 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 asm/z80/unlzs diff --git a/asm/z80/unlzs b/asm/z80/unlzs new file mode 100644 index 0000000..0c0d881 --- /dev/null +++ b/asm/z80/unlzs @@ -0,0 +1,69 @@ +; +; Size-optimized LZSA decompressor by spke (v.1 23/04/2019, 69 bytes) +; +; The data must be compressed using the command line compressor by Emmanuel Marty +; The compression is done as follows: +; +; lzsa.exe -r +; +; where option -r asks for the generation of raw (frame-less) data. +; +; The decompression is done in the standard way: +; +; ld hl,CompressedData +; ld de,WhereToDecompress +; call DecompressLZSA +; +; Of course, LZSA compression algorithm is (c) 2019 Emmanuel Marty, +; see https://github.com/emmanuel-marty/lzsa for more information +; +; Drop me an email if you have any comments/ideas/suggestions: zxintrospec@gmail.com +; + +@DecompressLZSA: + ld b,0 + + ; first a byte token "O|LLL|MMMM" is read from the stream, + ; where LLL is the number of literals and MMMM is + ; a length of the match that follows after the literals +ReadToken: ld a,(hl) : exa : ld a,(hl) : inc hl + and #70 : jr z,NoLiterals + + rrca : rrca : rrca : rrca ; LLL<7 means 0..6 literals... + cp #07 : call z,ReadLongBA ; LLL=7 means 7+ literals... + + ld c,a : ldir + + ; next we read the low byte of the -offset +NoLiterals: push de : ld e,(hl) : inc hl : ld d,#FF + ; the top bit of token is set if + ; the offset contains the high byte as well + exa : or a : jp p,ShortOffset + +LongOffset: ld d,(hl) : inc hl + + ; last but not least, the match length is read +ShortOffset: and #0F : add 3 ; MMMM<15 means match lengths 0+3..14+3 + cp 15+3 : call z,ReadLongBA ; MMMM=15 means lengths 14+3+ + ld c,a + + ex (sp),hl : push hl ; BC = len, DE = -offset, HL = dest, SP ->[dest,src] + add hl,de : pop de ; BC = len, DE = dest, HL = dest+(-offset), SP->[src] + ldir : pop hl ; BC = 0, DE = dest, HL = src + jr ReadToken + + ; a standard routine to read extended codes + ; into registers B (higher byte) and A (lower byte). +ReadLongBA: add (hl) : inc hl : ret nc + + ; the codes are designed to overflow; + ; the overflow value 1 means read 1 extra byte + ; and overflow value 0 means read 2 extra bytes +.code1: ld b,a : ld a,(hl) : inc hl : ret nz +.code0: ld c,a : ld b,(hl) : inc hl + + ; the two-byte match length equal to zero + ; designates the end-of-data marker + or b : ld a,c : ret nz + pop de : pop de : ret + diff --git a/asm/z80/unlzsa2_small_v1.asm b/asm/z80/unlzsa2_small_v1.asm index 7608b74..99df8bb 100644 --- a/asm/z80/unlzsa2_small_v1.asm +++ b/asm/z80/unlzsa2_small_v1.asm @@ -1,7 +1,7 @@ ; ; Size-optimized LZSA2 decompressor by spke (v.1 02-09/06/2019, 145 bytes) ; -; The data must be comressed using the command line compressor by Emmanuel Marty +; The data must be compressed using the command line compressor by Emmanuel Marty ; The compression is done as follows: ; ; lzsa.exe -f2 -r diff --git a/asm/z80/unlzsa_fast_v1.asm b/asm/z80/unlzsa_fast_v1.asm index a2354df..226bc67 100755 --- a/asm/z80/unlzsa_fast_v1.asm +++ b/asm/z80/unlzsa_fast_v1.asm @@ -1,7 +1,7 @@ ; ; Speed-optimized LZSA decompressor by spke (v.1 03-25/04/2019, 110 bytes) ; -; The data must be comressed using the command line compressor by Emmanuel Marty +; The data must be compressed using the command line compressor by Emmanuel Marty ; The compression is done as follows: ; ; lzsa.exe -r diff --git a/asm/z80/unlzsa_small_v1.asm b/asm/z80/unlzsa_small_v1.asm index f8cf5a5..4039948 100755 --- a/asm/z80/unlzsa_small_v1.asm +++ b/asm/z80/unlzsa_small_v1.asm @@ -1,7 +1,7 @@ ; ; Size-optimized LZSA decompressor by spke (v.1 23/04/2019, 69 bytes) ; -; The data must be comressed using the command line compressor by Emmanuel Marty +; The data must be compressed using the command line compressor by Emmanuel Marty ; The compression is done as follows: ; ; lzsa.exe -r