A2osX/SBIN/SHELL.S.HIS.txt

170 lines
3.1 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
>STA.G HIS.hBuf
2015-10-19 20:35:00 +00:00
lda #0
>STA.G HIS.BufIndex
>STA.G HIS.BufEnd
2015-10-19 20:35:00 +00:00
.9 rts
*--------------------------------------
HIS.Add >LDA.G HIS.hBuf
2015-10-19 20:35:00 +00:00
beq .9
>SYSCALL GetMemPtr.A
2015-10-19 20:35:00 +00:00
>STYA ZPPTR1
.10 >LDA.G HIS.BufEnd
.11 sec add len+1
adc CmdBuflen CmdBuffer length
2015-10-19 20:35:00 +00:00
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
>STA.G HIS.BufEnd mark new end of history
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
>LDA.G HIS.BufEnd save old END
2015-10-19 20:35:00 +00:00
pha
txa get back new END
>STA.G HIS.BufIndex set it as new IDX
>STA.G HIS.BufEnd 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 ldy #0
.4 lda (ZPCMDBuf),y
beq .5
2015-10-19 20:35:00 +00:00
iny
2015-10-19 20:35:00 +00:00
sta (ZPPTR1),y
iny
bra .4
.5 tya
sta (ZPPTR1)
2015-10-19 20:35:00 +00:00
.9 rts
*--------------------------------------
HIS.GetPrev >LDA.G HIS.hBuf
2015-10-19 20:35:00 +00:00
beq HISTORY.RTS
tax
>LDA.G HIS.BufEnd
2015-10-19 20:35:00 +00:00
beq HISTORY.RTS empty history,nothing to do
>LDA.G HIS.BufIndex
2015-10-19 20:35:00 +00:00
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
>STA.G HIS.BufIndex set new index
bra HIS.SetBuf
2015-10-19 20:35:00 +00:00
History.RTS rts
*--------------------------------------
HIS.GetNext >LDA.G HIS.hBuf
2015-10-19 20:35:00 +00:00
beq HISTORY.RTS
tax
>LDA.G HIS.BufEnd
2015-10-19 20:35:00 +00:00
beq HISTORY.RTS empty history,nothing to do
>CMP.G HIS.BufIndex
2015-10-19 20:35:00 +00:00
beq HISTORY.RTS already oldest,nothing to do
txa
>SYSCALL GetMemPtr.A
2015-10-19 20:35:00 +00:00
>STYA ZPPTR1
>LDA.G HIS.BufIndex
2015-10-19 20:35:00 +00:00
tay
sec
adc (ZPPTR1),y add length+1 of current line in history
>STA.G HIS.BufIndex
2015-10-19 20:35:00 +00:00
>CMP.G HIS.BufEnd
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
>LDA.G HIS.BufIndex
2015-10-19 20:35:00 +00:00
tay keep length of string
clc
adc ZPPTR1
sta ZPPTR1
bcc .1
inc ZPPTR1+1
.1 lda (ZPPTR1),y
sta (ZPCMDBuf),y
2015-10-19 20:35:00 +00:00
dey
bpl .1
jmp CmdLine.PRINT
2015-10-19 20:35:00 +00:00
*--------------------------------------
HIS.Quit >LDA.G HIS.hBuf
2015-10-19 20:35:00 +00:00
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