2006-02-25 20:50:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
2007-05-28 11:16:42 +00:00
|
|
|
extern class CSuperSerialCard sg_SSC;
|
|
|
|
|
|
|
|
enum {COMMEVT_WAIT=0, COMMEVT_ACK, COMMEVT_TERM, COMMEVT_MAX};
|
|
|
|
enum eFWMODE {FWMODE_CIC=0, FWMODE_SIC_P8, FWMODE_PPC, FWMODE_SIC_P8A}; // NB. CIC = SSC
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
//DIPSW1
|
|
|
|
UINT uBaudRate;
|
|
|
|
eFWMODE eFirmwareMode;
|
|
|
|
|
|
|
|
//DIPSW2
|
|
|
|
UINT uStopBits;
|
|
|
|
UINT uByteSize;
|
|
|
|
UINT uParity;
|
|
|
|
bool bLinefeed;
|
|
|
|
bool bInterrupts;
|
|
|
|
} SSC_DIPSW;
|
|
|
|
|
2009-10-07 21:38:42 +00:00
|
|
|
#define TEXT_SERIAL_COM TEXT("COM")
|
|
|
|
#define TEXT_SERIAL_TCP TEXT("TCP")
|
|
|
|
|
2007-05-28 11:16:42 +00:00
|
|
|
class CSuperSerialCard
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSuperSerialCard();
|
2009-10-07 21:38:42 +00:00
|
|
|
virtual ~CSuperSerialCard();
|
2007-05-28 11:16:42 +00:00
|
|
|
|
|
|
|
void CommInitialize(LPBYTE pCxRomPeripheral, UINT uSlot);
|
|
|
|
void CommReset();
|
|
|
|
void CommDestroy();
|
2009-10-07 21:38:42 +00:00
|
|
|
void CommSetSerialPort(HWND hWindow, DWORD dwNewSerialPortItem);
|
2007-05-28 11:16:42 +00:00
|
|
|
void CommUpdate(DWORD);
|
2015-02-13 22:40:53 +00:00
|
|
|
void SetSnapshot_v1(const DWORD baudrate, const BYTE bytesize, const BYTE commandbyte, const DWORD comminactivity, const BYTE controlbyte, const BYTE parity, const BYTE stopbits);
|
2015-12-05 16:50:27 +00:00
|
|
|
std::string GetSnapshotCardName(void);
|
|
|
|
void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
|
|
|
|
bool LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version);
|
2007-05-28 11:16:42 +00:00
|
|
|
|
2009-10-07 21:38:42 +00:00
|
|
|
char* GetSerialPortChoices();
|
|
|
|
DWORD GetSerialPort() { return m_dwSerialPortItem; } // Drop-down list item
|
|
|
|
char* GetSerialPortName() { return m_ayCurrentSerialPortName; }
|
|
|
|
void SetSerialPortName(const char* pSerialPortName);
|
|
|
|
bool IsActive() { return (m_hCommHandle != INVALID_HANDLE_VALUE) || (m_hCommListenSocket != INVALID_SOCKET); }
|
2007-05-28 11:16:42 +00:00
|
|
|
|
2009-01-26 15:24:40 +00:00
|
|
|
void CommTcpSerialAccept();
|
|
|
|
void CommTcpSerialReceive();
|
|
|
|
void CommTcpSerialClose();
|
|
|
|
void CommTcpSerialCleanup();
|
|
|
|
|
2007-05-28 11:16:42 +00:00
|
|
|
static BYTE __stdcall SSC_IORead(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nCyclesLeft);
|
|
|
|
static BYTE __stdcall SSC_IOWrite(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nCyclesLeft);
|
|
|
|
|
|
|
|
private:
|
|
|
|
BYTE __stdcall CommCommand(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
|
|
|
|
BYTE __stdcall CommControl(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
|
|
|
|
BYTE __stdcall CommDipSw(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
|
|
|
|
BYTE __stdcall CommReceive(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
|
|
|
|
BYTE __stdcall CommStatus(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
|
|
|
|
BYTE __stdcall CommTransmit(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
|
|
|
|
|
2009-10-07 21:38:42 +00:00
|
|
|
void InternalReset();
|
2007-05-28 11:16:42 +00:00
|
|
|
void GetDIPSW();
|
|
|
|
void SetDIPSWDefaults();
|
|
|
|
BYTE GenerateControl();
|
|
|
|
UINT BaudRateToIndex(UINT uBaudRate);
|
|
|
|
void UpdateCommState();
|
|
|
|
BOOL CheckComm();
|
|
|
|
void CloseComm();
|
|
|
|
void CheckCommEvent(DWORD dwEvtMask);
|
|
|
|
static DWORD WINAPI CommThread(LPVOID lpParameter);
|
|
|
|
bool CommThInit();
|
|
|
|
void CommThUninit();
|
2009-10-07 21:38:42 +00:00
|
|
|
UINT GetNumSerialPortChoices() { return m_vecSerialPortsItems.size(); }
|
|
|
|
void ScanCOMPorts();
|
2015-12-05 16:50:27 +00:00
|
|
|
void SaveSnapshotDIPSW(class YamlSaveHelper& yamlSaveHelper, std::string key, SSC_DIPSW& dipsw);
|
|
|
|
void LoadSnapshotDIPSW(class YamlLoadHelper& yamlLoadHelper, std::string key, SSC_DIPSW& dipsw);
|
2007-05-28 11:16:42 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2009-10-07 21:38:42 +00:00
|
|
|
public:
|
|
|
|
static const UINT SIZEOF_SERIALCHOICE_ITEM = 8*sizeof(char);
|
|
|
|
|
2007-05-28 11:16:42 +00:00
|
|
|
private:
|
2009-10-07 21:38:42 +00:00
|
|
|
char m_ayCurrentSerialPortName[SIZEOF_SERIALCHOICE_ITEM];
|
|
|
|
DWORD m_dwSerialPortItem;
|
|
|
|
|
|
|
|
static const UINT SERIALPORTITEM_INVALID_COM_PORT = 0;
|
|
|
|
std::vector<UINT> m_vecSerialPortsItems; // Includes "None" & "TCP" items
|
|
|
|
char* m_aySerialPortChoices;
|
|
|
|
UINT m_uTCPChoiceItemIdx;
|
2007-05-28 11:16:42 +00:00
|
|
|
|
|
|
|
static SSC_DIPSW m_DIPSWDefault;
|
|
|
|
SSC_DIPSW m_DIPSWCurrent;
|
|
|
|
|
|
|
|
// Derived from DIPSW1
|
|
|
|
UINT m_uBaudRate;
|
|
|
|
|
|
|
|
// Derived from DIPSW2
|
|
|
|
UINT m_uStopBits;
|
|
|
|
UINT m_uByteSize;
|
|
|
|
UINT m_uParity;
|
|
|
|
|
|
|
|
// SSC Registers
|
|
|
|
BYTE m_uControlByte;
|
|
|
|
BYTE m_uCommandByte;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
HANDLE m_hCommHandle;
|
2009-01-26 15:24:40 +00:00
|
|
|
SOCKET m_hCommListenSocket;
|
|
|
|
SOCKET m_hCommAcceptSocket;
|
2007-05-28 11:16:42 +00:00
|
|
|
DWORD m_dwCommInactivity;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
CRITICAL_SECTION m_CriticalSection; // To guard /g_vRecvBytes/
|
2014-08-13 20:30:35 +00:00
|
|
|
std::deque<BYTE> m_qComSerialBuffer[2];
|
2009-10-07 21:38:42 +00:00
|
|
|
volatile UINT m_vuRxCurrBuffer; // Written to on COM recv. SSC reads from other one
|
2014-08-13 20:30:35 +00:00
|
|
|
std::deque<BYTE> m_qTcpSerialBuffer;
|
2007-05-28 11:16:42 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
bool m_bTxIrqEnabled;
|
|
|
|
bool m_bRxIrqEnabled;
|
|
|
|
|
2009-10-07 21:38:42 +00:00
|
|
|
volatile bool m_vbTxIrqPending;
|
|
|
|
volatile bool m_vbRxIrqPending;
|
|
|
|
|
2007-05-28 11:16:42 +00:00
|
|
|
bool m_bWrittenTx;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
HANDLE m_hCommThread;
|
|
|
|
|
|
|
|
HANDLE m_hCommEvent[COMMEVT_MAX];
|
|
|
|
OVERLAPPED m_o;
|
|
|
|
|
|
|
|
BYTE* m_pExpansionRom;
|
2015-02-13 22:40:53 +00:00
|
|
|
UINT m_uSlot;
|
2007-05-28 11:16:42 +00:00
|
|
|
};
|