changeset 2475:c249cc490a83

Moved dw commands into main tree
author boisy
date Tue, 30 Mar 2010 02:46:29 +0000
parents 7d70b7e1cb21
children a4749998e787
files level1/cmds/dw.a level1/cmds/inetd.a level1/cmds/telnet.a level1/coco/bootfiles/makefile level1/coco/cmds/makefile level1/coco/makefile level1/coco/sys/inetd.conf level1/coco/sys/makefile
diffstat 8 files changed, 1202 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/level1/cmds/dw.a	Tue Mar 30 02:46:29 2010 +0000
@@ -0,0 +1,149 @@
+********************************************************************
+* dw - command interface to the server
+*
+* $Id$
+*
+* Edt/Rev  YYYY/MM/DD  Modified by
+* Comment
+* ------------------------------------------------------------------
+*   1      2010/01/02  Aaron Wolfe
+* Most basic implementation using new DW utility API
+
+               nam       dw
+               ttl       command interface to the server
+
+tylg           set       $01       Prgrm+Objct
+atrv           set       $80+rev   ReEnt+rev
+rev            set       $00
+edition        set       1
+
+               psect     dw_a,$01,$80,1,200,start
+
+               vsect
+pbuffer        rmb       256
+pbend          rmb       2
+cbuffer        rmb       256
+portdev        rmb       10
+portpath       rmb       1
+outpath        rmb       1
+numbyt         rmb       1
+die            rmb       1
+               endsect
+
+* signal handling
+icpt           lda       #1
+               sta       die,u
+               rti       
+
+command        fcc       'dw '
+
+* save initial parameters
+start:         pshs      d
+               pshs      x
+               clr       die,u
+* set intercept handler
+               leax      icpt,pcr            *ptr to handler
+               os9       F$Icpt
+
+               clra
+               lbsr      TCPOpen
+               lbcs      errex1
+
+
+gotport        sta       portpath,u
+
+* rawpath
+			   lbsr		RawPath
+
+* write command to port
+               lda       portpath,u
+               ldy       #3
+               leax      command,pc
+               os9       I$Write
+               lbcs      errex2
+
+* write parameters to port - X = start addr, y = # bytes, A = path#
+               puls      x
+               puls      y
+
+               os9       I$WritLn
+               lbcs      errex2
+
+* read result
+               leax      pbuffer,u
+               lda       portpath,u
+               ldy       #1
+rrloop         os9       I$Read
+               lbcs      errex2
+               ldb       ,x+
+               cmpb      #C$CR               * end of response
+               bne       rrloop
+
+* look for Fail
+               ldb       pbuffer,u
+               cmpb      #'F
+               bne       gotconn             * we connected
+
+* display failure message
+               lda       #1
+               ldy       #1
+               leax      pbuffer,u
+               ldb       #9                  *skip proto error info (FAIL xxx )
+               abx       
+prloop         os9       I$Write
+               ldb       ,x+
+               cmpb      #C$CR               *end of response
+               bne       prloop
+
+               ldy       #2
+               leax      crlf,pc
+               os9       I$Write
+
+               lbra      done
+
+crlf           fcb       C$CR
+               fcb       C$LF
+
+* response loop
+* read 1 byte, this is how many bytes follow in this set.  0 for end of response
+gotconn        nop       
+
+* check for incoming serial data
+rloop          lda       portpath,u
+               ldb       #SS.Ready
+               os9       I$GetStt
+               bcc       serinc              read and print the byte
+
+* if we got no data and die is set, bail
+               lda       die,u
+               bne       done
+
+* sleep a while
+               ldx       #0001
+               os9       F$Sleep
+               bra       rloop
+
+* read B bytes from serial, print on screen
+serinc         clra      
+               tfr       d,y
+               lda       portpath,u
+               leax      pbuffer,u
+               os9       I$Read
+               lbcs      errex2
+* print the data to stdout
+               lda       #1
+               leax      pbuffer,u
+               os9       I$Write
+               bra       rloop
+
+done           clrb                          *no errors here			
+* close port
+errex2         lda       portpath,u
+               os9       I$Close
+
+errex1         os9       F$Exit              *goodbye
+               endsect
+
+               
+               
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/level1/cmds/inetd.a	Tue Mar 30 02:46:29 2010 +0000
@@ -0,0 +1,482 @@
+********************************************************************
+* inetd - internet daemon
+*
+* $Id$
+*
+* Edt/Rev  YYYY/MM/DD  Modified by
+* Comment
+* ------------------------------------------------------------------
+*   1      2010/01/08  Boisy G. Pitre
+* Started.
+*
+*   2      2010/01/22  Boisy G. Pitre
+* Now reads inetd.conf file.
+
+               nam       inetd
+               ttl       internet daemon
+
+tylg           set       $01       Prgrm+Objct
+atrv           set       $80+rev   ReEnt+rev
+rev            set       $00
+edition        set       2
+
+               psect     inetd_a,$01,$80,1,200,start
+
+DEBUG          equ       1
+
+               vsect
+targetport     rmb       2
+netdatardy     rmb       1
+nbufferl       equ       128
+nbuffer        rmb       nbufferl
+lbufferl       equ       128
+lbuffer        rmb       lbufferl
+nnext          rmb       2
+token          rmb       2
+orgstdin       rmb       1
+orgstdout      rmb       1
+orgstderr      rmb       1
+childnetpath   rmb       1
+netpath        rmb       1
+targetprog     rmb       128
+targetparams   rmb       128
+               endsect
+
+NetSig         equ       2
+
+* signal intercept routine
+sigint         cmpb      #NetSig
+               bne       sigex
+               inc       netdatardy,u
+sigex          rti       
+
+**** Entry Point ****
+start:
+* setup signal intercept
+               leax      sigint,pcr
+               os9       F$Icpt
+
+               clr       netdatardy,u
+
+               leax      nbuffer,u
+               stx       nnext,u
+
+* open the path to the control channel
+               lbsr      TCPOpen
+               lbcs      errex
+               sta       netpath,u
+
+               leax      SetupPorts,pcr
+               lbsr      ProcInetd
+               lbcs      errex
+               
+               IFNE      DEBUG
+               lbsr      PRINTS
+               fcc       /Got netpath and setup ports/
+               fcb       C$CR
+               fcb       $00
+               ENDC
+
+ssignetpath
+               IFNE      DEBUG
+               lbsr      PRINTS
+               fcc       /SS.SSig on NetPath/
+               fcb       C$CR
+               fcb       $00
+               ENDC
+
+               lda       netpath,u
+               ldb       #SS.SSig            send signal on data ready
+               ldx       #NetSig
+               os9       I$SetStt
+               lbcs      errex
+
+**** MAIN LOOP ****
+mainloop
+               pshs      cc
+               orcc      #IntMasks
+               tst       netdatardy,u
+               bne       gotdata
+               
+* wait for a child to die (or wake up via signal)
+               os9       F$Wait
+               bcc       chkrdy
+               cmpb      #E$NoChld
+               bne       chkrdy			got error other than "no children"
+* if no children, go to sleep
+               ldx       #$0000
+               os9       F$Sleep
+
+chkrdy         puls      cc
+               bra       ssignetpath
+               
+gotdata        puls      cc
+               dec       netdatardy,u
+* read the data from netpath
+               IFNE      DEBUG
+               lbsr      PRINTS
+               fcc       /Reading data from netpath/
+               fcb       C$CR
+               fcb       $00
+               ENDC
+
+               lda       netpath,u
+               ldb       #SS.Ready
+               os9       I$GetStt
+               bcs       ssignetpath
+               
+               clra
+               tfr       d,y
+               lda       netpath,u
+               ldx       nnext,u
+               os9       I$Read
+               lbcs      errex
+               tfr       y,d
+               leax      d,x
+               stx       nnext,u
+               lda       -1,x
+               cmpa      #C$CR
+               lbne      ssignetpath
+               
+               leax      nbuffer,u
+               stx       nnext,u
+
+               lda       #1
+               ldy       #256
+               os9       I$WritLn 
+
+* determine response
+               lda       ,x
+               cmpa      #'9
+               ble       incoming
+               
+               cmpa      #'F
+               lbra      ssignetpath
+ 
+* get token number
+incoming
+               lbsr      DEC_BIN
+               std       token,u
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Got token /
+               fcb       $00
+               puls      d
+               lbsr      PRINT_DEC
+               lbsr      PRINTS
+               fcb       C$CR
+               fcb       $00
+               ENDC
+
+* skip over token number
+               IFNE      DEBUG
+               lbsr      PRINTS
+               fcc       /To Space.../
+               fcb       C$CR
+               fcb       $00
+               ENDC
+               lbsr      TO_SP
+               IFNE      DEBUG
+               lbsr      PRINTS
+               fcc       /To Non-Space.../
+               fcb       C$CR
+               fcb       $00
+               ENDC
+               lbsr      TO_NON_SP
+
+* get port number
+               lbsr      DEC_BIN
+               std       targetport,u
+               
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Got request for port /
+               fcb       $00
+               ldd       ,s
+               lbsr      PRINT_DEC
+               lbsr      PRINTS
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+
+               leax      ForkProcForPort,pcr
+               lbsr      ProcInetd
+               lbra      ssignetpath            we may want to tell server we have no app
+
+errex          os9       F$Exit
+
+
+* Process inetd.conf file
+*
+* Entry: X = processor routine
+*
+* - open conf file
+* - read each line and get first parameter (port number)
+* - send it to the processor routine at x
+* - if error or end of file, close and return
+ProcInetd      pshs      x
+               leax      inetdconf,pcr
+               lda       #READ.
+               os9       I$Open
+               bcs       adex
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Opened inetd.conf ok/
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+nextline       leax      lbuffer,u
+               ldy       #lbufferl-1
+               lbsr      FGETS
+               bcs       closeup
+               lbsr      TO_NON_SP        skip any leading spaces
+               ldb       ,x               check for EOL or comment
+               cmpb      #C$CR
+               beq       nextline
+               cmpb      #'#
+               beq       nextline
+               IFNE      DEBUG
+               pshs      d,x
+               lbsr      PRINTS
+               fcc       /Reading line: /
+               fcb       $00
+               ldx       2,s
+               lbsr      PUTS
+               puls      d,x
+               ENDC
+               pshs      a
+               jsr       [1,s]
+               puls      a
+               bcc       nextline
+closeup        cmpb      #E$EOF
+               bne       closeandex
+               clrb
+closeandex     pshs      b,cc
+               os9       I$Close
+               puls      b,cc
+adex           puls      x,pc
+
+               
+* Setup ports
+* Extract first parameter at X and send to server
+SetupPorts     lbsr      DEC_BIN
+               cmpd      #0
+               beq       ret0
+* find comma and change it to nul
+               tfr       x,y
+setuploop      lda       ,y+
+               cmpa      #C$CR
+               beq       ret0
+               cmpa      #',
+               bne       setuploop
+setuplisten 
+               clr       -1,y
+               IFNE      DEBUG
+               pshs      d,x
+               lbsr      PRINTS
+               fcc       /Send listen/
+               fcb       C$CR
+               fcb       $00
+               puls      d,x
+               ENDC
+               lda       netpath,u
+               lbsr      TCPListen
+ret0           rts
+
+* Fork Proccess that matches target port
+* Extract first parameter at X and see if it matches target port
+* if so, read rest of line and fork the process
+* Line looks like this:  portnumberplusoptions,prog,params
+ForkProcForPort
+* get port number
+               lbsr      DEC_BIN
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Reading port /
+               fcb       $00
+               ldd       ,s
+               lbsr      PRINT_DEC
+               lbsr      PRINTS
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+               cmpd      targetport,u
+               lbne      ret
+* point Y to byte after comma
+portloop       lda       ,y+
+               cmpa      #C$CR
+               beq       ret0
+               cmpa      #',
+               bne       portloop
+               tfr       y,x
+* copy bytes up to comma at X
+               leay      targetprog,u
+prgloop        lda       ,x+
+               cmpa      #',
+               beq       sethi
+               cmpa      #C$CR
+               lbeq      ret
+               sta       ,y+
+               bra       prgloop
+sethi          lda       -1,y
+               ora       #$80
+               sta       -1,y
+copypar        leay      targetparams,u
+parloop        lda       ,x+
+               sta       ,y+
+               cmpa      #C$CR
+               bne       parloop
+
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Got proc and params to fork/
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+
+* ignore client port number and hostname for now
+               lbsr      TCPOpen
+               bcc       savechild
+
+               ldd       token,u
+               leas      -8,s
+               leax      ,s
+               lbsr      BIN_DEC
+               lda       netpath,u
+               tfr       x,y
+               lbsr      TCPKill
+               leas      8,s
+               lbra      forkex
+
+savechild
+               sta       childnetpath,u
+               ldd       token,u
+               leas      -8,s
+               leax      ,s
+               lbsr      BIN_DEC
+               lda       childnetpath,u               
+               tfr       x,y
+               lbsr      TCPJoin
+               leas      8,s
+               bcc       turnonechoalf
+               os9       I$Close
+               lbra      forkex
+ 
+turnonechoalf
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Turning on PD.EKO and PD.ALF/
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+               lbsr      SetEcho
+               lbcs      ret
+               lbsr      SetAutoLF
+               lbcs      ret
+
+* dup paths
+duper
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Duping paths/
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+
+               clra
+               os9       I$Dup
+               lbcs      errex
+               sta       orgstdin,u
+               lda       #1
+               os9       I$Dup
+               lbcs      errex
+               sta       orgstdout,u
+               lda       #2
+               os9       I$Dup
+               lbcs      errex
+               sta       orgstderr,u
+
+* close original stdin/out/err paths
+               clra 
+               os9       I$Close                     
+               inca 
+               os9       I$Close                     
+               inca 
+               os9       I$Close                     
+
+* Dup child net path to stdin/stdout/stderr
+               lda       childnetpath,u
+               os9       I$Dup
+               lbcs      errex
+               os9       I$Dup
+               lbcs      errex
+               os9       I$Dup
+               lbcs      errex
+
+* fork child process
+               pshs      u 
+               leax      targetprog,u
+               leau      targetparams,u
+               lda       #Objct
+               clrb
+               ldy       #256
+               os9       F$Fork
+               puls      u
+* If our F$Fork fails, do not error out...
+*              bcs       ret2
+
+* restore orginal paths
+               clra
+               os9       I$Close
+               inca
+               os9       I$Close
+               inca
+               os9       I$Close
+
+               lda       orgstdin,u
+               os9       I$Dup
+               lbcs      errex
+               lda       orgstdout,u
+               os9       I$Dup
+               lbcs      errex
+               lda       orgstderr,u
+               os9       I$Dup
+               lbcs      errex
+               lda       orgstdin,u
+               os9       I$Close
+               lda       orgstdout,u
+               os9       I$Close
+               lda       orgstderr,u
+               os9       I$Close
+               lda       childnetpath,u
+               os9       I$Close
+
+               IFNE      DEBUG
+               pshs      d
+               lbsr      PRINTS
+               fcc       /Proc forked/
+               fcb       C$CR
+               fcb       $00
+               puls      d
+               ENDC
+
+forkex         comb
+               ldb       #E$EOF
+ret            rts
+
+inetdconf      fcc       "....../SYS/inetd.conf"
+               fcb       C$CR
+               endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/level1/cmds/telnet.a	Tue Mar 30 02:46:29 2010 +0000
@@ -0,0 +1,515 @@
+********************************************************************
+* telnet - telnet client
+*
+* $Id$
+*
+* Notes:
+* This utility works in similar fashion to telnet commands on other systems.
+* The user can telnet to a location, and once there, press the TELESCAPE key
+* to invoke telnet command mode. 
+*
+* Two sets of path options are kept for the standard input.  The first is an
+* unmodified copy and the second is a modifable copy.  The second is set up
+* for raw mode and is used when communicating with the host.  The first will
+* be used when going into telnet command mode or exiting the telnet program.
+*
+* The signal handler catches the S$HUP signal and shuts down gracefully.  It
+* also looks for the ABORT/QUIT characters and relays them to the session.
+*
+* Reference used: http://www.faqs.org/rfcs/rfc854.html
+*
+* Edt/Rev  YYYY/MM/DD  Modified by
+* Comment
+* ------------------------------------------------------------------
+*   1      2010/01/02  Aaron Wolfe
+* Most basic implementation using new DW utility API
+*
+*   2      2010/01/06  Boisy G. Pitre
+* Reformatted and optimized source. Added SS.Opt support, added telnet
+* command mode which can be entered by pressing the TELESCAPE key.
+*
+*   3      2010/01/07  Boisy G. Pitre
+* Reworked buffer processing routine.
+*
+*   4      2010/01/12  Boisy G. Pitre
+* We allow host to do echo if it wants, we also now advertise the
+* escape character when a connection is successful.
+*
+*   5      2010/01/15  Boisy G. Pitre
+* Modified to be an rma assembled module and use the netlib library.
+
+* Set to 1 if you want to see telnet CTRL chars from host
+DEBUG          set       0
+
+               nam       telnet
+               ttl       program module
+
+tylg           set       $01     Prgrm+Objct
+atrv           set       $80+rev ReEnt+rev
+rev            set       $00
+edition        set       5
+
+               psect     telnet_a,tylg,atrv,edition,200,start
+
+               vsect
+connected      rmb       1
+netdatardy     rmb       1
+keydatardy     rmb       1
+lastsig        rmb       1
+port           rmb       2
+hostname       rmb       2
+pbuffer        rmb       256
+pbufferl       equ       *
+pbend          rmb       2
+cbuffer        rmb       256
+ccount         rmb       1
+opts           rmb       32
+orgopts        rmb       32
+tcmdbufl       equ       32
+tcmdbuf        rmb       tcmdbufl
+portdev        rmb       10
+netpath        rmb       1
+outpath        rmb       1
+numbyt         rmb       1
+state          rmb       1
+telctrlbuf     rmb       3
+               endsect
+
+TELESCAPE      equ       'Y-$40              * CTRL-Y
+
+NetSig         equ       32
+KeySig         equ       33
+
+SE             equ       240                 * end of subnegotiation parameters
+NOP            equ       241                 * no operation
+DataMark       equ       242                 * the data stream portion of a Synch. This should always be accompanied by a TCP Urgent notification.
+Break          equ       243                 * NVT character BRK.
+IntProc        equ       244                 * the function IP
+AbortOut       equ       245                 * the function AO.
+AreUThere      equ       246                 * the function AYT
+EraseChar      equ       247                 * the function EC.
+EraseLine      equ       248                 * the function EL.
+GoAhead        equ       249                 * the GA signal.
+SB             equ       250                 * indicates that what follows is subnegotiation of the indicated option.
+WILL           equ       251                 * indicates the desire to begin performing, or confirmation that you are now performing, the indicated option.
+WONT           equ       252                 * indicates the refusal to perform, or continue performing, the indicated option.
+DO             equ       253                 * indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option.
+DONT           equ       254                 * indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option.
+IAC            equ       255                 * data byte 255.
+
+* Telnet Options
+TO_ECHO        equ       $01
+
+escprompt      fcc       /Escape character is '^/
+               fcb       TELESCAPE+$40
+               fcc       /'./
+crlf           fcb       C$CR,C$LF
+escpromptl     equ       *-escprompt
+tprompt        fcc       /telnet> /
+tpromptl       equ       *-tprompt
+
+trying         fcc       /Trying.../
+               fcb       C$CR
+tryingl        equ       *-trying
+
+peerclosm      fcc       /Connection closed by foreign host./
+               fcb       C$CR
+peerclosml     equ       *-peerclosm
+
+using          fcc       'Using port '
+usingl         equ       *-using
+
+defportstr     fcc       '23'
+               fcb       0
+               
+peerclosed
+               clr       connected,u
+               leax      peerclosm,pcr
+               ldy       #peerclosml
+               os9       I$WritLn
+               lbra      done
+
+* signal intercept routine
+sigint                   
+               stb       lastsig,u           * save our signal received
+               cmpb      #KeySig
+               bne       netchk
+               inc       keydatardy,u
+               rti
+netchk         cmpb      #NetSig
+               bne       hupchk
+               inc       netdatardy,u
+               rti
+hupchk         cmpb      #S$HUP              * disconnect from peer signal received?
+               beq       peerclosed          * yep, exit nicely
+               lda       #$03                * usual interrupt character
+               cmpb      #S$Intrpt
+               beq       chksig
+               lda       #$05                * usual quit character
+               cmpb      #S$Abort
+               bne       sigex
+chksig         tst       connected,u
+               lbeq      done
+               pshs      a
+               leax      ,s
+               ldy       #$0001
+               lda       netpath,u
+               os9       I$Write
+               puls      a
+sigex          rti       
+
+* save initial parameters
+start          pshs      x
+               clr       connected,u
+               clr       netdatardy,u
+               clr       keydatardy,u
+
+* setup signal intercept
+               leax      sigint,pcr
+               os9       F$Icpt
+
+* get path options (original and modifiable copy)
+               leax      orgopts,u
+               ldd       #SS.Opt
+               os9       I$GetStt
+               lbcs      errex2
+
+               leax      opts,u
+               ldd       #SS.Opt
+               os9       I$GetStt
+               lbcs      errex2
+
+* set up our path to be raw (we will actually set it later)
+               leax      PD.UPC-PD.OPT,x
+               ldb       #PD.INT-PD.UPC
+rawloop        clr       ,x+
+               decb      
+               bne       rawloop 
+
+* set address as nul terminated string
+addrloop
+               ldx       ,s
+addrloop2
+               lda       ,x+
+               cmpa      #C$SPAC
+               beq       nilit
+               cmpa      #C$CR
+               beq       nilit
+               bra       addrloop2
+
+nilit          clr       -1,x     nil terminate previous param
+               cmpa      #C$CR    are we at end of command line?
+               beq       defaultport yep, set default port
+
+skipspc        lda       ,x+
+               cmpa      #C$CR
+               beq       defaultport
+               cmpa      #C$SPAC
+               beq       skipspc
+* if here, we have a second parameter... probably port number
+               leay       -1,x
+               bra        parsedone
+defaultport    leay       defportstr,pcr
+parsedone      puls       x
+
+* X holds pointer to nul terminated address
+* Y holds port number string (nil terminated)
+* do the open and connect
+               pshs       y
+               std        port,u
+               stx        hostname,u
+
+* announce our attempt to try to connect
+               lda        #1
+               ldy        #tryingl
+               leax       trying,pcr
+               os9        I$WritLn
+               
+               lbsr       TCPOpen
+               puls       y
+               lbcs       errex1
+               sta        netpath,u
+               ldx        hostname,u
+               lbsr       TCPConnectToHost
+               lbcs       errex2
+               lbsr       RawPath
+               
+* we're connected...
+               lda       #1
+               sta       connected,u
+               leax      escprompt,pcr
+               ldy       #escpromptl
+               os9       I$WritLn
+
+* make our stdin opts raw
+               leax      opts,u
+               ldd       #SS.Opt
+               os9       I$SetStt
+               lbcs      errex2
+
+* setup data ready signal on stdin
+               clra
+               ldb       #SS.SSig
+               ldx       #KeySig
+               os9       I$SetStt
+               lbcs      errex2
+
+* setup data ready signal on netpath
+               lda       netpath,u
+               ldb       #SS.SSig
+               ldx       #NetSig
+               os9       I$SetStt
+               lbcs      errex2
+
+* response loop
+* check for typed characters
+rloop
+               pshs      cc				save interrupt state
+               orcc      #IntMasks      mask interrupts
+               tst       netdatardy,u
+               bne       GetNetData
+               tst       keydatardy,u
+               bne       GetKeyData
+* sleep until signal
+               ldx       #$0000
+               os9       F$Sleep
+               puls      cc              
+               bra       rloop
+
+GetKeyData     puls      cc
+               dec       keydatardy,u
+               bra       stdinc
+
+GetNetData     puls      cc
+               dec       netdatardy,u
+               lda       netpath,u
+               ldb       #SS.Ready
+               os9       I$GetStt
+               lbcc      serinc              read and print the byte
+               bra       rloop
+
+* telnet command interface
+cmdint                   
+* restore original opts for now
+               leax      orgopts,u
+               ldd       #SS.Opt
+               os9       I$SetStt
+               bcs       errex2
+
+* write CR		  
+               lda       #1
+               leax      crlf,pcr
+               ldy       #$02
+               os9       I$Write
+
+* show prompt
+cmdloop                  
+               lda       #1
+               leax      tprompt,pcr
+               ldy       #tpromptl
+               os9       I$Write
+
+* read command
+               leax      tcmdbuf,u
+               ldy       #tcmdbufl
+               clra      
+               os9       I$ReadLn
+               bcs       errex2
+
+* process command
+               lda       ,x
+               anda      #$5F                * make uppercase
+
+               cmpa      #C$CR
+               beq       ret2tel             * just CR... return to telnet session
+               cmpa      #'Q
+               beq       okex
+               bra       cmdloop
+
+* return to telnet session
+ret2tel                  
+               leax      opts,u
+               ldd       #SS.Opt
+               os9       I$SetStt
+               bcs       errex2
+
+* read one byte from stdin, send to server
+stdinc         ldy       #$0001
+               clra      
+               leax      numbyt,u
+               os9       I$Read
+               bcs       errex2
+
+* check if it is an escape character
+               lda       ,x
+               cmpa      #TELESCAPE
+               beq       cmdint
+
+outc           ldy       #$0001
+               lda       netpath,u
+               leax      numbyt,u
+               os9       I$Write
+               bcs       errex2
+
+* setup data ready signal on stdin
+               clra
+               ldb       #SS.SSig
+               ldx       #KeySig
+               os9       I$SetStt
+               lbcs      errex2
+
+               lbra      rloop
+
+done
+okex           clrb                          *no errors here
+* close port
+errex2
+               pshs      b,cc
+               lda       netpath,u
+               lbsr      TCPDisconnect
+               clr       connected,u
+               
+               leax      orgopts,u
+               ldd       #SS.Opt
+               os9       I$SetStt            *restore original path options
+               puls      b,cc
+               
+errex1         os9       F$Exit              *goodbye
+
+* read B bytes from serial
+serinc         clra      
+               tfr       d,y
+               lda       netpath,u
+               leax      pbuffer,u
+               os9       I$Read
+               bcs       errex2
+
+* set buffer
+               tfr       y,d
+               leax      pbuffer,u
+               abx       
+               stx       pbend,u             *set end addr
+               clrb      
+               leax      pbuffer,u
+               leay      cbuffer,u
+               clr       ccount,u
+
+* call buffer processor
+               bsr       procbuf
+
+* print buffer
+               ldb       ccount,u
+               beq       serincex
+               clra      
+               tfr       d,y
+               lda       #1
+               leax      cbuffer,u
+               os9       I$Write
+               bcs       errex2
+
+* return to loop
+serincex
+* setup data ready signal on netpath
+               lda       netpath,u
+               ldb       #SS.SSig
+               ldx       #NetSig
+               os9       I$SetStt
+               lbcs      errex2
+
+               lbra      rloop
+
+
+
+* buffer processing routine
+procbuf        cmpx      pbend,u
+               beq       procbufex
+* not at end of buffer, get next char
+               lda       ,x+
+* check state to see what we do with this byte
+               tst       state,u
+               bne       telctrl
+               cmpa      #IAC
+               beq       telstate
+               sta       ,y+
+               inc       ccount,u
+               bra       procbuf
+procbufex      rts       
+
+conv           anda      #$0F
+               cmpa      #$09
+               bgt       alpha
+               adda      #$30
+               fcb       $8C
+alpha          adda      #$41-$0A
+               rts
+
+               IFEQ      DEBUG-1
+printhex       pshs      d,x,y
+               bsr       conv
+               pshs      a
+               lda       1,s
+               lsra
+               lsra
+               lsra
+               lsra
+               bsr       conv
+               pshs      a
+               lda       #'$
+               pshs      a
+               leax      ,s
+               ldy       #$0003
+               lda       #$01
+               os9       I$Write
+               leas      3,s
+               puls      d,x,y,pc
+               ENDC
+       
+telstate       sta       telctrlbuf,u
+               IFEQ      DEBUG-1
+               bsr       printhex
+               ENDC
+               inc       state,u
+               bra       procbuf
+
+clrngo         clr       state,u
+               bra       procbuf
+ 
+* handles telnet control sequence... A = byte
+telctrl
+               IFEQ      DEBUG-1
+               bsr       printhex
+               ENDC
+               ldb       state,u
+               cmpb      #1
+               bne       telctrl2
+               cmpa      #SB
+               ble       clrngo
+               sta       telctrlbuf+1,u
+               inc       state,u
+               bra       procbuf
+telctrl2       sta       telctrlbuf+2,u
+               clr       state,u
+* here we have a complete telnet control sequence
+               ldd       telctrlbuf+1,u
+               cmpa      #DO
+               beq       dowont
+               cmpa      #WILL
+               lbne      procbuf
+               cmpb      #TO_ECHO
+               bne       dodont
+* allow host to echo
+               lda       #DO
+               fcb       $8C
+dodont         lda       #DONT
+               fcb       $8C
+dowont         lda       #WONT
+               sta       telctrlbuf+1,u
+               ldy       #3
+               lda       netpath,u
+               pshs      x
+               leax      telctrlbuf,u
+               os9       I$Write
+               puls      x
+               lbra      procbuf
+
+               endsect
--- a/level1/coco/bootfiles/makefile	Tue Mar 30 02:44:42 2010 +0000
+++ b/level1/coco/bootfiles/makefile	Tue Mar 30 02:46:29 2010 +0000
@@ -61,6 +61,13 @@
 		$(MD)/rbdw3.dr $(MD)/dw3_coco1.sb \
 		$(MD)/ddx0.dd $(MD)/x1.dd $(MD)/x2.dd $(MD)/x3.dd \
 		$(MD)/scf.mn \
+		$(MD)/scdwn.dr \
+		$(MD)/term_scdwn.dt \
+		$(MD)/n_scdwn.dd $(MD)/n1_scdwn.dd $(MD)/n2_scdwn.dd \
+		$(MD)/n3_scdwn.dd $(MD)/n4_scdwn.dd $(MD)/n5_scdwn.dd \
+		$(MD)/n6_scdwn.dd $(MD)/n7_scdwn.dd $(MD)/n8_scdwn.dd \
+		$(MD)/n9_scdwn.dd $(MD)/n10_scdwn.dd $(MD)/n11_scdwn.dd \
+		$(MD)/n12_scdwn.dd $(MD)/n13_scdwn.dd $(MD)/n14_scdwn.dd \
 		$(MD)/scdwp.dr $(MD)/p_scdwp.dd \
 		$(MD)/pipeman.mn $(MD)/piper.dr $(MD)/pipe.dd \
 		$(MD)/clock_60hz $(MD)/clock2_dw3 \
@@ -73,6 +80,12 @@
 		$(MD)/ddx0.dd $(MD)/x1.dd $(MD)/x2.dd $(MD)/x3.dd \
 		$(MD)/scf.mn \
 		$(MD)/vtio.dr $(MD)/covdg.io $(MD)/term32.dt \
+		$(MD)/scdwn.dr \
+		$(MD)/n_scdwn.dd $(MD)/n1_scdwn.dd $(MD)/n2_scdwn.dd \
+		$(MD)/n3_scdwn.dd $(MD)/n4_scdwn.dd $(MD)/n5_scdwn.dd \
+		$(MD)/n6_scdwn.dd $(MD)/n7_scdwn.dd $(MD)/n8_scdwn.dd \
+		$(MD)/n9_scdwn.dd $(MD)/n10_scdwn.dd $(MD)/n11_scdwn.dd \
+		$(MD)/n12_scdwn.dd $(MD)/n13_scdwn.dd $(MD)/n14_scdwn.dd \
 		$(MD)/scdwp.dr $(MD)/p_scdwp.dd \
 		$(MD)/pipeman.mn $(MD)/piper.dr $(MD)/pipe.dd \
 		$(MD)/clock_60hz $(MD)/clock2_dw3 \
@@ -83,6 +96,13 @@
 		$(MD)/rbdw3.dr $(MD)/dw3.sb \
 		$(MD)/ddx0.dd $(MD)/x1.dd $(MD)/x2.dd $(MD)/x3.dd \
 		$(MD)/scf.mn \
+		$(MD)/scdwn.dr \
+		$(MD)/term_scdwn.dt \
+		$(MD)/n_scdwn.dd $(MD)/n1_scdwn.dd $(MD)/n2_scdwn.dd \
+		$(MD)/n3_scdwn.dd $(MD)/n4_scdwn.dd $(MD)/n5_scdwn.dd \
+		$(MD)/n6_scdwn.dd $(MD)/n7_scdwn.dd $(MD)/n8_scdwn.dd \
+		$(MD)/n9_scdwn.dd $(MD)/n10_scdwn.dd $(MD)/n11_scdwn.dd \
+		$(MD)/n12_scdwn.dd $(MD)/n13_scdwn.dd $(MD)/n14_scdwn.dd \
 		$(MD)/scdwp.dr $(MD)/p_scdwp.dd \
 		$(MD)/pipeman.mn $(MD)/piper.dr $(MD)/pipe.dd \
 		$(MD)/clock_60hz $(MD)/clock2_dw3 \
@@ -95,6 +115,12 @@
 		$(MD)/ddx0.dd $(MD)/x1.dd $(MD)/x2.dd $(MD)/x3.dd \
 		$(MD)/scf.mn \
 		$(MD)/vtio.dr $(MD)/covdg.io $(MD)/term32.dt \
+		$(MD)/scdwn.dr \
+		$(MD)/n_scdwn.dd $(MD)/n1_scdwn.dd $(MD)/n2_scdwn.dd \
+		$(MD)/n3_scdwn.dd $(MD)/n4_scdwn.dd $(MD)/n5_scdwn.dd \
+		$(MD)/n6_scdwn.dd $(MD)/n7_scdwn.dd $(MD)/n8_scdwn.dd \
+		$(MD)/n9_scdwn.dd $(MD)/n10_scdwn.dd $(MD)/n11_scdwn.dd \
+		$(MD)/n12_scdwn.dd $(MD)/n13_scdwn.dd $(MD)/n14_scdwn.dd \
 		$(MD)/scdwp.dr $(MD)/p_scdwp.dd \
 		$(MD)/pipeman.mn $(MD)/piper.dr $(MD)/pipe.dd \
 		$(MD)/clock_60hz $(MD)/clock2_dw3 \
@@ -119,6 +145,12 @@
 		$(MD)/ddx0.dd $(MD)/x1.dd $(MD)/x2.dd $(MD)/x3.dd \
 		$(MD)/scf.mn \
 		$(MD)/vtio.dr $(MD)/cohr.io $(MD)/term51.dt \
+		$(MD)/scdwn.dr \
+		$(MD)/n_scdwn.dd $(MD)/n1_scdwn.dd $(MD)/n2_scdwn.dd \
+		$(MD)/n3_scdwn.dd $(MD)/n4_scdwn.dd $(MD)/n5_scdwn.dd \
+		$(MD)/n6_scdwn.dd $(MD)/n7_scdwn.dd $(MD)/n8_scdwn.dd \
+		$(MD)/n9_scdwn.dd $(MD)/n10_scdwn.dd $(MD)/n11_scdwn.dd \
+		$(MD)/n12_scdwn.dd $(MD)/n13_scdwn.dd $(MD)/n14_scdwn.dd \
 		$(MD)/scdwp.dr $(MD)/p_scdwp.dd \
 		$(MD)/pipeman.mn $(MD)/piper.dr $(MD)/pipe.dd \
 		$(MD)/clock_60hz $(MD)/clock2_dw3 \
@@ -131,6 +163,12 @@
 		$(MD)/ddx0.dd $(MD)/x1.dd $(MD)/x2.dd $(MD)/x3.dd \
 		$(MD)/scf.mn \
 		$(MD)/vtio.dr $(MD)/cohr.io $(MD)/term51.dt \
+		$(MD)/scdwn.dr \
+		$(MD)/n_scdwn.dd $(MD)/n1_scdwn.dd $(MD)/n2_scdwn.dd \
+		$(MD)/n3_scdwn.dd $(MD)/n4_scdwn.dd $(MD)/n5_scdwn.dd \
+		$(MD)/n6_scdwn.dd $(MD)/n7_scdwn.dd $(MD)/n8_scdwn.dd \
+		$(MD)/n9_scdwn.dd $(MD)/n10_scdwn.dd $(MD)/n11_scdwn.dd \
+		$(MD)/n12_scdwn.dd $(MD)/n13_scdwn.dd $(MD)/n14_scdwn.dd \
 		$(MD)/scdwp.dr $(MD)/p_scdwp.dd \
 		$(MD)/pipeman.mn $(MD)/piper.dr $(MD)/pipe.dd \
 		$(MD)/clock_60hz $(MD)/clock2_dw3 \
--- a/level1/coco/cmds/makefile	Tue Mar 30 02:44:42 2010 +0000
+++ b/level1/coco/cmds/makefile	Tue Mar 30 02:46:29 2010 +0000
@@ -1,11 +1,13 @@
 PORT = coco
 include $(NITROS9DIR)/rules.mak
 
+vpath %.a $(LEVEL1)/cmds
 vpath %.asm $(LEVEL1)/cmds:$(NITROS9DIR)/3rdparty/packages/basic09
 
 DEPENDS		= ./makefile
 
 AFLAGS		+= -i=$(NITROS9DIR)/3rdparty/packages/basic09
+LFLAGS		+= -l=$(NITROS9DIR)/lib/net.l -l=$(NITROS9DIR)/lib/alib.l -l=$(NITROS9DIR)/lib/sys6809l1.l
 
 BASIC09FILES	= basic09.asm runb.asm gfx.asm inkey.asm syscall.asm
 CMDS		= asm attr backup binex build calldbg cmp cobbler copy cputype \
@@ -19,6 +21,8 @@
 CMDS_D2		= basic09 runb gfx inkey syscall copy del echo format \
 		merge os9gen prompt tmode
 
+CMDS_DW		= inetd telnet dw
+
 SUBS		= gfx inkey syscall
 ALLOBJS		= $(CMDS) $(CMDS_D2) $(CMDS_DW) $(SUBS)
 
--- a/level1/coco/makefile	Tue Mar 30 02:44:42 2010 +0000
+++ b/level1/coco/makefile	Tue Mar 30 02:46:29 2010 +0000
@@ -62,7 +62,7 @@
 all:
 	@$(ECHO) "**************************************************"
 	@$(ECHO) "*                                                *"
-	@$(ECHO) "*         NitrOS-9/6809 Level 1 CoCo Port        *"
+	@$(ECHO) "*         NitrOS-9/$(CPU) Level 1 CoCo Port        *"
 	@$(ECHO) "*                                                *"
 	@$(ECHO) "**************************************************"
 	$(foreach dir, $(DIRS), ($(CD) $(dir); make);)
@@ -87,7 +87,7 @@
 
 $(DSKDW3COCO1):
 	$(RM) $@
-	$(OS9FORMAT_DW3) -q $@ -n"NitrOS-9/6809 Level 1"
+	$(OS9FORMAT_DW3) -q $@ -n"NitrOS-9/$(CPU) Level 1"
 	$(OS9GEN) $@ -b=$(BOOTFILE_COVDG_DW3_COCO1) -t=$(KERNELFILE_DW3_COCO1)
 	$(MAKDIR) $@,CMDS
 	$(MAKDIR) $@,SYS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/level1/coco/sys/inetd.conf	Tue Mar 30 02:46:29 2010 +0000
@@ -0,0 +1,11 @@
+# inetd configuration file format:
+# ListenPort <server opts>,Process,Params
+
+6809 telnet protect banner,login,
+6808,date,-t
+6807 telnet protect banner,shell,
+6806,mfree,
+6805,echo,lkasdflkasdjflksdjflksdfjlskdjflksdjflksjdflfkj
+6804,dw,s c
+6803,dir,/dd
+6802,procs,
--- a/level1/coco/sys/makefile	Tue Mar 30 02:44:42 2010 +0000
+++ b/level1/coco/sys/makefile	Tue Mar 30 02:46:29 2010 +0000
@@ -5,7 +5,7 @@
 
 DEPENDS		= ./makefile
 
-SYSFILES	= errmsg motd password
+SYSFILES	= errmsg motd password inetd.conf
 HELPFILES	= asm.hp attr.hp backup.hp binex.hp build.hp chd.hp \
 		chx.hp cmp.hp cobbler.hp config.hp copy.hp cputype.hp date.hp \
 		dcheck.hp debug.hp ded.hp deiniz.hp del.hp deldir.hp devs.hp \