Skip to content

Commit dc7bdd8

Browse files
committed
Support roms with no CHR-ROM but CHR-RAM
1 parent e7bf212 commit dc7bdd8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/nes/gamePak/factory.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ func CreateGamePakFromROMFile(romFilePath string) GamePak {
3838
prgLength := int(inesHeader.ProgramSize())*0x4000 + 16
3939
prgROM := data[16:prgLength]
4040

41-
chrLength := int(inesHeader.CHRSize()) * 0x2000
42-
chrROM := data[prgLength : chrLength+prgLength]
41+
var chrROM []byte
42+
chrLength := int(inesHeader.CHRSize())
43+
if chrLength == 0 {
44+
chrLength = 8 * 0x2000
45+
chrROM = make([]byte, chrLength)
46+
} else {
47+
chrLength *= 0x2000
48+
chrROM = data[prgLength : chrLength+prgLength]
49+
}
4350
return CreateGamePak(
4451
inesHeader,
4552
prgROM,

src/nes/gamePak/iNes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (ines INesHeader) TvSystem() byte {
6868
}
6969

7070
func CreateINes1Header(prgRomSize byte, chrRomSize byte, flag6 byte, flag7 byte, flag8 byte, flag9 byte, flag10 byte) INesHeader {
71+
// If the header CHR-ROM value is 0, we should assume that 8KB of CHR-RAM is available.
7172
return INesHeader{
7273
prgROMSize: prgRomSize,
7374
chrROMSize: chrRomSize,

0 commit comments

Comments
 (0)