; AIMesaMc.mu
; Alto 1822 Interface microcode control program

; Larry Stewart
; Version for scatter/gather
; Version for Mesa
; Modified September 1, 1978 5:10 PM
; This is a short control program containing nothing but 1822 code
; Last modified September 8, 1978 9:44 AM
; to include PREncrypt instruction

#AltoConsts23.mu;

; Ram entry vector, for access via Mesa JRAM instruction.
; Note that only Ram locations 400-777 and 1400-1777 are reachable from Rom1.

%7, 1777, 400, SilentBoot;

%7, 1777, 420, SetConPtr, PREncrypt;

; Reserve 774-1003 for Ram Utility Area.

%7, 1777, 774, RU774, RU775, RU776, RU777, RU1000, RU1001, RU1002, RU1003;

; For the moment, just throw these locations away. This is done only
; to squelch the "unused predef" warnings that would otherwise occur.
; If we ever run short of Ram, assign these to real instructions somewhere
; in microcode executed only by the Emulator.

RU774:
NOP;
RU775:
NOP;
RU776:
NOP;
RU777:
NOP;
RU1000:
NOP;
RU1001:
NOP;
RU1002:
NOP;
RU1003:
NOP;

; Mesa emulator conventions

$next
$L 4400, 0, 0;Emulator entry point

$stkp
$R16;Stack pointer (0 = empty, 10 = full)
$stk0
$R60;Stack (bottom)

; Initialization for putting this code in the RAM, including
; ’silent boot’ code

!
17,20,Emulator,,,,,IMLOOP,,,,,,,,,,;

; **** Emulator Task ****
; Degenerate -- just returns control to emulator in Rom1.

Emulator:
SWMODE;Switch to Rom1
:next;Mesa emulator entry point

; Microcode subroutines are defined and called from Mesa programs
; as shown in the following example:

; silentBootAddr: CARDINAL = 400B; -- Ram address of SilentBoot microcode --
; SilentBoot: PROCEDURE[bootLocusVector: WORD] =
; MACHINE CODE BEGIN
; Mopcodes.zLIW, silentBootAddr/256, silentBootAdr MOD 256;
; Mopcodes.zJRAM;
; END;

; SilentBoot[177376B]; -- the call --

; All these routines assume they are called with a clean stack.
; Hence, an invocation such as "SilentBoot[177376B]" must be written
; as a complete statement, not as an embedded expression.
; If the routine returns a value, it must be called in a statement
; of the form "simpleVariable ← Routine[args]".
; This permits the Ram subroutine to access fixed S-registers for
; arguments and return values. It must still adjust the stack pointer
; appropriately, however.


; SilentBoot: PROCEDURE[bootLocusVector: WORD]
; Sets the Boot Locus Vector and does a silent boot.
; Entry point is Ram address 400.

SilentBoot:
RMR← stk0;Set BLV from arg on stack
L← stkp-1,TASK;stkp← stkp-1
stkp← L;
SINK← 100000,STARTF,:Emulator;Boot the machine

#PREncrypt.mu;

; **** 1822 Task ****

#Mesa1822.mu;