A2osX/SYS/KERNEL.S.STRV.txt

336 lines
5.1 KiB
Plaintext
Raw Normal View History

2020-01-24 14:21:08 +00:00
NEW
AUTO 3,1
*/--------------------------------------
2020-01-30 14:59:40 +00:00
* # StrVShift
* ## ASM
* `>PUSHB hSTRV`
* `>PUSHB index`
* `>SYSCALL StrVShift`
2020-01-24 14:21:08 +00:00
* ## RETURN VALUE
*\--------------------------------------
2020-02-02 18:24:40 +00:00
K.StrVShift sta CLRREADAUX
>PULLA index
2020-01-30 14:59:40 +00:00
eor #$ff
tax
>PULLA
2020-02-02 18:24:40 +00:00
sta SETREADAUX
jsr K.GetMemPtr
2020-01-30 14:59:40 +00:00
>STYA ZPPtr1 strV
.1 inx
beq .2
jsr STRV.NStrPtr1
bcc .1
rts
.2 >LDYA ZPPtr1
>STYA ZPPtr2
jsr STRV.NStrPtr1
jsr STRV.Ptr1Ptr2cpy
clc
rts
2020-01-24 14:21:08 +00:00
*/--------------------------------------
* # StrVGet
2020-01-28 16:42:51 +00:00
* ## ASM
* `>PUSHB hSTRV`
2020-01-30 14:59:40 +00:00
* `>PUSHB index`
* `>PUSHW ptr`
2020-01-28 16:42:51 +00:00
* `>SYSCALL StrVGet`
2020-01-24 14:21:08 +00:00
* ## RETURN VALUE
2020-01-28 16:42:51 +00:00
* CC: Y,A = Ptr
* CS: Y,A = NULL
2020-01-24 14:21:08 +00:00
*\--------------------------------------
2020-02-02 18:24:40 +00:00
K.StrVGet sta CLRREADAUX
>PULLW FORPNT ptr
2020-01-30 14:59:40 +00:00
>PULLA index
2020-01-28 16:42:51 +00:00
eor #$ff
2020-01-30 14:59:40 +00:00
tax
2020-01-28 16:42:51 +00:00
>PULLA
2020-02-02 18:24:40 +00:00
sta SETREADAUX
2020-02-02 14:58:01 +00:00
jsr K.GetMemPtr
2020-01-28 16:42:51 +00:00
>STYA ZPPtr1 strV
2020-01-30 14:59:40 +00:00
.1 inx
beq .2
2020-01-28 16:42:51 +00:00
2020-01-30 14:59:40 +00:00
jsr STRV.NStrPtr1
2020-01-28 16:42:51 +00:00
bcc .1
2020-01-30 14:59:40 +00:00
rts
2020-01-28 16:42:51 +00:00
2020-01-30 14:59:40 +00:00
.2 lda (ZPPtr1)
2020-01-28 16:42:51 +00:00
tay
2020-02-02 14:58:01 +00:00
bne .3
2020-01-30 14:59:40 +00:00
sec
2020-02-02 14:58:01 +00:00
rts Y,A = 0
2020-01-30 14:59:40 +00:00
2020-02-02 14:58:01 +00:00
.3 lda FORPNT+1
2020-01-30 14:59:40 +00:00
beq .8
2020-01-28 16:42:51 +00:00
2020-01-30 14:59:40 +00:00
.4 ldy #$ff
.5 iny
lda (ZPPtr1),y
2020-02-02 18:24:40 +00:00
jsr SHARED.FORPNT.PutY
2020-01-30 14:59:40 +00:00
bne .5
2020-02-02 14:58:01 +00:00
>LDYA FORPNT
2020-01-28 16:42:51 +00:00
clc
rts
2020-01-30 14:59:40 +00:00
.8 >LDYA ZPPtr1
clc
.9 rts
2020-01-28 16:42:51 +00:00
*/--------------------------------------
* # StrVAdd
* ## ASM
* `>PUSHB hSTRV`
* `>PUSHW str`
* `>SYSCALL StrVAdd`
* ## RETURN VALUE
2020-01-30 14:59:40 +00:00
* CC : str added to hSTRV
* CS : hSTRV full
2020-01-28 16:42:51 +00:00
*\--------------------------------------
2020-02-02 18:24:40 +00:00
K.StrVAdd sta CLRREADAUX
>PULLW TXTPTR str
2020-01-30 14:59:40 +00:00
>PULLA
2020-02-02 18:24:40 +00:00
sta SETREADAUX
jsr K.GetMemPtr
2020-01-30 14:59:40 +00:00
>STYA ZPPtr1
2020-02-02 18:24:40 +00:00
lda TXTPTR+1
bne .10
sta (ZPPtr1)
clc
rts
2020-01-30 14:59:40 +00:00
2020-02-02 18:24:40 +00:00
.10 lda #1 for \0
2020-01-30 14:59:40 +00:00
sta ZPPtr2
stz ZPPtr2+1
.1 jsr STRV.NStrPtr1
bcs .2
2020-02-02 14:58:01 +00:00
jsr SHARED.AddYp1ToPtr2
2020-01-30 14:59:40 +00:00
bra .1
.2 ldy #$ff
.3 iny
2020-02-02 18:24:40 +00:00
jsr SHARED.TXTPTR.GetY
2020-01-30 14:59:40 +00:00
bne .3
tya
sec
adc ZPPtr2
bcc .4
inc ZPPtr2+1
ldy #S.MEM.LEN
lda (ZPMemMgrSPtr),y
cmp ZPPtr2
iny
lda (ZPMemMgrSPtr),y
sbc ZPPtr2+1
bcs .4
lda #E.OOM
sec
rts
.4 ldy #$ff
.5 iny
2020-02-02 18:24:40 +00:00
jsr SHARED.TXTPTR.GetY
2020-01-30 14:59:40 +00:00
sta (ZPPtr1),y
bne .5
iny
2020-02-02 14:58:01 +00:00
sta (ZPPtr1),y StrV Ending \0
2020-01-30 14:59:40 +00:00
clc
rts
2020-01-24 14:21:08 +00:00
*/--------------------------------------
* # StrVDup
2020-01-30 14:59:40 +00:00
* ## ASM
2020-01-24 14:21:08 +00:00
* Y,A = Src StrV
* ## RETURN VALUE
* X = hMem of new StrV
* A = Str Count
*\--------------------------------------
K.StrVDup >STYA ZPPtr1
>STYA ZPPtr2
ldy #0
ldx #0
.1 lda (ZPPtr2),y
beq .2
.11 iny
bne .1
inx
inc ZPPtr2+1
bra .1
.2 iny
bne .3
inx
inc ZPPtr2+1
.3 lda (ZPPtr2),y
bne .11
txa
jsr K.getmem
bcs .9
>STYA ZPPtr2
phx
2020-01-30 14:59:40 +00:00
jsr STRV.Ptr1Ptr2cpy
2020-01-24 14:21:08 +00:00
2020-01-30 14:59:40 +00:00
txa Count
2020-01-24 14:21:08 +00:00
plx hMem
clc
.9 rts
*/--------------------------------------
* # Str2StrV
2020-01-28 16:42:51 +00:00
* Expand String and convert to StrV List
2020-01-24 14:21:08 +00:00
* ## C
* short int str2strv(char* args, char* argv[])
* ## ASM
* `>PUSHW argv`
* `>LDYA args`
* `>SYSCALL Str2StrV`
* ## RETURN VALUE
* A = Arg count
*\--------------------------------------
K.Str2StrV jsr K.Expand
bcs .9
>STYA ZPPtr1
stx .80+1
>PULLW ZPPtr2 Get target buffer
ldx #0 Arg Count
2020-01-28 16:42:51 +00:00
ldy #0 bInQuote
2020-01-24 14:21:08 +00:00
.1 jsr SHARED.GetCharPtr1
beq .8
2020-01-28 16:42:51 +00:00
2020-01-24 14:21:08 +00:00
cmp #C.SPACE
beq .1 skip leading spaces
2020-01-28 16:42:51 +00:00
2020-01-24 14:21:08 +00:00
.2 cmp #'"' found a quote ?
bne .3
2020-01-28 16:42:51 +00:00
tya
2020-01-24 14:21:08 +00:00
eor #$ff
2020-01-28 16:42:51 +00:00
tay
2020-01-24 14:21:08 +00:00
bra .7 skip quote and check next char
2020-01-28 16:42:51 +00:00
2020-01-24 14:21:08 +00:00
.3 cmp #C.SPACE
bne .6 regular char ...store...
2020-01-28 16:42:51 +00:00
tya
2020-01-29 16:46:51 +00:00
bmi .4 between quotes... store space...
2020-01-24 14:21:08 +00:00
inx Found one arg !!!
lda #0 set this token End
jsr SHARED.PutCharPtr2
bra .1
2020-01-29 16:46:51 +00:00
.4 lda #C.SPACE
2020-01-24 14:21:08 +00:00
.6 jsr SHARED.PutCharPtr2
.7 jsr SHARED.GetCharPtr1
bne .2
2020-01-29 16:46:51 +00:00
2020-01-24 14:21:08 +00:00
inx
2020-01-29 16:46:51 +00:00
2020-01-24 14:21:08 +00:00
.8 jsr SHARED.PutCharPtr2 set Argv[x] Ending 0
sta (ZPPtr2) set Array Ending 0
phx
.80 lda #$FF SELF MODIFIED
jsr K.FreeMem Discard expanded string
pla get back Arg Count
* clc
rts
.9 >RET 2 Discard target buffer
*--------------------------------------
2020-01-28 16:42:51 +00:00
STRV.NStrPtr1 ldy #$ff
.1 iny
lda (ZPPtr1)
beq .2
inc ZPPtr1
bne .1
inc ZPPtr1+1
bra .1
.2 tya
beq .9
inc ZPPtr1
bne .8
inc ZPPtr1+1 skip \0
.8 clc
rts
2020-01-30 14:59:40 +00:00
.9 sec Y,A = 0
rts
*--------------------------------------
STRV.Ptr1Ptr2cpy
ldx #0
ldy #0
.4 lda (ZPPtr1),y
sta (ZPPtr2),y
beq .6
.5 iny
bne .4
inc ZPPtr1+1
inc ZPPtr2+1
bra .4
.6 inx
iny
bne .7
inc ZPPtr1+1
inc ZPPtr2+1
.7 lda (ZPPtr1),y
sta (ZPPtr2),y Ending \0 ?
bne .5
2020-01-28 16:42:51 +00:00
rts
*--------------------------------------
2020-01-24 14:21:08 +00:00
MAN
SAVE USR/SRC/SYS/KERNEL.S.STRV
LOAD USR/SRC/SYS/KERNEL.S
ASM