A2osX/DRV/UTHERNET.DRV.S.txt

523 lines
12 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2015-03-14 21:48:35 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
2015-06-03 18:30:57 +00:00
.TF /A2OSX.BOOT/DRV/UTHERNET.DRV
2015-03-14 21:48:35 +00:00
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
*--------------------------------------
ZPTmpPTR .EQ ZPDRV
*--------------------------------------
DEVID .EQ $630E
*--------------------------------------
* CS8900A IO Registers
*--------------------------------------
RTDATA .EQ $C080 Receive/Transmit Data (DWORD)
TxCMD .EQ $C084 Transmit Command
TxLength .EQ $C086 Transmission Length
IntStatusQueue .EQ $C088 Interrupt Status Queue
PacketPagePTR .EQ $C08A PacketPage Pointer
PacketPageDATA .EQ $C08C PacketPage Data (DWORD)
*--------------------------------------
* PacketPage Offsets & Masks
*--------------------------------------
PP.ID .EQ $0000 Product ID code (RO)
PP.RFBCNT .EQ $0050 Received Frame Byte Counter (RO)
PP.RxCFG .EQ $0102 Receiver Configuration (RW)
PP.RxCFG.LID .EQ %00000000.00000011
PP.RxCTL .EQ $0104 Receiver Control (RW)
PP.RxCTL.LID .EQ %00000000.00000101
PP.RxCTL.IAHashA .EQ %00000000.01000000
PP.RxCTL.PromisA .EQ %00000000.10000000
PP.RxCTL.RxOKA .EQ %00000001.00000000
PP.RxCTL.MulticastA .EQ %00000010.00000000
PP.RxCTL.IA .EQ %00000100.00000000
PP.RxCTL.BroadcastA .EQ %00001000.00000000
PP.RxCTL.CRCerrorA .EQ %00010000.00000000
PP.RxCTL.RuntA .EQ %00100000.00000000
PP.RxCTL.ExtradataA .EQ %01000000.00000000
PP.TxCFG .EQ $0106 Transmit Configuration (RW)
PP.TxCMD .EQ $0108 Receiver Control (RW)
2016-03-13 22:07:01 +00:00
PP.TxCMD.LID .EQ %00000000.00001001
PP.TxCMD.TxStart5 .EQ %00000000.00000000 00 = start after 5 Bytes
PP.TxCMD.TxStart381 .EQ %00000000.01000000 01 = start after 381 Bytes
PP.TxCMD.TxStart1021 .EQ %00000000.10000000 10 = start after 1021 Bytes
PP.TxCMD.TxStartFULL .EQ %00000000.11000000 11 = start after ENTIRE Frame
PP.TxCMD.Force .EQ %00000001.00000000
PP.TxCMD.OneColl .EQ %00000010.00000000
PP.TxCMD.InhibitCRC .EQ %00010000.00000000
PP.TxCMD.TxPadDis .EQ %00100000.00000000
2015-03-14 21:48:35 +00:00
PP.BufCFG .EQ $010A
PP.LineCTL .EQ $0112 Line Control (RW)
PP.LineCTL.LID .EQ %00000000.00010011
PP.LineCTL.SerRxOn .EQ %00000000.01000000
PP.LineCTL.SerTxOn .EQ %00000000.10000000
2016-03-13 22:07:01 +00:00
PP.LineCTL.10BaseT .EQ %00000000.00000000
2015-03-14 21:48:35 +00:00
PP.LineCTL.AUIonly .EQ %00000001.00000000
PP.LineCTL.Auto .EQ %00000010.00000000
PP.SelfCTL .EQ $0114 Self Control (RW)
PP.SelfCTL.LID .EQ %00000000.00010101
PP.SelfCTL.RESET .EQ %00000000.01000000
PP.SelfCTL.SWSuspnd .EQ %00000000.10000000
PP.SelfCTL.HWSleepE .EQ %00000001.00000000
PP.SelfCTL.HWStndby .EQ %00000010.00000000
PP.BufCTL .EQ $0116
PP.TestCTL .EQ $0118
PP.TestCTL.LID .EQ %00000000.00011001
PP.TestCTL.DisLT .EQ %00000000.10000000
PP.TestCTL.FDX .EQ %01000000.00000000
2015-03-14 21:48:35 +00:00
PP.ISQ .EQ $0120
PP.RxEvent .EQ $0124 Receiver Event (RO)
PP.RxEvent.LID .EQ %00000000.00000100
PP.RxEvent.RxOK .EQ %00000001.00000000
PP.RxEvent.IA .EQ %00000100.00000000
PP.RxEvent.Brdcast .EQ %00001000.00000000
PP.RxEvent.CRCerror .EQ %00010000.00000000
PP.RxEvent.Runt .EQ %00100000.00000000
PP.RxEvent.Xtradata .EQ %01000000.00000000
PP.TxEvent .EQ $0128 Transmitter Event (RO)
PP.TxEvent.LID .EQ %00000000.00001000
PP.BufEvent .EQ $012C
PP.RxMISS .EQ $0130
PP.TxCOL .EQ $0132
PP.LineST .EQ $0134 Line Status (RO)
PP.LineST.LID .EQ %00000000.00010100
PP.LineST.LinkOK .EQ %00000000.10000000
PP.LineST.AUI .EQ %00000001.00000000
PP.LineST.10BT .EQ %00000010.00000000
PP.LineST.PolOK .EQ %00010000.00000000
PP.LineST.CRS .EQ %01000000.00000000
PP.SelfST .EQ $0136 Self Status (RO)
PP.SelfST.INITD .EQ %00000000.10000000
PP.BusST .EQ $0138 Bus Status (RO)
PP.BusST.LID .EQ %00000000.00011000
PP.BusST.TxBidErr .EQ %00000000.10000000
PP.BusST.Rdy4TxNOW .EQ %00000001.00000000
PP.TDR .EQ $013C
PP.MAC .EQ $0158 MAC Address (RW)
PP.RxStatus .EQ $0400
PP.RxLength .EQ $0402
PP.RxFrame .EQ $0404
PP.TxFrame .EQ $0A00
*--------------------------------------
ERRTNOFRAME .EQ 0
ERRNOBUFFER .EQ 1
ERRTIMEOUT .EQ 2
*--------------------------------------
2015-06-03 18:30:57 +00:00
* File Header (16 Bytes)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.START cld
2015-06-03 18:30:57 +00:00
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
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
* 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
2015-06-03 18:30:57 +00:00
.DA 0 End Of Reloc Table
*--------------------------------------
Dev.Detect sta hArgs
>LDYA L.MSG.DETECT
>SYSCALL SYS.PSTROutYA
2015-06-03 18:30:57 +00:00
ldx #$10
2016-01-10 22:16:07 +00:00
.1 >LDYAI PP.ID
2015-03-14 21:48:35 +00:00
>STYA PacketPagePTR,x
>LDYA PacketPageDATA,x
cpy #DEVID
bne .2
cmp /DEVID
beq .3
2015-06-03 18:30:57 +00:00
.2 inc DEV.HEADER.NAME+4
2015-03-14 21:48:35 +00:00
txa
clc
adc #$10
tax
cpx #$80
bne .1
2015-06-03 18:30:57 +00:00
>LDYA L.MSG.DETECT.KO
>SYSCALL SYS.PSTROutYA
lda #DEVMGR.ERRNOHW Not Found in any slot, exiting
2015-03-14 21:48:35 +00:00
sec
rts
2015-06-03 18:30:57 +00:00
2016-01-10 22:16:07 +00:00
.3 stx DEVSLOTx0
lda hARGS
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
beq .4
>SYSCALL SYS.GetMemPtrA
>STYA ZPTmpPTR
jsr DecodeMac
bcc .4
2016-01-04 07:21:45 +00:00
lda #DEVMGR.ERRICL
2015-03-14 21:48:35 +00:00
sec
rts
.4 >LDYA L.MSG.DETECT.OK
>SYSCALL SYS.PSTROutYA
>LDYA L.DEV.HEADER.NAME
>SYSCALL SYS.PSTROutYA
lda #13
>SYSCALL SYS.COutA
clc
2015-06-03 18:30:57 +00:00
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 "UtherNet/CS8900A Driver.\n"
MSG.DETECT.OK >PSTRING "UtherNet/CS8900A Installed As Device : "
MSG.DETECT.KO >PSTRING "Hardware Not Found.\n"
2015-06-03 18:30:57 +00:00
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
2016-01-10 22:16:07 +00:00
.DA $FFFF no SETIPCFG
2015-06-03 18:30:57 +00:00
L.DEVINFO .DA DEVINFO
.DA 0 end or relocation
*--------------------------------------
* input :
* none
* output :
* CC on success
* CS on error
*--------------------------------------
OPEN jsr Reset
2015-03-14 21:48:35 +00:00
>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
2016-03-13 22:07:01 +00:00
>LDYAI PP.TestCTL
>STYA PacketPagePTR,x
>LDYAI PP.TestCTL.LID+PP.TestCTL.FDX
>STYA PacketPageDATA,x
2015-03-14 21:48:35 +00:00
>LDYAI PP.LineCTL
>STYA PacketPagePTR,x
>LDYAI PP.LineCTL.LID+PP.LineCTL.SerRxOn+PP.LineCTL.SerTxOn+PP.LineCTL.Auto
>STYA PacketPageDATA,x
2015-06-03 18:30:57 +00:00
clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
* input :
* pEvent
* output :
* CC no event
* CS event
*--------------------------------------
2015-06-03 18:30:57 +00:00
GETEVENT ldx DEVSLOTx0
2015-03-14 21:48:35 +00:00
>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
2016-03-13 22:07:01 +00:00
GETEVENT.RxOK and /PP.RxEvent.Brdcast
2015-03-14 21:48:35 +00:00
beq .10
lda #$80
.10 ldy #S.EVT.DATAHI
sta (pEvent),y
2016-03-13 22:07:01 +00:00
>LDYA RTDATA,x discard RxStatus
lda RTDATA+1,x get RxLength
sta FRAMELEN+1
pha
lda RTDATA,x
sta FRAMELEN
clc
adc #2
tay
pla
bcc .11
inc
.11 >PUSHYA FRAMLEN+2
2015-06-03 18:30:57 +00:00
>PUSHBI 0
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.GetMem
bcs .99
>STYA ZPTmpPTR
txa
ldy #S.EVT.DATALO
sta (pEvent),y
2016-03-13 22:07:01 +00:00
2015-03-14 21:48:35 +00:00
lda #S.EVT.F.NET+S.EVT.F.hMEM1
sta (pEvent)
2016-03-13 22:07:01 +00:00
lda FRAMELEN
sta (ZPTmpPTR)
ldy #1
lda FRAMELEN+1
sta (ZPTmpPTR),y
iny
2015-06-03 18:30:57 +00:00
2016-03-13 22:07:01 +00:00
ldx DEVSLOTx0
.1 jsr DecFrameLen
beq .8
lda RTDATA,x
2015-03-14 21:48:35 +00:00
sta (ZPTmpPTR),y
iny
bne .2
inc ZPTmpPTR+1
2016-03-13 22:07:01 +00:00
2015-03-14 21:48:35 +00:00
.2 jsr DecFrameLen
beq .8
lda RTDATA+1,x
sta (ZPTmpPTR),y
iny
2016-03-13 22:07:01 +00:00
bne .1
2015-03-14 21:48:35 +00:00
inc ZPTmpPTR+1
2015-06-03 18:30:57 +00:00
bne .1
2016-03-13 22:07:01 +00:00
2015-03-14 21:48:35 +00:00
.8 clc
rts
.99 sec
rts
2015-06-03 18:30:57 +00:00
*--------------------------------------
CLOSE jsr Reset
clc
rts
*--------------------------------------
* in:
* out:
* Y,A = BUFFER PTR
* CC on success
* CS on error
*--------------------------------------
2016-03-13 22:07:01 +00:00
GETINFO 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.DEVINFO
2015-06-03 18:30:57 +00:00
clc
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
* in:
* PULLW = FRAME PTR
* PULLW = FRAME LEN
* out:
* CC on success
* CS on error
*--------------------------------------
2015-06-03 18:30:57 +00:00
SEND >PULLW ZPTmpPTR
2016-03-13 22:07:01 +00:00
lda (ZPTmpPTR)
sta FRAMELEN
ldy #1
lda (ZPTmpPTR),y
sta FRAMELEN+1
ldy #2+6+5 Add Src MAC Address
2015-03-14 21:48:35 +00:00
ldx #5
.10 lda MAC,x
sta (ZPTmpPTR),y
dey
dex
bpl .10
ldx DEVSLOTx0
2016-03-13 22:07:01 +00:00
>LDYAI PP.TxCMD.LID+PP.TxCMD.TxStartFULL
2015-03-14 21:48:35 +00:00
>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
2016-03-13 22:07:01 +00:00
SENDPREADY ldy #2
.1 jsr DecFrameLen
beq .8
lda (ZPTmpPTR),y
2015-03-14 21:48:35 +00:00
sta RTDATA,x
iny
bne .2
inc ZPTmpPTR+1
2016-03-13 22:07:01 +00:00
2015-03-14 21:48:35 +00:00
.2 jsr DecFrameLen
beq .8
.3 lda (ZPTmpPTR),y
sta RTDATA+1,x
iny
2016-03-13 22:07:01 +00:00
bne .1
2015-03-14 21:48:35 +00:00
inc ZPTmpPTR+1
bne .1
2016-03-13 22:07:01 +00:00
2015-03-14 21:48:35 +00:00
.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
2015-06-03 18:30:57 +00:00
beq .8
2015-03-14 21:48:35 +00:00
dec FRAMELEN+1
.1 dec FRAMELEN
2015-06-03 18:30:57 +00:00
lda #1 Make something NZ
.8 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
DRV.CS.END
2015-03-14 21:48:35 +00:00
*--------------------------------------
DEVSLOTx0 .BS 1
FRAMELEN .BS 2
*--------------------------------------
2015-06-03 18:30:57 +00:00
DEVINFO .DA #S.DEVINFO.TYPE.NET
2016-01-09 22:34:18 +00:00
DEVFLAGS .DA #0
2015-03-14 21:48:35 +00:00
MAC .BS 6
2016-03-13 22:07:01 +00:00
LINK.STATUS .BS 1 OK/DUPLEX/SPEED
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE DRV/UTHERNET.DRV.S
ASM