-
Notifications
You must be signed in to change notification settings - Fork 2
/
deexoopt_p7.asm
484 lines (481 loc) · 11.7 KB
/
deexoopt_p7.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
;Exomizer 3 Z80 decoder
;Copyright (C) 2008-2018 by Jaime Tejedor Gomez (Metalbrain)
;
;Optimized by Antonio Villena and Urusergi
;
;Fixed a bug, and supported raw default on Exomizer3.0(-P7) by uniabis
;
;Compression algorithm by Magnus Lind
; exomizer raw -P5 -T0 [-b] (speed<3, literals=1, bitsalignstart=0)
; exomizer raw -P5 -T1 [-b] (speed<3, literals=0, bitsalignstart=0)
; exomizer raw -P7 -T0 [-b] (speed=3, literals=1, bitsalignstart=0)
; exomizer raw -P7 -T1 [-b] (speed=3, literals=0, bitsalignstart=0)
; exomizer raw -P13 -T0 [-b] (speed<3, literals=1, bitsalignstart=1)
; exomizer raw -P13 -T1 [-b] (speed<3, literals=0, bitsalignstart=1)
; exomizer raw -P15 -T0 [-b] (speed=3, literals=1, bitsalignstart=1)
; exomizer raw -P15 -T1 [-b] (speed=3, literals=0, bitsalignstart=1)
;
; This depacker is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public
; License along with this library; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;
; SIZE speed 0 speed 1 speed 2 speed 3 range88-ef
; forw nolit 152 154 171 208 +2
; back nolit 150 152 169 206 +2
; forw liter 167 170 189 219 +3
; back liter 165 168 187 217 +3
; output deexoopt.bin
; define mapbase $5b00
; define speed 3
; define back 0
; define literals 0
; define bitsalignstart 1
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld iy, 256+mapbase/256*256
ELSE
ld iy, (mapbase+16)/256*256+112
ENDIF
IF bitsalignstart=0
ld a, (hl)
inc hl
ELSE
ld a, 128
ENDIF
ld b, 52
push de
cp a
exinit ld c, 16
jr nz, exget4
ld de, 1
ld ixl, c
IF speed=0
exget4 call exgetb
ENDIF
IF speed=1
exget4 add a, a
call z, exgetb
ENDIF
IF speed=2 OR speed=3
defb 218
exgb4 ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
exget4 adc a, a
jr z, exgb4
ENDIF
rl c
jr nc, exget4
IF speed=0 OR speed=1
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld (iy-256+mapbase-mapbase/256*256), c
ELSE
ld (iy-112+mapbase-(mapbase+16)/256*256), c
ENDIF
push hl
ld hl, 1
defb 210
ENDIF
IF speed=2
inc c
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld (iy-256+mapbase-mapbase/256*256), c
ELSE
ld (iy-112+mapbase-(mapbase+16)/256*256), c
ENDIF
push hl
ld hl, 1
defb 48
ENDIF
IF speed=3
ex af, af'
ld a, c
rrca
inc a
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld (iy-256+mapbase-mapbase/256*256), a
ELSE
ld (iy-112+mapbase-(mapbase+16)/256*256), a
ENDIF
jr nc, get5
xor 136
get5 push hl
ld hl, 1
defb 56
setbit add hl, hl
dec a
jr nz, setbit
ex af, af'
ELSE
exsetb add hl, hl
dec c
jr nz, exsetb
ENDIF
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld (iy-204+mapbase-mapbase/256*256), e
ld (iy-152+mapbase-mapbase/256*256), d
ELSE
ld (iy-60+mapbase-(mapbase+16)/256*256), e
ld (iy-8+mapbase-(mapbase+16)/256*256), d
ENDIF
add hl, de
ex de, hl
inc iyl
pop hl
dec ixl
djnz exinit
pop de
IF back=1
IF literals=1 AND speed=0
exlit inc c
exseq lddr
ELSE
exlit ldd
ENDIF
ELSE
IF literals=1 AND speed=0
exlit inc c
exseq ldir
ELSE
exlit ldi
ENDIF
ENDIF
IF speed=0
exloop call exgetb
jr c, exlit
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld c, 256-1
ELSE
ld c, 112-1
ENDIF
exgeti call exgetb
ENDIF
IF speed=1
exloop add a, a
call z, exgetb
jr c, exlit
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld c, 256-1
ELSE
ld c, 112-1
ENDIF
exgeti add a, a
call z, exgetb
ENDIF
IF speed=2 OR speed=3
exloop add a, a
jr z, exgbm
jr c, exlit
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
exgbmc ld c, 256-1
ELSE
exgbmc ld c, 112-1
ENDIF
exgeti add a, a
jr z, exgbi
exgbic inc c
jr nc, exgeti
ccf
ELSE
exgbic inc c
jr nc, exgeti
ENDIF
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
bit 4, c
IF literals=1
jr nz, excat
ELSE
ret nz
ENDIF
ELSE
IF literals=1
jp m, excat
ELSE
ret m
ENDIF
ENDIF
push de
ld iyl, c
IF speed=2 OR speed=3
ld de, 0
ENDIF
IF speed=3
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld b, (iy-256+mapbase-mapbase/256*256)
ELSE
ld b, (iy-112+mapbase-(mapbase+16)/256*256)
ENDIF
dec b
call nz, exgbts
ex de, hl
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld c, (iy-204+mapbase-mapbase/256*256)
ld b, (iy-152+mapbase-mapbase/256*256)
ELSE
ld c, (iy-60+mapbase-(mapbase+16)/256*256)
ld b, (iy-8+mapbase-(mapbase+16)/256*256)
ENDIF
add hl, bc
ex de, hl
ELSE
call expair
ENDIF
push de
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
inc d
dec d
jr nz, dontgo
ld bc, 512+48
dec e
jr z, exgoit
dec e
dontgo ld bc, 1024+32
jr z, exgoit
ld c, 16
ELSE
inc d
dec d
jr nz, dontgo
ld bc, 512+160
dec e
jr z, exgoit
dec e
dontgo ld bc, 1024+144
jr z, exgoit
ld c, 128
ENDIF
IF speed=0 OR speed=1
exgoit call exgbts
ENDIF
IF speed=2
ld e, 0
exgoit ld d, e
call exgbts
ENDIF
IF speed=3
ld e, 0
exgoit ld d, e
call exlee8
ENDIF
ld iyl, c
add iy, de
IF speed=2 OR speed=3
ld e, d
ENDIF
IF speed=3
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld b, (iy-256+mapbase-mapbase/256*256)
ELSE
ld b, (iy-112+mapbase-(mapbase+16)/256*256)
ENDIF
dec b
call nz, exgbts
ex de, hl
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld c, (iy-204+mapbase-mapbase/256*256)
ld b, (iy-152+mapbase-mapbase/256*256)
ELSE
ld c, (iy-60+mapbase-(mapbase+16)/256*256)
ld b, (iy-8+mapbase-(mapbase+16)/256*256)
ENDIF
add hl, bc
ex de, hl
ELSE
call expair
ENDIF
pop bc
ex (sp), hl
IF back=1
ex de, hl
add hl, de
lddr
ELSE
push hl
sbc hl, de
pop de
ldir
ENDIF
pop hl
jr exloop
IF literals=1
excat
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
bit 0, c
ret z
ELSE
ret pe
ENDIF
IF speed=3
ld b, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
ld c, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
ELSE
push de
IF speed=2
ld d, b
ld e, b
ENDIF
ld b, 16
call exgbts
ld b, d
ld c, e
pop de
ENDIF
IF speed=0
jr exseq
ELSE
IF back=1
lddr
ELSE
ldir
ENDIF
jr exloop
ENDIF
ENDIF
IF speed=2 OR speed=3
exgbm ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
adc a, a
jr nc, exgbmc
jp exlit
exgbi ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
adc a, a
jp exgbic
ENDIF
IF speed=3
exgbts jp p, exlee8
sla b
jr z, exgby
srl b
defb 250
exxopy ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
exl16 adc a, a
jr z, exxopy
rl d
djnz exl16
exgby ld e, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
ret
excopy ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
exlee8 adc a, a
jr z, excopy
rl e
djnz exlee8
ret
ELSE
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
expair ld b, (iy-256+mapbase-mapbase/256*256)
ELSE
expair ld b, (iy-112+mapbase-(mapbase+16)/256*256)
ENDIF
IF speed=2
dec b
call nz, exgbts
ELSE
call exgbts
ENDIF
ex de, hl
IF mapbase-mapbase/256*256<240 AND mapbase-mapbase/256*256>135
ld c, (iy-204+mapbase-mapbase/256*256)
ld b, (iy-152+mapbase-mapbase/256*256)
ELSE
ld c, (iy-60+mapbase-(mapbase+16)/256*256)
ld b, (iy-8+mapbase-(mapbase+16)/256*256)
ENDIF
add hl, bc
ex de, hl
ret
ENDIF
IF speed=0 OR speed=1
exgbts ld de, 0
excont dec b
ret m
IF speed=0
call exgetb
ELSE
add a, a
call z, exgetb
ENDIF
rl e
rl d
jr excont
IF speed=0
exgetb add a, a
ret nz
ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
adc a, a
ret
ELSE
exgetb ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
adc a, a
ret
ENDIF
ENDIF
IF speed=2
exgbg ld a, (hl)
IF back=1
dec hl
ELSE
inc hl
ENDIF
exgbts adc a, a
jr z, exgbg
rl e
rl d
djnz exgbts
ret
ENDIF