A2osX/SBIN/SHELL.S.HIS.txt

176 lines
3.0 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 History.MAX Get a buffer for History
>SYSCALL GetMem0.YA
bcs .9
txa
>STA.G HIS.hBuf
lda #0
>STA.G HIS.Count
>STA.G HIS.Index
.9 rts
*--------------------------------------
HIS.Add >LDA.G HIS.hBuf
beq .9
>SYSCALL GetMemPtr.A
>STYA ZPPTR1
.10 lda #$ff
jsr HIS.GetA Y=ending 0
tya
sec add len+1
adc CmdBuflen CmdBuffer length
bcc .2 enough room
>DEC.G HIS.Count we must remove oldest
ldy #$ff
.12 iny
lda (ZPPTR1),y get len of oldest string
bne .12
tya
* sec
adc ZPPTR1
sta ZPPTR2
lda ZPPTR1+1
adc #0
sta ZPPTR2+1
ldy #$FF
.1 iny
lda (ZPPTR2),y move back until String ending 0 found
sta (ZPPTR1),y
bne .1
iny
lda (ZPPTR2),y move back until Array ending 0 found
sta (ZPPTR1),y
bne .1
bra .10 retry....
.2 tya Y=Array Ending 0
sec
adc ZPPTR1
sta ZPPTR2
lda ZPPTR1+1
adc #0
sta ZPPTR2+1
.3 ldy #$ff
.4 iny
lda (ZPCMDBuf),y
sta (ZPPTR1),y
bne .4
iny
sta (ZPPTR1),y set new array ending 0
* lda #0
>STA.G HIS.Index Reset Index
>INC.G HIS.Count
.9 rts
*--------------------------------------
HIS.GetPrev >LDA.G HIS.hBuf
beq HISTORY.RTS
>SYSCALL GetMemPtr.A
>STYA ZPPTR1
>LDA.G HIS.Count
beq HISTORY.RTS empty history,nothing to do
>LDA.G HIS.Index
bne .1
>LDA.G HIS.Count
.1 dec
>STA.G HIS.Index
jsr HIS.GetA
bra HIS.SetBuf
History.RTS rts
*--------------------------------------
HIS.GetNext >LDA.G HIS.hBuf
beq HISTORY.RTS
>SYSCALL GetMemPtr.A
>STYA ZPPTR1
>LDA.G HIS.Count
beq HISTORY.RTS empty history,nothing to do
>LDA.G HIS.Index
inc
>CMP.G HIS.Count
bne .1
lda #0
.1 >STA.G HIS.Index
jsr HIS.GetA
bne HIS.SetBuf
jmp CmdLine.CLR end of history, just blank buffer
*--------------------------------------
HIS.GetA tax
beq .8
ldy #0
lda (ZPPTR1),y
beq .9
.1 iny
lda (ZPPTR1),y
bne .1
dex
beq .8
iny
lda (ZPPTR1),y
bne .1
.9 sec Found ending 0....
rts
.8 clc
rts
*--------------------------------------
HIS.SetBuf jsr CmdLine.CLR
ldy #$ff
.1 lda (ZPPTR1),y
sta (ZPCMDBuf),y
bne .1
jmp CmdLine.PRINT
*--------------------------------------
HIS.Quit >LDA.G HIS.hBuf
beq .9
>SYSCALL FreeMem.A
.9 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.HIS
LOAD /A2OSX.SRC/SBIN/SHELL.S
ASM