NEW
  AUTO 3,1
				.LIST OFF
*--------------------------------------
* TBOX.New hParent,X1,Y1,W,H,pBuf,BufSize,F		10
*--------------------------------------
TBOX.New		lda #S.OBJ.T.TBOX
				jsr OBJ.Create
				bcs .9

				>PULLA
				ldy #S.OBJ.F
				sta (ZPObjPtr),y

				jsr OBJ.PullBuf

				jsr OBJ.PullHW

				jsr OBJ.PullY1X1hParent

				jsr CONT.Insert

				bcs .99

				lda hObj
*				clc
				rts

.9				>POP 10

.99				rts
*--------------------------------------
TBOX.Run		ldy #S.OBJ.S
				lda (ZPObjPtr),y
				bpl TBOX.RUN.Ignore

				ldy #S.OBJ.F
				lda (ZPObjPtr),y
				and #S.OBJ.F.bEdit
				bne TBOX.Run.RW

				lda (pStack)			Event

				cmp #C.SPACE
				beq .1

				cmp #27
				bcs TBOX.RUN.Ignore

				asl
				tax
				jmp (J.TBOX.RUN.RO,x)

.1				lda #EV.HL.PRESSED
				clc
				rts
*--------------------------------------
TBOX.Run.RW		lda (pStack)			Event

				cmp #C.SPACE
				bcs .1

				cmp #27
				bcs TBOX.RUN.Ignore

				asl
				tax
				jmp (J.TBOX.RUN.RW,x)

.1				cmp #C.DEL
				beq .2

				jsr TBOX.GetBuf
				jsr TBOX.ToBuf1
				bcs TBOX.RUN.Ignore		Buffer full

				jsr TBOX.RUN.FS1
				bra .3

.2				jsr TBOX.GetBuf

				jsr TBOX.Delete1
				bcs TBOX.RUN.Ignore		Buffer Empty

.3				bit bRepaintAll
				bmi .4

				jsr OBJ.CurUpdPos

				jmp TBOX.DrawCurLine

.4				jmp TBOX.DrawAllLines
*--------------------------------------
TBOX.RUN.Ignore	lda #0
				sec
				rts
*--------------------------------------
TBOX.RUN.PrevLink
				jsr OBJ.GetpBufPtr1
				
				ldy #S.TBOX.SelBegin
				jsr TBOX.RUN.GetSel		-> TempC

.1				ldx #0
			
.2				jsr TBOX.GetCharBW
				beq TBOX.RUN.PrevLink.9
				
				cmp #'['
				bne .1
				
				cpx #'['
				beq .3
				
				tax
				bra .2
				
.3				lda ZPPtr1
				sta TempI
				lda ZPPtr1+1
				sta TempI+1

				jsr TBOX.RUN.CheckLink
				bcs .1

				rts

TBOX.RUN.PrevLink.9
				lda #0
				sec
				rts
*--------------------------------------
TBOX.RUN.NextLink
				jsr OBJ.GetpBufPtr1
				
				ldy #S.TBOX.SelEnd
				jsr TBOX.RUN.GetSel		-> TempC

.1				ldx #0
			
.2				jsr TBOX.GetCharFW
				beq TBOX.RUN.PrevLink.9
				
				cmp #'['
				bne .1
				
				cpx #'['
				beq .3
				
				tax
				bra .2

.3				lda ZPPtr1
				sec
				sbc #2
				sta TempI
				lda ZPPtr1+1
				sbc #0
				sta TempI+1
				
				lda TempC
				sec
				sbc #2
				sta TempC
				lda TempC+1
				sbc #0
				sta TempC+1


				jsr TBOX.RUN.CheckLink
				bcc .99


.9				lda #0
				sec
.99				rts
*--------------------------------------
TBOX.RUN.GetSel lda (ZPObjPtr),y
				sta TempC
				clc
				adc ZPPtr1
				sta ZPPtr1
				
				iny
				lda (ZPObjPtr),y
				sta TempC+1
				adc ZPPtr1+1
				sta ZPPtr1+1
				
				rts
*--------------------------------------
TBOX.RUN.CheckLink
				ldy #S.TBOX.BufPtr
				jsr TBOX.SetTempCAtY

				ldy #S.TBOX.SelBegin
				jsr TBOX.SetTempCAtY
				
				ldx #0

.1				jsr TBOX.GetCharFW
				beq .9

				cmp #C.CR
				beq .9

				iny

				cmp #']'
				bne .1
				
				cpx #']'
				beq .2
				
				tax
				bra .1

.2				ldy #S.TBOX.SelEnd
				jsr TBOX.SetTempCAtY
				
				jsr OBJ.GetpVarPtr2

				ldy #$ff				SKIP "[[TEXT]"

.3				iny
				lda (TempI),y
				cmp #']'
				bne .3

				tya
				sec
				adc TempI
				sta TempI
				bcc .4

				inc TempI+1

.4				ldy #$ff

.5				iny
				lda (TempI),y
				sta (ZPPtr2),y
				cmp #']'
				bne .5

				lda #0
				sta (ZPPtr2),y
				
*				jsr TBOX.SetViewPort
*				bit bRepaintAll
*				bmi .6

*				jsr OBJ.CurUpdPos

*				jsr TBOX.DrawCurLine
*				bra .60

.6				jsr TBOX.DrawAllLines

.60				lda #EV.HL.SELECTED
				clc
				rts
				
.9				sec
				rts
*--------------------------------------
TBOX.RUN.GetLink

				lda #EV.HL.PRESSED
				clc
				rts

				lda #0
				sec
				rts
*--------------------------------------
TBOX.RUN.ScrollUp
				jsr TBOX.GetBuf

				ldy #S.OBJ.InnerH
				lda (ZPObjPtr),y
				clc
				ldy #S.TBOX.VScroll
				adc (ZPObjPtr),y
				pha

				iny						#S.TBOX.VScroll+1
				lda (ZPObjPtr),y
				adc #0
				plx

				jsr TBOX.GetLineAX
				bcs .8

				ldy #S.TBOX.VScroll
				jsr OBJ.IncWordAtY

				jmp TBOX.DrawAllLines

.8				clc
				rts
*--------------------------------------
TBOX.RUN.ScrollDown
				jsr TBOX.GetBuf

				ldy #S.TBOX.VScroll+1
				lda (ZPObjPtr),y
				dey
				ora (ZPObjPtr),y
				beq .8

				jsr OBJ.DecWordAtY

				ldy #S.TBOX.DocY
				jsr OBJ.DecWordAtY

				jmp TBOX.DrawAllLines

.8				clc
				rts
*--------------------------------------
TBOX.RUN.SelBegin
				ldy #S.TBOX.BufPtr
				lda (ZPObjPtr),y
				tax
				iny
				lda (ZPObjPtr),y

				ldy #S.TBOX.SelBegin+1
				sta (ZPObjPtr),y
				txa
				dey
				sta (ZPObjPtr),y

				jmp TBOX.DrawAllLines
*--------------------------------------
TBOX.RUN.SelEnd	ldy #S.TBOX.BufPtr
				lda (ZPObjPtr),y
				tax
				iny
				lda (ZPObjPtr),y

				ldy #S.TBOX.SelEnd+1
				sta (ZPObjPtr),y
				txa
				dey
				sta (ZPObjPtr),y

				jmp TBOX.DrawAllLines
*--------------------------------------
TBOX.RUN.BS		ldy #S.TBOX.BufPtr+1
				lda (ZPObjPtr),y
				dey
				ora (ZPObjPtr),y
				beq .9

				jsr OBJ.DecWordAtY

				jsr TBOX.GetBuf

				lda (ZPPtr2)
				cmp #C.CR
				beq .2

				ldy #S.TBOX.DocX
				jsr OBJ.DecWordAtY
				jmp TBOX.CheckViewPort

.2				ldy #S.TBOX.DocY
				jsr OBJ.DecWordAtY

				jmp TBOX.RUN.EOL

.9				sec
				rts
*--------------------------------------
TBOX.RUN.LF		jsr TBOX.GetBuf

TBOX.RUN.LF1	jsr TBOX.GetDocYInAX
				inx
				bne .1

				inc

.1				jsr TBOX.GetLineAX
				bcs TBOX.RUN.VT.8

				ldy #S.TBOX.DocY
				jsr OBJ.IncWordAtY
				bra TBOX.RUN.VT1
*--------------------------------------
TBOX.RUN.VT		jsr TBOX.GetBuf

				ldy #S.TBOX.DocY+1
				lda (ZPObjPtr),y
				dey
				ora (ZPObjPtr),y
				beq TBOX.RUN.VT.8

				jsr OBJ.DecWordAtY

TBOX.RUN.VT1	jsr TBOX.GetDocYInAX
				jsr TBOX.GetLineAX

				jsr TBOX.GetLineLenInAXC
				sta TempW
				stx TempW+1

				ldy #S.TBOX.DocX
				cmp (ZPObjPtr),y

				txa
				iny
				sbc (ZPObjPtr),y
				bcs .1

				lda TempW+1
				sta (ZPObjPtr),y
				dey
				lda TempW
				sta (ZPObjPtr),y

.1				ldy #S.TBOX.DocX

				lda	TempC
				clc
				adc (ZPObjPtr),y
				tax
				iny
				lda TempC+1
				adc (ZPObjPtr),y

				ldy #S.TBOX.BufPtr+1
				sta (ZPObjPtr),y
				dey
				txa
				sta (ZPObjPtr),y

				jmp TBOX.CheckViewPort

TBOX.RUN.VT.8	clc
				rts
*--------------------------------------
TBOX.RUN.FS		jsr TBOX.GetBuf

TBOX.RUN.FS1	lda (ZPPtr2)
				beq .8

				tax

				ldy #S.TBOX.BufPtr
				jsr OBJ.IncWordAtY

				ldy #S.TBOX.DocX
				cpx #C.CR
				bne .7

.1				jsr OBJ.ZeroWordAtY

				ldy #S.TBOX.DocY

.7				jsr OBJ.IncWordAtY

				jmp TBOX.CheckViewPort

.8				clc
				rts
*--------------------------------------
TBOX.RUN.SOL	ldy #S.TBOX.DocX
				jsr OBJ.ZeroWordAtY

				jsr TBOX.GetDocYInAX
				jsr TBOX.GetLineAX

				ldy #S.TBOX.BufPtr
				jsr TBOX.SetTempCAtY	BufPtr at SOL

				jmp TBOX.CheckViewPort
*--------------------------------------
TBOX.RUN.EOL	jsr TBOX.GetDocYInAX
				jsr TBOX.GetLineAX
				jsr TBOX.GetLineLenInAXC

				pha

				ldy #S.TBOX.BufPtr
				clc
				adc TempC				BufPtr at SOL+LineLen
				sta (ZPObjPtr),y
				iny
				txa
				adc TempC+1
				sta (ZPObjPtr),y

				pla

				ldy #S.TBOX.DocX
				sta (ZPObjPtr),y
				iny
				txa
				sta (ZPObjPtr),y

				jmp TBOX.CheckViewPort
*--------------------------------------
TBOX.RUN.CR		jsr TBOX.GetBuf
				jsr TBOX.ToBuf1
				bcs .8					Buffer full

				ldy #S.TBOX.DocX
				jsr OBJ.ZeroWordAtY

				jsr TBOX.RUN.LF1

				jsr OBJ.CurUpdPos

				bit bRepaintAll
				bmi .1

				jsr TBOX.DrawBottom

.1				jmp TBOX.DrawAllLines

.8				clc
				rts
*--------------------------------------
TBOX.RUN.PGUP
*--------------------------------------
TBOX.RUN.PGDN	lda #0
				sec
				rts
*--------------------------------------
TBOX.RUN.QUIT	lda #3					User Interrupt
				sec
				rts
*--------------------------------------
TBOX.RUN.Home	ldy #S.TBOX.DocX
				jsr OBJ.ZeroWordAtY

				ldy	#S.TBOX.DocY
				jsr OBJ.ZeroWordAtY

				ldy #S.TBOX.BufPtr
				jsr OBJ.ZeroWordAtY

				jmp TBOX.CheckViewPort
*--------------------------------------
TBOX.RUN.EraseCL
				jsr TBOX.GetDocYInAX
				jsr TBOX.GetLineAX
				jsr TBOX.GetLineLenInAXC
				jsr TBOX.DeleteAXC

				jmp TBOX.RUN.VT1
*--------------------------------------
TBOX.RUN.EOF	lda #$ff
				tax
				jsr TBOX.GetLineAX

				ldy #S.TBOX.DocY
				lda TempI
				sta (ZPObjPtr),y
				tax

				lda TempI+1
				iny
				sta (ZPObjPtr),y

				jsr TBOX.GetLineAX
				jsr TBOX.GetLineLenInAXC

				ldy #S.TBOX.DocX
				sta (ZPObjPtr),y
				iny
				txa
				sta (ZPObjPtr),y

				ldy #S.TBOX.BufCnt+1
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.TBOX.BufPtr
				sta (ZPObjPtr),y
				iny
				txa
				sta (ZPObjPtr),y

				jmp TBOX.CheckViewPort
*--------------------------------------
TBOX.DrawAllLines
				ldy #1					hObj
				lda (pStack),y
				>PUSHA

				jsr OBJ.Draw.Body
				inc pStack

				rts
*--------------------------------------
TBOX.DrawBottom ldy #S.OBJ.InnerY
				lda (ZPObjPtr),y

				clc

				ldy #S.OBJ.CurY
				adc (ZPObjPtr),y
				>PUSHA					Start

				ldy #S.OBJ.InnerH
				lda (ZPObjPtr),y

				sec

				ldy #S.OBJ.CurY
				sbc (ZPObjPtr),y
				>PUSHA					Count

				ldy #S.OBJ.CurY
				lda (ZPObjPtr),y		Relative Y
				>PUSHA

				jmp OBJ.Draw.Lines
*--------------------------------------
TBOX.DrawCurLine
				ldy #S.OBJ.InnerY
				lda (ZPObjPtr),y

				clc

				ldy #S.OBJ.CurY
				adc (ZPObjPtr),y
				>PUSHA					Start

				lda #1
				>PUSHA					Count

				ldy #S.OBJ.CurY
				lda (ZPObjPtr),y		Relative Y
				>PUSHA

				jmp OBJ.Draw.Lines
*--------------------------------------
TBOX.Draw		ldy #S.TBOX.VScroll
				lda (ZPObjPtr),y
				clc
				adc (pStack)			Relative Y
				tax

				iny
				lda (ZPObjPtr),y
				adc #0

				jsr TBOX.GetLineAX
				bcs .5

				ldy #S.TBOX.HScroll
				lda (ZPObjPtr),y
				beq .12

				tax

.1				jsr TBOX.GetLineChar
				beq .5

				cmp #C.CR
				beq .5

				dex
				bne .1

.12				ldy #S.OBJ.InnerW
				lda (ZPObjPtr),y
				tax

				stz bTemp1				reset selection
				stz bTemp2				reset Hyperlink

.2				jsr TBOX.CheckSel

				jsr TBOX.GetLineChar
				beq .3

				cmp #C.CR
				beq .3

				jsr LB.COut
				dex
				bne .2

.3				txa
				bne .6

				clc
				rts

.5				ldy #S.OBJ.InnerW
				lda (ZPObjPtr),y
				tax

.6				jsr TBOX.ResetSel

				lda #C.SPACE

.7				jsr LB.COut
				dex
				bne .7

.8				clc
				rts
*--------------------------------------
TBOX.Activate
*--------------------------------------
TBOX.Deactivate	clc
				rts
*--------------------------------------
TBOX.SetProp	jsr OBJ.SetProp
				bcs .9

				cpy #S.OBJ.pBuf
				bne .8

				ldy #S.TBOX.DocX
				lda #0

.1				sta (ZPObjPtr),y
				iny
				cpy #S.TBOX.BufPtr+2
				bcc .1

				jsr OBJ.GetpBufPtr1

				ldx #0
				ldy #0

.2				lda (ZPPtr1),y
				beq .3

				iny
				bne .2

				inc ZPPtr1+1
				inx
				bra .2

.3				tya
				ldy #S.TBOX.BufCnt
				sta (ZPObjPtr),y
				iny
				txa
				sta (ZPObjPtr),y

				jmp OBJ.Draw.Body.I

.8				clc
.9				rts
*--------------------------------------
TBOX.GetBuf		jsr OBJ.GetpBufPtr1

				ldy #S.TBOX.BufPtr
				lda ZPPtr1
				clc
				adc (ZPObjPtr),y
				sta ZPPtr2

				lda ZPPtr1+1
				iny
				adc (ZPObjPtr),y
				sta ZPPtr2+1

				rts
*--------------------------------------
TBOX.GetDocYInAX
				ldy #S.TBOX.DocY
				lda (ZPObjPtr),y
				tax

				iny
				lda (ZPObjPtr),y
				rts
*--------------------------------------
TBOX.GetLineAX	stx TempW
				sta TempW+1				Req Line Num

				jsr OBJ.GetpBufPtr1

				stz TempI				Current Line Num
				stz TempI+1

				stz TempC				Buffer Ofs
				stz TempC+1

.1				lda TempI
				eor TempW
				bne .2

				lda TempI+1
				eor TempW+1
				beq .8

.2				lda (ZPPtr1)
				beq .9

				jsr TBOX.GetLineLenInAXC
				bcc .9

*				sec

				pha

				adc TempC
				sta TempC
				txa
				adc TempC+1
				sta TempC+1

				sec

				pla

				adc ZPPtr1
				sta ZPPtr1
				txa
				adc ZPPtr1+1
				sta ZPPtr1+1

				inc TempI
				bne .1

				inc TempI+1
				bra .1

.9				sec
				rts

.8				clc
				rts
*--------------------------------------
TBOX.SetLineAtDocX
				ldy #S.TBOX.DocX
				lda (ZPObjPtr),y
				clc
				adc ZPPtr1
				sta ZPPtr1
				iny
				lda (ZPObjPtr),y
				adc ZPPtr1+1
				sta ZPPtr1+1

*				clc

				dey						#S.TBOX.DocX
				lda (ZPObjPtr),y
				adc TempC
				sta TempC
				iny
				lda (ZPObjPtr),y
				adc TempC+1
				sta TempC+1
				rts
*--------------------------------------
* TempC charPos
*--------------------------------------
TBOX.CheckSel	ldy #S.TBOX.SelBegin
				jsr TBOX.CmpTempCAtY
				bcc TBOX.ResetSel

				iny						#S.TBOX.SelEnd
				jsr TBOX.CmpTempCAtY
				bcs TBOX.ResetSel
*--------------------------------------
TBOX.SetSel		bit bTemp1
				bmi .8

				phx
				ldx #SEQ.INVERSE-SEQS
				jsr LB.SeqOut
				plx

				dec bTemp1

.8				rts
*--------------------------------------
TBOX.ResetSel	bit bTemp1
				bpl .8

				phx
				ldx #SEQ.NORMAL-SEQS
				jsr LB.SeqOut
				plx

				stz bTemp1

.8				rts
*--------------------------------------
* hyperlinks: [[text]targetUrl#targetHtag]
* htags:      [#htag]
*--------------------------------------
TBOX.GetLineChar
				ldy #S.OBJ.F
				lda (ZPObjPtr),y
				and #S.OBJ.F.bEdit
				bne TBOX.GetCharFW

				bit bTemp2
				bmi .3

				jsr TBOX.GetCharFW
				beq .8

				cmp #'['
				bne .8					NZ

				cmp (ZPPtr1)			"[["
				bne .1

				dec bTemp2			
				
				bra TBOX.GetCharFW		skip "[["

.1				lda (ZPPtr1)			"[#" ?
				cmp #'#'
				beq .2
				
				lda #'['				NZ
				rts

.2				jsr TBOX.GetCharFW		skip "[#"
				beq .8
				
				cmp #']'				skip "htag]"
				bne .2
				
				bra TBOX.GetCharFW		skip "]"
				
.3				jsr TBOX.GetCharFW
				beq .8

				cmp #']'				"text"
				bne .8					NZ

				stz bTemp2

.4				jsr TBOX.GetCharFW		skip "link]"
				beq .8

				cmp #']'
				bne .4

				lda #']'				NZ

.8				rts
*--------------------------------------
TBOX.GetCharFW	lda (ZPPtr1)
				beq .9

				inc ZPPtr1
				bne .1

				inc ZPPtr1+1

.1				inc TempC
				bne .9

				inc TempC+1				NZ

.9				rts
*--------------------------------------
TBOX.GetCharBW	lda TempC
				ora TempC+1
				beq .9
				
				lda ZPPtr1
				bne .1
				
				dec ZPPtr1+1
				
.1				dec ZPPtr1

				lda TempC
				bne .2

				dec TempC+1
				
.2				dec TempC				

				lda (ZPPtr1)

.9				rts
*--------------------------------------
TBOX.CmpTempCAtY
				lda TempC
				cmp (ZPObjPtr),y
				lda TempC+1
				iny
				sbc (ZPObjPtr),y
				rts
*--------------------------------------
TBOX.SetTempCAtY
				lda TempC
				sta (ZPObjPtr),y
				lda TempC+1
				iny
				sta (ZPObjPtr),y
				rts
*--------------------------------------
TBOX.GetLineLenInAXC
				lda ZPPtr1+1
				pha

				clc

				ldy #0
				ldx #0

.1				lda (ZPPtr1),y
				beq .8

				eor #C.CR
				beq .7

				iny
				bne .1

				inx
				bra .1

.7				sec						to skip CR

.8				pla
				sta ZPPtr1+1

				tya						AX = len, CS if CR ended

				rts
*--------------------------------------
TBOX.ToBuf1		ldy #S.TBOX.BufCnt
				lda (ZPObjPtr),y
				ldy #S.OBJ.BufSize
				cmp (ZPObjPtr),y

				ldy #S.TBOX.BufCnt+1
				lda (ZPObjPtr),y
				ldy #S.OBJ.BufSize+1
				sbc (ZPObjPtr),y
				bcs .9

				dey						ldy #S.TBOX.BufCnt

				jsr OBJ.IncWordAtY

				jsr TBOX.GetBuf

				jsr TBOX.Insert1

				lda (pStack)
				sta (ZPPtr2)

.8				clc

.9				rts
*--------------------------------------
TBOX.Insert1	lda #1
				ldx #0

TBOX.InsertAX	clc
				adc ZPPtr2
				sta ZPPtr3
				txa
				adc ZPPtr2+1
				sta ZPPtr3+1

				ldy #0
				ldx #0

.1				lda (ZPPtr2),y
				beq .4

				iny
				bne .1

				inx
				inc ZPPtr2+1
				inc ZPPtr3+1
				bra .1

.2				dex

.3				dey

				lda (ZPPtr2),y

.4				sta (ZPPtr3),y
				tya
				bne .3

				txa
				bne .2

.8				rts
*--------------------------------------
TBOX.Delete1	lda #1
				ldx #0
*--------------------------------------
TBOX.DeleteAX	clc
TBOX.DeleteAXC	adc ZPPtr2
				sta ZPPtr3
				txa
				adc ZPPtr2+1
				sta ZPPtr3+1

				ldy #0

.1				lda (ZPPtr3),y
				sta (ZPPtr2),y
				beq .8

				iny
				bne .1

				inc ZPPtr3+1
				inc ZPPtr2+1
				bra .1

.8				rts
*--------------------------------------
TBOX.CheckViewPort
				jsr TBOX.SetViewPort
				bit bRepaintAll
				bpl .8

				jmp TBOX.DrawAllLines

.8				jmp OBJ.CurUpdPos
*--------------------------------------
TBOX.SetViewPort
				stz bRepaintAll

				ldy #S.TBOX.DocX+1
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.TBOX.HScroll
				sec
				sbc (ZPObjPtr),y

				ldy #S.OBJ.CurX			set CurX = DocX - HScroll
				sta (ZPObjPtr),y

				ldy #S.TBOX.HScroll+1
				txa
				sbc (ZPObjPtr),y		DocX => HScroll ?

				bcs .10					yes..

				ldy #S.TBOX.DocX+1		no, set HScroll = DocX
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.TBOX.HScroll
				sta (ZPObjPtr),y
				iny
				txa
				sta (ZPObjPtr),y

				lda #0					set CurX = 0

				bra .20
*--------------------------------------
.10				ldy #S.TBOX.HScroll+1
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.OBJ.InnerW
				clc
				adc (ZPObjPtr),y
				bcc .11

				inx

.11				ldy #S.TBOX.DocX		(HScroll + InnerW) > (DocX + 1) ?
				clc						DocX+1
				sbc (ZPObjPtr),y
				iny
				txa
				sbc (ZPObjPtr),y
				bcs .21					no...

				ldy #S.OBJ.InnerW		yes, set HScroll = DocX - (InnerW - 1)
				lda (ZPObjPtr),y
				dec
				sta TempW				(InnerW - 1)

				ldy #S.TBOX.DocX
				lda (ZPObjPtr),y
				sec
				sbc TempW
				tax

				iny
				lda (ZPObjPtr),y
				sbc #0
				bcc .12					DocX - (InnerW - 1) < 0

				ldy #S.TBOX.HScroll+1
				sta (ZPObjPtr),y
				dey
				txa
				sta (ZPObjPtr),y

				lda TempW				set CurX = (InnerW - 1)

				bra .20

.12				lda #0
				ldy #S.TBOX.HScroll+1
				sta (ZPObjPtr),y
				dey
				sta (ZPObjPtr),y

.20				ldy #S.OBJ.CurX
				sta (ZPObjPtr),y

				dec bRepaintAll
*--------------------------------------
.21				ldy #S.TBOX.DocY+1
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.TBOX.VScroll
				sec
				sbc (ZPObjPtr),y

				ldy #S.OBJ.CurY			set CurY = DocY - VScroll
				sta (ZPObjPtr),y

				ldy #S.TBOX.VScroll+1
				txa
				sbc (ZPObjPtr),y		DocY => VScroll ?
				bcs .30					yes..

				ldy #S.TBOX.DocY+1		no, set VScroll = DocY
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.TBOX.VScroll
				sta (ZPObjPtr),y
				iny
				txa
				sta (ZPObjPtr),y

				lda #0					set CurY = 0

				bra .40
*--------------------------------------
.30				ldy #S.TBOX.VScroll+1
				lda (ZPObjPtr),y
				tax
				dey
				lda (ZPObjPtr),y

				ldy #S.OBJ.InnerH
				clc
				adc (ZPObjPtr),y
				bcc .31

				inx

.31				ldy #S.TBOX.DocY		(VScroll + InnerH) > (DocY + 1) ?
				clc						DocY+1
				sbc (ZPObjPtr),y
				iny
				txa
				sbc (ZPObjPtr),y
				bcs .41					no...

				ldy #S.OBJ.InnerH		yes, set VScroll = DocY - (InnerH - 1)
				lda (ZPObjPtr),y
				dec
				sta TempW				(InnerH - 1)

				ldy #S.TBOX.DocY
				lda (ZPObjPtr),y
				sec
				sbc TempW
				tax

				iny
				lda (ZPObjPtr),y
				sbc #0
				bcc .32					DocY - (InnerH - 1) < 0

				ldy #S.TBOX.VScroll+1
				sta (ZPObjPtr),y
				dey
				txa
				sta (ZPObjPtr),y

				lda TempW				set CurY = (InnerH - 1)

				bra .40

.32				ldy #S.TBOX.VScroll
				jsr OBJ.ZeroWordAtY

				ldy #S.TBOX.DocY
				lda (ZPObjPtr),y

.40				ldy #S.OBJ.CurY
				sta (ZPObjPtr),y

				dec bRepaintAll

.41				clc						CLC RTS to jmp to
				rts
*--------------------------------------
MAN
SAVE usr/src/lib/libtui.s.tbox
LOAD usr/src/lib/libtui.s
ASM
