NEW AUTO 3,1 .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 ZS.START ZPPtr1 .BS 2 ZPBufPtr .BS 2 ByteIndex .BS 1 ArgCount .BS 1 FileCount .BS 1 bPause .BS 1 bDummy .BS 1 bStdout .BS 1 ArgIndex .BS 1 hBuf .BS 1 hFile .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 *-------------------------------------- * 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.INIT .DA MSG.INIT .DA 0 *-------------------------------------- CS.INIT clc rts *-------------------------------------- CS.RUN .1 stz bStdout 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 lsr bcc CS.RUN.LOOP lda Nod.Table.hFD-2,x >SYSCALL GetMemPtr >STYA ZPPtr1 lda (ZPPtr1) beq CS.RUN.LOOP cmp #S.FD.T.PIPE beq CS.RUN.LOOP lda #$ff sta bStdout >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! >STYA ZPPtr1 lda (ZPPtr1) cmp #'-' beq .1 An option, skip... >LDYA ZPPtr1 jsr CS.RUN.OPEN .90 bcs .9 sta hFile .2 lda hFile >SYSCALL GetC bcs .7 pha >SYSCALL PutChar pla cmp #C.CR bne CS.RUN.LOOP lda bStdout beq CS.RUN.LOOP lda #C.LF >SYSCALL PutChar bra CS.RUN.LOOP .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 >PUSHYA >PUSHBI O.RDONLY+O.TEXT >PUSHBI S.FI.T.TXT >PUSHWZ Aux type >SYSCALL FOpen rts *-------------------------------------- CS.QUIT lda hBuf beq CS.RUN.CLOSE >SYSCALL FreeMem CS.RUN.CLOSE lda hFile beq .8 stz hFile >SYSCALL FClose .8 clc rts *-------------------------------------- CS.DOEVENT sec rts *-------------------------------------- CS.END *-------------------------------------- OptionList .AS "x" OptionList.Cnt .EQ *-OptionList OptionVars .DA #bDummy *-------------------------------------- MSG.USAGE .AS "Usage : CAT File1 [File2...]" MSG.CRLF .AZ "\r\n" MSG.INIT .AZ "\e[?7h" Enable Line Wrap *-------------------------------------- .DUMMY .OR 0 DS.START DS.END .ED *-------------------------------------- MAN SAVE usr/src/bin/cat.s ASM