mirror of
https://github.com/risingPhil/PokeMe64.git
synced 2026-04-24 06:56:50 -05:00
Make validating Japanese save files work correctly
Turns out these Japanese cartridges are using an MBC1 controller. There's a notable difference between it and MBC3: by default it is doing banking mode 0. But in this mode, you can't switch SRAM banks! So in order to make japanese cartridges work, we must switch to mode 1.
This commit is contained in:
parent
8770a6e640
commit
34825889e6
|
|
@ -66,6 +66,22 @@ public:
|
|||
*/
|
||||
void switchGBSRAMBank(uint8_t bankIndex);
|
||||
|
||||
/**
|
||||
* For MBC1 controllers, this will effect the ROM or RAM modes, depending on what is written in $6000-$7FFF.
|
||||
* If the mode is 0 (default), the RAM bank will be locked to 0, but the extended banks (bankindex > 0x1F)
|
||||
* can be accessed in the 0x0000 - 0x3FFF range (thereby replacing bank 0) by modifying the 0x4000-0x5FFF registers.
|
||||
* However, in this mode, the RAM bank is locked to bank 0
|
||||
*
|
||||
* If the mode is 1, the RAM bank can be switched, but the extended rom banks (bankindex > 0x1F) can't be switched to.
|
||||
* In this mode 0x0000 - 0x3FFF is locked to rom bank 0.
|
||||
* Sources:
|
||||
* - https://retrocomputing.stackexchange.com/questions/11732/how-does-the-gameboys-memory-bank-switching-work
|
||||
* - https://gbdev.io/pandocs/MBC1.html
|
||||
*
|
||||
* For our use case though, we don't need mode 0.
|
||||
*/
|
||||
void switchMBC1BankingMode(uint8_t mode);
|
||||
|
||||
/**
|
||||
* @brief This function reads data from the specified gameboy address
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 46bc5bab2cc74661c9a81e582042a3a8549b873b
|
||||
Subproject commit 8dbbe0c015a3c899ff5d600ca376c34f1457c529
|
||||
|
|
@ -180,10 +180,24 @@ void TransferPakManager::switchGBSRAMBank(uint8_t bankIndex)
|
|||
writeBufferSRAMBankOffset_ = 0xFFFF;
|
||||
}
|
||||
|
||||
void TransferPakManager::switchMBC1BankingMode(uint8_t mode)
|
||||
{
|
||||
uint8_t data[TPAK_BLOCK_SIZE];
|
||||
|
||||
debugf("[TransferPakManager]: %s(%hhu)\r\n", __FUNCTION__, mode);
|
||||
// make sure to finish any writes in the write buffer before switching
|
||||
finishWrites();
|
||||
|
||||
memset(data, mode, TPAK_BLOCK_SIZE);
|
||||
tpak_write(port_, 0x6000, data, TPAK_BLOCK_SIZE);
|
||||
|
||||
// invalidate read and write buffer
|
||||
readBufferBankOffset_ = 0xFFFF;
|
||||
writeBufferSRAMBankOffset_ = 0xFFFF;
|
||||
}
|
||||
|
||||
void TransferPakManager::read(uint16_t gbAddress, uint8_t* data, uint16_t size)
|
||||
{
|
||||
// debugf("[TransferPakManager]: %s(0x%x, %p, %u)\r\n", __FUNCTION__, gbAddress, data, size);
|
||||
|
||||
uint16_t bytesRemaining = size;
|
||||
uint8_t* cur = data;
|
||||
|
||||
|
|
|
|||
|
|
@ -293,6 +293,20 @@ bool TransferPakDetectionWidget::validateGameboyHeader()
|
|||
return false;
|
||||
}
|
||||
|
||||
// For MBC1 cartridges, we need to set the MBC1 banking mode to 1.
|
||||
// If we don't, we can't actually switch SRAM banks.
|
||||
// It looks like only the Japanese cartridges use MBC1 though.
|
||||
switch(cartridgeHeader.cartridge_type)
|
||||
{
|
||||
case GB_MBC1_RAM:
|
||||
case GB_MBC1_RAM_BATTERY:
|
||||
tpakManager_.switchMBC1BankingMode(1);
|
||||
break;
|
||||
default:
|
||||
// We don't need to do anything
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user