MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / CommTransmit

Method CommTransmit

source/SerialComms.cpp:738–792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

736}
737
738BYTE __stdcall CSuperSerialCard::CommTransmit(WORD, WORD, BYTE, BYTE value, ULONG)
739{
740 if (!CheckComm())
741 return 0;
742
743 // If transmitter is disabled then: Is data just discarded or does it get transmitted if transmitter is later enabled?
744 if ((m_uCommandByte & CMD_TX_MASK) == CMD_TX_IRQ_DIS_RTS_HIGH) // Transmitter disable, so just discard for now
745 return 0;
746
747 if (m_hCommAcceptSocket != INVALID_SOCKET)
748 {
749 BYTE data = value;
750 if (m_uByteSize < 8)
751 {
752 data &= ~(1 << m_uByteSize);
753 }
754 int sent = send(m_hCommAcceptSocket, (const char*)&data, 1, 0);
755 _ASSERT(sent == 1);
756 if (sent == 1)
757 {
758 m_vbTxEmpty = false;
759 // Assume that send() completes immediately
760 TransmitDone();
761 }
762 }
763 else if (m_hCommHandle != INVALID_HANDLE_VALUE)
764 {
765 BOOL res = false;
766 DWORD error = 0;
767
768 // Use CriticalSection to keep WriteFile() & m_vbTxEmpty in sync (GH#707)
769 EnterCriticalSection(&m_CriticalSection);
770
771 _ASSERT(m_vbTxEmpty == true);
772 DWORD uBytesWritten;
773 res = WriteFile(m_hCommHandle, &value, 1, &uBytesWritten, &m_o);
774 _ASSERT(res);
775 if (res)
776 {
777 m_vbTxEmpty = false;
778 // NB. Now CommThread() determines when transmit buffer is empty and calls TransmitDone()
779 }
780 else
781 {
782 error = GetLastError();
783 }
784
785 LeaveCriticalSection(&m_CriticalSection);
786
787 if (!res)
788 LogFileOutput("SSC: CommTransmit(): WriteFile() failed: 0x%08X\n", error);
789 }
790
791 return 0;
792}
793
794//===========================================================================
795

Callers 1

SSC_IOWriteMethod · 0.80

Calls 1

LogFileOutputFunction · 0.85

Tested by

no test coverage detected