mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-22 16:31:07 +00:00
407 lines
8.3 KiB
Plaintext
407 lines
8.3 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF /A2OSX.BOOT/DRV/UTHERNET2.DRV
|
||
*--------------------------------------
|
||
.INB INC/MACROS.I
|
||
.INB INC/A2OSX.I
|
||
.INB INC/A2OSX.API.I
|
||
.INB INC/KERNEL.I
|
||
*--------------------------------------
|
||
ZPTmpPTR .EQ ZPDRV
|
||
*--------------------------------------
|
||
DEVID .EQ $630E
|
||
*--------------------------------------
|
||
* WIZnet W5100 IO Registers
|
||
*--------------------------------------
|
||
W5100.MR .EQ $C084 Mode Register
|
||
W5100.MR.RST .EQ %10000000
|
||
W5100.MR.PB .EQ %00010000
|
||
W5100.MR.PPPOE .EQ %00001000
|
||
W5100.MR.AI .EQ %00000010
|
||
W5100.MR.IND .EQ %00000001
|
||
W5100.AR .EQ $C085 Memory Pointer
|
||
W5100.AR.GAR .EQ $0001
|
||
W5100.AR.SUBR .EQ $0005
|
||
W5100.AR.SHAR .EQ $0009
|
||
W5100.AR.IR .EQ $0015
|
||
W5100.AR.IMR .EQ $0016
|
||
W5100.AR.RTR .EQ $0017
|
||
W5100.AR.RCR .EQ $0019
|
||
W5100.AR.RMSR .EQ $001A
|
||
W5100.AR.TMSR .EQ $001B
|
||
W5100.AR.PATR .EQ $001C
|
||
W5100.AR.PTIMER .EQ $0028
|
||
W5100.AR.PMAGIC .EQ $0029
|
||
W5100.AR.UIPR .EQ $002A
|
||
W5100.AR.UPORT .EQ $002E
|
||
W5100.AR.S0.MR .EQ $0400
|
||
W5100.AR.S0.CR .EQ $0401
|
||
W5100.AR.S0.IR .EQ $0402
|
||
W5100.AR.S0.SR .EQ $0403
|
||
W5100.AR.S0.PORT .EQ $0404
|
||
W5100.AR.S0.DHAR .EQ $0406
|
||
W5100.AR.S0.DIPR .EQ $040C
|
||
W5100.AR.S0.DPORT .EQ $0410
|
||
W5100.AR.S0.MSSR .EQ $0412
|
||
W5100.AR.S0.PROTO .EQ $0414
|
||
W5100.AR.S0.TOS .EQ $0415
|
||
W5100.AR.S0.TTL .EQ $0416
|
||
W5100.AR.S0.TX.FSR .EQ $0420
|
||
W5100.AR.S0.TX.RD .EQ $0422
|
||
W5100.AR.S0.TX.WR .EQ $0424
|
||
W5100.AR.S0.RX.RSR .EQ $0426
|
||
W5100.AR.S0.RX.RD .EQ $0428
|
||
W5100.DR .EQ $C087
|
||
*--------------------------------------
|
||
ERRTNOFRAME .EQ 0
|
||
ERRNOBUFFER .EQ 1
|
||
ERRTIMEOUT .EQ 2
|
||
*--------------------------------------
|
||
* 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
|
||
.DA 0 End Of Reloc Table
|
||
*--------------------------------------
|
||
Dev.Detect sta hArgs
|
||
>LDYA L.MSG.DETECT
|
||
>SYSCALL SYS.SysScrPPSTRYA
|
||
|
||
ldx #$10
|
||
.1 stx DEVSLOTx0
|
||
>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
|
||
|
||
lda #DEVMGR.ERRNOHW
|
||
sec
|
||
rts
|
||
|
||
.3 lda hARGS
|
||
|
||
beq .4
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPTmpPTR
|
||
jsr DecodeMac
|
||
bcc .4
|
||
lda #DEVMGR.ERRNICL
|
||
sec
|
||
rts
|
||
|
||
.4 clc
|
||
rts
|
||
*--------------------------------------
|
||
DecodeMac lda (ZPTmpPTR)
|
||
cmp #12
|
||
bne .9
|
||
|
||
ldy #1
|
||
ldx #0
|
||
|
||
.1 lda (ZPTmpPTR),y
|
||
jsr Asc2NibbleA
|
||
bcs .9
|
||
|
||
asl
|
||
asl
|
||
asl
|
||
asl
|
||
sta MAC,x
|
||
|
||
iny
|
||
lda (ZPTmpPTR),y
|
||
jsr Asc2NibbleA
|
||
bcs .9
|
||
|
||
ora MAC,x
|
||
sta MAC,x
|
||
inx
|
||
iny
|
||
cpy #13
|
||
bne .1
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
Asc2NibbleA cmp #$30
|
||
bcc .9
|
||
cmp #$3A
|
||
bcs .1
|
||
and #$0F
|
||
clc
|
||
rts
|
||
.1 cmp #$41
|
||
bcc .9
|
||
cmp #$47
|
||
bcs .9
|
||
sbc #$36
|
||
clc
|
||
rts
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.END
|
||
MSG.DETECT >PSTRING "\nUtherNet II/W5100 Driver."
|
||
hArgs .BS 1
|
||
*--------------------------------------
|
||
* Device Header (16 Bytes)
|
||
*--------------------------------------
|
||
DEV.HEADER cld
|
||
jmp (DRV.CS.START,x)
|
||
.DA #S.DEV.F.SHARE+S.DEV.F.EVENT
|
||
DEV.HEADER.NAME >PSTRING "ETH1" NAME
|
||
.HS 00.00
|
||
.HS 00.00.00.00
|
||
*--------------------------------------
|
||
* Driver Code
|
||
*--------------------------------------
|
||
DRV.CS.START .DA OPEN
|
||
.DA GETEVENT
|
||
.DA $FFFF no COUT
|
||
.DA CLOSE
|
||
.DA GETINFO
|
||
.DA $FFFF no IRQ
|
||
.DA SEND
|
||
L.DEVINFO .DA DEVINFO
|
||
.DA 0 end or relocation
|
||
*--------------------------------------
|
||
* input :
|
||
* none
|
||
* output :
|
||
* CC on success
|
||
* CS on error
|
||
*--------------------------------------
|
||
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
|
||
*--------------------------------------
|
||
* input :
|
||
* pEvent
|
||
* output :
|
||
* CC no event
|
||
* CS event
|
||
*--------------------------------------
|
||
GETEVENT ldx DEVSLOTx0
|
||
>LDYAI PP.RxEvent
|
||
>STYA PacketPagePTR,x
|
||
>LDYA PacketPageDATA,x
|
||
and /PP.RxEvent.RxOK+PP.RxEvent.Brdcast+PP.RxEvent.IA
|
||
bne GETEVENT.RxOK
|
||
lda #ERRTNOFRAME
|
||
sec
|
||
rts
|
||
GETEVENT.RxOK
|
||
and /PP.RxEvent.Brdcast
|
||
beq .10
|
||
lda #$80
|
||
.10 ldy #S.EVT.DATAHI
|
||
sta (pEvent),y
|
||
>LDYA RTDATA,x discard RxStatus
|
||
>LDYA RTDATA,x get RxLength
|
||
>STYA FRAMELEN
|
||
>PUSHYA
|
||
>PUSHBI 0
|
||
>SYSCALL SYS.GetMem
|
||
bcs .99
|
||
>STYA ZPTmpPTR
|
||
txa
|
||
ldy #S.EVT.DATALO
|
||
sta (pEvent),y
|
||
ldy #S.EVT.DATAW1
|
||
lda FRAMELEN
|
||
sta (pEvent),y
|
||
iny
|
||
lda FRAMELEN+1
|
||
sta (pEvent),y
|
||
lda #S.EVT.F.NET+S.EVT.F.hMEM1
|
||
sta (pEvent)
|
||
ldy #0
|
||
ldx DEVSLOTx0
|
||
|
||
.1 lda RTDATA,x
|
||
sta (ZPTmpPTR),y
|
||
iny
|
||
bne .2
|
||
inc ZPTmpPTR+1
|
||
.2 jsr DecFrameLen
|
||
beq .8
|
||
lda RTDATA+1,x
|
||
sta (ZPTmpPTR),y
|
||
iny
|
||
bne .3
|
||
inc ZPTmpPTR+1
|
||
.3 jsr DecFrameLen
|
||
bne .1
|
||
.8 clc
|
||
rts
|
||
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
CLOSE jsr Reset
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* in:
|
||
* out:
|
||
* Y,A = BUFFER PTR
|
||
* CC on success
|
||
* CS on error
|
||
*--------------------------------------
|
||
GETINFO >LDYA L.DEVINFO
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* in:
|
||
* PULLW = FRAME PTR
|
||
* PULLW = FRAME LEN
|
||
* out:
|
||
* CC on success
|
||
* CS on error
|
||
*--------------------------------------
|
||
SEND >PULLW ZPTmpPTR
|
||
>PULLW FRAMELEN
|
||
|
||
ldy #11 Add Src MAC Address
|
||
ldx #5
|
||
.10 lda MAC,x
|
||
sta (ZPTmpPTR),y
|
||
dey
|
||
dex
|
||
bpl .10
|
||
|
||
ldx DEVSLOTx0
|
||
>LDYAI TxCMD.LID+TxCMD.TxStartFULL
|
||
>STYA TxCMD,x
|
||
>LDYA FRAMELEN
|
||
>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 SENDPREADY
|
||
bra *
|
||
lda #0
|
||
.2 dec
|
||
bne .2
|
||
dey
|
||
bne .1
|
||
bra *
|
||
lda #ERRTIMEOUT
|
||
sec
|
||
rts
|
||
.9 bra *
|
||
lda #ERRNOBUFFER
|
||
sec
|
||
rts
|
||
|
||
SENDPREADY ldy #0
|
||
.1 lda (ZPTmpPTR),y
|
||
sta RTDATA,x
|
||
iny
|
||
bne .2
|
||
inc ZPTmpPTR+1
|
||
.2 jsr DecFrameLen
|
||
beq .8
|
||
.3 lda (ZPTmpPTR),y
|
||
sta RTDATA+1,x
|
||
iny
|
||
bne .5
|
||
inc ZPTmpPTR+1
|
||
.5 jsr DecFrameLen
|
||
bne .1
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
* PRIVATE
|
||
*--------------------------------------
|
||
Reset ldx DEVSLOTx0
|
||
>LDYAI PP.SelfCTL
|
||
>STYA PacketPagePTR,x
|
||
>LDYAI PP.SelfCTL.LID+PP.SelfCTL.RESET
|
||
>STYA PacketPageDATA,x
|
||
rts
|
||
*--------------------------------------
|
||
DecFrameLen lda FRAMELEN
|
||
bne .1
|
||
lda FRAMELEN+1
|
||
beq .8
|
||
dec FRAMELEN+1
|
||
.1 dec FRAMELEN
|
||
lda #1 Make something NZ
|
||
.8 rts
|
||
*--------------------------------------
|
||
DRV.CS.END
|
||
*--------------------------------------
|
||
DEVSLOTx0 .BS 1
|
||
FRAMELEN .BS 2
|
||
*--------------------------------------
|
||
DEVINFO .DA #S.DEVINFO.TYPE.NET
|
||
MAC .BS 6
|
||
LINK.STATUS .BS 1
|
||
LINK.SPEED .BS 1 SPEED/DUPLEX
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE DRV/UTHERNET2.DRV.S
|
||
ASM
|