NEW
  AUTO 3,1
				.LIST OFF
*--------------------------------------
IO.GetCh		>SYSCALL GetChar
				bcs .9

				cmp #C.CR
				bne IO.GetCh.1

				ldy #S.PS.hStdIn		Check for any extra LF
				lda (pPS),y
				>SYSCALL FEOF
				bcs .9

				tay
				bne .8

				>SYSCALL GetChar
				bcs .9

.8				lda #C.CR

*				clc

.9				rts
*--------------------------------------
IO.GetCh.1		tax

				>LDA.G bEscMode
				bmi .1

				cpx #C.ESC
				bne .8

				lda #$ff
				>STA.G bEscMode

				inc
				clc
				rts

.1				>LDA.G bCSIMode
				bmi .11

				cpx #'['				\e[ ?
				bne IO.GetCh.Esc

				lda #$ff
				>STA.G bCSIMode

				inc

				sta (pData)				#EscBufferPtr

				clc
				rts
*--------------------------------------
.11				lda (pData)				#EscBufferPtr
				cmp #21
				bcc .10

.19				>STZ.G bEscMode
				>STA.G bCSIMode

				clc
				rts

.10				inc
				sta (pData)
				tay

				txa
				sta (pData),y
				cmp #64

				bcs IO.GetCh.CSI

				ldx #0

.8				txa
				clc
				rts
*--------------------------------------
IO.GetCh.Esc	>STZ.G bEscMode

IO.GetCh.Esc1	txa

				ldx #EscChars.Cnt-1

.1				cmp EscChars,x
				beq .2

				dex
				bpl .1

				lda #0
				clc
				rts

.2				lda EscAscii,x
				clc
				rts
*--------------------------------------
* \e[A	UP
* \e[B	DOWN
* \e[C	FOWARD
* \e[D	BACK
* \e[xxx;yyyR	DSR ("\e[I6n" reply)
*--------------------------------------
IO.GetCh.CSI	>STZ.G bEscMode
				>STA.G bCSIMode

				cpx #'R'				Response to cursor position query?
				beq .3
		
				bra IO.GetCh.Esc1

.3				stz TmpByte

				ldy #0

.4				iny

				lda (pData),y
				cmp #';'
				beq .5

				jsr IO.GetCh.TmpByte10pA
				bra .4

.5				phy

				lda TmpByte
				>STA.G ScreenH

				dec						Remove 2 (top & status bar) for viewportH
				dec

				>STA.G ViewPortH

				dec

				>STA.G ViewPortHm1		Remove 1 more to store offsert to last line of viewport

				ply
				stz TmpByte

.6				iny

				lda (pData),y
				cmp #'R'
				beq .7

				jsr IO.GetCh.TmpByte10pA
				bra .6

.7				lda TmpByte
				>STA.G ScreenW

.8				lda #0
				clc
				rts
*--------------------------------------
IO.GetCh.TmpByte10pA
				and #$0f
				pha
				lda TmpByte
				asl
				asl
				clc
				adc TmpByte
				asl
				sta TmpByte
				pla
				clc
				adc TmpByte
				sta TmpByte
				rts
*--------------------------------------
MAN
SAVE usr/src/bin/edit.s.io
LOAD usr/src/bin/edit.s
ASM
