home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
tbsource.lha
/
TBSource
/
ShellTerm
/
STv1.00.S
< prev
next >
Wrap
Text File
|
1993-12-21
|
13KB
|
670 lines
*************************************************
* *
* (C)opyright 1992 *
* *
* by Tomi Blinnikka *
* *
* Don´t try to understand the code *
* *
* Version 0.01 28/05/1992 *
* -0.99ö *
* *
*************************************************
INCLUDE "JMPLibs.i"
INCLUDE "exec/types.i"
INCLUDE "exec/nodes.i"
INCLUDE "exec/lists.i"
INCLUDE "exec/ports.i"
INCLUDE "exec/memory.i"
INCLUDE "exec/devices.i"
INCLUDE "exec/io.i"
INCLUDE "exec/tasks.i"
INCLUDE "libraries/dosextens.i"
INCLUDE "libraries/dos.i"
INCLUDE "devices/serial.i"
INCLUDE "XREF:2.0.xref"
INCLUDE "XREF:exec.xref"
INCLUDE "XREF:dos.xref"
LF: EQU 10
CR: EQU 13
CTRL_O: EQU $0F
CTRL_P: EQU $10
QUIT_KEY: EQU CTRL_P
STATS_KEY: EQU CTRL_O
FALSE: EQU 0
TRUE: EQU 1
BUFLEN: EQU 1024
section ST,CODE
push d2-d7/a2-a6
push d0/a0
sub.l a1,a1 ;Find our task
lib Exec,FindTask
move.l d0,OurTask
openlib Dos,NoDos ;Keep at beginning
CLIStart: lib Dos,Output
move.l d0,_stdout
lib Dos,Input
move.l d0,_stdin
move.l d0,d1
lib Dos,IsInteractive
tst.l d0
beq NotInteractive
pull d0/a0
clr.b -1(a0,d0.l)
cmp.b #'?',(a0)
beq Usage
cmp.w #'-?',(a0)
beq Usage
cmp.w #'-h',(a0)
beq Usage
Cont0.2: bsr ConvASCII
tst.w d0
beq Cont1
move.w d0,SerUnit
Cont1: cmp.b #' ',(a0)
bne Cont1.1
add.l #1,a0
Cont1.1: tst.b (a0)
beq Cont1.2
move.l a0,SerName
Cont1.2:
;Create read reply port for serial.device (or modem0.device etc.)
MainStart: lib Exec,CreateMsgPort
move.l d0,SRRPort
beq NoMsgPort
;Create read IOReq for serial.device (or for other device, but size is EXTSER)
move.l #IOEXTSER_SIZE,d0
move.l SRRPort,a0
lib Exec,CreateIORequest
move.l d0,IORRequest
beq NoIOReq
move.l IORRequest,a1
move.w #CMD_READ,IO_COMMAND(a1)
lea.l Buffer2,a0
move.l a0,IO_DATA(a1)
;Create write reply port for serial.device (or modem0.device etc.)
lib Exec,CreateMsgPort
move.l d0,SWRPort
beq NoMsgPort
;Create write IOReq for serial.device (or for other device, but size is EXTSER)
move.l #IOEXTSER_SIZE,d0
move.l SWRPort,a0
lib Exec,CreateIORequest
move.l d0,IOWRequest
beq NoIOReq
move.l IOWRequest,a1
move.w #CMD_WRITE,IO_COMMAND(a1)
move.l #1,IO_LENGTH(a1) ;writes in one byte "chunks"
lea.l Buffer1,a0
move.l a0,IO_DATA(a1)
;open serial.device
move.l SerName,a0
move.l SerUnit,d0
move.l IORRequest,a1
move.b #SERF_SHARED,IO_SERFLAGS(a1)
clr.l d1 ;no flags
lib Exec,OpenDevice
tst.l d0
bne NoSerial
move.w #$1,SerOpen ;just to tell if open
;Copy info from one req to the other
move.l IORRequest,a0
move.l IOWRequest,a1
move.l IO_DEVICE(a0),IO_DEVICE(a1)
move.l IO_UNIT(a0),IO_UNIT(a1)
lea.l StartText1,a0
bsr Printer
;Change mode for CLI to RAW:
move.l _stdin,d1
move.l #TRUE,d2
lib Dos,SetMode
bsr Reader
;LOOP
;waitfor char(shell,5000)
;if char
; IF 'EXIT' then exit
; ELSE write to serial
;ENDIF
;
;checkIO(readrequest)
;if done write to shell
;read 1 char from serial (immediate return)
;
;ELSE goto LOOP
Looper: move.l _stdin,d1
move.l #5000,d2
lib Dos,WaitForChar
tst.l d0
beq Looper1
move.l _stdin,d1
lea.l Buffer1,a0
move.l a0,d2
move.l #1,d3
lib Dos,Read
cmp.b #QUIT_KEY,Buffer1
beq Menu
bsr Writer
Looper1: bsr Read
tst.l d0
beq Looper
move.l _stdout,d1
lea.l Buffer3,a0
move.l a0,d2
move.l d0,d3
lib Dos,Write
bra Looper
Menu: lea.l MenuText1,a0
bsr Printer
Menu1: move.l _stdin,d1
lib Dos,FGetC
cmp.l #-1,d0
beq ShutDown
cmp.l #'1',d0
beq DoStats
cmp.l #'2',d0
beq ClearReceived
cmp.l #'3',d0
beq ClearSent
cmp.l #'4',d0
beq ClearBoth
cmp.l #'5',d0
beq DoCTRL_P
cmp.l #'6',d0
beq DoReset
cmp.l #'7',d0
beq DoHangUp
cmp.l #'8',d0
beq DoInfo
cmp.l #'9',d0
beq Quit
cmp.l #'0',d0
bne Menu2
lea.l ExitText1,a0
bsr Printer
bra Looper1
Menu2: bra Menu1
DoStats: lea.l StatsText2,a0
bsr Printer
lea.l CRLFText1,a0
bsr Printer
bsr GiveStats
bra Exit
ClearReceived: lea.l ClearText1,a0
bsr Printer
clr.l Received
bra Exit
ClearSent: lea.l ClearText1,a0
bsr Printer
clr.l Sent
bra Exit
ClearBoth: lea.l ClearText1,a0
bsr Printer
clr.l Received
clr.l Sent
bra Exit
DoCTRL_P: move.b CTRL_P,Buffer1
bsr Writer
lea.l CTRL_PText1,a0
bsr Printer
add.l #1,Sent
bra Exit
DoReset: lea.l ResetText1,a0
bsr Printer
lea.l ResetText2,a1
bsr GetLength
add.l d0,Sent
lea.l ResetText2,a0
bsr Writer2
bra Exit
DoHangUp: lea.l HangUpText1,a0
bsr Printer
move.l #55,d1
lib Dos,Delay
lea.l HangUpText2,a1
bsr GetLength
add.l d0,Sent
lea.l HangUpText2,a0
bsr Writer2
move.l #55,d1
lib Dos,Delay
lea.l HangUpText3,a1
bsr GetLength
add.l d0,Sent
lea.l HangUpText3,a0
bsr Writer2
bra Exit
DoInfo: lea.l InfoText1,a0
bsr Printer
lea.l AuthorText1,a0
bsr Printer
bra Exit
Quit: lea.l QuitText1,a0
bsr Printer
lea.l CRLFText1,a0
bsr Printer
bsr GiveStats
bra ShutDown
Exit: lea.l TerminalText1,a0
bsr Printer
bra Looper1
Break: lea.l BreakText1,a0
bsr Printer
clr.l d0
rts
ClearSer: move.l IORRequest,a1
lib Exec,CheckIO
tst.l d0
beq ClearSer1
move.l IORRequest,a1
lib Exec,WaitIO
ClearSer1: move.l IORRequest,a1
ABORTIO
move.l IORRequest,a1
lib Exec,WaitIO
rts
;Buffered read from a device
;
;Inputs d0 = Buffer length (maximum amount to read)
;
;Result d0 = amount read
;
Read: push d2-d7/a2-a6
move.l d0,d4
tst.w Requested
beq Read3
move.l SRRPort,a0
lib Exec,GetMsg
tst.l d0
beq Read_OUT1
move.l IORRequest,a1
tst.b IO_ERROR(a1)
beq Read1
clr.w Requested
bra Read_OUT1
Read1: add.l #1,Received
move.b Buffer2,Buffer3
move.l #1,BufCount
bra Read3
Read2: clr.l BufCount
Read3: move.l IORRequest,a1
clr.b IO_ERROR(a1)
or.b #IOF_QUICK,IO_FLAGS(a1)
move.w #1,Requested
ReadLoop: cmp.l BufCount,d4
beq Read_OUT2
move.l IORRequest,a1
BEGINIO
move.l IORRequest,a1
tst.b IO_ERROR(a1)
beq ReadLoop1
move.l SRRPort,a0
lib Exec,GetMsg
clr.w Requested
bra Read_OUT2
ReadLoop1: move.l IORRequest,a1
move.b IO_FLAGS(a1),d0
and.b #IOF_QUICK,d0
beq Read_OUT2
add.l #1,Received
lea.l Buffer3,a0
add.l BufCount,a0
move.b Buffer2,(a0)
add.l #1,BufCount
cmp.b #LF,Buffer2
bne ReadLoop
move.l IORRequest,a1
move.b IO_FLAGS(a1),d0
and.b #~IOF_QUICK,d0
move.b d0,IO_FLAGS(a1)
BEGINIO
move.l IORRequest,a1
tst.b IO_ERROR(a1)
beq Read_OUT2
move.l SRRPort,a0
lib Exec,GetMsg
clr.w Requested
bra Read_OUT2
Read_OUT1: clr.l d0
pull d2-d7/a2-a6
rts
Read_OUT2: move.l BufCount,d0
pull d2-d7/a2-a6
rts
Reader: move.l IORRequest,a1
move.w #CMD_READ,IO_COMMAND(a1)
move.l #1,IO_LENGTH(a1)
lea.l Buffer2,a0
move.l a0,IO_DATA(a1)
lib Exec,SendIO
rts
Writer: add.l #1,Sent
move.l IOWRequest,a1
lib Exec,DoIO ;May freeze, too bad
rts
;Writes string to serial port
;
;D0 = Length
;A0 = String
Writer2: move.l IOWRequest,a1
move.w #CMD_WRITE,IO_COMMAND(a1)
move.l d0,IO_LENGTH(a1)
move.l a0,IO_DATA(a1)
lib Exec,DoIO ;May freeze, too bad
;Reset back to default...
move.l IOWRequest,a1
move.w #CMD_WRITE,IO_COMMAND(a1)
move.l #1,IO_LENGTH(a1) ;writes in one byte "chunks"
lea.l Buffer1,a0
move.l a0,IO_DATA(a1)
rts
GiveStats: lea.l fstrl1,a0 ;HEX->ASCII
lea.l Received,a1 ;Number2Print
lea.l PutChProc,a2
lea.l ReceivedText1,a3 ;Destination
lib Exec,RawDoFmt
lea.l fstrl2,a0 ;HEX->ASCII
lea.l Sent,a1 ;Number2Print
lea.l PutChProc,a2
lea.l SentText1,a3 ;Destination
lib Exec,RawDoFmt
lea.l StatsText1,a0
bsr Printer
lea.l ReceivedText1,a0
bsr Printer
lea.l SentText1,a0
bsr Printer
lea.l CRLFText1,a0
bsr Printer
rts
ShutDown: tst.w SerOpen
beq ShutDown9000
bsr ClearSer
move.l IORRequest,a1
lib Exec,CloseDevice
ShutDown9000: move.l IORRequest,a0
lib Exec,DeleteIORequest
ShutDown8000: move.l SRRPort,a0
lib Exec,DeleteMsgPort
ShutDown7000: move.l IOWRequest,a0
lib Exec,DeleteIORequest
ShutDown6000: move.l SWRPort,a0
lib Exec,DeleteMsgPort
ShutDown5000: move.l _stdin,d1
beq ShutD