;Mesa-Specific Microcode for running Alto II CAT

; Intended for use with XMESA 4.1 and later releases

; Microcode command file for Audio Terminal
; MU/l CatMesaMc.mu
; PackMu CatMesaMc.mb AuburnMesaMc-U5-R4.br 160376 Auburn54Image

; Task assignments
%17,1777,0, NovaBoot,L1,L2,L3, L4, L5,L6,L7, AudioStart, DWT, CURT, DHT, DVT, L15, L16, L17;
; MESA emulator-routine entry points.
%17,1777, 600, SilentBoot, MAudioParam, MAudioMux, MAudioPhone, MAudioRTones,
MAudioSwitch, MAudioList, MAudioLink, MAudioCurrent, MAudioVersion,
MAudioRPhone;

; Address definition for Nova Emulator main loop in ROM0

$START
$L004020,000000,000000;

#CatConstsMc.mu;

L1: TASK, :L1; -- be sure XMESA starts at 20
L2: TASK, :L2;
L3: TASK, :L3;
L4: TASK, :L4;
L5: TASK, :L5;
L6: TASK, :L6;
L7: TASK, :L7;
; L10: TASK, :L10;
Memory refresh task
; L11: TASK, :L11;
Display Word Task
; L12: TASK, :L12;
Cursor Task
; L13: TASK, :L13;
Display horizontal task
; L14: TASK, :L14;
Display Vertical Task
L15: TASK, :L15;
L16: TASK, :L16;
L17: TASK, :L17;

; 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;

#MesaXRAM.mu;
-- overflow from Mesa ROMS for XM Mesa
#MesaBLTLReal.mu;
#IMEcode.mu;
#Adpcm.mu;
#u255.mu;
#Catu255.mu;
#CatMc.mu;
#CATIIMRT.mu;
contains MRT
#GateDisplay.mu;
contains DHT, DVT, CURT, DWT

; We are using Nova boot conventions
NovaBoot:
SWMODE;
:START;

!1,2, MAudioList2, MAudioList1;
!1,2, MSetLeft, MAudioRet0;
!1,2, MLink, MFail;
!1,2, McStart, MCurrent1;
;MESA Emulator routines (via JRAM)
; Arg1 in stk0, Arg2 in stk1, resultis in stk0 (stkp must be adjusted)
; indices are 0 for list 1, 1 for list 2
; Ram Location
Routine
;
600SilentBoot[RMR] -- does the StartIO
;
601MAudioParam[val] -- NOP
;
602AudioMux[val] -- NOP
;
603AudioPhone[val] -- NOP
;
604val ← AudioRTones[] -- returns 0
;
605AudioSwitch[val] -- NOP
;
606AudioList[acb, index] -- request to interpret acb list (0 to stop) -- list 1 or 2
;
607success ← AudioLink[newAcb, oldAcb] -- link in new Acb, fails if old is emptied
;
610MAudioCurrent[index] -- returns current acb, or NIL (none active this list)
;
611val ← MAudioVersion[] -- returns version ([0-9], hardware; [10-15], microcode)
;
612val ← MAudioRTelephone[] -- returns 0
; SilentBoot: PROCEDURE[resetModeRegister: WORD]
; Sets the Reset Mode Register and does a silent boot.
; From MesaGatewayMc

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

; Accept new list, set Samples count for first ACB
; Set silence detection register to 0
; ~~ Q -- how long do I have before I must task?
MAudioList:
L←stk0;
T←idxLength;
SINK←stk1, BUS=0;
MAR←stk0+T, :MAudioList2;!1,2,MAudioList2, MAudioList1;
MAudioList1:
T←0;
ACB1←L,L←T,SH=0;
Sil1←L, :MSetLeft;!1,2,MSetLeft, MAudioRet0;
MAudioList2:
T←0;
ACB2←L,L←T,SH=0;
Sil2←L,:MSetLeft;!1,2,MSetLeft, MAudioRet0;
MSetLeft:
L←MD;
T←stk0;
MAR←idxSamples+T;
NOP, TASK;
MD←LASTL, :MAudioRet0;**

; AudioLink[newAcb, oldAcb] -- fail if old is emptied, else succeed
MAudioLink:
T←idxSamples;
MAR←stk1+T;
T←0+1;
L←MD, BUS=0;
MAR←stk1, :MLink;!1,2,MLink, MFail;
MLink:
L←0-1;-- success
MD←stk0, :McS1;
MFail:
T←0+1, :McS1;

; returns currently running ACB for supplied index (0 = list1, 1 = list2)
MAudioCurrent:
SINK←stk0, BUS=0;
L←ACB2, :McStart;!1,2,McStart, MCurrent1;
MCurrent1:
L←ACB1, :McStart;

MAudioMux:
NOP, :MAudioRet0;
MAudioPhone:
NOP, :MAudioRet0;
MAudioParam:
NOP, :MAudioRet0;
MAudioSwitch:
NOP, :MAudioRet0;
MAudioStore:
NOP, :MAudioRet0;
MAudioRet0:
L←0, TASK;
MAudioRetn:
stkp←L, :Emulator; **
Emulator:
SWMODE;
:romnextA; ##
McStart:
T←0+1;
McS1:
stk0←L, L←T, TASK, :MAudioRetn;
MAudioRTones:
L←0, :McStart;
MAudioVersion:
T ← 2000;returns 2205B
L ← 200+T;
T ← LastL;
L← 5+T, :McStart;
MAudioRPhone:
L←0, :McStart;

;; DCS, July 10, 1978 9:37 PM, extracted from AuburnMc-U3-R2 -- must be lang.-specific
;; July 13, 1978 8:36 AM, version U4-R3-Bb
;; July 17, 1978 9:08 PM, MAudioSwitch: XOR’d results available on BUS in active cycle
;; July 21, 1978 11:59 AM, remove constants to AuburnConstsMc-U4..., revise MU ops
;; January 21, 1979 9:00 PM, add Mesa XRAM -- overflow from ROMS for XMesa
;;
Required moving all Audio JRAMS from 400 range to 600 range
;; May 21, 1979 9:27 AM, version U5-R4, supply hardware version too in version --
;;
microcode version occupies low 5 bits for now
;; May 24, 1979 5:23 PM, use XMesa’s version of emulator entry point
;; August 16, 1979 1:13 PM L. Stewart. Added ADPCM.mu include.
;; September 22, 1979 3:30 PM L. Stewart. Added u255.mu include.
;;
and task u-255 code (ut255.mu)
;; October 15, 1979 1:24 PM L. Stewart. Added includes for CPDispMRT.mu
;;
and GateDisp.mu in order to get more R registers for the
;;
audio task. See AuburnMc-u5-r4.mu.
;;
Added silence detection in list initialization.
;; October 15, 1979 3:57 PM L. Stewart. Added includes for ImeCode.mu
;; November 5, 1979 12:34 AM L. Stewart. Nova style silent boot.
;; March 16, 1980 5:14 PM L. Stewart. Formatting changes.
;; March 17, 1980 12:12 PM L. Stewart. Modified for CAT.