Skip to content

Instantly share code, notes, and snippets.

@sentient06
Last active August 23, 2022 13:31
Show Gist options
  • Save sentient06/7303670 to your computer and use it in GitHub Desktop.
Save sentient06/7303670 to your computer and use it in GitHub Desktop.
C code that generates a small console app to check Macintosh Old World ROM files.
//
// ROMTest.c
// ROMTest
//
// Created by Giancarlo Mariot on 04/11/2013.
// Copyright (c) 2013 Giancarlo Mariot. All rights reserved.
//
// Adapted from C++ code by Dennis Nedry.
// Reference: http://68kmla.org/forums/viewtopic.php?f=15&t=12920
//
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
if (argc < 2) {
printf("\nUsage: ROMTest [path to ROM file]\n");
return 0;
}
char filePath[512];
snprintf(filePath, 512, "%s", argv[1]);
printf("Checking file:\n%s\n", filePath);
FILE * f;
f = fopen(filePath, "r");
unsigned int sum = 0;
long int length = 0;
while (getc(f) != EOF) {
length++;
}
printf("\nROM Length: %f kiB\n", length/1024.0);
if (length % 65536 != 0)
printf("The ROM appears to be the wrong length.\n"); // Checks if the file size is divisible by 64kiB
fclose(f);
f = fopen(filePath, "r");
unsigned int recorded = getc(f)*16777216+getc(f)*65536+getc(f)*256+getc(f);
printf("\nRecorded Checksum: 0x%X", recorded);
for (int i=4; i<length; i+=2) {
sum += getc(f) * 256;
sum += getc(f);
}
printf("\nComputed Checksum: 0x%X\n", sum);
//cout << hex << "\nComputed Checksum: 0x" << sum << endl;
if (recorded == sum) printf("\nROM Checksum PASSED.\n");
else printf("\nROM Checksum FAILED.\n");
printf("\nThe mac with this ROM is ");
switch (recorded) {
//------------------------------------------------
// 64 KB
case 0x28BA61CE:
printf("Macintosh 128");
break;
case 0x28BA4E50:
printf("Macintosh 512K");
break;
//------------------------------------------------
// 128 KB
case 0x4D1EEEE1:
printf("Macintosh Plus v1 Lonely Hearts");
break;
case 0x4D1EEAE1:
printf("Macintosh Plus v2 Lonely Heifers");
break;
case 0x4D1F8172:
printf("Macintosh Plus v3 Loud Harmonicas");
break;
//------------------------------------------------
// 256 KB
case 0x97851DB6:
printf("Macintosh II v1");
break;
case 0xB2E362A8:
printf("Macintosh SE");
break;
case 0x9779D2C4:
printf("Macintosh II v2");
break;
case 0xB306E171:
printf("Macintosh SE FDHD");
break;
case 0x97221136:
printf("Macintosh IIx, IIcx, SE/30");
break;
case 0x96CA3846:
printf("Macintosh Portable");
break;
case 0xA49F9914:
printf("Macintosh Classic (XO)");
break;
case 0x96645F9C:
printf("Macintosh PowerBook 100");
break;
//------------------------------------------------
// 512 KB
case 0x4147DD77:
printf("Macintosh IIfx");
break;
case 0x350EACF0:
printf("Macintosh LC");
break;
case 0x3193670E:
printf("Macintosh Classic II");
break;
case 0x368CADFE:
printf("Macintosh IIci");
break;
case 0x36B7FB6C:
printf("Macintosh IIsi");
break;
case 0x35C28F5F:
printf("Mac LC II or Performa 400/405/410/430");
break;
case 0x4957EB49:
printf("Mac IIvx (Brazil) or IIvi/Performa 600");
break;
//------------------------------------------------
// 1024 KB
case 0x420DBFF3:
printf("Quadra 700/900 or PowerBook 140/170");
break;
case 0x3DC27823:
printf("Macintosh Quadra 950");
break;
case 0xE33B2724:
printf("Powerbook 160/165/165c/180/180c");
break;
case 0xECFA989B:
printf("Powerbook 210/230/250");
break;
case 0xEC904829:
printf("Macintosh LC III");
break;
case 0xECBBC41C:
printf("Macintosh LCIII/LCIII+ or Performa 460");
break;
case 0xECD99DC0:
printf("Macintosh Color Classic / Performa 250");
break;
case 0xF1A6F343:
printf("Quadra/Centris 610 or 650");
break;
case 0xF1ACAD13:
printf("Quadra/Centris 610 or 650 or 800");
break;
case 0x0024D346:
printf("Powerbook Duo 270C");
break;
case 0xEDE66CBD:
printf("Color Classic II, LC 550, Performa 275/550/560, Mac TV");
break;
case 0xFF7439EE:
printf("LC 475/575 Quadra 605 Performa 475/476/575/577/578");
break;
case 0x015621D7:
printf("Powerbook Duo 280 or 280C");
break;
case 0x06684214:
printf("LC/Quadra/Performa 630");
break;
case 0xFDA22562:
printf("Powerbook 150");
break;
case 0x064DC91D:
printf("LC/Performa 580/588");
break;
//------------------------------------------------
// 2MB ROMs
// 2048 KB
case 0xB6909089:
printf("PowerBook 520/520c/540/540c");
break;
case 0x5BF10FD1:
printf("Macintosh Quadra 660av or 840av");
break;
case 0x4D27039C:
printf("PowerBook 190 or 190cs");
break;
//------------------------------------------------
// 4MB
case 0x9FEB69B3:
printf("Power Mac 6100/7100/8100");
break;
case 0x9C7C98F7:
printf("Workgroup Server 9150 80MHz");
break;
case 0x9B7A3AAD:
printf("Power Mac 7100 (newer)");
break;
case 0x63ABFD3F:
printf("Power Mac & Performa 5200/5300/6200/6300");
break;
case 0x9B037F6F:
printf("Workgroup Server 9150 120MHz");
break;
case 0x83C54F75:
printf("PowerBook 2300 & PB5x0 PPC Upgrade");
break;
case 0x9630C68B:
printf("Power Mac 7200/7500/8500/9500 v2");
break;
case 0x96CD923D:
printf("Power Mac 7200/7500/8500/9500 v1");
break;
case 0x6F5724C0:
printf("PowerMac/Performa 6400");
break;
case 0x83A21950:
printf("PowerBook 1400, 1400cs");
break;
case 0x6E92FE08:
printf("Power Mac 6500");
break;
case 0x960E4BE9:
printf("Power Mac 7300/7600/8600/9600 (v1)");
break;
case 0x960FC647:
printf("Power Mac 8600 or 9600 (v2)");
break;
case 0x78F57389:
printf("Power Mac G3 (v3)");
break;
case 0x79D68D63:
printf("Power Mac G3 desktop");
break;
case 0xCBB01212:
printf("PowerBook G3 Wallstreet");
break;
case 0xB46FFB63:
printf("PowerBook G3 Wallstreet PDQ");
break;
//------------------------------------------------
// New World ROM
case 0x3C434852:
// Must use MD5 here, in the near future...
printf("Mac OS ROM 1.X");
break;
//------------------------------------------------
// Unknown
default:
printf("unknown");
}
printf(".\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment