mirror of
https://github.com/A2osX/A2osX.git
synced 2024-08-27 22:29:18 +00:00
299 lines
5.6 KiB
Plaintext
299 lines
5.6 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF bin/more
|
||
*--------------------------------------
|
||
.INB inc/macros.i
|
||
.INB inc/a2osx.i
|
||
.INB inc/kernel.i
|
||
.INB inc/mli.i
|
||
.INB inc/mli.e.i
|
||
*--------------------------------------
|
||
PG.SIZE .EQ 23
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR ZPBIN
|
||
ZS.START
|
||
ZPPtr1 .BS 2
|
||
ZPBufPtr .BS 2
|
||
ArgCount .BS 1
|
||
hFile .BS 1
|
||
LineCount .BS 1
|
||
LineNum .BS 2
|
||
bHelp .BS 1
|
||
bLineNum .BS 1
|
||
bPage .BS 1
|
||
bEscCodes .BS 1
|
||
ArgIndex .BS 1
|
||
hBuf .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 #0 S.PS.F.EVENT
|
||
.DA #0
|
||
.DA CS.END-CS.START Code Size (without Constants)
|
||
.DA DS.END-DS.START Data SegmentSize
|
||
.DA #64 Stack Size
|
||
.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.Init .DA MSG.Init
|
||
L.MSG.NUMLINE .DA MSG.NUMLINE
|
||
L.MSG.CRLF .DA MSG.CRLF
|
||
L.MSG.Pause .DA MSG.Pause
|
||
L.MSG.PauseErase .DA MSG.PauseErase
|
||
.DA 0
|
||
*--------------------------------------
|
||
CS.INIT clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN
|
||
.1 inc ArgCount
|
||
lda 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 >PUSHW L.MSG.USAGE
|
||
>PUSHBI 0
|
||
>SYSCALL PrintF
|
||
lda #E.SYN
|
||
sec
|
||
.9 rts
|
||
|
||
.3 ldy OptionVars-1,x
|
||
lda #$80
|
||
sta (pData),y
|
||
bra .1
|
||
.4 lda hFile
|
||
bne .99
|
||
>LDYA ZPPtr1
|
||
jsr CS.RUN.OPEN
|
||
bcs .9
|
||
bra .1 scan for any other args
|
||
.7 lda bHelp
|
||
beq .8
|
||
.71 jsr .99
|
||
lda #0
|
||
rts
|
||
|
||
.8 lda hFile
|
||
bne .80
|
||
ldy #S.PS.hStdIn
|
||
lda (pPS),y
|
||
tax
|
||
lda OF.Table.hFD-1,x
|
||
>SYSCALL GetMemPtr
|
||
>STYA ZPPtr1
|
||
|
||
lda (ZPPtr1)
|
||
cmp #S.FD.T.PIPE
|
||
bne .71
|
||
|
||
.80 >LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
>STYA ZPBufPtr
|
||
stx hBuf
|
||
|
||
>PUSHW L.MSG.Init
|
||
>PUSHBI 0
|
||
>SYSCALL PrintF
|
||
|
||
CS.RUN.LOOP jsr CS.RUN.GETLINE
|
||
bcs .9
|
||
.1 inc LineNum
|
||
bne .11
|
||
inc LineNum+1
|
||
.11 lda LineCount
|
||
bne .2
|
||
lda bPage
|
||
beq .2
|
||
lda #C.FF
|
||
>SYSCALL PutChar
|
||
.2 jsr CS.RUN.PRINT
|
||
|
||
inc LineCount
|
||
lda LineCount
|
||
cmp #PG.SIZE
|
||
bne CS.RUN.LOOP
|
||
stz LineCount
|
||
jsr CS.RUN.PAUSE
|
||
bcc CS.RUN.LOOP
|
||
.9 cmp #MLI.E.EOF
|
||
bne .99
|
||
lda #0 Exit with no Error
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.OPEN >PUSHYA
|
||
>PUSHBI O.RDONLY+O.TEXT
|
||
>PUSHBI S.FI.T.TXT
|
||
>PUSHWZ Aux type
|
||
|
||
>SYSCALL FOpen
|
||
bcs .9
|
||
sta hFile
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.RUN.PAUSE ldy #S.PS.hStdErr
|
||
lda (pPS),y
|
||
>PUSHA
|
||
>PUSHW L.MSG.Pause
|
||
>PUSHBI 0
|
||
>SYSCALL FPrintF
|
||
|
||
.10 jsr CS.RUN.GETC
|
||
bcs .99
|
||
|
||
cmp #'Q'
|
||
beq .9
|
||
cmp #'q'
|
||
beq .9
|
||
.3 cmp #C.SPACE
|
||
bne .4
|
||
jmp CS.RUN.ERASE
|
||
|
||
.4 cmp #C.CR
|
||
bne .10
|
||
|
||
jsr CS.RUN.ERASE
|
||
.40 jsr CS.RUN.GETLINE
|
||
bcc .5
|
||
cmp #MLI.E.EOF
|
||
beq .90
|
||
rts
|
||
.5 inc LineNum
|
||
bne .6
|
||
inc LineNum+1
|
||
|
||
.6 jsr CS.RUN.PRINT
|
||
|
||
bra CS.RUN.PAUSE
|
||
.9 jsr CS.RUN.ERASE
|
||
|
||
.90 lda #0
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.ERASE ldy #S.PS.hStdErr
|
||
lda (pPS),y
|
||
>PUSHA
|
||
>PUSHW L.MSG.PauseErase
|
||
>PUSHBI 0
|
||
>SYSCALL FPrintF
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.GETC lda hFile
|
||
bne .1
|
||
|
||
ldy #S.PS.hStdErr
|
||
lda (pPS),y
|
||
>SYSCALL GetC
|
||
rts
|
||
|
||
.1 >SYSCALL GetChar
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.GETLINE >PUSHWI 256
|
||
>PUSHW ZPBufPtr
|
||
lda hFile
|
||
bne .1
|
||
ldy #S.PS.hStdIn
|
||
lda (pPS),y
|
||
|
||
.1 >SYSCALL FGetS
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.PRINT lda bLineNum
|
||
bpl .1
|
||
|
||
>PUSHW L.MSG.NUMLINE
|
||
>PUSHW LineNum
|
||
>PUSHBI 2
|
||
>SYSCALL PrintF
|
||
bcs .9
|
||
.1 lda bEscCodes
|
||
bmi .2
|
||
|
||
>LDYA ZPBufPtr
|
||
>SYSCALL PutS
|
||
rts
|
||
|
||
.2 >PUSHW ZPBufPtr
|
||
>PUSHBI 0
|
||
>SYSCALL PrintF
|
||
bcs .9
|
||
|
||
>PUSHW L.MSG.CRLF
|
||
>PUSHBI 0
|
||
>SYSCALL PrintF
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.QUIT lda hBuf
|
||
beq .1
|
||
|
||
>SYSCALL FreeMem
|
||
|
||
.1 lda hFile
|
||
beq .2
|
||
|
||
>SYSCALL FClose
|
||
.2
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.DOEVENT sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.END
|
||
*--------------------------------------
|
||
OptionList >PSTR "NnHhPpSs"
|
||
OptionVars .DA #bLineNum,#bLineNum,#bHelp,#bHelp,#bPage,#bPage,#bEscCodes,#bEscCodes
|
||
*--------------------------------------
|
||
MSG.USAGE .AS "Usage : MORE <File>\r\n"
|
||
.AS " -H : This help screen\r\n"
|
||
.AS " -N : Number all output lines\r\n"
|
||
.AS " -P : Page mode, no scroll\r\n"
|
||
.AS " -S : Process ESC codes"
|
||
MSG.CRLF .AZ "\r\n"
|
||
MSG.Init .AZ "\e[?7l"
|
||
MSG.NUMLINE .AZ "%5D:"
|
||
MSG.Pause .AZ "\r\e[7m --- 'SPACE' for more, 'CR' one line, 'Q/q' to quit --- \e[0m"
|
||
MSG.PauseErase .AZ "\r\e[2K"
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR 0
|
||
DS.START
|
||
DS.END .ED
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE usr/src/bin/more.s
|
||
ASM
|