Last active
August 29, 2015 14:04
-
-
Save adamsmasher/1c5d779e37078f24d682 to your computer and use it in GitHub Desktop.
LZSS (Sharp LR35902 ASM)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; HL = src | |
;; DE = dest | |
Decompress:: | |
.chunk LD A, [HLI] ; get flags | |
LD B, A ; put flags in B | |
LD C, 8 ; 8 commands per chunk | |
.command LD A, [HLI] ; get next byte | |
BIT 0, B ; is this flag hi? | |
JR NZ, .literal ; if so, we have a literal | |
AND A ; otherwise, check for EOF | |
RET Z | |
LDH [$80], A ; store length to copy | |
LD A, [HLI] ; get -offset | |
PUSH HL ; backup read location | |
ADD E ; newLoc = E + (-offset) | |
LD L, A | |
LD H, D | |
JR c, .nowrap | |
DEC H | |
.nowrap LDH A, [$80] ; get length | |
PUSH BC ; backup flags | |
LD B, A | |
CALL Copy ; HL = SRC, DE = DEST, B = LEN | |
POP BC | |
POP HL ; get pointer to compressed data | |
JR .nextbyte | |
.literal LD [DE], A | |
INC DE | |
.nextbyte SRL B ; move to next flag | |
DEC C ; one less command | |
JR NZ, .command | |
JR .chunk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment