-
Notifications
You must be signed in to change notification settings - Fork 2
/
aplib247b_180_fast.asm
213 lines (175 loc) · 5.94 KB
/
aplib247b_180_fast.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
; aPPack decompressor
; original source by dwedit
; very slightly adapted by utopian
; optimized by Metalbrain & Antonio Villena
;247b to 234b optimized by uniabis
;hl = source
;de = dest
depack ;di
;call init
;ei
;ret
init ld a,128
;;cap v1.2 with load address version requires to copy two bytes on top
;ldi
;ldi
jr apbranch1
apgetbit1 ld a,(hl)
inc hl
rla
jr c,apbranch1n
apbranch1 ldi
aploop2 ld b,255
aploop add a,a
jr nc,apbranch1
jr z,apgetbit1
apbranch1n add a,a
jr nz,apnogetbit2
ld a,(hl)
inc hl
rla
apnogetbit2 jr nc,apbranch2
add a,a
jr nz,apnogetbit3
ld a,(hl)
inc hl
rla
apnogetbit3 jr nc,apbranch3
ld c,16 ;get an offset
apget4bits add a,a
jr nz,apnogetbit4
ld a,(hl)
inc hl
rla
apnogetbit4 rl c
jr nc,apget4bits
jr nz,apbranch4
ex de,hl
ld (hl),c ;write a 0
ex de,hl
inc de
jp 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
jp 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
inc hl
ex af,af'
add hl,de
ldir
pop hl
jp 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
apskip3 inc hl
ex af,af'
add hl,de
ldir
pop hl
jp aploop
ap_r0_gamma call ap_getgamma ;and a new gamma code for length
push ix
ex (sp),hl
inc hl
add hl,de
ldir
pop hl
jp aploop
ap5 ld a,(hl)
inc hl
rla
jp apnogetbit5
ap6 ld a, (hl)
inc hl
rla
jp apnogetbit6
ap7 ld a, (hl)
inc hl
rla
jp apnogetbit7
ap8 ld a, (hl)
inc hl
rla
jp apnogetbit8
ap9 ld a, (hl)
inc hl
rla
jp apnogetbit9
ap10 ld a, (hl)
inc hl
rla
ret nc
jp ap_getgammaloop
ap_getgamma ex af, af'
ld bc, 1
add a, a
jr z, ap5
apnogetbit5 rl c
add a, a
jr z, ap6
apnogetbit6 ret nc
add a, a
jr z, ap7
apnogetbit7 rl c
add a, a
jr z, ap8
apnogetbit8 ret nc
ap_getgammaloop add a, a
jr z, ap9
apnogetbit9 rl c
rl b
add a, a
jr z, ap10
apnogetbit10 ret nc
jp ap_getgammaloop