mirror of
https://github.com/A2osX/A2osX.git
synced 2024-08-14 13:29:02 +00:00
377 lines
7.6 KiB
Plaintext
377 lines
7.6 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF /A2OSX.BOOT/DRV/UTHERNET.DRV
|
||
*--------------------------------------
|
||
.INB /A2OSX.DEV/INC/MACROS.I
|
||
.INB /A2OSX.DEV/INC/A2OSX.I
|
||
.INB /A2OSX.DEV/INC/LIBTCPIP.I
|
||
.INB /A2OSX.DEV/INC/PRODOS.I
|
||
*--------------------------------------
|
||
ZPTmpPTR .EQ ZPDRV
|
||
*--------------------------------------
|
||
*S.DEVINFO.NET.FLAGS.ARPOFFLOAD .EQ %00000001
|
||
*S.DEVINFO.NET.FLAGS.IPOFFLOAD .EQ %00000010
|
||
*S.DEVINFO.NET.MAC .EQ 2
|
||
*S.DEVINFO.NET.STATUS .EQ 8
|
||
*S.DEVINFO.NET.STATUS.OK .EQ $80
|
||
*S.DEVINFO.NET.STATUS.FD .EQ $40
|
||
*S.DEVINFO.NET.STATUS.10 .EQ $01
|
||
*S.DEVINFO.NET.STATUS.100 .EQ $02
|
||
*S.DEVINFO.NET.STATUS.1000 .EQ $03
|
||
*--------------------------------------
|
||
.INB DRV/X.NET.8900A.S
|
||
*--------------------------------------
|
||
* File Header (16 Bytes)
|
||
*--------------------------------------
|
||
CS.START cld
|
||
jmp Dev.Detect cld,jmp abs=DRV
|
||
.DA #$61 6502,Level 1 (65c02)
|
||
.DA #1 DRV Layout Version 1
|
||
.DA 0
|
||
.DA CS.END-CS.START Code Length
|
||
.DA DEV.HEADER-CS.START Device Header Offset
|
||
.DA DRV.CS.START-CS.START Driver Code Offset
|
||
.DA DRV.CS.END-DRV.CS.START Drv Code Length
|
||
*--------------------------------------
|
||
* Relocation Table
|
||
*--------------------------------------
|
||
L.MSG.DETECT .DA MSG.DETECT
|
||
L.MSG.DETECT.OK .DA MSG.DETECT.OK
|
||
L.MSG.DETECT.KO .DA MSG.DETECT.KO
|
||
L.DEV.HEADER.NAME .DA DEV.HEADER.NAME
|
||
.DA 0 End Of Reloc Table
|
||
*--------------------------------------
|
||
Dev.Detect >STYA ARGS
|
||
>LDYA L.MSG.DETECT
|
||
>SYSCALL CPrintFYA
|
||
|
||
ldx #$10
|
||
.1 >LDYAI PP.ID
|
||
>STYA PacketPagePTR,x
|
||
>LDYA PacketPageDATA,x
|
||
cpy #DEVID
|
||
bne .2
|
||
cmp /DEVID
|
||
beq .3
|
||
|
||
.2 inc DEV.HEADER.NAME+4
|
||
txa
|
||
clc
|
||
adc #$10
|
||
tax
|
||
cpx #$80
|
||
bne .1
|
||
|
||
>LDYA L.MSG.DETECT.KO
|
||
>SYSCALL CPrintFYA
|
||
|
||
lda #MLI.ERR.NODEV
|
||
sec
|
||
rts
|
||
|
||
.3 stx DEVSLOTx0
|
||
|
||
>LDYA ARGS
|
||
>STYA ZPTmpPTR
|
||
lda (ZPTmpPTR)
|
||
bne .4
|
||
|
||
lda #$00
|
||
sta MAC
|
||
lda #$0E
|
||
sta MAC+1
|
||
lda #$3A
|
||
sta MAC+2
|
||
lda A2osX.RANDOM16
|
||
eor A2osX.TIMER16
|
||
sta MAC+3
|
||
eor A2osX.RANDOM16+1
|
||
sta MAC+4
|
||
eor A2osX.TIMER16+1
|
||
sta MAC+5
|
||
bra .8
|
||
|
||
.4 jsr DecodeMac
|
||
bcc .8
|
||
lda #DEVMGR.ERRICL
|
||
sec
|
||
rts
|
||
|
||
.8 >PUSHW L.DEV.HEADER.NAME
|
||
>LDYA L.MSG.DETECT.OK
|
||
>SYSCALL CPrintFYA
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
.INB DRV/X.NET.DRV.S
|
||
*--------------------------------------
|
||
CS.END
|
||
MSG.DETECT >CSTR "UtherNet/CS8900A Driver.\n"
|
||
MSG.DETECT.OK >CSTR "UtherNet/CS8900A Installed As Device : %S\n"
|
||
MSG.DETECT.KO >CSTR "Hardware Not Found.\n"
|
||
ARGS .BS 2
|
||
*--------------------------------------
|
||
* Device Header (16 Bytes)
|
||
*--------------------------------------
|
||
DEV.HEADER .DA DRV.CS.START
|
||
.DA #S.DEV.S.BLOCK+S.DEV.S.WRITE+S.DEV.S.READ
|
||
DEV.HEADER.NAME .DA #4
|
||
.AS "ETHx" NAME
|
||
*--------------------------------------
|
||
* Driver Code
|
||
*--------------------------------------
|
||
DRV.CS.START .DA STATUS
|
||
.DA READBLOCK
|
||
.DA WRITEBLOCK
|
||
.DA BADCALL
|
||
.DA BADCALL
|
||
.DA BADCALL
|
||
.DA OPEN
|
||
.DA CLOSE
|
||
.DA BADCALL
|
||
.DA BADCALL
|
||
L.DEVSTAT .DA DEVSTAT
|
||
.DA 0 end or relocation
|
||
*--------------------------------------
|
||
BADCALL lda #MLI.ERR.BADCALL
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
STATUS lda #S.DEVINFO.NET.STATUS.10
|
||
sta LINK.STATUS
|
||
|
||
ldx DEVSLOTx0
|
||
>LDYAI PP.LineST
|
||
>STYA PacketPagePTR,x
|
||
>LDYA PacketPageDATA,x
|
||
tya
|
||
and #PP.LineST.LinkOK
|
||
bne .1
|
||
lda LINK.STATUS
|
||
ora #S.DEVINFO.NET.STATUS.OK
|
||
sta LINK.STATUS
|
||
|
||
.1 >LDYAI PP.TestCTL
|
||
>STYA PacketPagePTR,x
|
||
>LDYA PacketPageDATA,x
|
||
and /PP.TestCTL.FDX
|
||
bne .2
|
||
lda LINK.STATUS
|
||
ora #S.DEVINFO.NET.STATUS.FD
|
||
sta LINK.STATUS
|
||
|
||
.2 >LDYA L.DEVSTAT
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
READBLOCK ldx DEVSLOTx0
|
||
>LDYAI PP.RxEvent
|
||
>STYA PacketPagePTR,x
|
||
>LDYA PacketPageDATA,x
|
||
and /PP.RxEvent.RxOK+PP.RxEvent.Brdcast+PP.RxEvent.IA
|
||
bne READBLOCK.RxOK
|
||
lda #ERR.DEV.NOFRAME
|
||
READBLOCK.Err sec
|
||
rts
|
||
|
||
READBLOCK.RxOK and /PP.RxEvent.Brdcast
|
||
beq .10
|
||
lda #$80
|
||
.10 ldy #S.EVT.DATAHI
|
||
sta (pEvent),y
|
||
>LDYA RTDATA,x discard RxStatus
|
||
|
||
lda RTDATA+1,x get RxLength
|
||
sta Size+1
|
||
pha
|
||
lda RTDATA,x
|
||
sta Size
|
||
clc
|
||
adc #2
|
||
tay
|
||
pla
|
||
bcc .11
|
||
inc
|
||
|
||
.11 >PUSHYA Size+2
|
||
>PUSHBI 0
|
||
>SYSCALL GetMem
|
||
bcs READBLOCK.Err
|
||
>STYA ZPTmpPTR
|
||
txa
|
||
ldy #S.EVT.DATALO
|
||
sta (pEvent),y
|
||
|
||
lda #S.EVT.F.NET+S.EVT.F.hMEM1
|
||
sta (pEvent)
|
||
|
||
lda Size
|
||
sta (ZPTmpPTR)
|
||
eor #$ff
|
||
sta Counter
|
||
ldy #1
|
||
lda Size+1
|
||
sta (ZPTmpPTR),y
|
||
eor #$ff
|
||
sta Counter+1
|
||
|
||
iny
|
||
|
||
ldx DEVSLOTx0
|
||
|
||
.1 inc Counter
|
||
bne .12
|
||
inc Counter+1
|
||
beq .8
|
||
|
||
.12 lda RTDATA,x
|
||
sta (ZPTmpPTR),y
|
||
iny
|
||
bne .2
|
||
inc ZPTmpPTR+1
|
||
|
||
.2 inc Counter
|
||
bne .21
|
||
inc Counter+1
|
||
beq .8
|
||
|
||
.21 lda RTDATA+1,x
|
||
sta (ZPTmpPTR),y
|
||
iny
|
||
bne .1
|
||
inc ZPTmpPTR+1
|
||
bne .1
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
WRITEBLOCK >PULLW ZPTmpPTR
|
||
|
||
lda (ZPTmpPTR)
|
||
sta Size
|
||
eor #$ff
|
||
sta Counter
|
||
ldy #1
|
||
lda (ZPTmpPTR),y
|
||
sta Size+1
|
||
eor #$ff
|
||
sta Counter+1
|
||
|
||
ldx DEVSLOTx0
|
||
>LDYAI PP.TxCMD.LID+PP.TxCMD.TxStartFULL
|
||
>STYA TxCMD,x
|
||
>LDYA Size
|
||
>STYA TxLength,x
|
||
>LDYAI PP.BusST
|
||
>STYA PacketPagePTR,x
|
||
|
||
ldy #16
|
||
.1 lda PacketPageDATA,x
|
||
and #PP.BusST.TxBidErr
|
||
bne .9
|
||
lda PacketPageDATA+1,x
|
||
and /PP.BusST.Rdy4TxNOW
|
||
bne WRITEBLOCK.1
|
||
lda #0
|
||
|
||
.2 dec
|
||
bne .2
|
||
|
||
dey
|
||
bne .1
|
||
|
||
.9 lda #ERR.DEV.NOBUFFER
|
||
sec
|
||
rts
|
||
|
||
WRITEBLOCK.1 ldy #S.ETH.SRCMAC+5
|
||
ldx #5
|
||
.10 lda MAC,x
|
||
sta (ZPTmpPTR),y
|
||
dey
|
||
dex
|
||
bpl .10
|
||
|
||
ldx DEVSLOTx0
|
||
ldy #2
|
||
|
||
.1 inc Counter
|
||
bne .11
|
||
inc Counter+1
|
||
beq .8
|
||
|
||
.11 lda (ZPTmpPTR),y
|
||
sta RTDATA,x
|
||
iny
|
||
bne .2
|
||
inc ZPTmpPTR+1
|
||
|
||
.2 inc Counter
|
||
bne .21
|
||
inc Counter+1
|
||
beq .8
|
||
|
||
.21 lda (ZPTmpPTR),y
|
||
sta RTDATA+1,x
|
||
iny
|
||
bne .1
|
||
inc ZPTmpPTR+1
|
||
bne .1
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
OPEN jsr Reset
|
||
>LDYAI PP.RxCTL
|
||
>STYA PacketPagePTR,x
|
||
>LDYAI PP.RxCTL.LID+PP.RxCTL.RxOKA+PP.RxCTL.IA+PP.RxCTL.BroadcastA
|
||
>STYA PacketPageDATA,x
|
||
|
||
>LDYAI PP.MAC
|
||
>STYA PacketPagePTR,x
|
||
>LDYA MAC
|
||
>STYA PacketPageDATA,x
|
||
>LDYAI PP.MAC+2
|
||
>STYA PacketPagePTR,x
|
||
>LDYA MAC+2
|
||
>STYA PacketPageDATA,x
|
||
>LDYAI PP.MAC+4
|
||
>STYA PacketPagePTR,x
|
||
>LDYA MAC+4
|
||
>STYA PacketPageDATA,x
|
||
|
||
>LDYAI PP.LineCTL
|
||
>STYA PacketPagePTR,x
|
||
>LDYAI PP.LineCTL.LID+PP.LineCTL.SerRxOn+PP.LineCTL.SerTxOn+PP.LineCTL.Auto
|
||
>STYA PacketPageDATA,x
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CLOSE jsr Reset
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Reset ldx DEVSLOTx0
|
||
>LDYAI PP.SelfCTL
|
||
>STYA PacketPagePTR,x
|
||
>LDYAI PP.SelfCTL.LID+PP.SelfCTL.RESET
|
||
>STYA PacketPageDATA,x
|
||
rts
|
||
DRV.CS.END
|
||
*--------------------------------------
|
||
DEVSLOTx0 .BS 1
|
||
Size .BS 2
|
||
Counter .BS 2
|
||
DEVSTAT .BS S.DEVSTAT
|
||
MAC .BS 6
|
||
LINK.STATUS .BS 1 OK/DUPLEX/SPEED
|
||
MAN
|
||
SAVE DRV/UTHERNET.DRV.S
|
||
ASM
|