2016-11-01 14:36:32 +00:00
|
|
|
|
NEW
|
2019-05-02 09:52:32 +00:00
|
|
|
|
AUTO 3,1
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.LIST OFF
|
|
|
|
|
.OP 65C02
|
|
|
|
|
.OR $2000
|
|
|
|
|
.TF bin/cat
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.INB inc/macros.i
|
|
|
|
|
.INB inc/a2osx.i
|
|
|
|
|
.INB inc/kernel.i
|
|
|
|
|
.INB inc/mli.i
|
|
|
|
|
.INB inc/mli.e.i
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.DUMMY
|
|
|
|
|
.OR ZPBIN
|
2019-02-27 16:44:11 +00:00
|
|
|
|
ZS.START
|
2021-07-24 20:42:23 +00:00
|
|
|
|
ZPPtr1 .BS 2
|
|
|
|
|
ZPBufPtr .BS 2
|
|
|
|
|
ByteIndex .BS 1
|
|
|
|
|
ArgCount .BS 1
|
|
|
|
|
FileCount .BS 1
|
|
|
|
|
bPause .BS 1
|
|
|
|
|
bPrintAll .BS 1
|
|
|
|
|
bLineNum .BS 1
|
|
|
|
|
bSuppressBlankLine .BS 1
|
|
|
|
|
ArgIndex .BS 1
|
|
|
|
|
hBuf .BS 1
|
|
|
|
|
hFile .BS 1
|
|
|
|
|
LineNum .BS 2
|
|
|
|
|
bPrintedBlankLine .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 #S.PS.F.EVENT S.PS.F
|
|
|
|
|
.DA #0
|
|
|
|
|
.DA CS.END-CS.START CS
|
|
|
|
|
.DA DS.END-DS.START DS
|
|
|
|
|
.DA #64 SS
|
|
|
|
|
.DA #ZS.END-ZS.START Zero Page Size
|
|
|
|
|
.DA 0
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Relocation Table
|
2019-10-03 06:25:27 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +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
|
|
|
|
|
L.MSG.INIT .DA MSG.INIT
|
|
|
|
|
L.MSG.LINENUM .DA MSG.LINENUM
|
|
|
|
|
L.MSG.CTRLCHAR .DA MSG.CTRLCHAR
|
|
|
|
|
L.ASCII .DA ASCII
|
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.INIT clc
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.RUN
|
|
|
|
|
.1 inc ArgCount
|
|
|
|
|
lda ArgCount
|
|
|
|
|
>SYSCALL ArgV
|
|
|
|
|
bcs .7
|
|
|
|
|
|
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
|
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
cmp #'-'
|
|
|
|
|
bne .4
|
|
|
|
|
|
|
|
|
|
ldy #1
|
|
|
|
|
lda (ZPPtr1),y
|
|
|
|
|
|
|
|
|
|
ldx #OptionList.Cnt-1
|
|
|
|
|
|
|
|
|
|
.2 cmp OptionList,x
|
|
|
|
|
beq .3
|
|
|
|
|
|
|
|
|
|
dex
|
|
|
|
|
bpl .2
|
|
|
|
|
|
|
|
|
|
.99 >PUSHW L.MSG.USAGE
|
|
|
|
|
>PUSHBI 0
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
lda #E.SYN
|
|
|
|
|
sec
|
|
|
|
|
.9 rts
|
|
|
|
|
|
|
|
|
|
.3 ldy OptionVars,x
|
|
|
|
|
lda #$80
|
|
|
|
|
sta 0,y
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.4 inc FileCount
|
|
|
|
|
bra .1 scan for any other args
|
|
|
|
|
|
|
|
|
|
.7 lda FileCount
|
|
|
|
|
beq .99
|
|
|
|
|
|
|
|
|
|
>LDYAI 256
|
|
|
|
|
>SYSCALL GetMem
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
>STYA ZPBufPtr
|
|
|
|
|
stx hBuf
|
|
|
|
|
|
|
|
|
|
ldy #S.PS.hStdOut
|
|
|
|
|
lda (pPS),y
|
|
|
|
|
|
|
|
|
|
tax
|
|
|
|
|
|
|
|
|
|
lda hFDs-1,x
|
|
|
|
|
>SYSCALL GetMemPtr
|
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
|
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
|
|
|
|
|
beq CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
cmp #S.FD.T.PIPE
|
|
|
|
|
beq CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
>PUSHW L.MSG.INIT
|
|
|
|
|
>PUSHBI 0
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.RUN.LOOP ldy #S.PS.hStdIn
|
|
|
|
|
lda (pPS),y
|
|
|
|
|
>SYSCALL FEOF
|
|
|
|
|
bcs .90 IO error
|
|
|
|
|
|
|
|
|
|
tay
|
|
|
|
|
bne .10 no char
|
|
|
|
|
|
|
|
|
|
>SYSCALL GetChar
|
|
|
|
|
bcs .9 IO error
|
|
|
|
|
|
|
|
|
|
cmp #$03 Ctrl-C
|
|
|
|
|
beq .9 Abort....
|
|
|
|
|
|
|
|
|
|
cmp #$13 Ctrl-S
|
|
|
|
|
bne .10
|
|
|
|
|
|
|
|
|
|
lda bPause
|
|
|
|
|
eor #$ff
|
|
|
|
|
sta bPause
|
|
|
|
|
bne CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
.10 lda bPause
|
|
|
|
|
bne CS.RUN.LOOP Pause...
|
|
|
|
|
|
|
|
|
|
.11 lda hFile
|
|
|
|
|
bne .2
|
|
|
|
|
|
|
|
|
|
.1 inc ArgIndex
|
|
|
|
|
lda ArgIndex
|
|
|
|
|
>SYSCALL ArgV
|
|
|
|
|
bcs .99 No more arg...the end!
|
2021-07-03 00:49:04 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
cmp #'-'
|
|
|
|
|
beq .1 An option, skip...
|
2021-07-03 00:49:04 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
>LDYA ZPPtr1
|
|
|
|
|
jsr CS.RUN.OPEN
|
|
|
|
|
.90 bcs .9
|
|
|
|
|
|
|
|
|
|
sta hFile
|
|
|
|
|
|
|
|
|
|
.2 >PUSHA
|
|
|
|
|
>PUSHW ZPBufPtr
|
|
|
|
|
>PUSHWI 254 Leave room for CRLF
|
|
|
|
|
>SYSCALL FGetS
|
|
|
|
|
bcs .7
|
|
|
|
|
|
|
|
|
|
jsr CS.RUN.PRINT
|
|
|
|
|
bcc CS.RUN.LOOP
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.7 cmp #MLI.E.EOF
|
|
|
|
|
bne .9
|
|
|
|
|
|
|
|
|
|
jsr CS.RUN.CLOSE
|
|
|
|
|
jmp CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
.99 lda #0 Exit with no Error
|
|
|
|
|
.9 sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.RUN.OPEN stz bPrintedBlankLine Reset this flag for the new file
|
|
|
|
|
>PUSHYA
|
|
|
|
|
>PUSHBI O.RDONLY+O.TEXT
|
|
|
|
|
>PUSHBI S.FI.T.TXT
|
|
|
|
|
>PUSHWZ Aux type
|
|
|
|
|
>SYSCALL FOpen
|
|
|
|
|
rts
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
CS.RUN.PRINT inc LineNum
|
|
|
|
|
bne .10
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
inc LineNum+1
|
2019-02-20 16:07:43 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.10 lda bSuppressBlankLine
|
|
|
|
|
bpl .2
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
lda (ZPBufPtr)
|
|
|
|
|
bne .1 Empty line ?
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
lda bPrintedBlankLine
|
|
|
|
|
bmi .8
|
2020-12-23 14:54:57 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
lda #$ff
|
|
|
|
|
sta bPrintedBlankLine
|
|
|
|
|
bra .2
|
2019-01-25 12:43:50 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.1 stz bPrintedBlankLine
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.2 jsr CS.RUN.PRINTNUM
|
|
|
|
|
bcs .99
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
lda bPrintAll
|
|
|
|
|
bmi .3
|
|
|
|
|
|
|
|
|
|
ldy #$ff
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.20 iny
|
|
|
|
|
lda (ZPBufPtr),y
|
|
|
|
|
beq .21
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
cmp #C.SPACE
|
|
|
|
|
bcs .20
|
2017-09-19 06:39:27 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
lda #C.SPACE
|
|
|
|
|
sta (ZPBufPtr),y
|
|
|
|
|
bra .20
|
|
|
|
|
|
|
|
|
|
.21 >LDYA ZPBufPtr
|
|
|
|
|
>SYSCALL PutS
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.3 stz ByteIndex
|
|
|
|
|
|
|
|
|
|
.4 ldy ByteIndex
|
|
|
|
|
lda (ZPBufPtr),y
|
|
|
|
|
beq .7
|
|
|
|
|
|
|
|
|
|
cmp #C.SPACE
|
|
|
|
|
bcc .5
|
|
|
|
|
|
|
|
|
|
>SYSCALL PutChar
|
|
|
|
|
.99 bcs .9
|
2019-02-27 22:02:56 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
bra .62
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.5 tax
|
2016-11-01 14:36:32 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
>LDYA L.ASCII
|
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
.6 dex
|
|
|
|
|
bmi .61
|
2021-07-03 00:49:04 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
lda ZPPtr1
|
|
|
|
|
sec
|
|
|
|
|
adc (ZPPtr1)
|
|
|
|
|
sta ZPPtr1
|
|
|
|
|
bcc .6
|
2021-07-03 00:49:04 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
bra .6
|
2021-07-03 00:49:04 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.61 >PUSHW L.MSG.CTRLCHAR
|
|
|
|
|
>PUSHW ZPPtr1
|
|
|
|
|
>PUSHBI 2
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
.62 inc ByteIndex
|
|
|
|
|
bne .4
|
|
|
|
|
|
|
|
|
|
.7 >PUSHW L.MSG.CRLF
|
|
|
|
|
>PUSHBI 0
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
|
|
|
|
|
.9 rts
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
CS.RUN.PRINTNUM clc
|
|
|
|
|
lda bLineNum
|
|
|
|
|
bpl .8
|
|
|
|
|
|
|
|
|
|
>PUSHW L.MSG.LINENUM
|
|
|
|
|
>PUSHW LineNum
|
|
|
|
|
>PUSHBI 2
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
.8 rts
|
2016-11-03 11:00:00 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
CS.QUIT lda hBuf
|
|
|
|
|
beq CS.RUN.CLOSE
|
|
|
|
|
>SYSCALL FreeMem
|
2017-09-19 06:39:27 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
CS.RUN.CLOSE lda hFile
|
|
|
|
|
beq .8
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
stz hFile
|
2020-08-25 10:56:00 +00:00
|
|
|
|
|
2021-07-24 20:42:23 +00:00
|
|
|
|
>SYSCALL FClose
|
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
2017-01-15 20:51:20 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
CS.DOEVENT sec
|
|
|
|
|
rts
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.END
|
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
OptionList .AS "ANSans"
|
|
|
|
|
OptionList.Cnt .EQ *-OptionList
|
|
|
|
|
OptionVars .DA #bPrintAll,#bLineNum,#bSuppressBlankLine,#bPrintAll,#bLineNum,#bSuppressBlankLine
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MSG.USAGE .AS "Usage : CAT File1 [File2...]\r\n"
|
|
|
|
|
.AS " -A : Show All non printable characters\r\n"
|
|
|
|
|
.AS " -N : Number all output lines\r\n"
|
|
|
|
|
.AS " -S : Suppress repeated empty output lines"
|
|
|
|
|
MSG.CRLF .AZ "\r\n"
|
|
|
|
|
MSG.INIT .AZ "\e[?7h" Enable Line Wrap
|
|
|
|
|
MSG.LINENUM .AZ "%5D:"
|
|
|
|
|
MSG.CTRLCHAR .AZ "[%S]"
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
ASCII >PSTR "NUL"
|
|
|
|
|
>PSTR "SOH"
|
|
|
|
|
>PSTR "STX"
|
|
|
|
|
>PSTR "ETX"
|
|
|
|
|
>PSTR "EOT"
|
|
|
|
|
>PSTR "ENQ"
|
|
|
|
|
>PSTR "ACK"
|
|
|
|
|
>PSTR "BEL"
|
|
|
|
|
>PSTR "BS"
|
|
|
|
|
>PSTR "TAB"
|
|
|
|
|
>PSTR "LF"
|
|
|
|
|
>PSTR "VT"
|
|
|
|
|
>PSTR "FF"
|
|
|
|
|
>PSTR "CR"
|
|
|
|
|
>PSTR "SO"
|
|
|
|
|
>PSTR "SI"
|
|
|
|
|
>PSTR "DLE"
|
|
|
|
|
>PSTR "DC1"
|
|
|
|
|
>PSTR "DC2"
|
|
|
|
|
>PSTR "DC3"
|
|
|
|
|
>PSTR "DC4"
|
|
|
|
|
>PSTR "NAK"
|
|
|
|
|
>PSTR "SYN"
|
|
|
|
|
>PSTR "ETB"
|
|
|
|
|
>PSTR "CAN"
|
|
|
|
|
>PSTR "EM"
|
|
|
|
|
>PSTR "SUB"
|
|
|
|
|
>PSTR "ESC"
|
|
|
|
|
>PSTR "FS"
|
|
|
|
|
>PSTR "GS"
|
|
|
|
|
>PSTR "RS"
|
|
|
|
|
>PSTR "US"
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-24 20:42:23 +00:00
|
|
|
|
.DUMMY
|
|
|
|
|
.OR 0
|
2016-11-01 14:36:32 +00:00
|
|
|
|
DS.START
|
2021-07-24 20:42:23 +00:00
|
|
|
|
DS.END .ED
|
2016-11-01 14:36:32 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MAN
|
2020-08-17 20:47:31 +00:00
|
|
|
|
SAVE usr/src/bin/cat.s
|
2016-11-01 14:36:32 +00:00
|
|
|
|
ASM
|