;------------------------------------------------------------------------------
; EXOMIZER 2.09 Z80 DECODER BY METALBRAIN AND OPTIMIZED BY ANTONIO VILLENA
; COMPRESSION ALGORITHM BY MAGNUS LIND
;
; INPUT HL = COMPRESSED DATA START
; DE = UNCOMPRESSED DESTINATION START
; EXO_MAPBASEBITS = BUFFER OF 156 BYTES
;------------------------------------------------------------------------------
EXO_MAPBASEBITS EQU &A000
ORG #8000
LD H,(IX+3)
LD L,(IX+2)
LD D,(IX+1)
LD E,(IX+0)
DI
CALL EXO_DEEXO
EI
RET
EXO_DEEXO LD IY, EXO_MAPBASEBITS
LD A, (HL)
INC HL
LD B,52
PUSH DE
EXO_INITBITS EX AF,AF'
LD A,B
SUB 4
AND 15
JR NZ,EXO_NODE1
LD DE,1 ;DE=B2
EXO_NODE1 LD C,16
EX AF,AF'
EXO_GET4BITS CALL EXO_GETBIT
RL C
JR NC,EXO_GET4BITS
LD (IY+0),C ;BITS[I]=B1
PUSH HL
LD HL, 1
DEFB 210 ;3 BYTES NOP (JP NC)
EXO_SETBIT ADD HL,HL
DEC C
JR NZ,EXO_SETBIT
LD (IY+52),E
LD (IY+104),D ;BASE[I]=B2
ADD HL,DE
EX DE,HL
INC IY
POP HL
DJNZ EXO_INITBITS
POP DE
DB 218 ;3 BYTES NOP (JP C) --> JR EXO_MAINLOOP
EXO_LITERALCOPY LDIR
EXO_MAINLOOP LD C,1 ;LENGHT=1
CALL EXO_GETBIT ;LITERAL?
JR C,EXO_LITERALCOPY
LD C,255
EXO_GETINDEX INC C
CALL EXO_GETBIT
JR NC,EXO_GETINDEX
BIT 4,C
JR Z, EXO_CONTINUE
BIT 0,C
RET Z
PUSH DE
LD D,16
CALL EXO_GETBITS
POP DE
JR EXO_LITERALCOPY
EXO_CONTINUE PUSH DE
CALL EXO_GETPAIR
PUSH BC
POP IX
LD DE,512+48 ;2 BITS, 48 OFFSET
INC B
DJNZ EXO_DONTGO
DEC C
JR Z, EXO_GOFORIT
DEC C ;2?
EXO_DONTGO LD DE,1024+32 ;4 BITS, 32 OFFSET
JR Z,EXO_GOFORIT
LD E,16 ;16 OFFSET
EXO_GOFORIT CALL EXO_GETBITS
EX AF,AF'
LD A,E
ADD A,C
LD C,A
EX AF,AF'
CALL EXO_GETPAIR
POP DE ;BC=OFFSET
PUSH HL ;DE=DESTINATION
LD H,D
LD L,E
SBC HL,BC ;HL=ORIGIN
PUSH IX
POP BC ;BC=LENGHT
LDIR
POP HL ;KEEP HL, DE IS UPDATED
JR EXO_MAINLOOP ;NEXT!
EXO_GETPAIR LD IY,EXO_MAPBASEBITS
LD B,0
ADD IY,BC
LD D,(IY+0)
CALL EXO_GETBITS
PUSH HL
LD L,(IY+52)
LD H,(IY+104)
ADD HL,BC ;ALWAYS CLEAR C FLAG
LD B,H
LD C,L
POP HL
RET
EXO_GETBITS LD BC,0 ;GET D BITS IN BC
EXO_GETTINGBITS DEC D
RET M
CALL EXO_GETBIT
RL C
RL B
JR EXO_GETTINGBITS
EXO_GETBIT SRL A ;GET ONE BIT
RET NZ
LD A,(HL)
INC HL
RRA
RET