1 |
|
/* |
2 |
|
* rsrc_patches.cpp - Resource patches |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2005 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 |
31 |
|
#include "rom_patches.h" |
32 |
|
#include "main.h" |
33 |
|
#include "audio.h" |
34 |
+ |
#include "audio_defs.h" |
35 |
+ |
#include "thunks.h" |
36 |
|
|
37 |
|
#define DEBUG 0 |
38 |
|
#include "debug.h" |
117 |
|
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)); |
118 |
|
|
119 |
|
// Don't modify resources in ROM |
120 |
< |
if ((uintptr)p >= ROM_BASE && (uintptr)p <= (ROM_BASE + ROM_SIZE)) |
120 |
> |
if ((uintptr)p >= (uintptr)ROMBaseHost && (uintptr)p <= (uintptr)(ROMBaseHost + ROM_SIZE)) |
121 |
|
return; |
122 |
|
|
123 |
|
if (type == FOURCC('b','o','o','t') && id == 3) { |
136 |
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (7.6, 7.6.1, 8.0, 8.1) |
137 |
|
p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH); |
138 |
|
D(bug(" patch 3 applied\n")); |
139 |
< |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff)) { |
139 |
> |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff) && PM(8,0x245f)) { |
140 |
|
// Check when ntrb 17 is installed (for native Resource Manager patch) (8.5, 8.6) |
141 |
|
p[8] = htons(M68K_EMUL_OP_NTRB_17_PATCH); |
142 |
|
D(bug(" patch 4 applied\n")); |
143 |
+ |
} else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff) && PM(7,0x301f)) { |
144 |
+ |
// Check when ntrb 17 is installed (for native Resource Manager patch) (9.0) |
145 |
+ |
p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH4); |
146 |
+ |
p[8] = htons(ntohs(p[8]) & 0xf0ff); // bra |
147 |
+ |
D(bug(" patch 8 applied\n")); |
148 |
|
} else if (PM(0,0x0c39) && PM(1,0x0001) && PM(2,0xf800) && PM(3,0x0008) && PM(4,0x6f00)) { |
149 |
|
// Don't read from 0xf8000008 (8.5 with Zanzibar ROM, 8.6) |
150 |
|
p[0] = htons(M68K_NOP); |
168 |
|
p[5] = htons(0x6010); // bra |
169 |
|
D(bug(" patch 7 applied\n")); |
170 |
|
} |
171 |
+ |
} else if (PM(0,0x2f3c) && PM(1,0x7665) && PM(2,0x7273) && PM(3,0x3f3c) && PM(4,0x0001) && PM(10,0x2041) && PM(11,0x2248) && PM(12,0x2050) && PM(20,0x7066) && PM(21,0xa9c9)) { |
172 |
+ |
// Check when vers 1 is installed (for safe abort if MacOS < 8.1 is used with a NewWorld ROM) |
173 |
+ |
p[10] = htons(M68K_EMUL_OP_CHECK_SYSV); |
174 |
+ |
p[11] = htons(0x4a81); // tst.l d1 |
175 |
+ |
p[12] = htons(0x670e); // beq.s <SysError #dsOldSystem> |
176 |
+ |
D(bug(" patch 9 applied\n")); |
177 |
|
} |
178 |
|
p++; |
179 |
|
} |
190 |
|
D(bug(" patch 1 applied\n")); |
191 |
|
} |
192 |
|
|
193 |
+ |
} else if (type == FOURCC('p','t','c','h') && id == 156) { |
194 |
+ |
D(bug("ptch 156 found\n")); |
195 |
+ |
size >>= 1; |
196 |
+ |
while (size--) { |
197 |
+ |
if (PM(0,0x4e56) && PM(1,0xfffa) && PM(2,0x48e7) && PM(3,0x1f18) && PM(4,0x7800) && PM(5,0x267c) && PM(6,0x6900) && PM(7,0x0000)) { |
198 |
+ |
// Don't call FE0A opcode (9.0) |
199 |
+ |
p[0] = htons(0x7000); // moveq #0,d0 |
200 |
+ |
p[1] = htons(M68K_RTS); |
201 |
+ |
D(bug(" patch 1 applied\n")); |
202 |
+ |
break; |
203 |
+ |
} |
204 |
+ |
p++; |
205 |
+ |
} |
206 |
+ |
|
207 |
|
} else if (type == FOURCC('p','t','c','h') && id == 420) { |
208 |
|
D(bug("ptch 420 found\n")); |
209 |
|
size >>= 1; |
457 |
|
p[(0x378 + 0x6c0) >> 1] = htons(0x4e80); // blr |
458 |
|
p[(0x37a + 0x6c0) >> 1] = htons(0x0020); |
459 |
|
D(bug(" patch 2 applied\n")); |
460 |
+ |
} else if (p[(0x374 + 0x510) >> 1] == htons(0x7c08) && p[(0x376 + 0x510) >> 1] == htons(0x02a6)) { |
461 |
+ |
// Don't overwrite our serial drivers (9.0) |
462 |
+ |
p[(0x374 + 0x510) >> 1] = htons(0x4e80); // blr |
463 |
+ |
p[(0x376 + 0x510) >> 1] = htons(0x0020); |
464 |
+ |
D(bug(" patch 3 applied\n")); |
465 |
|
} |
466 |
|
|
467 |
|
} else if (type == FOURCC('c','i','t','t') && id == 45) { |
479 |
|
|
480 |
|
} else if (type == FOURCC('t','h','n','g')) { |
481 |
|
// Collect info about used audio sifters |
482 |
< |
uint32 c_type = ntohl(0[(uint32 *)p]); |
483 |
< |
uint32 sub_type = ntohl(1[(uint32 *)p]); |
482 |
> |
uint32 thing = Host2MacAddr((uint8 *)p); |
483 |
> |
uint32 c_type = ReadMacInt32(thing); |
484 |
> |
uint32 sub_type = ReadMacInt32(thing + 4); |
485 |
|
if (c_type == FOURCC('s','d','e','v') && sub_type == FOURCC('s','i','n','g')) { |
486 |
< |
1[(uint32 *)p] = htonl(FOURCC('a','w','g','c')); |
486 |
> |
WriteMacInt32(thing + 4, FOURCC('a','w','g','c')); |
487 |
|
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)); |
488 |
< |
AddSifter(ReadMacInt32(((uintptr)p)+20), ntohs(p[12])); |
489 |
< |
if (ntohs(p[28])) // componentPFCount |
490 |
< |
AddSifter(ReadMacInt32(((uintptr)p)+62), ntohs(p[33])); |
488 |
> |
AddSifter(ReadMacInt32(thing + componentResType), ReadMacInt16(thing + componentResID)); |
489 |
> |
if (ReadMacInt32(thing + componentPFCount)) |
490 |
> |
AddSifter(ReadMacInt32(thing + componentPFResType), ReadMacInt16(thing + componentPFResID)); |
491 |
|
} |
492 |
|
|
493 |
|
} else if (type == FOURCC('s','i','f','t') || type == FOURCC('n','i','f','t')) { |
537 |
|
p16[1] = htons(M68K_RTS); |
538 |
|
D(bug(" patch 1 applied\n")); |
539 |
|
} |
540 |
+ |
|
541 |
+ |
} else if (type == FOURCC('N','O','b','j') && id == 100) { |
542 |
+ |
D(bug("NObj 100 found\n")); |
543 |
+ |
|
544 |
+ |
// Don't access VIA registers in MacBench 5.0 |
545 |
+ |
static const uint8 dat1[] = {0x7c, 0x08, 0x02, 0xa6, 0xbf, 0x01, 0xff, 0xe0, 0x90, 0x01, 0x00, 0x08}; |
546 |
+ |
base = find_rsrc_data((uint8 *)p, size, dat1, sizeof(dat1)); |
547 |
+ |
if (base) { |
548 |
+ |
p[(base + 0x00) >> 1] = htons(0x3860); // li r3,0 |
549 |
+ |
p[(base + 0x02) >> 1] = htons(0x0000); |
550 |
+ |
p[(base + 0x04) >> 1] = htons(0x4e80); // blr |
551 |
+ |
p[(base + 0x06) >> 1] = htons(0x0020); |
552 |
+ |
D(bug(" patch 1 applied\n")); |
553 |
+ |
} |
554 |
+ |
static const uint8 dat2[] = {0x7c, 0x6c, 0x1b, 0x78, 0x7c, 0x8b, 0x23, 0x78, 0x38, 0xc0, 0x3f, 0xfd}; |
555 |
+ |
base = find_rsrc_data((uint8 *)p, size, dat2, sizeof(dat2)); |
556 |
+ |
if (base) { |
557 |
+ |
p[(base + 0x00) >> 1] = htons(0x3860); // li r3,0 |
558 |
+ |
p[(base + 0x02) >> 1] = htons(0x0000); |
559 |
+ |
p[(base + 0x04) >> 1] = htons(0x4e80); // blr |
560 |
+ |
p[(base + 0x06) >> 1] = htons(0x0020); |
561 |
+ |
D(bug(" patch 2 applied\n")); |
562 |
+ |
} |
563 |
+ |
|
564 |
+ |
} else if (type == FOURCC('C','O','D','E') && id == 27 && size == 25024) { |
565 |
+ |
D(bug("CODE 27 found [Apple Personal Diagnostics]\n")); |
566 |
+ |
|
567 |
+ |
// Don't access FCBs directly in Apple Personal Diagnostics (MacOS 9) |
568 |
+ |
// FIXME: this should not be called in the first place, use UTResolveFCB? |
569 |
+ |
static const uint8 dat[] = {0x2d, 0x78, 0x03, 0x4e, 0xff, 0xf8, 0x20, 0x6e, 0xff, 0xf8}; |
570 |
+ |
base = find_rsrc_data((uint8 *)p, size, dat, sizeof(dat)); |
571 |
+ |
if (base |
572 |
+ |
&& ReadMacInt16(0x3f6) == 4 /* FSFCBLen */ |
573 |
+ |
&& p[(base + 0x1a) >> 1] == htons(0x605e) |
574 |
+ |
&& p[(base + 0x80) >> 1] == htons(0x7000)) |
575 |
+ |
{ |
576 |
+ |
p[(base + 0x1a) >> 1] = htons(0x6064); |
577 |
+ |
D(bug(" patch1 applied\n")); |
578 |
+ |
} |
579 |
|
} |
580 |
|
} |
581 |
|
|
598 |
|
return; |
599 |
|
uint32 size = ReadMacInt32(p - 2 * 4) & 0xffffff; |
600 |
|
|
601 |
< |
CheckLoad(type, id, (uint16 *)p, size); |
601 |
> |
CheckLoad(type, id, (uint16 *)Mac2HostAddr(p), size); |
602 |
|
} |
603 |
|
|
604 |
|
#ifdef __BEOS__ |
783 |
|
uint32 upp = ReadMacInt32(0x1480); |
784 |
|
if ((upp & 0xffc00000) == ROM_BASE) |
785 |
|
return; |
786 |
< |
uint32 *tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
787 |
< |
D(bug(" GetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
788 |
< |
*(uint32 *)XLM_RES_LIB_TOC = tvec[1]; |
789 |
< |
*(uint32 *)XLM_GET_RESOURCE = tvec[0]; |
786 |
> |
uint32 tvec = ReadMacInt32(upp + 5 * 4); |
787 |
> |
D(bug(" GetResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4))); |
788 |
> |
WriteMacInt32(XLM_RES_LIB_TOC, ReadMacInt32(tvec + 4)); |
789 |
> |
WriteMacInt32(XLM_GET_RESOURCE, ReadMacInt32(tvec)); |
790 |
|
#if EMULATED_PPC |
791 |
< |
tvec[0] = htonl(POWERPC_NATIVE_OP_FUNC(NATIVE_GET_RESOURCE)); |
791 |
> |
WriteMacInt32(tvec, NativeFunction(NATIVE_GET_RESOURCE)); |
792 |
|
#else |
793 |
|
#ifdef __BEOS__ |
794 |
|
uint32 *tvec2 = (uint32 *)get_resource; |
795 |
< |
tvec[0] = tvec2[0]; |
796 |
< |
tvec[1] = tvec2[1]; |
795 |
> |
WriteMacInt32(tvec, tvec2[0]); |
796 |
> |
WriteMacInt32(tvec + 4, tvec2[1]); |
797 |
|
#else |
798 |
< |
tvec[0] = (uint32)get_resource; |
798 |
> |
WriteMacInt32(tvec, (uint32)get_resource); |
799 |
|
#endif |
800 |
|
#endif |
801 |
|
|
802 |
|
// Patch native Get1Resource() |
803 |
|
upp = ReadMacInt32(0x0e7c); |
804 |
< |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
805 |
< |
D(bug(" Get1Resource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
806 |
< |
*(uint32 *)XLM_GET_1_RESOURCE = tvec[0]; |
804 |
> |
tvec = ReadMacInt32(upp + 5 * 4); |
805 |
> |
D(bug(" Get1Resource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4))); |
806 |
> |
WriteMacInt32(XLM_GET_1_RESOURCE, ReadMacInt32(tvec)); |
807 |
|
#if EMULATED_PPC |
808 |
< |
tvec[0] = htonl(POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_RESOURCE)); |
808 |
> |
WriteMacInt32(tvec, NativeFunction(NATIVE_GET_1_RESOURCE)); |
809 |
|
#else |
810 |
|
#ifdef __BEOS__ |
811 |
|
tvec2 = (uint32 *)get_1_resource; |
812 |
< |
tvec[0] = tvec2[0]; |
813 |
< |
tvec[1] = tvec2[1]; |
812 |
> |
WriteMacInt32(tvec, tvec2[0]); |
813 |
> |
WriteMacInt32(tvec + 4, tvec2[1]); |
814 |
|
#else |
815 |
< |
tvec[0] = (uint32)get_1_resource; |
815 |
> |
WriteMacInt32(tvec, (uint32)get_1_resource); |
816 |
|
#endif |
817 |
|
#endif |
818 |
|
|
819 |
|
// Patch native GetIndResource() |
820 |
|
upp = ReadMacInt32(0x1474); |
821 |
< |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
822 |
< |
D(bug(" GetIndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
823 |
< |
*(uint32 *)XLM_GET_IND_RESOURCE = tvec[0]; |
821 |
> |
tvec = ReadMacInt32(upp + 5 * 4); |
822 |
> |
D(bug(" GetIndResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4))); |
823 |
> |
WriteMacInt32(XLM_GET_IND_RESOURCE, ReadMacInt32(tvec)); |
824 |
|
#if EMULATED_PPC |
825 |
< |
tvec[0] = htonl(POWERPC_NATIVE_OP_FUNC(NATIVE_GET_IND_RESOURCE)); |
825 |
> |
WriteMacInt32(tvec, NativeFunction(NATIVE_GET_IND_RESOURCE)); |
826 |
|
#else |
827 |
|
#ifdef __BEOS__ |
828 |
|
tvec2 = (uint32 *)get_ind_resource; |
829 |
< |
tvec[0] = tvec2[0]; |
830 |
< |
tvec[1] = tvec2[1]; |
829 |
> |
WriteMacInt32(tvec, tvec2[0]); |
830 |
> |
WriteMacInt32(tvec + 4, tvec2[1]); |
831 |
|
#else |
832 |
< |
tvec[0] = (uint32)get_ind_resource; |
832 |
> |
WriteMacInt32(tvec, (uint32)get_ind_resource); |
833 |
|
#endif |
834 |
|
#endif |
835 |
|
|
836 |
|
// Patch native Get1IndResource() |
837 |
|
upp = ReadMacInt32(0x0e38); |
838 |
< |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
839 |
< |
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
840 |
< |
*(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0]; |
838 |
> |
tvec = ReadMacInt32(upp + 5 * 4); |
839 |
> |
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4))); |
840 |
> |
WriteMacInt32(XLM_GET_1_IND_RESOURCE, ReadMacInt32(tvec)); |
841 |
|
#if EMULATED_PPC |
842 |
< |
tvec[0] = htonl(POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_IND_RESOURCE)); |
842 |
> |
WriteMacInt32(tvec, NativeFunction(NATIVE_GET_1_IND_RESOURCE)); |
843 |
|
#else |
844 |
|
#ifdef __BEOS__ |
845 |
|
tvec2 = (uint32 *)get_1_ind_resource; |
846 |
< |
tvec[0] = tvec2[0]; |
847 |
< |
tvec[1] = tvec2[1]; |
846 |
> |
WriteMacInt32(tvec, tvec2[0]); |
847 |
> |
WriteMacInt32(tvec + 4, tvec2[1]); |
848 |
|
#else |
849 |
< |
tvec[0] = (uint32)get_1_ind_resource; |
849 |
> |
WriteMacInt32(tvec, (uint32)get_1_ind_resource); |
850 |
|
#endif |
851 |
|
#endif |
852 |
|
|
853 |
|
// Patch native RGetResource() |
854 |
|
upp = ReadMacInt32(0x0e30); |
855 |
< |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
856 |
< |
D(bug(" RGetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
857 |
< |
*(uint32 *)XLM_R_GET_RESOURCE = tvec[0]; |
855 |
> |
tvec = ReadMacInt32(upp + 5 * 4); |
856 |
> |
D(bug(" RGetResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4))); |
857 |
> |
WriteMacInt32(XLM_R_GET_RESOURCE, ReadMacInt32(tvec)); |
858 |
|
#if EMULATED_PPC |
859 |
< |
tvec[0] = htonl(POWERPC_NATIVE_OP_FUNC(NATIVE_R_GET_RESOURCE)); |
859 |
> |
WriteMacInt32(tvec, NativeFunction(NATIVE_R_GET_RESOURCE)); |
860 |
|
#else |
861 |
|
#ifdef __BEOS__ |
862 |
|
tvec2 = (uint32 *)r_get_resource; |
863 |
< |
tvec[0] = tvec2[0]; |
864 |
< |
tvec[1] = tvec2[1]; |
863 |
> |
WriteMacInt32(tvec, tvec2[0]); |
864 |
> |
WriteMacInt32(tvec + 4, tvec2[1]); |
865 |
|
#else |
866 |
< |
tvec[0] = (uint32)r_get_resource; |
866 |
> |
WriteMacInt32(tvec, (uint32)r_get_resource); |
867 |
|
#endif |
868 |
|
#endif |
869 |
|
} |