GBHawk: linking improvements

This commit is contained in:
alyosha-tas 2019-09-30 11:17:15 -04:00
parent 1520529acf
commit 5cfda44cbf
3 changed files with 33 additions and 18 deletions

View File

@ -12,6 +12,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public byte serial_control;
public byte serial_data;
public bool serial_start;
public bool can_pulse;
public int serial_clock;
public int serial_bits;
public int clk_rate;
@ -48,18 +49,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
if (((value & 2) > 0) && Core.GBC_compat)
{
clk_rate = 256;
clk_rate = 16;
}
else
{
clk_rate = 512;
}
serial_clock = clk_rate;
can_pulse = true;
}
else
{
clk_rate = -1;
serial_clock = clk_rate;
can_pulse = false;
}
}
else if (serial_start)
@ -68,18 +71,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
if (((value & 2) > 0) && Core.GBC_compat)
{
clk_rate = 256;
clk_rate = 16;
}
else
{
clk_rate = 512;
}
serial_clock = clk_rate;
can_pulse = true;
}
else
{
clk_rate = -1;
serial_clock = clk_rate;
can_pulse = false;
}
}
@ -123,6 +128,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
else
{
serial_clock = clk_rate;
if (clk_rate > 0) { can_pulse = true; }
}
}
}
@ -148,6 +154,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
ser.Sync(nameof(clk_rate), ref clk_rate);
ser.Sync(nameof(going_out), ref going_out);
ser.Sync(nameof(coming_in), ref coming_in);
ser.Sync(nameof(can_pulse), ref can_pulse);
}
}
}

View File

@ -103,11 +103,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
if (_cableconnected)
{
// the signal to shift out a bit is when serial_clock = 1
if (((L.serialport.serial_clock == 1) || (L.serialport.serial_clock == 2)) && !do_r_next)
if (((L.serialport.serial_clock == 1) || (L.serialport.serial_clock == 2)) && (L.serialport.clk_rate > 0) && !do_r_next)
{
L.serialport.going_out = (byte)(L.serialport.serial_data >> 7);
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start)
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start && L.serialport.can_pulse)
{
R.serialport.serial_clock = L.serialport.serial_clock;
R.serialport.going_out = (byte)(R.serialport.serial_data >> 7);
@ -115,14 +115,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
}
L.serialport.coming_in = R.serialport.going_out;
L.serialport.can_pulse = false;
}
else if ((R.serialport.serial_clock == 1) || (R.serialport.serial_clock == 2))
else if (((R.serialport.serial_clock == 1) || (R.serialport.serial_clock == 2)) && (R.serialport.clk_rate > 0))
{
do_r_next = false;
R.serialport.going_out = (byte)(R.serialport.serial_data >> 7);
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start)
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start && R.serialport.can_pulse)
{
L.serialport.serial_clock = R.serialport.serial_clock;
L.serialport.going_out = (byte)(L.serialport.serial_data >> 7);
@ -130,6 +131,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
}
R.serialport.coming_in = L.serialport.going_out;
R.serialport.can_pulse = false;
if (R.serialport.serial_clock == 2) { do_r_next = true; }
}

View File

@ -138,11 +138,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
if (_cableconnected_LC)
{
// the signal to shift out a bit is when serial_clock = 1
if (((L.serialport.serial_clock == 1) || (L.serialport.serial_clock == 2)) && !do_2_next)
if (((L.serialport.serial_clock == 1) || (L.serialport.serial_clock == 2)) && (L.serialport.clk_rate > 0) && !do_2_next)
{
L.serialport.going_out = (byte)(L.serialport.serial_data >> 7);
if ((C.serialport.clk_rate == -1) && C.serialport.serial_start)
if ((C.serialport.clk_rate == -1) && C.serialport.serial_start && L.serialport.can_pulse)
{
C.serialport.serial_clock = L.serialport.serial_clock;
C.serialport.going_out = (byte)(C.serialport.serial_data >> 7);
@ -150,14 +150,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
}
L.serialport.coming_in = C.serialport.going_out;
L.serialport.can_pulse = false;
}
else if ((C.serialport.serial_clock == 1) || (C.serialport.serial_clock == 2))
else if (((C.serialport.serial_clock == 1) || (C.serialport.serial_clock == 2)) && (C.serialport.clk_rate > 0))
{
do_2_next = false;
C.serialport.going_out = (byte)(C.serialport.serial_data >> 7);
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start)
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start && C.serialport.can_pulse)
{
L.serialport.serial_clock = C.serialport.serial_clock;
L.serialport.going_out = (byte)(L.serialport.serial_data >> 7);
@ -165,6 +166,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
}
C.serialport.coming_in = L.serialport.going_out;
C.serialport.can_pulse = false;
if (C.serialport.serial_clock == 2) { do_2_next = true; }
}
@ -180,11 +182,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
else if (_cableconnected_CR)
{
// the signal to shift out a bit is when serial_clock = 1
if (((C.serialport.serial_clock == 1) || (C.serialport.serial_clock == 2)) && !do_2_next)
if (((C.serialport.serial_clock == 1) || (C.serialport.serial_clock == 2)) && (C.serialport.clk_rate > 0) && !do_2_next)
{
C.serialport.going_out = (byte)(C.serialport.serial_data >> 7);
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start)
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start && C.serialport.can_pulse)
{
R.serialport.serial_clock = C.serialport.serial_clock;
R.serialport.going_out = (byte)(R.serialport.serial_data >> 7);
@ -192,14 +194,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
}
C.serialport.coming_in = R.serialport.going_out;
C.serialport.can_pulse = false;
}
else if ((R.serialport.serial_clock == 1) || (R.serialport.serial_clock == 2))
else if (((R.serialport.serial_clock == 1) || (R.serialport.serial_clock == 2)) && (R.serialport.clk_rate > 0))
{
do_2_next = false;
R.serialport.going_out = (byte)(R.serialport.serial_data >> 7);
if ((C.serialport.clk_rate == -1) && C.serialport.serial_start)
if ((C.serialport.clk_rate == -1) && C.serialport.serial_start && R.serialport.can_pulse)
{
C.serialport.serial_clock = R.serialport.serial_clock;
C.serialport.going_out = (byte)(C.serialport.serial_data >> 7);
@ -207,6 +210,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
}
R.serialport.coming_in = C.serialport.going_out;
R.serialport.can_pulse = false;
if (R.serialport.serial_clock == 2) { do_2_next = true; }
}
@ -222,11 +226,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
else if (_cableconnected_RL)
{
// the signal to shift out a bit is when serial_clock = 1
if (((R.serialport.serial_clock == 1) || (R.serialport.serial_clock == 2)) && !do_2_next)
if (((R.serialport.serial_clock == 1) || (R.serialport.serial_clock == 2)) && (R.serialport.clk_rate > 0) && !do_2_next)
{
R.serialport.going_out = (byte)(R.serialport.serial_data >> 7);
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start)
if ((L.serialport.clk_rate == -1) && L.serialport.serial_start && R.serialport.can_pulse)
{
L.serialport.serial_clock = R.serialport.serial_clock;
L.serialport.going_out = (byte)(L.serialport.serial_data >> 7);
@ -234,14 +238,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
}
R.serialport.coming_in = L.serialport.going_out;
R.serialport.can_pulse = false;
}
else if ((L.serialport.serial_clock == 1) || (L.serialport.serial_clock == 2))
else if (((L.serialport.serial_clock == 1) || (L.serialport.serial_clock == 2)) && (L.serialport.clk_rate > 0))
{
do_2_next = false;
L.serialport.going_out = (byte)(L.serialport.serial_data >> 7);
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start)
if ((R.serialport.clk_rate == -1) && R.serialport.serial_start && L.serialport.can_pulse)
{
R.serialport.serial_clock = L.serialport.serial_clock;
R.serialport.going_out = (byte)(R.serialport.serial_data >> 7);
@ -249,6 +254,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
}
L.serialport.coming_in = R.serialport.going_out;
L.serialport.can_pulse = false;
if (L.serialport.serial_clock == 2) { do_2_next = true; }
}