A2osX/BIN/CUT.S.txt

328 lines
5.3 KiB
Plaintext
Raw Normal View History

2019-03-12 14:41:55 +00:00
NEW
2019-07-26 14:23:07 +00:00
AUTO 3,1
2019-03-12 14:41:55 +00:00
.LIST OFF
.OP 65C02
.OR $2000
2020-03-03 16:44:52 +00:00
.TF bin/cut
2019-03-12 14:41:55 +00:00
*--------------------------------------
2020-05-25 21:03:11 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/kernel.i
.INB inc/mli.i
.INB inc/mli.e.i
2019-03-12 14:41:55 +00:00
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
2020-08-17 20:47:31 +00:00
ZPPtr1 .BS 2
ZPBuf .BS 2
2019-03-12 14:41:55 +00:00
ZPBufPtr .BS 2
ArgIndex .BS 1
ArgFile .BS 1
2019-03-12 14:41:55 +00:00
OptionIdx .BS 1
hBuf .BS 1
FieldNum .BS 1
StartChar .BS 1
EndChar .BS 1
2019-03-13 11:37:05 +00:00
Separator .BS 1
2019-10-26 14:33:37 +00:00
hToClose .BS 1
ZS.END .ED
2019-03-12 14:41:55 +00:00
*--------------------------------------
* 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 SegmentSize
2019-10-19 20:54:59 +00:00
.DA #32 Stack Size
2019-03-12 14:41:55 +00:00
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
2019-03-12 14:41:55 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
2019-03-12 14:41:55 +00:00
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.CRLF .DA MSG.CRLF
.DA 0
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
2019-10-31 10:30:27 +00:00
CS.RUN lda #C.SPACE
2019-03-13 11:37:05 +00:00
sta Separator
2019-10-19 18:35:30 +00:00
2019-03-13 11:37:05 +00:00
.10 jsr CS.RUN.NextArg
2019-03-12 14:41:55 +00:00
bcs .8
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
lda (ZPPtr1)
cmp #'-'
beq .1
2019-10-19 18:35:30 +00:00
lda ArgIndex
sta ArgFile
2019-03-12 14:41:55 +00:00
bra .10
2019-10-19 18:35:30 +00:00
.1 ldy #1
2019-03-12 14:41:55 +00:00
lda (ZPPtr1),y
2019-10-19 18:35:30 +00:00
ldx #OptionList.Cnt-1
2019-03-12 14:41:55 +00:00
.2 cmp OptionList,x
beq .3
2019-03-12 14:41:55 +00:00
dex
2019-10-19 18:35:30 +00:00
bpl .2
.97 lda #E.SYN
.98 pha
>LDYA L.MSG.USAGE
>SYSCALL PutS
pla
sec
.9 rts
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
.3 txa
lsr
2019-03-13 11:37:05 +00:00
beq .98 -H
2019-10-19 18:35:30 +00:00
2019-03-13 11:37:05 +00:00
cmp #4 -S
bne .4
2019-10-19 18:35:30 +00:00
2019-03-13 11:37:05 +00:00
jsr CS.RUN.NextArg
bcs .97
2019-03-13 11:37:05 +00:00
lda (ZPPtr1)
sta Separator
bra .10
2019-10-19 18:35:30 +00:00
2019-03-13 11:37:05 +00:00
.4 sta OptionIdx
jsr CS.RUN.NextArg
2019-03-12 14:41:55 +00:00
bcs .97
2020-05-25 21:03:11 +00:00
2020-08-17 20:47:31 +00:00
>SYSCALL AToI
2019-03-12 14:41:55 +00:00
bcs .97
tax
bne .97
2020-05-25 21:03:11 +00:00
2019-03-12 14:41:55 +00:00
tya
ldx OptionIdx
sta FieldNum-1,x
bra .10 scan for any other args
2019-03-12 14:41:55 +00:00
.8 >LDYAI 256
>SYSCALL GetMem
bcs .9
2020-05-25 21:03:11 +00:00
>STYA ZPBuf
2019-03-12 14:41:55 +00:00
>STYA ZPBufPtr
stx hBuf
lda ArgFile
2019-03-12 14:41:55 +00:00
beq .80
2019-10-19 18:35:30 +00:00
2021-05-04 17:31:21 +00:00
>PUSHW ZPBufPtr
2019-03-12 14:41:55 +00:00
>SYSCALL ArgV
>PUSHYA
2020-08-17 20:47:31 +00:00
>SYSCALL StrCpy
2021-05-04 17:31:21 +00:00
2019-10-19 18:35:30 +00:00
jsr CS.RUN.OUT
bcs .9
2019-10-19 18:35:30 +00:00
lda #0 Exit with no Error
sec
rts
2019-03-12 14:41:55 +00:00
.80 ldy #S.PS.hStdIn
lda (pPS),y
tax
2021-07-24 20:42:23 +00:00
lda hFDs-1,x
2019-03-12 14:41:55 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1
2020-12-15 13:23:22 +00:00
2019-03-12 14:41:55 +00:00
lda (ZPPtr1)
cmp #S.FD.T.PIPE
bne CS.RUN.LOOP
2019-10-26 14:33:37 +00:00
ldy #S.PS.hStdIn
lda (pPS),y
sta hToClose
2019-10-19 18:35:30 +00:00
*--------------------------------------
CS.RUN.LOOP >SLEEP
2019-03-12 14:41:55 +00:00
ldy #S.PS.hStdIn
lda (pPS),y
2020-12-23 14:54:57 +00:00
>PUSHA
>LDYA ZPBuf
>STYA ZPBufPtr
>PUSHYA
>PUSHWI 255
2020-08-17 20:47:31 +00:00
>SYSCALL FGetS
2019-10-19 18:35:30 +00:00
bcs .8
lda (ZPBufPtr)
beq CS.RUN.LOOP
2019-10-19 18:35:30 +00:00
jsr CS.RUN.OUT
2019-10-26 14:33:37 +00:00
bcc CS.RUN.LOOP
2019-10-19 18:35:30 +00:00
.8 cmp #MLI.E.EOF
bne .90
2019-10-19 18:35:30 +00:00
lda #0
.90 sec
.9 rts
2019-10-19 18:35:30 +00:00
*--------------------------------------
CS.RUN.OUT ldx FieldNum
2019-03-12 14:41:55 +00:00
beq CS.RUN.OUT.MN
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
ldy #$ff
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
.1 iny skip spaces
lda (ZPBufPtr),y
beq CS.RUN.PRINTCR
2019-10-19 18:35:30 +00:00
2019-03-13 11:37:05 +00:00
cmp Separator
2019-03-12 14:41:55 +00:00
beq .1
2019-10-19 18:35:30 +00:00
dex
2019-03-12 14:41:55 +00:00
beq .4
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
.2 iny skip token
lda (ZPBufPtr),y
beq CS.RUN.PRINTCR
2019-10-03 06:25:27 +00:00
2019-03-13 11:37:05 +00:00
eor Separator
2019-03-12 14:41:55 +00:00
bne .2
bra .1
.4 jsr CS.RUN.AddYToBufPtr
ldy #$ff
.6 iny
lda (ZPBufPtr),y
beq .8
2019-10-26 14:33:37 +00:00
2019-03-13 11:37:05 +00:00
eor Separator
2019-03-12 14:41:55 +00:00
bne .6
2019-10-26 14:33:37 +00:00
2019-03-12 14:41:55 +00:00
sta (ZPBufPtr),y
.8 >LDYA ZPBufPtr
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
rts
*--------------------------------------
2020-01-29 21:45:06 +00:00
CS.RUN.PRINTCR >PUSHW L.MSG.CRLF
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-10-19 18:35:30 +00:00
rts
2019-03-12 14:41:55 +00:00
*--------------------------------------
CS.RUN.OUT.MN ldy #0
2019-03-12 14:41:55 +00:00
ldx StartChar
beq .2
2019-10-19 18:35:30 +00:00
2019-12-16 13:14:11 +00:00
.1 dex
beq .2
2019-12-16 13:14:11 +00:00
lda (ZPBufPtr),y
beq CS.RUN.PRINTCR
iny
2019-12-16 13:14:11 +00:00
bra .1
2019-10-19 18:35:30 +00:00
2019-12-16 13:14:11 +00:00
.2 lda EndChar
beq .8
.3 lda (ZPBufPtr),y
2019-03-12 14:41:55 +00:00
beq .8
cpy EndChar
2019-12-16 13:14:11 +00:00
beq .4
iny
2019-12-16 13:14:11 +00:00
bra .3
2019-12-16 13:14:11 +00:00
.4 lda #0
sta (ZPBufPtr),y
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
.8 ldy StartChar
2019-12-16 13:14:11 +00:00
beq .80
dey
beq .80
2019-03-12 14:41:55 +00:00
jsr CS.RUN.AddYToBufPtr
2019-12-16 13:14:11 +00:00
.80 >LDYA ZPBufPtr
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-10-19 18:35:30 +00:00
2019-03-12 14:41:55 +00:00
rts
*--------------------------------------
CS.RUN.NextArg inc ArgIndex
lda ArgIndex
2019-03-13 11:37:05 +00:00
>SYSCALL ArgV
bcs .9
2019-03-13 11:37:05 +00:00
>STYA ZPPtr1
.9 rts
*--------------------------------------
2019-03-12 14:41:55 +00:00
CS.RUN.AddYToBufPtr
tya
clc
adc ZPBufPtr
sta ZPBufPtr
bcc .8
inc ZPBufPtr+1
2019-03-12 14:41:55 +00:00
.8 rts
*--------------------------------------
2019-10-26 14:33:37 +00:00
CS.QUIT lda hToClose
beq .1
2020-02-28 07:21:46 +00:00
>SYSCALL FClose Close the pipe
2019-10-26 14:33:37 +00:00
.1 lda hBuf
2019-03-12 14:41:55 +00:00
beq .8
>SYSCALL FreeMem
.8 clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.END
*--------------------------------------
2019-10-19 18:35:30 +00:00
OptionList .AS "HhFfMmNnSs"
OptionList.Cnt .EQ *-OptionList
2019-03-12 14:41:55 +00:00
*--------------------------------------
MSG.USAGE .CS "Usage : CUT "line of text"\r\n"
.CS " -H : This help screen\r\n"
.CS " -F nn : Output field nn\r\n"
.CS " -M nn : Output starting at nn\r\n"
.CS " -N nn : Output Ending at nn\r\n"
.CS " -S ch : Change default SPACE separator to 'ch'"
MSG.CRLF .CZ "\r\n"
2019-03-12 14:41:55 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
2019-10-19 18:35:30 +00:00
DS.END .ED
2019-03-12 14:41:55 +00:00
*--------------------------------------
MAN
2020-05-25 21:03:11 +00:00
SAVE usr/src/bin/cut.s
2019-03-12 14:41:55 +00:00
ASM