-
Notifications
You must be signed in to change notification settings - Fork 2
/
deexo3p7.asm
196 lines (164 loc) · 5.59 KB
/
deexo3p7.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
;Exomizer 3 raw -P7(default) Z80 decoder
;Copyright (C) 2008-2016 by Jaime Tejedor Gomez (Metalbrain)
;
;Optimized by Antonio Villena and Urusergi (169 bytes)
;Modified using z80 alternate registers to prevent undocumented instruction(169 -> 167bytes) by uniabis
;Modified for Exomizer 3 raw -P7(default) (167 -> 176bytes) by uniabis
;Apply speed boost(176 -> 179bytes)
;Replace JR with JP(179-> 181ytes)
;
;Compression algorithm by Magnus Lind
;
; 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
;
;
;input: hl=compressed data start
; de=uncompressed destination start
;
; you may change exo_mapbasebits to point to any free buffer
;
;ATTENTION!
;A huge speed boost (around 14%) can be gained at the cost of only 3 bytes.
;If you want this, replace all instances of "call exo_getbit" with "add a" followed by
;"call z,exo_getbit", and remove the first two instructions in exo_getbit routine.
IFNDEF OPTIMIZE_JUMP
DEFINE JPX jr
ELSE
DEFINE JPX jp
ENDIF
MACRO m_getbit
IFNDEF INLINE_GETBIT
call p_getbit
ELSE
add a
call z,p_getbit
ENDIF
ENDM
deexo: ld iy, exo_mapbasebits+11
ld a, (hl)
inc hl
tableinit:
ld b, 52
cp a ; SET ZF
exo_initbits:
exx
ld hl, 1
ld b, 16
jr nz, exo_get4bits
ld c, b
ld d, h
ld e, l
exo_get4bits: exx
m_getbit
exx
rl b
jr nc, exo_get4bits
ld (iy-11), b ;bits[i]
srl b
jr nc,.skp1
set 3,b
.skp1:
inc b
ld (iy+93), d ;baseh[i]
ld (iy+41), e ;basel[i] (and opcode 41 == add hl,hl)
exo_setbit:
djnz exo_setbit-1 ;jump to add hl,hl instruction
add hl, de
ex de, hl
inc iy
dec c
exx
djnz exo_initbits
exo_literalcopy:
ldi
exo_mainloop:
m_getbit
jr c, exo_literalcopy
ld bc, 240-1
exo_getindex:
m_getbit
inc c
jr nc,exo_getindex
ret z
jp p, exo_literalrun
push de
ld iy, exo_mapbasebits+11-240
call exo_getpair
push de
rlc d
jr nz, exo_dontgo
dec e
ld bc, 2*256 + 8 ;2 bits, 48 offset
jr z, exo_goforit
dec e ;2?
exo_dontgo: ld bc, 4*256 + 1 ;4 bits, 32 offset
jr z, exo_goforit
dec c
exo_goforit:
m_getbit
rl c
djnz exo_goforit
ld iy, exo_mapbasebits+11+16
call exo_getpair
pop bc
ex (sp), hl
push hl
sbc hl, de
pop de
ldir
pop hl
JPX exo_mainloop ;Next!
exo_literalrun:
ld b,(hl)
inc hl
ld c,(hl)
inc hl
ldir
JPX exo_mainloop ;Next!
exo_getpair: add iy, bc
ld d, b
ld e, b
ld c, (iy-11)
ld b, c
srl b
jr z,.skp3
.lp1:
m_getbit
rl e
djnz .lp1
.skp3:
bit 0,c
jr z,.skp4
ld d,e
ld e,(hl)
inc hl
.skp4:
ex de, hl
ld c, (iy+41)
ld b, (iy+93)
add hl, bc ;Always clear C flag
ex de, hl
ret
p_getbit:
IFNDEF INLINE_GETBIT
add a
ret nz
ENDIF
ld a, (hl)
inc hl
rla
ret
exo_mapbasebits:
;defs 156 ;tables for bits, baseL, baseH