A2osX/BIN/CAT.S.txt
2019-03-21 16:37:02 +00:00

352 lines
6.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
PREFIX
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/CAT
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/MLI.I
.INB INC/MLI.E.I
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPTR1 .BS 2
ZPBufPtr .BS 2
ByteIndex .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 #16 SS
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* 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.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.G ArgCount
>SYSCALL ArgV
bcs .7
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
lda (ZPPtr1),y
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.99 >PUSHBI 0
>LDYA L.MSG.USAGE
>SYSCALL printf
lda #E.SYN
sec
.9 rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 >INC.G FileCount
bra .1 scan for any other args
.7 >LDA.G FileCount
beq .99
>LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA ZPBufPtr
txa
>STA.G hBuf
*--------------------------------------
CS.RUN.LOOP ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL feof
bcs .90 IO error
tay
beq .10 no char
>SYSCALL GetChar
bcs .9 IO error
cmp #$03 Ctrl-C
beq .9 Abort....
cmp #$13 Ctrl-S
bne .10
>LDA.G bPause
eor #$ff
sta (pData),y
bne CS.RUN.LOOP
.10 >LDA.G bPause
bne CS.RUN.LOOP Pause...
.11 >LDA.G hFILE
bne .2
.1 >INC.G ArgIndex
>SYSCALL ArgV
bcs .99 No more arg...the end!
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
beq .1 An option, skip...
>LDYA ZPPtr1
jsr CS.RUN.OPEN
.90 bcs .9
>STA.G hFILE
.2 >PUSHWI 256
>PUSHW ZPBufPtr
>LDA.G hFILE
>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 phy
pha
lda #0
>STA.G bPrintedBlankLine Reset this flag for the new file
>PUSHWI 0 Aux type
>PUSHBI S.FI.T.TXT
>PUSHBI O.RDONLY+O.TEXT
pla
ply
>SYSCALL FOpen
rts
*--------------------------------------
CS.RUN.PRINT >INCW.G LineNum
>LDA.G bSuppressBlankLine
bpl .2
lda (ZPBufPtr)
bne .1 Empty line ?
>LDA.G bPrintedBlankLine
bmi .8
lda #$ff
sta (pData),y
bra .2
.1 >STZ.G bPrintedBlankLine
.2 jsr CS.RUN.PRINTNUM
bcs .99
>LDA.G bPrintAll
bmi .3
>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
bra .62
.8 clc
rts
.5 tax
>LDYA L.ASCII
>STYA ZPPtr1
.6 dex
bmi .61
lda ZPPtr1
sec
adc (ZPPtr1)
sta ZPPtr1
bcc .6
inc ZPPtr1+1
bra .6
.61 >PUSHW ZPPtr1
>PUSHBI 2
>LDYA L.MSG.CTRLCHAR
>SYSCALL printf
bcs .9
.62 inc ByteIndex
bne .4
.7 >PUSHBI 2
>LDYA L.MSG.CRLF
>SYSCALL printf
.9 rts
*--------------------------------------
CS.RUN.PRINTNUM clc
>LDA.G bLineNum
bpl .8
>PUSHW.G LineNum
>PUSHBI 2
>LDYA L.MSG.LINENUM
>SYSCALL printf
.8 rts
*--------------------------------------
CS.QUIT >LDA.G hBuf
beq CS.RUN.CLOSE
>SYSCALL FreeMem
CS.RUN.CLOSE >LDA.G hFILE
beq .8
pha
lda #0
sta (pData),y
pla
>SYSCALL FClose
.8 clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.END
*--------------------------------------
OptionList >PSTR "ANSans"
OptionVars .DA #bPrintAll,#bLineNum,#bSuppressBlankLine,#bPrintAll,#bLineNum,#bSuppressBlankLine
*--------------------------------------
MSG.USAGE .AS "Usage : CAT File1 [File2...]\r\n"
.AS " -A : Show All non printable caracters\r\n"
.AS " -N : Number all output lines\r\n"
.AS " -S : Suppress repeated empty output lines"
MSG.CRLF .AZ "\r\n"
MSG.LINENUM .AZ "%5D:"
MSG.CTRLCHAR .AZ "[%S]"
*--------------------------------------
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"
*--------------------------------------
.DUMMY
.OR 0
DS.START
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
DS.END
.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/CAT.S
ASM