A2osX/DRV/UTHER2.AI.DRV.S.txt

503 lines
9.3 KiB
Plaintext
Raw Normal View History

2016-04-04 20:48:20 +00:00
PR#3
PREFIX /A2OSX.SRC
NEW
2016-04-04 20:48:20 +00:00
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/DRV/UTHER2.AI.DRV
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
.INB /A2OSX.DEV/INC/LIBTCPIP.I
2016-04-04 20:48:20 +00:00
*--------------------------------------
ZPTmpPTR .EQ ZPDRV
*--------------------------------------
.INB DRV/X.NET.W5100.S
2016-04-04 20:48:20 +00:00
*--------------------------------------
* 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
2016-04-04 20:48:20 +00:00
>LDYA L.MSG.DETECT
>SYSCALL CPrintFYA
2016-04-04 20:48:20 +00:00
2016-04-07 21:05:38 +00:00
ldx #$10+$88
2016-04-04 20:48:20 +00:00
.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
2016-04-07 21:05:38 +00:00
bcc .1 #$108 ?
2016-04-04 20:48:20 +00:00
>LDYA L.MSG.DETECT.KO
>SYSCALL CPrintFYA
2016-04-04 20:48:20 +00:00
lda #DEVMGR.ERRNOHW
sec
rts
2016-04-07 21:05:38 +00:00
.3 stx DEVSLOTx8
2016-04-04 20:48:20 +00:00
>LDYA ARGS
>STYA ZPTmpPTR
lda (ZPTmpPTR)
2016-04-04 20:48:20 +00:00
bne .4
2016-04-04 20:48:20 +00:00
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 GetMemPtrA
2016-04-04 20:48:20 +00:00
>STYA ZPTmpPTR
jsr DecodeMac
bcc .8
lda #DEVMGR.ERRICL
sec
rts
.8 >PUSHW L.DEV.HEADER.NAME
>LDYA L.MSG.DETECT.OK
>SYSCALL CPrintFYA
2016-04-04 20:48:20 +00:00
clc
rts
*--------------------------------------
.INB DRV/X.NET.DRV.S
*--------------------------------------
CS.END
MSG.DETECT >CSTR "UtherNet2/W5100 Driver (ARP OffLoad).\n"
MSG.DETECT.OK >CSTR "UtherNet2/W5100 Installed As Device : %S\n"
MSG.DETECT.KO >CSTR "Hardware Not Found.\n"
Args .BS 2
2016-04-04 20:48:20 +00:00
*--------------------------------------
* Device Header (16 Bytes)
*--------------------------------------
DEV.HEADER cld
jmp (DRV.CS.START,x)
2016-06-07 06:10:18 +00:00
.HS 00
2016-04-04 20:48:20 +00:00
.DA #S.DEV.F.SHARE+S.DEV.F.EVENT
DEV.HEADER.NAME >PSTR "ETH1" NAME
2016-06-07 06:10:18 +00:00
.HS 00
2016-04-04 20:48:20 +00:00
.HS 00.00.00.00
*--------------------------------------
* Driver Code
*--------------------------------------
DRV.CS.START .DA OPEN
.DA GETEVENT
2016-04-07 21:05:38 +00:00
.DA COUT
2016-04-04 20:48:20 +00:00
.DA CLOSE
.DA GETINFO
2016-04-07 21:05:38 +00:00
.DA IRQ
2016-04-04 20:48:20 +00:00
.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 GAR
ldy #8 GAR,SUBR
.1 stz W5100.DR,x
dey
bne .1
* >AR.SELECT SHAR
ldy #0
.2 lda MAC,y
sta W5100.DR,x
iny
cpy #6
bne .2
* >AR.SELECT SIPR
ldy #4
.3 stz W5100.DR,x
dey
bne .3
2016-04-04 20:48:20 +00:00
>AR.SELECT RMSR
lda #3 8k,0k,0k,0k
sta W5100.DR,x ...for Socket RX Buffers
sta W5100.DR,x ...for Socket TX Buffers
2016-04-04 20:48:20 +00:00
clc
rts
*--------------------------------------
2016-04-07 21:05:38 +00:00
GETEVENT ldx DEVSLOTx8
2016-04-04 20:48:20 +00:00
>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
2016-04-07 21:05:38 +00:00
COUT
IRQ
2016-04-04 20:48:20 +00:00
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
ldy #0
.10 lda W5100.DR,x
sta RX.IP,y
iny
cpy #4
bne .10
2016-04-04 20:48:20 +00:00
2016-04-05 15:46:11 +00:00
ldy W5100.DR,x get RX.Size HI
sty RXTX.Size+1
2016-04-04 20:48:20 +00:00
lda W5100.DR,x get RX.Size LO
sta RXTX.Size
clc
2016-04-05 15:46:11 +00:00
adc #S.IP
2016-04-04 20:48:20 +00:00
pha
tya
2016-04-05 15:46:11 +00:00
adc /S.IP
2016-04-04 20:48:20 +00:00
ply
2016-04-05 15:46:11 +00:00
>PUSHYA
2016-04-04 20:48:20 +00:00
>PUSHBI 0
>SYSCALL GetMem
2016-04-04 20:48:20 +00:00
bcs GETEVENT.Err
>STYA ZPTmpPTR
txa
ldy #S.EVT.DATALO
sta (pEvent),y
2016-04-07 21:05:38 +00:00
lda #S.EVT.F.NET+S.EVT.F.hMEM1
sta (pEvent)
2016-04-05 15:46:11 +00:00
lda RXTX.Size
sta (ZPTmpPTR)
2016-04-07 21:05:38 +00:00
eor #$ff
sta Counter
2016-04-04 20:48:20 +00:00
ldy #1
2016-04-05 15:46:11 +00:00
lda RXTX.Size+1
sta (ZPTmpPTR),y
2016-04-07 21:05:38 +00:00
eor #$ff
sta Counter+1
lda RXTX.Size
clc
adc #6 Header Size
sta Offset
lda RXTX.Size+1
adc #0
sta Offset+1
2016-04-04 20:48:20 +00:00
ldy #S.IP.DST+3
ldx #3
.1 lda RX.IP,x
sta (ZPTmpPTR),y
dey
dex
bpl .1
2016-04-07 21:05:38 +00:00
ldx DEVSLOTx8
2016-04-04 20:48:20 +00:00
ldy #S.IP
.2 inc Counter
2016-04-04 20:48:20 +00:00
bne .3
inc Counter+1
beq .8
2016-04-04 20:48:20 +00:00
.3 lda W5100.DR,x
sta (ZPTmpPTR),y
iny
2016-04-04 20:48:20 +00:00
bne .2
inc ZPTmpPTR+1
2016-04-04 20:48:20 +00:00
bne .2
.8 >AR.SELECT S0.RX.RD
ldy W5100.DR,x Get HI
lda W5100.DR,x Get LO
clc
adc Offset
2016-04-04 20:48:20 +00:00
pha save LO
tya
adc Offset+1
pha
2016-04-04 20:48:20 +00:00
>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
ldy #S.IP.DST
lda (ZPTmpPTR),y
.81 iny
and (ZPTmpPTR),y
cpy #S.IP.DST+3
bne .81 if EQ, CS
inc $ff = Broadcast ??
beq .82
clc not a broadcast
.82 lda #$00
ror
ldy #S.EVT.DATAHI
sta (pEvent),y
* clc cleared by ROR
2016-04-04 20:48:20 +00:00
rts
*--------------------------------------
CLOSE jsr Reset
clc
rts
*--------------------------------------
GETINFO >LDYA L.DEVINFO
clc
rts
*--------------------------------------
SEND >PULLW ZPTmpPTR
lda (ZPTmpPTR)
sec
sbc #S.IP-2
2016-04-04 20:48:20 +00:00
sta RXTX.Size
2016-04-07 21:05:38 +00:00
eor #$ff
sta Counter
ldy #1
2016-04-04 20:48:20 +00:00
lda (ZPTmpPTR),y
sbc /S.IP-2
2016-04-04 20:48:20 +00:00
sta RXTX.Size+1
2016-04-07 21:05:38 +00:00
eor #$ff
sta Counter+1
2016-04-04 20:48:20 +00:00
2016-04-07 21:05:38 +00:00
ldx DEVSLOTx8
2016-04-04 20:48:20 +00:00
>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
stz W5100.DR,x
2016-04-04 20:48:20 +00:00
* >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
ldy #S.IP
2016-04-07 21:05:38 +00:00
.2 inc Counter
2016-04-04 20:48:20 +00:00
bne .3
2016-04-07 21:05:38 +00:00
inc Counter+1
beq .8
2016-04-04 20:48:20 +00:00
2016-04-07 21:05:38 +00:00
.3 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
2016-04-04 20:48:20 +00:00
bne .2
2016-04-07 21:05:38 +00:00
inc ZPTmpPTR+1
2016-04-04 20:48:20 +00:00
bne .2
2016-04-07 21:05:38 +00:00
.8 >AR.SELECT S0.TX.WR
2016-04-04 20:48:20 +00:00
clc
lda Offset
adc RXTX.Size
pha save LO
lda Offset+1
adc RXTX.Size+1
sta W5100.DR,x write HI
pla
sta W5100.DR,x write LO
2016-04-07 21:05:38 +00:00
>AR.SELECT S0.CR
2016-04-04 20:48:20 +00:00
lda #$20 SEND
sta W5100.DR,x
clc
rts
*--------------------------------------
SETIPCFG >STYA ZPTmpPTR
2016-04-04 20:48:20 +00:00
2016-04-07 21:05:38 +00:00
ldx DEVSLOTx8
2016-04-04 20:48:20 +00:00
>AR.SELECT S0.CR
lda #$10 CLOSE
2016-04-04 20:48:20 +00:00
sta W5100.DR,x
.10 >AR.SELECT S0.SR
lda W5100.DR,x
bne .10 CLOSED ???
2016-04-04 20:48:20 +00:00
>AR.SELECT GAR
2016-04-04 20:48:20 +00:00
ldy #S.IPCFG.GW
2016-04-04 20:48:20 +00:00
.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
2016-04-04 20:48:20 +00:00
.2 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.MASK+4
bne .2
>AR.SELECT SIPR
2016-04-04 20:48:20 +00:00
ldy #S.IPCFG.IP
.3 lda (ZPTmpPTR),y
2016-04-04 20:48:20 +00:00
sta W5100.DR,x
iny
cpy #S.IPCFG.IP+4
bne .3
2016-04-04 20:48:20 +00:00
>AR.SELECT S0.MR
lda #W5100.AR.S0.MR.IPRAW+W5100.AR.S0.MR.MF
sta W5100.DR,x
* >AR.SELECT S0.CR Implicit, next to S0.MR
2016-04-04 20:48:20 +00:00
lda #1 OPEN
sta W5100.DR,x
clc
rts
*--------------------------------------
2016-04-07 21:05:38 +00:00
Reset ldx DEVSLOTx8
2016-04-04 20:48:20 +00:00
lda #W5100.MR.RST
sta W5100.MR,x
lda $C019 we can use VBL as we are not on //c
.1 eor $C019
bpl .1
lda $C019
.2 eor $C019
bpl .2
2016-04-04 20:48:20 +00:00
rts
*--------------------------------------
DRV.CS.END
2016-04-07 21:05:38 +00:00
DEVSLOTx8 .BS 1
2016-04-04 20:48:20 +00:00
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+S.DEVINFO.NET.FLAGS.IPOFFLOAD
2016-04-04 20:48:20 +00:00
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