A2osX/SYS/KERNEL.S.ENV.txt

561 lines
9.9 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
*/--------------------------------------
* # ExpandStr.YA
* ## In:
* Y,A = PTR to String to Expand (C-String)
* ## Out:
* X = hMem to Expanded String (C-String)
* Y,A = PTR to Expanded String
*\--------------------------------------
K.ExpandStr.YA stz ENV.hStr Reset Intermediate string...
.1 >STYA ZPPtr2
stz ENV.BufLen init Expanded String len=0
stz ENV.bFound No var found yet
stz ENV.bNoExp Reset no expand flag
2015-03-14 21:48:35 +00:00
ldy #0
2017-10-27 14:56:46 +00:00
.10 stz ENV.VarLen
stz ENV.bInVar
.11 lda (ZPPtr2),y End of CSTR?
beq .8
2015-03-14 21:48:35 +00:00
iny
cmp #'''
bne .21
2017-10-27 14:56:46 +00:00
lda ENV.bNoExp
eor #$ff
sta ENV.bNoExp toggle flag
bra .11
2017-10-27 14:56:46 +00:00
.21 bit ENV.bNoExp
bpl .23
2017-10-27 14:56:46 +00:00
.22 ldx ENV.BufLen
sta K.Buf256,x
inx
2017-10-27 14:56:46 +00:00
stx ENV.BufLen
bra .11
.23 ldx ENV.bInVar already in a var?
bne .3 yes...
cmp #'$' no, found one ?
bne .22 no, store...
sta ENV.bFound Toggle flag
2017-10-27 14:56:46 +00:00
sta ENV.bInVar
bra .11 skip this char
.3 cmp #'{' we are in var, "{" after "$"?
bne .31
ldx ENV.VarLen 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 MEM.IsIDValid _,.,a-z,A-Z,0-9 ?
bcc .32 yes, add to varname
2017-10-27 14:56:46 +00:00
ldx ENV.VarLen
bne .5 varname has already chars...end of var
inx must be a $? or ?x.....go expand
2017-10-27 14:56:46 +00:00
stx ENV.VarLen
sta ENV.VarName
bra .51 go Expand....
2017-10-27 14:56:46 +00:00
.32 ldx ENV.VarLen
cpx #16
beq .11 varname longer than 15....ignore
2017-10-27 14:56:46 +00:00
sta ENV.VarName,x
inx
2017-10-27 14:56:46 +00:00
stx ENV.VarLen
bra .11
.5 dey last char was invalid...move back
2017-10-27 14:56:46 +00:00
.50 ldx ENV.VarLen
beq .52 var name is empty...start over
2017-10-27 14:56:46 +00:00
.51 stz ENV.VarName,x
phy save current index
2017-10-27 14:56:46 +00:00
jsr ENV.GetValue
ply restore index in string...
.52 jmp .10 reset start flag and continue
.8 ldx ENV.VarLen end of STR,are we in a var?
beq .80 no...exit...
2017-10-27 14:56:46 +00:00
stz ENV.VarName,x
jsr ENV.GetValue yes, expand and add to STR
.80 lda ENV.hStr working from our temp string ?
beq .81 no...
jsr K.FreeMem.A yes, discard....
2017-10-27 14:56:46 +00:00
.81 ldx ENV.BufLen
stz K.Buf256,x
>LDYAI K.Buf256
jsr K.NewStr.YA
bcs .9
2017-10-27 14:56:46 +00:00
stx ENV.hStr save this as temp string, in case of recurse
ldx ENV.bFound Did we expand something ?
beq .82
jmp .1 Yes, start over with hPStr
2017-10-27 14:56:46 +00:00
.82 ldx ENV.hStr
* or exit with Y,A from K.NewStrYA
.9 rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.GetValue jsr ENV.ExpandSysVar
bcc .9
2017-10-27 14:56:46 +00:00
>LDYAI ENV.VarName
jsr K.GetEnv.YA
bcs .9
>STYA ZPPtr3
2017-10-27 14:56:46 +00:00
jsr ENV.AddP3ToBuf
.9 rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.BufLen .BS 1
ENV.bNoExp .BS 1
ENV.bInVar .BS 1
ENV.bFound .BS 1
ENV.hStr .BS 1
ENV.VarLen .BS 1
ENV.VarName .BS 16
*/--------------------------------------
* # PutEnv.YA
* ## In:
* Y,A = PTR to String NAME=VALUE (C-String)
* ## Out:
*\--------------------------------------
K.PutEnv.YA >STYA ZPPtr1 NAME=VALUE
2016-08-17 06:25:58 +00:00
ldy #0
2016-06-07 06:10:18 +00:00
.1 lda (ZPPtr1),y copy STR to K.Buf256
2016-08-17 06:25:58 +00:00
beq .9
cmp #'='
beq .2
sta K.Buf256,y
iny
bne .1
2016-08-17 06:25:58 +00:00
.2 lda #0
sta K.Buf256,y
tya
sec
adc ZPPtr1
sta ZPPtr2
lda ZPPtr1+1
adc #0
2017-01-12 17:43:45 +00:00
sta ZPPtr2+1
>LDYAI K.Buf256
>STYA ZPPtr1
2017-10-27 14:56:46 +00:00
bra K.SetEnv.I
2016-08-17 06:25:58 +00:00
.9 sec
rts
*/--------------------------------------
* # SetEnv
* ## In:
* PUSHW = PTR To Value (PSTR)
* PUSHW = PTR To Name (PSTR)
* ## Out:
*\--------------------------------------
2017-10-27 14:56:46 +00:00
K.SetEnv jsr PullP1P2 Ptr1=NAME,Ptr2=VALUE
K.SetEnv.I jsr K.UnsetEnv.I
2016-08-17 06:25:58 +00:00
2017-10-27 14:56:46 +00:00
jsr ENV.InitEnvP3 ZPPtr3 -> Env
ldy #0
ldx #0
2016-08-17 06:25:58 +00:00
.10 lda (ZPPtr3) End of ENV
beq .15
2016-08-17 06:25:58 +00:00
.11 iny Compute ENV size in X,Y
bne .12
inx
2016-08-17 06:25:58 +00:00
.12 inc ZPPtr3
bne .13
inc ZPPtr3+1
2016-08-17 06:25:58 +00:00
.13 lda (ZPPtr3) End of string
bne .11
2015-03-14 21:48:35 +00:00
iny
bne .14
inx
2016-08-17 06:25:58 +00:00
.14 inc ZPPtr3
bne .10
2017-01-12 17:43:45 +00:00
inc ZPPtr3+1
bra .10
.15 sty ZPPtr4
stx ZPPtr4+1
ldy #0
2016-08-17 06:25:58 +00:00
.16 lda (ZPPtr1),y
beq .17
iny
bne .16
2016-08-17 06:25:58 +00:00
.17 tya
sec
adc ZPPtr4
sta ZPPtr4
bcc .18
inc ZPPtr4+1
2016-08-17 06:25:58 +00:00
.18 ldy #0
.19 lda (ZPPtr2),y
beq .20
iny
bne .19
2016-08-17 06:25:58 +00:00
.20 tya
sec
adc ZPPtr4
tax
bcc .21
inc ZPPtr4+1
.21 cpx #K.ENV.SIZE
lda ZPPtr4+1
sbc /K.ENV.SIZE
bcs .99
2016-08-17 06:25:58 +00:00
ldy #$ff
2016-08-17 06:25:58 +00:00
.22 iny
lda (ZPPtr1),y
sta (ZPPtr3),y
bne .22
2016-08-17 06:25:58 +00:00
tya
sec
adc ZPPtr3
sta ZPPtr3
bcc .23
inc ZPPtr3+1
2016-08-17 06:25:58 +00:00
.23 ldy #$ff
.24 iny
lda (ZPPtr2),y
sta (ZPPtr3),y
bne .24
iny
sta (ZPPtr3),y don't forget array ending 0
2015-03-14 21:48:35 +00:00
clc
rts
2016-08-17 06:25:58 +00:00
.99 lda #K.E.ENVF
* sec
2015-03-14 21:48:35 +00:00
rts
*/--------------------------------------
* # GetEnv.YA
* ## In:
* Y,A = PTR to NAME (PSTR)
* ## Out:
* CC : Y,A = PTR to VALUE (PSTR)
2016-08-17 06:25:58 +00:00
* CS : not found
*\--------------------------------------
K.GetEnv.YA >STYA ZPPtr1
2017-10-27 14:56:46 +00:00
jsr ENV.FindVarP1
2016-08-17 06:25:58 +00:00
bcs .9
2017-10-27 14:56:46 +00:00
jsr ENV.NextEnvP3 Skip NAME
clc just in case ADC in NextEnvPtr1 disturb CC
.9 >LDYA ZPPtr3
rts
*/--------------------------------------
* # UnsetEnv.YA
* ## In:
* Y,A = PTR To Name (PSTR)
* ## Out:
*\--------------------------------------
2017-10-27 14:56:46 +00:00
K.UnsetEnv.YA >STYA ZPPtr1 Store VAR Name
K.UnsetEnv.I jsr ENV.FindVarP1
bcs K.UnsetEnv.I.8 not found, quit
2017-10-27 14:56:46 +00:00
jsr ENV.DelVarP3 Ptr3 -> ENVNAME
K.UnsetEnv.I.8 clc
rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
* PRIVATE
*--------------------------------------
* ENV.ExpandSysVar
2015-03-14 21:48:35 +00:00
* In:
2017-10-27 14:56:46 +00:00
* ENV.VarLen,ENV.VarName
2016-08-17 06:25:58 +00:00
* Out:
* CC: Found
* Append VALUE to K.Buf256
2016-08-17 06:25:58 +00:00
* CS: Not Found
*--------------------------------------
ENV.ExpandSysVar
2017-10-27 14:56:46 +00:00
ldx ENV.VarLen
cpx #1 is name 1 char?
2016-08-17 06:25:58 +00:00
bne .9
2017-10-27 14:56:46 +00:00
lda ENV.VarName
jsr MEM.IsDigit $0...$9 ??
bcs .1
2016-08-17 06:25:58 +00:00
and #$0F
jsr K.GetArg.A
bcs K.UnsetEnv.I.8 Arg# is undefined, do not append anything
2017-01-12 17:43:45 +00:00
>STYA ZPPtr3
2017-10-27 14:56:46 +00:00
jmp ENV.AddP3ToBuf
.1 ldx #ENV.SysVarsJmp-ENV.SysVars-1
.2 cmp ENV.SysVars,x
beq .3
dex
bpl .2
2016-08-17 06:25:58 +00:00
.9 sec
.99 rts
2016-08-17 06:25:58 +00:00
.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 .8
>STYA ZPPtr3
.1 lda (ZPPtr3)
beq .8
2017-10-27 14:56:46 +00:00
jsr ENV.AddP3ToBuf
2017-10-27 14:56:46 +00:00
.2 jsr ENV.NextEnvP3
lda (ZPPtr3)
beq .8
inx
beq .8 make sure not overlapping buf 256
lda #' '
sta K.Buf256,x
2017-10-27 14:56:46 +00:00
stx ENV.BufLen
2017-10-27 14:56:46 +00:00
jsr ENV.AddP3ToBuf
bra .2
.8 clc
rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.AddP3ToBuf ldx ENV.BufLen
ldy #$ff
dex
.1 iny
inx
lda (ZPPtr3),y
sta K.Buf256,x
bne .1
2017-10-27 14:56:46 +00:00
stx ENV.BufLen
rts
*--------------------------------------
ENV.SysVarsArgC ldy #S.PS.ARGC
.HS 2C
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
stz .2+1
stz .3+1
ldx #8
sed
.1 asl
pha
.2 lda #$ff Self Modified
adc .2+1
sta .2+1
.3 lda #$ff Self Modified
adc .3+1
sta .3+1
2016-08-17 06:25:58 +00:00
pla
dex
bne .1
cld
2017-10-27 14:56:46 +00:00
ldx ENV.BufLen
lda .3+1
beq .4
sta K.Buf256,x
inx
.4 lda .2+1
lsr
lsr
lsr
lsr
beq .5
ora #$30
sta K.Buf256,x
inx
.5 lda .2+1
and #$0f
ora #$30
sta K.Buf256,x
inx
2017-10-27 14:56:46 +00:00
stx ENV.BufLen
clc
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2017-10-27 14:56:46 +00:00
* ENV.FindVarP1
2016-08-17 06:25:58 +00:00
* In:
2017-01-12 17:43:45 +00:00
* ZPPtr1 -> NAME
2015-03-14 21:48:35 +00:00
* Out:
* CC: Found
2017-01-12 17:43:45 +00:00
* ZPPtr1 -> NAME
* ZPPtr3 -> ENV.NAME
2015-03-14 21:48:35 +00:00
* CS: Not Found
2017-01-12 17:43:45 +00:00
* ZPPtr1 -> NAME
* ZPPtr3 -> PTR to Ending 0
2015-03-14 21:48:35 +00:00
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.FindVarP1 jsr ENV.InitEnvP3 Store ENV
.1 lda (ZPPtr3)
2016-08-17 06:25:58 +00:00
beq .9 end of ENV
ldy #0
2016-08-17 06:25:58 +00:00
2017-01-12 17:43:45 +00:00
.2 lda (ZPPtr1),y
cmp (ZPPtr3),y
2016-08-17 06:25:58 +00:00
bne .3
ora #0
beq .8
iny
2015-03-14 21:48:35 +00:00
bne .2
.8 clc
2016-08-17 06:25:58 +00:00
rts
2017-10-27 14:56:46 +00:00
.3 jsr ENV.NextEnvP3 Skip NAME
jsr ENV.NextEnvP3 Skip VALUE
bra .1
2016-08-17 06:25:58 +00:00
.9 sec
rts
2016-08-17 06:25:58 +00:00
*--------------------------------------
2017-10-27 14:56:46 +00:00
* ENV.DelVarP3
2016-08-17 06:25:58 +00:00
* In:
2017-01-12 17:43:45 +00:00
* ZPPtr3 -> ENV.NAME to Discard
2016-08-17 06:25:58 +00:00
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.DelVarP3 >LDYA ZPPtr3 save actual Ptr
>STYA ZPPtr4
2017-10-27 14:56:46 +00:00
jsr ENV.NextEnvP3 Skip current NAME....
jsr ENV.NextEnvP3 Skip current VALUE....
ldy #0
2016-08-17 06:25:58 +00:00
.1 lda (ZPPtr3),y Move back CSTRs...
.2 sta (ZPPtr4),y
beq .3 0 ended....
2015-03-14 21:48:35 +00:00
iny
bne .1
inc ZPPtr3+1
inc ZPPtr4+1
bra .1
.3 iny
bne .4
inc ZPPtr3+1
inc ZPPtr4+1
.4 lda (ZPPtr3),y
bne .2 Until array ending 0
sta (ZPPtr4),y
2016-08-17 06:25:58 +00:00
.8 rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.InitEnvP3 ldy #S.PS.hENV
2016-08-17 06:25:58 +00:00
lda (pPs),y
jsr K.GetMemPtr.A
>STYA ZPPtr3 Store ENV
2016-08-17 06:25:58 +00:00
rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
ENV.NextEnvP3 ldy #0
.1 lda (ZPPtr3),y
beq .2
iny
bne .1
.2 tya
2015-03-14 21:48:35 +00:00
sec
adc ZPPtr3
2017-01-12 17:43:45 +00:00
sta ZPPtr3
2016-08-17 06:25:58 +00:00
bcc .8
2017-01-12 17:43:45 +00:00
inc ZPPtr3+1
.8 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.ENV
LOAD /A2OSX.SRC/SYS/KERNEL.S
2015-03-14 21:48:35 +00:00
ASM