Skip to content

Commit fb84bbb

Browse files
authored
patterns: More accurate variable declarations on nes.hexpat, add n64, gen, and gbx.hexpat (#477)
* Add n64, gen, and gbx.hexpat * Add n64, gbx, and gen.hexpat to README.md * Remove leftover string import from n64.hexpat * More accurate variable declarations on nes.hexpat * Add source to gbx.hexpat * Add accidentally missing curly brace in nes.hexpat
1 parent 097ab49 commit fb84bbb

File tree

5 files changed

+288
-21
lines changed

5 files changed

+288
-21
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
9797
| Flipper Zero Settings | | [`patterns/flipper_settings.hexpat`](patterns/flipper_settings.hexpat) | Flipper Zero Settings Files |
9898
| GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Game Boy ROM |
9999
| GBA | `application/x-gameboy-advance-rom` | [`patterns/gba.hexpat`](patterns/gba.hexpat) | Game Boy Advance ROM header |
100+
| GBX | | [`patterns/gbx.hexpat`](patterns/gbx.hexpat) | GameBoy ROM file GBX footer |
101+
| Gen | | [`patterns/gen.hexpat`](patterns/gen.hexpat) | Sega Genesis/MegaDrive ROM |
100102
| GGUF | | [`patterns/gguf.hexpat`](patterns/gguf.hexpat) | GGML Inference Models |
101103
| GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files |
102104
| GLTF | `model/gltf-binary` | [`patterns/gltf.hexpat`](patterns/gltf.hexpat) | GL Transmission Format binary 3D model file |
@@ -136,6 +138,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
136138
| MSSCMP | | [`patterns/msscmp.hexpat`](patterns/msscmp.hexpat) | Miles Sound System Compressed Archive |
137139
| NACP | | [`patterns/nacp.hexpat`](patterns/nacp.hexpat) | Nintendo Switch NACP files |
138140
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
141+
| N64 | | [`patterns/n64.hexpat`](patterns/n64.hexpat) | Nintendo 64 ROM header |
139142
| NDS | `application/x-nintendo-ds-rom` | [`patterns/nds.hexpat`](patterns/nds.hexpat) | DS Cartridge Header |
140143
| NE | `application/x-ms-ne-executable` | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
141144
| nes | | [`patterns/nes.hexpat`](patterns/nes.hexpat) | Nintendo Entertainment System ROM |

patterns/gbx.hexpat

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#pragma author gmestanley
2+
#pragma description GameBoy ROM file GBX footer
3+
#pragma source hhug.me/gbx/1.0
4+
5+
import gb;
6+
7+
bitfield SachenMMC2SolderPad {
8+
padding : 5;
9+
opt1 : 1;
10+
openBus512KiBOuterBanks : 1;
11+
openBus1MiBOuterBanks : 1;
12+
};
13+
14+
bitfield VastFameRunningValueType {
15+
TaiwanReleases : 1;
16+
MainlandChinaReleases : 1;
17+
};
18+
19+
enum VastFamePCBType : u8 {
20+
DSHGGB81,
21+
BCR1616T3P
22+
};
23+
24+
fn specialMapper(str value) { return value == "SAM2" || value == "VF01" || value == "GB81"; };
25+
26+
struct MapperVariables {
27+
match(parent.mapper) {
28+
("SAM2"): SachenMMC2SolderPad solderPadConfig;
29+
("VF01"): VastFameRunningValueType runningValue;
30+
("GB81"): VastFamePCBType pcb; }
31+
padding[3*specialMapper(parent.mapper)];
32+
u32 mapperVariables[8-specialMapper(parent.mapper)];
33+
};
34+
35+
struct CartridgeInformation {
36+
char mapper[4];
37+
bool battery;
38+
bool rumble;
39+
bool timer;
40+
padding[1];
41+
u32 romSize;
42+
u32 ramSize;
43+
if (specialMapper(mapper))
44+
MapperVariables mapperVariables;
45+
else
46+
MapperVariables mapperVariables [[inline]];
47+
};
48+
49+
struct GBXMetadata {
50+
u32 footerSize;
51+
u32 majorVersion;
52+
u32 minorVersion;
53+
char signature[4];
54+
};
55+
56+
struct GBXFooter {
57+
CartridgeInformation cartInfo;
58+
GBXMetadata metadata;
59+
};
60+
61+
be GBXFooter gbxFooter @ std::mem::size() - 0x40;

patterns/gen.hexpat

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#pragma author gmestanley
2+
#pragma description Sega Genesis/MegaDrive header
3+
#pragma source plutiedev.com/rom-header wiki.neogeodev.org/index.php?title=68k_vector_table
4+
5+
#pragma endian big
6+
7+
import std.string;
8+
9+
struct M68000Vectors {
10+
u32 stackPointerReset;
11+
u32 programCounterReset [[comment("Entry Point")]];
12+
u32 busError;
13+
u32 addressError;
14+
u32 illegalInstruction;
15+
u32 divisionByZero;
16+
u32 chkInstruction;
17+
u32 trapVInstruction;
18+
u32 privilegeViolation;
19+
u32 trace;
20+
u32 lineAInstruction;
21+
u32 lineFInstruction;
22+
padding[12];
23+
u32 uninitializedInterruptVector;
24+
padding[32];
25+
u32 spuriousInterrupt;
26+
u32 interruptAutovectors[7];
27+
u32 traps[16];
28+
};
29+
30+
M68000Vectors vectors @ 0x00;
31+
32+
struct Info {
33+
char softwareType[2];
34+
char space;
35+
char serialNumber[8];
36+
char dash;
37+
char revision[2];
38+
};
39+
40+
enum DeviceType : char {
41+
NotFilled = ' ',
42+
Button3Controller = 'J',
43+
Button6Controller = '6',
44+
MasterSystemController = '0',
45+
AnalogJoystick = 'A',
46+
Multitap = '4',
47+
Lightgun = 'G',
48+
Activator = 'L',
49+
Mouse = 'M',
50+
Trackball = 'B',
51+
Mouse = 'T',
52+
Trackball = 'V',
53+
Keyboard = 'K',
54+
RS232 = 'R',
55+
Printer = 'P',
56+
CDROM = 'C',
57+
FloppyDrive = 'F',
58+
Download = 'D'
59+
};
60+
61+
bitfield RAMType {
62+
addresses : 1;
63+
padding : 3;
64+
bits : 2;
65+
saves : 1;
66+
sig : 1;
67+
};
68+
69+
enum MemoryType : char {
70+
RAM = ' ',
71+
EEPROM = '@'
72+
};
73+
74+
struct ExtraMemory {
75+
char signature[2];
76+
RAMType ramType;
77+
MemoryType memoryType;
78+
u32 startAddress;
79+
u32 endAddress;
80+
};
81+
82+
fn renderMicrophoneType(str value) {
83+
match(value) {
84+
("00"): value = "NoMicJapanOnly";
85+
("10"): value = "MicJapanOnly";
86+
("20"): value = "NoMicOverseasOnly";
87+
("30"): value = "MicOverseasOnly";
88+
("40"): value = "NoMic";
89+
("50"): value = "Mic";
90+
("60"): value = "NoMicJapan";
91+
("70"): value = "NoMicOverseas";
92+
}
93+
};
94+
95+
struct ModemSupport {
96+
char signature[2];
97+
char publisher[4];
98+
char gameNumber[2];
99+
char comma;
100+
char version;
101+
char microphone[2] [[format("renderMicrophoneType")]];
102+
};
103+
104+
enum RegionType : char {
105+
None = ' ',
106+
Japan = 'J',
107+
Americas = 'U',
108+
Europe = 'E'
109+
};
110+
111+
fn formatTerminatedString(str string) {
112+
u8 index;
113+
while (index < std::string::length(string)) {
114+
if (std::mem::read_string($+index, 2) == " ")
115+
break;
116+
index += 1;
117+
}
118+
return "\"" + std::string::substr(string, 0, index) + "\"";
119+
};
120+
121+
struct Header {
122+
char systemType[16] [[format("formatTerminatedString")]];
123+
char copyright[16] [[format("formatTerminatedString")]];
124+
char domesticTitle[48] [[format("formatTerminatedString")]];
125+
char overseasTitle[48] [[format("formatTerminatedString")]];
126+
Info info;
127+
u16 checksum;
128+
DeviceType deviceType[16];
129+
u32 romAddressRange[2];
130+
u32 ramAddressRange[2];
131+
if ($[$] == 'R') ExtraMemory extraMemory; else padding[12];
132+
if ($[$] == 'M') ModemSupport modemSupport; else padding[12];
133+
padding[40];
134+
RegionType regions[3];
135+
};
136+
137+
Header header @ 0x100;

patterns/n64.hexpat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma author gmestanley
2+
#pragma description Nintendo 64 ROM header
3+
4+
char name[20] @ 0x20;

0 commit comments

Comments
 (0)