home *** CD-ROM | disk | FTP | other *** search
- ' NSD: (N)ot (S)o (D)umb
- ' terminal program for CP/M Kaypro
- ' with an external modem.
- '
- ' Many Thanks to:
- ' Richard Walker, for the useful info in UARTKPRO.DOC
- ' ZEDCOR Inc., for the amazing ZBasic compiler.
- '
- ' NSD - Copyright, 1986 by Lee D. Rimar.
- ' ZBasic - Copyright, 1986 by ZEDCOR Inc.
- '
- ' NSD may be distributed without charge. Feel free to study
- ' and/or use any routines from this program, but please do
- ' NOT distribute altered versions of NSD. Thanks... LDR
-
- ON ERROR GOSUB "Error Traps"
-
- ' Definitions
-
- ' Initial Flagged Values
- Yes = -1
- No = 0
- AddLF = 0 ' add line feeds
- Done = 0 ' termination flag
- Echo = 0 ' echo mode
- Here = 0 ' local character
- Rate = 12 ' initial baud rate/100
- Wrap = 0 ' word wrap
-
- ' Serial Port Addresses
- Baud = 0
- Data = 4
- Cntl = 6
-
- ' Other Integers
- A = 0 ' for CHR$-ASC conversions
- Bel = 7 ' keyboard beep
- Bs = 8 ' back space
- Cmd = 0 ' for holding extended commands
- Cr = 13 ' carriage return
- Del = 127 ' delete
- Esc = 27 ' ESCape code
- Lf = 10 ' line feed
- Spc = 32 ' space
-
- ' Strings
-
- DEF LEN = 14
- File$ = "A:VERYLONG.FIL" ' just filling the space
-
- DEF LEN = 1
- A$ = " " ' for ASC-CHR$ conversions
- Cmd$ = " " ' see integer defs.
- Bel$ = CHR$(7)
- Bs$ = CHR$(8)
- Cr$ = CHR$(13)
- Lf$ = CHR$(10)
- Esc$ = CHR$(27)
-
- ' Long functions
-
- LONG FN WaitKey
- "Hit Any Key"
- ? Cr$ Lf$ "Hit any key... ";
- DO : UNTIL LEN(INKEY$)
- ?
- ENDFN ' WaitKey
-
- LONG FN CarriageReturn
- A$ = Cr$ : A = Cr
- ENDFN ' CarriageReturn
-
- LONG FN EmptyString
- A$ = "" : A = 0
- ENDFN ' EmptyString
-
- LONG FN CheckLocal ' scan local keyboard for character
- A$ = INKEY$
- IF LEN(A$) THEN A = ASC(A$) : Here = -1
- ENDFN ' CheckLocal
-
- LONG FN CheckRemote ' check modem for character
- LONG IF ((INP(Cntl) AND 1) AND 1) = 1
- A = INP(Data)
- A$ = CHR$(A)
- Here = 0
- ENDIF
- ENDFN ' CheckRemote
-
- LONG FN Sendout ' send character to modem
- OUT Data, A
- DO : UNTIL ((INP(Cntl) AND 4) AND 4) = 4
- ENDFN ' Sendout
-
- ' end of Definitions
-
- ' Single Use Code
-
- ' Z80 SIO Register Settings
- ' don't mess with this unless you know what you're doing!
- OUT Cntl, 4 : OUT Cntl, &H46 ' reg4: 16 clock, 1 stop bit, no parity
- OUT Cntl, 3 : OUT Cntl, &HC1 ' reg3: enable rx, 8 bit
- OUT Cntl, 5 : OUT Cntl, &HE8 ' reg5: enable tx, 8 bit, DTR on
- OUT Cntl, 1 : OUT Cntl, &H00 ' reg1: disable SIO interrupts
- GOSUB "Set Baud" ' can reset later with command "B"
- ' end of Initial Register Settings
-
- ' Sign On
- CLS
- ? "(N)ot (S)o (D)umb, a simple terminal program" Cr$ Lf$
- ? "Copyright, 1986 by Lee D. Rimar"
- ? "Portions Copyright, 1986 by ZEDCOR Inc." Cr$ Lf$
- ? "For: CP/M Kaypro computer with external modem" Cr$ Lf$
- ? "Type ESC-Q to exit. See NSD.DOC for help." Cr$ Lf$
- FN WaitKey
- CLS
-
- ' end of Single Use Code
-
- "Main Loop"
-
- DO:
- FN CheckLocal
- IF A$ = "" FN CheckRemote
- UNTIL LEN(A$)
-
- GOSUB "Filters"
- IF A$ = "" THEN "Main Loop"
-
- GOSUB "Process Character"
-
- LONG IF AddLF AND A = Cr
- A$ = Lf$ : A = Lf
- GOSUB "Process Character"
- ENDIF ' AddLF AND A = Cr
-
- GOTO "Main Loop"
-
- END ' of Main Loop
-
- ' Subroutines, in order of use.
-
- "Filters"
- IF Here AND A = Esc THEN "Command Processor"
- IF Wrap AND (A = Spc) AND (Count > 65) FN CarriageReturn
- IF AddLF AND A = Lf FN EmptyString
- IF A = Del THEN A$ = Bs$ : A = Bs
- IF A = Bs AND Count = 0 FN EmptyString
- RETURN ' de Filters
-
- "Process Character"
- LONG IF Echo
- ? A$;
- GOSUB "Count Characters"
- FN Sendout
- XELSE
- IF Here FN Sendout ELSE ? A$; : GOSUB "Count Characters"
- ENDIF
- RETURN ' de Process Character
-
- "Count Characters"
- IF A = 8 THEN Count = Count - 1 ELSE Count = Count + 1
- IF A = 13 THEN Count = 0
- RETURN ' de Count Characters
-
- "Command Processor"
- ? Bel$;
- DO: Cmd$ = UCASE$(INKEY$) : UNTIL LEN(Cmd$)
- Cmd = ASC(Cmd$) ' convert it to a number
- IF Cmd = Esc THEN A$ = Esc$ : A = Esc : RETURN
- IF Cmd = Lf THEN "Line Feed" ' LF
- IF Cmd = 66 THEN "Baud Rate" ' "B"
- IF Cmd = 68 THEN "Disconnect" ' "D"
- IF Cmd = 69 THEN "Echo Mode" ' "E"
- IF Cmd = 81 THEN CLS : END ' "Q"
- IF Cmd = 84 THEN "Send Text" ' "T"
- IF Cmd = 87 THEN "Word Wrap" ' "W"
- ? Bel$; ' if you get this far, it was an invalid command, so
- RETURN ' de Command Processor
-
- ' Command Processor Subroutines:
- ' if you didn't RETURN de Command Processor,
- ' you will from one of the routines below.
-
- "Line Feed"
- AddLF = NOT AddLF
- ? Cr$ Lf$ "Line feeds ";
- IF AddLF ? "ON" ELSE ? "OFF"
- FN EmptyString
- RETURN ' de Line Feeds
-
- "Baud Rate"
- ?
- "Get Rate" : INPUT "Baud/100 (3,6,12,24)? "; Rate
- "Set Baud" ' comes here once at beginning of program
- IF Rate<>3 AND Rate<>12 AND Rate<>24 THEN "Get Rate"
- IF Rate = 3 THEN OUT Baud, 5
- IF Rate = 6 THEN OUT Baud, 6
- IF Rate = 12 THEN OUT Baud, 7
- IF Rate = 24 THEN OUT Baud, 10
- FN CarriageReturn
- RETURN ' de Adjust Baud Rate
-
- "Disconnect"
- OUT Cntl, 5 ' select SIO register 5
- OUT Cntl, 0 ' don't be fussy, shut off everything
- ? Cr$ Lf$ "Disconnecting: ";
- DELAY 200 ' give modem time to notice (1/5 second)
- OUT Cntl, 5 ' gotta select the register again
- OUT Cntl,&HE8 ' restore register 5, turning DTR on
- ? "Ready to proceed."
- FN CarriageReturn
- RETURN ' de Disconnect
-
- "Echo Mode"
- Echo = NOT Echo
- ? Cr$ Lf$ "Echo ";
- IF Echo ? "ON" ELSE ? "OFF"
- FN EmptyString
- RETURN ' de Echo Mode
-
- "Send Text"
- ?
- "Get filename" ' if file is nil found, error trap returns here
- INPUT "File? "; File$
- IF LEN(File$) THEN File$ = UCASE$(File$) ELSE "Skip It"
- OPEN "I",1,File$
- INPUT "Slow? "; Slow
- WHILE NOT Done
- READ#1,A$;1 : A = ASC(A$)
- "Check EOF" ' error trap returns here if premature end of file
- LONG IF A = 26
- Done = -1
- XELSE
- ? A$;
- FN Sendout
- ENDIF
- IF A = Cr THEN DELAY Slow * 5 ELSE DELAY Slow
- WEND
- CLOSE
- ? Cr$ Lf$ "Transmit Complete"
- "Skip It" ' check here to see if transmit was really done
- IF Done FN CarriageReturn ELSE FN EmptyString
- Done = 0
- RETURN ' de Send Text
-
- "Word Wrap"
- Wrap = NOT Wrap
- ? Cr$ Lf$ "Word wrap ";
- IF Wrap ? "ON" ELSE ? "OFF"
- FN EmptyString
- RETURN ' de Word Wrap
-
- END ' of Command Processor Subroutines
-
- "Error Traps"
- IF ERROR = 259 THEN ERROR = 0 : CLOSE : RETURN "Get filename"
- IF ERROR = 257 THEN ERROR = 0 : A = 26 : RETURN "Check EOF"
-
- ? "Error: " ERROR; ERRMSG$(ERROR) ' untrapped error stops here
- STOP