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 |
gbeauche |
1.4 |
// 680x0 code pattern matching helper |
109 |
|
|
#define PM(N, V) (p[N] == htons(V)) |
110 |
|
|
|
111 |
cebix |
1.1 |
void CheckLoad(uint32 type, int16 id, uint16 *p, uint32 size) |
112 |
|
|
{ |
113 |
|
|
uint16 *p16; |
114 |
|
|
uint32 base; |
115 |
|
|
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)); |
116 |
|
|
|
117 |
|
|
// Don't modify resources in ROM |
118 |
gbeauche |
1.4 |
if ((uintptr)p >= ROM_BASE && (uintptr)p <= (ROM_BASE + ROM_SIZE)) |
119 |
cebix |
1.1 |
return; |
120 |
|
|
|
121 |
|
|
if (type == FOURCC('b','o','o','t') && id == 3) { |
122 |
|
|
D(bug("boot 3 found\n")); |
123 |
|
|
size >>= 1; |
124 |
|
|
while (size--) { |
125 |
gbeauche |
1.4 |
if (PM(0,0x2e49)) { |
126 |
cebix |
1.1 |
// 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) |
127 |
gbeauche |
1.4 |
p[0] = htons(M68K_EMUL_OP_FIX_BOOTSTACK); |
128 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
129 |
gbeauche |
1.4 |
} else if (PM(0,0x4267) && PM(1,0x3f01) && PM(2,0x3f2a) && PM(3,0x0006) && PM(4,0x6100)) { |
130 |
cebix |
1.1 |
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.5.3, 7.5.5) |
131 |
gbeauche |
1.4 |
p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH3); |
132 |
cebix |
1.1 |
D(bug(" patch 2 applied\n")); |
133 |
gbeauche |
1.4 |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x6100)) { |
134 |
cebix |
1.1 |
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.6, 7.6.1, 8.0, 8.1) |
135 |
gbeauche |
1.4 |
p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH); |
136 |
cebix |
1.1 |
D(bug(" patch 3 applied\n")); |
137 |
gbeauche |
1.4 |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff)) { |
138 |
cebix |
1.1 |
// Check when ntrb 17 is installed (for native Resource Manager patch) (8.5, 8.6) |
139 |
gbeauche |
1.4 |
p[8] = htons(M68K_EMUL_OP_NTRB_17_PATCH); |
140 |
cebix |
1.1 |
D(bug(" patch 4 applied\n")); |
141 |
gbeauche |
1.4 |
} else if (PM(0,0x0c39) && PM(1,0x0001) && PM(2,0xf800) && PM(3,0x0008) && PM(4,0x6f00)) { |
142 |
cebix |
1.1 |
// Don't read from 0xf8000008 (8.5 with Zanzibar ROM, 8.6) |
143 |
gbeauche |
1.4 |
p[0] = htons(M68K_NOP); |
144 |
|
|
p[1] = htons(M68K_NOP); |
145 |
|
|
p[2] = htons(M68K_NOP); |
146 |
|
|
p[3] = htons(M68K_NOP); |
147 |
|
|
p[4] = htons(0x6000); // bra |
148 |
cebix |
1.1 |
D(bug(" patch 5 applied\n")); |
149 |
gbeauche |
1.4 |
} 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)) { |
150 |
cebix |
1.1 |
// Don't replace nanokernel ("krnl" resource) (8.6) |
151 |
gbeauche |
1.4 |
p[0] = htons(M68K_NOP); |
152 |
|
|
p[1] = htons(M68K_NOP); |
153 |
|
|
p[2] = htons(M68K_NOP); |
154 |
|
|
p[3] = htons(M68K_NOP); |
155 |
|
|
p[4] = htons(M68K_NOP); |
156 |
|
|
p[7] = htons(0x6000); // bra |
157 |
cebix |
1.1 |
D(bug(" patch 6 applied\n")); |
158 |
gbeauche |
1.4 |
} else if (PM(0,0xa8fe) && PM(1,0x3038) && PM(2,0x017a) && PM(3,0x0c40) && PM(4,0x8805) && PM(5,0x6710)) { |
159 |
cebix |
1.1 |
// No SCSI (calls via 0x205c jump vector which is not initialized in NewWorld ROM 1.6) (8.6) |
160 |
|
|
if (ROMType == ROMTYPE_NEWWORLD) { |
161 |
gbeauche |
1.4 |
p[5] = htons(0x6010); // bra |
162 |
cebix |
1.1 |
D(bug(" patch 7 applied\n")); |
163 |
|
|
} |
164 |
|
|
} |
165 |
|
|
p++; |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
} else if (type == FOURCC('g','n','l','d') && id == 0) { |
169 |
|
|
D(bug("gnld 0 found\n")); |
170 |
|
|
|
171 |
|
|
// Patch native Resource Manager after ntrbs are installed (7.5.2) |
172 |
|
|
static const uint8 dat[] = {0x4e, 0xba, 0x00, 0x9e, 0x3e, 0x00, 0x50, 0x4f, 0x67, 0x04}; |
173 |
|
|
base = find_rsrc_data((uint8 *)p, size, dat, sizeof(dat)); |
174 |
|
|
if (base) { |
175 |
gbeauche |
1.4 |
p16 = (uint16 *)((uintptr)p + base + 6); |
176 |
cebix |
1.1 |
*p16 = htons(M68K_EMUL_OP_NTRB_17_PATCH2); |
177 |
|
|
D(bug(" patch 1 applied\n")); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
} else if (type == FOURCC('p','t','c','h') && id == 420) { |
181 |
|
|
D(bug("ptch 420 found\n")); |
182 |
|
|
size >>= 1; |
183 |
|
|
while (size--) { |
184 |
gbeauche |
1.4 |
if (PM(0,0xa030) && PM(1,0x5240) && PM(2,0x303c) && PM(3,0x0100) && PM(4,0xc06e) && PM(5,0xfef6)) { |
185 |
cebix |
1.1 |
// Disable VM (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1) |
186 |
gbeauche |
1.4 |
p[1] = htons(M68K_NOP); |
187 |
|
|
p[2] = htons(M68K_NOP); |
188 |
|
|
p[3] = htons(M68K_NOP); |
189 |
|
|
p[4] = htons(M68K_NOP); |
190 |
|
|
p[5] = htons(M68K_NOP); |
191 |
|
|
p[6] = htons(M68K_NOP); |
192 |
|
|
p[7] = htons(M68K_NOP); |
193 |
|
|
p[8] = htons(M68K_NOP); |
194 |
|
|
p[9] = htons(M68K_NOP); |
195 |
|
|
p[10] = htons(M68K_NOP); |
196 |
|
|
p[11] = htons(M68K_NOP); |
197 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
198 |
|
|
break; |
199 |
gbeauche |
1.4 |
} else if (PM(0,0xa030) && PM(1,0x5240) && PM(2,0x7000) && PM(3,0x302e) && PM(4,0xfef6) && PM(5,0x323c) && PM(6,0x0100)) { |
200 |
cebix |
1.1 |
// Disable VM (8.0, 8.1) |
201 |
gbeauche |
1.4 |
p[8] = htons(M68K_NOP); |
202 |
|
|
p[15] = htons(M68K_NOP); |
203 |
cebix |
1.1 |
D(bug(" patch 2 applied\n")); |
204 |
|
|
break; |
205 |
gbeauche |
1.4 |
} else if (PM(0,0xa030) && PM(1,0x5240) && PM(2,0x7000) && PM(3,0x302e) && PM(4,0xfecc) && PM(5,0x323c) && PM(6,0x0100)) { |
206 |
cebix |
1.1 |
// Disable VM (8.5, 8.6) |
207 |
gbeauche |
1.4 |
p[8] = htons(M68K_NOP); |
208 |
|
|
p[15] = htons(M68K_NOP); |
209 |
cebix |
1.1 |
D(bug(" patch 3 applied\n")); |
210 |
|
|
break; |
211 |
|
|
} |
212 |
|
|
p++; |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 16) { |
216 |
|
|
D(bug("gpch 16 found\n")); |
217 |
|
|
size >>= 1; |
218 |
|
|
while (size--) { |
219 |
gbeauche |
1.4 |
if (PM(0,0x6700) && PM(13,0x7013) && PM(14,0xfe0a)) { |
220 |
cebix |
1.1 |
// Don't call FE0A in Shutdown Manager (7.6.1, 8.0, 8.1, 8.5) |
221 |
gbeauche |
1.4 |
p[0] = htons(0x6000); |
222 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
223 |
|
|
break; |
224 |
|
|
} |
225 |
|
|
p++; |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 650) { |
229 |
|
|
D(bug("gpch 650 found\n")); |
230 |
|
|
size >>= 1; |
231 |
|
|
while (size--) { |
232 |
gbeauche |
1.4 |
if (PM(0,0x6600) && PM(1,0x001a) && PM(2,0x2278) && PM(3,0x0134)) { |
233 |
cebix |
1.1 |
// We don't have SonyVars (7.5.2) |
234 |
gbeauche |
1.4 |
p[0] = htons(0x6000); |
235 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
236 |
gbeauche |
1.4 |
} else if (PM(0,0x6618) && PM(1,0x2278) && PM(2,0x0134)) { |
237 |
cebix |
1.1 |
// We don't have SonyVars (7.5.3) |
238 |
gbeauche |
1.4 |
p[-6] = htons(M68K_NOP); |
239 |
|
|
p[-3] = htons(M68K_NOP); |
240 |
|
|
p[0] = htons(0x6018); |
241 |
cebix |
1.1 |
D(bug(" patch 2 applied\n")); |
242 |
gbeauche |
1.4 |
} else if (PM(0,0x666e) && PM(1,0x2278) && PM(2,0x0134)) { |
243 |
cebix |
1.1 |
// We don't have SonyVars (7.5.5) |
244 |
gbeauche |
1.4 |
p[-6] = htons(M68K_NOP); |
245 |
|
|
p[-3] = htons(M68K_NOP); |
246 |
|
|
p[0] = htons(0x606e); |
247 |
cebix |
1.1 |
D(bug(" patch 3 applied\n")); |
248 |
gbeauche |
1.4 |
} else if (PM(0,0x6400) && PM(1,0x011c) && PM(2,0x2278) && PM(3,0x0134)) { |
249 |
cebix |
1.1 |
// We don't have SonyVars (7.6.1, 8.0, 8.1, 8.5, 8.6) |
250 |
gbeauche |
1.4 |
p[0] = htons(0x6000); |
251 |
cebix |
1.1 |
D(bug(" patch 4 applied\n")); |
252 |
gbeauche |
1.4 |
} else if (PM(0,0x6400) && PM(1,0x00e6) && PM(2,0x2278) && PM(3,0x0134)) { |
253 |
cebix |
1.1 |
// We don't have SonyVars (7.6) |
254 |
gbeauche |
1.4 |
p[0] = htons(0x6000); |
255 |
cebix |
1.1 |
D(bug(" patch 5 applied\n")); |
256 |
|
|
} |
257 |
|
|
p++; |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 655) { |
261 |
|
|
D(bug("gpch 655 found\n")); |
262 |
|
|
size >>= 1; |
263 |
|
|
while (size--) { |
264 |
gbeauche |
1.4 |
if (PM(0,0x83a8) && PM(1,0x0024) && PM(2,0x4e71)) { |
265 |
cebix |
1.1 |
// Don't write to GC interrupt mask (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
266 |
gbeauche |
1.4 |
p[0] = htons(M68K_NOP); |
267 |
|
|
p[1] = htons(M68K_NOP); |
268 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
269 |
gbeauche |
1.4 |
} else if (PM(0,0x207c) && PM(1,0xf300) && PM(2,0x0034)) { |
270 |
cebix |
1.1 |
// Don't read PowerMac ID (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
271 |
gbeauche |
1.4 |
p[0] = htons(0x303c); // move.w #id,d0 |
272 |
|
|
p[1] = htons(0x3020); |
273 |
|
|
p[2] = htons(M68K_RTS); |
274 |
cebix |
1.1 |
D(bug(" patch 2 applied\n")); |
275 |
gbeauche |
1.4 |
} else if (PM(0,0x13fc) && PM(1,0x0081) && PM(2,0xf130) && PM(3,0xa030)) { |
276 |
cebix |
1.1 |
// Don't write to hardware (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
277 |
gbeauche |
1.4 |
p[0] = htons(M68K_NOP); |
278 |
|
|
p[1] = htons(M68K_NOP); |
279 |
|
|
p[2] = htons(M68K_NOP); |
280 |
|
|
p[3] = htons(M68K_NOP); |
281 |
cebix |
1.1 |
D(bug(" patch 3 applied\n")); |
282 |
gbeauche |
1.4 |
} else if (PM(0,0x4e56) && PM(1,0x0000) && PM(2,0x227c) && PM(3,0xf800) && PM(4,0x0000)) { |
283 |
cebix |
1.1 |
// OpenFirmare? (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
284 |
gbeauche |
1.4 |
p[0] = htons(M68K_RTS); |
285 |
cebix |
1.1 |
D(bug(" patch 4 applied\n")); |
286 |
gbeauche |
1.4 |
} else if (PM(0,0x4e56) && PM(1,0xfffc) && PM(2,0x48e7) && PM(3,0x0300) && PM(4,0x598f) && PM(5,0x2eb8) && PM(6,0x01dc)) { |
287 |
cebix |
1.1 |
// Don't write to SCC (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
288 |
gbeauche |
1.4 |
p[0] = htons(M68K_RTS); |
289 |
cebix |
1.1 |
D(bug(" patch 5 applied\n")); |
290 |
gbeauche |
1.4 |
} else if (PM(0,0x4e56) && PM(1,0x0000) && PM(2,0x227c) && PM(3,0xf300) && PM(4,0x0034)) { |
291 |
cebix |
1.1 |
// Don't write to GC (7.6.1, 8.0, 8.1 with Zanzibar ROM) |
292 |
gbeauche |
1.4 |
p[0] = htons(M68K_RTS); |
293 |
cebix |
1.1 |
D(bug(" patch 6 applied\n")); |
294 |
gbeauche |
1.4 |
} 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)) { |
295 |
cebix |
1.1 |
// Don't replace NVRAM routines (7.6, 7.6.1, 8.0, 8.1 with Zanzibar ROM) |
296 |
gbeauche |
1.4 |
p[0] = htons(M68K_RTS); |
297 |
cebix |
1.1 |
D(bug(" patch 7 applied\n")); |
298 |
gbeauche |
1.4 |
} else if (PM(0,0x207c) && PM(1,0x50f1) && PM(2,0xa101) && (PM(3,0x08d0) || PM(3,0x0890))) { |
299 |
cebix |
1.1 |
// Don't write to 0x50f1a101 (8.1 with Zanzibar ROM) |
300 |
gbeauche |
1.4 |
p[3] = htons(M68K_NOP); |
301 |
|
|
p[4] = htons(M68K_NOP); |
302 |
cebix |
1.1 |
D(bug(" patch 8 applied\n")); |
303 |
|
|
} |
304 |
|
|
p++; |
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 750) { |
308 |
|
|
D(bug("gpch 750 found\n")); |
309 |
|
|
size >>= 1; |
310 |
|
|
while (size--) { |
311 |
gbeauche |
1.4 |
if (PM(0,0xf301) && PM(1,0x9100) && PM(2,0x0c11) && PM(3,0x0044)) { |
312 |
cebix |
1.1 |
// Don't read from 0xf3019100 (MACE ENET) (7.6, 7.6.1, 8.0, 8.1) |
313 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
314 |
|
|
p[3] = htons(M68K_NOP); |
315 |
|
|
p[4] = htons(0x6026); |
316 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
317 |
gbeauche |
1.4 |
} else if (PM(0,0x41e8) && PM(1,0x0374) && PM(2,0xfc1e)) { |
318 |
cebix |
1.1 |
// Don't call FC1E opcode (7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
319 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
320 |
cebix |
1.1 |
D(bug(" patch 2 applied\n")); |
321 |
gbeauche |
1.4 |
} else if (PM(0,0x700a) && PM(1,0xfe0a)) { |
322 |
cebix |
1.1 |
// Don't call FE0A opcode (7.6, 7.6.1, 8.0, 8.1, 8.5, 8.6) |
323 |
gbeauche |
1.4 |
p[1] = htons(0x7000); |
324 |
cebix |
1.1 |
D(bug(" patch 3 applied\n")); |
325 |
gbeauche |
1.4 |
} else if (PM(0,0x6c00) && PM(1,0x016a) && PM(2,0x2278) && PM(3,0x0134)) { |
326 |
gbeauche |
1.3 |
// We don't have SonyVars (8.6) |
327 |
gbeauche |
1.4 |
p[-4] = htons(0x21fc); // move.l $40810000,($0000) |
328 |
|
|
p[-3] = htons(0x4081); |
329 |
|
|
p[-2] = htons(0x0000); |
330 |
|
|
p[-1] = htons(0x0000); |
331 |
|
|
p[0] = htons(0x6000); |
332 |
gbeauche |
1.3 |
D(bug(" patch 4 applied\n")); |
333 |
cebix |
1.1 |
} |
334 |
|
|
p++; |
335 |
|
|
} |
336 |
|
|
|
337 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 999) { |
338 |
|
|
D(bug("gpch 999 found\n")); |
339 |
|
|
size >>= 1; |
340 |
|
|
while (size--) { |
341 |
gbeauche |
1.4 |
if (PM(0,0xf301) && PM(1,0x9100) && PM(2,0x0c11) && PM(3,0x0044)) { |
342 |
cebix |
1.1 |
// Don't read from 0xf3019100 (MACE ENET) (8.5, 8.6) |
343 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
344 |
|
|
p[3] = htons(M68K_NOP); |
345 |
|
|
p[4] = htons(0x6026); |
346 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
347 |
|
|
} |
348 |
|
|
p++; |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
} else if (type == FOURCC('g','p','c','h') && id == 3000) { |
352 |
|
|
D(bug("gpch 3000 found\n")); |
353 |
|
|
size >>= 1; |
354 |
|
|
while (size--) { |
355 |
gbeauche |
1.4 |
if (PM(0,0xf301) && PM(1,0x9100) && PM(2,0x0c11) && PM(3,0x0044)) { |
356 |
cebix |
1.1 |
// Don't read from 0xf3019100 (MACE ENET) (8.1 with NewWorld ROM) |
357 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
358 |
|
|
p[3] = htons(M68K_NOP); |
359 |
|
|
p[4] = htons(0x6026); |
360 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
361 |
|
|
} |
362 |
|
|
p++; |
363 |
|
|
} |
364 |
|
|
|
365 |
|
|
} else if (type == FOURCC('l','t','l','k') && id == 0) { |
366 |
|
|
D(bug("ltlk 0 found\n")); |
367 |
|
|
#if 1 |
368 |
|
|
size >>= 1; |
369 |
|
|
while (size--) { |
370 |
gbeauche |
1.4 |
if (PM(0,0xc2fc) && PM(1,0x0fa0) && PM(2,0x82c5)) { |
371 |
cebix |
1.1 |
// 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) |
372 |
gbeauche |
1.4 |
p[2] = htons(0x7200); |
373 |
cebix |
1.1 |
WriteMacInt32(0x1d8, 0x2c00); |
374 |
|
|
WriteMacInt32(0x1dc, 0x2c00); |
375 |
|
|
D(bug(" patch 1 applied\n")); |
376 |
gbeauche |
1.4 |
} else if (PM(0,0x1418) && PM(1,0x84c1)) { |
377 |
cebix |
1.1 |
// Prevent division by 0 (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
378 |
gbeauche |
1.4 |
p[1] = htons(0x7400); |
379 |
cebix |
1.1 |
D(bug(" patch 2 applied\n")); |
380 |
gbeauche |
1.4 |
} else if (PM(0,0x2678) && PM(1,0x01dc) && PM(2,0x3018) && PM(3,0x6708) && PM(4,0x1680) && PM(5,0xe058) && PM(6,0x1680)) { |
381 |
cebix |
1.1 |
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
382 |
gbeauche |
1.4 |
p[4] = htons(M68K_NOP); |
383 |
|
|
p[6] = htons(M68K_NOP); |
384 |
cebix |
1.1 |
D(bug(" patch 3 applied\n")); |
385 |
gbeauche |
1.4 |
} else if (PM(0,0x2278) && PM(1,0x01dc) && PM(2,0x12bc) && PM(3,0x0006) && PM(4,0x4e71) && PM(5,0x1292)) { |
386 |
cebix |
1.1 |
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
387 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
388 |
|
|
p[3] = htons(M68K_NOP); |
389 |
|
|
p[5] = htons(M68K_NOP); |
390 |
cebix |
1.1 |
D(bug(" patch 4 applied\n")); |
391 |
gbeauche |
1.4 |
} else if (PM(0,0x2278) && PM(1,0x01dc) && PM(2,0x12bc) && PM(3,0x0003) && PM(4,0x4e71) && PM(5,0x1281)) { |
392 |
cebix |
1.1 |
// Don't write to SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
393 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
394 |
|
|
p[3] = htons(M68K_NOP); |
395 |
|
|
p[5] = htons(M68K_NOP); |
396 |
cebix |
1.1 |
D(bug(" patch 5 applied\n")); |
397 |
gbeauche |
1.4 |
} else if (PM(0,0x0811) && PM(1,0x0000) && PM(2,0x51c8) && PM(3,0xfffa)) { |
398 |
cebix |
1.1 |
// Don't test SCC (7.5.2, 7.5.3, 7.5.5, 7.6, 7.6.1, 8.0, 8.1) |
399 |
gbeauche |
1.4 |
p[0] = htons(M68K_NOP); |
400 |
|
|
p[1] = htons(M68K_NOP); |
401 |
cebix |
1.1 |
D(bug(" patch 6 applied\n")); |
402 |
gbeauche |
1.4 |
} else if (PM(0,0x4a2a) && PM(1,0x063e) && PM(2,0x66fa)) { |
403 |
cebix |
1.1 |
// Don't wait for SCC (7.5.2, 7.5.3, 7.5.5) |
404 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
405 |
cebix |
1.1 |
D(bug(" patch 7 applied\n")); |
406 |
gbeauche |
1.4 |
} else if (PM(0,0x4a2a) && PM(1,0x03a6) && PM(2,0x66fa)) { |
407 |
cebix |
1.1 |
// Don't wait for SCC (7.6, 7.6.1, 8.0, 8.1) |
408 |
gbeauche |
1.4 |
p[2] = htons(M68K_NOP); |
409 |
cebix |
1.1 |
D(bug(" patch 8 applied\n")); |
410 |
|
|
} |
411 |
|
|
p++; |
412 |
|
|
} |
413 |
|
|
#else |
414 |
|
|
// Disable LocalTalk |
415 |
gbeauche |
1.4 |
p[0] = htons(M68K_JMP_A0); |
416 |
|
|
p[1] = htons(0x7000); // moveq #0,d0 |
417 |
|
|
p[2] = htons(M68K_RTS); |
418 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
419 |
|
|
#endif |
420 |
|
|
|
421 |
|
|
} else if (type == FOURCC('n','s','r','d') && id == 1) { |
422 |
|
|
D(bug("nsrd 1 found\n")); |
423 |
|
|
if (p[(0x378 + 0x570) >> 1] == 0x7c08 && p[(0x37a + 0x570) >> 1] == 0x02a6) { |
424 |
|
|
// Don't overwrite our serial drivers (8.0, 8.1) |
425 |
|
|
p[(0x378 + 0x570) >> 1] = 0x4e80; // blr |
426 |
|
|
p[(0x37a + 0x570) >> 1] = 0x0020; |
427 |
|
|
D(bug(" patch 1 applied\n")); |
428 |
|
|
} else if (p[(0x378 + 0x6c0) >> 1] == 0x7c08 && p[(0x37a + 0x6c0) >> 1] == 0x02a6) { |
429 |
|
|
// Don't overwrite our serial drivers (8.5, 8.6) |
430 |
|
|
p[(0x378 + 0x6c0) >> 1] = 0x4e80; // blr |
431 |
|
|
p[(0x37a + 0x6c0) >> 1] = 0x0020; |
432 |
|
|
D(bug(" patch 2 applied\n")); |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
} else if (type == FOURCC('c','i','t','t') && id == 45) { |
436 |
|
|
D(bug("citt 45 found\n")); |
437 |
|
|
size >>= 1; |
438 |
|
|
while (size--) { |
439 |
gbeauche |
1.4 |
if (PM(0,0x203c) && PM(1,0x0100) && PM(2,0x0000) && PM(3,0xc0ae) && PM(4,0xfffc)) { |
440 |
cebix |
1.1 |
// Don't replace SCSI Manager (8.1, 8.5, 8.6) |
441 |
gbeauche |
1.4 |
p[5] = htons((p[5] & 0xff) | 0x6000); // beq |
442 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
443 |
|
|
break; |
444 |
|
|
} |
445 |
|
|
p++; |
446 |
|
|
} |
447 |
|
|
|
448 |
|
|
} else if (type == FOURCC('t','h','n','g')) { |
449 |
|
|
// Collect info about used audio sifters |
450 |
|
|
uint32 c_type = 0[(uint32 *)p]; |
451 |
|
|
uint32 sub_type = 1[(uint32 *)p]; |
452 |
|
|
if (c_type == FOURCC('s','d','e','v') && sub_type == FOURCC('s','i','n','g')) { |
453 |
|
|
1[(uint32 *)p] = FOURCC('a','w','g','c'); |
454 |
|
|
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)); |
455 |
gbeauche |
1.4 |
AddSifter(*(uint32 *)(((uintptr)p)+20), p[12]); |
456 |
cebix |
1.1 |
if (p[28]) // componentPFCount |
457 |
gbeauche |
1.4 |
AddSifter(*(uint32 *)(((uintptr)p)+62), p[33]); |
458 |
cebix |
1.1 |
} |
459 |
|
|
|
460 |
|
|
} else if (type == FOURCC('s','i','f','t') || type == FOURCC('n','i','f','t')) { |
461 |
|
|
// Patch audio sifters |
462 |
|
|
if (FindSifter(type, id)) { |
463 |
|
|
D(bug("sifter found\n")); |
464 |
gbeauche |
1.4 |
p[0] = htons(0x4e56); p[1] = htons(0x0000); // link a6,#0 |
465 |
|
|
p[2] = htons(0x48e7); p[3] = htons(0x8018); // movem.l d0/a3-a4,-(a7) |
466 |
|
|
p[4] = htons(0x266e); p[5] = htons(0x000c); // movea.l $c(a6),a3 |
467 |
|
|
p[6] = htons(0x286e); p[7] = htons(0x0008); // movea.l $8(a6),a4 |
468 |
|
|
p[8] = htons(M68K_EMUL_OP_AUDIO_DISPATCH); |
469 |
|
|
p[9] = htons(0x2d40); p[10] = htons(0x0010); // move.l d0,$10(a6) |
470 |
|
|
p[11] = htons(0x4cdf); p[12] = htons(0x1801); // movem.l (a7)+,d0/a3-a4 |
471 |
|
|
p[13] = htons(0x4e5e); // unlk a6 |
472 |
|
|
p[14] = htons(0x4e74); p[15] = htons(0x0008); // rtd #8 |
473 |
cebix |
1.1 |
D(bug(" patch applied\n")); |
474 |
|
|
} |
475 |
|
|
|
476 |
|
|
} else if (type == FOURCC('D','R','V','R') && (id == -16501 || id == -16500)) { |
477 |
|
|
D(bug("DRVR -16501/-16500 found\n")); |
478 |
|
|
// Install sound input driver |
479 |
|
|
memcpy(p, sound_input_driver, sizeof(sound_input_driver)); |
480 |
|
|
D(bug(" patch 1 applied\n")); |
481 |
|
|
|
482 |
|
|
} else if (type == FOURCC('I','N','I','T') && id == 1 && size == (2416 >> 1)) { |
483 |
|
|
D(bug("INIT 1 (size 2416) found\n")); |
484 |
|
|
size >>= 1; |
485 |
|
|
while (size--) { |
486 |
gbeauche |
1.4 |
if (PM(0,0x247c) && PM(1,0xf301) && PM(2,0x9000)) { |
487 |
cebix |
1.1 |
// Prevent "MacOS Licensing Extension" from accessing hardware (7.6) |
488 |
gbeauche |
1.4 |
p[22] = htons(0x6028); |
489 |
cebix |
1.1 |
D(bug(" patch 1 applied\n")); |
490 |
|
|
break; |
491 |
|
|
} |
492 |
|
|
p++; |
493 |
|
|
} |
494 |
gbeauche |
1.3 |
|
495 |
|
|
} else if (type == FOURCC('s','c','o','d') && id == -16465) { |
496 |
|
|
D(bug("scod -16465 found\n")); |
497 |
|
|
|
498 |
|
|
// Don't crash in Process Manager on reset/shutdown (8.6) |
499 |
|
|
static const uint8 dat[] = {0x4e, 0x56, 0x00, 0x00, 0x48, 0xe7, 0x03, 0x18, 0x2c, 0x2e, 0x00, 0x10}; |
500 |
|
|
base = find_rsrc_data((uint8 *)p, size, dat, sizeof(dat)); |
501 |
|
|
if (base) { |
502 |
gbeauche |
1.4 |
p16 = (uint16 *)((uintptr)p + base); |
503 |
|
|
p16[0] = htons(0x7000); // moveq #0,d0 |
504 |
|
|
p16[1] = htons(M68K_RTS); |
505 |
gbeauche |
1.3 |
D(bug(" patch 1 applied\n")); |
506 |
|
|
} |
507 |
cebix |
1.1 |
} |
508 |
|
|
} |
509 |
|
|
|
510 |
|
|
|
511 |
|
|
/* |
512 |
|
|
* Native Resource Manager patches |
513 |
|
|
*/ |
514 |
|
|
|
515 |
|
|
#ifdef __BEOS__ |
516 |
|
|
static |
517 |
gbeauche |
1.2 |
#else |
518 |
|
|
extern "C" |
519 |
cebix |
1.1 |
#endif |
520 |
|
|
void check_load_invoc(uint32 type, int16 id, uint16 **h) |
521 |
|
|
{ |
522 |
|
|
if (h == NULL) |
523 |
|
|
return; |
524 |
|
|
uint16 *p = *h; |
525 |
|
|
if (p == NULL) |
526 |
|
|
return; |
527 |
|
|
uint32 size = ((uint32 *)p)[-2] & 0xffffff; |
528 |
|
|
|
529 |
|
|
CheckLoad(type, id, p, size); |
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
#ifdef __BEOS__ |
533 |
|
|
static asm void **get_resource(register uint32 type, register int16 id) |
534 |
|
|
{ |
535 |
|
|
// Create stack frame |
536 |
|
|
mflr r0 |
537 |
|
|
stw r0,8(r1) |
538 |
|
|
stwu r1,-(56+12)(r1) |
539 |
|
|
|
540 |
|
|
// Save type/ID |
541 |
|
|
stw r3,56(r1) |
542 |
|
|
stw r4,56+4(r1) |
543 |
|
|
|
544 |
|
|
// Call old routine |
545 |
|
|
lwz r0,XLM_GET_RESOURCE |
546 |
|
|
lwz r2,XLM_RES_LIB_TOC |
547 |
|
|
mtctr r0 |
548 |
|
|
bctrl |
549 |
|
|
lwz r2,XLM_TOC // Get TOC |
550 |
|
|
stw r3,56+8(r1) // Save handle |
551 |
|
|
|
552 |
|
|
// Call CheckLoad |
553 |
|
|
lwz r3,56(r1) |
554 |
|
|
lwz r4,56+4(r1) |
555 |
|
|
lwz r5,56+8(r1) |
556 |
|
|
bl check_load_invoc |
557 |
|
|
lwz r3,56+8(r1) // Restore handle |
558 |
|
|
|
559 |
|
|
// Return to caller |
560 |
|
|
lwz r0,56+12+8(r1) |
561 |
|
|
mtlr r0 |
562 |
|
|
addi r1,r1,56+12 |
563 |
|
|
blr |
564 |
|
|
} |
565 |
|
|
|
566 |
|
|
static asm void **get_1_resource(register uint32 type, register int16 id) |
567 |
|
|
{ |
568 |
|
|
// Create stack frame |
569 |
|
|
mflr r0 |
570 |
|
|
stw r0,8(r1) |
571 |
|
|
stwu r1,-(56+12)(r1) |
572 |
|
|
|
573 |
|
|
// Save type/ID |
574 |
|
|
stw r3,56(r1) |
575 |
|
|
stw r4,56+4(r1) |
576 |
|
|
|
577 |
|
|
// Call old routine |
578 |
|
|
lwz r0,XLM_GET_1_RESOURCE |
579 |
|
|
lwz r2,XLM_RES_LIB_TOC |
580 |
|
|
mtctr r0 |
581 |
|
|
bctrl |
582 |
|
|
lwz r2,XLM_TOC // Get TOC |
583 |
|
|
stw r3,56+8(r1) // Save handle |
584 |
|
|
|
585 |
|
|
// Call CheckLoad |
586 |
|
|
lwz r3,56(r1) |
587 |
|
|
lwz r4,56+4(r1) |
588 |
|
|
lwz r5,56+8(r1) |
589 |
|
|
bl check_load_invoc |
590 |
|
|
lwz r3,56+8(r1) // Restore handle |
591 |
|
|
|
592 |
|
|
// Return to caller |
593 |
|
|
lwz r0,56+12+8(r1) |
594 |
|
|
mtlr r0 |
595 |
|
|
addi r1,r1,56+12 |
596 |
|
|
blr |
597 |
|
|
} |
598 |
|
|
|
599 |
|
|
static asm void **get_ind_resource(register uint32 type, register int16 index) |
600 |
|
|
{ |
601 |
|
|
// Create stack frame |
602 |
|
|
mflr r0 |
603 |
|
|
stw r0,8(r1) |
604 |
|
|
stwu r1,-(56+12)(r1) |
605 |
|
|
|
606 |
|
|
// Save type/index |
607 |
|
|
stw r3,56(r1) |
608 |
|
|
stw r4,56+4(r1) |
609 |
|
|
|
610 |
|
|
// Call old routine |
611 |
|
|
lwz r0,XLM_GET_IND_RESOURCE |
612 |
|
|
lwz r2,XLM_RES_LIB_TOC |
613 |
|
|
mtctr r0 |
614 |
|
|
bctrl |
615 |
|
|
lwz r2,XLM_TOC // Get TOC |
616 |
|
|
stw r3,56+8(r1) // Save handle |
617 |
|
|
|
618 |
|
|
// Call CheckLoad |
619 |
|
|
lwz r3,56(r1) |
620 |
|
|
lwz r4,56+4(r1) |
621 |
|
|
lwz r5,56+8(r1) |
622 |
|
|
bl check_load_invoc |
623 |
|
|
lwz r3,56+8(r1) // Restore handle |
624 |
|
|
|
625 |
|
|
// Return to caller |
626 |
|
|
lwz r0,56+12+8(r1) |
627 |
|
|
mtlr r0 |
628 |
|
|
addi r1,r1,56+12 |
629 |
|
|
blr |
630 |
|
|
} |
631 |
|
|
|
632 |
|
|
static asm void **get_1_ind_resource(register uint32 type, register int16 index) |
633 |
|
|
{ |
634 |
|
|
// Create stack frame |
635 |
|
|
mflr r0 |
636 |
|
|
stw r0,8(r1) |
637 |
|
|
stwu r1,-(56+12)(r1) |
638 |
|
|
|
639 |
|
|
// Save type/index |
640 |
|
|
stw r3,56(r1) |
641 |
|
|
stw r4,56+4(r1) |
642 |
|
|
|
643 |
|
|
// Call old routine |
644 |
|
|
lwz r0,XLM_GET_1_IND_RESOURCE |
645 |
|
|
lwz r2,XLM_RES_LIB_TOC |
646 |
|
|
mtctr r0 |
647 |
|
|
bctrl |
648 |
|
|
lwz r2,XLM_TOC // Get TOC |
649 |
|
|
stw r3,56+8(r1) // Save handle |
650 |
|
|
|
651 |
|
|
// Call CheckLoad |
652 |
|
|
lwz r3,56(r1) |
653 |
|
|
lwz r4,56+4(r1) |
654 |
|
|
lwz r5,56+8(r1) |
655 |
|
|
bl check_load_invoc |
656 |
|
|
lwz r3,56+8(r1) // Restore handle |
657 |
|
|
|
658 |
|
|
// Return to caller |
659 |
|
|
lwz r0,56+12+8(r1) |
660 |
|
|
mtlr r0 |
661 |
|
|
addi r1,r1,56+12 |
662 |
|
|
blr |
663 |
|
|
} |
664 |
|
|
|
665 |
|
|
static asm void **r_get_resource(register uint32 type, register int16 id) |
666 |
|
|
{ |
667 |
|
|
// Create stack frame |
668 |
|
|
mflr r0 |
669 |
|
|
stw r0,8(r1) |
670 |
|
|
stwu r1,-(56+12)(r1) |
671 |
|
|
|
672 |
|
|
// Save type/ID |
673 |
|
|
stw r3,56(r1) |
674 |
|
|
stw r4,56+4(r1) |
675 |
|
|
|
676 |
|
|
// Call old routine |
677 |
|
|
lwz r0,XLM_R_GET_RESOURCE |
678 |
|
|
lwz r2,XLM_RES_LIB_TOC |
679 |
|
|
mtctr r0 |
680 |
|
|
bctrl |
681 |
|
|
lwz r2,XLM_TOC // Get TOC |
682 |
|
|
stw r3,56+8(r1) // Save handle |
683 |
|
|
|
684 |
|
|
// Call CheckLoad |
685 |
|
|
lwz r3,56(r1) |
686 |
|
|
lwz r4,56+4(r1) |
687 |
|
|
lwz r5,56+8(r1) |
688 |
|
|
bl check_load_invoc |
689 |
|
|
lwz r3,56+8(r1) // Restore handle |
690 |
|
|
|
691 |
|
|
// Return to caller |
692 |
|
|
lwz r0,56+12+8(r1) |
693 |
|
|
mtlr r0 |
694 |
|
|
addi r1,r1,56+12 |
695 |
|
|
blr |
696 |
|
|
} |
697 |
|
|
#else |
698 |
|
|
// Routines in asm_linux.S |
699 |
|
|
extern "C" void get_resource(void); |
700 |
|
|
extern "C" void get_1_resource(void); |
701 |
|
|
extern "C" void get_ind_resource(void); |
702 |
|
|
extern "C" void get_1_ind_resource(void); |
703 |
|
|
extern "C" void r_get_resource(void); |
704 |
|
|
#endif |
705 |
|
|
|
706 |
|
|
void PatchNativeResourceManager(void) |
707 |
|
|
{ |
708 |
|
|
D(bug("PatchNativeResourceManager\n")); |
709 |
|
|
|
710 |
|
|
// Patch native GetResource() |
711 |
gbeauche |
1.3 |
uint32 **upp = (uint32 **)(uintptr)ReadMacInt32(0x1480); |
712 |
cebix |
1.1 |
if (((uint32)upp & 0xffc00000) == ROM_BASE) |
713 |
|
|
return; |
714 |
|
|
uint32 *tvec = upp[5]; |
715 |
|
|
D(bug(" GetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
716 |
|
|
*(uint32 *)XLM_RES_LIB_TOC = tvec[1]; |
717 |
|
|
*(uint32 *)XLM_GET_RESOURCE = tvec[0]; |
718 |
gbeauche |
1.3 |
#if EMULATED_PPC |
719 |
|
|
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_RESOURCE); |
720 |
|
|
#else |
721 |
cebix |
1.1 |
#ifdef __BEOS__ |
722 |
|
|
uint32 *tvec2 = (uint32 *)get_resource; |
723 |
|
|
tvec[0] = tvec2[0]; |
724 |
|
|
tvec[1] = tvec2[1]; |
725 |
|
|
#else |
726 |
|
|
tvec[0] = (uint32)get_resource; |
727 |
|
|
#endif |
728 |
gbeauche |
1.3 |
#endif |
729 |
cebix |
1.1 |
|
730 |
|
|
// Patch native Get1Resource() |
731 |
|
|
upp = *(uint32 ***)0xe7c; |
732 |
|
|
tvec = upp[5]; |
733 |
|
|
D(bug(" Get1Resource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
734 |
|
|
*(uint32 *)XLM_GET_1_RESOURCE = tvec[0]; |
735 |
gbeauche |
1.3 |
#if EMULATED_PPC |
736 |
|
|
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_RESOURCE); |
737 |
|
|
#else |
738 |
cebix |
1.1 |
#ifdef __BEOS__ |
739 |
|
|
tvec2 = (uint32 *)get_1_resource; |
740 |
|
|
tvec[0] = tvec2[0]; |
741 |
|
|
tvec[1] = tvec2[1]; |
742 |
|
|
#else |
743 |
|
|
tvec[0] = (uint32)get_1_resource; |
744 |
|
|
#endif |
745 |
gbeauche |
1.3 |
#endif |
746 |
cebix |
1.1 |
|
747 |
|
|
// Patch native GetIndResource() |
748 |
|
|
upp = *(uint32 ***)0x1474; |
749 |
|
|
tvec = upp[5]; |
750 |
|
|
D(bug(" GetIndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
751 |
|
|
*(uint32 *)XLM_GET_IND_RESOURCE = tvec[0]; |
752 |
gbeauche |
1.3 |
#if EMULATED_PPC |
753 |
|
|
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_IND_RESOURCE); |
754 |
|
|
#else |
755 |
cebix |
1.1 |
#ifdef __BEOS__ |
756 |
|
|
tvec2 = (uint32 *)get_ind_resource; |
757 |
|
|
tvec[0] = tvec2[0]; |
758 |
|
|
tvec[1] = tvec2[1]; |
759 |
|
|
#else |
760 |
|
|
tvec[0] = (uint32)get_ind_resource; |
761 |
|
|
#endif |
762 |
gbeauche |
1.3 |
#endif |
763 |
cebix |
1.1 |
|
764 |
|
|
// Patch native Get1IndResource() |
765 |
|
|
upp = *(uint32 ***)0xe38; |
766 |
|
|
tvec = upp[5]; |
767 |
|
|
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
768 |
|
|
*(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0]; |
769 |
gbeauche |
1.3 |
#if EMULATED_PPC |
770 |
|
|
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_IND_RESOURCE); |
771 |
|
|
#else |
772 |
cebix |
1.1 |
#ifdef __BEOS__ |
773 |
|
|
tvec2 = (uint32 *)get_1_ind_resource; |
774 |
|
|
tvec[0] = tvec2[0]; |
775 |
|
|
tvec[1] = tvec2[1]; |
776 |
|
|
#else |
777 |
|
|
tvec[0] = (uint32)get_1_ind_resource; |
778 |
|
|
#endif |
779 |
gbeauche |
1.3 |
#endif |
780 |
cebix |
1.1 |
|
781 |
|
|
// Patch native RGetResource() |
782 |
|
|
upp = *(uint32 ***)0xe30; |
783 |
|
|
tvec = upp[5]; |
784 |
|
|
D(bug(" RGetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
785 |
|
|
*(uint32 *)XLM_R_GET_RESOURCE = tvec[0]; |
786 |
gbeauche |
1.3 |
#if EMULATED_PPC |
787 |
|
|
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_R_GET_RESOURCE); |
788 |
|
|
#else |
789 |
cebix |
1.1 |
#ifdef __BEOS__ |
790 |
|
|
tvec2 = (uint32 *)r_get_resource; |
791 |
|
|
tvec[0] = tvec2[0]; |
792 |
|
|
tvec[1] = tvec2[1]; |
793 |
|
|
#else |
794 |
|
|
tvec[0] = (uint32)r_get_resource; |
795 |
gbeauche |
1.3 |
#endif |
796 |
cebix |
1.1 |
#endif |
797 |
|
|
} |