	include	ed.inc

	.code

	Entry	StorePagesInfo
	lea	bx,ds:PageTbl
	mov	ax,1
	jmp	@@2
@@1:	mov	[bx].FirstLineNumber,ax
	add	ax,[bx].LinesInPage
	add	bx,size PageInfo
@@2:	cmp	bx,ds:LastPage
	jb	@@1
	Exit	StorePagesInfo

	public	StoreLinesInfo
StoreLinesInfo	proc	far
	cmp	bx,ds:LastPage
	jae	@@3
	cmp	[bx].FirstLineNumber,0
	je	@@3
	push	ax bx cx dx
	sub	ax,ax
	xchg	ax,[bx].FirstLineNumber
	mov	cx,[bx].LinesInPage
	jcxz	@@2
	mov	bx,size PageHeader
	mov	dx,ds:PageSize
	sub	dx,2
@@1:	cmp	bx,dx
	jae	@@2
	mov	es:[bx].LineNumber,ax
	inc	ax
	add	bx,es:[bx].LineLength
	add	bx,size LineHeader+1
	and	bl,0feh
	loop	@@1
@@2:	pop	dx cx bx ax
@@3:	ret
StoreLinesInfo	endp

	Entry	FindOldLine
	mov	ax,word ptr ds:LParam
	lea	bx,ds:PageTbl
	mov	dx,1
	jmp	@@3
@@1:	mov	cx,[bx].FirstLineNumber
	jcxz	@@2
	cmp	ax,cx
	jb	@@2
	add	cx,[bx].LinesInPage
	cmp	ax,cx
	jae	@@2
	mov	cx,[bx].FirstLineNumber
	sub	ax,cx
	add	ax,dx
	jmp	@@10
@@2:	add	dx,[bx].LinesInPage
	add	bx,size PageInfo
@@3:	cmp	bx,ds:LastPage
	jb	@@1
	Invoke	GoTopPage
	Invoke	SetEditDS
@@4:	mov	bx,ds:CurPage
	mov	cx,[bx].FirstLineNumber
	jcxz	@@7
@@5:	Invoke	GoNextPage
	Invoke	SetEditDS
	jnc	@@4
	stc
	jmp	@@11
@@6:	jmp	@@11
@@7:	Invoke	GetCurPage
	Invoke	UseCurPage
	jc	@@6
	mov	dx,[bx].PageLength
	mov	bx,size PageHeader
	mov	cx,word ptr ds:LParam
	mov	ax,ds:CPFirstLine
	jmp	@@9
@@8:	cmp	cx,es:[bx].LineNumber
	je	@@10
	add	bx,es:[bx].LineLength
	add	bx,size LineHeader+1
	and	bl,0feh
	inc	ax
@@9:	cmp	bx,dx
	jb	@@8
	jmp	@@5
@@10:	mov	ds:CursorPos.Y,ax
	mov	ds:RedrawLine,ax
	mov	ds:CursorPos.X,1
	clc
@@11:	Exit	FindOldLine

	Entry	GetNewLineNumber
	mov	ax,word ptr ds:LParam
	Invoke	FindPage
	Invoke	SetEditDS
	jc	@@1
	mov	ax,[bx].FirstLineNumber
	test	ax,ax
	jnz	@@2
	Invoke	FindCurLine
	Invoke	UseCurPage
	jc	@@1
	cmp	bx,dx
	je	@@1
	mov	ax,es:[bx].LineNumber
	jmp	@@3
@@1:	sub	ax,ax
	jmp	@@3
@@2:	add	ax,cx
@@3:	mov	ds:ReturnCode,ax
	Exit	GetNewLineNumber

	end
