A2osX/BIN/EDIT.S.txt
2019-11-25 08:05:07 +01:00

532 lines
11 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/EDIT
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/MLI.I
.INB INC/MLI.E.I
*--------------------------------------
PROMPTBUFMAX .EQ 64
TABLEN .EQ 4
TABMASK .EQ 3
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
BufPtr .BS 2
BufPtrDst .BS 2
ClipboardPtr .BS 2
LineBufPtr .BS 2
BUF.LOffset .BS 2
BUF.COffset .BS 2
BUF.TmpLine1 .BS 2
BUF.TmpLine2 .BS 2
FileLen .BS 2
BufLen .BS 2
SelLen .BS 2
ZPPTR1 .BS 2
bRepaint .BS 1
bSelected .BS 1
ZPPTR2 .EQ *
TmpLen .BS 2
TmpIndex .BS 2
TmpCount .BS 1
TmpByte .BS 1
ZS.END .ED
*--------------------------------------
PromptModeHelp .EQ 2
PromptModeFind .EQ 4
PromptModeReplace .EQ 6
PromptModeSave .EQ 8
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0
.DA #0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.SEQ.DETECT .DA SEQ.DETECT
L.SEQ.INIT .DA SEQ.INIT
L.SEQ.SCROLLRGN .DA SEQ.SCROLLRGN
L.SEQ.RESET .DA SEQ.RESET
L.SEQ.SCROLLUP .DA SEQ.SCROLLUP
L.SEQ.SCROLLDN .DA SEQ.SCROLLDN
L.SEQ.SCROLLCURUP .DA SEQ.SCROLLCURUP
L.SEQ.SCROLLCURDN .DA SEQ.SCROLLCURDN
L.SEQ.CEOL .DA SEQ.CEOL
L.SEQ.BAR .DA SEQ.BAR
L.MSG.TOPBAR .DA MSG.TOPBAR
L.MSG.FILETYPES .DA MSG.TXTCR
.DA MSG.TXTCRLF
.DA MSG.TXTASM
L.MSG.STATUSBAR .DA MSG.STATUSBAR
.DA MSG.STATUSBAR.H
.DA MSG.STATUSBAR.F
.DA MSG.STATUSBAR.R
.DA MSG.STATUSBAR.S
.DA MSG.STATUSBAR.E
L.MSG.NEWFILE .DA MSG.NEWFILE
L.MSG.GOTOXY .DA MSG.GOTOXY
L.MSG.HELPLINE .DA MSG.HELPLINE
L.MSG.HELP .DA MSG.HELP
J.SAVE .DA FILE.Save.CR
.DA FILE.Save.CRLF
.DA FILE.Save.ASM
J.PROMPT .DA Prompt.Editor
.DA Prompt.Help
.DA Prompt.Find
.DA Prompt.Replace
.DA Prompt.Save
J.CTRL .DA Ctrl.Invalid
.DA Ctrl.A
.DA Ctrl.B
.DA Ctrl.C
.DA Ctrl.D
.DA Ctrl.E
.DA Ctrl.F
.DA Ctrl.G
.DA Ctrl.BS
.DA Ctrl.TAB
.DA Ctrl.LF
.DA Ctrl.VT
.DA Ctrl.L
.DA Ctrl.CR
.DA Ctrl.N
.DA Ctrl.O
.DA Ctrl.P
.DA Ctrl.Q
.DA Ctrl.R
.DA Ctrl.S
.DA Ctrl.T
.DA Ctrl.FS
.DA Ctrl.V
.DA Ctrl.W
.DA Ctrl.X
.DA Ctrl.Y
.DA Ctrl.Z
.DA Ctrl.Invalid
.DA Ctrl.Invalid
.DA Ctrl.Invalid
.DA Ctrl.Invalid
.DA Ctrl.Invalid
L.DLG.SAVE .DA DLG.SAVE
J.DLG.CTRL.Draw .DA DLG.CTRL.Draw.LBL
.DA DLG.CTRL.Draw.TB
.DA DLG.CTRL.Draw.OL
.DA DLG.CTRL.Draw.BUT
J.DLG.CTRL.Focus
.DA DLG.CTRL.Focus.LBL
.DA DLG.CTRL.Focus.TB
.DA DLG.CTRL.Focus.OL
.DA DLG.CTRL.Focus.BUT
.DA 0
*--------------------------------------
CS.INIT clc
CS.INIT.RTS rts
*--------------------------------------
CS.RUN >PUSHBI 0
>LDYA L.SEQ.DETECT
>SYSCALL printf Send Query for term W & H
bcs CS.INIT.RTS
.1 >SYSCALL GetChar
bcs CS.RUN.RTS
jsr CharIn
>LDA.G ScreenW Wait for Response from terminal for W & H
beq .1
>LDYAI 510+5+5+4+1 potentially 255*\\ NORM,INV,CEOL & \0
>SYSCALL Getmem
bcs CS.RUN.RTS
>STYA.G LineBufBase
txa
>STA.G hLineBuffer
lda #1
>SYSCALL ArgV
bcs .2 No arg, new file....
>SYSCALL RealPath
txa
>STA.G hFileName
jsr FILE.Load
bcc .3 if CS, Failed to load file, keep name, but new file....
cmp #E.OOM
beq CS.RUN.RTS
.2 jsr FILE.New
bcs CS.RUN.RTS
.3 lda #$ff
>STA.G bSaved
jsr SCRN.Init
bcs CS.RUN.RTS
CS.RUN.LOOP >SYSCALL GetChar
bcs CS.RUN.RTS I/O error
jsr CharIn
bcs .9
>LDA.G bExit
bpl CS.RUN.LOOP
lda #0
.9 pha
>PUSHBI 0
>LDYA L.SEQ.RESET
>SYSCALL printf
pla
sec
CS.RUN.RTS rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT ldy #hLineBuffer
jsr .8
ldy #hBuffer
jsr .8
ldy #hBufferBackup
jsr .8
ldy #hClipBoard
jsr .8
ldy #hFileName
.8 lda (pData),y
beq .9
>SYSCALL FreeMem
.9 clc
rts
*--------------------------------------
CharIn tax
>LDA.G bEscMode
asl
txa
bcc .1 Not in ESC mode
cmp #'['
beq .8
ldy #EscBuffer
lda (pData),y
inc
sta (pData),y
clc
adc #EscBuffer
tay
txa
sta (pData),y
cmp #64
bcc .8
jsr CharIn.Esc
bcs .8 Not translated, exit
.1 cmp #C.ESC
bne .2
lda #$ff
>STA.G bEscMode
inc
>STA.G EscBuffer
.8 clc
rts
.2 pha
>LDA.G PromptMode
tax
pla
jmp (J.PROMPT,x)
*--------------------------------------
CharIn.Esc >STZ.G bEscMode
ldy #EscBuffer
lda (pData),y
clc
adc #EscBuffer
tay
lda (pData),y
ldx #EscChars.Cnt-1
.1 cmp EscChars,x
beq .2
dex
bpl .1
cmp #'R' Response to cursor position query?
beq .3
sec
rts
.2 lda EscAscii,x
clc
rts
.3 stz TmpByte
ldy #EscBuffer+1
.4 lda (pData),y
cmp #';'
beq .5
and #$0f
pha
lda TmpByte
asl
asl
clc
adc TmpByte
asl
sta TmpByte
pla
clc
adc TmpByte
sta TmpByte
iny
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
iny
.6 lda (pData),y
cmp #'R'
beq .7
and #$0f
pha
lda TmpByte
asl
asl
clc
adc TmpByte
asl
sta TmpByte
pla
clc
adc TmpByte
sta TmpByte
iny
bra .6
.7 lda TmpByte
>STA.G ScreenW
sec
rts
*--------------------------------------
.INB USR/SRC/BIN/EDIT.S.BUF
.INB USR/SRC/BIN/EDIT.S.CTRL
.INB USR/SRC/BIN/EDIT.S.DLG
.INB USR/SRC/BIN/EDIT.S.FILE
.INB USR/SRC/BIN/EDIT.S.SCRN
*--------------------------------------
CS.END
SEQ.DETECT .AZ "Querying terminal capabilities...\e[999;999H\e[6n"
SEQ.RESET .AZ "\ec"
SEQ.INIT .AS "\ec"
SEQ.SCROLLRGN .AZ "\e[?7l\e[2;%dr"
SEQ.SCROLLUP .AZ "\eD"
SEQ.SCROLLDN .AZ "\eM"
SEQ.SCROLLCURUP .AZ "\e[?7l\e[%d;%dr\eD"
SEQ.SCROLLCURDN .AZ "\e[?7l\e[%d;%dr\eM"
SEQ.BAR .AS "\e[40;37m\e[7m%s" +SEQ.NORM
SEQ.NORM .AZ "\e[0m"
SEQ.INV .AZ "\e[7m"
SEQ.EDIT .AS "\e[93;44m" +SEQ.CEOL
SEQ.CEOL .AZ "\e[K"
MSG.TOPBAR .AZ "A2osX Edit:%s %s"
MSG.TXTCR .AZ "TXT/CR"
MSG.TXTCRLF .AZ "TXT/CRLF"
MSG.TXTASM .AZ "S-C/ASM"
MSG.STATUSBAR .AZ "Press Ctrl-A For Help Len: %5D Pos: %5D Col: %3d Line: %5D"
MSG.STATUSBAR.H .AZ "Press any key to exit this screen:"
MSG.STATUSBAR.F .AZ "Find:%s"
MSG.STATUSBAR.R .AZ "Replace:%s"
MSG.STATUSBAR.S .AZ "Save (Ctrl-C):%s"
MSG.STATUSBAR.E .AZ "Error:%h"
MSG.GOTOXY .AZ "\e[%d;%dH"
MSG.HELPLINE .AZ "\e[93;44m%S\e[K"
MSG.HELP >PSTR "All commands: (* = Not yet implemented)"
>PSTR "------------"
>PSTR " Ctrl-A : This help screen"
>PSTR " Ctrl-B : Mark beginning of selection"
>PSTR " Ctrl-C : Copy selection to clipboard"
>PSTR " Ctrl-D : Delete selection"
>PSTR " Ctrl-E : Mark end of selection"
>PSTR " Ctrl-F : * Find a string..."
>PSTR " Ctrl-G : Go to start of current line"
>PSTR " Ctrl-L : Go to end of current line"
>PSTR " Ctrl-N : * Find next"
>PSTR " Ctrl-O : Page up"
>PSTR " Ctrl-P : Page down"
>PSTR " Ctrl-Q : Quit"
>PSTR " Ctrl-R : * Replace found string with..."
>PSTR " Ctrl-S : Save file..."
>PSTR " Ctrl-T : Go to top of file"
>PSTR " Ctrl-V : Past clipboard at cursor position"
>PSTR " Ctrl-W : Erase current line"
>PSTR " Ctrl-X : Cut block to clipboard"
>PSTR " Ctrl-Y : Go to end of file"
>PSTR " Ctrl-Z : Erase char under cursor"
.HS 00
*--------------------------------------
MSG.NEWFILE .AZ "newfile"
EscChars .AS "DBAC"
EscChars.Cnt .EQ *-EscChars
EscAscii .HS 080A0B15
*--------------------------------------
S.DLG.Size .EQ 0
S.DLG.X .EQ 1
S.DLG.Y .EQ 2
S.DLG.W .EQ 3
S.DLG.H .EQ 4
S.DLG.Title .EQ 5
S.DLG.Status .EQ 6
S.DLG.Focus .EQ 7
S.DLG.Ctrls .EQ 8
S.DLG.Ctrl.LBL .EQ 0
S.DLG.Ctrl.TB .EQ 2
S.DLG.Ctrl.OL .EQ 4
S.DLG.Ctrl.BUT .EQ 6
*--------------------------------------
DLG.SAVE .DA #DLG.SAVE.LEN Size
.DA #0 X
.DA #0 Y
.DA #70 W
.DA #11 H
.DA #DLG.SAVE.T-DLG.SAVE Title
.DA #DLG.SAVE.S-DLG.SAVE Status
.DA #9 Focus
.DA #DLG.SAVE.1-DLG.SAVE
.DA #DLG.SAVE.2-DLG.SAVE
.DA #DLG.SAVE.3-DLG.SAVE
.DA #DLG.SAVE.4-DLG.SAVE
.DA #DLG.SAVE.5-DLG.SAVE
.DA #DLG.SAVE.6-DLG.SAVE
.DA #0
DLG.SAVE.1 .DA #S.DLG.Ctrl.LBL,#2,#2
.AZ "Filename :"
DLG.SAVE.2 .DA #S.DLG.Ctrl.TB,#2,#3
.DA #0,#64,#hFileName CURPOS,MAXCHAR,hMem
DLG.SAVE.3 .DA #S.DLG.Ctrl.LBL,#2,#5
.AZ "Filetype :"
DLG.SAVE.4 .DA #S.DLG.Ctrl.OL,#2,#6
.DA #20 Ctrl-T
.DA #0 Value
.AZ "TXT/CR"
.AZ "TXT/CRLF"
.AZ "S-C/ASM"
.DA #0
DLG.SAVE.5 .DA #S.DLG.Ctrl.BUT,#40,#8
.DA #C.CR
.AZ " Save "
DLG.SAVE.6 .DA #S.DLG.Ctrl.BUT,#52,#8
.DA #3 Ctrl-C
.AZ " Cancel "
DLG.SAVE.T .AZ "Save As..." Title
DLG.SAVE.S .AZ "CR:Save, Ctrl-T:Change Type, Ctrl-C:Cancel"
DLG.SAVE.LEN .EQ *-DLG.SAVE
*--------------------------------------
.DUMMY
.OR 0
DS.START
PromptBuf .BS PROMPTBUFMAX+1
PromptBufPtr .BS 1
PromptMode .BS 1
bExit .BS 1
bSaved .BS 1
bEscMode .BS 1
EscBuffer .BS 16
FileType .BS 1
hFileName .BS 1
hFind .BS 1
hReplace .BS 1
hLineBuffer .BS 1
LineBufBase .BS 2
BufBase .BS 2
hBuffer .BS 1
hBufferBackup .BS 1
hClipBoard .BS 1
ClipBoardLen .BS 2
SelStart .BS 2
SelEnd .BS 2
ScreenW .BS 1
ScreenH .BS 1
ViewPortH .BS 1
ViewPortHm1 .BS 1
FileX .BS 1
FileY .BS 2
ScreenX .BS 1
ScreenY .BS 2
CurX .BS 1
CurY .BS 1
hDLG .BS 1
STATBUF .BS S.STAT
DS.END
.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/EDIT.S
ASM