Refactor ParallelPrinter.cpp/h as a C++ class (PR #1067)

Add command line:  -s1 parallel.
NB. Only a single Parallel Printer card is supported, and currently it's restricted to slot 1.
This commit is contained in:
TomCh 2022-03-18 22:04:34 +00:00 committed by GitHub
parent cbc0c2cf87
commit b4b29e1ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 282 additions and 191 deletions

View File

@ -43,7 +43,9 @@
Insert an Apple 16K Language Card into slot 0 in the original Apple II and use the F8 auto-start ROM.<br>
NB. The Apple II+ already defaults to having a Language Card, so this switch is not required.<br><br>
-s1 empty<br>
Remove the printer card from slot 1.<br><br>
Remove the parallel printer card from slot 1.<br><br>
-s1 parallel<br>
Insert a parallel printer card into slot 1.<br><br>
-s2 empty<br>
Remove the SSC card from slot 2.<br><br>
-s3 empty<br>

View File

@ -83,7 +83,7 @@ Apple II would not last six months.</p>
late and
suffered from poor backwards compatibility and a nearly 100%
hardware failure rate. Although Apple eventually addressed these
issues, they were not able overcome the Apple III's bad
issues, they were not able to overcome the Apple III's bad
reputation. Apple III sales remained poor, while sales of the
older Apple II continued to climb. </p>

View File

@ -69,9 +69,6 @@ void DummyCard::InitializeIO(LPBYTE pCxRomPeripheral)
{
switch (QueryType())
{
case CT_GenericPrinter:
PrintLoadRom(pCxRomPeripheral, m_slot);
break;
case CT_GenericClock:
break; // nothing to do
case CT_MockingboardC:
@ -92,9 +89,6 @@ void DummyCard::Update(const ULONG nExecutedCycles)
{
switch (QueryType())
{
case CT_GenericPrinter:
PrintUpdate(nExecutedCycles);
break;
case CT_MockingboardC:
case CT_Phasor:
// only in slot 4
@ -110,9 +104,6 @@ void DummyCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
{
switch (QueryType())
{
case CT_GenericPrinter:
Printer_SaveSnapshot(yamlSaveHelper, m_slot);
break;
case CT_MockingboardC:
MB_SaveSnapshot(yamlSaveHelper, m_slot);
break;
@ -129,8 +120,6 @@ bool DummyCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
switch (QueryType())
{
case CT_GenericPrinter:
return Printer_LoadSnapshot(yamlLoadHelper, m_slot, version);
case CT_MockingboardC:
return MB_LoadSnapshot(yamlLoadHelper, m_slot, version);
case CT_Phasor:
@ -163,7 +152,7 @@ std::string Card::GetCardName(const SS_CARDTYPE cardType)
case CT_MockingboardC:
return MB_GetSnapshotCardName();
case CT_GenericPrinter:
return Printer_GetSnapshotCardName();
return ParallelPrinterCard::GetSnapshotCardName();
case CT_GenericHDD:
return HarddiskInterfaceCard::GetSnapshotCardName();
case CT_GenericClock:
@ -195,7 +184,7 @@ std::string Card::GetCardName(const SS_CARDTYPE cardType)
SS_CARDTYPE Card::GetCardType(const std::string & card)
{
if (card == Printer_GetSnapshotCardName())
if (card == ParallelPrinterCard::GetSnapshotCardName())
{
return CT_GenericPrinter;
}

View File

@ -37,6 +37,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "FourPlay.h"
#include "Harddisk.h"
#include "MouseInterface.h"
#include "ParallelPrinter.h"
#include "SAM.h"
#include "SerialComms.h"
#include "SNESMAX.h"
@ -67,7 +68,9 @@ void CardManager::InsertInternal(UINT slot, SS_CARDTYPE type)
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_GenericPrinter:
m_slot[slot] = new DummyCard(type, slot);
_ASSERT(m_pParallelPrinterCard == NULL);
if (m_pParallelPrinterCard) break; // Only support one Printer card
m_slot[slot] = m_pParallelPrinterCard = new ParallelPrinterCard(slot);
break;
case CT_GenericHDD:
m_slot[slot] = new HarddiskInterfaceCard(slot);
@ -153,6 +156,9 @@ void CardManager::RemoveInternal(UINT slot)
case CT_SSC:
m_pSSC = NULL;
break;
case CT_GenericPrinter:
m_pParallelPrinterCard = NULL;
break;
case CT_LanguageCard:
case CT_Saturn128K:
case CT_LanguageCardIIe:

View File

@ -10,7 +10,8 @@ public:
CardManager(void) :
m_pMouseCard(NULL),
m_pSSC(NULL),
m_pLanguageCard(NULL)
m_pLanguageCard(NULL),
m_pParallelPrinterCard(NULL)
{
InsertInternal(SLOT0, CT_Empty);
InsertInternal(SLOT1, CT_GenericPrinter);
@ -54,6 +55,8 @@ public:
bool IsMouseCardInstalled(void) { return m_pMouseCard != NULL; }
class CSuperSerialCard* GetSSC(void) { return m_pSSC; }
bool IsSSCInstalled(void) { return m_pSSC != NULL; }
class ParallelPrinterCard* GetParallelPrinterCard(void) { return m_pParallelPrinterCard; }
bool IsParallelPrinterCardInstalled(void) { return m_pParallelPrinterCard != NULL; }
class LanguageCardUnit* GetLanguageCard(void) { return m_pLanguageCard; }
@ -75,4 +78,5 @@ private:
class CMouseInterface* m_pMouseCard;
class CSuperSerialCard* m_pSSC;
class LanguageCardUnit* m_pLanguageCard;
class ParallelPrinterCard* m_pParallelPrinterCard;
};

View File

@ -167,6 +167,13 @@ bool ProcessCmdLine(LPSTR lpCmdLine)
g_cmdLine.bSlotEmpty[slot] = true;
if (strcmp(lpCmdLine, "diskii") == 0)
g_cmdLine.slotInsert[slot] = CT_Disk2;
if (strcmp(lpCmdLine, "parallel") == 0)
{
if (slot == SLOT1)
g_cmdLine.slotInsert[slot] = CT_GenericPrinter;
else
LogFileOutput("Parallel Printer card currently only supported in slot 1\n");
}
if (strcmp(lpCmdLine, "vidhd") == 0)
{
if (slot == SLOT3)
@ -394,7 +401,7 @@ bool ProcessCmdLine(LPSTR lpCmdLine)
}
else if (strcmp(lpCmdLine, "-use-real-printer") == 0) // Enable control in Advanced config to allow dumping to a real printer
{
g_bEnableDumpToRealPrinter = true;
g_cmdLine.enableDumpToRealPrinter = true;
}
else if (strcmp(lpCmdLine, "-speech") == 0)
{

View File

@ -21,6 +21,7 @@ struct CmdLine
snesMaxAltControllerType[0] = false;
snesMaxAltControllerType[1] = false;
supportDCD = false;
enableDumpToRealPrinter = false;
szImageName_harddisk[HARDDISK_1] = NULL;
szImageName_harddisk[HARDDISK_2] = NULL;
szSnapshotName = NULL;
@ -61,6 +62,7 @@ struct CmdLine
bool bRemoveNoSlotClock;
bool snesMaxAltControllerType[2];
bool supportDCD;
bool enableDumpToRealPrinter;
SS_CARDTYPE slotInsert[NUM_SLOTS];
LPCSTR szImageName_drive[NUM_SLOTS][NUM_DRIVES];
bool driveConnected[NUM_SLOTS][NUM_DRIVES];

View File

@ -131,18 +131,33 @@ INT_PTR CPageAdvanced::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, L
SendDlgItemMessage(hWnd,IDC_SAVESTATE_FILENAME,WM_SETTEXT,0,(LPARAM)Snapshot_GetFilename().c_str());
CheckDlgButton(hWnd, IDC_SAVESTATE_ON_EXIT, g_bSaveStateOnExit ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_DUMPTOPRINTER, g_bDumpToPrinter ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_PRINTER_CONVERT_ENCODING, g_bConvertEncoding ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_PRINTER_FILTER_UNPRINTABLE, g_bFilterUnprintable ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_PRINTER_APPEND, g_bPrinterAppend ? BST_CHECKED : BST_UNCHECKED);
SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_SETRANGE, 0, MAKELONG(999,0));
SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_SETPOS, 0, MAKELONG(Printer_GetIdleLimit (),0));
SendDlgItemMessage(hWnd, IDC_PRINTER_DUMP_FILENAME, WM_SETTEXT, 0, (LPARAM)Printer_GetFilename().c_str());
InitOptions(hWnd);
if (GetCardMgr().IsParallelPrinterCardInstalled())
{
ParallelPrinterCard* card = GetCardMgr().GetParallelPrinterCard();
CheckDlgButton(hWnd, IDC_DUMPTOPRINTER, card->GetDumpToPrinter() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_PRINTER_CONVERT_ENCODING, card->GetConvertEncoding() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_PRINTER_FILTER_UNPRINTABLE, card->GetFilterUnprintable() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hWnd, IDC_PRINTER_APPEND, card->GetPrinterAppend() ? BST_CHECKED : BST_UNCHECKED);
SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_SETRANGE, 0, MAKELONG(999, 0));
SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_SETPOS, 0, MAKELONG(card->GetIdleLimit(), 0));
SendDlgItemMessage(hWnd, IDC_PRINTER_DUMP_FILENAME, WM_SETTEXT, 0, (LPARAM)card->GetFilename().c_str());
// Need to specify cmd-line switch: -printer-real to enable this control
EnableWindow(GetDlgItem(hWnd, IDC_DUMPTOPRINTER), g_bEnableDumpToRealPrinter ? TRUE : FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_DUMPTOPRINTER), card->GetEnableDumpToRealPrinter() ? TRUE : FALSE);
}
else
{
EnableWindow(GetDlgItem(hWnd, IDC_DUMPTOPRINTER), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_CONVERT_ENCODING), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_FILTER_UNPRINTABLE), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_APPEND), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_SPIN_PRINTER_IDLE), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_DUMP_FILENAME), FALSE);
}
InitOptions(hWnd);
break;
}
@ -160,6 +175,13 @@ void CPageAdvanced::DlgOK(HWND hWnd)
m_PropertySheetHelper.SaveStateUpdate();
}
g_bSaveStateOnExit = IsDlgButtonChecked(hWnd, IDC_SAVESTATE_ON_EXIT) ? true : false;
REGSAVE(TEXT(REGVALUE_SAVE_STATE_ON_EXIT), g_bSaveStateOnExit ? 1 : 0);
if (GetCardMgr().IsParallelPrinterCardInstalled())
{
ParallelPrinterCard* card = GetCardMgr().GetParallelPrinterCard();
// Update printer dump filename
{
char szFilename[MAX_PATH];
@ -173,29 +195,19 @@ void CPageAdvanced::DlgOK(HWND hWnd)
nLineLength = nLineLength > sizeof(szFilename) - 1 ? sizeof(szFilename) - 1 : nLineLength;
szFilename[nLineLength] = 0x00;
Printer_SetFilename(szFilename);
RegSaveString(TEXT(REG_CONFIG), REGVALUE_PRINTER_FILENAME, 1, Printer_GetFilename());
card->SetFilename(szFilename);
}
g_bSaveStateOnExit = IsDlgButtonChecked(hWnd, IDC_SAVESTATE_ON_EXIT) ? true : false;
REGSAVE(TEXT(REGVALUE_SAVE_STATE_ON_EXIT), g_bSaveStateOnExit ? 1 : 0);
card->SetDumpToPrinter(IsDlgButtonChecked(hWnd, IDC_DUMPTOPRINTER) ? true : false);
card->SetConvertEncoding(IsDlgButtonChecked(hWnd, IDC_PRINTER_CONVERT_ENCODING) ? true : false);
card->SetFilterUnprintable(IsDlgButtonChecked(hWnd, IDC_PRINTER_FILTER_UNPRINTABLE) ? true : false);
card->SetPrinterAppend(IsDlgButtonChecked(hWnd, IDC_PRINTER_APPEND) ? true : false);
g_bDumpToPrinter = IsDlgButtonChecked(hWnd, IDC_DUMPTOPRINTER ) ? true : false;
REGSAVE(TEXT(REGVALUE_DUMP_TO_PRINTER), g_bDumpToPrinter ? 1 : 0);
card->SetIdleLimit((short)SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE, UDM_GETPOS, 0, 0));
g_bConvertEncoding = IsDlgButtonChecked(hWnd, IDC_PRINTER_CONVERT_ENCODING ) ? true : false;
REGSAVE(TEXT(REGVALUE_CONVERT_ENCODING), g_bConvertEncoding ? 1 : 0);
g_bFilterUnprintable = IsDlgButtonChecked(hWnd, IDC_PRINTER_FILTER_UNPRINTABLE ) ? true : false;
REGSAVE(TEXT(REGVALUE_FILTER_UNPRINTABLE), g_bFilterUnprintable ? 1 : 0);
g_bPrinterAppend = IsDlgButtonChecked(hWnd, IDC_PRINTER_APPEND) ? true : false;
REGSAVE(TEXT(REGVALUE_PRINTER_APPEND), g_bPrinterAppend ? 1 : 0);
//
Printer_SetIdleLimit((short)SendDlgItemMessage(hWnd, IDC_SPIN_PRINTER_IDLE , UDM_GETPOS, 0, 0));
REGSAVE(TEXT(REGVALUE_PRINTER_IDLE_LIMIT),Printer_GetIdleLimit());
// Now save all the above to Registry
card->SetRegistryConfig();
}
m_PropertySheetHelper.PostMsgAfterClose(hWnd, m_Page);
}

View File

@ -38,90 +38,70 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "../resource/resource.h"
static DWORD inactivity = 0;
static unsigned int g_PrinterIdleLimit = 10;
static FILE* file = NULL;
DWORD const PRINTDRVR_SIZE = APPLE_SLOT_SIZE;
#define DEFAULT_PRINT_FILENAME "Printer.txt"
static std::string g_szPrintFilename;
bool g_bDumpToPrinter = false;
bool g_bConvertEncoding = true;
bool g_bFilterUnprintable = true;
bool g_bPrinterAppend = false;
bool g_bEnableDumpToRealPrinter = false;
//===========================================================================
static BYTE __stdcall PrintStatus(WORD, WORD, BYTE, BYTE, ULONG);
static BYTE __stdcall PrintTransmit(WORD, WORD, BYTE, BYTE value, ULONG);
VOID PrintLoadRom(LPBYTE pCxRomPeripheral, const UINT uSlot)
void ParallelPrinterCard::InitializeIO(LPBYTE pCxRomPeripheral)
{
const DWORD PRINTDRVR_SIZE = APPLE_SLOT_SIZE;
BYTE* pData = GetFrame().GetResource(IDR_PRINTDRVR_FW, "FIRMWARE", PRINTDRVR_SIZE);
if(pData == NULL)
return;
memcpy(pCxRomPeripheral + uSlot*256, pData, PRINTDRVR_SIZE);
memcpy(pCxRomPeripheral + m_slot*APPLE_SLOT_SIZE, pData, PRINTDRVR_SIZE);
//
RegisterIoHandler(uSlot, PrintStatus, PrintTransmit, NULL, NULL, NULL, NULL);
RegisterIoHandler(m_slot, IORead, IOWrite, NULL, NULL, this, NULL);
}
//===========================================================================
static BOOL CheckPrint()
bool ParallelPrinterCard::CheckPrint(void)
{
inactivity = 0;
if (file == NULL)
m_inactivity = 0;
if (m_file == NULL)
{
//TCHAR filepath[MAX_PATH * 2];
//_tcsncpy(filepath, g_sProgramDir, MAX_PATH);
//_tcsncat(filepath, _T("Printer.txt"), MAX_PATH);
//file = fopen(filepath, "wb");
if (g_bPrinterAppend )
file = fopen(Printer_GetFilename().c_str(), "ab");
if (m_bPrinterAppend )
m_file = fopen(ParallelPrinterCard::GetFilename().c_str(), "ab");
else
file = fopen(Printer_GetFilename().c_str(), "wb");
m_file = fopen(ParallelPrinterCard::GetFilename().c_str(), "wb");
}
return (file != NULL);
return (m_file != NULL);
}
//===========================================================================
static void ClosePrint()
void ParallelPrinterCard::ClosePrint(void)
{
if (file != NULL)
if (m_file != NULL)
{
fclose(file);
file = NULL;
fclose(m_file);
m_file = NULL;
std::string ExtendedFileName = "copy \"";
ExtendedFileName.append (Printer_GetFilename());
ExtendedFileName.append (ParallelPrinterCard::GetFilename());
ExtendedFileName.append ("\" prn");
//if (g_bDumpToPrinter) ShellExecute(NULL, "print", Printer_GetFilename(), NULL, NULL, 0); //Print through Notepad
if (g_bDumpToPrinter)
if (m_bDumpToPrinter)
system (ExtendedFileName.c_str ()); //Print through console. This is supposed to be the better way, because it shall print images (with older printers only).
}
inactivity = 0;
m_inactivity = 0;
}
//===========================================================================
void PrintDestroy()
void ParallelPrinterCard::Destroy(void)
{
ClosePrint();
}
//===========================================================================
void PrintUpdate(DWORD totalcycles)
{
if (file == NULL)
void ParallelPrinterCard::Update(const ULONG nExecutedCycles)
{
if (m_file == NULL)
return;
}
// if ((inactivity += totalcycles) > (Printer_GetIdleLimit () * 1000 * 1000)) //This line seems to give a very big deviation
if ((inactivity += totalcycles) > (Printer_GetIdleLimit () * 710000))
if ((m_inactivity += nExecutedCycles) > (ParallelPrinterCard::GetIdleLimit () * 710000))
{
// inactive, so close the file (next print will overwrite or append to it, according to the settings made)
ClosePrint();
@ -129,22 +109,28 @@ void PrintUpdate(DWORD totalcycles)
}
//===========================================================================
void PrintReset()
void ParallelPrinterCard::Reset(const bool powerCycle)
{
ClosePrint();
}
//===========================================================================
static BYTE __stdcall PrintStatus(WORD, WORD, BYTE, BYTE, ULONG)
BYTE __stdcall ParallelPrinterCard::IORead(WORD, WORD address, BYTE, BYTE, ULONG)
{
CheckPrint();
UINT slot = ((address & 0xff) >> 4) - 8;
ParallelPrinterCard* card = (ParallelPrinterCard*)MemGetSlotParameters(slot);
card->CheckPrint();
return 0xFF; // status - TODO?
}
//===========================================================================
static BYTE __stdcall PrintTransmit(WORD, WORD address, BYTE, BYTE value, ULONG)
BYTE __stdcall ParallelPrinterCard::IOWrite(WORD, WORD address, BYTE, BYTE value, ULONG)
{
if (!CheckPrint())
UINT slot = ((address & 0xff) >> 4) - 8;
ParallelPrinterCard* card = (ParallelPrinterCard*)MemGetSlotParameters(slot);
if (!card->CheckPrint())
return 0;
// only allow writes to the load output port (i.e., $C090)
@ -155,44 +141,85 @@ static BYTE __stdcall PrintTransmit(WORD, WORD address, BYTE, BYTE value, ULONG)
if (IsPravets(GetApple2Type()))
{
if (g_bConvertEncoding)
if (card->m_bConvertEncoding)
c = GetPravets().ConvertToPrinterChar(value);
}
if ((g_bFilterUnprintable == false) || (c>31) || (c==13) || (c==10) || (c>0x7F)) //c>0x7F is needed for cyrillic characters
fwrite(&c, 1, 1, file);
if ((card->m_bFilterUnprintable == false) || (c>31) || (c==13) || (c==10) || (c>0x7F)) //c>0x7F is needed for cyrillic characters
fwrite(&c, 1, 1, card->m_file);
return 0;
}
//===========================================================================
const std::string & Printer_GetFilename()
const std::string& ParallelPrinterCard::GetFilename(void)
{
return g_szPrintFilename;
return m_szPrintFilename;
}
void Printer_SetFilename(const std::string & prtFilename)
#define DEFAULT_PRINT_FILENAME "Printer.txt"
void ParallelPrinterCard::SetFilename(const std::string& prtFilename)
{
if (!prtFilename.empty())
{
g_szPrintFilename = prtFilename;
m_szPrintFilename = prtFilename;
}
else //No registry entry is available
{
g_szPrintFilename = g_sProgramDir + DEFAULT_PRINT_FILENAME;
RegSaveString(REG_CONFIG, REGVALUE_PRINTER_FILENAME, 1, g_szPrintFilename);
m_szPrintFilename = g_sProgramDir + DEFAULT_PRINT_FILENAME;
RegSaveString(REG_CONFIG, REGVALUE_PRINTER_FILENAME, 1, m_szPrintFilename);
}
}
unsigned int Printer_GetIdleLimit()
UINT ParallelPrinterCard::GetIdleLimit(void)
{
return g_PrinterIdleLimit;
return m_printerIdleLimit;
}
void Printer_SetIdleLimit(unsigned int Duration)
void ParallelPrinterCard::SetIdleLimit(UINT Duration)
{
g_PrinterIdleLimit = Duration;
m_printerIdleLimit = Duration;
}
//===========================================================================
void ParallelPrinterCard::GetRegistryConfig(void)
{
std::string regSection = RegGetConfigSlotSection(m_slot);
DWORD dwTmp;
char szFilename[MAX_PATH];
if (RegLoadValue(regSection.c_str(), REGVALUE_DUMP_TO_PRINTER, TRUE, &dwTmp))
SetDumpToPrinter(dwTmp ? true : false);
if (RegLoadValue(regSection.c_str(), REGVALUE_CONVERT_ENCODING, TRUE, &dwTmp))
SetConvertEncoding(dwTmp ? true : false);
if (RegLoadValue(regSection.c_str(), REGVALUE_FILTER_UNPRINTABLE, TRUE, &dwTmp))
SetFilterUnprintable(dwTmp ? true : false);
if (RegLoadValue(regSection.c_str(), REGVALUE_PRINTER_APPEND, TRUE, &dwTmp))
SetPrinterAppend(dwTmp ? true : false);
if (RegLoadString(regSection.c_str(), REGVALUE_PRINTER_FILENAME, 1, szFilename, MAX_PATH, TEXT("")))
SetFilename(szFilename);
if (RegLoadValue(regSection.c_str(), REGVALUE_PRINTER_IDLE_LIMIT, TRUE, &dwTmp))
SetIdleLimit(dwTmp);
}
void ParallelPrinterCard::SetRegistryConfig(void)
{
std::string regSection = RegGetConfigSlotSection(m_slot);
RegSaveValue(regSection.c_str(), REGVALUE_DUMP_TO_PRINTER, TRUE, GetDumpToPrinter() ? 1 : 0);
RegSaveValue(regSection.c_str(), REGVALUE_CONVERT_ENCODING, TRUE, GetConvertEncoding() ? 1 : 0);
RegSaveValue(regSection.c_str(), REGVALUE_FILTER_UNPRINTABLE, TRUE, GetFilterUnprintable() ? 1 : 0);
RegSaveValue(regSection.c_str(), REGVALUE_PRINTER_APPEND, TRUE, GetPrinterAppend() ? 1 : 0);
RegSaveString(regSection.c_str(), REGVALUE_PRINTER_FILENAME, TRUE, GetFilename());
RegSaveValue(regSection.c_str(), REGVALUE_PRINTER_IDLE_LIMIT, TRUE, GetIdleLimit());
}
//===========================================================================
@ -209,57 +236,57 @@ void Printer_SetIdleLimit(unsigned int Duration)
#define SS_YAML_KEY_APPEND "Printer Append"
#define SS_YAML_KEY_DUMPTOREALPRINTER "Enable Dump To Real Printer"
const std::string& Printer_GetSnapshotCardName(void)
const std::string& ParallelPrinterCard::GetSnapshotCardName(void)
{
static const std::string name(SS_YAML_VALUE_CARD_PRINTER);
return name;
}
void Printer_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot)
void ParallelPrinterCard::SaveSnapshot(class YamlSaveHelper& yamlSaveHelper)
{
YamlSaveHelper::Slot slot(yamlSaveHelper, Printer_GetSnapshotCardName(), uSlot, 1);
YamlSaveHelper::Slot slot(yamlSaveHelper, ParallelPrinterCard::GetSnapshotCardName(), m_slot, 1);
YamlSaveHelper::Label state(yamlSaveHelper, "%s:\n", SS_YAML_KEY_STATE);
yamlSaveHelper.SaveUint(SS_YAML_KEY_INACTIVITY, inactivity);
yamlSaveHelper.SaveUint(SS_YAML_KEY_IDLELIMIT, g_PrinterIdleLimit);
yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, g_szPrintFilename);
yamlSaveHelper.SaveBool(SS_YAML_KEY_FILEOPEN, (file != NULL) ? true : false);
yamlSaveHelper.SaveBool(SS_YAML_KEY_DUMPTOPRINTER, g_bDumpToPrinter);
yamlSaveHelper.SaveBool(SS_YAML_KEY_CONVERTENCODING, g_bConvertEncoding);
yamlSaveHelper.SaveBool(SS_YAML_KEY_FILTERUNPRINTABLE, g_bFilterUnprintable);
yamlSaveHelper.SaveBool(SS_YAML_KEY_APPEND, g_bPrinterAppend);
yamlSaveHelper.SaveBool(SS_YAML_KEY_DUMPTOREALPRINTER, g_bEnableDumpToRealPrinter);
yamlSaveHelper.SaveUint(SS_YAML_KEY_INACTIVITY, m_inactivity);
yamlSaveHelper.SaveUint(SS_YAML_KEY_IDLELIMIT, m_printerIdleLimit);
yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, m_szPrintFilename);
yamlSaveHelper.SaveBool(SS_YAML_KEY_FILEOPEN, (m_file != NULL) ? true : false);
yamlSaveHelper.SaveBool(SS_YAML_KEY_DUMPTOPRINTER, m_bDumpToPrinter);
yamlSaveHelper.SaveBool(SS_YAML_KEY_CONVERTENCODING, m_bConvertEncoding);
yamlSaveHelper.SaveBool(SS_YAML_KEY_FILTERUNPRINTABLE, m_bFilterUnprintable);
yamlSaveHelper.SaveBool(SS_YAML_KEY_APPEND, m_bPrinterAppend);
yamlSaveHelper.SaveBool(SS_YAML_KEY_DUMPTOREALPRINTER, m_bEnableDumpToRealPrinter);
}
bool Printer_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
bool ParallelPrinterCard::LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (slot != 1) // fixme
Card::ThrowErrorInvalidSlot(CT_GenericPrinter, slot);
if (m_slot != SLOT1) // fixme
Card::ThrowErrorInvalidSlot(CT_GenericPrinter, m_slot);
if (version != 1)
Card::ThrowErrorInvalidVersion(CT_GenericPrinter, version);
inactivity = yamlLoadHelper.LoadUint(SS_YAML_KEY_INACTIVITY);
g_PrinterIdleLimit = yamlLoadHelper.LoadUint(SS_YAML_KEY_IDLELIMIT);
g_szPrintFilename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME);
m_inactivity = yamlLoadHelper.LoadUint(SS_YAML_KEY_INACTIVITY);
m_printerIdleLimit = yamlLoadHelper.LoadUint(SS_YAML_KEY_IDLELIMIT);
m_szPrintFilename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME);
if (yamlLoadHelper.LoadBool(SS_YAML_KEY_FILEOPEN))
{
yamlLoadHelper.LoadBool(SS_YAML_KEY_APPEND); // Consume
g_bPrinterAppend = true; // Re-open print-file in append mode
m_bPrinterAppend = true; // Re-open print-file in append mode
BOOL bRes = CheckPrint();
if (!bRes)
throw std::runtime_error("Printer Card: Unable to resume printing to file");
}
else
{
g_bPrinterAppend = yamlLoadHelper.LoadBool(SS_YAML_KEY_APPEND);
m_bPrinterAppend = yamlLoadHelper.LoadBool(SS_YAML_KEY_APPEND);
}
g_bDumpToPrinter = yamlLoadHelper.LoadBool(SS_YAML_KEY_DUMPTOPRINTER);
g_bConvertEncoding = yamlLoadHelper.LoadBool(SS_YAML_KEY_CONVERTENCODING);
g_bFilterUnprintable = yamlLoadHelper.LoadBool(SS_YAML_KEY_FILTERUNPRINTABLE);
g_bEnableDumpToRealPrinter = yamlLoadHelper.LoadBool(SS_YAML_KEY_DUMPTOREALPRINTER);
m_bDumpToPrinter = yamlLoadHelper.LoadBool(SS_YAML_KEY_DUMPTOPRINTER);
m_bConvertEncoding = yamlLoadHelper.LoadBool(SS_YAML_KEY_CONVERTENCODING);
m_bFilterUnprintable = yamlLoadHelper.LoadBool(SS_YAML_KEY_FILTERUNPRINTABLE);
m_bEnableDumpToRealPrinter = yamlLoadHelper.LoadBool(SS_YAML_KEY_DUMPTOREALPRINTER);
return true;
}

View File

@ -1,20 +1,69 @@
#pragma once
void PrintDestroy();
void PrintLoadRom(LPBYTE pCxRomPeripheral, UINT uSlot);
void PrintReset();
void PrintUpdate(DWORD);
void Printer_SetFilename(const std::string & pszFilename);
const std::string & Printer_GetFilename();
void Printer_SetIdleLimit(unsigned int Duration);
unsigned int Printer_GetIdleLimit();
#include "Card.h"
#include "Memory.h"
const std::string& Printer_GetSnapshotCardName(void);
void Printer_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot);
bool Printer_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version);
class ParallelPrinterCard : public Card
{
public:
ParallelPrinterCard(UINT slot) :
Card(CT_GenericPrinter, slot)
{
m_inactivity = 0;
m_printerIdleLimit = 10;
m_file = NULL;
extern bool g_bDumpToPrinter;
extern bool g_bConvertEncoding;
extern bool g_bFilterUnprintable;
extern bool g_bPrinterAppend;
extern bool g_bEnableDumpToRealPrinter; // Set by cmd-line: -printer-real
m_bDumpToPrinter = false;
m_bConvertEncoding = false;
m_bFilterUnprintable = false;
m_bPrinterAppend = false;
m_bEnableDumpToRealPrinter = false;
}
virtual ~ParallelPrinterCard(void) {}
virtual void Destroy(void);
virtual void Reset(const bool powerCycle);
virtual void Update(const ULONG nExecutedCycles);
virtual void InitializeIO(LPBYTE pCxRomPeripheral);
static BYTE __stdcall IORead(WORD pc, WORD addr, BYTE bWrite, BYTE value, ULONG nExecutedCycles);
static BYTE __stdcall IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE value, ULONG nExecutedCycles);
static const std::string& GetSnapshotCardName(void);
virtual void SaveSnapshot(YamlSaveHelper& yamlSaveHelper);
virtual bool LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version);
const std::string& GetFilename(void);
void SetFilename(const std::string& prtFilename);
UINT GetIdleLimit(void);
void SetIdleLimit(UINT Duration);
bool GetDumpToPrinter(void) { return m_bDumpToPrinter; }
void SetDumpToPrinter(bool value) { m_bDumpToPrinter = value; }
bool GetConvertEncoding(void) { return m_bConvertEncoding; }
void SetConvertEncoding(bool value) { m_bConvertEncoding = value; }
bool GetFilterUnprintable(void) { return m_bFilterUnprintable; }
void SetFilterUnprintable(bool value) { m_bFilterUnprintable = value; }
bool GetPrinterAppend(void) { return m_bPrinterAppend; }
void SetPrinterAppend(bool value) { m_bPrinterAppend = value; }
bool GetEnableDumpToRealPrinter(void) { return m_bEnableDumpToRealPrinter; }
void SetEnableDumpToRealPrinter(bool value) { m_bEnableDumpToRealPrinter = value; }
void GetRegistryConfig(void);
void SetRegistryConfig(void);
private:
bool CheckPrint(void);
void ClosePrint(void);
DWORD m_inactivity;
UINT m_printerIdleLimit;
FILE* m_file;
std::string m_szPrintFilename;
bool m_bDumpToPrinter;
bool m_bConvertEncoding;
bool m_bFilterUnprintable;
bool m_bPrinterAppend;
bool m_bEnableDumpToRealPrinter; // Set by cmd-line: -printer-real
};

View File

@ -205,20 +205,6 @@ void LoadConfiguration(bool loadImages)
if(REGLOAD(TEXT(REGVALUE_SAVE_STATE_ON_EXIT), &dwTmp))
g_bSaveStateOnExit = dwTmp ? true : false;
if(REGLOAD(TEXT(REGVALUE_DUMP_TO_PRINTER), &dwTmp))
g_bDumpToPrinter = dwTmp ? true : false;
if(REGLOAD(TEXT(REGVALUE_CONVERT_ENCODING), &dwTmp))
g_bConvertEncoding = dwTmp ? true : false;
if(REGLOAD(TEXT(REGVALUE_FILTER_UNPRINTABLE), &dwTmp))
g_bFilterUnprintable = dwTmp ? true : false;
if(REGLOAD(TEXT(REGVALUE_PRINTER_APPEND), &dwTmp))
g_bPrinterAppend = dwTmp ? true : false;
if(REGLOAD(TEXT(REGVALUE_PDL_XTRIM), &dwTmp))
JoySetTrim((short)dwTmp, true);
if(REGLOAD(TEXT(REGVALUE_PDL_YTRIM), &dwTmp))
@ -326,11 +312,10 @@ void LoadConfiguration(bool loadImages)
//
RegLoadString(TEXT(REG_CONFIG), TEXT(REGVALUE_PRINTER_FILENAME), 1, szFilename, MAX_PATH, TEXT(""));
Printer_SetFilename(szFilename); // If not in Registry than default will be used
if (GetCardMgr().IsParallelPrinterCardInstalled())
GetCardMgr().GetParallelPrinterCard()->GetRegistryConfig();
REGLOAD_DEFAULT(TEXT(REGVALUE_PRINTER_IDLE_LIMIT), &dwTmp, 10);
Printer_SetIdleLimit(dwTmp);
//
if (REGLOAD(TEXT(REGVALUE_WINDOW_SCALE), &dwTmp))
GetFrame().SetViewportScale(dwTmp);
@ -543,7 +528,6 @@ void ResetMachineState()
dynamic_cast<Disk2InterfaceCard&>(GetCardMgr().GetRef(SLOT6)).Boot();
GetVideo().VideoResetState();
KeybReset();
PrintReset();
JoyReset();
MB_Reset(true);
SpkrReset();

View File

@ -750,6 +750,16 @@ static void RepeatInitialization(void)
GetCardMgr().GetSSC()->SupportDCD(true);
}
if (g_cmdLine.slotInsert[SLOT1] != CT_Empty && g_cmdLine.slotInsert[SLOT1] == CT_GenericPrinter) // For now just support Printer card in slot 1
{
GetCardMgr().Insert(SLOT1, g_cmdLine.slotInsert[SLOT1]);
}
if (g_cmdLine.enableDumpToRealPrinter && GetCardMgr().IsParallelPrinterCardInstalled())
{
GetCardMgr().GetParallelPrinterCard()->SetEnableDumpToRealPrinter(true);
}
if (g_cmdLine.slotInsert[SLOT3] != CT_Empty && g_cmdLine.slotInsert[SLOT3] == CT_VidHD) // For now just support VidHD in slot 3
{
GetCardMgr().Insert(SLOT3, g_cmdLine.slotInsert[SLOT3]);

View File

@ -967,7 +967,6 @@ LRESULT Win32Frame::WndProc(
if (!g_bRestart) {
GetCardMgr().Destroy();
}
PrintDestroy();
CpuDestroy();
MemDestroy();
SpkrDestroy();