diff --git a/Assets/dll/puae.wbx.zst b/Assets/dll/puae.wbx.zst index ca01b08ced..0830a2c49c 100644 Binary files a/Assets/dll/puae.wbx.zst and b/Assets/dll/puae.wbx.zst differ diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/LibPUAE.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/LibPUAE.cs index 2da13a2cac..25fa6adcb5 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/LibPUAE.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/LibPUAE.cs @@ -8,13 +8,14 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga { public abstract class LibPUAE : LibWaterboxCore { - public const int PAL_WIDTH = 720; - public const int PAL_HEIGHT = 576; - public const int NTSC_WIDTH = 720; - public const int NTSC_HEIGHT = 480; + public const int PAL_WIDTH = 720; + public const int PAL_HEIGHT = 576; + public const int NTSC_WIDTH = 720; + public const int NTSC_HEIGHT = 480; public const int FASTMEM_AUTO = -1; public const int MAX_FLOPPIES = 4; - public const int KEY_COUNT = 0x68; + public const int FILENAME_MAXLENGTH = 64; + public const int KEY_COUNT = 0x68; [BizImport(CC, Compatibility = true)] public abstract bool Init(int argc, string[] argv); @@ -27,11 +28,24 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga public int MouseX; public int MouseY; public KeyBuffer Keys; - public struct KeyBuffer { public unsafe fixed byte Buffer[LibPUAE.KEY_COUNT]; } + public int CurrentDrive; + public DriveAction Action; + public FileName Name; + public struct FileName + { + public unsafe fixed byte Buffer[LibPUAE.FILENAME_MAXLENGTH]; + } + } + + public enum DriveAction : int + { + NONE, + EJECT, + INSERT } [Flags] @@ -46,23 +60,6 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga Joystick_Button_3 = 1 << 6 } - public enum DiscAction - { - Eject, - Insert - } - - [Flags] - public enum DiskControl : byte - { - FloppyDrive0 = 1 << 0, - FloppyDrive1 = 1 << 1, - FloppyDrive2 = 1 << 2, - FloppyDrive3 = 1 << 3, - CdDrive = 1 << 4, - Trigger = 1 << 5 - } - // https://wiki.amigaos.net/wiki/Keymap_Library public enum PUAEKeyboard : int { diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.cs index ac7b125035..4111912104 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/PUAE.cs @@ -8,6 +8,7 @@ using BizHawk.Emulation.DiscSystem; using System; using System.Collections.Generic; using System.IO; +using System.Text; namespace BizHawk.Emulation.Cores.Computers.Amiga { @@ -27,6 +28,8 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga private int _currentDrive = 0; private int _currentSlot = 0; private byte[] _currentRom; + private bool _ejectPressed = false; + private bool _insertPressed = false; private bool _nextSlotPressed = false; private bool _nextDrivePressed = false; @@ -64,12 +67,15 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), }); - for (var index = 0; index < Math.Min(Math.Min( - lp.Roms.Count, LibPUAE.MAX_FLOPPIES), _syncSettings.FloppyDrives); index++) + for (var index = 0; index < lp.Roms.Count; index++) { _exe.AddReadonlyFile(lp.Roms[index].FileData, FileNames.FD + index); - AppendSetting($"floppy{ index }={ FileNames.FD }{ index }"); - AppendSetting($"floppy{ index }type={ (int)DriveType.DRV_35_DD }"); + + if (index < Math.Min(LibPUAE.MAX_FLOPPIES, _syncSettings.FloppyDrives)) + { + AppendSetting($"floppy{index}={FileNames.FD}{index}"); + AppendSetting($"floppy{index}type={(int)DriveType.DRV_35_DD}"); + } } var (kickstartData, kickstartInfo) = CoreComm.CoreFileProvider.GetFirmwareWithGameInfoOrThrow( @@ -123,7 +129,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga controller.BoolButtons.AddRange(new List { - Inputs.EJ, Inputs.INS, Inputs.ND, Inputs.NS + Inputs.Eject, Inputs.Insert, Inputs.NextDrive, Inputs.NextSlot }); foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEKeyboard))) @@ -140,7 +146,8 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga { var fi = new LibPUAE.FrameInfo { - MouseButtons = 0 + MouseButtons = 0, + Action = LibPUAE.DriveAction.NONE }; foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEJoystick))) @@ -164,7 +171,30 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga fi.MouseButtons |= 1 << 2; } - if (controller.IsPressed(Inputs.NS)) + if (controller.IsPressed(Inputs.Eject)) + { + if (!_ejectPressed) + { + fi.Action = LibPUAE.DriveAction.EJECT; + } + } + else if (controller.IsPressed(Inputs.Insert)) + { + if (!_insertPressed) + { + fi.Action = LibPUAE.DriveAction.INSERT; + unsafe + { + string str = FileNames.FD + _currentSlot; + fixed(char* filename = str) + fixed (byte* buffer = fi.Name.Buffer) + { + Encoding.ASCII.GetBytes(filename, str.Length, buffer, LibPUAE.FILENAME_MAXLENGTH); + } + } + } + } + if (controller.IsPressed(Inputs.NextSlot)) { if (!_nextSlotPressed) { @@ -175,7 +205,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga _comm.Notify(selectedFile.Game.Name, null); } } - if (controller.IsPressed(Inputs.ND)) + if (controller.IsPressed(Inputs.NextDrive)) { if (!_nextDrivePressed) { @@ -184,8 +214,12 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga _comm.Notify($"Selected FD{ _currentDrive } Drive", null); } } - _nextSlotPressed = controller.IsPressed(Inputs.NS); - _nextDrivePressed = controller.IsPressed(Inputs.ND); + _ejectPressed = controller.IsPressed(Inputs.Eject); + _insertPressed = controller.IsPressed(Inputs.Insert); + _nextSlotPressed = controller.IsPressed(Inputs.NextSlot); + _nextDrivePressed = controller.IsPressed(Inputs.NextDrive); + + fi.CurrentDrive = _currentDrive; fi.MouseX = controller.AxisValue(Inputs.X); fi.MouseY = controller.AxisValue(Inputs.Y); @@ -208,12 +242,16 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga protected override void SaveStateBinaryInternal(BinaryWriter writer) { + writer.Write(_ejectPressed); + writer.Write(_insertPressed); writer.Write(_nextSlotPressed); writer.Write(_nextDrivePressed); } protected override void LoadStateBinaryInternal(BinaryReader reader) { + _ejectPressed = reader.ReadBoolean(); + _insertPressed = reader.ReadBoolean(); _nextSlotPressed = reader.ReadBoolean(); _nextDrivePressed = reader.ReadBoolean(); } @@ -230,12 +268,12 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga public const string MLB = "Mouse Left Button"; public const string MRB = "Mouse Right Button"; public const string MMB = "Mouse Middle Button"; - public const string X = "Mouse X"; - public const string Y = "Mouse Y"; - public const string EJ = "Eject"; - public const string INS = "Insert"; - public const string ND = "Next Drive"; - public const string NS = "Next Slot"; + public const string X = "Mouse X"; + public const string Y = "Mouse Y"; + public const string Eject = "Eject"; + public const string Insert = "Insert"; + public const string NextDrive = "Next Drive"; + public const string NextSlot = "Next Slot"; } } } \ No newline at end of file diff --git a/waterbox/uae/bizhawk.c b/waterbox/uae/bizhawk.c index 5045ba99fe..e81a11b5e4 100644 --- a/waterbox/uae/bizhawk.c +++ b/waterbox/uae/bizhawk.c @@ -48,14 +48,21 @@ ECL_EXPORT void FrameAdvance(MyFrameInfo* f) setmousestate( PORT_0, AXIS_VERTICAL, f->MouseY - last_mouse_y, MOUSE_RELATIVE); for (int i = 0; i < KEY_COUNT; i++) - { if (f->Keys[i] != last_key_state[i]) - { inputdevice_do_keyboard(i, f->Keys[i]); - } - } memcpy(last_key_state, f->Keys, KEY_COUNT); + if (f->Action == ACTION_EJECT) + { + disk_eject(f->CurrentDrive); + log_cb(RETRO_LOG_INFO, "EJECTED FD%d\n", f->CurrentDrive); + } + else if (f->Action == ACTION_INSERT) + { + disk_insert_force(f->CurrentDrive, f->FileName, true); + log_cb(RETRO_LOG_INFO, "INSERTED FD%d: \"%s\"\n", f->CurrentDrive, f->FileName); + } + m68k_go(1, 1); upload_output_audio_buffer(); f->base.Samples = sound_sample_count; diff --git a/waterbox/uae/bizhawk.h b/waterbox/uae/bizhawk.h index f4e4391981..45a88f7034 100644 --- a/waterbox/uae/bizhawk.h +++ b/waterbox/uae/bizhawk.h @@ -21,6 +21,7 @@ #include "libretro/libretro-core.h" +static const int FILENAME_MAXLENGTH = 4; static const int KEY_COUNT = 0x68; int16_t* sound_buffer = NULL; @@ -38,6 +39,8 @@ extern int umain(int argc, char **argv); extern int m68k_go(int may_quit, int resume); extern void init_output_audio_buffer(int32_t capacity); extern void upload_output_audio_buffer(); +extern void disk_eject(int num); +extern void disk_insert_force (int num, const TCHAR *name, bool forcedwriteprotect); enum Axis { @@ -77,6 +80,13 @@ enum AudioChannels AUDIO_STEREO }; +enum DriveAction +{ + ACTION_NONE, + ACTION_EJECT, + ACTION_INSERT +}; + typedef union { struct @@ -100,6 +110,9 @@ typedef struct int MouseX; int MouseY; char Keys[KEY_COUNT]; + int CurrentDrive; + int Action; + char FileName[FILENAME_MAXLENGTH]; } MyFrameInfo; size_t biz_audio_cb(const int16_t *data, size_t frames)