Skip to content

Commit

Permalink
features: submapper support, g101
Browse files Browse the repository at this point in the history
- Adding support for NES2.0 headers
- IREM-G101 chip/board
  • Loading branch information
stelcheck committed Dec 9, 2020
1 parent 035aada commit 9fd17a7
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"filesystem": "cpp",
"memory_resource": "cpp",
"cinttypes": "cpp",
"__memory": "cpp"
"__memory": "cpp",
"random": "cpp"
}
}
3 changes: 3 additions & 0 deletions higan/fc/cartridge/board/board.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "bandai-fcg.cpp"
#include "discrete-74x139x74.cpp"
#include "hvc-fmr.cpp"
#include "irem-g101.cpp"
#include "jaleco-jf.cpp"
#include "jaleco-jf16.cpp"
#include "konami-vrc1.cpp"
Expand Down Expand Up @@ -152,6 +153,8 @@ auto Board::load(string manifest) -> Board* {
if(type == "BANDAI-FCG" ) return new BandaiFCG(document);
if(type == "DISCRETE-74x139x74") return new DISCRETE74x139x74(document);

if(type == "IREM-G101" ) return new IremG101(document);

if(type == "HVC-FMR" ) return new HVC_FMR(document);

if(type == "JALECO-JF" ) return new JalecoJF(document);
Expand Down
55 changes: 55 additions & 0 deletions higan/fc/cartridge/board/irem-g101.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
struct IremG101 : Board {
IremG101(Markup::Node& document) : Board(document), g101(*this, document) {
if(!document["game/board/mirror"]) {
settings.mirror = 0;
} else {
string mirror = document["game/board/mirror/mode"].text();
if(mirror == "screen-0") settings.mirror = 1;
if(mirror == "screen-1") settings.mirror = 2;
}
}

auto readPRG(uint addr) -> uint8 {
if((addr & 0x8000) == 0x8000) return prgrom.read(g101.prgAddress(addr));
if((addr & 0xe000) == 0x6000) return prgram.read(addr & 0x1fff);
return cpu.mdr();
}

auto writePRG(uint addr, uint8 data) -> void {
if((addr & 0x8000) == 0x8000) return g101.regWrite(addr, data);
if((addr & 0xe000) == 0x6000) return prgram.write(addr & 0x1fff, data);
}

auto readCHR(uint addr) -> uint8 {
if(addr & 0x2000) switch(settings.mirror) {
case 0: return ppu.readCIRAM(g101.ciramAddress(addr));
case 1: return ppu.readCIRAM((addr & 0x03ff) | 0x0000);
case 2: return ppu.readCIRAM((addr & 0x03ff) | 0x0400);
}
return Board::readCHR(g101.chrAddress(addr));
}

auto writeCHR(uint addr, uint8 data) -> void {
if(addr & 0x2000) switch(settings.mirror) {
case 0: return ppu.writeCIRAM(g101.ciramAddress(addr), data);
case 1: return ppu.writeCIRAM((addr & 0x03ff) | 0x0000, data);
case 2: return ppu.writeCIRAM((addr & 0x03ff) | 0x0400, data);
}
return Board::writeCHR(g101.chrAddress(addr), data);
}

auto power(bool reset) -> void {
g101.power(reset);
}

auto serialize(serializer& s) -> void {
Board::serialize(s);
g101.serialize(s);
}

struct Settings {
uint2 mirror; //0 = G101-controlled, 1 = screen 0, 2 = screen 1
} settings;

G101 g101;
};
1 change: 1 addition & 0 deletions higan/fc/cartridge/chip/chip.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "g101.cpp"
#include "n108.cpp"
#include "n163.cpp"
#include "mmc1.cpp"
Expand Down
79 changes: 79 additions & 0 deletions higan/fc/cartridge/chip/g101.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
struct G101 : Chip {
G101(Board& board, Markup::Node& boardNode) : Chip(board) {
}

auto prgAddress(uint addr) const -> uint {
switch(addr & 0xe000) {
case 0x8000:
if(prgMode == 1) return (0x1e << 13) | (addr & 0x1fff);
return (prgBank[0] << 13) | (addr & 0x1fff);
case 0xa000:
return (prgBank[1] << 13) | (addr & 0x1fff);
case 0xc000:
if(prgMode == 0) return (0x1e << 13) | (addr & 0x1fff);
return (prgBank[0] << 13) | (addr & 0x1fff);
case 0xe000:
return (0x1f << 13) | (addr & 0x1fff);
}
unreachable;
}

auto chrAddress(uint addr) const -> uint {
return (chrBank[addr >> 10] << 10) | (addr & 0x03ff);
}

auto ciramAddress(uint addr) const -> uint {
switch(mirror) {
case 0: return (addr & 0x03ff) | ((addr & 0x0400) >> 0);
case 1: return (addr & 0x03ff) | ((addr & 0x0800) >> 1);
}
unreachable;
}

auto regWrite(uint addr, uint8 data) -> void {
switch(addr & 0xf000) {
case 0x8000:
prgBank[0] = data & 0x1f;
break;
case 0x9000:
mirror = data & 0x01;
prgMode = data & 0x02;
break;
case 0xa000:
prgBank[1] = data & 0x1f;
break;
case 0xb000:
chrBank[addr & 0x0007] = data;
break;
}
}

auto power(bool reset) -> void {
if(!reset) {
prgMode = 0;
prgBank[0] = 0x00;
prgBank[1] = 0x1e;
chrBank[0] = 0;
chrBank[1] = 0;
chrBank[2] = 0;
chrBank[3] = 0;
chrBank[4] = 0;
chrBank[5] = 0;
chrBank[6] = 0;
chrBank[7] = 0;
mirror = 0;
}
}

auto serialize(serializer& s) -> void {
s.integer(prgMode);
s.array(prgBank);
s.array(chrBank);
s.integer(mirror);
}

bool prgMode;
uint5 prgBank[2];
uint8 chrBank[8];
bool mirror;
};
26 changes: 23 additions & 3 deletions icarus/cartridge/famicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ auto Famicom::heuristicsINES(vector<uint8_t>& data, string location) -> string {
uint chrram = chrrom == 0u ? 8192u : 0u;
uint eeprom = 0u;

bool nes2 = (data[7] & 0x0c) == 0x08;
uint submapper = 0u;

if (nes2) {
submapper = data[8] >> 4;
prgrom += (data[9] & 0x0f) * 0x400000;
chrrom += (data[9] >> 4) * 0x200000;
prgram = ((data[10] & 0x0f) == 0 ? 0 : 64) << (data[10] & 0x0f); //no battery
prgram += ((data[10] >> 4) == 0 ? 0 : 64) << (data[10] >> 4); //battery
chrram = ((data[11] & 0x0f) == 0 ? 0 : 64) << (data[11] & 0x0f); //no battery
chrram += ((data[11] >> 4) == 0 ? 0 : 64) << (data[11] >> 4); //battery

}

string s;
s += "game\n";
s +={" name: ", Media::name(location), "\n"};
Expand Down Expand Up @@ -178,6 +192,13 @@ auto Famicom::heuristicsINES(vector<uint8_t>& data, string location) -> string {
s += " chip type=VRC6\n";
prgram = 8192;
break;

case 32:
s += " board: IREM-G101\n";
s += " chip type=G-101\n";
if(submapper == 1) s +={" mirror mode=screen-1\n"};
break;


case 34:
s += " board: NES-BNROM\n";
Expand Down Expand Up @@ -220,10 +241,8 @@ auto Famicom::heuristicsINES(vector<uint8_t>& data, string location) -> string {
break;

case 78:
// Todo: adde NES 2.0 support to correctly detect the submapper; this will be needed
// for Holy Diver to work correctly
s += " board: JALECO-JF16\n";
s += " submapper id=1\n";
s += {" submapper id=", submapper, "\n"};
break;

case 85:
Expand Down Expand Up @@ -321,6 +340,7 @@ auto Famicom::heuristicsINES(vector<uint8_t>& data, string location) -> string {
s += " content: Save\n";
}

printf("%s\n", s.data());
return s;
}

Expand Down

0 comments on commit 9fd17a7

Please sign in to comment.