From 07e7a83243143c3920b37ade0c3076f69592e57c Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 1 Apr 2020 09:44:43 -0400 Subject: [PATCH] GBHawk: optimizations --- .../CPUs/LR35902/Execute.cs | 1 + .../CPUs/LR35902/LR35902.cs | 25 +- .../Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs | 8 +- .../Consoles/Nintendo/GBHawk/GBC_PPU.cs | 4 +- .../Nintendo/GBHawk/GBHawk.IEmulator.cs | 61 ++-- .../Nintendo/GBHawk/GBHawk.IStatable.cs | 2 +- .../Consoles/Nintendo/GBHawk/GBHawk.cs | 14 +- .../Consoles/Nintendo/GBHawk/GB_PPU.cs | 2 +- .../Consoles/Nintendo/GBHawk/MemoryMap.cs | 268 ++++++++---------- .../Consoles/Nintendo/GBHawk/PPU.cs | 2 + .../GBHawkLink/GBHawkLink.IEmulator.cs | 32 +-- .../GBHawkLink3x/GBHawkLink3x.IEmulator.cs | 48 ++-- .../GBHawkLink4x/GBHawkLink4x.IEmulator.cs | 64 ++--- .../Nintendo/SubGBHawk/SubGBHawk.IEmulator.cs | 16 +- 14 files changed, 280 insertions(+), 267 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs index ddfaf3ec8e..d549963f60 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs @@ -20,6 +20,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 // unsaved variables public bool checker; + byte interrupt_src_reg, interrupt_enable_reg; public void BuildInstructionTable() { diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index d8a3f14bb7..ef62f3a6fb 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -86,12 +86,15 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 } // Memory Access - public Func ReadMemory; public Action WriteMemory; public Func PeekMemory; public Func DummyReadMemory; + // Get external interrupt registers + public Func GetIntRegs; + public Action SetIntRegs; + // Special Function for Speed switching executed on a STOP public Func SpeedFunc; @@ -134,7 +137,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 } // Execute instructions - public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable) + public void ExecuteOne() { switch (instr_table[instr_pntr++]) { @@ -424,6 +427,8 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 stop_time = SpeedFunc(0); stop_check = true; } + + interrupt_src_reg = GetIntRegs(0); if (stop_time > 0) { @@ -449,7 +454,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 instr_pntr = 256 * 60 * 2 + 60 * 5; // point to stop loop } } - else if (interrupt_src.Bit(4)) // button pressed, not actually an interrupt though + else if (interrupt_src_reg.Bit(4)) // button pressed, not actually an interrupt though { TraceCallback?.Invoke(new TraceInfo { @@ -506,7 +511,10 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 ushort bit_check = instr_table[instr_pntr++]; //Console.WriteLine(interrupt_src + " " + interrupt_enable + " " + TotalExecutedCycles); - if (interrupt_src.Bit(bit_check) && interrupt_enable.Bit(bit_check)) { int_src = bit_check; int_clear = (byte)(1 << bit_check); } + interrupt_src_reg = GetIntRegs(0); + interrupt_enable_reg = GetIntRegs(1); + + if (interrupt_src_reg.Bit(bit_check) && interrupt_enable_reg.Bit(bit_check)) { int_src = bit_check; int_clear = (byte)(1 << bit_check); } /* if (interrupt_src.Bit(0) && interrupt_enable.Bit(0)) { int_src = 0; int_clear = 1; } else if (interrupt_src.Bit(1) && interrupt_enable.Bit(1)) { int_src = 1; int_clear = 2; } @@ -530,9 +538,14 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 Halt_bug_2 = false; break; case IRQ_CLEAR: - if (interrupt_src.Bit(int_src)) { interrupt_src -= int_clear; } + interrupt_src_reg = GetIntRegs(0); + interrupt_enable_reg = GetIntRegs(1); - if ((interrupt_src & interrupt_enable) == 0) { FlagI = false; } + if (interrupt_src_reg.Bit(int_src)) { interrupt_src_reg -= int_clear; } + + SetIntRegs(interrupt_src_reg); + + if ((interrupt_src_reg & interrupt_enable_reg) == 0) { FlagI = false; } // reset back to default state int_src = 5; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs index d14d72716e..be2336c31f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs @@ -884,22 +884,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (use_sprite) { - Core._vidbuffer[LY * 160 + pixel_counter] = (int)OBJ_palette[pal_num * 4 + s_pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = OBJ_palette[pal_num * 4 + s_pixel]; } else { - Core._vidbuffer[LY * 160 + pixel_counter] = (int)BG_palette[pal_num * 4 + pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = BG_palette[pal_num * 4 + pixel]; } } else { if (use_sprite) { - Core._vidbuffer[LY * 160 + pixel_counter] = (int)OBJ_palette[pal_num * 4 + pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = OBJ_palette[pal_num * 4 + pixel]; } else { - Core._vidbuffer[LY * 160 + pixel_counter] = (int)BG_palette[pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = BG_palette[pixel]; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs index 9ff237777d..5ff0b35f0d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs @@ -862,11 +862,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // based on sprite priority and pixel values, pick a final pixel color if (use_sprite) { - Core._vidbuffer[LY * 160 + pixel_counter] = (int)OBJ_palette[pal_num * 4 + s_pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = OBJ_palette[pal_num * 4 + s_pixel]; } else { - Core._vidbuffer[LY * 160 + pixel_counter] = (int)BG_palette[pal_num * 4 + pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = BG_palette[pal_num * 4 + pixel]; } pixel_counter++; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs index ed9ea91290..3d79627e92 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -25,17 +25,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk //Update the color palette if a setting changed if (_settings.Palette == GBSettings.PaletteType.BW) { - color_palette[0] = color_palette_BW[0]; - color_palette[1] = color_palette_BW[1]; - color_palette[2] = color_palette_BW[2]; - color_palette[3] = color_palette_BW[3]; + ppu.color_palette[0] = color_palette_BW[0]; + ppu.color_palette[1] = color_palette_BW[1]; + ppu.color_palette[2] = color_palette_BW[2]; + ppu.color_palette[3] = color_palette_BW[3]; } else { - color_palette[0] = color_palette_Gr[0]; - color_palette[1] = color_palette_Gr[1]; - color_palette[2] = color_palette_Gr[2]; - color_palette[3] = color_palette_Gr[3]; + ppu.color_palette[0] = color_palette_Gr[0]; + ppu.color_palette[1] = color_palette_Gr[1]; + ppu.color_palette[2] = color_palette_Gr[2]; + ppu.color_palette[3] = color_palette_Gr[3]; } if (_tracer.Enabled) @@ -90,14 +90,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // Note that DMA is halted when the CPU is halted if (ppu.DMA_start && !cpu.halted) { ppu.DMA_tick(); } serialport.serial_transfer_tick(); - cpu.ExecuteOne(ref REG_FF0F, REG_FFFF); + cpu.ExecuteOne(); timer.tick(); if (double_speed) { if (ppu.DMA_start && !cpu.halted) { ppu.DMA_tick(); } serialport.serial_transfer_tick(); - cpu.ExecuteOne(ref REG_FF0F, REG_FFFF); + cpu.ExecuteOne(); timer.tick(); } } @@ -137,7 +137,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // But some GB gams, ex Battletoads, turn off the screen for a long time from the middle of the frame, so need to be cleared. if (ppu.clear_screen) { - for (int j = 0; j < frame_buffer.Length; j++) { frame_buffer[j] = (int)color_palette[0]; } + for (int j = 0; j < frame_buffer.Length; j++) { frame_buffer[j] = (int)ppu.color_palette[0]; } ppu.clear_screen = false; } } @@ -154,14 +154,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // These things all tick twice as fast in GBC double speed mode if (ppu.DMA_start && !cpu.halted) { ppu.DMA_tick(); } serialport.serial_transfer_tick(); - cpu.ExecuteOne(ref REG_FF0F, REG_FFFF); + cpu.ExecuteOne(); timer.tick(); if (double_speed) { if (ppu.DMA_start && !cpu.halted) { ppu.DMA_tick(); } serialport.serial_transfer_tick(); - cpu.ExecuteOne(ref REG_FF0F, REG_FFFF); + cpu.ExecuteOne(); timer.tick(); } } @@ -253,7 +253,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Acc_Y_state = _controllerDeck.ReadAccY1(controller); } + public byte GetIntRegs(ushort r) + { + if (r==0) + { + return REG_FF0F; + } + else + { + return REG_FFFF; + } + } + public void SetIntRegs(byte r) + { + REG_FF0F = r; + } public int Frame => _frame; @@ -280,10 +295,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk #region Video provider - public int[] _vidbuffer; - public int[] frame_buffer; + + public uint[] vid_buffer; + + public int[] GetVideoBuffer() { return frame_buffer; @@ -295,7 +312,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (!ppu.blank_frame) { - for (int j = 0; j < frame_buffer.Length; j++) { frame_buffer[j] = _vidbuffer[j]; } + for (int j = 0; j < frame_buffer.Length; j++) { frame_buffer[j] = (int)vid_buffer[j]; } } ppu.blank_frame = false; @@ -304,13 +321,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (ppu.blank_frame) { - for (int i = 0; i < _vidbuffer.Length; i++) + for (int i = 0; i < vid_buffer.Length; i++) { - _vidbuffer[i] = (int)color_palette[0]; + vid_buffer[i] = ppu.color_palette[0]; } } - - for (int j = 0; j < frame_buffer.Length; j++) { frame_buffer[j] = _vidbuffer[j]; } + + for (int j = 0; j < frame_buffer.Length; j++) { frame_buffer[j] = (int)vid_buffer[j]; } ppu.blank_frame = false; } @@ -324,11 +341,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public int VsyncNumerator => 262144; public int VsyncDenominator => 4389; - public static readonly uint[] color_palette_BW = { 0xFFFFFFFF , 0xFFAAAAAA, 0xFF555555, 0xFF000000 }; + public static readonly uint[] color_palette_BW = { 0xFFFFFFFF, 0xFFAAAAAA, 0xFF555555, 0xFF000000 }; public static readonly uint[] color_palette_Gr = { 0xFFA4C505, 0xFF88A905, 0xFF1D551D, 0xFF052505 }; - public uint[] color_palette = new uint[4]; - #endregion } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs index b7be7f9c7e..1ccff5eea4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs @@ -77,7 +77,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ser.Sync(nameof(addr_access), ref addr_access); ser.Sync(nameof(frame_buffer), ref frame_buffer, false); - ser.Sync(nameof(_vidbuffer), ref _vidbuffer, false); + ser.Sync(nameof(vid_buffer), ref vid_buffer, false); // probably a better way to do this if (cart_RAM != null) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs index d493f03a9f..0948fe37f9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs @@ -97,6 +97,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk DummyReadMemory = ReadMemory, OnExecFetch = ExecFetch, SpeedFunc = SpeedFunc, + GetIntRegs = GetIntRegs, + SetIntRegs = SetIntRegs }; timer = new Timer(); @@ -193,8 +195,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1); iptr1 = Marshal.AllocHGlobal(OAM.Length + 1); - iptr2 = Marshal.AllocHGlobal(color_palette.Length * 8 * 8 + 1); - iptr3 = Marshal.AllocHGlobal(color_palette.Length * 8 * 8 + 1); + iptr2 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1); + iptr3 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1); _scanlineCallback = null; } @@ -233,15 +235,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk 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]; + cp2[i] = (int)ppu.color_palette[(ppu.obj_pal_0 >> (i * 2)) & 3]; + cp2[i + 4] = (int)ppu.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]; + cp[i] = (int)ppu.color_palette[(ppu.BGP >> (i * 2)) & 3]; } Marshal.Copy(cp, 0, iptr3, cp.Length); } @@ -298,7 +300,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk mapper.Reset(); cpu.Reset(); - _vidbuffer = new int[VirtualWidth * VirtualHeight]; + vid_buffer = new uint[VirtualWidth * VirtualHeight]; frame_buffer = new int[VirtualWidth * VirtualHeight]; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs index 4dfc01e4c5..a1a5960866 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs @@ -610,7 +610,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } // based on sprite priority and pixel values, pick a final pixel color - Core._vidbuffer[LY * 160 + pixel_counter] = (int)Core.color_palette[pixel]; + Core.vid_buffer[LY * 160 + pixel_counter] = color_palette[pixel]; pixel_counter++; if (pixel_counter == 160) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs index 220a7d0441..e375ce9156 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs @@ -63,47 +63,51 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else if ((addr >= 0xFF80)) { + // register FFFF? return ZP_RAM[addr - 0xFF80]; } return 0xFF; } - if (addr < 0x900) + if (addr < 0x8000) { - if (addr < 0x100) + if (addr >= 0x900) { - // return Either BIOS ROM or Game ROM - if ((GB_bios_register & 0x1) == 0) - { - return _bios[addr]; // Return BIOS - } - else - { - return mapper.ReadMemory(addr); - } - } - else if (addr >= 0x200) - { - // return Either BIOS ROM or Game ROM - if (((GB_bios_register & 0x1) == 0) && is_GBC) - { - return _bios[addr]; // Return BIOS - } - else - { - return mapper.ReadMemory(addr); - } + return mapper.ReadMemory(addr); } else { - return mapper.ReadMemory(addr); + if (addr < 0x100) + { + // return Either BIOS ROM or Game ROM + if ((GB_bios_register & 0x1) == 0) + { + return _bios[addr]; // Return BIOS + } + else + { + return mapper.ReadMemory(addr); + } + } + else if (addr >= 0x200) + { + // return Either BIOS ROM or Game ROM + if (((GB_bios_register & 0x1) == 0) && is_GBC) + { + return _bios[addr]; // Return BIOS + } + else + { + return mapper.ReadMemory(addr); + } + } + else + { + return mapper.ReadMemory(addr); + } } } - else if (addr < 0x8000) - { - return mapper.ReadMemory(addr); - } else if (addr < 0xA000) { if (ppu.VRAM_access_read) { return VRAM[(VRAM_Bank * 0x2000) + (addr - 0x8000)]; } @@ -113,21 +117,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { return mapper.ReadMemory(addr); } - else if (addr < 0xD000) - { - return RAM[addr - 0xC000]; - } - else if (addr < 0xE000) - { - return RAM[(RAM_Bank * 0x1000) + (addr - 0xD000)]; - } - else if (addr < 0xF000) - { - return RAM[addr - 0xE000]; - } else if (addr < 0xFE00) { - return RAM[(RAM_Bank * 0x1000) + (addr - 0xF000)]; + addr = (ushort)(RAM_Bank * (addr & 0x1000) + (addr & 0xFFF)); + return RAM[addr]; } else if (addr < 0xFEA0) { @@ -185,83 +178,78 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } return; } - - if (addr < 0x900) + + // Writes are more likely from the top down + if (addr >= 0xFF00) { - if (addr < 0x100) + if (addr < 0xFF80) { - if ((GB_bios_register & 0x1) == 0) - { - // No Writing to BIOS - } - else - { - mapper.WriteMemory(addr, value); - } + Write_Registers(addr, value); } - else if (addr >= 0x200) + else if (addr < 0xFFFF) { - if (((GB_bios_register & 0x1) == 0) && is_GBC) - { - // No Writing to BIOS - } - else - { - mapper.WriteMemory(addr, value); - } + ZP_RAM[addr - 0xFF80] = value; } else { - mapper.WriteMemory(addr, value); + Write_Registers(addr, value); } } - else if (addr < 0x8000) + else if (addr >= 0xFE00) + { + if ((addr < 0xFEA0) && ppu.OAM_access_write) + { + OAM[addr - 0xFE00] = value; + } + } + else if (addr >= 0xC000) + { + addr = (ushort)(RAM_Bank * (addr & 0x1000) + (addr & 0xFFF)); + RAM[addr] = value; + } + else if (addr >= 0xA000) { mapper.WriteMemory(addr, value); } - else if (addr < 0xA000) + else if (addr >= 0x8000) { if (ppu.VRAM_access_write) { VRAM[(VRAM_Bank * 0x2000) + (addr - 0x8000)] = value; } } - else if (addr < 0xC000) - { - mapper.WriteMemory(addr, value); - } - else if (addr < 0xD000) - { - RAM[addr - 0xC000] = value; - } - else if (addr < 0xE000) - { - RAM[(RAM_Bank * 0x1000) + (addr - 0xD000)] = value; - } - else if (addr < 0xF000) - { - RAM[addr - 0xE000] = value; - } - else if (addr < 0xFE00) - { - RAM[(RAM_Bank * 0x1000) + (addr - 0xF000)] = value; - } - else if (addr < 0xFEA0) - { - if (ppu.OAM_access_write) { OAM[addr - 0xFE00] = value; } - } - else if (addr < 0xFF00) - { - // unmapped, writing has no effect - } - else if (addr < 0xFF80) - { - Write_Registers(addr, value); - } - else if (addr < 0xFFFF) - { - ZP_RAM[addr - 0xFF80] = value; - } else { - Write_Registers(addr, value); + if (addr >= 0x900) + { + mapper.WriteMemory(addr, value); + } + else + { + if (addr < 0x100) + { + if ((GB_bios_register & 0x1) == 0) + { + // No Writing to BIOS + } + else + { + mapper.WriteMemory(addr, value); + } + } + else if (addr >= 0x200) + { + if (((GB_bios_register & 0x1) == 0) && is_GBC) + { + // No Writing to BIOS + } + else + { + mapper.WriteMemory(addr, value); + } + } + else + { + mapper.WriteMemory(addr, value); + } + } } } @@ -305,40 +293,43 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return 0xFF; } - if (addr < 0x900) + if (addr < 0x8000) { - if (addr < 0x100) - { - // return Either BIOS ROM or Game ROM - if ((GB_bios_register & 0x1) == 0) - { - return _bios[addr]; // Return BIOS - } - else - { - return mapper.ReadMemory(addr); - } - } - else if (addr >= 0x200) - { - // return Either BIOS ROM or Game ROM - if (((GB_bios_register & 0x1) == 0) && is_GBC) - { - return _bios[addr]; // Return BIOS - } - else - { - return mapper.ReadMemory(addr); - } - } - else + if (addr >= 0x900) { return mapper.ReadMemory(addr); } - } - else if (addr < 0x8000) - { - return mapper.PeekMemory(addr); + else + { + if (addr < 0x100) + { + // return Either BIOS ROM or Game ROM + if ((GB_bios_register & 0x1) == 0) + { + return _bios[addr]; // Return BIOS + } + else + { + return mapper.ReadMemory(addr); + } + } + else if (addr >= 0x200) + { + // return Either BIOS ROM or Game ROM + if (((GB_bios_register & 0x1) == 0) && is_GBC) + { + return _bios[addr]; // Return BIOS + } + else + { + return mapper.ReadMemory(addr); + } + } + else + { + return mapper.ReadMemory(addr); + } + } } else if (addr < 0xA000) { @@ -349,21 +340,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { return mapper.PeekMemory(addr); } - else if (addr < 0xD000) - { - return RAM[addr - 0xC000]; - } - else if (addr < 0xE000) - { - return RAM[(RAM_Bank * 0x1000) + (addr - 0xD000)]; - } - else if (addr < 0xF000) - { - return RAM[addr - 0xE000]; - } else if (addr < 0xFE00) { - return RAM[(RAM_Bank * 0x1000) + (addr - 0xF000)]; + addr = (ushort)(RAM_Bank * (addr & 0x1000) + (addr & 0xFFF)); + return RAM[addr]; } else if (addr < 0xFEA0) { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs index 539db02990..eeb6be4dbe 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs @@ -9,6 +9,8 @@ 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; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IEmulator.cs index 210082f3db..0992d34048 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IEmulator.cs @@ -16,32 +16,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink //Update the color palette if a setting changed if (linkSettings.Palette_L == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - L.color_palette[0] = color_palette_BW[0]; - L.color_palette[1] = color_palette_BW[1]; - L.color_palette[2] = color_palette_BW[2]; - L.color_palette[3] = color_palette_BW[3]; + L.ppu.color_palette[0] = color_palette_BW[0]; + L.ppu.color_palette[1] = color_palette_BW[1]; + L.ppu.color_palette[2] = color_palette_BW[2]; + L.ppu.color_palette[3] = color_palette_BW[3]; } else { - L.color_palette[0] = color_palette_Gr[0]; - L.color_palette[1] = color_palette_Gr[1]; - L.color_palette[2] = color_palette_Gr[2]; - L.color_palette[3] = color_palette_Gr[3]; + L.ppu.color_palette[0] = color_palette_Gr[0]; + L.ppu.color_palette[1] = color_palette_Gr[1]; + L.ppu.color_palette[2] = color_palette_Gr[2]; + L.ppu.color_palette[3] = color_palette_Gr[3]; } if (linkSettings.Palette_R == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - R.color_palette[0] = color_palette_BW[0]; - R.color_palette[1] = color_palette_BW[1]; - R.color_palette[2] = color_palette_BW[2]; - R.color_palette[3] = color_palette_BW[3]; + R.ppu.color_palette[0] = color_palette_BW[0]; + R.ppu.color_palette[1] = color_palette_BW[1]; + R.ppu.color_palette[2] = color_palette_BW[2]; + R.ppu.color_palette[3] = color_palette_BW[3]; } else { - R.color_palette[0] = color_palette_Gr[0]; - R.color_palette[1] = color_palette_Gr[1]; - R.color_palette[2] = color_palette_Gr[2]; - R.color_palette[3] = color_palette_Gr[3]; + R.ppu.color_palette[0] = color_palette_Gr[0]; + R.ppu.color_palette[1] = color_palette_Gr[1]; + R.ppu.color_palette[2] = color_palette_Gr[2]; + R.ppu.color_palette[3] = color_palette_Gr[3]; } if (_tracer.Enabled) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IEmulator.cs index 4c01e5a544..f39a0071b2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IEmulator.cs @@ -16,47 +16,47 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x //Update the color palette if a setting changed if (Link3xSettings.Palette_L == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - L.color_palette[0] = color_palette_BW[0]; - L.color_palette[1] = color_palette_BW[1]; - L.color_palette[2] = color_palette_BW[2]; - L.color_palette[3] = color_palette_BW[3]; + L.ppu.color_palette[0] = color_palette_BW[0]; + L.ppu.color_palette[1] = color_palette_BW[1]; + L.ppu.color_palette[2] = color_palette_BW[2]; + L.ppu.color_palette[3] = color_palette_BW[3]; } else { - L.color_palette[0] = color_palette_Gr[0]; - L.color_palette[1] = color_palette_Gr[1]; - L.color_palette[2] = color_palette_Gr[2]; - L.color_palette[3] = color_palette_Gr[3]; + L.ppu.color_palette[0] = color_palette_Gr[0]; + L.ppu.color_palette[1] = color_palette_Gr[1]; + L.ppu.color_palette[2] = color_palette_Gr[2]; + L.ppu.color_palette[3] = color_palette_Gr[3]; } if (Link3xSettings.Palette_C == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - C.color_palette[0] = color_palette_BW[0]; - C.color_palette[1] = color_palette_BW[1]; - C.color_palette[2] = color_palette_BW[2]; - C.color_palette[3] = color_palette_BW[3]; + C.ppu.color_palette[0] = color_palette_BW[0]; + C.ppu.color_palette[1] = color_palette_BW[1]; + C.ppu.color_palette[2] = color_palette_BW[2]; + C.ppu.color_palette[3] = color_palette_BW[3]; } else { - C.color_palette[0] = color_palette_Gr[0]; - C.color_palette[1] = color_palette_Gr[1]; - C.color_palette[2] = color_palette_Gr[2]; - C.color_palette[3] = color_palette_Gr[3]; + C.ppu.color_palette[0] = color_palette_Gr[0]; + C.ppu.color_palette[1] = color_palette_Gr[1]; + C.ppu.color_palette[2] = color_palette_Gr[2]; + C.ppu.color_palette[3] = color_palette_Gr[3]; } if (Link3xSettings.Palette_R == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - R.color_palette[0] = color_palette_BW[0]; - R.color_palette[1] = color_palette_BW[1]; - R.color_palette[2] = color_palette_BW[2]; - R.color_palette[3] = color_palette_BW[3]; + R.ppu.color_palette[0] = color_palette_BW[0]; + R.ppu.color_palette[1] = color_palette_BW[1]; + R.ppu.color_palette[2] = color_palette_BW[2]; + R.ppu.color_palette[3] = color_palette_BW[3]; } else { - R.color_palette[0] = color_palette_Gr[0]; - R.color_palette[1] = color_palette_Gr[1]; - R.color_palette[2] = color_palette_Gr[2]; - R.color_palette[3] = color_palette_Gr[3]; + R.ppu.color_palette[0] = color_palette_Gr[0]; + R.ppu.color_palette[1] = color_palette_Gr[1]; + R.ppu.color_palette[2] = color_palette_Gr[2]; + R.ppu.color_palette[3] = color_palette_Gr[3]; } if (_tracer.Enabled) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IEmulator.cs index 911961b33a..b4566001dc 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IEmulator.cs @@ -16,62 +16,62 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x //Update the color palette if a setting changed if (Link4xSettings.Palette_A == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - A.color_palette[0] = color_palette_BW[0]; - A.color_palette[1] = color_palette_BW[1]; - A.color_palette[2] = color_palette_BW[2]; - A.color_palette[3] = color_palette_BW[3]; + A.ppu.color_palette[0] = color_palette_BW[0]; + A.ppu.color_palette[1] = color_palette_BW[1]; + A.ppu.color_palette[2] = color_palette_BW[2]; + A.ppu.color_palette[3] = color_palette_BW[3]; } else { - A.color_palette[0] = color_palette_Gr[0]; - A.color_palette[1] = color_palette_Gr[1]; - A.color_palette[2] = color_palette_Gr[2]; - A.color_palette[3] = color_palette_Gr[3]; + A.ppu.color_palette[0] = color_palette_Gr[0]; + A.ppu.color_palette[1] = color_palette_Gr[1]; + A.ppu.color_palette[2] = color_palette_Gr[2]; + A.ppu.color_palette[3] = color_palette_Gr[3]; } if (Link4xSettings.Palette_B == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - B.color_palette[0] = color_palette_BW[0]; - B.color_palette[1] = color_palette_BW[1]; - B.color_palette[2] = color_palette_BW[2]; - B.color_palette[3] = color_palette_BW[3]; + B.ppu.color_palette[0] = color_palette_BW[0]; + B.ppu.color_palette[1] = color_palette_BW[1]; + B.ppu.color_palette[2] = color_palette_BW[2]; + B.ppu.color_palette[3] = color_palette_BW[3]; } else { - B.color_palette[0] = color_palette_Gr[0]; - B.color_palette[1] = color_palette_Gr[1]; - B.color_palette[2] = color_palette_Gr[2]; - B.color_palette[3] = color_palette_Gr[3]; + B.ppu.color_palette[0] = color_palette_Gr[0]; + B.ppu.color_palette[1] = color_palette_Gr[1]; + B.ppu.color_palette[2] = color_palette_Gr[2]; + B.ppu.color_palette[3] = color_palette_Gr[3]; } if (Link4xSettings.Palette_C == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - C.color_palette[0] = color_palette_BW[0]; - C.color_palette[1] = color_palette_BW[1]; - C.color_palette[2] = color_palette_BW[2]; - C.color_palette[3] = color_palette_BW[3]; + C.ppu.color_palette[0] = color_palette_BW[0]; + C.ppu.color_palette[1] = color_palette_BW[1]; + C.ppu.color_palette[2] = color_palette_BW[2]; + C.ppu.color_palette[3] = color_palette_BW[3]; } else { - C.color_palette[0] = color_palette_Gr[0]; - C.color_palette[1] = color_palette_Gr[1]; - C.color_palette[2] = color_palette_Gr[2]; - C.color_palette[3] = color_palette_Gr[3]; + C.ppu.color_palette[0] = color_palette_Gr[0]; + C.ppu.color_palette[1] = color_palette_Gr[1]; + C.ppu.color_palette[2] = color_palette_Gr[2]; + C.ppu.color_palette[3] = color_palette_Gr[3]; } if (Link4xSettings.Palette_D == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - D.color_palette[0] = color_palette_BW[0]; - D.color_palette[1] = color_palette_BW[1]; - D.color_palette[2] = color_palette_BW[2]; - D.color_palette[3] = color_palette_BW[3]; + D.ppu.color_palette[0] = color_palette_BW[0]; + D.ppu.color_palette[1] = color_palette_BW[1]; + D.ppu.color_palette[2] = color_palette_BW[2]; + D.ppu.color_palette[3] = color_palette_BW[3]; } else { - D.color_palette[0] = color_palette_Gr[0]; - D.color_palette[1] = color_palette_Gr[1]; - D.color_palette[2] = color_palette_Gr[2]; - D.color_palette[3] = color_palette_Gr[3]; + D.ppu.color_palette[0] = color_palette_Gr[0]; + D.ppu.color_palette[1] = color_palette_Gr[1]; + D.ppu.color_palette[2] = color_palette_Gr[2]; + D.ppu.color_palette[3] = color_palette_Gr[3]; } if (_tracer.Enabled) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.IEmulator.cs index 68b5b1c0ee..ef4bde0a2e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.IEmulator.cs @@ -15,17 +15,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubGBHawk //Update the color palette if a setting changed if (GetSettings().Palette == GBHawk.GBHawk.GBSettings.PaletteType.BW) { - _GBCore.color_palette[0] = GBHawk.GBHawk.color_palette_BW[0]; - _GBCore.color_palette[1] = GBHawk.GBHawk.color_palette_BW[1]; - _GBCore.color_palette[2] = GBHawk.GBHawk.color_palette_BW[2]; - _GBCore.color_palette[3] = GBHawk.GBHawk.color_palette_BW[3]; + _GBCore.ppu.color_palette[0] = GBHawk.GBHawk.color_palette_BW[0]; + _GBCore.ppu.color_palette[1] = GBHawk.GBHawk.color_palette_BW[1]; + _GBCore.ppu.color_palette[2] = GBHawk.GBHawk.color_palette_BW[2]; + _GBCore.ppu.color_palette[3] = GBHawk.GBHawk.color_palette_BW[3]; } else { - _GBCore.color_palette[0] = GBHawk.GBHawk.color_palette_Gr[0]; - _GBCore.color_palette[1] = GBHawk.GBHawk.color_palette_Gr[1]; - _GBCore.color_palette[2] = GBHawk.GBHawk.color_palette_Gr[2]; - _GBCore.color_palette[3] = GBHawk.GBHawk.color_palette_Gr[3]; + _GBCore.ppu.color_palette[0] = GBHawk.GBHawk.color_palette_Gr[0]; + _GBCore.ppu.color_palette[1] = GBHawk.GBHawk.color_palette_Gr[1]; + _GBCore.ppu.color_palette[2] = GBHawk.GBHawk.color_palette_Gr[2]; + _GBCore.ppu.color_palette[3] = GBHawk.GBHawk.color_palette_Gr[3]; } if (_tracer.Enabled) {