Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| 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) | Game Boy ROM |
| GBA | `application/x-gameboy-advance-rom` | [`patterns/gba.hexpat`](patterns/gba.hexpat) | Game Boy Advance ROM header |
| GBX | | [`patterns/gbx.hexpat`](patterns/gbx.hexpat) | GameBoy ROM file GBX footer |
| Gen | | [`patterns/gen.hexpat`](patterns/gen.hexpat) | Sega Genesis/MegaDrive ROM |
| 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 |
Expand Down Expand Up @@ -136,6 +138,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| MSSCMP | | [`patterns/msscmp.hexpat`](patterns/msscmp.hexpat) | Miles Sound System Compressed Archive |
| NACP | | [`patterns/nacp.hexpat`](patterns/nacp.hexpat) | Nintendo Switch NACP files |
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
| N64 | | [`patterns/n64.hexpat`](patterns/n64.hexpat) | Nintendo 64 ROM header |
| NDS | `application/x-nintendo-ds-rom` | [`patterns/nds.hexpat`](patterns/nds.hexpat) | DS Cartridge Header |
| NE | `application/x-ms-ne-executable` | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
| nes | | [`patterns/nes.hexpat`](patterns/nes.hexpat) | Nintendo Entertainment System ROM |
Expand Down
61 changes: 61 additions & 0 deletions patterns/gbx.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma author gmestanley
#pragma description GameBoy ROM file GBX footer
#pragma source hhug.me/gbx/1.0

import gb;

bitfield SachenMMC2SolderPad {
padding : 5;
opt1 : 1;
openBus512KiBOuterBanks : 1;
openBus1MiBOuterBanks : 1;
};

bitfield VastFameRunningValueType {
TaiwanReleases : 1;
MainlandChinaReleases : 1;
};

enum VastFamePCBType : u8 {
DSHGGB81,
BCR1616T3P
};

fn specialMapper(str value) { return value == "SAM2" || value == "VF01" || value == "GB81"; };

struct MapperVariables {
match(parent.mapper) {
("SAM2"): SachenMMC2SolderPad solderPadConfig;
("VF01"): VastFameRunningValueType runningValue;
("GB81"): VastFamePCBType pcb; }
padding[3*specialMapper(parent.mapper)];
u32 mapperVariables[8-specialMapper(parent.mapper)];
};

struct CartridgeInformation {
char mapper[4];
bool battery;
bool rumble;
bool timer;
padding[1];
u32 romSize;
u32 ramSize;
if (specialMapper(mapper))
MapperVariables mapperVariables;
else
MapperVariables mapperVariables [[inline]];
};

struct GBXMetadata {
u32 footerSize;
u32 majorVersion;
u32 minorVersion;
char signature[4];
};

struct GBXFooter {
CartridgeInformation cartInfo;
GBXMetadata metadata;
};

be GBXFooter gbxFooter @ std::mem::size() - 0x40;
137 changes: 137 additions & 0 deletions patterns/gen.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#pragma author gmestanley
#pragma description Sega Genesis/MegaDrive header
#pragma source plutiedev.com/rom-header wiki.neogeodev.org/index.php?title=68k_vector_table

#pragma endian big

import std.string;

struct M68000Vectors {
u32 stackPointerReset;
u32 programCounterReset [[comment("Entry Point")]];
u32 busError;
u32 addressError;
u32 illegalInstruction;
u32 divisionByZero;
u32 chkInstruction;
u32 trapVInstruction;
u32 privilegeViolation;
u32 trace;
u32 lineAInstruction;
u32 lineFInstruction;
padding[12];
u32 uninitializedInterruptVector;
padding[32];
u32 spuriousInterrupt;
u32 interruptAutovectors[7];
u32 traps[16];
};

M68000Vectors vectors @ 0x00;

struct Info {
char softwareType[2];
char space;
char serialNumber[8];
char dash;
char revision[2];
};

enum DeviceType : char {
NotFilled = ' ',
Button3Controller = 'J',
Button6Controller = '6',
MasterSystemController = '0',
AnalogJoystick = 'A',
Multitap = '4',
Lightgun = 'G',
Activator = 'L',
Mouse = 'M',
Trackball = 'B',
Mouse = 'T',
Trackball = 'V',
Keyboard = 'K',
RS232 = 'R',
Printer = 'P',
CDROM = 'C',
FloppyDrive = 'F',
Download = 'D'
};

bitfield RAMType {
addresses : 1;
padding : 3;
bits : 2;
saves : 1;
sig : 1;
};

enum MemoryType : char {
RAM = ' ',
EEPROM = '@'
};

struct ExtraMemory {
char signature[2];
RAMType ramType;
MemoryType memoryType;
u32 startAddress;
u32 endAddress;
};

fn renderMicrophoneType(str value) {
match(value) {
("00"): value = "NoMicJapanOnly";
("10"): value = "MicJapanOnly";
("20"): value = "NoMicOverseasOnly";
("30"): value = "MicOverseasOnly";
("40"): value = "NoMic";
("50"): value = "Mic";
("60"): value = "NoMicJapan";
("70"): value = "NoMicOverseas";
}
};

struct ModemSupport {
char signature[2];
char publisher[4];
char gameNumber[2];
char comma;
char version;
char microphone[2] [[format("renderMicrophoneType")]];
};

enum RegionType : char {
None = ' ',
Japan = 'J',
Americas = 'U',
Europe = 'E'
};

fn formatTerminatedString(str string) {
u8 index;
while (index < std::string::length(string)) {
if (std::mem::read_string($+index, 2) == " ")
break;
index += 1;
}
return "\"" + std::string::substr(string, 0, index) + "\"";
};

struct Header {
char systemType[16] [[format("formatTerminatedString")]];
char copyright[16] [[format("formatTerminatedString")]];
char domesticTitle[48] [[format("formatTerminatedString")]];
char overseasTitle[48] [[format("formatTerminatedString")]];
Info info;
u16 checksum;
DeviceType deviceType[16];
u32 romAddressRange[2];
u32 ramAddressRange[2];
if ($[$] == 'R') ExtraMemory extraMemory; else padding[12];
if ($[$] == 'M') ModemSupport modemSupport; else padding[12];
padding[40];
RegionType regions[3];
};

Header header @ 0x100;
4 changes: 4 additions & 0 deletions patterns/n64.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma author gmestanley
#pragma description Nintendo 64 ROM header

char name[20] @ 0x20;
Loading