uae: swapper

This commit is contained in:
feos 2024-06-13 23:13:42 +03:00
parent 939762d9fb
commit a01a7bb61e
5 changed files with 98 additions and 43 deletions

Binary file not shown.

View File

@ -8,13 +8,14 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
{ {
public abstract class LibPUAE : LibWaterboxCore public abstract class LibPUAE : LibWaterboxCore
{ {
public const int PAL_WIDTH = 720; public const int PAL_WIDTH = 720;
public const int PAL_HEIGHT = 576; public const int PAL_HEIGHT = 576;
public const int NTSC_WIDTH = 720; public const int NTSC_WIDTH = 720;
public const int NTSC_HEIGHT = 480; public const int NTSC_HEIGHT = 480;
public const int FASTMEM_AUTO = -1; public const int FASTMEM_AUTO = -1;
public const int MAX_FLOPPIES = 4; 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)] [BizImport(CC, Compatibility = true)]
public abstract bool Init(int argc, string[] argv); public abstract bool Init(int argc, string[] argv);
@ -27,11 +28,24 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
public int MouseX; public int MouseX;
public int MouseY; public int MouseY;
public KeyBuffer Keys; public KeyBuffer Keys;
public struct KeyBuffer public struct KeyBuffer
{ {
public unsafe fixed byte Buffer[LibPUAE.KEY_COUNT]; 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] [Flags]
@ -46,23 +60,6 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
Joystick_Button_3 = 1 << 6 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 // https://wiki.amigaos.net/wiki/Keymap_Library
public enum PUAEKeyboard : int public enum PUAEKeyboard : int
{ {

View File

@ -8,6 +8,7 @@ using BizHawk.Emulation.DiscSystem;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Amiga namespace BizHawk.Emulation.Cores.Computers.Amiga
{ {
@ -27,6 +28,8 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
private int _currentDrive = 0; private int _currentDrive = 0;
private int _currentSlot = 0; private int _currentSlot = 0;
private byte[] _currentRom; private byte[] _currentRom;
private bool _ejectPressed = false;
private bool _insertPressed = false;
private bool _nextSlotPressed = false; private bool _nextSlotPressed = false;
private bool _nextDrivePressed = false; private bool _nextDrivePressed = false;
@ -64,12 +67,15 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck),
}); });
for (var index = 0; index < Math.Min(Math.Min( for (var index = 0; index < lp.Roms.Count; index++)
lp.Roms.Count, LibPUAE.MAX_FLOPPIES), _syncSettings.FloppyDrives); index++)
{ {
_exe.AddReadonlyFile(lp.Roms[index].FileData, FileNames.FD + 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( var (kickstartData, kickstartInfo) = CoreComm.CoreFileProvider.GetFirmwareWithGameInfoOrThrow(
@ -123,7 +129,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
controller.BoolButtons.AddRange(new List<string> controller.BoolButtons.AddRange(new List<string>
{ {
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))) foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEKeyboard)))
@ -140,7 +146,8 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
{ {
var fi = new LibPUAE.FrameInfo var fi = new LibPUAE.FrameInfo
{ {
MouseButtons = 0 MouseButtons = 0,
Action = LibPUAE.DriveAction.NONE
}; };
foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEJoystick))) foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEJoystick)))
@ -164,7 +171,30 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
fi.MouseButtons |= 1 << 2; 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) if (!_nextSlotPressed)
{ {
@ -175,7 +205,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
_comm.Notify(selectedFile.Game.Name, null); _comm.Notify(selectedFile.Game.Name, null);
} }
} }
if (controller.IsPressed(Inputs.ND)) if (controller.IsPressed(Inputs.NextDrive))
{ {
if (!_nextDrivePressed) if (!_nextDrivePressed)
{ {
@ -184,8 +214,12 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
_comm.Notify($"Selected FD{ _currentDrive } Drive", null); _comm.Notify($"Selected FD{ _currentDrive } Drive", null);
} }
} }
_nextSlotPressed = controller.IsPressed(Inputs.NS); _ejectPressed = controller.IsPressed(Inputs.Eject);
_nextDrivePressed = controller.IsPressed(Inputs.ND); _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.MouseX = controller.AxisValue(Inputs.X);
fi.MouseY = controller.AxisValue(Inputs.Y); fi.MouseY = controller.AxisValue(Inputs.Y);
@ -208,12 +242,16 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
protected override void SaveStateBinaryInternal(BinaryWriter writer) protected override void SaveStateBinaryInternal(BinaryWriter writer)
{ {
writer.Write(_ejectPressed);
writer.Write(_insertPressed);
writer.Write(_nextSlotPressed); writer.Write(_nextSlotPressed);
writer.Write(_nextDrivePressed); writer.Write(_nextDrivePressed);
} }
protected override void LoadStateBinaryInternal(BinaryReader reader) protected override void LoadStateBinaryInternal(BinaryReader reader)
{ {
_ejectPressed = reader.ReadBoolean();
_insertPressed = reader.ReadBoolean();
_nextSlotPressed = reader.ReadBoolean(); _nextSlotPressed = reader.ReadBoolean();
_nextDrivePressed = 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 MLB = "Mouse Left Button";
public const string MRB = "Mouse Right Button"; public const string MRB = "Mouse Right Button";
public const string MMB = "Mouse Middle Button"; public const string MMB = "Mouse Middle Button";
public const string X = "Mouse X"; public const string X = "Mouse X";
public const string Y = "Mouse Y"; public const string Y = "Mouse Y";
public const string EJ = "Eject"; public const string Eject = "Eject";
public const string INS = "Insert"; public const string Insert = "Insert";
public const string ND = "Next Drive"; public const string NextDrive = "Next Drive";
public const string NS = "Next Slot"; public const string NextSlot = "Next Slot";
} }
} }
} }

View File

@ -48,14 +48,21 @@ ECL_EXPORT void FrameAdvance(MyFrameInfo* f)
setmousestate( PORT_0, AXIS_VERTICAL, f->MouseY - last_mouse_y, MOUSE_RELATIVE); setmousestate( PORT_0, AXIS_VERTICAL, f->MouseY - last_mouse_y, MOUSE_RELATIVE);
for (int i = 0; i < KEY_COUNT; i++) for (int i = 0; i < KEY_COUNT; i++)
{
if (f->Keys[i] != last_key_state[i]) if (f->Keys[i] != last_key_state[i])
{
inputdevice_do_keyboard(i, f->Keys[i]); inputdevice_do_keyboard(i, f->Keys[i]);
}
}
memcpy(last_key_state, f->Keys, KEY_COUNT); 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); m68k_go(1, 1);
upload_output_audio_buffer(); upload_output_audio_buffer();
f->base.Samples = sound_sample_count; f->base.Samples = sound_sample_count;

View File

@ -21,6 +21,7 @@
#include "libretro/libretro-core.h" #include "libretro/libretro-core.h"
static const int FILENAME_MAXLENGTH = 4;
static const int KEY_COUNT = 0x68; static const int KEY_COUNT = 0x68;
int16_t* sound_buffer = NULL; 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 int m68k_go(int may_quit, int resume);
extern void init_output_audio_buffer(int32_t capacity); extern void init_output_audio_buffer(int32_t capacity);
extern void upload_output_audio_buffer(); 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 enum Axis
{ {
@ -77,6 +80,13 @@ enum AudioChannels
AUDIO_STEREO AUDIO_STEREO
}; };
enum DriveAction
{
ACTION_NONE,
ACTION_EJECT,
ACTION_INSERT
};
typedef union typedef union
{ {
struct struct
@ -100,6 +110,9 @@ typedef struct
int MouseX; int MouseX;
int MouseY; int MouseY;
char Keys[KEY_COUNT]; char Keys[KEY_COUNT];
int CurrentDrive;
int Action;
char FileName[FILENAME_MAXLENGTH];
} MyFrameInfo; } MyFrameInfo;
size_t biz_audio_cb(const int16_t *data, size_t frames) size_t biz_audio_cb(const int16_t *data, size_t frames)