(mossim)( (mossim.bcd) .loadbcd).cvx .def

mossim

(startsim)(.pop) .cvx .def
(endsim)( ) .cvx .def

(gnv)
(this is different from getnodevalue so that we can slip a tester 
function under it)
(getnodevalue)/xdef

(compare)
(Value Name compare compares value with signal name, and calls simerror if #)
(gnv .eq .not (simerror) .cvx .if) /xdef

(vcompare)
(IntegerValue NameArray compares bits in value with named signals, calls simerror if#)
(getword .eq .not (simerror) .cvx .if) /xdef

(vectorcompare)
(IntegerValue BitStringName compares bits in value with named signals, calls simerror if#)
(getvectorword .eq .not (simerror) .cvx .if) /xdef

(getword)
(NameArray getword  gets an integer with bits equal to the values of the named signals)
(0 .exch gw1 .cvx .arrayforall) /xdef

(gw1)
(Value Name gw1 merges the signal into lsb(Value) lsh 1)
(gnv 1 .eq 1 0 .ifelse .exch 1 .bitshift .bitor ) /def

(simerror)
((
Compare Error) /print /stk .stop) .cvx .def

(arrayvalues)
(prints values of signals named in the array)
((gnv (          ) .cvis .print) .cvx .arrayforall) /xdef

(putbit)
(Name Value putbit sets the named node to the value 0 =>lo, #0 =>hi)
( 0 .eq (lo) .load (hi) .load .ifelse
 ) /xdef

(putword)
(Value NameArray putword -- substitute for SIMMOS putword, but faster)
 (.dup 3 1 .roll .length 16 .exch .sub .bitshift .exch (pw1) .load .cvx .arrayforall .pop
 )  /xdef

(pw1)
(Inner loop of putword.)
(.exch .dup  1 .bitshift 3 1 .roll 0 .lt (hi) .load (lo) .load .ifelse)/def

(openbus)
(NameArray openbus sets all nodes in NameArray to x)
((x) .load .arrayforall) /xdef

(simstep)
(simsolve .pop ) .cvx .def

(channeldict) .where (.pop) .cvx ((channeldict) 128 .dict .def) .cvx .ifelse

(dip64channels)
(Array indexed by pin, contains corresponding tester channel.  This is for
the 64pin dip socket on the tester board)
[ 0 0 1 2 3 4 5 12 13
14 15 16 17 18 19 28 29
30 31 32 33 34 35 44 45
46 47 48 49 50 51 60 61
69 68 59 58 57 56 55 54
53 52 43 42 41 40 39 38
37 36 27 26 25 24 23 22
21 20 11 10 9 8 7 6
] /def

(3Mchannels)
(Array indexed by pin, contains corresponding tester channel.  This is for
the 3M carrier socket on the tester board)
[ 0 69 61 68 60 59 51 58 50
57 49 56 48 55 47 54 46
53 45 52 44 43 35 42 34
41 33 40 32 39 31 38 30
37 29 36 28 27 19 26 18
25 17 24 16 23 15 22 14
21 13 20 12 11 5 10 4
9 3 8 2 7 1 6 0
] /def

(makechanneldict)
(Takes an array of the form (NameA) PinNoA (NameB) PinNoB. . .  and builds
channeldict so that getchannel can produce the correct channel given
a signal name)
((.dup .itype 1 .eq (pinchannels .exch .aget channeldict 3 1 .roll .put) .cvx .if) .cvx .arrayforall) /xdef

(getchan)
((Name) getchan returns <name ChannelNumber .true> if defined, else <name .false> )
(.dup channeldict .exch .known (.dup channeldict .exch .get .true) (.false) .ifelse .cvx .exec) /xdef

(/vdef)
(StringName StringArray defines the array under the name, and registers
the string as a watch vector with MOSSim's bitstring command)
(2 .copy .def (.exch ( ) appstr .exch appstr) .cvx .arrayforall (
) appstr bitstring)/xdef

(appstr) 
(concatenate two strings)
(2 .copy .length .exch .length
 .dup 4 1 .roll
 .add .string
 0 5 -1 .roll .putstring
 3 1 .roll .putstring
)/xdef

(loadtv)(1 .wordstream .dup loadtest) .cvx .def

(testerdict) .where (.pop) .cvx ((testerdict) 256 .dict .def) .cvx .ifelse

testerdict .begin
(startsim)(6 .wordstream .dup (vstream) .exch .def tinit) .cvx .def
(endsim)(tstep .pop vstream .killstream) .cvx .def
(hi) (getchan (thi) (xhi) .ifelse .load .exec) .cvx .def
(lo) (getchan (tlo) (xlo) .ifelse .load .exec) .cvx .def
(x) (getchan (tx) (xtx) .ifelse .load .exec) .cvx .def
(simstep)(tstep .pop) .cvx .def
(simsolve)(tstep) .cvx .def
(gnv)(getchan (gnv1) (xgnv1) .ifelse .load .exec) .cvx .def
.end
(
) .print