Files
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

261 lines
6.5 KiB
C++

//===========================================================================//
// File: L4Serial.hh //
// Project: MUNGA Brick: Platform-specific IO //
// Contents: PC serial interface class //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- -----------------------------------------------------------//
// 01/04/95 CPB Initial coding. //
//---------------------------------------------------------------------------//
// Copyright (C) 1994, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#if !defined(L4SERIAL_HPP)
# define L4SERIAL_HPP
# if !defined(STYLE_HPP)
# include <style.hpp>
# endif
// WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING
// Do NOT change ANY of the following lines without making
// corresponding changes in PCSerial.asm! PCSerial.hh exists
// ONLY to inform C++ compilers of the data and structures
// used by PCSerial.asm!
// WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING
// These are purposely grouped as two parameters in one equate.
// The standard PC COM ports ALWAYS use these combinations.
#define PCS_COM1 0x3F8,0x0C // portAddress,interruptNumber
#define PCS_COM2 0x2F8,0x0B
#define PCS_COM3 0x3E8,0X0C
#define PCS_COM4 0x2E8,0x0B
// Data rates
#define PCS_300 0x0180 // 300 Baud
#define PCS_1200 0x0060 // 1200 Baud
#define PCS_2400 0x0030 // 2400 Baud
#define PCS_9600 0x000C // 9600 Baud
#define PCS_19P2 0x0006 // 19200 Baud
#define PCS_38P4 0x0003 // 38400 Baud
#define PCS_115K 0x0001 // 115,200 Baud (not supported on all PC's)
// Data formats
#define PCS5D 0x0000 // 5 data bits
#define PCS6D 0x0001 // 6 data bits
#define PCS7D 0x0002 // 7 data bits
#define PCS8D 0x0003 // 8 data bits
#define PCS1S 0x0000 // one stop bit
#define PCS2S 0x0004 // two stop bits
#define PCSNP 0x0000 // no parity
#define PCSOP 0x0008 // odd parity
#define PCSEP 0x0018 // even parity
#define PCSMP 0x0028 // mark parity (untested)
#define PCSSP 0x0038 // space parity (untested)
// some popular combinations-
#define PCS_N81 (PCS8D|PCS1S|PCSNP) // no parity, 8 data, 1 stop
#define PCS_E81 (PCS8D|PCS1S|PCSEP) // even parity, 8 data, 1 stop
#define PCS_O81 (PCS8D|PCS1S|PCSOP) // odd parity, 8 data, 1 stop
// Flow control
// #define PCS_NOFLOWCTRL 0x0000 // no flow control
// error bits returned by PC_Serial::Errors()
#define PCS_ERR_OVERRUN 0x0002
#define PCS_ERR_PARITY 0x0004
#define PCS_ERR_FRAMING 0x0008
#define PCS_ERR_BREAK 0x0010
#define PCS_ERR_ALLOC 0x0100 // failed at slot allocation
#define PCS_ERR_INIT 0x0200 // failed DPMI initialization
#define PCS_ERR_TXOVER 0x0400 // overran transmit buffer
#define PCS_ERR_RXOVER 0x0500 // overran receive buffer
// bits returned by PC_Serial::ModemStatus()
// (1st four bits not defined yet, but non-zero)
#define PCS_MS_CTS 0x0010
#define PCS_MS_DSR 0x0020
#define PCS_MS_RI 0x0040
#define PCS_MS_DCD 0x0080
class PCSerial;
extern "C" void
PCSerialInit(
PCSerial *pc_serial,
Word data_rate,
Word data_format,
Word port,
Word irq_num
);
extern "C" int
PCSerialTerm(
PCSerial *pc_serial
);
extern "C" int
PCSerialReceive(
PCSerial *pc_serial,
char *destination,
int destination_length
);
extern "C" void
PCSerialSend(
PCSerial *pc_serial,
char *source,
int source_length
);
extern "C" int
PCSerialErrors(
PCSerial *pc_serial
);
extern "C" int
PCSerialActive(
PCSerial *pc_serial
);
extern "C" int
PCSerialTestInstance(
PCSerial *pc_serial
);
extern "C" int
PCSerialIsSignatureBad(
const volatile PCSerial *pc_serial
);
extern "C" int
PCSerialReceiveCount(
PCSerial *pc_serial
);
extern "C" int
PCSerialTransmitCount(
PCSerial *pc_serial
);
extern "C" void
PCSerialSetRate(
PCSerial *pc_serial,
Word rate
);
extern "C" void
PCSerialSetDataFormat(
PCSerial *pc_serial,
Word format
);
extern "C" void
PCSerialFlowControl(
PCSerial *pc_serial,
int enable
);
extern "C" int
PCSerialModemStatus(
PCSerial *pc_serial
);
class PCSerial
{
public:
PCSerial(Word rate, Word format, Word port, Word int_num)
{ PCSerialInit(this, rate, format, port, int_num); }
~PCSerial()
{
if (this == NULL)
{
cout << "~PCSerial has been passed a NULL pointer\n";
}
else
{
PCSerialTerm(this);
}
}
Logical
TestInstance()
{ return PCSerialTestInstance(this); }
int
ReceiveString(char *destPtr, int maxLen) // returns length
{ return PCSerialReceive(this, destPtr, maxLen); }
void
FlowControlEnable(Logical onOff)
{ PCSerialFlowControl(this, (int) onOff); }
void
SendString(char *srcPtr, int length)
{ PCSerialSend(this, srcPtr, length); }
// error bits returned by PCSerial::Errors()
enum ErrorBits {
overrunError=0x0002,
parityError=0x0004,
framingError=0x0008,
breakDetect=0x0010,
initError=0x0100
};
int
ReceiveCharCount()
{ return PCSerialReceiveCount(this); }
int
TransmitCharCount()
{ return PCSerialTransmitCount(this); }
int
Errors() // returns error value, clears it
{ return PCSerialErrors(this); }
int
IsActive()
{ return PCSerialActive(this); }
int
ModemStatus()
{ return PCSerialModemStatus(this); }
# if defined(USE_SIGNATURE)
friend int
Is_Signature_Bad(const volatile PCSerial *ptr)
{ return PCSerialIsSignatureBad(ptr); }
# endif
// protected:
Word portBase;
Word errorValue;
Byte enabled;
Byte txFlow;
Byte flowOverride;
LWord intDataPtr;
LWord hackCount;
// This is for INTERNAL USE only (reflects structure in .ASM file)
struct PCSerBuf
{
Word head, tail, count;
Byte data[1024];
}
txBuf, rxBuf;
};
#endif