A2osX/LIB/LIBTCPIP.S.txt
2016-01-16 23:04:22 +01:00

312 lines
6.3 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/LIB/LIBTCPIP.O
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBTCPIP.I
*--------------------------------------
ZPFrameBase1 .EQ ZPLIB
ZPFrameLen1 .EQ ZPLIB+2
ZPFramePtr1 .EQ ZPLIB+4
ZPFrameBase2 .EQ ZPBIN+6
ZPFrameLen2 .EQ ZPBIN+8
ZPFramePtr2 .EQ ZPBIN+10
ZPPtrIP .EQ ZPLIB+12
ZPPtrMAC .EQ ZPLIB+14
ZPPtrDNS .EQ ZPLIB+16
ZPPtrSKT .EQ ZPLIB+18
ZPTmpPtr1 .EQ ZPLIB+20
ZPTmpPtr2 .EQ ZPLIB+22
ZPDataPtr .EQ ZPLIB+24
ZPDataLen .EQ ZPLIB+26
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START
.DA 0
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA LIB.LOAD
.DA LIB.UNLOAD
.DA SET.IPCFG
.DA GET.IPCFG
.DA NEW.ICMP.FRAME
.DA NEW.TCP.FRAME
.DA NEW.UDP.FRAME
.DA NEW.IP.FRAME
.DA NEW.ARP.FRAME
.DA NEW.ETH.FRAME
.DA SEND.ICMP.FRAME
.DA SEND.TCP.FRAME
.DA SEND.UDP.FRAME
.DA SEND.IP.FRAME
.DA SEND.ARP.FRAME
.DA SEND.ETH.FRAME
.DA ARP.CLEAR
.DA ARP.QUERY
.DA ARP.ADD
.DA ARP.GETCACHE
.DA DNS.CLEAR
.DA DNS.QUERY
.DA DNS.ADD
.DA DNS.GETCACHE
.DA ARP.IN
.DA IP.IN
.DA SKT.NEW
.DA SKT.LISTEN
.DA SKT.ACCEPT
.DA SKT.SENDA
.DA SKT.SEND
.DA SKT.RCVDA
.DA SKT.RCVD
.DA SKT.CLOSE
.DA SKT.GETTABLE
*--------------------------------------
L.IPCFG .DA IPCFG
L.ARP.CACHE .DA ARP.CACHE
L.DNS.CACHE .DA DNS.CACHE
L.SKT.TABLE .DA SKT.TABLE
.DA 0
*--------------------------------------
LIB.LOAD lda bFirstLoad
bne .8
jsr ARP.CLEAR
jsr DNS.CLEAR
>LDYA K.DYNPORT.START
>STYA DYNPORT.LAST
inc bFirstLoad
.8 clc
rts
*--------------------------------------
LIB.UNLOAD clc
rts
*--------------------------------------
* PULLW = PTR to S.IPCFG
*--------------------------------------
SET.IPCFG >PULLW ZPTmpPtr1
ldy #0
.1 lda (ZPTmpPtr1),y
sta IPCFG,y
iny
cpy #S.IPCFG
bne .1
lda IPCFG+S.IPCFG.HDEV
>SYSCALL SYS.GetDevByIDA
>STYA NetDevJmp+1
ldx #DEVMGR.GETINFO
jsr NetDevJmp
>STYA ZPTmpPtr2
ldy #S.DEVINFO.FLAGS
lda (ZPTmpPtr2),y
sta DevFlags
and #S.DEVINFO.FLAGS.ARPOFFLOAD
beq .2
>LDYA ZPTmpPtr1
ldx #DEVMGR.SETIPCFG
jsr NetDevJmp
.2 >LDYA ZPTmpPtr1
clc
rts
*--------------------------------------
* grab a copy on the fly for lib function
* OUT :
* Y,A = PTR to S.IPCFG
*--------------------------------------
GET.IPCFG >LDYA L.IPCFG
clc
rts
*--------------------------------------
ToLowerCaseA cmp #'A'
bcc .1
cmp #'Z'+1
bcs .1
adc #$20
.1 rts
*--------------------------------------
MakeIPReply >LDAXI S.IP.SRC
jsr SetFramePtr1AX
>LDAXI S.IP.DST
jsr SetFramePtr2AX
ldy #4
jsr CopyFramePtr12
>LDAXI S.IP.DST
jsr SetFramePtr1AX
>LDAXI S.IP.SRC
jsr SetFramePtr2AX
ldy #4
jsr CopyFramePtr12
>LDAXI S.ETH.SRCMAC
jsr SetFramePtr1AX
>LDAXI S.ETH.DSTMAC
jsr SetFramePtr2AX
ldy #6
jsr CopyFramePtr12
rts
*--------------------------------------
* A,X = Frame PTR
*--------------------------------------
SetFramePtr1AX clc
adc ZPFrameBase1
sta ZPFramePtr1
txa
adc ZPFrameBase1+1
sta ZPFramePtr1+1
rts
*--------------------------------------
* A,X = Frame PTR
*--------------------------------------
SetFramePtr2AX clc
adc ZPFrameBase2
sta ZPFramePtr2
txa
adc ZPFrameBase2+1
sta ZPFramePtr2+1
rts
*--------------------------------------
* Y = bytes to copy from ZPFramePtr1 to ZPFramePtr2
*--------------------------------------
CopyFramePtr12 dey
lda (ZPFramePtr1),y
sta (ZPFramePtr2),y
tya
bne CopyFramePtr12
rts
*--------------------------------------
GetDynPort inc DYNPORT.LAST
bne .1
inc DYNPORT.LAST+1
lda DYNPORT.LAST
sec
sbc #K.DYNPORT.END
lda DYNPORT.LAST+1
sbc /K.DYNPORT.END
bcs .1
>LDAXI K.DYNPORT.END
>STAX DYNPORT.LAST
rts CC
.1 >LDAX DYNPORT.LAST
clc
rts
*--------------------------------------
PSTR2DNSHostName >STYA ZPTmpPtr1
lda (ZPTmpPtr1)
beq .9
cmp #K.DNS.MAXLEN-1
bcs .9
tay
inc
sta DNSHostNameLen
lda #0 Ending 0
sta DNSHostName+1,y
ldx #0
.1 lda (ZPTmpPtr1),y
and #$7f
cmp #'.'
beq .2
cmp #'A'
bcc .10
cmp #'Z'+1
bcs .10
adc #$20
.10 inx
bra .3
.2 txa
ldx #0
.3 sta DNSHostName,y
dey
bne .1
stx DNSHostName
clc
rts
.9 sec
rts
*--------------------------------------
DecDataLen lda ZPDataLen
bne .1
lda ZPDataLen+1
beq .9
dec ZPDataLen+1
.1 dec ZPDataLen
lda #$FF Make NZ
.9 rts
*--------------------------------------
NetDevJmp jmp *
*--------------------------------------
.INB LIB/LIBTCPIP.S.FRM
.INB LIB/LIBTCPIP.S.ARP
.INB LIB/LIBTCPIP.S.IP
.INB LIB/LIBTCPIP.S.ICMP
.INB LIB/LIBTCPIP.S.UDP
.INB LIB/LIBTCPIP.S.TCP
.INB LIB/LIBTCPIP.S.DNS
.INB LIB/LIBTCPIP.S.SKT
*--------------------------------------
CS.END
*--------------------------------------
bFirstLoad .DA #0
Status .BS 1
DevFlags .BS 1
DNSMessageID .BS 2
DNSDynamicPort .BS 2
DNSHostTTL .BS 4
DNSHostName .BS K.DNS.MAXLEN+1
DNSHostNameLen .BS 1
IP.CHECKSUM .BS 4
IPCFG .BS S.IPCFG
ARP.CACHE .BS K.ARPCACHE.SIZE*S.ARPCACHE
DNS.CACHE .BS K.DNSCACHE.SIZE*S.DNSCACHE
SKT.TABLE .BS K.SKTTABLE.SIZE*S.SOCKET
hSocket .BS 1
bFound .BS 1
DYNPORT.LAST .BS 2
*TmpCounter .BS 2
TmpOffset .BS 2
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S
ASM