-
Notifications
You must be signed in to change notification settings - Fork 1
/
decrunch.asm
91 lines (78 loc) · 1.09 KB
/
decrunch.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
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
.module DECRUNCH
; http://www.cpcwiki.eu/forum/programming/lz48-cruncherdecruncher/
decrunch:
ldi
ld b,0
nextsequence:
ld a,(hl)
inc hl
ld (lx),a
and $f0
jr z,lzunpack ; no litteral bytes
rrca
rrca
rrca
rrca
ld c,a
cp 15 ; more bytes for length?
jr nz,copyliteral
getadditionallength:
ld a,(hl)
inc hl
inc a
jr nz,lengthnext
inc b
dec bc
jr getadditionallength
lengthnext:
dec a
add a,c
ld c,a
ld a,b
adc a,0
ld b,a ; bc=length
copyliteral:
ldir
lzunpack:
ld a,(lx)
and $f
add a,3
ld c,a
cp 18 ; more bytes for length?
jr nz,readoffset
getadditionallengthbis:
ld a,(hl)
inc hl
inc a
jr nz,lengthnextbis
inc b
dec bc
jr getadditionallengthbis
lengthnextbis:
dec a
add a,c
ld c,a
ld a,b
adc a,0
ld b,a ; bc=length
readoffset:
; read encoded offset
ld a,(hl)
inc a
ret z ; LZ48 end with zero offset
inc hl
push hl
ld l,a
ld a,e
sub l
ld l,a
ld a,d
sbc a,0
ld h,a
; source=dest-copyoffset
copykey:
ldir
pop hl
jr nextsequence