2016-03-13 21:54:28 +00:00
|
|
|
|
PR#3
|
|
|
|
|
PREFIX /A2OSX.SRC
|
|
|
|
|
NEW
|
|
|
|
|
INC 1
|
|
|
|
|
AUTO 6
|
|
|
|
|
.LIST OFF
|
|
|
|
|
.OP 65C02
|
|
|
|
|
.OR $2000
|
|
|
|
|
.TF /A2OSX.BOOT/SBIN/HTTPD
|
|
|
|
|
*--------------------------------------
|
2016-10-26 20:51:06 +00:00
|
|
|
|
.INB /A2OSX.DEV/INC/MACROS.I
|
|
|
|
|
.INB /A2OSX.DEV/INC/A2OSX.I
|
|
|
|
|
.INB /A2OSX.DEV/INC/LIBTCPIP.I
|
2016-03-13 21:54:28 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
TIMEOUT.MAX .EQ 30 30 sec.
|
2017-02-15 16:14:41 +00:00
|
|
|
|
CONN.MAX .EQ 16
|
2016-03-13 21:54:28 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
ZPIPCfgPtr .EQ ZPBIN
|
|
|
|
|
ZPSktPtr .EQ ZPBIN+2
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* 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 Code Length To Relocate
|
|
|
|
|
.DA DS.END-DS.START Data Segment to Allocate
|
|
|
|
|
.DA 0
|
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Relocation Table
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.1 .DA CS.INIT
|
|
|
|
|
.DA CS.RUN
|
|
|
|
|
.DA CS.DOEVENT
|
|
|
|
|
.DA CS.QUIT
|
|
|
|
|
L.LIBTCPIP .DA LIBTCPIP
|
|
|
|
|
L.Socket .DA Socket
|
|
|
|
|
L.MSG.TCPWAIT .DA MSG.TCPWAIT
|
|
|
|
|
L.MSG.INITOK .DA MSG.INITOK
|
|
|
|
|
L.MSG.TCPIPERR .DA MSG.TCPIPERR
|
|
|
|
|
L.MSG.SKTERR .DA MSG.SKTERR
|
|
|
|
|
L.MSG.ABORT .DA MSG.ABORT
|
|
|
|
|
L.MSG.INCOMING .DA MSG.INCOMING
|
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.INIT >LDYA L.LIBTCPIP
|
2016-10-24 15:54:43 +00:00
|
|
|
|
>SYSCALL LoadLibYA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
sta hLIBTCPIP
|
|
|
|
|
|
|
|
|
|
lda (pPs)
|
|
|
|
|
ora #S.PS.F.EVENT Now accept events
|
|
|
|
|
sta (pPs)
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.RUN jsr Init.Timeout
|
|
|
|
|
|
|
|
|
|
>LDYA L.MSG.TCPWAIT
|
2016-11-03 16:23:46 +00:00
|
|
|
|
>SYSCALL CPrintFYA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
|
|
|
|
|
.1 >LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG is TCPIP loaded ?
|
|
|
|
|
bcs .99
|
|
|
|
|
>STYA ZPIPCfgPtr
|
|
|
|
|
|
|
|
|
|
lda (ZPIPCfgPtr) Configured ?
|
|
|
|
|
bmi CS.RUN.INIT
|
|
|
|
|
|
2016-10-24 15:54:43 +00:00
|
|
|
|
>SYSCALL Sleep
|
2016-03-13 21:54:28 +00:00
|
|
|
|
jsr Wait.Timeout
|
|
|
|
|
bcc .1
|
2017-01-28 22:05:20 +00:00
|
|
|
|
>SYSCALL GetC
|
|
|
|
|
bcs .1
|
|
|
|
|
cmp #$03
|
|
|
|
|
bne .1
|
|
|
|
|
jmp CS.RUN.ABORT
|
2016-03-13 21:54:28 +00:00
|
|
|
|
|
|
|
|
|
.99 >LDYA L.MSG.TCPIPERR
|
2016-11-03 16:23:46 +00:00
|
|
|
|
>SYSCALL CPrintFYA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
lda #SYSMGR.ERRSYN
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
CS.RUN.INIT ldx #3
|
|
|
|
|
ldy #S.IPCFG.IP+3
|
|
|
|
|
.1 lda (ZPIPCfgPtr),y
|
|
|
|
|
sta Socket.Src.Addr,x
|
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
>PUSHW L.Socket
|
2017-02-15 21:46:21 +00:00
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New
|
2016-03-13 21:54:28 +00:00
|
|
|
|
bcs .9
|
|
|
|
|
txa
|
2017-02-15 16:14:41 +00:00
|
|
|
|
ldy #hSrvSocket
|
2016-03-13 21:54:28 +00:00
|
|
|
|
sta (pData),y
|
|
|
|
|
|
|
|
|
|
>LDYA L.MSG.INITOK
|
2016-11-03 16:23:46 +00:00
|
|
|
|
>SYSCALL CPrintFYA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
|
2016-10-24 15:54:43 +00:00
|
|
|
|
.11 >SYSCALL Sleep
|
2016-03-13 21:54:28 +00:00
|
|
|
|
|
2017-02-15 16:14:41 +00:00
|
|
|
|
.12 ldy #hSrvSocket
|
2016-03-13 21:54:28 +00:00
|
|
|
|
lda (pData),y
|
|
|
|
|
|
2017-02-15 21:46:21 +00:00
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.AcceptA
|
2017-02-15 16:14:41 +00:00
|
|
|
|
bcs .15
|
|
|
|
|
|
|
|
|
|
pha
|
|
|
|
|
|
|
|
|
|
ldy #hSockets
|
|
|
|
|
ldx #CONN.MAX
|
|
|
|
|
|
|
|
|
|
.13 lda (pData),y
|
|
|
|
|
beq .14
|
|
|
|
|
iny
|
|
|
|
|
dex
|
|
|
|
|
bne .13
|
|
|
|
|
|
|
|
|
|
pla
|
2017-02-15 21:46:21 +00:00
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CloseA
|
2017-02-15 16:14:41 +00:00
|
|
|
|
bra .15
|
|
|
|
|
|
|
|
|
|
.14 pla
|
|
|
|
|
sta (pData),y
|
|
|
|
|
|
2017-02-15 21:46:21 +00:00
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GetA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
>STYA ZPSktPtr
|
|
|
|
|
|
|
|
|
|
ldx #3
|
|
|
|
|
ldy #S.SOCKET.DST.ADDR+3
|
|
|
|
|
|
|
|
|
|
.2 >PUSHB (ZPSktPtr),y
|
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .2
|
|
|
|
|
|
|
|
|
|
>LDYA L.MSG.INCOMING
|
2016-11-03 16:23:46 +00:00
|
|
|
|
>SYSCALL CPrintFYA
|
2017-02-15 16:14:41 +00:00
|
|
|
|
|
|
|
|
|
.15 ldy #SktIndex
|
|
|
|
|
lda (pData),y
|
|
|
|
|
tay
|
|
|
|
|
lda (pData),y hSockets
|
|
|
|
|
|
|
|
|
|
beq .16
|
|
|
|
|
|
|
|
|
|
jsr CS.RUN.CLIENT
|
|
|
|
|
|
|
|
|
|
.16 ldy #SktIndex
|
|
|
|
|
lda (pData),y
|
|
|
|
|
inc
|
|
|
|
|
cmp #CONN.MAX
|
|
|
|
|
bne .17
|
|
|
|
|
lda #0
|
|
|
|
|
|
|
|
|
|
.17 sta (pData),y
|
|
|
|
|
|
2016-03-13 21:54:28 +00:00
|
|
|
|
bra .11
|
|
|
|
|
|
|
|
|
|
.9 >LDYA L.MSG.SKTERR
|
2016-11-03 16:23:46 +00:00
|
|
|
|
>SYSCALL CPrintFYA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
lda #SYSMGR.ERRSYN
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
|
2017-01-28 22:05:20 +00:00
|
|
|
|
CS.RUN.ABORT >LDYA L.MSG.ABORT
|
2016-11-03 16:23:46 +00:00
|
|
|
|
>SYSCALL CPrintFYA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
lda #0
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-02-15 16:14:41 +00:00
|
|
|
|
CS.RUN.CLIENT >PUSHA hSocket
|
|
|
|
|
>PUSHWI UsrBuf256
|
|
|
|
|
>PUSHWI 256
|
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GetS
|
|
|
|
|
bcc .1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.1 clc
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-01-28 22:05:20 +00:00
|
|
|
|
CS.DOEVENT sec
|
2016-03-13 21:54:28 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-02-15 16:14:41 +00:00
|
|
|
|
CS.QUIT ldx #CONN.MAX
|
|
|
|
|
ldy #hSockets
|
|
|
|
|
|
|
|
|
|
.1 lda (pData),y
|
|
|
|
|
beq .2
|
|
|
|
|
|
|
|
|
|
phx
|
|
|
|
|
phy
|
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
|
|
|
|
|
ply
|
|
|
|
|
plx
|
|
|
|
|
|
|
|
|
|
.2 iny
|
|
|
|
|
dex
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
ldy #hSrvSocket
|
2016-03-13 21:54:28 +00:00
|
|
|
|
lda (pData),y
|
|
|
|
|
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
|
|
|
|
|
|
|
|
|
|
lda hLIBTCPIP
|
2016-10-24 15:54:43 +00:00
|
|
|
|
>SYSCALL UnloadLibA
|
2016-03-13 21:54:28 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
Init.Timeout ldy #TimeOut
|
|
|
|
|
lda #TIMEOUT.MAX
|
|
|
|
|
sta (pData),y
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
Wait.TimeOut sec
|
|
|
|
|
ldy #TimeOut
|
|
|
|
|
lda (pData),y
|
|
|
|
|
beq .9
|
|
|
|
|
clc
|
|
|
|
|
.9 rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.END
|
|
|
|
|
*--------------------------------------
|
2016-10-24 15:54:43 +00:00
|
|
|
|
LIBTCPIP >PSTR "libtcpip.o"
|
|
|
|
|
MSG.TCPWAIT >CSTR "HTTPD:Waiting for TCP/IP initializing...\n"
|
|
|
|
|
MSG.INITOK >CSTR "HTTPD:Init Ok, Listening.\n"
|
|
|
|
|
MSG.TCPIPERR >CSTR "HTTPD:TCP/IP Not initialized properly\n"
|
|
|
|
|
MSG.SKTERR >CSTR "HTTPD:Listen Error\n"
|
|
|
|
|
MSG.ABORT >CSTR "HTTPD:User Aborted\n"
|
|
|
|
|
MSG.INCOMING >CSTR "HTTPD:Incoming Connection From : %d.%d.%d.%d\n"
|
2016-03-13 21:54:28 +00:00
|
|
|
|
hLIBTCPIP .BS 1
|
|
|
|
|
*--------------------------------------
|
2017-02-15 16:14:41 +00:00
|
|
|
|
Socket .DA #S.SOCKET.SOCK.STREAM
|
2016-03-13 21:54:28 +00:00
|
|
|
|
.DA #S.SOCKET.SO.ACCEPTCONN
|
2017-02-15 16:14:41 +00:00
|
|
|
|
.DA #S.SOCKET.TCP.STATUS.LISTEN
|
2016-03-13 21:54:28 +00:00
|
|
|
|
.BS 1
|
|
|
|
|
Socket.Src.Addr .BS 4
|
|
|
|
|
Socket.Src.Port .DA 80
|
|
|
|
|
Socket.Dst.Addr .BS 4
|
|
|
|
|
Socket.Dst.Port .BS 2
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.DUMMY
|
|
|
|
|
.OR 0
|
|
|
|
|
DS.START
|
2017-02-15 16:14:41 +00:00
|
|
|
|
hSockets .BS CONN.MAX pData
|
|
|
|
|
SktIndex .BS 1
|
|
|
|
|
hSrvSocket .BS 1
|
2016-03-13 21:54:28 +00:00
|
|
|
|
TimeOut .BS 1
|
|
|
|
|
DS.END
|
|
|
|
|
.ED
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MAN
|
|
|
|
|
SAVE SBIN/HTTPD.S
|
|
|
|
|
ASM
|