-- Test2764.mesa
-- Last Edit: Stewart, October 8, 1982 9:54 pm
-- Last Edit: Stewart, December 6, 1982 4:07 pm, Cedar 3.5

DIRECTORY
  FileIO,
  Inline USING [BITAND, BITSHIFT, HighByte, LowByte, LowHalf],
  IO,
  Rope USING [Cat, Fetch, Length, ROPE],
  Transaction,
  UserExec USING [RegisterCommand, CommandProc];

LarkPromsImpl: PROGRAM
IMPORTS FileIO, Inline, IO, Rope, UserExec =
BEGIN

Bit: TYPE = BOOL;

PromAddress: TYPE = MACHINE DEPENDENT RECORD [
  pad (0: 0..2): [0..7B],
  adr (0: 3..15): [0..17777B]
  ];

PromData: TYPE = MACHINE DEPENDENT RECORD [
  data (0: 0..7): [0..377B],
  pad (0: 8..15): [0..377B]
  ];

PromProc: TYPE = PROC [in: CARDINAL] RETURNS [out: CARDINAL];

IncrementLowProm: PromProc = {
  address: PromAddress = LOOPHOLE[in];
  data: PromData;
  data.pad ← 0;
  -- PROM logic goes here
  data.data ← Inline.BITAND[address.adr, 377B];
  out ← LOOPHOLE[data, CARDINAL];
  };

IncrementHighProm: PromProc = {
  address: PromAddress = LOOPHOLE[in];
  data: PromData;
  data.pad ← 0;
  -- PROM logic goes here
  data.data ← Inline.BITSHIFT[address.adr, -5];
  out ← LOOPHOLE[data, CARDINAL];
  };


  OByte: PROC [s: IO.Handle, x: CARDINAL] = INLINE { s.PutChar[LOOPHOLE[x]]; };
  OWord: PROC [s: IO.Handle, x: CARDINAL] = INLINE {
    s.PutChar[LOOPHOLE[Inline.HighByte[x]]];
    s.PutChar[LOOPHOLE[Inline.LowByte[x]]];
    };

  MakeMBFile: PROC [name: Rope.ROPE, size: CARDINAL, width: CARDINAL, proc: PromProc] = {
    filename: Rope.ROPE ← Rope.Cat[name, ".mb"];
    s: IO.STREAM ← FileIO.Open[filename, FileIO.AccessOptions[overwrite]];
    namelength: INT ← name.Length[];
    OWord[s, 4];  -- boilerplate
    OWord[s, 1];  -- memorynumber
    OWord[s, width];  -- memorywidth in bits
    FOR i: INT IN [0..namelength) DO
      OByte[s, name.Fetch[i]-0C];
      ENDLOOP;
    OByte[s, 0];  -- ASCIZ end of string
    -- pad to word boundary
    IF Inline.BITAND[Inline.LowHalf[namelength], 1] = 0 THEN OByte[s, 0];
    OWord[s, 2];  -- set current memory and location
    OWord[s, 1];  -- memorynumber again
    OWord[s, 0];  -- location
    FOR i: CARDINAL IN [0..size) DO
      OWord[s, 1];  -- memory data word
      OWord[s, 0];  -- source line number (not used)
      OWord[s, proc[i]]; -- left justified
      ENDLOOP;
    OWord[s, 0];  -- end of file
    s.Close[];
    };

Main: UserExec.CommandProc = TRUSTED {
  MakeMBFile["IncLow", 8192, 8, IncrementLowProm];
  MakeMBFile["IncHigh", 8192, 8, IncrementHighProm];
  };

-- Mainline Code
  UserExec.RegisterCommand["Test2764.~", Main, "Create .mb files for testing 2764"];

END.
March 21, 1982 6:12 pm, Stewart, created