; November 4, 75

	.TITL	ZPCONVERT
; outgoing
	.BEXT	paintDot,paintString
; incoming
	.BEXTZ	maxStringHeight
	.BEXTZ	scanlineWidth

;************ statics:

	.SREL
paintDot:	paintDotC
paintString:	paintStringC
convTable:	convTableC


;************procedure
; paintString(string pointer,nwrds,dba,dwa-nwrds,font)
; returns the width of the string in bits

;offsets in the frame
stringPointer=4
nwrds=5
dba=6
wad=7
fontPointer=8.
bsofar=9.
charsdone=10.
ret=11.

	.NREL

paintStringC:	STA 3 1 2
	JSR@ 370
	20
	JSR@ 367
	SUB 0 0
	STA 0 @plc
	STA 0 bsofar,2
	LDA 0 @stringPointer,2
	MOVS 0 0
	LDA 1 c377
	AND 1 0
	STA 0 charsdone,2
doright:	LDA 0 @stringPointer,2
	JSR docnv
	ISZ stringPointer,2
	DSZ charsdone,2
	JMP doleft
	JMP retx
doleft:	LDA 0 @stringPointer,2
	MOVS 0 0
	JSR docnv
	DSZ charsdone,2
	JMP doright
retx:	LDA 0 bsofar,2
	JMP@ 366


plc:	maxStringHeight
temp:	0
c377:	377
c20:	20

docnv:	STA 3 ret,2
	LDA 1 c377
	AND 1 0
put1:	LDA 3 fontPointer,2
	ADD 0 3
	STA 3 temp	;get the height of this character
	LDA 0 0 3
	INC 0 0
	ADD 0 3
	LDA 0 0 3	;xh,hd for this character
	MOVS 0 3
	AND 1 0
	AND 1 3
	ADD 3 0		;total extension below base of this character
	LDA 1 @plc	;max height so far
	SGT 1 0
	STA 0 @plc	;current is bigger
	LDA 3 temp
	LDA 0 wad,2
	CONVERT nwrds
	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
	LDA 3 c20
	ADD 3 1
put3:	STA 1 dba,2
	JMP@ ret,2

put2:	ISZ wad,2
	LDA 0 bsofar,2
	LDA 1 c20
	ADD 1 0
	STA 0 bsofar,2
	MOV 3 0
	JMP put1



;************ procedure :
; paintDot(word address, bit offset, brush pointer)

	.NREL

saveAC3:	0
saveAC2:	0
Swidth:		scanlineWidth
convTableS:	convTable
fifteen:	17
convTableC:		0	; convTable!0 = scanline width
BitOff:		0	; convTable!1 = bit offset (special format ...)

paintDotC:
	STA	2,saveAC2
	STA	3,saveAC3
	LDA	3,@Swidth
	STA	3,convTableC
	SUB	3,0		;AC0 = word address - scanline width
	LDA	3,fifteen
	SUB	1,3
	STA	3,BitOff	;bit offset (special format)
	LDA	3,3,2		;AC3 = brush pointer
	LDA	2,@convTableS	;AC2 = address of 2-word convTable
	CONVERT	0
	NOP
	LDA	2,saveAC2
	LDA	3,saveAC3
	JMP	1,3


	.END