From 738fa25344a607e5bb6894fc2293e2d688847fd5 Mon Sep 17 00:00:00 2001 From: cebix <> Date: Fri, 29 Jun 2001 12:51:21 +0000 Subject: [PATCH] slot ROM checksum is recalculated after patching during resolution switch --- BasiliskII/src/include/slot_rom.h | 1 + BasiliskII/src/slot_rom.cpp | 45 ++++++++++++++++++++++--------- BasiliskII/src/video.cpp | 6 ++++- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/BasiliskII/src/include/slot_rom.h b/BasiliskII/src/include/slot_rom.h index ed9c5669..c7f65859 100644 --- a/BasiliskII/src/include/slot_rom.h +++ b/BasiliskII/src/include/slot_rom.h @@ -22,5 +22,6 @@ #define SLOT_ROM_H extern bool InstallSlotROM(void); +extern void ChecksumSlotROM(void); #endif diff --git a/BasiliskII/src/slot_rom.cpp b/BasiliskII/src/slot_rom.cpp index 5419d134..15625a66 100644 --- a/BasiliskII/src/slot_rom.cpp +++ b/BasiliskII/src/slot_rom.cpp @@ -42,6 +42,9 @@ static uint8 srom[4096]; // Index in srom static uint32 p; +// Length of slot ROM +static int slot_rom_size = 0; + // Check whether a mode with the specified depth exists static bool has_depth(video_depth depth) @@ -433,23 +436,39 @@ bool InstallSlotROM(void) // Format/header block Offs(0, sRsrcDir); // sResource directory Long(p + 16); // Length of declaration data - Long(0); // CRC (calculated below) + Long(0); // CRC (calculated later) Word(0x0101); // Rev. level, format Long(0x5a932bc7); // Test pattern Word(0x000f); // Byte lanes - // Calculate CRC - uint32 crc = 0; - for (uint32 i=0; i> 31); - crc += srom[i]; - } - srom[p - 12] = crc >> 24; - srom[p - 11] = crc >> 16; - srom[p - 10] = crc >> 8; - srom[p - 9] = crc; - // Copy slot ROM to Mac ROM - memcpy(ROMBaseHost + ROMSize - p, srom, p); + slot_rom_size = p; + memcpy(ROMBaseHost + ROMSize - slot_rom_size, srom, slot_rom_size); + + // Calculate checksum + ChecksumSlotROM(); return true; } + +/* + * Calculate slot ROM checksum (in-place) + */ + +void ChecksumSlotROM(void) +{ + // Calculate CRC + uint8 *p = ROMBaseHost + ROMSize - slot_rom_size; + p[slot_rom_size - 12] = 0; + p[slot_rom_size - 11] = 0; + p[slot_rom_size - 10] = 0; + p[slot_rom_size - 9] = 0; + uint32 crc = 0; + for (uint32 i=0; i> 31); + crc += p[i]; + } + p[slot_rom_size - 12] = crc >> 24; + p[slot_rom_size - 11] = crc >> 16; + p[slot_rom_size - 10] = crc >> 8; + p[slot_rom_size - 9] = crc; +} diff --git a/BasiliskII/src/video.cpp b/BasiliskII/src/video.cpp index c45a4b1c..f906bfde 100644 --- a/BasiliskII/src/video.cpp +++ b/BasiliskII/src/video.cpp @@ -31,6 +31,7 @@ #include "cpu_emulation.h" #include "main.h" #include "macos_util.h" +#include "slot_rom.h" #include "video.h" #include "video_defs.h" @@ -349,7 +350,7 @@ int16 VideoDriverControl(uint32 pb, uint32 dce) Execute68kTrap(0xa06e, &r); // SRsrcInfo() uint32 rsrc = ReadMacInt32(sp + spPointer); - // Patch minorBase + // Patch minorBase (otherwise rebooting won't work) WriteMacInt8(sp + spID, 0x0a); // minorBase r.d[0] = 0x0006; Execute68kTrap(0xa06e, &r); // SFindStruct() @@ -375,6 +376,9 @@ int16 VideoDriverControl(uint32 pb, uint32 dce) ROMBaseHost[p + 16] = i->x >> 8; ROMBaseHost[p + 17] = i->x; + // Recalculate slot ROM checksum + ChecksumSlotROM(); + // Update sResource WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId)); r.d[0] = 0x002b;