Improve behaviour of MBC3 if statements.

This commit is contained in:
Emmet Young 2016-02-02 19:44:18 +11:00
parent aab625734d
commit 696d419e5b
1 changed files with 18 additions and 18 deletions

View File

@ -332,7 +332,15 @@ static void read_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, uint8_t
{ {
if (gb_cart->ram != NULL) if (gb_cart->ram != NULL)
{ {
if (gb_cart->has_rtc && (gb_cart->ram_bank >= 0x08 && gb_cart->ram_bank <= 0x0c)) if (gb_cart->ram_bank >= 0x00 && gb_cart->ram_bank <= 0x03)
{
offset = (address - 0xA000) + (gb_cart->ram_bank * 0x2000);
if (offset < gb_cart->ram_size)
{
memcpy(data, &gb_cart->ram[offset], 0x20);
}
}
else if (gb_cart->has_rtc)
{ {
switch (gb_cart->ram_bank) switch (gb_cart->ram_bank)
{ {
@ -353,14 +361,6 @@ static void read_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, uint8_t
break; break;
} }
} }
else
{
offset = (address - 0xA000) + (gb_cart->ram_bank * 0x2000);
if (offset < gb_cart->ram_size)
{
memcpy(data, &gb_cart->ram[offset], 0x20);
}
}
} }
} }
} }
@ -413,7 +413,15 @@ static void write_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, const
{ {
if (gb_cart->ram != NULL) if (gb_cart->ram != NULL)
{ {
if (gb_cart->has_rtc && (gb_cart->ram_bank >= 0x8 && gb_cart->ram_bank <= 0xC)) if (gb_cart->ram_bank >= 0x00 && gb_cart->ram_bank <= 0x03)
{
offset = (address - 0xA000) + (gb_cart->ram_bank * 0x2000);
if (offset < gb_cart->ram_size)
{
memcpy(&gb_cart->ram[offset], data, 0x20);
}
}
else if (gb_cart->has_rtc)
{ {
bank = data[0]; bank = data[0];
@ -444,14 +452,6 @@ static void write_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, const
break; break;
} }
} }
else
{
offset = (address - 0xA000) + (gb_cart->ram_bank * 0x2000);
if (offset < gb_cart->ram_size)
{
memcpy(&gb_cart->ram[offset], data, 0x20);
}
}
} }
} }
} }