Skip to content

Commit

Permalink
puae: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vadosnaprimer committed Nov 7, 2024
1 parent 9fd58a7 commit a2d401d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 80 deletions.
Binary file modified Assets/dll/puae.wbx.zst
Binary file not shown.
26 changes: 18 additions & 8 deletions src/BizHawk.Emulation.Cores/Computers/Amiga/LibPUAE.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.ComponentModel.DataAnnotations;
using System.Runtime.InteropServices;

using BizHawk.BizInvoke;
using BizHawk.Emulation.Cores.Waterbox;
Expand Down Expand Up @@ -66,11 +67,27 @@ public struct FileName
[StructLayout(LayoutKind.Sequential)]
public struct ControllerState
{
public ControllerType Type;
public AllButtons Buttons;
public int MouseX;
public int MouseY;
}

public enum ControllerType : int
{
Joystick,
Mouse,
[Display(Name = "CD32 pad")]
CD32_pad
}

public enum DriveAction : int
{
None,
Eject,
Insert
}

[Flags]
public enum AllButtons : short
{
Expand Down Expand Up @@ -198,12 +215,5 @@ public enum PUAEKeyboard : int
Key_Left_Amiga = 0x66,
Key_Right_Amiga = 0x67,
}

public enum DriveAction : int
{
None,
Eject,
Insert
}
}
}
10 changes: 5 additions & 5 deletions src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.Controllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
{
public partial class PUAE
{
private ControllerType[] _ports { get; set; }
private LibPUAE.ControllerType[] _ports { get; set; }
private static readonly (string Name, LibPUAE.AllButtons Button)[] _joystickMap = CreateJoystickMap();
private static readonly (string Name, LibPUAE.AllButtons Button)[] _cd32padMap = CreateCd32padMap();
private static readonly (string Name, LibPUAE.PUAEKeyboard Key)[] _keyboardMap = CreateKeyboardMap();
Expand Down Expand Up @@ -62,29 +62,29 @@ private static ControllerDefinition CreateControllerDefinition(PUAESyncSettings

for (int port = 1; port <= 2; port++)
{
ControllerType type = port == 1
LibPUAE.ControllerType type = port == 1
? settings.ControllerPort1
: settings.ControllerPort2;

switch (type)
{
case ControllerType.Joystick:
case LibPUAE.ControllerType.Joystick:
{
foreach (var (name, _) in _joystickMap)
{
controller.BoolButtons.Add($"P{port} {Inputs.Joystick} {name}");
}
break;
}
case ControllerType.CD32_pad:
case LibPUAE.ControllerType.CD32_pad:
{
foreach (var (name, _) in _cd32padMap)
{
controller.BoolButtons.Add($"P{port} {Inputs.Cd32Pad} {name}");
}
break;
}
case ControllerType.Mouse:
case LibPUAE.ControllerType.Mouse:
{
controller.BoolButtons.AddRange(
[
Expand Down
16 changes: 4 additions & 12 deletions src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.ISettable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ public enum DriveType
DRV_FB
}

public enum ControllerType
{
Joystick,
Mouse,
[Display(Name = "CD32 pad")]
CD32_pad
}

private void CreateArguments(PUAESyncSettings settings)
{
_args = new List<string>
Expand Down Expand Up @@ -336,15 +328,15 @@ public class PUAESyncSettings

[DisplayName("Controller port 1")]
[Description("")]
[DefaultValue(ControllerType.Joystick)]
[DefaultValue(LibPUAE.ControllerType.Joystick)]
[TypeConverter(typeof(DescribableEnumConverter))]
public ControllerType ControllerPort1 { get; set; }
public LibPUAE.ControllerType ControllerPort1 { get; set; }

[DisplayName("Controller port 2")]
[Description("")]
[DefaultValue(ControllerType.Mouse)]
[DefaultValue(LibPUAE.ControllerType.Mouse)]
[TypeConverter(typeof(DescribableEnumConverter))]
public ControllerType ControllerPort2 { get; set; }
public LibPUAE.ControllerType ControllerPort2 { get; set; }

[DisplayName("Mouse speed")]
[Description("Mouse speed in percents (1% - 1000%). Adjust if there's mismatch between emulated and host mouse movement. Note that maximum mouse movement is still 127 pixels due to Amiga hardware limitations.")]
Expand Down
8 changes: 5 additions & 3 deletions src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro
{
Port1 = new LibPUAE.ControllerState
{
Type = _ports[0],
Buttons = 0
},
Port2 = new LibPUAE.ControllerState
{
Type = _ports[1],
Buttons = 0
},
Action = LibPUAE.DriveAction.None
Expand All @@ -164,7 +166,7 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro

switch (_ports[port - 1])
{
case ControllerType.Joystick:
case LibPUAE.ControllerType.Joystick:
{
foreach (var (name, button) in _joystickMap)
{
Expand All @@ -175,7 +177,7 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro
}
break;
}
case ControllerType.CD32_pad:
case LibPUAE.ControllerType.CD32_pad:
{
foreach (var (name, button) in _cd32padMap)
{
Expand All @@ -186,7 +188,7 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro
}
break;
}
case ControllerType.Mouse:
case LibPUAE.ControllerType.Mouse:
{
if (controller.IsPressed($"P{port} {Inputs.MouseLeftButton}"))
{
Expand Down
81 changes: 49 additions & 32 deletions waterbox/uae/bizhawk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

ECL_EXPORT bool Init(int argc, char **argv)
{
last_mouse_x = 0;
last_mouse_y = 0;
log_cb = biz_log_cb;
libretro_runloop_active = 0;

pix_bytes = 4;
defaultw = PUAE_VIDEO_WIDTH;
defaulth = PUAE_VIDEO_HEIGHT_PAL;
retrow = PUAE_VIDEO_WIDTH;
retrow_crop = retrow;
retroh_crop = retroh;
log_cb = biz_log_cb;

retro_set_audio_sample_batch(biz_audio_cb);
init_output_audio_buffer(2048);
Expand All @@ -33,39 +32,48 @@ void SetCD32ButtonState(int port, int button, int state)

ECL_EXPORT void FrameAdvance(MyFrameInfo* f)
{

cd32_pad_enabled[0] = 1;
cd32_pad_enabled[1] = 1;
bool is_ntsc = minfirstline == VBLANK_ENDLINE_NTSC;
f->base.Width = PUAE_VIDEO_WIDTH;
f->base.Height = is_ntsc ? PUAE_VIDEO_HEIGHT_NTSC : PUAE_VIDEO_HEIGHT_PAL;
sound_buffer = f->base.SoundBuffer;
thisframe_y_adjust = minfirstline;
visible_left_border = retro_max_diwlastword - retrow;

setjoystickstate(PORT_0, AXIS_VERTICAL,
f->JoystickState.up ? JOY_MIN :
f->JoystickState.down ? JOY_MAX : JOY_MID, 1);
setjoystickstate(PORT_0, AXIS_HORIZONTAL,
f->JoystickState.left ? JOY_MIN :
f->JoystickState.right ? JOY_MAX : JOY_MID, 1);
setjoybuttonstate(PORT_0, JOYBUTTON_1, f->JoystickState.b1);
setjoybuttonstate(PORT_0, JOYBUTTON_2, f->JoystickState.b2);
setjoybuttonstate(PORT_0, JOYBUTTON_3, f->JoystickState.b3);

SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_PLAY, f->JoystickState.b4);
SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_RWD, f->JoystickState.b5);
SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_FFW, f->JoystickState.b6);
SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_GREEN, f->JoystickState.b7);
SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_YELLOW, f->JoystickState.b8);
SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_RED, f->JoystickState.b9);
SetCD32ButtonState(PORT_0, JOYBUTTON_CD32_BLUE, f->JoystickState.b10);

setmousebuttonstate(PORT_0, MOUSE_LEFT, f->MouseButtons & 1);
setmousebuttonstate(PORT_0, MOUSE_RIGHT, f->MouseButtons & 2);
setmousebuttonstate(PORT_0, MOUSE_MIDDLE, f->MouseButtons & 4);
setmousestate( PORT_0, AXIS_HORIZONTAL, f->MouseX - last_mouse_x, MOUSE_RELATIVE);
setmousestate( PORT_0, AXIS_VERTICAL, f->MouseY - last_mouse_y, MOUSE_RELATIVE);
sound_buffer = f->base.SoundBuffer;

for (int port = 0; port <= 1; port++)
{
Controller *controller = (port == 0) ? &f->Port1 : &f->Port2;
cd32_pad_enabled[port] = 0;

// shared between mouse and joystick
setjoybuttonstate(port, JOYBUTTON_1, controller->Buttons.b1);
setjoybuttonstate(port, JOYBUTTON_2, controller->Buttons.b2);
setjoybuttonstate(port, JOYBUTTON_3, controller->Buttons.b3);

switch (controller->Type)
{
case CONTROLLER_JOYSTICK:
setjoystickstate(port, AXIS_VERTICAL, controller->Buttons.up ? JOY_MIN :
controller->Buttons.down ? JOY_MAX : JOY_MID, 1);
setjoystickstate(port, AXIS_HORIZONTAL, controller->Buttons.left ? JOY_MIN :
controller->Buttons.right ? JOY_MAX : JOY_MID, 1);
break;
case CONTROLLER_CD32PAD:
cd32_pad_enabled[port] = 1;
SetCD32ButtonState(port, JOYBUTTON_CD32_PLAY, controller->Buttons.play);
SetCD32ButtonState(port, JOYBUTTON_CD32_RWD, controller->Buttons.rewind);
SetCD32ButtonState(port, JOYBUTTON_CD32_FFW, controller->Buttons.forward);
SetCD32ButtonState(port, JOYBUTTON_CD32_GREEN, controller->Buttons.green);
SetCD32ButtonState(port, JOYBUTTON_CD32_YELLOW, controller->Buttons.yellow);
SetCD32ButtonState(port, JOYBUTTON_CD32_RED, controller->Buttons.red);
SetCD32ButtonState(port, JOYBUTTON_CD32_BLUE, controller->Buttons.blue);
break;
case CONTROLLER_MOUSE:
setmousestate(port, AXIS_HORIZONTAL, controller->MouseX - last_mouse_x[port], MOUSE_RELATIVE);
setmousestate(port, AXIS_VERTICAL, controller->MouseY - last_mouse_y[port], MOUSE_RELATIVE);
break;
}
}

for (int i = 0; i < KEY_COUNT; i++)
if (f->Keys[i] != last_key_state[i])
Expand All @@ -88,9 +96,18 @@ ECL_EXPORT void FrameAdvance(MyFrameInfo* f)
upload_output_audio_buffer();
f->base.Samples = sound_sample_count;
memcpy(f->base.VideoBuffer, retro_bmp, sizeof(retro_bmp) / sizeof(retro_bmp[0]));
last_mouse_x = f->MouseX;
last_mouse_y = f->MouseY;
sound_buffer = NULL;

for (int port = 0; port <= 1; port++)
{
Controller *controller = (port == 0) ? &f->Port1 : &f->Port2;

if (controller->Type == CONTROLLER_MOUSE)
{
last_mouse_x[port] = controller->MouseX;
last_mouse_y[port] = controller->MouseY;
}
}
}

ECL_EXPORT void GetMemoryAreas(MemoryArea *m)
Expand Down
48 changes: 28 additions & 20 deletions waterbox/uae/bizhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ static const int KEY_COUNT = 0x68;
int16_t* sound_buffer = NULL;
int sound_sample_count = 0;
static char last_key_state[KEY_COUNT];
static int last_mouse_x;
static int last_mouse_y;
static int last_mouse_x[NORMAL_JPORTS] = {0};
static int last_mouse_y[NORMAL_JPORTS] = {0};

extern uint8_t libretro_runloop_active;
extern int thisframe_y_adjust;
extern unsigned short int defaultw;
extern unsigned short int defaulth;
Expand Down Expand Up @@ -58,12 +59,6 @@ enum JoystickRange
JOY_MAX
};

enum ControllerPort
{
PORT_0,
PORT_1
};

enum MouseButtons
{
MOUSE_LEFT,
Expand All @@ -90,6 +85,13 @@ enum DriveAction
ACTION_INSERT
};

enum ControllerType
{
CONTROLLER_JOYSTICK,
CONTROLLER_MOUSE,
CONTROLLER_CD32PAD
};

typedef union
{
struct
Expand All @@ -101,24 +103,30 @@ typedef union
bool b1:1;
bool b2:1;
bool b3:1;
bool b4:1;
bool b5:1;
bool b6:1;
bool b7:1;
bool b8:1;
bool b9:1;
bool b10:1;
bool play:1;
bool rewind:1;
bool forward:1;
bool green:1;
bool yellow:1;
bool red:1;
bool blue:1;
};
uint16_t data;
} PUAEJoystick;
} AllButtons;

typedef struct
typedef struct ControllerState
{
FrameInfo base;
PUAEJoystick JoystickState;
uint8_t MouseButtons;
int Type;
AllButtons Buttons;
int MouseX;
int MouseY;
} Controller;

typedef struct
{
FrameInfo base;
Controller Port1;
Controller Port2;
char Keys[KEY_COUNT];
int CurrentDrive;
int Action;
Expand Down

0 comments on commit a2d401d

Please sign in to comment.