
	load 'macros.dump'
	include 'driver.equ'
	include 'pl.equ'

;-----------------------------------------------
;
;   Imported addresses
;
;-----------------------------------------------

	IMPORT	P_KillUndo
	IMPORT	T_DotLine
	IMPORT	T_DotObj
	IMPORT	T_DotOffset
	IMPORT	T_DotParag
	IMPORT	T_DotPixs
	IMPORT	T_FontFlags
	IMPORT	T_GetObject
	IMPORT	T_GetParPtr
	IMPORT	T_GetParSize
	IMPORT	T_InvSelect
	IMPORT	T_JunkRight
	IMPORT	T_MovedDot
	IMPORT	T_NextChar
	IMPORT	T_Pix2Offset
	IMPORT	T_PrevChar
	IMPORT	T_RangeFont
	IMPORT	T_TextSelect



;-----------------------------------------------------------------------------
;
; T_DoControl (Char:w; ModFlags:w)
;

T_DoControl	PROC		EXPORT
			;Using P_ObjData
			;Using T_TextEqu
			;Using T_Data

		INPUT Char:w,ModFlags:w
		LOCAL ParagPtr:l,LastPar:w
		LOCAL ObjHdl:l,ObjPtr:l,MaxWidth:w

		BEGIN

		stz T_FontFlags
		jsl T_InvSelect
		stz T_TextSelect

		rcall T_GetParPtr,in=(#0:a),out=(ParagPtr:ax)
		moveword [ParagPtr],a
		dec a
		sta LastPar



		lda Char
		asl a
		tax
		jmp (JumpTable,x)



; Left arrow

_LeftArrow
		rcall T_PrevChar,in=(T_DotParag:a,T_DotOffset:x)
		cmp #0
		beq PrevParag
		sta T_DotOffset
		brl MovedDot


PrevParag
		lda T_DotParag
		beq NoDec
		dec a
		sta T_DotParag

		rcall T_GetParSize,in=(a:a),out=(a:a)
		dec a
		sta T_DotOffset
NoDec	brl MovedDot



_RightArrow
		rcall T_NextChar,in=(T_DotParag:a,T_DotOffset:x)
		cmp #0
		beq NextParag
		sta T_DotOffset
		brl MovedDot

NextParag
		cmpw T_DotParag,LastPar
		bge NoInc
		inc T_DotParag
		moveword #T_ParHeader,T_DotOffset
NoInc	brl MovedDot



_UpArrow
		lda T_DotLine
		beq PrevParag2

		dec T_DotLine
		bra FindPixs

PrevParag2
		lda T_DotParag
		jeq Exit

		dec T_DotParag
		rcall T_GetParPtr,in=(T_DotParag:a),out=(ParagPtr:ax)
		moveword [ParagPtr]:#T_LineCount,a
		dec a
		sta T_DotLine
		bra FindPixs


_DownArrow
		rcall T_GetParPtr,in=(T_DotParag:a),out=(ParagPtr:ax)
		lda T_DotLine
		inc a
		cmpw a,[ParagPtr]:#T_LineCount
		bge NextParag2

		inc T_DotLine
		bra FindPixs

NextParag2
		cmpw T_DotParag,LastPar
		jeq Exit

		inc T_DotParag
		stz T_DotLine


FindPixs
		call T_GetObject,in=(T_DotParag:w,T_DotLine:w),out=(T_DotObj:l)

		movelong T_DotObj,ObjHdl
		movelong [ObjHdl],ObjPtr
		subword [ObjPtr]:#P_TRect+6,[ObjPtr]:#P_TRect+2,MaxWidth
		in  T_DotParag:w,T_DotLine:w,T_DotPixs:w,MaxWidth:w
		out T_DotOffset:w,T_DotPixs:w
		xcall T_Pix2Offset



MovedDot
		rcall T_JunkRight,in=(T_DotParag:a,T_DotOffset:x)
		sta T_DotOffset

		jsl P_KillUndo
		jsl T_MovedDot
		jsl T_RangeFont

Exit
		RETURN


JumpTable
	DC.W	Exit	;0
	DC.W	Exit	;1
	DC.W	Exit	;2
	DC.W	Exit	;3
	DC.W	Exit	;4
	DC.W	Exit	;5
	DC.W	Exit	;6
	DC.W	Exit	;7
	DC.W	_LeftArrow	;8
	DC.W	Exit	;9 Tab
	DC.W	_DownArrow	;10
	DC.W	_UpArrow	;11
	DC.W	Exit	;12
	DC.W	Exit	;13 CR
	DC.W	Exit	;14
	DC.W	Exit	;15
	DC.W	Exit	;16
	DC.W	Exit	;17
	DC.W	Exit	;18
	DC.W	Exit	;19
	DC.W	Exit	;20
	DC.W	_RightArrow	;21
	DC.W	Exit	;22
	DC.W	Exit	;23
	DC.W	Exit	;24
	DC.W	Exit	;25
	DC.W	Exit	;26
	DC.W	Exit	;27
	DC.W	Exit	;28
	DC.W	Exit	;29
	DC.W	Exit	;30
	DC.W	Exit	;31

		ENDP
		END

