31 |
|
#include "rom_patches.h" |
32 |
|
#include "main.h" |
33 |
|
#include "audio.h" |
34 |
+ |
#include "thunks.h" |
35 |
|
|
36 |
|
#define DEBUG 0 |
37 |
|
#include "debug.h" |
106 |
|
* Resource patches via vCheckLoad |
107 |
|
*/ |
108 |
|
|
109 |
+ |
// 680x0 code pattern matching helper |
110 |
+ |
#define PM(N, V) (p[N] == htons(V)) |
111 |
+ |
|
112 |
|
void CheckLoad(uint32 type, int16 id, uint16 *p, uint32 size) |
113 |
|
{ |
114 |
|
uint16 *p16; |
116 |
|
D(bug("vCheckLoad %c%c%c%c (%08x) ID %d, data %p, size %d\n", type >> 24, (type >> 16) & 0xff, (type >> 8) & 0xff, type & 0xff, type, id, p, size)); |
117 |
|
|
118 |
|
// Don't modify resources in ROM |
119 |
< |
if ((uint32)p >= ROM_BASE && (uint32)p <= (ROM_BASE + ROM_SIZE)) |
119 |
> |
if ((uintptr)p >= ROM_BASE && (uintptr)p <= (ROM_BASE + ROM_SIZE)) |
120 |
|
return; |
121 |
|
|
122 |
|
if (type == FOURCC('b','o','o','t') && id == 3) { |
123 |
|
D(bug("boot 3 found\n")); |
124 |
|
size >>= 1; |
125 |
|
while (size--) { |
126 |
< |
if (p[0] == 0x2e49) { |
126 |
> |
if (PM(0,0x2e49)) { |
127 |
|
// Set boot stack pointer (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
128 |
< |
p[0] = M68K_EMUL_OP_FIX_BOOTSTACK; |
128 |
> |
p[0] = htons(M68K_EMUL_OP_FIX_BOOTSTACK); |
129 |
|
D(bug(" patch 1 applied\n")); |
130 |
< |
} else if (p[0] == 0x4267 && p[1] == 0x3f01 && p[2] == 0x3f2a && p[3] == 0x0006 && p[4] == 0x6100) { |
130 |
> |
} else if (PM(0,0x4267) && PM(1,0x3f01) && PM(2,0x3f2a) && PM(3,0x0006) && PM(4,0x6100)) { |
131 |
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.5.3, 7.5.5) |
132 |
< |
p[7] = M68K_EMUL_OP_NTRB_17_PATCH3; |
132 |
> |
p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH3); |
133 |
|
D(bug(" patch 2 applied\n")); |
134 |
< |
} else if (p[0] == 0x3f2a && p[1] == 0x0006 && p[2] == 0x3f2a && p[3] == 0x0002 && p[4] == 0x6100) { |
134 |
> |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x6100)) { |
135 |
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.6, 7.6.1, 8.0, 8.1) |
136 |
< |
p[7] = M68K_EMUL_OP_NTRB_17_PATCH; |
136 |
> |
p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH); |
137 |
|
D(bug(" patch 3 applied\n")); |
138 |
< |
} else if (p[0] == 0x3f2a && p[1] == 0x0006 && p[2] == 0x3f2a && p[3] == 0x0002 && p[4] == 0x61ff) { |
138 |
> |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff)) { |
139 |
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (8.5, 8.6) |
140 |
< |
p[8] = M68K_EMUL_OP_NTRB_17_PATCH; |
140 |
> |
p[8] = htons(M68K_EMUL_OP_NTRB_17_PATCH); |
141 |
|
D(bug(" patch 4 applied\n")); |
142 |
< |
} else if (p[0] == 0x0c39 && p[1] == 0x0001 && p[2] == 0xf800 && p[3] == 0x0008 && p[4] == 0x6f00) { |
142 |
> |
} else if (PM(0,0x0c39) && PM(1,0x0001) && PM(2,0xf800) && PM(3,0x0008) && PM(4,0x6f00)) { |
143 |
|
// Don't read from 0xf8000008 (8.5 with Zanzibar ROM, 8.6) |
144 |
< |
p[0] = M68K_NOP; |
145 |
< |
p[1] = M68K_NOP; |
146 |
< |
p[2] = M68K_NOP; |
147 |
< |
p[3] = M68K_NOP; |
148 |
< |
p[4] = 0x6000; // bra |
144 |
> |
p[0] = htons(M68K_NOP); |
145 |
> |
p[1] = htons(M68K_NOP); |
146 |
> |
p[2] = htons(M68K_NOP); |
147 |
> |
p[3] = htons(M68K_NOP); |
148 |
> |
p[4] = htons(0x6000); // bra |
149 |
|
D(bug(" patch 5 applied\n")); |
150 |
< |
} else if (p[0] == 0x2f3c && p[1] == 0x6b72 && p[2] == 0x6e6c && p[3] == 0x4267 && p[4] == 0xa9a0 && p[5] == 0x265f && p[6] == 0x200b && p[7] == 0x6700) { |
150 |
> |
} else if (PM(0,0x2f3c) && PM(1,0x6b72) && PM(2,0x6e6c) && PM(3,0x4267) && PM(4,0xa9a0) && PM(5,0x265f) && PM(6,0x200b) && PM(7,0x6700)) { |
151 |
|
// Don't replace nanokernel ("krnl" resource) (8.6) |
152 |
< |
p[0] = M68K_NOP; |
153 |
< |
p[1] = M68K_NOP; |
154 |
< |
p[2] = M68K_NOP; |
155 |
< |
p[3] = M68K_NOP; |
156 |
< |
p[4] = M68K_NOP; |
157 |
< |
p[7] = 0x6000; // bra |
152 |
> |
p[0] = htons(M68K_NOP); |
153 |
> |
p[1] = htons(M68K_NOP); |
154 |
> |
p[2] = htons(M68K_NOP); |
155 |
> |
p[3] = htons(M68K_NOP); |
156 |
> |
p[4] = htons(M68K_NOP); |
157 |
> |
p[7] = htons(0x6000); // bra |
158 |
|
D(bug(" patch 6 applied\n")); |
159 |
< |
} else if (p[0] == 0xa8fe && p[1] == 0x3038 && p[2] == 0x017a && p[3] == 0x0c40 && p[4] == 0x8805 && p[5] == 0x6710) { |
159 |
> |
} else if (PM(0,0xa8fe) && PM(1,0x3038) && PM(2,0x017a) && PM(3,0x0c40) && PM(4,0x8805) && PM(5,0x6710)) { |
160 |
|
// No SCSI (calls via 0x205c jump vector which is not initialized in NewWorld ROM 1.6) (8.6) |
161 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
162 |
< |
p[5] = 0x6010; // bra |
162 |
> |
p[5] = htons(0x6010); // bra |
163 |
|
D(bug(" patch 7 applied\n")); |
164 |
|
} |
165 |
|
} |
173 |
|
static const uint8 dat[] = {0x4e, 0xba, 0x00, 0x9e, 0x3e, 0x00, 0x50, 0x4f, 0x67, 0x04}; |
174 |
|
base = find_rsrc_data((uint8 *)p, size, dat, sizeof(dat)); |
175 |
|
if (base) { |
176 |
< |
p16 = (uint16 *)((uint32)p + base + 6); |
176 |
> |
p16 = (uint16 *)((uintptr)p + base + 6); |
177 |
|
*p16 = htons(M68K_EMUL_OP_NTRB_17_PATCH2); |
178 |
|
D(bug(" patch 1 applied\n")); |
179 |
|
} |
182 |
|
D(bug("ptch 420 found\n")); |
183 |
|
size >>= 1; |
184 |
|
while (size--) { |
185 |
< |
if (p[0] == 0xa030 && p[1] == 0x5240 && p[2] == 0x303c && p[3] == 0x0100 && p[4] == 0xc06e && p[5] == 0xfef6) { |
185 |
> |
if (PM(0,0xa030) && PM(1,0x5240) && PM(2,0x303c) && PM(3,0x0100) && PM(4,0xc06e) && PM(5,0xfef6)) { |
186 |
|
// Disable VM (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1) |
187 |
< |
p[1] = M68K_NOP; |
188 |
< |
p[2] = M68K_NOP; |
189 |
< |
p[3] = M68K_NOP; |
190 |
< |
p[4] = M68K_NOP; |
191 |
< |
p[5] = M68K_NOP; |
192 |
< |
p[6] = M68K_NOP; |
193 |
< |
p[7] = M68K_NOP; |
194 |
< |
p[8] = M68K_NOP; |
195 |
< |
p[9] = M68K_NOP; |
196 |
< |
p[10] = M68K_NOP; |
197 |
< |
p[11] = M68K_NOP; |
187 |
> |
p[1] = htons(M68K_NOP); |
188 |
> |
p[2] = htons(M68K_NOP); |
189 |
> |
p[3] = htons(M68K_NOP); |
190 |
> |
p[4] = htons(M68K_NOP); |
191 |
> |
p[5] = htons(M68K_NOP); |
192 |
> |
p[6] = htons(M68K_NOP); |
193 |
> |
p[7] = htons(M68K_NOP); |
194 |
> |
p[8] = htons(M68K_NOP); |
195 |
> |
p[9] = htons(M68K_NOP); |
196 |
> |
p[10] = htons(M68K_NOP); |
197 |
> |
p[11] = htons(M68K_NOP); |
198 |
|
D(bug(" patch 1 applied\n")); |
199 |
|
break; |
200 |
< |
} else if (p[0] == 0xa030 && p[1] == 0x5240 && p[2] == 0x7000 && p[3] == 0x302e && p[4] == 0xfef6 && p[5] == 0x323c && p[6] == 0x0100) { |
200 |
> |
} else if (PM(0,0xa030) && PM(1,0x5240) && PM(2,0x7000) && PM(3,0x302e) && PM(4,0xfef6) && PM(5,0x323c) && PM(6,0x0100)) { |
201 |
|
// Disable VM (8.0, 8.1) |
202 |
< |
p[8] = M68K_NOP; |
203 |
< |
p[15] = M68K_NOP; |
202 |
> |
p[8] = htons(M68K_NOP); |
203 |
> |
p[15] = htons(M68K_NOP); |
204 |
|
D(bug(" patch 2 applied\n")); |
205 |
|
break; |
206 |
< |
} else if (p[0] == 0xa030 && p[1] == 0x5240 && p[2] == 0x7000 && p[3] == 0x302e && p[4] == 0xfecc && p[5] == 0x323c && p[6] == 0x0100) { |
206 |
> |
} else if (PM(0,0xa030) && PM(1,0x5240) && PM(2,0x7000) && PM(3,0x302e) && PM(4,0xfecc) && PM(5,0x323c) && PM(6,0x0100)) { |
207 |
|
// Disable VM (8.5, 8.6) |
208 |
< |
p[8] = M68K_NOP; |
209 |
< |
p[15] = M68K_NOP; |
208 |
> |
p[8] = htons(M68K_NOP); |
209 |
> |
p[15] = htons(M68K_NOP); |
210 |
|
D(bug(" patch 3 applied\n")); |
211 |
|
break; |
212 |
|
} |
217 |
|
D(bug("gpch 16 found\n")); |
218 |
|
size >>= 1; |
219 |
|
while (size--) { |
220 |
< |
if (p[0] == 0x6700 && p[13] == 0x7013 && p[14] == 0xfe0a) { |
220 |
> |
if (PM(0,0x6700) && PM(13,0x7013) && PM(14,0xfe0a)) { |
221 |
|
// Don't call FE0A in Shutdown Manager (7.6.1, 8.0, 8.1, 8.5) |
222 |
< |
p[0] = 0x6000; |
222 |
> |
p[0] = htons(0x6000); |
223 |
|
D(bug(" patch 1 applied\n")); |
224 |
|
break; |
225 |
|
} |
230 |
|
D(bug("gpch 650 found\n")); |
231 |
|
size >>= 1; |
232 |
|
while (size--) { |
233 |
< |
if (p[0] == 0x6600 && p[1] == 0x001a && p[2] == 0x2278 && p[3] == 0x0134) { |
233 |
> |
if (PM(0,0x6600) && PM(1,0x001a) && PM(2,0x2278) && PM(3,0x0134)) { |
234 |
|
// We don't have SonyVars (7.5.2) |
235 |
< |
p[0] = 0x6000; |
235 |
> |
p[0] = htons(0x6000); |
236 |
|
D(bug(" patch 1 applied\n")); |
237 |
< |
} else if (p[0] == 0x6618 && p[1] == 0x2278 && p[2] == 0x0134) { |
237 |
> |
} else if (PM(0,0x6618) && PM(1,0x2278) && PM(2,0x0134)) { |
238 |
|
// We don't have SonyVars (7.5.3) |
239 |
< |
p[-6] = M68K_NOP; |
240 |
< |
p[-3] = M68K_NOP; |
241 |
< |
p[0] = 0x6018; |
239 |
> |
p[-6] = htons(M68K_NOP); |
240 |
> |
p[-3] = htons(M68K_NOP); |
241 |
> |
p[0] = htons(0x6018); |
242 |
|
D(bug(" patch 2 applied\n")); |
243 |
< |
} else if (p[0] == 0x666e && p[1] == 0x2278 && p[2] == 0x0134) { |
243 |
> |
} else if (PM(0,0x666e) && PM(1,0x2278) && PM(2,0x0134)) { |
244 |
|
// We don't have SonyVars (7.5.5) |
245 |
< |
p[-6] = M68K_NOP; |
246 |
< |
p[-3] = M68K_NOP; |
247 |
< |
p[0] = 0x606e; |
245 |
> |
p[-6] = htons(M68K_NOP); |
246 |
> |
p[-3] = htons(M68K_NOP); |
247 |
> |
p[0] = htons(0x606e); |
248 |
|
D(bug(" patch 3 applied\n")); |
249 |
< |
} else if (p[0] == 0x6400 && p[1] == 0x011c && p[2] == 0x2278 && p[3] == 0x0134) { |
249 |
> |
} else if (PM(0,0x6400) && PM(1,0x011c) && PM(2,0x2278) && PM(3,0x0134)) { |
250 |
|
// We don't have SonyVars (7.6.1, 8.0, 8.1, 8.5, 8.6) |
251 |
< |
p[0] = 0x6000; |
251 |
> |
p[0] = htons(0x6000); |
252 |
|
D(bug(" patch 4 applied\n")); |
253 |
< |
} else if (p[0] == 0x6400 && p[1] == 0x00e6 && p[2] == 0x2278 && p[3] == 0x0134) { |
253 |
> |
} else if (PM(0,0x6400) && PM(1,0x00e6) && PM(2,0x2278) && PM(3,0x0134)) { |
254 |
|
// We don't have SonyVars (7.6) |
255 |
< |
p[0] = 0x6000; |
255 |
> |
p[0] = htons(0x6000); |
256 |
|
D(bug(" patch 5 applied\n")); |
257 |
|
} |
258 |
|
p++; |
262 |
|
D(bug("gpch 655 found\n")); |
263 |
|
size >>= 1; |
264 |
|
while (size--) { |
265 |
< |
if (p[0] == 0x83a8 && p[1] == 0x0024 && p[2] == 0x4e71) { |
265 |
> |
if (PM(0,0x83a8) && PM(1,0x0024) && PM(2,0x4e71)) { |
266 |
|
// Don't write to GC interrupt mask (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
267 |
< |
p[0] = M68K_NOP; |
268 |
< |
p[1] = M68K_NOP; |
267 |
> |
p[0] = htons(M68K_NOP); |
268 |
> |
p[1] = htons(M68K_NOP); |
269 |
|
D(bug(" patch 1 applied\n")); |
270 |
< |
} else if (p[0] == 0x207c && p[1] == 0xf300 && p[2] == 0x0034) { |
270 |
> |
} else if (PM(0,0x207c) && PM(1,0xf300) && PM(2,0x0034)) { |
271 |
|
// Don't read PowerMac ID (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
272 |
< |
p[0] = 0x303c; // move.w #id,d0 |
273 |
< |
p[1] = 0x3020; |
274 |
< |
p[2] = M68K_RTS; |
272 |
> |
p[0] = htons(0x303c); // move.w #id,d0 |
273 |
> |
p[1] = htons(0x3020); |
274 |
> |
p[2] = htons(M68K_RTS); |
275 |
|
D(bug(" patch 2 applied\n")); |
276 |
< |
} else if (p[0] == 0x13fc && p[1] == 0x0081 && p[2] == 0xf130 && p[3] == 0xa030) { |
276 |
> |
} else if (PM(0,0x13fc) && PM(1,0x0081) && PM(2,0xf130) && PM(3,0xa030)) { |
277 |
|
// Don't write to hardware (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
278 |
< |
p[0] = M68K_NOP; |
279 |
< |
p[1] = M68K_NOP; |
280 |
< |
p[2] = M68K_NOP; |
281 |
< |
p[3] = M68K_NOP; |
278 |
> |
p[0] = htons(M68K_NOP); |
279 |
> |
p[1] = htons(M68K_NOP); |
280 |
> |
p[2] = htons(M68K_NOP); |
281 |
> |
p[3] = htons(M68K_NOP); |
282 |
|
D(bug(" patch 3 applied\n")); |
283 |
< |
} else if (p[0] == 0x4e56 && p[1] == 0x0000 && p[2] == 0x227c && p[3] == 0xf800 && p[4] == 0x0000) { |
283 |
> |
} else if (PM(0,0x4e56) && PM(1,0x0000) && PM(2,0x227c) && PM(3,0xf800) && PM(4,0x0000)) { |
284 |
|
// OpenFirmare? (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
285 |
< |
p[0] = M68K_RTS; |
285 |
> |
p[0] = htons(M68K_RTS); |
286 |
|
D(bug(" patch 4 applied\n")); |
287 |
< |
} else if (p[0] == 0x4e56 && p[1] == 0xfffc && p[2] == 0x48e7 && p[3] == 0x0300 && p[4] == 0x598f && p[5] == 0x2eb8 && p[6] == 0x01dc) { |
287 |
> |
} else if (PM(0,0x4e56) && PM(1,0xfffc) && PM(2,0x48e7) && PM(3,0x0300) && PM(4,0x598f) && PM(5,0x2eb8) && PM(6,0x01dc)) { |
288 |
|
// Don't write to SCC (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
289 |
< |
p[0] = M68K_RTS; |
289 |
> |
p[0] = htons(M68K_RTS); |
290 |
|
D(bug(" patch 5 applied\n")); |
291 |
< |
} else if (p[0] == 0x4e56 && p[1] == 0x0000 && p[2] == 0x227c && p[3] == 0xf300 && p[4] == 0x0034) { |
291 |
> |
} else if (PM(0,0x4e56) && PM(1,0x0000) && PM(2,0x227c) && PM(3,0xf300) && PM(4,0x0034)) { |
292 |
|
// Don't write to GC (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
293 |
< |
p[0] = M68K_RTS; |
293 |
> |
p[0] = htons(M68K_RTS); |
294 |
|
D(bug(" patch 6 applied\n")); |
295 |
< |
} else if (p[0] == 0x40e7 && p[1] == 0x007c && p[2] == 0x0700 && p[3] == 0x48e7 && p[4] == 0x00c0 && p[5] == 0x2078 && p[6] == 0x0dd8 && p[7] == 0xd1e8 && p[8] == 0x0044 && p[9] == 0x8005 && p[11] == 0x93c8 && p[12] == 0x2149 && p[13] == 0x0024) { |
295 |
> |
} else if (PM(0,0x40e7) && PM(1,0x007c) && PM(2,0x0700) && PM(3,0x48e7) && PM(4,0x00c0) && PM(5,0x2078) && PM(6,0x0dd8) && PM(7,0xd1e8) && PM(8,0x0044) && PM(9,0x8005) && PM(11,0x93c8) && PM(12,0x2149) && PM(13,0x0024)) { |
296 |
|
// Don't replace NVRAM routines (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
297 |
< |
p[0] = M68K_RTS; |
297 |
> |
p[0] = htons(M68K_RTS); |
298 |
|
D(bug(" patch 7 applied\n")); |
299 |
< |
} else if (p[0] == 0x207c && p[1] == 0x50f1 && p[2] == 0xa101 && (p[3] == 0x08d0 || p[3] == 0x0890)) { |
299 |
> |
} else if (PM(0,0x207c) && PM(1,0x50f1) && PM(2,0xa101) && (PM(3,0x08d0) || PM(3,0x0890))) { |
300 |
|
// Don't write to 0x50f1a101 (8.1 with Zanzibar ROM) |
301 |
< |
p[3] = M68K_NOP; |
302 |
< |
p[4] = M68K_NOP; |
301 |
> |
p[3] = htons(M68K_NOP); |
302 |
> |
p[4] = htons(M68K_NOP); |
303 |
|
D(bug(" patch 8 applied\n")); |
304 |
|
} |
305 |
|
p++; |
309 |
|
D(bug("gpch 750 found\n")); |
310 |
|
size >>= 1; |
311 |
|
while (size--) { |
312 |
< |
if (p[0] == 0xf301 && p[1] == 0x9100 && p[2] == 0x0c11 && p[3] == 0x0044) { |
312 |
> |
if (PM(0,0xf301) && PM(1,0x9100) && PM(2,0x0c11) && PM(3,0x0044)) { |
313 |
|
// Don't read from 0xf3019100 (MACE ENET) (7.6, 7.6.1, 8.0, 8.1) |
314 |
< |
p[2] = M68K_NOP; |
315 |
< |
p[3] = M68K_NOP; |
316 |
< |
p[4] = 0x6026; |
314 |
> |
p[2] = htons(M68K_NOP); |
315 |
> |
p[3] = htons(M68K_NOP); |
316 |
> |
p[4] = htons(0x6026); |
317 |
|
D(bug(" patch 1 applied\n")); |
318 |
< |
} else if (p[0] == 0x41e8 && p[1] == 0x0374 && p[2] == 0xfc1e) { |
318 |
> |
} else if (PM(0,0x41e8) && PM(1,0x0374) && PM(2,0xfc1e)) { |
319 |
|
// Don't call FC1E opcode (7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
320 |
< |
p[2] = M68K_NOP; |
320 |
> |
p[2] = htons(M68K_NOP); |
321 |
|
D(bug(" patch 2 applied\n")); |
322 |
< |
} else if (p[0] == 0x700a && p[1] == 0xfe0a) { |
322 |
> |
} else if (PM(0,0x700a) && PM(1,0xfe0a)) { |
323 |
|
// Don't call FE0A opcode (7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
324 |
< |
p[1] = 0x7000; |
324 |
> |
p[1] = htons(0x7000); |
325 |
|
D(bug(" patch 3 applied\n")); |
326 |
+ |
} else if (PM(0,0x6c00) && PM(1,0x016a) && PM(2,0x2278) && PM(3,0x0134)) { |
327 |
+ |
// We don't have SonyVars (8.6) |
328 |
+ |
p[-4] = htons(0x21fc); // move.l $40810000,($0000) |
329 |
+ |
p[-3] = htons(0x4081); |
330 |
+ |
p[-2] = htons(0x0000); |
331 |
+ |
p[-1] = htons(0x0000); |
332 |
+ |
p[0] = htons(0x6000); |
333 |
+ |
D(bug(" patch 4 applied\n")); |
334 |
|
} |
335 |
|
p++; |
336 |
|
} |
339 |
|
D(bug("gpch 999 found\n")); |
340 |
|
size >>= 1; |
341 |
|
while (size--) { |
342 |
< |
if (p[0] == 0xf301 && p[1] == 0x9100 && p[2] == 0x0c11 && p[3] == 0x0044) { |
342 |
> |
if (PM(0,0xf301) && PM(1,0x9100) && PM(2,0x0c11) && PM(3,0x0044)) { |
343 |
|
// Don't read from 0xf3019100 (MACE ENET) (8.5, 8.6) |
344 |
< |
p[2] = M68K_NOP; |
345 |
< |
p[3] = M68K_NOP; |
346 |
< |
p[4] = 0x6026; |
344 |
> |
p[2] = htons(M68K_NOP); |
345 |
> |
p[3] = htons(M68K_NOP); |
346 |
> |
p[4] = htons(0x6026); |
347 |
|
D(bug(" patch 1 applied\n")); |
348 |
|
} |
349 |
|
p++; |
353 |
|
D(bug("gpch 3000 found\n")); |
354 |
|
size >>= 1; |
355 |
|
while (size--) { |
356 |
< |
if (p[0] == 0xf301 && p[1] == 0x9100 && p[2] == 0x0c11 && p[3] == 0x0044) { |
356 |
> |
if (PM(0,0xf301) && PM(1,0x9100) && PM(2,0x0c11) && PM(3,0x0044)) { |
357 |
|
// Don't read from 0xf3019100 (MACE ENET) (8.1 with NewWorld ROM) |
358 |
< |
p[2] = M68K_NOP; |
359 |
< |
p[3] = M68K_NOP; |
360 |
< |
p[4] = 0x6026; |
358 |
> |
p[2] = htons(M68K_NOP); |
359 |
> |
p[3] = htons(M68K_NOP); |
360 |
> |
p[4] = htons(0x6026); |
361 |
|
D(bug(" patch 1 applied\n")); |
362 |
|
} |
363 |
|
p++; |
368 |
|
#if 1 |
369 |
|
size >>= 1; |
370 |
|
while (size--) { |
371 |
< |
if (p[0] == 0xc2fc && p[1] == 0x0fa0 && p[2] == 0x82c5) { |
371 |
> |
if (PM(0,0xc2fc) && PM(1,0x0fa0) && PM(2,0x82c5)) { |
372 |
|
// Prevent division by 0 in speed test (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
373 |
< |
p[2] = 0x7200; |
373 |
> |
p[2] = htons(0x7200); |
374 |
|
WriteMacInt32(0x1d8, 0x2c00); |
375 |
|
WriteMacInt32(0x1dc, 0x2c00); |
376 |
|
D(bug(" patch 1 applied\n")); |
377 |
< |
} else if (p[0] == 0x1418 && p[1] == 0x84c1) { |
377 |
> |
} else if (PM(0,0x1418) && PM(1,0x84c1)) { |
378 |
|
// Prevent division by 0 (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
379 |
< |
p[1] = 0x7400; |
379 |
> |
p[1] = htons(0x7400); |
380 |
|
D(bug(" patch 2 applied\n")); |
381 |
< |
} else if (p[0] == 0x2678 && p[1] == 0x01dc && p[2] == 0x3018 && p[3] == 0x6708 && p[4] == 0x1680 && p[5] == 0xe058 && p[6] == 0x1680) { |
381 |
> |
} else if (PM(0,0x2678) && PM(1,0x01dc) && PM(2,0x3018) && PM(3,0x6708) && PM(4,0x1680) && PM(5,0xe058) && PM(6,0x1680)) { |
382 |
|
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
383 |
< |
p[4] = M68K_NOP; |
384 |
< |
p[6] = M68K_NOP; |
383 |
> |
p[4] = htons(M68K_NOP); |
384 |
> |
p[6] = htons(M68K_NOP); |
385 |
|
D(bug(" patch 3 applied\n")); |
386 |
< |
} else if (p[0] == 0x2278 && p[1] == 0x01dc && p[2] == 0x12bc && p[3] == 0x0006 && p[4] == 0x4e71 && p[5] == 0x1292) { |
386 |
> |
} else if (PM(0,0x2278) && PM(1,0x01dc) && PM(2,0x12bc) && PM(3,0x0006) && PM(4,0x4e71) && PM(5,0x1292)) { |
387 |
|
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
388 |
< |
p[2] = M68K_NOP; |
389 |
< |
p[3] = M68K_NOP; |
390 |
< |
p[5] = M68K_NOP; |
388 |
> |
p[2] = htons(M68K_NOP); |
389 |
> |
p[3] = htons(M68K_NOP); |
390 |
> |
p[5] = htons(M68K_NOP); |
391 |
|
D(bug(" patch 4 applied\n")); |
392 |
< |
} else if (p[0] == 0x2278 && p[1] == 0x01dc && p[2] == 0x12bc && p[3] == 0x0003 && p[4] == 0x4e71 && p[5] == 0x1281) { |
392 |
> |
} else if (PM(0,0x2278) && PM(1,0x01dc) && PM(2,0x12bc) && PM(3,0x0003) && PM(4,0x4e71) && PM(5,0x1281)) { |
393 |
|
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
394 |
< |
p[2] = M68K_NOP; |
395 |
< |
p[3] = M68K_NOP; |
396 |
< |
p[5] = M68K_NOP; |
394 |
> |
p[2] = htons(M68K_NOP); |
395 |
> |
p[3] = htons(M68K_NOP); |
396 |
> |
p[5] = htons(M68K_NOP); |
397 |
|
D(bug(" patch 5 applied\n")); |
398 |
< |
} else if (p[0] == 0x0811 && p[1] == 0x0000 && p[2] == 0x51c8 && p[3] == 0xfffa) { |
398 |
> |
} else if (PM(0,0x0811) && PM(1,0x0000) && PM(2,0x51c8) && PM(3,0xfffa)) { |
399 |
|
// Don't test SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
400 |
< |
p[0] = M68K_NOP; |
401 |
< |
p[1] = M68K_NOP; |
400 |
> |
p[0] = htons(M68K_NOP); |
401 |
> |
p[1] = htons(M68K_NOP); |
402 |
|
D(bug(" patch 6 applied\n")); |
403 |
< |
} else if (p[0] == 0x4a2a && p[1] == 0x063e && p[2] == 0x66fa) { |
403 |
> |
} else if (PM(0,0x4a2a) && PM(1,0x063e) && PM(2,0x66fa)) { |
404 |
|
// Don't wait for SCC (7.5.2, 7.5.3, 7.5.5) |
405 |
< |
p[2] = M68K_NOP; |
405 |
> |
p[2] = htons(M68K_NOP); |
406 |
|
D(bug(" patch 7 applied\n")); |
407 |
< |
} else if (p[0] == 0x4a2a && p[1] == 0x03a6 && p[2] == 0x66fa) { |
407 |
> |
} else if (PM(0,0x4a2a) && PM(1,0x03a6) && PM(2,0x66fa)) { |
408 |
|
// Don't wait for SCC (7.6, 7.6.1, 8.0, 8.1) |
409 |
< |
p[2] = M68K_NOP; |
409 |
> |
p[2] = htons(M68K_NOP); |
410 |
|
D(bug(" patch 8 applied\n")); |
411 |
|
} |
412 |
|
p++; |
413 |
|
} |
414 |
|
#else |
415 |
|
// Disable LocalTalk |
416 |
< |
p[0] = M68K_JMP_A0; |
417 |
< |
p[1] = 0x7000; // moveq #0,d0 |
418 |
< |
p[2] = M68K_RTS; |
416 |
> |
p[0] = htons(M68K_JMP_A0); |
417 |
> |
p[1] = htons(0x7000); // moveq #0,d0 |
418 |
> |
p[2] = htons(M68K_RTS); |
419 |
|
D(bug(" patch 1 applied\n")); |
420 |
|
#endif |
421 |
|
|
422 |
|
} else if (type == FOURCC('n','s','r','d') && id == 1) { |
423 |
|
D(bug("nsrd 1 found\n")); |
424 |
< |
if (p[(0x378 + 0x570) >> 1] == 0x7c08 && p[(0x37a + 0x570) >> 1] == 0x02a6) { |
424 |
> |
if (p[(0x378 + 0x570) >> 1] == htons(0x7c08) && p[(0x37a + 0x570) >> 1] == htons(0x02a6)) { |
425 |
|
// Don't overwrite our serial drivers (8.0, 8.1) |
426 |
< |
p[(0x378 + 0x570) >> 1] = 0x4e80; // blr |
427 |
< |
p[(0x37a + 0x570) >> 1] = 0x0020; |
426 |
> |
p[(0x378 + 0x570) >> 1] = htons(0x4e80); // blr |
427 |
> |
p[(0x37a + 0x570) >> 1] = htons(0x0020); |
428 |
|
D(bug(" patch 1 applied\n")); |
429 |
< |
} else if (p[(0x378 + 0x6c0) >> 1] == 0x7c08 && p[(0x37a + 0x6c0) >> 1] == 0x02a6) { |
429 |
> |
} else if (p[(0x378 + 0x6c0) >> 1] == htons(0x7c08) && p[(0x37a + 0x6c0) >> 1] == htons(0x02a6)) { |
430 |
|
// Don't overwrite our serial drivers (8.5, 8.6) |
431 |
< |
p[(0x378 + 0x6c0) >> 1] = 0x4e80; // blr |
432 |
< |
p[(0x37a + 0x6c0) >> 1] = 0x0020; |
431 |
> |
p[(0x378 + 0x6c0) >> 1] = htons(0x4e80); // blr |
432 |
> |
p[(0x37a + 0x6c0) >> 1] = htons(0x0020); |
433 |
|
D(bug(" patch 2 applied\n")); |
434 |
|
} |
435 |
|
|
437 |
|
D(bug("citt 45 found\n")); |
438 |
|
size >>= 1; |
439 |
|
while (size--) { |
440 |
< |
if (p[0] == 0x203c && p[1] == 0x0100 && p[2] == 0x0000 && p[3] == 0xc0ae && p[4] == 0xfffc) { |
440 |
> |
if (PM(0,0x203c) && PM(1,0x0100) && PM(2,0x0000) && PM(3,0xc0ae) && PM(4,0xfffc)) { |
441 |
|
// Don't replace SCSI Manager (8.1, 8.5, 8.6) |
442 |
< |
p[5] = (p[5] & 0xff) | 0x6000; // beq |
442 |
> |
p[5] = htons((ntohs(p[5]) & 0xff) | 0x6000); // beq |
443 |
|
D(bug(" patch 1 applied\n")); |
444 |
|
break; |
445 |
|
} |
448 |
|
|
449 |
|
} else if (type == FOURCC('t','h','n','g')) { |
450 |
|
// Collect info about used audio sifters |
451 |
< |
uint32 c_type = 0[(uint32 *)p]; |
452 |
< |
uint32 sub_type = 1[(uint32 *)p]; |
451 |
> |
uint32 c_type = ntohl(0[(uint32 *)p]); |
452 |
> |
uint32 sub_type = ntohl(1[(uint32 *)p]); |
453 |
|
if (c_type == FOURCC('s','d','e','v') && sub_type == FOURCC('s','i','n','g')) { |
454 |
< |
1[(uint32 *)p] = FOURCC('a','w','g','c'); |
454 |
> |
1[(uint32 *)p] = htonl(FOURCC('a','w','g','c')); |
455 |
|
D(bug("thng %d, type %c%c%c%c (%08x), sub type %c%c%c%c (%08x), data %p\n", id, c_type >> 24, (c_type >> 16) & 0xff, (c_type >> 8) & 0xff, c_type & 0xff, c_type, sub_type >> 24, (sub_type >> 16) & 0xff, (sub_type >> 8) & 0xff, sub_type & 0xff, sub_type, p)); |
456 |
< |
AddSifter(*(uint32 *)(((uint32)p)+20), p[12]); |
457 |
< |
if (p[28]) // componentPFCount |
458 |
< |
AddSifter(*(uint32 *)(((uint32)p)+62), p[33]); |
456 |
> |
AddSifter(ReadMacInt32(((uintptr)p)+20), ntohs(p[12])); |
457 |
> |
if (ntohs(p[28])) // componentPFCount |
458 |
> |
AddSifter(ReadMacInt32(((uintptr)p)+62), ntohs(p[33])); |
459 |
|
} |
460 |
|
|
461 |
|
} else if (type == FOURCC('s','i','f','t') || type == FOURCC('n','i','f','t')) { |
462 |
|
// Patch audio sifters |
463 |
|
if (FindSifter(type, id)) { |
464 |
|
D(bug("sifter found\n")); |
465 |
< |
p[0] = 0x4e56; p[1] = 0x0000; // link a6,#0 |
466 |
< |
p[2] = 0x48e7; p[3] = 0x8018; // movem.l d0/a3-a4,-(a7) |
467 |
< |
p[4] = 0x266e; p[5] = 0x000c; // movea.l $c(a6),a3 |
468 |
< |
p[6] = 0x286e; p[7] = 0x0008; // movea.l $8(a6),a4 |
469 |
< |
p[8] = M68K_EMUL_OP_AUDIO_DISPATCH; |
470 |
< |
p[9] = 0x2d40; p[10] = 0x0010; // move.l d0,$10(a6) |
471 |
< |
p[11] = 0x4cdf; p[12] = 0x1801; // movem.l (a7)+,d0/a3-a4 |
472 |
< |
p[13] = 0x4e5e; // unlk a6 |
473 |
< |
p[14] = 0x4e74; p[15] = 0x0008; // rtd #8 |
465 |
> |
p[0] = htons(0x4e56); p[1] = htons(0x0000); // link a6,#0 |
466 |
> |
p[2] = htons(0x48e7); p[3] = htons(0x8018); // movem.l d0/a3-a4,-(a7) |
467 |
> |
p[4] = htons(0x266e); p[5] = htons(0x000c); // movea.l $c(a6),a3 |
468 |
> |
p[6] = htons(0x286e); p[7] = htons(0x0008); // movea.l $8(a6),a4 |
469 |
> |
p[8] = htons(M68K_EMUL_OP_AUDIO_DISPATCH); |
470 |
> |
p[9] = htons(0x2d40); p[10] = htons(0x0010); // move.l d0,$10(a6) |
471 |
> |
p[11] = htons(0x4cdf); p[12] = htons(0x1801); // movem.l (a7)+,d0/a3-a4 |
472 |
> |
p[13] = htons(0x4e5e); // unlk a6 |
473 |
> |
p[14] = htons(0x4e74); p[15] = htons(0x0008); // rtd #8 |
474 |
|
D(bug(" patch applied\n")); |
475 |
|
} |
476 |
|
|
484 |
|
D(bug("INIT 1 (size 2416) found\n")); |
485 |
|
size >>= 1; |
486 |
|
while (size--) { |
487 |
< |
if (p[0] == 0x247c && p[1] == 0xf301 && p[2] == 0x9000) { |
487 |
> |
if (PM(0,0x247c) && PM(1,0xf301) && PM(2,0x9000)) { |
488 |
|
// Prevent "MacOS Licensing Extension" from accessing hardware (7.6) |
489 |
< |
p[22] = 0x6028; |
489 |
> |
p[22] = htons(0x6028); |
490 |
|
D(bug(" patch 1 applied\n")); |
491 |
|
break; |
492 |
|
} |
493 |
|
p++; |
494 |
|
} |
495 |
+ |
|
496 |
+ |
} else if (type == FOURCC('s','c','o','d') && id == -16465) { |
497 |
+ |
D(bug("scod -16465 found\n")); |
498 |
+ |
|
499 |
+ |
// Don't crash in Process Manager on reset/shutdown (8.6) |
500 |
+ |
static const uint8 dat[] = {0x4e, 0x56, 0x00, 0x00, 0x48, 0xe7, 0x03, 0x18, 0x2c, 0x2e, 0x00, 0x10}; |
501 |
+ |
base = find_rsrc_data((uint8 *)p, size, dat, sizeof(dat)); |
502 |
+ |
if (base) { |
503 |
+ |
p16 = (uint16 *)((uintptr)p + base); |
504 |
+ |
p16[0] = htons(0x7000); // moveq #0,d0 |
505 |
+ |
p16[1] = htons(M68K_RTS); |
506 |
+ |
D(bug(" patch 1 applied\n")); |
507 |
+ |
} |
508 |
|
} |
509 |
|
} |
510 |
|
|
515 |
|
|
516 |
|
#ifdef __BEOS__ |
517 |
|
static |
518 |
+ |
#else |
519 |
+ |
extern "C" |
520 |
|
#endif |
521 |
< |
void check_load_invoc(uint32 type, int16 id, uint16 **h) |
521 |
> |
void check_load_invoc(uint32 type, int16 id, uint32 h) |
522 |
|
{ |
523 |
< |
if (h == NULL) |
523 |
> |
if (h == 0) |
524 |
|
return; |
525 |
< |
uint16 *p = *h; |
526 |
< |
if (p == NULL) |
525 |
> |
uint32 p = ReadMacInt32(h); |
526 |
> |
if (p == 0) |
527 |
|
return; |
528 |
< |
uint32 size = ((uint32 *)p)[-2] & 0xffffff; |
528 |
> |
uint32 size = ReadMacInt32(p - 2 * 4) & 0xffffff; |
529 |
|
|
530 |
< |
CheckLoad(type, id, p, size); |
530 |
> |
CheckLoad(type, id, (uint16 *)p, size); |
531 |
|
} |
532 |
|
|
533 |
|
#ifdef __BEOS__ |
709 |
|
D(bug("PatchNativeResourceManager\n")); |
710 |
|
|
711 |
|
// Patch native GetResource() |
712 |
< |
uint32 **upp = *(uint32 ***)0x1480; |
713 |
< |
if (((uint32)upp & 0xffc00000) == ROM_BASE) |
712 |
> |
uint32 upp = ReadMacInt32(0x1480); |
713 |
> |
if ((upp & 0xffc00000) == ROM_BASE) |
714 |
|
return; |
715 |
< |
uint32 *tvec = upp[5]; |
716 |
< |
D(bug(" GetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
715 |
> |
uint32 *tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
716 |
> |
D(bug(" GetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
717 |
|
*(uint32 *)XLM_RES_LIB_TOC = tvec[1]; |
718 |
|
*(uint32 *)XLM_GET_RESOURCE = tvec[0]; |
719 |
+ |
#if EMULATED_PPC |
720 |
+ |
tvec[0] = htonl(NativeFunction(NATIVE_GET_RESOURCE)); |
721 |
+ |
#else |
722 |
|
#ifdef __BEOS__ |
723 |
|
uint32 *tvec2 = (uint32 *)get_resource; |
724 |
|
tvec[0] = tvec2[0]; |
726 |
|
#else |
727 |
|
tvec[0] = (uint32)get_resource; |
728 |
|
#endif |
729 |
+ |
#endif |
730 |
|
|
731 |
|
// Patch native Get1Resource() |
732 |
< |
upp = *(uint32 ***)0xe7c; |
733 |
< |
tvec = upp[5]; |
734 |
< |
D(bug(" Get1Resource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
732 |
> |
upp = ReadMacInt32(0x0e7c); |
733 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
734 |
> |
D(bug(" Get1Resource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
735 |
|
*(uint32 *)XLM_GET_1_RESOURCE = tvec[0]; |
736 |
+ |
#if EMULATED_PPC |
737 |
+ |
tvec[0] = htonl(NativeFunction(NATIVE_GET_1_RESOURCE)); |
738 |
+ |
#else |
739 |
|
#ifdef __BEOS__ |
740 |
|
tvec2 = (uint32 *)get_1_resource; |
741 |
|
tvec[0] = tvec2[0]; |
743 |
|
#else |
744 |
|
tvec[0] = (uint32)get_1_resource; |
745 |
|
#endif |
746 |
+ |
#endif |
747 |
|
|
748 |
|
// Patch native GetIndResource() |
749 |
< |
upp = *(uint32 ***)0x1474; |
750 |
< |
tvec = upp[5]; |
751 |
< |
D(bug(" GetIndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
749 |
> |
upp = ReadMacInt32(0x1474); |
750 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
751 |
> |
D(bug(" GetIndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
752 |
|
*(uint32 *)XLM_GET_IND_RESOURCE = tvec[0]; |
753 |
+ |
#if EMULATED_PPC |
754 |
+ |
tvec[0] = htonl(NativeFunction(NATIVE_GET_IND_RESOURCE)); |
755 |
+ |
#else |
756 |
|
#ifdef __BEOS__ |
757 |
|
tvec2 = (uint32 *)get_ind_resource; |
758 |
|
tvec[0] = tvec2[0]; |
760 |
|
#else |
761 |
|
tvec[0] = (uint32)get_ind_resource; |
762 |
|
#endif |
763 |
+ |
#endif |
764 |
|
|
765 |
|
// Patch native Get1IndResource() |
766 |
< |
upp = *(uint32 ***)0xe38; |
767 |
< |
tvec = upp[5]; |
768 |
< |
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
766 |
> |
upp = ReadMacInt32(0x0e38); |
767 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
768 |
> |
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
769 |
|
*(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0]; |
770 |
+ |
#if EMULATED_PPC |
771 |
+ |
tvec[0] = htonl(NativeFunction(NATIVE_GET_1_IND_RESOURCE)); |
772 |
+ |
#else |
773 |
|
#ifdef __BEOS__ |
774 |
|
tvec2 = (uint32 *)get_1_ind_resource; |
775 |
|
tvec[0] = tvec2[0]; |
777 |
|
#else |
778 |
|
tvec[0] = (uint32)get_1_ind_resource; |
779 |
|
#endif |
780 |
+ |
#endif |
781 |
|
|
782 |
|
// Patch native RGetResource() |
783 |
< |
upp = *(uint32 ***)0xe30; |
784 |
< |
tvec = upp[5]; |
785 |
< |
D(bug(" RGetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
783 |
> |
upp = ReadMacInt32(0x0e30); |
784 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
785 |
> |
D(bug(" RGetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
786 |
|
*(uint32 *)XLM_R_GET_RESOURCE = tvec[0]; |
787 |
+ |
#if EMULATED_PPC |
788 |
+ |
tvec[0] = htonl(NativeFunction(NATIVE_R_GET_RESOURCE)); |
789 |
+ |
#else |
790 |
|
#ifdef __BEOS__ |
791 |
|
tvec2 = (uint32 *)r_get_resource; |
792 |
|
tvec[0] = tvec2[0]; |
794 |
|
#else |
795 |
|
tvec[0] = (uint32)r_get_resource; |
796 |
|
#endif |
797 |
+ |
#endif |
798 |
|
} |