A2osX/SYS/KERNEL.S.ENV.txt
2015-03-15 23:00:40 +01:00

386 lines
8.2 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.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
*--------------------------------------
* S.ExpandPStr
* In:
* PULLW = PSTR to String to Expand (PSTRING)
* Out:
* A = hMem to Expanded String (PSTRING)
*--------------------------------------
* S.ExpandPStrA
* In:
* A = hMem of String to Expand (PSTRING)
* Out:
* A = hMem to Expanded String (PSTRING)
*--------------------------------------
S.ExpandPStr >PULLW R.AX
bra S.ExpandPStr2
S.ExpandPStrA jsr S.GetMemPtrA
>STYA R.AX
S.ExpandPStr2 stz TmpBuffer256 init Expanded String len=0
stz R.BL reset "in var"
ldy #0
.1 iny
lda (R.AX),y
cmp #'%'
beq .10
jmp .7
.10 ldx R.BL in var?
bne .2
sty R.BL no, save start
jmp .8 skip this char
.2 sty R.BH yes, save end
phy save Actual char position
tya
sec
sbc R.BL compute len of %VAR% -1
tay
lda #0
>PUSHYA
>PUSHBI 0
jsr S.GetMem create VARNAME
phx save hMem for discard
>STYA R.CX
lda R.BH
sec
sbc R.BL
dec skip %
sta (R.CX)
ldy R.BL
iny
.3 inc R.CL
bne .4
inc R.CH
.4 lda (R.AX),y Copy string between % to ENVNAME
sta (R.CX)
iny
cpy R.BH
bne .3
pla
pha Get back ENVNAME hMem
>PUSHA
ldy #S.PS.hENV
lda (TSKMGR.TSKPTR),y
>PUSHA
jsr S.GetEnvVarH
bcs .5
pha save hMem of VALUE
jsr S.GetMemPtrA
>STYA R.DX
ldy #0
.41 iny
lda (R.DX),y
inc TmpBuffer256
ldx TmpBuffer256
sta TmpBuffer256,x
tya
cmp (R.DX)
bne .41
pla
jsr S.FreeMemA discard VALUE hMem
.5 pla
jsr S.FreeMemA discard VARNAME hMem
* ldy R.BL TODO:continue scanning from first % found
stz R.BL reset "in var"
ply
bra .8
.7 ldx R.BL in var?
bne .8 yes, skip this char
inc TmpBuffer256
ldx TmpBuffer256
sta TmpBuffer256,x
.8 tya
cmp (R.AX) last char?
beq .81
jmp .1
.81 >PUSHWI TmpBuffer256
jsr S.NewPStr
rts
*--------------------------------------
* S.CreateEnv
* in :
* out :
* A = hMem to new env
*--------------------------------------
S.CreateEnv >PUSHWI K.ENV.SIZE get a buffer for ENV
>PUSHBI 0
jsr S.GetMem create it...
bcs .9
>STYA ZPQuickPtr1
lda #0
sta (ZPQuickPtr1)
txa
clc
.9 rts
*--------------------------------------
* S.DupEnvA2
* In:
* A = ENV hMem To Duplicate
* Out:
* A = hMem to new ENV
*--------------------------------------
S.DupEnvA pha
jsr S.GetMemPtrA
>STYA ZPQuickPtr1
pla
jsr S.GetMemLenA
>PUSHYA
>PUSHBI 0
jsr S.GetMem
bcs .9
>STYA ZPQuickPtr2
phx
.1 lda (ZPQuickPtr1)
sta (ZPQuickPtr2)
beq .8
inc ZPQuickPtr1
bne .2
inc ZPQuickPtr1+1
.2 inc ZPQuickPtr2
bne .1
inc ZPQuickPtr2+1
bra .1
.8 pla
clc
.9 rts
*--------------------------------------
* S.GetEnvVarH
* In:
* PULLB = hENV
* PULLB = hMem to NAME (PSTRING)
*--------------------------------------
* S.GetEnvVarP
* In:
* PULLB = hENV
* PULLW = PTR to NAME (PSTRING)
* Out:
* A = hMem to VALUE (PSTRING) 0,"" if not exist
*--------------------------------------
S.GetEnvVarH jsr S.SelectEnvH
bra S.GetEnvVar
S.GetEnvVarP jsr S.SelectEnvP
S.GetEnvVar bcc .1
>LDYAI 1 not found
>PUSHYA create "" PSTR
>PUSHBI 0
jsr S.GetMem create a new PSTR
bcs .99
>STYA ZPQuickPtr3
lda #0
sta (ZPQuickPtr3) set len of PSTR
txa
clc
rts
.1 lda (ZPQuickPtr1) get NAME=VALUE len
sec
sbc (ZPQuickPtr2) substract (NAME len)
tay y=len("=VALUE")
lda #0
>PUSHYA
>PUSHBI 0
jsr S.GetMem create a new PSTR
bcs .99
>STYA ZPQuickPtr3
phx save hMem
lda (ZPQuickPtr1) get NAME=VALUE len
clc
sbc (ZPQuickPtr2) compute VALUE len
sta (ZPQuickPtr3) set new PSTR Len
tax x = chr to copy
lda (ZPQuickPtr2) get name len
inc add 1 to skip "="
tay
.2 iny
inc ZPQuickPtr3
bne .3
inc ZPQuickPtr3+1
.3 lda (ZPQuickPtr1),y
sta (ZPQuickPtr3)
dex
bne .2
pla get back PSTR hMem
clc
.99 rts
*--------------------------------------
* S.SetEnvVarH
* In:
* PULLB = hENV
* PULLB = hMem To Name (PSTRING)
* PULLB = hMem To Value (PSTRING)
*--------------------------------------
* S.SetEnvVarP
* In:
* PULLB = hENV
* PULLW = PTR To Name (PSTRING)
* PULLW = PTR To Value (PSTRING)
* Out:
*--------------------------------------
S.SetEnvVarH jsr S.SelectEnvH
php
>PULLA
jsr S.GetMemPtrA
>STYA ZPQuickPtr3 ZPQuickPtr3 = VALUE
bra S.SetEnvVar
S.SetEnvVarP jsr S.SelectEnvP
php
>PULLW ZPQuickPtr3 ZPQuickPtr3 = VALUE
S.SetEnvVar plp
bcs .3 Not Found,ZPQuickPtr1 -> End Of Env
lda (ZPQuickPtr1) Found, Discard current NAME definition
sec
adc ZPQuickPtr1 add NAME=VALUE len+1 to ZPQuickPtr1
sta ZPQuickPtr4
lda #0
adc ZPQuickPtr1+1 store it in ZPQuickPtr4
sta ZPQuickPtr4+1
.1 lda (ZPQuickPtr4)
sta (ZPQuickPtr1)
beq .3 until we move ending 0
inc ZPQuickPtr1
bne .2
inc ZPQuickPtr1+1
.2 inc ZPQuickPtr4
bne .1
inc ZPQuickPtr4+1
bra .1
.3 lda ZPQuickPtr1 Compute ENV UPPER LIMIT
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(for len)
bcc .4
iny
.4 sec
adc (ZPQuickPtr3) add VALUE len +1(for "=")
bcc .5
iny
.5 sec A,Y=new upper limit
sbc ZPQuickPtr4 greater than hMem Upper limit ?
bcc .51
tya
sbc ZPQuickPtr4+1
bcs .99
.51 lda (ZPQuickPtr2) make len = NAME+VALUE+1
sec
adc (ZPQuickPtr3)
sta (ZPQuickPtr1)
inc ZPQuickPtr1
bne .6
inc ZPQuickPtr1+1
.6 ldy #0
.7 iny
lda (ZPQuickPtr2),y
sta (ZPQuickPtr1)
inc ZPQuickPtr1
bne .8
inc ZPQuickPtr1+1
.8 tya
cmp (ZPQuickPtr2)
bne .7
lda #'='
sta (ZPQuickPtr1)
inc ZPQuickPtr1
bne .9
inc ZPQuickPtr1+1
.9 ldy #0
.10 iny
lda (ZPQuickPtr3),y
sta (ZPQuickPtr1)
inc ZPQuickPtr1
bne .11
inc ZPQuickPtr1+1
.11 tya
cmp (ZPQuickPtr3)
bne .10
lda #0
sta (ZPQuickPtr1)
clc
rts
.99 lda #SYSMGR.ERRENVF
sec
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
* S.SelectEnvH
* In:
* PULLB = hENV
* PULLB = hMem to NAME (PSTRING)
*--------------------------------------
* S.SelectEnvP
* In:
* PULLB = hENV
* PULLW = PTR to NAME (PSTRING)
*--------------------------------------
* Out:
* CC: Found
* ZPQuickPtr1 -> NAME=VALUE
* ZPQuickPtr2 -> NAME
* CS: Not Found
* ZPQuickPtr1 -> PTR to Ending 0
* ZPQuickPtr2 -> NAME
*--------------------------------------
S.SelectEnvH >PULLA get ENV
jsr S.GetMemPtrA
>STYA ZPQuickPtr1 Store ENV
>PULLA get NAME
jsr S.GetMemPtrA
>STYA ZPQuickPtr2 Store VAR Name
bra S.SelectEnv
S.SelectEnvP >PULLA get ENV
jsr S.GetMemPtrA
>STYA ZPQuickPtr1 Store ENV
>PULLW ZPQuickPtr2 get NAME
S.SelectEnv
.1 lda (ZPQuickPtr1)
beq .9
ldy #0
.2 iny
lda (ZPQuickPtr1),y
cmp #'=' End Of VAR Name ?
beq .4
.3 cmp (ZPQuickPtr2),y
bne .7
tya
cmp (ZPQuickPtr2)
bne .2
iny
lda (ZPQuickPtr1),y
cmp #'=' End Of VAR Name ?
bne .3
.4 dey
tya
cmp (ZPQuickPtr2) Y = VAR Name Len ?
beq .8 yes, found VAR
.7 lda (ZPQuickPtr1) no, go to next NAME=VALUE
sec
adc ZPQuickPtr1
sta ZPQuickPtr1
bcc .1
inc ZPQuickPtr1+1
bra .1
.8 clc
rts
.9 sec
rts
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.ENV
LOAD SYS/KERNEL.S
ASM