Kernel version 0.8 : new CAT command, see README.md

This commit is contained in:
Rémy GIBERT 2016-11-01 15:36:32 +01:00
parent 105617950d
commit 627ba98812
3 changed files with 406 additions and 0 deletions

Binary file not shown.

Binary file not shown.

406
BIN/CAT.S.txt Normal file
View File

@ -0,0 +1,406 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/BIN/CAT
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
.INB /A2OSX.DEV/INC/PRODOS.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
*--------------------------------------
* 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 Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.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 >SYSCALL GetArgC
sta ArgCount
cmp #1
beq .99
.1 dec ArgCount
beq .5
lda ArgCount
>SYSCALL GetArgA
>STYA ZPPtr1
ldy #1
lda (ZPPtr1),y
cmp #'-'
bne .4
lda (ZPPtr1)
cmp #2
bne .4
iny
lda (ZPPtr1),y
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.99 >LDYA L.MSG.USAGE
>SYSCALL PrintFYA
lda #SYSMGR.ERRSYN
sec
rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 inc FileCount
bra .1 scan for any other args
.5 lda FileCount
beq .99
.8 lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
rts
*--------------------------------------
CS.RUN ldy #bCANCEL
lda (pData),y
bmi .99
ldy #bSTOP
lda (pData),y
bmi .8
ldy #hFILE
lda (pData),y
bne .2
.1 ldy #ArgIndex
lda (pData),y
inc
sta (pData),y
>SYSCALL GetArgA
bcs .99 No more arg...the end!
>STYA ZPPtr1
ldy #1
lda (ZPPtr1),y
cmp #'-'
beq .1 An option, skip...
>LDYA ZPPtr1
jsr CS.RUN.OPEN
bcs .9
ldy #hFILE
sta (pData),y
clc
rts
.2 pha
>PUSHWI UsrBuf256
>PUSHWI 256
pla
>PUSHA
>SYSCALL FRead
bcc CS.RUN.PRINT
cmp #MLI.ERR.EOF
bne .9
ldy #hFILE
lda (pData),y
pha
lda #0
sta (pData),y
pla
>SYSCALL FCloseA
.8 clc
rts
.99 lda #0 Exit with no Error
.9 sec
rts
*--------------------------------------
CS.RUN.PRINT sty BytesRead Y,A = Bytes read
stz ByteIndex
ldy #bLineNum
lda (pData),y
bpl .10
ldy #LineNum
lda (pData),y
clc
adc #1
sta (pData),y
pha
iny
lda (pData),y
adc #0
sta (pData),y
ply
>PUSHYA
>LDYA L.MSG.LINENUM
>SYSCALL PrintFYA
bcc .10
rts
* bcs .9
.10 lda BytesRead
beq .12
dec
bne .1 Only CR ?
lda UsrBuf256
cmp #13
bne .1
.12 ldy #bSuppress
lda (pData),y
bpl .8
ldy #bPrintedBlankLine
lda (pData),y
bpl .11
clc
rts
.11 lda #$ff
sta (pData),y
bra .8
.1 ldy #bPrintedBlankLine
lda #0
sta (pData),y
.20 ldx ByteIndex
lda UsrBuf256,x
cmp #' '
bcs .6
ldy #bPrintAll
lda (pData),y
bpl .7
>LDYA L.ASCII
>STYA ZPPtr1
lda UsrBuf256,x
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 PrintFYA
bcs .9
bra .7
.6 >SYSCALL COutA
bcs .9
.7 inc ByteIndex
dec BytesRead
bne .20
.8 lda #13
>SYSCALL COutA
.9 rts
*--------------------------------------
CS.RUN.OPEN >SYSCALL GetFullPathYA
bcs .9
stx hFullPath
pha
>PUSHWI 0 Aux type
>PUSHBI 4 S.FILEINFO.TYPE.TXT
>PUSHBI SYS.FOPEN.R+SYS.FOPEN.T
pla
>PUSHYA
>SYSCALL FOPEN
bcs .99
jsr .99
pha
ldy #LineNum
lda #0
sta (pData),y
iny
sta (pData),y
ldy #bPrintedBlankLine
sta (pData),y
pla
clc
rts
.99 pha
lda hFullPath
>SYSCALL FreeMemA
pla
.9 sec
rts
*--------------------------------------
CS.DOEVENT ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
cmp (pPs),y
bne .9
lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .1
lda #$FF
ldy #bCANCEL
sta (pData),y
bra .8
.1 cmp #$13 Ctrl-S
bne .8
ldy #bSTOP
lda (pData),y
eor #$FF
sta (pData),y
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.QUIT ldy #hFILE
lda (pData),y
beq .8
>SYSCALL FCloseA
.8 clc
rts
*--------------------------------------
CS.END
*--------------------------------------
OptionList >PSTR "ANS"
OptionVars .DA #bPrintAll,#bLineNum,#bSuppress
*--------------------------------------
MSG.USAGE >CSTR "Usage : CAT File1 [File2...]\n -A : Show All non printable caracters\n -N : Number all output lines\n -S : Suppress repeated empty output lines\n"
MSG.LINENUM >CSTR "%5D:"
MSG.CTRLCHAR >CSTR "[%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"
*--------------------------------------
ArgCount .BS 1
FileCount .BS 1
hFullPath .BS 1
BytesRead .BS 1
ByteIndex .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
bCANCEL .BS 1
bSTOP .BS 1
bPrintAll .BS 1
bLineNum .BS 1
bSuppress .BS 1
ArgIndex .BS 1
hFILE .BS 1
LineNum .BS 2
bPrintedBlankLine .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE BIN/CAT.S
ASM