A2osX/BIN/MORE.S.txt

320 lines
5.5 KiB
Plaintext
Raw Normal View History

2018-11-05 16:28:40 +00:00
NEW
2019-07-24 05:53:09 +00:00
AUTO 3,1
2018-11-05 16:28:40 +00:00
.LIST OFF
.OP 65C02
.OR $2000
2020-02-14 16:32:52 +00:00
.TF bin/more
*/-------------------------------------
* # MORE
* Displays content of specified file
* Input pipe allowed
* ## Arguments
* **-H**
* Displays help screen
* **-N**
* Number all output lines
* **-P**
* Page mode, no scroll
* ## Return Value
*\-------------------------------------
2020-07-21 05:26:07 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/kernel.i
.INB inc/mli.i
.INB inc/mli.e.i
2018-11-05 16:28:40 +00:00
*--------------------------------------
2019-01-16 14:37:21 +00:00
PG.SIZE .EQ 23
2018-11-21 16:01:38 +00:00
*--------------------------------------
2018-12-20 20:59:48 +00:00
.DUMMY
.OR ZPBIN
ZS.START
2020-08-17 20:47:31 +00:00
ZPPtr1 .BS 2
2018-12-20 20:59:48 +00:00
ZPBufPtr .BS 2
2019-05-12 20:45:11 +00:00
ArgCount .BS 1
hFile .BS 1
LineCount .BS 1
LineNum .BS 2
bHelp .BS 1
bLineNum .BS 1
bPage .BS 1
ArgIndex .BS 1
hBuf .BS 1
2020-08-17 20:47:31 +00:00
ZS.END .ED
2018-11-05 16:28:40 +00:00
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2018-12-20 20:59:48 +00:00
.DA #0 S.PS.F.EVENT
2018-11-05 16:28:40 +00:00
.DA #0
2018-12-20 20:59:48 +00:00
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
2019-05-12 20:45:11 +00:00
.DA #64 Stack Size
2018-12-20 20:59:48 +00:00
.DA #ZS.END-ZS.START Zero Page Size
2018-11-05 16:28:40 +00:00
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
2018-11-05 16:28:40 +00:00
.1 .DA CS.INIT
.DA CS.RUN
2023-10-18 05:41:12 +00:00
.DA CS.DOEVENT
2018-11-05 16:28:40 +00:00
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
2019-02-14 16:38:36 +00:00
L.MSG.Init .DA MSG.Init
2018-11-28 11:39:33 +00:00
L.MSG.NUMLINE .DA MSG.NUMLINE
2018-11-06 16:31:13 +00:00
L.MSG.Pause .DA MSG.Pause
2018-11-21 16:01:38 +00:00
L.MSG.PauseErase .DA MSG.PauseErase
2018-11-05 16:28:40 +00:00
.DA 0
*--------------------------------------
CS.RUN inc ArgCount
2019-05-12 20:45:11 +00:00
lda ArgCount
2018-11-05 16:28:40 +00:00
>SYSCALL ArgV
bcs .7
2018-11-05 16:28:40 +00:00
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
2020-12-15 13:23:22 +00:00
2023-10-18 05:41:12 +00:00
ldy #1
2018-11-05 16:28:40 +00:00
lda (ZPPtr1),y
beq .99
2018-11-05 16:28:40 +00:00
.1 ldx #OptionVars-OptionList-1
2018-11-05 16:28:40 +00:00
.2 cmp OptionList,x
beq .3
2020-12-15 13:23:22 +00:00
2018-11-05 16:28:40 +00:00
dex
bpl .2
2023-10-18 05:41:12 +00:00
.99 >LDYA L.MSG.USAGE
>SYSCALL PutS
2018-11-05 16:28:40 +00:00
lda #E.SYN
sec
.9 rts
2020-02-14 16:32:52 +00:00
.3 lda OptionVars,x
tax
sec
ror $0,x
2023-10-18 05:41:12 +00:00
iny
lda (ZPPtr1),y
bne .1
2023-10-18 05:41:12 +00:00
bra CS.RUN
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
.4 lda hFile
2018-11-05 16:28:40 +00:00
bne .99
2020-12-15 13:23:22 +00:00
2018-11-06 16:31:13 +00:00
>LDYA ZPPtr1
2018-11-05 16:28:40 +00:00
jsr CS.RUN.OPEN
bcs .9
2020-12-15 13:23:22 +00:00
bra CS.RUN scan for any other args
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
.7 lda bHelp
2018-11-05 16:28:40 +00:00
beq .8
2020-12-15 13:23:22 +00:00
2019-03-12 14:41:55 +00:00
.71 jsr .99
2018-11-05 16:28:40 +00:00
lda #0
rts
2019-05-12 20:45:11 +00:00
.8 lda hFile
2019-03-12 14:41:55 +00:00
bne .80
2020-12-15 13:23:22 +00:00
2019-03-12 14:41:55 +00:00
ldy #S.PS.hStdIn
lda (pPS),y
2023-10-18 05:41:12 +00:00
tay
ldx FILEs.hFD-1,y
lda FDs.pLO-1,x
sta ZPPtr1
lda FDs.pHI-1,x
sta ZPPtr1+1
2020-12-15 13:23:22 +00:00
2019-03-12 14:41:55 +00:00
lda (ZPPtr1)
2023-10-18 05:41:12 +00:00
2019-03-12 14:41:55 +00:00
cmp #S.FD.T.PIPE
bne .71
2023-10-18 05:41:12 +00:00
sty hFile
2019-03-12 14:41:55 +00:00
.80 >LDYAI 256
2018-11-05 16:28:40 +00:00
>SYSCALL GetMem
bcs .9
2020-12-15 13:23:22 +00:00
2018-11-05 16:28:40 +00:00
>STYA ZPBufPtr
2019-05-12 20:45:11 +00:00
stx hBuf
2020-02-14 16:32:52 +00:00
>PUSHW L.MSG.Init
2019-02-14 16:38:36 +00:00
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2023-10-18 05:41:12 +00:00
*--------------------------------------
2019-02-25 07:39:19 +00:00
CS.RUN.LOOP jsr CS.RUN.GETLINE
2019-02-25 16:36:09 +00:00
bcs .9
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
.1 inc LineNum
bne .11
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
inc LineNum+1
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
.11 lda LineCount
2019-02-25 16:36:09 +00:00
bne .2
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
lda bPage
2019-02-25 16:36:09 +00:00
beq .2
2020-12-15 13:23:22 +00:00
2018-11-06 16:31:13 +00:00
lda #C.FF
2020-08-17 20:47:31 +00:00
>SYSCALL PutChar
2020-12-15 13:23:22 +00:00
2019-02-25 16:36:09 +00:00
.2 jsr CS.RUN.PRINT
2019-05-12 20:45:11 +00:00
inc LineCount
lda LineCount
2018-11-21 16:01:38 +00:00
cmp #PG.SIZE
2019-02-25 16:36:09 +00:00
bne CS.RUN.LOOP
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
stz LineCount
2018-11-21 16:01:38 +00:00
jsr CS.RUN.PAUSE
2019-02-25 16:36:09 +00:00
bcc CS.RUN.LOOP
2020-12-15 13:23:22 +00:00
2019-02-25 16:36:09 +00:00
.9 cmp #MLI.E.EOF
bne .99
2020-12-15 13:23:22 +00:00
2018-11-05 16:28:40 +00:00
lda #0 Exit with no Error
2020-12-15 13:23:22 +00:00
2019-02-25 16:36:09 +00:00
.99 sec
rts
2018-11-05 16:28:40 +00:00
*--------------------------------------
2020-02-14 16:32:52 +00:00
CS.RUN.OPEN >PUSHYA
2018-11-05 16:28:40 +00:00
>PUSHBI O.RDONLY+O.TEXT
2020-02-14 16:32:52 +00:00
>PUSHBI S.FI.T.TXT
>PUSHWZ Aux type
2023-10-18 05:41:12 +00:00
2018-11-05 16:28:40 +00:00
>SYSCALL FOpen
2018-11-06 16:31:13 +00:00
bcs .9
2019-05-12 20:45:11 +00:00
sta hFile
2018-11-05 16:28:40 +00:00
.9 rts
*--------------------------------------
2020-02-14 07:21:56 +00:00
CS.RUN.PAUSE ldy #S.PS.hStdErr
2018-11-21 16:01:38 +00:00
lda (pPS),y
2020-02-14 07:21:56 +00:00
>PUSHA
>PUSHW L.MSG.Pause
>SYSCALL FPutS
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.10 ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL GetC
2019-02-25 14:47:31 +00:00
bcs .99
2018-11-21 16:01:38 +00:00
cmp #'Q'
beq .9
2020-12-15 13:23:22 +00:00
2018-11-28 11:39:33 +00:00
cmp #'q'
beq .9
2020-12-15 13:23:22 +00:00
2018-11-21 16:01:38 +00:00
.3 cmp #C.SPACE
bne .4
2020-12-15 13:23:22 +00:00
2018-11-21 16:01:38 +00:00
jmp CS.RUN.ERASE
.4 cmp #C.CR
bne .10
jsr CS.RUN.ERASE
2020-12-15 13:23:22 +00:00
2019-02-25 14:47:31 +00:00
.40 jsr CS.RUN.GETLINE
2019-01-16 14:37:21 +00:00
bcc .5
2020-12-15 13:23:22 +00:00
2019-01-16 14:37:21 +00:00
cmp #MLI.E.EOF
2019-05-16 15:51:19 +00:00
beq .90
2020-12-15 13:23:22 +00:00
2019-05-16 15:51:19 +00:00
rts
2019-05-12 20:45:11 +00:00
.5 inc LineNum
bne .6
2020-12-15 13:23:22 +00:00
2019-05-12 20:45:11 +00:00
inc LineNum+1
.6 jsr CS.RUN.PRINT
2018-11-21 16:01:38 +00:00
bra CS.RUN.PAUSE
.9 jsr CS.RUN.ERASE
2019-02-25 14:47:31 +00:00
2019-01-16 14:37:21 +00:00
.90 lda #0
2018-11-21 16:01:38 +00:00
.99 sec
2019-10-03 06:25:27 +00:00
rts
2018-11-21 16:01:38 +00:00
*--------------------------------------
2020-02-14 07:21:56 +00:00
CS.RUN.ERASE ldy #S.PS.hStdErr
2018-11-21 16:01:38 +00:00
lda (pPS),y
2020-02-14 07:21:56 +00:00
>PUSHA
>PUSHW L.MSG.PauseErase
>SYSCALL FPutS
2018-11-21 16:01:38 +00:00
rts
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.RUN.GETLINE >PUSHB hFile
2023-10-18 05:41:12 +00:00
2020-12-23 14:54:57 +00:00
>PUSHW ZPBufPtr
>PUSHWI 256
>SYSCALL FGetS
2019-05-17 05:51:01 +00:00
rts
2018-11-21 16:01:38 +00:00
*--------------------------------------
2019-05-12 20:45:11 +00:00
CS.RUN.PRINT lda bLineNum
bpl .1
2018-11-05 16:28:40 +00:00
2020-02-14 16:32:52 +00:00
>PUSHW L.MSG.NUMLINE
2019-05-12 20:45:11 +00:00
>PUSHW LineNum
2018-11-21 16:01:38 +00:00
>PUSHBI 2
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2018-11-28 11:39:33 +00:00
bcs .9
2020-12-15 13:23:22 +00:00
.1 >LDYA ZPBufPtr
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
.9 rts
2018-11-05 16:28:40 +00:00
*--------------------------------------
2019-05-12 20:45:11 +00:00
CS.QUIT lda hBuf
2018-11-05 16:28:40 +00:00
beq .1
>SYSCALL FreeMem
2020-08-17 20:47:31 +00:00
.1 lda hFile
2018-11-06 16:31:13 +00:00
beq .2
2018-11-05 16:28:40 +00:00
>SYSCALL FClose
2019-10-03 06:25:27 +00:00
.2
.8
CS.INIT clc
2018-11-05 16:28:40 +00:00
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.END
*--------------------------------------
OptionList .AS "NnHhPp"
OptionVars .DA #bLineNum,#bLineNum,#bHelp,#bHelp,#bPage,#bPage
2018-11-05 16:28:40 +00:00
*--------------------------------------
MSG.USAGE .CS "Usage : MORE <File>\r\n"
.CS " -H : This help screen\r\n"
.CS " -N : Number all output lines\r\n"
.CZ " -P : Page mode, no scroll\r\n"
MSG.Init .CZ "\e[?7l"
MSG.NUMLINE .CZ "%5D:"
MSG.Pause .CZ "\r\e[7m --- 'SPACE' for more, 'CR' one line, 'Q/q' to quit --- \e[0m"
MSG.PauseErase .CZ "\r\e[2K"
2018-11-05 16:28:40 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
2020-08-17 20:47:31 +00:00
DS.END .ED
2018-11-05 16:28:40 +00:00
*--------------------------------------
MAN
2020-07-21 05:26:07 +00:00
SAVE usr/src/bin/more.s
2018-11-05 16:28:40 +00:00
ASM