perm filename IAUX1B.2[EAL,HE]1 blob
sn#677500 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00005 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN More auxilliary routines for Interpreter }
C00033 00003 { Externally defined routines: }
C00036 00004 (* aux io routines: prntSval, prntVec, prntTrans, prntStrng, prntPlist, onum, prntVar *)
C00044 00005 (* aux routines: addPdb, sleep, deClkQueue, msgDispatch, swap *)
C00063 ENDMK
C⊗;
{$NOMAIN More auxilliary routines for Interpreter }
const
(* Constants from EDIT *)
maxLines = 28; (* smaller on the 11 than on the 10 *)
maxPPLines = 18;
maxBpts = 25;
maxTBpts = 20; (* max could be exceeded by huge case stmnt *)
listinglength = 2000; (* Length of Listingarray *)
(* Random type declarations for OMSI/SAIL compatibility *)
type
byte = 0..255; (* doesn't really belong here, but... *)
ascii = char;
atext = text;
{ Define all the pointer types here }
vectorp = ↑vector;
transp = ↑trans;
strngp = ↑strng;
eventp = ↑event;
framep = ↑frame;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
pdbp = ↑pdb;
envheaderp = ↑envheader;
enventryp = ↑enventry;
environp = ↑environment;
cmoncbp = ↑cmoncb;
messagep = ↑message;
dump = ↑integer;
token = array[1..4] of integer;
cursorp = array[1..4] of integer;
(* datatype definitions *)
datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
frametype, eventtype, strngtype, labeltype, proctype, arraytype,
reftype, valtype, cmontype, nulltype, undeftype,
dimensiontype, mactype, macargtype, freevartype);
scalar = real;
u = (used,free);
vector = record case u of
used: (refcnt: integer; val: array [1..3] of real);
free: (next: vectorp);
end;
trans = record case u of
used: (refcnt: integer; val: array [1..3,1..4] of real);
free: (next: transp);
end;
cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;
strng = record
next: strngp;
ch: cstring;
end;
event = record
next: eventp; (* all events are on one big list *)
count: integer;
waitlist: pdbp;
end;
frame = record
vari: varidefp; (* back pointer to variable name & info *)
calcs: nodep; (* affixment info *)
case ftype: boolean of (* frame = true, device = false *)
true: (valid: integer; val, fdepr: transp; dcntr: integer; dev: framep);
false: (mech: integer; case sdev: boolean of
true: (sdest: real); false: (tdest,appr,depr: transp));
(* sdev = true for scalar devices, false for frames *)
end;
(* statement definitions *)
stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
fortype, iftype, whiletype, untiltype, casetype,
calltype, returntype,
printtype, prompttype, pausetype, aborttype, assigntype,
signaltype, waittype, enabletype, disabletype, cmtype,
affixtype, unfixtype,
movetype, operatetype, opentype, closetype, centertype,
stoptype, retrytype,
requiretype, definetype, macrotype, commenttype, dimdeftype,
setbasetype, wristtype, tovaltype, declaretype, emptytype);
(* more??? *)
(* auxiliary definitions: variable, etc. *)
varidef = packed record
next,dnext: varidefp;
name: dump;
level: 0..255; (* environment level *)
offset: 0..255; (* environment offset *)
dtype: varidefp; (* to hold the dimension info *)
tbits: 0..15; (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
dbits: 0..15; (* for use by debugger/interpreter *)
case vtype: datatypes of
arraytype: (a: nodep);
proctype: (p: nodep);
labeltype,
cmontype: (s: dump);
mactype: (mdef: dump);
macargtype: (marg: dump);
pconstype: (c: nodep);
dimensiontype: (dim: nodep);
end;
(* definition of the ubiquitous NODE record *)
nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
deprnode, viaptnode, apprnode, destnode, durnode,
sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
arrivalnode, departingnode,
ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
calcnode, arraydefnode, bnddefnode, bndvalnode,
waitlistnode, procdefnode, tlistnode, dimnode, commentnode);
exprtypes = ( svalop, (* scalar operators *)
sltop, sleop, seqop, sgeop, sgtop, sneop, (* relations *)
notop, orop, xorop, andop, eqvop, (* logical *)
saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
sexpop, maxop, minop, intop, idivop, modop,
sqrtop, logop, expop, timeop, (* functions *)
sinop, cosop, tanop, asinop, acosop, atan2op, (* trig *)
vdotop, vmagnop, tmagnop,
vecop, (* vector operators *)
vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
svmulop, vsmulop, vsdivop, tvmulop, wrtop,
tposop, taxisop,
transop, (* trans operators *)
tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
ioop, (* i/o operators *)
queryop, inscalarop,
specop, (* special operators *)
arefop, callop, grinchop, macroop, vmop, adcop, dacop,
badop,
addop, subop, negop, mulop, divop, absop); (* for parsing *)
leaftypes = pconstype..strngtype;
reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);
node = record
next: nodep;
case ntype: nodetypes of
exprnode: (op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
leafnode: (case ltype: leaftypes of
varitype: (vari: varidefp; vid: identp);
pconstype: (cname: varidefp; pcval: nodep);
svaltype: (s: scalar; wid: integer);
vectype: (v: vectorp);
transtype: (t: transp);
strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
listnode: (lval: nodep);
clistnode: (cval: integer; stmnt: dump; clast: nodep);
colistnode: (prev: nodep; cstmnt: dump);
forvalnode: (fvar: enventryp; fstep: scalar);
arrivalnode:(evar: varidefp);
deprnode,
apprnode,
destnode: (loc: nodep; code: dump);
viaptnode: (vlist: boolean; via,duration,velocity: nodep; vcode: dump);
durnode: (durrel: reltypes; durval: nodep);
sfacnode,
wobblenode,
swtnode: (clval: nodep);
nullingnode,
wristnode,
cwnode: (notp: boolean); (* true = nonulling/zero wrist/counter_clockwise *)
ffnode: (ff: nodep; csys, pdef: boolean); (* true = world, false = hand *)
forcenode: (ftype: forcetypes; frel: reltypes; fval, fvec, fframe: nodep);
stiffnode: (fv, mv, coc: nodep);
gathernode: (gbits: integer);
cmonnode: (cmon: dump; errhandlerp: boolean);
errornode: (eexpr: nodep);
calcnode: (rigid, frame1: boolean; other: framep; case tvarp: boolean of
false: (tval: transp); true: (tvar: enventryp) );
arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
bnddefnode: (lower, upper: nodep);
bndvalnode: (lb, ub, mult: integer);
waitlistnode: (who: pdbp; when: integer);
procdefnode:(ptype: datatypes; level: 0..255;
pname, paramlist: varidefp; body: dump);
tlistnode: (tok: dump);
dimnode: (time, distance, angle, dforce: integer);
end;
ident = record
next: identp;
length: integer;
name: strngp;
predefined: varidefp;
end;
(* process descriptor blocks & environment record definitions *)
queuetypes = (nullqueue,nowrunning,runqueue,inputqueue,eventqueue,sleepqueue,
forcewait,devicewait,joinwait,proccall);
pdb = packed record
nextpdb,next: pdbp; (* for list of all/active pdb's *)
level: 0..255; (* lexical level *)
mode: 0..255; (* expression/statement/sub-statement *)
priority: 0..255;
status: queuetypes; (* what are we doing *)
env: envheaderp;
spc: dump; (* current statement *)
epc: nodep; (* current expression (if any) *)
sp: nodep; (* intermediate value stack *)
cm: cmoncbp; (* if we're a cmon point to our definition *)
mech: framep; (* current device being used *)
linenum: integer; (* used by editor/debugger *)
case procp: boolean of (* true if we're a procedure *)
true: (opdb: pdbp; (* pdb to restore when procedure exits *)
pdef: nodep); (* procedure definition node *)
false: (evt: eventp; (* event to signal when process goes away *)
sdef: dump); (* first statement where process was defined *)
end;
envheader = packed record
parent: envheaderp;
env: array [0..4] of environp;
varcnt: 0..255; (* # of variables in use ??? *)
case procp: boolean of (* true if we're a procedure *)
true: (proc: nodep);
false:(block: dump);
end;
enventry = record
case etype: datatypes of
svaltype: (s: scalar);
vectype: (v: vectorp);
transtype: (t: transp);
frametype: (f: framep);
eventtype: (evt: eventp);
strngtype: (length: integer; str: strngp);
cmontype: (c: cmoncbp);
proctype: (p: nodep; penv: envheaderp);
reftype: (r: enventryp);
arraytype: (a: envheaderp; bnds: nodep);
end;
environment = record
next: environp;
vals: array [0..9] of enventryp;
end;
cmoncb = record
running, enabled: boolean; (* cmon's status *)
cmon: dump;
pdb: pdbp;
evt: eventp;
fbits: integer; (* bits for force sensing *)
oldcmon: cmoncbp; (* for debugger *)
end;
(* definition of AL-ARM messages *)
msgtypes = (initarmscmd,calibcmd,killarmscmd,wherecmd,
abortcmd,stopcmd,movehdrcmd,movesegcmd,
centercmd,operatecmd,movedonecmd,signalcmd,readjtcmd,drivecmd,
setccmd,forcesigcmd,forceoffcmd,biasoncmd,biasoffcmd,setstiffcmd,
zerowristcmd,wristcmd,gathercmd,getgathercmd,readadccmd,writedaccmd,
errorcmd,floatcmd);
errortypes = (noerror,noarmsol,timerr,durerr,toolong,useopr,nosuchdev,featna,
unkmess,srvdead,adcdead,nozind,exjtfc,paslim,nopower,badpot,devbusy,
baddev,timout,panicb);
message = record
cmd: msgtypes;
ok: boolean;
case integer of
1: (dev, bits, n: integer;
(* (dev, bits, n, evt: integer; (* for arm code version *)
evt: eventp;
dur: real;
case integer of
1: (v1,v2,v3: real);
2: (sfac,wobble,pos: real);
3: (val,angle,mag: real);
4: (max,min: real);
5: (error: errortypes));
2: (fv1,fv2,fv3,mv1,mv2,mv3: real); (* may never use these... *)
3: (t: array [1..6] of real);
end;
interr = record
case integer of
0: (i: integer);
1: (err,foo: errortypes);
end;
(* Global variables *)
var
(* From ALMAIN *)
b:boolean;
ch:ascii;
ltime: real;
(* From PARSE *)
reswords: array [0..26] of dump;
idents: array [0..26] of dump;
macrostack: array [1..10] of dump;
curmacstack: array [1..10] of varidefp;
macrodepth: integer;
curchar, maxchar, curline: integer;
curBlock,newDeclarations: dump;
curProc: varidefp;
pnode: nodep;
nodim, distancedim, timedim, angledim,
forcedim, torquedim, veldim, angveldim: varidefp;
fvstiffdim, mvstiffdim: nodep;
filedepth: integer;
curpage: integer;
sysVars,unVars: varidefp;
errcount: integer;
outerBlock: dump;
curVariable: varidefp;
curMotion: dump;
endOk,coendOk: integer;
moveLevel: integer;
curErrhandler, curCmon: dump;
endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
semiseen, shownline: boolean;
eofError: boolean;
inMove,inCoblock: boolean;
curtoken: token;
file1,file2,file3,file4,file5: atext;
line: linestr;
(* From INTERP *)
curInt, activeInts, readQueue, allPdbs: pdbp;
curEnv, sysEnv: envheaderp;
clkQueue: nodep;
allEvents: eventp;
STLevel: integer; (* set by GO *)
etime: integer; (* used by eval *)
curtime: integer; (* Time of day, in ticks *)
stime: integer; (* used for clock queue on 10 *)
msg: messagep; (* for AL-ARM interaction *)
inputp: integer; (* current offset into inputLine array above *)
debugLevel: integer;
tSingleThreadMode: boolean;
resched, running, escapeI, singleThreadMode: boolean;
msgp: boolean; (* flag set if any messages pending *)
inputReady: boolean;
inputLine: array [1..20] of ascii;
(* From EDIT *)
lines: array [1..maxLines] of dump;
ppLines: array [1..maxPPLines] of dump;
marks: array [1..20] of integer;
cursorStack: array [1..15] of cursorp;
bpts: array [1..maxBpts] of dump;
tbpts: array [1..maxTBpts] of dump;
debugPdbs: array [0..10] of pdbp;
screenheight,dispHeight: integer;
ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
firstDline,topDline,botDline,firstLine,lastLine: integer;
freeLines,oldLines: dump;
findStmnt: dump;
nbpts,ntbpts: integer;
eCurInt: pdbp;
dProg: dump;
smartTerminal: boolean;
setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
eBackup: boolean;
eSingleThreadMode: boolean;
listing: packed array [0..listinglength] of ascii;
lbuf: array [1..160] of ascii;
ppBuf: array [1..100] of ascii;
outFile: atext;
eCurToken: token;
(* Various device & variable pointers *)
speedfactor: enventryp;
barm: framep;
(* Various constant pointers *)
xhat,yhat,zhat,nilvect: vectorp;
niltrans: transp;
bpark, ypark, gpark, rpark: transp; (* arm park positions *)
{ Externally defined routines: }
(* From ALLOC *)
procedure relVector(v: vectorp); external;
procedure relTrans(t: transp); external;
function newNode: nodep; external;
procedure relNode(n: nodep); external;
procedure relEvent(n: eventp); external;
(* Display-related Routines *)
procedure ppLine; external;
procedure ppOutNow; external;
procedure ppChar(ch: ascii); external;
procedure pp5(ch: c5str; length: integer); external;
procedure pp10(ch: cstring; length: integer); external;
procedure pp10L(ch: cstring; length: integer); external;
procedure pp20(ch: c20str; length: integer); external;
procedure pp20L(ch: c20str; length: integer); external;
procedure ppInt(i: integer); external;
procedure ppStrng(length: integer; s: strngp); external;
(* From IAUX1B.MAC *)
procedure getTime(var curTime: integer); external;
procedure clrTimeQueue; external;
(* From IROOT *)
function i1bTaxis (t: transp): vectorp; external;
function i1bTmagn (t: transp): scalar; external;
(* From CALLER *)
procedure i1bPpReal(r: real); external;
procedure markTime(when: integer; var curTime,stime: integer); external;
procedure iAux1bGet; external;
procedure iAux1bGet; begin end; { Used only to read in this overlay }
function pop: nodep; (* Copied from IAUX1 - not externally available *)
begin
pop := curInt↑.sp;
if curInt↑.sp = nil then
begin (* **** error - stack underflow **** *)
pp20L('Value Stack Underflo',20); ppChar('w'); ppLine;
(* code to show where error occurred & to maybe recover??? *)
end
else curInt↑.sp := curInt↑.sp↑.next;
end;
(* aux io routines: prntSval, prntVec, prntTrans, prntStrng, prntPlist, onum, prntVar *)
procedure prntSval(s: real); external;
procedure prntSval;
var si: real;
begin
si := trunc(s);
i1bPpReal(si + round(1000*(s-si))/1000);
end;
procedure prntVec(v: vectorp); external;
procedure prntVec;
var i: integer;
begin
pp10('vector( ',7);
with v↑ do
for i := 1 to 3 do
begin
prntSval(val[i]);
if i = 3 then ppChar(')') else ppChar(',');
end;
ppOutNow;
end;
procedure prntTrans(t: transp); external;
procedure prntTrans;
var i: integer; v: vectorp;
begin
with t↑ do
begin
refcnt := refcnt + 1;
pp10('trans(rot(',10);
v := i1bTaxis(t); prntVec(v); relVector(v);
ppChar(',');
prntSval(i1bTmagn(t));
pp10('),vector( ',9);
for i := 1 to 3 do
begin prntSval(val[i,4]); if i = 3 then ppChar(')') else ppChar(',') end;
ppChar(')');
refcnt := refcnt - 1;
end;
ppLine;
end;
procedure prntStrng(length: integer; s: strngp); external; (* Also in EAUX3B *)
procedure prntStrng;
begin
ppStrng(length,s);
ppOutNow;
end;
procedure prntPlist(n: nodep); external;
procedure prntPlist;
var np: nodep; b: boolean;
(* The following is copied from IAUX1A *)
function getNval(n: nodep; var b: boolean): nodep;
begin
b := false;
with n↑ do
if (ntype <> leafnode) or (ltype = varitype) then
begin n := pop; b := true end;
if n <> nil then
if n↑.ltype = pconstype then
begin n := n↑.pcval; b := false end;
getNval := n;
end;
(* The following is copied from IAUX1A *)
procedure killNode(n: nodep);
begin
with n↑ do
if ntype = leafnode then
case ltype of
vectype: if v↑.refcnt <= 0 then relVector(v);
transtype: if t↑.refcnt <= 0 then relTrans(t);
otherwise {do nothing};
end;
relNode(n);
end;
begin
while n <> nil do (* print out the list *)
begin
np := getNval(n↑.lval,b);
if np <> nil then
begin
with np↑ do
case ltype of
svaltype: begin prntSval(s); ppOutNow end;
vectype: prntVec(v);
transtype: prntTrans(t);
strngtype: prntStrng(length,str);
otherwise {do nothing};
end;
if b then killNode(np); (* flush used stack entry *)
end;
n := n↑.next;
end;
end;
procedure onum(s: integer); external;
procedure onum;
procedure onum1(s: integer);
var i,j: integer;
begin
i := s div 8;
j := s mod 8;
if i > 0 then onum1(i);
ppInt(j);
end;
begin
if s < 0 then begin ppChar('-'); s := -s end;
onum1(s);
ppOutNow;
end;
procedure prntVar(v: nodep); external;
procedure prntVar;
var i: integer; n,p: nodep;
begin
if v = nil then pp10('Noname ',6)
else if v↑.ntype = leafnode then
with v↑.vid↑ do ppStrng(length,name) (* print variable name *)
else
begin (* array ref *)
with v↑.arg1↑.vid↑ do ppStrng(length,name); (* print variable name *)
n := v↑.arg2;
ppChar('[');
while n <> nil do
begin
p := pop; (* get this subscript's value *)
i := round(p↑.s);
ppInt(i);
relNode(p);
n := n↑.next;
if n = nil then ppChar(']') else ppChar(',');
end;
end;
ppLine;
end;
procedure badJoints(angle: integer); external;
procedure badJoints;
var i: integer;
begin
if angle <> 0 then
begin (* tell associated joint numbers *)
pp20(' joint(s) = ',14);
i := 1;
while angle <> 0 do (* decode them *)
begin
if odd(angle) then
begin
ppInt(i);
if angle > 1 then ppChar(',');
end;
angle := angle div 2;
i := i + 1;
end;
ppLine;
end;
end;
(* aux routines: addPdb, sleep, deClkQueue, msgDispatch, swap *)
procedure addPdb(var plist: pdbp; pn: pdbp); external;
procedure addPdb;
var p,pp: pdbp; b: boolean;
begin
if plist = nil then
begin (* empty queue - we're it *)
plist := pn;
pn↑.next := nil;
end
else if plist↑.priority < pn↑.priority then
begin (* add us to start of queue *)
pn↑.next := plist;
plist := pn;
end
else
begin (* merge us into the queue *)
p := plist;
b := true;
while (p↑.next <> nil) and b do
if p↑.next↑.priority >= pn↑.priority then p := p↑.next else b := false;
pn↑.next := p↑.next;
p↑.next := pn;
end;
end;
procedure sleep(whenV: integer); external;
procedure sleep;
var w,n,np: nodep; p,pp: pdbp; b: boolean; ti,oldtime: integer;
begin
curInt↑.next := nil;
np := clkQueue;
n := nil;
b := true;
if np <> nil then (* ** Find correct value for "ti" *)
begin
oldTime := curTime; (* need to save this value *)
getTime(curTime);
if stime <> 0 then
begin
ti := -((curtime - oldtime) MOD 18000); (* time since last scheduled *)
repeat (* about to be scheduled *)
n := np;
np := np↑.next;
if np <> nil then ti := ti + np↑.when (* time til next entry is scheduled *)
else
begin
ti := - ti;
whenV := whenV + ti; (* so it'll get scheduled at right time *)
end;
until ti >= 0; (* point at first pending queue entry (if any) *)
end
else (* time til first queue entry gets scheduled MOD 5 minutes *)
ti := (oldTime - curTime) MOD 18000;
curTime := oldTime; (* restore it now *)
end;
while np <> nil do
if ti = whenV then (* add us to this wait node *)
begin
addPdb(np↑.who,curInt);
np := nil;
b := false;
end
else if ti < whenV then
begin (* move down list *)
whenV := whenV - ti; (* update relative wait time *)
n := np;
np := np↑.next;
if np <> nil then ti := np↑.when;
end
else np := nil;
if b then (* need to make a new entry *)
begin
w := newNode;
with w↑ do
begin
ntype := waitlistnode;
who := curInt;
when := whenV;
next := nil;
end;
(* request a Marktime ast to have us made active *)
if n = nil then
begin
w↑.next := clkQueue;
clkQueue := w; (* first entry in queue *)
clrTimeQueue; (* Cancel old MarkTime requests *)
getTime(curTime); (* Find out current time *)
markTime(whenv,curTime,stime); (* Make an AST for this one *)
end
else
begin (* add us to the queue *)
w↑.next := n↑.next;
n↑.next := w;
end;
if w↑.next <> nil then w↑.next↑.when := w↑.next↑.when - whenV;
end;
curInt↑.status := sleepqueue;
curInt := nil; (* swap in someone else *)
resched := true;
end;
procedure deClkQueue(po: pdbp); external;
procedure deClkQueue;
var n,np: nodep; p,pp: pdbp; b: boolean;
begin (* remove pdb from clock queue *)
n := clkQueue;
np := nil;
b := true;
while (n <> nil) and b do
begin
p := n↑.who;
pp := nil;
while (p <> nil) and (p <> po) do begin pp := p; p := p↑.next end;
if p <> nil then (* found us, now splice us out of the list *)
begin
b := false;
if pp = nil then
begin (* we were first entry in list *)
n↑.who := p↑.next;
if n↑.who = nil then (* check if we were only entry *)
begin (* yup - remove this wait list node *)
if np <> nil then np↑.next := n↑.next (* splice out node *)
else
begin (* we were first node *)
clrTimeQueue; (* Cancel markTime request for this guy *)
clkQueue := n↑.next;
if n↑.next <> nil then
markTime(clkQueue↑.when,curTime,stime); (* Put next in queue *)
end;
if n↑.next <> nil then n↑.next↑.when := n↑.when + n↑.next↑.when;
relNode(n); (* done with waitlist node now *)
end
end
else pp↑.next := p↑.next; (* splice us out of list *)
end
else begin np := n; n := n↑.next end; (* try next node *)
end;
end;
procedure msgDispatch; external; (* handles signals & movedone from ARM *)
procedure msgDispatch;
const
YARMDEV = 1; (* device numbers *)
YHANDDEV = 2;
BARMDEV = 3;
BHANDDEV = 4;
VISEDEV = 5;
DRIVERDEV = 6;
GARMDEV = 7;
GHANDDEV = 8;
RARMDEV = 9;
RHANDDEV = 10;
var p: pdbp; nd: nodep;
procedure freeEvent(e: eventp); (* Copied from IAUX1 *)
var eo: eventp; b: boolean;
begin (* remove event from list *)
if allEvents = e then begin allEvents := e↑.next; b := true end
else
begin
eo := allEvents;
b := false;
repeat (* find event in list *)
if eo↑.next = e then b := true else eo := eo↑.next
until b or (eo = nil);
if b then eo↑.next := e↑.next; (* splice us out of list *)
end;
if b then relEvent(e); (* if not in list already released *)
end;
begin
with msg↑ do
if cmd = errorcmd then
begin
if ok then pp20L('Fatal error: ',13)
else pp10L('Warning: ',9);
case dev of (* tell which device *)
yarmdev: pp10('yarm - ',7);
yhanddev: pp10('yhand - ',8);
barmdev: pp10('barm - ',7);
bhanddev: pp10('bhand - ',8);
visedev: pp10('vise - ',7);
driverdev: pp10('driver - ',9);
garmdev: pp10('garm - ',7);
ghanddev: pp10('ghand - ',8);
rarmdev: pp10('rarm - ',7);
rhanddev: pp10('rhand - ',8);
otherwise {do nothing};
end;
case error of
noarmsol: begin pp20('No arm solution foun',20); pp20('d, will use approxim',20);
pp20('ate solution. ',13) end;
timerr: begin pp20('Specified motion tim',20); pp20('e is too short, will',20);
pp20(' try to use it anywa',20); pp5('y. ',2) end;
durerr: begin pp20('Motion overly constr',20); pp20('ained, will ignore g',20);
pp20('lobal time constrain',20); pp5('t. ',2) end;
toolong: begin pp20('Segment longer than ',20); pp20('32.6 seconds, will u',20);
pp20('se 32.6 seconds for ',20); pp10('length. ',7) end;
featna: begin pp20('Feature not availabl',20); pp10('e yet. ',6) end;
otherwise pp20('Unknown error! ',14);
end;
ppLine;
badJoints(bits); (* tell which joint(s) were bad, if any *)
end
else
begin
evt↑.count := evt↑.count + 1;
p := evt↑.waitlist; (* get pdb of process to schedule (if any) *)
if p <> nil then
begin
evt↑.waitlist := p↑.next; (* remove node from waitlist *)
p↑.status := runqueue;
addPdb(activeInts,p); (* add it to active process list *)
if curInt = nil then resched := true
else if p↑.priority > curInt↑.priority then
resched := true; (* swap it in and swap us out *)
if cmd = movedonecmd then
begin (* need to put error bits on stack *)
nd := newNode;
with nd↑ do
begin
ntype := leafnode;
ltype := svaltype;
if ok then s := 0 else s := 128 * ord(error) + bits;
next := p↑.sp; (* push it *)
p↑.sp := nd;
end;
freeEvent(evt); (* also need to reclaim event *)
end
else if cmd <> signalcmd then
begin pp20('Unknown message of t',20); pp5('ype: ',5);
ppInt(ord(cmd)); ppLine end;
end;
end;
end;
procedure swap(newp: pdbp); external;
procedure swap;
var p,po: pdbp; b: boolean; e: eventp;
begin
if newp = nil then
begin (* swap in some active process *)
curInt := activeInts;
if activeInts <> nil then activeInts := activeInts↑.next;
end
else
begin
if newp↑.status = runqueue then
begin (* remove us from activeInts list *)
if activeInts = newp then activeInts := newp↑.next;
p := activeInts;
while p↑.next <> nil do
if p↑.next = newp then p↑.next := newp↑.next (* remove us *)
else p := p↑.next;
end
else if newp↑.status = sleepqueue then deClkQueue(newp)
else if newp↑.status = eventqueue then
begin (* run through all events & remove us from event queue *)
e := allEvents;
b := true;
while b and (e <> nil) do
with e↑ do
begin
if waitlist = newp then
begin waitlist := newp↑.next; b := false end
else
begin
p := waitlist;
while b and (p <> nil) do
if p↑.next = newp then
begin p↑.next := newp↑.next; b := false end
else p := p↑.next;
end;
if b then e := next else count := count + 1;
end;
end;
if (newp <> curInt) and (curInt <> nil) then
begin
curInt↑.status := runqueue;
addPdb(activeInts,curInt); (* swap current process out *)
end;
curInt := newp; (* make new guy active *)
newp↑.next := nil;
end;
if curInt <> nil then
begin curInt↑.status := nowrunning; curInt↑.next := nil end;
end;