SMS: Add Korea BIOS support

This commit is contained in:
alyosha-tas 2018-01-01 12:04:07 -05:00
parent 06201a1c4f
commit 353fec4f00
5 changed files with 81 additions and 7 deletions

View File

@ -124,13 +124,16 @@ namespace BizHawk.Emulation.Common
var sms_jp_21 = File("A8C1B39A2E41137835EDA6A5DE6D46DD9FADBAF2", 8192, "sms_jp_2.1.sms", "SMS BIOS 2.1 (Japan)");
var sms_us_1b = File("29091FF60EF4C22B1EE17AA21E0E75BAC6B36474", 8192, "sms_us_1.0b.sms", "SMS BIOS 1.0 (USA) (Proto)"); // ?? is this size correct?
var sms_m404 = File("4A06C8E66261611DCE0305217C42138B71331701", 8192, "sms_m404.sms", "SMS BIOS (USA) (M404) (Proto)"); // ?? is this size correct?
var sms_kr = File("2FEAFD8F1C40FDF1BD5668F8C5C02E5560945B17", 131072, "sms_kr.sms", "SMS BIOS (Kr)"); // ?? is this size correct?
Firmware("SMS", "Export", "SMS Bios (USA/Export)");
Firmware("SMS", "Japan", "SMS Bios (Japan)");
Firmware("SMS", "Korea", "SMS Bios (Korea)");
Option("SMS", "Export", sms_us_13);
Option("SMS", "Export", sms_us_1b);
Option("SMS", "Export", sms_m404);
Option("SMS", "Japan", sms_jp_21);
Option("SMS", "Korea", sms_kr);
// PSX
// http://forum.fobby.net/index.php?t=msg&goto=2763 [f]

View File

@ -1,4 +1,6 @@
namespace BizHawk.Emulation.Cores.Sega.MasterSystem
using System;
namespace BizHawk.Emulation.Cores.Sega.MasterSystem
{
public partial class SMS
{
@ -8,9 +10,32 @@
byte ReadMemoryKR(ushort address)
{
if (address < 0x8000) return RomData[address & 0x7FFF];
if (address < 0xC000) return RomData[(RomBank2 * BankSize) + (address & BankSizeMask)];
return SystemRam[address & RamSizeMask];
if (address < 0xC000)
{
if ((Port3E & 0x48) == 0x48) // cart and bios disabled, return empty bus
return 0xFF;
if (BiosMapped && BiosRom != null)
{
// korean BIOS (and a couple of rarer BIOses) use memory slot 2 mechanics as needed
if (address < 0x8000)
{
return BiosRom[address];
}
else
{
return BiosRom[(Bios_bank * BankSize) + (address & BankSizeMask)];
}
}
else
{
if (address < 0x8000) return RomData[address & 0x7FFF];
else return RomData[(RomBank2 * BankSize) + (address & BankSizeMask)];
}
}
else
{
return SystemRam[address & RamSizeMask];
}
}
CDLog_MapResults MapMemoryKR(ushort address, bool write)
@ -26,6 +51,11 @@
SystemRam[address & RamSizeMask] = value;
else if (address == 0xA000)
RomBank2 = (byte)(value % RomBanks);
if ((address == 0xFFFF) && BiosMapped)
{
Bios_bank = value;
}
}
void InitKoreaMapper()
@ -36,6 +66,7 @@
RomBank0 = 0;
RomBank1 = 1;
RomBank2 = 2;
Bios_bank = 2;
}
// ======================================================================

View File

@ -30,7 +30,32 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
if ((Port3E & 0x48) == 0x48) // cart and bios disabled, return empty bus
ret = 0xFF;
else if (BiosMapped && BiosRom != null)
ret = BiosRom[address & 0x1FFF];
{
if (BiosRom.Length == 0x2000)
{
ret = BiosRom[address & 0x1FFF];
}
else
{
// korean BIOS (and a couple of rarer BIOses) use memory slot 2 mechanics as needed
if (address < 0x8000)
{
return BiosRom[address];
}
else
{
switch (SaveRamBank)
{
case 0: ret = BiosRom[(Bios_bank * BankSize) + (address & BankSizeMask)]; break;
case 1: if (SaveRAM != null) ret = SaveRAM[(address & BankSizeMask) % SaveRAM.Length]; break;
case 2: if (SaveRAM != null) ret = SaveRAM[(BankSize + (address & BankSizeMask)) % SaveRAM.Length]; break;
default:
ret = SystemRam[address & RamSizeMask];
break;
}
}
}
}
else if (address < 1024)
ret = RomData[address];
else if (address < 0x4000)
@ -125,7 +150,17 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
}
else if (address == 0xFFFD) RomBank0 = (byte)(value % RomBanks);
else if (address == 0xFFFE) RomBank1 = (byte)(value % RomBanks);
else if (address == 0xFFFF) RomBank2 = (byte)(value % RomBanks);
else if (address == 0xFFFF)
{
if (BiosMapped)
{
Bios_bank = (byte)value;
}
else
{
RomBank2 = (byte)(value % RomBanks);
}
}
return;
}
}
@ -139,6 +174,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
WriteMemorySega(0xFFFD, 0);
WriteMemorySega(0xFFFE, 1);
WriteMemorySega(0xFFFF, 2);
Bios_bank = 2;
}
// Mapper when loading a BIOS as a ROM (simulating no cart loaded)

View File

@ -61,6 +61,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
ser.Sync("RomBank1", ref RomBank1);
ser.Sync("RomBank2", ref RomBank2);
ser.Sync("RomBank3", ref RomBank3);
ser.Sync("Bios_bank", ref Bios_bank);
ser.Sync("Port01", ref Port01);
ser.Sync("Port02", ref Port02);
ser.Sync("Port3E", ref Port3E);

View File

@ -195,6 +195,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
// ROM
private byte[] RomData;
private byte RomBank0, RomBank1, RomBank2, RomBank3;
private byte Bios_bank;
private byte RomBanks;
private byte[] BiosRom;
@ -241,6 +242,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
return "Export";
if (gameRegion.IndexOf("Australia") >= 0)
return "Export";
if (gameRegion.IndexOf("Korea") >= 0)
return "Korea";
return "Japan";
}
@ -382,6 +385,6 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
}
}
private readonly string[] validRegions = { "Export", "Japan", "Auto" };
private readonly string[] validRegions = { "Export", "Japan", "Auto" , "Korea" };
}
}