2015-11-21 07:36:48 +00:00
|
|
|
auto Cartridge::MBC1::mmio_read(uint16 addr) -> uint8 {
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xc000) == 0x0000) { //$0000-3fff
|
2011-01-02 04:46:54 +00:00
|
|
|
return cartridge.rom_read(addr);
|
|
|
|
}
|
|
|
|
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xc000) == 0x4000) { //$4000-7fff
|
2011-01-04 10:42:27 +00:00
|
|
|
if(mode_select == 0) {
|
|
|
|
return cartridge.rom_read((ram_select << 19) | (rom_select << 14) | (addr & 0x3fff));
|
|
|
|
} else {
|
|
|
|
return cartridge.rom_read((rom_select << 14) | (addr & 0x3fff));
|
|
|
|
}
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xe000) == 0xa000) { //$a000-bfff
|
2011-01-04 10:42:27 +00:00
|
|
|
if(ram_enable) {
|
|
|
|
if(mode_select == 0) {
|
|
|
|
return cartridge.ram_read(addr & 0x1fff);
|
|
|
|
} else {
|
|
|
|
return cartridge.ram_read((ram_select << 13) | (addr & 0x1fff));
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 09:23:46 +00:00
|
|
|
return 0xff;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
2011-01-04 10:42:27 +00:00
|
|
|
|
2016-01-08 09:23:46 +00:00
|
|
|
return 0xff;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto Cartridge::MBC1::mmio_write(uint16 addr, uint8 data) -> void {
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xe000) == 0x0000) { //$0000-1fff
|
2011-01-02 04:46:54 +00:00
|
|
|
ram_enable = (data & 0x0f) == 0x0a;
|
2011-01-04 10:42:27 +00:00
|
|
|
return;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xe000) == 0x2000) { //$2000-3fff
|
2011-01-04 10:42:27 +00:00
|
|
|
rom_select = (data & 0x1f) + ((data & 0x1f) == 0);
|
|
|
|
return;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xe000) == 0x4000) { //$4000-5fff
|
2011-01-02 04:46:54 +00:00
|
|
|
ram_select = data & 0x03;
|
2011-01-04 10:42:27 +00:00
|
|
|
return;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xe000) == 0x6000) { //$6000-7fff
|
2011-01-02 04:46:54 +00:00
|
|
|
mode_select = data & 0x01;
|
2011-01-04 10:42:27 +00:00
|
|
|
return;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 10:49:48 +00:00
|
|
|
if((addr & 0xe000) == 0xa000) { //$a000-bfff
|
2011-01-04 10:42:27 +00:00
|
|
|
if(ram_enable) {
|
|
|
|
if(mode_select == 0) {
|
|
|
|
cartridge.ram_write(addr & 0x1fff, data);
|
|
|
|
} else {
|
|
|
|
cartridge.ram_write((ram_select << 13) | (addr & 0x1fff), data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2011-01-02 04:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto Cartridge::MBC1::power() -> void {
|
2011-01-02 04:46:54 +00:00
|
|
|
ram_enable = false;
|
|
|
|
rom_select = 0x01;
|
|
|
|
ram_select = 0x00;
|
|
|
|
mode_select = 0;
|
|
|
|
}
|