From de7f35e6bd91e2ebe38edb0342ee05a6a99cce45 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 19 May 2021 21:10:22 +0100 Subject: [PATCH 1/3] Make path separator OS-dependent (PR #954) --- source/Common.h | 6 ++++++ source/Core.cpp | 4 ++-- source/Debugger/Debug.cpp | 4 ++-- source/Disk.cpp | 4 ++-- source/DiskImage.cpp | 4 ++-- source/DiskImageHelper.cpp | 4 ++-- source/Harddisk.cpp | 6 +++--- source/SaveState.cpp | 12 ++++++------ source/Utilities.cpp | 4 ++-- source/Windows/AppleWin.cpp | 6 +++--- 10 files changed, 30 insertions(+), 24 deletions(-) diff --git a/source/Common.h b/source/Common.h index 21c8b8af..e5ea19e7 100644 --- a/source/Common.h +++ b/source/Common.h @@ -143,6 +143,12 @@ enum AppMode_e #define WM_USER_FULLSCREEN WM_USER+8 #define VK_SNAPSHOT_TEXT WM_USER+9 // PrintScreen+Ctrl +#ifdef _MSC_VER +#define PATH_SEPARATOR '\\' +#else +#define PATH_SEPARATOR '/' +#endif + enum eIRQSRC {IS_6522=0, IS_SPEECH, IS_SSC, IS_MOUSE}; // diff --git a/source/Core.cpp b/source/Core.cpp index 4eba1bda..79dae7bd 100644 --- a/source/Core.cpp +++ b/source/Core.cpp @@ -288,8 +288,8 @@ bool SetCurrentImageDir(const std::string& pszImageDir) { g_sCurrentDir = pszImageDir; - if (!g_sCurrentDir.empty() && *g_sCurrentDir.rbegin() != '\\') - g_sCurrentDir += '\\'; + if (!g_sCurrentDir.empty() && *g_sCurrentDir.rbegin() != PATH_SEPARATOR) + g_sCurrentDir += PATH_SEPARATOR; if (SetCurrentDirectory(g_sCurrentDir.c_str())) return true; diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 5741ae24..25854672 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -3690,7 +3690,7 @@ Update_t CmdConfigSetDebugDir (int nArgs) { sPath = g_aArgs[1].sArg; } - else if (g_aArgs[1].sArg[0] == '\\') // Absolute + else if (g_aArgs[1].sArg[0] == PATH_SEPARATOR) // Absolute { if (g_sCurrentDir[1] == ':') { @@ -5982,7 +5982,7 @@ Update_t CmdOutputRun (int nArgs) sMiniFileName = pFileName.substr(0, MIN(pFileName.size(), CONSOLE_WIDTH)); // strcat( sMiniFileName, ".aws" ); // HACK: MAGIC STRING - if (pFileName[0] == '\\' || pFileName[1] == ':') // NB. Any prefix quote has already been stripped + if (pFileName[0] == PATH_SEPARATOR || pFileName[1] == ':') // NB. Any prefix quote has already been stripped { // Abs pathname sFileName = sMiniFileName; diff --git a/source/Disk.cpp b/source/Disk.cpp index df476444..21188e2a 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -202,7 +202,7 @@ void Disk2InterfaceCard::SaveLastDiskImage(const int drive) TCHAR szPathName[MAX_PATH]; StringCbCopy(szPathName, MAX_PATH, DiskGetFullPathName(drive).c_str()); - TCHAR* slash = _tcsrchr(szPathName, TEXT('\\')); + TCHAR* slash = _tcsrchr(szPathName, TEXT(PATH_SEPARATOR)); if (slash != NULL) { slash[1] = '\0'; @@ -599,7 +599,7 @@ void Disk2InterfaceCard::GetFilenameAndPathForSaveState(std::string& filename, s filename = GetBaseName(i); std::string pathname = DiskGetFullPathName(i); - int idx = pathname.find_last_of('\\'); + int idx = pathname.find_last_of(PATH_SEPARATOR); if (idx >= 0 && idx+1 < (int)pathname.length()) // path exists? { path = pathname.substr(0, idx+1); diff --git a/source/DiskImage.cpp b/source/DiskImage.cpp index 4ccc160c..1dc0e3d9 100644 --- a/source/DiskImage.cpp +++ b/source/DiskImage.cpp @@ -260,8 +260,8 @@ void GetImageTitle(LPCTSTR pPathname, std::string & pImageName, std::string & pF LPCTSTR startpos = pPathname; // imagetitle = - if (_tcsrchr(startpos, TEXT('\\'))) - startpos = _tcsrchr(startpos, TEXT('\\'))+1; + if (_tcsrchr(startpos, TEXT(PATH_SEPARATOR))) + startpos = _tcsrchr(startpos, TEXT(PATH_SEPARATOR))+1; _tcsncpy(imagetitle, startpos, MAX_DISK_FULL_NAME); imagetitle[MAX_DISK_FULL_NAME] = 0; diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index 8e2b48ce..c0d4a6d2 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -1541,8 +1541,8 @@ void CImageHelperBase::GetCharLowerExt(TCHAR* pszExt, LPCTSTR pszImageFilename, { LPCTSTR pImageFileExt = pszImageFilename; - if (_tcsrchr(pImageFileExt, TEXT('\\'))) - pImageFileExt = _tcsrchr(pImageFileExt, TEXT('\\'))+1; + if (_tcsrchr(pImageFileExt, TEXT(PATH_SEPARATOR))) + pImageFileExt = _tcsrchr(pImageFileExt, TEXT(PATH_SEPARATOR))+1; if (_tcsrchr(pImageFileExt, TEXT('.'))) pImageFileExt = _tcsrchr(pImageFileExt, TEXT('.')); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 7a70b0ed..6b77f8a9 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -247,9 +247,9 @@ static void HD_SaveLastDiskImage(const int iDrive) char szPathName[MAX_PATH]; strcpy(szPathName, HD_GetFullPathName(iDrive).c_str()); - if (_tcsrchr(szPathName, TEXT('\\'))) + if (_tcsrchr(szPathName, TEXT(PATH_SEPARATOR))) { - char* pPathEnd = _tcsrchr(szPathName, TEXT('\\'))+1; + char* pPathEnd = _tcsrchr(szPathName, TEXT(PATH_SEPARATOR))+1; *pPathEnd = 0; RegSaveString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_HDV_START_DIR), 1, szPathName); } @@ -335,7 +335,7 @@ void HD_GetFilenameAndPathForSaveState(std::string& filename, std::string& path) filename = HD_DiskGetBaseName(i); std::string pathname = HD_GetFullPathName(i); - int idx = pathname.find_last_of('\\'); + int idx = pathname.find_last_of(PATH_SEPARATOR); if (idx >= 0 && idx+1 < (int)pathname.length()) // path exists? { path = pathname.substr(0, idx+1); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index 396fb63e..caf58958 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -86,8 +86,8 @@ static void Snapshot_SetPathname(const std::string& strPathname) g_strSaveStateFilename = DEFAULT_SNAPSHOT_NAME; g_strSaveStatePathname = g_sCurrentDir; - if (!g_strSaveStatePathname.empty() && *g_strSaveStatePathname.rbegin() != '\\') - g_strSaveStatePathname += "\\"; + if (!g_strSaveStatePathname.empty() && *g_strSaveStatePathname.rbegin() != PATH_SEPARATOR) + g_strSaveStatePathname += PATH_SEPARATOR; g_strSaveStatePathname.append(DEFAULT_SNAPSHOT_NAME); g_strSaveStatePath = g_sCurrentDir; @@ -97,7 +97,7 @@ static void Snapshot_SetPathname(const std::string& strPathname) std::string strFilename = strPathname; // Set default, as maybe there's no path g_strSaveStatePath.clear(); - int nIdx = strPathname.find_last_of('\\'); + int nIdx = strPathname.find_last_of(PATH_SEPARATOR); if (nIdx >= 0 && nIdx+1 < (int)strPathname.length()) // path exists? { strFilename = &strPathname[nIdx+1]; @@ -113,12 +113,12 @@ void Snapshot_SetFilename(const std::string& filename, const std::string& path/* if (path.empty()) return Snapshot_SetPathname(filename); - _ASSERT(filename.find('\\') == std::string::npos); // since we have a path, then filename mustn't contain a path too! + _ASSERT(filename.find(PATH_SEPARATOR) == std::string::npos); // since we have a path, then filename mustn't contain a path too! // Ensure path is suffixed with '\' before adding filename std::string pathname = path; - if (*pathname.rbegin() != '\\') - pathname += "\\"; + if (*pathname.rbegin() != PATH_SEPARATOR) + pathname += PATH_SEPARATOR; Snapshot_SetPathname(pathname+filename); } diff --git a/source/Utilities.cpp b/source/Utilities.cpp index 2f2890d9..7be4f674 100644 --- a/source/Utilities.cpp +++ b/source/Utilities.cpp @@ -321,7 +321,7 @@ static std::string GetFullPath(LPCSTR szFileName) { std::string strPathName; - if (szFileName[0] == '\\' || szFileName[1] == ':') + if (szFileName[0] == PATH_SEPARATOR || szFileName[1] == ':') { // Abs pathname strPathName = szFileName; @@ -344,7 +344,7 @@ static void SetCurrentDir(std::string pathname) // . if -[sN]d1 and -[sN]d2 are specified, then g_sCurrentDir will be set to the d2 image's path // This is purely dependent on the current order of InsertFloppyDisks() & InsertHardDisks() - ie. very brittle! // . better to use -current-dir to be explicit - std::size_t found = pathname.find_last_of("\\"); + std::size_t found = pathname.find_last_of(PATH_SEPARATOR); std::string path = pathname.substr(0, found); SetCurrentImageDir(path); } diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index 46d036c5..dda970dc 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -340,7 +340,7 @@ static void GetProgramDirectory(void) int loop = g_sProgramDir.size(); while (loop--) { - if ((g_sProgramDir[loop] == TEXT('\\')) || (g_sProgramDir[loop] == TEXT(':'))) + if ((g_sProgramDir[loop] == TEXT(PATH_SEPARATOR)) || (g_sProgramDir[loop] == TEXT(':'))) { g_sProgramDir.resize(loop + 1); // this reduces the size break; @@ -619,7 +619,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) char startDir[_MAX_PATH]; GetCurrentDirectory(sizeof(startDir), startDir); g_sStartDir = startDir; - if (*(g_sStartDir.end()-1) != '\\') g_sStartDir += '\\'; + if (*(g_sStartDir.end()-1) != PATH_SEPARATOR) g_sStartDir += PATH_SEPARATOR; if (!ProcessCmdLine(lpCmdLine)) return 0; @@ -948,7 +948,7 @@ static void RepeatInitialization(void) if (g_cmdLine.szSnapshotName) { std::string strPathname(g_cmdLine.szSnapshotName); - int nIdx = strPathname.find_last_of('\\'); + int nIdx = strPathname.find_last_of(PATH_SEPARATOR); if (nIdx >= 0 && nIdx+1 < (int)strPathname.length()) // path exists? { const std::string strPath = strPathname.substr(0, nIdx+1); From 05b9668f725b19268f0d638cb7701c8ed9cbd334 Mon Sep 17 00:00:00 2001 From: tomcw Date: Wed, 19 May 2021 21:26:23 +0100 Subject: [PATCH 2/3] Use enum SLOTS and remove pre-processor SLOTn defines --- source/Card.h | 2 +- source/Common.h | 2 -- source/Harddisk.cpp | 2 +- source/LanguageCard.h | 2 +- source/Mockingboard.cpp | 3 --- 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/source/Card.h b/source/Card.h index 6d2ccb3f..64170098 100644 --- a/source/Card.h +++ b/source/Card.h @@ -23,7 +23,7 @@ enum SS_CARDTYPE CT_Saturn128K, // Saturn 128K (but may be populated with less RAM, in multiples of 16K) }; -enum SLOTS { SLOT0=0, SLOT1, SLOT2, SLOT3, SLOT4, SLOT5, SLOT6, SLOT7 }; +enum SLOTS { SLOT0=0, SLOT1, SLOT2, SLOT3, SLOT4, SLOT5, SLOT6, SLOT7, NUM_SLOTS }; class Card { diff --git a/source/Common.h b/source/Common.h index e5ea19e7..43920691 100644 --- a/source/Common.h +++ b/source/Common.h @@ -6,8 +6,6 @@ const double CLK_6502_NTSC = (_14M_NTSC * 65.0) / (65.0*14.0+2.0); // 65 cycles const double CLK_6502_PAL = (_14M_PAL * 65.0) / (65.0*14.0+2.0); //const double CLK_6502 = 23 * 44100; // 1014300 -#define NUM_SLOTS 8 - #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define MIN(a,b) (((a) < (b)) ? (a) : (b)) diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 6b77f8a9..c9159af8 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -175,7 +175,7 @@ static BYTE g_nHD_Command; static HDD g_HardDisk[NUM_HARDDISKS]; static bool g_bSaveDiskImage = true; // Save the DiskImage name to Registry -static UINT g_uSlot = 7; +static UINT g_uSlot = SLOT7; //=========================================================================== diff --git a/source/LanguageCard.h b/source/LanguageCard.h index 6f236cb9..8f98c3db 100644 --- a/source/LanguageCard.h +++ b/source/LanguageCard.h @@ -29,7 +29,7 @@ public: static BYTE __stdcall IO(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nExecutedCycles); static const UINT kMemModeInitialState; - static const UINT kSlot0 = 0; + static const UINT kSlot0 = SLOT0; private: UINT m_uLastRamWrite; diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index 9578e38a..1ec86f89 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -98,9 +98,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define SY6522_DEVICE_A 0 #define SY6522_DEVICE_B 1 -#define SLOT4 4 -#define SLOT5 5 - #define NUM_MB 2 #define NUM_DEVS_PER_MB 2 #define NUM_AY8910 (NUM_MB*NUM_DEVS_PER_MB) From d631b23d24cef6f0e308b820327163c892a59e70 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 19 May 2021 21:44:33 +0100 Subject: [PATCH 3/3] Uthernet: fix usability and settings (PR #947) * Make Uthernet settings behave like all other cards. Fix as well the fact that the Uthernet interface would not be reapplied after a restart. * Uthernet: use consistent types to reduce code complexity. Use std::string everywhere. --- source/Configuration/Config.h | 10 +++ source/Configuration/PageConfig.cpp | 8 ++ source/Configuration/PageConfigTfe.cpp | 26 ++---- source/Configuration/PageConfigTfe.h | 6 ++ source/Configuration/PropertySheetHelper.cpp | 16 ++++ source/Tfe/tfe.cpp | 88 +++++--------------- source/Tfe/tfe.h | 7 +- source/Tfe/tfearch.cpp | 19 ++++- source/Tfe/tfearch.h | 3 +- source/Utilities.cpp | 2 +- 10 files changed, 90 insertions(+), 95 deletions(-) diff --git a/source/Configuration/Config.h b/source/Configuration/Config.h index a2b52e10..659b12c7 100644 --- a/source/Configuration/Config.h +++ b/source/Configuration/Config.h @@ -6,6 +6,7 @@ #include "../DiskImage.h" // Disk_Status_e #include "../Harddisk.h" // HD_CardIsEnabled() #include "../Interface.h" // VideoRefreshRate_e, GetVideoRefreshRate() +#include "../Tfe/tfe.h" class CConfigNeedingRestart { @@ -23,6 +24,9 @@ public: m_Slot[SLOT4] = GetCardMgr().QuerySlot(SLOT4); m_Slot[SLOT5] = GetCardMgr().QuerySlot(SLOT5); m_Slot[SLOT7] = GetCardMgr().QuerySlot(SLOT7); + + m_tfeEnabled = get_tfe_enabled(); + m_tfeInterface = get_tfe_interface(); } const CConfigNeedingRestart& operator= (const CConfigNeedingRestart& other) @@ -31,6 +35,8 @@ public: m_CpuType = other.m_CpuType; memcpy(m_Slot, other.m_Slot, sizeof(m_Slot)); m_bEnableHDD = other.m_bEnableHDD; + m_tfeEnabled = other.m_tfeEnabled; + m_tfeInterface = other.m_tfeInterface; m_bEnableTheFreezesF8Rom = other.m_bEnableTheFreezesF8Rom; m_uSaveLoadStateMsg = other.m_uSaveLoadStateMsg; m_videoRefreshRate = other.m_videoRefreshRate; @@ -43,6 +49,8 @@ public: m_CpuType == other.m_CpuType && memcmp(m_Slot, other.m_Slot, sizeof(m_Slot)) == 0 && m_bEnableHDD == other.m_bEnableHDD && + m_tfeEnabled == other.m_tfeEnabled && + m_tfeInterface == other.m_tfeInterface && m_bEnableTheFreezesF8Rom == other.m_bEnableTheFreezesF8Rom && m_uSaveLoadStateMsg == other.m_uSaveLoadStateMsg && m_videoRefreshRate == other.m_videoRefreshRate; @@ -58,6 +66,8 @@ public: SS_CARDTYPE m_Slot[NUM_SLOTS]; // 0..7 SS_CARDTYPE m_SlotAux; bool m_bEnableHDD; + int m_tfeEnabled; + std::string m_tfeInterface; UINT m_bEnableTheFreezesF8Rom; UINT m_uSaveLoadStateMsg; VideoRefreshRate_e m_videoRefreshRate; diff --git a/source/Configuration/PageConfig.cpp b/source/Configuration/PageConfig.cpp index c753589b..8c1c2c80 100644 --- a/source/Configuration/PageConfig.cpp +++ b/source/Configuration/PageConfig.cpp @@ -238,6 +238,11 @@ INT_PTR CPageConfig::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPA EnableTrackbar(hWnd, bCustom); } + { + m_PageConfigTfe.m_tfe_enabled = get_tfe_enabled(); + m_PageConfigTfe.m_tfe_interface_name = get_tfe_interface(); + } + InitOptions(hWnd); break; @@ -310,6 +315,9 @@ void CPageConfig::DlgOK(HWND hWnd) m_PropertySheetHelper.GetConfigNew().m_videoRefreshRate = isNewVideoRate50Hz ? VR_50HZ : VR_60HZ; } + m_PropertySheetHelper.GetConfigNew().m_tfeEnabled = m_PageConfigTfe.m_tfe_enabled; + m_PropertySheetHelper.GetConfigNew().m_tfeInterface = m_PageConfigTfe.m_tfe_interface_name; + if (bVideoReinit) { win32Frame.FrameRefreshStatus(DRAW_TITLE); diff --git a/source/Configuration/PageConfigTfe.cpp b/source/Configuration/PageConfigTfe.cpp index 084d9cde..fbba5842 100644 --- a/source/Configuration/PageConfigTfe.cpp +++ b/source/Configuration/PageConfigTfe.cpp @@ -196,29 +196,19 @@ void CPageConfigTfe::init_tfe_dialog(HWND hwnd) HWND temp_hwnd; int active_value; - int tfe_enable; int xsize, ysize; - char *interface_name = NULL; - uilib_get_group_extent(hwnd, ms_leftgroup, &xsize, &ysize); uilib_adjust_group_width(hwnd, ms_leftgroup); uilib_move_group(hwnd, ms_rightgroup, xsize + 30); - //resources_get_value("ETHERNET_ACTIVE", (void *)&tfe_enabled); - get_tfe_enabled(&tfe_enable); - - //resources_get_value("ETHERNET_AS_RR", (void *)&tfe_as_rr_net); - active_value = (tfe_enable ? 1 : 0); + active_value = (m_tfe_enabled > 0 ? 1 : 0); temp_hwnd=GetDlgItem(hwnd,IDC_TFE_SETTINGS_ENABLE); SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)"Disabled"); SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)"Uthernet"); SendMessage(temp_hwnd, CB_SETCURSEL, (WPARAM)active_value, 0); - //resources_get_value("ETHERNET_INTERFACE", (void *)&interface_name); - interface_name = (char *) get_tfe_interface(); - if (tfe_enumadapter_open()) { int cnt = 0; @@ -232,7 +222,7 @@ void CPageConfigTfe::init_tfe_dialog(HWND hwnd) { BOOL this_entry = FALSE; - if (strcmp(pname, interface_name) == 0) + if (strcmp(pname, m_tfe_interface_name.c_str()) == 0) { this_entry = TRUE; } @@ -274,7 +264,6 @@ void CPageConfigTfe::init_tfe_dialog(HWND hwnd) void CPageConfigTfe::save_tfe_dialog(HWND hwnd) { int active_value; - int tfe_enabled; char buffer[256]; buffer[255] = 0; @@ -283,16 +272,13 @@ void CPageConfigTfe::save_tfe_dialog(HWND hwnd) // RGJ - Added check for NULL interface so we don't set it active without a valid interface selected if (strlen(buffer) > 0) { - RegSaveString(TEXT(REG_CONFIG), TEXT(REGVALUE_UTHERNET_INTERFACE), 1, buffer); - + m_tfe_interface_name = buffer; active_value = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), CB_GETCURSEL, 0, 0); - - tfe_enabled = active_value >= 1 ? 1 : 0; - REGSAVE(TEXT(REGVALUE_UTHERNET_ACTIVE) ,tfe_enabled); + m_tfe_enabled = active_value >= 1 ? 1 : 0; } else { - REGSAVE(TEXT(REGVALUE_UTHERNET_ACTIVE) ,0); + m_tfe_enabled = 0; + m_tfe_interface_name.clear(); } } - diff --git a/source/Configuration/PageConfigTfe.h b/source/Configuration/PageConfigTfe.h index 648afef4..3bf92e57 100644 --- a/source/Configuration/PageConfigTfe.h +++ b/source/Configuration/PageConfigTfe.h @@ -3,17 +3,23 @@ #include "IPropertySheetPage.h" #include "../Tfe/Uilib.h" +#include + class CPageConfigTfe : private IPropertySheetPage { public: CPageConfigTfe() { CPageConfigTfe::ms_this = this; + m_tfe_enabled = 0; } virtual ~CPageConfigTfe(){} static INT_PTR CALLBACK DlgProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam); + int m_tfe_enabled; + std::string m_tfe_interface_name; + protected: // IPropertySheetPage virtual INT_PTR DlgProcInternal(HWND window, UINT message, WPARAM wparam, LPARAM lparam); diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index 51b2dec3..3a6c833c 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -370,6 +370,17 @@ void CPropertySheetHelper::ApplyNewConfig(const CConfigNeedingRestart& ConfigNew { REGSAVE(TEXT(REGVALUE_VIDEO_REFRESH_RATE), ConfigNew.m_videoRefreshRate); } + + if (CONFIG_CHANGED_LOCAL(m_tfeEnabled)) + { + REGSAVE(TEXT(REGVALUE_UTHERNET_ACTIVE), ConfigNew.m_tfeEnabled); + } + + if (CONFIG_CHANGED_LOCAL(m_tfeInterface)) + { + RegSaveString(TEXT(REG_CONFIG), TEXT(REGVALUE_UTHERNET_INTERFACE), 1, ConfigNew.m_tfeInterface); + } + } void CPropertySheetHelper::ApplyNewConfig(void) @@ -387,6 +398,8 @@ void CPropertySheetHelper::SaveCurrentConfig(void) m_ConfigOld.m_bEnableHDD = HD_CardIsEnabled(); m_ConfigOld.m_bEnableTheFreezesF8Rom = GetPropertySheet().GetTheFreezesF8Rom(); m_ConfigOld.m_videoRefreshRate = GetVideo().GetVideoRefreshRate(); + m_ConfigOld.m_tfeEnabled = get_tfe_enabled(); + m_ConfigOld.m_tfeInterface = get_tfe_interface(); // Reset flags each time: m_ConfigOld.m_uSaveLoadStateMsg = 0; @@ -470,6 +483,9 @@ bool CPropertySheetHelper::HardwareConfigChanged(HWND hWnd) if (CONFIG_CHANGED(m_bEnableTheFreezesF8Rom)) strMsgMain += ". F8 ROM changed (The Freeze's F8 Rom)\n"; + + if (CONFIG_CHANGED(m_tfeEnabled) || CONFIG_CHANGED(m_tfeInterface)) + strMsgMain += ". Ethernet (TFE) Options\n"; } std::string strMsgPost("\n"); diff --git a/source/Tfe/tfe.cpp b/source/Tfe/tfe.cpp index be46456e..cbe137a7 100644 --- a/source/Tfe/tfe.cpp +++ b/source/Tfe/tfe.cpp @@ -60,13 +60,6 @@ typedef unsigned int UINT; /* ------------------------------------------------------------------------- */ /* variables needed */ -/* - This variable is used when we need to postpone the initialization - because tfe_init() is not yet called -*/ -static int should_activate = 0; - - static int init_tfe_flag = 0; /* status which received packages to accept @@ -100,7 +93,7 @@ int tfe_enabled = 0; /* Flag: Do we use the "original" memory map or the memory map of the RR-Net? */ //static int tfe_as_rr_net = 0; -char *tfe_interface = NULL; +std::string tfe_interface; /* TFE registers */ /* these are the 8 16-bit-ports for "I/O space configuration" @@ -397,7 +390,7 @@ static BYTE __stdcall TfeIo (WORD programcounter, WORD address, BYTE write, BYTE void tfe_reset(void) { - if (tfe_enabled && !should_activate) + if (tfe_enabled) { assert( tfe ); assert( tfe_packetpage ); @@ -550,13 +543,7 @@ int tfe_activate(void) { if(g_fh) fprintf( g_fh, "tfe_activate()." ); #endif - if (init_tfe_flag) { - return tfe_activate_i(); - } - else { - should_activate = 1; - } - return 0; + return tfe_activate_i(); } static @@ -565,28 +552,25 @@ int tfe_deactivate(void) { if(g_fh) fprintf( g_fh, "tfe_deactivate()." ); #endif - if (should_activate) - should_activate = 0; - else { - if (init_tfe_flag) - return tfe_deactivate_i(); - } - - return 0; + return tfe_deactivate_i(); } void tfe_init(void) { - init_tfe_flag = 1; - if (!tfe_arch_init()) { tfe_enabled = 0; tfe_cannot_use = 1; } + else + { + // the first time this is a NOOP + // but when called from RepeatInitialization() + // it ensures new settings are taken into account + if (tfe) + tfe_deactivate(); - if (should_activate) { - should_activate = 0; - if (tfe_activate() < 0) { + // only activate if the settings say so + if (tfe_enabled && (tfe_activate() < 0)) { tfe_enabled = 0; tfe_cannot_use = 1; } @@ -600,8 +584,7 @@ void tfe_shutdown(void) if (tfe) tfe_deactivate(); - lib_free(tfe_interface); - tfe_interface = NULL; + tfe_interface.clear(); } @@ -1395,37 +1378,12 @@ int set_tfe_enabled(void *v, void *param) static -int set_tfe_interface(void *v, void *param) +int set_tfe_interface(const std::string & name) { - const char *name = (const char *)v; - - if (tfe_interface != NULL && name != NULL - && strcmp(name, tfe_interface) == 0) - return 0; - - util_string_set(&tfe_interface, name); - - if (tfe_enabled) { - /* ethernet is enabled, make sure that the new name is - taken account of - */ - if (tfe_deactivate() < 0) { - return -1; - } - if (tfe_activate() < 0) { - return -1; - } - - /* virtually reset the LAN chip */ - if (tfe) { - tfe_reset(); - } - } + tfe_interface = name; return 0; } - - /* ------------------------------------------------------------------------- */ /* commandline support functions */ @@ -1547,21 +1505,19 @@ void get_disabled_state(int * param) } -int update_tfe_interface(void *v, void *param) +int update_tfe_interface(const std::string & name) { - return set_tfe_interface(v,param); + return set_tfe_interface(name); } -void * get_tfe_interface(void) +const std::string & get_tfe_interface(void) { - void *v; - v = tfe_interface; - return v; + return tfe_interface; } -void get_tfe_enabled(int * param) +int get_tfe_enabled(void) { - *param = tfe_enabled; + return tfe_enabled; } //#endif /* #ifdef HAVE_TFE */ diff --git a/source/Tfe/tfe.h b/source/Tfe/tfe.h index 5f79cee2..ba2cd136 100644 --- a/source/Tfe/tfe.h +++ b/source/Tfe/tfe.h @@ -29,6 +29,7 @@ #include "../CommonVICE/types.h" #include +#include /* define this only if VICE should write each and every frame received and send into the VICE log @@ -43,7 +44,7 @@ extern int tfe_enabled; extern void tfe_init(void); extern int tfe_resources_init(void); extern int tfe_cmdline_options_init(void); -extern int update_tfe_interface(void *v, void *param); +extern int update_tfe_interface(const std::string & name); void get_disabled_state(int * param); extern void tfe_reset(void); @@ -77,8 +78,8 @@ extern int tfe_enumadapter_open(void); extern int tfe_enumadapter(char **ppname, char **ppdescription); extern int tfe_enumadapter_close(void); -extern void* get_tfe_interface(void); -extern void get_tfe_enabled(int *tfe_enabled); +extern int get_tfe_enabled(void); +extern const std::string & get_tfe_interface(void); extern FILE* g_fh; // Filehandle for log file diff --git a/source/Tfe/tfearch.cpp b/source/Tfe/tfearch.cpp index 32af5f93..b07e1230 100644 --- a/source/Tfe/tfearch.cpp +++ b/source/Tfe/tfearch.cpp @@ -51,6 +51,7 @@ #ifdef _MSC_VER typedef pcap_t *(*pcap_open_live_t)(const char *, int, int, int, char *); +typedef void (*pcap_close_t)(pcap_t *); typedef int (*pcap_dispatch_t)(pcap_t *, int, pcap_handler, u_char *); typedef int (*pcap_setnonblock_t)(pcap_t *, int, char *); typedef int (*pcap_datalink_t)(pcap_t *); @@ -60,6 +61,7 @@ typedef int (*pcap_sendpacket_t)(pcap_t *p, u_char *buf, int size); typedef const char *(*pcap_lib_version_t)(void); static pcap_open_live_t p_pcap_open_live; +static pcap_close_t p_pcap_close; static pcap_dispatch_t p_pcap_dispatch; static pcap_setnonblock_t p_pcap_setnonblock; static pcap_findalldevs_t p_pcap_findalldevs; @@ -80,6 +82,7 @@ void TfePcapFreeLibrary(void) pcap_library = NULL; p_pcap_open_live = NULL; + p_pcap_close = NULL; p_pcap_dispatch = NULL; p_pcap_setnonblock = NULL; p_pcap_findalldevs = NULL; @@ -118,6 +121,7 @@ BOOL TfePcapLoadLibrary(void) } GET_PROC_ADDRESS_AND_TEST(pcap_open_live); + GET_PROC_ADDRESS_AND_TEST(pcap_close); GET_PROC_ADDRESS_AND_TEST(pcap_dispatch); GET_PROC_ADDRESS_AND_TEST(pcap_setnonblock); GET_PROC_ADDRESS_AND_TEST(pcap_findalldevs); @@ -138,6 +142,7 @@ BOOL TfePcapLoadLibrary(void) // libpcap is a standard package, just link to it #define p_pcap_open_live pcap_open_live +#define p_pcap_close pcap_close #define p_pcap_dispatch pcap_dispatch #define p_pcap_setnonblock pcap_setnonblock #define p_pcap_findalldevs pcap_findalldevs @@ -276,7 +281,7 @@ int tfe_arch_enumadapter_close(void) } static -BOOL TfePcapOpenAdapter(const char *interface_name) +BOOL TfePcapOpenAdapter(const std::string & interface_name) { pcap_if_t *TfePcapDevice = NULL; @@ -289,12 +294,12 @@ BOOL TfePcapOpenAdapter(const char *interface_name) char *pdescription; BOOL found = FALSE; - if (interface_name) { + if (!interface_name.empty()) { /* we have an interface name, try it */ TfePcapDevice = TfePcapAlldevs; while (tfe_enumadapter(&pname, &pdescription)) { - if (strcmp(pname, interface_name)==0) { + if (strcmp(pname, interface_name.c_str())==0) { found = TRUE; } lib_free(pname); @@ -328,6 +333,8 @@ BOOL TfePcapOpenAdapter(const char *interface_name) { if(g_fh) fprintf(g_fh, "ERROR: TFE works only on Ethernet networks.\n"); tfe_enumadapter_close(); + (*p_pcap_close)(TfePcapFP); + TfePcapFP = NULL; return FALSE; } @@ -365,7 +372,7 @@ void tfe_arch_post_reset( void ) #endif } -int tfe_arch_activate(const char *interface_name) +int tfe_arch_activate(const std::string & interface_name) { #ifdef TFE_DEBUG_ARCH if(g_fh) fprintf( g_fh, "tfe_arch_activate().\n" ); @@ -381,6 +388,10 @@ void tfe_arch_deactivate( void ) #ifdef TFE_DEBUG_ARCH if(g_fh) fprintf( g_fh, "tfe_arch_deactivate().\n" ); #endif + if (TfePcapFP) { + (*p_pcap_close)(TfePcapFP); + TfePcapFP = NULL; + } } void tfe_arch_set_mac( const BYTE mac[6] ) diff --git a/source/Tfe/tfearch.h b/source/Tfe/tfearch.h index ecd95f3d..a7b5be49 100644 --- a/source/Tfe/tfearch.h +++ b/source/Tfe/tfearch.h @@ -29,11 +29,12 @@ #define _TFEARCH_H #include "../CommonVICE/types.h" +#include extern int tfe_arch_init(void); extern void tfe_arch_pre_reset(void); extern void tfe_arch_post_reset(void); -extern int tfe_arch_activate(const char *interface_name); +extern int tfe_arch_activate(const std::string & interface_name); extern void tfe_arch_deactivate(void); extern void tfe_arch_set_mac(const BYTE mac[6]); extern void tfe_arch_set_hashfilter(const DWORD hash_mask[2]); diff --git a/source/Utilities.cpp b/source/Utilities.cpp index 7be4f674..7aa8b688 100644 --- a/source/Utilities.cpp +++ b/source/Utilities.cpp @@ -300,7 +300,7 @@ void LoadConfiguration(void) tfe_enabled = dwTfeEnabled ? 1 : 0; RegLoadString(TEXT(REG_CONFIG), TEXT(REGVALUE_UTHERNET_INTERFACE), 1, szFilename, MAX_PATH, TEXT("")); - update_tfe_interface(szFilename, NULL); + update_tfe_interface(szFilename); //