ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/rsrc_patches.cpp
Revision: 1.11
Committed: 2002-01-15T14:58:32Z (22 years, 10 months ago) by cebix
Branch: MAIN
CVS Tags: nigel-build-12, nigel-build-13, snapshot-15012002
Changes since 1.10: +1 -1 lines
Log Message:
- documentation updates
- 2001 -> 2002
- version 0.9 -> 1.0

File Contents

# Content
1 /*
2 * rsrc_patches.cpp - Resource patches
3 *
4 * Basilisk II (C) 1997-2002 Christian Bauer
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 <string.h>
22
23 #include "sysdeps.h"
24 #include "cpu_emulation.h"
25 #include "macos_util.h"
26 #include "main.h"
27 #include "emul_op.h"
28 #include "audio.h"
29 #include "audio_defs.h"
30 #include "rsrc_patches.h"
31
32 #if ENABLE_MON
33 #include "mon.h"
34 #endif
35
36 #define DEBUG 0
37 #include "debug.h"
38
39
40 /*
41 * Search resource for byte string, return offset (or 0)
42 */
43
44 static uint32 find_rsrc_data(const uint8 *rsrc, uint32 max, const uint8 *search, uint32 search_len, uint32 ofs = 0)
45 {
46 while (ofs < max - search_len) {
47 if (!memcmp(rsrc + ofs, search, search_len))
48 return ofs;
49 ofs++;
50 }
51 return 0;
52 }
53
54
55 /*
56 * Resource patches via vCheckLoad
57 */
58
59 void CheckLoad(uint32 type, int16 id, uint8 *p, uint32 size)
60 {
61 uint16 *p16;
62 uint32 base;
63 D(bug("vCheckLoad %c%c%c%c (%08x) ID %d, data %p, size %d\n", (char)(type >> 24), (char)((type >> 16) & 0xff), (char )((type >> 8) & 0xff), (char )(type & 0xff), type, id, p, size));
64
65 if (type == FOURCC('b','o','o','t') && id == 3) {
66 D(bug(" boot 3 found\n"));
67
68 // Set boot stack pointer (7.5, 7.6, 7.6.1, 8.0)
69 static const uint8 dat[] = {0x22, 0x00, 0xe4, 0x89, 0x90, 0x81, 0x22, 0x40};
70 base = find_rsrc_data(p, size, dat, sizeof(dat));
71 if (base) {
72 p16 = (uint16 *)(p + base + 6);
73 *p16 = htons(M68K_EMUL_OP_FIX_BOOTSTACK);
74 FlushCodeCache(p + base + 6, 2);
75 D(bug(" patch 1 applied\n"));
76 }
77
78 #if !ROM_IS_WRITE_PROTECTED
79 // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.1, 7.5, 8.0)
80 static const uint8 dat2[] = {0x20, 0x78, 0x02, 0xae, 0xd1, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x21, 0xc8, 0x00, 0x00};
81 base = find_rsrc_data(p, size, dat2, sizeof(dat2));
82 if (base) {
83 p16 = (uint16 *)(p + base);
84
85 #if defined(USE_SCRATCHMEM_SUBTERFUGE)
86 // Set 0x0000 to scratch memory area
87 extern uint8 *ScratchMem;
88 const uint32 ScratchMemBase = Host2MacAddr(ScratchMem);
89 *p16++ = htons(0x207c); // move.l #ScratchMem,a0
90 *p16++ = htons(ScratchMemBase >> 16);
91 *p16++ = htons(ScratchMemBase);
92 *p16++ = htons(M68K_NOP);
93 *p16 = htons(M68K_NOP);
94 #else
95 #error System specific handling for writable ROM is required here
96 #endif
97 FlushCodeCache(p + base, 14);
98 D(bug(" patch 2 applied\n"));
99 }
100
101 } else if (type == FOURCC('b','o','o','t') && id == 2) {
102 D(bug(" boot 2 found\n"));
103
104 // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.1, 7.5, 8.0)
105 static const uint8 dat[] = {0x20, 0x78, 0x02, 0xae, 0xd1, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x21, 0xc8, 0x00, 0x00};
106 base = find_rsrc_data(p, size, dat, sizeof(dat));
107 if (base) {
108 p16 = (uint16 *)(p + base);
109
110 #if defined(USE_SCRATCHMEM_SUBTERFUGE)
111 // Set 0x0000 to scratch memory area
112 extern uint8 *ScratchMem;
113 const uint32 ScratchMemBase = Host2MacAddr(ScratchMem);
114 *p16++ = htons(0x207c); // move.l #ScratchMem,a0
115 *p16++ = htons(ScratchMemBase >> 16);
116 *p16++ = htons(ScratchMemBase);
117 *p16++ = htons(M68K_NOP);
118 *p16 = htons(M68K_NOP);
119 #else
120 #error System specific handling for writable ROM is required here
121 #endif
122 FlushCodeCache(p + base, 14);
123 D(bug(" patch 1 applied\n"));
124 }
125 #endif
126
127 } else if (type == FOURCC('P','T','C','H') && id == 630) {
128 D(bug("PTCH 630 found\n"));
129
130 // Don't replace Time Manager (Classic ROM, 6.0.3)
131 static const uint8 dat[] = {0x30, 0x3c, 0x00, 0x58, 0xa2, 0x47};
132 base = find_rsrc_data(p, size, dat, sizeof(dat));
133 if (base) {
134 p16 = (uint16 *)(p + base);
135 p16[2] = htons(M68K_NOP);
136 p16[7] = htons(M68K_NOP);
137 p16[12] = htons(M68K_NOP);
138 FlushCodeCache(p + base, 26);
139 D(bug(" patch 1 applied\n"));
140 }
141
142 // Don't replace Time Manager (Classic ROM, 6.0.8)
143 static const uint8 dat2[] = {0x70, 0x58, 0xa2, 0x47};
144 base = find_rsrc_data(p, size, dat2, sizeof(dat2));
145 if (base) {
146 p16 = (uint16 *)(p + base);
147 p16[1] = htons(M68K_NOP);
148 p16[5] = htons(M68K_NOP);
149 p16[9] = htons(M68K_NOP);
150 FlushCodeCache(p + base, 20);
151 D(bug(" patch 1 applied\n"));
152 }
153
154 } else if (type == FOURCC('p','t','c','h') && id == 26) {
155 D(bug(" ptch 26 found\n"));
156
157 // Trap ABC4 is initialized with absolute ROM address (7.1, 7.5, 7.6, 7.6.1, 8.0)
158 static const uint8 dat[] = {0x40, 0x83, 0x36, 0x10};
159 base = find_rsrc_data(p, size, dat, sizeof(dat));
160 if (base) {
161 p16 = (uint16 *)(p + base);
162 *p16++ = htons((ROMBaseMac + 0x33610) >> 16);
163 *p16 = htons((ROMBaseMac + 0x33610) & 0xffff);
164 FlushCodeCache(p + base, 4);
165 D(bug(" patch 1 applied\n"));
166 }
167
168 } else if (type == FOURCC('p','t','c','h') && id == 34) {
169 D(bug(" ptch 34 found\n"));
170
171 // Don't wait for VIA (Classic ROM, 6.0.8)
172 static const uint8 dat[] = {0x22, 0x78, 0x01, 0xd4, 0x10, 0x11, 0x02, 0x00, 0x00, 0x30};
173 base = find_rsrc_data(p, size, dat, sizeof(dat));
174 if (base) {
175 p16 = (uint16 *)(p + base + 14);
176 *p16 = htons(M68K_NOP);
177 FlushCodeCache(p + base + 14, 2);
178 D(bug(" patch 1 applied\n"));
179 }
180
181 // Don't replace ADBOp() (Classic ROM, 6.0.8)
182 static const uint8 dat2[] = {0x21, 0xc0, 0x05, 0xf0};
183 base = find_rsrc_data(p, size, dat2, sizeof(dat2));
184 if (base) {
185 p16 = (uint16 *)(p + base);
186 *p16++ = htons(M68K_NOP);
187 *p16 = htons(M68K_NOP);
188 FlushCodeCache(p + base, 4);
189 D(bug(" patch 2 applied\n"));
190 }
191
192 } else if (type == FOURCC('g','p','c','h') && id == 750) {
193 D(bug(" gpch 750 found\n"));
194
195 // Don't use PTEST instruction in BlockMove() (7.5, 7.6, 7.6.1, 8.0)
196 static const uint8 dat[] = {0x20, 0x5f, 0x22, 0x5f, 0x0c, 0x38, 0x00, 0x04, 0x01, 0x2f};
197 base = find_rsrc_data(p, size, dat, sizeof(dat));
198 if (base) {
199 p16 = (uint16 *)(p + base + 4);
200 *p16++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
201 *p16++ = htons(0x7000);
202 *p16 = htons(M68K_RTS);
203 FlushCodeCache(p + base + 4, 6);
204 D(bug(" patch 1 applied\n"));
205 }
206
207 } else if (type == FOURCC('l','p','c','h') && id == 24) {
208 D(bug(" lpch 24 found\n"));
209
210 // Don't replace Time Manager (7.0.1, 7.1, 7.5, 7.6, 7.6.1, 8.0)
211 static const uint8 dat[] = {0x70, 0x59, 0xa2, 0x47};
212 base = find_rsrc_data(p, size, dat, sizeof(dat));
213 if (base) {
214 p16 = (uint16 *)(p + base + 2);
215 *p16++ = htons(M68K_NOP);
216 p16 += 3;
217 *p16++ = htons(M68K_NOP);
218 p16 += 7;
219 *p16 = htons(M68K_NOP);
220 FlushCodeCache(p + base + 2, 28);
221 D(bug(" patch 1 applied\n"));
222 }
223
224 } else if (type == FOURCC('l','p','c','h') && id == 31) {
225 D(bug(" lpch 31 found\n"));
226
227 // Don't write to VIA in vSoundDead() (7.0.1, 7.1, 7.5, 7.6, 7.6.1, 8.0)
228 static const uint8 dat[] = {0x20, 0x78, 0x01, 0xd4, 0x08, 0xd0, 0x00, 0x07, 0x4e, 0x75};
229 base = find_rsrc_data(p, size, dat, sizeof(dat));
230 if (base) {
231 p16 = (uint16 *)(p + base);
232 *p16 = htons(M68K_RTS);
233 FlushCodeCache(p + base, 2);
234 D(bug(" patch 1 applied\n"));
235 }
236
237 // Don't replace SCSI manager (7.1, 7.5, 7.6.1, 8.0)
238 static const uint8 dat2[] = {0x0c, 0x6f, 0x00, 0x0e, 0x00, 0x04, 0x66, 0x0c};
239 base = find_rsrc_data(p, size, dat2, sizeof(dat2));
240 if (base) {
241 p16 = (uint16 *)(p + base);
242 *p16++ = htons(M68K_EMUL_OP_SCSI_DISPATCH);
243 *p16++ = htons(0x2e49); // move.l a1,a7
244 *p16 = htons(M68K_JMP_A0);
245 FlushCodeCache(p + base, 6);
246 D(bug(" patch 2 applied\n"));
247 }
248
249 } else if (type == FOURCC('t','h','n','g') && id == -16563) {
250 D(bug(" thng -16563 found\n"));
251
252 // Set audio component flags (7.5, 7.6, 7.6.1, 8.0)
253 *(uint32 *)(p + componentFlags) = htonl(audio_component_flags);
254 D(bug(" patch 1 applied\n"));
255
256 } else if (type == FOURCC('s','i','f','t') && id == -16563) {
257 D(bug(" sift -16563 found\n"));
258
259 // Replace audio component (7.5, 7.6, 7.6.1, 8.0)
260 p16 = (uint16 *)p;
261 *p16++ = htons(0x4e56); *p16++ = htons(0x0000); // link a6,#0
262 *p16++ = htons(0x48e7); *p16++ = htons(0x8018); // movem.l d0/a3-a4,-(sp)
263 *p16++ = htons(0x266e); *p16++ = htons(0x000c); // movea.l 12(a6),a3
264 *p16++ = htons(0x286e); *p16++ = htons(0x0008); // movea.l 8(a6),a4
265 *p16++ = htons(M68K_EMUL_OP_AUDIO);
266 *p16++ = htons(0x2d40); *p16++ = htons(0x0010); // move.l d0,16(a6)
267 *p16++ = htons(0x4cdf); *p16++ = htons(0x1801); // movem.l (sp)+,d0/a3-a4
268 *p16++ = htons(0x4e5e); // unlk a6
269 *p16++ = htons(0x4e74); *p16++ = htons(0x0008); // rtd #8
270 FlushCodeCache(p, 32);
271 D(bug(" patch 1 applied\n"));
272
273 } else if (type == FOURCC('i','n','s','t') && id == -19069) {
274 D(bug(" inst -19069 found\n"));
275
276 // Don't replace Microseconds (QuickTime 2.0)
277 static const uint8 dat[] = {0x30, 0x3c, 0xa1, 0x93, 0xa2, 0x47};
278 base = find_rsrc_data(p, size, dat, sizeof(dat));
279 if (base) {
280 p16 = (uint16 *)(p + base + 4);
281 *p16 = htons(M68K_NOP);
282 FlushCodeCache(p + base + 4, 2);
283 D(bug(" patch 1 applied\n"));
284 }
285
286 } else if (type == FOURCC('D','R','V','R') && id == -20066) {
287 D(bug("DRVR -20066 found\n"));
288
289 // Don't access SCC in .Infra driver
290 static const uint8 dat[] = {0x28, 0x78, 0x01, 0xd8, 0x48, 0xc7, 0x20, 0x0c, 0xd0, 0x87, 0x20, 0x40, 0x1c, 0x10};
291 base = find_rsrc_data(p, size, dat, sizeof(dat));
292 if (base) {
293 p16 = (uint16 *)(p + base + 12);
294 *p16 = htons(0x7a00); // moveq #0,d6
295 FlushCodeCache(p + base + 12, 2);
296 D(bug(" patch 1 applied\n"));
297 }
298
299 } else if (type == FOURCC('l','t','l','k') && id == 0) {
300 D(bug(" ltlk 0 found\n"));
301
302 // Disable LocalTalk (7.0.1, 7.5, 7.6, 7.6.1, 8.0)
303 p16 = (uint16 *)p;
304 *p16++ = htons(M68K_JMP_A0);
305 *p16++ = htons(0x7000);
306 *p16 = htons(M68K_RTS);
307 FlushCodeCache(p, 6);
308 D(bug(" patch 1 applied\n"));
309 }
310 #if REAL_ADDRESSING && !defined(AMIGA)
311 else if (type == FOURCC('D','R','V','R') && id == 41) {
312 D(bug(" DRVR 41 found\n"));
313
314 // gb-- [0x28E (ROM85)] contains 0x3fff that will be placed into a0
315 // Seems to be caused by the AppleShare extension from MacOS 8.1 (3.7.4)
316 // .AFPTranslator (DRVR addr 0x2372)
317 static const uint8 dat[] = {0x3a, 0x2e, 0x00, 0x0a, 0x55, 0x4f, 0x3e, 0xb8, 0x02, 0x8e, 0x30, 0x1f, 0x48, 0xc0, 0x24, 0x40, 0x20, 0x40};
318 base = find_rsrc_data(p, size, dat, sizeof(dat));
319 if (base) {
320 p16 = (uint16 *)(p + base + 4);
321 *p16++ = htons(0x3078); // movea.w ROM85,%a0
322 *p16++ = htons(0x028e);
323 *p16++ = htons(0xd1fc); // adda.l #RAMBaseMac,%a0
324 *p16++ = htons((RAMBaseMac >> 16) & 0xffff);
325 *p16++ = htons(RAMBaseMac & 0xffff);
326 *p16++ = htons(0x2448); // movea.l %a0,%a2
327 *p16++ = htons(M68K_NOP);
328 FlushCodeCache(p + base + 4, 14);
329 D(bug(" patch 1 applied\n"));
330 }
331 }
332 #endif
333 }