From fcfba056d2f00d275e918d498b6fef8e6c0677bc Mon Sep 17 00:00:00 2001 From: introspec <31136975+specke@users.noreply.github.com> Date: Wed, 24 Jul 2019 17:28:39 +0100 Subject: [PATCH 1/4] Add files via upload LZSA2 decompressors with support for -b option. --- asm/z80/unlzsa2_fast_v1.asm | 107 ++++++++++++++++++++++++++--------- asm/z80/unlzsa2_small_v1.asm | 84 +++++++++++++++++++++++---- 2 files changed, 151 insertions(+), 40 deletions(-) diff --git a/asm/z80/unlzsa2_fast_v1.asm b/asm/z80/unlzsa2_fast_v1.asm index b6a1d31..7274e68 100644 --- a/asm/z80/unlzsa2_fast_v1.asm +++ b/asm/z80/unlzsa2_fast_v1.asm @@ -10,15 +10,74 @@ ; ; The decompression is done in the standard way: ; -; ld hl,CompressedData -; ld de,WhereToDecompress +; ld hl,FirstByteOfCompressedData +; ld de,FirstByteOfMemoryForDecompressedData ; call DecompressLZSA2 ; +; Backward compression is also supported; you can compress files backward using: +; +; lzsa.exe -f2 -r -b +; +; and decompress the resulting files using: +; +; ld hl,LastByteOfCompressedData +; ld de,LastByteOfMemoryForDecompressedData +; call DecompressLZSA2 +; +; (do not forget to uncomment the BACKWARD_DECOMPRESS option in the decompressor). +; ; Of course, LZSA2 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 ; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source distribution. + +; DEFINE BACKWARD_DECOMPRESS + + IFDEF BACKWARD_DECOMPRESS + + MACRO NEXT_HL + dec hl + ENDM + + MACRO ADD_OFFSET + or a : sbc hl,de + ENDM + + MACRO BLOCKCOPY + lddr + ENDM + + ELSE + + MACRO NEXT_HL + inc hl + ENDM + + MACRO ADD_OFFSET + add hl,de + ENDM + + MACRO BLOCKCOPY + ldir + ENDM + + ENDIF @DecompressLZSA2: ; A' stores next nibble as %1111.... or assumed to contain trash @@ -32,16 +91,16 @@ LongerMatch: exa : jp m,.noUpdate ld a,(hl) : or #F0 : exa - ld a,(hl) : inc hl : or #0F + ld a,(hl) : NEXT_HL : or #0F rrca : rrca : rrca : rrca .noUpdate sub #F0-9 : cp 15+9 : jr c,CopyMatch ;inc a : jr z,LongMatch : sub #F0-9+1 : jp CopyMatch LongMatch: ;ld a,24 : - add (hl) : inc hl : jr nc,CopyMatch - ld c,(hl) : inc hl - ld b,(hl) : inc hl + add (hl) : NEXT_HL : jr nc,CopyMatch + ld c,(hl) : NEXT_HL + ld b,(hl) : NEXT_HL jr nz,CopyMatch.useC pop de : ret @@ -49,19 +108,19 @@ LongMatch: ;ld a,24 : ManyLiterals: ld a,18 : - add (hl) : inc hl : jr nc,CopyLiterals - ld c,(hl) : inc hl + add (hl) : NEXT_HL : jr nc,CopyLiterals + ld c,(hl) : NEXT_HL ld a,b : ld b,(hl) : inc hl jr CopyLiterals.useBC -MoreLiterals: ld b,(hl) : inc hl +MoreLiterals: ld b,(hl) : NEXT_HL exa : jp m,.noUpdate ld a,(hl) : or #F0 : exa - ld a,(hl) : inc hl : or #0F + ld a,(hl) : NEXT_HL : or #0F rrca : rrca : rrca : rrca .noUpdate ;sub #F0-3 : cp 15+3 : jr z,ManyLiterals @@ -69,7 +128,7 @@ MoreLiterals: ld b,(hl) : inc hl CopyLiterals: ld c,a .useC ld a,b : ld b,0 -.useBC ldir +.useBC BLOCKCOPY push de : or a : jp p,CASE0xx : jr CASE1xx @@ -78,7 +137,7 @@ CopyLiterals: ld c,a ; if "LL" of the byte token is equal to 0, ; there are no literals to copy -NoLiterals: xor (hl) : inc hl +NoLiterals: xor (hl) : NEXT_HL push de : jp m,CASE1xx ; short (5 or 9 bit long) offsets @@ -87,7 +146,7 @@ CASE0xx ld d,#FF : cp %01000000 : jr c,CASE00x ; "01x": the case of the 9-bit offset CASE01x: cp %01100000 : rl d -ReadOffsetE: ld e,(hl) : inc hl +ReadOffsetE: ld e,(hl) : NEXT_HL SaveOffset: ld ixl,e : ld ixh,d @@ -95,8 +154,8 @@ MatchLen: inc a : and %00000111 : jr z,LongerMatch : inc a CopyMatch: ld c,a .useC 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 + ADD_OFFSET : pop de ; BC = len, DE = dest, HL = dest-offset, SP->[src] + BLOCKCOPY : pop hl ; compressed data stream contains records ; each record begins with the byte token "XYZ|LL|MMM" @@ -105,8 +164,8 @@ ReadToken: ld a,(hl) : and %00011000 : jr z,NoLiterals jp pe,MoreLiterals ; 00 has already been processed; this identifies the case of 11 rrca : rrca : rrca - ld c,a : ld a,(hl) : inc hl ; token is re-read for further processing - ldir + ld c,a : ld a,(hl) : NEXT_HL ; token is re-read for further processing + BLOCKCOPY ; the token and literals are followed by the offset push de : or a : jp p,CASE0xx @@ -118,7 +177,7 @@ CASE10x: ld c,a : xor a exa : jp m,.noUpdate ld a,(hl) : or #F0 : exa - ld a,(hl) : inc hl : or #0F + ld a,(hl) : NEXT_HL : or #0F rrca : rrca : rrca : rrca .noUpdate ld d,a : ld a,c @@ -130,7 +189,7 @@ CASE00x: ld c,a : xor a exa : jp m,.noUpdate ld a,(hl) : or #F0 : exa - ld a,(hl) : inc hl : or #0F + ld a,(hl) : NEXT_HL : or #0F rrca : rrca : rrca : rrca .noUpdate ld e,a : ld a,c @@ -143,15 +202,7 @@ CASE11x cp %11100000 : jr c,CASE110 CASE111: ld e,ixl : ld d,ixh : jr MatchLen ; "110": 16-bit offset -CASE110: ld d,(hl) : inc hl : jr ReadOffsetE - -;ReadNibble: ; 17 bytes, 44 t-state per nibble -; exa : ret m ; 4+11 = 15t -;UpdateNibble: -; ld a,(hl) : or #F0 : exa -; ld a,(hl) : inc hl : or #0F -; rrca : rrca : rrca : rrca : ret ; 4+5 + 7+7+4+7+6+7+4+4+4+4+10 = 73t - +CASE110: ld d,(hl) : NEXT_HL : jr ReadOffsetE diff --git a/asm/z80/unlzsa2_small_v1.asm b/asm/z80/unlzsa2_small_v1.asm index 99df8bb..a2697e7 100644 --- a/asm/z80/unlzsa2_small_v1.asm +++ b/asm/z80/unlzsa2_small_v1.asm @@ -10,15 +10,75 @@ ; ; The decompression is done in the standard way: ; -; ld hl,CompressedData -; ld de,WhereToDecompress +; ld hl,FirstByteOfCompressedData +; ld de,FirstByteOfMemoryForDecompressedData ; call DecompressLZSA2 ; +; Backward compression is also supported; you can compress files backward using: +; +; lzsa.exe -f2 -r -b +; +; and decompress the resulting files using: +; +; ld hl,LastByteOfCompressedData +; ld de,LastByteOfMemoryForDecompressedData +; call DecompressLZSA2 +; +; (do not forget to uncomment the BACKWARD_DECOMPRESS option in the decompressor). +; ; Of course, LZSA2 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 ; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source distribution. +; + +; DEFINE BACKWARD_DECOMPRESS + + IFDEF BACKWARD_DECOMPRESS + + MACRO NEXT_HL + dec hl + ENDM + + MACRO ADD_OFFSET + or a : sbc hl,de + ENDM + + MACRO BLOCKCOPY + lddr + ENDM + + ELSE + + MACRO NEXT_HL + inc hl + ENDM + + MACRO ADD_OFFSET + add hl,de + ENDM + + MACRO BLOCKCOPY + ldir + ENDM + + ENDIF @DecompressLZSA2: xor a : ld b,a : exa : jr ReadToken @@ -27,7 +87,7 @@ CASE0xx ld d,#FF : cp %01000000 : jr c,CASE00x CASE01x: cp %01100000 : rl d -OffsetReadE: ld e,(hl) : inc hl +OffsetReadE: ld e,(hl) : NEXT_HL SaveOffset: ld iyl,e : ld iyh,d @@ -35,17 +95,17 @@ MatchLen: and %00000111 : add 2 : cp 9 : call z,ExtendedCode CopyMatch: 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 + ADD_OFFSET : pop de ; BC = len, DE = dest, HL = dest-offset, SP->[src] + BLOCKCOPY : pop hl -ReadToken: ld a,(hl) : ld ixl,a : inc hl +ReadToken: ld a,(hl) : ld ixl,a : NEXT_HL and %00011000 : jr z,NoLiterals rrca : rrca : rrca call pe,ExtendedCode ld c,a - ldir + BLOCKCOPY NoLiterals: push de : ld a,ixl or a : jp p,CASE0xx @@ -65,18 +125,18 @@ CASE11x cp %11100000 : jr c,CASE110 CASE111: ld e,iyl : ld d,iyh : jr MatchLen -CASE110: ld d,(hl) : inc hl : jr OffsetReadE +CASE110: ld d,(hl) : NEXT_HL : jr OffsetReadE ExtendedCode: call ReadNibble : inc a : jr z,ExtraByte sub #F0+1 : add c : ret -ExtraByte ld a,15 : add c : add (hl) : inc hl : ret nc - ld a,(hl) : inc hl - ld b,(hl) : inc hl : ret nz +ExtraByte ld a,15 : add c : add (hl) : NEXT_HL : ret nc + ld a,(hl) : NEXT_HL + ld b,(hl) : NEXT_HL : ret nz pop de : pop de : ret ReadNibble: ld c,a : xor a : exa : ret m UpdateNibble ld a,(hl) : or #F0 : exa - ld a,(hl) : inc hl : or #0F + ld a,(hl) : NEXT_HL : or #0F rrca : rrca : rrca : rrca : ret From fd61f403ad751b4dc70876f43dbd313298530fa3 Mon Sep 17 00:00:00 2001 From: introspec <31136975+specke@users.noreply.github.com> Date: Wed, 24 Jul 2019 17:30:37 +0100 Subject: [PATCH 2/4] LZSA1 decompressors with added support for -b. --- asm/z80/unlzsa1_fast_v1.asm | 145 +++++++++++++++++++++++++++++++++++ asm/z80/unlzsa1_small_v1.asm | 128 +++++++++++++++++++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 asm/z80/unlzsa1_fast_v1.asm create mode 100644 asm/z80/unlzsa1_small_v1.asm diff --git a/asm/z80/unlzsa1_fast_v1.asm b/asm/z80/unlzsa1_fast_v1.asm new file mode 100644 index 0000000..b8443cd --- /dev/null +++ b/asm/z80/unlzsa1_fast_v1.asm @@ -0,0 +1,145 @@ +; +; Speed-optimized LZSA decompressor by spke (v.1 03-25/04/2019, 110 bytes) +; +; The data must be compressed using the command line compressor by Emmanuel Marty +; The compression is done as follows: +; +; lzsa.exe -f1 -r +; +; where option -r asks for the generation of raw (frame-less) data. +; +; The decompression is done in the standard way: +; +; ld hl,FirstByteOfCompressedData +; ld de,FirstByteOfMemoryForDecompressedData +; call DecompressLZSA +; +; Backward compression is also supported; you can compress files backward using: +; +; lzsa.exe -f1 -r -b +; +; and decompress the resulting files using: +; +; ld hl,LastByteOfCompressedData +; ld de,LastByteOfMemoryForDecompressedData +; call DecompressLZSA +; +; (do not forget to uncomment the BACKWARD_DECOMPRESS option in the decompressor). +; +; 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 +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source distribution. + +; DEFINE BACKWARD_DECOMPRESS + + IFDEF BACKWARD_DECOMPRESS + + MACRO NEXT_HL + dec hl + ENDM + + MACRO ADD_OFFSET + or a : sbc hl,de + ENDM + + MACRO BLOCKCOPY + lddr + ENDM + + ELSE + + MACRO NEXT_HL + inc hl + ENDM + + MACRO ADD_OFFSET + add hl,de + ENDM + + MACRO BLOCKCOPY + ldir + ENDM + + ENDIF + +@DecompressLZSA: + ld b,0 : jr ReadToken + +NoLiterals: xor (hl) : NEXT_HL + push de : ld e,(hl) : NEXT_HL : jp m,LongOffset + + ; short matches have length 0+3..14+3 +ShortOffset: ld d,#FF : add 3 : cp 15+3 : jr nc,LongerMatch + + ; placed here this saves a JP per iteration +CopyMatch: ld c,a +.UseC ex (sp),hl : push hl ; BC = len, DE = offset, HL = dest, SP ->[dest,src] + ADD_OFFSET : pop de ; BC = len, DE = dest, HL = dest-offset, SP->[src] + BLOCKCOPY : pop hl ; BC = 0, DE = dest, HL = src + +ReadToken: ; 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 + ld a,(hl) : and #70 : jr z,NoLiterals + + cp #70 : jr z,MoreLiterals ; LLL=7 means 7+ literals... + rrca : rrca : rrca : rrca ; LLL<7 means 0..6 literals... + + ld c,a : ld a,(hl) : NEXT_HL + BLOCKCOPY + + ; next we read the first byte of the offset + push de : ld e,(hl) : NEXT_HL + ; the top bit of token is set if the offset contains two bytes + and #8F : jp p,ShortOffset + +LongOffset: ; read second byte of the offset + ld d,(hl) : NEXT_HL + add -128+3 : cp 15+3 : jp c,CopyMatch + + ; MMMM=15 indicates a multi-byte number of literals +LongerMatch: add (hl) : NEXT_HL : jr nc,CopyMatch + + ; 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 c,(hl) : NEXT_HL : jr nz,CopyMatch.UseC +.code0 ld b,(hl) : NEXT_HL + + ; the two-byte match length equal to zero + ; designates the end-of-data marker + ld a,b : or c : jr nz,CopyMatch.UseC + pop de : ret + +MoreLiterals: ; there are three possible situations here + xor (hl) : NEXT_HL : exa + ld a,7 : add (hl) : NEXT_HL : jr c,ManyLiterals + +CopyLiterals: ld c,a +.UseC BLOCKCOPY + + push de : ld e,(hl) : NEXT_HL + exa : jp p,ShortOffset : jr LongOffset + +ManyLiterals: +.code1 ld b,a : ld c,(hl) : NEXT_HL : jr nz,CopyLiterals.UseC +.code0 ld b,(hl) : NEXT_HL : jr CopyLiterals.UseC + + diff --git a/asm/z80/unlzsa1_small_v1.asm b/asm/z80/unlzsa1_small_v1.asm new file mode 100644 index 0000000..df4dfc5 --- /dev/null +++ b/asm/z80/unlzsa1_small_v1.asm @@ -0,0 +1,128 @@ +; +; 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 -f1 -r +; +; where option -r asks for the generation of raw (frame-less) data. +; +; The decompression is done in the standard way: +; +; ld hl,FirstByteOfCompressedData +; ld de,FirstByteOfMemoryForDecompressedData +; call DecompressLZSA +; +; Backward compression is also supported; you can compress files backward using: +; +; lzsa.exe -f1 -r -b +; +; and decompress the resulting files using: +; +; ld hl,LastByteOfCompressedData +; ld de,LastByteOfMemoryForDecompressedData +; call DecompressLZSA +; +; (do not forget to uncomment the BACKWARD_DECOMPRESS option in the decompressor). +; +; 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 +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source distribution. + +; DEFINE BACKWARD_DECOMPRESS + + IFDEF BACKWARD_DECOMPRESS + + MACRO NEXT_HL + dec hl + ENDM + + MACRO ADD_OFFSET + or a : sbc hl,de + ENDM + + MACRO BLOCKCOPY + lddr + ENDM + + ELSE + + MACRO NEXT_HL + inc hl + ENDM + + MACRO ADD_OFFSET + add hl,de + ENDM + + MACRO BLOCKCOPY + ldir + ENDM + + ENDIF + +@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) : NEXT_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 : BLOCKCOPY + + ; next we read the low byte of the -offset +NoLiterals: push de : ld e,(hl) : NEXT_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) : NEXT_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_OFFSET : pop de ; BC = len, DE = dest, HL = dest+(-offset), SP->[src] + BLOCKCOPY : 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) : NEXT_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) : NEXT_HL : ret nz +.code0: ld c,a : ld b,(hl) : NEXT_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 + From 607b26d3372f67bbaba1978bc77509c98c468f8d Mon Sep 17 00:00:00 2001 From: introspec <31136975+specke@users.noreply.github.com> Date: Wed, 24 Jul 2019 17:31:14 +0100 Subject: [PATCH 3/4] Delete unlzsa_fast_v1.asm --- asm/z80/unlzsa_fast_v1.asm | 101 ------------------------------------- 1 file changed, 101 deletions(-) delete mode 100755 asm/z80/unlzsa_fast_v1.asm diff --git a/asm/z80/unlzsa_fast_v1.asm b/asm/z80/unlzsa_fast_v1.asm deleted file mode 100755 index 226bc67..0000000 --- a/asm/z80/unlzsa_fast_v1.asm +++ /dev/null @@ -1,101 +0,0 @@ -; -; Speed-optimized LZSA decompressor by spke (v.1 03-25/04/2019, 110 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 -; -; This software is provided 'as-is', without any express or implied -; warranty. In no event will the authors be held liable for any damages -; arising from the use of this software. -; -; Permission is granted to anyone to use this software for any purpose, -; including commercial applications, and to alter it and redistribute it -; freely, subject to the following restrictions: -; -; 1. The origin of this software must not be misrepresented; you must not -; claim that you wrote the original software. If you use this software -; in a product, an acknowledgment in the product documentation would be -; appreciated but is not required. -; 2. Altered source versions must be plainly marked as such, and must not be -; misrepresented as being the original software. -; 3. This notice may not be removed or altered from any source distribution. - -@DecompressLZSA: - ld b,0 : jr ReadToken - -NoLiterals: xor (hl) : inc hl - push de : ld e,(hl) : inc hl : jp m,LongOffset - - ; short matches have length 0+3..14+3 -ShortOffset: ld d,#FF : add 3 : cp 15+3 : jr nc,LongerMatch - - ; placed here this saves a JP per iteration -CopyMatch: ld c,a -.UseC 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 - -ReadToken: ; 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 - ld a,(hl) : and #70 : jr z,NoLiterals - - cp #70 : jr z,MoreLiterals ; LLL=7 means 7+ literals... - rrca : rrca : rrca : rrca ; LLL<7 means 0..6 literals... - - ld c,a : ld a,(hl) : inc hl - ldir - - ; next we read the first byte of the offset - push de : ld e,(hl) : inc hl - ; the top bit of token is set if the offset contains two bytes - and #8F : jp p,ShortOffset - -LongOffset: ; read second byte of the offset - ld d,(hl) : inc hl - add -128+3 : cp 15+3 : jp c,CopyMatch - - ; MMMM=15 indicates a multi-byte number of literals -LongerMatch: add (hl) : inc hl : jr nc,CopyMatch - - ; 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 c,(hl) : inc hl : jr nz,CopyMatch.UseC -.code0 ld b,(hl) : inc hl - - ; the two-byte match length equal to zero - ; designates the end-of-data marker - ld a,b : or c : jr nz,CopyMatch.UseC - pop de : ret - -MoreLiterals: ; there are three possible situations here - xor (hl) : inc hl : exa - ld a,7 : add (hl) : inc hl : jr c,ManyLiterals - -CopyLiterals: ld c,a -.UseC ldir - - push de : ld e,(hl) : inc hl - exa : jp p,ShortOffset : jr LongOffset - -ManyLiterals: -.code1 ld b,a : ld c,(hl) : inc hl : jr nz,CopyLiterals.UseC -.code0 ld b,(hl) : inc hl : jr CopyLiterals.UseC - - From cca79e3e597b7147ec2dd72090cfc799758f1c86 Mon Sep 17 00:00:00 2001 From: introspec <31136975+specke@users.noreply.github.com> Date: Wed, 24 Jul 2019 17:31:22 +0100 Subject: [PATCH 4/4] Delete unlzsa_small_v1.asm --- asm/z80/unlzsa_small_v1.asm | 85 ------------------------------------- 1 file changed, 85 deletions(-) delete mode 100755 asm/z80/unlzsa_small_v1.asm diff --git a/asm/z80/unlzsa_small_v1.asm b/asm/z80/unlzsa_small_v1.asm deleted file mode 100755 index 4039948..0000000 --- a/asm/z80/unlzsa_small_v1.asm +++ /dev/null @@ -1,85 +0,0 @@ -; -; 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 -; -; This software is provided 'as-is', without any express or implied -; warranty. In no event will the authors be held liable for any damages -; arising from the use of this software. -; -; Permission is granted to anyone to use this software for any purpose, -; including commercial applications, and to alter it and redistribute it -; freely, subject to the following restrictions: -; -; 1. The origin of this software must not be misrepresented; you must not -; claim that you wrote the original software. If you use this software -; in a product, an acknowledgment in the product documentation would be -; appreciated but is not required. -; 2. Altered source versions must be plainly marked as such, and must not be -; misrepresented as being the original software. -; 3. This notice may not be removed or altered from any source distribution. -; - -@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 -