PR#3 PREFIX /A2OSX.BUILD LOMEM $A00 INC 1 AUTO 6 */-------------------------------------- * # NewPStrYA * Create a new copy of PSTR * ## In: * Y,A = PTR to buffer * ## Out: * CC : success * Y,A = PTR to String * X = hMem (PSTR) * CS : error * A = SYS error code *\-------------------------------------- K.NewPStr.YA >STYA ZPPtr2 lda (ZPPtr2) inc tay lda #0 Y,A = len of new string jsr K.GetMemYA bcs .9 >STYA ZPPtr1 lda (ZPPtr2) sta (ZPPtr1) tay beq .2 .1 lda (ZPPtr2),y sta (ZPPtr1),y dey bne .1 .2 >LDYA ZPPtr1 clc .9 rts */-------------------------------------- * # ExpandPStr.YA * ## In: * Y,A = PTR to String to Expand (PSTR) * ## Out: * X = hMem to Expanded String (PSTR) * Y,A = PTR to Expanded String *\-------------------------------------- K.ExpandPStr.YA stz K.ExpandPStr.hPStr Reset Intermediate string... .1 >STYA ZPPtr2 stz K.Buf256 init Expanded String len=0 stz K.ExpandPStr.bFound No var found yet stz K.ExpandPStr.bNoExp Reset no expand flag ldy #0 .10 stz K.ExpandPStr.Name stz K.ExpandPStr.bInVar .11 tya cmp (ZPPtr2) End of PSTR? beq .8 iny lda (ZPPtr2),y cmp #''' bne .21 lda K.ExpandPStr.bNoExp eor #$ff sta K.ExpandPStr.bNoExp toggle flag bra .11 .21 bit K.ExpandPStr.bNoExp bpl .23 .22 ldx K.Buf256 inx beq .8 sta K.Buf256,x stx K.Buf256 bra .11 .23 ldx K.ExpandPStr.bInVar already in a var? bne .3 yes.... cmp #'$' no, found one ? bne .22 no, store.... sta K.ExpandPStr.bFound Toggle flag sta K.ExpandPStr.bInVar bra .11 skip this char .3 cmp #'{' we are in var, "{" after "$"? bne .31 ldx K.ExpandPStr.Name No char in var yet ? beq .11 normal, "${" syntax is ok,skip bne .5 not allowed char in varname, end of var .31 cmp #'}' end of var? beq .50 jsr K.ExpandPStrValidChar bcc .32 yes, add to varname ldx K.ExpandPStr.Name bne .5 varname has already chars...end of var inx must be a $? or ?x.....go expand stx K.ExpandPStr.Name sta K.ExpandPStr.Name+1 bra .51 go Expand.... .32 ldx K.ExpandPStr.Name inx cpx #16 beq .11 varname longer than 15....ignore sta K.ExpandPStr.Name,x stx K.ExpandPStr.Name bra .11 .5 dey last char was invalid...move back .50 ldx K.ExpandPStr.Name beq .52 var name is empty...start over .51 phy save current index jsr K.ExpandPStrGetValue ply restore index in string... .52 jmp .10 reset start flag and continue .8 ldx K.ExpandPStr.Name end of PSTR,are we in a var? beq .80 no...exit... jsr K.ExpandPStrGetValue yes, expand and add to STR .80 lda K.ExpandPStr.hPStr working from our temp string ? beq .81 no... jsr K.FreeMemA yes, discard.... .81 >LDYAI K.Buf256 jsr K.NewPStr.YA bcs .9 stx K.ExpandPStr.hPStr save this as temp string, in case of recurse ldx K.ExpandPStr.bFound Did we expand something ? beq .82 jmp .1 Yes, start over with hPStr .82 ldx K.ExpandPStr.hPStr * or exit with Y,A from K.NewPStrYA .9 rts *-------------------------------------- K.ExpandPStrValidChar cmp #'0' bcc .9 cmp #'9'+1 bcc .8 cmp #'A' bcc .9 cmp #'Z'+1 bcc .8 cmp #'_' bne .9 .8 clc rts .9 sec rts *-------------------------------------- K.ExpandPStrGetValue jsr ENV.ExpandSysVar bcc .9 >LDYAI K.ExpandPStr.Name jsr K.GetEnv.YA bcs .9 >STYA ZPPtr3 jsr ENV.AppendPtr3ToBuf .9 rts *-------------------------------------- K.ExpandPStr.bNoExp .BS 1 K.ExpandPStr.bInVar .BS 1 K.ExpandPStr.bFound .BS 1 K.ExpandPStr.hPStr .BS 1 K.ExpandPStr.Name .BS 16 */-------------------------------------- * # PutEnv.YA * ## In: * Y,A = PTR to String NAME=VALUE (PSTR) * ## Out: *\-------------------------------------- K.PutEnv.YA >STYA ZPPtr1 NAME=VALUE lda (ZPPtr1) beq .9 sta K.Buf256 tay .1 lda (ZPPtr1),y copy PSTR to K.Buf256 sta K.Buf256,y dey bne .1 ldy #0 .2 iny cpy K.Buf256 last char ? beq .9 no "=" found lda K.Buf256,y cmp #'=' bne .2 cpy #1 String like "=value" ? beq .9 cpy K.Buf256 last char ? beq .9 we have "VAR=" lda K.Buf256 get actual string len sty K.Buf256 set length of VAR string dec K.Buf256 ...without "=" clc Substract VAR len+1 from whole len to get sbc K.Buf256 VALUE len sta K.Buf256,y save it at "=" POS stz ZPPtr1 #K.Buf256 sty ZPPtr2 lda /K.Buf256 sta ZPPtr1+1 sta ZPPtr2+1 bra K.SetEnvPtr1Ptr2 .9 sec rts */-------------------------------------- * # SetEnv * ## In: * PUSHW = PTR To Value (PSTR) * PUSHW = PTR To Name (PSTR) * ## Out: *\-------------------------------------- K.SetEnv jsr PullPtr1Ptr2 Ptr1=NAME,Ptr2=VALUE K.SetEnvPtr1Ptr2 jsr S.UnsetEnvPtr1 jsr ENV.InitEnvPtr3 ZPPtr3 -> Env lda ZPPtr3 Compute ENV UPPER LIMIT in Ptr4 clc adc #K.ENV.SIZE sta ZPPtr4 lda ZPPtr3+1 adc /K.ENV.SIZE sta ZPPtr4+1 ldy ZPPtr3+1 lda ZPPtr3 Compute New Env Upper limit in A,Y sec adc (ZPPtr1) add NAME len +1 bcc .1 iny .1 sec adc (ZPPtr2) add VALUE len +1 bcc .2 iny .2 cmp ZPPtr4 GE than hMem Upper limit ? tya sbc ZPPtr4+1 bcs .99 .3 lda (ZPPtr3) Scan until ending 0... beq .4 inc ZPPtr3 bne .3 inc ZPPtr3+1 bne .3 .4 lda (ZPPtr1) sta (ZPPtr3) tay .5 lda (ZPPtr1),y sta (ZPPtr3),y dey bne .5 jsr ENV.NextEnvPtr3 lda (ZPPtr2) sta (ZPPtr3) tay .6 lda (ZPPtr2),y sta (ZPPtr3),y dey bne .6 jsr ENV.NextEnvPtr3 .8 lda #0 sta (ZPPtr3) clc rts .99 lda #SYSMGR.ERRENVF sec rts */-------------------------------------- * # GetEnv.YA * ## In: * Y,A = PTR to NAME (PSTR) * ## Out: * CC : Y,A = PTR to VALUE (PSTR) * CS : not found *\-------------------------------------- K.GetEnv.YA >STYA ZPPtr1 jsr ENV.FindVarPtr1 bcs .9 jsr ENV.NextEnvPtr3 Skip NAME >LDYA ZPPtr3 clc just in case ADC in NextEnvPtr1 disturb CC .8 rts .9 >LDYAI EmptyPSTR rts */-------------------------------------- * # UnsetEnv.YA * ## In: * Y,A = PTR To Name (PSTR) * ## Out: *\-------------------------------------- K.UnsetEnv.YA >STYA ZPPtr1 Store VAR Name S.UnsetEnvPtr1 jsr ENV.FindVarPtr1 bcs .8 not found, quit jsr ENV.DiscardVarPtr3 Ptr3 -> ENVNAME .8 clc rts *-------------------------------------- * PRIVATE *-------------------------------------- * ENV.ExpandSysVar * In: * K.ExpandPStr.Name * Out: * CC: Found * Append VALUE to K.Buf256 * CS: Not Found *-------------------------------------- ENV.ExpandSysVar ldx K.ExpandPStr.Name cpx #1 is name 1 char? bne .9 ldy #1 lda K.ExpandPStr.Name+1 cmp #'0'-1 $0...$9 ?? bcc .1 cmp #'9'+1 bcs .1 and #$0F jsr K.GetArg.A bcs .99 >STYA ZPPtr3 jmp ENV.AppendPtr3ToBuf .8 clc rts .1 ldx #ENV.SysVarsJmp-ENV.SysVars-1 .2 cmp ENV.SysVars,x beq .3 dex bpl .2 .9 sec .99 rts .3 txa asl tax jmp (ENV.SysVarsJmp,x) ENV.SysVars .AS "*#?@$!" ENV.SysVarsJmp .DA ENV.SysVarsArgs .DA ENV.SysVarsArgC .DA ENV.SysVarsRC .DA ENV.SysVarsPPID .DA ENV.SysVarsPID .DA ENV.SysVarsCPID *-------------------------------------- ENV.SysVarsArgs lda #1 jsr K.GetArg.A bcs ENV.SysVarsExit2 >STYA ZPPtr3 .1 lda (ZPPtr3) beq ENV.SysVarsExit2 jsr ENV.AppendPtr3ToBuf .2 jsr ENV.NextEnvPtr3 lda (ZPPtr3) beq ENV.SysVarsExit2 ldx K.Buf256 inx beq ENV.SysVarsExit2 make sure not overlapping buf 256 stx K.Buf256 lda #' ' sta K.Buf256,x jsr ENV.AppendPtr3ToBuf bra .2 *-------------------------------------- ENV.SysVarsArgC jsr K.GetArgC Trash Ptr1 bra ENV.SysVarsA ENV.SysVarsRC ldy #S.PS.RC .HS 2C ENV.SysVarsPPID ldy #S.PS.PPID .HS 2C ENV.SysVarsPID ldy #S.PS.PID .HS 2C ENV.SysVarsCPID ldy #S.PS.CPID lda (pPS),y ENV.SysVarsA sta HEXBUF stz HEXBUF+1 stz HEXBUF+2 stz HEXBUF+3 jsr HEX2DEC ldy #6 Start at 0000000xxx .1 iny lda ASCBUF,y cmp #'0' bne .2 cpy #9 Print always last char bne .1 .2 ldx K.Buf256 .3 inx beq ENV.SysVarsExit2 sta K.Buf256,x iny cpy #10 beq ENV.SysVarsExit lda ASCBUF,y bra .3 ENV.SysVarsExit stx K.Buf256 ENV.SysVarsExit2 clc rts *-------------------------------------- * ENV.FindVarPtr1 * In: * ZPPtr1 -> NAME * Out: * CC: Found * ZPPtr1 -> NAME * ZPPtr3 -> ENV.NAME * CS: Not Found * ZPPtr1 -> NAME * ZPPtr3 -> PTR to Ending 0 *-------------------------------------- ENV.FindVarPtr1 jsr ENV.InitEnvPtr3 Store ENV bcs .99 lda (ZPPtr3) beq .9 end of ENV .1 cmp (ZPPtr1) Same len as NAME? bne .3 tay .2 lda (ZPPtr1),y cmp (ZPPtr3),y bne .3 dey bne .2 clc rts .3 jsr ENV.NextEnvPtr3 Skip NAME jsr ENV.NextEnvPtr3 Skip VALUE lda (ZPPtr3) bne .1 .9 sec .99 rts *-------------------------------------- * ENV.DiscardVarPtr3 * In: * ZPPtr3 -> ENV.NAME to Discard *-------------------------------------- ENV.DiscardVarPtr3 lda ZPPtr3 Discard current NAME & VALUE definition sec ZPPtr3 -> NAME adc (ZPPtr3) add NAME+1 to ZPPtr3 sta ZPPtr4 store it in ZPPtr4 lda #0 adc ZPPtr3+1 sta ZPPtr4+1 lda ZPPtr4 add VALUE+1 to ZPPtr4 sec adc (ZPPtr4) sta ZPPtr4 bcc .1 inc ZPPtr4+1 .1 ldy #0 .2 lda (ZPPtr4),y Move back tail... sta (ZPPtr3),y beq .8 ...until we move ending 0 iny bne .2 inc ZPPtr3+1 inc ZPPtr4+1 bra .2 .8 rts *-------------------------------------- ENV.InitEnvPtr3 ldy #S.PS.hENV lda (pPs),y jsr K.GetMemPtrA >STYA ZPPtr3 Store ENV rts *-------------------------------------- ENV.NextEnvPtr3 lda ZPPtr3 sec adc (ZPPtr3) sta ZPPtr3 bcc .8 inc ZPPtr3+1 .8 rts *-------------------------------------- ENV.AppendPtr3ToBuf ldy #0 ldx K.Buf256 .1 iny lda (ZPPtr3),y inx beq .9 sta K.Buf256,x tya cmp (ZPPtr3) last char? bne .1 stx K.Buf256 .9 rts *-------------------------------------- MAN SAVE /A2OSX.SRC/SYS/KERNEL.S.ENV LOAD /A2OSX.SRC/SYS/KERNEL.S ASM