;; DispatchMc.mu - Press Microcode -- "Main" code, and trap dispatcher

; last modified by Butterfield, October 17, 1980  5:12 PM
; - enabled X10 and X13 trap locations - 7/21/80

; PackMu X.Mb X.Br 77764  -- for slot,disk
; PackMu X.Mb X.Br 77766  -- for disk only

; To re-configure to assemble by itself, complement state of semicolons
; marked ;&;
;&;#Symbols.X13;
;&;#Constants.X13;

; ;Additional emulator definitions

;&;$AC0		$R3;
;&;$AC1		$R2;
$AC2		$R1;
$AC3		$R0;
$PC		$R6;
$XREG		$R7;
$TEMP		$R5;		Shared with SAD
;&;$LREG		$R40;

;&;$10000	$10000;
;&;$4000	$4000;
$400		$400;

;R register availability:
; R10
; (R14 used by disk)
; R15-R17
; R35-R36
;
;S register availability:
; (R40 = last L in RAM)
; R41-R56 -- used by Slot, but can be re-used if Slot off.
; (R71-R76 used by disk)
; (R77 unusable)

; Notation:
;	** means TASK break may happen after this instruction
;		Note that an instruction line with ** may NOT have
;		branch conditions or BUS (i.e., anything that alters NEXT)
;	!a,b means the label a (which is the goto of this instruction)
;		is in a branch table with b.
;
;********************************************************************
; Trap handling stuff (copied from Ingalls)
; If trap is 70000 + disp field, this is a trap for us; dispatch
; on low order 3 bits to TRP0-TRP7.  Otherwise, return the trap
; to the Emulator.

;%0, 1777, 637, TRAPX10;  X10 microcode locn of TRAP
;%0, 1777, 645, TRAPX13;  X13 location
;%0, 1777, 37, TRAP1;  X21 location

;&;!20,1,START;
!1,2,RETRAP,TRPDISP;
!7,10,TRP0,TRP1,TRP2,TRP3,TRP4,TRP5,TRP6,TRP7;

TRAPX10:  T← 37, :TRPX;
TRAPX13:  T← 37, :TRPX;
TRAP1:	T← 37;
TRPX:	L← T← XREG.T;	Look for trap # 70000
	TEMP← L;
	T← 20;
	L← LREG-T;
	SH=0, TASK;
	:RETRAP;		** !RETRAP, TRPDISP
RETRAP: MAR← TRAPPC;
	T← TEMP;
	MD← PC;
	MAR← TRAPPC+T+1;
	NOP;
	L← MD, TASK, :PCL;

; Trap dispatch to the various functions

TRPDISP:  SINK← DISP, SINK← M7, BUS;	One of 7 functions
	:TRP0;			!TRP0, TRP1, ...

;********************************************************************
; BCPLRETL -- Do a "Bcpl return" with L as value of the function.
; BCPLRET -- Simply do a "Bcpl return"

BCPLRETL: AC0← L;
BCPLRET:  L← AC3+1, TASK;
PCL:	PC← L;			**
SWRET:	 SWMODE;
	:START;

; BUMTRAP -- Do a normal trap and watch things fall into Swat

BUMTRAP:	:RETRAP;	RETURN IN PLEASANT WAY