*Micro/O/U Dtest
title[dtest];


*The following locations are defined here so that dtest can be loaded without mesa
	SetTask[0];
	OnPage[7];
kfcr:	breakpoint,return;

	OnPage[xfPage1];
LoadC:	breakpoint, return;

*The following intercepts attempts on the part of the timer task to notify the Ethernet output task
insert[EtherDefs];
Etherbreak:	breakpoint, AT[EOTimerDoneLoc];
	return;



	SetTask[0];

RV[uiCC0,40];
RV[uiCC1,41];
RV[uiCC2,42];
RV[uiCC3,43];
RV[uiBASE,44];
RV[uiBASE1,45];
RV[uiTEMP,46];
RV[uiRetLink,47];
*RV[FieldCount,50];
RV[uiCC4,52];
RV[uiCC5,53];
RV[uiCC6,54];
RV[cWord,56];
RV[cCnt,57];
RV[cLink,60]; *Register assignment depends on DCB being quad-aligned (at 1000b)
RV[cNWrds,61];
RV[cDBA,62];
RV[cSLC,63];

	OnPage[nepage];

DisplayTest: uiBASE ← 0C;
	uiBASE1 ← 0C;


SetUpDCBs: uiCC0 ← 1000C; *Form two DCB'S at 1000b and 1004b
	uiCC1 ← 20C; * first is 16 words wide, starting at 1100, tabbed 4 words
	uiCC1 ← (uiCC1) or (2000c);
	uiCC2 ← 1000c;
	uiCC2 ← (uiCC2)+(100C);
	uiCC3 ← 50C; *5*16 = 80 scan lines total height

	T ← (uiCC0) + (4c); *store DCB at 1004b
	uiTEMP ← T;
	PSTORE4[uiBASE,uiCC0];

*The second DCB contains default values that can be changed with Midas
	T ← uiCC0;
	uiCC0 ← (ZERO); *second DCB (at 1000b) is end of chain
	uiCC1←44C; *second DCB is 44b words wide, no tab
	uiCC2 ← 4000c; *second DCB points to 4000
	uiCC3 ← 400c; *and is 400b (*2) scan lines long
	nop;
	PSTORE4[uiBASE,uiCC0];

	T ← (R400) + (20C); *turn on the display
	PSTORE1[uiBASE,uiTEMP], call[uiRETN];
	uiTEMP ← 1C;
	T ← (R400)+(21c); *set interrupt mask to 1 so that we can count fields
	PSTORE1[uiBASE,uiTEMP];

*set mouse and keyboard words to -1
	uiTEMP ← 177000C;
	T← (uiTEMP) or (30C);
	uiCC0 ← (ZERO)-1;
	uiCC1 ← (ZERO)-1;
	uiCC2 ← (ZERO)-1;
	uiCC3 ← (ZERO)-1;
	PSTORE4[uiBASE,uiCC0];
	T ← (uiTemp) or (34c);
	PStore4[uiBase,uiCC0];


*Set the cursor words (431b - 450b) to -1

	T ← (R400) + (30c);
	Pstore4[uiBASE,uiCC0], call[uiRETN];
	T ← (R400) + (34c);
	Pstore4[uiBASE,uiCC0], call[uiRETN];
	T ← (R400) + (40c);
	Pstore4[uiBASE,uiCC0], call[uiRETN];
	T ← (R400) + (44c);
	Pstore4[uiBASE,uiCC0], call[uiRETN];
	T ← (R400) + (50c);
	Pstore4[uiBASE,uiCC0];
	cLink ← 0c;

uiPRESPIN: CALL[uiRETN];
uiSPIN:	T← (R400) + (24C); *Fetch mouse coordinates
	PFETCH2[uiBASE,uiCC0],CALL[uiRETN];
	T ← 177000C; *mask coordinates so that they stay on the screen
	uiCC0 ← (uiCC0) and not (T);
	uiCC1 ← (uiCC1) and not (T);
	T← (R400) + (26C); *Store into cursor coordinates
	PSTORE2[uiBASE,uiCC0], call[uiRETN];
*Update memory (one scan line) with a diagonal line pattern
	call[DiagPat];
*Store 177030 (mouse/keyset) and 177034-37 into the first DCB, one word per bit.
	uiCC0 ← 1000c;
	uiCC0 ← (uiCC0) + (100c);
	uiCC1 ← 0c;
	uiCC2 ← 177000c;
	uiCC2 ← (uiCC2) + (30c), call[KbdFill]; *do 177030
	uiCC2 ← (uiCC2) + (4c), call[KbdFill]; *do 177034
	uiCC2 ← (uiCC2) + 1, call[KbdFill]; *do 177035
	uiCC2 ← (uiCC2) + 1, call[KbdFill]; *do 177036
	uiCC2 ← (uiCC2) + 1, call[KbdFill]; *do 177037

	lu ← NWW, goto[.+2,RODD];
	goto[uiPRESPIN];
	NWW ← 0C, goto[uiPRESPIN];

uiRETN: 	RETURN;


KbdFill: usectask;
	T ← apc&apctask;
	uiCC3 ← 0c;	*high half of base
	uiTemp ← T, Task;
	PFetch1[uiCC2,uiCC3,0];
	uiCC4 ← 17c;	*count the scan line loop here
KbdFillLoop:
	uiCC5 ← 17c;	*count the bit loop here
KbFL1:
	uiCC3 ← lcy[uiCC3,1], dblgoto[xBit1,xBit0,R<0];

xBit1:	uiCC6 ← (zero)-1, goto[KbSendBit];
xBit0:	uiCC6 ← 0c, goto[KbSendBit];

KbSendBit:	PStore1[uiCC0,uiCC6,0], TASK;
	uiCC0 ← (uiCC0) + 1;
	uiCC5 ← (uiCC5)-1;
	goto[KbFL1,ALU>=0];
	uiCC4 ← (uiCC4)-1;
	goto[KbdFillLoop,ALU>=0];
	apc&apctask ← uiTemp;
	return;
	
DiagPat:
	usectask;
	T ← apc&apctask;
	uiCC0 ← T;

	cLink ← (cLink) -1;
	goto[NewDCB,ALU<0];
DiagSetup:
	T ← (cNWrds);
	cWord ← rcy[cWord,1];
	cCnt ← T, call[DiagLoop];

DiagLoop:
	cCnt ← (cCnt) - 1;
	goto[.+2,ALU>=0];
	apc&apctask ← uiCC0, goto[DiagRet];
	PStore1[cDBA,cWord,0];
	cDBA ← (cDBA) +1;
DiagRet:	return;

NewDCB:	T ← 1000c, TASK;
	PFetch4[uiBASE,cLink];
	T ← lsh[cSLC,1];
	cLink ← T; * now holds scan line count
	cSLC ← 0c;	*now is high half of base register
	cNWrds ← rhmask[cNWrds];
	cWord ← 1c, goto[DiagSetup];



	



	END;