A2osX/BIN/CAT.S.txt

366 lines
6.4 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 /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BUILD/BIN/CAT
*--------------------------------------
.INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I
.INB /A2OSX.BUILD/INC/MLI.ERR.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPBufPtr .EQ ZPBIN+2
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #4 ZP
.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.LINENUM .DA MSG.LINENUM
L.MSG.CTRLCHAR .DA MSG.CTRLCHAR
L.ASCII .DA ASCII
.DA 0
*--------------------------------------
CS.INIT
.1 >INC.G ArgCount
>SYSCALL GetArg.A
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 >LDYA L.MSG.USAGE
>SYSCALL PrintF.YA
lda #K.E.SYN
sec
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.YA
bcs .9
>STYA ZPBufPtr
txa
>STA.G hBuf
.8
* lda (pPs)
* ora #S.PS.F.EVENT Now accept events
* sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN >SYSCALL GetChar
bcs .10 no char
cmp #$03 Ctrl-C
beq .99 Abort....
cmp #$13 Ctrl-S
bne .10
>LDA.G bPause
eor #$ff
sta (pData),y
bne .8
.10 >LDA.G bPause
bne .8 Pause...
>LDA.G hFILE
bne .2
.1 >INC.G ArgIndex
>SYSCALL GetArg.A
bcs .99 No more arg...the end!
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
beq .1 An option, skip...
>LDYA ZPPtr1
jsr CS.RUN.OPEN
bcs .9
>STA.G hFILE
clc
rts
.2 pha
>PUSHW ZPBufPtr
>PUSHWI 256
pla
>PUSHA
>SYSCALL FRead
bcc CS.RUN.PRINT
cmp #MLI.E.EOF
bne .9
jsr CS.RUN.CLOSE
.8 clc
rts
.99 lda #0 Exit with no Error
.9 sec
rts
*--------------------------------------
CS.RUN.PRINT sty BytesRead Y,A = Bytes read
stz ByteIndex
>INCW.G LineNum
>LDA.G bSuppressBlankLine
lda (pData),y
bpl .10
lda BytesRead
beq .12 Empty line ?
dec
bne .1 Only one CR ?
lda (ZPBufPtr)
cmp #13
bne .1
.12 >LDA.G bPrintedBlankLine
bmi .8
lda #$ff
sta (pData),y
bra .10
.1 lda #0
>STA.G bPrintedBlankLine
.10 jsr CS.RUN.PRINTNUM
bcs .9
.20 ldy ByteIndex
lda (ZPBufPtr),y
cmp #' '
bcs .6
cmp #13 Allow printing of CR even if not bPrintAll
beq .4
>LDA.G bPrintAll
bpl .7
>LDYA L.ASCII
>STYA ZPPtr1
ldy ByteIndex
lda (ZPBufPtr),y
tax
.2 dex
bmi .3
lda ZPPtr1
sec
adc (ZPPtr1)
sta ZPPtr1
bcc .2
inc ZPPtr1+1
bra .2
.3 >PUSHW ZPPtr1
>LDYA L.MSG.CTRLCHAR
>SYSCALL PrintF.YA
bcs .9
bra .7
.4 lda #13
>SYSCALL PutChar.A
bcs .9
lda #10
.6 >SYSCALL PutChar.A
bcs .9
.7 inc ByteIndex
dec BytesRead
bne .20
.8 clc
.9 rts
*--------------------------------------
CS.RUN.PRINTNUM clc
>LDA.G bLineNum
bpl .8
>LDYA.G LineNum
>PUSHYA
>LDYA L.MSG.LINENUM
>SYSCALL PrintF.YA
.8 rts
*--------------------------------------
CS.RUN.OPEN >SYSCALL RealPath.YA
bcs .9
stx hFullPath
pha
>PUSHWI 0 Aux type
>PUSHBI 4 S.FI.T.TXT
>PUSHBI SYS.FOpen.R+SYS.FOpen.T
pla
>PUSHYA
>SYSCALL FOpen
bcs .99
jsr .99
pha
lda #0
>STA.G bPrintedBlankLine Reset this flag for the new file
pla
clc
rts
.99 pha
lda hFullPath
>SYSCALL FreeMem.A
pla
.9 sec
rts
*--------------------------------------
CS.QUIT >LDA.G hBuf
beq CS.RUN.CLOSE
>SYSCALL FreeMem.A
CS.RUN.CLOSE ldy #hFILE
lda (pData),y
beq .8
pha
lda #0
sta (pData),y
pla
>SYSCALL FClose.A
.8 clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.END
*--------------------------------------
OptionList >PSTR "ANSans"
OptionVars .DA #bPrintAll,#bLineNum,#bSuppressBlankLine,#bPrintAll,#bLineNum,#bSuppressBlankLine
*--------------------------------------
MSG.USAGE .AZ "Usage : CAT File1 [File2...]\r\n -A : Show All non printable caracters\r\n -N : Number all output lines\r\n -S : Suppress repeated empty output lines\r\n"
MSG.LINENUM .AZ "%5D:"
MSG.CTRLCHAR .AZ "[%S]"
*--------------------------------------
ASCII >PSTR "NULL"
>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"
*--------------------------------------
hFullPath .BS 1
BytesRead .BS 1
ByteIndex .BS 1
*--------------------------------------
.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 /A2OSX.SRC/BIN/CAT.S
ASM