; DspStreamsA.asm -- companion file is DspStreamsB.bcpl
; Copyright Xerox Corporation 1979, 1980
; Last modified November 26, 1980  2:29 PM by Taft

.ent DisplayPut

	.srel

DisplayPut:	.DisplayPut

	.nrel


.DALC	SKL = ADCZ# 0,0,SNC
.DALC	SKLE = SUBZ# 0,0,SNC
.DALC	SKE = SUB# 0,0,SZR
.DALC	SKNE = SUB# 0,0,SNR
.DALC	SKGE = ADCZ# 0,0,SZC
.DALC	SKG = SUBZ# 0,0,SZC


; STRUCTURE OF STREAM

SCROLL = 12.	;SCROLLING ROUTINE
PFONT = 19.	;POINTER TO FONT
BWRDS = 20.	;WORDS PER SCAN LINE (*** must immediately precede DBA)
DBA = 21.	;DESTINATION BIT ADDRESS
BSTOP = 22.	;BIT POSITION AT WHICH TO STOP WRITING
BSOFAR = 23.	;BITS USED SO FAR IN THIS LINE
WAD = 24.	;DESTINATION WORD ADDRESS
SAVAC2 = 25.	;TEMP FOR AC2 DURING CONVERT

; STRUCTURE OF TEMPS IN FRAME
LINK = 1
ST = 2
TEMP = 3


;DisplayPut(ST, CHAR)
;Writes a character on a display stream.
;All control characters are passed to the scroller.

.DisplayPut:
	STA 3 LINK,2
	STA 0 ST,2
	MOV 0 3		;USE AC3 TO ADDRESS STREAM
	LDA 0 C377	;MASK CHARACTER TO 8 BITS
	AND 0 1
	STA 1 TEMP,2

;TEST IF THE CHARACTER WILL FIT.
;BSTOP = NWRDS * 16 - THE MAX. WIDTH OF ANY CHARACTER IN THE FONT

	LDA 0 BSOFAR,3
	LDA 1 BSTOP,3
	SKG 1 0
	 JMP SCR1
	LDA 1 TEMP,2
	STA 2 SAVAC2,3
	MOV 3 2

PUT1:	LDA 3 PFONT,2	;POINTER TO FONT
	LDA 0 -2,3
	MOVL# 0 0 SZC	; boldface font?
	 JMP PUTB	; yes
PUT1A:	ADD 1 3		; ac3← pointer to character pointer in table
	LDA 0 0 3
	ADD 0 3		; ac3← pointer to word XW of character
	LDA 1 0 3
	MOVZR# 1 1 SZR	; XW = 1?
	 JMP PUT1B	; no
	LDA 1 1 3
	MOV# 1 1 SNR	; yes, XH = 0?
	 JMP NOCHAR	; yes, this character does not exist in font
PUT1B:	SUB 0 3		; ac3← pointer to character pointer in table
	LDA 0 WAD,2	;WORD ADDRESS IN THIS LINE
	CONVERT	BWRDS	;BINGO!
	 JMP PUT2	;CHARACTER HAS AN EXTENSION

	LDA 0 BSOFAR,2	;NO EXTENSION, AC3=WIDTH, AC1=DBA AND 17B
	ADD 3 0
	STA 0 BSOFAR,2

	SUBZ 3 1 SZC
	 JMP PUT3	;DIDN'T OVERFLOW A WORD BOUNDARY
	ISZ WAD,2	;INCREMENT WORD ADDRESS
	LDA 0 C20
	ADD 0 1		;UPDATE DBA, WHICH IS NOW NEGATIVE
PUT3:	STA 1 DBA,2
	LDA 2 SAVAC2,2
	LDA 3 LINK,2
	JMP 1,3

; Here if character is nonexistent -- call scroll routine instead
NOCHAR:	MOV 2 3
	LDA 2 SAVAC2 2
SCR1:	LDA 1 TEMP,2	;PICK UP CHARACTER
	LDA 0 SCROLL,3
	STA 0 TEMP,2
	MOV 3 0
	LDA 3 LINK,2
	JMP @TEMP,2	;GO DO SCROLL INSTEAD

C377:	377
C40:	40


PUT2:	ISZ WAD,2	;HANDLE EXTENSION.  AC3 HAS PSEUDO-CHARACTER CODE
PUT2A:	LDA 0 BSOFAR,2
	LDA 1 C20
	ADD 1 0
	STA 0 BSOFAR,2
	MOV 3 1
	JMP PUT1

PUTB:	LDA 3 -1,3	; get real font pointer
	ADD 1 3
	LDA 0 0 3
	ADD 0 3		; ac3← pointer to word XW of character
	LDA 1 0 3
	MOVZR# 1 1 SZR	; XW = 1?
	 JMP PUTB1B	; no
	LDA 1 1 3
	MOV# 1 1 SNR	; yes, XH = 0?
	 JMP NOCHAR	; yes, this character does not exist in font
PUTB1B:	SUB 0 3		; ac3← pointer to character pointer in table
	LDA 0 WAD,2
	CONVERT BWRDS
	 JMP PUTB2	; character has an extension
	JSR DSTEP	; move over 1 bit
	LDA 3 SAVAC2,2
	LDA 1 TEMP,3	; recover character
	LDA 3 PFONT,2
	LDA 3 -1,3	; recover real font pointer
	JMP PUT1A	; put out displaced copy of character

PUTB2:	JSR DSTEP	; put out copy of initial part first
	LDA 3 SAVAC2,2
	LDA 1 TEMP,3
	LDA 3 PFONT,2
	LDA 3 -1,3
	CONVERT BWRDS	; can't skip
	ISZ DBA,2	; move back 1 bit for rest of character
	LDA 1 DBA,2
	LDA 0 C20
	SUB 0 1 SZR	; at beginning of word?
	 JMP PUT2	; no
	STA 1 DBA,2	; yes, reset DBA
	JMP PUT2A


; Subroutine to move over 1 bit
DSTEP:	ISZ BSOFAR,2
	LDA 1 DBA,2
	NEG 1 1 SNR	; at end of word?
	 JMP DS1	; yes
	COM 1 1		; no, just decrement DBA
DS2:	STA 1 DBA,2
	JMP 0,3

DS1:	ISZ WAD,2	; move to next word
	LDA 1 C17
	JMP DS2


C20:	20
C17:	17

	.END