From abd99d109e5319235294b486b268cf68c47a134b Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 19 Mar 2017 21:44:20 +0000 Subject: [PATCH] SSC: Experimental support for 6551's status bits: DCD and DSR via -dcd[-invert] and -dsr[-invert] args (#386) --- source/Applewin.cpp | 16 ++++++++++++++++ source/SerialComms.cpp | 36 +++++++++++++++++++++++++++--------- source/SerialComms.h | 12 +++++++++++- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index c1d76cf6..ff8e197d 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -1034,6 +1034,22 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { g_bMultiMon = true; } + else if (strcmp(lpCmdLine, "-dcd") == 0) // GH#386 + { + sg_SSC.SupportDCD(true, false); + } + else if (strcmp(lpCmdLine, "-dcd-invert") == 0) // GH#386 + { + sg_SSC.SupportDCD(true, true); + } + else if (strcmp(lpCmdLine, "-dsr") == 0) // GH#386 + { + sg_SSC.SupportDSR(true, false); + } + else if (strcmp(lpCmdLine, "-dsr-invert") == 0) // GH#386 + { + sg_SSC.SupportDSR(true, true); + } else if (strcmp(lpCmdLine, "-dtr") == 0) // GH#386 { sg_SSC.SupportDTR(true, false); diff --git a/source/SerialComms.cpp b/source/SerialComms.cpp index cc89be08..075c1c27 100644 --- a/source/SerialComms.cpp +++ b/source/SerialComms.cpp @@ -721,10 +721,12 @@ BYTE __stdcall CSuperSerialCard::CommStatus(WORD, WORD, BYTE, BYTE, ULONG) if (!CheckComm()) return ST_DSR | ST_DCD | ST_TX_EMPTY; -#ifdef SUPPORT_MODEM - DWORD modemstatus = 0; - GetCommModemStatus(m_hCommHandle,&modemstatus); // Returns 0x30 = MS_DSR_ON|MS_CTS_ON -#endif + DWORD modemStatus = 0; + if ((m_hCommHandle != INVALID_HANDLE_VALUE) && (m_bCfgSupportDCD || m_bCfgSupportDSR)) + { + // Do this outside of the critical section (don't know how long it takes) + GetCommModemStatus(m_hCommHandle, &modemStatus); // Returns 0x30 = MS_DSR_ON|MS_CTS_ON + } // @@ -757,13 +759,29 @@ BYTE __stdcall CSuperSerialCard::CommStatus(WORD, WORD, BYTE, BYTE, ULONG) // + BYTE DCD = 0; + BYTE DSR = 0; + + if ((m_hCommHandle != INVALID_HANDLE_VALUE) && (m_bCfgSupportDCD || m_bCfgSupportDSR)) + { + if (m_bCfgSupportDCD) + { + DCD = (modemStatus & MS_RLSD_ON) ? 0x00 : ST_DCD; + if (m_bCfgInvertDCD) DCD = (DCD == 0) ? ST_DCD : 0; + } + + if (m_bCfgSupportDSR) + { + DSR = (modemStatus & MS_DSR_ON) ? 0x00 : ST_DSR; + if (m_bCfgInvertDSR) DSR = (DSR == 0) ? ST_DSR : 0; + } + } + BYTE uStatus = ST_TX_EMPTY | ((!bComSerialBufferEmpty || !m_qTcpSerialBuffer.empty()) ? ST_RX_FULL : 0x00) -#ifdef SUPPORT_MODEM - | ((modemstatus & MS_RLSD_ON) ? 0x00 : ST_DCD) // Need 0x00 to allow ZLink to start up - | ((modemstatus & MS_DSR_ON) ? 0x00 : ST_DSR) -#endif - | (bIRQ ? ST_IRQ : 0x00); + | DCD // Need 0x00 to allow ZLink to start up + | DSR + | (bIRQ ? ST_IRQ : 0x00); if (m_hCommHandle != INVALID_HANDLE_VALUE) { diff --git a/source/SerialComms.h b/source/SerialComms.h index 036486bb..bfa06e8a 100644 --- a/source/SerialComms.h +++ b/source/SerialComms.h @@ -43,7 +43,9 @@ public: char* GetSerialPortName() { return m_ayCurrentSerialPortName; } void SetSerialPortName(const char* pSerialPortName); bool IsActive() { return (m_hCommHandle != INVALID_HANDLE_VALUE) || (m_hCommListenSocket != INVALID_SOCKET); } - void SupportDTR(bool bEnable, bool bInvert) { m_bCfgSupportDTR = bEnable; m_bCfgInvertDTR = bInvert; } + void SupportDCD(bool bEnable, bool bInvert) { m_bCfgSupportDCD = bEnable; m_bCfgInvertDCD = bInvert; } // Status + void SupportDSR(bool bEnable, bool bInvert) { m_bCfgSupportDSR = bEnable; m_bCfgInvertDSR = bInvert; } // Status + void SupportDTR(bool bEnable, bool bInvert) { m_bCfgSupportDTR = bEnable; m_bCfgInvertDTR = bInvert; } // Control void CommTcpSerialAccept(); void CommTcpSerialReceive(); @@ -141,6 +143,14 @@ private: BYTE* m_pExpansionRom; UINT m_uSlot; + // DCD + bool m_bCfgSupportDCD; + bool m_bCfgInvertDCD; + + // DSR + bool m_bCfgSupportDSR; + bool m_bCfgInvertDSR; + // DTR UINT m_uDTR; bool m_bCfgSupportDTR;