; CATMRT.mu
; MEMORY REFRESH TASK AND MOUSE HANDLER

; Obtained from AltoCode23.mu
; Modified to remove interval timer and EIA
; Only works on Alto I
; L. Stewart December 29, 1979 8:21 PM

!17,20,TX0,TX6,TX3,TX2,TX8,TX5,TX1,TX7,TX4,,,,,,,;
!1,2,DOCUR,NOCUR;
!1,2,SHOWC,WAITC;

!1,2,NOCLK,CLOCK;
!1,1,MRTLAST;
!1,2,CNOTLAST,CLAST;

$NWW
$R4;State of interrupt system
$CURX
$R20;
$CURDATA
$R21;
$MTEMP
$R25;
$YPOS
$R27;
$R37
$R37;

MRT:
SINK← MOUSE, BUS;MOUSE DATA IS ANDED WITH 17B
MRTA:
L← T← -2, :TX0;DISPATCH ON MOUSE CHANGE
TX0:
NOP,:AudioTest;Call the audio microcode
ATDone:
T← R37;
L←T← 77+T+1;
R37← L, ALUCY;
NOTIMER:
L← CURX, :NOCLK;
NOCLK:
T← REFMSK, SH=0;
MAR← R37 AND T, :DOCUR;MAR ← R37 clears the wakeup
NOCUR:
CURDATA← L, TASK;
MRTLAST:
CURDATA← L, :MRT;

CLOCK:
MAR← CLOCKLOC;R37 OVERFLOWED. UPDATE CLOCK
NOP;
L← MD+1;
MAR← CLOCKLOC;
MTEMP← L, TASK;
MD← MTEMP, :NOTIMER;

DOCUR:
L← T← YPOS;CHECK FOR VISIBLE CURSOR ON THIS SCAN
SH < 0, L← 20-T-1;***x13 change: the constant 20 was 17
SH<0, L← 2+T, :SHOWC;

WAITC:
YPOS← L, L← 0, TASK, :MRTLAST;squash branch at MRTLAST
SHOWC:
MAR← CLOCKLOC+T+1, :CNOTLAST;

CNOTLAST:
T← CURX, :CURF;
CLAST:
T← 0;
CURF:
YPOS← L, L← T;
CURX← L;
L← MD, TASK;
CURDATA← L, :MRT;

;AFTER THIS DISPATCH, T WILL CONTAIN XCHANGE, L WILL CONTAIN YCHANGE-1

TX1:
L← T← ONE +T, :M00;Y=0, X=1
TX2:
L← T← ALLONES, :M00;Y=0, X=-1
TX3:
L← T← 0, :M00;Y=1, X= 0
TX4:
L← T← ONE AND T, :M00;Y=1, X=1
TX5:
L← T← ALLONES XOR T, :M00;Y=1, X=-1
TX6:
T← 0, :M00;Y= -1, X=0
TX7:
T← ONE, :M00;Y= -1, X=1
TX8:
T← ALLONES, :M00;Y= -1, X= -1

M00:
MAR← MOUSELOC;START THE FETCH OF THE COORDINATES
MTEMP← L;YCHANGE -1
L← MD+ T;X+ XCHANGE
T← MD;Y
MAR← MOUSELOC;NOW RESTORE THE UPDATED COORDINATES
T← MTEMP+ T+1;Y+ (YCHANGE-1) + 1
MTEMP← L, L← T;
MD← MTEMP;
MAR← MOUSELOC+1;
MTEMP← L, TASK;
MD← MTEMP, :TX0;was :MRTA