Skip to content

Commit

Permalink
ROM files in resources; ability to select ROM file in menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Oct 4, 2020
1 parent d2fde06 commit 0cf99a4
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 42 deletions.
File renamed without changes.
File renamed without changes.
82 changes: 48 additions & 34 deletions emulator/Emulator.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions emulator/Emulator.h
Expand Up @@ -17,6 +17,14 @@ MS0515BTL. If not, see <http://www.gnu.org/licenses/>. */

//////////////////////////////////////////////////////////////////////

enum EmulatorConfiguration
{
EMU_CONF_ROMA = 1,
EMU_CONF_ROMB = 2,
};


//////////////////////////////////////////////////////////////////////

const int MAX_BREAKPOINTCOUNT = 16;
const int MAX_WATCHPOINTCOUNT = 16;
Expand Down
5 changes: 5 additions & 0 deletions emulator/Main.cpp
Expand Up @@ -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());

Expand Down
41 changes: 33 additions & 8 deletions emulator/MainWindow.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions emulator/Settings.cpp
Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions emulator/res/Resource.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file modified emulator/res/Resource.rc
Binary file not shown.
File renamed without changes.
File renamed without changes.

0 comments on commit 0cf99a4

Please sign in to comment.