changeset 2383:b399116a3b5f

Now we have a /N descriptor... and the code in scdwn.asm to handle it.
author boisy
date Sat, 23 Jan 2010 22:37:16 +0000
parents d5ecf07aae74
children 67b11fbf5253
files level1/coco/modules/makefile level1/modules/dw3.asm level1/modules/scdwn.asm level1/modules/scdwndesc.asm level2/coco3/modules/makefile level2/coco3_6309/modules/makefile
diffstat 6 files changed, 483 insertions(+), 428 deletions(-) [+]
line wrap: on
line diff
--- a/level1/coco/modules/makefile	Sat Jan 23 14:55:34 2010 +0000
+++ b/level1/coco/modules/makefile	Sat Jan 23 22:37:16 2010 +0000
@@ -43,7 +43,7 @@
 		nil.dd p_scbbp.dd p_scdwp.dd pipe.dd ssp.dd \
 		term_scbbt.dt term_sc6551.dt t1_scbbt.dd t2_sc6551.dd t3_sc6551.dd \
 		term32.dt term51.dt \
-		scdwn.dr term_scdwn.dt n1_scdwn.dd n2_scdwn.dd \
+		scdwn.dr term_scdwn.dt n_scdwn.dd n1_scdwn.dd n2_scdwn.dd \
 		n3_scdwn.dd n4_scdwn.dd n5_scdwn.dd n6_scdwn.dd n7_scdwn.dd \
 		n8_scdwn.dd n9_scdwn.dd n10_scdwn.dd n11_scdwn.dd n12_scdwn.dd \
 		n13_scdwn.dd n14_scdwn.dd
@@ -146,6 +146,9 @@
 term_scdwn.dt: scdwndesc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=0
 
+n_scdwn.dd: scdwndesc.asm
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=255
+
 n1_scdwn.dd: scdwndesc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=1
 
--- a/level1/modules/dw3.asm	Sat Jan 23 14:55:34 2010 +0000
+++ b/level1/modules/dw3.asm	Sat Jan 23 22:37:16 2010 +0000
@@ -409,12 +409,12 @@
 * NEW: root through all process descriptors. if any has a path open to this
 * device, send then S$HUP
                ldx       <D.AProcQ
-               beq       dowait
+               beq       dowaitq
                bsr       RootThrough
-dowait         ldx       <D.WProcQ
-               beq       dosleep
+dowaitq        ldx       <D.WProcQ
+               beq       dosleepq
                bsr       RootThrough
-dosleep        ldx       <D.SProcQ
+dosleepq       ldx       <D.SProcQ
                beq       CkLPRC
                bsr       RootThrough
 
--- a/level1/modules/scdwn.asm	Sat Jan 23 14:55:34 2010 +0000
+++ b/level1/modules/scdwn.asm	Sat Jan 23 22:37:16 2010 +0000
@@ -18,37 +18,40 @@
 *
 *          2010/01/03  Boisy G. Pitre
 * Moved IRQ stuff into DW3 subroutine module
-
-         	nam   	scdwn
-         	ttl   	CoCo DriveWire Network Driver
+*
+*   2      2010/01/23  Boisy G. Pitre
+* Added code in SS.Open to use /N wildcard device (tricky stuff!)
 
-         	ifp1
-         	use   	defsfile
-         	use   	dwdefs.d
-         	endc
+               nam       scdwn
+               ttl       CoCo DriveWire Network Driver
+
+               ifp1      
+               use       defsfile
+               use       dwdefs.d
+               endc      
 
 
-tylg     	set   	Drivr+Objct   
-atrv     	set   	ReEnt+Rev
-rev      	set   	$00
-edition  	set   	1
+tylg           set       Drivr+Objct
+atrv           set       ReEnt+Rev
+rev            set       $00
+edition        set       2
 
 * Note: driver memory defined in dwdefs.d
-         	mod   	eom,name,tylg,atrv,start,SCFDrvMemSz
+               mod       eom,name,tylg,atrv,start,SCFDrvMemSz
 
 * module info         	
-         	fcb   	UPDAT.+SHARE.	;driver access modes
-name     	fcs   	/scdwn/		;driver name
-         	fcb   	edition   	;driver edition 
+               fcb       UPDAT.+SHARE.       ;driver access modes
+name           fcs       /scdwn/             ;driver name
+               fcb       edition             ;driver edition 
 
 * dispatch calls            
-start    	equ   	*
-         	lbra  	Init
-         	lbra  	Read
-         	lbra  	Write
-         	lbra  	GetStat
-         	lbra  	SetStat
-	 	
+start          equ       *
+               lbra      Init
+               lbra      Read
+               lbra      Write
+               lbra      GetStat
+               lbra      SetStat
+
 ***********************************************************************
 * Term
 *
@@ -62,42 +65,43 @@
 * Exit:
 *    CC = carry set on error
 *    B  = error code   
-Term     	equ   	*
-          lda       <V.PORT+1,u		;get our port #
-          pshs 	a				;port # on stack
+Term           equ       *
+               lda       <V.PORT+1,u         ;get our port #
+ bmi termbye
+               pshs      a                   ;port # on stack
           * clear statics table entry
-          IFGT      Level-1
-          ldx   	<D.DWStat
-          ELSE
-          ldx   	>D.DWStat
-          ENDC
-          beq       tell
+               ifgt      Level-1
+               ldx       <D.DWStat
+               else      
+               ldx       >D.DWStat
+               endc      
+               beq       tell
 ; cheat: we know DW.StatTbl is at offset $00 from D.DWStat, do not bother with leax
 ;		leax      DW.StatTbl,x
-          clr		a,x				;clear out
+               clr       a,x                 ;clear out
 
           ; tell server
-tell
-          lda       #OP_SERTERM ; load command
-          pshs   	a      		; command store on stack
-          leax      ,s     		; point X to stack 
-          ldy       #2          ; 2 bytes to send 
+tell                     
+               lda       #OP_SERTERM         ; load command
+               pshs      a                   ; command store on stack
+               leax      ,s                  ; point X to stack 
+               ldy       #2                  ; 2 bytes to send 
 
-          pshs      u
+               pshs      u
 
-          IFGT      Level-1
-          ldu   	<D.DWSubAddr
-          ELSE
-          ldu   	>D.DWSubAddr
-          ENDC
-          beq       nosub		
-    		jsr       6,u      	; call DWrite
+               ifgt      Level-1
+               ldu       <D.DWSubAddr
+               else      
+               ldu       >D.DWSubAddr
+               endc      
+               beq       nosub
+               jsr       6,u                 ; call DWrite
 
-nosub
-          puls      u
-    		leas      2,s			; clean 3 DWsub args from stack 
-    		clrb
-          rts
+nosub                    
+               puls      u
+               leas      2,s                 ; clean 3 DWsub args from stack 
+termbye        clrb      
+               rts       
 
 ***********************************************************************
 * Init
@@ -110,90 +114,92 @@
 *    CC = carry set on error
 *    B  = error code
 *
-            
-Init		equ		*
+
+Init           equ       *
 
 ; link to subroutine module
 ; has the link already been done?
-          IFGT      Level-1
-          ldx       <D.DWSubAddr
-          ELSE
-          ldx       >D.DWSubAddr
-          ENDC
-          bne       already			; if so, do not bother
-			
-         	pshs      u				; preserve u since os9 link is coming up
+               ifgt      Level-1
+               ldx       <D.DWSubAddr
+               else      
+               ldx       >D.DWSubAddr
+               endc      
+               bne       already             ; if so, do not bother
+
+               pshs      u                   ; preserve u since os9 link is coming up
+
+               ifgt      Level-1
+               ldx       <D.Proc
+               pshs      x
+               ldx       <D.SysPrc
+               stx       <D.Proc
+               endc      
+               clra      
+
+               leax      dw3name,pcr
+               os9       F$Link
+               ifgt      Level-1
+               puls      x
+               stx       <D.Proc
+               endc      
+               bcs       InitEx2
+               ifgt      Level-1
+               sty       <D.DWSubAddr
+               else      
+               sty       >D.DWSubAddr
+               endc      
+               jsr       ,y                  ; call DW init routine
+
+               puls      u                   ; restore u
 
-          IFGT  	Level-1
-         	ldx   	<D.Proc
-         	pshs  	x
-         	ldx   	<D.SysPrc
-         	stx   	<D.Proc
-         	ENDC
-         	clra
-         		
-         	leax  	dw3name,pcr
-         	os9   	F$Link
-         	IFGT  	Level-1
-         	puls  	x
-         	stx   	<D.Proc
-         	ENDC
-         	bcs   	InitEx2
-         	IFGT  	Level-1
-         	sty   	<D.DWSubAddr
-         	ELSE
-         	sty   	>D.DWSubAddr
-         	ENDC
-         	jsr   	,y				; call DW init routine
-       	
-          puls	u                        ; restore u
-      	
-already
+already                  
 ; tell DW we have a new port opening (port mode already on stack)
-          ldb		<V.PORT+1,u		; get our port #			
-          lda       #OP_SERINIT         ; command 
-          pshs   	d      			; command + port # on stack
-          leax      ,s     			; point X to stack 
-          ldy       #2                  ; # of bytes to send
-			
-          pshs u
-          IFGT      Level-1
-          ldu   	<D.DWSubAddr
-          ELSE
-          ldu   	>D.DWSubAddr
-          ENDC
-    		jsr       6,u                 ; call DWrite
-          puls      u
-    		
+               ldb       <V.PORT+1,u         ; get our port #	
+* if /N wildcard, skip advertising via SERINIT
+ bmi initEx              
+               lda       #OP_SERINIT         ; command 
+               pshs      d                   ; command + port # on stack
+               leax      ,s                  ; point X to stack 
+               ldy       #2                  ; # of bytes to send
+
+               pshs      u
+               ifgt      Level-1
+               ldu       <D.DWSubAddr
+               else      
+               ldu       >D.DWSubAddr
+               endc      
+               jsr       6,u                 ; call DWrite
+               puls      u
+
 ; set up local buffer
-          ldb   	#RxBufDSz      	; default Rx buffer size
-          leax  	RxBuff,u       	; default Rx buffer address
-          stb   	RxBufSiz,u     	; save Rx buffer size
-          stx   	RxBufPtr,u     	; save Rx buffer address
-          stx   	RxBufGet,u          ; set initial Rx buffer input address
-          stx   	RxBufPut,u          ; set initial Rx buffer output address
-          abx  					; add buffer size to buffer start..
-          stx   	RxBufEnd,u     	; save Rx buffer end address
+               ldb       #RxBufDSz           ; default Rx buffer size
+               leax      RxBuff,u            ; default Rx buffer address
+               stb       RxBufSiz,u          ; save Rx buffer size
+               stx       RxBufPtr,u          ; save Rx buffer address
+               stx       RxBufGet,u          ; set initial Rx buffer input address
+               stx       RxBufPut,u          ; set initial Rx buffer output address
+               abx                           ; add buffer size to buffer start..
+               stx       RxBufEnd,u          ; save Rx buffer end address
 
-          tfr       u,d                 ; (A = high page of statics)
-          puls      b
-          puls      b                   ; (B = port number)
-          IFGT      Level-1
-          ldx       <D.DWStat
-          ELSE
-          ldx       >D.DWStat
-          ENDC
+               tfr       u,d                 ; (A = high page of statics)
+               puls      b
+               puls      b                   ; (B = port number)
+               ifgt      Level-1
+               ldx       <D.DWStat
+               else      
+               ldx       >D.DWStat
+               endc      
 ; cheat: we know DW.StatTbl is at offset $00 from D.DWStat, do not bother with leax
 ;		leax      DW.StatTbl,x
-          sta       b,x
-InitEx	equ		*
-          rts
-InitEx2
-          puls      u
-          rts
+               sta       b,x
+InitEx         equ       *
+               rts       
+InitEx2                  
+               puls      u
+               rts       
 
 ; drivewire info
-dw3name  	fcs  	/dw3/
+dw3name        fcs       /dw3/
 
 
 *****************************************************************************
@@ -208,26 +214,26 @@
 *    CC = carry set on error
 *    B  = error code
 * 
-Write    	equ   	*
-         	pshs      a			; character to send on stack
-         	ldb		<V.PORT+1,u	; port number into B
-         	lda   	#OP_SERWRITE	; put command into A
-         	pshs  	d
-         	leax  	,s
-         	ldy   	#$0003		; 3 bytes to send.. ugh.  need WRITEM (data mode)
-         	IFGT  	Level-1
-         	ldu   	<D.DWSubAddr
-         	ELSE
-         	ldu   	>D.DWSubAddr
-         	ENDC
-         	jsr   	6,u
-WriteOK   clrb
-WriteExit puls      a,x,pc		; clean stack, return
+Write          equ       *
+               pshs      a                   ; character to send on stack
+               ldb       <V.PORT+1,u         ; port number into B
+               lda       #OP_SERWRITE        ; put command into A
+               pshs      d
+               leax      ,s
+               ldy       #$0003              ; 3 bytes to send.. ugh.  need WRITEM (data mode)
+               ifgt      Level-1
+               ldu       <D.DWSubAddr
+               else      
+               ldu       >D.DWSubAddr
+               endc      
+               jsr       6,u
+WriteOK        clrb      
+WriteExit      puls      a,x,pc              ; clean stack, return
 
-	
-NotReady  comb
-          ldb       #E$NotRdy
-          rts
+
+NotReady       comb      
+               ldb       #E$NotRdy
+               rts       
 
 *************************************************************************************
 * Read
@@ -241,100 +247,100 @@
 *    CC = carry set on error
 *    B  = error code
 *
-Read      equ           *
+Read           equ       *
 * Check to see if there is a signal-on-data-ready set for this path.
 * If so, we return a Not Ready error.
-          lda           <SSigID,u     data ready signal trap set up?
-          bne           NotReady        yes, exit with not ready error
-          pshs  	cc,dp       ; save IRQ/Carry status, system DP
+               lda       <SSigID,u           data ready signal trap set up?
+               bne       NotReady            yes, exit with not ready error
+               pshs      cc,dp               ; save IRQ/Carry status, system DP
 
-ReadChr   orcc          #IntMasks	; mask interrupts
-          
-          lda   	RxDatLen,u 	; get our Rx buffer count
-          beq   	ReadSlp 	; no data, go sleep while waiting for new Rx data...
-			
+ReadChr        orcc      #IntMasks           ; mask interrupts
+
+               lda       RxDatLen,u          ; get our Rx buffer count
+               beq       ReadSlp             ; no data, go sleep while waiting for new Rx data...
+
           ; we have data waiting
-          deca				; one less byte in buffer
-          sta   	RxDatLen,u 	; save new Rx data count
-          
-          ldx   	RxBufGet,u 	; current Rx buffer pickup position
-          lda   	,x+       	; get Rx character, set up next pickup position
-          
-          cmpx  	RxBufEnd,u 	; end of Rx buffer?
-          blo   	ReadChr1   	; no, keep pickup pointer
-          ldx   	RxBufPtr,u 	; get Rx buffer start address
-ReadChr1 	stx   	RxBufGet,u	; set new Rx data pickup pointer
-			
+               deca                          ; one less byte in buffer
+               sta       RxDatLen,u          ; save new Rx data count
+
+               ldx       RxBufGet,u          ; current Rx buffer pickup position
+               lda       ,x+                 ; get Rx character, set up next pickup position
+
+               cmpx      RxBufEnd,u          ; end of Rx buffer?
+               blo       ReadChr1            ; no, keep pickup pointer
+               ldx       RxBufPtr,u          ; get Rx buffer start address
+ReadChr1       stx       RxBufGet,u          ; set new Rx data pickup pointer
+
           ; return to caller
-          puls  	cc,dp,pc   	; recover IRQ/Carry status, system DP, return with character in A
+               puls      cc,dp,pc            ; recover IRQ/Carry status, system DP, return with character in A
 
-ReadSlp	equ		*
+ReadSlp        equ       *
 
-          IFEQ  	Level-1
-ReadSlp2 	lda   	<V.BUSY,u
-          sta   	<V.WAKE,u	; store process id in this port's entry in the waiter table
-          lbsr  	Sleep0     	; sleep level 1 style
-          ELSE
-ReadSlp2   lda   	>D.Proc    	; process descriptor address MSB
-          sta   	<V.WAKE,u   ; save MSB in V.WAKE
-          clrb
-          tfr		d,x			; process descriptor address
-          IFNE  	H6309
-          oim   	#Suspend,P$State,x 	; suspend
-          ELSE
-          ldb   	P$State,x
-          orb   	#Suspend
-          stb   	P$State,x 	; suspend
-          ENDC
-          bsr		Sleep1		; sleep level 2 style
-          ENDC
-          
+               ifeq      Level-1
+ReadSlp2       lda       <V.BUSY,u
+               sta       <V.WAKE,u           ; store process id in this port's entry in the waiter table
+               lbsr      Sleep0              ; sleep level 1 style
+               else      
+ReadSlp2       lda       >D.Proc             ; process descriptor address MSB
+               sta       <V.WAKE,u           ; save MSB in V.WAKE
+               clrb      
+               tfr       d,x                 ; process descriptor address
+               ifne      H6309
+               oim       #Suspend,P$State,x  ; suspend
+               else      
+               ldb       P$State,x
+               orb       #Suspend
+               stb       P$State,x           ; suspend
+               endc      
+               bsr       Sleep1              ; sleep level 2 style
+               endc      
+
           ; we have been awakened..
-          
+
           ; check for signals
-          ldx   	>D.Proc		; process descriptor address
-          ldb   	P$Signal,x 	; pending signal for this process?
-          beq   	ChkState  	; no, go check process state...
-          cmpb  	#S$HUP  	; (S$HUP or lower)
-          bls  	ErrExit    	; yes, go do it...
+               ldx       >D.Proc             ; process descriptor address
+               ldb       P$Signal,x          ; pending signal for this process?
+               beq       ChkState            ; no, go check process state...
+               cmpb      #S$HUP              ; (S$HUP or lower)
+               bls       ErrExit             ; yes, go do it...
 
-ChkState 	equ   	*
+ChkState       equ       *
           ; have we been condemned to die?
-          IFNE  	H6309
-          tim   	#Condem,P$State,x
-          ELSE
-          ldb   	P$State,x
-          bitb  	#Condem
-          ENDC
-          bne   	PrAbtErr 	; yes, go do it...
-          
+               ifne      H6309
+               tim       #Condem,P$State,x
+               else      
+               ldb       P$State,x
+               bitb      #Condem
+               endc      
+               bne       PrAbtErr            ; yes, go do it...
+
           ; check that our waiter byte was cleared by ISR instance
-          tst		<V.WAKE,u	; our waiter byte
-          beq		ReadChr		; 0 = its our turn, go get a character 
-          bra   	ReadSlp		; false alarm, go back to sleep
+               tst       <V.WAKE,u           ; our waiter byte
+               beq       ReadChr             ; 0 = its our turn, go get a character 
+               bra       ReadSlp             ; false alarm, go back to sleep
 
-PrAbtErr	ldb   	#E$PrcAbt	; set error code
+PrAbtErr       ldb       #E$PrcAbt           ; set error code
 
-ErrExit  	equ  	*
-          IFNE  	H6309
-          oim   	#Carry,,s 	; set carry
-          ELSE
-          lda   	,s
-          ora   	#Carry
-          sta   	,s
-          ENDC
-          puls 	cc,dp,pc 	; restore CC, system DP, return
+ErrExit        equ       *
+               ifne      H6309
+               oim       #Carry,,s           ; set carry
+               else      
+               lda       ,s
+               ora       #Carry
+               sta       ,s
+               endc      
+               puls      cc,dp,pc            ; restore CC, system DP, return
 
-          IFEQ  	Level-1
-Sleep0   	ldx   	#$0			; sleep till ISR wakes us
-          bra   	TimedSlp
-          ENDC
+               ifeq      Level-1
+Sleep0         ldx       #$0                 ; sleep till ISR wakes us
+               bra       TimedSlp
+               endc      
 
-Sleep1    ldx   	#$1			; just sleep till end of slice, we are suspended (level 2)             
-TimedSlp	andcc 	#^Intmasks     ; enable IRQs
-          os9   	F$Sleep
-          clr       <V.WAKE,u
-          rts                      ; return
+Sleep1         ldx       #$1                 ; just sleep till end of slice, we are suspended (level 2)             
+TimedSlp       andcc     #^Intmasks          ; enable IRQs
+               os9       F$Sleep
+               clr       <V.WAKE,u
+               rts                           ; return
 
 
 **********************************************************************
@@ -349,74 +355,74 @@
 *    CC = carry set on error
 *    B  = error code 
 *
-GetStat
-          clrb                     ; default to no error...
-          pshs  	cc,dp  		; save IRQ/Carry status,system DP
-           
-        	ldx   	PD.RGS,y       ; caller's register stack pointer
-        	cmpa  	#SS.EOF		
-        	beq   	GSExitOK       ; SCF devices never return EOF
-           
-        	cmpa  	#SS.Ready
-        	bne   	Advertise      ; next check
-           	
+GetStat                  
+               clrb                          ; default to no error...
+               pshs      cc,dp               ; save IRQ/Carry status,system DP
+
+               ldx       PD.RGS,y            ; caller's register stack pointer
+               cmpa      #SS.EOF
+               beq       GSExitOK            ; SCF devices never return EOF
+
+               cmpa      #SS.Ready
+               bne       Advertise           ; next check
+
         	; SS.Ready
-        	lda   	RxDatLen,u	; get Rx data length
-        	beq   	NRdyErr    	; none, go report error
-        	sta   	R$B,x		; set Rx data available in caller's [B]
-GSExitOK	puls  	cc,dp,pc       ; restore Carry status, system DP, return         
-         
-NRdyErr	ldb  	#E$NotRdy         
-          bra		ErrExit		; return error code 
+               lda       RxDatLen,u          ; get Rx data length
+               beq       NRdyErr             ; none, go report error
+               sta       R$B,x               ; set Rx data available in caller's [B]
+GSExitOK       puls      cc,dp,pc            ; restore Carry status, system DP, return         
+
+NRdyErr        ldb       #E$NotRdy
+               bra       ErrExit             ; return error code 
 
-UnSvcErr 	ldb   	#E$UnkSvc
-          bra   	ErrExit		; return error code			
-			
+UnSvcErr       ldb       #E$UnkSvc
+               bra       ErrExit             ; return error code			
+
 ; We advertise all of our SERGETSTAT calls (except SS.Ready) to the server
-Advertise
-          ldb		#OP_SERGETSTAT
-          bsr		SendStat
+Advertise                
+               ldb       #OP_SERGETSTAT
+               bsr       SendStat
 
 ; Note: Here we could somehow obtain the size of the terminal window from the server
-GetScSiz  cmpa  	#SS.ScSiz
-          bne   	GetComSt	; next check
-          ldu   	PD.DEV,y
-          ldu   	V$DESC,u	; device descriptor
-          clra
-          ldb   	IT.COL,u	; return screen size
-          std   	R$X,x
-          ldb   	IT.ROW,u
-          std   	R$Y,x
-          puls  	cc,dp,pc	; restore Carry status, system DP, return
+GetScSiz       cmpa      #SS.ScSiz
+               bne       GetComSt            ; next check
+               ldu       PD.DEV,y
+               ldu       V$DESC,u            ; device descriptor
+               clra      
+               ldb       IT.COL,u            ; return screen size
+               std       R$X,x
+               ldb       IT.ROW,u
+               std       R$Y,x
+               puls      cc,dp,pc            ; restore Carry status, system DP, return
 
-GetComSt  cmpa  	#SS.ComSt
-          bne  	UnSvcErr	; no, we have no more answers, report error
-          ldd   	#$0000		; not used, return $0000
-          std   	R$Y,x
-          sta   	R$B,x
-          puls  	cc,dp,pc	; restore Carry status, system DP, return			
+GetComSt       cmpa      #SS.ComSt
+               bne       UnSvcErr            ; no, we have no more answers, report error
+               ldd       #$0000              ; not used, return $0000
+               std       R$Y,x
+               sta       R$B,x
+               puls      cc,dp,pc            ; restore Carry status, system DP, return			
 
 * Advertise Stat Code to server
 * A = Function Code
 * B = OP_SERGETSTAT or OP_SERSETSTAT
-SendStat
+SendStat                 
 ; advertise our GetStt code to the server
-          pshs      a,y,x,u
-          leas      -3,s
-          leax      ,s
-          stb		,x
-          sta		2,x
-          ldb		V.PORT+1,u
-          stb		1,x
-          ldy		#$0003
-          IFGT      LEVEL-1
-          ldu		<D.DWSubAddr
-          ELSE
-          ldu		>D.DWSubAddr
-          ENDC
-          jsr		6,u                    
-          leas      3,s
-          puls      a,y,x,u,pc
+               pshs      a,y,x,u
+               leas      -3,s
+               leax      ,s
+               stb       ,x
+               sta       2,x
+               ldb       V.PORT+1,u
+               stb       1,x
+               ldy       #$0003
+               ifgt      LEVEL-1
+               ldu       <D.DWSubAddr
+               else      
+               ldu       >D.DWSubAddr
+               endc      
+               jsr       6,u
+               leas      3,s
+               puls      a,y,x,u,pc
 
 *************************************************************************         
 * SetStat
@@ -430,156 +436,189 @@
 *    CC = carry set on error
 *    B  = error code 
 *
-SetStat  
-		ldb       #OP_SERSETSTAT
-		bsr       SendStat
-		cmpa      #SS.Open
-                beq       open
-		cmpa      #SS.Close
-                beq       ex
-		cmpa      #SS.ComSt
-                beq       comst
-                cmpa      #SS.SSig
-		beq       ssig
-                cmpa      #SS.Relea
-                lbne      donebad
-relea           lda      PD.CPR,y	get curr proc #
-                cmpa     <SSigID,u    same?
-                bne      ex
-                clr      <SSigID,u    clear process id
-ex              rts
-ssig            pshs    cc
-                orcc    #IntMasks
-                lda     PD.CPR,y        ; get curr proc #
-                ldx     PD.RGS,y
-                ldb     R$X+1,x         ; get user signal code
-        	tst     RxDatLen,u	; get Rx data length
-                beq     ssigsetup       ; branch if no data in buffer
+SetStat                  
+               cmpa      #SS.Open
+               bne       isitclose
+               bsr       open
+               ldd       #SS.Open*256+OP_SERSETSTAT
+               bra       SendStat
+               
+isitclose
+               ldb       #OP_SERSETSTAT
+               bsr       SendStat
+               cmpa      #SS.Close
+               beq       ex
+               cmpa      #SS.ComSt
+               beq       comst
+               cmpa      #SS.SSig
+               beq       ssig
+               cmpa      #SS.Relea
+               lbne      donebad
+relea          lda       PD.CPR,y            get curr proc #
+               cmpa      <SSigID,u           same?
+               bne       ex
+               clr       <SSigID,u           clear process id
+ex             rts       
+ssig           pshs      cc
+               orcc      #IntMasks
+               lda       PD.CPR,y            ; get curr proc #
+               ldx       PD.RGS,y
+               ldb       R$X+1,x             ; get user signal code
+               tst       RxDatLen,u          ; get Rx data length
+               beq       ssigsetup           ; branch if no data in buffer
 * if here, we have data so send signal immediately
-                os9     F$Send
-                puls    cc,pc
-ssigsetup       std     <SSigID,u     ; save process ID & signal
-                puls    cc,pc
+               os9       F$Send
+               puls      cc,pc
+ssigsetup      std       <SSigID,u           ; save process ID & signal
+               puls      cc,pc
 
-comst		leax      PD.OPT,y
-		ldy       #OPTCNT
-		IFGT      LEVEL-1
-		ldu       <D.DWSubAddr
-		ELSE
-		ldu       >D.DWSubAddr
-		ENDC
-		jsr       6,u
-          clrb
-          rts
+comst          leax      PD.OPT,y
+               ldy       #OPTCNT
+               ifgt      LEVEL-1
+               ldu       <D.DWSubAddr
+               else      
+               ldu       >D.DWSubAddr
+               endc      
+               jsr       6,u
+               clrb      
+               rts       
 
 * SS.Open processor
 * Entry: X=Register stack pointer
+*        U=Static memory pointer
 *        Y=Path descriptor pointer
-*        U=Static memory pointer
-open            pshs    u,y
-                tst     <V.PORT+1,u     check if this is $FF00 (wildcard)
- bra openex
-*                bne     openex
-* wildcard /N device... search for free device
-                IFGT    Level-1
-                ldx   	<D.DWStat
-                ELSE
-                ldx    	>D.DWStat
-                ENDC
+open     pshs  u,y        preserve registers
+         tst   <V.PORT+1,u         check if this is $FF00 (wildcard)
+         lbpl  L0BCD
+         ldx   PD.DEV,y   get pointer to device table entry
+         ldx   V$DESC,x   get pointer to /N descriptor
+         pshs  x          save device descriptor pointer
+L0B58    equ   *
+         ifgt      Level-1
+         ldx       <D.DWStat
+         else      
+         ldx       >D.DWStat
+         endc      
 ; cheat: we know DW.StatTbl is at offset $00 from D.DWStat, do not bother with leax
 ;		leax      DW.StatTbl,x
-                clrb
-next            tst     ,x+
-                beq     found
-                incb
-                cmpb    #DW.StatCnt-1
-                blt     next
-                comb
-                ldb     #E$MNF		failed to find device
-openex          puls    y,u,pc
+* start at /N1
+         ldb       #1      
+         leax      1,x
+next     tst       ,x+
+         beq       found
+         incb      
+         cmpb      #DW.StatCnt-1
+         blt       next
+         puls  u,y,x      purge stack
+         comb             set carry
+         ldb   #E$MNF     get module not found error
+         rts              return
+         
+* Found a free spot
+found    pshs  b          save # of free entry
+         leas  -5,s
+         leay  ,s
+         ldb   #'N        get netdev name prefix
+         stb   ,y+        put it in buffer
+         ldb   5,s        get netdev # that was free
+* Convert netdev # in B to ASCII eqivalent with high bit set
+
+         IFNE  H6309
+         divd  #10        divide it by 10
+         ELSE
+         lda   #-1
+L0B87b   inca
+         subb  #10
+         bcc   L0B87b
+         addb  #10
+         exg   a,b
+         cmpb  #0
+         ENDC
+         beq   L0B87      if answer is 0 there is only 1 digit, skip ahead 
+         orb   #$30       make first digit ASCII
+         stb   ,y+        put it in buffer
+L0B87    ora   #$B0       make remainder ASCII with high bit set
+         sta   ,y+        put it in buffer
+L0B92    leas  -2,s       make a buffer for process decriptor pointer
+         IFGT  Level-1
+         lbsr  L0238      switch to system process descriptor
+         ENDC
+         leax  2,s         Point to calculated dsc. name
+         lda   #Devic+Objct get module type
+         os9   F$Link     try & link it
+         IFGT  Level-1
+         lbsr  L0244      switch back to current process
+         ENDC
+         leas  7,s        purge stack
+         bcc   L0BAB      it's linked, skip ahead
+L0BA7    leas  1,s        purge netdev #
+         bra   L0B58      go look for another one
 
-* we have found a free device (B holds #), build name, link it, then
-* put into device table
-found
-* build name
-                leas    -4,s
-                leax    ,s
-                lda     #'N
-                sta     ,x+
-* take byte in B and turn into ASCII string at X
-                lda     #'0
-                cmpb    #9
-                bls     lo1
-lo10            subb    #10
-                bcs     hi10
-                inca
-                bra     lo10 
-hi10            addb     #10
-                sta      ,x+
-                lda      #'0
-lo1             decb
-                bmi      hi1
-                inca
-                bra      lo1
-hi1             
-* terminate with CR
-                ldb      #13
-                std      ,x
-* switch to system process descriptor
-                IFGT     Level-1
-                ldd      <D.Proc    Get current process dsc. ptr
-                pshs     d          Save on stack
-                ldd      <D.SysPrc  Get system process dsc. ptr
-                std      <D.Proc    Make it the current process
-                ENDC
-* link device
-                leax     2,s
-                lda      #Devic+Objct get module type
-                os9      F$Link     try & link it
-                IFGT     Level-1
-                puls     y
-* switch back to current process descriptor
-                sty      <D.Proc    Make it the current process
-                ENDC
-                leas     4,s        restore stack
-                bcs      openex
-* if no error on link, manipulate device table
-* Got a device descriptor, put into device table & save window # into static
-                ldy      ,s         get path descriptor pointer
-                ldx      PD.DEV,y   get pointer to device table
-                stu      V$DESC,x   save pointer to descriptor into it
-                os9      F$UnLink   unlink it from system map
-                bra      openex
+         IFGT  Level-1
+* Switch to system process descriptor
+L0238    pshs  d          Preserve D
+         ldd   <D.Proc    Get current process dsc. ptr
+         std   4,s        Preserve on stack
+         ldd   <D.SysPrc  Get system process dsc. ptr
+         std   <D.Proc    Make it the current process
+         puls  d,pc       Restore D & return
+
+* Switch back to current process
+L0244    pshs  d          Preserve D
+         ldd   4,s        Get current process ptr
+         std   <D.Proc    Make it the current process
+         puls  d,pc       Restore D & return
+         ENDC
+         
+* Got a device descriptor, put into device table & save netdev # into static
+L0BAB    
+         lda   M$PORT+2,u get MSB of port byte of newly linked /N? descriptor
+         ldy   3,s        get path descriptor pointer
+         ldx   PD.DEV,y   get pointer to device table
+         stu   V$DESC,x   save pointer to descriptor into it
+         ldu   1,s        get pointer to descriptor
+         os9   F$UnLink   unlink it from system map
+         ldu   5,s        get static mem pointer
+         sta   V.PORT+1,u
+         leas  7,s        purge stack
+* Load Y with address of descriptor and U with address of memory area
+ ldy   V$DESC,x
+ pshs  x,y,u
+ lbsr  Init
+ puls  x,y,u,pc
 
-          IFEQ      1
-SetPortSig    
-          cmpa      #SS.PortSig
-          bne       SetPortRel
-          lda       PD.CPR,y       current process ID
-          ldb       R$X+1,x        LSB of [X] is signal code
-          std       <PortSigPID
-          clrb
-          rts
-SetPortRel 
-          cmpa      #SS.PortRel
-          bne       donebad
-          leax      PortSigPID,u
-          bsr       ReleaSig
-          clrb
-          rts
-          ENDC
-donebad	comb
-		ldb       #E$UnkSvc
-		rts
-          
-ReleaSig  pshs    cc             save IRQ enable status
-          orcc    #IntMasks      disable IRQs while releasing signal
-          lda     PD.CPR,y       get current process ID
-          suba    ,x             same as signal process ID?
-          bne     NoReleas       no, go return...
-          sta     ,x             clear this signal's process ID
-NoReleas  puls    cc,pc          restore IRQ enable status, return
+L0BCD    clrb             No error
+         puls             y,u,pc
 
-		emod
-eom		equ		*
-		end
+               ifeq      1
+SetPortSig               
+               cmpa      #SS.PortSig
+               bne       SetPortRel
+               lda       PD.CPR,y            current process ID
+               ldb       R$X+1,x             LSB of [X] is signal code
+               std       <PortSigPID
+               clrb      
+               rts       
+SetPortRel               
+               cmpa      #SS.PortRel
+               bne       donebad
+               leax      PortSigPID,u
+               bsr       ReleaSig
+               clrb      
+               rts       
+               endc      
+donebad        comb      
+               ldb       #E$UnkSvc
+               rts       
+
+ReleaSig       pshs      cc                  save IRQ enable status
+               orcc      #IntMasks           disable IRQs while releasing signal
+               lda       PD.CPR,y            get current process ID
+               suba      ,x                  same as signal process ID?
+               bne       NoReleas            no, go return...
+               sta       ,x                  clear this signal's process ID
+NoReleas       puls      cc,pc               restore IRQ enable status, return
+
+               emod      
+eom            equ       *
+               end       
--- a/level1/modules/scdwndesc.asm	Sat Jan 23 14:55:34 2010 +0000
+++ b/level1/modules/scdwndesc.asm	Sat Jan 23 22:37:16 2010 +0000
@@ -76,16 +76,21 @@
          fcb   24         (szy) number of rows for display
 initsize equ   *
 
+name     equ   *
          IFEQ  Addr-0
-name     fcs   /Term/
+         fcs   /Term/
          ELSE
-name     fcc   /N/
+         IFNE  Addr-255
+         fcc   /N/
          IFGT  Addr-9
          fcc   '1'
          fcb   176+Addr-10
          ELSE
          fcb   176+Addr
          ENDC
+         ELSE
+         fcs   /N/
+         ENDC
          ENDC
 mgrnam   fcs   /SCF/
 drvnam   fcs   /scdwn/
--- a/level2/coco3/modules/makefile	Sat Jan 23 14:55:34 2010 +0000
+++ b/level2/coco3/modules/makefile	Sat Jan 23 22:37:16 2010 +0000
@@ -55,7 +55,8 @@
 		w8.dw w9.dw w10.dw w11.dw w12.dw w13.dw w14.dw w15.dw \
 		v1.dw v2.dw v3.dw v4.dw v5.dw \
 		v6.dw v7.dw \
-		scdwn.dr term_scdwn.dt n1_scdwn.dd n2_scdwn.dd n3_scdwn.dd \
+		scdwn.dr term_scdwn.dt n_scdwn.dd \
+		n1_scdwn.dd n2_scdwn.dd n3_scdwn.dd \
                 n4_scdwn.dd n5_scdwn.dd n6_scdwn.dd n7_scdwn.dd \
 		n8_scdwn.dd n9_scdwn.dd n10_scdwn.dd n11_scdwn.dd \
                 n12_scdwn.dd n13_scdwn.dd n14_scdwn.dd
@@ -198,6 +199,9 @@
 term_scdwn.dt: scdwndesc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=0
 
+n_scdwn.dd: scdwndesc.asm
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=255
+
 n1_scdwn.dd: scdwndesc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=1
 
--- a/level2/coco3_6309/modules/makefile	Sat Jan 23 14:55:34 2010 +0000
+++ b/level2/coco3_6309/modules/makefile	Sat Jan 23 22:37:16 2010 +0000
@@ -55,7 +55,8 @@
 		w8.dw w9.dw w10.dw w11.dw w12.dw w13.dw w14.dw w15.dw \
 		v1.dw v2.dw v3.dw v4.dw v5.dw \
 		v6.dw v7.dw \
-		scdwn.dr term_scdwn.dt n1_scdwn.dd n2_scdwn.dd n3_scdwn.dd \
+		scdwn.dr term_scdwn.dt n_scdwn.dd \
+		n1_scdwn.dd n2_scdwn.dd n3_scdwn.dd \
                 n4_scdwn.dd n5_scdwn.dd n6_scdwn.dd n7_scdwn.dd \
 		n8_scdwn.dd n9_scdwn.dd n10_scdwn.dd n11_scdwn.dd \
                 n12_scdwn.dd n13_scdwn.dd n14_scdwn.dd
@@ -198,6 +199,9 @@
 term_scdwn.dt: scdwndesc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=0
 
+n_scdwn.dd: scdwndesc.asm
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=255
+
 n1_scdwn.dd: scdwndesc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) -aAddr=1