A2osX/SYS/KERNEL.S.ENV.txt
2016-08-28 22:48:01 +02:00

457 lines
8.8 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.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
S.ExpandPStrYA >STYA ZPQuickPtr3
lda (ZPQuickPtr3)
sta KrnBuffer256
tay
.1 lda (ZPQuickPtr3),y
sta KrnBuffer256,y
dey
bne .1
ldy #0
.2 stz S.ExpandPStr.Start
.3 tya
cmp KrnBuffer256 End of PSTR?
beq .80
iny
lda KrnBuffer256,y
*--------------------------------------
* S.ExpandPStrYA
* In:
* Y,A = PTR to String to Expand (PSTRING)
* Out:
* X = hMem to Expanded String (PSTRING)
* Y,A = PTR to Expanded String
*--------------------------------------
S.ExpandPStrYA.OLD
>STYA ZPQuickPtr3
stz KrnBuffer256 init Expanded String len=0
ldy #0
.10 stz S.ExpandPStr.Start
.1 tya
cmp (ZPQuickPtr3) End of PSTR?
beq .6
iny
lda (ZPQuickPtr3),y
ldx S.ExpandPStr.Start
bne .3 already in a var?
cmp #'$' no, found one ?
beq .2
inc KrnBuffer256 no, copy char
ldx KrnBuffer256
sta KrnBuffer256,x
bra .1
.2 sty S.ExpandPStr.Start save var start
stz S.ExpandPStr.End
bra .1 skip this char
.3 cmp #'{' in var, "{" after "$"?
beq .2
cmp #'}' end of var?
beq .5
.4 jsr S.ExpandPStr.VC valid char ?
bcs .5 no, end here
sty S.ExpandPStr.End yes, save end
bra .1
.5 lda S.ExpandPStr.End get end
beq .1 empty {} or $/
phy save current index
jsr S.ExpandPStr.AV
ply restore index in string...
bra .10 reset start flag and continue
.6 sty S.ExpandPStr.End end of PSTR
lda S.ExpandPStr.Start are we in a var?
beq .7 no...exit...
jsr S.ExpandPStr.AV yes, expand and add to STR
.7 >LDYAI KrnBuffer256
jsr S.NewPStrYA
rts
*--------------------------------------
S.ExpandPStr.AV lda S.ExpandPStr.End
sec
sbc S.ExpandPStr.Start compute len of VAR End-Start+1
ldx KrnBuffer256
inx
sta KrnBuffer256,x
stx ZPQuickPtr2
lda /KrnBuffer256
sta ZPQuickPtr2+1
ldy S.ExpandPStr.Start
.1 iny
inx
lda (ZPQuickPtr3),y
sta KrnBuffer256,x
cpy S.ExpandPStr.End
bne .1
jsr S.CheckSysVarPtr2
bcs .10
>STYA ZPQuickPtr1
bra .11
.10 jsr S.FindVarPtr2
bcs .9
jsr S.NextEnvPtr1 Skip NAME
.11 ldy #0
ldx KrnBuffer256
.2 iny
lda (ZPQuickPtr1),y
inx
sta KrnBuffer256,x
tya
cmp (ZPQuickPtr1) last char?
bne .2
stx KrnBuffer256
.9 rts
*--------------------------------------
S.ExpandPStr.VC 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
*--------------------------------------
S.ExpandPStr.Start .BS 1
S.ExpandPStr.End .BS 1
*--------------------------------------
* S.PutEnvYA
*--------------------------------------
S.PutEnvYA >STYA ZPQuickPtr2 NAME=VALUE
lda (ZPQuickPtr2)
beq .9
sta KrnBuffer256
tay
.1 lda (ZPQuickPtr2),y
sta KrnBuffer256,y
dey
bne .1
ldy #0
.2 iny
cpy KrnBuffer256 last char ?
beq .9 no "=" found
lda KrnBuffer256,y
cmp #'='
bne .2
cpy #1 String like "=value" ?
beq .9
cpy KrnBuffer256 last char ?
beq .9 we have "VAR="
lda KrnBuffer256 save actual string len
sty KrnBuffer256 set length of VAR string
dec KrnBuffer256 ...without "="
.3 clc Substract VAR len+1 from whole len to get
sbc KrnBuffer256 VALUE len
sta KrnBuffer256,y save it at "=" POS
tya
clc
adc #KrnBuffer256
sta ZPQuickPtr3
lda /KrnBuffer256
sta ZPQuickPtr3+1
>LDYAI KrnBuffer256
>STYA ZPQuickPtr2
bra S.SetEnvPtr2Ptr3
.9 sec
rts
*--------------------------------------
* S.SetEnv
* In:
* PULLW = PTR To Name (PSTRING)
* PULLW = PTR To Value (PSTRING)
* Out:
*--------------------------------------
S.SetEnv >PULLW ZPQuickPtr2 NAME...
>PULLW ZPQuickPtr3 ...VALUE
S.SetEnvPtr2Ptr3
jsr S.UnsetEnvPtr2
jsr S.InitEnvPtr1 Y,A = ZPQuickPtr1 -> Env
lda ZPQuickPtr1 Compute ENV UPPER LIMIT in Ptr4
clc
adc #K.ENV.SIZE
sta ZPQuickPtr4
lda ZPQuickPtr1+1
adc /K.ENV.SIZE
sta ZPQuickPtr4+1
ldy ZPQuickPtr1+1
lda ZPQuickPtr1 Compute New Env Upper limit in A,Y
sec
adc (ZPQuickPtr2) add NAME len +1
bcc .1
iny
.1 sec
adc (ZPQuickPtr3) add VALUE len +1
bcc .2
iny
.2 cmp ZPQuickPtr4 GE than hMem Upper limit ?
tya
sbc ZPQuickPtr4+1
bcs .99
.3 lda (ZPQuickPtr1) Scan until endig 0...
beq .4
inc ZPQuickPtr1
bne .3
inc ZPQuickPtr1+1
bne .3
.4 lda (ZPQuickPtr2)
sta (ZPQuickPtr1)
tay
.5 lda (ZPQuickPtr2),y
sta (ZPQuickPtr1),y
dey
bne .5
jsr S.NextEnvPtr1
lda (ZPQuickPtr3)
sta (ZPQuickPtr1)
tay
.6 lda (ZPQuickPtr3),y
sta (ZPQuickPtr1),y
dey
bne .6
jsr S.NextEnvPtr1
.8 lda #0
sta (ZPQuickPtr1)
clc
rts
.99 lda #SYSMGR.ERRENVF
sec
rts
*--------------------------------------
* S.GetEnvYA
* In:
* Y,A = PTR to NAME (PSTRING)
* Out:
* CC : Y,A = PTR to VALUE (PSTRING)
* CS : not found
*--------------------------------------
S.GetEnvYA >STYA ZPQuickPtr2
jsr S.CheckSysVarPtr2
bcc .9
jsr S.FindVarPtr2
bcs .9
jsr S.NextEnvPtr1 Skip NAME
>LDYA ZPQuickPtr1
.9 rts
*--------------------------------------
* S.UnsetEnvYA
* In:
* YA = PTR To Name (PSTRING)
* Out:
*--------------------------------------
S.UnsetEnvYA >STYA ZPQuickPtr2 Store VAR Name
S.UnsetEnvPtr2 jsr S.FindVarPtr2
bcs .8 not found, quit
jsr S.DiscardVarPtr1 Ptr1 -> ENVNAME
.8 clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
* S.CheckSysVarPtr2
* In:
* ZPQuickPtr2 -> NAME
* Out:
* CC: Found
* YA -> VALUE
* CS: Not Found
*--------------------------------------
S.CheckSysVarPtr2
lda (ZPQuickPtr2)
cmp #1 is name 1 char?
bne .9
ldy #1
lda (ZPQuickPtr2),y
cmp #'0' $0...$9 ??
bcc .1 no,
cmp #'9'+1
bcs .99
and #$0F
jmp S.GetArgA
.1 cmp #'*' $* : All ARGS
bne .9
cmp #'#' $# : ARGC
bne .9
cmp #'?' $? : RC
bne .9
cmp #'$' $$ : PID
bne .9
.9 sec
.99 rts
*--------------------------------------
* S.FindVarPtr2
* In:
* ZPQuickPtr2 -> NAME
* Out:
* CC: Found
* ZPQuickPtr1 -> ENV.NAME
* ZPQuickPtr2 -> NAME
* CS: Not Found
* ZPQuickPtr1 -> PTR to Ending 0
* ZPQuickPtr2 -> NAME
*--------------------------------------
S.FindVarPtr2 jsr S.InitEnvPtr1 Store ENV
bcs .99
lda (ZPQuickPtr1)
beq .9 end of ENV
.1 cmp (ZPQuickPtr2) Same len as NAME?
bne .3
tay
.2 lda (ZPQuickPtr1),y
cmp (ZPQuickPtr2),y
bne .3
dey
bne .2
clc
rts
.3 jsr S.NextEnvPtr1 Skip NAME
jsr S.NextEnvPtr1 Skip VALUE
lda (ZPQuickPtr1)
bne .1
.9 sec
.99 rts
*--------------------------------------
* S.DiscardVar
* In:
* ZPQuickPtr1 -> ENV.NAME to Discard
*--------------------------------------
S.DiscardVarPtr1
lda ZPQuickPtr1 Discard current NAME & VALUE definition
sec ZPQuickPtr1 -> NAME
adc (ZPQuickPtr1) add NAME+1 to ZPQuickPtr1
sta ZPQuickPtr4 store it in ZPQuickPtr4
lda #0
adc ZPQuickPtr1+1
sta ZPQuickPtr4+1
lda ZPQuickPtr4 add VALUE+1 to ZPQuickPtr4
sec
adc (ZPQuickPtr4)
sta ZPQuickPtr4
bcc .1
inc ZPQuickPtr4+1
.1 ldy #0
.2 lda (ZPQuickPtr4),y Move back tail...
sta (ZPQuickPtr1),y
beq .8 ...until we move ending 0
iny
bne .2
inc ZPQuickPtr1+1
inc ZPQuickPtr4+1
bra .2
.8 rts
*--------------------------------------
S.InitEnvPtr1 ldy #S.PS.hENV
lda (pPs),y
jsr S.GetMemPtrA
>STYA ZPQuickPtr1 Store ENV
rts
*--------------------------------------
S.NextEnvPtr1 lda ZPQuickPtr1
sec
adc (ZPQuickPtr1)
sta ZPQuickPtr1
bcc .8
inc ZPQuickPtr1+1
.8 rts
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.ENV
LOAD SYS/KERNEL.S
ASM