A2osX/SBIN/TELNETD.S.txt
2018-09-28 17:24:44 +02:00

263 lines
5.1 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.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF SBIN/TELNETD
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/ETH.I
.INB INC/LIBTCPIP.I
*--------------------------------------
CONN.MAX .EQ 16
TIMEOUT.MAX .EQ 30 30 sec.
*--------------------------------------
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 #S.PS.F.EVENT S.PS.F
.DA #0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
.DA #4 ZP SS
.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
>SYSCALL LoadLib
sta hLIBTCPIP
clc
rts
*--------------------------------------
CS.RUN jsr Init.Timeout
>LDYA L.MSG.TCPWAIT
>SYSCALL puts
.1 >LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG 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
jmp CS.RUN.ABORT
.99 pha
>LDYA L.MSG.TCPIPERR
>SYSCALL puts
pla
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
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New
bcs .9
>STA.G hSrvSocket
>LDYA L.MSG.INITOK
>SYSCALL puts
.2 >SLEEP
jsr CS.RUN.SERVER
bcs CS.RUN.ERR
* >SYSCALL GetChar
* bcs .2
* cmp #$03
* beq CS.RUN.ABORT
bra .2
.9 pha
>LDYA L.MSG.SKTERR
>SYSCALL puts
pla
sec
rts
CS.RUN.ABORT >LDYA L.MSG.ABORT
>SYSCALL puts
lda #3
CS.RUN.ERR sec
rts
*--------------------------------------
CS.RUN.SERVER >LDA.G hSrvSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Accept
bcs .8
>STA.G hClientSocket
ldy #hSockets
ldx #CONN.MAX
.1 lda (pData),y
beq .2
iny
dex
bne .1
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Close
bra .8
.2 sta (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Get
>STYA ZPSktPtr
ldx #3
ldy #S.SOCKET.DST.ADDR+3
.3 >PUSHB (ZPSktPtr),y
dey
dex
bpl .3
>PUSHB.G hClientSocket
>PUSHBI 5
>LDYA L.MSG.INCOMING
>SYSCALL printf
bcs .9
.8 clc
.9 rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
>LDA.G TimeOut
beq .9
dec
sta (pData),y
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.QUIT ldx #CONN.MAX
ldy #hSockets
.1 lda (pData),y
beq .2
phx
phy
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Close
ply
plx
.2 iny
dex
bne .1
ldy #hSrvSocket
lda (pData),y
beq .3
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Close
.3 lda hLIBTCPIP
>SYSCALL UnloadLib
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
*--------------------------------------
hLIBTCPIP .BS 1
LIBTCPIP .AZ "libtcpip.o"
MSG.TCPWAIT .AZ "TELNETD:Waiting for TCP/IP initializing..."
MSG.INITOK .AZ "TELNETD:Init Ok, Listening."
MSG.TCPIPERR .AZ "TELNETD:TCP/IP Not initialized properly"
MSG.SKTERR .AZ "TELNETD:Listen Error."
MSG.ABORT .AZ "TELNETD:User Aborted."
MSG.INCOMING .AZ "TELNETD:Incoming Connection [SKT=%h] From : %d.%d.%d.%d\r\n"
CMD.LINE .AS "${A2OSX}SBIN/GETTY "
.AZ " ${A2OSX}SBIN/LOGIN"
*--------------------------------------
Socket .DA #S.SOCKET.T.STREAM
.DA #S.SOCKET.O.ACCEPTCONN
.DA #S.SOCKET.TCP.S.LISTEN
.BS 1
Socket.Src.Addr .BS 4
Socket.Src.Port .DA TCP.PORT.TELNET
Socket.Dst.Addr .BS 4
Socket.Dst.Port .BS 2
*--------------------------------------
NOD.Name .AZ "TTY%h"
*--------------------------------------
.DUMMY
.OR 0
DS.START
hSockets .BS CONN.MAX pData
SktIndex .BS 1
hSrvSocket .BS 1
hClientSocket .BS 1
TimeOut .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/TELNETD.S
ASM