From 38c2262f1c398677dd28ced1c2cae65f8b56bad1 Mon Sep 17 00:00:00 2001 From: Lesserkuma Date: Wed, 28 Sep 2022 15:15:04 +0200 Subject: [PATCH] Add support for the Game Boy MBC6 mapper (ROM read) --- Cart_Reader/GB.ino | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index eeb2293..c0671d3 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -421,7 +421,7 @@ void showCartInfo_GB() { else if ((romType == 25) || (romType == 26) || (romType == 27) || (romType == 28) || (romType == 29) || (romType == 309)) print_Msg(F("MBC5")); else if (romType == 32) - print_Msg(F("MBC6 (no support)")); + print_Msg(F("MBC6")); else if (romType == 34) print_Msg(F("MBC7")); else if (romType == 252) @@ -924,18 +924,28 @@ void readROM_GB() { if (romType == 0x104) { startBank = 0; romBanks >>= 1; + endAddress = 0x7FFF; + } + // MBC6 banks are half size + else if (romType == 32) { + romBanks <<= 1; + endAddress = 0x3FFF; } for (word currBank = startBank; currBank < romBanks; currBank++) { // Second bank starts at 0x4000 if (currBank > 1) { romAddress = 0x4000; + + // MBC6 banks are half size + if (romType == 32) { + endAddress = 0x5FFF; + } } - // M161 banks are double size and need mapper reset + // Set ROM bank for M161 if (romType == 0x104) { romAddress = 0; - endAddress = 0x7FFF; PORTH &= ~(1 << 0); delay(50); PORTH |= (1 << 0); @@ -953,6 +963,14 @@ void readROM_GB() { } } + // Set ROM bank for MBC6 + else if (romType == 32) { + writeByte_GB(0x2800, 0); + writeByte_GB(0x3800, 0); + writeByte_GB(0x2000, currBank); + writeByte_GB(0x3000, currBank); + } + // Set ROM bank for TAMA5 else if (romType == 0xFD) { writeByteSRAM_GB(0xA001, 0);