home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
perqa.tar.gz
/
perqa.tar
/
connect232.pas
next >
Wrap
Pascal/Delphi Source File
|
1984-12-04
|
6KB
|
199 lines
MODULE Connect232 ;
(*)
* A communications routine via the RS232 line to another host.
* Parameters are:
*
* EscChar The "escape" character, when this character is read
* from the keyboard return to caller.
* HalfDuplex The state of the host's connection, if HalfDuplex is
* true echo the keyboard characters locally.
* TabletOk If true, the yellow button on the puck causes an
* exit too.
5-Oct-83. Change cursor shape and allow ANY puck button
to cause an exit.
* RETURN: ConCharExit if <EscChar> caused exit,
* ConButtonExit for puck button.
(*)
EXPORTS (*-------------*)
IMPORTS IO_Unit FROM IO_Unit;
IMPORTS IOErrors FROM IOErrors;
TYPE
(* What caused "Connect" to exit *)
ConExitFlag = (ConCharExit, ConButtonExit) ;
FUNCTION Connect( EscChar: Char; HalfDuplex, TabletOk: Boolean ) : ConExitFlag;
PRIVATE (*---------------*)
IMPORTS Screen FROM Screen ;
IMPORTS System FROM System ;
IMPORTS IO_Others FROM IO_Others;
FUNCTION Connect( EscChar: Char; HalfDuplex, TabletOk: Boolean ) : ConExitFlag;
CONST
NUL = Chr(#000) ;
BS = Chr(#010) ;
TAB = Chr(#011) ;
LF = Chr(#012) ;
CR = Chr(#015) ;
CtrlQ = Chr(#021) ;
CtrlS = Chr(#023) ;
VAR
hpos: Integer ; (* current position in the line (for tabs) *)
oldX, oldY: Integer ; (* Old cursor offsets *)
quit: Boolean ; (* loop control *)
LineChr, KeyChr: Char; (* current RS232 and keyboard characters *)
OldCurs, NewCurs: CurPatPtr ; (* Old and New cursors (if TabletOk) *)
return: ConExitFlag ; (* the exit flag *)
PROCEDURE WriteChr( c: Char ) ;
BEGIN
SPutChr( c ) ;
Hpos := Hpos + 1
END ;
HANDLER CtlC ;
BEGIN
END ;
BEGIN (*-Connect-*)
(* Allocate cursor space *)
New( 0, 4, NewCurs) ;
New( 0, 4, OldCurs) ;
(* Clear the cursor area *)
RasterOp(RXor, 64, 64, 0, 0, 4, RECAST(NewCurs, RasterPtr),
0, 0, 4, RECAST(NewCurs, RasterPtr) ) ;
(* Cursor values from file: Connect3.Cursor *)
NewCurs^[ 0,0] := #40 ;
NewCurs^[ 1,0] := #120 ;
NewCurs^[ 1,1] := #1642 ;
NewCurs^[ 1,2] := #167000 ;
NewCurs^[ 2,0] := #210 ;
NewCurs^[ 2,1] := #1024 ;
NewCurs^[ 2,2] := #42000 ;
NewCurs^[ 3,0] := #404 ;
NewCurs^[ 3,1] := #1610 ;
NewCurs^[ 3,2] := #42000 ;
NewCurs^[ 4,0] := #1002 ;
NewCurs^[ 4,1] := #1024 ;
NewCurs^[ 4,2] := #42000 ;
NewCurs^[ 5,0] := #404 ;
NewCurs^[ 5,1] := #1642 ;
NewCurs^[ 5,2] := #162000 ;
NewCurs^[ 6,0] := #2211 ;
NewCurs^[ 7,0] := #5122 ;
NewCurs^[ 7,1] := #100000 ;
NewCurs^[ 8,0] := #10444 ;
NewCurs^[ 8,1] := #40000 ;
NewCurs^[ 9,0] := #20210 ;
NewCurs^[ 9,1] := #20000 ;
NewCurs^[10,0] := #40120 ;
NewCurs^[10,1] := #10000 ;
NewCurs^[11,0] := #20210 ;
NewCurs^[11,1] := #20000 ;
NewCurs^[12,0] := #10444 ;
NewCurs^[12,1] := #40000 ;
NewCurs^[13,0] := #5122 ;
NewCurs^[13,1] := #100000 ;
NewCurs^[14,0] := #2211 ;
NewCurs^[15,0] := #404 ;
NewCurs^[16,0] := #1002 ;
NewCurs^[17,0] := #404 ;
NewCurs^[18,0] := #210 ;
NewCurs^[19,0] := #120 ;
NewCurs^[20,0] := #40 ;
(* Debug :- %)
Writeln('TabletOk = ', TabletOk) ;
(% Debug *)
SCurOn ; (* ? *)
(* Set up our cursor, or turn the cursor off if we can't use a cursor *)
IF TabletOk THEN
BEGIN
IOReadCursPicture( OldCurs, oldX, oldY ) ;
IOLoadCursor( NewCurs, 0, 0) ;
IOSetModeTablet( relTablet ) ;
IOCursorMode( TrackCursor )
END
ELSE
IOCursorMode( OffCursor ) ; (* Turn it off *)
return := ConCharExit ; (* Assume the exit by escape char *)
quit := False ;
WHILE NOT quit DO
BEGIN
(*---------- RS232 Input ----------*)
IF (IOCRead(RS232In, LineChr)=IOEIOC) THEN
BEGIN
LineChr := Chr( Land( Ord(LineChr), #177) ) ;
IF (LineChr = TAB) THEN
BEGIN
WriteChr( ' ' ) ;
WHILE (Hpos MOD 8) <> 0 DO WriteChr( ' ' )
END
ELSE
IF (LineChr = BS) THEN
BEGIN
IF Hpos > 0 THEN
BEGIN (* Delete the character *)
SBackSpace( ' ' );
SPutChr( ' ' ) ;
SBackSpace( ' ' ) ;
Hpos := Hpos - 1
END
END
ELSE
IF (LineChr IN [NUL, CtrlS, CtrlQ]) THEN (* NOTHING *)
ELSE
WriteChr( LineChr ) ; (* write it *)
IF (LineChr IN [CR, LF]) THEN Hpos := 0 ; (* a new line *)
END ; (* RS232 input *)
(*---------- Keyboard Input ----------*)
IF (IOCRead(TransKey, KeyChr)=IOEIOC) THEN
BEGIN
IF (KeyChr = EscChar) THEN
BEGIN
quit := True
END
ELSE
BEGIN
IF IOCWrite(RS232Out, KeyChr)<>IOEIOC THEN
KeyChr := Chr(#277) ;
IF HalfDuplex THEN WriteChr( KeyChr )
END
END ; (* Keyboard input *)
(*---------- Tablet Input ----------*)
IF TabletOk AND TabSwitch THEN
BEGIN
return := ConButtonExit ;
quit := True
END
END ; (* while *)
(* Restore cursor *)
IF TabletOk THEN IOLoadCursor( OldCurs, oldX, oldY )
ELSE IOCursorMode( TrackCursor ) ; (* I assume it was originally on *)
Dispose( NewCurs ) ;
Connect := return
END . (*-Connect-*)