GBHAwk: Linked play initial capability

This commit is contained in:
alyosha-tas 2019-01-03 19:24:18 -06:00
parent 12ad2d5b36
commit 32e4a2d9a4
4 changed files with 49 additions and 4 deletions

View File

@ -16,6 +16,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public int serial_bits;
public bool clk_internal;
public int clk_rate;
public byte going_out;
public byte coming_in;
public byte ReadReg(int addr)
{
@ -84,16 +86,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
if (serial_start)
{
if (serial_clock > 0) { serial_clock--; }
if (serial_clock == 0)
{
if (serial_bits > 0)
{
send_external_bit((byte)(serial_data & 0x80));
byte temp = get_external_bit();
serial_data = (byte)((serial_data << 1) | temp);
serial_bits--;
if (serial_bits == 0)
{
serial_control &= 0x7F;
@ -122,12 +124,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// no device connected returns 0xFF
public byte get_external_bit()
{
return 1;
return coming_in;
}
// calling this function buts an external bit on the cable line
public void send_external_bit(byte bit_send)
{
going_out = (byte)(bit_send >> 7);
}
public void Reset()
@ -135,6 +138,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
serial_control = 0x7E;
serial_start = false;
serial_data = 0x00;
going_out = 0;
coming_in = 1;
}
public void SyncState(Serializer ser)
@ -146,6 +151,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Sync("serial_bits", ref serial_bits);
ser.Sync("clk_internal", ref clk_internal);
ser.Sync("clk_rate", ref clk_rate);
ser.Sync("going_out", ref going_out);
ser.Sync("coming_in", ref coming_in);
}
}
}

View File

@ -104,6 +104,40 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
L.do_single_step();
R.do_single_step();
// the signal to shift out a bit is when serial_clock = 1
if (L.serialport.serial_clock == 1)
{
if (LinkConnected)
{
L.serialport.send_external_bit((byte)(L.serialport.serial_data & 0x80));
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start)
{
R.serialport.serial_clock = 1;
R.serialport.send_external_bit((byte)(R.serialport.serial_data & 0x80));
R.serialport.coming_in = L.serialport.going_out;
}
L.serialport.coming_in = R.serialport.going_out;
}
}
else if (R.serialport.serial_clock == 1)
{
if (LinkConnected)
{
R.serialport.send_external_bit((byte)(R.serialport.serial_data & 0x80));
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start)
{
L.serialport.serial_clock = 1;
L.serialport.send_external_bit((byte)(L.serialport.serial_data & 0x80));
L.serialport.coming_in = R.serialport.going_out;
}
R.serialport.coming_in = L.serialport.going_out;
}
}
// if we hit a frame boundary, update video
if (L.vblank_rise)
{

View File

@ -57,6 +57,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
ser.Sync("Lag", ref _lagcount);
ser.Sync("Frame", ref _frame);
ser.Sync("IsLag", ref _islag);
ser.Sync("_cableconnected", ref _cableconnected);
ser.Sync("_cablediscosignal", ref _cablediscosignal);
_controllerDeck.SyncState(ser);
}
}

View File

@ -72,6 +72,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
SetupMemoryDomains();
HardReset();
LinkConnected = _cableconnected;
}
public void HardReset()