A2osX/SBIN/TCPIP.S.txt

553 lines
9.8 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/SBIN/TCPIP
2015-03-14 21:48:35 +00:00
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBTCPIP.I
*--------------------------------------
2016-03-16 07:19:54 +00:00
ZPIPCfgPtr .EQ ZPBIN
ZPIPDevPtr .EQ ZPBIN+2
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
* File Header (16 Bytes)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.START cld
jmp (.1,x)
2015-06-03 18:30:57 +00:00
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA 0
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
2015-03-14 21:48:35 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.DEVNAME .DA DEVNAME
L.MSG.DEV.KO .DA MSG.DEV.KO
L.MSG.DEV.OK .DA MSG.DEV.OK
L.MSG.CFG .DA MSG.CFG
L.MSG.CFG.KO .DA MSG.CFG.KO
L.MSG.CFG.OK .DA MSG.CFG.OK
L.HOSTNAME .DA HOSTNAME
L.TCPIP.CONF .DA TCPIP.CONF
L.HOSTS .DA HOSTS
2015-03-14 21:48:35 +00:00
L.IPCFG .DA IPCFG
.DA 0
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL SYS.LoadLibYA
2015-03-14 21:48:35 +00:00
bcs .99
sta hLIBTCPIP
jsr CS.INIT.DEV
2015-03-14 21:48:35 +00:00
bcs .99
jsr CFG.Read continue even if error opening CFG file
2015-03-14 21:48:35 +00:00
lda IPCFG+S.IPCFG.HOSTNAME
bne .4
2015-03-14 21:48:35 +00:00
ldy #0
.2 lda DefaultHostName,y
beq .3
sta IPCFG+S.IPCFG.HOSTNAME,y
2015-03-14 21:48:35 +00:00
iny
bne .2
.3 lda A2osX.TIMER16
jsr A2CharAX
sta IPCFG+S.IPCFG.HOSTNAME,y
iny
txa
sta IPCFG+S.IPCFG.HOSTNAME,y
iny
lda A2osX.TIMER16+1
jsr A2CharAX
sta IPCFG+S.IPCFG.HOSTNAME,y
iny
txa
sta IPCFG+S.IPCFG.HOSTNAME,y
iny
lda #0
sta IPCFG+S.IPCFG.HOSTNAME,y
.4 >PUSHW L.IPCFG
>LIBCALL hLIBTCPIP,LIBTCPIP.SET.IPCFG
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
lda (pPs)
2015-03-14 21:48:35 +00:00
ora #S.PS.F.EVENT Now accept events
2015-06-03 18:30:57 +00:00
sta (pPs)
2015-03-14 21:48:35 +00:00
clc
.99 rts
*--------------------------------------
CS.INIT.DEV >LDYA L.DEVNAME
>SYSCALL SYS.GetDevByNameYA
bcc .1
inc DEVNAME+4
lda DEVNAME+4
cmp #'8'
bne CS.INIT.DEV
>LDYA L.MSG.DEV.KO
>SYSCALL SYS.PSTROutYA
lda #DEVMGR.ERRDNF
sec
rts
.1 >STYA pNetDevJmp+1
2015-06-03 18:30:57 +00:00
txa
sta hNetDev
sta IPCFG+S.IPCFG.HDEV
>PUSHW L.DEVNAME
>LDYA L.MSG.DEV.OK
>SYSCALL SYS.PSTROutYA
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
ldx #DEVMGR.OPEN
jsr pNetDevJmp
bcs .9
2015-06-03 18:30:57 +00:00
ldx #DEVMGR.GETINFO
jsr pNetDevJmp
bcs .9
>STYA ZPIPDevPtr
2015-06-03 18:30:57 +00:00
ldy #1
lda (ZPIPDevPtr),y
sta DEVFLAGS
iny
2015-03-14 21:48:35 +00:00
ldx #S.IPCFG.MAC
.2 lda (ZPIPDevPtr),y
2015-03-14 21:48:35 +00:00
sta IPCFG,x
iny
2015-06-03 18:30:57 +00:00
inx
cpx #S.IPCFG.MAC+6
bne .2
2015-03-14 21:48:35 +00:00
clc
rts
.9 sec
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.RUN clc
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT lda (pEvent)
2015-03-14 21:48:35 +00:00
and #S.EVT.F.NET
beq .9
ldy #S.EVT.hDEV
lda (pEvent),y
cmp hNetDev
bne .9
2015-03-14 21:48:35 +00:00
ldy #S.EVT.DATALO Get Frame hMem
2015-03-14 21:48:35 +00:00
lda (pEvent),y
>LIBCALL hLIBTCPIP,LIBTCPIP.RCVD.FRAMEA
2015-03-14 21:48:35 +00:00
rts
.9 sec
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
CS.QUIT lda IPCFG+S.IPCFG.HDEV
beq .1
ldx #DEVMGR.CLOSE
jsr pNetDevJmp
2015-06-03 18:30:57 +00:00
.1 lda hLIBTCPIP
2015-10-19 20:35:00 +00:00
>SYSCALL SYS.UnloadLibA
2015-03-14 21:48:35 +00:00
clc
rts
*--------------------------------------
CFG.Read >PUSHW L.HOSTNAME
>LDYA L.MSG.CFG
>SYSCALL SYS.PSTROutYA
jsr CFG.Read.HOSTNAME
bcc .1
>PUSHA
>LDYA L.MSG.CFG.KO
>SYSCALL SYS.PSTROutYA
bra .2
.1 >LDYA L.MSG.CFG.OK
>SYSCALL SYS.PSTROutYA
.2 >PUSHW L.TCPIP.CONF
>LDYA L.MSG.CFG
>SYSCALL SYS.PSTROutYA
jsr CFG.Read.TCPIP.CONF
bcc .3
>PUSHA
>LDYA L.MSG.CFG.KO
>SYSCALL SYS.PSTROutYA
bra .4
.3 >LDYA L.MSG.CFG.OK
>SYSCALL SYS.PSTROutYA
.4 >PUSHW L.HOSTS
>LDYA L.MSG.CFG
>SYSCALL SYS.PSTROutYA
jsr CFG.Read.HOSTS
bcc .5
>PUSHA
>LDYA L.MSG.CFG.KO
>SYSCALL SYS.PSTROutYA
bra .6
.5 >LDYA L.MSG.CFG.OK
>SYSCALL SYS.PSTROutYA
.6 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.Read.HOSTNAME
>LDYA L.HOSTNAME
>SYSCALL SYS.LoadFileYA
bcs .99
stx CFG.hCfgFile
>STYA CFG.FileLen
txa
>SYSCALL SYS.GetMemPtrA
>STYA ZPIPCfgPtr
2015-03-14 21:48:35 +00:00
lda CFG.FileLen+1
bne .2
ldy CFG.FileLen
beq .2
cpy #15
bcs .2
sta IPCFG+S.IPCFG.HOSTNAME,y
2015-03-14 21:48:35 +00:00
.1 dey
bmi .89
lda (ZPIPCfgPtr),y
sta IPCFG+S.IPCFG.HOSTNAME,y
bra .1
.2 jsr .89
sec
2015-03-14 21:48:35 +00:00
rts
.89 lda CFG.hCfgFile
>SYSCALL SYS.FreeMemA
clc
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.Read.TCPIP.CONF
>LDYA L.TCPIP.CONF
>SYSCALL SYS.LoadFileYA
bcs .99
stx CFG.hCfgFile
>STYA CFG.FileLen
txa
>SYSCALL SYS.GetMemPtrA
>STYA ZPIPCfgPtr
.1 jsr CFG.GetLine
bcs .89
jsr CFG.GetKeyword
bcs .1
lda CFG.Keyword
bne .3
ldy TmpBuffer256
lda TmpBuffer256+1,y
cmp #35 DOMAIN too long!!!
bcs .1
sta IPCFG+S.IPCFG.DOMAIN
ldx #0
.2 lda TmpBuffer256+2,y
sta IPCFG+S.IPCFG.DOMAIN,x
beq .1
inx
iny
bne .2
bra .1
.3 jsr CFG.ScanIP
bcs .1
ldy CFG.Keyword
lda CFG.Keyword.Map,y
tax
ldy #0
.4 lda CFG.IP+1,y
sta IPCFG,x
inx
iny
cpy #4
bne .4
lda CFG.Keyword
cmp #1
bne .1
lda #S.IPCFG.STATUS.OK
sta IPCFG
bra .1
.89 lda CFG.hCfgFile
>SYSCALL SYS.FreeMemA
clc
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.Read.HOSTS >LDYA L.HOSTS
>SYSCALL SYS.LoadFileYA
bcs .99
stx CFG.hCfgFile
>STYA CFG.FileLen
txa
>SYSCALL SYS.GetMemPtrA
>STYA ZPIPCfgPtr
.89 lda CFG.hCfgFile
>SYSCALL SYS.FreeMemA
clc
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.GetLine stz TmpBuffer256
ldx #0
ldy #0
.1 jsr CFG.GetChar
bne .2 end of file?
txa
bne .8
sec
rts
.2 cmp #$0D
beq .8 end of line
inx
sta TmpBuffer256,x
cmp #'='
bne .3
txa
dec
tay
.3 cpx #64 line too long ?
bne .1
sec
rts
.8 tya = found ?
beq .9
sta TmpBuffer256
2015-03-14 21:48:35 +00:00
txa
sec
sbc TmpBuffer256
sta TmpBuffer256+1,y
stz TmpBuffer256+1,x End with 0 for ScanIP
clc
2015-03-14 21:48:35 +00:00
rts
.9 sec
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.GetChar lda CFG.FileLen
bne .1
lda CFG.FileLen+1
beq .9
dec CFG.FileLen+1
.1 dec CFG.FileLen
lda (ZPIPCfgPtr)
inc ZPIPCfgPtr
bne .9
inc ZPIPCfgPtr+1 NZ
.9 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.GetKeyword stz CFG.Keyword
ldx #0
.1 phx
ldy #0
.2 lda CFG.Keywords,x
cmp TmpBuffer256,y
bne .3
cpy TmpBuffer256
beq .4
inx
iny
bne .2
plx
sec
rts
.3 inc CFG.Keyword
plx
2015-03-14 21:48:35 +00:00
txa
sec
adc CFG.Keywords,x
tax
lda CFG.Keywords,x
bne .1
sec
rts
.4 plx
clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
CFG.ScanIP stz CFG.IP
ldx TmpBuffer256
.1 ldy #0
.11 lda TmpBuffer256+2,x
beq .3
cmp #'0'
bcc .2
cmp #'9'+1
bcs .2
cpy #3
beq .9
iny
sta CFG.StrBuf,y
inx
bra .11
.2 cmp #'.'
bne .9
.3 sty CFG.StrBuf
lda CFG.IP
cmp #4
beq .9
jsr CFG.Dec2Hex
bcs .9
lda CFG.HexByte
inc CFG.IP
ldy CFG.IP
sta CFG.IP,y
inx
lda TmpBuffer256+1,x
bne .1
clc
rts
.9 sec
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CFG.Dec2Hex sec
ldy CFG.StrBuf
beq .9
lda CFG.StrBuf+1
and #$0f
sta CFG.HexByte
ldy #1
.1 cpy CFG.StrBuf
beq .8
iny
lda CFG.HexByte
asl CFG.HexByte
bcs .9
asl CFG.HexByte
bcs .9
adc CFG.HexByte
bcs .9
asl
bcs .9
sta CFG.HexByte
lda CFG.StrBuf,y
and #$0f
adc CFG.HexByte
sta CFG.HexByte
bcc .1
.9 rts
.8 clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
A2CharAX pha
lsr
lsr
lsr
lsr
and #$0F
ora #$30
cmp #'9'+1
bcc .1
adc #6
.1 tax
pla
and #$0F
ora #$30
cmp #'9'+1
bcc .8
adc #6
.8 rts
*--------------------------------------
pNetDevJmp jmp *
*--------------------------------------
2015-03-14 21:48:35 +00:00
CS.END
*--------------------------------------
LIBTCPIP >PSTRING "libtcpip.o"
DEVNAME >PSTRING "ETH1"
MSG.DEV.KO >PSTRING "TCPIP:No Device Found, exiting.\n"
MSG.DEV.OK >PSTRING "TCPIP:Bound To Device : %S\n"
2016-01-10 22:18:12 +00:00
MSG.CFG >PSTRING "TCPIP:Reading %S..."
MSG.CFG.KO >PSTRING "Failed!!! [%h]\n"
MSG.CFG.OK >PSTRING "OK.\n"
HOSTNAME >PSTRING "${A2OSX}ETC/HOSTNAME"
TCPIP.CONF >PSTRING "${A2OSX}ETC/TCPIP.CONF"
HOSTS >PSTRING "${A2OSX}ETC/HOSTS"
DefaultHostName >CSTRING "a2osx-"
CFG.Keywords >PSTRING "DOMAIN"
>PSTRING "IP"
>PSTRING "MASK"
>PSTRING "GW"
>PSTRING "DNS1"
>PSTRING "DNS2"
CFG.Keyword.Map .DA #0 End Of Keyword table and NA Keyword
.DA #S.IPCFG.IP
.DA #S.IPCFG.MASK
.DA #S.IPCFG.GW
.DA #S.IPCFG.DNS1
.DA #S.IPCFG.DNS2
2015-03-14 21:48:35 +00:00
hLIBTCPIP .BS 1
hNetDev .BS 1
DEVFLAGS .BS 1
IPCFG .BS S.IPCFG
CFG.hCfgFile .BS 1
CFG.FileLen .BS 2
CFG.Keyword .BS 1
CFG.StrBuf .BS 4
CFG.HexByte .BS 1
CFG.IP .BS 5
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE SBIN/TCPIP.S
ASM