*-----------------------------------------------------------
Title[InitialDisplay.mc...June 19, 1982  11:45 AM...Taft];
* Minimal Terminal Horizontal Task microcode:
* Initializes HRam so that horizontal sync will be generated, and then
* simply receives terminal messages and updates the keyboard words.
*-----------------------------------------------------------

Set[XTask, IP[DHT]];	* or AHT
Subroutine;
KnowRBase[THTRegion];
THTInitPC:
	T← AHT, DisplayConfig, Branch[THTInitAHT, R<0];
	T← DHT;
	Wakeup[DHT], CoReturn;
TopLevel;
* DHT starts here
	T← Statics, Branch[THTInit1];	* Use DispY TIOA

Subroutine;
THTInitAHT:
	Wakeup[AHT], CoReturn;
TopLevel;
* AHT starts here
	T← TStatics, Branch[THTInit1];	* Use DispM TIOA

THTInit1:
	TIOA← T;
	RBase← RBase[THTRegion];
	T← AllShutUp, Call[OutputGetsT]; * Disable WakeUps, Reset DDC
	T← DWTShutUp, Call[OutputGetsT]; * Enable DHT wakeups
	PD← DisplayConfig, MemBase← IOBR;
	TReg400C← 400C, Branch[.+2, ALU<0]; * Skip HRam setup if DispM in use
	T← A0, Call[InitHRam]; * Initialize HRam
	TerminalHi← A0, Cnt← 5S;
	TerminalLo← A0, TIOA[TNLCB];
	T← (TReg400C) XOR (177434C);	* Initialize to all keys "up"
	T← (Store← T)+1, DBuf← -1C, Branch[., Cnt#0&-1];
	TVCWShadowReg← VBlank, Branch[THTLast];

* Main loop must do at least one Output to TNLCB per wakeup, and
* must send vertical sync during 24B out of every 265B scan lines.
THTPerScanLine:
	Output← TVCWShadowReg;
	Call[ReadTerminal];
* ReadTerminal returns with TIOA[NLCB], ALU = TFieldAreaReg (decremented)
	PD← (TVCWShadowReg) AND (VSync), Block, Branch[THTPerScanLine, ALU#0];
	TVCWShadowReg← (TVCWShadowReg) XOR (VSync), Branch[.+2, ALU#0];
	TFieldAreaReg← 24C, Branch[THTPerScanLine]; * Time for VSync&VBlank
THTLast:
	TFieldAreaReg← 241C, Branch[THTPerScanLine]; * Time for VBlank