Skip to content

Commit

Permalink
auto dismount drive B if user tries to insert same disk into drive A.…
Browse files Browse the repository at this point in the history
… Added retromapper option for auto rotating disks (M3U). Fixed weird issue where right analog was not detected in some instances on Xbox One
  • Loading branch information
greenchili2 committed Sep 19, 2023
1 parent 0e7fbe1 commit 81107ed
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ When launched with a valid disk image the emulator will automatically launch the

There are also options to write protect floppy disks as well as an option to enable/disable fast floppy access.

There is an option in the RetroMapper where you can assign a button to "Auto Rotate" the disks (M3U). Be cautious about what button you assign it to ( You've been warned ).

## M3U Support and Disk control
When you have a multi disk game, you can use a m3u file to specify each disk of the game and change them from the RetroArch Disk control interface.

Expand Down
16 changes: 16 additions & 0 deletions libretro/hatari-mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//RETRO LIB
extern void retro_message(unsigned int frames, int level, const char* format, ...);
extern void retro_status(unsigned int frames, const char* format, ...);
extern void disk_rotate_images();

//CORE VAR
extern const char *retro_save_directory;
Expand Down Expand Up @@ -742,6 +743,21 @@ void update_input(void)
Screen_SetFullUpdate();
}
}
d = RETRO_DEVICE_ID_JOYPAD_L3;//not mapped
if (mapper_keys[i] == ROTATE_DISKS)
{
if (which && mbt[d] == 0)
{
mbt[d] = 1;
selected[d] = i;
}
else if (mbt[d] == 1 && !which && selected[d] == i)
{
mbt[d] = 0;
selected[d] = -1;
disk_rotate_images();
}
}
}
// do these only when VKBD is active.
else
Expand Down
4 changes: 3 additions & 1 deletion libretro/hatari-mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#define TOGGLE_VKBS -33
#define TOGGLE_STATUSBAR -34
#define TOGGLE_SETTINGS -35
//#define SWITCH_JOYPORT -36
#define ROTATE_DISKS -36
//#define SWITCH_JOYPORT -37
#define MOUSE_SLOWER -5
#define MOUSE_FASTER -6
#define JOYSTICK_UP -11
Expand Down Expand Up @@ -93,6 +94,7 @@ static retro_keymap retro_keys[RETROK_LAST] =
{TOGGLE_VKBS, "TOGGLE_VKBS", "Toggle VKBD Shift"},
{TOGGLE_SETTINGS, "TOGGLE_SETTINGS", "Hatari Settings"},
{TOGGLE_STATUSBAR, "TOGGLE_STATUSBAR", "Toggle Status Display"},
{ROTATE_DISKS, "ROTATE_DISKS", "Rotate Disks"},
/* {SWITCH_JOYPORT, "SWITCH_JOYPORT", "Switch Joyport"}, */
{JOYSTICK_UP, "JOYSTICK_UP", "Joystick Up"},
{JOYSTICK_DOWN, "JOYSTICK_DOWN", "Joystick Down"},
Expand Down
38 changes: 38 additions & 0 deletions libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ static struct retro_input_descriptor input_descriptors[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Set in RetroPad Mapping" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Set in RetroPad Mapping" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Set in RetroPad Mapping" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Set in RetroPad Mapping" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Set in RetroPad Mapping" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Joystick Up" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Joystick Down" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Joystick Left" },
Expand Down Expand Up @@ -1006,6 +1008,7 @@ void retro_shutdown_hatari(void)
//*****************************************************************************
// Disk control
extern bool Floppy_EjectDiskFromDrive(int Drive);
extern const char* Floppy_SetDiskFileNameNone(int Drive);
extern const char* Floppy_SetDiskFileName(int Drive, const char *pszFileName, const char *pszZipPath);
extern bool Floppy_InsertDiskIntoDrive(int Drive);

Expand All @@ -1030,6 +1033,13 @@ static void disk_insert_image()
{
if (dc->unit == DC_IMAGE_TYPE_FLOPPY)
{
// check if in Drive B ( mount to A will fail if so ). If it is.. eject from drive B first
if (strcmp(dc->files[dc->index], ConfigureParams.DiskImage.szDiskFileName[1]) == 0)
{
Floppy_EjectDiskFromDrive(1);
Floppy_SetDiskFileNameNone(1);
}

if (Floppy_SetDiskFileName(0, dc->files[dc->index], NULL) == NULL)
{
retro_message(3000, RETRO_LOG_ERROR, "[disk_insert_image] mount in Drive A failed.\n", dc->files[dc->index]);
Expand Down Expand Up @@ -1218,6 +1228,34 @@ static bool disk_get_image_label(unsigned index, char* label, size_t len)
return false;
}

void disk_rotate_images()
{
char *p = 0;

//nothing to see here..move along!
if (dc->count < 2)
return;

// eject current disk
disk_set_eject_state(true);

// rotate
dc->index++;
if (dc->index >= dc->count)
dc->index = 0;

// insert next disk in line
disk_set_eject_state(false);

//let the user know
p = strrchr(dc->files[dc->index], RETRO_PATH_SEPARATOR[0]);

if (p)
retro_message(3000, RETRO_LOG_INFO, "Rotate to disk %s in drive A.", p+1 );
else
retro_message(3000, RETRO_LOG_INFO, "Rotate to disk %s in drive A.", dc->files[dc->index]);
}

static struct retro_disk_control_callback disk_interface = {
disk_set_eject_state,
disk_get_eject_state,
Expand Down

0 comments on commit 81107ed

Please sign in to comment.