--- BasiliskII/src/slot_rom.cpp 2001/06/27 20:05:23 1.6 +++ BasiliskII/src/slot_rom.cpp 2002/01/15 14:58:32 1.13 @@ -1,7 +1,7 @@ /* * slot_rom.cpp - Slot declaration ROM * - * Basilisk II (C) 1996-2001 Christian Bauer + * Basilisk II (C) 1997-2002 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,18 +42,8 @@ static uint8 srom[4096]; // Index in srom static uint32 p; - -// 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(); - while (i != end) { - if (i->depth == depth) - return true; - ++i; - } - return false; -} +// Length of slot ROM +static int slot_rom_size = 0; /* @@ -115,61 +105,61 @@ static void PString(char *str) srom[p++] = 0; } -static uint32 VModeParms(uint32 width, uint32 height, uint32 bytes_per_row, video_depth depth) +static uint32 VModeParms(const video_mode &mode, 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(video_bytes_per_row(depth, mode.resolution_id)); + 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(mode.y); + Word(mode.x); + 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 +223,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 @@ -312,12 +302,12 @@ bool InstallSlotROM(void) Offs(0x80, defaultGamma); EndOfList(); - vidModeParms1 = VModeParms(VideoMonitor.mode.x, VideoMonitor.mode.y, VideoMonitor.mode.bytes_per_row, VDEPTH_1BIT); - vidModeParms2 = VModeParms(VideoMonitor.mode.x, VideoMonitor.mode.y, VideoMonitor.mode.bytes_per_row, VDEPTH_2BIT); - vidModeParms4 = VModeParms(VideoMonitor.mode.x, VideoMonitor.mode.y, VideoMonitor.mode.bytes_per_row, VDEPTH_4BIT); - vidModeParms8 = VModeParms(VideoMonitor.mode.x, VideoMonitor.mode.y, VideoMonitor.mode.bytes_per_row, VDEPTH_8BIT); - vidModeParms16 = VModeParms(VideoMonitor.mode.x, VideoMonitor.mode.y, VideoMonitor.mode.bytes_per_row, VDEPTH_16BIT); - vidModeParms32 = VModeParms(VideoMonitor.mode.x, VideoMonitor.mode.y, VideoMonitor.mode.bytes_per_row, VDEPTH_32BIT); + vidModeParms1 = VModeParms(VideoMonitor.mode, VDEPTH_1BIT); + vidModeParms2 = VModeParms(VideoMonitor.mode, VDEPTH_2BIT); + vidModeParms4 = VModeParms(VideoMonitor.mode, VDEPTH_4BIT); + vidModeParms8 = VModeParms(VideoMonitor.mode, VDEPTH_8BIT); + vidModeParms16 = VModeParms(VideoMonitor.mode, VDEPTH_16BIT); + vidModeParms32 = VModeParms(VideoMonitor.mode, VDEPTH_32BIT); vidMode1 = VModeDesc(vidModeParms1, false); vidMode2 = VModeDesc(vidModeParms2, false); @@ -335,18 +325,18 @@ bool InstallSlotROM(void) Offs(0x0b, minorLength); // Frame buffer length Offs(0x40, gammaDir); // Gamma directory Rsrc(0x7d, 6); // Video attributes: Default to color, built-in - if (has_depth(VDEPTH_1BIT)) - Offs(0x80, vidMode1); // Video mode parameters for 1 bit - if (has_depth(VDEPTH_2BIT)) - Offs(0x81, vidMode2); // Video mode parameters for 2 bit - if (has_depth(VDEPTH_4BIT)) - Offs(0x82, vidMode4); // Video mode parameters for 4 bit - if (has_depth(VDEPTH_8BIT)) - Offs(0x83, vidMode8); // Video mode parameters for 8 bit - if (has_depth(VDEPTH_16BIT)) - Offs(0x84, vidMode16); // Video mode parameters for 16 bit - if (has_depth(VDEPTH_32BIT)) - Offs(0x85, vidMode32); // Video mode parameters for 32 bit + if (video_has_depth(VDEPTH_1BIT)) + Offs(DepthToAppleMode(VDEPTH_1BIT), vidMode1); // Video mode parameters for 1 bit + if (video_has_depth(VDEPTH_2BIT)) + Offs(DepthToAppleMode(VDEPTH_2BIT), vidMode2); // Video mode parameters for 2 bit + if (video_has_depth(VDEPTH_4BIT)) + Offs(DepthToAppleMode(VDEPTH_4BIT), vidMode4); // Video mode parameters for 4 bit + if (video_has_depth(VDEPTH_8BIT)) + Offs(DepthToAppleMode(VDEPTH_8BIT), vidMode8); // Video mode parameters for 8 bit + if (video_has_depth(VDEPTH_16BIT)) + Offs(DepthToAppleMode(VDEPTH_16BIT), vidMode16); // Video mode parameters for 16 bit + if (video_has_depth(VDEPTH_32BIT)) + Offs(DepthToAppleMode(VDEPTH_32BIT), vidMode32); // Video mode parameters for 32 bit EndOfList(); // CPU sResource @@ -433,23 +423,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; }