-
Notifications
You must be signed in to change notification settings - Fork 1
/
asm.py
305 lines (254 loc) · 7.03 KB
/
asm.py
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
"""
Per-file ASM edits for Appareden.
"""
FULLWIDTH_CHECK = b'\x81\x74\x2b\x3C\x82\x74\x27'
"""
fullwidthCheck:
cmp al, 82 ; just the 82 part of the instruction
jz 5839 ; fullwidthOriginal
cmp al, 81
jz 5839
"""
"""
dictEndCheck
cmp al, ee
jnz 5816 ; dictStartCheck
pop si
lodsb
jmp 57de ; initial text handling code
"""
DICT_END_CHECK = b'\x3C\xee\x75\x04\x5E\xAC\xEB\xC4'
"""
dictStartCheck:
cmp al, ef
jbe 5825 ; overlineCode ; Must be an unsigned comparison! So use jnb instead of jg
push si
mov ah, al
lodsb
and ah, 0f
mov si, 43aa ; 4c18 for ORBTL
add si, ax
lodsb
"""
DICT_START_CHECK = b'\x3C\xef\x76\x0d\x56\x88\xc4\xac\x80\xe4\x0f\xbe\xaa\x43\x01\xc6\xac'
OVERLINE_CODE = b'\x3C\x7E\x75\x01\x4F'
#BTL_OVERLINE_CODE = b'\x3c\x7e\x75\x01\x4f'
"""
overlineCode:
cmp al, 7e
jnz 5830 ; overlineEndCode
dec di
"""
OVERLINE_END_CODE = b'\x3c\x7c\x75\x31\x47\x30\xc0\xeb\x2c'
"""
overlineEndCode:
cmp al, 7c
jnz 585f ; halfwidthOriginal
inc di
xor al, al
jmp 585f ; halfwidthOriginal
nop
"""
#NOPS = b'\x90'*9
FULLWIDTH_ORIGINAL = b'\x8a\xe0\xac\xe8\xb4\xfe\x8b\xd0\xe8\x16\xff\x56\xe8\x4f\xfe\xe8\xcc\xfe\xbe\x14\x04\xe8\xdc\xfe\x90\x90\x90\xa1\xd6\x03\xe8\xbd\xfe\xbe\xd8\x03\xe8\xcd\xfe\x5e\x47\x47\xeb\x26'
"""
fullwidthOriginal:
mov ah, al
lodsb
call 56f3
mov dx, ax
call 575a
push si
call 5697
call 5717
mov si, 0414 <- Makes shadows look good
call 572d <- in charge of outlines/shadows
mov ax, [03d6]
call 5717
mov si, 03d8
call 572d <- Makes text appear on top of shadows
pop si
inc di
inc di
jmp 588b ; jumps to the 'jmp 57da' in halfwidthOriginal, since it can't reach 57da with a short jump
"""
HALFWIDTH_ORIGINAL = b'\xB4\x09\x86\xE0\x8B\xD0\xE8\xEc\xFE\x56\xE8\x25\xFE\x33\xc0\xE8\xA0\xFE\xBE\x14\x04\xE8\xC6\xFE\xA1\xD6\x03\xE8\x94\xFE\xBE\xD8\x03\xE8\xBA\xFE\x5E\x47\xE9\x4C'
"""
halfwidthOriginal:
mov ah, 09
xchg al, ah
mov dx, ax
call 575a
push si
call 5697
xor ax, ax <- necessary for fixing weird parens/overline coloring
call 5717
mov si, 0414
call 5743
mov ax, [03d6]
call 5717
mov si, 03d8
call 5743
pop si
inc di
jmp 57da
"""
ORFIELD_CODE = [FULLWIDTH_CHECK, DICT_END_CHECK, DICT_START_CHECK, OVERLINE_CODE, OVERLINE_END_CODE,
FULLWIDTH_ORIGINAL, HALFWIDTH_ORIGINAL]
CD_FULLWIDTH_CHECK = b"\x3C\x81\x74\x2C\x3C\x82\x74\x28"
"""
cd_fullwidthCheck:
cmp al, 81
jz 5834 ; cd_fullwidthOriginal
cmp al, 82
jz 5834 ; cd_fullwidthOriginal
"""
CD_DICT_END_CHECK = b'\x3C\xEE\x75\x04\x5E\xAC\xEB\xc4'
"""
cd_dictEndCheck:
cmp al, ee
jnz 5814 ; dict_start_check
pop si
lodsb
jmp 57d8 ; beginning of text handling loop, 'lodsb'
"""
CD_DICT_START_CHECK = b'\x3C\xEF\x76\x0D\x56\x88\xC4\xAC\x80\xE4\x0F\xBE\xD0\x43\x01\xC6\xAC'
"""
cd_dictStartCheck:
cmp al, ef
jbe 5825
push si
mov ah, al
lodsb
and ah, 0f
mov si, 43d0
add si, ax
lodsb
"""
CD_OVERLINE_CODE = b'\x3C\x7E\x75\x01\x4F'
"""
cd_overlineCode:
cmp al, 7e
jnz 582a
dec di
"""
CD_OVERLINE_END_CODE = b'\x3c\x7c\x75\x31\x47\x30\xc0\xeb\x2c\x90'
"""
cd_overlineEndCode:
cmp al, 7c
jnz 585f ; cd_halfwidthOriginal
inc di
xor al, al
jmp 585f ; cd_halfwidthOriginal
nop
"""
CD_FULLWIDTH_ORIGINAL = b'\x8A\xE0\xAC\xE8\xB3\xFE\x8B\xD0\xE8\x15\xFF\x56\xE8\x4E\xFE\x33\xC0\xE8\xC9\xFE\xBE\x14\x04\xE8\xD9\xFE\xA1\xD6\x03\xE8\xBD\xFE\xBE\xD8\x03\xE8\xCD\xFE\x5E\x47\x47\xEB\x26'
"""
cd_fullwidthOriginal:
mov ah, al
lodsb
call 56ed
mov dx, ax
call 5754
push si
call 5691
xor ax, ax
call 5711
mov si, 0414
call 5727
mov ax, [03d6]
call 5711
mov si, 03d8
call 5727
pop si
inc di
inc di
jmp 5885
"""
CD_HALFWIDTH_ORIGINAL = b'\xB4\x09\x86\xE0\x8B\xD0\xE8\xEC\xFE\x56\xE8\x25\xFE\x33\xC0\xE8\xA0\xFE\xBE\x14\x04\xE8\xC6\xFE\xA1\xD6\x03\xE8\x94\xFE\xBE\xD8\x03\xE8\xBA\xFE\x5E\x47\xE9\x4c'
"""
cd_halfwidthOriginal:
mov ah, 09
xchg al, ah
mov dx, ax
call 5754
push si
call 5691
xor ax, ax
call 5711
mov si, 0414
call 573d
mov ax, [03d6]
call 5711
mov si, 03d8
call 573d
pop si
inc di
jmp 57d4 ; actually 5885, which is 'jmp 57d4'
"""
CD_ORFIELD_CODE = [CD_FULLWIDTH_CHECK, CD_DICT_END_CHECK, CD_DICT_START_CHECK, CD_OVERLINE_CODE,
CD_OVERLINE_END_CODE, CD_FULLWIDTH_ORIGINAL, CD_HALFWIDTH_ORIGINAL]
CD_ORBTL_CODE = b'\x3C\xEE\x75\x04\x5E\xAC\xEB\xCC\x3C\xEF\x76\x0d\x56\x88\xc4\xAC\x80\xE4\x0F\xBE\x66\x44\x01\xC6\xAC\x3C\x7E\x75\x01\x4F\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\xEB\x14'
ORBTL_CODE = CD_ORBTL_CODE.replace(b'\xBE\x66\x44', b'\xBE\x18\x4c')
# Those control codes as bytes.
B_CONTROL_CODES = {
b'w': b'}',
b'c': b'$',
b'n': b'/'
}
FD_EDITS = {
# ORFIELD
'ORFIELD.EXE': [
(0x151b7, B_CONTROL_CODES[b'w']), # w = "}"
(0x15b0f, B_CONTROL_CODES[b'w']), # w = "}"
(0x15b99, B_CONTROL_CODES[b'w']), # w = "}"
(0x15519, B_CONTROL_CODES[b'n']), # n = "/"
(0x15528, B_CONTROL_CODES[b'n']), # n = "/"
(0x155df, B_CONTROL_CODES[b'n']), # n = "/"
(0x155ee, B_CONTROL_CODES[b'n']), # n = "/"
(0x15b1d, B_CONTROL_CODES[b'n']), # n = "/"
(0x15b5f, B_CONTROL_CODES[b'n']), # n = "/"
(0x15b16, B_CONTROL_CODES[b'c']), # c = "$"
(0x15b6c, B_CONTROL_CODES[b'c']), # c = "$"
(0x2551b, B_CONTROL_CODES[b'c']), # c = "$"
(0x1ab14, b'\xb2'), # Ailment buffer fix
(0x8c0b, b''.join(ORFIELD_CODE)) # Text handling code
],
'ORBTL.EXE': [
#(0x3647, b''.join(ORBTL_CODE)),
(0x3647, ORBTL_CODE),
(0x11e17, b'\x90\x90\x90') # Remove enemy-name-limiter
]
}
CD_EDITS = {
'ORFIELD.EXE': [
(0x157c9, B_CONTROL_CODES[b'w']),
(0x1612b, B_CONTROL_CODES[b'w']),
(0x161b5, B_CONTROL_CODES[b'w']),
(0x15b2b, B_CONTROL_CODES[b'n']),
(0x15b3a, B_CONTROL_CODES[b'n']),
(0x15bf1, B_CONTROL_CODES[b'n']),
(0x15c00, B_CONTROL_CODES[b'n']),
(0x16139, B_CONTROL_CODES[b'n']),
(0x1617b, B_CONTROL_CODES[b'n']),
(0x16132, B_CONTROL_CODES[b'c']),
(0x16188, B_CONTROL_CODES[b'c']),
(0x25b49, B_CONTROL_CODES[b'c']),
(0x1b141, b'\xb2'),
(0x8e04, b''.join(CD_ORFIELD_CODE))
],
'ORBTL.EXE': [
(0x3647, CD_ORBTL_CODE),
(0x11e1f, b'\x90\x90\x90') # Remove enemy-name-limiter
]
}
FD_CHEATS = {
'ORFIELD.EXE': [
(0x1a143, b'\x90\x90'), # Turn off random battles
]
}
CD_CHEATS = {
'ORFIELD.EXE': [
(0x1a770, b'\x90\x90'), # Turn off random battles
]
}