--- BasiliskII/src/slot_rom.cpp 2001/06/27 20:05:23 1.6 +++ BasiliskII/src/slot_rom.cpp 2001/06/29 12:51:20 1.9 @@ -42,11 +42,14 @@ 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) { - vector::const_iterator i = VideoModes.begin(), end = VideoModes.end(); + std::vector::const_iterator i = VideoModes.begin(), end = VideoModes.end(); while (i != end) { if (i->depth == depth) return true; @@ -118,58 +121,58 @@ static void PString(char *str) static uint32 VModeParms(uint32 width, uint32 height, uint32 bytes_per_row, video_depth depth) { uint32 ret = p; - Long(50); // Length - Long(0); // Base offset - Word(bytes_per_row); // Row bytes - Word(0); // Bounds + Long(50); // Length + Long(0); // Base offset + Word(bytes_per_row); // Row bytes + Word(0); // Bounds Word(0); Word(height); Word(width); - Word(0); // Version - Word(0); // Pack type - Long(0); // Pack size - Long(0x00480000); // HRes - Long(0x00480000); // VRes + Word(0); // Version + Word(0); // Pack type + Long(0); // Pack size + Long(0x00480000); // HRes + Long(0x00480000); // VRes switch (depth) { case VDEPTH_1BIT: - Word(0); // Pixel type (indirect) - Word(1); // Pixel size - Word(1); // CmpCount - Word(1); // CmpSize + Word(0); // Pixel type (indirect) + Word(1); // Pixel size + Word(1); // CmpCount + Word(1); // CmpSize break; case VDEPTH_2BIT: - Word(0); // Pixel type (indirect) - Word(2); // Pixel size - Word(1); // CmpCount - Word(2); // CmpSize + Word(0); // Pixel type (indirect) + Word(2); // Pixel size + Word(1); // CmpCount + Word(2); // CmpSize break; case VDEPTH_4BIT: - Word(0); // Pixel type (indirect) - Word(4); // Pixel size - Word(1); // CmpCount - Word(4); // CmpSize + Word(0); // Pixel type (indirect) + Word(4); // Pixel size + Word(1); // CmpCount + Word(4); // CmpSize break; case VDEPTH_8BIT: - Word(0); // Pixel type (indirect) - Word(8); // Pixel size - Word(1); // CmpCount - Word(8); // CmpSize + Word(0); // Pixel type (indirect) + Word(8); // Pixel size + Word(1); // CmpCount + Word(8); // CmpSize break; case VDEPTH_16BIT: - Word(16); // Pixel type (direct) - Word(16); // Pixel size - Word(3); // CmpCount - Word(5); // CmpSize + Word(16); // Pixel type (direct) + Word(16); // Pixel size + Word(3); // CmpCount + Word(5); // CmpSize break; case VDEPTH_32BIT: - Word(16); // Pixel type (direct) - Word(32); // Pixel size - Word(3); // CmpCount - Word(8); // CmpSize + Word(16); // Pixel type (direct) + Word(32); // Pixel size + Word(3); // CmpCount + Word(8); // CmpSize break; } - Long(0); // Plane size - Long(0); // Reserved + Long(0); // Plane size + Long(0); // Reserved return ret; } @@ -233,13 +236,13 @@ bool InstallSlotROM(void) // Video sResource for default mode videoType = p; // Literals - Word(3); Word(1); Word(1); Word(0x4232); // Display Video Apple 'B2' + Word(3); Word(1); Word(1); Word(0x4232); // Display Video Apple 'B2' videoName = p; String("Display_Video_Apple_Basilisk"); minorBase = p; - Long(VideoMonitor.mac_frame_base); // Frame buffer base + Long(VideoMonitor.mac_frame_base); // Frame buffer base minorLength = p; - Long(VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); // Frame buffer size + Long(0); // Frame buffer size (unspecified) videoDrvr = p; // Video driver Long(0x72); // Length @@ -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 + // Copy slot ROM to Mac ROM + 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 += srom[i]; + crc += p[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); - return true; + 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; }