Category : Modula II Source Code
Archive   : PCKERM.ZIP
Filename : SHELL.MOD

 
Output of file : SHELL.MOD contained in archive : PCKERM.ZIP
IMPLEMENTATION MODULE Shell; (* User interface for Kermit *)

FROM SYSTEM IMPORT
AX, BX, CX, DX, SETREG, SWI;

FROM Exec IMPORT
DosCommand;

FROM Terminal IMPORT
WriteString, WriteLn, KeyPressed, ReadString;

IMPORT Terminal; (* for Terminal.Write and Terminal.Read *)

FROM InOut IMPORT
WriteCard;

FROM RS232Int IMPORT
Init, StartReading, StopReading;

IMPORT RS232Int; (* for RS232Int.Write and RS232Int.BusyRead *)

FROM Strings IMPORT
Length, Concat;

FROM NumberConversion IMPORT
StringToCard;

IMPORT ASCII;


VAR
baudRate : CARDINAL;
stopBits : CARDINAL;
parityBit : BOOLEAN;
evenParity : BOOLEAN;
nbrOfBits : CARDINAL;
OK : BOOLEAN;
echo : (Off, Local, On);
ch : CHAR;
str : ARRAY [0..10] OF CHAR;
n : CARDINAL;


PROCEDURE Initialize;
BEGIN
Init (baudRate, stopBits, parityBit, evenParity, nbrOfBits, OK);
END Initialize;


PROCEDURE ClrScr;
(* Clear the screen, and home the cursor *)
BEGIN
SETREG (AX, 0600H); (* function 6 = scroll or clear window *)
SETREG (BX, 0700H); (* 7 = normal screen attribute *)
SETREG (CX, 0000H); (* top LH of screen *)
SETREG (DX, 184FH); (* bottom RH of screen *)
SWI (10H); (* call bios *)
SETREG (AX, 0200h); (* function 2 = position cursor *)
SETREG (BX, 0000H); (* page 0 *)
SETREG (DX, 0000H); (* home position *)
SWI (10H); (* call bios *)
END ClrScr;


PROCEDURE CommHelp;
(* help menu for communications options *)
BEGIN
ClrScr;
WriteString (" C o m m u n i c a t i o n s O p t i o n s");
WriteLn;
WriteString (" H e l p M e n u");
WriteLn; WriteLn;
WriteString ("set Baud rate ................................ B");
WriteLn;
WriteString ("set Parity ................................... P");
WriteLn;
WriteString ("set Word length .............................. W");
WriteLn;
WriteString ("set Stop bits ................................ S");
WriteLn;
WriteString ("eXit ......................................... X");
WriteLn;
END CommHelp;


PROCEDURE dispOpts;
(* Display communications parameters for the user *)
BEGIN
WriteLn;
WriteString ("Baud rate = "); WriteCard (baudRate, 0);
WriteString ("; ");
IF parityBit THEN
IF evenParity THEN
WriteString ("Even ");
ELSE
WriteString ("Odd ");
END;
ELSE
WriteString ("No ");
END;
WriteString ("parity; ");
WriteCard (nbrOfBits, 0);
WriteString (" Data bits; ");
IF stopBits = 1 THEN
WriteString ("One stop bit.");
ELSE
WriteString ("Two stop bits.");
END;
WriteLn;
END dispOpts;


PROCEDURE Options;
(* set communications options *)

VAR
Quit : BOOLEAN;

BEGIN
ClrScr;
Quit := FALSE;
dispOpts;

REPEAT
WriteLn; WriteLn;
WriteString ("Set Communications Options [B, P, W, S, X, ?]: ");
LOOP
Terminal.Read (ch);
CASE CAP (ch) OF
'B' : Baud; EXIT;
| 'P' : Parity; EXIT;
| 'W' : Word; EXIT;
| 'S' : Stops; EXIT;
| '?' : CommHelp; EXIT;
| 'X' : Quit := TRUE; EXIT;
ELSE
(* ignore *)
END;
END;
IF Quit THEN
ClrScr;
ELSE
Initialize;
dispOpts;
END;
UNTIL Quit;
END Options;


PROCEDURE Baud;
(* Allow user to change the bit rate of the communications port *)
BEGIN
WriteString ("Baud Rate? [110 - 9600]: ");
ReadString (str);
IF Length (str) # 0 THEN
StringToCard (str, n, OK);
IF OK THEN
CASE n OF
110, 150, 300, 600, 1200, 2400, 4800, 9600 : baudRate := n;
ELSE
(* do nothing *)
END;
END;
END;
END Baud;


PROCEDURE Word;
(* Allow user to change the word length of the communications port *)
BEGIN
WriteString ("Word Length? [7, 8]: ");
ReadString (str);
IF Length (str) # 0 THEN
StringToCard (str, n, OK);
IF OK AND (n IN {7, 8}) THEN
nbrOfBits := n;
END;
END;
END Word;


PROCEDURE Parity;
(* Allow user to change the parity bit of the communications port *)
BEGIN
WriteString ("Parity? [None, Even, Odd]: ");
ReadString (str);
IF Length (str) # 0 THEN
CASE CAP (str[0]) OF
'N' : parityBit := FALSE;
| 'E' : parityBit := TRUE; evenParity := TRUE;
| 'O' : parityBit := TRUE; evenParity := FALSE;
ELSE
(* no action *)
END;
END;
END Parity;


PROCEDURE Stops;
(* Allow user to change the number of stop bits *)
BEGIN
WriteString ("Stop Bits? [1, 2]: ");
ReadString (str);
IF Length (str) # 0 THEN
StringToCard (str, n, OK);
IF OK AND (n IN {1, 2}) THEN
stopBits := n;
END;
END;
END Stops;


PROCEDURE Dir;

VAR
done, gotFN : BOOLEAN;
path : ARRAY [0..60] OF CHAR;
filename : ARRAY [0..20] OF CHAR;
i, j, k : INTEGER;

BEGIN
filename := ""; (* in case no directory change *)
WriteString ("Path? (*.*): ");
ReadString (path);
i := Length (path);
IF i # 0 THEN
gotFN := FALSE;
WHILE (i >= 0) AND (path[i] # '\') DO
IF path[i] = '.' THEN
gotFN := TRUE;
END;
DEC (i);
END;
IF gotFN THEN
j := i + 1;
k := 0;
WHILE path[j] # 0C DO
filename[k] := path[j];
INC (k); INC (j);
END;
filename[k] := 0C;
IF (i = -1) OR ((i = 0) AND (path[0] = '\')) THEN
INC (i);
END;
path[i] := 0C;
END;
END;
IF Length (path) # 0 THEN
DosCommand ("CHDIR", path, done);
END;
IF Length (filename) = 0 THEN
filename := "*.*";
END;
Concat (filename, "/w", filename);
ClrScr;
DosCommand ("DIR", filename, done);
END Dir;


PROCEDURE ConnectHelp;
(* provide help while in connect mode *)
BEGIN
ClrScr;
WriteString ("LOCAL COMMANDS:"); WriteLn;
WriteString ("^E = Echo mode"); WriteLn;
WriteString ("^L = Local echo mode"); WriteLn;
WriteString ("^T = Terminal mode (no echo)"); WriteLn;
WriteString ("^X = eXit from connect"); WriteLn;
WriteLn; WriteLn;
END ConnectHelp;


PROCEDURE Connect;
(* Terminal mode allows connection to host (possibly through MODEM) *)

VAR
Input : BOOLEAN;

BEGIN
ConnectHelp;

REPEAT
RS232Int.BusyRead (ch, Input);
IF Input THEN
IF ((ch >= 40C) AND (ch < 177C))
OR (ch = ASCII.cr) OR (ch = ASCII.lf) OR (ch = ASCII.bs) THEN
Terminal.Write (ch);
END;
IF echo = On THEN
RS232Int.Write (ch);
END;
END;

IF KeyPressed() THEN
Terminal.Read (ch);
IF ch = ASCII.enq THEN (* Control-E *)
echo := On;
ELSIF ch = ASCII.ff THEN (* Control-L *)
echo := Local;
ELSIF ch = ASCII.dc4 THEN (* Control-T *)
echo := Off;
ELSIF ((ch >= 40C) AND (ch < 177C))
OR (ch = ASCII.EOL) OR (ch = ASCII.bs) THEN
IF ch = ASCII.EOL THEN
RS232Int.Write (ASCII.cr);
RS232Int.Write (ASCII.lf);
ELSE
RS232Int.Write (ch);
END;
IF (echo = On) OR (echo = Local) THEN
Terminal.Write (ch);
END;
END;
END;
UNTIL ch = ASCII.can; (* Control-X *)
END Connect;


PROCEDURE eXit (VAR q : BOOLEAN);
(* Allow user to exit program after prompting for confirmation *)
BEGIN
WriteString ("Exit PCKermit? [Y/N]: ");
Terminal.Read (ch);
IF CAP (ch) = 'Y' THEN
Terminal.Write ('Y');
StopReading; (* turn off the serial port *)
q := TRUE;
ELSE
Terminal.Write ('N');
END;
WriteLn;
END eXit;


PROCEDURE MainHelp;
(* help menu for main program loop *)
BEGIN
ClrScr;
WriteString (" P C K e r m i t H e l p M e n u"); WriteLn;
WriteLn;
WriteString ("set communications Options ............. O");
WriteLn;
WriteString ("Connect to host ........................ C");
WriteLn;
WriteString ("Directory .............................. D");
WriteLn;
WriteString ("Send a file ............................ S");
WriteLn;
WriteString ("Receive a file ......................... R");
WriteLn;
WriteString ("eXit ................................... X");
WriteLn; WriteLn;
WriteString ("To establish connection to Host:"); WriteLn;
WriteString (" -Use Connect Mode"); WriteLn;
WriteString (" -Dial Host (AT command set?)"); WriteLn;
WriteString (" -Log On to Host"); WriteLn;
WriteString (" -Issue Send (or Receive) command"); WriteLn;
WriteString (" -Return to main menu (^X)"); WriteLn;
WriteString (" -Issue Receive (or Send) command"); WriteLn;
WriteLn;
END MainHelp;


BEGIN (* module initialization *)
ClrScr;
baudRate := 1200;
stopBits := 1;
parityBit := TRUE;
evenParity := TRUE;
nbrOfBits := 7;
Initialize;
StartReading; (* turn on the serial port *)
echo := Off;
END Shell.

  3 Responses to “Category : Modula II Source Code
Archive   : PCKERM.ZIP
Filename : SHELL.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/