A2osX/DRV/UTHERNET.DRV.S.txt
2015-03-15 23:00:40 +01:00

435 lines
10 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
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF DRV/UTHERNET.DRV
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
* .INB INC/ZP.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)
*--------------------------------------
TxCMD.LID .EQ %00000000.00001001
TxCMD.TxStart5 .EQ %00000000.00000000 00 = start after 5 Bytes
TxCMD.TxStart381 .EQ %00000000.01000000 01 = start after 381 Bytes
TxCMD.TxStart1021 .EQ %00000000.10000000 10 = start after 1021 Bytes
TxCMD.TxStartFULL .EQ %00000000.11000000 11 = start after ENTIRE Frame
TxCMD.Force .EQ %00000001.00000000
TxCMD.OneColl .EQ %00000010.00000000
TxCMD.InhibitCRC .EQ %00010000.00000000
TxCMD.TxPadDis .EQ %00100000.00000000
*--------------------------------------
* 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)
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
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.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
*--------------------------------------
* Main DRV entry point
* input :
* X = CMD
* 0 : OPEN
* 2 : GETEVENT
* 4 : OUT
* 6 : CLOSE
* 8 : GETINFO
*--------------------------------------
* CLD $D8
* JMP (*,x) $7C
* #JMPTABLE
* /JMPTABLE
*--------------------------------------
CS.START cld
jmp (.1,x)
.1 .DA OPEN
.DA GETEVENT
.DA OUT
.DA CLOSE
.DA GETINFO
L.DEVINFO .DA DEVINFO
.DA 0 end or relocation
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
*--------------------------------------
* input :
* none
* output :
* CC on success
* CS on error
*--------------------------------------
OPEN ldx #$10
.1 stx DEVSLOTx0
>LDYAI PP.ID
>STYA PacketPagePTR,x
>LDYA PacketPageDATA,x
cpy #DEVID
bne .2
cmp /DEVID
beq .3
.2 inc DEVNAME+4
txa
clc
adc #$10
tax
cpx #$80
bne .1
lda #DEVMGR.ERRNOHW
sec
rts
.3 ldy #S.DEV.hARGS
lda (pDevContext),y
beq .4
>SYSCALL SYS.GetMemPtrA
>STYA ZPTmpPTR
jsr DecodeMac
bcc .4
lda #DEVMGR.ERRNICL
sec
rts
.4 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
lda #S.DEV.F.NET+S.DEV.F.EVENT+S.DEV.F.OUT
sta (pDevContext)
ldy #S.DEV.NAME
ldx #0
.7 lda DEVNAME,x
sta (pDevContext),y
cpx DEVNAME
beq .8
inx
iny
bne .7
.8 clc
rts
*--------------------------------------
* input :
* pEvent
* output :
* CC no event
* CS event
*--------------------------------------
GETEVENT >PULLW pEvent
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
>PUSHB 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
beq .8
bra .1
.8 clc
rts
.99 sec
rts
*--------------------------------------
* in:
* PULLW = FRAME PTR
* PULLW = FRAME LEN
* out:
* CC on success
* CS on error
*--------------------------------------
OUT >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
*--------------------------------------
CLOSE jsr Reset
clc
rts
*--------------------------------------
* in:
* out:
* Y,A = BUFFER PTR
* CC on success
* CS on error
*--------------------------------------
GETINFO >LDYA L.DEVINFO
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
Reset ldx DEVSLOTx0
>LDYAI PP.SelfCTL
>STYA PacketPagePTR,x
>LDYAI PP.SelfCTL.LID+PP.SelfCTL.RESET
>STYA PacketPageDATA,x
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
*--------------------------------------
DecFrameLen lda FRAMELEN
bne .1
lda FRAMELEN+1
beq .2
dec FRAMELEN+1
.1 dec FRAMELEN
.2 lda FRAMELEN
ora FRAMELEN+1
rts
*--------------------------------------
CS.END
DEVNAME >PSTRING "ETH1"
*--------------------------------------
DS.START
*--------------------------------------
DEVSLOTx0 .BS 1
FRAMELEN .BS 2
*--------------------------------------
DEVINFO
MAC .BS 6
*--------------------------------------
DS.END
*--------------------------------------
MAN
SAVE DRV/UTHERNET.DRV.S
ASM