DECLARE SUB Parser (Parse$, Params%, Arg$())
DECLARE SUB Terminal (ComPort%, AnsiHand%, Baud$, HandShake%, Echo%, LineFeeds%, Reg AS ANY)
DECLARE SUB AnsiPrint (AnsiHand%, Send$)
DECLARE SUB FossilDeInit (ComPort%, Reg AS ANY)
DECLARE SUB FossilInit (ComPort%, Reg AS ANY)
DECLARE SUB Recieve (ComPort%, Send%, Reg AS ANY)
DECLARE SUB SetDtr (ComPort%, DtrStatus$, Reg AS ANY)
DECLARE SUB SetHandShake (ComPort%, HandShake%, Reg AS ANY)
DECLARE SUB SetPortParams (ComPort%, Baud$, Bits%, Stops%, Parity$, Reg AS ANY)
DECLARE SUB Status (ComPort%, Info%, Reg AS ANY)
DECLARE SUB Transmit (ComPort%, Send%, Reg AS ANY)
DECLARE SUB BaudSelect (ComPort%, AnsiHand%, Baud$, Bits%, Stops%, Parity$, Reg AS ANY)


' *****************
' ** Fossil.Bas  **
' *****************
'
' $INCLUDE: 'QB.BI'                      ' Include Data Types for INTERRUPT calls

Version$ = "Fossil Version 2.00a"        ' Program version stamp
VersionDate$ = "July 29th, 1990"
							     
DIM SHARED Reg AS RegType                ' Used for INTERRUPT calls
DIM Arg$(20)                             ' Used for command line parser

CrLf$ = CHR$(&HD) + CHR$(&HA)            ' A Carriage return + linefeed string

Baud$ = "9600"
HandShake% = 2
ComPort% = 0
Echo% = 0

LOCATE , , 1                     ' Turn curser on

CALL AnsiPrint(AnsiHand%, CHR$(27) + "[2J")   ' Clear the screen
CALL AnsiPrint(AnsiHand%, CrLf$ + Version$ + CrLf$)
CALL AnsiPrint(AnsiHand%, "By Chris Wagner " + VersionDate$ + CrLf$ + CrLf$)

Parse$ = UCASE$(COMMAND$)         ' Get command line paramaters
CALL Parser(Parse$, Params%, Arg$())
FOR Counter1% = 1 TO Params%
    SELECT CASE LEFT$(Arg$(Counter1%), 3)

	CASE "-BD"  ' Set baud rate
	    Baud$ = RIGHT$(Arg$(Counter1%), LEN(Arg$(Counter1%)) - 3)
	    CALL AnsiPrint(AnsiHand%, "Setting Baud rate set to " + Baud$ + CrLf$)

	CASE "-CP" ' Set COM port
	    ComPort% = VAL(RIGHT$(Arg$(Counter1%), LEN(Arg$(Counter1%)) - 3)) - 1
	    SELECT CASE ComPort%
		CASE 0 TO 3
		    CALL AnsiPrint(AnsiHand%, "Using Comminications port COM" + LTRIM$(STR$(ComPort% + 1)) + CrLf$)
		CASE ELSE
		    ComPort% = 0
		    CALL AnsiPrint(AnsiHand%, "Invalid Communications port parameter:  " + Arg$(Counter1%) + CrLf$)
		    CALL AnsiPrint(AnsiHand%, "Using Comminications port COM1" + CrLf$)
	    END SELECT

	CASE "-HS" ' Set handshake type
	    HandShake$ = UCASE$(RIGHT$(Arg$(Counter1%), LEN(Arg$(Counter1%)) - 3))
	    HandShake% = VAL("&H" + HandShake$)
	    IF HandShake% > &HF THEN
		    CALL AnsiPrint(AnsiHand%, "Bad HandShake Enable parameter:  " + LTRIM$(STR$(HandShake%)) + CrLf$)
	    END IF

	CASE "-LR" ' Add linefeeds to received carriage returns
	    LineFeeds% = LineFeeds% OR 1

	CASE "-LT" ' Add linefeeds to transmitted carriage returns
	    LineFeeds% = LineFeeds% OR 2

	CASE "-EC" ' Set local echo on or off
	    Echo$ = UCASE$(RIGHT$(Arg$(Counter1%), LEN(Arg$(Counter1%)) - 3))
	    Echo% = VAL(LEFT$(Echo$, 1))

	CASE ELSE
	    CALL AnsiPrint(AnsiHand%, "Invalid Parameter: " + CHR$(34) + Arg$(Counter1%) + CHR$(34) + CrLf$)
    END SELECT
NEXT Counter1%

CALL Terminal(ComPort%, AnsiHand%, Baud$, HandShake%, Echo%, LineFeeds%, Reg)      ' The terminal itself

CALL AnsiPrint(AnsiHand%, CHR$(27) + "[2J")          ' Clear the screen

AnsiHand% = -1
CALL AnsiPrint(AnsiHand%, "")

CALL FossilDeInit(ComPort%, Reg)

END

SUB AnsiPrint (AnsiHand%, Send$)

SELECT CASE AnsiHand%
    CASE 0
	AnsiHand% = FREEFILE
	OPEN "CONS:" FOR OUTPUT AS #AnsiHand%
    CASE -1
	CLOSE #AnsiHand%
	AnsiHand% = 0
	EXIT SUB
    CASE ELSE
END SELECT

PRINT #AnsiHand%, Send$;

END SUB

SUB BaudSelect (ComPort%, AnsiHand%, Baud$, Bits%, Stops%, Parity$, Reg AS RegType)

CrLf$ = CHR$(&HD) + CHR$(&HA)

CALL AnsiPrint(AnsiHand%, CrLf$)
CALL AnsiPrint(AnsiHand%, "Current baud rate:  " + Baud$ + CrLf$)
CALL AnsiPrint(AnsiHand%, CrLf$)
CALL AnsiPrint(AnsiHand%, "Select a baud rate:" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   A.    300" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   B.    600" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   C.   1200" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   D.   2400" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   E.   4800" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   F.   9600" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   G.  19200" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   H.  38400" + CrLf$)
CALL AnsiPrint(AnsiHand%, "   Q.  No Change" + CrLf$)
CALL AnsiPrint(AnsiHand%, CrLf$)

WHILE INKEY$ <> "": WEND  ' Clear the keyboard buffer

DO
    SELECT CASE UCASE$(INKEY$)
	CASE ""
	CASE "A"
	    Baud$ = "300"
	    EXIT DO
	CASE "B"
	    Baud$ = "600"
	    EXIT DO
	CASE "C"
	    Baud$ = "1200"
	    EXIT DO
	CASE "D"
	    Baud$ = "2400"
	    EXIT DO
	CASE "E"
	    Baud$ = "4800"
	    EXIT DO
	CASE "F"
	    Baud$ = "9600"
	    EXIT DO
	CASE "G"
	    Baud$ = "19200"
	    EXIT DO
	CASE "H"
	    Baud$ = "38400"
	    EXIT DO
	CASE "Q"
	    CALL AnsiPrint(AnsiHand%, "Baud not changed" + CrLf$)
	    CALL AnsiPrint(AnsiHand%, CrLf$)
	    EXIT SUB
	CASE ELSE
    END SELECT
LOOP

CALL SetPortParams(ComPort%, Baud$, Bits%, Stops%, Parity$, Reg)
CALL AnsiPrint(AnsiHand%, "Baud changed to:  " + Baud$ + CrLf$)

END SUB

SUB FossilDeInit (ComPort%, Reg AS RegType)

' Release the FOSSIL device driver (Call when finished)
'
' ah = &H05    Fossil Function Number - DeInitialize FOSSIL driver
' al = &H00    Place Holder
' dx = Communications port number (0-3)

Reg.ax = &H500
Reg.dx = ComPort%
CALL Interrupt(&H14, Reg, Reg)

END SUB

SUB FossilInit (ComPort%, Reg AS RegType)

' Initialize the FOSSIL device driver
'
' dx = Communications port number (0-3)
' ah = &H04    Fossil Function Number - Initialize FOSSIL driver
'                                       (Raises DTR in the porcess)

Reg.dx = ComPort%
Reg.ax = &H400
CALL Interrupt(&H14, Reg, Reg)

IF Reg.ax <> &H1954 THEN
    CLS
    PRINT
    PRINT "ERROR:  Fossil Driver not responding - READ MANUAL!"
    PRINT "You may need to add DEVICE={path}\X00.SYS for proper operation"
    PRINT "    (Note:  {path} means the drive:\path where the file is located"
    PRINT
    SLEEP (5)
    END
END IF

END SUB

'    DECLARE SUB Parser (Parse$, Params%, Arg$())
'
'    DIM Arg$(50)
'    CLS
'
'    Parse$ = "    1a 2bb 3ccc   4dddd   5eeeee 6ffffff     "
'
'    CALL Parser(Parse$, Params%, Arg$())
'
'    FOR Counter1% = 1 TO Params%
'          PRINT Counter1%, CHR$(34) + Arg$(Counter1%) + CHR$(34)
'    NEXT Counter1%
'
'   Argument splitter by Chris Wagner
'   call with:
'
'        Parse$ = input to be divided
'
'   Returns:
'        Params%   Number of parameters
'        Arg$()    Array of arguments, starting at 1
'
'
SUB Parser (Parse$, Params%, Arg$())

Params% = 0
Temp$ = RTRIM$(Parse$)

DO
    Temp$ = LTRIM$(Temp$)
    IF LEN(Temp$) = 0 THEN EXIT DO
    Temp% = INSTR(Temp$, SPACE$(1))

    IF Temp% = 0 THEN
	Params% = Params% + 1
	Arg$(Params%) = Temp$
	EXIT DO
    END IF

    Arg$(Params% + 1) = RTRIM$(LEFT$(Temp$, Temp%))
    Temp$ = RIGHT$(Temp$, LEN(Temp$) - Temp%)
    IF LEN(Arg$(Params% + 1)) > 0 THEN Params% = Params% + 1
LOOP

END SUB

SUB Recieve (ComPort%, Send%, Reg AS RegType)

CALL Status(ComPort%, Info%, Reg) ' Test for space in OUTPUT buffer

IF (Info% AND &H4) = 0 THEN
    IF (Info% AND &H2) = &H2 THEN
	' ah = &H02      Fossil Function Number - Recieve Character
	' al = &H00      Place Holder
	' dx = Communications port (0-3)
	Reg.ax = &H200
	Reg.dx = ComPort%
	CALL Interrupt(&H14, Reg, Reg)
	Send% = Reg.ax
      ELSE
	Send% = -1 ' No Characters in input buffer
    END IF
  ELSE ' Input buffer over-run
    Send% = -2
    ' ah = &H0A      Fossil Function Number - Purge INPUT Buffer
    ' al = &H00      Place Holder
    ' dx = Communications port (0-3)
    Reg.ax = &HA00
    Reg.dx = ComPort%
    CALL Interrupt(&H14, Reg, Reg)
    CLS
    PRINT
    PRINT " *** Input buffer over-run."
    PRINT "     Buffer purged."
    PRINT
    SLEEP (5)
END IF

END SUB

SUB SetDtr (ComPort%, DtrStatus$, Reg AS RegType)

' ah = &H06    Fossil Function Number - DTR Control
' al = &H00    Fossil Sub-Function    - Lower DTR
' al = &H01    Fossil Sub-Function    - Raise DTR
' dx = Communications port number     - (0-3)

Reg.dx = ComPort%

SELECT CASE UCASE$(DtrStatus$)
    CASE "LOW"
	Reg.ax = &H600
    CASE "HIGH"
	Reg.ax = &H601
    CASE ELSE
	Reg.ax = &H600
	CLS
	PRINT
	PRINT "Invalid parameter for DTR in SetDtr:  "; CHR$(34); DtrStatus$; CHR$(34)
	PRINT "Setting DTR LOW."
	PRINT
	SLEEP (5)
END SELECT

CALL Interrupt(&H14, Reg, Reg)

END SUB

SUB SetHandShake (ComPort%, HandShake%, Reg AS RegType)

' ah = &H0F    Fossil Function Number - Flow Control
' al = &Hxx    Flow Control bit mask
' dx = Communications port number (0-3)
'
'  HandShake% = BITMAP                                        3 2 1 0
'
' Enable FOSSIL to restrain remote using XON/XOFF             1 - - -  (Reg.ax OR &H8)
' Enable FOSSIL to use RTS/CTS                                - - 1 -  (Reg.ax OR &H2)
' Enable remote to restrain FOSSIL transmitter using XON/XOFF - - - 1  (Reg.ax OR &H1)

Reg.dx = ComPort%

IF HandShake% > &HF THEN
    HandShake% = &H2
    CLS
    PRINT
    PRINT "Invalid parameter for HandShake in SetHandShake:  "; LTRIM$(STR$(HandShake%)); CHR$(34)
    PRINT "Setting HandShake to RTS/CTS."
    PRINT
    SLEEP (5)
END IF

Reg.ax = &HF00 + HandShake%
CALL Interrupt(&H14, Reg, Reg)

' ah = &H10    Fossil Function Number - Ctl+C, Ctl+K Checking
' al = &Hxx    Check Enable bit mask
' dx = Communications port number (0-3)

Reg.ax = &H1000
Reg.dx = ComPort%
CALL Interrupt(&H14, Reg, Reg)

END SUB

SUB SetPortParams (ComPort%, Baud$, Bits%, Stops%, Parity$, Reg AS RegType)

' ah = &H00    Fossil Function Number - Set Communications Parameters
' al = &Hxx    Baud/Parity/Stops
' dx = Communications port number (0-3)

Reg.dx = ComPort%
Reg.ax = 0

' Bit Mapped instruction     7 6 5 4 3 2 1 0
'
'  baud:  19200              0 0 0 - - - - -   (Reg.ax OR &H00)
'         38400              0 0 1 - - - - -   (Reg.ax OR &H20)
'           300              0 1 0 - - - - -   (Reg.ax OR &H40)
'           600              0 1 1 - - - - -   (Reg.ax OR &H60)
'          1200              1 0 0 - - - - -   (Reg.ax OR &H80)
'          2400              1 0 1 - - - - -   (Reg.ax OR &HA0)
'          4800              1 1 0 - - - - -   (Reg.ax OR &HC0)
'          9600              1 1 1 - - - - -   (Reg.ax OR &HE0)
'
' Parity:  None              - - - 0 0 - - -   (Reg.ax OR &H00)
'          Odd               - - - 0 1 - - -   (Reg.ax OR &H08)
'          None              - - - 1 0 - - -   (Reg.ax OR &H10)
'          Even              - - - 1 1 - - -   (Reg.ax OR &H18)
'
' Stop Bits: 1               - - - - - 0 - -   (Reg.ax OR &H00)
'            2               - - - - - 1 - -   (Reg.ax OR &H04)
'
' Character Len:  5          - - - - - - 0 0   (Reg.ax OR &H00)
'                 6          - - - - - - 0 1   (Reg.ax OR &H01)
'                 7          - - - - - - 1 0   (Reg.ax OR &H02)
'                 8          - - - - - - 1 1   (Reg.ax OR &H03)

SELECT CASE Baud$
    CASE "300"
	Reg.ax = (Reg.ax OR &H40)
    CASE "600"
	Reg.ax = (Reg.ax OR &H60)
    CASE "1200"
	Reg.ax = (Reg.ax OR &H80)
    CASE "2400"
	Reg.ax = (Reg.ax OR &HA0)
    CASE "4800"
	Reg.ax = (Reg.ax OR &HC0)
    CASE "9600"
	Reg.ax = (Reg.ax OR &HE0)
    CASE "19200"
	Reg.ax = (Reg.ax OR &H0)
    CASE "38400"
	Reg.ax = (Reg.ax OR &H20)
    CASE ELSE
	Reg.ax = (Reg.ax OR &HE0)
	CLS
	PRINT
	PRINT "Invalid parameter for Baud rate in SetBaud:  "; CHR$(34); Baud$; CHR$(34)
	PRINT "Defaulting to 9600 baud."
	PRINT
	SLEEP (5)
END SELECT
       
SELECT CASE Bits%
    CASE 5
	Reg.ax = (Reg.ax OR &H0)
    CASE 6
	Reg.ax = (Reg.ax OR &H1)
    CASE 7
	Reg.ax = (Reg.ax OR &H2)
    CASE 8
	Reg.ax = (Reg.ax OR &H3)
    CASE ELSE
	Reg.ax = (Reg.ax OR &H3)
	CLS
	PRINT
	PRINT "Invalid parameter for DataBits in SetBaud:  "; LTRIM$(STR$(Bits%))
	PRINT "Defaulting to 8 bits per word."
	PRINT
	SLEEP (5)
END SELECT

SELECT CASE Stops%
    CASE 1
	Reg.ax = (Reg.ax OR &H0)
    CASE 2
	Reg.ax = (Reg.ax OR &H4)
    CASE ELSE
	Reg.ax = (Reg.ax OR &H0)
	CLS
	PRINT
	PRINT "Invalid parameter for Stop Bits in SetBaud:  "; LTRIM$(STR$(Stops%))
	PRINT "Defaulting to 1 stop bit."
	PRINT
	SLEEP (5)
END SELECT

SELECT CASE UCASE$(Parity$)
    CASE "NONE"
	Reg.ax = (Reg.ax OR &H0)
    CASE "ODD"
	Reg.ax = (Reg.ax OR &H8)
    CASE "EVEN"
	Reg.ax = (Reg.ax OR &H18)
    CASE ELSE
	Reg.ax = (Reg.ax OR &H0)
	CLS
	PRINT
	PRINT "Invalid parameter for Parity in SetBaud:  "; CHR$(34); Parity$; CHR$(34)
	PRINT "Defaulting to NO Patiry."
	PRINT
	SLEEP (5)
END SELECT

' ah = &H00    Fossil Function Number - Set Communications Parameters
' al = &Hxx    Baud/Parity/Stops
' dx = Communications port number (0-3)

Reg.dx = ComPort%
CALL Interrupt(&H14, Reg, Reg)

END SUB

SUB Status (ComPort%, Info%, Reg AS RegType)

' ah = &H03     Fossil Function Number - Status
' al = &H00     Place Holder
' dx = Communications port number       (0-3)
'
' Info% = Bitmap                  4 3 2 1 0
'
' DCD True                       - - - - 1  OR &H01
' Characters in input buffer     - - - 1 -  OR &H02
' Input buffer over-run          - - 1 - -  OR &H04
' Characters in output buffer    - 1 - - -  OR &H08
' Output buffer full             1 - - - -  OR &H10

Reg.dx = ComPort%
Reg.ax = &H300
CALL Interrupt(&H14, Reg, Reg)

IF (Reg.ax AND &H80) <> 0 THEN ' Carrier Detect TRUE
    Info% = (Info% OR &H1)
END IF

IF (Reg.ax AND &H100) <> 0 THEN ' Data in input buffer
    Info% = (Info% OR &H2)
END IF

IF (Reg.ax AND &H200) <> 0 THEN ' Input buffer overun
    Info% = (Info% OR &H4)
END IF

IF (Reg.ax AND &H4000) = 0 THEN ' Data in output buffer
    Info% = (Info% OR &H8)
END IF

IF (Reg.ax AND &H2000) = 0 THEN ' Output buffer full
    Info% = (Info% OR &H10)
END IF

END SUB

SUB Terminal (ComPort%, AnsiHand%, Baud$, HandShake%, Echo%, LineFeeds%, Reg AS RegType)

Bits% = 8
Stops% = 1
Parity$ = "NONE"

CALL FossilInit(ComPort%, Reg)
CALL SetHandShake(ComPort%, HandShake%, Reg)
CALL SetPortParams(ComPort%, Baud$, Bits%, Stops%, Parity$, Reg)

Cr$ = CHR$(&HD)
Lf$ = CHR$(&HA)
CrLf$ = Cr$ + Lf$
DtrStatus$ = "H"

GOSUB ModeStatus

DO
ReCheck:
    C$ = INKEY$
    IF LEN(C$) > 0 THEN
	A$ = LEFT$(C$, 1)
	IF LEN(C$) > 1 THEN
	    A$ = UCASE$(LEFT$(C$, 1))
	    B$ = UCASE$(RIGHT$(C$, 1))
	    SELECT CASE (ASC(A$) * &H100) + ASC(B$)

		CASE 81 ' Trap PgDn Download Command
		    SHELL "DSZ port " + LTRIM$(STR$(ComPort% + 1)) + " rz"
		    GOTO ReCheck
		
		CASE 73 ' Trap PgUp UpLoad Command
		    INPUT "Enter File Name to send "; FileName$
		    IF FileName$ <> "" THEN
			SHELL "DSZ port " + LTRIM$(STR$(ComPort% + 1)) + " sz " + LCASE$(FileName$)
		    END IF
		    GOTO ReCheck

		CASE 36 ' Trap Alt+J Dos Shell Command
		    SHELL
		    CALL AnsiPrint(AnsiHand%, CrLf$ + "Terminal in operation now." + CrLf$)
		    GOTO ReCheck

		CASE 45 ' Trap Alt+X EXIT Command
		    CALL AnsiPrint(AnsiHand%, CrLf$ + "Lower DTR signal? [Y/n]")
		    DO
			SELECT CASE UCASE$(INKEY$)
			    CASE "Y", CHR$(&HD)
				CALL SetDtr(ComPort%, "LOW", Reg)
				EXIT SUB
			    CASE "N"
				EXIT SUB
			    CASE ELSE
			END SELECT
		    LOOP

		CASE 32  ' Trap Alt+D DTR Toggle Command
		    IF DtrStatus$ = "H" THEN
			DtrStatus$ = "L"
		      ELSE
			DtrStatus$ = "H"
		    END IF
		    GOSUB ModeStatus
		    GOTO ReCheck

		CASE 35 ' Trap Alt+H HangUp Command
		    CALL AnsiPrint(AnsiHand%, CrLf$ + "Hanging up Modem" + CrLf$)
		    CALL SetDtr(ComPort%, "LOW", Reg)
		    SLEEP (2)
		    CALL SetDtr(ComPort%, "HIGH", Reg)
		    GOTO ReCheck

		CASE 44 ' Trap Alt+Z Status Command
		    GOSUB ModeStatus
		    GOTO ReCheck

		CASE 48 ' Trap Alt+B Baud Command Command
		    CALL BaudSelect(ComPort%, AnsiHand%, Baud$, Bits%, Stops%, Parity$, Reg)
		    GOTO ReCheck

		CASE 18 ' Trap Alt+E ECHO Command
		    Echo% = (Echo% + 1) MOD 2
		    GOSUB ModeStatus
		    GOTO ReCheck

		CASE 68 ' Trap F10 Hex Mode/Debug command
		    HexMode% = (HexMode% + 1) MOD 2
		    GOSUB ModeStatus
		    GOTO ReCheck

		CASE 46 ' Trap Alt+C CLEAR SCREEN Command
		    CALL AnsiPrint(AnsiHand%, CHR$(27) + "[2J")          ' Clear the screen
		    GOTO ReCheck

		CASE 38  ' Trap Alt+L Line Feed Addition command
		    LineFeeds% = (LineFeeds% + 1) MOD 4
		    GOSUB ModeStatus
		    GOTO ReCheck

		CASE ELSE
		    CALL AnsiPrint(AnsiHand%, " Alt KeyCode = " + LTRIM$(STR$(ASC(B$))) + CrLf$)
		    GOTO ReCheck
	    END SELECT
	END IF

	IF Echo% = 1 THEN CALL AnsiPrint(AnsiHand%, A$)
	       
	Send% = ASC(A$)
	CALL Transmit(ComPort%, Send%, Reg)
	       
	IF A$ = Cr$ THEN
	    IF Echo% = 1 THEN CALL AnsiPrint(AnsiHand%, Lf$)
	END IF

	IF (LineFeeds% AND 2) = 2 THEN
	    Send% = &HA
	    CALL Transmit(ComPort%, Send%, Reg)
	END IF

    END IF

    CALL Recieve(ComPort%, Send%, Reg)
    IF Send% > -1 THEN
	IF HexMode% = 1 THEN
	    Temp$ = LTRIM$(HEX$(Send%))
	    Temp$ = STRING$(2 - LEN(Temp$), "0") + Temp$
	    Temp$ = "&H" + Temp$ + CrLf$
	    CALL AnsiPrint(AnsiHand%, Temp$)
	  ELSE
	    CALL AnsiPrint(AnsiHand%, CHR$(Send%))
	    IF Send% = &HA AND LineFeeds% MOD 2 = 1 THEN
		CALL AnsiPrint(AnsiHand%, CHR$(&HA))
	    END IF
	END IF
    END IF
LOOP

ModeStatus:

CALL AnsiPrint(AnsiHand%, CrLf$)

' ----- Alt+D DTR Status
IF DtrStatus$ = "L" THEN
    CALL AnsiPrint(AnsiHand%, " *** DTR is LOW" + CrLf$)
  ELSE
    CALL AnsiPrint(AnsiHand%, "     DTR is HIGH" + CrLf$)
END IF

' ----- Alt+E ECHO Status
IF Echo% = 1 THEN
    CALL AnsiPrint(AnsiHand%, " *** Local Echo ON (Half Duplex)" + CrLf$)
  ELSE
    CALL AnsiPrint(AnsiHand%, "     Local Echo OFF (Full Duplex)" + CrLf$)
END IF

' ----- Alt+H HEX Mode Status
IF HexMode% = 1 THEN
    CALL AnsiPrint(AnsiHand%, " *** Hex Mode ON" + CrLf$)
  ELSE
    CALL AnsiPrint(AnsiHand%, "     Hex Mode OFF" + CrLf$)
END IF

' ----- Alt+S String Mode Status
IF StringMode% = 1 THEN
    CALL AnsiPrint(AnsiHand%, " *** String Mode ON" + CrLf$)
  ELSE
    CALL AnsiPrint(AnsiHand%, "     String Mode OFF" + CrLf$)
END IF

' ----- Trap Alt+L Line Feed Addition command

SELECT CASE LineFeeds% AND 1
    CASE 0
	CALL AnsiPrint(AnsiHand%, "     NOT Adding LF's to Recieved CR's" + CrLf$)
    CASE 1
	CALL AnsiPrint(AnsiHand%, " *** Adding LF's to Recieved CR's" + CrLf$)
END SELECT

SELECT CASE LineFeeds% AND 2
    CASE 0
	CALL AnsiPrint(AnsiHand%, "     NOT Adding LF's to Transmitted CR's" + CrLf$)
    CASE 2
	CALL AnsiPrint(AnsiHand%, " *** Adding LF's to Transmitted CR's" + CrLf$)
END SELECT

CALL AnsiPrint(AnsiHand%, CrLf$)
       
RETURN

END SUB

SUB Transmit (ComPort%, Send%, Reg AS RegType)

' ah = &H03      Fossil Function Number - StatusRequest
' al = &H00      Place Holder
' dx = Communications port (0-3)
'

CALL Status(ComPort%, Info%, Reg) ' Test for space in OUTPUT buffer
IF (Info% AND &H10) = 0 THEN ' Space in output buffer
    ' ah = &H01      Fossil Function Number - Transmit Character
    ' al = &Hxx      Character to be Transmitted
    ' dx = Communications port (0-3)
    Reg.dx = ComPort%
    Reg.ax = &H100 + Send%
    CALL Interrupt(&H14, Reg, Reg)
  ELSE
    Send% = -2 ' Output buffer full
    ' ah = &H09      Fossil Function Number - Purge OUTPUT Buffer
    ' al = &H00      Place Holder
    ' dx = Communications port (0-3)
    Reg.ax = &H900
    Reg.dx = ComPort%
    CALL Interrupt(&H14, Reg, Reg)
    CLS
    PRINT
    PRINT " *** Output Buffer Full."
    PRINT "     Transmission Terminated and buffer purged."
    PRINT
    SLEEP (5)
END IF

END SUB

