From 6063d8e96f4b7c8f7097a0caede7d56ae18550c9 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 18 Mar 2017 13:56:18 +0000 Subject: [PATCH] SSC: Experimental support for 6551's DTR via -dtr or -dtr-invert args (#386) --- source/Applewin.cpp | 8 ++++++++ source/SerialComms.cpp | 21 +++++++++++++++++---- source/SerialComms.h | 6 ++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 119e782a..c1d76cf6 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -1034,6 +1034,14 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { g_bMultiMon = true; } + else if (strcmp(lpCmdLine, "-dtr") == 0) // GH#386 + { + sg_SSC.SupportDTR(true, false); + } + else if (strcmp(lpCmdLine, "-dtr-invert") == 0) // GH#386 + { + sg_SSC.SupportDTR(true, true); + } else // unsupported { LogFileOutput("Unsupported arg: %s\n", lpCmdLine); diff --git a/source/SerialComms.cpp b/source/SerialComms.cpp index 5aa1f209..f45743f3 100644 --- a/source/SerialComms.cpp +++ b/source/SerialComms.cpp @@ -74,7 +74,9 @@ SSC_DIPSW CSuperSerialCard::m_DIPSWDefault = CSuperSerialCard::CSuperSerialCard() : m_aySerialPortChoices(NULL), m_uTCPChoiceItemIdx(0), - m_uSlot(0) + m_uSlot(0), + m_bCfgSupportDTR(false), // GH#386 - don't support by default until we have confirmed it works + m_bCfgInvertDTR(false) { memset(m_ayCurrentSerialPortName, 0, sizeof(m_ayCurrentSerialPortName)); m_dwSerialPortItem = 0; @@ -111,6 +113,8 @@ void CSuperSerialCard::InternalReset() m_qComSerialBuffer[0].clear(); m_qComSerialBuffer[1].clear(); m_qTcpSerialBuffer.clear(); + + m_uDTR = DTR_CONTROL_DISABLE; } CSuperSerialCard::~CSuperSerialCard() @@ -212,6 +216,7 @@ void CSuperSerialCard::UpdateCommState() dcb.ByteSize = m_uByteSize; dcb.Parity = m_uParity; dcb.StopBits = m_uStopBits; + dcb.fDtrControl = m_uDTR; SetCommState(m_hCommHandle,&dcb); } @@ -511,10 +516,18 @@ BYTE __stdcall CSuperSerialCard::CommCommand(WORD, WORD, BYTE write, BYTE value, // interrupt request disable [0=enable receiver interrupts] - NOTE: SSC docs get this wrong! m_bRxIrqEnabled = ((m_uCommandByte & 0x02) == 0); - if (m_uCommandByte & 0x01) // Data Terminal Ready (DTR) setting [0=set DTR high (indicates 'not ready')] + if (m_bCfgSupportDTR) // GH#386 { - // Note that, although the DTR is generally not used in the SSC (it may actually not - // be connected!), it must be set to 'low' in order for the 6551 to function correctly. + // Legacy comment - inaccurate? (see docs\SSC Memory Locations for Programmers.txt) + // . Note that, although the DTR is generally not used in the SSC (it may actually not be connected!), + // it must be set to 'low' in order for the 6551 to function correctly. + + // Data Terminal Ready (DTR) setting [0=set DTR high (indicates 'not ready')] + const bool bDTR_Ready = (m_uCommandByte & 0x01) ? true : false; + if (bDTR_Ready) + m_uDTR = !m_bCfgInvertDTR ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE; + else + m_uDTR = !m_bCfgInvertDTR ? DTR_CONTROL_DISABLE : DTR_CONTROL_ENABLE; } UpdateCommState(); diff --git a/source/SerialComms.h b/source/SerialComms.h index c86678d2..036486bb 100644 --- a/source/SerialComms.h +++ b/source/SerialComms.h @@ -43,6 +43,7 @@ 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 CommTcpSerialAccept(); void CommTcpSerialReceive(); @@ -139,4 +140,9 @@ private: BYTE* m_pExpansionRom; UINT m_uSlot; + + // DTR + UINT m_uDTR; + bool m_bCfgSupportDTR; + bool m_bCfgInvertDTR; };