-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlz48decrunch_v006_180_speed.asm
115 lines (98 loc) · 1.63 KB
/
lz48decrunch_v006_180_speed.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;
; LZ48 decrunch
;
; In ; HL=compressed data address
; ; DE=output data address
; Out ; HL last address of compressed data read (you must inc once for LZ48 stream)
; ; DE last address of decrunched data write +1
; ; BC always 1
; ; A always zero
; ; flags (Z,NC,P,PE)
; ; HL' address of lzunpack(if OPTIMIZE_JUMP=2)
; ; E' undetermined
; ; BC' always 0f10h
; Modif ; AF, BC, DE, HL, BC', E', HL'
;DEFINE OPTIMIZE_JUMP 2
LZ48_decrunch
ldi
ld b,0
exx
ld bc,0f10h
IFNDEF OPTIMIZE_JUMP
ELSE
IF OPTIMIZE_JUMP=2
ld hl,lzunpack
ENDIF
ENDIF
exx
jr nextsequence
loop:
ld e,a
rrca
rrca
rrca
rrca
and b
cp b ; more bytes for literal length?
exx
call nc,getadditionallength
copyliteral
ld c,a
ldir
exx
ld a,e
and b
lzunpack
cp b ; more bytes for match length?
inc a
exx
call nc,getadditionallength
readoffset
ld c,a
; read encoded offset
sbc a,(hl)
sub c
ret z ; LZ48 end with zero offset
inc hl
push hl
; source=dest-copyoffset
; A != 0 here
ld l,a
ld h,0ffh
add hl,de
ldir
inc b
ldi
ldi
pop hl
nextsequence
ld a,(hl)
inc hl
exx
cp c
jr nc,loop
IFNDEF OPTIMIZE_JUMP
jr lzunpack ; no literal bytes
ELSE
IF OPTIMIZE_JUMP=2
jp (hl)
ELSE
IF OPTIMIZE_JUMP=1
jp lzunpack ; no literal bytes
ELSE
jr lzunpack ; no literal bytes
ENDIF
ENDIF
ENDIF
lengthNC
scf
lengthC
inc c
ret nz
getadditionallength
ld c,(hl) ; get additional literal length byte
inc hl
add a,c ; compute literal length total
jr nc,lengthNC
inc b
jr lengthC