2016-01-16 22:04:22 +00:00
|
|
|
|
PR#3
|
|
|
|
|
PREFIX /A2OSX.SRC
|
|
|
|
|
NEW
|
|
|
|
|
INC 1
|
|
|
|
|
AUTO 6
|
|
|
|
|
.LIST OFF
|
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
* IN : PULLW = PTR to S.SOCKET template
|
|
|
|
|
* OUT :
|
|
|
|
|
* YA=PTR to new S.SOCKET
|
|
|
|
|
* X hSocket 128<x<255
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.NEW >PULLW ZPTmpPtr1
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.SRC.PORT+1
|
2016-03-13 22:09:00 +00:00
|
|
|
|
lda (ZPTmpPtr1),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
dey
|
2016-03-13 22:09:00 +00:00
|
|
|
|
ora (ZPTmpPtr1),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
jsr GetDynPort
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta (ZPTmpPtr1),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
txa
|
|
|
|
|
iny
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta (ZPTmpPtr1),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
|
|
|
|
.1 >LDYA L.SKT.TABLE
|
2016-03-13 22:09:00 +00:00
|
|
|
|
>STYA ZPTmpPtr2
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
stz TmpOffset to keep track of any free slot
|
|
|
|
|
|
2016-01-16 22:04:22 +00:00
|
|
|
|
ldx #0
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.2 lda (ZPTmpPtr2)
|
2016-01-16 22:04:22 +00:00
|
|
|
|
beq .4
|
2016-03-13 22:09:00 +00:00
|
|
|
|
cmp (ZPTmpPtr1)
|
|
|
|
|
bne .5
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
ldy #S.SOCKET.SRC.ADDR
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.3 lda (ZPTmpPtr1),y
|
|
|
|
|
cmp (ZPTmpPtr2),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
bne .5
|
2016-03-13 22:09:00 +00:00
|
|
|
|
iny
|
|
|
|
|
cpy #S.SOCKET.DST.PORT+2
|
|
|
|
|
bne .3
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
|
|
|
|
lda ERR.SBUSY
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.4 bit TmpOffset
|
|
|
|
|
bmi .5 Already found an empty slot
|
|
|
|
|
>LDYA ZPTmpPtr2
|
|
|
|
|
>STYA ZPTmpPtr3
|
|
|
|
|
txa
|
|
|
|
|
ora #$80
|
|
|
|
|
sta TmpOffset
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.5 lda ZPTmpPtr2
|
2016-01-16 22:04:22 +00:00
|
|
|
|
clc
|
|
|
|
|
adc #S.SOCKET
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta ZPTmpPtr2
|
2016-01-16 22:04:22 +00:00
|
|
|
|
bcc .6
|
2016-03-13 22:09:00 +00:00
|
|
|
|
inc ZPTmpPtr2+1
|
2016-01-16 22:04:22 +00:00
|
|
|
|
.6 inx
|
|
|
|
|
cpx #K.SKTTABLE.SIZE
|
|
|
|
|
bne .2
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
bit TmpOffset Did we found an empty slot ?
|
2016-01-16 22:04:22 +00:00
|
|
|
|
bpl .9
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET-1
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.7 lda (ZPTmpPtr1),y
|
|
|
|
|
sta (ZPTmpPtr3),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
dey
|
|
|
|
|
bpl .7
|
|
|
|
|
|
2016-03-16 07:19:54 +00:00
|
|
|
|
ldx TmpOffset
|
2016-03-13 22:09:00 +00:00
|
|
|
|
>LDYA ZPTmpPtr3
|
2016-01-16 22:04:22 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.9 lda #ERR.OOS
|
2016-01-16 22:04:22 +00:00
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
SKT.ACCEPTA jsr SKT.GetA
|
|
|
|
|
bcs .9
|
|
|
|
|
ldy #S.SOCKET.SO
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
and #S.SOCKET.SO.ACCEPTCONN
|
|
|
|
|
bne .99
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.LQ.HEAD
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
ldy #S.SOCKET.LQ.TAIL
|
|
|
|
|
cmp (ZPPtrSKT),y Queue Empty
|
|
|
|
|
beq .9 CC
|
|
|
|
|
pha
|
|
|
|
|
inc
|
|
|
|
|
cmp #S.SOCKET.LQ.MAX
|
|
|
|
|
bne .1
|
|
|
|
|
lda #0
|
|
|
|
|
.1 sta (ZPPtrSKT),y
|
|
|
|
|
pla
|
|
|
|
|
clc
|
|
|
|
|
adc #S.SOCKET.LQ
|
|
|
|
|
tay
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
clc
|
2016-01-16 22:04:22 +00:00
|
|
|
|
rts
|
2016-03-13 22:09:00 +00:00
|
|
|
|
|
|
|
|
|
.99 lda #ERR.SBAD
|
2016-01-16 22:04:22 +00:00
|
|
|
|
sec
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.9 rts
|
2016-01-16 22:04:22 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.SENDA
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.SEND >PULLB hSocket
|
|
|
|
|
pha
|
|
|
|
|
>PULLW ZPDataPtr
|
|
|
|
|
>PULLW ZPDataLen
|
|
|
|
|
|
|
|
|
|
pla
|
|
|
|
|
jsr SKT.GetA
|
|
|
|
|
bcs .9
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
cpx #S.SOCKET.SOCK.DGRAM
|
2016-01-16 22:04:22 +00:00
|
|
|
|
beq SKT.SEND.UDP
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
cpx #S.SOCKET.SOCK.STREAM
|
|
|
|
|
bne .99
|
|
|
|
|
jmp SKT.SEND.TCP
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.99 sec
|
2016-01-16 22:04:22 +00:00
|
|
|
|
.9 rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.SEND.UDP jsr NEW.UDP.FRAME
|
|
|
|
|
bcs .9
|
2016-03-13 22:09:00 +00:00
|
|
|
|
stx hFrame1
|
|
|
|
|
|
|
|
|
|
lda #S.UDP-2
|
2016-01-16 22:04:22 +00:00
|
|
|
|
clc
|
|
|
|
|
adc ZPDataLen
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta (ZPFrameBase1)
|
2016-01-16 22:04:22 +00:00
|
|
|
|
sta ZPFrameLen1
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
lda /S.UDP-2
|
2016-01-16 22:04:22 +00:00
|
|
|
|
adc ZPDataLen+1
|
2016-03-13 22:09:00 +00:00
|
|
|
|
ldy #1
|
|
|
|
|
sta (ZPFrameBase1),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
sta ZPFrameLen1+1
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.SRC.PORT
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
tax
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
ldy #S.UDP.SRCPORT
|
|
|
|
|
sta (ZPFrameBase1),y
|
|
|
|
|
iny
|
|
|
|
|
txa
|
|
|
|
|
sta (ZPFrameBase1),y
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
ldy #S.SOCKET.DST.ADDR
|
2016-01-16 22:04:22 +00:00
|
|
|
|
ldx #4
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtrSKT),y
|
|
|
|
|
pha
|
|
|
|
|
iny
|
|
|
|
|
dex
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
ldy #S.IP.DST+3
|
|
|
|
|
ldx #4
|
|
|
|
|
|
|
|
|
|
.2 pla
|
|
|
|
|
sta (ZPFrameBase1),y
|
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bne .2
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.DST.PORT
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
tax
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
ldy #S.UDP.DSTPORT
|
|
|
|
|
sta (ZPFrameBase1),y
|
|
|
|
|
iny
|
|
|
|
|
txa
|
|
|
|
|
sta (ZPFrameBase1),y
|
|
|
|
|
|
|
|
|
|
lda #S.UDP
|
|
|
|
|
clc
|
|
|
|
|
adc ZPFrameBase1
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta ZPFramePtr1
|
2016-01-16 22:04:22 +00:00
|
|
|
|
lda /S.UDP
|
|
|
|
|
adc ZPFrameBase1+1
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta ZPFramePtr1+1
|
2016-01-16 22:04:22 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
.3 jsr DecDataLen
|
|
|
|
|
beq .4
|
|
|
|
|
lda (ZPDataPtr),y
|
2016-03-13 22:09:00 +00:00
|
|
|
|
sta (ZPFramePtr1),y
|
2016-01-16 22:04:22 +00:00
|
|
|
|
iny
|
|
|
|
|
bne .3
|
|
|
|
|
inc ZPDataPtr
|
2016-03-13 22:09:00 +00:00
|
|
|
|
inc ZPFramePtr1
|
2016-01-16 22:04:22 +00:00
|
|
|
|
bra .3
|
|
|
|
|
|
2016-03-13 22:09:00 +00:00
|
|
|
|
.4 jsr SEND.UDP.FRAME.I
|
|
|
|
|
bcc .9
|
|
|
|
|
lda hFrame1
|
|
|
|
|
>SYSCALL SYS.FreeMemA
|
|
|
|
|
sec
|
2016-01-16 22:04:22 +00:00
|
|
|
|
.9 rts
|
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
SKT.SEND.TCP
|
|
|
|
|
bra *
|
2016-01-16 22:04:22 +00:00
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
SKT.RCVDA jsr SKT.GetA
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.DQ.TAIL
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.DQ.HEAD
|
|
|
|
|
cmp (ZPPtrSKT),y
|
|
|
|
|
beq .99
|
|
|
|
|
|
|
|
|
|
pha
|
|
|
|
|
inc
|
|
|
|
|
cmp #S.SOCKET.DQ.MAX
|
|
|
|
|
bne .1
|
|
|
|
|
lda #0
|
|
|
|
|
.1 sta (ZPPtrSKT),y
|
|
|
|
|
pla
|
|
|
|
|
clc
|
|
|
|
|
adc #S.SOCKET.DQ
|
|
|
|
|
tay
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
clc
|
2016-01-16 22:04:22 +00:00
|
|
|
|
rts
|
2016-03-13 22:09:00 +00:00
|
|
|
|
|
|
|
|
|
.99 sec
|
|
|
|
|
.9 rts
|
2016-01-16 22:04:22 +00:00
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
SKT.CLOSEA jsr SKT.GetA
|
|
|
|
|
bcs .9
|
|
|
|
|
cpx #S.SOCKET.SOCK.DGRAM
|
|
|
|
|
|
|
|
|
|
beq .8
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.SO
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
bit #S.SOCKET.SO.ACCEPTCONN
|
|
|
|
|
|
|
|
|
|
beq *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.8 lda #0
|
|
|
|
|
sta (ZPPtrSKT)
|
|
|
|
|
clc
|
|
|
|
|
.9 rts
|
2016-01-16 22:04:22 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.GETTABLE >LDYA L.SKT.TABLE
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
SKT.GetA stz ZPPtrSKT
|
|
|
|
|
|
|
|
|
|
and #$7f Strip off msb
|
|
|
|
|
lsr
|
|
|
|
|
ror ZPPtrSKT
|
|
|
|
|
lsr
|
|
|
|
|
ror ZPPtrSKT
|
|
|
|
|
lsr
|
|
|
|
|
ror ZPPtrSKT
|
|
|
|
|
pha
|
|
|
|
|
|
|
|
|
|
lda ZPPtrSKT
|
2016-01-16 22:04:22 +00:00
|
|
|
|
adc L.SKT.TABLE
|
|
|
|
|
sta ZPPtrSKT
|
2016-03-13 22:09:00 +00:00
|
|
|
|
pla
|
2016-01-16 22:04:22 +00:00
|
|
|
|
adc L.SKT.TABLE+1
|
|
|
|
|
sta ZPPtrSKT+1
|
2016-03-13 22:09:00 +00:00
|
|
|
|
|
2016-01-16 22:04:22 +00:00
|
|
|
|
lda (ZPPtrSKT)
|
|
|
|
|
beq .9
|
2016-03-13 22:09:00 +00:00
|
|
|
|
tax
|
|
|
|
|
>LDYA ZPPtrSKT
|
2016-01-16 22:04:22 +00:00
|
|
|
|
rts CC
|
|
|
|
|
|
|
|
|
|
.9 lda #ERR.SBAD
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-03-13 22:09:00 +00:00
|
|
|
|
* ZPPtrSKT -> actual socket
|
|
|
|
|
* A = hSocket
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.AddToQueueL pha
|
|
|
|
|
ldy #S.SOCKET.LQ.HEAD
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
tax
|
|
|
|
|
inc
|
|
|
|
|
cmp #S.SOCKET.LQ.MAX
|
|
|
|
|
bne .1
|
|
|
|
|
lda #0
|
|
|
|
|
.1 ldy #S.SOCKET.LQ.TAIL
|
|
|
|
|
cmp (ZPPtrSKT),y
|
|
|
|
|
beq .9 Queue full!!
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.LQ.HEAD
|
|
|
|
|
sta (ZPPtrSKT),y
|
|
|
|
|
txa
|
|
|
|
|
clc
|
|
|
|
|
adc #S.SOCKET.LQ
|
|
|
|
|
tay
|
|
|
|
|
pla
|
|
|
|
|
sta (ZPPtrSKT),y
|
|
|
|
|
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.9 pla
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.AddToQueueD ldy #S.SOCKET.DQ.HEAD
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
tax
|
|
|
|
|
inc
|
|
|
|
|
cmp #S.SOCKET.DQ.MAX
|
|
|
|
|
bne .1
|
|
|
|
|
lda #0
|
|
|
|
|
.1 ldy #S.SOCKET.DQ.TAIL
|
|
|
|
|
cmp (ZPPtrSKT),y
|
|
|
|
|
beq .9 Queue full!!
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.DQ.HEAD
|
|
|
|
|
sta (ZPPtrSKT),y
|
|
|
|
|
txa
|
|
|
|
|
clc
|
|
|
|
|
adc #S.SOCKET.DQ
|
|
|
|
|
tay
|
|
|
|
|
lda hFrame1
|
|
|
|
|
sta (ZPPtrSKT),y
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.9 sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.AddToQueueS
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.9 sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
SKT.TCPSendSYNACKA
|
|
|
|
|
jsr SKT.GetA
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.SRC.ADDR+3
|
|
|
|
|
ldx #3
|
|
|
|
|
.1 lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.IP.SRC,x
|
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.SRC.PORT
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.TCP.SRCPORT+1
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.TCP.SRCPORT
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.DST.ADDR+3
|
|
|
|
|
ldx #3
|
|
|
|
|
.2 lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.IP.DST,x
|
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .2
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.DST.PORT
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.TCP.DSTPORT+1
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.TCP.DSTPORT
|
|
|
|
|
|
|
|
|
|
ldy #S.SOCKET.SQ.SEQNUM+7
|
|
|
|
|
ldx #7
|
|
|
|
|
.3 lda (ZPPtrSKT),y
|
|
|
|
|
sta TCP.MSG+S.TCP.SEQ.NUMBER,x
|
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .3
|
|
|
|
|
|
|
|
|
|
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
|
|
|
|
|
sta TCP.MSG+S.TCP.OPTIONS
|
|
|
|
|
|
|
|
|
|
>PUSHW L.TCP.MSG
|
|
|
|
|
jsr SEND.TCP.FRAME
|
|
|
|
|
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-01-16 22:04:22 +00:00
|
|
|
|
MAN
|
|
|
|
|
SAVE LIB/LIBTCPIP.S.SKT
|
|
|
|
|
LOAD LIB/LIBTCPIP.S
|
|
|
|
|
ASM
|