1 |
cebix |
1.1 |
/* |
2 |
|
|
* rsrc_patches.cpp - Resource patches |
3 |
|
|
* |
4 |
|
|
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include <stdio.h> |
22 |
|
|
#include <stdlib.h> |
23 |
|
|
#include <string.h> |
24 |
|
|
|
25 |
|
|
#include "sysdeps.h" |
26 |
|
|
#include "rsrc_patches.h" |
27 |
|
|
#include "cpu_emulation.h" |
28 |
|
|
#include "emul_op.h" |
29 |
|
|
#include "xlowmem.h" |
30 |
|
|
#include "macos_util.h" |
31 |
|
|
#include "rom_patches.h" |
32 |
|
|
#include "main.h" |
33 |
|
|
#include "audio.h" |
34 |
|
|
|
35 |
|
|
#define DEBUG 0 |
36 |
|
|
#include "debug.h" |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
// Sound input driver |
40 |
|
|
static const uint8 sound_input_driver[] = { // .AppleSoundInput driver header |
41 |
|
|
// Driver header |
42 |
|
|
0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
43 |
|
|
0x00, 0x24, // Open() offset |
44 |
|
|
0x00, 0x28, // Prime() offset |
45 |
|
|
0x00, 0x2c, // Control() offset |
46 |
|
|
0x00, 0x38, // Status() offset |
47 |
|
|
0x00, 0x5e, // Close() offset |
48 |
|
|
0x10, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x00, // ".AppleSoundInput" |
49 |
|
|
|
50 |
|
|
// Open() |
51 |
|
|
M68K_EMUL_OP_SOUNDIN_OPEN >> 8, M68K_EMUL_OP_SOUNDIN_OPEN & 0xff, |
52 |
|
|
0x4e, 0x75, // rts |
53 |
|
|
|
54 |
|
|
// Prime() |
55 |
|
|
M68K_EMUL_OP_SOUNDIN_PRIME >> 8, M68K_EMUL_OP_SOUNDIN_PRIME & 0xff, |
56 |
|
|
0x60, 0x0e, // bra IOReturn |
57 |
|
|
|
58 |
|
|
// Control() |
59 |
|
|
M68K_EMUL_OP_SOUNDIN_CONTROL >> 8, M68K_EMUL_OP_SOUNDIN_CONTROL & 0xff, |
60 |
|
|
0x0c, 0x68, 0x00, 0x01, 0x00, 0x1a, // cmp.w #1,$1a(a0) |
61 |
|
|
0x66, 0x04, // bne IOReturn |
62 |
|
|
0x4e, 0x75, // rts |
63 |
|
|
|
64 |
|
|
// Status() |
65 |
|
|
M68K_EMUL_OP_SOUNDIN_STATUS >> 8, M68K_EMUL_OP_SOUNDIN_STATUS & 0xff, |
66 |
|
|
|
67 |
|
|
// IOReturn |
68 |
|
|
0x32, 0x28, 0x00, 0x06, // move.w 6(a0),d1 |
69 |
|
|
0x08, 0x01, 0x00, 0x09, // btst #9,d1 |
70 |
|
|
0x67, 0x0c, // beq 1 |
71 |
|
|
0x4a, 0x40, // tst.w d0 |
72 |
|
|
0x6f, 0x02, // ble 2 |
73 |
|
|
0x42, 0x40, // clr.w d0 |
74 |
|
|
0x31, 0x40, 0x00, 0x10, //2 move.w d0,$10(a0) |
75 |
|
|
0x4e, 0x75, // rts |
76 |
|
|
0x4a, 0x40, //1 tst.w d0 |
77 |
|
|
0x6f, 0x04, // ble 3 |
78 |
|
|
0x42, 0x40, // clr.w d0 |
79 |
|
|
0x4e, 0x75, // rts |
80 |
|
|
0x2f, 0x38, 0x08, 0xfc, //3 move.l $8fc,-(sp) |
81 |
|
|
0x4e, 0x75, // rts |
82 |
|
|
|
83 |
|
|
// Close() |
84 |
|
|
M68K_EMUL_OP_SOUNDIN_CLOSE >> 8, M68K_EMUL_OP_SOUNDIN_CLOSE & 0xff, |
85 |
|
|
0x4e, 0x75, // rts |
86 |
|
|
}; |
87 |
|
|
|
88 |
|
|
|
89 |
|
|
/* |
90 |
|
|
* Search resource for byte string, return offset (or 0) |
91 |
|
|
*/ |
92 |
|
|
|
93 |
|
|
static uint32 find_rsrc_data(const uint8 *rsrc, uint32 max, const uint8 *search, uint32 search_len, uint32 ofs = 0) |
94 |
|
|
{ |
95 |
|
|
while (ofs < max - search_len) { |
96 |
|
|
if (!memcmp(rsrc + ofs, search, search_len)) |
97 |
|
|
return ofs; |
98 |
|
|
ofs++; |
99 |
|
|
} |
100 |
|
|
return 0; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
|
104 |
|
|
/* |
105 |
|
|
* Resource patches via vCheckLoad |
106 |
|
|
*/ |
107 |
|
|
|
108 |
|
|
void CheckLoad(uint32 type, int16 id, uint16 *p, uint32 size) |
109 |
|
|
{ |
110 |
|
|
uint16 *p16; |
111 |
|
|
uint32 base; |
112 |
|
|
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)); |
113 |
|
|
|
114 |
|
|
// Don't modify resources in ROM |
115 |
|
|
if ((uint32)p >= ROM_BASE && (uint32)p <= (ROM_BASE + ROM_SIZE)) |
116 |
|
|
return; |
117 |
|
|
|
118 |
|
|
if (type == FOURCC('b','o','o','t') && id == 3) { |
119 |
|
|
D(bug("boot 3 found\n")); |
120 |
|
|
size >>= 1; |
121 |
|
|
while (size--) { |
122 |
|
|
if (p[0] == 0x2e49) { |
123 |
|
|
// 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) |
124 |
|
|
p[0] = M68K_EMUL_OP_FIX_BOOTSTACK; |
125 |
|
|
D(bug(" patch 1 applied\n")); |
126 |
|
|
} else if (p[0] == 0x4267 && p[1] == 0x3f01 && p[2] == 0x3f2a && p[3] == 0x0006 && p[4] == 0x6100) { |
127 |
|
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.5.3, 7.5.5) |
128 |
|
|
p[7] = M68K_EMUL_OP_NTRB_17_PATCH3; |
129 |
|
|
D(bug(" patch 2 applied\n")); |
130 |
|
|
} else if (p[0] == 0x3f2a && p[1] == 0x0006 && p[2] == 0x3f2a && p[3] == 0x0002 && p[4] == 0x6100) { |
131 |
|
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.6, 7.6.1, 8.0, 8.1) |
132 |
|
|
p[7] = M68K_EMUL_OP_NTRB_17_PATCH; |
133 |
|
|
D(bug(" patch 3 applied\n")); |
134 |
|
|
} else if (p[0] == 0x3f2a && p[1] == 0x0006 && p[2] == 0x3f2a && p[3] == 0x0002 && p[4] == 0x61ff) { |
135 |
|
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (8.5, 8.6) |
136 |
|
|
p[8] = M68K_EMUL_OP_NTRB_17_PATCH; |
137 |
|
|
D(bug(" patch 4 applied\n")); |
138 |
|
|
} else if (p[0] == 0x0c39 && p[1] == 0x0001 && p[2] == 0xf800 && p[3] == 0x0008 && p[4] == 0x6f00) { |
139 |
|
|
// Don't read from 0xf8000008 (8.5 with Zanzibar ROM, 8.6) |
140 |
|
|
p[0] = M68K_NOP; |
141 |
|
|
p[1] = M68K_NOP; |
142 |
|
|
p[2] = M68K_NOP; |
143 |
|
|
p[3] = M68K_NOP; |
144 |
|
|
p[4] = 0x6000; // bra |
145 |
|
|
D(bug(" patch 5 applied\n")); |
146 |
|
|
} 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) { |
147 |
|
|
// Don't replace nanokernel ("krnl" resource) (8.6) |
148 |
|
|
p[0] = M68K_NOP; |
149 |
|
|
p[1] = M68K_NOP; |
150 |
|
|
p[2] = M68K_NOP; |
151 |
|
|
p[3] = M68K_NOP; |
152 |
|
|
p[4] = M68K_NOP; |
153 |
|
|
p[7] = 0x6000; // bra |
154 |
|
|
D(bug(" patch 6 applied\n")); |
155 |
|
|
} else if (p[0] == 0xa8fe && p[1] == 0x3038 && p[2] == 0x017a && p[3] == 0x0c40 && p[4] == 0x8805 && p[5] == 0x6710) { |
156 |
|
|
// No SCSI (calls via 0x205c jump vector which is not initialized in NewWorld ROM 1.6) (8.6) |
157 |
|
|
if (ROMType == ROMTYPE_NEWWORLD) { |
158 |
|
|
p[5] = 0x6010; // bra |
159 |
|
|
D(bug(" patch 7 applied\n")); |
160 |
|
|
} |
161 |
|
|
} |
162 |
|
|
p++; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
} else if (type == FOURCC('g','n','l','d') && id == 0) { |
166 |
|
|
D(bug("gnld 0 found\n")); |
167 |
|
|
|
168 |
|
|
// Patch native Resource Manager after ntrbs are installed (7.5.2) |
169 |
|
|
static const uint8 dat[] = {0x4e, 0xba, 0x00, 0x9e, 0x3e, 0x00, 0x50, 0x4f, 0x67, 0x04}; |
170 |
|
|
base = find_rsrc_data((uint8 *)p, size, dat, sizeof(dat)); |
171 |
|
|
if (base) { |
172 |
|
|
p16 = (uint16 *)((uint32)p + base + 6); |
173 |
|
|
*p16 = htons(M68K_EMUL_OP_NTRB_17_PATCH2); |
174 |
|
|
D(bug(" patch 1 applied\n")); |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
} else if (type == FOURCC('p','t','c','h') && id == 420) { |
178 |
|
|
D(bug("ptch 420 found\n")); |
179 |
|
|
size >>= 1; |
180 |
|
|
while (size--) { |
181 |
|
|
if (p[0] == 0xa030 && p[1] == 0x5240 && p[2] == 0x303c && p[3] == 0x0100 && p[4] == 0xc06e && p[5] == 0xfef6) { |
182 |
|
|
// Disable VM (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1) |
183 |
|
|
p[1] = M68K_NOP; |
184 |
|
|
p[2] = M68K_NOP; |
185 |
|
|
p[3] = M68K_NOP; |
186 |
|
|
p[4] = M68K_NOP; |
187 |
|
|
p[5] = M68K_NOP; |
188 |
|
|
p[6] = M68K_NOP; |
189 |
|
|
p[7] = M68K_NOP; |
190 |
|
|
p[8] = M68K_NOP; |
191 |
|
|
p[9] = M68K_NOP; |
192 |
|
|
p[10] = M68K_NOP; |
193 |
|
|
p[11] = M68K_NOP; |
194 |
|
|
D(bug(" patch 1 applied\n")); |
195 |
|
|
break; |
196 |
|
|
} else if (p[0] == 0xa030 && p[1] == 0x5240 && p[2] == 0x7000 && p[3] == 0x302e && p[4] == 0xfef6 && p[5] == 0x323c && p[6] == 0x0100) { |
197 |
|
|
// Disable VM (8.0, 8.1) |
198 |
|
|
p[8] = M68K_NOP; |
199 |
|
|
p[15] = M68K_NOP; |
200 |
|
|
D(bug(" patch 2 applied\n")); |
201 |
|
|
break; |
202 |
|
|
} else if (p[0] == 0xa030 && p[1] == 0x5240 && p[2] == 0x7000 && p[3] == 0x302e && p[4] == 0xfecc && p[5] == 0x323c && p[6] == 0x0100) { |
203 |
|
|
// Disable VM (8.5, 8.6) |
204 |
|
|
p[8] = M68K_NOP; |
205 |
|
|
p[15] = M68K_NOP; |
206 |
|
|
D(bug(" patch 3 applied\n")); |
207 |
|
|
break; |
208 |
|
|
} |
209 |
|
|
p++; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 16) { |
213 |
|
|
D(bug("gpch 16 found\n")); |
214 |
|
|
size >>= 1; |
215 |
|
|
while (size--) { |
216 |
|
|
if (p[0] == 0x6700 && p[13] == 0x7013 && p[14] == 0xfe0a) { |
217 |
|
|
// Don't call FE0A in Shutdown Manager (7.6.1, 8.0, 8.1, 8.5) |
218 |
|
|
p[0] = 0x6000; |
219 |
|
|
D(bug(" patch 1 applied\n")); |
220 |
|
|
break; |
221 |
|
|
} |
222 |
|
|
p++; |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 650) { |
226 |
|
|
D(bug("gpch 650 found\n")); |
227 |
|
|
size >>= 1; |
228 |
|
|
while (size--) { |
229 |
|
|
if (p[0] == 0x6600 && p[1] == 0x001a && p[2] == 0x2278 && p[3] == 0x0134) { |
230 |
|
|
// We don't have SonyVars (7.5.2) |
231 |
|
|
p[0] = 0x6000; |
232 |
|
|
D(bug(" patch 1 applied\n")); |
233 |
|
|
} else if (p[0] == 0x6618 && p[1] == 0x2278 && p[2] == 0x0134) { |
234 |
|
|
// We don't have SonyVars (7.5.3) |
235 |
|
|
p[-6] = M68K_NOP; |
236 |
|
|
p[-3] = M68K_NOP; |
237 |
|
|
p[0] = 0x6018; |
238 |
|
|
D(bug(" patch 2 applied\n")); |
239 |
|
|
} else if (p[0] == 0x666e && p[1] == 0x2278 && p[2] == 0x0134) { |
240 |
|
|
// We don't have SonyVars (7.5.5) |
241 |
|
|
p[-6] = M68K_NOP; |
242 |
|
|
p[-3] = M68K_NOP; |
243 |
|
|
p[0] = 0x606e; |
244 |
|
|
D(bug(" patch 3 applied\n")); |
245 |
|
|
} else if (p[0] == 0x6400 && p[1] == 0x011c && p[2] == 0x2278 && p[3] == 0x0134) { |
246 |
|
|
// We don't have SonyVars (7.6.1, 8.0, 8.1, 8.5, 8.6) |
247 |
|
|
p[0] = 0x6000; |
248 |
|
|
D(bug(" patch 4 applied\n")); |
249 |
|
|
} else if (p[0] == 0x6400 && p[1] == 0x00e6 && p[2] == 0x2278 && p[3] == 0x0134) { |
250 |
|
|
// We don't have SonyVars (7.6) |
251 |
|
|
p[0] = 0x6000; |
252 |
|
|
D(bug(" patch 5 applied\n")); |
253 |
|
|
} |
254 |
|
|
p++; |
255 |
|
|
} |
256 |
|
|
|
257 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 655) { |
258 |
|
|
D(bug("gpch 655 found\n")); |
259 |
|
|
size >>= 1; |
260 |
|
|
while (size--) { |
261 |
|
|
if (p[0] == 0x83a8 && p[1] == 0x0024 && p[2] == 0x4e71) { |
262 |
|
|
// Don't write to GC interrupt mask (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
263 |
|
|
p[0] = M68K_NOP; |
264 |
|
|
p[1] = M68K_NOP; |
265 |
|
|
D(bug(" patch 1 applied\n")); |
266 |
|
|
} else if (p[0] == 0x207c && p[1] == 0xf300 && p[2] == 0x0034) { |
267 |
|
|
// Don't read PowerMac ID (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
268 |
|
|
p[0] = 0x303c; // move.w #id,d0 |
269 |
|
|
p[1] = 0x3020; |
270 |
|
|
p[2] = M68K_RTS; |
271 |
|
|
D(bug(" patch 2 applied\n")); |
272 |
|
|
} else if (p[0] == 0x13fc && p[1] == 0x0081 && p[2] == 0xf130 && p[3] == 0xa030) { |
273 |
|
|
// Don't write to hardware (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
274 |
|
|
p[0] = M68K_NOP; |
275 |
|
|
p[1] = M68K_NOP; |
276 |
|
|
p[2] = M68K_NOP; |
277 |
|
|
p[3] = M68K_NOP; |
278 |
|
|
D(bug(" patch 3 applied\n")); |
279 |
|
|
} else if (p[0] == 0x4e56 && p[1] == 0x0000 && p[2] == 0x227c && p[3] == 0xf800 && p[4] == 0x0000) { |
280 |
|
|
// OpenFirmare? (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
281 |
|
|
p[0] = M68K_RTS; |
282 |
|
|
D(bug(" patch 4 applied\n")); |
283 |
|
|
} else if (p[0] == 0x4e56 && p[1] == 0xfffc && p[2] == 0x48e7 && p[3] == 0x0300 && p[4] == 0x598f && p[5] == 0x2eb8 && p[6] == 0x01dc) { |
284 |
|
|
// Don't write to SCC (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
285 |
|
|
p[0] = M68K_RTS; |
286 |
|
|
D(bug(" patch 5 applied\n")); |
287 |
|
|
} else if (p[0] == 0x4e56 && p[1] == 0x0000 && p[2] == 0x227c && p[3] == 0xf300 && p[4] == 0x0034) { |
288 |
|
|
// Don't write to GC (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
289 |
|
|
p[0] = M68K_RTS; |
290 |
|
|
D(bug(" patch 6 applied\n")); |
291 |
|
|
} 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) { |
292 |
|
|
// Don't replace NVRAM routines (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
293 |
|
|
p[0] = M68K_RTS; |
294 |
|
|
D(bug(" patch 7 applied\n")); |
295 |
|
|
} else if (p[0] == 0x207c && p[1] == 0x50f1 && p[2] == 0xa101 && (p[3] == 0x08d0 || p[3] == 0x0890)) { |
296 |
|
|
// Don't write to 0x50f1a101 (8.1 with Zanzibar ROM) |
297 |
|
|
p[3] = M68K_NOP; |
298 |
|
|
p[4] = M68K_NOP; |
299 |
|
|
D(bug(" patch 8 applied\n")); |
300 |
|
|
} |
301 |
|
|
p++; |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 750) { |
305 |
|
|
D(bug("gpch 750 found\n")); |
306 |
|
|
size >>= 1; |
307 |
|
|
while (size--) { |
308 |
|
|
if (p[0] == 0xf301 && p[1] == 0x9100 && p[2] == 0x0c11 && p[3] == 0x0044) { |
309 |
|
|
// Don't read from 0xf3019100 (MACE ENET) (7.6, 7.6.1, 8.0, 8.1) |
310 |
|
|
p[2] = M68K_NOP; |
311 |
|
|
p[3] = M68K_NOP; |
312 |
|
|
p[4] = 0x6026; |
313 |
|
|
D(bug(" patch 1 applied\n")); |
314 |
|
|
} else if (p[0] == 0x41e8 && p[1] == 0x0374 && p[2] == 0xfc1e) { |
315 |
|
|
// Don't call FC1E opcode (7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
316 |
|
|
p[2] = M68K_NOP; |
317 |
|
|
D(bug(" patch 2 applied\n")); |
318 |
|
|
} else if (p[0] == 0x700a && p[1] == 0xfe0a) { |
319 |
|
|
// Don't call FE0A opcode (7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
320 |
|
|
p[1] = 0x7000; |
321 |
|
|
D(bug(" patch 3 applied\n")); |
322 |
|
|
} |
323 |
|
|
p++; |
324 |
|
|
} |
325 |
|
|
|
326 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 999) { |
327 |
|
|
D(bug("gpch 999 found\n")); |
328 |
|
|
size >>= 1; |
329 |
|
|
while (size--) { |
330 |
|
|
if (p[0] == 0xf301 && p[1] == 0x9100 && p[2] == 0x0c11 && p[3] == 0x0044) { |
331 |
|
|
// Don't read from 0xf3019100 (MACE ENET) (8.5, 8.6) |
332 |
|
|
p[2] = M68K_NOP; |
333 |
|
|
p[3] = M68K_NOP; |
334 |
|
|
p[4] = 0x6026; |
335 |
|
|
D(bug(" patch 1 applied\n")); |
336 |
|
|
} |
337 |
|
|
p++; |
338 |
|
|
} |
339 |
|
|
|
340 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 3000) { |
341 |
|
|
D(bug("gpch 3000 found\n")); |
342 |
|
|
size >>= 1; |
343 |
|
|
while (size--) { |
344 |
|
|
if (p[0] == 0xf301 && p[1] == 0x9100 && p[2] == 0x0c11 && p[3] == 0x0044) { |
345 |
|
|
// Don't read from 0xf3019100 (MACE ENET) (8.1 with NewWorld ROM) |
346 |
|
|
p[2] = M68K_NOP; |
347 |
|
|
p[3] = M68K_NOP; |
348 |
|
|
p[4] = 0x6026; |
349 |
|
|
D(bug(" patch 1 applied\n")); |
350 |
|
|
} |
351 |
|
|
p++; |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
} else if (type == FOURCC('l','t','l','k') && id == 0) { |
355 |
|
|
D(bug("ltlk 0 found\n")); |
356 |
|
|
#if 1 |
357 |
|
|
size >>= 1; |
358 |
|
|
while (size--) { |
359 |
|
|
if (p[0] == 0xc2fc && p[1] == 0x0fa0 && p[2] == 0x82c5) { |
360 |
|
|
// 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) |
361 |
|
|
p[2] = 0x7200; |
362 |
|
|
WriteMacInt32(0x1d8, 0x2c00); |
363 |
|
|
WriteMacInt32(0x1dc, 0x2c00); |
364 |
|
|
D(bug(" patch 1 applied\n")); |
365 |
|
|
} else if (p[0] == 0x1418 && p[1] == 0x84c1) { |
366 |
|
|
// Prevent division by 0 (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
367 |
|
|
p[1] = 0x7400; |
368 |
|
|
D(bug(" patch 2 applied\n")); |
369 |
|
|
} else if (p[0] == 0x2678 && p[1] == 0x01dc && p[2] == 0x3018 && p[3] == 0x6708 && p[4] == 0x1680 && p[5] == 0xe058 && p[6] == 0x1680) { |
370 |
|
|
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
371 |
|
|
p[4] = M68K_NOP; |
372 |
|
|
p[6] = M68K_NOP; |
373 |
|
|
D(bug(" patch 3 applied\n")); |
374 |
|
|
} else if (p[0] == 0x2278 && p[1] == 0x01dc && p[2] == 0x12bc && p[3] == 0x0006 && p[4] == 0x4e71 && p[5] == 0x1292) { |
375 |
|
|
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
376 |
|
|
p[2] = M68K_NOP; |
377 |
|
|
p[3] = M68K_NOP; |
378 |
|
|
p[5] = M68K_NOP; |
379 |
|
|
D(bug(" patch 4 applied\n")); |
380 |
|
|
} else if (p[0] == 0x2278 && p[1] == 0x01dc && p[2] == 0x12bc && p[3] == 0x0003 && p[4] == 0x4e71 && p[5] == 0x1281) { |
381 |
|
|
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
382 |
|
|
p[2] = M68K_NOP; |
383 |
|
|
p[3] = M68K_NOP; |
384 |
|
|
p[5] = M68K_NOP; |
385 |
|
|
D(bug(" patch 5 applied\n")); |
386 |
|
|
} else if (p[0] == 0x0811 && p[1] == 0x0000 && p[2] == 0x51c8 && p[3] == 0xfffa) { |
387 |
|
|
// Don't test SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
388 |
|
|
p[0] = M68K_NOP; |
389 |
|
|
p[1] = M68K_NOP; |
390 |
|
|
D(bug(" patch 6 applied\n")); |
391 |
|
|
} else if (p[0] == 0x4a2a && p[1] == 0x063e && p[2] == 0x66fa) { |
392 |
|
|
// Don't wait for SCC (7.5.2, 7.5.3, 7.5.5) |
393 |
|
|
p[2] = M68K_NOP; |
394 |
|
|
D(bug(" patch 7 applied\n")); |
395 |
|
|
} else if (p[0] == 0x4a2a && p[1] == 0x03a6 && p[2] == 0x66fa) { |
396 |
|
|
// Don't wait for SCC (7.6, 7.6.1, 8.0, 8.1) |
397 |
|
|
p[2] = M68K_NOP; |
398 |
|
|
D(bug(" patch 8 applied\n")); |
399 |
|
|
} |
400 |
|
|
p++; |
401 |
|
|
} |
402 |
|
|
#else |
403 |
|
|
// Disable LocalTalk |
404 |
|
|
p[0] = M68K_JMP_A0; |
405 |
|
|
p[1] = 0x7000; // moveq #0,d0 |
406 |
|
|
p[2] = M68K_RTS; |
407 |
|
|
D(bug(" patch 1 applied\n")); |
408 |
|
|
#endif |
409 |
|
|
|
410 |
|
|
} else if (type == FOURCC('n','s','r','d') && id == 1) { |
411 |
|
|
D(bug("nsrd 1 found\n")); |
412 |
|
|
if (p[(0x378 + 0x570) >> 1] == 0x7c08 && p[(0x37a + 0x570) >> 1] == 0x02a6) { |
413 |
|
|
// Don't overwrite our serial drivers (8.0, 8.1) |
414 |
|
|
p[(0x378 + 0x570) >> 1] = 0x4e80; // blr |
415 |
|
|
p[(0x37a + 0x570) >> 1] = 0x0020; |
416 |
|
|
D(bug(" patch 1 applied\n")); |
417 |
|
|
} else if (p[(0x378 + 0x6c0) >> 1] == 0x7c08 && p[(0x37a + 0x6c0) >> 1] == 0x02a6) { |
418 |
|
|
// Don't overwrite our serial drivers (8.5, 8.6) |
419 |
|
|
p[(0x378 + 0x6c0) >> 1] = 0x4e80; // blr |
420 |
|
|
p[(0x37a + 0x6c0) >> 1] = 0x0020; |
421 |
|
|
D(bug(" patch 2 applied\n")); |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
} else if (type == FOURCC('c','i','t','t') && id == 45) { |
425 |
|
|
D(bug("citt 45 found\n")); |
426 |
|
|
size >>= 1; |
427 |
|
|
while (size--) { |
428 |
|
|
if (p[0] == 0x203c && p[1] == 0x0100 && p[2] == 0x0000 && p[3] == 0xc0ae && p[4] == 0xfffc) { |
429 |
|
|
// Don't replace SCSI Manager (8.1, 8.5, 8.6) |
430 |
|
|
p[5] = (p[5] & 0xff) | 0x6000; // beq |
431 |
|
|
D(bug(" patch 1 applied\n")); |
432 |
|
|
break; |
433 |
|
|
} |
434 |
|
|
p++; |
435 |
|
|
} |
436 |
|
|
|
437 |
|
|
} else if (type == FOURCC('t','h','n','g')) { |
438 |
|
|
// Collect info about used audio sifters |
439 |
|
|
uint32 c_type = 0[(uint32 *)p]; |
440 |
|
|
uint32 sub_type = 1[(uint32 *)p]; |
441 |
|
|
if (c_type == FOURCC('s','d','e','v') && sub_type == FOURCC('s','i','n','g')) { |
442 |
|
|
1[(uint32 *)p] = FOURCC('a','w','g','c'); |
443 |
|
|
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)); |
444 |
|
|
AddSifter(*(uint32 *)(((uint32)p)+20), p[12]); |
445 |
|
|
if (p[28]) // componentPFCount |
446 |
|
|
AddSifter(*(uint32 *)(((uint32)p)+62), p[33]); |
447 |
|
|
} |
448 |
|
|
|
449 |
|
|
} else if (type == FOURCC('s','i','f','t') || type == FOURCC('n','i','f','t')) { |
450 |
|
|
// Patch audio sifters |
451 |
|
|
if (FindSifter(type, id)) { |
452 |
|
|
D(bug("sifter found\n")); |
453 |
|
|
p[0] = 0x4e56; p[1] = 0x0000; // link a6,#0 |
454 |
|
|
p[2] = 0x48e7; p[3] = 0x8018; // movem.l d0/a3-a4,-(a7) |
455 |
|
|
p[4] = 0x266e; p[5] = 0x000c; // movea.l $c(a6),a3 |
456 |
|
|
p[6] = 0x286e; p[7] = 0x0008; // movea.l $8(a6),a4 |
457 |
|
|
p[8] = M68K_EMUL_OP_AUDIO_DISPATCH; |
458 |
|
|
p[9] = 0x2d40; p[10] = 0x0010; // move.l d0,$10(a6) |
459 |
|
|
p[11] = 0x4cdf; p[12] = 0x1801; // movem.l (a7)+,d0/a3-a4 |
460 |
|
|
p[13] = 0x4e5e; // unlk a6 |
461 |
|
|
p[14] = 0x4e74; p[15] = 0x0008; // rtd #8 |
462 |
|
|
D(bug(" patch applied\n")); |
463 |
|
|
} |
464 |
|
|
|
465 |
|
|
} else if (type == FOURCC('D','R','V','R') && (id == -16501 || id == -16500)) { |
466 |
|
|
D(bug("DRVR -16501/-16500 found\n")); |
467 |
|
|
// Install sound input driver |
468 |
|
|
memcpy(p, sound_input_driver, sizeof(sound_input_driver)); |
469 |
|
|
D(bug(" patch 1 applied\n")); |
470 |
|
|
|
471 |
|
|
} else if (type == FOURCC('I','N','I','T') && id == 1 && size == (2416 >> 1)) { |
472 |
|
|
D(bug("INIT 1 (size 2416) found\n")); |
473 |
|
|
size >>= 1; |
474 |
|
|
while (size--) { |
475 |
|
|
if (p[0] == 0x247c && p[1] == 0xf301 && p[2] == 0x9000) { |
476 |
|
|
// Prevent "MacOS Licensing Extension" from accessing hardware (7.6) |
477 |
|
|
p[22] = 0x6028; |
478 |
|
|
D(bug(" patch 1 applied\n")); |
479 |
|
|
break; |
480 |
|
|
} |
481 |
|
|
p++; |
482 |
|
|
} |
483 |
|
|
} |
484 |
|
|
} |
485 |
|
|
|
486 |
|
|
|
487 |
|
|
/* |
488 |
|
|
* Native Resource Manager patches |
489 |
|
|
*/ |
490 |
|
|
|
491 |
|
|
#ifdef __BEOS__ |
492 |
|
|
static |
493 |
|
|
#endif |
494 |
|
|
void check_load_invoc(uint32 type, int16 id, uint16 **h) |
495 |
|
|
{ |
496 |
|
|
if (h == NULL) |
497 |
|
|
return; |
498 |
|
|
uint16 *p = *h; |
499 |
|
|
if (p == NULL) |
500 |
|
|
return; |
501 |
|
|
uint32 size = ((uint32 *)p)[-2] & 0xffffff; |
502 |
|
|
|
503 |
|
|
CheckLoad(type, id, p, size); |
504 |
|
|
} |
505 |
|
|
|
506 |
|
|
#ifdef __BEOS__ |
507 |
|
|
static asm void **get_resource(register uint32 type, register int16 id) |
508 |
|
|
{ |
509 |
|
|
// Create stack frame |
510 |
|
|
mflr r0 |
511 |
|
|
stw r0,8(r1) |
512 |
|
|
stwu r1,-(56+12)(r1) |
513 |
|
|
|
514 |
|
|
// Save type/ID |
515 |
|
|
stw r3,56(r1) |
516 |
|
|
stw r4,56+4(r1) |
517 |
|
|
|
518 |
|
|
// Call old routine |
519 |
|
|
lwz r0,XLM_GET_RESOURCE |
520 |
|
|
lwz r2,XLM_RES_LIB_TOC |
521 |
|
|
mtctr r0 |
522 |
|
|
bctrl |
523 |
|
|
lwz r2,XLM_TOC // Get TOC |
524 |
|
|
stw r3,56+8(r1) // Save handle |
525 |
|
|
|
526 |
|
|
// Call CheckLoad |
527 |
|
|
lwz r3,56(r1) |
528 |
|
|
lwz r4,56+4(r1) |
529 |
|
|
lwz r5,56+8(r1) |
530 |
|
|
bl check_load_invoc |
531 |
|
|
lwz r3,56+8(r1) // Restore handle |
532 |
|
|
|
533 |
|
|
// Return to caller |
534 |
|
|
lwz r0,56+12+8(r1) |
535 |
|
|
mtlr r0 |
536 |
|
|
addi r1,r1,56+12 |
537 |
|
|
blr |
538 |
|
|
} |
539 |
|
|
|
540 |
|
|
static asm void **get_1_resource(register uint32 type, register int16 id) |
541 |
|
|
{ |
542 |
|
|
// Create stack frame |
543 |
|
|
mflr r0 |
544 |
|
|
stw r0,8(r1) |
545 |
|
|
stwu r1,-(56+12)(r1) |
546 |
|
|
|
547 |
|
|
// Save type/ID |
548 |
|
|
stw r3,56(r1) |
549 |
|
|
stw r4,56+4(r1) |
550 |
|
|
|
551 |
|
|
// Call old routine |
552 |
|
|
lwz r0,XLM_GET_1_RESOURCE |
553 |
|
|
lwz r2,XLM_RES_LIB_TOC |
554 |
|
|
mtctr r0 |
555 |
|
|
bctrl |
556 |
|
|
lwz r2,XLM_TOC // Get TOC |
557 |
|
|
stw r3,56+8(r1) // Save handle |
558 |
|
|
|
559 |
|
|
// Call CheckLoad |
560 |
|
|
lwz r3,56(r1) |
561 |
|
|
lwz r4,56+4(r1) |
562 |
|
|
lwz r5,56+8(r1) |
563 |
|
|
bl check_load_invoc |
564 |
|
|
lwz r3,56+8(r1) // Restore handle |
565 |
|
|
|
566 |
|
|
// Return to caller |
567 |
|
|
lwz r0,56+12+8(r1) |
568 |
|
|
mtlr r0 |
569 |
|
|
addi r1,r1,56+12 |
570 |
|
|
blr |
571 |
|
|
} |
572 |
|
|
|
573 |
|
|
static asm void **get_ind_resource(register uint32 type, register int16 index) |
574 |
|
|
{ |
575 |
|
|
// Create stack frame |
576 |
|
|
mflr r0 |
577 |
|
|
stw r0,8(r1) |
578 |
|
|
stwu r1,-(56+12)(r1) |
579 |
|
|
|
580 |
|
|
// Save type/index |
581 |
|
|
stw r3,56(r1) |
582 |
|
|
stw r4,56+4(r1) |
583 |
|
|
|
584 |
|
|
// Call old routine |
585 |
|
|
lwz r0,XLM_GET_IND_RESOURCE |
586 |
|
|
lwz r2,XLM_RES_LIB_TOC |
587 |
|
|
mtctr r0 |
588 |
|
|
bctrl |
589 |
|
|
lwz r2,XLM_TOC // Get TOC |
590 |
|
|
stw r3,56+8(r1) // Save handle |
591 |
|
|
|
592 |
|
|
// Call CheckLoad |
593 |
|
|
lwz r3,56(r1) |
594 |
|
|
lwz r4,56+4(r1) |
595 |
|
|
lwz r5,56+8(r1) |
596 |
|
|
bl check_load_invoc |
597 |
|
|
lwz r3,56+8(r1) // Restore handle |
598 |
|
|
|
599 |
|
|
// Return to caller |
600 |
|
|
lwz r0,56+12+8(r1) |
601 |
|
|
mtlr r0 |
602 |
|
|
addi r1,r1,56+12 |
603 |
|
|
blr |
604 |
|
|
} |
605 |
|
|
|
606 |
|
|
static asm void **get_1_ind_resource(register uint32 type, register int16 index) |
607 |
|
|
{ |
608 |
|
|
// Create stack frame |
609 |
|
|
mflr r0 |
610 |
|
|
stw r0,8(r1) |
611 |
|
|
stwu r1,-(56+12)(r1) |
612 |
|
|
|
613 |
|
|
// Save type/index |
614 |
|
|
stw r3,56(r1) |
615 |
|
|
stw r4,56+4(r1) |
616 |
|
|
|
617 |
|
|
// Call old routine |
618 |
|
|
lwz r0,XLM_GET_1_IND_RESOURCE |
619 |
|
|
lwz r2,XLM_RES_LIB_TOC |
620 |
|
|
mtctr r0 |
621 |
|
|
bctrl |
622 |
|
|
lwz r2,XLM_TOC // Get TOC |
623 |
|
|
stw r3,56+8(r1) // Save handle |
624 |
|
|
|
625 |
|
|
// Call CheckLoad |
626 |
|
|
lwz r3,56(r1) |
627 |
|
|
lwz r4,56+4(r1) |
628 |
|
|
lwz r5,56+8(r1) |
629 |
|
|
bl check_load_invoc |
630 |
|
|
lwz r3,56+8(r1) // Restore handle |
631 |
|
|
|
632 |
|
|
// Return to caller |
633 |
|
|
lwz r0,56+12+8(r1) |
634 |
|
|
mtlr r0 |
635 |
|
|
addi r1,r1,56+12 |
636 |
|
|
blr |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
static asm void **r_get_resource(register uint32 type, register int16 id) |
640 |
|
|
{ |
641 |
|
|
// Create stack frame |
642 |
|
|
mflr r0 |
643 |
|
|
stw r0,8(r1) |
644 |
|
|
stwu r1,-(56+12)(r1) |
645 |
|
|
|
646 |
|
|
// Save type/ID |
647 |
|
|
stw r3,56(r1) |
648 |
|
|
stw r4,56+4(r1) |
649 |
|
|
|
650 |
|
|
// Call old routine |
651 |
|
|
lwz r0,XLM_R_GET_RESOURCE |
652 |
|
|
lwz r2,XLM_RES_LIB_TOC |
653 |
|
|
mtctr r0 |
654 |
|
|
bctrl |
655 |
|
|
lwz r2,XLM_TOC // Get TOC |
656 |
|
|
stw r3,56+8(r1) // Save handle |
657 |
|
|
|
658 |
|
|
// Call CheckLoad |
659 |
|
|
lwz r3,56(r1) |
660 |
|
|
lwz r4,56+4(r1) |
661 |
|
|
lwz r5,56+8(r1) |
662 |
|
|
bl check_load_invoc |
663 |
|
|
lwz r3,56+8(r1) // Restore handle |
664 |
|
|
|
665 |
|
|
// Return to caller |
666 |
|
|
lwz r0,56+12+8(r1) |
667 |
|
|
mtlr r0 |
668 |
|
|
addi r1,r1,56+12 |
669 |
|
|
blr |
670 |
|
|
} |
671 |
|
|
#else |
672 |
|
|
// Routines in asm_linux.S |
673 |
|
|
extern "C" void get_resource(void); |
674 |
|
|
extern "C" void get_1_resource(void); |
675 |
|
|
extern "C" void get_ind_resource(void); |
676 |
|
|
extern "C" void get_1_ind_resource(void); |
677 |
|
|
extern "C" void r_get_resource(void); |
678 |
|
|
#endif |
679 |
|
|
|
680 |
|
|
void PatchNativeResourceManager(void) |
681 |
|
|
{ |
682 |
|
|
D(bug("PatchNativeResourceManager\n")); |
683 |
|
|
|
684 |
|
|
// Patch native GetResource() |
685 |
|
|
uint32 **upp = *(uint32 ***)0x1480; |
686 |
|
|
if (((uint32)upp & 0xffc00000) == ROM_BASE) |
687 |
|
|
return; |
688 |
|
|
uint32 *tvec = upp[5]; |
689 |
|
|
D(bug(" GetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
690 |
|
|
*(uint32 *)XLM_RES_LIB_TOC = tvec[1]; |
691 |
|
|
*(uint32 *)XLM_GET_RESOURCE = tvec[0]; |
692 |
|
|
#ifdef __BEOS__ |
693 |
|
|
uint32 *tvec2 = (uint32 *)get_resource; |
694 |
|
|
tvec[0] = tvec2[0]; |
695 |
|
|
tvec[1] = tvec2[1]; |
696 |
|
|
#else |
697 |
|
|
tvec[0] = (uint32)get_resource; |
698 |
|
|
#endif |
699 |
|
|
|
700 |
|
|
// Patch native Get1Resource() |
701 |
|
|
upp = *(uint32 ***)0xe7c; |
702 |
|
|
tvec = upp[5]; |
703 |
|
|
D(bug(" Get1Resource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
704 |
|
|
*(uint32 *)XLM_GET_1_RESOURCE = tvec[0]; |
705 |
|
|
#ifdef __BEOS__ |
706 |
|
|
tvec2 = (uint32 *)get_1_resource; |
707 |
|
|
tvec[0] = tvec2[0]; |
708 |
|
|
tvec[1] = tvec2[1]; |
709 |
|
|
#else |
710 |
|
|
tvec[0] = (uint32)get_1_resource; |
711 |
|
|
#endif |
712 |
|
|
|
713 |
|
|
// Patch native GetIndResource() |
714 |
|
|
upp = *(uint32 ***)0x1474; |
715 |
|
|
tvec = upp[5]; |
716 |
|
|
D(bug(" GetIndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
717 |
|
|
*(uint32 *)XLM_GET_IND_RESOURCE = tvec[0]; |
718 |
|
|
#ifdef __BEOS__ |
719 |
|
|
tvec2 = (uint32 *)get_ind_resource; |
720 |
|
|
tvec[0] = tvec2[0]; |
721 |
|
|
tvec[1] = tvec2[1]; |
722 |
|
|
#else |
723 |
|
|
tvec[0] = (uint32)get_ind_resource; |
724 |
|
|
#endif |
725 |
|
|
|
726 |
|
|
// Patch native Get1IndResource() |
727 |
|
|
upp = *(uint32 ***)0xe38; |
728 |
|
|
tvec = upp[5]; |
729 |
|
|
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
730 |
|
|
*(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0]; |
731 |
|
|
#ifdef __BEOS__ |
732 |
|
|
tvec2 = (uint32 *)get_1_ind_resource; |
733 |
|
|
tvec[0] = tvec2[0]; |
734 |
|
|
tvec[1] = tvec2[1]; |
735 |
|
|
#else |
736 |
|
|
tvec[0] = (uint32)get_1_ind_resource; |
737 |
|
|
#endif |
738 |
|
|
|
739 |
|
|
// Patch native RGetResource() |
740 |
|
|
upp = *(uint32 ***)0xe30; |
741 |
|
|
tvec = upp[5]; |
742 |
|
|
D(bug(" RGetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
743 |
|
|
*(uint32 *)XLM_R_GET_RESOURCE = tvec[0]; |
744 |
|
|
#ifdef __BEOS__ |
745 |
|
|
tvec2 = (uint32 *)r_get_resource; |
746 |
|
|
tvec[0] = tvec2[0]; |
747 |
|
|
tvec[1] = tvec2[1]; |
748 |
|
|
#else |
749 |
|
|
tvec[0] = (uint32)r_get_resource; |
750 |
|
|
#endif |
751 |
|
|
} |