A2osX/SBIN/HTTPD.S.txt

301 lines
5.8 KiB
Plaintext
Raw Normal View History

NEW
2018-11-17 17:17:13 +00:00
PREFIX
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
2018-07-23 15:28:42 +00:00
.TF SBIN/HTTPD
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
2019-03-02 22:18:21 +00:00
.INB INC/ETH.I
2018-07-23 15:28:42 +00:00
.INB INC/LIBTCPIP.I
2019-03-02 22:18:21 +00:00
.INB INC/NET.HTTP.I
*--------------------------------------
TIMEOUT.MAX .EQ 30 30 sec.
CONN.MAX .EQ 16
*--------------------------------------
ZPIPCfgPtr .EQ ZPBIN
ZPSktPtr .EQ ZPBIN+2
ZPLinePtr .EQ ZPBIN+4
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2019-03-02 20:47:58 +00:00
.DA #S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
.DA #6 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
2019-03-02 22:18:21 +00:00
L.SA.Local .DA SA.Local
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
L.HTTP.200OK .DA HTTP.200OK
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
2018-07-19 15:33:55 +00:00
>SYSCALL LoadLib
sta hLIBTCPIP
clc
rts
*--------------------------------------
CS.RUN jsr Init.Timeout
>LDYA L.MSG.TCPWAIT
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2019-03-02 22:18:21 +00:00
.1 >LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
bcs .99
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.INIT
>SLEEP
jsr Wait.Timeout
bcc .1
>SYSCALL GetChar
bcs .1
cmp #$03
bne .1
>LDYA L.MSG.ABORT
2018-06-21 15:12:10 +00:00
>SYSCALL printf
lda #0
clc
rts
.99 >LDYA L.MSG.TCPIPERR
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
CS.RUN.RTS rts
CS.RUN.INIT ldx #3
ldy #S.IPCFG.IP+3
.1 lda (ZPIPCfgPtr),y
2019-03-02 22:18:21 +00:00
sta SA.LOCAL+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
2019-03-02 22:18:21 +00:00
>PUSHBI 0 no protocol
lda #S.SOCKET.T.STREAM
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs CS.RUN.ERR
2018-09-17 15:42:38 +00:00
>STA.G hSrvSocket
2019-03-02 22:18:21 +00:00
pha
>PUSHW L.SA.LOCAL
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
bcs CS.RUN.ERR
>LDA.G hSrvSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Listen
bcs CS.RUN.ERR
>LDYAI 256
2018-07-20 11:51:08 +00:00
>SYSCALL getmem
bcs CS.RUN.RTS
>STYA ZPLinePtr
txa
>STA.G hLineBuf
>LDYA L.MSG.INITOK
2018-06-21 15:12:10 +00:00
>SYSCALL printf
CS.RUN.LOOP >SLEEP
jsr CS.RUN.SERVER
bcs CS.RUN.ERR
ldy #SktIndex
lda (pData),y
tay
lda (pData),y hSockets
beq .3
jsr CS.RUN.CLIENT
.3 ldy #SktIndex
lda (pData),y
inc
cmp #CONN.MAX
bne .4
lda #0
.4 sta (pData),y
bra CS.RUN.LOOP
.9 >LDYA L.MSG.SKTERR
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
2019-03-02 22:18:21 +00:00
CS.RUN.ERR rts
*--------------------------------------
2019-03-02 22:18:21 +00:00
CS.RUN.SERVER >LDA.G hSrvSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.accept
bcs .8
pha
ldy #hSockets
ldx #CONN.MAX
.1 lda (pData),y
beq .2
iny
dex
bne .1
pla
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
bra .8
.2 pla
sta (pData),y
2019-03-02 22:18:21 +00:00
>STA.G hClntSocket
>SYSCALL GetMemPtr
>STYA ZPSktPtr
ldx #3
2019-03-02 22:18:21 +00:00
ldy #S.SOCKET.REM.ADDR+3
.3 >PUSHB (ZPSktPtr),y
dey
dex
bpl .3
2019-03-02 22:18:21 +00:00
>PUSHB.G hClntSocket
>PUSHBI 5
>LDYA L.MSG.INCOMING
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2019-03-02 22:18:21 +00:00
.8 clc
.9 rts
*--------------------------------------
2019-03-02 22:18:21 +00:00
CS.RUN.CLIENT >STA.G hClntSocket
pha
>PUSHWI 256
2019-03-02 22:18:21 +00:00
>PUSHW ZPLinePtr
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.read
bcs .1
>PUSHW ZPLinePtr
2018-06-21 15:12:10 +00:00
>SYSCALL printf
>PUSHB hClntSocket
>PUSHW L.HTTP.200OK
2019-03-02 22:18:21 +00:00
>LDA.G hClntSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.write
.1 clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT ldx #CONN.MAX
ldy #hSockets
.1 lda (pData),y
beq .2
phx
phy
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
ply
plx
.2 iny
dex
bne .1
ldy #hSrvSocket
lda (pData),y
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
>LDA.G hLineBuf
beq .3
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.3 lda hLIBTCPIP
2018-11-12 09:22:06 +00:00
beq .8
2018-07-20 14:10:10 +00:00
>SYSCALL UnloadLib
2018-11-12 09:22:06 +00:00
.8 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
*--------------------------------------
LIBTCPIP .AZ "libtcpip.o"
MSG.TCPWAIT .AZ "HTTPD:Waiting for TCP/IP initializing...\r\n"
MSG.INITOK .AZ "HTTPD:Init Ok, Listening.\r\n"
MSG.TCPIPERR .AZ "HTTPD:TCP/IP Not initialized properly\r\n"
MSG.SKTERR .AZ "HTTPD:Listen Error\r\n"
MSG.ABORT .AZ "HTTPD:User Aborted\r\n"
MSG.INCOMING .AZ "HTTPD:Incoming Connection [SKT=%h] From : %d.%d.%d.%d\r\n"
hLIBTCPIP .BS 1
*--------------------------------------
2019-03-02 22:18:21 +00:00
HTTP.200OK .AS "HTTP/1.1 200 OK\r\n"
HTTP.200OK.len .EQ *-HTTP.200OK
*--------------------------------------
2019-03-02 22:18:21 +00:00
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
.BS 1
2019-03-02 22:18:21 +00:00
.BS 4 S.SOCKADDR.ADDR
.DA TCP.PORT.HTTP
*--------------------------------------
.DUMMY
.OR 0
DS.START
hSockets .BS CONN.MAX pData
hLineBuf .BS 1
SktIndex .BS 1
hSrvSocket .BS 1
2019-03-02 22:18:21 +00:00
hClntSocket .BS 1
TimeOut .BS 1
DS.END
.ED
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SBIN/HTTPD.S
ASM