A2osX/BIN/EDIT.S.txt

556 lines
10 KiB
Plaintext
Raw Normal View History

NEW
2017-12-22 21:24:30 +00:00
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BUILD/BIN/EDIT
*--------------------------------------
.INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2
2016-01-04 07:25:43 +00:00
BufPtr .EQ ZPBIN+4
BufPtrBackup .EQ ZPBIN+6
2016-01-29 17:05:08 +00:00
ClipboardPtr .EQ ZPBIN+8
2016-01-04 07:25:43 +00:00
*--------------------------------------
PromptBufferMax .EQ 64
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 CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #10 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
2016-01-04 07:25:43 +00:00
L.SEQ.DETECT .DA SEQ.DETECT
L.SEQ.INIT .DA SEQ.INIT
L.SEQ.RESET .DA SEQ.RESET
L.SEQ.SCROLLUP .DA SEQ.SCROLLUP
L.SEQ.SCROLLDN .DA SEQ.SCROLLDN
L.SEQ.INV .DA SEQ.INV
L.SEQ.NORM .DA SEQ.NORM
2016-01-04 07:25:43 +00:00
L.SEQ.CEOL .DA SEQ.CEOL
L.MSG.TOPBAR .DA MSG.TOPBAR
2016-01-04 07:25:43 +00:00
L.MSG.STATUSBAR .DA MSG.STATUSBAR
L.MSG.STATUSBAR.H .DA MSG.STATUSBAR.H
L.MSG.STATUSBAR.F .DA MSG.STATUSBAR.F
L.MSG.STATUSBAR.R .DA MSG.STATUSBAR.R
L.MSG.STATUSBAR.S .DA MSG.STATUSBAR.S
L.MSG.STATUSBAR.E .DA MSG.STATUSBAR.E
L.MSG.NEWFILE .DA MSG.NEWFILE
2016-01-04 07:25:43 +00:00
L.MSG.GOTOXY .DA MSG.GOTOXY
L.MSG.HELPLINE .DA MSG.HELPLINE
2016-01-04 07:25:43 +00:00
L.MSG.HELP .DA MSG.HELP
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.ESC
.DA Ctrl.Invalid
.DA Ctrl.Invalid
.DA Ctrl.Invalid
.DA Ctrl.Invalid
.DA 0
*--------------------------------------
CS.INIT lda #$ff
>STA.G bSaved
ldy #S.PS.ARGC
lda (pPs),y
beq .1 No arg, new file....
2016-08-17 06:25:58 +00:00
lda #1
>SYSCALL GetArg.A
>SYSCALL RealPath.YA
txa
ldy #hFileName
sta (pData),y
jsr LoadFile
bcc .8 if CS, Failed to load file, keep name, but new file....
2016-01-04 07:25:43 +00:00
.1 >LDYAI 1 buffer size = 0 (+ 1 for ending 0)
>SYSCALL GetMem0.YA
bcs .9
2016-08-17 06:25:58 +00:00
txa
ldy #hBuffer FileLen already set to 0
2016-08-17 06:25:58 +00:00
sta (pData),y
.8 lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN >LDYA L.SEQ.DETECT
>SYSCALL PrintF.YA Send Query for term W & H
2016-01-04 07:25:43 +00:00
bcs .9
.1 >SLEEP
>SYSCALL GetChar
bcs .1
jsr CharIn
2016-01-04 07:25:43 +00:00
ldy #ScreenW Wait for Response from terminal
lda (pData),y for W & H
beq .1
2016-01-21 07:05:23 +00:00
jsr SCRN.Init
2016-01-04 07:25:43 +00:00
bcs .9
.2 ldy #bCancel
lda (pData),y
bne .99
>SLEEP
>SYSCALL GetChar
2016-01-04 07:25:43 +00:00
bcs .2
jsr CharIn
bra .2
.99 lda #0
.9 sec
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT ldy #hBuffer
lda (pData),y
beq .1
>SYSCALL FreeMem.A
.1 ldy #hBufferBackup
lda (pData),y
beq .2
>SYSCALL FreeMem.A
.2 ldy #hClipBoard
lda (pData),y
beq .3
>SYSCALL FreeMem.A
.3 ldy #hFileName
lda (pData),y
beq .8
>SYSCALL FreeMem.A
.8 >LDYA L.SEQ.RESET
>SYSCALL PrintF.YA
.9 rts
*--------------------------------------
CharIn tax
2016-01-04 07:25:43 +00:00
ldy #bEscMode
lda (pData),y
asl
txa
bcc .1 Not in ESC mode
2016-01-04 07:25:43 +00:00
cmp #'['
beq .8
ldy #EscBuffer
lda (pData),y
inc
sta (pData),y
clc
adc #EscBuffer
tay
txa
sta (pData),y
2016-01-04 07:25:43 +00:00
cmp #64
bcc .8
jsr CharIn.Esc
2016-01-04 07:25:43 +00:00
bcs .8 Not translated, exit
.1 cmp #27 Esc ?
bne .2
ldy #bEscMode
lda #$ff
sta (pData),y
inc
ldy #EscBuffer
sta (pData),y
.8 clc
rts
.2 pha
2016-01-04 07:25:43 +00:00
ldy #PromptMode
lda (pData),y
tax
pla
jmp (J.PROMPT,x)
*--------------------------------------
CharIn.Esc ldy #bEscMode
2016-01-04 07:25:43 +00:00
lda #0
sta (pData),y
ldy #EscBuffer
lda (pData),y
2016-01-04 07:25:43 +00:00
clc
adc #EscBuffer
tay
lda (pData),y
2016-01-04 07:25:43 +00:00
ldx EscChars
2016-01-04 07:25:43 +00:00
.1 cmp EscChars,x
2016-01-04 07:25:43 +00:00
beq .2
dex
bne .1
2016-01-04 07:25:43 +00:00
cmp #'R' Response to cursor position query?
beq .3
2016-01-04 07:25:43 +00:00
sec
rts
2016-01-04 07:25:43 +00:00
.2 lda EscAscii,x
clc
rts
.3 stz TmpByte
ldy #EscBuffer+1
2016-01-04 07:25:43 +00:00
.4 lda (pData),y
cmp #';'
beq .5
and #$0f
pha
lda TmpByte
2016-01-04 07:25:43 +00:00
asl
asl
clc
adc TmpByte
2016-01-04 07:25:43 +00:00
asl
sta TmpByte
2016-01-04 07:25:43 +00:00
pla
clc
adc TmpByte
sta TmpByte
2016-01-04 07:25:43 +00:00
iny
bra .4
.5 phy
lda TmpByte
2016-01-04 07:25:43 +00:00
ldy #ScreenH
sta (pData),y
dec Remove 2 (top & status bar) for viewportH
dec
ldy #ViewPortH
sta (pData),y
dec
ldy #ViewPortHm1 Remove 1 more to store offsert to last line of viewport
sta (pData),y
2016-01-04 07:25:43 +00:00
ply
stz TmpByte
iny
2016-01-04 07:25:43 +00:00
.6 lda (pData),y
cmp #'R'
beq .7
and #$0f
pha
lda TmpByte
2016-01-04 07:25:43 +00:00
asl
asl
clc
adc TmpByte
2016-01-04 07:25:43 +00:00
asl
sta TmpByte
2016-01-04 07:25:43 +00:00
pla
clc
adc TmpByte
sta TmpByte
2016-01-04 07:25:43 +00:00
iny
bra .6
.7 lda TmpByte
2016-01-04 07:25:43 +00:00
ldy #ScreenW
sta (pData),y
sec
2016-01-04 07:25:43 +00:00
rts
*--------------------------------------
LoadFile >PUSHWI 0 Aux type
2017-10-27 14:56:46 +00:00
>PUSHBI 4 S.FI.T.TXT
2017-01-12 17:43:45 +00:00
>PUSHBI SYS.FOpen.R
2016-01-09 22:33:47 +00:00
ldy #hFileName
lda (pData),y
>SYSCALL GetMemPtr.A
2016-01-09 22:33:47 +00:00
>PUSHYA
>SYSCALL LoadFile
bcs .9
stx hMem
>STYA TmpLen
iny
bne .2
inc +1 for ending zero
.2 >SYSCALL GetMem0.YA
bcs .98
>STYA ZPPTR2
txa
ldy #hBuffer
sta (pData),y
lda hMem
>SYSCALL GetMemPtr.A
>STYA ZPPTR1
lda TmpLen
eor #$ff
tax
lda TmpLen+1
eor #$ff
pha
ldy #0
.5 inx
bne .6
pla
inc
beq .7
pha
.6 lda (ZPPTR1),y
sta (ZPPTR2),y
iny
bne .5
inc ZPPTR1+1
inc ZPPTR2+1
bra .5
.7 ldy #FileLen
lda TmpLen
sta (pData),y
iny
lda TmpLen+1
sta (pData),y
jsr .98
clc
rts
.98 pha
lda hMem
>SYSCALL FreeMem.A
pla
sec
.9 rts
*--------------------------------------
SaveFile >PUSHWI 0 Aux type
2017-10-27 14:56:46 +00:00
>PUSHBI 4 S.FI.T.TXT
>PUSHBI SYS.FOpen.X+SYS.FOpen.W
>LDA.G hFileName
>SYSCALL GetMemPtr.A
>PUSHYA
>SYSCALL FOpen
bcs .9
pha
>LDA.G hBuffer
>SYSCALL GetMemPtr.A
>PUSHYA
>PUSHW.G FileLen
pla
pha
>PUSHA
>SYSCALL FWrite
bcc .1
tax
pla
phx
>SYSCALL FClose.A
pla
sec
2016-01-09 22:33:47 +00:00
rts
.1 pla
>SYSCALL FClose.A
.9 rts
*--------------------------------------
2016-01-04 07:25:43 +00:00
DecTmpCount lda TmpCount
bne .1
lda TmpCount+1
beq .9
dec TmpCount+1
.1 dec TmpCount
ora #$ff make sure NZ
.9 rts
*--------------------------------------
.INB /A2OSX.SRC/BIN/EDIT.S.BUF
.INB /A2OSX.SRC/BIN/EDIT.S.CTRL
.INB /A2OSX.SRC/BIN/EDIT.S.SCRN
2016-01-04 07:25:43 +00:00
*--------------------------------------
CS.END
SEQ.DETECT >CSTR "Querying terminal capabilities...\e[999;999H\e[6n"
SEQ.INIT >CSTR "\ec\e[2;%dr" \e[?6h
SEQ.RESET >CSTR "\ec"
SEQ.SCROLLUP >CSTR "\e[%d;%dH\eD"
SEQ.SCROLLDN >CSTR "\e[%d;%dH\eM"
SEQ.INV >CSTR "\e[7m"
SEQ.NORM >CSTR "\e[0m"
SEQ.CEOL >CSTR "\e[K"
2017-12-22 21:24:30 +00:00
MSG.TOPBAR >CSTR "\e[1;1HA2osX Edit:%s\e[0m"
MSG.STATUSBAR >CSTR "Press Ctrl-A For Help Length:%5D,Col:%3d,Line:%5D"
MSG.STATUSBAR.H >CSTR "Press any key to exit this screen:\e[0m"
2017-12-22 21:24:30 +00:00
MSG.STATUSBAR.F >CSTR "Find:%s\e[0m"
MSG.STATUSBAR.R >CSTR "Replace:%s\e[0m"
MSG.STATUSBAR.S >CSTR "Save:%s\e[0m"
MSG.STATUSBAR.E >CSTR "Error:%h\e[0m"
MSG.GOTOXY >CSTR "\e[%d;%dH"
MSG.HELPLINE >CSTR "%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 to disk..."
>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 : * Undo previous change"
2016-01-04 07:25:43 +00:00
.HS 00
*--------------------------------------
MSG.NEWFILE >PSTR "(new file)"
EscChars >PSTR "DBAC"
2016-01-04 07:25:43 +00:00
EscAscii .HS 04080A0B15
hMem .BS 1
2016-08-17 06:25:58 +00:00
TmpFilename .BS 1
TmpByte .BS 1
2016-01-04 07:25:43 +00:00
TmpLen .BS 2
TmpCount .BS 2
TmpIndex .BS 2
2016-02-25 17:02:57 +00:00
SelLen .BS 2
2016-01-04 07:25:43 +00:00
BUF.LOffset .BS 2
BUF.COffset .BS 2
BUF.TmpLine1 .BS 2
BUF.TmpLine2 .BS 2
bNotRepaint .BS 1
bSelected .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
2016-01-04 07:25:43 +00:00
PromptBuffer .BS PromptBufferMax+1
PromptMode .BS 1
bCancel .BS 1
bSaved .BS 1
bEscMode .BS 1
EscBuffer .BS 16
hFileName .BS 1
2016-01-04 07:25:43 +00:00
hFind .BS 1
hReplace .BS 1
hBuffer .BS 1
2016-01-04 07:25:43 +00:00
hBufferBackup .BS 1
FileLen .BS 2
2016-01-29 17:05:08 +00:00
hClipBoard .BS 1
ClipBoardLen .BS 2
2016-01-04 07:25:43 +00:00
ScreenW .BS 1
ScreenH .BS 1
ViewPortH .BS 1
ViewPortHm1 .BS 1
2016-01-04 07:25:43 +00:00
ScreenX .BS 1
ScreenY .BS 2
CurX .BS 1
CurY .BS 1
FileX .BS 1
FileY .BS 2
SelStart .BS 2
SelEnd .BS 2
DS.END
.ED
*--------------------------------------
MAN
SAVE /A2OSX.SRC/BIN/EDIT.S
ASM