Kernel 0.9.2

This commit is contained in:
Rémy GIBERT 2018-08-25 18:26:41 +02:00
parent 81dc8d99f0
commit b76dbeafb2
7 changed files with 565 additions and 1031 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -24,11 +24,11 @@
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">.BS&#x000D;&#x000A;.DA&#x000D;&#x000A;.AS&#x000D;&#x000A;.AT&#x000D;&#x000A;.AZ&#x000D;&#x000A;.EQ&#x000D;&#x000A;.MA&#x000D;&#x000A;.EM&#x000D;&#x000A;.OR&#x000D;&#x000A;.TF&#x000D;&#x000A;.LIST&#x000D;&#x000A;.HS&#x000D;&#x000A;.IN&#x000D;&#x000A;.INB&#x000D;&#x000A;.OP&#x000D;&#x000A;.TA&#x000D;&#x000A;.EM&#x000D;&#x000A;.PH&#x000D;&#x000A;.EP&#x000D;&#x000A;.DUMMY&#x000D;&#x000A;.ED&#x000D;&#x000A;.DO&#x000D;&#x000A;.ELSE&#x000D;&#x000A;.FIN</Keywords>
<Keywords name="Keywords1">.BS&#x000D;&#x000A;.DA&#x000D;&#x000A;.AS&#x000D;&#x000A;.AT&#x000D;&#x000A;.AZ&#x000D;&#x000A;.EQ&#x000D;&#x000A;.MA&#x000D;&#x000A;.EM&#x000D;&#x000A;.OR&#x000D;&#x000A;.TF&#x000D;&#x000A;.LIST&#x000D;&#x000A;.HS&#x000D;&#x000A;.IN&#x000D;&#x000A;.INB&#x000D;&#x000A;.OP&#x000D;&#x000A;.TA&#x000D;&#x000A;.EM&#x000D;&#x000A;.PH&#x000D;&#x000A;.EP&#x000D;&#x000A;.DUMMY&#x000D;&#x000A;.ED</Keywords>
<Keywords name="Keywords2">adc&#x000D;&#x000A;and&#x000D;&#x000A;asl&#x000D;&#x000A;bit&#x000D;&#x000A;brk&#x000D;&#x000A;clc&#x000D;&#x000A;cld&#x000D;&#x000A;cli&#x000D;&#x000A;clv&#x000D;&#x000A;cmp&#x000D;&#x000A;cpx&#x000D;&#x000A;cpy&#x000D;&#x000A;dec&#x000D;&#x000A;dex&#x000D;&#x000A;dey&#x000D;&#x000A;eor&#x000D;&#x000A;inc&#x000D;&#x000A;inx&#x000D;&#x000A;iny&#x000D;&#x000A;lda&#x000D;&#x000A;ldx&#x000D;&#x000A;ldy&#x000D;&#x000A;lsr&#x000D;&#x000A;nop&#x000D;&#x000A;ora&#x000D;&#x000A;rmb&#x000D;&#x000A;rol&#x000D;&#x000A;ror&#x000D;&#x000A;rti&#x000D;&#x000A;rts&#x000D;&#x000A;sbc&#x000D;&#x000A;sec&#x000D;&#x000A;sed&#x000D;&#x000A;sei&#x000D;&#x000A;smb&#x000D;&#x000A;sta&#x000D;&#x000A;stp&#x000D;&#x000A;stx&#x000D;&#x000A;sty&#x000D;&#x000A;stz&#x000D;&#x000A;tax&#x000D;&#x000A;tay&#x000D;&#x000A;trb&#x000D;&#x000A;tsb&#x000D;&#x000A;tsx&#x000D;&#x000A;txa&#x000D;&#x000A;txs&#x000D;&#x000A;tya&#x000D;&#x000A;wai</Keywords>
<Keywords name="Keywords3">$&#x000D;&#x000A;%&#x000D;&#x000A;/&#x000D;&#x000A;#&#x000D;&#x000A;&amp;</Keywords>
<Keywords name="Keywords4">.1&#x000D;&#x000A;.2&#x000D;&#x000A;.3&#x000D;&#x000A;.4&#x000D;&#x000A;.5&#x000D;&#x000A;.6&#x000D;&#x000A;.7&#x000D;&#x000A;.8&#x000D;&#x000A;.9&#x000D;&#x000A;</Keywords>
<Keywords name="Keywords5">AUTO&#x000D;&#x000A;MAN&#x000D;&#x000A;LOAD&#x000D;&#x000A;SAVE&#x000D;&#x000A;ASM&#x000D;&#x000A;CREATE&#x000D;&#x000A;INC&#x000D;&#x000A;LOMEM&#x000D;&#x000A;PREFIX&#x000D;&#x000A;PR#&#x000D;&#x000A;NEW&#x000D;&#x000A;BLOAD&#x000D;&#x000A;BSAVE&#x000D;&#x000A;TEXT&#x000D;&#x000A;DELETE&#x000D;&#x000A;</Keywords>
<Keywords name="Keywords5">AUTO&#x000D;&#x000A;MAN&#x000D;&#x000A;LOAD&#x000D;&#x000A;SAVE&#x000D;&#x000A;ASM&#x000D;&#x000A;CREATE&#x000D;&#x000A;INC&#x000D;&#x000A;LOMEM&#x000D;&#x000A;PREFIX&#x000D;&#x000A;PR#&#x000D;&#x000A;NEW&#x000D;&#x000A;BLOAD&#x000D;&#x000A;BSAVE&#x000D;&#x000A;TEXT&#x000D;&#x000A;DELETE&#x000D;&#x000A;.DO&#x000D;&#x000A;.ELSE&#x000D;&#x000A;.FIN</Keywords>
<Keywords name="Keywords6">pha&#x000D;&#x000A;php&#x000D;&#x000A;phx&#x000D;&#x000A;phy&#x000D;&#x000A;pla&#x000D;&#x000A;plp&#x000D;&#x000A;plx&#x000D;&#x000A;ply</Keywords>
<Keywords name="Keywords7">bbr&#x000D;&#x000A;bbs&#x000D;&#x000A;bcc&#x000D;&#x000A;bcs&#x000D;&#x000A;beq&#x000D;&#x000A;bmi&#x000D;&#x000A;bne&#x000D;&#x000A;bpl&#x000D;&#x000A;bra&#x000D;&#x000A;jmp&#x000D;&#x000A;jsr&#x000D;&#x000A;bvc&#x000D;&#x000A;bvs</Keywords>
<Keywords name="Keywords8">&gt;</Keywords>
@ -43,7 +43,7 @@
<WordsStyle name="KEYWORDS2" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="00B32D" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="0000FF" bgColor="FFFF00" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="800040" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="CC1F15" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />

View File

@ -2,512 +2,17 @@ NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF DRV/UTHER2.AI.DRV
*--------------------------------------
U2AI .EQ 1
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/MLI.ERR.I
.INB INC/NIC.I
.INB INC/NIC.W5100.I
.INB INC/LIBTCPIP.I
.INB INC/ETH.I
.INB /A2OSX.SRC/DRV/X.U2.DRV.S
*--------------------------------------
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 printf
ldx #$70+$88
ldy #7
.1 lda A2osX.S,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 printf
lda #MLI.E.NODEV
sec
rts
.3 stx DEVSLOTx0
lda #A2osX.S.NIC
sta A2osX.S,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 #K.E.SYN
sec
rts
.8 >PUSHW L.DEV.HEADER.NAME
>LDYA L.MSG.DETECT.OK
>SYSCALL printf
clc
rts
*--------------------------------------
.INB /A2OSX.SRC/DRV/X.NET.DRV.S
*--------------------------------------
CS.END
MSG.DETECT .AZ "UtherNet2/W5100 Driver.\r\n"
MSG.DETECT.OK .AZ "UtherNet2/W5100 Installed As Device : %S\r\n"
MSG.DETECT.KO .AZ "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 A2osX.BADCALL
.DA CONTROL
.DA A2osX.BADCALL
.DA OPEN
.DA CLOSE
.DA A2osX.BADCALL
.DA A2osX.BADCALL
L.DEVSTAT .DA DEVSTAT
.DA 0 end or relocation
*--------------------------------------
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 #MLI.E.EOF
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
ply
>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 #MLI.E.EOF
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.DIB.T.NET
.BS 1 Subtype
.BS 2 Version
*--------------------------------------
FLAGS .DA #S.DIB.NIC.FLAGS.ARPOFFLOAD+S.DIB.NIC.FLAGS.IPOFFLOAD
LINK.STATUS .DA #S.DIB.NIC.STATUS.OK+S.DIB.NIC.STATUS.FD+S.DIB.NIC.STATUS.100
MAC .BS 6
MAN
SAVE /A2OSX.SRC/DRV/UTHER2.AI.DRV.S
ASM

View File

@ -2,9 +2,8 @@ NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF DRV/UTHERNET2.DRV
*--------------------------------------
U2AI .EQ 0
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
@ -12,533 +11,8 @@ AUTO 4,1
.INB INC/NIC.I
.INB INC/NIC.W5100.I
.INB INC/ETH.I
.INB /A2OSX.SRC/DRV/X.U2.DRV.S
*--------------------------------------
ZPArgPtr .EQ ZPDRV
*--------------------------------------
* 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 0
.DA 0
.DA 0
*--------------------------------------
* 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.DRV.CS.START .DA DRV.CS.START
L.FD.DEV .DA FD.DEV
L.FD.DEV.NAME .DA FD.DEV.NAME
L.SSCANF.MAC .DA SSCANF.MAC
L.MAC0 .DA DCB+S.DCB.NIC.MAC
L.MAC1 .DA DCB+S.DCB.NIC.MAC+1
L.MAC2 .DA DCB+S.DCB.NIC.MAC+2
L.MAC3 .DA DCB+S.DCB.NIC.MAC+3
L.MAC4 .DA DCB+S.DCB.NIC.MAC+4
L.MAC5 .DA DCB+S.DCB.NIC.MAC+5
.DA 0 End Of Reloc Table
*--------------------------------------
Dev.Detect >STYA ARGS
>LDYA L.MSG.DETECT
>SYSCALL puts
ldx #$70+$88
ldy #7
.1 lda A2osX.S,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 FD.DEV.NAME+3
txa
sec
sbc #$10
tax
dey
bne .1
>LDYA L.MSG.DETECT.KO
>SYSCALL puts
lda #MLI.E.NODEV
sec
rts
.3 stx DEVSLOTx0
lda #A2osX.S.NIC
sta A2osX.S,y
jsr Dev.ParseArgs
bcs .9
.8 >PUSHW L.FD.DEV.NAME
>PUSHBI 2
>LDYA L.MSG.DETECT.OK
>SYSCALL printf
>PUSHWI DRV.END
>PUSHWI DRV.CS.END
>PUSHWI DRV.CS.START
>LDYA L.DRV.CS.START
>SYSCALL InsDrv
bcs .9
>STYA FD.DEV+S.FD.DEV.DRVPTR
>LDYA L.FD.DEV
>SYSCALL MKDEV
.9 rts
*--------------------------------------
Dev.ParseArgs >LDYA ARGS
>STYA ZPArgPTR
lda (ZPArgPTR)
bne .1
lda A2osX.RANDOM16
eor A2osX.TIMER16
sta DCB+S.DCB.NIC.MAC+3
eor A2osX.RANDOM16+1
sta DCB+S.DCB.NIC.MAC+4
eor A2osX.TIMER16+1
sta DCB+S.DCB.NIC.MAC+5
clc
rts
.1 >PUSHW L.MAC5
>PUSHW L.MAC4
>PUSHW L.MAC3
>PUSHW L.MAC2
>PUSHW L.MAC1
>PUSHW L.MAC0
>PUSHBI 12 6 x byte PTRs
>PUSHW L.SSCANF.MAC
>LDYA ZPArgPtr
>SYSCALL sscanf
bcc .8
lda #K.E.SYN
sec
.8 rts
*--------------------------------------
CS.END
ARGS .BS 2
MSG.DETECT .AZ "UtherNet2/W5100 Driver."
MSG.DETECT.OK .AZ "UtherNet2/W5100 Installed As Device : %s\r\n"
MSG.DETECT.KO .AZ "Hardware Not Found."
SSCANF.MAC .AZ "%h:%h:%h:%h:%h:%h"
*--------------------------------------
FD.DEV .DA #S.FD.T.CDEV
.DA #0 HANDLER
.DA #0 BUSID
.DA #0 DEVID
.DA 0 BUSPTR
.BS 2 DRVPTR
FD.DEV.NAME .AZ "ETH7" NAME
.HS 000000
*--------------------------------------
* Driver Code
*--------------------------------------
ZPIOCTL .EQ ZPDRV
ZPBufPtr .EQ ZPDRV+2
Counter .EQ ZPDRV+4
Offset .EQ ZPDRV+6
RXTX.Size .EQ ZPDRV+8
*--------------------------------------
DRV.CS.START cld
jmp (.1,x)
.1 .DA STATUS
.DA A2osX.BADCALL
.DA A2osX.BADCALL
.DA A2osX.BADCALL
.DA CONTROL
.DA A2osX.BADCALL
.DA OPEN
.DA CLOSE
.DA READ
.DA WRITE
.DA A2osX.BADCALL IRQ
.DA 0 end or relocation
*--------------------------------------
STATUS >STYA ZPIOCTL
ldy #S.IOCTL.STATCODE
lda (ZPIOCTL),y
beq .1
cmp #S.IOCTL.STATCODE.GETDIB
bne STATUS.DCB
ldx #S.DIB-1
.HS 2C bit abs
.1 ldx #3
ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .3+1
iny
lda (ZPIOCTL),y
sta .3+2
.2 lda DIB,x
.3 sta $ffff,x SELF MODIFIED
dex
bpl .2
clc
rts
STATUS.DCB cmp #S.IOCTL.STATCODE.GETDCB
bne STATUS.9
.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .3+1
iny
lda (ZPIOCTL),y
sta .3+2
ldx #S.DCB.NIC-1
.2 lda DCB,x
.3 sta $ffff,x SELF MODIFIED
dex
bpl .2
clc
rts
STATUS.9 lda #MLI.E.BADCTL
sec
rts
*--------------------------------------
CONTROL >STYA ZPIOCTL
ldy #S.IOCTL.CTRLCODE
lda (ZPIOCTL),y
cmp #S.IOCTL.CTRLCODE.SETDCB
bne STATUS.9
.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .2+1
iny
lda (ZPIOCTL),y
sta .2+2
ldx #S.DCB.NIC-1
.2 lda $ffff,x SELF MODIFIED
sta DCB,x
dex
bpl .2
clc
rts
*--------------------------------------
OPEN jsr CLOSE
* ldx DEVSLOTx0 Done by CLOSE
lda #W5100.MR.AI+W5100.MR.IND
sta W5100.MR,x
>AR.SELECT SHAR
ldy #0
.1 lda DCB+S.DCB.NIC.MAC,y
sta W5100.DR,x
iny
cpy #6
bne .1
>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
>AR.SELECT S0.MR
lda #W5100.AR.S0.MR.MACRAW+W5100.AR.S0.MR.MF
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
*--------------------------------------
READ php
sei
>STYA ZPIOCTL
ldx DEVSLOTx0
>AR.SELECT S0.RX.RSR
lda W5100.DR,x get the received size HI
ora W5100.DR,x LO
bne .1
lda #MLI.E.EOF
.9 plp
sec
rts
.1 >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
lda W5100.DR,x get RX.Size HI
sta RXTX.Size+1
ldy W5100.DR,x get RX.Size LO
sty RXTX.Size
>SYSCALL getmem
bcs .9
>STYA ZPBufPtr
stx .8+1
phy
ldy #S.IOCTL.BUFPTR+1
sta (ZPIOCTL),y
dey
pla
sta (ZPIOCTL),y
ldy #S.IOCTL.BYTECNT
lda RXTX.Size
sec
sbc #2 Header Size
sta (ZPIOCTL),y
eor #$ff
sta Counter
iny
lda RXTX.Size+1
sbc #0
sta (ZPIOCTL),y
eor #$ff
sta Counter+1
ldx DEVSLOTx0
ldy #0
.2 inc Counter
bne .3
inc Counter+1
beq .4
.3 lda W5100.DR,x
sta (ZPBufPtr),y
iny
bne .2
inc ZPBufPtr+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 SELF MODIFIED hMem
plp
clc
rts
*--------------------------------------
WRITE php
sei
>STYA ZPIOCTL
ldx DEVSLOTx0
ldy #S.IOCTL.BYTECNT
lda (ZPIOCTL),y
sta RXTX.Size
eor #$ff
sta Counter
iny
lda (ZPIOCTL),y
sta RXTX.Size+1
eor #$ff
sta Counter+1
>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 WRITE.1
lda #MLI.E.EOF
plp
sec
rts
WRITE.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta ZPBufPtr
iny
lda (ZPIOCTL),y
sta ZPBufPtr+1
ldy #S.ETH.SRCMAC+5
ldx #5
.1 lda DCB+S.DCB.NIC.MAC,x
sta (ZPBufPtr),y
dey
dex
bpl .1
ldx DEVSLOTx0
>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 #0
.2 inc Counter
bne .3
inc Counter+1
beq .8
.3 lda (ZPBufPtr),y
sta W5100.DR,x
iny
bne .2
inc ZPBufPtr+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
plp
clc
rts
*--------------------------------------
DRV.CS.END
DEVSLOTx0 .BS 1
*--------------------------------------
DIB .DA #0
.DA #0,#0,#0 size
>PSTR "UtherNetII/W5100"
.DA #S.DIB.T.NIC
.BS 1 Subtype
.DA K.VER Version
*--------------------------------------
DCB .DA #S.DCB.T.NIC
.DA #0 FLAGS
.DA #S.DCB.NIC.LINK.OK+S.DCB.NIC.LINK.FD
.DA #S.DCB.NIC.SPEED.100
.HS 0008DC123456 MAC
.BS 12 IP/MASK/GW
*--------------------------------------
DRV.END
MAN
SAVE /A2OSX.SRC/DRV/UTHERNET2.DRV.S
ASM

555
DRV/X.U2.DRV.S.txt Normal file
View File

@ -0,0 +1,555 @@
NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.OP 65C02
.OR $2000
*--------------------------------------
.DO U2AI=1
.TF DRV/UTHER2.AI.DRV
.ELSE
.TF DRV/UTHERNET2.DRV
.FIN
*--------------------------------------
ZPArgPtr .EQ ZPDRV
*--------------------------------------
* 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 0
.DA 0
.DA 0
*--------------------------------------
* 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.DRV.CS.START .DA DRV.CS.START
L.FD.DEV .DA FD.DEV
L.FD.DEV.NAME .DA FD.DEV.NAME
L.SSCANF.MAC .DA SSCANF.MAC
L.MAC0 .DA DCB+S.DCB.NIC.MAC
L.MAC1 .DA DCB+S.DCB.NIC.MAC+1
L.MAC2 .DA DCB+S.DCB.NIC.MAC+2
L.MAC3 .DA DCB+S.DCB.NIC.MAC+3
L.MAC4 .DA DCB+S.DCB.NIC.MAC+4
L.MAC5 .DA DCB+S.DCB.NIC.MAC+5
.DA 0 End Of Reloc Table
*--------------------------------------
Dev.Detect >STYA ARGS
>LDYA L.MSG.DETECT
>SYSCALL puts
ldx #$70+$88
ldy #7
.1 lda A2osX.S,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 FD.DEV.NAME+3
txa
sec
sbc #$10
tax
dey
bne .1
>LDYA L.MSG.DETECT.KO
>SYSCALL puts
lda #MLI.E.NODEV
sec
rts
.3 stx DEVSLOTx0
lda #A2osX.S.NIC
sta A2osX.S,y
jsr Dev.ParseArgs
bcs .9
.8 >PUSHW L.FD.DEV.NAME
>PUSHBI 2
>LDYA L.MSG.DETECT.OK
>SYSCALL printf
>PUSHWI DRV.END
>PUSHWI DRV.CS.END
>PUSHWI DRV.CS.START
>LDYA L.DRV.CS.START
>SYSCALL InsDrv
bcs .9
>STYA FD.DEV+S.FD.DEV.DRVPTR
>LDYA L.FD.DEV
>SYSCALL MKDEV
.9 rts
*--------------------------------------
Dev.ParseArgs >LDYA ARGS
>STYA ZPArgPTR
lda (ZPArgPTR)
bne .1
lda A2osX.RANDOM16
eor A2osX.TIMER16
sta DCB+S.DCB.NIC.MAC+3
eor A2osX.RANDOM16+1
sta DCB+S.DCB.NIC.MAC+4
eor A2osX.TIMER16+1
sta DCB+S.DCB.NIC.MAC+5
clc
rts
.1 >PUSHW L.MAC5
>PUSHW L.MAC4
>PUSHW L.MAC3
>PUSHW L.MAC2
>PUSHW L.MAC1
>PUSHW L.MAC0
>PUSHBI 12 6 x byte PTRs
>PUSHW L.SSCANF.MAC
>LDYA ZPArgPtr
>SYSCALL sscanf
bcc .8
lda #K.E.SYN
sec
.8 rts
*--------------------------------------
CS.END
ARGS .BS 2
.DO U2AI=1
MSG.DETECT .AZ "UtherNet2/W5100 Driver (ARP/IP Offload)."
.ELSE
MSG.DETECT .AZ "UtherNet2/W5100 Driver."
.FIN
MSG.DETECT.OK .AZ "UtherNet2/W5100 Installed As Device : %s\r\n"
MSG.DETECT.KO .AZ "Hardware Not Found."
SSCANF.MAC .AZ "%h:%h:%h:%h:%h:%h"
*--------------------------------------
FD.DEV .DA #S.FD.T.CDEV
.DA #0 HANDLER
.DA #0 BUSID
.DA #0 DEVID
.DA 0 BUSPTR
.BS 2 DRVPTR
FD.DEV.NAME .AZ "ETH7" NAME
.HS 000000
*--------------------------------------
* Driver Code
*--------------------------------------
ZPIOCTL .EQ ZPDRV
ZPBufPtr .EQ ZPDRV+2
Counter .EQ ZPDRV+4
Offset .EQ ZPDRV+6
RXTX.Size .EQ ZPDRV+8
.DO U2AI=1
RX.IP .EQ ZPDRV+10
.FIN
*--------------------------------------
DRV.CS.START cld
jmp (.1,x)
.1 .DA STATUS
.DA A2osX.BADCALL
.DA A2osX.BADCALL
.DA A2osX.BADCALL
.DA CONTROL
.DA A2osX.BADCALL
.DA OPEN
.DA CLOSE
.DA READ
.DA WRITE
.DA A2osX.BADCALL IRQ
.DA 0 end or relocation
*--------------------------------------
STATUS >STYA ZPIOCTL
ldy #S.IOCTL.STATCODE
lda (ZPIOCTL),y
beq .1
cmp #S.IOCTL.STATCODE.GETDIB
bne STATUS.DCB
ldx #S.DIB-1
.HS 2C bit abs
.1 ldx #3
ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .3+1
iny
lda (ZPIOCTL),y
sta .3+2
.2 lda DIB,x
.3 sta $ffff,x SELF MODIFIED
dex
bpl .2
clc
rts
STATUS.DCB cmp #S.IOCTL.STATCODE.GETDCB
bne STATUS.9
.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .3+1
iny
lda (ZPIOCTL),y
sta .3+2
ldx #S.DCB.NIC-1
.2 lda DCB,x
.3 sta $ffff,x SELF MODIFIED
dex
bpl .2
clc
rts
STATUS.9 lda #MLI.E.BADCTL
sec
rts
*--------------------------------------
CONTROL >STYA ZPIOCTL
ldy #S.IOCTL.CTRLCODE
lda (ZPIOCTL),y
cmp #S.IOCTL.CTRLCODE.SETDCB
bne STATUS.9
.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .2+1
iny
lda (ZPIOCTL),y
sta .2+2
ldx #S.DCB.NIC-1
.2 lda $ffff,x SELF MODIFIED
sta DCB,x
dex
bpl .2
clc
rts
*--------------------------------------
OPEN jsr CLOSE
* ldx DEVSLOTx0 Done by CLOSE
lda #W5100.MR.AI+W5100.MR.IND
sta W5100.MR,x
>AR.SELECT SHAR
ldy #0
.1 lda DCB+S.DCB.NIC.MAC,y
sta W5100.DR,x
iny
cpy #6
bne .1
>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
>AR.SELECT S0.MR
lda #W5100.AR.S0.MR.MACRAW+W5100.AR.S0.MR.MF
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
*--------------------------------------
READ php
sei
>STYA ZPIOCTL
ldx DEVSLOTx0
>AR.SELECT S0.RX.RSR
lda W5100.DR,x get the received size HI
ora W5100.DR,x LO
bne .1
lda #MLI.E.EOF
.9 plp
sec
rts
.1 >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
lda W5100.DR,x get RX.Size HI
sta RXTX.Size+1
ldy W5100.DR,x get RX.Size LO
sty RXTX.Size
>SYSCALL getmem
bcs .9
>STYA ZPBufPtr
stx .8+1
phy
ldy #S.IOCTL.BUFPTR+1
sta (ZPIOCTL),y
dey
pla
sta (ZPIOCTL),y
ldy #S.IOCTL.BYTECNT
lda RXTX.Size
sec
sbc #2 Header Size
sta (ZPIOCTL),y
eor #$ff
sta Counter
iny
lda RXTX.Size+1
sbc #0
sta (ZPIOCTL),y
eor #$ff
sta Counter+1
ldx DEVSLOTx0
ldy #0
.2 inc Counter
bne .3
inc Counter+1
beq .4
.3 lda W5100.DR,x
sta (ZPBufPtr),y
iny
bne .2
inc ZPBufPtr+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 SELF MODIFIED hMem
plp
clc
rts
*--------------------------------------
WRITE php
sei
>STYA ZPIOCTL
ldx DEVSLOTx0
ldy #S.IOCTL.BYTECNT
lda (ZPIOCTL),y
sta RXTX.Size
eor #$ff
sta Counter
iny
lda (ZPIOCTL),y
sta RXTX.Size+1
eor #$ff
sta Counter+1
>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 WRITE.1
lda #MLI.E.EOF
plp
sec
rts
WRITE.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta ZPBufPtr
iny
lda (ZPIOCTL),y
sta ZPBufPtr+1
ldy #S.ETH.SRCMAC+5
ldx #5
.1 lda DCB+S.DCB.NIC.MAC,x
sta (ZPBufPtr),y
dey
dex
bpl .1
ldx DEVSLOTx0
>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 #0
.2 inc Counter
bne .3
inc Counter+1
beq .8
.3 lda (ZPBufPtr),y
sta W5100.DR,x
iny
bne .2
inc ZPBufPtr+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
plp
clc
rts
*--------------------------------------
DRV.CS.END
DEVSLOTx0 .BS 1
*--------------------------------------
DIB .DA #0
.DA #0,#0,#0 size
>PSTR "UtherNetII/W5100"
.DA #S.DIB.T.NIC
.BS 1 Subtype
.DA K.VER Version
*--------------------------------------
DCB .DA #S.DCB.T.NIC
.DO U2AI=1
.DA #S.DCB.NIC.FLAGS.ARPOFFLOAD+S.DCB.NIC.FLAGS.IPOFFLOAD
.ELSE
.DA #0 FLAGS
.FIN
.DA #S.DCB.NIC.LINK.OK+S.DCB.NIC.LINK.FD
.DA #S.DCB.NIC.SPEED.100
.HS 0008DC123456 MAC
.DA #0,#0,#0,#0 IP
.DA #255,#255,#255,#255 MASK
.DA #0,#0,#0,#0 GW
*--------------------------------------
DRV.END
MAN
SAVE /A2OSX.SRC/DRV/X.U2.DRV.S
LOAD /A2OSX.SRC/DRV/UTHER2.AI.DRV.S
ASM