GBHawk: GBC initial Compatibility

This commit is contained in:
alyosha-tas 2018-03-27 10:50:55 -04:00
parent 75d86e995e
commit 3b9835274a
4 changed files with 116 additions and 21 deletions

View File

@ -7,9 +7,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
public class GBC_PPU : PPU
{
public uint[] BG_palette = new uint[32];
public uint[] OBJ_palette = new uint[32];
// individual byte used in palette colors
public byte[] BG_bytes = new byte[64];
public byte[] OBJ_bytes = new byte[64];
@ -739,6 +736,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
use_sprite = true;
}
// There is another priority bit in GBC, that can still override sprite priority
if (LCDC.Bit(0) && tile_data_latch[2].Bit(7))
{
use_sprite = false;
}
}
if (use_sprite)
@ -1456,9 +1459,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Sync("HBL_HDMA_go", ref HBL_HDMA_go);
ser.Sync("HBL_test", ref HBL_test);
ser.Sync("BG_palette", ref BG_palette, false);
ser.Sync("OBJ_palette", ref OBJ_palette, false);
ser.Sync("BG_bytes", ref BG_bytes, false);
ser.Sync("OBJ_bytes", ref OBJ_bytes, false);
ser.Sync("BG_bytes_inc", ref BG_bytes_inc);
@ -1468,5 +1468,71 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
base.SyncState(ser);
}
public override void Reset()
{
LCDC = 0;
STAT = 0x80;
scroll_y = 0;
scroll_x = 0;
LY = 0;
LYC = 0;
DMA_addr = 0xFF;
BGP = 0xFF;
obj_pal_0 = 0xFF;
obj_pal_1 = 0xFF;
window_y = 0x0;
window_x = 0x0;
window_x_latch = 0xFF;
LY_inc = 1;
no_scan = false;
OAM_access_read = true;
VRAM_access_read = true;
OAM_access_write = true;
VRAM_access_write = true;
DMA_OAM_access = true;
cycle = 0;
LYC_INT = false;
HBL_INT = false;
VBL_INT = false;
OAM_INT = false;
stat_line = false;
stat_line_old = false;
window_counter = 0;
window_pre_render = false;
window_started = false;
window_tile_inc = 0;
window_y_tile = 0;
window_x_tile = 0;
window_y_tile_inc = 0;
BG_bytes_inc = false;
OBJ_bytes_inc = false;
BG_bytes_index = 0;
OBJ_bytes_index = 0;
BG_transfer_byte = 0;
OBJ_transfer_byte = 0;
HDMA_src_hi = 0;
HDMA_src_lo = 0;
HDMA_dest_hi = 0;
HDMA_dest_lo = 0;
VRAM_sel = 0;
BG_V_flip = false;
HDMA_active = false;
HDMA_mode = false;
cur_DMA_src = 0;
cur_DMA_dest = 0;
HDMA_length = 0;
HDMA_countdown = 0;
HBL_HDMA_count = 0;
last_HBL = 0;
HBL_HDMA_go = false;
HBL_test = false;
}
}
}

View File

@ -40,8 +40,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
_rom.Length,
MemoryDomain.Endian.Little,
addr => _rom[addr],
(addr, value) => ZP_RAM[addr] = value,
(addr, value) => _rom[addr] = value,
1),
new MemoryDomainDelegate(
"VRAM",
VRAM.Length,
MemoryDomain.Endian.Little,
addr => VRAM[addr],
(addr, value) => VRAM[addr] = value,
1)
};
if (cart_RAM != null)

View File

@ -186,15 +186,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1);
iptr1 = Marshal.AllocHGlobal(OAM.Length + 1);
iptr2 = Marshal.AllocHGlobal(color_palette.Length * 2 * 8 + 1);
iptr3 = Marshal.AllocHGlobal(color_palette.Length * 8 + 1);
iptr2 = Marshal.AllocHGlobal(color_palette.Length * 8 * 8 + 1);
iptr3 = Marshal.AllocHGlobal(color_palette.Length * 8 * 8 + 1);
_scanlineCallback = null;
}
#region GPUViewer
public bool IsCGBMode() => false;
public bool IsCGBMode() => is_GBC;
public IntPtr iptr0 = IntPtr.Zero;
public IntPtr iptr1 = IntPtr.Zero;
@ -208,21 +208,36 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
Marshal.Copy(VRAM, 0, iptr0, VRAM.Length);
Marshal.Copy(OAM, 0, iptr1, OAM.Length);
int[] cp2 = new int[8];
for (int i = 0; i < 4; i++)
if (is_GBC)
{
cp2[i] = (int)color_palette[(ppu.obj_pal_0 >> (i * 2)) & 3];
cp2[i + 4] = (int)color_palette[(ppu.obj_pal_1 >> (i * 2)) & 3];
}
Marshal.Copy(cp2, 0, iptr2, cp2.Length);
int[] cp2 = new int[32];
int[] cp = new int[32];
for (int i = 0; i < 32; i++)
{
cp2[i] = (int)ppu.OBJ_palette[i];
cp[i] = (int)ppu.BG_palette[i];
}
int[] cp = new int[4];
for (int i = 0; i < 4; i++)
Marshal.Copy(cp2, 0, iptr2, ppu.OBJ_palette.Length);
Marshal.Copy(cp, 0, iptr3, ppu.BG_palette.Length);
}
else
{
cp[i] = (int)color_palette[(ppu.BGP >> (i * 2)) & 3];
}
Marshal.Copy(cp, 0, iptr3, cp.Length);
int[] cp2 = new int[8];
for (int i = 0; i < 4; i++)
{
cp2[i] = (int)color_palette[(ppu.obj_pal_0 >> (i * 2)) & 3];
cp2[i + 4] = (int)color_palette[(ppu.obj_pal_1 >> (i * 2)) & 3];
}
Marshal.Copy(cp2, 0, iptr2, cp2.Length);
int[] cp = new int[4];
for (int i = 0; i < 4; i++)
{
cp[i] = (int)color_palette[(ppu.BGP >> (i * 2)) & 3];
}
Marshal.Copy(cp, 0, iptr3, cp.Length);
}
return new GPUMemoryAreas(iptr0, iptr1, iptr2, iptr3);
}

View File

@ -9,6 +9,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
public GBHawk Core { get; set; }
public uint[] BG_palette = new uint[32];
public uint[] OBJ_palette = new uint[32];
// register variables
public byte LCDC;
public byte STAT;
@ -154,6 +157,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public virtual void SyncState(Serializer ser)
{
ser.Sync("BG_palette", ref BG_palette, false);
ser.Sync("OBJ_palette", ref OBJ_palette, false);
ser.Sync("LCDC", ref LCDC);
ser.Sync("STAT", ref STAT);
ser.Sync("scroll_y", ref scroll_y);