Skip to content

Commit

Permalink
Fixed autoload for cmdline
Browse files Browse the repository at this point in the history
- Fixed autoload joystick mapping for command line images and tapes.
  • Loading branch information
monkeyman79 committed Feb 1, 2021
1 parent 3ae3f27 commit 25fcda4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
77 changes: 40 additions & 37 deletions Src/beebwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ bool BeebWin::Initialise()
ReadROMFile(RomFile, RomConfig);
ApplyPrefs();

if (m_AutoloadJoystickMap)
CheckForJoystickMap(m_CommandLineFileName1);

if (m_DebugScript[0] != '\0')
{
DebugOpenDialog(hInst, m_hWnd);
Expand Down Expand Up @@ -374,11 +377,7 @@ void BeebWin::ApplyPrefs()
GetDataPath(m_UserDataPath, keymap);
ReadKeyMap(keymap, &defaultMapping);

strcpy(keymap, "DefaultUser.jmap");
GetDataPath(m_UserDataPath, keymap);
ResetJoyMap(&JoystickMap);
if (GetFileAttributes(keymap) != INVALID_FILE_ATTRIBUTES)
ReadJoyMap(keymap, &JoystickMap);
ResetJoyMapToDefaultUser();


InitMenu();
Expand Down Expand Up @@ -4468,15 +4467,44 @@ void BeebWin::ParseCommandLine()
}
}

/*****************************************************************************/
// Look for file specific joystick map
void BeebWin::CheckForJoystickMap(const char *path)
{
char file[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char filename[_MAX_FNAME];

if (!path || !path[0] || !m_AutoloadJoystickMap)
return;

_splitpath(path, drive, dir, filename, NULL);

// Look for prefs file with the same name with ".jmap" extension
_makepath(file, drive, dir, filename, "jmap");

if (GetFileAttributes(file) != INVALID_FILE_ATTRIBUTES)
{
ReadJoyMap(file, &JoystickMap);
}
else
{
// Mapping file not found - reset to default
ResetJoyMapToDefaultUser();

// Set jmap path even if the file doesn't exist
strcpy(m_JoystickMapPath, file);
}
}

/*****************************************************************************/
// Check for preference files in the same directory as the file specified
void BeebWin::CheckForLocalPrefs(const char *path, bool bLoadPrefs)
{
char file[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char filename[_MAX_FNAME];
char ext[_MAX_EXT];
FILE *fd;

if (path[0] == 0)
Expand Down Expand Up @@ -4506,36 +4534,6 @@ void BeebWin::CheckForLocalPrefs(const char *path, bool bLoadPrefs)
}
}

if (m_AutoloadJoystickMap)
{
// Look for file specific joystick map
_splitpath(path, drive, dir, filename, ext);

if (filename[0])
{
// Look for prefs file with the same name with ".jmap" extension
_makepath(file, drive, dir, filename, "jmap");

// Set jmap path even if it doesn't exist
strcpy(m_JoystickMapPath, file);

fd = fopen(file, "r");
if (fd != NULL)
{
fclose(fd);

if (bLoadPrefs)
{
ReadJoyMap(m_JoystickMapPath, &JoystickMap);
}
}
else if (bLoadPrefs)
{
ResetJoyMap(&JoystickMap);
}
}
}

// Look for ROMs file
_makepath(file, drive, dir, "Roms", "cfg");
fd = fopen(file, "r");
Expand All @@ -4550,6 +4548,11 @@ void BeebWin::CheckForLocalPrefs(const char *path, bool bLoadPrefs)
BeebReadRoms();
}
}

if (bLoadPrefs && m_AutoloadJoystickMap)
{
CheckForJoystickMap(path);
}
}

/*****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions Src/beebwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class BeebWin {
void ResetTiming(void);
int TranslateKey(int vkey, bool keyUp, int &row, int &col);
void ParseCommandLine(void);
void CheckForJoystickMap(const char *path);
void CheckForLocalPrefs(const char *path, bool bLoadPrefs);
void FindCommandLineFile(char *CmdLineFile);
void HandleCommandLineFile(int drive, const char *CmdLineFile);
Expand Down Expand Up @@ -600,6 +601,7 @@ class BeebWin {
FILE* OpenWriteFile(const char *filename, const char *typeDescr);
bool ReadKeyMap(const char *filename, KeyMap *keymap);
bool WriteKeyMap(const char *filename, KeyMap *keymap);
void ResetJoyMapToDefaultUser(void);
void ResetJoyMap(JoyMap* joymap);
bool ReadJoyMap(const char *filename, JoyMap *joymap);
bool WriteJoyMap(const char *filename, JoyMap *joymap);
Expand Down
15 changes: 14 additions & 1 deletion Src/beebwinio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ void BeebWin::LoadTape(void)
else if (hasFileExt(FileName, ".csw")) {
LoadCSWTape(FileName);
}

CheckForJoystickMap(FileName);
}
}

Expand Down Expand Up @@ -1182,7 +1184,7 @@ void BeebWin::SaveUserKeyMap()
/****************************************************************************/
void BeebWin::ResetJoystickMap()
{
if (MessageBox(GETHWND, "Remove all joystick to keyboard mapping?", WindowTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
if (MessageBox(GETHWND, "Clear joystick to keyboard mapping table?", WindowTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
return;

ResetJoyMap(&JoystickMap);
Expand Down Expand Up @@ -1337,6 +1339,17 @@ bool BeebWin::ReadKeyMap(const char *filename, KeyMap *keymap)
return success;
}

/****************************************************************************/
void BeebWin::ResetJoyMapToDefaultUser(void)
{
char keymap[_MAX_PATH];
strcpy(keymap, "DefaultUser.jmap");
GetDataPath(m_UserDataPath, keymap);
ResetJoyMap(&JoystickMap);
if (GetFileAttributes(keymap) != INVALID_FILE_ATTRIBUTES)
ReadJoyMap(keymap, &JoystickMap);
}

/****************************************************************************/
void BeebWin::ResetJoyMap(JoyMap* joymap)
{
Expand Down

0 comments on commit 25fcda4

Please sign in to comment.