MSXHawk: allocate memory because pointers may be bad due to garbage collection somehow

This commit is contained in:
alyosha-tas 2020-01-23 09:01:44 -05:00
parent 751ef54f4f
commit 7da04e2bf2
5 changed files with 24 additions and 13 deletions

View File

@ -6,7 +6,7 @@ using System.Text;
namespace BizHawk.Emulation.Cores.Computers.MSX
{
/// <summary>
/// static bindings into MSXHAWK.dll
/// static bindings into MSXHawk.dll
/// </summary>
public static class LibMSX
{

View File

@ -157,10 +157,10 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
return _vidbuffer;
}
public int VirtualWidth => 160;
public int VirtualHeight => 144;
public int BufferWidth => 160;
public int BufferHeight => 144;
public int VirtualWidth => 256;
public int VirtualHeight => 192;
public int BufferWidth => 256;
public int BufferHeight => 192;
public int BackgroundColor => unchecked((int)0xFF000000);
public int VsyncNumerator => _frameHz;
public int VsyncDenominator => 1;

View File

@ -27,8 +27,6 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
}
byte[] Bios = null;
byte[] Basic = null;
Bios = comm.CoreFileProvider.GetFirmware("MSX", "bios", true, "BIOS Not Found, Cannot Load");
Basic = comm.CoreFileProvider.GetFirmware("MSX", "basic", true, "BIOS Not Found, Cannot Load");
@ -68,8 +66,8 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
IntPtr MSX_Pntr { get; set; } = IntPtr.Zero;
byte[] MSX_core = new byte[0x20000];
public byte[] _bios;
public byte[] _basic;
public static byte[] Bios;
public static byte[] Basic;
// Constants
private const int BankSize = 16384;

View File

@ -21,6 +21,10 @@ MSXHawk_EXPORT MSXCore* MSX_create()
// free the memory from the core pointer
MSXHawk_EXPORT void MSX_destroy(MSXCore* p)
{
delete p->MemMap.bios_rom;
delete p->MemMap.basic_rom;
delete p->MemMap.rom_1;
delete p->MemMap.rom_2;
std::free(p);
}

View File

@ -52,18 +52,27 @@ namespace MSXHawk
void remap();
// NOTE: only called from source when both are available and of correct size (0x4000)
void Load_BIOS(uint8_t* bios, uint8_t* basic)
{
bios_rom = bios;
basic_rom = basic;
bios_rom = new uint8_t[0x4000];
basic_rom = new uint8_t[0x4000];
memcpy(bios_rom, bios, 0x4000);
memcpy(basic_rom, basic, 0x4000);
}
void Load_ROM(uint8_t* ext_rom_1, uint32_t ext_rom_size_1, uint32_t ext_rom_mapper_1, uint8_t* ext_rom_2, uint32_t ext_rom_size_2, uint32_t ext_rom_mapper_2)
{
rom_1 = ext_rom_1;
rom_1 = new uint8_t[ext_rom_size_1];
rom_2 = new uint8_t[ext_rom_size_2];
memcpy(rom_1, ext_rom_1, ext_rom_size_1);
memcpy(rom_2, ext_rom_2, ext_rom_size_2);
rom_size_1 = ext_rom_size_1 / 0x4000;
rom_mapper_1 = ext_rom_mapper_1;
rom_2 = ext_rom_2;
rom_size_2 = ext_rom_size_2 / 0x4000;
rom_mapper_2 = ext_rom_mapper_2;