UTHERNET2.DRV.S.txt: complete rewrite

This commit is contained in:
Rémy GIBERT 2016-04-04 22:48:20 +02:00
parent 0716922067
commit 35a42a30c4
2 changed files with 554 additions and 129 deletions

514
DRV/UTHER2.AI.DRV.S.txt Normal file
View File

@ -0,0 +1,514 @@
PR#3
PREFIX /A2OSX.SRC
LOMEM $C00
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/DRV/UTHER2.AI.DRV
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBTCPIP.I
*--------------------------------------
ZPTmpPTR .EQ ZPDRV
*--------------------------------------
.MA AR.SELECT
lda /W5100.AR.]1
sta W5100.AR,x
lda #W5100.AR.]1
sta W5100.AR+1,x
.EM
*--------------------------------------
* 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.SIPR .EQ $000F
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
*--------------------------------------
RX.BASE .EQ $4000
TX.BASE .EQ $6000
RXTX.MASK .EQ $1FFF
*--------------------------------------
* 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 sta hArgs
>LDYA L.MSG.DETECT
>SYSCALL SYS.PSTROutYA
ldx #$10
.1 lda #W5100.MR.RST
sta W5100.MR,x
lda #W5100.MR.AI+W5100.MR.IND
sta W5100.MR,x
lda W5100.MR,x
cmp #W5100.MR.AI+W5100.MR.IND
bne .2
>AR.SELECT RTR Double Check with RTR default value...
lda W5100.DR,x Get RTR HI
cmp /2000
bne .2
lda W5100.DR,x Get RTR LO
cmp #2000
beq .3
.2 inc DEV.HEADER.NAME+4
txa
clc
adc #$10
tax
bpl .1 #$80 ?
>LDYA L.MSG.DETECT.KO
>SYSCALL SYS.PSTROutYA
lda #DEVMGR.ERRNOHW
sec
rts
.3 stx DEVSLOTx0
lda hARGS
bne .4
lda #$00
sta MAC
lda #$08
sta MAC+1
lda #$DC
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 >SYSCALL SYS.GetMemPtrA
>STYA ZPTmpPTR
jsr DecodeMac
bcc .8
lda #DEVMGR.ERRICL
sec
rts
.8 >LDYA L.MSG.DETECT.OK
>SYSCALL SYS.PSTROutYA
>LDYA L.DEV.HEADER.NAME
>SYSCALL SYS.PSTROutYA
lda #13
>SYSCALL SYS.COutA
clc
rts
*--------------------------------------
.INB DRV/X.NET.DRV.S
*--------------------------------------
CS.END
MSG.DETECT >PSTRING "UtherNetII/W5100 Driver.\n"
MSG.DETECT.OK >PSTRING "UtherNetII/W5100 Installed As Device : "
MSG.DETECT.KO >PSTRING "Hardware Not Found.\n"
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
.DA SETIPCFG
L.DEVINFO .DA DEVINFO
.DA 0 end or relocation
*--------------------------------------
OPEN jsr Reset
lda #W5100.MR.AI+W5100.MR.IND
sta W5100.MR,x
>AR.SELECT RMSR
lda #3 8k
sta W5100.DR,x ...for Socket0 RX Buffer
sta W5100.DR,x ...for Socket0 TX Buffer
clc
rts
*--------------------------------------
GETEVENT ldx DEVSLOTx0
>AR.SELECT S0.RX.RSR
lda W5100.DR,x get the received size HI
ora W5100.DR,x LO
bne GETEVENT.RxOK
lda #ERR.DEV.NOFRAME
GETEVENT.Err sec
rts
GETEVENT.RxOK >AR.SELECT S0.RX.RD
lda W5100.DR,x get the received ptr HI
ldy W5100.DR,x get the received ptr LO
and /RXTX.MASK
ora /RX.BASE
sta W5100.AR,x
tya
sta W5100.AR+1,x
lda W5100.DR,x
sta RX.IP
lda W5100.DR,x
sta RX.IP+1
lda W5100.DR,x
sta RX.IP+2
lda W5100.DR,x
sta RX.IP+3
lda W5100.DR,x get RX.Size HI
sta RXTX.Size+1
tay
lda W5100.DR,x get RX.Size LO
sta RXTX.Size
clc
adc #S.IP-2
sta FRAMELEN
pha
tya
adc /S.IP-2
sta FRAMELEN+1
ply
iny
bne .10
inc
.10 iny
bne .11
inc
.11 >PUSHYA
>PUSHBI 0
>SYSCALL SYS.GetMem
bcs GETEVENT.Err
>STYA ZPTmpPTR
txa
ldy #S.EVT.DATALO
sta (pEvent),y
lda FRAMELEN
sta (ZPTmpPTR)
ldy #1
lda FRAMELEN+1
sta (ZPTmpPTR),y
lda #S.EVT.F.NET+S.EVT.F.hMEM1
sta (pEvent)
ldy #S.IP.DST+3
ldx #3
.1 lda RX.IP,x
sta (ZPTmpPTR),y
dey
dex
bpl .1
sec
lda #0
sbc RXTX.Size
sta Counter
lda #0
sbc RXTX.Size+1
sta Counter+1
ldx DEVSLOTx0
ldy #S.IP
.2 lda W5100.DR,x
sta (ZPTmpPTR),y
iny
bne .3
inc ZPTmpPTR+1
.3 inc Counter
bne .2
inc Counter+1
bne .2
.8 >AR.SELECT S0.RX.RD
ldy W5100.DR,x Get HI
lda W5100.DR,x Get LO
clc
adc RXTX.Size
pha save LO
tya
adc RXTX.Size+1
and /RXTX.MASK
ora /RX.BASE
pha save HI
>AR.SELECT S0.RX.RD
pla
sta W5100.DR,x write HI
pla
sta W5100.DR,x write LO
>AR.SELECT S0.CR
lda #$40 RECV
sta W5100.DR,x
clc
rts
*--------------------------------------
CLOSE jsr Reset
clc
rts
*--------------------------------------
GETINFO >LDYA L.DEVINFO
clc
rts
*--------------------------------------
SEND >PULLW ZPTmpPTR
ldy #S.IP.TOTAL.LENGTH+1
lda (ZPTmpPTR),y
sta RXTX.Size
dey
lda (ZPTmpPTR),y
sta RXTX.Size+1
ldx DEVSLOTx0
>AR.SELECT S0.TX.FSR
lda W5100.DR,x get send size HI
ldy W5100.DR,x LO
cpy RXTX.Size
sbc RXTX.Size+1
bcs SEND.READY
lda #ERR.DEV.NOBUFFER
sec
rts
SEND.READY >AR.SELECT S0.DIPR
ldy #S.IP.DST
.1 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IP.DST+4
bne .1
>AR.SELECT S0.PROTO
ldy #S.IP.PROTOCOL
lda (ZPTmpPTR),y
sta W5100.DR,x
* >AR.SELECT S0.TOS
lda #0
sta W5100.DR,x
* >AR.SELECT S0.TTL
lda #K.IP.TTL
sta W5100.DR,x
>AR.SELECT S0.TX.WR
lda W5100.DR,x Get HI
ldy W5100.DR,x Get LO
and /RXTX.MASK
ora /TX.BASE
sta W5100.AR,x Write HI
sta Offset+1
tya
sta W5100.AR+1,x Write LO
sta Offset
sec
lda #0
sbc RXTX.Size
sta Counter
lda #0
sbc RXTX.Size+1
sta Counter+1
ldy #S.IP
.2 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
bne .3
inc ZPTmpPTR+1
.3 inc Counter
bne .2
inc Counter+1
bne .2
>AR.SELECT S0.TX.WR
clc
lda Offset
adc RXTX.Size
pha save LO
lda Offset+1
adc RXTX.Size+1
and /RXTX.MASK
ora /TX.BASE
sta W5100.DR,x write HI
pla
sta W5100.DR,x write LO
.8 >AR.SELECT S0.CR
lda #$20 SEND
sta W5100.DR,x
clc
rts
*--------------------------------------
SETIPCFG >PULLW ZPTmpPTR
ldx DEVSLOTx0
>AR.SELECT S0.CR
lda #10 CLOSE
sta W5100.DR,x
>AR.SELECT S0.MR
lda #3 IPRAW
sta W5100.DR,x
>AR.SELECT GAR
ldy #S.IPCFG.GW
.1 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.GW+4
bne .1
* >AR.SELECT SUBR Implicit, next to GAR
ldy #S.IPCFG.MASK
.2 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.MASK+4
bne .2
* >AR.SELECT SHAR Implicit, next to SUBR
ldy #0
.3 lda MAC,y
sta W5100.DR,x
iny
cpy #6
bne .3
* >AR.SELECT SIPR Implicit, next to SHAR
ldy #S.IPCFG.IP
.4 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.IP+4
bne .4
>AR.SELECT S0.CR
lda #1 OPEN
sta W5100.DR,x
clc
rts
*--------------------------------------
Reset ldx DEVSLOTx0
lda #W5100.MR.RST
sta W5100.MR,x
rts
*--------------------------------------
DRV.CS.END
DEVSLOTx0 .BS 1
FRAMELEN .BS 2
RX.IP .BS 4
RXTX.Size .BS 2
Counter .BS 2
Offset .BS 2
*--------------------------------------
DEVINFO .DA #S.DEVINFO.TYPE.NET
DEVFLAGS .DA #S.DEVINFO.NET.FLAGS.ARPOFFLOAD
MAC .BS 6
LINK.STATUS .DA #S.DEVINFO.NET.STATUS.OK+S.DEVINFO.NET.STATUS.FD+S.DEVINFO.NET.STATUS.100
MAN
SAVE DRV/UTHER2.AI.DRV.S
ASM

View File

@ -189,7 +189,7 @@ DRV.CS.START .DA OPEN
.DA GETINFO
.DA $FFFF no IRQ
.DA SEND
.DA SETIPCFG
.DA $FFFF no SETIPCFG
L.DEVINFO .DA DEVINFO
.DA 0 end or relocation
*--------------------------------------
@ -203,20 +203,34 @@ OPEN jsr Reset
sta W5100.DR,x ...for Socket0 RX Buffer
sta W5100.DR,x ...for Socket0 TX Buffer
>AR.SELECT S0.MR
lda #4 MACRAW
sta W5100.DR,x
>AR.SELECT SHAR Implicit, next to SUBR
ldy #0
.1 lda MAC,y
sta W5100.DR,x
iny
cpy #6
bne .1
>AR.SELECT S0.CR
lda #1 OPEN
sta W5100.DR,x
clc
rts
*--------------------------------------
GETEVENT ldx DEVSLOTx0
>AR.SELECT S0.CR
lda W5100.DR,x
bne .9
>AR.SELECT S0.RX.RSR
lda W5100.DR,x get the received size HI
ora W5100.DR,x LO
bne GETEVENT.RxOK
.9 lda #ERR.DEV.NOFRAME
lda #ERR.DEV.NOFRAME
GETEVENT.Err sec
rts
@ -229,29 +243,14 @@ GETEVENT.RxOK >AR.SELECT S0.RX.RD
tya
sta W5100.AR+1,x
lda W5100.DR,x
sta RX.IP
lda W5100.DR,x
sta RX.IP+1
lda W5100.DR,x
sta RX.IP+2
lda W5100.DR,x
sta RX.IP+3
lda W5100.DR,x get RX.Size HI
sta RXTX.Size+1
tay
pha
lda W5100.DR,x get RX.Size LO
sta RXTX.Size
tay
pla
clc
adc #S.IP-2
sta FRAMELEN
pha
tya
adc /S.IP-2
sta FRAMELEN+1
ply
iny
bne .10
inc
@ -268,25 +267,16 @@ GETEVENT.RxOK >AR.SELECT S0.RX.RD
ldy #S.EVT.DATALO
sta (pEvent),y
lda FRAMELEN
lda RXTX.Size
sta (ZPTmpPTR)
ldy #1
lda FRAMELEN+1
lda RXTX.Size+1
sta (ZPTmpPTR),y
lda #S.EVT.F.NET+S.EVT.F.hMEM1
sta (pEvent)
ldy #S.IP.DST+3
ldx #3
.1 lda RX.IP,x
sta (ZPTmpPTR),y
dey
dex
bpl .1
sec
lda #0
sbc RXTX.Size
@ -297,8 +287,8 @@ GETEVENT.RxOK >AR.SELECT S0.RX.RD
ldx DEVSLOTx0
ldy #S.IP
.2
ldy #2
.2 lda W5100.DR,x
sta (ZPTmpPTR),y
iny
bne .3
@ -307,7 +297,7 @@ GETEVENT.RxOK >AR.SELECT S0.RX.RD
.3 inc Counter
bne .2
inc Counter+1
bne .3
bne .2
.8 >AR.SELECT S0.RX.RD
ldy W5100.DR,x Get HI
@ -343,10 +333,9 @@ GETINFO >LDYA L.DEVINFO
*--------------------------------------
SEND >PULLW ZPTmpPTR
ldy #S.IP.TOTAL.LENGTH+1
lda (ZPTmpPTR),y
lda (ZPTmpPTR)
sta RXTX.Size
dey
ldy #1
lda (ZPTmpPTR),y
sta RXTX.Size+1
@ -363,36 +352,16 @@ SEND >PULLW ZPTmpPTR
sec
rts
SEND.READY >AR.SELECT S0.DIPR
ldy #S.IP.DST
.1 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IP.DST+4
bne .1
>AR.SELECT S0.PROTO
ldy #S.IP.PROTOCOL
lda (ZPTmpPTR),y
sta W5100.DR,x
* >AR.SELECT S0.TOS
lda #0
sta W5100.DR,x
* >AR.SELECT S0.TTL
lda #K.IP.TTL
sta W5100.DR,x
>AR.SELECT S0.TX.WR
SEND.READY >AR.SELECT S0.TX.WR
lda W5100.DR,x Get HI
ldy W5100.DR,x Get LO
and /RXTX.MASK
ora /TX.BASE
sta W5100.AR,x Write HI
sta Offset+1
tya
sta W5100.AR+1,x Write LO
sta Offset
sec
lda #0
@ -403,7 +372,7 @@ SEND.READY >AR.SELECT S0.DIPR
sbc RXTX.Size+1
sta Counter+1
ldy #S.IP
ldy #2
.2 lda (ZPTmpPTR),y
sta W5100.DR,x
@ -418,18 +387,16 @@ SEND.READY >AR.SELECT S0.DIPR
bne .2
>AR.SELECT S0.TX.WR
ldy W5100.DR,x Get HI
lda W5100.DR,x Get LO
clc
lda Offset
adc RXTX.Size
pha save LO
tya
lda Offset+1
adc RXTX.Size+1
and /RXTX.MASK
ora /TX.BASE
pha save HI
>AR.SELECT S0.TX.WR
pla
sta W5100.DR,x write HI
pla
sta W5100.DR,x write LO
@ -440,61 +407,6 @@ SEND.READY >AR.SELECT S0.DIPR
clc
rts
*--------------------------------------
SETIPCFG >PULLW ZPTmpPTR
ldx DEVSLOTx0
>AR.SELECT S0.CR
lda #10 CLOSE
sta W5100.DR,x
>AR.SELECT S0.MR
lda #3 IPRAW
sta W5100.DR,x
>AR.SELECT GAR
ldy #S.IPCFG.GW
.1 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.GW+4
bne .1
* >AR.SELECT SUBR Implicit, next to GAR
ldy #S.IPCFG.MASK
.2 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.MASK+4
bne .2
* >AR.SELECT SHAR Implicit, next to SUBR
ldy #0
.3 lda MAC,y
sta W5100.DR,x
iny
cpy #6
bne .3
* >AR.SELECT SIPR Implicit, next to SHAR
ldy #S.IPCFG.IP
.4 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.IP+4
bne .4
>AR.SELECT S0.CR
lda #1 OPEN
sta W5100.DR,x
clc
rts
*--------------------------------------
Reset ldx DEVSLOTx0
lda #W5100.MR.RST
sta W5100.MR,x
@ -502,13 +414,12 @@ Reset ldx DEVSLOTx0
*--------------------------------------
DRV.CS.END
DEVSLOTx0 .BS 1
FRAMELEN .BS 2
RX.IP .BS 4
RXTX.Size .BS 2
Counter .BS 2
Offset .BS 2
*--------------------------------------
DEVINFO .DA #S.DEVINFO.TYPE.NET
DEVFLAGS .DA #S.DEVINFO.NET.FLAGS.ARPOFFLOAD
DEVFLAGS .DA #0
MAC .BS 6
LINK.STATUS .DA #S.DEVINFO.NET.STATUS.OK+S.DEVINFO.NET.STATUS.FD+S.DEVINFO.NET.STATUS.100
MAN