A2osX/BIN/OD.S.txt

350 lines
8.8 KiB
Plaintext
Raw Normal View History

NEW
AUTO 3,1
2023-05-16 16:53:52 +00:00
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/od
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +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-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
.DUMMY
.OR ZPBIN
2021-07-03 04:04:38 +00:00
ZS.START
2023-05-16 16:53:52 +00:00
ArgIndex .BS 1
ArgPattern .BS 1
ZPPtr1 .BS 2
ZPBufPtr .BS 2
hFile .BS 1
hBuf .BS 1
char .BS 1
ByteCount .BS 3
bPause .BS 1
bPipe .BS 1
bIsTTY .BS 1
bTemp .BS 1
bDummy .BS 1
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
ZS.END .ED
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
* File Header (16 Bytes)
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +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-03 04:04:38 +00:00
*--------------------------------------
* Relocation Table
*--------------------------------------
2023-05-16 16:53:52 +00:00
.1 .DA CS.INIT
.DA CS.RUN
2023-10-18 05:41:12 +00:00
.DA CS.DOEVENT
2023-05-16 16:53:52 +00:00
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.CRLF .DA MSG.CRLF
L.MSG.OFFSET .DA MSG.OFFSET
L.MSG.HEXBYTE .DA MSG.HEXBYTE
.DA 0
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.INIT clc
rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.RUN stz bPipe
stz bIsTTY
jsr CS.RUN.ISATTY
jsr CS.RUN.CheckArgs
bcs CS.RUN.LOOP.RTS
stz ByteCount
stz ByteCount+1
stz ByteCount+2
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
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
lda bPause
eor #$ff
sta bPause
2023-10-18 05:41:12 +00:00
bne CS.RUN.LOOP
2023-05-16 16:53:52 +00:00
.1 lda bPause
bne CS.RUN.LOOP
2023-05-16 16:53:52 +00:00
.2 >SLEEP
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
lda hFile
>SYSCALL GetC
bcs .7
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
jsr CS.RUN.PRINTBYTE
bra CS.RUN.LOOP
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
.7 cmp #MLI.E.EOF
bne .9
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
jsr CS.RUN.FINISHUP
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
.8 lda #0 Exit with no Error
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
.9 sec
CS.RUN.LOOP.RTS rts
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.RUN.CheckArgs
jsr CS.RUN.NextArg
bcs .4
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
lda (ZPPtr1)
cmp #'-'
beq .1
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.11 lda hFile
bne .97
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
>LDYA ZPPtr1
jsr CS.RUN.OPEN
bcs .9
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
sta hFile
bra CS.RUN.CheckArgs
2023-10-18 05:41:12 +00:00
.1 ldy #1
2023-05-16 16:53:52 +00:00
lda (ZPPtr1),y
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
ldx #OptionList.Cnt-1
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.2 cmp OptionList,x
beq .3
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
dex
bpl .2
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
bra .97
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.3 txa
lsr
beq .98
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
tax
lda #$80
2023-10-18 05:41:12 +00:00
sta bDummy-1,x
2023-05-16 16:53:52 +00:00
bra CS.RUN.CheckArgs
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.4 lda hFile
bne .80
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +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
2023-05-16 16:53:52 +00:00
lda (ZPPtr1)
cmp #S.FD.T.PIPE
bne .97
2023-10-18 05:41:12 +00:00
sty hFile
inc bPipe
2023-05-16 16:53:52 +00:00
.80 >LDYAI 256
>SYSCALL GetMem
bcs .9
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
>STYA ZPBufPtr
stx hBuf
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
* clc
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.9 rts
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.97 lda #E.SYN
2023-10-18 05:41:12 +00:00
2023-05-16 16:53:52 +00:00
.98 pha
>PUSHW L.MSG.USAGE
>PUSHBI 0
>SYSCALL PrintF
pla
sec
rts
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.RUN.NextArg inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs .9
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
>STYA ZPPtr1
2021-07-03 04:04:38 +00:00
2023-05-16 16:53:52 +00:00
.9 rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +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-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.RUN.ISATTY ldy #S.PS.hStdOut
lda (pPS),y
tax
2023-10-18 05:41:12 +00:00
lda FILEs.hFD-1,x
2023-05-16 16:53:52 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1
lda (ZPPtr1)
beq .9
inc bIsTTY
.9 rts
*--------------------------------------
2023-05-16 16:53:52 +00:00
CS.QUIT lda hFile
beq .1
>SYSCALL FClose
.1 lda hBuf
beq .8
>SYSCALL FreeMem
.8 clc
rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
CS.RUN.PRINTBYTE
pha Char is in A
lda ByteCount Divisible by 16
and #$0f
sta bTemp
bne .2
>PUSHW L.MSG.OFFSET Print offset
lda ByteCount+2
>PUSHA
lda ByteCount+1
>PUSHA
lda ByteCount
>PUSHA
>PUSHBI 3
>SYSCALL PrintF
.2 ldy bTemp Offset mod 16
pla Character
pha
sta (ZPBufPtr),y
2023-10-18 05:41:12 +00:00
>PUSHW L.MSG.HEXBYTE
pla
>PUSHA
>PUSHBI 1
>SYSCALL PrintF
.6 inc ByteCount
bne .7
inc ByteCount+1
bne .7
inc ByteCount+2
.7 lda bTemp
cmp #$0f
bne .9
jsr CS.RUN.PRINTASCII
.9 rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
CS.RUN.PRINTASCII
lda #'>'
>SYSCALL PutChar
ldy #$00
.7 lda (ZPBufPtr),y
phy
cmp #$7f
bcs .75 Character >= $7f
cmp #C.SPACE
bcc .75 Character < Space
bra .8
.75 lda #'.'
.8 >SYSCALL PutChar
ply
cpy bTemp
beq .85
iny
bra .7
.85 lda #'<'
>SYSCALL PutChar
lda #C.CR
>SYSCALL PutChar
lda bIsTTY
beq .9
lda #C.LF
>SYSCALL PutChar
.9 rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
CS.RUN.FINISHUP
lda ByteCount
and #$0f
bne .1
rts
.1 pha
lda #' '
>SYSCALL PutChar
lda #' '
>SYSCALL PutChar
2023-10-18 05:41:12 +00:00
lda #' '
>SYSCALL PutChar
pla
inc
cmp #$10
bne .1
.2 jsr CS.RUN.PRINTASCII
rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
CS.DOEVENT sec
rts
2021-07-03 04:04:38 +00:00
*--------------------------------------
CS.END
*--------------------------------------
2023-05-16 16:53:52 +00:00
OptionList .AS "x"
OptionList.Cnt .EQ *-OptionList
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
MSG.USAGE .CS "Usage : OD <File> or CMD|OD"
MSG.CRLF .CZ "\r\n"
MSG.OFFSET .CZ "%h%h%h "
MSG.HEXBYTE .CZ "%h "
2021-07-03 04:04:38 +00:00
*--------------------------------------
2023-05-16 16:53:52 +00:00
.DUMMY
.OR 0
2021-07-03 04:04:38 +00:00
DS.START
2023-05-16 16:53:52 +00:00
DS.END .ED
2021-07-03 04:04:38 +00:00
*--------------------------------------
MAN
SAVE usr/src/bin/od.s
ASM