-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaplib247b_180_minimal.asm
143 lines (112 loc) · 3.93 KB
/
aplib247b_180_minimal.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
; aPPack decompressor
; original source by dwedit
; very slightly adapted by utopian
; optimized by Metalbrain & Antonio Villena
;247b to 152b optimized by uniabis
;hl = source
;de = dest
depack
init ld a,128
;;cap v1.2 with load address version requires to copy two bytes on top
;ldi
;ldi
apbranch1 ldi
aploop2 ld b,255
aploop call ap_getbit
jr nc,apbranch1
call ap_getbit
jr nc,apbranch2
call ap_getbit
jr nc,apbranch3
ld c,16 ;get an offset
apget4bits call ap_getbit
rl c
jr nc,apget4bits
jr nz,apbranch4
ex de,hl
ld (hl),c ;write a 0
ex de,hl
inc de
jr aploop2
apbranch4 ex af,af'
ld a,e
sub c
ld c,a
sbc a,a
add d
ld b,a
ld a,(bc)
ld (de),a
ex af,af'
inc de
jr aploop2
apbranch3 ex af,af'
ld a,(hl) ;use 7 bit offset, length = 2 or 3
srl a
ret z ;if a zero is found here, it's EOF
inc hl
push hl
ld bc,1
rl c
ld h,255
cpl
ld l,a
push hl
pop ix
apskip3 ex af,af'
apskip4 inc hl
add hl,de
ldir
pop hl
jr aploop
apbranch2 ex af,af'
ld a,b
call ap_getgamma ;use a gamma code * 256 for offset, another gamma code for length
dec c
ex af,af'
add a,c
jr z,ap_r0_gamma
dec a
;do I even need this code?
;bc=bc*256+(hl), lazy 16bit way
cpl
ld b,a
ld a,(hl)
inc hl
cpl
ld c,a
push bc
push bc
pop ix
call ap_getgamma
ex (sp),hl ;bc = len, hl=offs
ex af,af'
ld a,h
cp 255-4
jr nc,apskip2
inc bc
apskip2 inc a
jr nz,apskip3
or l
jp p,apskip3
inc bc
inc bc
jr apskip3
ap_r0_gamma call ap_getgamma ;and a new gamma code for length
push ix
ex (sp),hl
jr apskip4
ap_getgamma ex af,af'
ld bc,1
ap_getgammaloop call ap_getbit
rl c
rl b
call ap_getbit
ret nc
jr ap_getgammaloop
ap_getbit add a,a
ret nz
ld a,(hl)
inc hl
rla
ret