-
Notifications
You must be signed in to change notification settings - Fork 2
/
lz48decrunch_v006_180_size.asm
86 lines (68 loc) · 1.14 KB
/
lz48decrunch_v006_180_size.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
;
; 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)
; Modif ; AF, BC, DE, HL
LZ48_decrunch
ldi
ld b,0
jr nextsequence
loop:
push af
rrca
rrca
rrca
rrca
and 0fh
cp 0fh ; more bytes for literal length?
call nc,getadditionallength
copyliteral
ld c,a
ldir
pop af
and 0fh
lzunpack
cp 0fh ; more bytes for match length?
inc a
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
inc bc
inc bc
ldir
pop hl
nextsequence
ld a,(hl)
inc hl
cp 10h
jr nc, loop
jr lzunpack
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