PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
				.LIST OFF
*--------------------------------------
SCRN.Init		ldy #ScreenH
				lda (pData),y
				dec
				>PUSHA
				>LDYA L.SEQ.INIT
				>SYSCALL SYS.PrintFYA
				bcs .9
				lda #12
				>SYSCALL SYS.COutA
				bcs .9
				
				lda #0

				ldy #FileX
				sta (pData),y

				ldy #FileY
				sta (pData),y
				iny
				sta (pData),y
		
				ldy #ScreenX
				sta (pData),y

				ldy #ScreenY
				sta (pData),y
				iny
				sta (pData),y

				jsr SCRN.UpdateTopBar
				bcs .9
				jsr SCRN.UpdateViewPort
				bcs .9
				jsr SCRN.UpdateMain
.9				rts
*--------------------------------------
SCRN.UpdateTopBar	
				ldy #hFileName
				lda (pData),y
				beq .1
				>SYSCALL SYS.GetMemPtrA
				bra .2
				
.1				>LDYA L.MSG.NEWFILE

.2				>PUSHYA

				>LDYA L.MSG.TOPBAR
				>SYSCALL SYS.PrintFYA
				bcs .9


				clc
.9				rts
*--------------------------------------
SCRN.UpdateMain	ldy #ScreenY
				lda (pData),y
				sta TmpIndex
				iny
				lda (pData),y
				sta TmpIndex+1

				lda #0
				sta TmpByte
				
				ldy #ScreenH
				lda (pData),y
				dec
				dec
				sta TmpCount

.1				>LDAX TmpIndex
				jsr BUF.GetLineAX		Y = line length
				bcs .5

				lda TmpByte
				jsr SCRN.UpdateLineAtALenY
				bcs .9
				
.3				inc TmpByte
				inc TmpIndex
				bne .4
				inc TmpIndex+1
				
.4				dec TmpCount
				bne .1
				jmp SCRN.GotoCurXCurY
				
.5				ldx #0
				ldy TmpByte
				jsr GotoXY
				bcs .9
				
				>LDYA L.SEQ.CEOL
				>SYSCALL SYS.PrintFYA
				bcs .9
				
				inc TmpByte
				dec TmpCount
				bne .5
				
				jmp SCRN.GotoCurXCurY

.9				rts
*--------------------------------------
SCRN.UpdateCurrentLine
				ldy #ScreenY+1
				lda (pData),y
				tax
				dey
				lda (pData),y
				clc
				ldy #CurY
				adc (pData),y
				bcc .1
				inx
.1				jsr BUF.GetLineAX
				bcs .9

				phy
				ldy #CurY
				lda (pData),y
				ply
				jsr SCRN.UpdateLineAtALenY
.9				rts
*--------------------------------------
SCRN.UpdateLineAtALenY
				stz bSelected
				sty TmpLen
				ldx #0
				tay
				jsr GotoXY
				bcs .9
				
				ldy #ScreenW
				lda (pData),y
				tax
				
				ldy #ScreenX
				lda (pData),y
				tay
				
.1				cpy TmpLen
				bcs .3
				
				jsr BUF.GetCharAtY
				beq .3
				cmp #13
				beq .3
				phx
				phy
				pha
				jsr BUF.CheckSelected
				jsr SCRN.UpdateAttrC
				pla
				bcs .11
				
				>SYSCALL SYS.COutA
.11				ply
				plx
				bcs .9
				
.2				iny
				dex
				bne .1
				
.3				sec
				jsr SCRN.UpdateAttrC
				bcs .9
				
				>LDYA L.SEQ.CEOL
				>SYSCALL SYS.PrintFYA
				bcs .9
				rts
.9				jmp Ctrl.Q				
*--------------------------------------
* CC = set INV, CS = set NORM
*--------------------------------------
SCRN.UpdateAttrC
				bcc .1
				bit bSelected
				bpl .8
				
				>LDYA L.SEQ.NORM
				>SYSCALL SYS.PrintFYA
				bcs .9
				stz bSelected
				rts
				
.1				bit bSelected
				bmi .8
				
				>LDYA L.SEQ.INV
				>SYSCALL SYS.PrintFYA
				bcs .9
				lda #$ff
				sta bSelected

.8				clc
				rts
.9				jmp Ctrl.Q				
*--------------------------------------
SCRN.UpdateStatusBar 
				ldy #PromptMode
				lda (pData),y
				tax
				bne .2
				
				ldy #FileY+1
				lda (pData),y
				tax
				dey
				lda (pData),y
				inc
				bne .1
				inx
.1				>PUSHAX				
				
				ldy #FileX
				lda (pData),y
				inc
				>PUSHA
				
				ldy #FileLen+1
				>PUSHB (pData),y
				dey
				>PUSHB (pData),y
				
				ldy #ScreenH
				lda (pData),y
				>PUSHA
				>LDYA L.MSG.STATUSBAR
				>SYSCALL SYS.PrintFYA
				bcs .9
				jmp SCRN.GotoCurXCurY
				
.2				cmp #PromptModeHelp
				beq .3
				>PUSHW pData
.3				ldy #ScreenH
				lda (pData),y
				>PUSHA
				>LDYA L.MSG.STATUSBAR,x
				>SYSCALL SYS.PrintFYA
				bcs .9
				rts
.9				jmp Ctrl.Q				
*--------------------------------------
SCRN.UpdateStatusBarErrA
				>PUSHA
				ldy #ScreenH
				lda (pData),y
				>PUSHA
				>LDYA L.MSG.STATUSBAR.E
				>SYSCALL SYS.PrintFYA
				bcs .9
				rts
.9				jmp Ctrl.Q				
*--------------------------------------
SCRN.GotoCurXCurY	
				ldy #CurX
				lda (pData),y
				tax
				ldy #CurY
				lda (pData),y
				tay
				
GotoXY			txa
				inc
				>PUSHA
				tya
				inc
				inc
				>PUSHA

				>LDYA L.MSG.GOTOXY
				>SYSCALL SYS.PrintFYA
				bcs .9
				rts
.9				jmp Ctrl.Q
*--------------------------------------
SCRN.UpdateViewPort	
				lda #$ff
				sta bNotRepaint
				
.1				ldy #FileX
				lda (pData),y
				ldy #ScreenX
				cmp (pData),y
				bcs .2					out of left border ?
				
				ldy #ScreenX
				lda (pData),y
				dec
				sta (pData),y
				stz bNotRepaint
				bra .1
				
.2				clc
				ldy #ScreenX
				lda (pData),y
				
				ldy #ScreenW
				adc (pData),y
				dec
				ldy #FileX
				cmp (pData),y
				bcs .3					out of right border ?
				ldy #ScreenX
				lda (pData),y
				inc
				sta (pData),y
				stz bNotRepaint
				bra .2
				
.3				sec
				ldy #FileY
				lda (pData),y
				ldy #ScreenY
				sbc (pData),y
				ldy #FileY+1
				lda (pData),y
				ldy #ScreenY+1
				sbc (pData),y
				bcs .4					out of top border ?
				
				sec
				ldy #ScreenY
				lda (pData),y
				sbc #1
				sta (pData),y
				iny
				lda (pData),y
				sbc #0
				sta (pData),y
				bit bNotRepaint
				bpl .3
				jsr SCRN.scrollDn
				bcc .3
				jmp Ctrl.Q
				
.4				clc
				ldy #ScreenY
				lda (pData),y
				ldy #ScreenH
				adc (pData),y
				pha
				ldy #ScreenY+1
				lda (pData),y
				adc #0
				tax
				pla

				sec
				sbc #3
				bcs .41
				dex		
				sec
				
.41				ldy #FileY
				sbc (pData),y
				txa
				iny
				sbc (pData),y
				bcs .5					out of bottom border ?
				
				clc
				ldy #ScreenY
				lda (pData),y
				adc #1
				sta (pData),y
				iny
				lda (pData),y
				adc #0
				sta (pData),y
				bit  bNotRepaint
				bpl .4
				jsr SCRN.scrollUp
				bcs .9
				
.5				sec
				ldy #FileX
				lda (pData),y
				ldy #ScreenX
				sbc (pData),y
				ldy #CurX
				sta (pData),y
				
				sec
				ldy #FileY
				lda (pData),y
				ldy #ScreenY
				sbc (pData),y
				ldy #CurY
				sta (pData),y
				
				bit bNotRepaint
				bmi .6
				jsr SCRN.UpdateMain
				bcs .9
.6				jsr SCRN.UpdateStatusBar			
				bcs .9
				jsr SCRN.GotoCurXCurY
				bcs .9
				rts
.9				jmp Ctrl.Q
*--------------------------------------
SCRN.scrollUp	lda #$1B
				>SYSCALL SYS.COutA
				bcs .9
				lda #'M'
				>SYSCALL SYS.COutA
				bcs .9
				
				ldy #ScreenY+1
				lda (pData),y
				tax
				dey
				lda (pData),y
				clc
				adc #21
				bcc .1
				inx
.1				jsr BUF.GetLineAX
				bcs .9
				
				lda #21
				jsr SCRN.UpdateLineAtALenY
				bcs .9
				rts
.9				jmp Ctrl.Q
*--------------------------------------
SCRN.scrollDn	lda #$1B
				>SYSCALL SYS.COutA
				bcs .9
				lda #'D'
				>SYSCALL SYS.COutA
				bcs .9
				
				ldy #ScreenY+1
				lda (pData),y
				tax
				dey
				lda (pData),y
				jsr BUF.GetLineAX
				bcs .9
				
				lda #0
				jsr SCRN.UpdateLineAtALenY
				bcs .9
				rts
.9				jmp Ctrl.Q
*--------------------------------------
MAN
SAVE BIN/EDIT.S.SCRN
LOAD BIN/EDIT.S
ASM
