A2osX/SYS/KERNEL.S.ARG.txt
2018-10-23 17:36:57 +02:00

121 lines
2.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.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
*/--------------------------------------
* # Args2ArgV
* int args2argv(char* args, char* argv[])
* ## ASM
* `>PUSHW argv`
* `>LDYA args`
* `>SYSCALL Args2ArgV
* ## RETURN VALUE
*\--------------------------------------
ARG.bInQuote .BS 1
*--------------------------------------
K.Args2ArgV >DEBUG
jsr MEM.SPtr1PPtr2
ldx #0 Arg Count
stz ARG.bInQuote
.1 jsr ARG.GetCharPtr1
beq .8
cmp #C.SPACE
beq .1 skip leading spaces
.2 cmp #'"' found a quote ?
bne .3
lda ARG.bInQuote
eor #$ff
sta ARG.bInQuote
bra .7 skip quote and check next char
.3 cmp #C.SPACE
bne .6 regular char ...store...
bit ARG.bInQuote
bmi .6 between quotes... store space...
inx Found one arg !!!
lda #0 set this token End
jsr ARG.PutCharPtr2
bra .1
.6 jsr ARG.PutCharPtr2
.7 jsr ARG.GetCharPtr1
bne .2
inx
.8 jsr ARG.PutCharPtr2 set Argv[x] Ending 0
sta (ZPPtr2) set Array Ending 0
txa X=Arg Count
clc
.9 rts
*/--------------------------------------
* # ArgV
* ## ASM
* **In:**
* A = argument index.
* ## RETURN VALUE
* CC : success
* Y,A = PTR To Arg[A]
* CS : Out Of Bound
*\--------------------------------------
K.ArgV tax save requested arg#
ldy #S.PS.hARGV
lda (pPs),y
jsr K.GetMemPtr
>STYA ZPPtr1
.1 lda (ZPPtr1) end of ARGV[] ?
beq .9 yes, not found....
dex
bmi .7
.3 jsr ARG.GetCharPtr1 skip str
bne .3
jsr ARG.NextCharPtr1 skip \0
bra .1
.7 >LDYA ZPPtr1
.8 clc
rts
.9 sec
rts
*--------------------------------------
ARG.GetCharPtr1 lda (ZPPtr1)
beq ARG.GetCharPtr1.8
ARG.NextCharPtr1
inc ZPPtr1
bne ARG.GetCharPtr1.8
inc ZPPtr1+1 never Z
ARG.GetCharPtr1.8
rts
*--------------------------------------
ARG.PutCharPtr2 sta (ZPPtr2)
inc ZPPtr2
bne .8
inc ZPPtr2+1
.8 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.ARG
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM