Vectrex: a bit more controller and frame cleanup
This commit is contained in:
parent
84b0917f65
commit
9fe277a3ff
|
@ -2,6 +2,7 @@
|
|||
using System.Drawing;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Consoles.Vectrex;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -10,8 +11,29 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public IEnumerable<PadSchema> GetPadSchemas(IEmulator core)
|
||||
{
|
||||
yield return StandardController(1);
|
||||
yield return StandardController(2);
|
||||
var VECSyncSettings = ((VectrexHawk)core).GetSyncSettings().Clone();
|
||||
var port1 = VECSyncSettings.Port1;
|
||||
var port2 = VECSyncSettings.Port2;
|
||||
|
||||
if (port1 == "Vectrex Digital Controller")
|
||||
{
|
||||
yield return StandardController(1);
|
||||
}
|
||||
|
||||
if (port2 == "Vectrex Digital Controller")
|
||||
{
|
||||
yield return StandardController(2);
|
||||
}
|
||||
|
||||
if (port1 == "Vectrex Analog Controller")
|
||||
{
|
||||
yield return AnalogController(1);
|
||||
}
|
||||
|
||||
if (port2 == "Vectrex Analog Controller")
|
||||
{
|
||||
yield return AnalogController(2);
|
||||
}
|
||||
}
|
||||
|
||||
private static PadSchema StandardController(int controller)
|
||||
|
@ -19,7 +41,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return new PadSchema
|
||||
{
|
||||
IsConsole = false,
|
||||
DefaultSize = new Size(280, 380),
|
||||
DefaultSize = new Size(200, 100),
|
||||
Buttons = new[]
|
||||
{
|
||||
new PadSchema.ButtonSchema
|
||||
|
@ -50,6 +72,46 @@ namespace BizHawk.Client.EmuHawk
|
|||
Location = new Point(24, 34),
|
||||
Type = PadSchema.PadInputType.Boolean
|
||||
},
|
||||
new PadSchema.ButtonSchema
|
||||
{
|
||||
Name = $"P{controller} Button 1",
|
||||
DisplayName = "1",
|
||||
Location = new Point(74, 34),
|
||||
Type = PadSchema.PadInputType.Boolean
|
||||
},
|
||||
new PadSchema.ButtonSchema
|
||||
{
|
||||
Name = $"P{controller} Button 2",
|
||||
DisplayName = "2",
|
||||
Location = new Point(98, 34),
|
||||
Type = PadSchema.PadInputType.Boolean
|
||||
},
|
||||
new PadSchema.ButtonSchema
|
||||
{
|
||||
Name = $"P{controller} Button 3",
|
||||
DisplayName = "3",
|
||||
Location = new Point(122, 34),
|
||||
Type = PadSchema.PadInputType.Boolean
|
||||
},
|
||||
new PadSchema.ButtonSchema
|
||||
{
|
||||
Name = $"P{controller} Button 4",
|
||||
DisplayName = "4",
|
||||
Location = new Point(146, 34),
|
||||
Type = PadSchema.PadInputType.Boolean
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static PadSchema AnalogController(int controller)
|
||||
{
|
||||
return new PadSchema
|
||||
{
|
||||
IsConsole = false,
|
||||
DefaultSize = new Size(280, 380),
|
||||
Buttons = new[]
|
||||
{
|
||||
new PadSchema.ButtonSchema
|
||||
{
|
||||
Name = $"P{controller} Button 1",
|
||||
|
@ -81,7 +143,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
new PadSchema.ButtonSchema
|
||||
{
|
||||
Name = $"P{controller} Stick X",
|
||||
Location = new Point(2, 85),
|
||||
Location = new Point(2, 80),
|
||||
MinValue = 127,
|
||||
MidValue = 0,
|
||||
MaxValue = -128,
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
{
|
||||
|
||||
Core._vidbuffer[(int)(Math.Round(x_pos) + 260 * Math.Round(y_pos))] |= (int)(br & bright_int_1);
|
||||
|
||||
|
||||
Core._vidbuffer[(int)(Math.Round(x_pos) + 1 + 260 * Math.Round(y_pos))] |= (int)(br & bright_int_2);
|
||||
Core._vidbuffer[(int)(Math.Round(x_pos) - 1 + 260 * Math.Round(y_pos))] |= (int)(br & bright_int_2);
|
||||
Core._vidbuffer[(int)(Math.Round(x_pos) + 260 * (Math.Round(y_pos) + 1))] |= (int)(br & bright_int_2);
|
||||
|
@ -66,7 +66,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
Core._vidbuffer[(int)(Math.Round(x_pos) + 1 + 260 * (Math.Round(y_pos) - 1))] |= (int)(br & bright_int_3);
|
||||
Core._vidbuffer[(int)(Math.Round(x_pos) - 1 + 260 * (Math.Round(y_pos) + 1))] |= (int)(br & bright_int_3);
|
||||
Core._vidbuffer[(int)(Math.Round(x_pos) - 1 + 260 * (Math.Round(y_pos) - 1))] |= (int)(br & bright_int_3);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,25 +35,31 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
audio.Register[14] = (byte)(_controllerDeck.ReadPort1(controller) & 0xF);
|
||||
audio.Register[14] |= (byte)(_controllerDeck.ReadPort2(controller) << 4);
|
||||
|
||||
// joystick position is based on pot reading
|
||||
joy1_LR = (byte)(Math.Floor(controller.GetFloat("P1 Stick X")) + 128);
|
||||
joy1_UD = (byte)(Math.Floor(controller.GetFloat("P1 Stick Y")) + 128);
|
||||
joy2_LR = (byte)(Math.Floor(controller.GetFloat("P2 Stick X")) + 128);
|
||||
joy2_UD = (byte)(Math.Floor(controller.GetFloat("P2 Stick Y")) + 128);
|
||||
if (ControllerDefinition.Name == "Vectrex Analog Controller")
|
||||
{
|
||||
// joystick position is based on pot reading
|
||||
joy1_LR = (byte)(Math.Floor(controller.GetFloat("P1 Stick X")) + 128);
|
||||
joy1_UD = (byte)(Math.Floor(controller.GetFloat("P1 Stick Y")) + 128);
|
||||
joy2_LR = (byte)(Math.Floor(controller.GetFloat("P2 Stick X")) + 128);
|
||||
joy2_UD = (byte)(Math.Floor(controller.GetFloat("P2 Stick Y")) + 128);
|
||||
}
|
||||
else
|
||||
{
|
||||
// most games just use digital reading, so have a digital option for simplicity
|
||||
// On vectrex there is no such thing as pressing left + right or up + down
|
||||
// so convention will be up and right dominate
|
||||
joy1_UD = joy1_LR = joy2_UD = joy2_LR = 128;
|
||||
|
||||
// override stick reading with digital input if supplied
|
||||
// On vectrex there is no such thing as pressing left + right or up + down
|
||||
// so convention will be up and right dominate
|
||||
if (controller.IsPressed("P1 Down")) { joy1_UD = 0xFF; }
|
||||
if (controller.IsPressed("P1 Up")) { joy1_UD = 0; }
|
||||
if (controller.IsPressed("P1 Left")) { joy1_LR = 0xFF; }
|
||||
if (controller.IsPressed("P1 Right")) { joy1_LR = 0; }
|
||||
|
||||
if (controller.IsPressed("P2 Down")) { joy2_UD = 0xFF; }
|
||||
if (controller.IsPressed("P2 Up")) { joy2_UD = 0; }
|
||||
if (controller.IsPressed("P2 Left")) { joy2_LR = 0xFF; }
|
||||
if (controller.IsPressed("P2 Right")) { joy2_LR = 0; }
|
||||
if (controller.IsPressed("P1 Down")) { joy1_UD = 0xFF; }
|
||||
if (controller.IsPressed("P1 Up")) { joy1_UD = 0; }
|
||||
if (controller.IsPressed("P1 Left")) { joy1_LR = 0xFF; }
|
||||
if (controller.IsPressed("P1 Right")) { joy1_LR = 0; }
|
||||
|
||||
if (controller.IsPressed("P2 Down")) { joy2_UD = 0xFF; }
|
||||
if (controller.IsPressed("P2 Up")) { joy2_UD = 0; }
|
||||
if (controller.IsPressed("P2 Left")) { joy2_LR = 0xFF; }
|
||||
if (controller.IsPressed("P2 Right")) { joy2_LR = 0; }
|
||||
}
|
||||
|
||||
frame_end = false;
|
||||
|
||||
|
@ -69,15 +75,19 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
|
||||
public void do_frame()
|
||||
{
|
||||
_vidbuffer = new int[VirtualWidth * VirtualHeight];
|
||||
|
||||
//for (int i = 0; i < 100; i++)
|
||||
while (!frame_end)
|
||||
for (int i = 0; i < 30000; i++)
|
||||
//while (!frame_end)
|
||||
{
|
||||
internal_state_tick();
|
||||
audio.tick();
|
||||
ppu.tick();
|
||||
cpu.ExecuteOne();
|
||||
cpu.ExecuteOne();
|
||||
|
||||
if (frame_end)
|
||||
{
|
||||
get_video_frame();
|
||||
frame_end = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,10 +116,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
public int _frameHz = 50;
|
||||
|
||||
public int[] _vidbuffer;
|
||||
public int[] _framebuffer;
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return _vidbuffer;
|
||||
return _framebuffer;
|
||||
}
|
||||
|
||||
public void get_video_frame()
|
||||
{
|
||||
for (int i = 0; i < _vidbuffer.Length; i++)
|
||||
{
|
||||
_framebuffer[i] = _vidbuffer[i];
|
||||
_vidbuffer[i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int VirtualWidth => 256 + 4;
|
||||
|
|
|
@ -53,7 +53,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
|
||||
public enum ControllerType
|
||||
{
|
||||
Default,
|
||||
Digital,
|
||||
Analog
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
|
@ -62,14 +63,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
|
||||
[DisplayName("Controller 1")]
|
||||
[Description("Select Controller Type")]
|
||||
[DefaultValue(ControllerType.Default)]
|
||||
[DefaultValue(ControllerType.Digital)]
|
||||
public ControllerType VectrexController1
|
||||
{
|
||||
get { return _VectrexController1; }
|
||||
set
|
||||
{
|
||||
if (value == ControllerType.Default) { Port1 = VectrexHawkControllerDeck.DefaultControllerName; }
|
||||
else { Port1 = VectrexHawkControllerDeck.DefaultControllerName; }
|
||||
if (value == ControllerType.Digital) { Port1 = VectrexHawkControllerDeck.DefaultControllerName; }
|
||||
else { Port1 = "Vectrex Analog Controller"; }
|
||||
|
||||
_VectrexController1 = value;
|
||||
}
|
||||
|
@ -77,14 +78,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
|
||||
[DisplayName("Controller 2")]
|
||||
[Description("Select Controller Type")]
|
||||
[DefaultValue(ControllerType.Default)]
|
||||
[DefaultValue(ControllerType.Digital)]
|
||||
public ControllerType VectrexController2
|
||||
{
|
||||
get { return _VectrexController2; }
|
||||
set
|
||||
{
|
||||
if (value == ControllerType.Default) { Port2 = VectrexHawkControllerDeck.DefaultControllerName; }
|
||||
else { Port2 = VectrexHawkControllerDeck.DefaultControllerName; }
|
||||
if (value == ControllerType.Digital) { Port2 = VectrexHawkControllerDeck.DefaultControllerName; }
|
||||
else { Port2 = "Vectrex Analog Controller"; }
|
||||
|
||||
_VectrexController2 = value;
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
serialport.Reset();
|
||||
|
||||
_vidbuffer = new int[VirtualWidth * VirtualHeight];
|
||||
_framebuffer = new int[VirtualWidth * VirtualHeight];
|
||||
}
|
||||
|
||||
private void ExecFetch(ushort addr)
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
int PortNum { get; }
|
||||
}
|
||||
|
||||
[DisplayName("Vectrex Controller")]
|
||||
[DisplayName("Vectrex Digital Controller")]
|
||||
public class StandardControls : IPort
|
||||
{
|
||||
public StandardControls(int portNum)
|
||||
|
@ -30,12 +30,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
PortNum = portNum;
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
Name = "Vectrex Controller",
|
||||
Name = "Vectrex Digital Controller",
|
||||
BoolButtons = BaseDefinition
|
||||
.Select(b => "P" + PortNum + " " + b)
|
||||
.ToList(),
|
||||
FloatControls = { "P" + PortNum + " Stick X", "P" + PortNum + " Stick Y" },
|
||||
FloatRanges = { new[] { 127.0f, 0, -128.0f }, new[] { -128.0f, 0, 127.0f } }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -72,4 +70,51 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
|
|||
//nothing
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("Vectrex Analog Controller")]
|
||||
public class AnalogControls : IPort
|
||||
{
|
||||
public AnalogControls(int portNum)
|
||||
{
|
||||
PortNum = portNum;
|
||||
Definition = new ControllerDefinition
|
||||
{
|
||||
Name = "Vectrex Analog Controller",
|
||||
BoolButtons = BaseDefinition
|
||||
.Select(b => "P" + PortNum + " " + b)
|
||||
.ToList(),
|
||||
FloatControls = { "P" + PortNum + " Stick X", "P" + PortNum + " Stick Y" },
|
||||
FloatRanges = { new[] { 127.0f, 0, -128.0f }, new[] { -128.0f, 0, 127.0f } }
|
||||
};
|
||||
}
|
||||
|
||||
public int PortNum { get; }
|
||||
|
||||
public ControllerDefinition Definition { get; }
|
||||
|
||||
public byte Read(IController c)
|
||||
{
|
||||
byte result = 0xFF;
|
||||
|
||||
if (c.IsPressed($"P{PortNum} Button 1")) { result &= 0xFE; }
|
||||
if (c.IsPressed($"P{PortNum} Button 2")) { result &= 0xFD; }
|
||||
if (c.IsPressed($"P{PortNum} Button 3")) { result &= 0xFB; }
|
||||
if (c.IsPressed($"P{PortNum} Button 4")) { result &= 0xF7; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static readonly string[] BaseDefinition =
|
||||
{
|
||||
"Button 1",
|
||||
"Button 2",
|
||||
"Button 3",
|
||||
"Button 4"
|
||||
};
|
||||
|
||||
public void SyncState(Serializer ser)
|
||||
{
|
||||
//nothing
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue