home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8603.arc
/
BERGLST1.MAR
next >
Wrap
Text File
|
1986-03-31
|
3KB
|
136 lines
{task #1: keyboard -> serial out
task #2: serial in -> video out
control-C will abort program}
program main;
const TASKS=2;
STACKSIZE=70;
{next 7 constants are needed for the Kaypro}
KDATA=5;
KSTAT=7;
BAUDP=0;
SDATA=4;
SSTAT=6;
RMASK=1;
TMASK=4;
CC=3;
type stack = array[0..STACKSIZE] of integer;
tasknum = -1..TASKS;
var sp0,sp1,sp2: integer;{when zero, task not initialized}
oldn: tasknum;
nextn: tasknum;
Procedure defer; forward;
procedure exit;
begin
writeln('TASK #',oldn,' terminated.');
oldn:=-1;
defer;
end;
function keyin:byte;
begin
repeat
defer;
until (RMASK = (RMASK and port[KSTAT]));
keyin:= port[KDATA];
end;
procedure videout(b:byte);
begin
bdos(6,b);
end;
function serin: byte;
begin
repeat
defer;
until (RMASK = (RMASK and port[SSTAT]));
serin:= port[SDATA];
end;
procedure serout(b:byte);
begin
repeat
defer;
until (TMASK = (TMASK and port[SSTAT]));
port[SDATA]:=b;
end;
.ne 10
Procedure task1;
var mystack: stack;
key: byte;
begin
stackptr:=addr(mystack[STACKSIZE]);
repeat
key:=keyin;
if key=CC then exit
else serout(key);
until false;{forever}
exit;
end;
Procedure task2;
var mystack: stack;
begin
stackptr:=addr(mystack[STACKSIZE]);
repeat
videout(serin);
until false{forever};
exit;
end;
procedure initall;
var i: integer;
Begin
sp1:=0;
sp2:=0;
oldn:=0;
{initialize Kaypro's SIO}
port[BAUDP]:=14;{9600 Baud}
port[SSTAT]:=24;
port[SSTAT]:=4;
port[SSTAT]:=68;
port[SSTAT]:=1;
port[SSTAT]:=0;
port[SSTAT]:=3;
port[SSTAT]:=193;
port[SSTAT]:=5;
port[SSTAT]:=234;
end;
Procedure schedule;
begin
if oldn=TASKS then nextn:=1
else nextn:=oldn+1;
end;
.bp
procedure defer;
var sp: integer;
begin
case oldn of
0: sp0:=stackptr;
1: sp1:=stackptr;
2: sp2:=stackptr;
end{case};
schedule;
oldn:=nextn;
case nextn of
0: sp:=sp0;
1: sp:=sp1;
2: sp:=sp2;
end{case};
if sp<>0 {initialized}
then begin
stackptr:=sp;
end
else {not initialized}
begin
writeln('Starting task #',nextn);
case nextn of
1: task1;
2: task2;
end{case};
end;
end{defer};
begin{main}
initall;
writeln('Multitasking version of simple terminal program');
writeln('Control-C will terminate it');
writeln;
defer;
writeln('Main: done');
end.