From 36cbb48fc052a59300546f9149b80c23a78214b5 Mon Sep 17 00:00:00 2001 From: Geky Date: Wed, 20 Nov 2024 17:16:38 +0100 Subject: [PATCH 1/4] add support for cartridge size type $54 Added support for cartridge size type $54, corresponding to 1.5 MiB (96 banks). --- patterns/gb.hexpat | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/patterns/gb.hexpat b/patterns/gb.hexpat index 79d0d33c..a947554a 100644 --- a/patterns/gb.hexpat +++ b/patterns/gb.hexpat @@ -33,6 +33,10 @@ namespace format { romSize = 1258291; romBanks = 80; } + if (cartSizeType == 0x54) { + romSize = 1572864; + romBanks = 96; + } return std::format("size: {}, banks: {}", type::impl::size_formatter(romSize), romBanks); }; From 254a761fbda171a31686799516fbc29c9ab22d4b Mon Sep 17 00:00:00 2001 From: Geky Date: Wed, 20 Nov 2024 17:24:41 +0100 Subject: [PATCH 2/4] add missing license --- patterns/gb.hexpat | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/patterns/gb.hexpat b/patterns/gb.hexpat index a947554a..0bce2312 100644 --- a/patterns/gb.hexpat +++ b/patterns/gb.hexpat @@ -135,6 +135,7 @@ namespace format { (0x46 | 0xCF): return "Angel"; (0x47): return "Spectrum Holoby"; (0x49): return "Irem"; + (0x4F): return "U.S. Gold"; (0x50): return "Absolute"; (0x51 | 0xB0): return "Acclaim"; (0x52): return "Activision"; @@ -221,6 +222,7 @@ namespace format { (0xE8): return "Asmik"; (0xE9): return "Natsume"; (0xEA): return "King Records"; + (0xEC): return "Epic/Sony Records"; (0xEE): return "IGS"; (0xF0): return "A Wave"; (0xF3): return "Extreme Entertainment"; @@ -291,7 +293,10 @@ namespace format { ("96"): return "Yonezawa/s’pal"; ("97"): return "Kaneko"; ("99"): return "Pack in soft"; + ("9H"): return "Bottom Up"; ("A4"): return "Konami (Yu-Gi-Oh!)"; + ("BL"): return "MTO"; + ("DK"): return "Kodansha"; } return "Unknown"; }; From ff998890e1856fe16892dee9f5838b42eb093cc3 Mon Sep 17 00:00:00 2001 From: Geky Date: Sun, 24 Nov 2024 19:30:36 +0100 Subject: [PATCH 3/4] Add GBA Cartridge Header --- patterns/gba.hexpat | 175 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 patterns/gba.hexpat diff --git a/patterns/gba.hexpat b/patterns/gba.hexpat new file mode 100644 index 00000000..3e6cb7ad --- /dev/null +++ b/patterns/gba.hexpat @@ -0,0 +1,175 @@ +#pragma author GekySan +#pragma description Game Boy Advance ROM Header + +#pragma MIME application/x-gameboy-advance-rom +#pragma MIME application/x-agb-rom +#pragma MIME application/x-gba-rom + +import std.string; +import std.mem; +import std.sys; + +// In gb.hexpat +namespace format { + fn licensee_code(str code) { + match(code) { + ("00"): return "None"; + ("01" | "31"): return "Nintendo"; + ("08" | "38"): return "Capcom"; + ("09"): return "Hot-B"; + ("0A" | "E0"): return "Jaleco"; + ("0B"): return "Coconuts Japan"; + ("0C" | "6E"): return "Elite Systems"; + ("13" | "69"): return "EA (Electronic Arts)"; + ("18"): return "Hudsonsoft"; + ("19"): return "ITC Entertainment"; + ("1A"): return "Yanoman"; + ("1D"): return "Japan Clary"; + ("1F" | "4A" | "61"): return "Virgin Interactive"; + ("24"): return "PCM Complete"; + ("25"): return "San-X"; + ("28"): return "Kotobuki Systems"; + ("29"): return "Seta"; + ("30" | "70"): return "Infogrames"; + ("32" | "A2" | "B2" | "C4"): return "Bandai"; + ("33"): return "See new licensee code"; + ("34" | "A4"): return "Konami"; + ("35"): return "HectorSoft"; + ("39" | "9D"): return "Banpresto"; + ("3C"): return ".Entertainment i"; + ("3E"): return "Gremlin"; + ("41"): return "Ubisoft"; + ("42" | "EB"): return "Atlus"; + ("44" | "4D"): return "Malibu"; + ("46" | "CF"): return "Angel"; + ("47"): return "Spectrum Holoby"; + ("49"): return "Irem"; + ("4F"): return "U.S. Gold"; + ("50"): return "Absolute"; + ("51" | "B0"): return "Acclaim"; + ("52"): return "Activision"; + ("53"): return "American Sammy"; + ("54"): return "GameTek"; + ("55"): return "Park Place"; + ("56" | "DB" | "FF"): return "LJN"; + ("57"): return "Matchbox"; + ("59"): return "Milton Bradley"; + ("5A"): return "Mindscape"; + ("5B"): return "Romstar"; + ("5C" | "D6"): return "Naxat Soft"; + ("5D"): return "Tradewest"; + ("60"): return "Titus"; + ("67"): return "Ocean Interactive"; + ("6F"): return "Electro Brain"; + ("71"): return "Interplay"; + ("72" | "AA"): return "Broderbund"; + ("73"): return "Sculptered Soft"; + ("75"): return "The Sales Curve"; + ("78"): return "t.hq"; + ("79"): return "Accolade"; + ("7A"): return "Triffix Entertainment"; + ("7C"): return "Microprose"; + ("7F" | "C2"): return "Kemco"; + ("80"): return "Misawa Entertainment"; + ("83"): return "Lozc"; + ("86" | "C4"): return "Tokuma Shoten Intermedia"; + ("8B"): return "Bullet-Proof Software"; + ("8C"): return "Vic Tokai"; + ("8E"): return "Ape"; + ("8F"): return "I'Max"; + ("91"): return "Chunksoft Co."; + ("92"): return "Video System"; + ("93"): return "Tsubaraya Productions Co."; + ("95"): return "Varie Corporation"; + ("96"): return "Yonezawa/S’Pal"; + ("97"): return "Kaneko"; + ("99"): return "Arc"; + ("9A"): return "Nihon Bussan"; + ("9B"): return "Tecmo"; + ("9C"): return "Imagineer"; + ("9F"): return "Nova"; + ("A1"): return "Hori Electric"; + ("A6"): return "Kawada"; + ("A7"): return "Takara"; + ("A9"): return "Technos Japan"; + ("AC"): return "Toei Animation"; + ("AD"): return "Toho"; + ("AF"): return "Namco"; + ("B1"): return "ASCII or Nexsoft"; + ("B4"): return "Square Enix"; + ("B6"): return "HAL Laboratory"; + ("B7"): return "SNK"; + ("B9" | "CE"): return "Pony Canyon"; + ("BA"): return "Culture Brain"; + ("BB"): return "Sunsoft"; + ("BD"): return "Sony Imagesoft"; + ("BF"): return "Sammy"; + ("C0" | "D0"): return "Taito"; + ("C3"): return "Squaresoft"; + ("C5"): return "Data East"; + ("C6"): return "Tonkinhouse"; + ("C8"): return "Koei"; + ("C9"): return "UFL"; + ("CA"): return "Ultra"; + ("CB"): return "Vap"; + ("CC"): return "Use Corporation"; + ("CD"): return "Meldac"; + ("D1"): return "Sofel"; + ("D2"): return "Quest"; + ("D3"): return "Sigma Enterprises"; + ("D4"): return "ASK Kodansha Co."; + ("D7"): return "Copya System"; + ("DA"): return "Tomy"; + ("DD"): return "NCS"; + ("DE"): return "Human"; + ("DF"): return "Altron"; + ("E1"): return "Towa Chiki"; + ("E2"): return "Yutaka"; + ("E3"): return "Varie"; + ("E5"): return "Epoch"; + ("E7"): return "Athena"; + ("E8"): return "Asmik"; + ("E9"): return "Natsume"; + ("EA"): return "King Records"; + ("EC"): return "Epic/Sony Records"; + ("EE"): return "IGS"; + ("F0"): return "A Wave"; + ("F3"): return "Extreme Entertainment"; + } + return "Unknown Licensee"; + }; +} + +fn calcChecksum() { + u8 sum = 0; + u8 offset = 0xA0; + + while (offset <= 0xBC) { + sum += std::mem::read_unsigned(offset, 1); + offset += 1; + } + + return ((-((0x19 + sum) & 0xFF)) & 0xFF) == std::mem::read_unsigned(0xBD, 1); +}; + +struct GBAHeader { + u8 entryPoint[4] [[comment("ARM entry point code, typically a 'B rom_start' instruction")]]; + u8 nintendoLogo[156] [[comment("Nintendo logo")]]; + char gameTitle[12] [[comment("Game title, uppercase ASCII, max 12 characters")]]; + char gameCode[4] [[comment("Game code, uppercase ASCII, 4 characters")]]; + char makerCode[2] [[format("format::licensee_code"), comment("Maker code, uppercase ASCII, 2 characters")]]; + u8 fixedValue [[comment("Fixed value, must be 0x96")]]; + u8 unitCode [[comment("Main unit code, identifies required hardware (00h for GBA)")]]; + u8 deviceType [[comment("Device type, usually 00h. Bit 7 relates to DACS/debug features")]]; + u8 reserved1[7] [[comment("Reserved area, must be zero-filled")]]; + u8 softwareVersion [[comment("Software version number, usually 00h")]]; + u8 complementCheck [[comment("Header checksum, required for validation")]]; + u8 reserved2[2] [[comment("Reserved area, must be zero-filled")]]; +}; + + +if (!calcChecksum()) { + std::error("Checksum validation failed: Calculated value does not match the expected checksum in the header."); +} + +GBAHeader gbaHeader @ 0x0000; From 67836e847cb4f0cc1948ac14aa8994390aa8c29b Mon Sep 17 00:00:00 2001 From: Geky Date: Sun, 24 Nov 2024 19:35:04 +0100 Subject: [PATCH 4/4] Update README.md Added GBA information to README.md and corrected a typo. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 89ee9a1a..f5786eef 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi | File System | | [`patterns/fs.hexpat`](patterns/fs.hexpat) | Drive File System | | FLAC | `audio/flac` | [`patterns/flac.hexpat`](patterns/flac.hexpat) | Free Lossless Audio Codec, FLAC Audio Format | | Flipper Zero Settings | | [`patterns/flipper_settings.hexpat`](patterns/flipper_settings.hexpat) | Flipper Zero Settings Files | -| GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Gameboy ROM | +| GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Game Boy ROM | +| GBA | `application/x-gameboy-advance-rom` | [`patterns/gba.hexpat`](patterns/gba.hexpat) | Game Boy Advance ROM header | | GGUF | | [`patterns/gguf.hexpat`](patterns/gguf.hexpat) | GGML Inference Models | | GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files | | GLTF | `model/gltf-binary` | [`patterns/gltf.hexpat`](patterns/gltf.hexpat) | GL Transmission Format binary 3D model file |