A2osX/BIN/XARGS.S.txt

267 lines
4.9 KiB
Plaintext
Raw Normal View History

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/xargs
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/kernel.i
.INB inc/mli.i
.INB inc/mli.e.i
*--------------------------------------
.DUMMY
.OR ZPBIN
2021-06-20 22:29:06 +00:00
ZS.START
ArgIndex .BS 1
ArgPattern .BS 1
ZPPtr1 .BS 2
ZPCommandPtr .BS 2
ZPBufPtr .BS 2
ZPCmdBuf .BS 2
hFile .BS 1
hBuf .BS 1
hCmdBuf .BS 1
DashArgs .BS 1
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0 S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data Segment Size
.DA #16 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
2021-06-20 22:29:06 +00:00
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.CRLF .DA MSG.CRLF
L.CMD.SPC .DA CMD.SPC
.DA 0
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.INIT clc
rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.RUN jsr CS.RUN.CheckArgs
bcs CS.RUN.LOOP.RTS
2021-06-20 22:29:06 +00:00
CS.RUN.LOOP >SLEEP
2021-06-20 22:29:06 +00:00
>PUSHB hFile
>PUSHW ZPBufPtr
>PUSHWI 256
>SYSCALL FGetS
bcs .9
2021-06-20 22:29:06 +00:00
.2 jsr CS.RUN.EXEC
2021-06-20 22:29:06 +00:00
bcc CS.RUN.LOOP
rts
2021-06-20 22:29:06 +00:00
.9 cmp #MLI.E.EOF
bne .99
2021-06-20 22:29:06 +00:00
lda #0 Exit with no Error
2021-06-20 22:29:06 +00:00
.99 sec
CS.RUN.LOOP.RTS rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.RUN.CheckArgs
jsr CS.RUN.NextArg
bcs .4
lda (ZPPtr1)
cmp #'-'
beq .1
lda ArgPattern
bne .11
lda ArgIndex
sta ArgPattern
>LDYA ZPPtr1
>STYA ZPCommandPtr
bra CS.RUN.CheckArgs
.11 lda hFile
bne .97
>LDYA ZPPtr1
jsr CS.RUN.OPEN
bcs .9
sta hFile
bra CS.RUN.CheckArgs
*--------------------------------------
.1 ldy #1
lda (ZPPtr1),y
ldx #OptionList.Cnt-1
.2 cmp OptionList,x
beq .3
dex
bpl .2
bra .97
.3 txa
lsr
beq .98
tax
lda #$80
sta DashArgs-1,x
bra CS.RUN.CheckArgs
*--------------------------------------
.4 lda hFile
bne .80
ldy #S.PS.hStdIn
lda (pPS),y
2023-10-18 05:41:12 +00:00
tay
ldx FILEs.hFD-1,y
lda FDs.pLO-1,x
sta ZPPtr1
lda FDs.pHI-1,x
sta ZPPtr1+1
lda (ZPPtr1)
cmp #S.FD.T.PIPE
bne .97
2023-10-18 05:41:12 +00:00
sty hFile
2021-06-20 22:29:06 +00:00
.80 >LDYAI 256
>SYSCALL GetMem
bcs .9
2021-06-20 22:29:06 +00:00
>STYA ZPBufPtr
stx hBuf
2021-06-20 22:29:06 +00:00
>LDYAI 256
>SYSCALL GetMem
bcs .9
2021-06-20 22:29:06 +00:00
>STYA ZPCmdBuf
stx hCmdBuf
2021-06-20 22:29:06 +00:00
* clc
2021-06-20 22:29:06 +00:00
.9 rts
2021-06-20 22:29:06 +00:00
.97 lda #E.SYN
2021-06-20 22:29:06 +00:00
.98 pha
>LDYA L.MSG.USAGE
>SYSCALL PutS
pla
sec
rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.RUN.NextArg inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs .9
2021-06-20 22:29:06 +00:00
>STYA ZPPtr1
2021-06-20 22:29:06 +00:00
.9 rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.RUN.OPEN >PUSHYA
>PUSHBI O.RDONLY+O.TEXT
>PUSHBI S.FI.T.TXT
>PUSHWZ Aux type
>SYSCALL FOpen
bcs .9
2021-06-20 22:29:06 +00:00
sta hFile
2021-06-20 22:29:06 +00:00
.9 rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.RUN.EXEC >PUSHW ZPCmdBuf
>PUSHW ZPCommandPtr
>SYSCALL StrCpy
>PUSHW ZPCmdBuf
>PUSHW L.CMD.SPC
>SYSCALL StrCat
>PUSHW ZPCmdBuf
>LDYA ZPBufPtr
>PUSHYA
>SYSCALL StrCat
* >LDYA ZPCmdBuf
* >SYSCALL PutS
>PUSHW ZPCmdBuf
>PUSHBI S.PS.F.HOLD
>SYSCALL ExecL
bcs .9
>SLEEP
ldy #S.PS.RC
lda (pPS),y
beq .9
sec
.9 rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.QUIT lda hFile
beq .1
>SYSCALL FClose
2021-06-20 22:29:06 +00:00
.1 lda hBuf
beq .2
>SYSCALL FreeMem
2021-06-20 22:29:06 +00:00
.2 lda hCmdBuf
beq .8
2021-06-20 22:29:06 +00:00
>SYSCALL FreeMem
2021-06-20 22:29:06 +00:00
.8 clc
rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.DOEVENT sec
rts
2021-06-20 22:29:06 +00:00
*--------------------------------------
CS.END
*--------------------------------------
OptionList .AS "Hh"
OptionList.Cnt .EQ *-OptionList
2021-06-20 22:29:06 +00:00
*--------------------------------------
MSG.USAGE .CS "Usage : XARGS command <file>\r\n"
.CS " or : CMD|XARGS command"
MSG.CRLF .CZ "\r\n"
CMD.SPC .CZ " "
2021-06-20 22:29:06 +00:00
*--------------------------------------
.DUMMY
.OR 0
2021-06-20 22:29:06 +00:00
DS.START
DS.END .ED
2021-06-20 22:29:06 +00:00
*--------------------------------------
MAN
SAVE usr/src/bin/xargs.s
ASM