-- File: AltoRam.mesa,  Last Edit: HGM  July 18, 1980  8:31 AM

DIRECTORY
  Mopcodes USING [zLIW, zJRAM, zPOP];

AltoRam: DEFINITIONS =
  BEGIN

  Shorten: PROCEDURE [LONG POINTER] RETURNS [POINTER] = MACHINE CODE
    BEGIN Mopcodes.zPOP; END;

  -- This is a kludgy place to put this, but all the Alto drivers already use this module

  GetTicks: PROCEDURE RETURNS [CARDINAL] = INLINE
    BEGIN clock: POINTER TO CARDINAL = LOOPHOLE[430B]; RETURN[clock↑] END;

  msPerTick: CARDINAL = 39;


  LoadRamAndBoot: PROCEDURE [filename: STRING];
  CantFindFile: ERROR;
  FileLooksCrufty: ERROR;

  -- Internal things used to prevent the microcode from getting confused
  --  when the bank registers are reset
  LockThingsInLowMemory: PROCEDURE;
  DoSilentBoot: PROCEDURE [WORD];
  UnBoot: PROCEDURE;

  -- Interface to Taft's microcode

  -- Beware: these routines assume that the stack does not have anything extra on it when they are called.  Also, PupChecksum is interruptable.  It assumes that the JRAM is alpha aligned which is forced by the preceeding LIW.


  ramOffset: CARDINAL = 1400B;

  silentBootAddr: CARDINAL = ramOffset + 0;
  SilentBoot: PROCEDURE [bootLocusVector: WORD] = MACHINE CODE
    BEGIN
    Mopcodes.zLIW, silentBootAddr/256, silentBootAddr MOD 256;
    Mopcodes.zJRAM;
    END;

  enableEiaAddr: CARDINAL = ramOffset + 1;
  EnableEia: PROCEDURE [p: POINTER] = MACHINE CODE
    BEGIN
    Mopcodes.zLIW, enableEiaAddr/256, enableEiaAddr MOD 256;
    Mopcodes.zJRAM;
    END;

  setLineTabAddr: CARDINAL = ramOffset + 1;
  SetLineTab: PROCEDURE [p: POINTER] = MACHINE CODE
    BEGIN
    Mopcodes.zLIW, setLineTabAddr/256, setLineTabAddr MOD 256;
    Mopcodes.zJRAM;
    END;

  pupChecksumAddr: CARDINAL = ramOffset + 2;
  PupChecksum: PROCEDURE [initial: WORD, where: POINTER, length: CARDINAL]
    RETURNS [WORD] = MACHINE CODE
    BEGIN
    Mopcodes.zLIW, pupChecksumAddr/256, pupChecksumAddr MOD 256;
    Mopcodes.zJRAM;
    END;

  changeControlRegAddr: CARDINAL = ramOffset + 3;
  ChangeControlReg: PROCEDURE [lineTimes4: CARDINAL, changeMask: WORD] = MACHINE
    CODE
    BEGIN
    Mopcodes.zLIW, changeControlRegAddr/256, changeControlRegAddr MOD 256;
    Mopcodes.zJRAM;
    END;


  END.