A2osX/SBIN/SHELL.S.HIS.txt
2017-08-22 08:37:03 +02:00

188 lines
3.4 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.

PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
HIS.Init >LDYAI 256 Get a buffer for History
>SYSCALL GetMem0YA
bcs .9
txa
ldy #HIS.hBuf
sta (pData),y
lda #0
ldy #HIS.BufIndex
sta (pData),y
ldy #HIS.BufEnd
sta (pData),y
.9 rts
*--------------------------------------
HIS.Add ldy #HIS.hBuf
lda (pData),y
beq .9
>SYSCALL GetMemPtrA
>STYA ZPPTR1
.10 ldy #HIS.BufEnd
lda (pData),y
.11 sec add len+1
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
sta (pData),y
bra .11 retry....
.2 tax keep new HIS.BufEnd
tay
lda #0
sta (ZPPTR1),y set ending 0
ldy #HIS.BufEnd save old END
lda (pData),y
pha
txa get back new END
ldy #HIS.BufIndex set it as new IDX
sta (pData),y
ldy #HIS.BufEnd
sta (pData),y set new HIS.BufEnd
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
lda (pData),y
beq HISTORY.RTS
tax
ldy #HIS.BufEnd
lda (pData),y
beq HISTORY.RTS empty history,nothing to do
ldy #HIS.BufIndex
lda (pData),y
beq HISTORY.RTS already oldest,nothing to do
txa
>SYSCALL GetMemPtrA
>STYA ZPPTR1
lda #0
.1 tax
tay
sec
adc (ZPPTR1),y
bcs History.RTS out of buffer
ldy #HIS.BufIndex
cmp (pData),y
bne .1 reached current index
.2 txa
ldy #HIS.BufIndex set new index
sta (pData),y
bra HIS.SetBuf
History.RTS rts
*--------------------------------------
HIS.GetNext ldy #HIS.hBuf
lda (pData),y
beq HISTORY.RTS
tax
ldy #HIS.BufEnd
lda (pData),y
beq HISTORY.RTS empty history,nothing to do
ldy #HIS.BufIndex
cmp (pData),y
beq HISTORY.RTS already oldest,nothing to do
txa
>SYSCALL GetMemPtrA
>STYA ZPPTR1
ldy #HIS.BufIndex
lda (pData),y
phy
tay
sec
adc (ZPPTR1),y add length+1 of current line in history
ply
sta (pData),y
ldy #HIS.BufEnd
cmp (pData),y
bne HIS.SetBuf
jmp CmdLine.CLR end of history, just blank buffer
*--------------------------------------
HIS.SetBuf jsr CmdLine.CLR
ldy #HIS.BufIndex
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
*--------------------------------------
HIS.Quit ldy #HIS.hBuf
lda (pData),y
beq .9
>SYSCALL FreeMemA
.9 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.HIS
LOAD /A2OSX.SRC/SBIN/SHELL.S
ASM