-- EmulatorTestImpl.mesa    11-Dec-81 10:07:06 by JGS

-- Test program to exercise the the Mesa emulator of a PrincOps machine.

DIRECTORY
  EmulatorTest,
  ESCAlpha,
  Mopcodes,
  SDDefs;

EmulatorTestImpl: PROGRAM
  IMPORTS EmulatorTest =

  BEGIN OPEN EmulatorTest, SDDefs, ESCAlpha, Mopcodes;
 
  -- Useful variables:

  BothOnes: PROCEDURE RETURNS [LONG CARDINAL] = MACHINE CODE {zLIN1; zLIN1};
  
  zero: CARDINAL ← 0; 
  one: CARDINAL ← 1; 
  two: CARDINAL ← 2; 
  three: CARDINAL ← 3; 
  four: CARDINAL ← 4; 
  five: CARDINAL ← 5; 
  six: CARDINAL ← 6; 
  seven: CARDINAL ← 7; 
  eight: CARDINAL ← 8; 
  nine: CARDINAL ← 9; 
  ten: CARDINAL ← 10; 
  eleven: CARDINAL ← 11; 
  twelve: CARDINAL ← 12; 
  thirteen: CARDINAL ← 13; 
  fourteen: CARDINAL ← 14; 
  fifteen: CARDINAL ← 15; 
  fourHundred: CARDINAL = 400B;
  allOnes: CARDINAL ← 177777B; 
  negInfinity: CARDINAL = 100000B;
  minusTwo: CARDINAL = 177776B;
  
  loopCount: CARDINAL ← 100; 
  currentOpcode: CARDINAL;
  
  oneTwo: LONG CARDINAL ← 200000B * 1 + 2;
  oneThree: LONG CARDINAL ← 200000B * 1 + 3;
  twoFour: LONG CARDINAL ← 200000B * 2 + 4;
  threeFour: LONG CARDINAL ← 200000B * 3 + 4;
  fourSix: LONG CARDINAL ← 200000B * 4 + 6;
  fiveSix: LONG CARDINAL ← 200000B * 5 + 6;
  zeroAllOnes: LONG CARDINAL ← 177777B;
  oneAllZeros: LONG CARDINAL ← 200000B;
  bothZero: LONG CARDINAL ← 0;
  bothOnes: LONG CARDINAL ← BothOnes[];
   
  a, b, i: CARDINAL;
  aD, bD: LONG CARDINAL;
   
  proc: PROCEDURE;
  
  SetMP: PROCEDURE [CARDINAL] = MACHINE CODE {zESC, aWRMP};

  Halt: PROCEDURE [code: CARDINAL] = INLINE {SetMP[code]; DO i ← 0 ENDLOOP};
  
  SetTest: PROCEDURE [opcode: CARDINAL] = INLINE {
    SetMP[opcode]; currentOpcode ← opcode};

  Low: PROCEDURE [a: LONG UNSPECIFIED] RETURNS [UNSPECIFIED] = INLINE {
    RETURN[LOOPHOLE[a, RECORD[low, high: CARDINAL]].low]};
  
  High: PROCEDURE [a: LONG UNSPECIFIED] RETURNS [UNSPECIFIED] = INLINE {
    RETURN[LOOPHOLE[a, RECORD[low, high: CARDINAL]].high]};
  
  -- Trap Handlers
  
  BreakTrap: PROCEDURE = {Halt[9000+SDDefs.sBreakTrap]};
  StackError: PROCEDURE = {Halt[8000+currentOpcode]};
  RescheduleError: PROCEDURE = {Halt[9000+SDDefs.sRescheduleError]};
  XferTrap: PROCEDURE = {Halt[9000+SDDefs.sXferTrap]};
  OpcodeTrap: PROCEDURE = {Halt[9000+SDDefs.sOpcodeTrap]};
  ControlTrap: PROCEDURE = {Halt[9000+SDDefs.sControlTrap]};
  CodeTrap: PROCEDURE = {Halt[9000+SDDefs.sCodeTrap]};
  HardwareError: PROCEDURE = {Halt[9000+SDDefs.sHardwareError]};
  UnboundTrap: PROCEDURE = {Halt[9000+SDDefs.sUnboundTrap]};
  DivZeroTrap: PROCEDURE = {Halt[9000+SDDefs.sDivZeroTrap]};
  DivCheckTrap: PROCEDURE = {Halt[9000+SDDefs.sDivCheckTrap]};
  InterruptError: PROCEDURE = {Halt[9000+SDDefs.sInterruptError]};
  ProcessTrap: PROCEDURE = {Halt[9000+SDDefs.sProcessTrap]};
  BoundsTrap: PROCEDURE = {Halt[9000+SDDefs.sBoundsTrap]};
  PointerTrap: PROCEDURE = {Halt[9000+SDDefs.sPointerTrap]};
  
  FillInSD: PROCEDURE = {
    SDDefs.SD[sBreakTrap] ← BreakTrap;
    SDDefs.SD[sStackError] ← StackError;
    SDDefs.SD[sRescheduleError] ← RescheduleError;
    SDDefs.SD[sXferTrap] ← XferTrap;
    SDDefs.SD[sOpcodeTrap] ← OpcodeTrap;
    SDDefs.SD[sControlTrap] ← ControlTrap;
    SDDefs.SD[sCodeTrap] ← CodeTrap;
    SDDefs.SD[sHardwareError] ← HardwareError;
    SDDefs.SD[sUnboundTrap] ← UnboundTrap;
    SDDefs.SD[sDivZeroTrap] ← DivZeroTrap;
    SDDefs.SD[sDivCheckTrap] ← DivCheckTrap;
    SDDefs.SD[sInterruptError] ← InterruptError;
    SDDefs.SD[sProcessTrap] ← ProcessTrap;
    SDDefs.SD[sBoundsTrap] ← BoundsTrap;
    SDDefs.SD[sPointerTrap] ← PointerTrap;
    SetTest[zRET]};

  JumpTests: PROC = {
    SetTest[zJEP];
    a ← one;
    b ← two;
    IF a # 2 THEN a ← one ELSE Halt[1000+zJEP];
    IF a # 1 THEN Halt[2000+zJEP];
    SetTest[zJEBB];
    a ← 40;
    b ← one;
    IF a # 44 THEN a ← 40 ELSE Halt[1000+zJEBB];
    IF a # 40 THEN Halt[2000+zJEBB];
    SetTest[zJNEP];
    a ← one;
    b ← two;
    IF a = 1 THEN a ← two ELSE Halt[1000+zJNEP];
    IF a = 1 THEN Halt[2000+zJNEP];
    SetTest[zJNEBB];
    a ← 40;
    b ← one;
    IF a = 40 THEN a ← 44 ELSE Halt[1000+zJNEBB];
    IF a = 40 THEN Halt[2000+zJNEBB];
    SetTest[zRET];
    RETURN};
     
  
  StackTests: PROCEDURE = {
    SetTest[zREC];
    i ← 0;
    DO
      a ← nine; IF REC[] # nine THEN Halt[1000+zREC]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zREC2];
    i ← 0;
    DO
      aD ← threeFour;
      bD ← REC2[];
      IF High[bD] # three OR Low[bD] # four THEN Halt[1000+zREC2]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDIS];
    i ← 0;
    DO
      DIS[a]; IF REC[] # a THEN Halt[1000+zDIS]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDIS2];
    i ← 0;
    DO
      DIS2[twoFour]; 
      bD ← REC2[];
      IF High[bD] # two OR Low[bD] # four THEN Halt[1000+zDIS2]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zEXCH];
    i ← 0;
    DO
      [c: a, d: b] ← EXCH[a: one, b: two];
      IF a # two OR b # one THEN Halt[1000+zEXCH];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDEXCH];
    i ← 0;
    DO
      [c: aD, d: bD] ← DEXCH[a: oneTwo, b: threeFour];
      IF High[aD] # three OR Low[aD] # four OR High[bD] # one OR Low[bD] # two THEN
        Halt[1000+zDEXCH];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDUP];
    i ← 0;
    DO
      [a: a, b: b] ← DUP[six];
      IF a # six OR b # six THEN Halt[1000+zDUP];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDDUP];
    i ← 0;
    DO
      [a: aD, b: bD] ← DDUP[fiveSix];
      IF High[aD] # five OR Low[aD] # six OR High[bD] # five OR Low[bD] # six THEN Halt[1000+zDDUP];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zEXDIS];
    i ← 0;
    DO
      a ← EXDIS[a: three, b: four]; IF a # four THEN Halt[1000+zEXDIS]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zNEG];
    i ← 0;
    DO
      a ← NEG[one]; IF a # allOnes THEN Halt[1000+zNEG]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zINC];
    i ← 0;
    DO
      a ← INC[one]; IF a # two THEN Halt[1000+zINC]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDEC];
    i ← 0;
    DO
      a ← DEC[three]; IF a # two THEN Halt[1000+zDEC]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDINC];
    i ← 0;
    DO
      aD ← DINC[zeroAllOnes];
      IF Low[aD] # zero OR High[aD] # one THEN Halt[1000+zDINC]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDBL];
    i ← 0;
    DO
      a ← DBL[six]; IF a # twelve THEN Halt[1000+zDBL]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDDBL];
    i ← 0;
    DO
      aD ← DDBL[oneTwo];
      IF High[aD] # two OR Low[aD] # four THEN Halt[1000+zDDBL]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zTRPL];
    i ← 0;
    DO
      a ← TRPL[three]; IF a # nine THEN Halt[1000+zTRPL]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zAND];
    i ← 0;
    DO
      a ← ANDOp[a: three, b: six];
      IF a # two THEN Halt[1000+zAND]; 
      a ← ANDOp[a: five, b: allOnes];
      IF a # five THEN Halt[2000+zAND]; 
      a ← ANDOp[a: five, b: zero];
      IF a # zero THEN Halt[3000+zAND];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zIOR];
    i ← 0;
    DO
      a ← IOR[a: three, b: six];
      IF a # seven THEN Halt[1000+zIOR]; 
      a ← IOR[a: five, b: allOnes];
      IF a # allOnes THEN Halt[2000+zIOR]; 
      a ← IOR[a: five, b: zero];
      IF a # five THEN Halt[3000+zIOR];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zADDSB];
    i ← 0;
    DO
      ADDOne: PROC [CARDINAL] RETURNS [CARDINAL] = MACHINE CODE {zADDSB, 1};
      ADDNegOne: PROC [CARDINAL] RETURNS [CARDINAL] = MACHINE CODE {zADDSB, 377B};
      a ← ADDOne[four];
      IF a # five THEN Halt[1000+zADDSB]; 
      a ← ADDNegOne[four];
      IF a # three THEN Halt[2000+zADDSB]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zADD];
    i ← 0;
    DO
      a ← ADD[a: three, b: four];
      IF a # seven THEN Halt[1000+zADD]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zSUB];
    i ← 0;
    DO
      a ← SUB[a: four, b: three];
      IF a # one THEN Halt[1000+zSUB]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDADD];
    i ← 0;
    DO
      aD ← DADD[a: oneTwo, b: threeFour];
      IF High[aD] # four OR Low[aD] # six THEN Halt[1000+zDADD];
      aD ← DADD[a: zeroAllOnes, b: one];
      IF High[aD] # one OR Low[aD] # zero THEN Halt[2000+zDADD]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDSUB];
    i ← 0;
    DO
      aD ← DSUB[a: fourSix, b: threeFour];
      IF High[aD] # one OR Low[aD] # two THEN Halt[1000+zDSUB];
      aD ← DSUB[a: oneAllZeros, b: one];
      IF High[aD] # zero OR Low[aD] # allOnes THEN Halt[2000+zDSUB]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zACD];
    i ← 0;
    DO
      aD ← ACD[a: one, b: oneTwo];
      IF High[aD] # one OR Low[aD] # three THEN Halt[1000+zACD];
      aD ← ACD[a: one, b: zeroAllOnes];
      IF High[aD] # one OR Low[aD] # zero THEN Halt[2000+zACD]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zADC];
    i ← 0;
    DO
      aD ← ADC[a: oneTwo, b: one];
      IF High[aD] # one OR Low[aD] # three THEN Halt[1000+zADC];
      aD ← ADC[a: zeroAllOnes, b: one];
      IF High[aD] # one OR Low[aD] # zero THEN Halt[2000+zADC]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zMUL];
    i ← 0;
    DO
      [c: a, d: b] ← MUL[a: one, b: three];
      IF a # three OR b # zero THEN Halt[1000+zMUL];
      [c: a, d: b] ← MUL[a: fourHundred, b: fourHundred];
      IF a # zero OR b # one THEN Halt[2000+zMUL]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zDCMP];
    i ← 0;
    DO
      a ← DCMP[a: FIRST[LONG INTEGER], b: bothZero];
      IF a # allOnes THEN Halt[1000+zDCMP];
      a ← DCMP[a: oneTwo, b: oneTwo];
      IF a # zero THEN Halt[2000+zDCMP];
      a ← DCMP[a: LAST[LONG INTEGER], b: bothZero];
      IF a # one THEN Halt[3000+zDCMP]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zUDCMP];
    i ← 0;
    DO
      a ← UDCMP[a: zero, b: fourSix];
      IF a # allOnes THEN Halt[1000+zUDCMP];
      a ← UDCMP[a: oneTwo, b: oneTwo];
      IF a # zero THEN Halt[2000+zUDCMP];
      a ← UDCMP[a: bothOnes, b: bothZero];
      IF a # one THEN Halt[3000+zUDCMP]; 
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zSHIFT];
    i ← 0;
    DO
      a ← SHIFT[a: one, b: two];
      IF a # four THEN Halt[1000+zSHIFT];
      a ← SHIFT[a: one, b: fourHundred];
      IF a # zero THEN Halt[2000+zSHIFT];
      a ← SHIFT[a: fourHundred, b: -5];
      IF a # eight THEN Halt[3000+zSHIFT];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zSHIFTSB];
    i ← 0;
    DO
      a ← three*4;
      IF a # twelve THEN Halt[1000+zSHIFTSB];
      a ← fourHundred/200B;
      IF a # two THEN Halt[2000+zSHIFTSB];
      i ← i + one;
      IF loopCount = i THEN EXIT;
      ENDLOOP;
    SetTest[zRET];
    RETURN};
    
  Singles: TYPE = RECORD [a, b, c, d, e, f: CARDINAL ← NULL];
  pSingles: POINTER TO Singles;
  lpSingles: LONG POINTER TO Singles;
  singles: Singles;

  Doubles: TYPE = RECORD [a, b, c: LONG CARDINAL ← NULL];
  lpDoubles: LONG POINTER TO Doubles;
  pDoubles: POINTER TO Doubles;
  doubles: Doubles;
  
  Bytes: TYPE = RECORD [
    SELECT OVERLAID * FROM 
      bytes => [bytes: PACKED ARRAY [0..4) OF [0..256)],
      words => [words: ARRAY [0..2) OF CARDINAL],
      ENDCASE];
  lpBytes: LONG POINTER TO Bytes;
  pBytes: POINTER TO Bytes;
  bytes: Bytes;

  Fields: TYPE = RECORD [
    SELECT OVERLAID * FROM 
      fields => [a,b,c,d,e,f,g,h,i,j,k,l: [0..16) ← NULL],
      stackFields => [stackFields: PACKED ARRAY [0..12) OF [0..16)],
      words => [words: ARRAY [0..3) OF CARDINAL],
      ENDCASE];
  lpFields: LONG POINTER TO Fields;
  pFields: POINTER TO Fields;
  fields: Fields;

  SetupReadTests: PROC = {
    pSingles ← @singles;
    lpSingles ← @singles;
    pDoubles ← @doubles;
    lpDoubles ← @doubles;
    pBytes ← @bytes;
    lpBytes ← @bytes;
    pFields ← @fields;
    lpFields ← @fields;
    RETURN};
  
  ReadWriteTests: PROC = {
    LocalVars: TYPE = RECORD [
      l0, l1: POINTER TO Doubles, l2: LONG POINTER TO Doubles,
      l4: POINTER TO Singles, l5: LONG POINTER TO Singles,
      l7: POINTER TO Fields, l8: LONG POINTER TO Fields];
    locals: LocalVars ← [
      l0: pDoubles, l1: pDoubles, l2: lpDoubles, l4: pSingles, l5: lpSingles,
      l7: pFields, l8: lpFields];
    SetTest[zRD0];
    THROUGH [0..loopCount) DO
      doubles.a ← oneTwo;
      IF pDoubles.a # oneTwo THEN Halt[1000+zRD0]; 
      ENDLOOP;
    SetTest[zRDB];
    THROUGH [0..loopCount) DO
      doubles.b ← oneTwo;
      IF pDoubles.b # oneTwo THEN Halt[1000+zRDB]; 
      ENDLOOP;
    SetTest[zRDL0];
    THROUGH [0..loopCount) DO
      doubles.a ← oneTwo;
      IF lpDoubles.a # oneTwo THEN Halt[1000+zRDL0]; 
      ENDLOOP;
    SetTest[zRDLB];
    THROUGH [0..loopCount) DO
      doubles.b ← oneTwo;
      IF lpDoubles.b # oneTwo THEN Halt[1000+zRDLB]; 
      ENDLOOP;
    SetTest[zPSB];
    THROUGH [0..loopCount) DO
      pSingles↑ ← [a: zero, c: one, e: two];
      IF singles.a # zero OR singles.c # one OR singles.e # two THEN
        Halt[1000+zPSB]; 
      ENDLOOP;
    SetTest[zWLB];
    THROUGH [0..loopCount) DO
      lpSingles.a ← four;
      IF singles.a # four THEN Halt[1000+zWLB]; 
      ENDLOOP;
    SetTest[zPSLB];
    THROUGH [0..loopCount) DO
      lpSingles↑ ← [a: zero, c: one, e: two];
      IF singles.a # zero OR singles.c # one OR singles.e # two THEN
        Halt[1000+zPSLB]; 
      ENDLOOP;
    SetTest[zWDB];
    THROUGH [0..loopCount) DO
      pDoubles.a ← oneTwo;
      IF doubles.a # oneTwo THEN Halt[1000+zWDB]; 
      ENDLOOP;
    SetTest[zPSD0];
    THROUGH [0..loopCount) DO
      PSD0: PROC [p: POINTER, d: LONG CARDINAL] RETURNS[POINTER] =
        MACHINE CODE {zPSD0};
      [] ← PSD0[pDoubles, threeFour];
      IF doubles.a # threeFour THEN Halt[1000+zPSD0]; 
      ENDLOOP;
    SetTest[zPSDB];
    THROUGH [0..loopCount) DO
      pDoubles↑ ← [b: oneTwo, c: fiveSix];
      IF doubles.b # oneTwo OR doubles.c # fiveSix THEN Halt[1000+zPSDB]; 
      ENDLOOP;
    SetTest[zWDLB];
    THROUGH [0..loopCount) DO
      lpDoubles.a ← oneTwo;
      IF doubles.a # oneTwo THEN Halt[1000+zWDLB]; 
      ENDLOOP;
    SetTest[zRLI00];
    THROUGH [0..loopCount) DO
      doubles.a ← oneTwo;
      IF Low[locals.l0.a] # two THEN Halt[1000+zRLI00]; 
      ENDLOOP;
    SetTest[zRLI01];
    THROUGH [0..loopCount) DO
      doubles.a ← oneTwo;
      IF High[locals.l0.a] # one THEN Halt[1000+zRLI01]; 
      ENDLOOP;
    SetTest[zRLI02];
    THROUGH [0..loopCount) DO
      doubles.b ← oneTwo;
      IF Low[locals.l0.b] # two THEN Halt[1000+zRLI02]; 
      ENDLOOP;
    SetTest[zRLI03];
    THROUGH [0..loopCount) DO
      doubles.b ← oneTwo;
      IF High[locals.l0.b] # one THEN Halt[1000+zRLI03]; 
      ENDLOOP;
    SetTest[zRLIP];
    THROUGH [0..loopCount) DO
      doubles.b ← oneTwo;
      IF High[locals.l1.b] # one THEN Halt[1000+zRLIP]; 
      ENDLOOP;
    SetTest[zRLILP];
    THROUGH [0..loopCount) DO
      doubles.b ← threeFour;
      IF High[locals.l2.b] # three THEN Halt[1000+zRLILP]; 
      ENDLOOP;
    SetTest[zRLDI00];
    THROUGH [0..loopCount) DO
      doubles.a ← threeFour;
      IF locals.l0.a # threeFour THEN Halt[1000+zRLDI00]; 
      ENDLOOP;
    SetTest[zRLDIP];
    THROUGH [0..loopCount) DO
      doubles.a ← threeFour;
      IF locals.l1.b # threeFour THEN Halt[1000+zRLDIP]; 
      ENDLOOP;
    SetTest[zRLDILP];
    THROUGH [0..loopCount) DO
      doubles.a ← threeFour;
      IF locals.l2.b # threeFour THEN Halt[1000+zRLDILP]; 
      ENDLOOP;
    SetTest[zWLIP];
    THROUGH [0..loopCount) DO
      locals.l4.a ← three;
      IF singles.a # three THEN Halt[1000+zWLIP]; 
      ENDLOOP;
    SetTest[zWLILP];
    THROUGH [0..loopCount) DO
      locals.l5.b ← one;
      IF singles.b # one THEN Halt[1000+zWLILP]; 
      ENDLOOP;
    SetTest[zWLDILP];
    THROUGH [0..loopCount) DO
      locals.l2.b ← allOnes;
      IF doubles.b # allOnes THEN Halt[1000+zWLDILP]; 
      ENDLOOP;
    SetTest[zRS];
    THROUGH [0..loopCount) DO
      bytes.words[0] ← fourHundred;
      IF pBytes.bytes[zero] # one OR pBytes.bytes[one] # zero THEN Halt[1000+zRS]; 
      ENDLOOP;
    SetTest[zRLS];
    THROUGH [0..loopCount) DO
      bytes.words[0] ← fourHundred;
      IF lpBytes.bytes[zero] # one OR lpBytes.bytes[one] # zero THEN
        Halt[1000+zRLS]; 
      ENDLOOP;
    SetTest[zWS];
    THROUGH [0..loopCount) DO
      pBytes.bytes[zero] ← zero;
      pBytes.bytes[one] ← allOnes;
      IF bytes.words[zero] # fourHundred - one THEN Halt[1000+zWS]; 
      ENDLOOP;
    SetTest[zWLS];
    THROUGH [0..loopCount) DO
      lpBytes.bytes[two] ← one;
      lpBytes.bytes[three] ← two;
      IF bytes.words[1] # (fourHundred + two) THEN Halt[1000+zWLS]; 
      ENDLOOP;
    SetTest[zR0F];
    THROUGH [0..loopCount) DO
      fields.words[0] ← four;
      IF pFields.a # zero OR pFields.d # four THEN Halt[1000+zR0F]; 
      ENDLOOP;
    SetTest[zRF];
    THROUGH [0..loopCount) DO
      fields.words[1] ← seven;
      IF pFields.f # zero OR pFields.h # seven THEN Halt[1000+zRF]; 
      ENDLOOP;
    SetTest[zRL0F];
    THROUGH [0..loopCount) DO
      fields.words[0] ← fourHundred;
      IF lpFields.b # one OR lpFields.d # zero THEN Halt[1000+zRL0F]; 
      ENDLOOP;
    SetTest[zRLF];
    THROUGH [0..loopCount) DO
      fields.words[1] ← nine;
      IF lpFields.g # zero OR lpFields.h # nine THEN Halt[1000+zRLF]; 
      ENDLOOP;
    SetTest[zRLFS];
    THROUGH [0..loopCount) DO
      fields.words[0] ← nine;
      IF lpFields.stackFields[one] # zero
      OR lpFields.stackFields[three] # nine THEN Halt[1000+zRLFS]; 
      ENDLOOP;
    SetTest[zRLIPF];
    THROUGH [0..loopCount) DO
      locals.l7.words[0] ← fourHundred + nine;
      IF locals.l7.b # one OR locals.l7.d # nine THEN
        Halt[1000+zRLIPF]; 
      ENDLOOP;
    SetTest[zRLILPF];
    THROUGH [0..loopCount) DO
      locals.l7.words[1] ← fourHundred + ten;
      IF locals.l8.f # one OR locals.l8.h # ten THEN
        Halt[1000+zRLILPF]; 
      ENDLOOP;
    SetTest[zW0F];
    THROUGH [0..loopCount) DO
      pFields.a ← one;
      pFields.c ← four;
      IF pFields.a # one OR pFields.c # four THEN Halt[1000+zW0F]; 
      ENDLOOP;
    SetTest[zWF];
    THROUGH [0..loopCount) DO
      pFields.e ← one;
      pFields.f ← four;
      IF pFields.e # one OR pFields.f # four THEN Halt[1000+zWF]; 
      ENDLOOP;
    SetTest[zPS0F];
    THROUGH [0..loopCount) DO
      pFields↑ ← [fields[a: one, b: two, c: three, d: five]];
      IF pFields.a # one OR pFields.b # two OR pFields.c # three THEN
        Halt[1000+zPS0F]; 
      IF pFields.d # five THEN Halt[1000+zWS0F]; 
      ENDLOOP;
    SetTest[zWL0F];
    THROUGH [0..loopCount) DO
      lpFields.a ← one;
      lpFields.c ← four;
      IF lpFields.a # one OR lpFields.c # four THEN Halt[1000+zWL0F]; 
      ENDLOOP;
    SetTest[zWLF];
    THROUGH [0..loopCount) DO
      lpFields.e ← two;
      lpFields.h ← eight;
      IF lpFields.e # two OR lpFields.h # eight THEN Halt[1000+zWLF]; 
      ENDLOOP;
    SetTest[zPSLF];
    THROUGH [0..loopCount) DO
      lpFields↑ ← [fields[a: one, b: two, c: three, d: five]];
      IF lpFields.a # one OR lpFields.b # two OR lpFields.c # three
      OR lpFields.d # five THEN Halt[1000+zPSLF]; 
      ENDLOOP;
    SetTest[zWLFS];
    THROUGH [0..loopCount) DO
      lpFields.stackFields[1] ← zero;
      lpFields.stackFields[3] ← nine;
      IF lpFields.stackFields[1] # zero OR lpFields.stackFields[3] # nine THEN
        Halt[1000+zWLFS]; 
      ENDLOOP;
    SetTest[zRET];
    RETURN}; 

  ExternalTests: PROC = {
    SetTest[zEFCB];
    EmulatorTest.InitHelper[]; 
    SetTest[zRKIB];
    THROUGH [0..loopCount) DO
      a ← EmulatorTest.varOne;
      IF a # one THEN Halt[1000+zRKIB]; 
      ENDLOOP;
    SetTest[zRKDIB];
    THROUGH [0..loopCount) DO
      aD ← EmulatorTest.varOneTwo;
      IF aD # varOneTwo THEN Halt[1000+zRKDIB]; 
      ENDLOOP;
    SetTest[zEFCB];
    proc ← EmulatorTest.Proc[];
    SetTest[zLLKB];
    THROUGH [0..loopCount) DO
      IF EmulatorTest.InitHelper # proc THEN Halt[1000+zLLKB]; 
      ENDLOOP;
    SetTest[zRET];
    RETURN}; 
      
        -- Start Tests
  
  SetTest[400];
  FillInSD[];

  DO
    SetTest[zLFCB];
    JumpTests[];
    SetTest[zLFCB];
    StackTests[];
    SetTest[zLFCB];
    SetupReadTests[];
    SetTest[zLFCB];
    ReadWriteTests[]
    ENDLOOP;
  
  
  END.


LOG

12-Oct-81 16:05:36   Knutsen   New instruction set.