DECLARE SUB initsp ()
DECLARE SUB spreed (TXT$, seg$)
DECLARE SUB CLBOT ()
DECLARE SUB BgAR (x%, y%, c%)
DECLARE SUB JMOUSE ()
DECLARE SUB WDWS ()
DECLARE SUB proccmd (ORDER$)
DECLARE SUB GRPset (x%, y%, c%)
DECLARE SUB UOSP (op%)
DECLARE SUB INDATA (incom$)
DECLARE SUB LN (h%, v%, x%, y%, c%, BF%)
DECLARE SUB border ()
DECLARE SUB XPOD (x%, y%, c%)
DECLARE SUB SSCR ()
DECLARE SUB FSET (x%, y%, c%)
DECLARE SUB TCLOCK ()
DECLARE SUB DBASE ()
DECLARE SUB hand (G1%, G2%, GC%, b%)
DECLARE SUB ARROW (AH%, AV%, AC%)
DECLARE SUB opencom ()     'opens com port for communication
DECLARE FUNCTION menu% ()  'displays menu and accepts&returns input
DECLARE SUB waitforcall () 'waits for a call and connects when modem rings
DECLARE SUB callbbs ()     'calls a place and connects
DECLARE SUB setmodemoption ()  'sets modem option and saves it to a file
DECLARE SUB endprog ()     'ends the program
DECLARE SUB connect ()     'connects and handles output/input to/from modem
DECLARE SUB MOUSE (cx%, dx%, bx%)
DECLARE SUB MousePointer (SW%)

'BASTerm.BAS Version 1.2d
'A terminal example program in QBASIC (Freeware)
'Copyright (C)1995-1996 Mark Kim
'* Supports basic I/O from/to modem.
'* Supports only COM1 and COM2
'* ANSI support (with ANSI.SYS)
'* No upload or download support in any mode.
'* No guarentee, warentee, or any type of -rentees whatsoever.  Use at your
'  own risk.
'* No distribution after modification.  Parts of this file may be used in
'  others' programs provided that credit is given in proper place(s).  Must
'  include in the credit where the original file (this) can be found.
'Comments via Internet E-Mail to: markkkim@aol.com
'Older versions of the program is available.  Contact the author for info.
'RUN SETUP FROM THE MENU FIRST!!!

'Function/Sub declarations


'Change this value to other values to change the key that cuts communication
CONST HALT = 27    'ASCII value for Escape key
DEFINT A-Z
'

      
        REM %%%%% SPECIAL THANKS TO  Jeff Barnette  %%%%%
        REM %%%%% FOR THIS MOUSE ROUTINE %%%%%
       
         REM osiu$ - stands for opperating systems in use
        
         COMMON SHARED incom$, LINCOM$, osp$, CRC$, ORDER$, CR$, osiu$
         COMMON SHARED LBATCH$, BATCH$

         COMMON SHARED gph2, gpv2
         COMMON osp1, lll, UIN1, portopen
         DIM SHARED BASE$(64, 64)
         DIM SHARED a(9): REM %%% FOR MOUSEROUTINE %%%

        DEF SEG = VARSEG(a(0))
     
        RESTORE
        FOR I = 0 TO 17
        READ r
        POKE VARPTR(a(0)) + I, r
        NEXT I
        DATA &HB8,&H00,&H00,&H55,&H8B,&HEC,&HCD,&H33,&H92
        DATA &H8B,&H5E,&H06,&H89,&H07,&H5D,&HCA,&H02,&H00
       
        CALL MousePointer(0)      'Reset mouse and
        CALL MousePointer(1)      'Reset mouse and
        CALL MousePointer(3)      'Get coordinates
         osiu$ = "DOS 6.0"

CLS
WIDTH 80
DO
LOCATE 1, 1
CR$ = CHR$(13)
CALL initsp
CALL spreed(TXT$, seg$)
PRINT " returning to ..."
SLEEP

PRINT "############################"
PRINT "# MAIN FRAME TERMINAL PORT #"
PRINT "#  <W> for window          #"
PRINT "############################"
PRINT TIME$
PRINT " HIT SPACE BAR  "


ke$ = INKEY$
lpc = lpc + 1


IF lpc > 10000 OR ke$ = "W" THEN CALL SSCR: lpc = 0

IF ke$ = CHR$(27) THEN END
IF ke$ = "P" THEN CALL WDWS

LOOP UNTIL ke$ = CHR$(32)

COLOR 7, 0: REM CODE TO MAKE TEXT BLINK
    'CLS
COLOR 7
PRINT " CONNECTION IN PROGRESS..."
PRINT " 0 will dissable any com port activity for stand alone usage "
INPUT "Select Com Port ( 1 / 2 )  "; n

 'ON ERROR GOTO er:

SELECT CASE (n)
CASE IS = 0
PRINT "   ZERO "
PRINT " ----------"
CASE IS = 1
    OPEN "com1:19200,n,8,1,RB2048,TB2048" FOR RANDOM AS #1
    PRINT "com 1 is ON"
CASE IS = 2
1   OPEN "com2:19200,n,8,1,RB2048,TB2048" FOR RANDOM AS #1
   PRINT " com 2 is ON"
END SELECT
       CLS
      
       IF n = 0 THEN portopen = 0: PRINT " no rs232 link ... "
       SLEEP 1
      
       COLOR 7
    
     LOCATE 10, 10
     
     IF n <> 0 THEN
     PRINT "getting term please wait ..."
       SLEEP
     END IF
IF portopen = 1 THEN
 PRINT #1, "OK"
END IF

DO    'loop until user tells the program to end program
  item% = menu%    'run menu function and store return value to item integer
  SELECT CASE item%      'run subs according to the option chosen
    CASE 1: waitforcall
    CASE 2: callbbs
    CASE 3: setmodemoption
    CASE 4: endprog
    CASE 5
    CALL DBASE
    CASE 6
    CALL SSCR
  END SELECT
LOOP UNTIL item% = 4     '4 is the value that ends the loop
'SYSTEM                   'exit to DOS, if it was called directly from DOS

'VERSION HISTORY:
' Version 1.0a:
' Version 1.0b:
'   Fixed: Now setmodemoption sub creates CFG instead of INI.
'   Updated: More efficient/modifiable input-from-modem process.
' Version 1.1a:
'   Fixed: Some spelling/grammar errors in comments
'   Updated: Option to print the outgoing data to screen, a process
'     needed when connecting to other terminal programs (not BBS program)
'   (never released)
' Version 1.2a:
'   Fixed: Forgot to add local echo option -- oops!  While I'm at it,
'     options menu added.
'   Updated: ANSI support.  Requires ANSI.SYS to be loaded.  Special thanks
'     to Ariel R. Benzakein (He's a guy!) from AOL for the ANSI tip.
'   Bug: Because the program uses PRINT and PRINT to CON, the alignment of
'     the screen does not look that great.  Oh well.
' Version 1.2b:
'   Fixed: Some unnecessary commentted lines of programming were deleted
'   Fixed: "Local echo enabled" message changed to "Local echo toggled"
' Version 1.2c:
'   Fixed: "END IF without IF" error statement corrected
' Version 1.2d:
'   Fixed: Bug with not printing anything to the screen was fixed (oops!)
'   Updated: ASCII 254 "remarks start indicators" changed to asterisk


COLOR 7, 0
CLS
PRINT " Endind Terminal"


END
er:

CLS
 lt = 1
 DO
 LOCATE 10, 10
 PRINT " Restarting please wait ..."
 LOCATE 15, 10
 PRINT lt
 LOOP UNTIL TIMER > (lt + 30)
 RUN

SUB ARROW (AH, AV, AC)
 ARW$ = "R5G2F2G2H2G2U6"
' DRAW "BM0,0C" + STR$(AC) + "BR" + STR$(AH) + "BD" + STR$(AV) + ARW$



END SUB

SUB BgAR (x, y, c)



 CALL FSET(x, y, c)
 'CALL FSET(x, y + 1, c)
 'CALL FSET(x + 1, y, c)
 'CALL FSET(x - 1, y, c)
 'CALL FSET(x, y - 1, c)





END SUB

SUB border

c = 7
CALL LN(1, 1, 79, 1, c, BF)
CALL LN(1, 1, 1, 33, c, BF)
CALL LN(1, 33, 79, 33, c, BF)
CALL LN(79, 33, 79, 1, c, BF)
END SUB

SUB box (h, v, x, y, c)



     rl = x
     bt = y

    'CALL horline(H, V, rl, C)
  
    'CALL horline(H, Y, rl, C)

    'CALL VerLine(H, V, bt, C)
  
  
    'CALL VerLine(X, V, bt, C)


END SUB

DEFSNG A-Z
'A sub that calls another computer via modem...
'I just call it callbbs because I am testing it on a BBS
SUB callbbs
'  COLOR 3
  INPUT "Number to call: ", number$
  opencom  'a sub that opens the com port for communication
  'PRINT #1, "ATDT" + number$  'call the number in tone (not pulse)
  PRINT "Calling " + number$ + "...."
  connect  'a sub to processes data and sends/receives it via modem
END SUB

DEFINT A-Z
SUB CLBOT
COLOR 0, 3
IF LBATCH$ <> (BATCH$) THEN
    LOCATE 21, 1
     PRINT STRING$(60, " ")
     PRINT STRING$(60, " ")
     PRINT STRING$(60, " ")
END IF
LOCATE 21, 1
PRINT BATCH$;


END SUB

'A sub that processes and exchanges data between the modems
SUB connect
  
  COLOR 4, 0
  CLS
  echo% = 0                   'local echo.  0 = off, 1 = on
  
  DO
   
    'User enters stuff
    ch$ = INKEY$              'get a character from keyboard, if any is typed
    IF ch$ = CHR$(8) THEN
    
     ll = LEN(TELETYPE$)
     IF ll > 0 THEN
       TELETYPE$ = LEFT$(TELETYPE$, ll - 1)
     END IF
   
    END IF
    IF ch$ = CHR$(0) + CHR$(59) THEN
     CALL spreed(TXT$, seg$)
    END IF
   
    IF ch$ = CHR$(0) + "H" THEN
           TELETYPE$ = TELETYPE$ + " "
           CALL proccmd(TELETYPE$)
           TELETYPE$ = ""
           'dta$ = ""
           BATCH$ = ""
           
           ch$ = ""
    END IF
    IF ch$ = CHR$(27) THEN dta$ = ""
    IF ch$ <> "" THEN
    dta$ = dta$ + ch$
    PRINT ch$;
    END IF
   
   
   
    IF ch$ <> CHR$(8) AND ch$ <> CHR$(13) THEN
    TELETYPE$ = TELETYPE$ + ch$
    END IF
   
    CALL MOUSE(cx, dx, bx)
    MH = dx
    MV = cx


     'CIRCLE (MH, MV), 5, 1
     AC = 2
     AH = MH
     AV = MV
     CALL ARROW(AH, AV, AC)

     IF MH <> (MH1) OR MV <> (MV1) THEN
     ' CIRCLE (MH1, MV1), 5, 0
     AC = 0
     AH = MH1
     AV = MV1
     CALL ARROW(AH, AV, AC)
     MH1 = MH
     MV1 = MV
     END IF
   
   
     CALL JMOUSE

    
     B0 = STRIG(0)
    GPH1 = STICK(2): GPV1 = STICK(3): B1 = STICK(1)
       b = STRIG(0): b = STRIG(1): b = STRIG(2)
      GPH1 = GPH1 * 2
        GC = 3
      CALL hand(GPH1, GPV1, GC, b)
      
     'CIRCLE (GPH1, GPV1), 5, 1
    
     IF GPH1 <> (G1) OR GPV1 <> (G2) THEN
           GC = 0
      CALL hand(G1, G2, GC, b)
     
      G1 = GPH1
      G2 = GPV1
     
     END IF
    
     B2 = STRIG(2): B3 = STRIG(3)
    COLOR 7

    IF ch$ = CHR$(HALT) THEN  'if ESC pressed
      
     
      LOCATE 3, 2
     
      IF kbtgl = 1 THEN PRINT "keyboard on" ELSE PRINT "  KEY OFF"
      IF portopen = 0 THEN
      PRINT "     You are not currently connected to main CPU "
      END IF
      PRINT "     OS in use "; osiu$
      PRINT "     ====== OPTIONS ======="
      PRINT "  1. Local echo on/off  "
      PRINT "  2. Send HALT character (<ESC> by default)"
      PRINT "  3. Close port         "
      PRINT "  4. Return to terminal "
      PRINT "  5. Joy/Mouse Sync"
      PRINT "  6. turns joy/mouse off"
      PRINT "  7. Screen Saver "
      PRINT "  8. Toggle keyboard out"
      PRINT "  9. CPU TERM 8088      "
      PRINT
      CALL border
     
     
     
      SELECT CASE INPUT$(1)   'input a character and select case at same time"
        CASE "1":
          echo% = echo% XOR 1            'toggle echo% between 0 and 1
          PRINT "Local echo toggled. Returning to terminal...."
        CASE "2":
          IF portopen = 1 THEN
          PRINT #1, CHR$(HALT)           'send #1 the HALT character (ESC)
          PRINT "HALT character sent. Returning to terminal...."
          END IF
        CASE "3": EXIT DO                'exitting DO closes port
        CASE "4":                        'acknowledges pressing 4, but does X
        CASE "5"
       
        jjm = 1
        CASE "6"

        jjm = 0
        CASE "7"
        CALL SSCR
        CASE "8"
        
         kbtgl = kbtgl + 1
         IF kbtgl > 1 THEN kbtgl = 0
        CASE "9"

        CALL WDWS

        CASE ELSE:
          PRINT "Invalid option! Returning to terminal...."
          
          
      END SELECT
   

    ELSEIF ch$ <> "" AND kbglt = 1 AND portopen = 1 THEN PRINT #1, ch$; 'if something is typed send to modem
   
       END IF

    IF ch$ = CHR$(0) + "M" THEN ch$ = "": OGM = 1
    IF ch$ = CHR$(8) THEN
     
     ll = LEN(BATCH$)
     IF ll > 0 THEN
      BATCH$ = LEFT$(BATCH$, ll - 1): ch$ = ""
     END IF
    END IF
    IF ch$ <> "" THEN BATCH$ = BATCH$ + ch$
   
   
    IF echo% = 1 THEN         'if local echo enabled
      'PRINT #3, ch$;          'print to monitor using ANSI.SYS, if avail
    END IF
    'Messages received
    'input message:
    ' LOC(1) is zero if nothing is in the buffer.  Otherwise it tells
    ' how big the incoming data is.  So if there is anything in the buffer
    ' input 1 character, the line says:
    IF portopen = 1 THEN
    IF LOC(1) > 0 AND poertopen = 1 THEN
       inchar$ = INPUT$(LOC(1), #1)
     
      
      
       IF inchar$ = CHR$(13) THEN
        SOUND 100, 1
        SOUND 1000, 1
        CALL proccmd(ORDER$)
       END IF
       IF inchar$ = CHR$(13) THEN incom$ = incom$ + CHR$(188)

        
    IF inchar$ <> CHR$(13) THEN
    ORDER$ = ORDER$ + inchar$
    END IF
    
    ELSE
      inchar$ = ""
    END IF
    END IF
       

    IF inchar$ <> CHR$(10) THEN
    incom$ = incom$ + inchar$
    LOCATE 1, 1: COLOR 4, 0
   
    IF OGM = 1 THEN PRINT " @ "; "send 0" + STR$(OGMPLH)
   
       ll = LEN(incom$)
      
       
     
     
      UIN1 = UIN1 + 1
      IF UIN1 > 10 AND ll <> (lll) THEN
       CALL INDATA(incom$)
      lll = ll: UIN1 = 0
      END IF
   
   
    IF portopen = 1 THEN
     PRINT "LOC" + STR$(LOC(1)) + " CR " + CRC$ + " LEN " + STR$(ll);
    END IF
    LOCATE 1, 70: PRINT TIME$
    LOCATE 2, 1
    PRINT incom$ + ttp$
   
   
    LOCATE 20, 1
    
   
    osp1 = osp1 + 1
    IF osp1 > 24 THEN osp1 = 0
              
     SELECT CASE osp1
     CASE IS = 0
    
    
     ttp$ = " "
     COLOR 0, 7
     PRINT STRING$(80, 219)' REM SCREEN PROMPT
     CASE IS = 10
     ttp$ = "_"
     COLOR 7, 0
     PRINT STRING$(80, "-")' REM SCREEN PROMPT
    
     CASE IS = 17
     ttp$ = " "
     COLOR 7, 0
     PRINT STRING$(80, osp$)' REM SCREEN PROMPT
  LOCATE 23, 70
           BLTP = BLTP + 1
           IF BLTP > 1 THEN BLTP = 0
     SELECT CASE (BLTP)
     CASE IS = 0
     COLOR 7, 0
     CASE IS = 1
     COLOR 0, 7
     END SELECT

     PRINT "TERMINAL"
     LOCATE 1, 1: PRINT "File"

     SELECT CASE (BLTP)
     CASE IS = 0
     COLOR 0, 7
     CASE IS = 1
     COLOR 7, 0
     END SELECT
     LOCATE 1, 7: PRINT "Edit"


     COLOR 7, 0
   

    END SELECT
    LOCATE 21, 1
    COLOR 0, 3
    IF LBATCH$ <> BATCH$ OR CCTP = 6 THEN CALL CLBOT: LBATCH$ = BATCH$

    osp$ = CHR$(219)
   
    CALL CLBOT
    'PRINT BATCH$; '
       
        CCTP = CCTP + 1
        IF CCTP > 7 THEN
         CC = CC + 1: IF CC > 24 THEN CC = 0
        CCTP = 0
        END IF
         COLOR CC, 10
      

    PRINT osp$; : REM print the (COLOR) OS curser
    
    END IF
          
      COLOR 4, 0
    IF OGM = 1 THEN
     ll = LEN(BATCH$)
     OGMPLH = OGMPLH + 1
      ox$ = MID$(BATCH$, OGMPLH, 1)
       IF portopen = 1 THEN
        PRINT #1, ox$;
       END IF
     IF OGMPLH > (ll) THEN
     OGMPLH = 0
      BATCH$ = ""
       COLOR 4, 0
       
       OGM = 0
     END IF
    END IF

  LOOP
  IF portopen = 1 THEN
   CLOSE #1   'close the file once done
   CLOSE #3   'close the screen of ANSI support
  END IF

END SUB

SUB DBASE
'
'
'
'
CALL TCLOCK
CR$ = CHR$(13)
PRINT "GETTING DBASE"
OGC$ = "BASE" + CR$



END SUB

DEFSNG A-Z
'This is how the program ends
SUB endprog
  COLOR 7
  PRINT "Ending Program."
END SUB

DEFINT A-Z
SUB FSET (x, y, c)

IF y > 2 THEN
 Y2 = y / 2
 Y2 = INT(Y2)
 ELSE
 Y2 = y
 END IF

IF y = 1 THEN Y2 = 1     ' border protection
IF Y2 < 1 THEN Y2 = 1
IF Y2 > 23 THEN Y2 = 23
IF x < 1 THEN x = 1
IF x > 79 THEN x = 79


AK = SCREEN(Y2, x)
BL = 0: REM TEST FOR FULL BLOCK
'LOCATE 1, 20: PRINT AK

LOCATE Y2, x
IF y MOD 2 = 1 THEN

 ch$ = CHR$(220)
 IF AK = 223 THEN BL = 1
 ELSE
 ch$ = CHR$(223)
 IF AK = 220 THEN BL = 1
END IF
IF BL = 1 THEN ch$ = CHR$(219)

COLOR c
PRINT ch$

END SUB

SUB GRPset (x, y, c)

REM mon is global

SCREEN 0
WIDTH 80

SELECT CASE (mon)
 CASE IS = 0
   COLOR c
  CALL FSET(x, y, c)

 CASE IS = 1

 CASE IS = 2
END SELECT


END SUB

'
SUB hand (G1, G2, GC, b)
 hnd$ = "r4d4l4u4br9d4l4u4r4bd9l4u4r4d4bl9u4r4d4l4bu"
 'DRAW "BM0,0C" + STR$(0) + "BR" + STR$(G1) + "BD" + STR$(G2) + hnd$

 hnd$ = "R5u5r5d5r5d5l5d5l5u5l5u5"
 IF b = -1 THEN
      CLS
      WINDOW SCREEN (G1, G2)-(G1 + 180, G2 + 100)

 DRAW "BM0,0C" + STR$(0) + "BR" + STR$(G1) + "BD" + STR$(G2) + hnd$
 ELSE
 'DRAW "BM0,0C" + STR$(0) + "BR" + STR$(G1) + "BD" + STR$(G2) + hnd$

 hnd$ = "r4d4l4u4br9d4l4u4r4bd9l4u4r4d4bl9u4r4d4l4bu"
 'DRAW "BM0,0C" + STR$(0) + "BR" + STR$(G1) + "BD" + STR$(G2) + hnd$


 END IF

 'DRAW "BM0,0C" + STR$(GC) + "BR" + STR$(G1) + "BD" + STR$(G2) + hnd$


END SUB

SUB INDATA (incom$)

CT = 0
ll = LEN(incom$)
DO
 CT = CT + 1
 CC$ = MID$(incom$, CT, 1)
 IF CC$ = CHR$(13) THEN CR = CR + 1

LOOP UNTIL CT > (ll)

   CRC$ = STR$(CR)
IF CR >= 10 OR ll > 512 THEN
      CLS
 incom$ = RIGHT$(incom$, (ll / 2))

 END IF
' 12, 30: PRINT CR

END SUB

SUB initsp
CLOSE 8
FILES
SLEEP
     PRINT " Opening Spread Sheet "
OPEN "mfhlp.txt" FOR INPUT AS (8)
DO
  INPUT #8, w$
  seg$ = seg$ + w$
   
    IF w$ = CHR$(13) THEN
     l = l + 1
      seg$ = ""
       PRINT seg$;
    
    END IF
 


LOOP UNTIL EOF(8) OR l >= 34
CLOSE 8
END SUB

SUB JMOUSE
    gph = STICK(0): gpv = STICK(1)
                c = INT(RND(1) * (16)) + 1
     CALL BgAR(gph, gpv, c)
    
     IF gph2 <> (gph) OR gpv2 <> (gpv) THEN
     
      CALL BgAR(gph2, gpv2, 0)
     
      gph2 = gph
      gpv2 = gpv
     END IF

END SUB

SUB LN (h, v, x, y, c, BF)

PX = h
PY = v
  IF x > (h) THEN l = x - h ELSE l = h - x
  IF y > (v) THEN t = y - v ELSE t = v - y
XS1 = (l / 16)
YS1 = (t / 16)
DO
CALL FSET(PX, PY, c)
IF x < (PX) THEN PX = PX - XS1
IF x > (PX) THEN PX = PX + XS1
IF y > (PY) THEN PY = PY + YS1
IF y < (PY) THEN PY = PY - YS1

LOOP UNTIL PX = x AND PY = y

END SUB

DEFSNG A-Z
'Draws menu and returns the option the user typed
FUNCTION menu%
  DO    'a loop to draw the menu over and over until a valid option is typed
    CLS
    COLOR 5, 7
    PRINT "==== BASTerm Menu ===="
    PRINT " 1. Wait for a call  "
    PRINT " 2. Call somewhere    "
    PRINT " 3. Set Modem options "
    PRINT " 4. End Program       "
    PRINT " 5. Restart <Reboot>  "
    PRINT "     Choose One: ";       'A semicolon is needed to have cursor
                                     'at the end instead of next line
    LOCATE , , 1: ch$ = INPUT$(1)  'LOCATE,,1 is to show the cursor...
                                   'the cursor is otherwise hidden during
                                   'INPUT$(1) operation
    PRINT : PRINT   'go to the next line then skip a line
  LOOP UNTIL VAL(ch$) >= 1 AND VAL(ch$) <= 5  'until 1,2,3, or 4 is entered
  menu% = VAL(ch$)  'returns the typed option to the function's caller
  IF ch$ = "5" THEN RUN
END FUNCTION

DEFINT A-Z
SUB MOUSE (cx, dx, bx)
       
       
      

           POKE VARPTR(a(4)), &H92           'Swap code,Get CX setup
          CALL absolute(cx, VARPTR(a(0)))     'Run Code
              cx = cx                     'Adjust 25x80
           POKE VARPTR(a(4)), &H91           'Swap code,Get DX setup
          CALL absolute(dx, VARPTR(a(0)))     'Run Code
              dx = dx                     'Adjust 25x80
           POKE VARPTR(a(4)), &H93           'Swap code,Get BX setup
          CALL absolute(bx, VARPTR(a(0)))     'Run Code


IF bx = 1 THEN
PSET (cx, dx), 1
END IF
END SUB

SUB MousePointer (SW)
       
           POKE VARPTR(a(0)) + 1, SW         'Swap code,Set AX = (SW)
          CALL absolute(c, VARPTR(a(0)))     'Run Code

                                          'Note:
                                             'SW = 0-reset
                                             'SW = 1-on
                                             'SW = 2-off
                                             'SW = 3-coordinates


END SUB

DEFSNG A-Z
'Opens the comport for communication
SUB opencom
  PRINT "Retrieving COM port data.  Please hold."  'it didn't take long
                                                   'before but it does now!
  'open configuration file to input comport data:
  'OPEN "BASTerm.CFG" FOR INPUT AS #2    'open config file for data input
  'INPUT #2, comport$    'input the line
  CLOSE #2     'close file
  'open comport using data from the file:
  'RB2048 and TB2048 are the buffer sizes.  Bigger the buffer size the
  'more stable they are.  I think they maybe are used up as the data
  'comes in and out but I think maybe they are the sizes of the data
  'that can be held at once.  This can cause trouble if you Ctrl-Brk
  'during connection to fix parts of the program so make them pretty
  'big.
  
END SUB

DEFINT A-Z
SUB proccmd (ORDER$)
  LOCATE 2, 2: COLOR 7: PRINT " Processing :"; TIMER
  LOCATE 3, 2: PRINT ORDER$; "#"
  ORDER$ = UCASE$(ORDER$)
  
   ll = LEN(ORDER$)
   c = 1
 DO
  IF c <= (ll) THEN
   ch$ = MID$(ORDER$, c, 1)
  END IF
 IF ch$ <> CHR$(32) THEN
   LORDER$ = LORDER$ + ch$
 END IF

c = c + 1
 LOOP UNTIL c >= (ll) OR ch$ = CHR$(32)


 incom$ = incom$ + CR$ + "* " + LORDER$ + "---" + CR$

 IF c < (ll) THEN
 RORDER$ = RIGHT$(ORDER$, ll - c)
 END IF

 SELECT CASE (LORDER$)
  CASE IS = "BEEP"
   BEEP

  CASE IS = "SHELL", "SH"
   
   SHELL RORDER$


 END SELECT

ORDER$ = ""
END SUB

DEFSNG A-Z
'Asks and saves new com port information
SUB setmodemoption
  COLOR 2
  INPUT "COM Port Number (1 or 2): ", portno$
  INPUT "Modem Speed (300, 1200, 2400, etc): ", speed$
  PRINT "Are The Settings Right? ";
  ch$ = INPUT$(1)
  IF ch$ = "Y" OR ch$ = "y" THEN    'if Y or y is entered
    PRINT "Yes"   'print Yes... something fancy here....
    comport$ = "COM" + portno$ + ":" + speed$  'put the data into a variable
    OPEN "BASTerm.CFG" FOR OUTPUT AS #2  'open the config file for output
    PRINT #2, comport$   'store data
    CLOSE #2    'close file
    PRINT "Settings saved."
  ELSE   'anything other than Y or y is entered
    PRINT "No"  'print No... something fancy here....
    PRINT "Disregarding New Settings...."
  END IF
  PRINT
END SUB

DEFINT A-Z
SUB spreed (TXT$, seg$)
CLS
LOCATE 2, 1
 PRINT "### Spreed sheet ###"
v = 2' REM SET TO VERTI6CAL 2
l = 0
hlw = 1
worl = 1
DO
v = 3
DO
  
   l = worl
   l2 = 30
   tx$ = BASE$(SegTag, l)
   lll = LEN(tx$)
   IF hlw + l2 > (lll) THEN hlw = 1
   seg$ = tx$: 'MID$(tx$, hlw, l2)
LOCATE v, 1: PRINT " "; seg$; "    ";
  
   l = l + 1
  
 
  v = v + 1
LOOP UNTIL l >= 8 OR v > 8

DO
  ke$ = INKEY$


LOOP UNTIL ke$ <> ""
v = 2
IF ke$ = "6" THEN hlw = hlw + 1
IF ke$ = "4" THEN hlw = hlw - 1: IF hlw < 1 THEN hlw = 1

LOOP UNTIL ke$ = CHR$(27)
END SUB

' rem SCREEN 12 graphix
' rem  use only on win 95 98 machien
' rem   change or don't use on older systems
' rem    not cga tandy 1000 compatable
SUB SSCR

SELECT CASE mon  ' set to appropriate graphix settings

CASE IS = 0 ' tandy 1000 CGA 8088 processor

  x = INT(RND(1) * 80) + 1
   y = INT(RND(1) * 40) + 1
       

 DO
 
     
     
      x = x + 1: IF x > 79 THEN x = 0
        y = y + 1: IF y > 44 THEN y = 0
      c = c + 1: IF c > 20 THEN c = 0
     
      CALL GRPset(x, y, c)

 ke$ = INKEY$

LOOP UNTIL ke$ = CHR$(27)





CASE IS = 1 ' 586 processor vga graphix
SCREEN 12

 DO





 LOOP UNTIL ke$ = CHR$(27)

 END SELECT


END SUB

SUB TCLOCK

PRINT " TERM CLOCK AT "; TIMER; " - "; TIME$
END SUB

SUB TEXTOUT
' THIS SUB FEEDS BYTE BY BYTE ANY STRING OF TEXT
'  TO THE EMULATEDD (MF) (CPE)
'   C.P.E. - STANDS FOR CENTRAL PROCERSSING ENVIRONMENT -
'
'


END SUB

SUB UOSP (osp1)

osp1 = osp1 + 1


IF osp1 > 3 THEN osp1 = 0



END SUB

DEFSNG A-Z
'A function that sets the modem to detect ringing and then connect
SUB waitforcall
  'COLOR 3
  opencom       'open comport
  'PRINT #1, "ATS0=1"    'ATS0=1 is used to connect after 1 ring.
  connect       'make communcation between modems available when the
                'connection is made
END SUB

DEFINT A-Z
SUB WDWS
CLS
DO
ke$ = INKEY$
  IF ke$ = CHR$(13) THEN
  CLS
  SELECT CASE (CD$)
  CASE IS = "/"
   
  
  END SELECT

 
  M = VAL(CD$)
  IF M < 256 * 16 THEN
  c$ = c$ + STR$(PEEK(M)) + CR$
  END IF
  CD$ = ""
  END IF
osp$ = CHR$(cln)
 osp1$ = CHR$(cll)
  osp2$ = CHR$(cl2)


IF ke$ <> "" OR TIME$ <> tl$ THEN
                 tl$ = TIME$
  c$ = c$ + ke$
  CD$ = CD$ + ke$
LOCATE 1, 1
PRINT c$; op$

tt = tt + 1
IF tt = 1 THEN op$ = CHR$(4)
IF tt > 1 THEN op$ = CHR$(219): tt = 0

END IF


          cln = cln + 1
          IF cln > 255 THEN cln = 1: cll = cll + 1
           IF cll > 255 THEN cll = 0: cl2 = cl2 + 1
            IF cl2 > 255 THEN cl2 = 1

          IF cll < 95 THEN cll = 95
          IF cln < 95 THEN cln = 95
          IF cl2 < 96 THEN cl2 = 95

  LOCATE 20, 1
  PRINT STRING$(79, 4)

  LOCATE 21, 1
  PRINT osp$; osp1$; osp2$;

  LOCATE 23, 1
  PRINT cln, cll, cl2
  CALL JMOUSE
  COLOR 7
LOOP UNTIL ke$ = "_"
END SUB

SUB XPOD (x, y, c)

CALL FSET(x, y, c)
CALL FSET(x - 1, y - 1, c)
CALL FSET(x + 1, y - 1, c)
CALL FSET(x + 1, y + 1, c)
CALL FSET(x - 1, y + 1, c)
CALL FSET(x - 1, y + 2, c)

END SUB

