A2osX/SBIN/SHELL.S.HIS.txt

188 lines
3.4 KiB
Plaintext
Raw Normal View History

2015-10-19 20:35:00 +00:00
PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
2015-10-19 20:35:00 +00:00
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
HIS.Init >LDYAI 256 Get a buffer for History
>SYSCALL GetMem0.YA
2015-10-19 20:35:00 +00:00
bcs .9
txa
ldy #HIS.hBuf
2015-10-19 20:35:00 +00:00
sta (pData),y
lda #0
ldy #HIS.BufIndex
2015-10-19 20:35:00 +00:00
sta (pData),y
ldy #HIS.BufEnd
2015-10-19 20:35:00 +00:00
sta (pData),y
.9 rts
*--------------------------------------
HIS.Add ldy #HIS.hBuf
2015-10-19 20:35:00 +00:00
lda (pData),y
beq .9
>SYSCALL GetMemPtr.A
2015-10-19 20:35:00 +00:00
>STYA ZPPTR1
.10 ldy #HIS.BufEnd
2015-10-19 20:35:00 +00:00
lda (pData),y
.11 sec add len+1
2015-10-19 20:35:00 +00:00
adc (pData) CmdBuffer length
bcc .2 enough room
lda (ZPPTR1) get len of oldest string
sec
adc ZPPTR1
sta ZPPTR2
lda ZPPTR1+1
adc #0
sta ZPPTR2+1
ldy #$FF
.1 iny
lda (ZPPTR2),y move back until ending 0 found
sta (ZPPTR1),y
bne .1
tya
ldy #HIS.BufEnd mark new end of history
2015-10-19 20:35:00 +00:00
sta (pData),y
bra .11 retry....
2015-10-19 20:35:00 +00:00
.2 tax keep new HIS.BufEnd
2015-10-19 20:35:00 +00:00
tay
lda #0
sta (ZPPTR1),y set ending 0
ldy #HIS.BufEnd save old END
2015-10-19 20:35:00 +00:00
lda (pData),y
pha
txa get back new END
ldy #HIS.BufIndex set it as new IDX
2015-10-19 20:35:00 +00:00
sta (pData),y
ldy #HIS.BufEnd
sta (pData),y set new HIS.BufEnd
2015-10-19 20:35:00 +00:00
pla get back old END
clc
adc ZPPTR1
sta ZPPTR1
bcc .3
inc ZPPTR1+1
.3 lda (pData)
tay
.4 lda (pData),y
sta (ZPPTR1),y
dey
bpl .4
.9 rts
*--------------------------------------
HIS.GetPrev ldy #HIS.hBuf
2015-10-19 20:35:00 +00:00
lda (pData),y
beq HISTORY.RTS
tax
ldy #HIS.BufEnd
2015-10-19 20:35:00 +00:00
lda (pData),y
beq HISTORY.RTS empty history,nothing to do
ldy #HIS.BufIndex
2015-10-19 20:35:00 +00:00
lda (pData),y
beq HISTORY.RTS already oldest,nothing to do
txa
>SYSCALL GetMemPtr.A
2015-10-19 20:35:00 +00:00
>STYA ZPPTR1
lda #0
.1 tax
tay
sec
adc (ZPPTR1),y
2016-04-28 14:55:22 +00:00
bcs History.RTS out of buffer
ldy #HIS.BufIndex
2015-10-19 20:35:00 +00:00
cmp (pData),y
bne .1 reached current index
.2 txa
ldy #HIS.BufIndex set new index
2015-10-19 20:35:00 +00:00
sta (pData),y
bra HIS.SetBuf
2015-10-19 20:35:00 +00:00
History.RTS rts
*--------------------------------------
HIS.GetNext ldy #HIS.hBuf
2015-10-19 20:35:00 +00:00
lda (pData),y
beq HISTORY.RTS
tax
ldy #HIS.BufEnd
2015-10-19 20:35:00 +00:00
lda (pData),y
beq HISTORY.RTS empty history,nothing to do
ldy #HIS.BufIndex
2015-10-19 20:35:00 +00:00
cmp (pData),y
beq HISTORY.RTS already oldest,nothing to do
txa
>SYSCALL GetMemPtr.A
2015-10-19 20:35:00 +00:00
>STYA ZPPTR1
ldy #HIS.BufIndex
2015-10-19 20:35:00 +00:00
lda (pData),y
phy
tay
sec
adc (ZPPTR1),y add length+1 of current line in history
ply
sta (pData),y
ldy #HIS.BufEnd
2015-10-19 20:35:00 +00:00
cmp (pData),y
bne HIS.SetBuf
jmp CmdLine.CLR end of history, just blank buffer
2015-10-19 20:35:00 +00:00
*--------------------------------------
HIS.SetBuf jsr CmdLine.CLR
2015-10-19 20:35:00 +00:00
ldy #HIS.BufIndex
2015-10-19 20:35:00 +00:00
lda (pData),y
tay keep length of string
clc
adc ZPPTR1
sta ZPPTR1
bcc .1
inc ZPPTR1+1
.1 lda (ZPPTR1),y
sta (pData),y
dey
bpl .1
jmp CmdLine.SET
2015-10-19 20:35:00 +00:00
*--------------------------------------
HIS.Quit ldy #HIS.hBuf
2015-10-19 20:35:00 +00:00
lda (pData),y
beq .9
>SYSCALL FreeMem.A
2015-10-19 20:35:00 +00:00
.9 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.HIS
LOAD /A2OSX.SRC/SBIN/SHELL.S
2015-10-19 20:35:00 +00:00
ASM