2021-07-04 21:09:08 +00:00
|
|
|
|
NEW
|
|
|
|
|
AUTO 3,1
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.LIST OFF
|
2023-10-18 05:41:12 +00:00
|
|
|
|
.OP 65C02
|
|
|
|
|
.OR $2000
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.TF bin/nl
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.INB inc/macros.i
|
|
|
|
|
.INB inc/a2osx.i
|
|
|
|
|
.INB inc/kernel.i
|
|
|
|
|
.INB inc/mli.i
|
|
|
|
|
.INB inc/mli.e.i
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.DUMMY
|
|
|
|
|
.OR ZPBIN
|
2021-07-04 21:09:08 +00:00
|
|
|
|
ZS.START
|
2023-06-02 20:31:09 +00:00
|
|
|
|
ArgIndex .BS 1
|
|
|
|
|
ArgPattern .BS 1
|
|
|
|
|
ZPPtr1 .BS 2
|
|
|
|
|
ZPBufPtr .BS 2
|
|
|
|
|
hFile .BS 1
|
|
|
|
|
hBuf .BS 1
|
|
|
|
|
char .BS 1
|
|
|
|
|
LineCount .BS 2
|
|
|
|
|
bPause .BS 1
|
|
|
|
|
bPipe .BS 1
|
|
|
|
|
bIsTTY .BS 1
|
|
|
|
|
bNewLine .BS 1
|
|
|
|
|
bDummy .BS 1
|
|
|
|
|
|
|
|
|
|
ZS.END .ED
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
* File Header (16 Bytes)
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
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 Segment Size
|
|
|
|
|
.DA #16 Stack Size
|
|
|
|
|
.DA #ZS.END-ZS.START Zero Page Size
|
|
|
|
|
.DA 0
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Relocation Table
|
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.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.LINENUM .DA MSG.LINENUM
|
|
|
|
|
.DA 0
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.INIT clc
|
|
|
|
|
rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.RUN stz bPipe
|
|
|
|
|
stz bIsTTY
|
|
|
|
|
stz bNewLine
|
|
|
|
|
inc bNewLine
|
|
|
|
|
jsr CS.RUN.ISATTY
|
|
|
|
|
jsr CS.RUN.CheckArgs
|
|
|
|
|
bcs CS.RUN.LOOP.RTS
|
|
|
|
|
|
|
|
|
|
stz LineCount
|
|
|
|
|
stz LineCount+1
|
|
|
|
|
inc LineCount
|
|
|
|
|
|
|
|
|
|
CS.RUN.LOOP lda bPipe If reading from pipe
|
|
|
|
|
bne .2 No ^C/^S handling
|
|
|
|
|
|
|
|
|
|
ldy #S.PS.hStdIn
|
|
|
|
|
lda (pPS),y
|
|
|
|
|
>SYSCALL FEOF
|
|
|
|
|
bcs .9 I/O Error
|
|
|
|
|
|
|
|
|
|
tay
|
|
|
|
|
bne .1 No char
|
|
|
|
|
|
|
|
|
|
>SYSCALL GetChar
|
|
|
|
|
bcs .9 I/O error
|
|
|
|
|
|
|
|
|
|
cmp #$03 Ctrl-C
|
|
|
|
|
beq .9
|
|
|
|
|
|
|
|
|
|
cmp #$13 Ctrl-S
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
lda bPause
|
|
|
|
|
eor #$ff
|
|
|
|
|
sta bPause
|
|
|
|
|
bne CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
.1 lda bPause
|
|
|
|
|
bne CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
.2 >SLEEP
|
|
|
|
|
|
|
|
|
|
lda hFile
|
|
|
|
|
>SYSCALL GetC
|
|
|
|
|
bcs .7
|
|
|
|
|
|
|
|
|
|
jsr CS.RUN.PRINTBYTE
|
|
|
|
|
bra CS.RUN.LOOP
|
|
|
|
|
|
|
|
|
|
.7 cmp #MLI.E.EOF
|
|
|
|
|
bne .9
|
|
|
|
|
|
|
|
|
|
.8 lda #0 Exit with no Error
|
|
|
|
|
|
|
|
|
|
.9 sec
|
|
|
|
|
CS.RUN.LOOP.RTS rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.RUN.CheckArgs
|
|
|
|
|
jsr CS.RUN.NextArg
|
|
|
|
|
bcs .4
|
|
|
|
|
|
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
cmp #'-'
|
|
|
|
|
beq .1
|
|
|
|
|
|
|
|
|
|
.11 lda hFile
|
|
|
|
|
bne .97
|
|
|
|
|
|
|
|
|
|
>LDYA ZPPtr1
|
|
|
|
|
jsr CS.RUN.OPEN
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
sta hFile
|
|
|
|
|
bra CS.RUN.CheckArgs
|
|
|
|
|
|
|
|
|
|
.1 ldy #1
|
|
|
|
|
lda (ZPPtr1),y
|
|
|
|
|
|
|
|
|
|
ldx #OptionList.Cnt-1
|
|
|
|
|
|
|
|
|
|
.2 cmp OptionList,x
|
|
|
|
|
beq .3
|
|
|
|
|
|
|
|
|
|
dex
|
|
|
|
|
bpl .2
|
|
|
|
|
|
|
|
|
|
bra .97
|
|
|
|
|
|
|
|
|
|
.3 txa
|
|
|
|
|
lsr
|
|
|
|
|
beq .98
|
|
|
|
|
|
|
|
|
|
tax
|
|
|
|
|
lda #$80
|
|
|
|
|
sta bDummy-1,x
|
|
|
|
|
bra CS.RUN.CheckArgs
|
|
|
|
|
|
|
|
|
|
.4 lda hFile
|
|
|
|
|
bne .80
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2023-06-02 20:31:09 +00:00
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
cmp #S.FD.T.PIPE
|
|
|
|
|
bne .97
|
|
|
|
|
|
2023-10-18 05:41:12 +00:00
|
|
|
|
sty hFile
|
2023-06-02 20:31:09 +00:00
|
|
|
|
inc bPipe
|
|
|
|
|
|
|
|
|
|
.80 >LDYAI 256
|
|
|
|
|
>SYSCALL GetMem
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
>STYA ZPBufPtr
|
|
|
|
|
stx hBuf
|
|
|
|
|
|
|
|
|
|
* clc
|
|
|
|
|
|
|
|
|
|
.9 rts
|
|
|
|
|
|
|
|
|
|
.97 lda #E.SYN
|
|
|
|
|
|
|
|
|
|
.98 pha
|
|
|
|
|
>PUSHW L.MSG.USAGE
|
|
|
|
|
>PUSHBI 0
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
pla
|
|
|
|
|
sec
|
|
|
|
|
rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.RUN.NextArg inc ArgIndex
|
|
|
|
|
lda ArgIndex
|
|
|
|
|
>SYSCALL ArgV
|
|
|
|
|
bcs .9
|
2021-07-04 21:09:08 +00:00
|
|
|
|
|
2023-06-02 20:31:09 +00:00
|
|
|
|
>STYA ZPPtr1
|
2021-07-04 21:09:08 +00:00
|
|
|
|
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.9 rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
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
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.RUN.ISATTY ldy #S.PS.hStdOut
|
|
|
|
|
lda (pPS),y
|
2023-10-18 05:41:12 +00:00
|
|
|
|
tay
|
|
|
|
|
ldx FILEs.hFD-1,y
|
|
|
|
|
ldy FDs.pLO-1,x
|
|
|
|
|
lda FDs.pHI-1,x
|
2023-06-02 20:31:09 +00:00
|
|
|
|
>STYA ZPPtr1
|
2023-10-18 05:41:12 +00:00
|
|
|
|
|
2023-06-02 20:31:09 +00:00
|
|
|
|
lda (ZPPtr1)
|
|
|
|
|
beq .9
|
|
|
|
|
|
|
|
|
|
inc bIsTTY
|
|
|
|
|
|
|
|
|
|
.9 rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.QUIT lda hFile
|
|
|
|
|
beq .1
|
|
|
|
|
|
|
|
|
|
>SYSCALL FClose
|
|
|
|
|
|
|
|
|
|
.1 lda hBuf
|
|
|
|
|
beq .8
|
|
|
|
|
|
|
|
|
|
>SYSCALL FreeMem
|
|
|
|
|
|
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.RUN.PRINTBYTE
|
|
|
|
|
pha
|
|
|
|
|
lda bNewLine
|
|
|
|
|
beq .2
|
|
|
|
|
|
|
|
|
|
stz bNewLine
|
|
|
|
|
>PUSHW L.MSG.LINENUM
|
|
|
|
|
>PUSHW LineCount
|
|
|
|
|
>PUSHBI 2
|
|
|
|
|
>SYSCALL PrintF
|
|
|
|
|
|
|
|
|
|
.2 pla
|
|
|
|
|
pha
|
|
|
|
|
>SYSCALL PutChar
|
|
|
|
|
pla
|
|
|
|
|
cmp #C.CR
|
|
|
|
|
bne .9
|
|
|
|
|
|
|
|
|
|
lda bIsTTY
|
|
|
|
|
beq .4
|
|
|
|
|
|
|
|
|
|
lda #C.LF
|
|
|
|
|
>SYSCALL PutChar
|
|
|
|
|
|
|
|
|
|
.4 inc bNewLine
|
|
|
|
|
inc LineCount
|
|
|
|
|
bne .9
|
|
|
|
|
|
|
|
|
|
inc LineCount+1
|
|
|
|
|
.9 rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
CS.DOEVENT sec
|
|
|
|
|
rts
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.END
|
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
OptionList .AS "x"
|
|
|
|
|
OptionList.Cnt .EQ *-OptionList
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
MSG.USAGE .CS "Usage : NL <File> or CMD|NL"
|
|
|
|
|
MSG.CRLF .CZ "\r\n"
|
|
|
|
|
MSG.LINENUM .CZ "%5D "
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
2023-06-02 20:31:09 +00:00
|
|
|
|
.DUMMY
|
|
|
|
|
.OR 0
|
2021-07-04 21:09:08 +00:00
|
|
|
|
DS.START
|
2023-06-02 20:31:09 +00:00
|
|
|
|
DS.END .ED
|
2021-07-04 21:09:08 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MAN
|
|
|
|
|
SAVE usr/src/bin/nl.s
|
|
|
|
|
ASM
|