GBHawk: Clean up and PPU seperation.
This commit is contained in:
parent
2c575dd91a
commit
815145c939
|
@ -4,8 +4,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902
|
|||
{
|
||||
public partial class LR35902
|
||||
{
|
||||
private ulong totalExecutedCycles;
|
||||
public ulong TotalExecutedCycles { get { return totalExecutedCycles; } set { totalExecutedCycles = value; } }
|
||||
public ulong TotalExecutedCycles;
|
||||
|
||||
private int EI_pending;
|
||||
private bool interrupts_enabled;
|
||||
|
|
|
@ -539,13 +539,13 @@ namespace BizHawk.Emulation.Common.Components.LR35902
|
|||
RegPC--;
|
||||
Halt_bug_3 = true;
|
||||
Console.WriteLine("Halt_bug_3");
|
||||
Console.WriteLine(totalExecutedCycles);
|
||||
Console.WriteLine(TotalExecutedCycles);
|
||||
}
|
||||
|
||||
Halt_bug_2 = false;
|
||||
break;
|
||||
}
|
||||
totalExecutedCycles++;
|
||||
TotalExecutedCycles++;
|
||||
}
|
||||
|
||||
// tracer stuff
|
||||
|
@ -597,7 +597,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902
|
|||
ser.Sync(nameof(Halt_bug_2), ref Halt_bug_2);
|
||||
ser.Sync(nameof(Halt_bug_3), ref Halt_bug_3);
|
||||
ser.Sync("Halted", ref halted);
|
||||
ser.Sync("ExecutedCycles", ref totalExecutedCycles);
|
||||
ser.Sync(nameof(TotalExecutedCycles), ref TotalExecutedCycles);
|
||||
ser.Sync(nameof(EI_pending), ref EI_pending);
|
||||
ser.Sync(nameof(int_src), ref int_src);
|
||||
ser.Sync(nameof(stop_time), ref stop_time);
|
||||
|
|
|
@ -768,7 +768,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
// start shifting data into the LCD
|
||||
if (render_counter >= (render_offset + 8))
|
||||
{
|
||||
if (tile_data_latch[2].Bit(5) && Core.GBC_compat)
|
||||
if (tile_data_latch[2].Bit(5))
|
||||
{
|
||||
pixel = tile_data_latch[0].Bit(render_counter % 8) ? 1 : 0;
|
||||
pixel |= tile_data_latch[1].Bit(render_counter % 8) ? 2 : 0;
|
||||
|
@ -781,18 +781,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
int ref_pixel = pixel;
|
||||
|
||||
if (!Core.GBC_compat)
|
||||
{
|
||||
if (LCDC.Bit(0))
|
||||
{
|
||||
pixel = (BGP >> (pixel * 2)) & 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int pal_num = tile_data_latch[2] & 0x7;
|
||||
|
||||
bool use_sprite = false;
|
||||
|
@ -831,7 +819,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
}
|
||||
|
||||
// There is another priority bit in GBC, that can still override sprite priority
|
||||
if (LCDC.Bit(0) && tile_data_latch[2].Bit(7) && (ref_pixel != 0) && Core.GBC_compat)
|
||||
if (LCDC.Bit(0) && tile_data_latch[2].Bit(7) && (ref_pixel != 0))
|
||||
{
|
||||
use_sprite = false;
|
||||
}
|
||||
|
@ -839,47 +827,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
if (use_sprite)
|
||||
{
|
||||
pal_num = sprite_attr & 7;
|
||||
|
||||
if (!Core.GBC_compat)
|
||||
{
|
||||
pal_num = sprite_attr.Bit(4) ? 1 : 0;
|
||||
|
||||
if (sprite_attr.Bit(4))
|
||||
{
|
||||
pixel = (obj_pal_1 >> (s_pixel * 2)) & 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel = (obj_pal_0 >> (s_pixel * 2)) & 3;
|
||||
}
|
||||
}
|
||||
pal_num = sprite_attr & 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// based on sprite priority and pixel values, pick a final pixel color
|
||||
if (Core.GBC_compat)
|
||||
if (use_sprite)
|
||||
{
|
||||
if (use_sprite)
|
||||
{
|
||||
Core._vidbuffer[LY * 160 + pixel_counter] = (int)OBJ_palette[pal_num * 4 + s_pixel];
|
||||
}
|
||||
else
|
||||
{
|
||||
Core._vidbuffer[LY * 160 + pixel_counter] = (int)BG_palette[pal_num * 4 + pixel];
|
||||
}
|
||||
Core._vidbuffer[LY * 160 + pixel_counter] = (int)OBJ_palette[pal_num * 4 + s_pixel];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (use_sprite)
|
||||
{
|
||||
Core._vidbuffer[LY * 160 + pixel_counter] = (int)OBJ_palette[pal_num * 4 + pixel];
|
||||
}
|
||||
else
|
||||
{
|
||||
Core._vidbuffer[LY * 160 + pixel_counter] = (int)BG_palette[pixel];
|
||||
}
|
||||
Core._vidbuffer[LY * 160 + pixel_counter] = (int)BG_palette[pal_num * 4 + pixel];
|
||||
}
|
||||
|
||||
pixel_counter++;
|
||||
|
@ -933,7 +893,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
tile_data[2] = Core.VRAM[0x3800 + (LCDC.Bit(3) ? 1 : 0) * 0x400 + temp_fetch];
|
||||
VRAM_sel = tile_data[2].Bit(3) ? 1 : 0;
|
||||
|
||||
BG_V_flip = tile_data[2].Bit(6) & Core.GBC_compat;
|
||||
BG_V_flip = tile_data[2].Bit(6);
|
||||
|
||||
read_case = 1;
|
||||
if (!pre_render)
|
||||
|
@ -1035,7 +995,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
tile_byte = Core.VRAM[0x1800 + (LCDC.Bit(6) ? 1 : 0) * 0x400 + temp_fetch];
|
||||
tile_data[2] = Core.VRAM[0x3800 + (LCDC.Bit(6) ? 1 : 0) * 0x400 + temp_fetch];
|
||||
VRAM_sel = tile_data[2].Bit(3) ? 1 : 0;
|
||||
BG_V_flip = tile_data[2].Bit(6) & Core.GBC_compat;
|
||||
BG_V_flip = tile_data[2].Bit(6);
|
||||
|
||||
window_tile_inc++;
|
||||
read_case = 5;
|
||||
|
@ -1237,7 +1197,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
public override void process_sprite()
|
||||
{
|
||||
int y;
|
||||
int VRAM_temp = (SL_sprites[sl_use_index * 4 + 3].Bit(3) && Core.GBC_compat) ? 1 : 0;
|
||||
int VRAM_temp = (SL_sprites[sl_use_index * 4 + 3].Bit(3)) ? 1 : 0;
|
||||
|
||||
if (SL_sprites[sl_use_index * 4 + 3].Bit(6))
|
||||
{
|
||||
|
@ -1337,38 +1297,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
sprite_ordered_index = 0;
|
||||
|
||||
// In CGB mode, sprites are ordered solely based on their position in OAM, so they are already ordered
|
||||
|
||||
if (Core.GBC_compat)
|
||||
for (int j = 0; j < SL_sprites_index; j++)
|
||||
{
|
||||
for (int j = 0; j < SL_sprites_index; j++)
|
||||
{
|
||||
sl_use_index = j;
|
||||
process_sprite();
|
||||
SL_sprites_ordered[sprite_ordered_index * 4] = SL_sprites[j * 4 + 1];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 1] = sprite_sel[0];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 2] = sprite_sel[1];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 3] = SL_sprites[j * 4 + 3];
|
||||
sprite_ordered_index++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
for (int j = 0; j < SL_sprites_index; j++)
|
||||
{
|
||||
if (SL_sprites[j * 4 + 1] == i)
|
||||
{
|
||||
sl_use_index = j;
|
||||
process_sprite();
|
||||
SL_sprites_ordered[sprite_ordered_index * 4] = SL_sprites[j * 4 + 1];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 1] = sprite_sel[0];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 2] = sprite_sel[1];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 3] = SL_sprites[j * 4 + 3];
|
||||
sprite_ordered_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
sl_use_index = j;
|
||||
process_sprite();
|
||||
SL_sprites_ordered[sprite_ordered_index * 4] = SL_sprites[j * 4 + 1];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 1] = sprite_sel[0];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 2] = sprite_sel[1];
|
||||
SL_sprites_ordered[sprite_ordered_index * 4 + 3] = SL_sprites[j * 4 + 3];
|
||||
sprite_ordered_index++;
|
||||
}
|
||||
|
||||
bool have_pixel = false;
|
||||
|
@ -1641,189 +1578,5 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
HBL_HDMA_go = false;
|
||||
HBL_test = false;
|
||||
}
|
||||
|
||||
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_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,8 +226,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
if (speed_switch)
|
||||
{
|
||||
speed_switch = false;
|
||||
|
||||
int ret = double_speed ? 50000 : 25000; // actual time needs checking
|
||||
Console.WriteLine(cpu.TotalExecutedCycles);
|
||||
int ret = double_speed ? 70224 * 2 : 70224 * 2; // actual time needs checking
|
||||
double_speed = !double_speed;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -158,6 +158,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);
|
||||
|
||||
if (is_GBC && (header[0x43] == 0))
|
||||
{
|
||||
ppu = new GBC_PPU_GB();
|
||||
}
|
||||
|
||||
Console.WriteLine("MD5: " + rom.HashMD5(0, rom.Length));
|
||||
Console.WriteLine("SHA1: " + rom.HashSHA1(0, rom.Length));
|
||||
_rom = rom;
|
||||
|
|
|
@ -284,7 +284,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
// if no bits are in common between flags and enables, de-assert the IRQ
|
||||
if (((REG_FF0F & 0x1F) & REG_FFFF) == 0) { cpu.FlagI = false; }
|
||||
|
||||
break;
|
||||
|
||||
// audio regs
|
||||
|
@ -352,17 +351,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
Console.WriteLine(value);
|
||||
GBC_compat = false;
|
||||
|
||||
if (GB_bios_register == 0)
|
||||
{
|
||||
var ppu2 = new GBC_PPU();
|
||||
|
||||
ppu2.Reg_Copy(ppu as GBC_PPU);
|
||||
|
||||
ppu = new GBC_PPU_GB();
|
||||
ppu.Core = this;
|
||||
ppu.Reg_Copy(ppu2);
|
||||
}
|
||||
|
||||
// cpu operation is a function of hardware only
|
||||
//cpu.is_GBC = GBC_compat;
|
||||
}
|
||||
|
@ -467,7 +455,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
// if no bits are in common between flags and enables, de-assert the IRQ
|
||||
if (((REG_FF0F & 0x1F) & REG_FFFF) == 0) { cpu.FlagI = false; }
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue