From cd06ae69eb43405659c65b081da1b00df0e892d4 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Thu, 30 Jul 2020 17:50:34 -0230 Subject: [PATCH] Add SerialPort::isCTS() to all ports, and connect it to AtariVox. --- src/emucore/AtariVox.cxx | 5 +++-- src/macos/SerialPortMACOS.cxx | 12 ++++++++++++ src/macos/SerialPortMACOS.hxx | 7 +++++++ src/unix/SerialPortUNIX.cxx | 15 +++++++++++++++ src/unix/SerialPortUNIX.hxx | 7 +++++++ src/windows/SerialPortWINDOWS.cxx | 12 ++++++++++++ src/windows/SerialPortWINDOWS.hxx | 8 ++++++++ src/windows/Stella.vcxproj | 1 + src/windows/Stella.vcxproj.filters | 3 +++ 9 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/emucore/AtariVox.cxx b/src/emucore/AtariVox.cxx index 994b494cf..fd75024e4 100644 --- a/src/emucore/AtariVox.cxx +++ b/src/emucore/AtariVox.cxx @@ -50,10 +50,11 @@ bool AtariVox::read(DigitalPin pin) switch(pin) { // Pin 2: SpeakJet READY - // CTS enabled means the SpeakJet can accept more data + // CTS (Clear To Send) is connected inverted + // So CTS = 0 means the buffer is full, which pulls pin 2 high case DigitalPin::Two: { - return setPin(pin, mySerialPort->isCTS()); + return setPin(pin, !mySerialPort->isCTS()); } default: diff --git a/src/macos/SerialPortMACOS.cxx b/src/macos/SerialPortMACOS.cxx index 90235e0a8..9745eceff 100644 --- a/src/macos/SerialPortMACOS.cxx +++ b/src/macos/SerialPortMACOS.cxx @@ -73,3 +73,15 @@ bool SerialPortMACOS::writeByte(uInt8 data) } return false; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SerialPortMACOS::isCTS() +{ + if(myHandle) + { + int status = 0; + ioctl(myHandle, TIOCMGET, &status); + return status & TIOCM_CTS; + } + return false; +} diff --git a/src/macos/SerialPortMACOS.hxx b/src/macos/SerialPortMACOS.hxx index 0c83e5045..3d71d5135 100644 --- a/src/macos/SerialPortMACOS.hxx +++ b/src/macos/SerialPortMACOS.hxx @@ -48,6 +48,13 @@ class SerialPortMACOS : public SerialPort */ bool writeByte(uInt8 data) override; + /** + Test for 'Clear To Send' enabled. + + @return True if CTS signal enabled, else false + */ + bool isCTS() override; + private: // File descriptor for serial connection int myHandle{0}; diff --git a/src/unix/SerialPortUNIX.cxx b/src/unix/SerialPortUNIX.cxx index f114e18fe..1105d2092 100644 --- a/src/unix/SerialPortUNIX.cxx +++ b/src/unix/SerialPortUNIX.cxx @@ -49,6 +49,9 @@ bool SerialPortUNIX::openPort(const string& device) if(myHandle <= 0) return false; + // Open the device in nonblocking mode + fcntl(myHandle, F_SETFL, FNDELAY); + struct termios termios; memset(&termios, 0, sizeof(struct termios)); @@ -71,3 +74,15 @@ bool SerialPortUNIX::writeByte(uInt8 data) } return false; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SerialPortUNIX::isCTS() +{ + if(myHandle) + { + int status = 0; + ioctl(myHandle, TIOCMGET, &status); + return status & TIOCM_CTS; + } + return false; +} diff --git a/src/unix/SerialPortUNIX.hxx b/src/unix/SerialPortUNIX.hxx index b46d0a64a..7a675298e 100644 --- a/src/unix/SerialPortUNIX.hxx +++ b/src/unix/SerialPortUNIX.hxx @@ -48,6 +48,13 @@ class SerialPortUNIX : public SerialPort */ bool writeByte(uInt8 data) override; + /** + Test for 'Clear To Send' enabled. + + @return True if CTS signal enabled, else false + */ + bool isCTS() override; + private: // File descriptor for serial connection int myHandle{0}; diff --git a/src/windows/SerialPortWINDOWS.cxx b/src/windows/SerialPortWINDOWS.cxx index 51ed73247..91b6c0bb3 100644 --- a/src/windows/SerialPortWINDOWS.cxx +++ b/src/windows/SerialPortWINDOWS.cxx @@ -79,3 +79,15 @@ bool SerialPortWINDOWS::writeByte(uInt8 data) } return false; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SerialPortWINDOWS::isCTS() +{ + if(myHandle) + { + DWORD modemStat; + GetCommModemStatus(myHandle, &modemStat); + return modemStat & MS_CTS_ON; + } + return false; +} diff --git a/src/windows/SerialPortWINDOWS.hxx b/src/windows/SerialPortWINDOWS.hxx index 8c0ed789c..3f8513573 100644 --- a/src/windows/SerialPortWINDOWS.hxx +++ b/src/windows/SerialPortWINDOWS.hxx @@ -47,6 +47,14 @@ class SerialPortWINDOWS : public SerialPort */ bool writeByte(uInt8 data) override; + /** + Test for 'Clear To Send' enabled. By default, assume it's always + OK to send more data. + + @return True if CTS signal enabled, else false + */ + bool isCTS() override; + private: // Handle to serial port HANDLE myHandle{0}; diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index c6ba9d7ff..52a8c4327 100644 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -1774,6 +1774,7 @@ + diff --git a/src/windows/Stella.vcxproj.filters b/src/windows/Stella.vcxproj.filters index 215e9eeab..5875efb8c 100644 --- a/src/windows/Stella.vcxproj.filters +++ b/src/windows/Stella.vcxproj.filters @@ -2087,6 +2087,9 @@ Header Files\gui + + Header Files\emucore +