2016-11-01 14:36:32 +00:00
NEW
2017-12-22 21:24:30 +00:00
PREFIX /A2OSX.BUILD
AUTO 4,1
2016-11-01 14:36:32 +00:00
.LIST OFF
.OP 65C02
.OR $2000
2017-03-29 15:48:15 +00:00
.TF /A2OSX.BUILD/BIN/CAT
2016-11-01 14:36:32 +00:00
*--------------------------------------
2017-03-29 15:48:15 +00:00
.INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I
.INB /A2OSX.BUILD/INC/MLI.ERR.I
2016-11-01 14:36:32 +00:00
*--------------------------------------
ZPPTR1 .EQ ZPBIN
2017-09-19 06:39:27 +00:00
ZPBufPtr .EQ ZPBIN+2
2016-11-01 14:36:32 +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
2017-10-03 15:33:30 +00:00
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #4 ZP
2016-11-01 14:36:32 +00:00
.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
*--------------------------------------
2017-10-23 15:39:19 +00:00
CS.INIT
.1 >INC.G ArgCount
2017-08-24 12:46:48 +00:00
>SYSCALL GetArg.A
2017-10-23 15:39:19 +00:00
bcs .7
2016-11-01 14:36:32 +00:00
2017-10-23 15:39:19 +00:00
>STYA ZPPtr1
2016-11-01 14:36:32 +00:00
lda (ZPPtr1)
2017-10-23 15:39:19 +00:00
cmp #'-'
2016-11-01 14:36:32 +00:00
bne .4
2017-10-23 15:39:19 +00:00
ldy #1
2016-11-01 14:36:32 +00:00
lda (ZPPtr1),y
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.99 >LDYA L.MSG.USAGE
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2017-10-26 16:01:54 +00:00
lda #K.E.SYN
2016-11-01 14:36:32 +00:00
sec
rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
2017-10-23 15:39:19 +00:00
.4 >INC.G FileCount
2016-11-01 14:36:32 +00:00
bra .1 scan for any other args
2017-10-23 15:39:19 +00:00
.7 >LDA.G FileCount
2016-11-01 14:36:32 +00:00
beq .99
2017-09-19 06:39:27 +00:00
>LDYAI 256
>SYSCALL GetMem.YA
bcs .9
>STYA ZPBufPtr
txa
>STA.G hBuf
2017-08-22 06:37:03 +00:00
.8
* lda (pPs)
* ora #S.PS.F.EVENT Now accept events
* sta (pPs)
2016-11-01 14:36:32 +00:00
clc
2017-09-19 06:39:27 +00:00
.9 rts
2016-11-01 14:36:32 +00:00
*--------------------------------------
2017-09-19 06:39:27 +00:00
CS.RUN >SYSCALL GetChar
2017-01-15 20:51:20 +00:00
bcs .10 no char
cmp #$03 Ctrl-C
beq .99 Abort....
cmp #$13 Ctrl-S
bne .10
2017-09-19 06:39:27 +00:00
>LDA.G bPause
2017-01-15 20:51:20 +00:00
eor #$ff
sta (pData),y
bne .8
2016-11-01 14:36:32 +00:00
2017-09-19 06:39:27 +00:00
.10 >LDA.G bPause
2017-01-15 20:51:20 +00:00
bne .8 Pause...
2017-09-19 06:39:27 +00:00
>LDA.G hFILE
2016-11-01 14:36:32 +00:00
bne .2
2017-10-23 15:39:19 +00:00
.1 >INC.G ArgIndex
2017-08-24 12:46:48 +00:00
>SYSCALL GetArg.A
2016-11-01 14:36:32 +00:00
bcs .99 No more arg...the end!
>STYA ZPPtr1
2017-10-23 15:39:19 +00:00
lda (ZPPtr1)
2016-11-01 14:36:32 +00:00
cmp #'-'
beq .1 An option, skip...
>LDYA ZPPtr1
jsr CS.RUN.OPEN
bcs .9
2017-09-19 06:39:27 +00:00
>STA.G hFILE
2016-11-01 14:36:32 +00:00
clc
rts
.2 pha
2017-09-19 06:39:27 +00:00
>PUSHW ZPBufPtr
2016-11-01 14:36:32 +00:00
>PUSHWI 256
pla
>PUSHA
>SYSCALL FRead
2017-01-15 20:51:20 +00:00
2016-11-01 14:36:32 +00:00
bcc CS.RUN.PRINT
2017-10-26 16:01:54 +00:00
cmp #MLI.E.EOF
2016-11-01 14:36:32 +00:00
bne .9
2017-01-15 20:51:20 +00:00
jsr CS.RUN.CLOSE
2016-11-01 14:36:32 +00:00
.8 clc
rts
.99 lda #0 Exit with no Error
.9 sec
rts
*--------------------------------------
CS.RUN.PRINT sty BytesRead Y,A = Bytes read
stz ByteIndex
2017-09-19 06:39:27 +00:00
>INCW.G LineNum
2016-11-01 14:36:32 +00:00
2017-09-19 06:39:27 +00:00
>LDA.G bSuppressBlankLine
2017-08-22 06:37:03 +00:00
lda (pData),y
bpl .10
lda BytesRead
beq .12 Empty line ?
2016-11-01 14:36:32 +00:00
dec
2017-08-22 06:37:03 +00:00
bne .1 Only one CR ?
2017-09-19 06:39:27 +00:00
lda (ZPBufPtr)
2016-11-01 14:36:32 +00:00
cmp #13
bne .1
2017-09-19 06:39:27 +00:00
.12 >LDA.G bPrintedBlankLine
2017-08-22 06:37:03 +00:00
bmi .8
2016-11-01 14:36:32 +00:00
2017-08-22 06:37:03 +00:00
lda #$ff
2016-11-01 14:36:32 +00:00
sta (pData),y
2017-08-22 06:37:03 +00:00
bra .10
2016-11-01 14:36:32 +00:00
2017-09-19 06:39:27 +00:00
.1 lda #0
>STA.G bPrintedBlankLine
2016-11-01 14:36:32 +00:00
2017-08-22 06:37:03 +00:00
.10 jsr CS.RUN.PRINTNUM
2016-11-03 11:00:00 +00:00
bcs .9
2017-09-19 06:39:27 +00:00
.20 ldy ByteIndex
lda (ZPBufPtr),y
2016-11-01 14:36:32 +00:00
cmp #' '
bcs .6
2016-11-04 10:53:21 +00:00
cmp #13 Allow printing of CR even if not bPrintAll
2017-04-03 15:35:03 +00:00
beq .4
2016-11-04 10:53:21 +00:00
2017-09-19 06:39:27 +00:00
>LDA.G bPrintAll
2016-11-01 14:36:32 +00:00
bpl .7
>LDYA L.ASCII
>STYA ZPPtr1
2017-09-19 06:39:27 +00:00
ldy ByteIndex
lda (ZPBufPtr),y
2016-11-01 14:36:32 +00:00
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
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2016-11-01 14:36:32 +00:00
bcs .9
bra .7
2017-04-03 15:35:03 +00:00
.4 lda #13
2017-08-25 06:37:21 +00:00
>SYSCALL PutChar.A
2017-04-03 15:35:03 +00:00
bcs .9
lda #10
2017-08-25 06:37:21 +00:00
.6 >SYSCALL PutChar.A
2016-11-01 14:36:32 +00:00
bcs .9
.7 inc ByteIndex
dec BytesRead
bne .20
2016-11-04 10:53:21 +00:00
.8 clc
2016-11-01 14:36:32 +00:00
.9 rts
*--------------------------------------
2016-11-03 11:00:00 +00:00
CS.RUN.PRINTNUM clc
2017-09-19 06:39:27 +00:00
>LDA.G bLineNum
2016-11-03 11:00:00 +00:00
bpl .8
2017-09-19 06:39:27 +00:00
>LDYA.G LineNum
2016-11-03 11:00:00 +00:00
>PUSHYA
>LDYA L.MSG.LINENUM
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2016-11-03 11:00:00 +00:00
.8 rts
*--------------------------------------
2017-10-03 15:33:30 +00:00
CS.RUN.OPEN >SYSCALL RealPath.YA
2016-11-01 14:36:32 +00:00
bcs .9
stx hFullPath
pha
>PUSHWI 0 Aux type
2017-10-27 14:56:46 +00:00
>PUSHBI 4 S.FI.T.TXT
2017-01-12 17:43:45 +00:00
>PUSHBI SYS.FOpen.R+SYS.FOpen.T
2016-11-01 14:36:32 +00:00
pla
>PUSHYA
2017-01-12 17:43:45 +00:00
>SYSCALL FOpen
2016-11-01 14:36:32 +00:00
bcs .99
jsr .99
pha
2016-11-04 10:53:21 +00:00
2017-08-22 06:37:03 +00:00
lda #0
2017-09-19 06:39:27 +00:00
>STA.G bPrintedBlankLine Reset this flag for the new file
2016-11-01 14:36:32 +00:00
pla
clc
rts
.99 pha
lda hFullPath
2017-08-25 06:37:21 +00:00
>SYSCALL FreeMem.A
2016-11-01 14:36:32 +00:00
pla
.9 sec
rts
*--------------------------------------
2017-09-19 06:39:27 +00:00
CS.QUIT >LDA.G hBuf
beq CS.RUN.CLOSE
>SYSCALL FreeMem.A
CS.RUN.CLOSE ldy #hFILE
2016-11-01 14:36:32 +00:00
lda (pData),y
2017-01-15 20:51:20 +00:00
beq .8
pha
lda #0
2016-11-01 14:36:32 +00:00
sta (pData),y
2017-01-15 20:51:20 +00:00
pla
2017-08-25 06:37:21 +00:00
>SYSCALL FClose.A
2017-01-15 20:51:20 +00:00
2016-11-01 14:36:32 +00:00
.8 clc
rts
2017-01-15 20:51:20 +00:00
*--------------------------------------
CS.DOEVENT sec
2016-11-01 14:36:32 +00:00
rts
*--------------------------------------
CS.END
*--------------------------------------
2017-06-25 12:04:33 +00:00
OptionList >PSTR "ANSans"
2017-08-22 06:37:03 +00:00
OptionVars .DA #bPrintAll,#bLineNum,#bSuppressBlankLine,#bPrintAll,#bLineNum,#bSuppressBlankLine
2016-11-01 14:36:32 +00:00
*--------------------------------------
2018-04-11 15:35:51 +00:00
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]"
2016-11-01 14:36:32 +00:00
*--------------------------------------
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
2017-09-19 06:39:27 +00:00
ArgCount .BS 1
FileCount .BS 1
2017-01-15 20:51:20 +00:00
bPause .BS 1
2016-11-01 14:36:32 +00:00
bPrintAll .BS 1
bLineNum .BS 1
2017-08-22 06:37:03 +00:00
bSuppressBlankLine .BS 1
2016-11-01 14:36:32 +00:00
ArgIndex .BS 1
2017-09-19 06:39:27 +00:00
hBuf .BS 1
hFile .BS 1
2016-11-01 14:36:32 +00:00
LineNum .BS 2
bPrintedBlankLine .BS 1
DS.END
.ED
*--------------------------------------
MAN
2017-03-29 15:48:15 +00:00
SAVE /A2OSX.SRC/BIN/CAT.S
2016-11-01 14:36:32 +00:00
ASM