Apply K&R brace style to drv/ and README examples
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e25428bb8b
commit
e45d72588a
3 changed files with 51 additions and 103 deletions
117
drv/commdrv.c
117
drv/commdrv.c
|
|
@ -16,14 +16,12 @@
|
||||||
#define DBG_ENABLED 0
|
#define DBG_ENABLED 0
|
||||||
|
|
||||||
#if DBG_ENABLED
|
#if DBG_ENABLED
|
||||||
static void dbgStr(const char FAR *msg)
|
static void dbgStr(const char FAR *msg) {
|
||||||
{
|
|
||||||
OutputDebugString(msg);
|
OutputDebugString(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log a label and a 16-bit hex value: "label: 0xNNNN\r\n"
|
// Log a label and a 16-bit hex value: "label: 0xNNNN\r\n"
|
||||||
static void dbgHex16(const char FAR *label, uint16_t val)
|
static void dbgHex16(const char FAR *label, uint16_t val) {
|
||||||
{
|
|
||||||
static const char hex[] = "0123456789ABCDEF";
|
static const char hex[] = "0123456789ABCDEF";
|
||||||
char buf[48];
|
char buf[48];
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -46,8 +44,7 @@ static void dbgHex16(const char FAR *label, uint16_t val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log a label and a signed 16-bit value: "label: -NNNN\r\n"
|
// Log a label and a signed 16-bit value: "label: -NNNN\r\n"
|
||||||
static void dbgInt16(const char FAR *label, int16_t val)
|
static void dbgInt16(const char FAR *label, int16_t val) {
|
||||||
{
|
|
||||||
char buf[48];
|
char buf[48];
|
||||||
int i;
|
int i;
|
||||||
uint16_t uv;
|
uint16_t uv;
|
||||||
|
|
@ -85,8 +82,7 @@ static void dbgInt16(const char FAR *label, int16_t val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log a FAR pointer as "label: SSSS:OOOO\r\n"
|
// Log a FAR pointer as "label: SSSS:OOOO\r\n"
|
||||||
static void dbgFarPtr(const char FAR *label, void FAR *ptr)
|
static void dbgFarPtr(const char FAR *label, void FAR *ptr) {
|
||||||
{
|
|
||||||
static const char hex[] = "0123456789ABCDEF";
|
static const char hex[] = "0123456789ABCDEF";
|
||||||
char buf[48];
|
char buf[48];
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -117,8 +113,7 @@ static void dbgFarPtr(const char FAR *label, void FAR *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hex dump first 'count' bytes at a FAR pointer
|
// Hex dump first 'count' bytes at a FAR pointer
|
||||||
static void dbgDump(const char FAR *label, void FAR *ptr, int count)
|
static void dbgDump(const char FAR *label, void FAR *ptr, int count) {
|
||||||
{
|
|
||||||
static const char hex[] = "0123456789ABCDEF";
|
static const char hex[] = "0123456789ABCDEF";
|
||||||
char buf[80];
|
char buf[80];
|
||||||
uint8_t FAR *p;
|
uint8_t FAR *p;
|
||||||
|
|
@ -227,8 +222,7 @@ volatile uint16_t isrHitCount = 0;
|
||||||
// 115200, CBR_* index constants (0xFF00+) encode the rate. We detect
|
// 115200, CBR_* index constants (0xFF00+) encode the rate. We detect
|
||||||
// these and translate via cbrToBaud().
|
// these and translate via cbrToBaud().
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void applyBaudRate(PortStateT *port, uint16_t baud)
|
void applyBaudRate(PortStateT *port, uint16_t baud) {
|
||||||
{
|
|
||||||
uint32_t actualBaud;
|
uint32_t actualBaud;
|
||||||
uint16_t divisor;
|
uint16_t divisor;
|
||||||
uint8_t lcr;
|
uint8_t lcr;
|
||||||
|
|
@ -276,8 +270,7 @@ void applyBaudRate(PortStateT *port, uint16_t baud)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// applyLineParams - Set word length, parity, and stop bits on UART
|
// applyLineParams - Set word length, parity, and stop bits on UART
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void applyLineParams(PortStateT *port, uint8_t byteSize, uint8_t parity, uint8_t stopBits)
|
void applyLineParams(PortStateT *port, uint8_t byteSize, uint8_t parity, uint8_t stopBits) {
|
||||||
{
|
|
||||||
uint8_t lcr;
|
uint8_t lcr;
|
||||||
uint16_t base;
|
uint16_t base;
|
||||||
|
|
||||||
|
|
@ -334,8 +327,7 @@ void applyLineParams(PortStateT *port, uint8_t byteSize, uint8_t parity, uint8_t
|
||||||
// Returns baud rate as uint32_t (needed for 115200 which exceeds 16 bits).
|
// Returns baud rate as uint32_t (needed for 115200 which exceeds 16 bits).
|
||||||
// Returns 0 for unrecognized constants.
|
// Returns 0 for unrecognized constants.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static uint32_t cbrToBaud(uint16_t cbr)
|
static uint32_t cbrToBaud(uint16_t cbr) {
|
||||||
{
|
|
||||||
switch (cbr) {
|
switch (cbr) {
|
||||||
case CBR_110:
|
case CBR_110:
|
||||||
return 110UL;
|
return 110UL;
|
||||||
|
|
@ -370,8 +362,7 @@ static uint32_t cbrToBaud(uint16_t cbr)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// cclrbrk - Clear break signal (ordinal 14)
|
// cclrbrk - Clear break signal (ordinal 14)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export cclrbrk(int16_t commId)
|
int16_t FAR PASCAL _export cclrbrk(int16_t commId) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint8_t lcr;
|
uint8_t lcr;
|
||||||
|
|
||||||
|
|
@ -401,8 +392,7 @@ int16_t FAR PASCAL _export cclrbrk(int16_t commId)
|
||||||
// This matches the stock COMM.DRV behavior -- the event word is a
|
// This matches the stock COMM.DRV behavior -- the event word is a
|
||||||
// volatile uint16_t that accumulates event bits until cleared.
|
// volatile uint16_t that accumulates event bits until cleared.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int32_t FAR PASCAL _export cevt(int16_t commId, int16_t evtMask)
|
int32_t FAR PASCAL _export cevt(int16_t commId, int16_t evtMask) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint16_t FAR *ptr;
|
uint16_t FAR *ptr;
|
||||||
int32_t retVal;
|
int32_t retVal;
|
||||||
|
|
@ -448,8 +438,7 @@ int32_t FAR PASCAL _export cevt(int16_t commId, int16_t evtMask)
|
||||||
//
|
//
|
||||||
// Returns current event bits masked by evtMask, then clears those bits.
|
// Returns current event bits masked by evtMask, then clears those bits.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
uint16_t FAR PASCAL _export cevtget(int16_t commId, int16_t evtMask)
|
uint16_t FAR PASCAL _export cevtget(int16_t commId, int16_t evtMask) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint16_t events;
|
uint16_t events;
|
||||||
|
|
||||||
|
|
@ -478,8 +467,7 @@ uint16_t FAR PASCAL _export cevtget(int16_t commId, int16_t evtMask)
|
||||||
//
|
//
|
||||||
// Note: 16-bit API returns 0 on success (unlike Win32 nonzero=success).
|
// Note: 16-bit API returns 0 on success (unlike Win32 nonzero=success).
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export cextfcn(int16_t commId, int16_t func)
|
int16_t FAR PASCAL _export cextfcn(int16_t commId, int16_t func) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint8_t mcr;
|
uint8_t mcr;
|
||||||
uint16_t base;
|
uint16_t base;
|
||||||
|
|
@ -548,8 +536,7 @@ int16_t FAR PASCAL _export cextfcn(int16_t commId, int16_t func)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// cflush - Flush receive or transmit buffer (ordinal 10)
|
// cflush - Flush receive or transmit buffer (ordinal 10)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export cflush(int16_t commId, int16_t queue)
|
int16_t FAR PASCAL _export cflush(int16_t commId, int16_t queue) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
dbgInt16("KPCOMM: cflush Id", commId);
|
dbgInt16("KPCOMM: cflush Id", commId);
|
||||||
|
|
@ -595,8 +582,7 @@ int16_t FAR PASCAL _export cflush(int16_t commId, int16_t queue)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// commWriteString - Write data (ordinal 19, alias for sndcom)
|
// commWriteString - Write data (ordinal 19, alias for sndcom)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export commWriteString(int16_t commId, void FAR *buf, int16_t len)
|
int16_t FAR PASCAL _export commWriteString(int16_t commId, void FAR *buf, int16_t len) {
|
||||||
{
|
|
||||||
dbgInt16("KPCOMM: commWriteStr Id", commId);
|
dbgInt16("KPCOMM: commWriteStr Id", commId);
|
||||||
return sndcom(commId, buf, len);
|
return sndcom(commId, buf, len);
|
||||||
}
|
}
|
||||||
|
|
@ -610,8 +596,7 @@ int16_t FAR PASCAL _export commWriteString(int16_t commId, void FAR *buf, int16_
|
||||||
// USER.EXE. CyberCom's implementation uses plain RETF (no params).
|
// USER.EXE. CyberCom's implementation uses plain RETF (no params).
|
||||||
// Return 0 (not handled).
|
// Return 0 (not handled).
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int FAR PASCAL _export commNotifyWndProc(void)
|
int FAR PASCAL _export commNotifyWndProc(void) {
|
||||||
{
|
|
||||||
dbgStr("KPCOMM: ord101 called\r\n");
|
dbgStr("KPCOMM: ord101 called\r\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -620,8 +605,7 @@ int FAR PASCAL _export commNotifyWndProc(void)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// csetbrk - Assert break signal (ordinal 13)
|
// csetbrk - Assert break signal (ordinal 13)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export csetbrk(int16_t commId)
|
int16_t FAR PASCAL _export csetbrk(int16_t commId) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint8_t lcr;
|
uint8_t lcr;
|
||||||
|
|
||||||
|
|
@ -647,8 +631,7 @@ int16_t FAR PASCAL _export csetbrk(int16_t commId)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// ctx - Send single character with priority (ordinal 6)
|
// ctx - Send single character with priority (ordinal 6)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export ctx(int16_t commId, int16_t ch)
|
int16_t FAR PASCAL _export ctx(int16_t commId, int16_t ch) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
dbgInt16("KPCOMM: ctx Id", commId);
|
dbgInt16("KPCOMM: ctx Id", commId);
|
||||||
|
|
@ -677,8 +660,7 @@ int16_t FAR PASCAL _export ctx(int16_t commId, int16_t ch)
|
||||||
//
|
//
|
||||||
// Returns 1 if 16550A (working FIFO), 0 otherwise.
|
// Returns 1 if 16550A (working FIFO), 0 otherwise.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t detect16550(uint16_t baseAddr)
|
int16_t detect16550(uint16_t baseAddr) {
|
||||||
{
|
|
||||||
uint8_t iir;
|
uint8_t iir;
|
||||||
|
|
||||||
// Try to enable FIFOs
|
// Try to enable FIFOs
|
||||||
|
|
@ -702,8 +684,7 @@ int16_t detect16550(uint16_t baseAddr)
|
||||||
// Uses port->fifoTrigger (set from SYSTEM.INI COMnRxTRIGGER, default 8).
|
// Uses port->fifoTrigger (set from SYSTEM.INI COMnRxTRIGGER, default 8).
|
||||||
// Respects port->fifoEnabled (set from SYSTEM.INI COMnFIFO, default 1).
|
// Respects port->fifoEnabled (set from SYSTEM.INI COMnFIFO, default 1).
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void enableFifo(PortStateT *port)
|
void enableFifo(PortStateT *port) {
|
||||||
{
|
|
||||||
if (!port->is16550 || !port->fifoEnabled) {
|
if (!port->is16550 || !port->fifoEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -719,8 +700,7 @@ void enableFifo(PortStateT *port)
|
||||||
// Retained as a no-op stub for API compatibility. Stores threshold
|
// Retained as a no-op stub for API compatibility. Stores threshold
|
||||||
// values but nothing reads them -- polling replaces notifications.
|
// values but nothing reads them -- polling replaces notifications.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export enableNotification(int16_t commId, HWND hwnd, int16_t rxThresh, int16_t txThresh)
|
int16_t FAR PASCAL _export enableNotification(int16_t commId, HWND hwnd, int16_t rxThresh, int16_t txThresh) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
if (commId < 0 || commId >= MAX_PORTS) {
|
if (commId < 0 || commId >= MAX_PORTS) {
|
||||||
|
|
@ -743,8 +723,7 @@ int16_t FAR PASCAL _export enableNotification(int16_t commId, HWND hwnd, int16_t
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// freeBuffers - Free ring buffers for a port
|
// freeBuffers - Free ring buffers for a port
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void freeBuffers(PortStateT *port)
|
static void freeBuffers(PortStateT *port) {
|
||||||
{
|
|
||||||
if (port->rxBufH) {
|
if (port->rxBufH) {
|
||||||
GlobalUnlock(port->rxBufH);
|
GlobalUnlock(port->rxBufH);
|
||||||
GlobalFree(port->rxBufH);
|
GlobalFree(port->rxBufH);
|
||||||
|
|
@ -768,8 +747,7 @@ static void freeBuffers(PortStateT *port)
|
||||||
// The caller (USER.EXE / COMMTASK.DLL) copies from this pointer.
|
// The caller (USER.EXE / COMMTASK.DLL) copies from this pointer.
|
||||||
// CyberCom confirms: RETF 2, return pointer.
|
// CyberCom confirms: RETF 2, return pointer.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
DCB FAR * FAR PASCAL _export getdcb(int16_t commId)
|
DCB FAR * FAR PASCAL _export getdcb(int16_t commId) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
dbgInt16("KPCOMM: getdcb Id", commId);
|
dbgInt16("KPCOMM: getdcb Id", commId);
|
||||||
|
|
@ -801,8 +779,7 @@ DCB FAR * FAR PASCAL _export getdcb(int16_t commId)
|
||||||
//
|
//
|
||||||
// Returns commId (0-3) on success, negative error code on failure.
|
// Returns commId (0-3) on success, negative error code on failure.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export inicom(DCB FAR *dcb)
|
int16_t FAR PASCAL _export inicom(DCB FAR *dcb) {
|
||||||
{
|
|
||||||
int16_t commId;
|
int16_t commId;
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint16_t rxBufSize;
|
uint16_t rxBufSize;
|
||||||
|
|
@ -966,8 +943,7 @@ int16_t FAR PASCAL _export inicom(DCB FAR *dcb)
|
||||||
// without requiring GlobalLock. Saves handles in PortStateT for
|
// without requiring GlobalLock. Saves handles in PortStateT for
|
||||||
// clean freeing (no GlobalHandle recovery hack).
|
// clean freeing (no GlobalHandle recovery hack).
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static int16_t initBuffers(PortStateT *port, uint16_t rxSz, uint16_t txSz)
|
static int16_t initBuffers(PortStateT *port, uint16_t rxSz, uint16_t txSz) {
|
||||||
{
|
|
||||||
HGLOBAL hRx;
|
HGLOBAL hRx;
|
||||||
HGLOBAL hTx;
|
HGLOBAL hTx;
|
||||||
|
|
||||||
|
|
@ -1006,8 +982,7 @@ static int16_t initBuffers(PortStateT *port, uint16_t rxSz, uint16_t txSz)
|
||||||
// Reads COMnBase, COMnIRQ, COMnFIFO, and COMnRxTRIGGER from
|
// Reads COMnBase, COMnIRQ, COMnFIFO, and COMnRxTRIGGER from
|
||||||
// SYSTEM.INI [386Enh] to support non-standard port configurations.
|
// SYSTEM.INI [386Enh] to support non-standard port configurations.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void initPortState(PortStateT *port, int16_t commId)
|
static void initPortState(PortStateT *port, int16_t commId) {
|
||||||
{
|
|
||||||
uint16_t baseAddr;
|
uint16_t baseAddr;
|
||||||
uint8_t irq;
|
uint8_t irq;
|
||||||
uint16_t fifoEnabled;
|
uint16_t fifoEnabled;
|
||||||
|
|
@ -1090,8 +1065,7 @@ static void initPortState(PortStateT *port, int16_t commId)
|
||||||
// Called after writing data to the TX ring buffer to kick off
|
// Called after writing data to the TX ring buffer to kick off
|
||||||
// transmission if it's not already running.
|
// transmission if it's not already running.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void primeTx(PortStateT *port)
|
void primeTx(PortStateT *port) {
|
||||||
{
|
|
||||||
uint8_t ier;
|
uint8_t ier;
|
||||||
|
|
||||||
ier = (uint8_t)_inp(port->baseAddr + UART_IER);
|
ier = (uint8_t)_inp(port->baseAddr + UART_IER);
|
||||||
|
|
@ -1109,8 +1083,7 @@ void primeTx(PortStateT *port)
|
||||||
// and re-enables interrupts. A DOS fullscreen app or VM switch may
|
// and re-enables interrupts. A DOS fullscreen app or VM switch may
|
||||||
// have reprogrammed the UART, so we must restore everything.
|
// have reprogrammed the UART, so we must restore everything.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void FAR PASCAL _export reactivateOpenCommPorts(void)
|
void FAR PASCAL _export reactivateOpenCommPorts(void) {
|
||||||
{
|
|
||||||
int16_t i;
|
int16_t i;
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint8_t mcr;
|
uint8_t mcr;
|
||||||
|
|
@ -1161,8 +1134,7 @@ void FAR PASCAL _export reactivateOpenCommPorts(void)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// readCommString - Read data (ordinal 20, alias for reccom)
|
// readCommString - Read data (ordinal 20, alias for reccom)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export readCommString(int16_t commId, void FAR *buf, int16_t len)
|
int16_t FAR PASCAL _export readCommString(int16_t commId, void FAR *buf, int16_t len) {
|
||||||
{
|
|
||||||
dbgInt16("KPCOMM: readCommStr Id", commId);
|
dbgInt16("KPCOMM: readCommStr Id", commId);
|
||||||
return reccom(commId, buf, len);
|
return reccom(commId, buf, len);
|
||||||
}
|
}
|
||||||
|
|
@ -1174,8 +1146,7 @@ int16_t FAR PASCAL _export readCommString(int16_t commId, void FAR *buf, int16_t
|
||||||
// Checks [386Enh] for COMnBase (hex) and COMnIRQ overrides.
|
// Checks [386Enh] for COMnBase (hex) and COMnIRQ overrides.
|
||||||
// Falls back to standard defaults if not present.
|
// Falls back to standard defaults if not present.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void readPortConfig(int16_t commId, uint16_t FAR *baseAddr, uint8_t FAR *irq)
|
static void readPortConfig(int16_t commId, uint16_t FAR *baseAddr, uint8_t FAR *irq) {
|
||||||
{
|
|
||||||
char key[10];
|
char key[10];
|
||||||
char buf[16];
|
char buf[16];
|
||||||
|
|
||||||
|
|
@ -1236,8 +1207,7 @@ static void readPortConfig(int16_t commId, uint16_t FAR *baseAddr, uint8_t FAR *
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// readSystemIni - Read an unsigned integer value from SYSTEM.INI
|
// readSystemIni - Read an unsigned integer value from SYSTEM.INI
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static uint16_t readSystemIni(const char FAR *section, const char FAR *key, uint16_t defVal)
|
static uint16_t readSystemIni(const char FAR *section, const char FAR *key, uint16_t defVal) {
|
||||||
{
|
|
||||||
return (uint16_t)GetPrivateProfileInt(section, key, (int)defVal, "SYSTEM.INI");
|
return (uint16_t)GetPrivateProfileInt(section, key, (int)defVal, "SYSTEM.INI");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1248,8 +1218,7 @@ static uint16_t readSystemIni(const char FAR *section, const char FAR *key, uint
|
||||||
// Copies up to len bytes from the receive ring buffer into buf.
|
// Copies up to len bytes from the receive ring buffer into buf.
|
||||||
// Returns number of bytes read, or negative error code.
|
// Returns number of bytes read, or negative error code.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export reccom(int16_t commId, void FAR *buf, int16_t len)
|
int16_t FAR PASCAL _export reccom(int16_t commId, void FAR *buf, int16_t len) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint8_t FAR *dst;
|
uint8_t FAR *dst;
|
||||||
uint16_t bytesRead;
|
uint16_t bytesRead;
|
||||||
|
|
@ -1335,8 +1304,7 @@ int16_t FAR PASCAL _export reccom(int16_t commId, void FAR *buf, int16_t len)
|
||||||
// Takes DCB FAR * (4 bytes, RETF 4). CommId is in dcb->Id.
|
// Takes DCB FAR * (4 bytes, RETF 4). CommId is in dcb->Id.
|
||||||
// Both USER.EXE and COMMTASK.DLL push 4 bytes for this call.
|
// Both USER.EXE and COMMTASK.DLL push 4 bytes for this call.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export setcom(DCB FAR *dcb)
|
int16_t FAR PASCAL _export setcom(DCB FAR *dcb) {
|
||||||
{
|
|
||||||
int16_t commId;
|
int16_t commId;
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
|
|
@ -1408,8 +1376,7 @@ int16_t FAR PASCAL _export setcom(DCB FAR *dcb)
|
||||||
// Caller passes port ID and requested RX/TX buffer sizes.
|
// Caller passes port ID and requested RX/TX buffer sizes.
|
||||||
// We manage our own GlobalAlloc'd buffers.
|
// We manage our own GlobalAlloc'd buffers.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export setque(int16_t commId, int16_t rxSz, int16_t txSz)
|
int16_t FAR PASCAL _export setque(int16_t commId, int16_t rxSz, int16_t txSz) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
dbgInt16("KPCOMM: setque Id", commId);
|
dbgInt16("KPCOMM: setque Id", commId);
|
||||||
|
|
@ -1501,8 +1468,7 @@ int16_t FAR PASCAL _export setque(int16_t commId, int16_t rxSz, int16_t txSz)
|
||||||
// Copies up to len bytes from buf into the transmit ring buffer.
|
// Copies up to len bytes from buf into the transmit ring buffer.
|
||||||
// Returns number of bytes written, or negative error code.
|
// Returns number of bytes written, or negative error code.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export sndcom(int16_t commId, void FAR *buf, int16_t len)
|
int16_t FAR PASCAL _export sndcom(int16_t commId, void FAR *buf, int16_t len) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
uint8_t FAR *src;
|
uint8_t FAR *src;
|
||||||
int16_t bytesWritten;
|
int16_t bytesWritten;
|
||||||
|
|
@ -1557,8 +1523,7 @@ int16_t FAR PASCAL _export sndcom(int16_t commId, void FAR *buf, int16_t len)
|
||||||
// Returns accumulated error flags (CE_*) and fills the COMSTAT
|
// Returns accumulated error flags (CE_*) and fills the COMSTAT
|
||||||
// structure with current buffer counts and status.
|
// structure with current buffer counts and status.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export stacom(int16_t commId, COMSTAT FAR *stat)
|
int16_t FAR PASCAL _export stacom(int16_t commId, COMSTAT FAR *stat) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
int16_t errors;
|
int16_t errors;
|
||||||
|
|
||||||
|
|
@ -1600,8 +1565,7 @@ int16_t FAR PASCAL _export stacom(int16_t commId, COMSTAT FAR *stat)
|
||||||
// Called by Windows when switching away from this VM.
|
// Called by Windows when switching away from this VM.
|
||||||
// Disables interrupts on all open ports to prevent ISR problems.
|
// Disables interrupts on all open ports to prevent ISR problems.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void FAR PASCAL _export suspendOpenCommPorts(void)
|
void FAR PASCAL _export suspendOpenCommPorts(void) {
|
||||||
{
|
|
||||||
int16_t i;
|
int16_t i;
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
|
|
@ -1632,8 +1596,7 @@ void FAR PASCAL _export suspendOpenCommPorts(void)
|
||||||
// Disables interrupts, drops DTR/RTS, unhooks ISR, frees buffers.
|
// Disables interrupts, drops DTR/RTS, unhooks ISR, frees buffers.
|
||||||
// Returns 0 on success.
|
// Returns 0 on success.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t FAR PASCAL _export trmcom(int16_t commId)
|
int16_t FAR PASCAL _export trmcom(int16_t commId) {
|
||||||
{
|
|
||||||
PortStateT *port;
|
PortStateT *port;
|
||||||
|
|
||||||
dbgInt16("KPCOMM: trmcom Id", commId);
|
dbgInt16("KPCOMM: trmcom Id", commId);
|
||||||
|
|
@ -1688,8 +1651,7 @@ int16_t FAR PASCAL _export trmcom(int16_t commId)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// LibMain - DLL entry point
|
// LibMain - DLL entry point
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpCmdLine)
|
int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpCmdLine) {
|
||||||
{
|
|
||||||
int16_t i;
|
int16_t i;
|
||||||
|
|
||||||
(void)wDataSeg;
|
(void)wDataSeg;
|
||||||
|
|
@ -1716,8 +1678,7 @@ int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lp
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// WEP - DLL exit procedure
|
// WEP - DLL exit procedure
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int FAR PASCAL _export WEP(int nParam)
|
int FAR PASCAL _export WEP(int nParam) {
|
||||||
{
|
|
||||||
int16_t i;
|
int16_t i;
|
||||||
|
|
||||||
(void)nParam;
|
(void)nParam;
|
||||||
|
|
|
||||||
30
drv/isr.c
30
drv/isr.c
|
|
@ -38,8 +38,7 @@ static int16_t irq4RefCount = 0;
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// checkFlowRx - Check RX buffer level and assert/deassert flow control
|
// checkFlowRx - Check RX buffer level and assert/deassert flow control
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void checkFlowRx(PortStateT *port)
|
static void checkFlowRx(PortStateT *port) {
|
||||||
{
|
|
||||||
uint16_t base;
|
uint16_t base;
|
||||||
|
|
||||||
base = port->baseAddr;
|
base = port->baseAddr;
|
||||||
|
|
@ -84,8 +83,7 @@ static void checkFlowRx(PortStateT *port)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// handleLsr - Process line status errors
|
// handleLsr - Process line status errors
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void handleLsr(PortStateT *port, uint8_t lsr)
|
static void handleLsr(PortStateT *port, uint8_t lsr) {
|
||||||
{
|
|
||||||
if (lsr & LSR_OE) {
|
if (lsr & LSR_OE) {
|
||||||
port->errorFlags |= CE_OVERRUN;
|
port->errorFlags |= CE_OVERRUN;
|
||||||
}
|
}
|
||||||
|
|
@ -108,8 +106,7 @@ static void handleLsr(PortStateT *port, uint8_t lsr)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// handleMsr - Process modem status changes
|
// handleMsr - Process modem status changes
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void handleMsr(PortStateT *port)
|
static void handleMsr(PortStateT *port) {
|
||||||
{
|
|
||||||
uint8_t msr;
|
uint8_t msr;
|
||||||
|
|
||||||
msr = (uint8_t)_inp(port->baseAddr + UART_MSR);
|
msr = (uint8_t)_inp(port->baseAddr + UART_MSR);
|
||||||
|
|
@ -151,8 +148,7 @@ static void handleMsr(PortStateT *port)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// handleRx - Read all available bytes from UART into RX ring buffer
|
// handleRx - Read all available bytes from UART into RX ring buffer
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void handleRx(PortStateT *port, uint8_t lsr)
|
static void handleRx(PortStateT *port, uint8_t lsr) {
|
||||||
{
|
|
||||||
uint16_t base;
|
uint16_t base;
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
|
|
||||||
|
|
@ -215,8 +211,7 @@ static void handleRx(PortStateT *port, uint8_t lsr)
|
||||||
// For 16550: burst up to 16 bytes per THRE interrupt.
|
// For 16550: burst up to 16 bytes per THRE interrupt.
|
||||||
// For 8250: send 1 byte at a time.
|
// For 8250: send 1 byte at a time.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
static void handleTx(PortStateT *port)
|
static void handleTx(PortStateT *port) {
|
||||||
{
|
|
||||||
uint16_t base;
|
uint16_t base;
|
||||||
uint16_t burst;
|
uint16_t burst;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
@ -267,8 +262,7 @@ static void handleTx(PortStateT *port)
|
||||||
//
|
//
|
||||||
// Returns 0 on success, -1 on error.
|
// Returns 0 on success, -1 on error.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
int16_t hookIsr(PortStateT *port)
|
int16_t hookIsr(PortStateT *port) {
|
||||||
{
|
|
||||||
uint8_t intNum;
|
uint8_t intNum;
|
||||||
uint8_t picMask;
|
uint8_t picMask;
|
||||||
int16_t *refCount;
|
int16_t *refCount;
|
||||||
|
|
@ -343,8 +337,7 @@ int16_t hookIsr(PortStateT *port)
|
||||||
// Reads IIR in a loop until no more interrupts are pending.
|
// Reads IIR in a loop until no more interrupts are pending.
|
||||||
// Handles in priority order: LSR > RX > TX > MSR.
|
// Handles in priority order: LSR > RX > TX > MSR.
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void isrDispatch(PortStateT *port)
|
void isrDispatch(PortStateT *port) {
|
||||||
{
|
|
||||||
uint8_t iir;
|
uint8_t iir;
|
||||||
uint8_t lsr;
|
uint8_t lsr;
|
||||||
uint16_t base;
|
uint16_t base;
|
||||||
|
|
@ -402,8 +395,7 @@ void isrDispatch(PortStateT *port)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// unhookIsr - Restore previous interrupt vector via DPMI
|
// unhookIsr - Restore previous interrupt vector via DPMI
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void unhookIsr(PortStateT *port)
|
void unhookIsr(PortStateT *port) {
|
||||||
{
|
|
||||||
uint8_t intNum;
|
uint8_t intNum;
|
||||||
uint8_t picMask;
|
uint8_t picMask;
|
||||||
int16_t *refCount;
|
int16_t *refCount;
|
||||||
|
|
@ -448,8 +440,7 @@ void unhookIsr(PortStateT *port)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// isr3 - ISR entry point for IRQ3 (COM2 and COM4)
|
// isr3 - ISR entry point for IRQ3 (COM2 and COM4)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void _far _interrupt isr3(void)
|
void _far _interrupt isr3(void) {
|
||||||
{
|
|
||||||
int16_t i;
|
int16_t i;
|
||||||
|
|
||||||
// Load DLL's data segment -- _interrupt saves/restores DS but doesn't
|
// Load DLL's data segment -- _interrupt saves/restores DS but doesn't
|
||||||
|
|
@ -472,8 +463,7 @@ void _far _interrupt isr3(void)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// isr4 - ISR entry point for IRQ4 (COM1 and COM3)
|
// isr4 - ISR entry point for IRQ4 (COM1 and COM3)
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void _far _interrupt isr4(void)
|
void _far _interrupt isr4(void) {
|
||||||
{
|
|
||||||
int16_t i;
|
int16_t i;
|
||||||
|
|
||||||
// Load DLL's data segment -- see comment in isr3
|
// Load DLL's data segment -- see comment in isr3
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,7 @@ typedef void (*EventCallbackT)(int32_t formId, int32_t ctrlId,
|
||||||
```c
|
```c
|
||||||
#include "formsrv.h"
|
#include "formsrv.h"
|
||||||
|
|
||||||
void onEvent(int32_t formId, int32_t ctrlId,
|
void onEvent(int32_t formId, int32_t ctrlId, const char *eventName, const char *data, void *userData) {
|
||||||
const char *eventName, const char *data, void *userData)
|
|
||||||
{
|
|
||||||
printf("Event: form=%d ctrl=%d event=%s data=%s\n",
|
printf("Event: form=%d ctrl=%d event=%s data=%s\n",
|
||||||
formId, ctrlId, eventName, data);
|
formId, ctrlId, eventName, data);
|
||||||
|
|
||||||
|
|
@ -177,8 +175,7 @@ void onEvent(int32_t formId, int32_t ctrlId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
|
||||||
FormTransportT transport = { myReadFn, myWriteFn, myCtx };
|
FormTransportT transport = { myReadFn, myWriteFn, myCtx };
|
||||||
FormServerT *server = formServerCreate(&transport);
|
FormServerT *server = formServerCreate(&transport);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue