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
|
|
|
|
|
ZPPTR1 .BS 2
|
|
|
|
|
ZPBufPtr .BS 2
|
|
|
|
|
ArgCount .BS 1
|
|
|
|
|
ArgIndex .BS 1
|
|
|
|
|
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
|
|
|
|
|
.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
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
lda ArgCount
|
|
|
|
|
sta ArgIndex
|
|
|
|
|
bra .10
|
2019-10-19 18:35:30 +00:00
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
.1 ldy #1
|
|
|
|
|
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
|
|
|
|
|
dex
|
2019-10-19 18:35:30 +00:00
|
|
|
|
bpl .2
|
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
bra .97
|
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
|
|
|
|
|
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
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
>SYSCALL atoi
|
|
|
|
|
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-10-19 18:35:30 +00:00
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
.97 lda #E.SYN
|
2019-10-03 06:25:27 +00:00
|
|
|
|
.98 pha
|
2020-01-29 21:45:06 +00:00
|
|
|
|
>PUSHW L.MSG.USAGE
|
2019-03-12 14:41:55 +00:00
|
|
|
|
>PUSHBI 0
|
2020-02-28 07:21:46 +00:00
|
|
|
|
>SYSCALL PrintF
|
2019-03-12 14:41:55 +00:00
|
|
|
|
pla
|
|
|
|
|
sec
|
|
|
|
|
.9 rts
|
|
|
|
|
|
|
|
|
|
.8 >LDYAI 256
|
|
|
|
|
>SYSCALL GetMem
|
|
|
|
|
bcs .9
|
2020-05-25 21:03:11 +00:00
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
>STYA ZPBufPtr
|
|
|
|
|
stx hBuf
|
|
|
|
|
lda ArgIndex
|
|
|
|
|
beq .80
|
2019-10-19 18:35:30 +00:00
|
|
|
|
|
2019-03-12 14:41:55 +00:00
|
|
|
|
>SYSCALL ArgV
|
|
|
|
|
>PUSHYA
|
|
|
|
|
>LDYA ZPBufPtr
|
|
|
|
|
>SYSCALL strcpy
|
2019-10-19 18:35:30 +00:00
|
|
|
|
jsr CS.RUN.OUT
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
lda OF.Table.hFD-1,x
|
|
|
|
|
>SYSCALL GetMemPtr
|
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
cmp #S.FD.T.PIPE
|
|
|
|
|
bne .97
|
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
|
|
|
|
>PUSHWI 256
|
|
|
|
|
>PUSHW ZPBufPtr
|
|
|
|
|
ldy #S.PS.hStdIn
|
|
|
|
|
lda (pPS),y
|
|
|
|
|
|
|
|
|
|
>SYSCALL fgets
|
2019-10-19 18:35:30 +00:00
|
|
|
|
bcs .8
|
|
|
|
|
|
|
|
|
|
lda (ZPBufPtr)
|
|
|
|
|
beq CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
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-26 14:33:37 +00:00
|
|
|
|
|
2019-10-19 18:35:30 +00:00
|
|
|
|
lda #0
|
|
|
|
|
.90 sec
|
|
|
|
|
.9 rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
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
|
|
|
|
*--------------------------------------
|
2019-12-14 18:44:01 +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-14 18:44:01 +00:00
|
|
|
|
|
2019-12-16 13:14:11 +00:00
|
|
|
|
lda (ZPBufPtr),y
|
|
|
|
|
beq CS.RUN.PRINTCR
|
2019-12-14 18:44:01 +00:00
|
|
|
|
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
|
2019-12-14 18:44:01 +00:00
|
|
|
|
|
|
|
|
|
iny
|
2019-12-16 13:14:11 +00:00
|
|
|
|
bra .3
|
2019-12-14 18:44:01 +00:00
|
|
|
|
|
2019-12-16 13:14:11 +00:00
|
|
|
|
.4 lda #0
|
2019-03-12 14:41:55 +00:00
|
|
|
|
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
|
|
|
|
|
*--------------------------------------
|
2019-03-13 11:37:05 +00:00
|
|
|
|
CS.RUN.NextArg inc ArgCount
|
|
|
|
|
lda ArgCount
|
|
|
|
|
>SYSCALL ArgV
|
|
|
|
|
bcs .9
|
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
|
|
|
|
|
.9 rts
|
|
|
|
|
*--------------------------------------
|
2019-03-12 14:41:55 +00:00
|
|
|
|
CS.RUN.AddYToBufPtr
|
|
|
|
|
tya
|
|
|
|
|
clc
|
|
|
|
|
adc ZPBufPtr
|
|
|
|
|
sta ZPBufPtr
|
|
|
|
|
bcc .8
|
2019-12-14 18:44:01 +00:00
|
|
|
|
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 .AS "Usage : CUT "line of text"\r\n"
|
|
|
|
|
.AS " -H : This help screen\r\n"
|
2019-03-13 11:37:05 +00:00
|
|
|
|
.AS "-F nn : Output field nn\r\n"
|
2019-03-12 14:41:55 +00:00
|
|
|
|
.AS "-M nn : Output starting at nn\r\n"
|
2019-03-13 11:37:05 +00:00
|
|
|
|
.AS "-N nn : Output Ending at nn\r\n"
|
|
|
|
|
.AS "-S ch : Change default SPACE separator to 'ch'"
|
2019-03-12 14:41:55 +00:00
|
|
|
|
MSG.CRLF .AZ "\r\n"
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.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
|