Skip to content

Commit

Permalink
be suspicious about NES files claiming to have more banks than are ac…
Browse files Browse the repository at this point in the history
…tually in the file

If you can't write in the proper way
If you don't know how to conjugate
Maybe you flunked that class
And maybe now you find
That people mock you online
  • Loading branch information
andrew-hoffman committed Jul 28, 2015
1 parent aa3d43b commit a4aa6e6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/com/grapeshot/halfnes/ROMLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ public void parseHeader() throws BadMapperException {
//submapper number is the high 4 bits of byte 8
submapper = (header[8] >> 4);
//extra prg and chr bits in byte 9
prgsize = 16384 * (header[4] + ((header[9] & 15) << 8));
prgsize = Math.min(therom.length - 16,
16384 * (header[4] + ((header[9] & 15) << 8)));
if (prgsize == 0) {
throw new BadMapperException("No PRG ROM size in header");
}
chrsize = 8192 * (header[5] + ((header[9] >> 4) << 8));
chrsize = Math.min(therom.length - 16 - prgsize,
8192 * (header[5] + ((header[9] >> 4) << 8)));
//prg ram size in header byte 10
//chr ram size byte 11
//tv type is byte 12
Expand All @@ -82,15 +84,15 @@ public void parseHeader() throws BadMapperException {

} else {
//nes 1 format, with hacks
prgsize = 16384 * header[4];
prgsize = Math.min(therom.length - 16, 16384 * header[4]);
if (prgsize == 0) {
throw new BadMapperException("No PRG ROM size in header");
//someone made this field zero on a 4mb multicart ROM
//and someone ELSE made this zero for an 8k PRG dump (no-intro)
//so if anyone gets this error make some heuristics to fix it.
//basically no multicarts > 2mb in iNES 1.0 format
}
chrsize = 8192 * header[5];
chrsize = Math.min(therom.length - 16 - prgsize, 8192 * header[5]);
if (header[11] + header[12] + header[13] + header[14]
+ header[15] == 0) {
//only consider upper bytes of mapper # if the end bytes are zero
Expand Down

0 comments on commit a4aa6e6

Please sign in to comment.