	include	ed.inc

	.code

	extrn	DeleteEmptyPages:near,UseTwoPages:near

	Entry	InsertBuf
	sub	si,si
@@1:	les	bx,ds:LParam
	mov	al,es:[bx+si]
	cmp	al,0
	je	@@2
	mov	byte ptr ds:CParam,al
	push	si
	Invoke	InsertAllowWS
	Invoke	SetEditDS
	pop	si
	inc	si
	jmp	@@1
@@2:	Exit	InsertBuf

	Entry	InsertText
	push	ds:Options
	and	ds:Options,not eoOverwrite
	or	ds:Options,eoUseTab+eoNoTruncate
@@1:	Invoke	GetParam
	Invoke	SetEditDS
	cmp	al,0
	je	@@2
	mov	byte ptr ds:CParam,al
	Invoke	TypeChar
	Invoke	SetEditDS
	jmp	@@1
@@2:	pop	ds:Options
	Exit	InsertText

	Entry	SmartTab
	test	ds:Options,eoUseTab
	jz	@@1
	mov	byte ptr ds:CParam,9
	Invoke	TypeChar
	jmp	@@12
@@1:	mov	ax,ds:CursorPos.X
	push	ax
	mov	cx,ds:TabSize
	cmp	cx,1
	jg	@@2
	inc	ax
	jmp	@@3
@@2:	add	ax,cx
	push	ax
	dec	ax
	sub	dx,dx
	div	cx
	pop	ax
	sub	ax,dx
@@3:	pop	cx
	push	ds:CursorPos.Y
	push	ax
@@4:	dec	ds:CursorPos.Y
	jz	@@5
	Invoke	GoLine
	Invoke	SetEditDS
	test	ax,ax
	jz	@@4
	cmp	ax,ds:CursorPos.X
	ja	@@6
@@5:	pop	ax
	jmp	@@10
@@6:	Invoke	GoCurPos
	dec	bx
@@7:	inc	bx
	Invoke	CheckWS
	jc	@@9
	jnz	@@7
@@8:	inc	bx
	Invoke	CheckWS
	jz	@@8
@@9:	Invoke	CalcColumn
	Invoke	SetEditDS
	pop	bx
	cmp	ax,ds:CursorPos.X
	ja	@@10
	mov	ax,bx
@@10:	pop	ds:CursorPos.Y
	sub	ax,ds:CursorPos.X
	mov	cx,ax
@@11:	push	cx
	mov	byte ptr ds:CParam,' '
	Invoke	TypeChar
	Invoke	SetEditDS
	pop	cx
	jc	@@12
	loop	@@11
@@12:	Invoke	CenterFixScreen
	Exit	SmartTab

NoteRedraw	proc	near
	or	ds:RedrawFlags,rfCurLine
	or	ds:Modified,emShow+emUpdate
	ret
NoteRedraw	endp

InsertEmptyPage	proc	near
@@1:	lea	bx,ds:PageTbl
	cmp	bx,ds:LastPage
	je	@@2
	cmp	[bx].LinesInPage,0
	jne	@@3
	Invoke	GoTopPage
	Invoke	DeletePage
	Invoke	SetEditDS
	jmp	@@1
@@2:	Invoke	InsertPage
	jc	@@4
	Invoke	GetCurPage
	Invoke	UseCurPage
	jc	@@4
	mov	bx,[bx].PageLength
	mov	es:[bx].LineLength,0
	mov	es:[bx].LineNumber,0
	lea	ax,[bx+size LineHeader+1]
	mov	bx,ds:CurPage
	mov	[bx].PageLength,ax
	inc	[bx].LinesInPage
	clc
	jmp	@@4
@@3:	stc
@@4:	ret
InsertEmptyPage	endp

BreakLine	proc	near
	mov	ax,dx
	sub	ax,cx
	add	ax,size LineHeader+1
	and	al,0feh
	add	ax,cx
	add	ax,size LineHeader+1
	and	al,0feh
	sub	ax,size LineHeader
	sub	ax,dx
	and	al,0feh
	mov	bx,ds:CurPage
	add	ax,[bx].PageLength
	cmp	ax,ds:PageSize
	jbe	@@1
	stc
	jmp	@@5
@@1:	Invoke	ShiftDown
	Invoke	UseCurPage
	Invoke	StoreLinesInfo
	push	ds
	xchg	ax,[bx].PageLength
	inc	[bx].LinesInPage
	mov	es:[di].LineLength,cx
	sub	bx,bx
	test	cx,cx
	jnz	@@2
	xchg	bx,es:[di].LineNumber
@@2:	push	bx
	mov	bx,di
	add	bx,size LineHeader+1
	add	bx,cx
	and	bl,0feh
	add	di,size LineHeader+1
	add	di,dx
	and	di,0fffeh
	sub	dx,cx
	mov	cx,ax
	sub	cx,di
	shr	cx,1
	push	bx
	mov	bx,ds:CurPage
	mov	di,[bx].PageLength
	pop	bx
	dec	di
	dec	di
	push	es
	pop	ds
	push	si
	mov	si,ax
	std
	lodsw
	rep	movsw
	pop	ax
	mov	cx,dx
	test	al,1
	jnz	@@4
	test	cl,1
	jnz	@@3
	inc	si
	inc	si
@@3:	dec	si
@@4:	mov	cx,di
	sub	cx,bx
	shr	cx,1
	rep	movsw
	cld
	mov	[di].LineLength,dx
	pop	ax
	mov	[di].LineNumber,ax
	pop	ds
	mov	ds:CursorPos.X,1
	or	ds:RedrawFlags,rfBelowPrevLine
	Invoke	Down
	Invoke	InvalidateUndo
	Invoke	SetEditDS
	clc
@@5:	ret
BreakLine	endp

CharIntoLine	proc	near
	mov	ax,dx
	add	ax,16
	cmp	ax,ds:PageSize
	jae	@@1
	test	dl,1
	jz	@@4
	mov	bx,ds:CurPage
	mov	ax,[bx].PageLength
	cmp	ax,ds:PageSize
	jb	@@2
@@1:	stc
	jmp	@@5
@@2:	mov	cx,ax
	add	[bx].PageLength,2
	push	si di
	mov	ax,es:[di].LineLength
	add	ax,di
	add	ax,size LineHeader
	push	ds
	push	es
	pop	ds
	mov	di,cx
	sub	cx,ax
	jae	@@3
	sub	cx,cx
@@3:	shr	cx,1
	lea	si,[di-2]
	std
	rep	movsw
	cld
	pop	ds
	pop	di si
@@4:	mov	al,byte ptr ds:CParam
	push	di ds
	push	es
	pop	ds
	mov	cx,[di].LineLength
	inc	[di].LineLength
	sub	cx,si
	add	cx,di
	add	cx,size LineHeader
	add	si,cx
	mov	di,si
	dec	si
	shr	cx,1
	std
	dec	si
	dec	di
	rep	movsw
	inc	si
	inc	di
	rcl	cx,1
	rep	movsb
	cld
	inc	si
	stosb
	pop	ds di
	Invoke	ShiftRight
	inc	si
	mov	bx,si
	Invoke	CalcColumn
	Invoke	SetEditDS
	mov	ds:CursorPos.X,ax
	clc
@@5:	ret
CharIntoLine	endp

_CharIntoPage	proc	near
	test	di,di
	jnz	@@1
	jmp	@@5
@@1:	mov	si,bx
	cmp	di,bx
	je	@@2
	mov	dx,es:[di].LineLength
	mov	cx,si
	sub	cx,di
	sub	cx,size LineHeader
	test	ds:Options,eoOverwrite
	jz	@@3
	mov	al,byte ptr ds:CParam
	cmp	al,0dh
	je	@@6
	cmp	al,0ah
	je	@@6
	cmp	cx,dx
	jae	@@3
	mov	es:[si],al
	call	NoteRedraw
	inc	si
	mov	bx,si
	Invoke	CalcColumn
	Invoke	SetEditDS
	mov	ds:CursorPos.X,ax
	clc
	jmp	@@8
@@2:	lea	ax,[si+size LineHeader]
	inc	ax
	and	al,0feh
	cmp	ax,ds:PageSize
	ja	@@5
	sub	dx,dx
	mov	es:[di].LineLength,dx
	mov	ds:CursorPos.X,1
	or	ds:RedrawFlags,rfBelowPrevLine
	mov	bx,ds:CurPage
	mov	[bx].PageLength,ax
	inc	[bx].LinesInPage
	mov	dx,es:[di].LineLength
	sub	cx,cx
@@3:	cmp	byte ptr ds:CParam,0ah
	je	@@8
	call	NoteRedraw
	cmp	byte ptr ds:CParam,0dh
	je	@@4
	call	CharIntoLine
	jmp	@@8
@@4:	call	BreakLine
	jmp	@@8
@@5:	stc
	jmp	@@8
@@6:	Invoke	CheckForLastLine
	jc	@@7
	Invoke	Down
	Invoke	LOfLine
	Invoke	SetEditDS
	test	ds:Options,eoAutoIndent
	jz	@@8
	Invoke	SkipWS
	Invoke	SetEditDS
	jmp	@@8
@@7:	Invoke	ROfLine
	Invoke	SetEditDS
	push	ds:Options
	and	ds:Options,not eoOverwrite
	Invoke	TypeChar
	Invoke	SetEditDS
	pop	ds:Options
@@8:	ret
_CharIntoPage	endp

CharIntoPage	proc	near
	Invoke	GoCurPos
	Invoke	UseCurPage
	jc	@@4
	cmp	byte ptr ds:CParam,0dh
	je	@@2
	mov	cx,ax
	mov	ax,bx
	sub	ax,di
	sub	ax,size LineHeader
	sub	ax,es:[di].LineLength
	jz	@@3
	test	cx,cx
	jz	@@2
	cmp	byte ptr ds:CParam,9
	je	@@2
	mov	al,byte ptr ds:CParam
	push	ax ds:Options
	and	ds:Options,not eoOverwrite
	mov	byte ptr ds:CParam,' '
@@1:	push	cx
	call	_CharIntoPage
	Invoke	GoCurPos
	Invoke	UseCurPage
	pop	cx
	loop	@@1
	pop	ds:Options ax
	mov	byte ptr ds:CParam,al
@@2:	call	_CharIntoPage
	jmp	@@4
@@3:	inc	cx
	mov	ax,cx
	add	ax,es:[di].LineLength
	jc	@@4
	add	ax,16
	jc	@@4
	cmp	ax,ds:PageSize
	jb	@@5
	stc
@@4:	jmp	@@12
@@5:	mov	si,ds:CurPage
	mov	ax,ds:PageSize
	sub	ax,[si].PageLength
	cmp	ax,cx
	jb	@@6
	jmp	@@11
@@6:	add	ax,di
	sub	ax,size PageHeader
	cmp	ax,cx
	jae	@@9
	mov	ax,ds:PageSize
	sub	ax,di
	sub	ax,size LineHeader
	sub	ax,es:[di].LineLength
	cmp	ax,cx
	jae	@@8
	Invoke	ReserveSpace
	Invoke	SetEditDS
	jnc	@@8
@@7:	jmp	@@4
@@8:	Invoke	FindCurLine
	Invoke	UseCurPage
	mov	ax,es:[bx].LineLength
	add	ax,bx
	add	ax,size LineHeader+1
	mov	bx,ds:CurPage
	cmp	ax,[bx].PageLength
	jae	@@10
	inc	ds:CursorPos.Y
	Invoke	RestToNextPage
	Invoke	SetEditDS
	dec	ds:CursorPos.Y
	jnc	@@9
	Invoke	InsertPage
	Invoke	SetEditDS
	jc	@@4
	inc	ds:CursorPos.Y
	Invoke	RestToNextPage
	Invoke	SetEditDS
	dec	ds:CursorPos.Y
	jnc	@@10
	jmp	@@7
@@9:	Invoke	ReserveSpace
	Invoke	SetEditDS
	jc	@@7
@@10:	Invoke	GoCurPos
	Invoke	UseCurPage
	mov	cx,ax
	inc	cx
@@11:	mov	bx,es:[di].LineLength
	lea	ax,[di+size LineHeader+bx+1]
	and	al,0feh
	add	bx,cx
	lea	bx,[di+size LineHeader+bx+1]
	and	bl,0feh
	sub	bx,ax
	push	di cx
	mov	di,ds:CurPage
	mov	si,[di].PageLength
	mov	cx,si
	sub	cx,ax
	shr	cx,1
	add	[di].PageLength,bx
	dec	si
	dec	si
	lea	di,[bx+si]
	push	ds
	push	es
	pop	ds
	std
	rep	movsw
	pop	ds
	cld
	pop	cx di
	mov	bx,es:[di].LineLength
	add	es:[di].LineLength,cx
	mov	si,di
	lea	di,[di+size LineHeader+bx]
	mov	al,' '
	dec	cx
	rep	stosb
	mov	al,byte ptr ds:CParam
	mov	di,si
	lea	bx,[di+size LineHeader-1]
	add	bx,es:[di].LineLength
	mov	si,bx
	mov	es:[si],al
	call	NoteRedraw
	Invoke	ShiftRight
	inc	si
	mov	bx,si
	Invoke	CalcColumn
	Invoke	SetEditDS
	mov	ds:CursorPos.X,ax
	clc
@@12:	ret
CharIntoPage	endp

	loc	H,dword,1
	Entry	LineToPrevPage
	mov	bx,ds:CurPage
	cmp	bx,offset PageTbl
	jbe	@@2
	Invoke	LockCurPage
	jc	@@2
	mov	bx,ds:CurPage
	les	bx,[bx-size PageInfo].PageHandle
	mov	H.Offs,bx
	mov	H.Segm,es
	mov	ax,es:[bx]
	cmp	ax,VMemLimit
	ja	@@1
	push	es bx
	push	es bx
	SetTurboDS
	Invoke	UseHandle
	Invoke	SetEditDS
	pop	bx es
	mov	ax,es:[bx]
	cmp	ax,VMemLimit
	ja	@@1
	InvokeJ	ErrorExit
@@1:	mov	bx,ds:CurPage
	mov	ax,ds:PageSize
	sub	ax,[bx-size PageInfo].pageLength
	jbe	@@2
	les	si,ds:LockedPage
	mov	es,es:[si]
	mov	cx,es:[size PageHeader].LineLength
	add	cx,size LineHeader+1
	and	cl,0feh
	cmp	ax,cx
	jae	@@3
@@2:	stc
	jmp	@@4
@@3:	Invoke	StoreLinesInfo
	les	bx,H
	mov	es,es:[bx]
	mov	bx,ds:CurPage
	sub	bx,size PageInfo
	Invoke	StoreLinesInfo
	add	bx,size PageInfo
	inc	word ptr [bx-size PageInfo].LinesInPage
	dec	word ptr [bx].LinesInPage
	mov	di,[bx-size PageInfo].PageLength
	add	[bx-size PageInfo].PageLength,cx
	sub	[bx].PageLength,cx
	mov	bx,[bx].PageLength
	push	ds
	lds	si,ds:LockedPage
	mov	ds,[si]
	mov	si,size PageHeader
	cld
	shr	cx,1
	rep	movsw
	push	ds
	pop	es
	mov	di,size PageHeader
	mov	ds:CurLineNum,-1
	mov	cx,bx
	sub	cx,di
	shr	cx,1
	rep	movsw
	pop	ds
	inc	ds:CPFirstLine
	clc
@@4:	Exit	LineToPrevPage

	loc	H,dword,1
	Entry	LineToNextPage
	call	UseTwoPages
	jc	@@3
	mov	H.Offs,ax
	mov	H.Segm,dx
	mov	ax,ds:PageSize
	sub	ax,[bx+size PageInfo].PageLength
	jbe	@@3
	les	si,ds:LockedPage
	mov	es,es:[si]
	mov	cx,[bx].PageLength
	mov	si,cx
	mov	bx,size PageHeader
	mov	dx,bx
@@1:	cmp	bx,si
	jae	@@2
	mov	dx,bx
	add	bx,es:[bx].LineLength
	add	bx,size LineHeader+1
	and	bl,0feh
	loop	@@1
@@2:	sub	bx,dx
	cmp	ax,bx
	jae	@@4
@@3:	jmp	@@5
@@4:	mov	ax,bx
	les	bx,H
	mov	es,es:[bx]
	mov	bx,ds:CurPage
	add	bx,size PageInfo
	Invoke	StoreLinesInfo
	mov	bx,ds:CurPage
	mov	si,[bx+size PageInfo].PageLength
	inc	word ptr [bx+size PageInfo].LinesInPage
	add	[bx+size PageInfo].PageLength,ax
	dec	word ptr [bx].LinesInPage
	sub	[bx].PageLength,ax
	push	ds
	push	es
	pop	ds
	mov	ds:CurLineNum,-1
	mov	cx,si
	sub	cx,size PageHeader
	shr	cx,1
	dec	si
	dec	si
	mov	bx,ax
	lea	di,[bx+si]
	std
	rep	movsw
	pop	ds
	push	ds
	lds	si,ds:LockedPage
	mov	ds,[si]
	mov	ds:CurLineNum,-1
	mov	si,dx
	add	si,bx
	dec	si
	dec	si
	mov	cx,bx
	shr	cx,1
	rep	movsw
	cld
	pop	ds
	clc
	jmp	@@6
@@5:	stc
@@6:	Exit	LineToNextPage

	Entry	RestToNextPage
	Invoke	FindCurLine
	Invoke	UseCurPage
	jc	@@1
	mov	ax,ds:CurPage
	mov	si,ax
	add	ax,size PageInfo
	cmp	ax,ds:LastPage
	jae	@@1
	mov	cx,[si].PageLength
	sub	cx,bx
	jbe	@@2
	mov	ax,ds:PageSize
	sub	ax,[si+size PageInfo].PageLength
	jbe	@@1
	cmp	ax,cx
	jb	@@1
	push	bx cx
	call	UseTwoPages
	pop	cx bx
	jnc	@@3
@@1:	jmp	@@5
@@2:	jmp	@@4
@@3:	mov	si,bx
	mov	es,dx
	mov	bx,ax
	mov	es,es:[bx]
	mov	bx,ds:CurPage
	add	bx,size PageInfo
	Invoke	StoreLinesInfo
	mov	bx,si
	mov	si,ds:CurPage
	mov	dx,[si+size PageInfo].PageLength
	xchg	bx,[si].PageLength
	add	[si+size PageInfo].PageLength,cx
	push	ds
	push	es
	pop	ds
	mov	si,dx
	mov	di,si
	add	di,cx
	push	cx
	mov	cx,si
	sub	cx,size PageHeader
	shr	cx,1
	std
	dec	si
	dec	si
	dec	di
	dec	di
	rep	movsw
	pop	cx
	pop	ds
	push	ds
	lds	si,ds:LockedPage
	mov	ds,[si]
	mov	si,bx
	dec	si
	dec	si
	shr	cx,1
	rep	movsw
	cld
	mov	es:CurLineNum,-1
	pop	ds
	mov	ax,ds:CursorPos.Y
	sub	ax,ds:CPFirstLine
	mov	bx,ds:CurPage
	xchg	ax,[bx].LinesInPage
	sub	ax,[bx].LinesInPage
	add	[bx+size PageInfo].LinesInPage,ax
@@4:	clc
	jmp	@@6
@@5:	stc
@@6:	Exit	RestToNextPage

	loc	H,dword,1
	Entry	LineFromNextPage
	call	DeleteEmptyPages
	jnc	@@1
	sub	cx,cx
	stc
	jmp	@@3
@@1:	mov	H.Offs,ax
	mov	H.Segm,dx
	mov	ax,ds:PageSize
	sub	ax,[bx].PageLength
	jbe	@@2
	les	si,H
	mov	es,es:[si]
	mov	cx,es:[size PageHeader].LineLength
	add	cx,size LineHeader+1
	and	cl,0feh
	cmp	ax,cx
	jb	@@2
	les	si,ds:LockedPage
	mov	es,es:[si]
	Invoke	StoreLinesInfo
	les	si,H
	mov	es,es:[si]
	add	bx,size PageInfo
	Invoke	StoreLinesInfo
	Invoke	SetEditDS
	les	si,H
	mov	es,es:[si]
	sub	bx,size PageInfo
	mov	di,[bx].PageLength
	mov	si,size PageHeader
	mov	dx,[bx+size PageInfo].PageLength
	add	[bx].PageLength,cx
	inc	[bx].LinesInPage
	sub	[bx+size PageInfo].PageLength,cx
	dec	[bx+size PageInfo].LinesInPage
	push	ds
	push	es
	les	bx,ds:LockedPage
	mov	es,es:[bx]
	pop	ds
	cld
	shr	cx,1
	rep	movsw
	push	ds
	pop	es
	mov	di,size PageHeader
	mov	ds:CurLineNum,-1
	mov	cx,dx
	sub	cx,si
	shr	cx,1
	rep	movsw
	pop	ds
	clc
	jmp	@@3
@@2:	mov	cx,1
	stc
@@3:	Exit	LineFromNextPage

_Insert	proc	near
	test	ds:Options,eoOverwrite
	jnz	@@3
	cmp	byte ptr ds:CParam,0dh
	jne	@@1
	Invoke	TotalLines
	Invoke	SetEditDS
	cmp	ax,32767
	jb	@@2
	mov	ax,erTooManyLines
	or	ds:Errors,al
	mov	ds:ReturnCode,ax
	stc
	jmp	@@14
@@1:	Invoke	FindCurLine
	Invoke	UseCurPage
	jc	@@3
	cmp	es:[bx].LineLength,4000
	jle	@@3
	mov	ax,erLineTooLong
	or	ds:Errors,al
	mov	ds:ReturnCode,ax
	stc
	jmp	@@14
@@2:	inc	ax
@@3:	mov	cx,2
	push	cx
	jmp	@@5
@@4:	push	cx
	Invoke	CompactPages
@@5:	mov	cx,4
@@6:	push	cx
	call	CharIntoPage
	jnc	@@12
	Invoke	LineToPrevPage
	jc	@@7
	call	CharIntoPage
	jnc	@@12
	jmp	@@8
@@7:	Invoke	LineToNextPage
	jnc	@@9
	call	InsertEmptyPage
	jnc	@@9
@@8:	Invoke	InsertPage
	jc	@@10
	Invoke	LineToNextPage
	jc	@@10
@@9:	pop	cx
	loop	@@6
	jmp	@@11
@@10:	pop	cx
@@11:	pop	cx
	loop	@@4
	stc
	jmp	@@13
@@12:	pop	cx
	pop	cx
	sub	ax,ax
@@13:	Invoke	SetEditDS
@@14:	ret
_Insert	endp

	Entry	InsertAllowUndo
	push	si di
	Invoke	CheckLine
	Invoke	SetEditDS
	test	ds:Options,eoUndoDisabled
	jnz	@@3
	Invoke	GoCurPos
	Invoke	UseCurPage
	jc	@@3
	cmp	di,bx
	je	@@1
	mov	ax,es:[di].LineLength
	test	ax,ax
	jnz	@@2
@@1:	Invoke	InvalidateUndo
@@2:	Invoke	UpdateUndo
@@3:	call	_Insert
	pop	di si
	Exit	InsertAllowUndo

	Entry	InsertAllowWS
	push	ds:Options
	and	ds:Options,not eoOverwrite
	or	ds:Options,eoUseTab+eoNoTruncate
	Invoke	InsertAllowUndo
	Invoke	SetEditDS
	pop	ds:Options
	Exit	InsertAllowWS

	Entry	TypeChar
	push	si di ds:Options
	Invoke	CheckLine
	Invoke	SetEditDS
	test	ds:Options,eoUndoDisabled
	jnz	@@3
	Invoke	GoCurPos
	Invoke	UseCurPage
	jc	@@1
	cmp	di,bx
	je	@@1
	mov	ax,es:[di].LineLength
	test	ax,ax
	jnz	@@2
@@1:	Invoke	InvalidateUndo
@@2:	Invoke	UpdateUndo
	Invoke	SetEditDS
@@3:	cmp	byte ptr ds:CParam,0dh
	jne	@@5
	test	ds:Options,eoAutoIndent
	jz	@@5
	test	ds:Options,eoOverwrite
	jnz	@@5
	push	ds:CursorPos.X
	Invoke	SkipWS
	Invoke	SetEditDS
	pop	ax
	jcxz	@@6
	cmp	ax,ds:CursorPos.X
	jg	@@6
	push	ds:CursorPos.X
	mov	ds:CursorPos.X,1
	call	_Insert
	pop	ds:CursorPos.X
@@4:	jmp	@@14
@@5:	call	_Insert
	jmp	@@4
@@6:	mov	ds:CursorPos.X,ax
	call	_Insert
	jc	@@4
	push	ds:CursorPos.Y
@@7:	dec	ds:CursorPos.Y
	jz	@@8
	Invoke	SkipWS
	Invoke	SetEditDS
	jcxz	@@7
@@8:	pop	ds:CursorPos.Y
	Invoke	FindCurLine
	Invoke	UseCurPage
	cmp	es:[bx].LineLength,0
	je	@@13
	mov	cx,ds:CursorPos.X
	mov	ds:CursorPos.X,1
	dec	cx
	jz	@@13
	and	ds:Options,not eoOverwrite
	push	cx
	mov	byte ptr ds:CParam,'x'
	call	_Insert
	mov	ds:CursorPos.X,1
	pop	cx
	test	ds:Options,eoUseTab
	jz	@@11
@@9:	sub	cx,ds:TabSize
	jb	@@10
	push	cx
	mov	byte ptr ds:CParam,9
	call	_Insert
	pop	cx
	jc	@@14
	jmp	@@9
@@10:	add	cx,ds:TabSize
	jz	@@12
@@11:	push	cx
	mov	byte ptr ds:CParam,' '
	call	_Insert
	pop	cx
	jc	@@14
	loop	@@11
@@12:	Invoke	DeleteChar
	Invoke	SetEditDS
@@13:	clc
@@14:	pop	ds:Options di si
	Exit	TypeChar

	Entry	InsertNoOver
	push	ds:Options
	and	ds:Options,not eoOverwrite
	Invoke	InsertAllowUndo
	Invoke	SetEditDS
	pop	ds:Options
	Exit	InsertNoOver

	end
