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" |
422 |
|
|
423 |
|
} else if (type == FOURCC('n','s','r','d') && id == 1) { |
424 |
|
D(bug("nsrd 1 found\n")); |
425 |
< |
if (p[(0x378 + 0x570) >> 1] == 0x7c08 && p[(0x37a + 0x570) >> 1] == 0x02a6) { |
425 |
> |
if (p[(0x378 + 0x570) >> 1] == htons(0x7c08) && p[(0x37a + 0x570) >> 1] == htons(0x02a6)) { |
426 |
|
// Don't overwrite our serial drivers (8.0, 8.1) |
427 |
< |
p[(0x378 + 0x570) >> 1] = 0x4e80; // blr |
428 |
< |
p[(0x37a + 0x570) >> 1] = 0x0020; |
427 |
> |
p[(0x378 + 0x570) >> 1] = htons(0x4e80); // blr |
428 |
> |
p[(0x37a + 0x570) >> 1] = htons(0x0020); |
429 |
|
D(bug(" patch 1 applied\n")); |
430 |
< |
} else if (p[(0x378 + 0x6c0) >> 1] == 0x7c08 && p[(0x37a + 0x6c0) >> 1] == 0x02a6) { |
430 |
> |
} else if (p[(0x378 + 0x6c0) >> 1] == htons(0x7c08) && p[(0x37a + 0x6c0) >> 1] == htons(0x02a6)) { |
431 |
|
// Don't overwrite our serial drivers (8.5, 8.6) |
432 |
< |
p[(0x378 + 0x6c0) >> 1] = 0x4e80; // blr |
433 |
< |
p[(0x37a + 0x6c0) >> 1] = 0x0020; |
432 |
> |
p[(0x378 + 0x6c0) >> 1] = htons(0x4e80); // blr |
433 |
> |
p[(0x37a + 0x6c0) >> 1] = htons(0x0020); |
434 |
|
D(bug(" patch 2 applied\n")); |
435 |
|
} |
436 |
|
|
440 |
|
while (size--) { |
441 |
|
if (PM(0,0x203c) && PM(1,0x0100) && PM(2,0x0000) && PM(3,0xc0ae) && PM(4,0xfffc)) { |
442 |
|
// Don't replace SCSI Manager (8.1, 8.5, 8.6) |
443 |
< |
p[5] = htons((p[5] & 0xff) | 0x6000); // beq |
443 |
> |
p[5] = htons((ntohs(p[5]) & 0xff) | 0x6000); // beq |
444 |
|
D(bug(" patch 1 applied\n")); |
445 |
|
break; |
446 |
|
} |
449 |
|
|
450 |
|
} else if (type == FOURCC('t','h','n','g')) { |
451 |
|
// Collect info about used audio sifters |
452 |
< |
uint32 c_type = 0[(uint32 *)p]; |
453 |
< |
uint32 sub_type = 1[(uint32 *)p]; |
452 |
> |
uint32 thing = (uintptr)p; |
453 |
> |
uint32 c_type = ReadMacInt32(thing); |
454 |
> |
uint32 sub_type = ReadMacInt32(thing + 4); |
455 |
|
if (c_type == FOURCC('s','d','e','v') && sub_type == FOURCC('s','i','n','g')) { |
456 |
< |
1[(uint32 *)p] = FOURCC('a','w','g','c'); |
456 |
> |
WriteMacInt32(thing + 4, FOURCC('a','w','g','c')); |
457 |
|
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)); |
458 |
< |
AddSifter(*(uint32 *)(((uintptr)p)+20), p[12]); |
459 |
< |
if (p[28]) // componentPFCount |
460 |
< |
AddSifter(*(uint32 *)(((uintptr)p)+62), p[33]); |
458 |
> |
AddSifter(ReadMacInt32(thing + componentResType), ReadMacInt16(thing + componentResID)); |
459 |
> |
if (ReadMacInt32(thing + componentPFCount)) |
460 |
> |
AddSifter(ReadMacInt32(thing + componentPFResType), ReadMacInt16(thing + componentPFResID)); |
461 |
|
} |
462 |
|
|
463 |
|
} else if (type == FOURCC('s','i','f','t') || type == FOURCC('n','i','f','t')) { |
520 |
|
#else |
521 |
|
extern "C" |
522 |
|
#endif |
523 |
< |
void check_load_invoc(uint32 type, int16 id, uint16 **h) |
523 |
> |
void check_load_invoc(uint32 type, int16 id, uint32 h) |
524 |
|
{ |
525 |
< |
if (h == NULL) |
525 |
> |
if (h == 0) |
526 |
|
return; |
527 |
< |
uint16 *p = *h; |
528 |
< |
if (p == NULL) |
527 |
> |
uint32 p = ReadMacInt32(h); |
528 |
> |
if (p == 0) |
529 |
|
return; |
530 |
< |
uint32 size = ((uint32 *)p)[-2] & 0xffffff; |
530 |
> |
uint32 size = ReadMacInt32(p - 2 * 4) & 0xffffff; |
531 |
|
|
532 |
< |
CheckLoad(type, id, p, size); |
532 |
> |
CheckLoad(type, id, (uint16 *)p, size); |
533 |
|
} |
534 |
|
|
535 |
|
#ifdef __BEOS__ |
711 |
|
D(bug("PatchNativeResourceManager\n")); |
712 |
|
|
713 |
|
// Patch native GetResource() |
714 |
< |
uint32 **upp = (uint32 **)(uintptr)ReadMacInt32(0x1480); |
715 |
< |
if (((uint32)upp & 0xffc00000) == ROM_BASE) |
714 |
> |
uint32 upp = ReadMacInt32(0x1480); |
715 |
> |
if ((upp & 0xffc00000) == ROM_BASE) |
716 |
|
return; |
717 |
< |
uint32 *tvec = upp[5]; |
718 |
< |
D(bug(" GetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
717 |
> |
uint32 *tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
718 |
> |
D(bug(" GetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
719 |
|
*(uint32 *)XLM_RES_LIB_TOC = tvec[1]; |
720 |
|
*(uint32 *)XLM_GET_RESOURCE = tvec[0]; |
721 |
|
#if EMULATED_PPC |
722 |
< |
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_RESOURCE); |
722 |
> |
tvec[0] = htonl(NativeFunction(NATIVE_GET_RESOURCE)); |
723 |
|
#else |
724 |
|
#ifdef __BEOS__ |
725 |
|
uint32 *tvec2 = (uint32 *)get_resource; |
731 |
|
#endif |
732 |
|
|
733 |
|
// Patch native Get1Resource() |
734 |
< |
upp = *(uint32 ***)0xe7c; |
735 |
< |
tvec = upp[5]; |
736 |
< |
D(bug(" Get1Resource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
734 |
> |
upp = ReadMacInt32(0x0e7c); |
735 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
736 |
> |
D(bug(" Get1Resource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
737 |
|
*(uint32 *)XLM_GET_1_RESOURCE = tvec[0]; |
738 |
|
#if EMULATED_PPC |
739 |
< |
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_RESOURCE); |
739 |
> |
tvec[0] = htonl(NativeFunction(NATIVE_GET_1_RESOURCE)); |
740 |
|
#else |
741 |
|
#ifdef __BEOS__ |
742 |
|
tvec2 = (uint32 *)get_1_resource; |
748 |
|
#endif |
749 |
|
|
750 |
|
// Patch native GetIndResource() |
751 |
< |
upp = *(uint32 ***)0x1474; |
752 |
< |
tvec = upp[5]; |
753 |
< |
D(bug(" GetIndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
751 |
> |
upp = ReadMacInt32(0x1474); |
752 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
753 |
> |
D(bug(" GetIndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
754 |
|
*(uint32 *)XLM_GET_IND_RESOURCE = tvec[0]; |
755 |
|
#if EMULATED_PPC |
756 |
< |
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_IND_RESOURCE); |
756 |
> |
tvec[0] = htonl(NativeFunction(NATIVE_GET_IND_RESOURCE)); |
757 |
|
#else |
758 |
|
#ifdef __BEOS__ |
759 |
|
tvec2 = (uint32 *)get_ind_resource; |
765 |
|
#endif |
766 |
|
|
767 |
|
// Patch native Get1IndResource() |
768 |
< |
upp = *(uint32 ***)0xe38; |
769 |
< |
tvec = upp[5]; |
770 |
< |
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
768 |
> |
upp = ReadMacInt32(0x0e38); |
769 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
770 |
> |
D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
771 |
|
*(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0]; |
772 |
|
#if EMULATED_PPC |
773 |
< |
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_IND_RESOURCE); |
773 |
> |
tvec[0] = htonl(NativeFunction(NATIVE_GET_1_IND_RESOURCE)); |
774 |
|
#else |
775 |
|
#ifdef __BEOS__ |
776 |
|
tvec2 = (uint32 *)get_1_ind_resource; |
782 |
|
#endif |
783 |
|
|
784 |
|
// Patch native RGetResource() |
785 |
< |
upp = *(uint32 ***)0xe30; |
786 |
< |
tvec = upp[5]; |
787 |
< |
D(bug(" RGetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1])); |
785 |
> |
upp = ReadMacInt32(0x0e30); |
786 |
> |
tvec = (uint32 *)ReadMacInt32(upp + 5 * 4); |
787 |
> |
D(bug(" RGetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1]))); |
788 |
|
*(uint32 *)XLM_R_GET_RESOURCE = tvec[0]; |
789 |
|
#if EMULATED_PPC |
790 |
< |
tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_R_GET_RESOURCE); |
790 |
> |
tvec[0] = htonl(NativeFunction(NATIVE_R_GET_RESOURCE)); |
791 |
|
#else |
792 |
|
#ifdef __BEOS__ |
793 |
|
tvec2 = (uint32 *)r_get_resource; |