From 0cf99a45283d708c31375ce3cc8da62fae73faa8 Mon Sep 17 00:00:00 2001 From: Nikita Zimin Date: Sun, 4 Oct 2020 04:03:30 +0300 Subject: [PATCH] ROM files in resources; ability to select ROM file in menu. --- docs/{ms0515-b92c.lst => ms0515-roma.lst} | 0 docs/{ms0515-3d60.lst => ms0515-romb.lst} | 0 emulator/Emulator.cpp | 82 ++++++++++-------- emulator/Emulator.h | 8 ++ emulator/Main.cpp | 5 ++ emulator/MainWindow.cpp | 41 +++++++-- emulator/Settings.cpp | 2 + emulator/res/Resource.h | 4 + emulator/res/Resource.rc | Bin 20746 -> 21552 bytes .../res/ms0515-roma.rom | Bin .../res/ms0515-romb.rom | Bin 11 files changed, 100 insertions(+), 42 deletions(-) rename docs/{ms0515-b92c.lst => ms0515-roma.lst} (100%) rename docs/{ms0515-3d60.lst => ms0515-romb.lst} (100%) rename ms0515-b92c.rom => emulator/res/ms0515-roma.rom (100%) rename ms0515-3d60.rom => emulator/res/ms0515-romb.rom (100%) diff --git a/docs/ms0515-b92c.lst b/docs/ms0515-roma.lst similarity index 100% rename from docs/ms0515-b92c.lst rename to docs/ms0515-roma.lst diff --git a/docs/ms0515-3d60.lst b/docs/ms0515-romb.lst similarity index 100% rename from docs/ms0515-3d60.lst rename to docs/ms0515-romb.lst diff --git a/emulator/Emulator.cpp b/emulator/Emulator.cpp index f37ff11..6e12ccf 100644 --- a/emulator/Emulator.cpp +++ b/emulator/Emulator.cpp @@ -104,35 +104,11 @@ const uint32_t Emulator_Palette[24] = ////////////////////////////////////////////////////////////////////// -const LPCTSTR FILENAME_ROM_MS0515 = _T("ms0515.rom"); +const LPCTSTR FILENAME_ROM_MS0515 = _T("ms0515.rom"); ////////////////////////////////////////////////////////////////////// -bool Emulator_LoadRomFile(LPCTSTR strFileName, uint8_t* buffer, uint32_t fileOffset, uint32_t bytesToRead) -{ - FILE* fpRomFile = ::_tfsopen(strFileName, _T("rb"), _SH_DENYWR); - if (fpRomFile == nullptr) - return false; - - ::memset(buffer, 0, bytesToRead); - - if (fileOffset > 0) - { - ::fseek(fpRomFile, fileOffset, SEEK_SET); - } - - uint32_t dwBytesRead = ::fread(buffer, 1, bytesToRead, fpRomFile); - if (dwBytesRead != bytesToRead) - { - ::fclose(fpRomFile); - return false; - } - - ::fclose(fpRomFile); - - return true; -} bool Emulator_Init() { @@ -165,15 +141,6 @@ bool Emulator_Init() g_pBoard->SetSoundGenCallback(Emulator_SoundGenCallback); } - // Load ROM file - uint8_t buffer[16384]; - if (!Emulator_LoadRomFile(FILENAME_ROM_MS0515, buffer, 0, 16384)) - { - AlertWarning(_T("Failed to load the ROM.")); - return false; - } - g_pBoard->LoadROM(buffer); - return true; } @@ -201,6 +168,53 @@ void Emulator_Done() ::free(g_pEmulatorChangedRam); } +bool Emulator_InitConfiguration(int configuration) +{ + g_pBoard->SetConfiguration((uint16_t)configuration); + + uint8_t buffer[16384]; + + // Load ROM from the file, if found + FILE* fpFile = ::_tfsopen(FILENAME_ROM_MS0515, _T("rb"), _SH_DENYWR); + if (fpFile != nullptr) + { + size_t dwBytesRead = ::fread(buffer, 1, 16384, fpFile); + ::fclose(fpFile); + if (dwBytesRead != 16384) + { + AlertWarning(_T("Failed to load the ROM file.")); + return false; + } + } + else // ms0515.rom not found, use ROM image from resources + { + int romresid = configuration == 1 ? IDR_ROMA : IDR_ROMB; + + HRSRC hRes = NULL; + DWORD dwDataSize = 0; + HGLOBAL hResLoaded = NULL; + void * pResData = nullptr; + if ((hRes = ::FindResource(NULL, MAKEINTRESOURCE(romresid), _T("BIN"))) == NULL || + (dwDataSize = ::SizeofResource(NULL, hRes)) < 16384 || + (hResLoaded = ::LoadResource(NULL, hRes)) == NULL || + (pResData = ::LockResource(hResLoaded)) == NULL) + { + AlertWarning(_T("Failed to load the ROM resource.")); + return false; + } + ::memcpy(buffer, pResData, 16384); + } + g_pBoard->LoadROM(buffer); + + g_nEmulatorConfiguration = configuration; + + g_pBoard->Reset(); + + m_nUptimeFrameCount = 0; + + return true; +} + void Emulator_Start() { g_okEmulatorRunning = true; diff --git a/emulator/Emulator.h b/emulator/Emulator.h index 9ed26d1..548f415 100644 --- a/emulator/Emulator.h +++ b/emulator/Emulator.h @@ -17,6 +17,14 @@ MS0515BTL. If not, see . */ ////////////////////////////////////////////////////////////////////// +enum EmulatorConfiguration +{ + EMU_CONF_ROMA = 1, + EMU_CONF_ROMB = 2, +}; + + +////////////////////////////////////////////////////////////////////// const int MAX_BREAKPOINTCOUNT = 16; const int MAX_WATCHPOINTCOUNT = 16; diff --git a/emulator/Main.cpp b/emulator/Main.cpp index f0bcab3..c834eb0 100644 --- a/emulator/Main.cpp +++ b/emulator/Main.cpp @@ -178,6 +178,11 @@ BOOL InitInstance(HINSTANCE /*hInstance*/, int /*nCmdShow*/) if (!Emulator_Init()) return FALSE; + int conf = Settings_GetConfiguration(); + if (conf == 0) conf = EMU_CONF_ROMA; + if (!Emulator_InitConfiguration(conf)) + return FALSE; + Emulator_SetSound(Settings_GetSound()); Emulator_SetSpeed(Settings_GetRealSpeed()); diff --git a/emulator/MainWindow.cpp b/emulator/MainWindow.cpp index 773acfa..abccd49 100644 --- a/emulator/MainWindow.cpp +++ b/emulator/MainWindow.cpp @@ -718,14 +718,13 @@ void MainWindow_UpdateMenu() MainWindow_SetToolbarImage(ID_EMULATOR_SOUND, (Settings_GetSound() ? ToolbarImageSoundOn : ToolbarImageSoundOff)); EnableMenuItem(hMenu, ID_DEBUG_STEPINTO, (g_okEmulatorRunning ? MF_DISABLED : MF_ENABLED)); - //UINT configcmd = 0; - //switch (g_nEmulatorConfiguration) - //{ - //case EMU_CONF_NEMIGA303: configcmd = ID_CONF_NEMIGA303; break; - //case EMU_CONF_NEMIGA405: configcmd = ID_CONF_NEMIGA405; break; - //case EMU_CONF_NEMIGA406: configcmd = ID_CONF_NEMIGA406; break; - //} - //CheckMenuRadioItem(hMenu, ID_CONF_NEMIGA303, ID_CONF_NEMIGA406, configcmd, MF_BYCOMMAND); + UINT configcmd = 0; + switch (g_nEmulatorConfiguration) + { + case EMU_CONF_ROMA: configcmd = ID_CONF_ROMA; break; + case EMU_CONF_ROMB: configcmd = ID_CONF_ROMB; break; + } + CheckMenuRadioItem(hMenu, ID_CONF_ROMA, ID_CONF_ROMB, configcmd, MF_BYCOMMAND); // Emulator|FloppyX CheckMenuItem(hMenu, ID_EMULATOR_FLOPPY0, (g_pBoard->IsFloppyImageAttached(0) ? MF_CHECKED : MF_UNCHECKED)); @@ -861,6 +860,12 @@ bool MainWindow_DoCommand(int commandId) //case ID_FILE_CREATEDISK: // MainWindow_DoFileCreateDisk(); // break; + case ID_CONF_ROMA: + MainWindow_DoEmulatorConf(EMU_CONF_ROMA); + break; + case ID_CONF_ROMB: + MainWindow_DoEmulatorConf(EMU_CONF_ROMB); + break; case ID_FILE_SETTINGS: MainWindow_DoFileSettings(); break; @@ -1109,6 +1114,26 @@ void MainWindow_DoFileSettingsColors() } } +void MainWindow_DoEmulatorConf(int configuration) +{ + // Check if configuration changed + if (g_nEmulatorConfiguration == configuration) + return; + + // Ask user -- we have to reset machine to change configuration + if (!AlertOkCancel(_T("Reset required after configuration change.\nAre you agree?"))) + return; + + // Change configuration + Emulator_InitConfiguration(configuration); + + Settings_SetConfiguration(configuration); + + MainWindow_UpdateMenu(); + MainWindow_UpdateAllViews(); + //KeyboardView_Update(); +} + void MainWindow_DoEmulatorFloppy(int slot) { BOOL okImageAttached = g_pBoard->IsFloppyImageAttached(slot); diff --git a/emulator/Settings.cpp b/emulator/Settings.cpp index a9012ae..16510d1 100644 --- a/emulator/Settings.cpp +++ b/emulator/Settings.cpp @@ -260,6 +260,8 @@ SETTINGS_GETSET_DWORD(WindowMaximized, _T("WindowMaximized"), BOOL, FALSE); SETTINGS_GETSET_DWORD(WindowFullscreen, _T("WindowFullscreen"), BOOL, FALSE); +SETTINGS_GETSET_DWORD(Configuration, _T("Configuration"), int, 0); + void Settings_GetFloppyFilePath(int slot, LPTSTR buffer) { TCHAR bufValueName[8]; diff --git a/emulator/res/Resource.h b/emulator/res/Resource.h index 86f4a1d..ec2553d 100644 --- a/emulator/res/Resource.h +++ b/emulator/res/Resource.h @@ -18,6 +18,8 @@ #define IDD_SETTINGS_COLORS 146 #define IDD_DCB_EDITOR 148 #define IDB_KEYBOARDMASK 149 +#define IDR_ROMA 151 +#define IDR_ROMB 152 #define IDC_EDIT1 1000 #define IDC_BUILDDATE 1001 #define IDC_EDITADDR 1001 @@ -70,6 +72,8 @@ #define ID_EMULATOR_FLOPPY2 32806 #define ID_EMULATOR_FLOPPY3 32807 #define ID_EMULATOR_CONF 32808 +#define ID_CONF_ROMA 32809 +#define ID_CONF_ROMB 32810 #define ID_EMULATOR_SERIAL 32812 #define ID_EMULATOR_PARALLEL 32818 #define ID_EMULATOR_SOUND 32831 diff --git a/emulator/res/Resource.rc b/emulator/res/Resource.rc index 93f62f18da4a0be927c10ac2bede8022bf018118..08acc614e102f6e7b6fca76e256b3645324a4790 100644 GIT binary patch delta 245 zcmeBL#JFJv$rz@{V>2ZQVanu-o?AEH I@zG-e0D$5+AOHXW delta 27 jcmdn6g0X86~&z diff --git a/ms0515-b92c.rom b/emulator/res/ms0515-roma.rom similarity index 100% rename from ms0515-b92c.rom rename to emulator/res/ms0515-roma.rom diff --git a/ms0515-3d60.rom b/emulator/res/ms0515-romb.rom similarity index 100% rename from ms0515-3d60.rom rename to emulator/res/ms0515-romb.rom