-
Notifications
You must be signed in to change notification settings - Fork 2
/
dehrust8_hl.asm
336 lines (237 loc) · 3.72 KB
/
dehrust8_hl.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
; hrust 8bits-buffer depacker for Z80 sjasm (262bytes)
;
; license:zlib license
;
; Copyright (c) 2022 uniabis
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
;
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
;
; 3. This notice may not be removed or altered from any source
; distribution.
;
dehrust8:
; [in]
; hl : source address
; de : destination address
; [work]
; bc,af,af'
ld a, #80
ex af,af';'
ldi
scf
jr .fill_bitbuffer1
.code011:
call .get_bit_proc
jr c, .code0111
.code0110:
ld e, c
.checkE0:
push af
ld a, (hl)
inc hl
cp #E0
jr nc, .rirE0
ld e, a
pop af
jr .copy_block
.code00:
inc c
ld de, #FF3F
jr .get_offset_bit_loop
.code0111:
.get_offset10:
ld de, #FF0F
.get_offset_bit_loop:
call .get_bits_proc
.copy_block:
ex (sp), hl
ex de, hl
add hl, de
ldir
pop hl
add a, a
jr nc, .insert_one
jr nz, .get_length
.fill_bitbuffer1:
ld a, (hl)
inc hl
adc a, a
jr c, .get_length
DUP 1
ldi
add a, a
jr c, .get_length
EDUP
.insert_one:
ldi
.main_loop:
add a, a
jr nc, .insert_one
jr z, .fill_bitbuffer1
.get_length:
push de
ld bc, #0501
.get_length_loop:
call .get_bit_proc
jr c, .get_length_add2
ld b, #01
;jr .get_length_bitl
db #DA ; Z80 opcode jp c,nnnn
.get_length_add2:
inc c
inc c
.get_length_bitl:
call .get_bit_proc
jr nc, .get_length_end
inc c
djnz .get_length_loop
.get_length_end:
dec c
ld b, c
jr z, .code00
djnz .chcek10
.code01:
inc c
ld d, #FF
call .get_bit_proc
jr c, .code011
.code010:
call .get_bit_proc
rl d
dec d
ld e, (hl)
inc hl
jr .copy_block
.get_offset1x:
call .get_bit_proc
jr nc, .get_offset10
.get_offset11:
ex af,af';'
ld e, a
ex af,af';'
dec e
;jr z, .exit1
call .get_bits_proc
ld d, e
ld e, (hl)
inc hl
jp .copy_block
.offset_extend:
pop af
ex af,af';'
rrca
ex af,af';'
pop de
jr .main_loop
.get_offset01:
ld de, #FF03
jr .checkE0
.rirE0:
scf
adc a, a
xor e
inc a
jr z, .offset_extend
sub #10
ld e, a
pop af
.copy_rir:
ex (sp), hl
ex de, hl
add hl, de
ldi
ex (sp), hl
ldi
ex (sp), hl
inc hl
ldi
pop hl
jr .main_loop
.code110001:
ld e, #10
call .get_bits_proc
ld d, a
ld a, e
add #06
add a, a
ld c, a
ld a, d
pop de
ldir
jr .main_loop
.check1100:
djnz .set_length_c
.code1100:
call .get_bit_proc
jr nc, .code11000
.code11001:
ld de, #FF1F
call .get_bits_proc
jr .copy_rir
.exit1:
pop de
ret
.chcek10:
djnz .check1100
.code10:
inc c
.set_length_c:
ld b, #00
.set_length_bc:
call .get_bit_proc
jr c, .get_offset1x
.get_offset0x:
call .get_bit_proc
jr c, .get_offset01
.get_offset00:
ld d, #FE
ld e, (hl)
inc hl
jp .copy_block
.code11000:
call .get_bit_proc
jr c, .code110001
.code110000:
ld e, #02
call .get_bits_proc
ld c, e
ld e, a
ld a, #0F
cp c
jr z, .exit1
jr c, .short_length
.long_length:
ld b, c
ld c, (hl)
inc hl
.short_length:
ld a, e
jr .set_length_bc
.get_bits_proc:
add a, a
call z, .fill_bitbuffer_proc
rl e
jr nc, .get_bits_proc
ret
.get_bit_proc:
add a, a
ret nz
.fill_bitbuffer_proc:
ld a, (hl)
inc hl
adc a, a
ret