Added cmd line arg -rom <file> for 12KB & 16KB roms (#771)

This commit is contained in:
tomcw 2020-03-25 23:05:02 +00:00
parent c204783816
commit 3659603228
5 changed files with 77 additions and 5 deletions

View File

@ -109,8 +109,10 @@ int g_nMemoryClearType = MIP_FF_FF_00_00; // Note: -1 = random MIP in Memory.c
CardManager g_CardMgr;
IPropertySheet& sg_PropertySheet = * new CPropertySheet;
HANDLE g_hCustomRomF8 = INVALID_HANDLE_VALUE; // Cmd-line specified custom ROM at $F800..$FFFF
static bool g_bCustomRomF8Failed = false; // Set if custom ROM file failed
HANDLE g_hCustomRomF8 = INVALID_HANDLE_VALUE; // Cmd-line specified custom F8 ROM at $F800..$FFFF
static bool g_bCustomRomF8Failed = false; // Set if custom F8 ROM file failed
HANDLE g_hCustomRom = INVALID_HANDLE_VALUE; // Cmd-line specified custom ROM at $C000..$FFFF(16KiB) or $D000..$FFFF(12KiB)
static bool g_bCustomRomFailed = false; // Set if custom ROM file failed
static bool g_bEnableSpeech = false;
#ifdef USE_SPEECH_API
@ -1541,6 +1543,18 @@ static bool ProcessCmdLine(LPSTR lpCmdLine)
if ((g_hCustomRomF8 == INVALID_HANDLE_VALUE) || (GetFileSize(g_hCustomRomF8, NULL) != 0x800))
g_bCustomRomF8Failed = true;
}
else if (strcmp(lpCmdLine, "-rom") == 0) // Use custom 16K at [$C000..$FFFF] or 12K ROM at [$D000..$FFFF]
{
lpCmdLine = GetCurrArg(lpNextArg);
lpNextArg = GetNextArg(lpNextArg);
if (g_hCustomRom != INVALID_HANDLE_VALUE) // Stop resource leak if -rom is specified twice!
CloseHandle(g_hCustomRom);
g_hCustomRom = CreateFile(lpCmdLine, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
if ((g_hCustomRom == INVALID_HANDLE_VALUE) || ((GetFileSize(g_hCustomRom, NULL) != 0x4000) && (GetFileSize(g_hCustomRom, NULL) != 0x3000)))
g_bCustomRomFailed = true;
}
else if (strcmp(lpCmdLine, "-videorom") == 0) // Use 2K (for II/II+). Use 4K,8K or 16K video ROM (for Enhanced //e)
{
lpCmdLine = GetCurrArg(lpNextArg);
@ -1957,9 +1971,12 @@ static void RepeatInitialization(void)
g_cmdLine.bShutdown = true;
}
if (g_bCustomRomF8Failed)
if (g_bCustomRomF8Failed || g_bCustomRomFailed || (g_hCustomRomF8 != INVALID_HANDLE_VALUE && g_hCustomRom != INVALID_HANDLE_VALUE))
{
std::string msg = "Failed to load custom F8 rom (not found or not exactly 2KiB)\n";
std::string msg = g_bCustomRomF8Failed ? "Failed to load custom F8 rom (not found or not exactly 2KiB)\n"
: g_bCustomRomFailed ? "Failed to load custom rom (not found or not exactly 12KiB or 16KiB)\n"
: "Unsupported -rom and -f8rom being used at the same time\n";
LogFileOutput("%s", msg.c_str());
MessageBox(g_hFrameWindow, msg.c_str(), TEXT("AppleWin Error"), MB_OK);
g_cmdLine.bShutdown = true;
@ -2064,6 +2081,9 @@ static void Shutdown(void)
if (g_hCustomRomF8 != INVALID_HANDLE_VALUE)
CloseHandle(g_hCustomRomF8);
if (g_hCustomRom != INVALID_HANDLE_VALUE)
CloseHandle(g_hCustomRom);
if (g_cmdLine.bSlot7EmptyOnExit)
UnplugHardDiskControllerCard();
}

View File

@ -54,7 +54,8 @@ extern int g_nMemoryClearType; // Cmd line switch: use specific MIP (
extern class CardManager g_CardMgr;
extern HANDLE g_hCustomRomF8; // NULL if no custom rom
extern HANDLE g_hCustomRomF8; // INVALID_HANDLE_VALUE if no custom F8 rom
extern HANDLE g_hCustomRom; // INVALID_HANDLE_VALUE if no custom rom
#ifdef USE_SPEECH_API
class CSpeech;

View File

@ -1491,6 +1491,7 @@ void MemInitialize()
CreateLanguageCard();
MemInitializeROM();
MemInitializeCustomROM();
MemInitializeCustomF8ROM();
MemInitializeIO();
MemReset();
@ -1645,6 +1646,54 @@ void MemInitializeCustomF8ROM(void)
}
}
void MemInitializeCustomROM(void)
{
if (g_hCustomRom == INVALID_HANDLE_VALUE)
return;
std::vector<BYTE> oldRom;
oldRom.resize(Apple2RomSize);
memcpy(&oldRom[0], memrom, Apple2RomSize);
std::vector<BYTE> oldRomC0;
oldRomC0.resize(CxRomSize);
memcpy(&oldRomC0[0], pCxRomInternal, CxRomSize);
SetFilePointer(g_hCustomRom, 0, NULL, FILE_BEGIN);
DWORD uNumBytesRead;
BOOL bRes = TRUE;
if (GetFileSize(g_hCustomRom, NULL) == Apple2eRomSize)
{
bRes = ReadFile(g_hCustomRom, pCxRomInternal, CxRomSize, &uNumBytesRead, NULL);
if (uNumBytesRead != CxRomSize)
{
memcpy(pCxRomInternal, &oldRomC0[0], CxRomSize); // ROM at $C000...$CFFF
bRes = FALSE;
}
}
if (bRes)
{
bRes = ReadFile(g_hCustomRom, memrom, Apple2RomSize, &uNumBytesRead, NULL);
if (uNumBytesRead != Apple2RomSize)
{
memcpy(memrom, &oldRom[0], Apple2RomSize); // ROM at $D000...$FFFF
bRes = FALSE;
}
}
// NB. If succeeded, then keep g_hCustomRom handle open - so that any next restart can load it again
if (!bRes)
{
MessageBox( g_hFrameWindow, "Failed to read custom rom", TEXT("AppleWin Error"), MB_OK );
CloseHandle(g_hCustomRom);
g_hCustomRom = INVALID_HANDLE_VALUE;
// Failed, so use default rom...
}
}
// Called by:
// . MemInitialize()
// . Snapshot_LoadState_v2()

View File

@ -71,6 +71,7 @@ bool MemOptimizeForModeChanging(WORD programcounter, WORD address);
bool MemIsAddrCodeMemory(const USHORT addr);
void MemInitialize ();
void MemInitializeROM(void);
void MemInitializeCustomROM(void);
void MemInitializeCustomF8ROM(void);
void MemInitializeIO(void);
void MemInitializeCardExpansionRomFromSnapshot(void);

View File

@ -448,6 +448,7 @@ static void Snapshot_LoadState_v2(void)
sg_PropertySheet.ApplyNewConfig(m_ConfigNew, ConfigOld); // Mainly just saves (some) new state to Registry
MemInitializeROM();
MemInitializeCustomROM();
MemInitializeCustomF8ROM();
MemInitializeIO();
MemInitializeCardExpansionRomFromSnapshot();