//CHATDIS.D - Bob Sproull - Display protocol definitions
// Copyright Xerox Corporation 1979

// modified: April 13, 1979  5:42 PM (E. Taft)

//Note: Display dimensions defined in Chat.d, which must precede

//Strike font format

structure STRIKE[
	oneBit		bit		//=1 to mean new style font
	index		bit
	fixed		bit
	blank		bit 13
	min		word		//Lowest char code
	max		word		//Highest char code
	maxwidth	word		//Maximum width

	length		word		//Number of words in strike body
	ascent		word		// above baseline
	descent		word		// below baseline
	xoffset		word		// for kerning
	raster		word		//# words per scan line
	bitmap		word		// raster*height
//	xpostable
	]

//In-core version with pointer to xpostable:

structure STRIK[
	xPosTable	word		//Pointer to table of xpositions
	@STRIKE				//Regular strike
	]

//A "window" on part of the screen:

structure LIMITS[
	Left		word		//0 to XMax; -1 => limits are illegal
	Right		word		// ditto
	Top		word		// 0 => top of screen
	Bottom		word		//   
	]

//A "region" in which characters may be displayed:

structure REG[
	@BBC				//BitBlt block for displaying them
//index 16:
	@LIMITS				//Where the region lies
	BBCValid	word		//True if BBC is believed to be set up
	SimpleClip	word		//True if only left-right clipping involved
//index 22:
	Italic		word		//True if italic in effect
	Bold		word		//1 if bold chars
	Scroll		word		//Auto scroll when LF off bottom
	BBCOp		word		//Operation for character BitBlt's
	CurX		word		//Present X coordinate
	CurY		word		//Present Y coordinate (0 => top of screen)
	CrX		word		//Carriage return X
	LfY		word		//Line feed DY
//index 30:
	Font		word		//Pointer to font structure
	ClearColor	word		//Color to use (0,-1, etc.) for clearing on scrolls
	spare		word
	Tab		word		//Tab setting (in screen units)
	]
manifest lREG=size REG/16


//Argument vector has logs of definitions:

structure ArgSpot[
	arguments word 20 =
		[
		argWord↑1,20 word
		] =
		[
		argByte↑1,40 byte
		]
	]

//DISV is the main display state vector, pointed to by SS:

structure DISV[
	Version		word		//Code = Display version for LISP
	DISVLoc		word		//Address of this table (for address computation)
	ScreenBuf	word		//Location of screen buffer
//*** beginning of zeroed area ***
	CurrentRegion	word		//Current region in use
	TTYRegion	word		//Pointer to region to use for TTY output

//Stuff for input events
//index 5:
	Event		byte		//Command code =DEvent
	Buttons		byte		//Current button readings
	CursorX		word		//Current cursor coordinates
	CursorY		word
	ChangedButtons	byte		//Buttons changed since last time
	ElapsedTime	byte		//Since last event
	OtherButtons	byte		//Various keyboard keys...
	evSpare	byte

//index 10:
	EnableEvents	word		//Mask for enabled key strokes
	EnableTimerStart word		// for starting the timer
	EnableTimerStop	word		// for stopping the timer
	TimerInterval	word		//And the length of the timer interval (27ths sec)
	TimerGoing	word		//Flag true if timer going
	TimerComplete	word		//Time at which timer expires
	LastEventTime	word		//Time at last event

	CursorDX	word		//Current offset of cursor "sensitive point"
	CursorDY	word

//index 19:
	Blocked		word		//DIS input blocked waiting for TTY activity
	EventTypeChars	word		//2 chars to type on each event

	CaretRegion	word		//Which region the caret lies in
	CaretRate	word
	CaretDX		word
	CaretDY		word
	CaretPattern	word 16

//index 41:
	EscapeChar	word		//Character code for escape sequence
	sparex		word 19

//index 61:
	@ArgSpot			//Place to put arguments
//*** end of zeroed area ***

//index 81:
	nRegions	word		//So ADIS can find it....

// index 82:				// curve stuff
	YMax		word
	CurveBbc	word
	spare		word

//Table of available fonts (0=> non-existent font)
//index 85:
	fonts		word maxNDisplayFonts

//Table of set-up regions (default Typing region=0)
// actual number of regions is in PARM.nRegions
	regions		word 1
	]

manifest [
	zeroDISVFirst=(offset DISV.CurrentRegion)/16
	zeroDISVLength=(offset DISV.nRegions/16)-zeroDISVFirst
	]

//Protocol commands:
// If a byte < 128 is received, it is assumed to be a character to be
//  displayed in the default TTYregion.
// Bytes > 127 are protocol commands, possibly followed by arguments.
// There are two classes of protocol commands:
//	1. Special -- handled by special loops
//	2. Normal -- op[1b] args[nofa b]
//
// If a mark is received, this resynchronizes the command interpreter to
//  expect a protocol command next.
//  A "region" is: xleft[2b] ytop[2b] width[2b] height[2b]

manifest [

// NET => Alto

//Deposit/Examine class:
	DDepositM=#200		//Deposit memory: first[2b] count[b] vals[2*count b]
	DExamineM=#201		//Examine memory: first[2b] count[b]
				//   Replies DExaminedM count[b] vals[count*2 b]
	DDepositV=#202		//Deposit state vector: val[2b] index[b]
	DExamineV=#203		//Examine state vector: index[b]
				//	Replies DExaminedV val[2b]
	DDepositR=#204		//Deposit region vector: val[2b] index[b]
	DExamineR=#205		//Examine region vector: index[b]
				//	Replies DExaminedR val[2b]


	DInvalidate=#206	//Invalidate current region BBC
	DFlushInput=#207	//Force input to be sent to NET
	DSync=#210		//Replies DSync
	DClose=#211		//Close display connection
	DReset=#212		//Reset display to initial state

//Graphics:
	DLineTo=#213		//Draw a line to x[2b] y[2b] wid[b]
	DRegionR=#214		//Region op: func[2b] region[8b] region[8b] gray[2b]
	DRegionC=#215		//Region op: func[2b] region[8b] gray[2b]
	DCursorNudge=#216	//Set cursor: dx[2b] dy[2b] saveDxDy[2b]
	DPress=#217		//Write Press file: name[40b]	
	DReadState=#220		//Replies same as DEvent, but with DState
	DCaretOff=#221		//Force caret off
	DReadFont=#222		//Read font: fontNumber[2b] name[38b]
	DStartTimer=#223	//Fudge starting input timer: timeout[2b]
	DSyncBefore=#224	//Sync with TTY begin: syncNumber[b]
	DSyncAfter=#225		//Sync with TTY end
	DBackup=#226		//Backup character pointer: distance[2b]
	DCurveSetup=#227	//Setup CurveTo command: op[b] brushShape[b] brushWidth[b]
	DCurveTo= #230		//Draw curve: x1[2b] y1[2b] d1x[4b] d1y[4b]
				// d2x[4b] d2y[4b] d3x[4b] d3y[4b] n[2b]
	DAudioOut = #231	//Audio output via Diablo printer interface:
				// pitch[2b] duration [2b]

// Alto => NET

//	DSync
	DExaminedM=#201		//Examined memory: count[b] vals[2*count b]
	DExaminedV=#203		//Examined state vector: val[2b]
	DExaminedR=#205		//Examined region vector: val[2b]

	DEvent=#240		//Event arrived: buttons[b] x[2b] y[2b]
				//    buttonchanges[b] elapsedtime[b] otherbuttons[b]
	DTimeout=#241		//When input timeout happens
	DBlocked=#242		//When typein arrives
	DState=#243		//Same as DEvent, but reply to DReadState
	]


manifest DLargest=#231		//Maximum protocol command to receive

manifest EscChar=#3		//Control C