A2osX/DRV/LANCEGS.DRV.S.txt
2016-03-13 23:07:01 +01:00

567 lines
11 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.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/DRV/LANCEGS.DRV
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
*--------------------------------------
ZPTmpPTR .EQ ZPDRV
*--------------------------------------
DEVID .EQ $33
REVID .EQ $46 CHIP=4,REV=6
*--------------------------------------
* SMSC L91C96 IO Registers
*--------------------------------------
L91C96.0.TCR .EQ $C080
L91C96.0.TCR.FDSE .EQ %10000000.00000000
L91C96.0.TCR.FUDPLX .EQ %00001000.00000000
L91C96.0.TCR.PADEN .EQ %00000000.10000000
L91C96.0.TCR.TXENA .EQ %00000000.00000001
L91C96.0.EPHSR .EQ $C082
L91C96.0.EPHSR.LINK .EQ %01000000.00000000
L91C96.0.RCR .EQ $C084
L91C96.0.RCR.RESET .EQ %10000000.00000000
L91C96.0.RCR.NOCRC .EQ %00000010.00000000
L91C96.0.RCR.RXENA .EQ %00000001.00000000
L91C96.0.RCR.ALLMUL .EQ %00000000.00000100
L91C96.0.RCR.PRMS .EQ %00000000.00000010
L91C96.0.RCR.RXABRT .EQ %00000000.00000001
L91C96.0.ECR .EQ $C086
L91C96.0.MIR .EQ $C088
L91C96.0.MCR .EQ $C08A
L91C96.1.CR .EQ $C080
L91C96.1.CR.NOWAIT .EQ %00010000.00000000
L91C96.1.BAR .EQ $C082
L91C96.1.IAR .EQ $C084
L91C96.1.GPR .EQ $C08A
L91C96.1.CTR .EQ $C08C
L91C96.1.CTR.AUTOREL .EQ %00000000.00001000
L91C96.2.MMUCR .EQ $C080
L91C96.2.MMUCR.ALLOC .EQ %00100000
L91C96.2.MMUCR.RESET .EQ %01000000
L91C96.2.MMUCR.REMREL .EQ %10000000
L91C96.2.MMUCR.NQPKT .EQ %11000000
L91C96.2.PNR .EQ $C082
L91C96.2.AAR .EQ $C083
L91C96.2.FIFO .EQ $C084
L91C96.2.PTR .EQ $C086
L91C96.2.PTR.RCVD .EQ %10000000.00000000
L91C96.2.PTR.AUTOI .EQ %01000000.00000000
L91C96.2.PTR.READ .EQ %00100000.00000000
L91C96.2.DATA .EQ $C088
L91C96.2.IST .EQ $C08C
L91C96.2.IST.ALLOC .EQ %00001000
L91C96.2.IST.RCV .EQ %00000001
L91C96.2.ACK .EQ $C08C
L91C96.2.MSK .EQ $C08D
L91C96.3.MT .EQ $C080
L91C96.3.MGMT .EQ $C088
L91C96.3.REV .EQ $C08A
L91C96.3.RCV .EQ $C08C
L91C96.BSR .EQ $C08E
*--------------------------------------
ERRTNOFRAME .EQ 0
ERRNOBUFFER .EQ 1
ERRTIMEOUT .EQ 2
*--------------------------------------
* 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 L91C96.BSR+1,x
cmp #DEVID
bne .2
lda #3
sta L91C96.BSR,x
lda L91C96.3.REV,x
cmp #REVID
bra .3
.2 inc DEV.HEADER.NAME+4
txa
clc
adc #$10
tax
cpx #$80
bne .1
>LDYA L.MSG.DETECT.KO
>SYSCALL SYS.PSTROutYA
lda #DEVMGR.ERRNOHW Not Found in any slot, exiting
sec
rts
.3 stx DEVSLOTx0
lda hARGS
beq .4
sec
ror USERMAC
>SYSCALL SYS.GetMemPtrA
>STYA ZPTmpPTR
jsr DecodeMac
bcc .4
lda #DEVMGR.ERRICL
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
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 "LanCeGS/SMSC91C96 Driver.\n"
MSG.DETECT.OK >PSTRING "LanCeGS/SMSC91C96 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 $FFFF no SETIPCFG
L.DEVINFO .DA DEVINFO
.DA 0 end or relocation
*--------------------------------------
* input :
* none
* output :
* CC on success
* CS on error
*--------------------------------------
OPEN jsr Reset will select L91C96.0
lda #L91C96.0.TCR.FDSE+L91C96.0.TCR.FUDPLX+L91C96.0.TCR.PADEN+L91C96.0.TCR.TXENA
sta L91C96.0.TCR,x
lda /L91C96.0.TCR.FDSE+L91C96.0.TCR.FUDPLX+L91C96.0.TCR.PADEN+L91C96.0.TCR.TXENA
sta L91C96.0.TCR+1,x
lda #L91C96.0.RCR.NOCRC+L91C96.0.RCR.RXENA+L91C96.0.RCR.ALLMUL
sta L91C96.0.RCR,x
lda /L91C96.0.RCR.NOCRC+L91C96.0.RCR.RXENA+L91C96.0.RCR.ALLMUL
sta L91C96.0.RCR+1,x
lda #1
sta L91C96.BSR,x
lda #L91C96.1.CR.NOWAIT
sta L91C96.1.CR,x
lda /L91C96.1.CR.NOWAIT
sta L91C96.1.CR+1,x
ldy #0
bit USERMAC
bpl .2
.1 lda L91C96.1.IAR,x
sta MAC,y
inx
iny
cpy #6
bne .1
bra .3
.2 lda MAC,y
sta L91C96.1.IAR,x
inx
iny
cpy #6
bne .2
.3 ldx DEVSLOTx0
lda #L91C96.1.CTR.AUTOREL
sta L91C96.1.CTR,x
lda /L91C96.1.CTR.AUTOREL
sta L91C96.1.CTR+1,x
clc
rts
*--------------------------------------
* input :
* pEvent
* output :
* CC no event
* CS event
*--------------------------------------
GETEVENT ldx DEVSLOTx0
lda #2
sta L91C96.BSR,x
lda L91C96.2.IST,x
and #L91C96.2.IST.RCV
bne GETEVENT.RxOK
lda #ERRTNOFRAME
sec
rts
GETEVENT.RxOK lda #L91C96.2.PTR.RCVD+L91C96.2.PTR.AUTOI+L91C96.2.PTR.READ
sta L91C96.2.PTR,x
lda /L91C96.2.PTR.RCVD+L91C96.2.PTR.AUTOI+L91C96.2.PTR.READ
sta L91C96.2.PTR+1,x
lda L91C96.2.DATA,x
lda L91C96.2.DATA+1,x
pha
and #$60 Broadcast?
asl
ldy #S.EVT.DATAHI
sta (pEvent),y
clc
pla #$10 = odd?
and #$10
beq .1
sec
.1 lda L91C96.2.DATA,x get lo byte count
sbc #3 compute FRAMELEN+2
sta FRAMELEN
tay
lda L91C96.2.DATA+1,x
sta FRAMELEN+1
>PUSHYA FRAMLEN+2
>PUSHBI 0
>SYSCALL SYS.GetMem
bcs .99
>STYA ZPTmpPTR
txa
ldy #S.EVT.DATALO
sta (pEvent),y
lda #S.EVT.F.NET+S.EVT.F.hMEM1
sta (pEvent)
ldy #0
lda FRAMELEN
sbc #1 CC from SYSCALL
sta FRAMELEN
sta (ZPTmpPTR),y
iny
lda FRAMELEN+1
sbc #0
sta (ZPTmpPTR),y
iny
ldx DEVSLOTx0
.2 jsr DecFrameLen
beq .8
lda L91C96.2.DATA,x
sta (ZPTmpPTR),y
iny
bne .3
inc ZPTmpPTR+1
.3 jsr DecFrameLen
beq .8
lda L91C96.2.DATA+1,x
sta (ZPTmpPTR),y
iny
bne .2
inc ZPTmpPTR+1
bra .2
.8 lda #L91C96.2.MMUCR.REMREL
sta L91C96.2.MMUCR,x
clc
rts
.99 sec
rts
*--------------------------------------
CLOSE jsr Reset
lda #0
sta L91C96.0.RCR,x
sta L91C96.0.RCR+1,x
clc
rts
*--------------------------------------
* in:
* out:
* Y,A = BUFFER PTR
* CC on success
* CS on error
*--------------------------------------
GETINFO lda #S.DEVINFO.NET.STATUS.10
sta LINK.STATUS
ldx DEVSLOTx0
lda #0
sta L91C96.BSR,x
lda L91C96.0.EPHSR,x
lda L91C96.0.EPHSR+1,x
and /L91C96.0.EPHSR.LINK
beq .1
lda LINK.STATUS
ora #S.DEVINFO.NET.STATUS.OK
sta LINK.STATUS
.1 lda L91C96.0.TCR,x
lda L91C96.0.TCR+1,x
and /L91C96.0.TCR.FDSE
bne .2
lda LINK.STATUS
ora #S.DEVINFO.NET.STATUS.FD
sta LINK.STATUS
.2 >LDYA L.DEVINFO
clc
rts
*--------------------------------------
* in:
* PULLW = FRAME PTR
* PULLW = FRAME LEN
* out:
* CC on success
* CS on error
*--------------------------------------
SEND >PULLW ZPTmpPTR
ldx DEVSLOTx0
lda #2
sta L91C96.BSR,x
lda (ZPTmpPTR)
sta FRAMELEN
clc
adc #6 3 WORDs more Status, len & Control
pha
ldy #1
lda (ZPTmpPTR),y
sta FRAMELEN+1
adc #0
ply
bne .1
dec
.1 ora #L91C96.2.MMUCR.ALLOC
sta L91C96.2.MMUCR,x
ldy #0
.2 lda L91C96.2.IST,x
and #L91C96.2.IST.ALLOC
bne .3
dey
bne .2
bra *
lda #ERRNOBUFFER
sec
rts
.3 lda L91C96.2.AAR,x
sta L91C96.2.PNR,x
lda #L91C96.2.PTR.AUTOI+2 skip status WORD
sta L91C96.2.PTR,x
lda /L91C96.2.PTR.AUTOI+2
sta L91C96.2.PTR+1,x
ldy #2+6+5 Add Src MAC Address
ldx #5
.4 lda MAC,x
sta (ZPTmpPTR),y
dey
dex
bpl .4
ldx DEVSLOTx0
lda FRAMELEN
pha
lsr
pla
sbc #$fb add 5 if odd, 6 if even
sta L91C96.2.DATA,x
lda FRAMELEN+1
sta L91C96.2.DATA+1,x
ldy #2
.5 jsr DecFrameLen
beq .70
lda (ZPTmpPTR),y
iny
bne .6
inc ZPTmpPTR+1
.6 pha
jsr DecFrameLen
beq .71
pla
sta L91C96.2.DATA,x
lda (ZPTmpPTR),y
sta L91C96.2.DATA+1,x
iny
bne .5
inc ZPTmpPTR+1
bra .5
.70 lda #0
sta L91C96.2.DATA,x
sta L91C96.2.DATA+1,x
bra .8
.71 lda #$40 signal an extra (odd) byte
sta L91C96.2.DATA,x
pla
sta L91C96.2.DATA+1,x
.8 lda #L91C96.2.MMUCR.NQPKT
sta L91C96.2.MMUCR,x
clc
rts
.9 sec
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
Reset ldx DEVSLOTx0
lda #0
sta L91C96.BSR,x
lda #L91C96.0.RCR.RESET
sta L91C96.0.RCR,x
lda /L91C96.0.RCR.RESET
sta L91C96.0.RCR+1,x
lda $C019 we can use VBL as we are not on //c
.1 eor $C019
bpl .1
.2 eor $C019
bpl .2
rts
*--------------------------------------
DecFrameLen lda FRAMELEN
bne .1
lda FRAMELEN+1
beq .8
dec FRAMELEN+1
.1 dec FRAMELEN
lda #1 Make something NZ
.8 rts
*--------------------------------------
DRV.CS.END
*--------------------------------------
DEVSLOTx0 .BS 1
USERMAC .BS 1
FRAMELEN .BS 2
*--------------------------------------
DEVINFO .DA #S.DEVINFO.TYPE.NET
DEVFLAGS .DA #0
MAC .BS 6
LINK.STATUS .BS 1 OK/DUPLEX/SPEED
*--------------------------------------
MAN
SAVE DRV/LANCEGS.DRV.S
ASM