diff --git a/SBIN/SHELL.S.txt b/SBIN/SHELL.S.txt index fb93d7f4..4fa60efa 100644 --- a/SBIN/SHELL.S.txt +++ b/SBIN/SHELL.S.txt @@ -56,13 +56,18 @@ T.INTCMDS .DA EXEC.CMD.CD CS.INIT lda #0 ldy #bEXIT sta (pData),y - ldy #CmdHistory - sta (pData),y ldy #CmdHistory.IDX sta (pData),y ldy #CmdHistory.END sta (pData),y + >PUSHWI 256 Get a buffer for History + >PUSHBI S.MEM.F.INIT0 + >SYSCALL SYS.GetMem + bcs .99 + + stx hCmdHistory + >LDYA L.LIBSTR >LOADLIBYA bcs .99 @@ -95,11 +100,9 @@ CS.RUN lda #0 lda #" " jsr COUT -.1 lda (pData) - bmi .2 - jsr A2osX.SLEEP - - bra .1 +.1 jsr A2osX.SLEEP + lda (pData) + bpl .1 .2 and #$7F sta (pData) @@ -111,7 +114,7 @@ CS.RUN lda #0 ldy #hCMDLINE sta (pData),y -* jsr HISTORY.ADD + jsr HISTORY.ADD jsr EXEC.CMD bcc .3 @@ -214,14 +217,14 @@ CS.EVENT.CTRL.CHAR .2 cmp #10 LF (down arrow) bne .3 -* jsr HISTORY.GETNEXT + jsr HISTORY.GETNEXT clc rts .3 cmp #11 VT (up arrow) bne .4 -* jsr HISTORY.GETPREV + jsr HISTORY.GETPREV clc rts @@ -235,7 +238,11 @@ CS.EVENT.CTRL.CHAR clc rts *-------------------------------------- -CS.QUIT lda hLIBSTR +CS.QUIT lda hCmdHistory + beq .1 + >SYSCALL SYS.FreeMemA + +.1 lda hLIBSTR >SYSCALL SYS.UnloadLibA clc rts @@ -487,46 +494,73 @@ EXEC.CMD.EXIT ldy #bEXIT clc rts *-------------------------------------- -HISTORY.ADD lda CmdHistory.END ending 0 +HISTORY.ADD lda hCmdHistory + >SYSCALL SYS.GetMemPtrA + >STYA ZPPTR1 + +.10 lda CmdHistory.END ending 0 inc keep room for new ending 0 sec add len+1 - adc CmdBuffer + adc (pData) CmdBuffer bcc .2 enough room - ldx CmdHistory get len of oldest string - ldy #0 -.1 inx - iny - lda CmdHistory,x move back until 0 found - sta CmdHistory-1,y - bne .1 - sty CmdHistory.END mark new end of history - bra HISTORY.ADD retry.... + lda (ZPPTR1) get len of oldest string + sec + adc ZPPTR1 + sta ZPPTR2 + lda ZPPTR1+1 + adc #0 + sta ZPPTR2+1 -.2 ldx CmdHistory.END ldy #$FF -.3 iny - lda CmdBuffer,y - sta CmdHistory,x - inx - cpy CmdBuffer - bne .3 - stz CmdHistory,x set ending 0 - stx CmdHistory.IDX - stx CmdHistory.END + +.1 iny + lda (ZPPTR2),y move back until 0 found + sta (ZPPTR1),y + bne .1 + + sty CmdHistory.END mark new end of history + bra .10 retry.... + +.2 ldy CmdHistory.END + lda (pData) + tax + lda pData + sta ZPPTR2 + lda pData+1 + sta ZPPTR2+1 + +.3 lda (ZPPTR2) + sta (ZPPTR1),y + inc ZPPTR2 + bne .4 + inc ZPPTR2+1 +.4 iny + dex + bpl .3 + + lda #0 + sta (ZPPTR1),y set ending 0 + sty CmdHistory.IDX + sty CmdHistory.END .9 rts *-------------------------------------- HISTORY.GETPREV lda CmdHistory.END beq HISTORY.RTS empty history,nothing to do lda CmdHistory.IDX beq HISTORY.RTS already oldest,nothing to do + + lda hCmdHistory + >SYSCALL SYS.GetMemPtrA + >STYA ZPPTR1 + lda #0 -.1 tax save current index +.1 tay save current index sec - adc CmdHistory,x + adc (ZPPTR1),y cmp CmdHistory.IDX bne .1 not yet reached current index - stx CmdHistory.IDX set new index + sty CmdHistory.IDX set new index bra HISTORY.SETBUF HISTORY.RTS rts *-------------------------------------- @@ -534,8 +568,13 @@ HISTORY.GETNEXT ldx CmdHistory.END beq HISTORY.RTS empty history,nothing to do cpx CmdHistory.IDX beq HISTORY.RTS - ldx CmdHistory.IDX - lda CmdHistory,x + + lda hCmdHistory + >SYSCALL SYS.GetMemPtrA + >STYA ZPPTR1 + + ldy CmdHistory.IDX + lda (ZPPTR1),y sec adc CmdHistory.IDX cmp CmdHistory.END @@ -543,15 +582,26 @@ HISTORY.GETNEXT ldx CmdHistory.END beq CmdBuffer.CLR end of history, just blank buffer *-------------------------------------- HISTORY.SETBUF jsr CmdBuffer.CLR - ldx CmdHistory.IDX - ldy #$ff -.1 iny - lda CmdHistory,x - inx - sta CmdBuffer,y - cpy CmdBuffer - bne .1 - bra CmdBuffer.PRINT + + lda pData + sta ZPPTR2 + lda pData+1 + sta ZPPTR2+1 + + ldy CmdHistory.IDX + lda (ZPPTR1),y + tax + +.1 lda (ZPPTR1),y + sta (ZPPTR2) + + inc ZPPTR2 + bne .2 + inc ZPPTR2+1 + +.2 iny + dex + bpl .1 *-------------------------------------- CmdBuffer.PRINT ldy #0 .1 iny @@ -631,7 +681,7 @@ bEXIT .BS 1 hCMDLINE .BS 1 hCMD .BS 1 hARGS .BS 1 -CmdHistory .BS 256 +hCmdHistory .BS 1 CmdHistory.IDX .BS 1 CmdHistory.END .BS 1 DS.END