ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/rsrc_patches.cpp
Revision: 1.5
Committed: 2000-07-22T16:07:18Z (23 years, 9 months ago) by cebix
Branch: MAIN
Changes since 1.4: +17 -16 lines
Log Message:
- new FOURCC() macro in macos_util.h

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * rsrc_patches.cpp - Resource patches
3     *
4 cebix 1.3 * Basilisk II (C) 1997-2000 Christian Bauer
5 cebix 1.1 *
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 cebix 1.5 #include "macos_util.h"
26 cebix 1.1 #include "main.h"
27     #include "emul_op.h"
28     #include "audio.h"
29     #include "audio_defs.h"
30     #include "rsrc_patches.h"
31    
32 cebix 1.2 #if ENABLE_MON
33     #include "mon.h"
34     #endif
35    
36 cebix 1.1 #define DEBUG 0
37     #include "debug.h"
38    
39    
40     #if !EMULATED_68K
41     // Assembly functions
42     extern "C" void Scod060Patch1(void);
43     extern "C" void Scod060Patch2(void);
44     extern "C" void ThInitFPUPatch(void);
45     #endif
46    
47    
48     /*
49     * Search resource for byte string, return offset (or 0)
50     */
51    
52     static uint32 find_rsrc_data(const uint8 *rsrc, uint32 max, const uint8 *search, uint32 search_len, uint32 ofs = 0)
53     {
54     while (ofs < max - search_len) {
55     if (!memcmp(rsrc + ofs, search, search_len))
56     return ofs;
57     ofs++;
58     }
59     return 0;
60     }
61    
62    
63     /*
64     * Resource patches via vCheckLoad
65     */
66    
67     void CheckLoad(uint32 type, int16 id, uint8 *p, uint32 size)
68     {
69     uint16 *p16;
70     uint32 base;
71 cebix 1.5 D(bug("vCheckLoad %c%c%c%c (%08x) ID %d, data %08x, size %d\n", (char)(type >> 24), (char)((type >> 16) & 0xff), (char )((type >> 8) & 0xff), (char )(type & 0xff), type, id, p, size));
72 cebix 1.1
73 cebix 1.5 if (type == FOURCC('b','o','o','t') && id == 3) {
74 cebix 1.1 D(bug(" boot 3 found\n"));
75    
76     // Set boot stack pointer (7.5, 7.6, 7.6.1, 8.0)
77     static const uint8 dat[] = {0x22, 0x00, 0xe4, 0x89, 0x90, 0x81, 0x22, 0x40};
78     base = find_rsrc_data(p, size, dat, sizeof(dat));
79     if (base) {
80     p16 = (uint16 *)(p + base + 6);
81     *p16 = htons(M68K_EMUL_OP_FIX_BOOTSTACK);
82     FlushCodeCache(p + base + 6, 2);
83     D(bug(" patch 1 applied\n"));
84     }
85    
86     #if !ROM_IS_WRITE_PROTECTED
87     // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.5, 8.0)
88     static const uint8 dat2[] = {0x20, 0x78, 0x02, 0xae, 0xd1, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x21, 0xc8, 0x00, 0x00};
89     base = find_rsrc_data(p, size, dat2, sizeof(dat2));
90     if (base) {
91     p16 = (uint16 *)(p + base);
92    
93 cebix 1.4 #if defined(AMIGA) || defined(__NetBSD__)
94 cebix 1.1 // Set 0x0000 to scratch memory area
95     extern uint32 ScratchMem;
96     *p16++ = htons(0x207c); // move.l #ScratchMem,a0
97     *p16++ = htons(ScratchMem >> 16);
98     *p16++ = htons(ScratchMem);
99     *p16++ = htons(M68K_NOP);
100     *p16 = htons(M68K_NOP);
101     #else
102     #error System specific handling for writable ROM is required here
103     #endif
104     FlushCodeCache(p + base, 14);
105     D(bug(" patch 2 applied\n"));
106     }
107    
108 cebix 1.5 } else if (type == FOURCC('b','o','o','t') && id == 2) {
109 cebix 1.1 D(bug(" boot 2 found\n"));
110    
111     // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.5, 8.0)
112     static const uint8 dat[] = {0x20, 0x78, 0x02, 0xae, 0xd1, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x21, 0xc8, 0x00, 0x00};
113     base = find_rsrc_data(p, size, dat, sizeof(dat));
114     if (base) {
115     p16 = (uint16 *)(p + base);
116    
117 cebix 1.4 #if defined(AMIGA) || defined(__NetBSD__)
118 cebix 1.1 // Set 0x0000 to scratch memory area
119     extern uint32 ScratchMem;
120     *p16++ = htons(0x207c); // move.l #ScratchMem,a0
121     *p16++ = htons(ScratchMem >> 16);
122     *p16++ = htons(ScratchMem);
123     *p16++ = htons(M68K_NOP);
124     *p16 = htons(M68K_NOP);
125     #else
126     #error System specific handling for writable ROM is required here
127     #endif
128     FlushCodeCache(p + base, 14);
129     D(bug(" patch 1 applied\n"));
130     }
131     #endif
132    
133 cebix 1.5 } else if (type == FOURCC('P','T','C','H') && id == 630) {
134 cebix 1.1 D(bug("PTCH 630 found\n"));
135    
136     // Don't replace Time Manager (Classic ROM, 6.0.3)
137     static const uint8 dat[] = {0x30, 0x3c, 0x00, 0x58, 0xa2, 0x47};
138     base = find_rsrc_data(p, size, dat, sizeof(dat));
139     if (base) {
140     p16 = (uint16 *)(p + base);
141     p16[2] = htons(M68K_NOP);
142     p16[7] = htons(M68K_NOP);
143     p16[12] = htons(M68K_NOP);
144     FlushCodeCache(p + base, 26);
145     D(bug(" patch 1 applied\n"));
146     }
147    
148     // Don't replace Time Manager (Classic ROM, 6.0.8)
149     static const uint8 dat2[] = {0x70, 0x58, 0xa2, 0x47};
150     base = find_rsrc_data(p, size, dat2, sizeof(dat2));
151     if (base) {
152     p16 = (uint16 *)(p + base);
153     p16[1] = htons(M68K_NOP);
154     p16[5] = htons(M68K_NOP);
155     p16[9] = htons(M68K_NOP);
156     FlushCodeCache(p + base, 20);
157     D(bug(" patch 1 applied\n"));
158     }
159    
160 cebix 1.5 } else if (type == FOURCC('p','t','c','h') && id == 26) {
161 cebix 1.1 D(bug(" ptch 26 found\n"));
162    
163     // Trap ABC4 is initialized with absolute ROM address (7.5, 7.6, 7.6.1, 8.0)
164     static const uint8 dat[] = {0x40, 0x83, 0x36, 0x10};
165     base = find_rsrc_data(p, size, dat, sizeof(dat));
166     if (base) {
167     p16 = (uint16 *)(p + base);
168     *p16++ = htons((ROMBaseMac + 0x33610) >> 16);
169     *p16 = htons((ROMBaseMac + 0x33610) & 0xffff);
170     FlushCodeCache(p + base, 4);
171     D(bug(" patch 1 applied\n"));
172     }
173    
174 cebix 1.5 } else if (type == FOURCC('p','t','c','h') && id == 34) {
175 cebix 1.1 D(bug(" ptch 34 found\n"));
176    
177     // Don't wait for VIA (Classic ROM, 6.0.8)
178     static const uint8 dat[] = {0x22, 0x78, 0x01, 0xd4, 0x10, 0x11, 0x02, 0x00, 0x00, 0x30};
179     base = find_rsrc_data(p, size, dat, sizeof(dat));
180     if (base) {
181     p16 = (uint16 *)(p + base + 14);
182     *p16 = htons(M68K_NOP);
183     FlushCodeCache(p + base + 14, 2);
184     D(bug(" patch 1 applied\n"));
185     }
186    
187     // Don't replace ADBOp() (Classic ROM, 6.0.8)
188     static const uint8 dat2[] = {0x21, 0xc0, 0x05, 0xf0};
189     base = find_rsrc_data(p, size, dat2, sizeof(dat2));
190     if (base) {
191     p16 = (uint16 *)(p + base);
192     *p16++ = htons(M68K_NOP);
193     *p16 = htons(M68K_NOP);
194     FlushCodeCache(p + base, 4);
195     D(bug(" patch 2 applied\n"));
196     }
197    
198     #if !EMULATED_68K
199 cebix 1.5 } else if (CPUIs68060 && (type == FOURCC('g','p','c','h') && id == 669 || type == FOURCC('l','p','c','h') && id == 63)) {
200 cebix 1.1 D(bug(" gpch 669/lpch 63 found\n"));
201    
202     static uint16 ThPatchSpace[1024]; // Replacement routines are constructed here
203     uint16 *q = ThPatchSpace;
204     uint32 start;
205     int i;
206    
207     // Patch Thread Manager thread switcher for 68060 FPU (7.5, 8.0)
208     static const uint8 dat[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x18};
209     base = find_rsrc_data(p, size, dat, sizeof(dat));
210     if (base) { // Skip first routine (no FPU -> no FPU)
211    
212     base = find_rsrc_data(p, size - base - 2, dat, sizeof(dat), base + 2);
213     if (base) { // no FPU -> FPU
214    
215     p16 = (uint16 *)(p + base);
216     start = (uint32)q;
217     for (i=0; i<28; i++) *q++ = *p16++;
218     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?)
219     *q++ = htons(2);
220     *q++ = htons(0x6712); // beq
221     *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it)
222     *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers)
223     *q++ = htons(0x9000);
224     *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr
225     *q++ = htons(0x8800);
226     *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar
227     *q++ = htons(0x8400);
228     *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7
229     *q++ = htons(0xd0ff);
230     *q++ = htons(0xf35f); // frestore (sp)+
231     *q++ = htons(0x4e75); // rts
232    
233     p16 = (uint16 *)(p + base);
234     *p16++ = htons(M68K_JMP);
235     *p16++ = htons(start >> 16);
236     *p16 = htons(start & 0xffff);
237     FlushCodeCache(p + base, 6);
238     D(bug(" patch 1 applied\n"));
239    
240     static const uint8 dat2[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x28};
241     base = find_rsrc_data(p, size, dat2, sizeof(dat2));
242     if (base) { // FPU -> FPU
243    
244     p16 = (uint16 *)(p + base);
245     start = (uint32)q;
246     for (i=0; i<4; i++) *q++ = *p16++;
247     *q++ = htons(0x6736); // beq
248     *q++ = htons(0xf327); // fsave -(sp) (save FPU state frame)
249     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?)
250     *q++ = htons(2);
251     *q++ = htons(0x6716); // beq
252     *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers)
253     *q++ = htons(0xe0ff);
254     *q++ = htons(0xf227); // fmove.l fpiar,-(sp)
255     *q++ = htons(0xa400);
256     *q++ = htons(0xf227); // fmove.l fpsr,-(sp)
257     *q++ = htons(0xa800);
258     *q++ = htons(0xf227); // fmove.l fpcr,-(sp)
259     *q++ = htons(0xb000);
260     *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag)
261     *q++ = htons(0xffff);
262     *q++ = htons(0xffff);
263     p16 += 9;
264     for (i=0; i<23; i++) *q++ = *p16++;
265     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?)
266     *q++ = htons(2);
267     *q++ = htons(0x6712); // beq
268     *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it)
269     *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers)
270     *q++ = htons(0x9000);
271     *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr
272     *q++ = htons(0x8800);
273     *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar
274     *q++ = htons(0x8400);
275     *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7
276     *q++ = htons(0xd0ff);
277     *q++ = htons(0xf35f); // frestore (sp)+
278     *q++ = htons(0x4e75); // rts
279    
280     p16 = (uint16 *)(p + base);
281     *p16++ = htons(M68K_JMP);
282     *p16++ = htons(start >> 16);
283     *p16 = htons(start & 0xffff);
284     FlushCodeCache(p + base, 6);
285     D(bug(" patch 2 applied\n"));
286    
287     base = find_rsrc_data(p, size - base - 2, dat2, sizeof(dat2), base + 2);
288     if (base) { // FPU -> no FPU
289    
290     p16 = (uint16 *)(p + base);
291     start = (uint32)q;
292     for (i=0; i<4; i++) *q++ = *p16++;
293     *q++ = htons(0x6736); // beq
294     *q++ = htons(0xf327); // fsave -(sp) (save FPU state frame)
295     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?)
296     *q++ = htons(2);
297     *q++ = htons(0x6716); // beq
298     *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers)
299     *q++ = htons(0xe0ff);
300     *q++ = htons(0xf227); // fmove.l fpiar,-(sp)
301     *q++ = htons(0xa400);
302     *q++ = htons(0xf227); // fmove.l fpsr,-(sp)
303     *q++ = htons(0xa800);
304     *q++ = htons(0xf227); // fmove.l fpcr,-(sp)
305     *q++ = htons(0xb000);
306     *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag)
307     *q++ = htons(0xffff);
308     *q++ = htons(0xffff);
309     p16 += 9;
310     for (i=0; i<24; i++) *q++ = *p16++;
311    
312     p16 = (uint16 *)(p + base);
313     *p16++ = htons(M68K_JMP);
314     *p16++ = htons(start >> 16);
315     *p16 = htons(start & 0xffff);
316     FlushCodeCache(p + base, 6);
317     D(bug(" patch 3 applied\n"));
318     }
319     }
320     }
321     }
322    
323     // Patch Thread Manager thread switcher for 68060 FPU (additional routines under 8.0 for Mixed Mode Manager)
324     static const uint8 dat3[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x40};
325     base = find_rsrc_data(p, size, dat3, sizeof(dat3));
326     if (base) { // Skip first routine (no FPU -> no FPU)
327    
328     base = find_rsrc_data(p, size - base - 2, dat3, sizeof(dat3), base + 2);
329     if (base) { // no FPU -> FPU
330    
331     p16 = (uint16 *)(p + base);
332     start = (uint32)q;
333     for (i=0; i<48; i++) *q++ = *p16++;
334     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?)
335     *q++ = htons(2);
336     *q++ = htons(0x6712); // beq
337     *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it)
338     *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers)
339     *q++ = htons(0x9000);
340     *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr
341     *q++ = htons(0x8800);
342     *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar
343     *q++ = htons(0x8400);
344     *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7
345     *q++ = htons(0xd0ff);
346     p16 += 7;
347     for (i=0; i<20; i++) *q++ = *p16++;
348    
349     p16 = (uint16 *)(p + base);
350     *p16++ = htons(M68K_JMP);
351     *p16++ = htons(start >> 16);
352     *p16 = htons(start & 0xffff);
353     FlushCodeCache(p + base, 6);
354     D(bug(" patch 4 applied\n"));
355    
356     static const uint8 dat4[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x50};
357     base = find_rsrc_data(p, size, dat4, sizeof(dat4));
358     if (base) { // FPU -> FPU
359    
360     p16 = (uint16 *)(p + base);
361     start = (uint32)q;
362     for (i=0; i<4; i++) *q++ = *p16++;
363     *q++ = htons(0x675e); // beq
364     p16++;
365     for (i=0; i<21; i++) *q++ = *p16++;
366     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?)
367     *q++ = htons(2);
368     *q++ = htons(0x6716); // beq
369     *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers)
370     *q++ = htons(0xe0ff);
371     *q++ = htons(0xf227); // fmove.l fpiar,-(sp)
372     *q++ = htons(0xa400);
373     *q++ = htons(0xf227); // fmove.l fpsr,-(sp)
374     *q++ = htons(0xa800);
375     *q++ = htons(0xf227); // fmove.l fpcr,-(sp)
376     *q++ = htons(0xb000);
377     *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag)
378     *q++ = htons(0xffff);
379     *q++ = htons(0xffff);
380     p16 += 7;
381     for (i=0; i<23; i++) *q++ = *p16++;
382     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?)
383     *q++ = htons(2);
384     *q++ = htons(0x6712); // beq
385     *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it)
386     *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers)
387     *q++ = htons(0x9000);
388     *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr
389     *q++ = htons(0x8800);
390     *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar
391     *q++ = htons(0x8400);
392     *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7
393     *q++ = htons(0xd0ff);
394     p16 += 7;
395     for (i=0; i<20; i++) *q++ = *p16++;
396    
397     p16 = (uint16 *)(p + base);
398     *p16++ = htons(M68K_JMP);
399     *p16++ = htons(start >> 16);
400     *p16 = htons(start & 0xffff);
401     FlushCodeCache(p + base, 6);
402     D(bug(" patch 5 applied\n"));
403    
404     base = find_rsrc_data(p, size - base - 2, dat4, sizeof(dat4), base + 2);
405     if (base) { // FPU -> no FPU
406    
407     p16 = (uint16 *)(p + base);
408     start = (uint32)q;
409     for (i=0; i<4; i++) *q++ = *p16++;
410     *q++ = htons(0x675e); // beq
411     p16++;
412     for (i=0; i<21; i++) *q++ = *p16++;
413     *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?)
414     *q++ = htons(2);
415     *q++ = htons(0x6716); // beq
416     *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers)
417     *q++ = htons(0xe0ff);
418     *q++ = htons(0xf227); // fmove.l fpiar,-(sp)
419     *q++ = htons(0xa400);
420     *q++ = htons(0xf227); // fmove.l fpsr,-(sp)
421     *q++ = htons(0xa800);
422     *q++ = htons(0xf227); // fmove.l fpcr,-(sp)
423     *q++ = htons(0xb000);
424     *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag)
425     *q++ = htons(0xffff);
426     *q++ = htons(0xffff);
427     p16 += 7;
428     for (i=0; i<42; i++) *q++ = *p16++;
429    
430     p16 = (uint16 *)(p + base);
431     *p16++ = htons(M68K_JMP);
432     *p16++ = htons(start >> 16);
433     *p16 = htons(start & 0xffff);
434     FlushCodeCache(p + base, 6);
435     D(bug(" patch 6 applied\n"));
436     }
437     }
438     }
439     }
440    
441     FlushCodeCache(ThPatchSpace, 1024);
442    
443     // Patch Thread Manager FPU init for 68060 FPU (7.5, 8.0)
444     static const uint8 dat5[] = {0x4a, 0x28, 0x00, 0xa4, 0x67, 0x0a, 0x4a, 0x2c, 0x00, 0x40};
445     base = find_rsrc_data(p, size, dat5, sizeof(dat5));
446     if (base) {
447     p16 = (uint16 *)(p + base + 6);
448     *p16++ = htons(M68K_JSR);
449     *p16++ = htons((uint32)ThInitFPUPatch >> 16);
450     *p16++ = htons((uint32)ThInitFPUPatch & 0xffff);
451     *p16++ = htons(M68K_NOP);
452     *p16 = htons(M68K_NOP);
453     FlushCodeCache(p + base + 6, 10);
454     D(bug(" patch 7 applied\n"));
455     }
456     #endif
457    
458 cebix 1.5 } else if (type == FOURCC('g','p','c','h') && id == 750) {
459 cebix 1.1 D(bug(" gpch 750 found\n"));
460    
461     // Don't use PTEST instruction in BlockMove() (7.5, 7.6, 7.6.1, 8.0)
462     static const uint8 dat[] = {0xa0, 0x8d, 0x0c, 0x81, 0x00, 0x00, 0x0c, 0x00, 0x65, 0x06, 0x4e, 0x71, 0xf4, 0xf8};
463     base = find_rsrc_data(p, size, dat, sizeof(dat));
464     if (base) {
465     p16 = (uint16 *)(p + base + 8);
466     *p16 = htons(M68K_NOP);
467     FlushCodeCache(p + base + 8, 2);
468     D(bug(" patch 1 applied\n"));
469     }
470    
471 cebix 1.5 } else if (type == FOURCC('l','p','c','h') && id == 24) {
472 cebix 1.1 D(bug(" lpch 24 found\n"));
473    
474     // Don't replace Time Manager (7.0.1, 7.1, 7.5, 7.6, 7.6.1, 8.0)
475     static const uint8 dat[] = {0x70, 0x59, 0xa2, 0x47};
476     base = find_rsrc_data(p, size, dat, sizeof(dat));
477     if (base) {
478     p16 = (uint16 *)(p + base + 2);
479     *p16++ = htons(M68K_NOP);
480     p16 += 3;
481     *p16++ = htons(M68K_NOP);
482     p16 += 7;
483     *p16 = htons(M68K_NOP);
484     FlushCodeCache(p + base + 2, 28);
485     D(bug(" patch 1 applied\n"));
486     }
487    
488 cebix 1.5 } else if (type == FOURCC('l','p','c','h') && id == 31) {
489 cebix 1.1 D(bug(" lpch 31 found\n"));
490    
491     // Don't write to VIA in vSoundDead() (7.0.1, 7.1, 7.5, 7.6, 7.6.1, 8.0)
492     static const uint8 dat[] = {0x20, 0x78, 0x01, 0xd4, 0x08, 0xd0, 0x00, 0x07, 0x4e, 0x75};
493     base = find_rsrc_data(p, size, dat, sizeof(dat));
494     if (base) {
495     p16 = (uint16 *)(p + base);
496     *p16 = htons(M68K_RTS);
497     FlushCodeCache(p + base, 2);
498     D(bug(" patch 1 applied\n"));
499     }
500    
501     // Don't replace SCSI manager (7.1, 7.5, 7.6.1, 8.0)
502     static const uint8 dat2[] = {0x0c, 0x6f, 0x00, 0x0e, 0x00, 0x04, 0x66, 0x0c};
503     base = find_rsrc_data(p, size, dat2, sizeof(dat2));
504     if (base) {
505     p16 = (uint16 *)(p + base);
506     *p16++ = htons(M68K_EMUL_OP_SCSI_DISPATCH);
507     *p16++ = htons(0x2e49); // move.l a1,a7
508     *p16 = htons(M68K_JMP_A0);
509     FlushCodeCache(p + base, 6);
510     D(bug(" patch 2 applied\n"));
511     }
512    
513     #if !EMULATED_68K
514 cebix 1.5 } else if (CPUIs68060 && type == FOURCC('s','c','o','d') && (id == -16463 || id == -16464)) {
515 cebix 1.1 D(bug(" scod -16463/-16464 found\n"));
516    
517     // Correct 68060 FP frame handling in Process Manager task switches (7.1, 7.5, 8.0)
518     static const uint8 dat[] = {0xf3, 0x27, 0x4a, 0x17};
519     base = find_rsrc_data(p, size, dat, sizeof(dat));
520     if (base) {
521     p16 = (uint16 *)(p + base);
522     *p16++ = htons(M68K_JMP);
523     *p16++ = htons((uint32)Scod060Patch1 >> 16);
524     *p16 = htons((uint32)Scod060Patch1 & 0xffff);
525     FlushCodeCache(p + base, 6);
526     D(bug(" patch 1 applied\n"));
527     }
528    
529     // Even a null FP frame is 3 longwords on the 68060 (7.1, 7.5, 8.0)
530     static const uint8 dat2[] = {0xf3, 0x5f, 0x4e, 0x75};
531     base = find_rsrc_data(p, size, dat2, sizeof(dat2));
532     if (base) {
533     p16 = (uint16 *)(p + base - 2);
534     *p16++ = htons(M68K_JMP);
535     *p16++ = htons((uint32)Scod060Patch2 >> 16);
536     *p16 = htons((uint32)Scod060Patch2 & 0xffff);
537     FlushCodeCache(p + base - 2, 6);
538     D(bug(" patch 2 applied\n"));
539     }
540     #endif
541    
542 cebix 1.5 } else if (type == FOURCC('t','h','n','g') && id == -16563) {
543 cebix 1.1 D(bug(" thng -16563 found\n"));
544    
545     // Set audio component flags (7.5, 7.6, 7.6.1, 8.0)
546     *(uint32 *)(p + componentFlags) = htonl(audio_component_flags);
547     D(bug(" patch 1 applied\n"));
548    
549 cebix 1.5 } else if (type == FOURCC('s','i','f','t') && id == -16563) {
550 cebix 1.1 D(bug(" sift -16563 found\n"));
551    
552     // Replace audio component (7.5, 7.6, 7.6.1, 8.0)
553     p16 = (uint16 *)p;
554     *p16++ = htons(0x4e56); *p16++ = htons(0x0000); // link a6,#0
555     *p16++ = htons(0x48e7); *p16++ = htons(0x8018); // movem.l d0/a3-a4,-(sp)
556     *p16++ = htons(0x266e); *p16++ = htons(0x000c); // movea.l 12(a6),a3
557     *p16++ = htons(0x286e); *p16++ = htons(0x0008); // movea.l 8(a6),a4
558     *p16++ = htons(M68K_EMUL_OP_AUDIO);
559     *p16++ = htons(0x2d40); *p16++ = htons(0x0010); // move.l d0,16(a6)
560     *p16++ = htons(0x4cdf); *p16++ = htons(0x1801); // movem.l (sp)+,d0/a3-a4
561     *p16++ = htons(0x4e5e); // unlk a6
562     *p16++ = htons(0x4e74); *p16++ = htons(0x0008); // rtd #8
563     FlushCodeCache(p, 32);
564     D(bug(" patch 1 applied\n"));
565    
566 cebix 1.5 } else if (type == FOURCC('i','n','s','t') && id == -19069) {
567 cebix 1.1 D(bug(" inst -19069 found\n"));
568    
569     // Don't replace Microseconds (QuickTime 2.0)
570     static const uint8 dat[] = {0x30, 0x3c, 0xa1, 0x93, 0xa2, 0x47};
571     base = find_rsrc_data(p, size, dat, sizeof(dat));
572     if (base) {
573     p16 = (uint16 *)(p + base + 4);
574     *p16 = htons(M68K_NOP);
575     FlushCodeCache(p + base + 4, 2);
576     D(bug(" patch 1 applied\n"));
577     }
578    
579 cebix 1.5 } else if (type == FOURCC('D','R','V','R') && id == -20066) {
580 cebix 1.1 D(bug("DRVR -20066 found\n"));
581    
582     // Don't access SCC in .Infra driver
583     static const uint8 dat[] = {0x28, 0x78, 0x01, 0xd8, 0x48, 0xc7, 0x20, 0x0c, 0xd0, 0x87, 0x20, 0x40, 0x1c, 0x10};
584     base = find_rsrc_data(p, size, dat, sizeof(dat));
585     if (base) {
586     p16 = (uint16 *)(p + base + 12);
587     *p16 = htons(0x7a00); // moveq #0,d6
588     FlushCodeCache(p + base + 12, 2);
589     D(bug(" patch 1 applied\n"));
590     }
591    
592 cebix 1.5 } else if (type == FOURCC('l','t','l','k') && id == 0) {
593 cebix 1.1 D(bug(" ltlk 0 found\n"));
594    
595     // Disable LocalTalk (7.0.1, 7.5, 7.6, 7.6.1, 8.0)
596     p16 = (uint16 *)p;
597     *p16++ = htons(M68K_JMP_A0);
598     *p16++ = htons(0x7000);
599     *p16 = htons(M68K_RTS);
600     FlushCodeCache(p, 6);
601     D(bug(" patch 1 applied\n"));
602     }
603     }