// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie // // SPDX-License-Identifier: MIT //! What a ROM file is, so that nobody has to guess which of them a flag wants. //! //! The problem this solves is that Apple II ROM images arrive named anything //! at all -- `APPLE2E.ROM`, `342-0077-b.bin`, `rom.bin`, `Apple IIgs (new)` -- //! and a machine given the wrong one fails in a way that says nothing about //! which one it wanted. `zig65 id FILE...` says what each file is and, where //! this program can use it, which flag to give it to. //! //! ## Two ways of knowing, and they answer different questions //! //! **By hash**, which is exact. Every file in `~/dev/Apple ROMs` has been //! identified, most of them by running them, and the table below is that //! catalogue's SHA-256 column with its identification. A match means *this //! file*, the one that was tested, and the answer can say so without hedging. //! //! **By structure**, when nothing matches. A hash table only knows the files //! it has seen, and a reader who has a differently trimmed dump, or a ROM //! nobody here has met, gets nothing from it -- which is the least helpful //! moment to say nothing. So an unknown file is read instead: the signature //! bytes a card carries so that a scan can find it, the version byte a IIc //! keeps at `$fbbf`, the marks that say which bank of a IIgs ROM is which, //! the strings inside. That cannot say "this is the one that was tested", and //! it does not pretend to; it says what can be seen, which is usually enough //! to know which flag to try. //! //! The structural half is deliberately the same reasoning the ROM catalogue //! itself records, since that is how those files came to be identified in the //! first place. const std = @import("std"); /// One file this project has identified. pub const Known = struct { /// Lowercase hexadecimal, which is what `sha256sum` prints. sha256: []const u8, size: usize, /// What it is called in `~/dev/Apple ROMs`, which is where these came /// from and where a reader can go for the whole description. file: []const u8, /// What it is, in the catalogue's own words. what: []const u8, /// The flag to give it to, or null for a ROM this program has no use for /// -- a Macintosh ROM, a character generator for a card that is not /// modelled, a chip nobody has identified. flag: ?[]const u8, }; /// The catalogue, by hash. /// /// Taken from `~/dev/Apple ROMs/README.md`, which is where these files are /// kept and where each one's full description lives. It is a copy rather than /// a reference because that archive is not a dependency of this program: a /// reader who has this binary and a ROM should get an answer without needing /// the archive too. pub const known = [_]Known{ .{ .sha256 = "3b1655207956b1f0e6a32665dc67e5829eac6adab8a473f9b8c1c812909531f6", .size = 2048, .file = "10.ic10.bin", .what = "A second firmware of the same family", .flag = null }, .{ .sha256 = "de1e3e035878bab43d0af8fe38f5839c527e9548647036598ee6fe7ec74d2a7d", .size = 256, .file = "341-0027-a.p5", .what = "Disk II boot PROM (P5), 16 sector", .flag = "--disk-rom" }, .{ .sha256 = "e5e30615040567c1e7a2d21599681f8dac820edbdcda177b816a64d74b3a12f2", .size = 256, .file = "341-0028-a.rom", .what = "Disk II state machine PROM (P6)", .flag = null }, .{ .sha256 = "aaa2f3a91f5adaf5484a65a3e9f8c0b26d2cfc50a5c0623977fed8ee9471e3f8", .size = 512, .file = "341-0057.bin", .what = "An Apple II slot card firmware, 512 bytes", .flag = null }, .{ .sha256 = "4fa1323ba31f4bd562486838397b7744257c126806766e360876720daca6e2aa", .size = 2048, .file = "341-0065-a.bin", .what = "Super Serial Card firmware", .flag = "--serial-rom" }, .{ .sha256 = "66480812edad5f6bd70349949cf8bd8fbafee2dc8bf396541d4e78bac2629ec0", .size = 2048, .file = "341-0269.2b", .what = "AppleMouse II card firmware", .flag = null }, .{ .sha256 = "7f8e50c0e8a409991264201f9300f109b872b68e09c43f3e6c26af35fd8b89af", .size = 2048, .file = "341-0270-c.4b", .what = "An Apple peripheral card firmware", .flag = null }, .{ .sha256 = "2b9beab16f64cda027ef8f2a048e54f3cb8f8016eafdc98d7be500c6a90ccc9c", .size = 4096, .file = "341-0344a.bin", .what = "Apple II Memory Expansion Card firmware", .flag = "--memory-expansion-rom" }, .{ .sha256 = "5e1efe51b2c8be901ab4283c671bd84364a574845b7269f92bdddc4dae9ae5d5", .size = 16384, .file = "341-0437-a.bin", .what = "Apple II SCSI Card firmware, revision C", .flag = "--scsi-rom" }, .{ .sha256 = "fbb9620e01f4f728e5a8ba86544900978d7803f6a7d577d384e288dfed9a4907", .size = 2048, .file = "342-0132-c.e12", .what = "Apple IIe keyboard ROM", .flag = null }, .{ .sha256 = "0d54ff735c060c55d54b8a22d0112af78a6465ce9c9aae4a865d207e5c8ff1e7", .size = 4096, .file = "342-0133-a.chr", .what = "Apple character generator", .flag = null }, .{ .sha256 = "ca06c6e6921d5709538fb1a60d3ecbb4623f13c69fca828985963753c95b6285", .size = 8192, .file = "342-0134-a.64", .what = "Apple IIe EF ROM ($e000-$ffff), the original 1983 firmware", .flag = null }, .{ .sha256 = "f119063639c04770ea4a8e6515304560c348ca9bd10da4055623efbbdc198c65", .size = 8192, .file = "342-0135-b.64", .what = "Apple IIe CD ROM ($c000-$dfff), the original 1983 firmware", .flag = null }, .{ .sha256 = "4d03bd0934ab39cb18f22444e0361f91d1984131759c07010398ad5cf84397c0", .size = 2048, .file = "4.ic4.bin", .what = "The same character generator again, bit-inverted", .flag = null }, .{ .sha256 = "c4ec7f4afe47133e0452db27f133eacba043b416612486d32031e1188eced11b", .size = 2048, .file = "5.ic5.bin", .what = "The character generator", .flag = null }, .{ .sha256 = "420da3867e489824f5fc0377c287c48a125296f19e1306df764e8f63bd23b00a", .size = 2048, .file = "6.ic6.bin", .what = "Videoterm firmware, a hair off 2.4", .flag = null }, .{ .sha256 = "3bb883b1bccad5ed02def4531638a0b130d8caee6c435384dbb83cb0d649a4ba", .size = 2048, .file = "8.ic8.bin", .what = "A line drawing character generator", .flag = null }, .{ .sha256 = "cea97fcb59d970a1a71c82b0fa20404bc6f5c12ae9130bc94b0d2ccbe64b22a9", .size = 16384, .file = "840-003a.bin", .what = "SwyftCard", .flag = null }, .{ .sha256 = "152a993bbe88808db75d32457729a25e7d48f4afe14effd9c65f0562602cb7e2", .size = 2048, .file = "9.ic9.bin", .what = "The same character generator", .flag = null }, .{ .sha256 = "c0db2970f96c1c9b26bcf57c850757ec59f84d82316d06e6cd6b017e955c0994", .size = 2048, .file = "a4.7.u10", .what = "Corvus disk interface card firmware", .flag = null }, .{ .sha256 = "1b9fcf6f3e9e77b8956181f399dfb7905eb7cc947b658a6c202f6b123518a0b7", .size = 256, .file = "aci.rom", .what = "Apple-1 Cassette Interface PROM, 256 bytes, $c100 to $c1ff", .flag = "--machine i --aci-rom" }, .{ .sha256 = "58522db3fe3de0c5b264739e629d49be9d15b799adb980e3d730d51962276325", .size = 8192, .file = "ae ramfactor rom v1.0.bin", .what = "Applied Engineering RamFactor, a memory card; firmware revis", .flag = null }, .{ .sha256 = "05ad7be9f1a951b8a5dcfac0c682fda01ae93973a840ea8c8d38e6bdf101714d", .size = 8192, .file = "ae ramfactor rom v1.1.bin", .what = "RamFactor firmware revision 1.1", .flag = null }, .{ .sha256 = "b0c1abc480aa96a50546204386ecce9da9679567e5ffb00fa0a269616705df7e", .size = 8192, .file = "ae ramfactor rom v1.3.bin", .what = "RamFactor firmware revision 1.3", .flag = null }, .{ .sha256 = "3369e5e9838db52df7924e79e65451267953172390d30308a28c688a886989ce", .size = 8192, .file = "ae ramfactor rom v1.4.bin", .what = "RamFactor firmware revision 1.4", .flag = null }, .{ .sha256 = "3b24f88ec5f7b28dcef2e9c1fcfabad65cdce7aea391be43ae6d8d6dbab12bb1", .size = 4096, .file = "ae timemaster ii h.o. rom rev. 5.bin", .what = "Applied Engineering TimeMaster II H.O., a clock card", .flag = null }, .{ .sha256 = "fc2ff608f66208f4c5c377dac16ca5cbbce843c452202ad0b031b7e0d61ff886", .size = 32768, .file = "ap2k.ic3c", .what = "Epson ActionPrinter 2000", .flag = null }, .{ .sha256 = "702ccf0f4a7abad0dc6d89dd981ef48a11f9d121dee25c969b9347894256553b", .size = 2048, .file = "Apple IIc Keyboard ROM - 342-0284-A - Italian.ROM", .what = "Apple IIc keyboard ROM, Italian layout", .flag = null }, .{ .sha256 = "678d5c9d374664d2ee94ba9c9564d26a917b31116b07c46df30a3e82c640885b", .size = 32768, .file = "Apple IIc ROM 00 - 342-0033-A - 1985.bin", .what = "Apple IIc ROM 0, 32K, 1985", .flag = "--machine iic --rom" }, .{ .sha256 = "48318d174d7df008c12efe7a26e9c83147499141933b8041d94639fb767466c1", .size = 32768, .file = "Apple IIc ROM 03 - 341-0445-A.bin", .what = "Apple IIc ROM 3, 32K", .flag = "--machine iic --rom" }, .{ .sha256 = "8ad5e6c4ed15d09b62183965b6c04762610d4b26510afc1896bdb4ecc55da883", .size = 32768, .file = "Apple IIc ROM 04 - 341-0445-B.bin", .what = "Apple IIc ROM 4, 32K", .flag = "--machine iic --rom" }, .{ .sha256 = "5a62070f6a0b07784681d4df4bf2ce88b2809bec0cbaa65fcb963e804ed60374", .size = 32768, .file = "Apple IIc ROM 05 - IIc Plus.bin", .what = "Apple IIc Plus ROM (version $05), 32K", .flag = "--machine iic --rom" }, .{ .sha256 = "3ca1c8a27bf111aa0f4dc9372c5e6404457adb9a458ce32ae4b03a7e989e0c76", .size = 16384, .file = "Apple IIc ROM FF - 342-0272-A.bin", .what = "Apple IIc original ROM (version 255/$FF), 16K", .flag = "--machine iic --rom" }, .{ .sha256 = "52c3b87900ac939f6525402cab1ccfd8f8259290fc6df54da48fb4c98ae3ed0f", .size = 4096, .file = "Apple IIe Video ROM - 341-0265-A.bin", .what = "The enhanced //e and IIc character generator, 4K", .flag = null }, .{ .sha256 = "478ec7010393151cb5b129330b18336562e7d0bdc43ac3dd0decd3a4a5cfbc6a", .size = 131072, .file = "Apple IIGS Alpha ROM 2.0 19860310.bin", .what = "IIGS alpha firmware, build stamped 8:00:00 March 10, 1986", .flag = null }, .{ .sha256 = "cfdb12dc37851af7f2af28f61428c68651094643c72fdc72df40ffac2040e44b", .size = 131072, .file = "Apple IIGS BT ROM 19860626.bin", .what = "IIGS firmware, build stamped 18:00:00 June 18, 1986", .flag = null }, .{ .sha256 = "9a36f55562d483e11c777a73bb76bb3b01a9ca34ea867f22d2c3277cdca16176", .size = 131072, .file = "Apple IIGS ROM 00 - 342-0077-A.bin", .what = "IIGS ROM 00", .flag = "--machine iigs --rom" }, .{ .sha256 = "eeacf455cc642f9e7e36353ecf67eea65b4a9d725606400f50a0987006eed5f3", .size = 131072, .file = "Apple IIGS ROM 01 - 342-0077-B.bin", .what = "IIGS ROM 01", .flag = "--machine iigs --rom" }, .{ .sha256 = "b327c945a15a11b4a54ca1fb30f5974dc10f6322e280579e1cce51f775cfa588", .size = 131072, .file = "Apple IIGS ROM 3 Banks FC-FD - 341-0728.bin", .what = "IIGS ROM 3, banks $FC-$FD", .flag = "--machine iigs --rom" }, .{ .sha256 = "31947bb32cd6c564be93fd251e0900f45a9561874bc00307d4978c3db08c9a66", .size = 131072, .file = "Apple IIGS ROM 3 Banks FF-FE - 341-0748 (new).bin", .what = "A third variant, differing from both of the above in nearly ", .flag = "--machine iigs --rom" }, .{ .sha256 = "3dc560f51f2a0b3c61472163e212d36c8321f43203b343abafe289072dc4472b", .size = 131072, .file = "Apple IIGS ROM 3 Banks FF-FE - 341-0748.bin", .what = "IIGS ROM 3, banks $FE-$FF", .flag = "--machine iigs --rom" }, .{ .sha256 = "83c9480899bee32abff4267e98bd6c4b4c886b9ba302984c33ca41f6e3e731a3", .size = 131072, .file = "Apple IIGS ROM 3 Banks FF-FE - 341-0749.bin", .what = "The same firmware, differing from 341-0748.bin in about 58", .flag = "--machine iigs --rom" }, .{ .sha256 = "e6a15f1b7849fab9a8824a8e41c803381056dc15975cf7ddde7b7355f8fb444b", .size = 262144, .file = "Apple IIGS ROM 3 Tenspeed Late 1988 Early 1989 v16.bin", .what = "A full 256K ROM 3 era image, \"Tenspeed\" build v16", .flag = "--machine iigs --rom" }, .{ .sha256 = "4e606469961649381216b2a61334ccb29af4da90c630df19214b08ff7fdb9bc5", .size = 262144, .file = "Apple IIGS ROM 3 Tenspeed Late 1988 Early 1989 v25.bin", .what = "The same, build v25", .flag = "--machine iigs --rom" }, .{ .sha256 = "565d8ca073e5c46367ca56d4b12827020e76e6a0bf6c2300da0989161aa34ad9", .size = 262144, .file = "Apple IIGS ROM 4 Mark Twain.bin", .what = "\"Mark Twain\" ROM 4, 256K", .flag = "--machine iigs --rom" }, .{ .sha256 = "34cd454c6201bfd26839d6ace2ff6b1231e09d6279e49b4890311756dc3825fb", .size = 131072, .file = "Apple IIGS ROM from PVT92.bin", .what = "A IIGS ROM 01 era image", .flag = "--machine iigs --rom" }, .{ .sha256 = "afbf4b1bccf88b3f89fa7ebadfc771d9ab699b23a5464d0695bc92af24e232ce", .size = 1024, .file = "Apple III/341-0042.bin", .what = "1K×4 PROM specific to the earlier 12 V logic board, dumped f", .flag = null }, .{ .sha256 = "3b30fda2ff94500f1224918f14a0c71f10f7f8f2f027386dba4c428d757563eb", .size = 1024, .file = "Apple III/341-0044.bin", .what = "1K×4 PROM specific to the 12 V logic board, as above", .flag = null }, .{ .sha256 = "9e04e16903f33b38cd8d7c17dc6ef4c2eab7f5bfb926158194448d8dfbadeace", .size = 2048, .file = "Apple III/342-0030.bin", .what = "Board location G9. Synchronization ROM (\"Synchrom\") of the", .flag = null }, .{ .sha256 = "370be5f0c1b57b606d6c7312f99e5f6064bf405b22430ab53d9bec9bcc0f7520", .size = 4096, .file = "Apple III/342-0031.bin", .what = "Board location B9. The boot ROM, a 2332 4K×8 at $F000.", .flag = null }, .{ .sha256 = "c147357681cfc9954740f9c163818fc801cb48894b5ba0a6967d90526eacfd69", .size = 2048, .file = "Apple III/342-0032.bin", .what = "Board location G5. Video control ROM, a 2316 2K×8. The v", .flag = null }, .{ .sha256 = "0dc6efe955ac9627e05baef87187c2740055c65f65115360a689a1467abe58ea", .size = 1024, .file = "Apple III/342-0043.bin", .what = "Board location C10. 1K×4 PROM, board location U174 — one of ", .flag = null }, .{ .sha256 = "37bae828a72098713612dd5f6ccb6b0206db23081a4a710e9574bcef3fa7cda0", .size = 1024, .file = "Apple III/342-0045.bin", .what = "Board location F5. 1K×4 PROM, board location U176.2", .flag = null }, .{ .sha256 = "8ca7d9e76627a1f4cf9f5592b378c4e51bdaa4ea4ad3d4c66ca6c000ae93af1b", .size = 1024, .file = "Apple III/342-0046.bin", .what = "Board location F7. 1K×4 PROM, board location U180", .flag = null }, .{ .sha256 = "9d266ac016d2b7124bbc50a586145482c8a84798aef3f92a33f87d8fbd60f909", .size = 1024, .file = "Apple III/342-0055.bin", .what = "Board location F9. 1K×4 PROM, U175-65", .flag = null }, .{ .sha256 = "c370630ef41b870e71128acf0fd2d5826aaa990bcc36f13975c4c0ce6408ab82", .size = 1024, .file = "Apple III/342-0056.bin", .what = "Board location C12. 1K×4 PROM, CASB65.1: column address st", .flag = null }, .{ .sha256 = "32e3c28b6b81ee81acc6ce7f00ddaa9650f60fc55ca77f607ae2e0b7289c2868", .size = 1024, .file = "Apple III/342-0061.bin", .what = "Board location C11. 1K×4 PROM, RAS65: row address strobe t", .flag = null }, .{ .sha256 = "336ee3d21deffd4e728a46fd0fbbe98b166fccaff6da65b1c1f5ce592ca6ca1c", .size = 1024, .file = "Apple III/342-0063.bin", .what = "Board location C13. 1K×4 PROM, CASB256: column address str", .flag = null }, .{ .sha256 = "77cfec07458f2ea4a4676dfccdaa30bee7918cbbf0941ddeb86a32bb85d82878", .size = 2048, .file = "Apple III/342-0145-A.bin", .what = "Board location G9. Interlace synchronization ROM (\"Interla", .flag = null }, .{ .sha256 = "c9421c9c35ef96379f4ec8c7d812c89356c2e76d8178670c1bb85486bb182f4d", .size = 1433, .file = "Apple III/Apple III (5V+256KB) ROMs.csv", .what = "The uploader's sheet for the Apple III with the 5 V logic bo", .flag = null }, .{ .sha256 = "20266e085159e77aae6fbeb02bd47ed60bb9db98cc4f83e7b944f4b32f5d5bc9", .size = 1423, .file = "Apple III/Apple III Plus ROMs.csv", .what = "The uploader's sheet for the Apple III Plus: file name, boar", .flag = null }, .{ .sha256 = "5d8a3fe3c20c42903b226d67430c840ea5119557f88774c069e2e4dd80ad2c67", .size = 4096, .file = "Apple-1 BASIC ROM.bin", .what = "Apple-1 BASIC as a 4K binary for $e000, patched for a fully decoded PIA", .flag = null }, .{ .sha256 = "92c4bef609920842ea472d21b661a0d35dbda6cd90963b8b734a205e22d84108", .size = 20480, .file = "APPLE2.ROM", .what = "Apple II Plus system ROM, 20K, dumped from a machine with a Disk II card in slot 6", .flag = "--machine ii+ --rom" }, .{ .sha256 = "2bfbb529d8acd65b0c84167e6933461134514727267af54099631d65471b3650", .size = 2048, .file = "apple2dead v1.0.2.bin", .what = "misterblack1's Apple II Dead Test, v1.0.2", .flag = null }, .{ .sha256 = "1fb812584c6633fa16b77b20915986ed1178d1e6fc07a647f7ee8d4e6ab9d40b", .size = 16384, .file = "apple2e-unenhanced.rom", .what = "Apple IIe original firmware, 16K, made here", .flag = "--machine iie --rom" }, .{ .sha256 = "c17bc38c75ba96c33a30c688a1efd60144811073423533fe7f8453cdd9457aab", .size = 32768, .file = "APPLE2E.ROM", .what = "Apple IIe system ROM, 32K — the 1985 enhanced firmware", .flag = "--machine iie --rom" }, .{ .sha256 = "68d9db6bb4c305d40c3fa89fa0f2d7b7f71516a9431e3138859f23bc5bddb2d1", .size = 12288, .file = "apple2o.rom", .what = "Apple II system ROM, 12K: Integer BASIC and the old Monitor", .flag = "--machine ii --rom" }, .{ .sha256 = "ee9841257e923e1d6be9cd366d2d98d12db9647c9cb1cfe3ce5d631f588cdeca", .size = 2048, .file = "applicard-v9.bin", .what = "PCPI Applicard, a Z80 card; the code in it is Z80 rather tha", .flag = null }, .{ .sha256 = "3d7f6918f9af3828f5a6299299a817df0d354ee62e547bc0238755de66162a88", .size = 4096, .file = "cffa20ee02.bin", .what = "CFFA 2.0 firmware", .flag = null }, .{ .sha256 = "a08cb25ad80054649ee5fcb620e01ed56f025acb28c753bc28dd187a1d149cab", .size = 4096, .file = "cffa20eec02.bin", .what = "CFFA 2.0 firmware, 65C02 build", .flag = null }, .{ .sha256 = "8d492395490f80cf5fb400ed89f3700e59f250aecf7e27e4f24b9afe27beade0", .size = 2048, .file = "chargen-15ie.bin", .what = "15IE-00-013 terminal character generator. Not Apple: a MAME ", .flag = null }, .{ .sha256 = "cbbfd3d07be729795d2b5a2bcdb1f1daf01af945f2f80430a5666bb7f0fedcd0", .size = 4096, .file = "chs_5604.bin", .what = "An UltraTerm character set", .flag = null }, .{ .sha256 = "d9c3108abb2a21a3807deb992af62c963891f18938f1da945e536f82e4676651", .size = 4096, .file = "chs_7859.bin", .what = "A second UltraTerm character set", .flag = null }, .{ .sha256 = "8f57b5ca600c1513c3f6ac15cfa7f19338ef2ac25e7ae88b29a9d37d5d05bb72", .size = 256, .file = "Corvus Transporter A2 slot PROM - U15 63S281.bin", .what = "Corvus Omninet Transporter, Apple II slot firmware, 256 bytes", .flag = null }, .{ .sha256 = "ac13fabc211cf4db78b1ce43056f79401c803162522c5e4873b33c6f80e737e6", .size = 2048, .file = "Corvus Transporter firmware - TA6 A2 IBM.bin", .what = "Corvus Omninet Transporter, onboard firmware, 2K", .flag = null }, .{ .sha256 = "2d2599521fc5763d4e8c308c2ee7c5c4d5c93785b8fb9a4f7d0381dfd5eb60b6", .size = 256, .file = "DISK2-13sector.rom", .what = "Disk II boot PROM (P5), 13 sector", .flag = "--disk-rom" }, .{ .sha256 = "3f31f1ec852a2d1686f306e6963fc42b5858d4f246b31d8b2650ebffd2faf55d", .size = 4096, .file = "dump1.bin", .what = "Two revisions of one 4K EPROM, this and dump5.bin. They ag", .flag = null }, .{ .sha256 = "f4f840da556b0402aedcfa3e9f9768c7a19ca4b38e3ec467192c85542bea0269", .size = 4096, .file = "dump5.bin", .what = "The other revision: programmed through page $0a, blank from ", .flag = null }, .{ .sha256 = "8c9888dbc0c5dc8d51493e3f192a09415216ccb96d99e9d94ea29c58dec643e0", .size = 4096, .file = "frm_b537.bin", .what = "UltraTerm firmware", .flag = null }, .{ .sha256 = "cb17d747d3370723df02504f94bcf72aae9ef6d7419dc1e2edeb2cccfedf4024", .size = 4096, .file = "frm_b5c9.bin", .what = "UltraTerm firmware, second revision or variant", .flag = null }, .{ .sha256 = "c452c3f2a970ebd89605ecc55138347fa621347e6519856ef0f2dc8eae84c05a", .size = 65536, .file = "IIGS Prototype ROM 512K 2-3-86.BIN", .what = "IIGS prototype firmware", .flag = null }, .{ .sha256 = "e6737232e31acd46090b92281eae01a463f91fb3b886817d6148e5f85173db39", .size = 8192, .file = "it.em.ou.bin", .what = "A font ROM carrying its own menu: 1. ITALIC, 2. EMPHASIZE", .flag = null }, .{ .sha256 = "d584f295ec2374ab173a8a7a2a6c3f74375077c2a1ae67bcb130d18617384319", .size = 32768, .file = "lx800.ic3c", .what = "Epson LX-800 printer", .flag = null }, .{ .sha256 = "a67a643864faff058ac3e833519f3eaa09ffbc7fdf28865446388115ba095887", .size = 32768, .file = "lx810l.ic3c", .what = "Epson LX-810L printer", .flag = null }, .{ .sha256 = "47b367e4bd75bb14867d287ff62f53ec515d35aaf66d4b357bb5c5be31704480", .size = 256, .file = "mmi_pal16r4a(binary).2a", .what = "A 16R4 PAL, as a binary image. The same part as the file bel", .flag = null }, .{ .sha256 = "0af675986b455ce10236e9a98bd73fd226474db75c2139560f31a6ff807a890e", .size = 2820, .file = "mmi_pal16r4a(jedec).2a", .what = "The same 16R4 PAL as a JEDEC fuse map", .flag = null }, .{ .sha256 = "3aad41591859f8679fe21a60bb9e2e4fba578abdb5f4dd10884305f7e8b65867", .size = 1048576, .file = "p72.2c", .what = "A printer ROM, one megabyte", .flag = null }, .{ .sha256 = "93e2dfd516973e449782c147862c2677ffb0e2fe2ef592187d6e4e8a47793599", .size = 3584, .file = "pl80.pt6", .what = "PL-80 plotter", .flag = null }, .{ .sha256 = "4db029004801199f06d8abe732128016fb6f207117a4adc16c1c796cd1a73572", .size = 1024, .file = "Signetics 2513 Video ROM.bin", .what = "A 128-glyph ASCII character generator, not a 2513", .flag = null }, .{ .sha256 = "2b2626ca26b5f4d8ee2602648f6a9832ec11ca6a69ae81650c3799796fe836ce", .size = 8192, .file = "space 84 video ap16.bin", .what = "Space 84 clone 80 column firmware", .flag = null }, .{ .sha256 = "987276421d730c4bebfc0b63a4809e697f309499a6d6b97e0930f3183b06ec01", .size = 8192, .file = "space 84 video chargen ap16.bin", .what = "Space 84 clone character generator", .flag = null }, .{ .sha256 = "3f32f0a632df50a245e210fd31ce6673d76f5ffc7eefb45399253da60b75f035", .size = 2287, .file = "swyft_pal16r4.jed", .what = "A 16R4 PAL from a Swyft, going by the name", .flag = null }, .{ .sha256 = "ecca793179427fdd193373080bf23e49a95743bd7b5e0b218c747663938b6c03", .size = 2048, .file = "thunderclock plus rom.bin", .what = "Thunderclock Plus, a clock card", .flag = null }, .{ .sha256 = "24712b1e32295b4466e81444ee7be5a213df6b8e9ecd159a9850a9c369b5d39b", .size = 1024, .file = "tiny.bin", .what = "Contains 2120 CHAR and TEK, so a Tektronix 2120 characte", .flag = null }, .{ .sha256 = "e7b25b6be6c220317d4d81a0f538784cc72024821f402d6edaf80b81d9012082", .size = 773, .file = "ult_251c.jed", .what = "A PAL from a Videx UltraTerm, going by the name", .flag = null }, .{ .sha256 = "9e4e93f9634a058e4cb8dd4ce06aa7987d4ca93eb43d9f47069b95ce36775f85", .size = 773, .file = "ult_2a313.jed", .what = "A PAL from a Videx UltraTerm, going by the name", .flag = null }, .{ .sha256 = "c43ce36cb4371c448fad9ada18604b5fa426334db83609e632b140954b5c337f", .size = 4096, .file = "unknown apple ii clone video 1.bin", .what = "An Apple II clone's video ROM", .flag = null }, .{ .sha256 = "d38893d5b47e5ea718575e0a81084e539968a5dbf1ee3f8a21c66f9e2707706a", .size = 4096, .file = "unknown apple ii clone video 3.bin", .what = "An Apple II clone's 80 column firmware", .flag = null }, .{ .sha256 = "402ec5d8f3fe99eb76438ff8e1d45fa67bd9879bad7f13306cf82d94799047f2", .size = 2048, .file = "videx videoterm character rom apl.bin", .what = "The apl set", .flag = null }, .{ .sha256 = "96f27dfd968015775f3daa94f4c51ce537410c99a0cedcaeb2314d2ede38498f", .size = 2048, .file = "videx videoterm character rom epson.bin", .what = "The epson set", .flag = null }, .{ .sha256 = "c08f83879238b215ea9fb4dae42a026e0b9d881abf27e9f411dd65723dbe62e1", .size = 2048, .file = "videx videoterm character rom french.bin", .what = "The french set", .flag = null }, .{ .sha256 = "f18932f5edaf6b2f4a11d10829371ed7b25e70800e127a747983c76a0a9ef218", .size = 2048, .file = "videx videoterm character rom german.bin", .what = "The german set", .flag = null }, .{ .sha256 = "617b95856c8cbc7eae14b9d198cdcb29e52235d7f7cff3af2d417ead9f768cb2", .size = 2048, .file = "videx videoterm character rom katakana.bin", .what = "The katakana set", .flag = null }, .{ .sha256 = "2710dc2dbc169b6176fb6ef7738cb37b6f1c1af8e2accae1399cef779ce72a2f", .size = 2048, .file = "videx videoterm character rom normal uppercase.bin", .what = "The normal uppercase set", .flag = null }, .{ .sha256 = "ad873ca47e09def4c942177c84809d853231d4774e8d824e1b834d2033b8199c", .size = 2048, .file = "videx videoterm character rom normal.bin", .what = "The normal set", .flag = null }, .{ .sha256 = "9f481c0a08107f68eaf3563b840b1517b325638cd59e20f2416d11151739bd91", .size = 2048, .file = "videx videoterm character rom spanish.bin", .what = "The spanish set", .flag = null }, .{ .sha256 = "71032013477732cf5e3679b37f48e24468ee9d3bbea77a863df6dbd7b282c79b", .size = 2048, .file = "videx videoterm character rom super and subscript.bin", .what = "The super and subscript set", .flag = null }, .{ .sha256 = "e0377c334bb929402c4b3b50cbadfcd62fd05baca91ded03fa14ae79e3af4d5f", .size = 2048, .file = "videx videoterm character rom symbol.bin", .what = "The symbol set", .flag = null }, .{ .sha256 = "616f4d9f81a7a4ea0fa918842a05dfb3b503927776d2bfe97e6950b5431b562e", .size = 1024, .file = "videx videoterm rom 2.4.bin", .what = "Videx Videoterm firmware 2.4", .flag = null }, .{ .sha256 = "e1dd63e2e8facaf89a7ab15af02c4f3de2bbd50d75b49ab88a9b520684512cc9", .size = 32768, .file = "w8_pe9.9b", .what = "A printer ROM", .flag = null }, .{ .sha256 = "e5af0d1c4057bd8e0ef5cb069c208ff7cc0984a7dff53b12c5cf119de8cb5c25", .size = 256, .file = "wozmon.bin", .what = "Apple-1 Woz Monitor, 256 bytes, $ff00 to $ffff", .flag = "--machine i --rom" }, .{ .sha256 = "fb115daf1c0caca98e1cab7b06473f2b91dd7ab7ada6b7ce8c4d8edf5e532c6b", .size = 8192, .file = "zip drive - rom.bin", .what = "Zip Technology accelerator", .flag = null }, }; /// What was worked out about a file. pub const Identity = union(enum) { /// A file in the table: this exact ROM, tested. known: Known, /// Not in the table, but it can be read. The text says what was seen and /// what to try, and is written for somebody deciding which flag to use. guessed: []const u8, /// Nothing in it says anything. unknown, }; /// Looks a file up by hash, and reads it if that fails. /// /// `into` is where a guess is written, since one is built rather than chosen; /// it wants about two hundred bytes. pub fn identify(bytes: []const u8, into: []u8) Identity { var digest: [32]u8 = undefined; std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{}); var hex: [64]u8 = undefined; _ = std.fmt.bufPrint(&hex, "{x}", .{&digest}) catch unreachable; for (known) |entry| { if (std.mem.eql(u8, entry.sha256, &hex)) return .{ .known = entry }; } return guess(bytes, into); } /// The hash as a program would print it, for a file nobody has catalogued: a /// reader who wants to add one to the archive needs it, and working it out /// again by hand is a nuisance. pub fn hash(bytes: []const u8, into: *[64]u8) []const u8 { var digest: [32]u8 = undefined; std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{}); return std.fmt.bufPrint(into, "{x}", .{&digest}) catch unreachable; } /// What can be read off a file nobody has catalogued. /// /// Each of these is a mark at a fixed place that a machine or a card carries /// so that something else can find it, which is exactly what makes them /// usable here: they are there to be looked at. fn guess(bytes: []const u8, into: []u8) Identity { var writer = std.Io.Writer.fixed(into); // A slot card's firmware page. The four bytes at $Cn01, $Cn03, $Cn05 and // $Cn07 are how a scan tells a card from an empty slot, and the fourth of // them says what kind: $3c is a Disk II, $00 a SmartPort, and anything // else with the first three right is a Pascal 1.1 device whose kind is at // $CnFB. A page of firmware is 256 bytes, and a card's ROM is that page // somewhere in it -- often at the top of a larger image. for ([_]usize{ 0, 0x700, bytes.len -| 0x100 }) |base| { if (base + 0x100 > bytes.len) continue; const page = bytes[base..][0..0x100]; if (page[1] != 0x20 or page[3] != 0x00 or page[5] != 0x03) continue; writer.print("an Apple II slot card's firmware", .{}) catch {}; if (base != 0) writer.print(" at offset ${x}", .{base}) catch {}; switch (page[7]) { 0x3c => writer.print(", a Disk II controller by its $3c at $Cn07 -- try --disk-rom", .{}) catch {}, 0x00 => { writer.print(", a SmartPort device by its $00 at $Cn07", .{}) catch {}; if (page[0xfb] & 0x02 != 0) writer.print(", and SCSI by bit 1 of $CnFB -- try --scsi-rom", .{}) catch {}; }, else => writer.print(", a Pascal 1.1 device with class byte ${x:0>2} at $CnFB", .{page[0xfb]}) catch {}, } return .{ .guessed = writer.buffered() }; } // A machine's own ROM. `$fbb3` is `$06` on every IIe and IIc and on // nothing else, which makes it the mark to look for; then `$fbc0` says // which family and `$fbbf` says which revision of a IIc (Apple Computer, // Inc., 1985b, p. xxix, and 1985e, Appendix F.1). // // Both sixteen-kilobyte halves are looked at, because which one carries // the marks depends on the machine: a 32K IIe image has them in the half // that answers at `$c000-$ffff`, and a 32K IIc image has them in its // *first* half, the second being the other bank `$c028` switches to. if (bytes.len >= 0x4000) { var offset = bytes.len; while (offset >= 0x4000) { offset -= 0x4000; const bank = bytes[offset..][0..0x4000]; if (bank[0x3bb3] != 0x06) continue; switch (bank[0x3bc0]) { 0xe0 => writer.print("an Apple IIe system ROM, the 1985 enhanced firmware by $e0 at $fbc0 -- try --machine iie --rom", .{}) catch {}, 0xea => writer.print("an Apple IIe system ROM, the original 1983 firmware by $ea at $fbc0 -- try --machine iie --rom", .{}) catch {}, 0x00 => writer.print("an Apple IIc system ROM, revision ${x:0>2} by $fbbf -- try --machine iic --rom", .{bank[0x3bbf]}) catch {}, else => writer.print("an Apple II family system ROM: $06 at $fbb3, but ${x:0>2} at $fbc0 is a firmware nothing here knows", .{bank[0x3bc0]}) catch {}, } return .{ .guessed = writer.buffered() }; } } // And failing all of that, whatever it says about itself. A ROM with // words in it is at least a ROM somebody wrote a message into, and the // message is usually the fastest way to find out what it belongs to. // // "Words" rather than "printable bytes": 6502 code is full of runs that // happen to be printable -- an opcode stream reads as punctuation -- and // printing those is worse than saying nothing, because it looks like // evidence. A run has to be mostly letters before it counts. var found: usize = 0; var at: usize = 0; while (at < bytes.len and found < 3) { const start_of = at; while (at < bytes.len and printable(bytes[at])) at += 1; const run = bytes[start_of..at]; at += 1; if (run.len < 8) continue; var letters: usize = 0; for (run) |byte| { const c = byte & 0x7f; if ((c >= 'A' and c <= 'Z') or (c >= 'a' and c <= 'z')) letters += 1; } if (letters * 5 < run.len * 3) continue; // three fifths of it, at least if (found == 0) writer.print("nothing here recognises it, but it holds the text", .{}) catch {}; writer.print(" '", .{}) catch {}; for (run[0..@min(run.len, 32)]) |byte| writer.writeByte(byte & 0x7f) catch {}; writer.print("'", .{}) catch {}; found += 1; } if (found != 0) return .{ .guessed = writer.buffered() }; return .unknown; } /// High bit set is how an Apple stores a character it means, so both halves /// count as text. fn printable(byte: u8) bool { const stripped = byte & 0x7f; return stripped >= 0x20 and stripped < 0x7f; } const testing = std.testing; test "every entry in the table is a distinct, well formed hash" { // The table is generated from the ROM catalogue, so the thing that can go // wrong with it is a bad paste rather than a bad idea: a truncated hash, a // duplicate row, a size of nought. for (known, 0..) |entry, i| { try testing.expectEqual(@as(usize, 64), entry.sha256.len); for (entry.sha256) |c| try testing.expect((c >= '0' and c <= '9') or (c >= 'a' and c <= 'f')); try testing.expect(entry.size > 0); try testing.expect(entry.what.len > 0); try testing.expect(entry.file.len > 0); for (known[i + 1 ..]) |other| { try testing.expect(!std.mem.eql(u8, entry.sha256, other.sha256)); } } } test "a catalogued ROM is recognised by its hash, and says which flag wants it" { // The Disk II's boot PROM, built rather than read: a file this project // ships nothing of, so the test carries the bytes that matter. Its hash is // what the table has, so anything else would be a table that had drifted. var buffer: [256]u8 = undefined; // Not the real PROM -- a made-up one, to check the *miss* path. var made_up: [256]u8 = @splat(0); made_up[1] = 0x20; made_up[3] = 0x00; made_up[5] = 0x03; made_up[7] = 0x3c; switch (identify(&made_up, &buffer)) { .known => return error.ShouldNotBeCatalogued, .guessed => |what| { // It is not one of ours, and it still says what it is and what to // do with it, which is the whole point of the second half. try testing.expect(std.mem.indexOf(u8, what, "Disk II") != null); try testing.expect(std.mem.indexOf(u8, what, "--disk-rom") != null); }, .unknown => return error.ShouldHaveBeenRead, } } test "a SmartPort card says so, and a SCSI one says which kind" { var buffer: [256]u8 = undefined; var page: [256]u8 = @splat(0); page[1] = 0x20; page[3] = 0x00; page[5] = 0x03; page[7] = 0x00; // SmartPort rather than a Disk II page[0xfb] = 0x82; // extended, and bit 1 is SCSI switch (identify(&page, &buffer)) { .guessed => |what| { try testing.expect(std.mem.indexOf(u8, what, "SmartPort") != null); try testing.expect(std.mem.indexOf(u8, what, "--scsi-rom") != null); }, else => return error.ShouldHaveBeenRead, } // The same card without the SCSI bit is a SmartPort device and no more, // and saying more than that would be inventing it. page[0xfb] = 0x80; switch (identify(&page, &buffer)) { .guessed => |what| { try testing.expect(std.mem.indexOf(u8, what, "SmartPort") != null); try testing.expect(std.mem.indexOf(u8, what, "--scsi-rom") == null); }, else => return error.ShouldHaveBeenRead, } } test "a machine's ROM is told from its identification bytes" { var buffer: [256]u8 = undefined; const gpa = testing.allocator; const image = try gpa.alloc(u8, 0x4000); defer gpa.free(image); // $06 at $fbb3 is every IIe and IIc; $fbc0 says which family. @memset(image, 0); image[0x3bb3] = 0x06; image[0x3bc0] = 0xe0; switch (identify(image, &buffer)) { .guessed => |what| { try testing.expect(std.mem.indexOf(u8, what, "enhanced") != null); try testing.expect(std.mem.indexOf(u8, what, "--machine iie") != null); }, else => return error.ShouldHaveBeenRead, } image[0x3bc0] = 0xea; switch (identify(image, &buffer)) { .guessed => |what| try testing.expect(std.mem.indexOf(u8, what, "original 1983") != null), else => return error.ShouldHaveBeenRead, } // A IIc, whose revision is the byte beside it. image[0x3bc0] = 0x00; image[0x3bbf] = 0x05; switch (identify(image, &buffer)) { .guessed => |what| { try testing.expect(std.mem.indexOf(u8, what, "IIc") != null); try testing.expect(std.mem.indexOf(u8, what, "$05") != null); }, else => return error.ShouldHaveBeenRead, } } test "a file with nothing in it says nothing, rather than something invented" { var buffer: [256]u8 = undefined; // Printable, but not words: an opcode stream reads like this, and saying // "it holds the text" of it would look like evidence. var punctuation: [512]u8 = undefined; for (&punctuation, 0..) |*byte, i| byte.* = @intCast(0x21 + (i % 15)); try testing.expectEqual(Identity.unknown, identify(&punctuation, &buffer)); // And real words are reported. var message: [512]u8 = @splat(0); @memcpy(message[100..][0.."COPYRIGHT APPLE".len], "COPYRIGHT APPLE"); switch (identify(&message, &buffer)) { .guessed => |what| try testing.expect(std.mem.indexOf(u8, what, "COPYRIGHT APPLE") != null), else => return error.ShouldHaveBeenRead, } }