GBHawk: Implement power button

This commit is contained in:
alyosha-tas 2020-02-22 08:47:39 -05:00
parent ab119af113
commit 1b301862db
25 changed files with 151 additions and 51 deletions

View File

@ -74,6 +74,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
skip_once = false;
Halt_bug_2 = false;
Halt_bug_3 = false;
interrupts_enabled = false;
}
}
}

View File

@ -69,6 +69,10 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
TotalExecutedCycles = 8;
stop_check = false;
cur_instr = new ushort[] { IDLE, IDLE, HALT_CHK, OP };
stopped = jammed = halted = FlagI = false;
instr_pntr = 0;
EI_pending = 0;
CB_prefix = false;
}
// Memory Access

View File

@ -930,6 +930,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
Audio_Regs = new byte[21];
for (int i = 0; i < 0x16; i++)
{
WriteReg(0xFF10 + i, 0);
}
SQ1_duty_cntr = SQ2_duty_cntr = 0;
SQ1_enable = SQ1_swp_enable = SQ2_enable = WAVE_enable = NOISE_enable = false;
SQ1_len_en = SQ2_len_en = WAVE_len_en = NOISE_len_en = false;
SQ1_output = SQ2_output = WAVE_output = NOISE_output = 0;
SQ1_length = SQ2_length = WAVE_length = NOISE_length = 0;
SQ1_len_cntr = SQ2_len_cntr = WAVE_len_cntr = NOISE_len_cntr = 0;
master_audio_clock = 0;
sequencer_len = 0;

View File

@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
_frame++;
if (controller.IsPressed("Power"))
if (controller.IsPressed("P1 Power"))
{
HardReset();
}
@ -117,6 +117,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
if (in_vblank && !in_vblank_old)
{
_islag = false;
// update the controller state on VBlank
GetControllerState(controller);
@ -257,6 +259,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
Acc_Y_state = _controllerDeck.ReadAccY1(controller);
}
public int Frame => _frame;
public string SystemId => "GB";

View File

@ -190,6 +190,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Register<ITraceable>(_tracer);
ser.Register<IStatable>(new StateSerializer(SyncState, false));
SetupMemoryDomains();
cpu.SetCallbacks(ReadMemory, PeekMemory, PeekMemory, WriteMemory);
HardReset();
iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1);
@ -287,7 +288,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
GBC_compat = is_GBC;
in_vblank = true; // we start off in vblank since the LCD is off
in_vblank_old = true;
double_speed = false;
VRAM_Bank = 0;
RAM_Bank = 1; // RAM bank always starts as 1 (even writing zero still sets 1)
Register_Reset();
@ -295,9 +297,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ppu.Reset();
audio.Reset();
serialport.Reset();
cpu.SetCallbacks(ReadMemory, PeekMemory, PeekMemory, WriteMemory);
mapper.Reset();
cpu.Reset();
_vidbuffer = new int[VirtualWidth * VirtualHeight];
frame_buffer = new int[VirtualWidth * VirtualHeight];
}
@ -459,7 +461,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
}
mapper.Core = this;
mapper.Initialize();
if (cart_RAM != null && (mppr != "MBC7"))
{
@ -532,6 +533,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
Use_MT = true;
// currently no date / time input for TAMA5
}
}
}

View File

@ -512,6 +512,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
input_register = 0xCF; // not reading any input
REG_FFFF = 0;
REG_FF0F = 0xE0;
REG_FF0F_OLD = 0xE0;
//undocumented registers
undoc_6C = 0xFE;
undoc_72 = 0;

View File

@ -33,7 +33,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
}
public virtual void Initialize()
public virtual void Reset()
{
}

View File

@ -1,45 +1,70 @@
using BizHawk.Emulation.Cores.Components.LR35902;
using BizHawk.Common;
using BizHawk.Emulation.Cores.Components.LR35902;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
// Default mapper with no bank switching
// Gameboy Camera Mapper (no camera support yet)
// 128 kb of RAM
public class MapperCamera : MapperBase
{
public override void Initialize()
public int ROM_bank;
public int RAM_bank;
public bool RAM_enable;
public int ROM_mask;
public int RAM_mask;
public override void Reset()
{
// nothing to initialize
ROM_bank = 1;
RAM_bank = 0;
RAM_enable = false;
ROM_mask = Core._rom.Length / 0x4000 - 1;
RAM_mask = 0;
RAM_mask = Core.cart_RAM.Length / 0x2000 - 1;
if (Core.cart_RAM.Length == 0x800) { RAM_mask = 0; }
}
public override byte ReadMemory(ushort addr)
{
if (addr < 0x8000)
if (addr < 0x4000)
{
return Core._rom[addr];
}
else if (addr < 0x8000)
{
return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000];
}
else
{
if (Core.cart_RAM != null)
if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length))
{
return Core.cart_RAM[addr - 0xA000];
return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000];
}
else
{
return 0;
return 0xFF;
}
}
}
public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags)
{
if (addr < 0x8000)
if (addr < 0x4000)
{
// lowest bank is fixed, but is still effected by mode
SetCDLROM(flags, addr);
}
else if (addr < 0x8000)
{
SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000);
}
else
{
if (Core.cart_RAM != null)
if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length))
{
SetCDLRAM(flags, addr - 0xA000);
SetCDLRAM(flags, (addr - 0xA000) + RAM_bank * 0x2000);
}
else
{
@ -57,13 +82,39 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
if (addr < 0x8000)
{
// no mapping hardware available
if (addr < 0x2000)
{
RAM_enable = (value & 0xF) == 0xA;
}
else if (addr < 0x3000)
{
ROM_bank = value;
ROM_bank &= ROM_mask;
}
else if (addr < 0x4000)
{
}
else if (addr < 0x5000)
{
//registers
}
else if (addr < 0x6000)
{
ROM_bank &= 0x1F;
ROM_bank |= ((value & 3) << 5);
ROM_bank &= ROM_mask;
}
else
{
RAM_bank = 0;
}
}
else
{
if (Core.cart_RAM != null)
if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length))
{
Core.cart_RAM[addr - 0xA000] = value;
Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000] = value;
}
}
}
@ -72,5 +123,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
WriteMemory(addr, value);
}
public override void SyncState(Serializer ser)
{
ser.Sync(nameof(ROM_bank), ref ROM_bank);
ser.Sync(nameof(ROM_mask), ref ROM_mask);
ser.Sync(nameof(RAM_bank), ref RAM_bank);
ser.Sync(nameof(RAM_mask), ref RAM_mask);
ser.Sync(nameof(RAM_enable), ref RAM_enable);
}
}
}

View File

@ -5,7 +5,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// Default mapper with no bank switching
public class MapperDefault : MapperBase
{
public override void Initialize()
public override void Reset()
{
// nothing to initialize
}

View File

@ -13,7 +13,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int RAM_mask;
public bool IR_signal;
public override void Initialize()
public override void Reset()
{
ROM_bank = 0;
RAM_bank = 0;

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int RTC_low_clock;
public int RTC_seconds;
public override void Initialize()
public override void Reset()
{
ROM_bank = 0;
RAM_bank = 0;

View File

@ -13,7 +13,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int ROM_mask;
public int RAM_mask;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
RAM_bank = 0;

View File

@ -13,13 +13,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int ROM_mask;
public int RAM_mask;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
RAM_bank = 0;
RAM_enable = false;
sel_mode = false;
ROM_mask = (Core._rom.Length / 0x4000 * 2) - 1; // due to how mapping workd, we want a 1 bit higher mask
ROM_mask = (Core._rom.Length / 0x4000 * 2) - 1; // due to how mapping works, we want a 1 bit higher mask
RAM_mask = 0;
if (Core.cart_RAM != null)
{

View File

@ -11,7 +11,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public bool RAM_enable;
public int ROM_mask;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
RAM_bank = 0;

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public bool halt;
public int RTC_offset;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
RAM_bank = 0;
@ -36,11 +36,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
if (Core.cart_RAM.Length == 0x800) { RAM_mask = 0; }
}
RTC_regs[0] = 0;
RTC_regs[1] = 0;
RTC_regs[2] = 0;
RTC_regs[3] = 0;
RTC_regs[4] = 0;
RTC_regs_latch[0] = 0;
RTC_regs_latch[1] = 0;
RTC_regs_latch[2] = 0;
RTC_regs_latch[3] = 0;
RTC_regs_latch[4] = 0;
RTC_regs_latch_wr = true;
}

View File

@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int ROM_mask;
public int RAM_mask;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
RAM_bank = 0;

View File

@ -5,7 +5,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// Default mapper with no bank switching
public class MapperMBC6 : MapperBase
{
public override void Initialize()
public override void Reset()
{
// nothing to initialize
}

View File

@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public bool countdown_start;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
RAM_enable_1 = RAM_enable_2 = false;
@ -48,7 +48,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
acc_x_high = 0x80;
acc_y_low = 0;
acc_y_high = 0x80;
}
// reset acceerometer
is_erased = false;
// EEPROM related
CS_prev = CLK_prev = DI_prev = DO = instr_read = perf_instr = WR_EN = countdown_start = false;
instr_bit_counter = instr = EE_addr = instr_case = instr_clocks = EE_value = countdown = 0;
}
public override byte ReadMemory(ushort addr)
{

View File

@ -5,7 +5,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// Default mapper with no bank switching
public class MapperMMM01 : MapperBase
{
public override void Initialize()
public override void Reset()
{
// nothing to initialize
}

View File

@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int ROM_bank;
public int ROM_mask;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
ROM_mask = Core._rom.Length / 0x4000 - 1;

View File

@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public ushort addr_last;
public int counter;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
ROM_mask = Core._rom.Length / 0x4000 - 1;

View File

@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public ushort addr_last;
public int counter;
public override void Initialize()
public override void Reset()
{
ROM_bank = 1;
ROM_mask = Core._rom.Length / 0x4000 - 1;

View File

@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public byte Chip_return_low;
public byte Chip_return_high;
public override void Initialize()
public override void Reset()
{
ROM_bank = 0;
RAM_bank = 0;
@ -39,11 +39,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
if (Core.cart_RAM.Length == 0x800) { RAM_mask = 0; }
}
RTC_regs[0] = 0;
RTC_regs[1] = 0;
RTC_regs[2] = 0;
RTC_regs[3] = 0;
RTC_regs[4] = 0;
RAM_addr_low = RAM_addr_high = RAM_val_low = RAM_val_high = 0;
Chip_return_low = Chip_return_high = 0;
halt = false;
ctrl = 0;
}

View File

@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int ROM_bank;
public int ROM_mask;
public override void Initialize()
public override void Reset()
{
ROM_bank = 0;
ROM_mask = Core._rom.Length / 0x8000 - 1;

View File

@ -136,10 +136,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public void Reset()
{
serial_control = 0x7E;
serial_start = false;
serial_data = 0x00;
serial_start = false;
serial_clock = 0;
serial_bits = 0;
clk_rate = 16;
going_out = 0;
coming_in = 1;
coming_in = 1;
can_pulse = false;
}
public void SyncState(Serializer ser)