tic80 settings for enabling/disabling controllers, proper mnemonics
This commit is contained in:
parent
98a8cdf693
commit
9174d17bd8
Binary file not shown.
|
@ -628,6 +628,41 @@ namespace BizHawk.Client.Common
|
|||
["Offscreen Shot"] = 'o',
|
||||
["Open Tray"] = 'o',
|
||||
["Close Tray"] = 'c',
|
||||
},
|
||||
[VSystemID.Raw.TIC80] = new()
|
||||
{
|
||||
["Mouse Left Click"] = 'l',
|
||||
["Mouse Middle Click"] = 'm',
|
||||
["Mouse Right Click"] = 'r',
|
||||
["Mouse Relative Toggle"] = 't',
|
||||
|
||||
["Minus"] = '-',
|
||||
["Equals"] = '=',
|
||||
["Left Bracket"] = '[',
|
||||
["Right Bracket"] = ']',
|
||||
["Backslash"] = '\\',
|
||||
["Semicolon"] = ';',
|
||||
["Grave"] = '`',
|
||||
["Comma"] = ',',
|
||||
["Period"] = '.',
|
||||
["Slash"] = '/',
|
||||
["Space"] = 's',
|
||||
["Tab"] = 't',
|
||||
["Return"] = 'r',
|
||||
["Backspace"] = 'b',
|
||||
["Delete"] = 'd',
|
||||
["Insert"] = 'i',
|
||||
["Page Up"] = 'u',
|
||||
["Page Down"] = 'v',
|
||||
["Home"] = 'h',
|
||||
["End"] = 'e',
|
||||
["Caps Lock"] = 'l',
|
||||
["Control"] = 'c',
|
||||
["Shift"] = '^',
|
||||
["Alt"] = 'a',
|
||||
["Escape"] = 'e',
|
||||
["F11"] = '1',
|
||||
["F12"] = '2',
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -671,6 +706,13 @@ namespace BizHawk.Client.Common
|
|||
["Motion Left / Right"] = "mX",
|
||||
["Motion Up / Down"] = "mY",
|
||||
["Twist | / |"] = "Twist",
|
||||
},
|
||||
[VSystemID.Raw.TIC80] = new()
|
||||
{
|
||||
["Mouse Position X"] = "mpX",
|
||||
["Mouse Position Y"] = "mpY",
|
||||
["Mouse Scroll X"] = "msX",
|
||||
["Mouse Scroll Y"] = "msY",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
|
|||
}
|
||||
|
||||
[BizImport(CC)]
|
||||
public abstract bool Init(byte[] rom, int sz);
|
||||
public abstract bool Init(byte[] rom, int sz, bool[] inputsEnabled);
|
||||
|
||||
[BizImport(CC)]
|
||||
public abstract void SetInputs(ref TIC80Inputs inputs);
|
||||
|
|
|
@ -46,6 +46,36 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
|
|||
|
||||
public class TIC80SyncSettings
|
||||
{
|
||||
[DisplayName("Gamepad 1 Enable")]
|
||||
[Description("Ignored if game does not support gamepads.")]
|
||||
[DefaultValue(true)]
|
||||
public bool Gamepad1 { get; set; }
|
||||
|
||||
[DisplayName("Gamepad 2 Enable")]
|
||||
[Description("Ignored if game does not support gamepads.")]
|
||||
[DefaultValue(false)]
|
||||
public bool Gamepad2 { get; set; }
|
||||
|
||||
[DisplayName("Gamepad 3 Enable")]
|
||||
[Description("Ignored if game does not support gamepads.")]
|
||||
[DefaultValue(false)]
|
||||
public bool Gamepad3 { get; set; }
|
||||
|
||||
[DisplayName("Gamepad 4 Enable")]
|
||||
[Description("Ignored if game does not support gamepads.")]
|
||||
[DefaultValue(false)]
|
||||
public bool Gamepad4 { get; set; }
|
||||
|
||||
[DisplayName("Mouse Enable")]
|
||||
[Description("Ignored if game does not support the mouse.")]
|
||||
[DefaultValue(true)]
|
||||
public bool Mouse { get; set; }
|
||||
|
||||
[DisplayName("Keyboard Enable")]
|
||||
[Description("Ignored if game does not support the keyboard.")]
|
||||
[DefaultValue(true)]
|
||||
public bool Keyboard { get; set; }
|
||||
|
||||
[DisplayName("Initial Time")]
|
||||
[Description("Initial time of emulation.")]
|
||||
[DefaultValue(typeof(DateTime), "2010-01-01")]
|
||||
|
|
|
@ -49,68 +49,98 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
|
|||
});
|
||||
|
||||
var rom = lp.Roms[0].FileData;
|
||||
var inputsEnabled = new bool[6]
|
||||
{
|
||||
_syncSettings.Gamepad1,
|
||||
_syncSettings.Gamepad2,
|
||||
_syncSettings.Gamepad3,
|
||||
_syncSettings.Gamepad4,
|
||||
_syncSettings.Mouse,
|
||||
_syncSettings.Keyboard,
|
||||
};
|
||||
|
||||
if (!_core.Init(rom, rom.Length))
|
||||
if (!_core.Init(rom, rom.Length, inputsEnabled))
|
||||
{
|
||||
throw new InvalidOperationException("Init returned false!");
|
||||
}
|
||||
|
||||
// inputsEnabled is mutated in Init call
|
||||
// as such any Autodetects in inputsEnabled will be set to True or False
|
||||
ControllerDefinition = CreateControllerDefinition(inputsEnabled);
|
||||
PostInit();
|
||||
|
||||
DeterministicEmulation = lp.DeterministicEmulationRequested || (!_syncSettings.UseRealTime);
|
||||
InitializeRtc(_syncSettings.InitialTime);
|
||||
}
|
||||
|
||||
private static readonly List<KeyValuePair<string, LibTIC80.TIC80Keys>> KeyMap = new();
|
||||
private static readonly IReadOnlyCollection<KeyValuePair<string, LibTIC80.TIC80Keys>> KeyMap = MakeKeyMap();
|
||||
|
||||
public override ControllerDefinition ControllerDefinition => TIC80Controller;
|
||||
private static IReadOnlyCollection<KeyValuePair<string, LibTIC80.TIC80Keys>> MakeKeyMap()
|
||||
{
|
||||
var enumValues = Enum.GetValues(typeof(LibTIC80.TIC80Keys));
|
||||
var ret = new KeyValuePair<string, LibTIC80.TIC80Keys>[enumValues.Length - 1];
|
||||
for (int i = 0; i < ret.Length; i++)
|
||||
{
|
||||
var val = enumValues.GetValue(i + 1);
|
||||
var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), val).TrimStart('_').Replace('_', ' ');
|
||||
ret[i] = new(name, (LibTIC80.TIC80Keys)val);
|
||||
}
|
||||
|
||||
private static readonly ControllerDefinition TIC80Controller = CreateControllerDefinition();
|
||||
return Array.AsReadOnly(ret);
|
||||
}
|
||||
|
||||
private static ControllerDefinition CreateControllerDefinition()
|
||||
private static ControllerDefinition CreateControllerDefinition(bool[] inputsEnabled)
|
||||
{
|
||||
var ret = new ControllerDefinition("TIC-80 Controller");
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
foreach (var b in Enum.GetValues(typeof(LibTIC80.TIC80Gamepad)))
|
||||
if (inputsEnabled[i])
|
||||
{
|
||||
ret.BoolButtons.Add($"P{i + 1} {Enum.GetName(typeof(LibTIC80.TIC80Gamepad), b)}");
|
||||
foreach (var b in Enum.GetValues(typeof(LibTIC80.TIC80Gamepad)))
|
||||
{
|
||||
ret.BoolButtons.Add($"P{i + 1} {Enum.GetName(typeof(LibTIC80.TIC80Gamepad), b)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret.AddXYPair("Mouse Position {0}", AxisPairOrientation.RightAndUp, (-128).RangeTo(127), 0);
|
||||
ret.BoolButtons.Add("Mouse Left Click");
|
||||
ret.BoolButtons.Add("Mouse Middle Click");
|
||||
ret.BoolButtons.Add("Mouse Right Click");
|
||||
ret.AddXYPair("Mouse Scroll {0}", AxisPairOrientation.RightAndUp, (-32).RangeTo(31), 0);
|
||||
ret.BoolButtons.Add("Mouse Relative Toggle");
|
||||
|
||||
foreach (var n in ret.BoolButtons)
|
||||
if (inputsEnabled[4])
|
||||
{
|
||||
if (n.StartsWith("Mouse"))
|
||||
ret.AddXYPair("Mouse Position {0}", AxisPairOrientation.RightAndUp, (-128).RangeTo(127), 0);
|
||||
ret.BoolButtons.Add("Mouse Left Click");
|
||||
ret.BoolButtons.Add("Mouse Middle Click");
|
||||
ret.BoolButtons.Add("Mouse Right Click");
|
||||
ret.AddXYPair("Mouse Scroll {0}", AxisPairOrientation.RightAndUp, (-32).RangeTo(31), 0);
|
||||
ret.BoolButtons.Add("Mouse Relative Toggle");
|
||||
|
||||
foreach (var n in ret.BoolButtons)
|
||||
{
|
||||
ret.CategoryLabels[n] = "Mouse";
|
||||
if (n.StartsWith("Mouse"))
|
||||
{
|
||||
ret.CategoryLabels[n] = "Mouse";
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var n in ret.Axes.Keys)
|
||||
{
|
||||
if (n.StartsWith("Mouse"))
|
||||
{
|
||||
ret.CategoryLabels[n] = "Mouse";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var n in ret.Axes.Keys)
|
||||
if (inputsEnabled[5])
|
||||
{
|
||||
if (n.StartsWith("Mouse"))
|
||||
foreach (var k in Enum.GetValues(typeof(LibTIC80.TIC80Keys)))
|
||||
{
|
||||
ret.CategoryLabels[n] = "Mouse";
|
||||
var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), k).TrimStart('_').Replace('_', ' ');
|
||||
if (name is "Unknown") continue;
|
||||
ret.BoolButtons.Add(name);
|
||||
ret.CategoryLabels[name] = "Keyboard";
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var k in Enum.GetValues(typeof(LibTIC80.TIC80Keys)))
|
||||
{
|
||||
var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), k).TrimStart('_').Replace('_', ' ');
|
||||
if (name is "Unknown") continue;
|
||||
KeyMap.Add(new(name, (LibTIC80.TIC80Keys)k));
|
||||
ret.BoolButtons.Add(name);
|
||||
ret.CategoryLabels[name] = "Keyboard";
|
||||
}
|
||||
|
||||
ret.BoolButtons.Add("Reset");
|
||||
|
||||
return ret.MakeImmutable();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <tic80.h>
|
||||
#include <tic.h>
|
||||
#include <api.h>
|
||||
#include <core.h>
|
||||
|
||||
#include <emulibc.h>
|
||||
#include <waterboxcore.h>
|
||||
|
@ -21,8 +22,16 @@ clock_t BizClockCallback()
|
|||
}
|
||||
|
||||
static tic80* tic;
|
||||
static tic80_input biz_inputs;
|
||||
|
||||
ECL_EXPORT bool Init(u8* rom, u32 sz)
|
||||
typedef struct
|
||||
{
|
||||
u8 gamepad[4];
|
||||
u8 mouse;
|
||||
u8 keyboard;
|
||||
} InputsEnabled;
|
||||
|
||||
ECL_EXPORT bool Init(u8* rom, u32 sz, InputsEnabled* inputsEnable)
|
||||
{
|
||||
tic = tic80_create(TIC80_SAMPLERATE, TIC80_PIXEL_COLOR_BGRA8888);
|
||||
if (!tic)
|
||||
|
@ -31,7 +40,29 @@ ECL_EXPORT bool Init(u8* rom, u32 sz)
|
|||
}
|
||||
|
||||
tic80_load(tic, rom, sz);
|
||||
return true;
|
||||
|
||||
// advance one frame to initialize things
|
||||
// if initializing failed we can know after it advances
|
||||
memset(&biz_inputs, 0, sizeof(biz_inputs));
|
||||
tic80_tick(tic, biz_inputs);
|
||||
tic80_sound(tic); // should this be done?
|
||||
|
||||
tic_mem* mem = (tic_mem*)tic;
|
||||
if (!mem->input.gamepad)
|
||||
{
|
||||
memset(inputsEnable->gamepad, 0, sizeof(inputsEnable->gamepad));
|
||||
}
|
||||
if (!mem->input.mouse)
|
||||
{
|
||||
inputsEnable->mouse = false;
|
||||
}
|
||||
if (!mem->input.keyboard)
|
||||
{
|
||||
inputsEnable->keyboard = false;
|
||||
}
|
||||
|
||||
tic_core* core = (tic_core*)tic;
|
||||
return core->state.initialized;
|
||||
}
|
||||
|
||||
ECL_EXPORT void GetMemoryAreas(MemoryArea* m)
|
||||
|
@ -54,8 +85,6 @@ ECL_EXPORT void GetMemoryAreas(MemoryArea* m)
|
|||
m[2].Flags = MEMORYAREA_FLAGS_WORDSIZE1 | MEMORYAREA_FLAGS_WRITABLE;
|
||||
}
|
||||
|
||||
static tic80_input biz_inputs;
|
||||
|
||||
ECL_EXPORT void SetInputs(tic80_input* inputs)
|
||||
{
|
||||
memcpy(&biz_inputs, inputs, sizeof(tic80_input));
|
||||
|
|
Loading…
Reference in New Issue