GBHawk: general clean up and minor bug fixes

This commit is contained in:
alyosha-tas 2020-10-11 17:48:08 -04:00
parent 24d07121e2
commit da6ea1ec9f
14 changed files with 23 additions and 244 deletions

View File

@ -11,7 +11,6 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
public int instr_pntr = 0;
public ushort[] cur_instr = new ushort [60];
public ushort[] instr_table = new ushort[256 * 2 * 60 + 60 * 8];
public int opcode;
public bool CB_prefix;
public bool halted;
public bool stopped;

View File

@ -764,8 +764,6 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
void FetchInstruction(int op)
{
opcode = op;
instr_pntr = 0;
if (CB_prefix) { instr_pntr += 256 * 60; }
@ -801,7 +799,6 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
ser.Sync(nameof(instr_pntr), ref instr_pntr);
ser.Sync(nameof(CB_prefix), ref CB_prefix);
ser.Sync(nameof(stopped), ref stopped);
ser.Sync(nameof(opcode), ref opcode);
ser.Sync(nameof(jammed), ref jammed);
ser.Sync(nameof(LY), ref LY);
ser.Sync(nameof(FlagI), ref FlagI);

View File

@ -10,7 +10,6 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
byte a_d;
bool imm;
public void Read_Func(ushort dest, ushort src_l, ushort src_h)
{
ushort addr = (ushort)(Regs[src_l] | (Regs[src_h]) << 8);

View File

@ -1080,16 +1080,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
sound_update_needed = true;
}
public void update_sound()
{
if (sound_update_needed)
{
}
}
public void SyncState(Serializer ser)
{
ser.Sync(nameof(Audio_Regs), ref Audio_Regs, false);

View File

@ -38,7 +38,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public byte HDMA_ctrl => (byte)(((HDMA_active ? 0 : 1) << 7) | ((HDMA_length >> 4) - 1));
// controls for tile attributes
public int VRAM_sel;
public bool BG_V_flip;
@ -227,11 +226,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
HDMA_tick = 0;
if (value.Bit(7))
{
// HDMA during HBlank only
// HDMA during HBlank only, but only if screen is on, otherwise DMA immediately one block of data
// worms armaggedon requires HDMA to fire in hblank mode even if the screen is off.
HDMA_active = true;
HBL_HDMA_count = 0x10;
// TODO: DOES HDMA start if triggered in mode 0 immediately? (for now assume no)
last_HBL = LY - 1;
HBL_test = true;
@ -1798,190 +1797,5 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
for (int i = 0; i < BG_bytes.Length; i++) { BG_bytes[i] = 0xFF; }
for (int i = 0; i < OBJ_bytes.Length; i++) { OBJ_bytes[i] = 0xFF; }
}
public override void Reg_Copy(GBC_PPU ppu2)
{
BG_transfer_byte = ppu2.BG_transfer_byte;
OBJ_transfer_byte = ppu2.OBJ_transfer_byte;
HDMA_src_hi = ppu2.HDMA_src_hi;
HDMA_src_lo = ppu2.HDMA_src_lo;
HDMA_dest_hi = ppu2.HDMA_dest_hi;
HDMA_dest_lo = ppu2.HDMA_dest_lo;
HDMA_tick = ppu2.HDMA_tick;
HDMA_byte = ppu2.HDMA_byte;
VRAM_sel = ppu2.VRAM_sel;
BG_V_flip = ppu2.BG_V_flip;
HDMA_mode = ppu2.HDMA_mode;
cur_DMA_src = ppu2.cur_DMA_src;
cur_DMA_dest = ppu2.cur_DMA_dest;
HDMA_length = ppu2.HDMA_length;
HDMA_countdown = ppu2.HDMA_countdown;
HBL_HDMA_count = ppu2.HBL_HDMA_count;
last_HBL = ppu2.last_HBL;
HBL_HDMA_go = ppu2.HBL_HDMA_go;
HBL_test = ppu2.HBL_test;
for (int i = 0; i < BG_bytes.Length; i++)
{
BG_bytes[i] = ppu2.BG_bytes[i];
}
for (int i = 0; i < OBJ_bytes.Length; i++)
{
OBJ_bytes[i] = ppu2.OBJ_bytes[i];
}
BG_bytes_inc = ppu2.BG_bytes_inc;
OBJ_bytes_inc = ppu2.OBJ_bytes_inc;
BG_bytes_index = ppu2.BG_bytes_index;
OBJ_bytes_index = ppu2.OBJ_bytes_index;
LYC_t = ppu2.LYC_t;
LYC_cd = ppu2.LYC_cd;
for (int i = 0; i < BG_palette.Length; i++)
{
BG_palette[i] = ppu2.BG_palette[i];
}
for (int i = 0; i < OBJ_palette.Length; i++)
{
OBJ_palette[i] = ppu2.OBJ_palette[i];
}
HDMA_active = ppu2.HDMA_active;
LCDC = ppu2.LCDC;
STAT = ppu2.STAT;
scroll_y = ppu2.scroll_y;
scroll_x = ppu2.scroll_x;
LY = ppu2.LY;
LY_actual = ppu2.LY_actual;
LY_inc = ppu2.LY_inc;
LYC = ppu2.LYC;
DMA_addr = ppu2.DMA_addr;
BGP = ppu2.BGP;
obj_pal_0 = ppu2.obj_pal_0;
obj_pal_1 = ppu2.obj_pal_1;
window_y = ppu2.window_y;
window_y_latch = ppu2.window_y_latch;
window_x = ppu2.window_x;
DMA_start = ppu2.DMA_start;
DMA_clock = ppu2.DMA_clock;
DMA_inc = ppu2.DMA_inc;
DMA_byte = ppu2.DMA_byte;
cycle = ppu2.cycle;
LYC_INT = ppu2.LYC_INT;
HBL_INT = ppu2.HBL_INT;
VBL_INT = ppu2.VBL_INT;
OAM_INT = ppu2.OAM_INT;
stat_line = ppu2.stat_line;
stat_line_old = ppu2.stat_line_old;
LCD_was_off = ppu2.LCD_was_off;
OAM_scan_index = ppu2.OAM_scan_index;
SL_sprites_index = ppu2.SL_sprites_index;
for (int i = 0; i < SL_sprites.Length; i++)
{
SL_sprites[i] = ppu2.SL_sprites[i];
}
write_sprite = ppu2.write_sprite;
no_scan = ppu2.no_scan;
DMA_OAM_access = ppu2.DMA_OAM_access;
OAM_access_read = ppu2.OAM_access_read;
OAM_access_write = ppu2.OAM_access_write;
VRAM_access_read = ppu2.VRAM_access_read;
VRAM_access_write = ppu2.VRAM_access_write;
read_case = ppu2.read_case;
internal_cycle = ppu2.internal_cycle;
y_tile = ppu2.y_tile;
y_scroll_offset = ppu2.y_scroll_offset;
x_tile = ppu2.x_tile;
x_scroll_offset = ppu2.x_scroll_offset;
tile_byte = ppu2.tile_byte;
sprite_fetch_cycles = ppu2.sprite_fetch_cycles;
fetch_sprite = ppu2.fetch_sprite;
going_to_fetch = ppu2.going_to_fetch;
first_fetch = ppu2.first_fetch;
sprite_fetch_counter = ppu2.sprite_fetch_counter;
for (int i = 0; i < sprite_attr_list.Length; i++)
{
sprite_attr_list[i] = ppu2.sprite_attr_list[i];
}
for (int i = 0; i < sprite_pixel_list.Length; i++)
{
sprite_pixel_list[i] = ppu2.sprite_pixel_list[i];
}
for (int i = 0; i < sprite_present_list.Length; i++)
{
sprite_present_list[i] = ppu2.sprite_present_list[i];
}
temp_fetch = ppu2.temp_fetch;
tile_inc = ppu2.tile_inc;
pre_render = ppu2.pre_render;
pre_render_2 = ppu2.pre_render_2;
for (int i = 0; i < tile_data.Length; i++)
{
tile_data[i] = ppu2.tile_data[i];
}
for (int i = 0; i < tile_data_latch.Length; i++)
{
tile_data_latch[i] = ppu2.tile_data_latch[i];
}
latch_counter = ppu2.latch_counter;
latch_new_data = ppu2.latch_new_data;
render_counter = ppu2.render_counter;
render_offset = ppu2.render_offset;
pixel_counter = ppu2.pixel_counter;
pixel = ppu2.pixel;
for (int i = 0; i < sprite_data.Length; i++)
{
sprite_data[i] = ppu2.sprite_data[i];
}
sl_use_index = ppu2.sl_use_index;
for (int i = 0; i < sprite_sel.Length; i++)
{
sprite_sel[i] = ppu2.sprite_sel[i];
}
no_sprites = ppu2.no_sprites;
evaled_sprites = ppu2.evaled_sprites;
for (int i = 0; i < SL_sprites_ordered.Length; i++)
{
SL_sprites_ordered[i] = ppu2.SL_sprites_ordered[i];
}
sprite_ordered_index = ppu2.sprite_ordered_index;
blank_frame = ppu2.blank_frame;
window_latch = ppu2.window_latch;
consecutive_sprite = ppu2.consecutive_sprite;
last_eval = ppu2.last_eval;
window_counter = ppu2.window_counter;
window_pre_render = ppu2.window_pre_render;
window_started = ppu2.window_started;
window_is_reset = ppu2.window_is_reset;
window_tile_inc = ppu2.window_tile_inc;
window_y_tile = ppu2.window_y_tile;
window_x_tile = ppu2.window_x_tile;
window_y_tile_inc = ppu2.window_y_tile_inc;
window_x_latch = ppu2.window_x_latch;
}
}
}

View File

@ -215,6 +215,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
cur_DMA_dest = (ushort)((cur_DMA_dest & 0xFF00) | (HDMA_dest_lo & 0xF0));
break;
case 0xFF55: // HDMA5
//Console.WriteLine("hdma " + Core.cpu.TotalExecutedCycles);
if (!HDMA_active)
{
HDMA_mode = value.Bit(7);

View File

@ -7,14 +7,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
private void SyncState(Serializer ser)
{
byte[] core = null;
if (ser.IsWriter)
{
using var ms = new MemoryStream();
ms.Close();
core = ms.ToArray();
}
ser.BeginSection("Gameboy");
cpu.SyncState(ser);
mapper.SyncState(ser);
@ -23,7 +15,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
serialport.SyncState(ser);
audio.SyncState(ser);
ser.Sync(nameof(core), ref core, false);
ser.Sync("Lag", ref _lagcount);
ser.Sync("Frame", ref _frame);
ser.Sync("IsLag", ref _islag);

View File

@ -10,6 +10,7 @@ using System.Runtime.InteropServices;
// TODO: mode1_disableint_gbc.gbc behaves differently between GBC and GBA, why?
// TODO: oam_dma_start.gb does not behave as expected but test still passes through lucky coincidences / test deficiency
// TODO: LYC interrupt behaves differently in GBC and GB compat mode
// TODO: Window Position A6 behaves differently
namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
@ -31,8 +32,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public byte REG_FFFF;
// The unused bits in this register (interrupt flags) are always set
public byte REG_FF0F = 0xE0;
// Updating reg FF0F seemsto be delayed by one cycle
// tests
// Updating reg FF0F seems to be delayed by one cycle,needs more testing
public byte REG_FF0F_OLD = 0xE0;
// memory domains
@ -135,8 +135,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
Bios = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
ppu = new GBC_PPU();
is_GBC = true;
}
}
}
else if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.GB)
{

View File

@ -181,7 +181,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// They vary widely based on physical hand movements, but this roughly matches what I observe in a real GBP
float temp2 = (float)((phi - 2 * phi_prev + phi_prev_2) * 59.7275 * 59.7275 * 0.1);
return (ushort)(0x8370 - Math.Floor(temp * 216) - temp2);
}

View File

@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
}
else
{
return 0;
return 0xFF;
}
}

View File

@ -98,7 +98,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
return;
}
}
else
{

View File

@ -1,7 +1,6 @@
using BizHawk.Emulation.Common;
using System;
/*
$FFFF Interrupt Enable Flag
$FF80-$FFFE Zero Page - 127 bytes

View File

@ -9,8 +9,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public uint[] BG_palette = new uint[32];
public uint[] OBJ_palette = new uint[32];
public uint[] color_palette = new uint[4];
public bool HDMA_active;
public bool clear_screen;
@ -44,18 +42,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public bool HBL_INT;
public bool VBL_INT;
public bool OAM_INT;
public bool LCD_was_off;
public bool stat_line;
public bool stat_line_old;
public bool LCD_was_off;
// OAM scan
public bool DMA_OAM_access;
public bool OAM_access_read;
public bool OAM_access_write;
public int OAM_scan_index;
public int SL_sprites_index;
public int[] SL_sprites = new int[40];
public int write_sprite;
public bool no_scan;
public bool DMA_OAM_access;
public bool OAM_access_read;
public bool OAM_access_write;
// render
public bool VRAM_access_read;
public bool VRAM_access_write;
@ -66,7 +64,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int x_tile;
public int x_scroll_offset;
public int tile_byte;
public int sprite_fetch_cycles;
public bool fetch_sprite;
public bool going_to_fetch;
public bool first_fetch;
@ -99,7 +96,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int consecutive_sprite;
public int last_eval;
public int total_counter;
// windowing state
public int window_counter;
public bool window_pre_render;
@ -115,6 +111,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int hbl_countdown;
public int sprite_scroll_offset;
// variables not in state
public int total_counter;
public uint[] color_palette = new uint[4];
public virtual byte ReadReg(int addr)
{
return 0;
@ -163,11 +163,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
}
public virtual void Reg_Copy(GBC_PPU ppu2)
{
}
// order sprites according to x coordinate
// note that for sprites of equal x coordinate, priority goes to first on the list
public virtual void reorder_and_assemble_sprites()
@ -210,19 +205,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Sync(nameof(OAM_INT), ref OAM_INT);
ser.Sync(nameof(stat_line), ref stat_line);
ser.Sync(nameof(stat_line_old), ref stat_line_old);
ser.Sync(nameof(LCD_was_off), ref LCD_was_off);
ser.Sync(nameof(LCD_was_off), ref LCD_was_off);
ser.Sync(nameof(OAM_scan_index), ref OAM_scan_index);
ser.Sync(nameof(SL_sprites_index), ref SL_sprites_index);
ser.Sync(nameof(SL_sprites), ref SL_sprites, false);
ser.Sync(nameof(write_sprite), ref write_sprite);
ser.Sync(nameof(no_scan), ref no_scan);
ser.Sync(nameof(DMA_OAM_access), ref DMA_OAM_access);
ser.Sync(nameof(OAM_access_read), ref OAM_access_read);
ser.Sync(nameof(OAM_access_write), ref OAM_access_write);
ser.Sync(nameof(VRAM_access_read), ref VRAM_access_read);
ser.Sync(nameof(VRAM_access_write), ref VRAM_access_write);
ser.Sync(nameof(read_case), ref read_case);
ser.Sync(nameof(internal_cycle), ref internal_cycle);
ser.Sync(nameof(y_tile), ref y_tile);
@ -230,7 +225,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Sync(nameof(x_tile), ref x_tile);
ser.Sync(nameof(x_scroll_offset), ref x_scroll_offset);
ser.Sync(nameof(tile_byte), ref tile_byte);
ser.Sync(nameof(sprite_fetch_cycles), ref sprite_fetch_cycles);
ser.Sync(nameof(fetch_sprite), ref fetch_sprite);
ser.Sync(nameof(going_to_fetch), ref going_to_fetch);
ser.Sync(nameof(first_fetch), ref first_fetch);
@ -252,11 +246,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Sync(nameof(pixel_counter), ref pixel_counter);
ser.Sync(nameof(pixel), ref pixel);
ser.Sync(nameof(sprite_data), ref sprite_data, false);
ser.Sync(nameof(sl_use_index), ref sl_use_index);
ser.Sync(nameof(sprite_sel), ref sprite_sel, false);
ser.Sync(nameof(sl_use_index), ref sl_use_index);
ser.Sync(nameof(no_sprites), ref no_sprites);
ser.Sync(nameof(evaled_sprites), ref evaled_sprites);
ser.Sync(nameof(SL_sprites_ordered), ref SL_sprites_ordered, false);
ser.Sync(nameof(evaled_sprites), ref evaled_sprites);
ser.Sync(nameof(sprite_ordered_index), ref sprite_ordered_index);
ser.Sync(nameof(blank_frame), ref blank_frame);
ser.Sync(nameof(window_latch), ref window_latch);

View File

@ -10,13 +10,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public byte serial_control;
public byte serial_data;
public bool can_pulse;
public int serial_clock;
public int serial_bits;
public int clk_rate;
public byte going_out;
public byte coming_in;
public int serial_bits_old;
public bool can_pulse;
public bool IRQ_block;
public byte ReadReg(int addr)
@ -75,12 +74,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
}
else
{
serial_bits_old = serial_bits;
serial_bits = 8;
clk_rate = -1;
serial_clock = clk_rate;
can_pulse = false;
can_pulse = false;
}
if (Core.GBC_compat)
@ -142,6 +139,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
going_out = 0;
coming_in = 1;
can_pulse = false;
IRQ_block = false;
}
public void SyncState(Serializer ser)