saturnus: get rid of the round-tripping of analogs through the mednafen input system.

This commit is contained in:
nattthebear 2017-06-18 12:25:01 -04:00
parent 9ff2da5265
commit 37b285fe8d
6 changed files with 792 additions and 824 deletions

View File

@ -98,7 +98,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
private abstract class ButtonedDevice : IDevice private abstract class ButtonedDevice : IDevice
{ {
private static readonly FloatRange AnalogFloatRange = new FloatRange(-32767, 0, 32767); private static readonly FloatRange AnalogFloatRange = new FloatRange(0, 128, 255);
protected ButtonedDevice() protected ButtonedDevice()
{ {
@ -164,13 +164,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
int pos = offset + AnalogByteOffset; int pos = offset + AnalogByteOffset;
for (int i = 0; i < _bakedAnalogNames.Length; i++) for (int i = 0; i < _bakedAnalogNames.Length; i++)
{ {
var data = (int)controller.GetFloat(_bakedAnalogNames[i]); var data = (byte)(int)controller.GetFloat(_bakedAnalogNames[i]);
var datal = (short)Math.Max(-data, 0); dest[pos++] = data;
var datar = (short)Math.Max(data, 0);
dest[pos++] = (byte)datal;
dest[pos++] = (byte)(datal >> 8);
dest[pos++] = (byte)datar;
dest[pos++] = (byte)(datar >> 8);
} }
} }
@ -233,11 +228,18 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
{ {
"Stick Horizontal", "Stick Horizontal",
"Stick Vertical", "Stick Vertical",
"Third Axis" "Left Shoulder",
"Right Shoulder"
}; };
protected override string[] AnalogNames => _analogNames; protected override string[] AnalogNames => _analogNames;
public ThreeDeeGamepad()
{
Definition.FloatRanges[2] = new FloatRange(0, 0, 255);
Definition.FloatRanges[3] = new FloatRange(0, 0, 255);
}
public override void Update(IController controller, byte[] dest, int offset) public override void Update(IController controller, byte[] dest, int offset)
{ {
base.Update(controller, dest, offset); base.Update(controller, dest, offset);
@ -248,37 +250,19 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
private class Mouse : ButtonedDevice private class Mouse : ButtonedDevice
{ {
private static readonly FloatRange MouseFloatRange = new FloatRange(-32768, 0, 32767);
private static readonly string[] _buttonNames = private static readonly string[] _buttonNames =
{ {
"Left", "Right", "Middle", "Start" "Left", "Right", "Middle", "Start"
}; };
protected override string[] ButtonNames => _buttonNames; protected override string[] ButtonNames => _buttonNames;
protected override int ButtonByteOffset => 8;
public Mouse() private static readonly string[] _analogNames =
{ {
Definition.FloatControls.AddRange(new[] { "0X", "0Y" }); "X", "Y"
Definition.FloatRanges.AddRange(new[] { MouseFloatRange, MouseFloatRange }); };
}
private void SetMouseAxis(float value, byte[] dest, int offset) protected override string[] AnalogNames => _analogNames;
{
var data = (short)value;
dest[offset++] = 0;
dest[offset++] = 0;
dest[offset++] = (byte)data;
dest[offset++] = (byte)(data >> 8);
}
public override void Update(IController controller, byte[] dest, int offset)
{
base.Update(controller, dest, offset);
SetMouseAxis(controller.GetFloat("0X"), dest, offset + 0);
SetMouseAxis(controller.GetFloat("0Y"), dest, offset + 4);
}
} }
private class Wheel : ButtonedDevice private class Wheel : ButtonedDevice
@ -319,7 +303,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
}; };
protected override string[] AnalogNames => _analogNames; protected override string[] AnalogNames => _analogNames;
protected override int AnalogByteOffset => 3; protected override int AnalogByteOffset => 4;
} }
private class DualMission : Mission private class DualMission : Mission

Binary file not shown.

View File

@ -42,32 +42,24 @@ void IODevice_3DPad::Power(void)
data_out = 0x01; data_out = 0x01;
} }
void IODevice_3DPad::UpdateInput(const uint8* data, const int32 time_elapsed) void IODevice_3DPad::UpdateInput(const uint8 *data, const int32 time_elapsed)
{ {
const uint16 dtmp = MDFN_de16lsb(&data[0]); const uint16 dtmp = MDFN_de16lsb(&data[0]);
dbuttons = (dbuttons & 0x8800) | (dtmp & 0x0FFF); dbuttons = (dbuttons & 0x8800) | (dtmp & 0x0FFF);
mode = (bool)(dtmp & 0x1000); mode = (bool)(dtmp & 0x1000);
for(unsigned axis = 0; axis < 2; axis++) thumb[0] = data[2];
thumb[1] = data[3];
shoulder[0] = data[4];
shoulder[1] = data[5];
for (unsigned w = 0; w < 2; w++)
{ {
int32 tmp = 32767 + MDFN_de16lsb(&data[0x2 + (axis << 2) + 2]) - MDFN_de16lsb(&data[0x2 + (axis << 2) + 0]);
if(tmp >= (32767 - 128) && tmp < 32767)
tmp = 32767;
tmp = (tmp * 255 + 32767) / 65534;
thumb[axis] = tmp;
}
for(unsigned w = 0; w < 2; w++)
{
shoulder[w] = (MDFN_de16lsb(&data[0xA + (w << 1)]) * 255 + 16383) / 32767;
// May not be right for digital mode, but shouldn't matter too much: // May not be right for digital mode, but shouldn't matter too much:
if(shoulder[w] <= 0x55) if (shoulder[w] <= 0x55)
dbuttons &= ~(0x0800 << (w << 2)); dbuttons &= ~(0x0800 << (w << 2));
else if(shoulder[w] >= 0x8E) else if (shoulder[w] >= 0x8E)
dbuttons |= 0x0800 << (w << 2); dbuttons |= 0x0800 << (w << 2);
} }
} }

View File

@ -52,7 +52,7 @@ void IODevice_Mission::Power(void)
afphase = false; afphase = false;
} }
void IODevice_Mission::UpdateInput(const uint8* data, const int32 time_elapsed) void IODevice_Mission::UpdateInput(const uint8 *data, const int32 time_elapsed)
{ {
const uint32 dtmp = MDFN_de32lsb(&data[0]); const uint32 dtmp = MDFN_de32lsb(&data[0]);
@ -60,13 +60,12 @@ void IODevice_Mission::UpdateInput(const uint8* data, const int32 time_elapsed)
afeswitches = ((dtmp >> 12) & 0x8FF) << 4; afeswitches = ((dtmp >> 12) & 0x8FF) << 4;
afspeed = (dtmp >> 20) & 0x7; afspeed = (dtmp >> 20) & 0x7;
for(unsigned stick = 0; stick < (dual ? 2 : 1); stick++) int offs = 4;
for (unsigned stick = 0; stick < (dual ? 2 : 1); stick++)
{ {
for(unsigned axis = 0; axis < 3; axis++) for (unsigned axis = 0; axis < 3; axis++)
{ {
int32 tmp = 32767 + MDFN_de16lsb(&data[0x3 + ((axis + (stick * 3)) * 4) + 2]) - MDFN_de16lsb(&data[0x3 + ((axis + (stick * 3)) * 4) + 0]); axes[stick][axis] = data[offs++];
axes[stick][axis] = (tmp * 255 + 32767) / 65534;
} }
} }

View File

@ -46,9 +46,9 @@ void IODevice_Mouse::Power(void)
void IODevice_Mouse::UpdateInput(const uint8* data, const int32 time_elapsed) void IODevice_Mouse::UpdateInput(const uint8* data, const int32 time_elapsed)
{ {
accum_xdelta += MDFN_de32lsb(&data[0]); accum_xdelta += data[1];
accum_ydelta -= MDFN_de32lsb(&data[4]); accum_ydelta -= data[2];
buttons = data[8] & 0xF; buttons = data[0] & 0xF;
} }
uint8 IODevice_Mouse::UpdateBus(const uint8 smpc_out, const uint8 smpc_out_asserted) uint8 IODevice_Mouse::UpdateBus(const uint8 smpc_out, const uint8 smpc_out_asserted)

View File

@ -42,26 +42,19 @@ void IODevice_Wheel::Power(void)
data_out = 0x01; data_out = 0x01;
} }
void IODevice_Wheel::UpdateInput(const uint8* data, const int32 time_elapsed) void IODevice_Wheel::UpdateInput(const uint8 *data, const int32 time_elapsed)
{ {
dbuttons = (dbuttons & 0xC) | (MDFN_de16lsb(&data[0]) & 0x07F3); dbuttons = (dbuttons & 0xC) | (MDFN_de16lsb(&data[0]) & 0x07F3);
wheel = data[2];
// if (wheel >= 0x6F)
{
int32 tmp = 32767 + MDFN_de16lsb(&data[0x2 + 2]) - MDFN_de16lsb(&data[0x2 + 0]);
wheel = 1 + tmp * 253 / 65534;
if(wheel >= 0x6F)
dbuttons &= ~0x4; dbuttons &= ~0x4;
else if(wheel <= 0x67) else if (wheel <= 0x67)
dbuttons |= 0x4; dbuttons |= 0x4;
if(wheel <= 0x8F) if (wheel <= 0x8F)
dbuttons &= ~0x8; dbuttons &= ~0x8;
else if(wheel >= 0x97) else if (wheel >= 0x97)
dbuttons |= 0x8; dbuttons |= 0x8;
}
} }
uint8 IODevice_Wheel::UpdateBus(const uint8 smpc_out, const uint8 smpc_out_asserted) uint8 IODevice_Wheel::UpdateBus(const uint8 smpc_out, const uint8 smpc_out_asserted)