ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/rsrc_patches.cpp
(Generate patch)

Comparing SheepShaver/src/rsrc_patches.cpp (file contents):
Revision 1.4 by gbeauche, 2003-09-29T20:30:19Z vs.
Revision 1.10 by gbeauche, 2004-01-26T22:04:01Z

# Line 1 | Line 1
1   /*
2   *  rsrc_patches.cpp - Resource patches
3   *
4 < *  SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
4 > *  SheepShaver (C) 1997-2004 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
# Line 31 | Line 31
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"
# Line 420 | Line 422 | void CheckLoad(uint32 type, int16 id, ui
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  
# Line 438 | Line 440 | void CheckLoad(uint32 type, int16 id, ui
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                          }
# Line 447 | Line 449 | void CheckLoad(uint32 type, int16 id, ui
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')) {
# Line 504 | Line 507 | void CheckLoad(uint32 type, int16 id, ui
507                          p16[1] = htons(M68K_RTS);
508                          D(bug(" patch 1 applied\n"));
509                  }
510 +
511 +        } else if (type == FOURCC('N','O','b','j') && id == 100) {
512 +                D(bug("NObj 100 found\n"));
513 +
514 +                // Don't access VIA registers in MacBench 5.0
515 +                static const uint8 dat1[] = {0x7c, 0x08, 0x02, 0xa6, 0xbf, 0x01, 0xff, 0xe0, 0x90, 0x01, 0x00, 0x08};
516 +                base = find_rsrc_data((uint8 *)p, size, dat1, sizeof(dat1));
517 +                if (base) {
518 +                        p[(base + 0x00) >> 1] = htons(0x3860);          // li r3,0
519 +                        p[(base + 0x02) >> 1] = htons(0x0000);
520 +                        p[(base + 0x04) >> 1] = htons(0x4e80);          // blr
521 +                        p[(base + 0x06) >> 1] = htons(0x0020);
522 +                        D(bug(" patch 1 applied\n"));
523 +                }
524 +                static const uint8 dat2[] = {0x7c, 0x6c, 0x1b, 0x78, 0x7c, 0x8b, 0x23, 0x78, 0x38, 0xc0, 0x3f, 0xfd};
525 +                base = find_rsrc_data((uint8 *)p, size, dat2, sizeof(dat2));
526 +                if (base) {
527 +                        p[(base + 0x00) >> 1] = htons(0x3860);          // li r3,0
528 +                        p[(base + 0x02) >> 1] = htons(0x0000);
529 +                        p[(base + 0x04) >> 1] = htons(0x4e80);          // blr
530 +                        p[(base + 0x06) >> 1] = htons(0x0020);
531 +                        D(bug(" patch 2 applied\n"));
532 +                }
533          }
534   }
535  
# Line 517 | Line 543 | static
543   #else
544   extern "C"
545   #endif
546 < void check_load_invoc(uint32 type, int16 id, uint16 **h)
546 > void check_load_invoc(uint32 type, int16 id, uint32 h)
547   {
548 <        if (h == NULL)
548 >        if (h == 0)
549                  return;
550 <        uint16 *p = *h;
551 <        if (p == NULL)
550 >        uint32 p = ReadMacInt32(h);
551 >        if (p == 0)
552                  return;
553 <        uint32 size = ((uint32 *)p)[-2] & 0xffffff;
553 >        uint32 size = ReadMacInt32(p - 2 * 4) & 0xffffff;
554  
555 <        CheckLoad(type, id, p, size);
555 >        CheckLoad(type, id, (uint16 *)p, size);
556   }
557  
558   #ifdef __BEOS__
# Line 708 | Line 734 | void PatchNativeResourceManager(void)
734          D(bug("PatchNativeResourceManager\n"));
735  
736          // Patch native GetResource()
737 <        uint32 **upp = (uint32 **)(uintptr)ReadMacInt32(0x1480);
738 <        if (((uint32)upp & 0xffc00000) == ROM_BASE)
737 >        uint32 upp = ReadMacInt32(0x1480);
738 >        if ((upp & 0xffc00000) == ROM_BASE)
739                  return;
740 <        uint32 *tvec = upp[5];
741 <        D(bug(" GetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1]));
740 >        uint32 *tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
741 >        D(bug(" GetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
742          *(uint32 *)XLM_RES_LIB_TOC = tvec[1];
743          *(uint32 *)XLM_GET_RESOURCE = tvec[0];
744   #if EMULATED_PPC
745 <        tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_RESOURCE);
745 >        tvec[0] = htonl(NativeFunction(NATIVE_GET_RESOURCE));
746   #else
747   #ifdef __BEOS__
748          uint32 *tvec2 = (uint32 *)get_resource;
# Line 728 | Line 754 | void PatchNativeResourceManager(void)
754   #endif
755  
756          // Patch native Get1Resource()
757 <        upp = *(uint32 ***)0xe7c;
758 <        tvec = upp[5];
759 <        D(bug(" Get1Resource() entry %08x, TOC %08x\n", tvec[0], tvec[1]));
757 >        upp = ReadMacInt32(0x0e7c);
758 >        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
759 >        D(bug(" Get1Resource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
760          *(uint32 *)XLM_GET_1_RESOURCE = tvec[0];
761   #if EMULATED_PPC
762 <        tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_RESOURCE);
762 >        tvec[0] = htonl(NativeFunction(NATIVE_GET_1_RESOURCE));
763   #else
764   #ifdef __BEOS__
765          tvec2 = (uint32 *)get_1_resource;
# Line 745 | Line 771 | void PatchNativeResourceManager(void)
771   #endif
772  
773          // Patch native GetIndResource()
774 <        upp = *(uint32 ***)0x1474;
775 <        tvec = upp[5];
776 <        D(bug(" GetIndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1]));
774 >        upp = ReadMacInt32(0x1474);
775 >        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
776 >        D(bug(" GetIndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
777          *(uint32 *)XLM_GET_IND_RESOURCE = tvec[0];
778   #if EMULATED_PPC
779 <        tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_IND_RESOURCE);
779 >        tvec[0] = htonl(NativeFunction(NATIVE_GET_IND_RESOURCE));
780   #else
781   #ifdef __BEOS__
782          tvec2 = (uint32 *)get_ind_resource;
# Line 762 | Line 788 | void PatchNativeResourceManager(void)
788   #endif
789  
790          // Patch native Get1IndResource()
791 <        upp = *(uint32 ***)0xe38;
792 <        tvec = upp[5];
793 <        D(bug(" Get1IndResource() entry %08x, TOC %08x\n", tvec[0], tvec[1]));
791 >        upp = ReadMacInt32(0x0e38);
792 >        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
793 >        D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
794          *(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0];
795   #if EMULATED_PPC
796 <        tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_GET_1_IND_RESOURCE);
796 >        tvec[0] = htonl(NativeFunction(NATIVE_GET_1_IND_RESOURCE));
797   #else
798   #ifdef __BEOS__
799          tvec2 = (uint32 *)get_1_ind_resource;
# Line 779 | Line 805 | void PatchNativeResourceManager(void)
805   #endif
806  
807          // Patch native RGetResource()
808 <        upp = *(uint32 ***)0xe30;
809 <        tvec = upp[5];
810 <        D(bug(" RGetResource() entry %08x, TOC %08x\n", tvec[0], tvec[1]));
808 >        upp = ReadMacInt32(0x0e30);
809 >        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
810 >        D(bug(" RGetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
811          *(uint32 *)XLM_R_GET_RESOURCE = tvec[0];
812   #if EMULATED_PPC
813 <        tvec[0] = POWERPC_NATIVE_OP_FUNC(NATIVE_R_GET_RESOURCE);
813 >        tvec[0] = htonl(NativeFunction(NATIVE_R_GET_RESOURCE));
814   #else
815   #ifdef __BEOS__
816          tvec2 = (uint32 *)r_get_resource;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines