PR#3 PREFIX /A2OSX.BUILD NEW INC 1 AUTO 6 .LIST OFF *-------------------------------------- CMD.Init >LDYAI CmdLine.MAX+1 >SYSCALL GetMem.YA bcs .9 txa >STA.G hCmdBuf .9 rts *-------------------------------------- * ZPCMDBuf : Remove extra SPACE & comment *-------------------------------------- Cmd.Parse >LDYA ZPCMDBuf >STYA ZPPtr1 lda (ZPCMDBuf) empty line...quit beq .9 ldy #0 .1 jsr Cmd.Parse.NextC beq .8 no more char, exit cmp #' ' skip leading spaces beq .1 cmp #'#' Comment ? beq .8 ignore remaining chars .3 sta (ZPCMDBuf),y add char to buffer iny jsr Cmd.Parse.NextC beq .8 cmp #' ' bne .3 sta (ZPCMDBuf),y add One SPACE to buffer iny .5 jsr Cmd.Parse.NextC beq .8 cmp #' ' beq .5 skip additional spaces bne .3 no more space, add next word... .8 lda #0 sta (ZPCMDBuf),y .9 rts Cmd.Parse.NextC lda (ZPPtr1) beq .8 inc ZPPtr1 bne .8 inc ZPPtr1+1 never Z .8 rts *-------------------------------------- * ZPCMDBuf-> Command line (formatted & not empty) *-------------------------------------- Cmd.Exec stz bStartProc >LDYA ZPCMDBuf >SYSCALL ExpandStr.YA >STYA ZPPtr1 Ptr to CMD ARGS txa >STA.G CMD.hCmdLine Cmd.Exec.2 ldy #$ff CMD Len .1 iny lda (ZPPtr1),y Get CMD char... beq .2 cmp #' ' we reached blank between CMD ARGS bne .1 lda #0 sta (ZPPtr1),y Cut CMD with the ending 0 iny .2 tya Y=CMD len+0, if ARGS="" Y= clc adc ZPPtr1 sta ZPPtr2 lda ZPPtr1+1 adc #0 sta ZPPtr2+1 ZPPtr2->ARGS or CMD ending 0 if empty >LDYA L.INTCMDS >STYA ZPCMDBuf we use ZPCMDBuf as a temp Ptr ldx #0 .3 lda (ZPCMDBuf) beq Cmd.Exec.EXT Array Ending 0, must be an external Cmd.... ldy #$ff .4 iny lda (ZPCMDBuf),y bne .41 End of string in array lda (ZPPtr1),y Get CMD char... beq .8 both end with 0, found! .41 lda (ZPPtr1),y Get CMD char... beq .61 end of CMD.....too short... cmp #'a' To Uppercase bcc .5 cmp #'z'+1 bcs .5 eor #$20 .5 cmp (ZPCMDBuf),y beq .4 .61 iny lda (ZPCMDBuf),y bne .61 .7 inx inx tya sec adc ZPCMDBuf sta ZPCMDBuf bcc .3 inc ZPCMDBuf+1 bra .3 .8 jsr Cmd.Exec.INT Found an internal Cmd... Cmd.Exec.Done php pha >LDA.G CMD.hCmdLine >SYSCALL FreeMem.A pla plp rts *-------------------------------------- * ZPPtr1->CMD * ZPPtr2->ARGS *-------------------------------------- Cmd.Exec.EXT >LDYAI 256 >SYSCALL GetMem.YA bcs .99 >STYA ZPCMDBuf lda #0 sta (ZPCMDBuf) txa >STA.G CMD.hExtCmdLine lda (ZPPtr1) cmp #'/' Command line is already full path, no search bne .1 >PUSHW L.STAT >PUSHW ZPPtr1 >SYSCALL STAT bcs Cmd.Exec.Done >LDYA ZPPtr1 bra .4 .1 >LDYA L.ENV.PATH push ENVNAME=PATH for search >SYSCALL GetEnv.YA get value for ENV=PATH bcs .2 No PATH, try in CD jsr Cmd.Exec.EXT.Search bcc .3 .2 ldy #S.PS.hPREFIX not found, try in CD lda (pPs),y >SYSCALL GetMemPtr.A jsr Cmd.Exec.EXT.Search bcs .99 .3 >LDYA ZPCMDBuf .4 >SYSCALL NewStr.YA bcs .99 txa >STA.G CMD.hFullpath lda STAT+S.STAT.P.TYPE cmp #$04 TXT File ? beq Cmd.Exec.EXT.TXT cmp #$06 BIN File ? beq Cmd.Exec.EXT.BIN cmp #$ff SYS File ? bne .9 bra * .9 lda #SYSMGR.ERRSYN sec .99 jmp Cmd.Exec.Done *-------------------------------------- * TXT : Launch "/PATH/SHELL /PATH/CMD ARGS" *-------------------------------------- Cmd.Exec.EXT.TXT lda #0 Get arg[0] = /PATH/SHELL >SYSCALL GetArg.A >PUSHYA >PUSHW ZPCMDBuf >SYSCALL StrCpy jsr Cmd.Exec.EXT.SEP Add a space.... >LDA.G CMD.hFullpath >SYSCALL GetMemPtr.A >PUSHYA >PUSHW ZPCMDBuf >SYSCALL StrCat *-------------------------------------- * BIN : Launch "/PATH/CMD ARGS" *-------------------------------------- Cmd.Exec.EXT.BIN jsr Cmd.Exec.EXT.SEP Add a space.... >PUSHW ZPPTR2 >PUSHW ZPCMDBuf >SYSCALL StrCat .1 >LDYA ZPCMDBuf bit bStartProc bmi .2 startproc >SYSCALL ExecProcessNewEnvYA jmp Cmd.Exec.Done .2 >SYSCALL CreateProcessYA jmp Cmd.Exec.Done *-------------------------------------- Cmd.Exec.EXT.Search >PUSHYA push search list >PUSHW ZPPtr1 push CMD >PUSHW ZPCMDBuf push dest full path >PUSHW L.STAT >SYSCALL FileSearch rts *-------------------------------------- Cmd.Exec.EXT.SEP ldy #$ff .1 iny lda (ZPCMDBuf),y bne .1 lda #' ' sta (ZPCMDBuf),y iny lda #0 sta (ZPCMDBuf),y rts *-------------------------------------- * Internal Commands *-------------------------------------- Cmd.Exec.INT jmp (J.INTCMDS,x) *-------------------------------------- Cmd.Exec.CD lda (ZPPTR2) bne Cmd.Exec.CD1 Cmd.Exec.PWD ldy #S.PS.hPREFIX lda (pPs),y >SYSCALL GetMemPtr.A >SYSCALL PrintF.YA rts Cmd.Exec.CD1 stz UsrBuf256 cmp #'/' Full Path? beq .1 ldy #S.PS.hPREFIX no, init target prefix with actual prefix lda (pPs),y >SYSCALL GetMemPtr.A >PUSHYA >PUSHWI UsrBuf256 >SYSCALL StrCpy .1 >PUSHW ZPPTR2 Append ARG to buffer >PUSHWI UsrBuf256 >SYSCALL StrCat lda #'/' ldx UsrBuf256 cmp UsrBuf256,x Ending '/' ? beq .2 sta UsrBuf256+1,x no, add one... inc UsrBuf256 .2 ldx #0 path is something like : /dir1/../dir2/ .3 ldy #0 reset char counter .4 cpx UsrBuf256 beq .8 inx lda UsrBuf256,x cmp #'/' beq .5 iny char=char+1!!! bra .4 .5 tya any char count? beq .4 no, start counting... cpy #2 do we have /xx/? bne .3 no, skip this token lda #'.' cmp UsrBuf256-1,x /yy/x./ ? bne .3 cmp UsrBuf256-2,x /yy/../ ? bne .3 cpx #4 /../ ? beq Cmd.Exec.ERRSYN illegal txa tay save end of /../ sec sbc #3 remove ../ tax .6 dex lda UsrBuf256,x Found beginning of dir before /../ cmp #'/' bne .6 .7 lda UsrBuf256,y strip dir/../ sta UsrBuf256,x cpy UsrBuf256 beq .71 iny inx bra .7 .71 stx UsrBuf256 bra .2 Start over... .8 cpx #1 beq .80 we have '/' go change prefix >PUSHW L.STAT >PUSHWI UsrBuf256 >SYSCALL STAT bcs .9 lda STAT+S.STAT.P.TYPE cmp #$0F Directory ? bne Cmd.Exec.ERRSYN .80 >LDYAI UsrBuf256 >SYSCALL NewStr.YA bcs .9 phx ldy #S.PS.hPREFIX lda (pPs),y >SYSCALL FreeMem.A pla ldy #S.PS.hPREFIX sta (pPs),y jsr SetPWD clc .9 rts *-------------------------------------- Cmd.Exec.ERRSYN lda #SYSMGR.ERRSYN sec rts *-------------------------------------- Cmd.Exec.STARTPROC lda (ZPPTR2) beq Cmd.Exec.ERRSYN sec ror bStartProc >LDYA ZPPTR2 >STYA ZPPTR1 jmp Cmd.Exec.2 *-------------------------------------- Cmd.Exec.SET lda (ZPPTR2) bne Cmd.Exec.SETVAR * No arg, print all ENV ldy #S.PS.hENV lda (pPs),y >SYSCALL GetMemPtr.A >STYA ZPPTR1 .1 lda (ZPPTR1) beq .8 Ending 0 ? ldy #$ff .2 iny lda (ZPPTR1),y bne .2 tya sec adc ZPPTR1 sta ZPPTR2 lda #0 adc ZPPTR1+1 sta ZPPTR2+1 >PUSHW ZPPTR2 Push value >PUSHW ZPPTR1 Push name >LDYA L.MSG.PRINTENV >SYSCALL PrintF.YA bcs .9 ldy #$ff .3 iny lda (ZPPTR2),y bne .3 tya sec adc ZPPTR2 sta ZPPTR1 lda #0 adc ZPPTR2+1 sta ZPPTR1+1 bra .1 .8 clc .9 rts Cmd.Exec.SETVAR ldy #0 lda (ZPPTR2),y iny cmp #'=' string is '=value' ? beq .99 syntax error .1 lda (ZPPTR2),y iny beq .3 no =, GetEnv cmp #'=' ARGS contains =, PutEnv bne .1 lda (ZPPTR2),y beq .2 "VAR=" go UnsetEnv >LDYA ZPPTR2 String is VAR=VALUE... >SYSCALL PutEnv.YA rts .2 dey String is "VAR=", Remove endig '=' sta (ZPPTR2),y >LDYA ZPPTR2 String is "VAR"... >SYSCALL UnsetEnv.YA rts * Print requested VAR .3 >LDYA ZPPTR2 >SYSCALL GetEnv.YA bcs .8 >PUSHYA push value >PUSHW ZPPTR2 push name >LDYA L.MSG.PRINTENV >SYSCALL PrintF.YA .8 clc .9 rts .99 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.Exec.DATE sec .HS 90 bcc Cmd.Exec.TIME clc php >LDYA L.TIME >SYSCALL TimeYA >PUSHWI UsrBuf256 plp bcc .1 >PUSHW L.FMT.DATE bra .2 .1 >PUSHW L.FMT.TIME .2 >PUSHW L.TIME >SYSCALL StrFTime >LDYAI UsrBuf256 >SYSCALL PrintF.YA bcs Cmd.Exec.ECHO.RTS bra Cmd.Exec.ECHO.CR *-------------------------------------- Cmd.Exec.ECHO lda (ZPPtr2) beq Cmd.Exec.ECHO.CR >LDYA ZPPtr2 >SYSCALL PrintF.YA Cmd.Exec.ECHO.CR lda #13 >SYSCALL PutChar.A bcs Cmd.Exec.ECHO.RTS lda #10 >SYSCALL PutChar.A Cmd.Exec.ECHO.RTS rts *-------------------------------------- Cmd.Exec.READ lda (ZPPtr2) beq .9 lda #0 >STA.G bSecureRead lda pData clc adc #CMD.VarName sta ZPPTR1 lda pData+1 adc #0 sta ZPPTR1+1 ldy #0 .1 lda (ZPPtr2),y beq .8 iny cmp #' ' beq .1 cmp #'-' bne .7 lda (ZPPtr2),y beq .9 iny cmp #'S' bne .2 lda #$80 >STA.G bSecureRead bra .1 .2 cmp #'P' bne .9 lda (ZPPtr2),y beq .9 iny cmp #' ' bne .9 lda (ZPPtr2),y beq .9 iny cmp #'"' bne .9 .3 lda (ZPPtr2),y beq .9 iny cmp #'"' beq .1 phy >SYSCALL PutChar.A ply bcs .99 bra .3 .9 jmp Cmd.Exec.ERRSYN .70 lda (ZPPtr2),y cmp #' ' beq .1 .7 lda (ZPPTR1) cmp #VarLen.MAX beq .9 inc sta (ZPPTR1) tay lda (ZPPtr2),y sta (ZPPTR1),y bne .70 .8 lda (ZPPTR1) No var name ? SYNERR beq .9 clc .99 rts *-------------------------------------- Cmd.Exec.SLEEP lda (ZPPtr2) beq .9 lda #Sleep clc adc pData tay lda /Sleep adc pData+1 >PUSHYA >PUSHW ZPPtr2 >SYSCALL AToI.YA bcs .9 rts .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.Exec.PAUSE lda #$FF >STA.G bPause clc rts *-------------------------------------- Cmd.Exec.EXIT lda #$FF >STA.G bExit clc rts *-------------------------------------- MAN SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD LOAD /A2OSX.SRC/SBIN/SHELL.S ASM