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

523 lines
9.5 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BUILD/DRV/UTHER2.AI.DRV
*--------------------------------------
.INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I
.INB /A2OSX.BUILD/INC/MLI.ERR.I
.INB /A2OSX.BUILD/INC/NET.I
.INB /A2OSX.BUILD/INC/NET.W5100.I
.INB /A2OSX.BUILD/INC/LIBTCPIP.I
*--------------------------------------
ZPTmpPTR .EQ ZPDRV
RXTX.Size .EQ ZPDRV+2
Counter .EQ ZPDRV+4
Offset .EQ ZPDRV+6
RX.IP .EQ ZPDRV+8
*--------------------------------------
* 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 #$70+$88
ldy #7
.1 lda A2osX.SLOTS,y IO based detection, avoid scanning in Disk Controller IO!!!!
bne .2
lda #W5100.MR.RST
sta W5100.MR,x
lda #0
.10 dec give some time....
bne .10
lda #W5100.MR.AI+W5100.MR.IND
sta W5100.MR,x
pha
pla
lda W5100.MR,x
cmp #W5100.MR.AI+W5100.MR.IND
bne .2
>AR.SELECT RTR
lda W5100.DR,x Get RTR HI
cmp /2000
bne .2
lda W5100.DR,x Get RTR LO
cmp #2000
beq .3
.2 dec DEV.HEADER.NAME+4
txa
sec
sbc #$10
tax
dey
bne .1
>LDYA L.MSG.DETECT.KO
>SYSCALL CPrintFYA
lda #MLI.ERR.NODEV
sec
rts
.3 stx DEVSLOTx0
lda #A2osX.SLOTS.NET
sta A2osX.SLOTS,y
>LDYA ARGS
>STYA ZPTmpPTR
lda (ZPTmpPTR)
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 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 /A2OSX.SRC/DRV/X.NET.DRV.S
*--------------------------------------
CS.END
MSG.DETECT >CSTR "UtherNet2/W5100 Driver.\r\n"
MSG.DETECT.OK >CSTR "UtherNet2/W5100 Installed As Device : %S\r\n"
MSG.DETECT.KO >CSTR "Hardware Not Found.\r\n"
Args .BS 2
*--------------------------------------
* Device Header (16 Bytes)
*--------------------------------------
DEV.HEADER cld
jmp (DRV.CS.START,x)
.DA #0
.BS 6
DEV.HEADER.NAME >PSTR "ETH7"
*--------------------------------------
* Driver Code
*--------------------------------------
DRV.CS.START .DA STATUS
.DA READBLOCK
.DA WRITEBLOCK
.DA BADCALL
.DA CONTROL
.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 >LDYA L.DEVSTAT
clc
rts
*--------------------------------------
READBLOCK ldx DEVSLOTx0
>AR.SELECT S0.RX.RSR
lda W5100.DR,x get the received size HI
ora W5100.DR,x LO
bne READBLOCK.RxOK
lda #ERR.DEV.NOFRAME
sec
READBLOCK.RTS rts
READBLOCK.RxOK >AR.SELECT S0.RX.RD
lda W5100.DR,x get the received ptr HI
sta offset+1
ldy W5100.DR,x get the received ptr LO
sty offset
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
ldy W5100.DR,x get RX.Size HI
sty RXTX.Size+1
lda W5100.DR,x get RX.Size LO
sta RXTX.Size
clc
adc #S.IP
pha
tya
adc /S.IP
>PUSHA
pla
>PUSHA
>PUSHBI 0
>SYSCALL GetMem
bcs READBLOCK.RTS
>STYA ZPTmpPTR
stx .8+1
sty .8+3
sta .8+5
lda RXTX.Size
sta (ZPTmpPTR)
pha
eor #$ff
sta Counter
pla
* clc
adc #6 Header Size
sta RXTX.Size
ldy #1
lda RXTX.Size+1
sta (ZPTmpPTR),y
pha
eor #$ff
sta Counter+1
pla
adc #0
sta RXTX.Size+1
ldy #S.IP.DST+3
ldx #3
.1 lda RX.IP,x
sta (ZPTmpPTR),y
dey
dex
bpl .1
ldx DEVSLOTx0
ldy #S.IP
.2 inc Counter
bne .3
inc Counter+1
beq .4
.3 lda W5100.DR,x
sta (ZPTmpPTR),y
iny
bne .2
inc ZPTmpPTR+1
bne .2
.4 >AR.SELECT S0.RX.RD
lda Offset
clc
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
>AR.SELECT S0.CR
lda #W5100.AR.S0.CR.RCVD
sta W5100.DR,x
.8 ldx #$ff hMem
ldy #$ff PtrLO
lda #$ff PtrHI
clc
rts
*--------------------------------------
WRITEBLOCK >STYA ZPTmpPTR
lda (ZPTmpPTR)
sec
sbc #S.IP-2
sta RXTX.Size
eor #$ff
sta Counter
ldy #1
lda (ZPTmpPTR),y
sbc /S.IP-2
sta RXTX.Size+1
eor #$ff
sta Counter+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 WRITEBLOCK.1
lda #ERR.DEV.NOBUFFER
sec
rts
WRITEBLOCK.1 >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.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
.2 inc Counter
bne .3
inc Counter+1
beq .8
.3 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
bne .2
inc ZPTmpPTR+1
bne .2
.8 >AR.SELECT S0.TX.WR
lda Offset
clc
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
>AR.SELECT S0.CR
lda #W5100.AR.S0.CR.SEND
sta W5100.DR,x
clc
rts
*--------------------------------------
OPEN jsr CLOSE
lda #W5100.MR.AI+W5100.MR.IND
sta W5100.MR,x
>AR.SELECT GAR
ldy #4
.1 stz W5100.DR,x
dey
bne .1
* >AR.SELECT SUBR
ldy #4
lda #255
.2 sta W5100.DR,x
dey
bne .2
* >AR.SELECT SHAR
ldy #0
.3 lda MAC,y
sta W5100.DR,x
iny
cpy #6
bne .3
* >AR.SELECT SIPR
ldy #4
.4 stz W5100.DR,x
dey
bne .4
>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
bra CONTROL.OPEN
*--------------------------------------
CONTROL >STYA ZPTmpPTR
ldx DEVSLOTx0
>AR.SELECT S0.CR
lda #W5100.AR.S0.CR.CLOSE
sta W5100.DR,x
.10 >AR.SELECT S0.SR
lda W5100.DR,x
bne .10 CLOSED ???
>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 SIPR
ldy #S.IPCFG.IP
.3 lda (ZPTmpPTR),y
sta W5100.DR,x
iny
cpy #S.IPCFG.IP+4
bne .3
CONTROL.OPEN >AR.SELECT S0.MR
lda #W5100.AR.S0.MR.IPRAW+W5100.AR.S0.MR.MF
sta W5100.DR,x
>AR.SELECT S0.TOS
stz W5100.DR,x
* >AR.SELECT S0.TTL
lda #K.IP.TTL
sta W5100.DR,x
>AR.SELECT S0.CR
lda #W5100.AR.S0.CR.OPEN
sta W5100.DR,x
clc
rts
*--------------------------------------
CLOSE ldx DEVSLOTx0
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
clc
rts
*--------------------------------------
DRV.CS.END
DEVSLOTx0 .BS 1
*--------------------------------------
DEVSTAT .DA #0
.BS 3 size
>PSTR "UtherNetII/W5100"
.DA #S.DEVSTAT.T.NET
.BS 1 Subtype
.BS 2 Version
*--------------------------------------
FLAGS .DA #S.DEVSTAT.NET.FLAGS.ARPOFFLOAD+S.DEVSTAT.NET.FLAGS.IPOFFLOAD
LINK.STATUS .DA #S.DEVSTAT.NET.STATUS.OK+S.DEVSTAT.NET.STATUS.FD+S.DEVSTAT.NET.STATUS.100
MAC .BS 6
MAN
SAVE /A2OSX.SRC/DRV/UTHER2.AI.DRV.S
ASM