NEW
  AUTO 3,1
				.LIST OFF
				.OP	65C02
				.OR	$2000
				.TF bin/netconfig
*--------------------------------------
* for build 2666 onwards
*--------------------------------------

				.INB inc/macros.i
				.INB inc/a2osx.i
				.INB inc/mli.i
				.INB inc/mli.e.i
				.INB inc/libtui.i
*--------------------------------------
* Constants
*--------------------------------------
EV.SAVE			.EQ $C0
EV.QUIT			.EQ $C1
EV.AUTOIP		.EQ $C2
EV.OK			.EQ $CE
EV.CANCEL		.EQ $CF
SCR.X1			.EQ 3
SCR.X2			.EQ 27
SCR.X3			.EQ 52
SCR.Y1			.EQ 1
SCR.Y2			.EQ 12
*--------------------------------------
* Zero Page Segment, up to 32 bytes
*--------------------------------------
				.DUMMY
				.OR ZPBIN
ZS.START
hFile			.BS 1
hBuf1			.BS 1
hCTX			.BS 1
hSCRN			.BS 1
hItem1			.BS 1
hIPLabel		.BS 1
hIPaddrL		.BS 1
hIPaddrV		.BS 1
hIPmaskL		.BS 1
hIPmaskV		.BS 1
hIPgwayL		.BS 1
hIPgwayV		.BS 1
hIPns1L			.BS 1
hIPns1V			.BS 1
hIPns2L			.BS 1
hIPns2V			.BS 1
hIPdomL			.BS 1
hIPdomV			.BS 1
hDLGS			.BS 1
hDLGitem		.BS 1
ZPPtr1			.BS 2
ZPTmpPtr1		.BS 2
ZPTmpPtr2		.BS 2
ZPTmpPtr3		.BS 2
ZPTmpPtr4		.BS 2
ZPBufPtr		.BS 1
ZS.END			.ED
*--------------------------------------
*			File Header (16 Bytes)
*--------------------------------------
CS.START		cld
				jmp (.1,x)
				.DA #$61				6502,Level 1 (65c02)
				.DA #1					BIN Layout Version 1
				.DA #0					S.PS.F
				.DA #0
				.DA CS.END-CS.START		Code Length To Relocate
				.DA DS.END-DS.START		Data Segment to Allocate
				.DA #16					Stack Size
				.DA #ZS.END-ZS.START	Zero Page Size
				.DA 0
*--------------------------------------
.1				.DA CS.INIT
				.DA CS.RUN
				.DA CS.DOEVENT
				.DA	CS.QUIT

L.LIBTUI		.DA LIBTUI
*--------------------------------------
L.NETSTART		.DA NETSTART
L.HOSTNAME		.DA HOSTNAME
L.NETWORK		.DA NETWORK
L.NETWORKIP		.DA NETWORKIP
L.NETWORKET		.DA NETWORKET
L.TCPIP.CONF	.DA TCPIP.CONF
L.SCRN.Title	.DA SCRN.Title
L.SCRN.Status	.DA SCRN.Status
L.SCRN.StatusSv	.DA SCRN.StatusSv
L.HOST.Label	.DA HOST.Label
L.IFACE.Label	.DA IFACE.Label
L.IFACE.List	.DA IFACE.List
L.AUTOIP.Label	.DA AUTOIP.Label
L.AUTOIP.List	.DA AUTOIP.List
L.PROTO.Label	.DA PROTO.Label
L.LIBTCPIP.Label .DA LIBTCPIP.Label
L.LIBETALK.Label .DA LIBETALK.Label
L.SERV.Label	.DA SERV.Label
L.TELNET.Label	.DA TELNET.Label
L.HTTPD.Label	.DA	HTTPD.Label
L.BBSD.Label	.DA BBSD.Label
L.MANUAL.Label	.DA MANUAL.Label
L.IPADDR.Label	.DA IPADDR.Label
L.MASK.Label	.DA MASK.Label
L.GATEWAY.Label .DA GATEWAY.Label
L.NS1.Label		.DA NS1.Label
L.NS2.Label		.DA NS2.Label
L.DOM.Label		.DA DOM.Label
L.BUTQ.Label	.DA BUTQ.Label
L.BUTS.Label	.DA BUTS.Label
L.DLGS.Title	.DA DLGS.Title
L.DLGS.Text		.DA DLGS.Text
L.DLGS.Label	.DA DLGS.Label
L.BUT.OK		.DA BUT.OK
L.BUT.Cancel	.DA BUT.Cancel
L.NS.Hdr		.DA NS.Hdr		

T.NICs			.DA NS.Uth				Table of 6 ptrs -> NIC lines
				.DA NS.Lanc		
				.DA NS.U2
				.DA NS.Dan2Eth		
				.DA NS.Udeth
				.DA NS.Udeth.D	

L.NS.networkd	.DA NS.networkd
L.NS.libtcpip	.DA NS.libtcpip
L.NS.libetalk	.DA NS.libetalk
L.NS.amper		.DA NS.amper
L.NS.telnetd	.DA NS.telnetd	
L.NS.httpd	    .DA NS.httpd	
L.NS.bbsd		.DA NS.bbsd	
L.IP.Hash		.DA IP.Hash
L.Host.Hdr		.DA Host.Hdr
L.EOL			.DA EOL
*L.Str.debug		.DA Str.debug
L.IP.Keywords	.DA IP.Keywords
J.IP.Keywords	.DA CS.IPR.addr
				.DA CS.IPR.mask
				.DA CS.IPR.gway
				.DA CS.IPR.ns1
				.DA CS.IPR.dom
				.DA 0
*--------------------------------------
CS.INIT			>LDYA L.LIBTUI
				>SYSCALL LoadLib
				bcs CS.INIT.RTS

				sta hLIBTUI
*				clc
CS.INIT.RTS		rts
*--------------------------------------
CS.RUN			>LDYAI 80
				>SYSCALL GetMem
				bcc .1
				rts

.1				>STYA ZPTmpPtr1
				stx hBuf1
				
				jsr CS.HOSTR				Read HOSTNAME file
				jsr CS.IPR					Read TCPIP.CONF file
				jsr CS.File.Close			CS.IPR doesn't close the file

				>LIBCALL hLIBTUI,LIBTUI.Init
				bcc .2
				rts

.2				sta hCTX
				jsr CS.SCRN.Init
				bcc .3
				rts

.3				jsr CS.HOST.INIT
				bcs CS.RUN.RTS

				jsr CS.IFACE.Init
				bcs CS.RUN.RTS

				jsr CS.AUTOIP.Init
				bcs CS.RUN.RTS

				jsr CS.PROTO.Init
				bcs CS.RUN.RTS

				jsr CS.SERV.Init
				bcs CS.RUN.RTS

				jsr CS.IP.Init
				bcs CS.RUN.RTS

				jsr CS.BUT.Init
				bcs CS.RUN.RTS

				jsr CS.SCRN.Draw			Will Call SCRN.Draw
				
				>LDA.G AUTOIP.Var
				bne .4
				
				jsr CS.AUTOIP.Hide
.4				lda hItem1
				>LIBCALL hLIBTUI,LIBTUI.Activate

*--------------------------------------
CS.RUN.LOOP2	lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Exec
				bcs CS.RUN.RTS

				cmp #EV.RESIZE
				bne .1

				jsr CS.SCRN.Draw
				bcs CS.RUN.RTS

				bra CS.RUN.LOOP2

.1				cmp #EV.AUTOIP
				bne .2
				
				>LDA.G AUTOIP.Var
				bne .11
				jsr CS.AUTOIP.Hide
				bra CS.RUN.LOOP2
				
.11				jsr CS.AUTOIP.Show
				bra CS.RUN.LOOP2

.2				cmp #EV.SAVE
				bne .3

				jsr CS.DLG.SAVE
				bcc CS.RUN.LOOP2

.3				cmp #EV.QUIT
				bne CS.RUN.LOOP2

				lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Destroy

				lda #0
				sec
CS.RUN.RTS		rts
*--------------------------------------
CS.HOSTR		>LDYA L.HOSTNAME			etc/hostname
				JSR CS.File.OpenRD
				bcc CS.HOSTR.Loop
				rts
CS.HOSTR.Loop	jsr CS.File.Read
				bcs .1
				lda (ZPTmpPtr1)
				beq CS.HOSTR.Loop
				cmp #'#'
				beq CS.HOSTR.Loop
.1				>LEA.G HOST.Buf
				>STYA ZPTmpPtr4

				ldy #0					Copy setting to var string

CS.HOSTR.Loop2	lda (ZPTmpPtr1),y
				beq .2

				sta (ZPTmpPtr4),y
				iny 
				cpy #$0F
				bcc CS.HOSTR.Loop2

.2				lda #0
				sta (ZPTmpPtr4),y
*				clc
				jmp CS.File.Close
*--------------------------------------
CS.IPR			>LDYA L.TCPIP.CONF		etc/tcpip.conf
				JSR CS.File.OpenRD
				bcc .1
				rts
				
.1				lda #1
				>STA.G AUTOIP.Var		Preselect manual IP

CS.IPR.Loop		jsr CS.File.Read
				bcs .8
.1				ldy #$ff
.2				iny
.21				lda (ZPTmpPtr1),y
				cmp #C.SPACE
				beq .3
				cmp #'#'
				bne .2
				lda #0
				>STA.G AUTOIP.Var		Any hash found preselects autoip/dhcp
				
				inc ZPTmpPtr1
				bcc .21
				inc ZPTmpPtr2+1
				bra .21
.3				lda L.IP.Keywords		Whole word, check
				sta ZPTmpPtr2
				lda L.IP.Keywords+1
				sta ZPTmpPtr2+1
				ldx #0
.4				phy						save keyword len
				tya
				cmp (ZPTmpPtr2)
				bne .6					empty
.5				lda (ZPTmpPtr2),y		check next char
				dey
				cmp (ZPTmpPtr1),y
				bne .6					no match
				tya
				bne .5					
				ply						discard keyword len
				jsr CS.IPR.Keyword		keyword matched - action it
				bcc CS.IPR.Loop
				rts
.6				lda (ZPTmpPtr2)
				sec
				adc ZPTmpPtr2
				sta ZPTmpPtr2
				bcc .7
				inc ZPTmpPtr2+1
.7				inx
				inx
				ply						reset keyword len
				lda (ZPTmpPtr2)
				bne .4

				bra CS.IPR.Loop

.8				clc
				jmp CS.File.Close

CS.IPR.Keyword	lda ZPTmpPtr1+1			Move ptr to after keyword+space
				sta ZPTmpPtr3+1
				iny
				clc
				tya
				adc ZPTmpPtr1
				sta ZPTmpPtr3
				bcc .81

				inc ZPTmpPtr3+1

.81				jmp (J.IP.Keywords,x)

CS.IPR.addr		>LEA.G IPADDR.Buf

				>STYA ZPTmpPtr4

CS.IPR.Copy		ldx #15					"255.255.255.255" + \0 = 16

CS.IPR.CopyX	ldy #0					Copy setting to correct var

.1				lda (ZPTmpPtr3),y
				beq .9

				sta (ZPTmpPtr4),y
				iny 
				dex
				bne .1

.9				lda #0
				sta (ZPTmpPtr4),y

				clc
				rts

CS.IPR.mask		>LEA.G MASK.Buf 
				>STYA ZPTmpPtr4
				jmp CS.IPR.Copy
				
CS.IPR.gway		>LEA.G GATEWAY.Buf
				>STYA ZPTmpPtr4
				jmp CS.IPR.Copy
				
CS.IPR.ns1		>LEA.G NS1.Buf
				>STYA ZPTmpPtr4

				lda (ZPTmpPtr4)
				bne CS.IPR.ns2			NS1 already populated
				jmp CS.IPR.Copy
				
CS.IPR.ns2		>LEA.G NS2.Buf
				>STYA ZPTmpPtr4
				jmp CS.IPR.Copy
				
CS.IPR.dom		>LEA.G DOM.Buf
				>STYA ZPTmpPtr4

				ldx #31					!!! max 32 for domain name
				jsr CS.IPR.CopyX
				sec						last one so sec
				rts
*--------------------------------------
CS.File.OpenRD	stz hFile
				>PUSHYA
				>PUSHBI	O.RDONLY
				>PUSHBI 0				Type
				>PUSHWZ					Aux type
				>SYSCALL FOpen
				bcs .9

				sta hFile

.9				rts
*--------------------------------------
CS.File.Read	>PUSHB hFile
				>PUSHW ZPTmpPtr1
				>PUSHWI 80
				>SYSCALL FGetS
				bcs .9

				lda (ZPTmpPtr1)
				beq CS.File.Read

*				clc

.9				rts
*--------------------------------------
CS.File.OpenWR	>PUSHYA
				>PUSHBI O.CREATE+O.WRONLY+O.TRUNC
				>PUSHBI $04				Type Text
				>PUSHWZ					Aux type
				>SYSCALL FOpen
				bcs .9
				sta hFile
.9				rts
*--------------------------------------
CS.File.FPutSYA	pha
				>PUSHB hFile
				pla
				>PUSHYA
				>SYSCALL FPutS
				rts
*--------------------------------------
CS.File.Close	php
				pha
				lda hFile
				beq .8
				>SYSCALL FClose
.8				pla
				plp
				rts
*--------------------------------------
CS.SCRN.Init	>PUSHB hCTX				hParent
				>PUSHBI S.OBJ.F.bTitle+S.OBJ.F.bStatus
				>LIBCALL hLIBTUI,LIBTUI.NewScrn
				bcs .9

				sta hSCRN

				>PUSHA
				>PUSHBI S.OBJ.pTITLE
				>PUSHEA.G SCRN.TitleBuf
				>LIBCALL hLIBTUI,LIBTUI.SetProp

				>PUSHB hSCRN
				>PUSHBI S.OBJ.pSTATUS
				>PUSHW L.SCRN.Status
				>LIBCALL hLIBTUI,LIBTUI.SetProp

.9				rts
*--------------------------------------
CS.HOST.INIT	>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y1
				>PUSHW L.HOST.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcs .9

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1+9
				>PUSHBI SCR.Y1
				>PUSHBI 18				W
				>PUSHEA.G HOST.Buf
				>PUSHWI 15				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta	hItem1
.9				rts
*--------------------------------------
CS.IFACE.Init	>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y1+2
				>PUSHW L.IFACE.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcs .9

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y1+3
				>PUSHWZ
				>PUSHW L.IFACE.List
				>PUSHEA.G IFACE.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewRadio

.9				rts
*--------------------------------------
CS.AUTOIP.Init	>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y1+2
				>PUSHW L.AUTOIP.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcs .9
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y1+3
				>PUSHBI 0				HK
				>PUSHBI EV.AUTOIP		EV
				>PUSHW L.AUTOIP.List
				>PUSHEA.G AUTOIP.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewRadio
.9				rts				

CS.PROTO.Init	>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y1+6
				>PUSHW L.PROTO.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcs .1

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y1+7
				>PUSHWZ
				>PUSHW L.LIBTCPIP.Label
				>PUSHEA.G LIBTCPIP.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
.1				bcs .9				

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y1+8
				>PUSHWZ
				>PUSHW L.LIBETALK.Label
				>PUSHEA.G LIBETALK.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
.9				rts				

CS.SERV.Init	>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y1+2
				>PUSHW L.SERV.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcc .1
				rts

.1				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y1+3
				>PUSHWZ
				>PUSHW L.TELNET.Label
				>PUSHEA.G TELNET.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
				bcc .2
				rts

.2				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y1+4
				>PUSHWZ
				>PUSHW L.HTTPD.Label
				>PUSHEA.G HTTPD.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
				bcc .3

				rts

.3				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y1+5
				>PUSHWZ
				>PUSHW L.BBSD.Label
				>PUSHEA.G BBSD.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
				rts

CS.IP.Init		>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y2
				>PUSHW L.MANUAL.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPLabel
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y2+2
				>PUSHW L.IPADDR.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPaddrL

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y2+3
				>PUSHBI 18				W
				>PUSHEA.G IPADDR.Buf
				>PUSHWI 15				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta hIPaddrV
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y2+2
				>PUSHW L.MASK.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPmaskL

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y2+3
				>PUSHBI 18				W
				>PUSHEA.G MASK.Buf
				>PUSHWI 15				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta hIPmaskV
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y2+2
				>PUSHW L.GATEWAY.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPgwayL

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y2+3
				>PUSHBI 18				W
				>PUSHEA.G GATEWAY.Buf
				>PUSHWI 15				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta hIPgwayV
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y2+5
				>PUSHW L.NS1.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPns1L

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X1
				>PUSHBI SCR.Y2+6
				>PUSHBI 18				W
				>PUSHEA.G NS1.Buf
				>PUSHWI 15				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta hIPns1V
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y2+5
				>PUSHW L.NS2.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPns2L

				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X2
				>PUSHBI SCR.Y2+6
				>PUSHBI 18				W
				>PUSHEA.G NS2.Buf
				>PUSHWI 15				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta hIPns2V
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y2+5
				>PUSHW L.DOM.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				sta hIPdomL
				
				>PUSHB hSCRN			hParent
				>PUSHBI SCR.X3
				>PUSHBI SCR.Y2+6
				>PUSHBI 25				W
				>PUSHEA.G DOM.Buf
				>PUSHWI 65				Len
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				sta hIPdomV
				rts
*--------------------------------------
CS.BUT.Init		>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 20				Y1
				>PUSHBI	19				Ctrl-S
				>PUSHBI EV.SAVE
				>PUSHW L.BUTS.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
				bcs .9

				>PUSHB hSCRN			hParent
				>PUSHBI 65				X1
				>PUSHBI 20				Y1
				>PUSHBI	17				Ctrl-Q
				>PUSHBI EV.QUIT
				>PUSHW L.BUTQ.Label
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
.9				rts
*--------------------------------------
CS.AUTOIP.Hide	lda hIPLabel
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPaddrL
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPaddrV
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPmaskL
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPmaskV
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPgwayL
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPgwayV
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPns1L
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPns1V
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPns2L
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPns2V
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPdomL
				>LIBCALL hLIBTUI,LIBTUI.Hide
				lda hIPdomV
				>LIBCALL hLIBTUI,LIBTUI.Hide
				rts
*--------------------------------------
CS.AUTOIP.Show	lda hIPLabel
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPaddrL
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPaddrV
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPmaskL
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPmaskV
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPgwayL
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPgwayV
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPns1L
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPns1V
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPns2L
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPns2V
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPdomL
				>LIBCALL hLIBTUI,LIBTUI.Show
				lda hIPdomV
				>LIBCALL hLIBTUI,LIBTUI.Show
				rts
*--------------------------------------
CS.DLG.SAVE		>PUSHB hCTX				hParent
				>PUSHBI 70				W
				>PUSHBI 11				H
				>PUSHBI 0
				>PUSHW L.DLGS.Title
				>LIBCALL hLIBTUI,LIBTUI.NewDlg
				bcs .9
				
				sta hDLGS
				>PUSHB hDLGS			hParent
				>PUSHBI 2				X1
				>PUSHBI 2				Y1
				>PUSHW L.DLGS.Text
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcs .9
				
				>PUSHB hDLGS			hParent
				>PUSHBI 2
				>PUSHBI 4				Y1
				>PUSHWZ					HotKey, EV
				>PUSHW L.DLGS.Label
				>PUSHEA.G DLGS.Var
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
				bcc CS.DLG.SAVE2
.9				rts

CS.DLG.SAVE2	sta hDLGitem
				>PUSHB hDLGS			hParent
				>PUSHBI 48				X1
				>PUSHBI 7				Y1
				>PUSHBI	C.CR			Hotkey ENTER
				>PUSHBI EV.OK
				>PUSHW L.BUT.OK
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
				bcs .8

				>PUSHB hDLGS			hParent
				>PUSHBI 57				X1
				>PUSHBI 7				Y1
				>PUSHBI	3				Hotkey Ctrl-C
				>PUSHBI EV.CANCEL
				>PUSHW L.BUT.Cancel
				>PUSHBI	0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
				bcs .8

				lda hDLGS
				>LIBCALL hLIBTUI,LIBTUI.Draw
				bcc .9
.8				rts
.9				lda hDLGitem
				>LIBCALL hLIBTUI,LIBTUI.Activate
CS.DLG.Loop		lda hDLGS
				>LIBCALL hLIBTUI,LIBTUI.Exec
				cmp #EV.OK
				bne .1
				>PUSHB hSCRN
				>PUSHBI S.OBJ.pSTATUS
				>PUSHW L.SCRN.StatusSv
				>LIBCALL hLIBTUI,LIBTUI.SetProp
				jsr CS.IPW						write tcpip.conf
				jsr CS.HOSTW					write hostname
				jsr CS.NETW						write startup system script
				>LDA.G DLGS.Var
				cmp #1
				beq .1
				jsr CS.SHW						write startup shell script
				bra .2
.1				cmp #EV.CANCEL
				bne CS.DLG.Loop
				
.2				php
				pha
				lda hDLGS
				>LIBCALL hLIBTUI,LIBTUI.Destroy
				lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Draw
				pla
				plp
.9				rts						
*--------------------------------------
CS.HOSTW		>LDYA L.HOSTNAME
				jsr CS.File.OpenWR
				bcc .1
				rts
.1				>LDYA L.HOST.Hdr
				jsr CS.File.FPutSYA
				
				>LEA.G HOST.Buf
				jsr CS.File.FPutSYA

				>LDYA L.EOL
				jsr CS.File.FPutSYA

				jmp CS.File.Close
*--------------------------------------
CS.IPW			>LDYA L.TCPIP.CONF
				jsr CS.File.OpenWR
				bcc .1

				rts

.1				>LDA.G AUTOIP.Var
				bne CS.IPW.addr

				>LDYA L.IP.Hash
				jsr CS.File.FPutSYA

CS.IPW.addr		>LDYA L.IPADDR.Label
				jsr CS.File.FPutSYA
				
				>LEA.G IPADDR.Buf
				jsr CS.File.FPutSYA

				>LDYA L.EOL
				jsr CS.File.FPutSYA

				>LDA.G AUTOIP.Var
				bne CS.IPW.mask

				>LDYA L.IP.Hash
				jsr CS.File.FPutSYA

CS.IPW.mask		>LDYA L.MASK.Label
				jsr CS.File.FPutSYA
				
				>LEA.G MASK.Buf
				jsr CS.File.FPutSYA
				
				>LDYA L.EOL
				jsr CS.File.FPutSYA
				
				>LDA.G AUTOIP.Var
				bne CS.IPW.gway
				
				>LDYA L.IP.Hash
				jsr CS.File.FPutSYA

CS.IPW.gway		>LDYA L.GATEWAY.Label
				jsr CS.File.FPutSYA
				
				>LEA.G GATEWAY.Buf
				jsr CS.File.FPutSYA
				
				>LDYA L.EOL
				jsr CS.File.FPutSYA
				
				>LDA.G AUTOIP.Var
				bne CS.IPW.ns1
				
				>LDYA L.IP.Hash
				jsr CS.File.FPutSYA

CS.IPW.ns1		>LDYA L.NS1.Label
				jsr CS.File.FPutSYA
				
				>LEA.G NS1.Buf
				jsr CS.File.FPutSYA
				
				>LDYA L.EOL
				jsr CS.File.FPutSYA
				
				>LDA.G AUTOIP.Var
				bne CS.IPW.ns2
				
				>LDYA L.IP.Hash
				jsr CS.File.FPutSYA

CS.IPW.ns2		>LDYA L.NS1.Label			Must use NS1 label again
				jsr CS.File.FPutSYA
				
				>LEA.G NS2.Buf
				jsr CS.File.FPutSYA
				
				>LDYA L.EOL
				jsr CS.File.FPutSYA

				>LDA.G AUTOIP.Var
				bne CS.IPW.dom

				>LDYA L.IP.Hash
				jsr CS.File.FPutSYA

CS.IPW.dom		>LDYA L.DOM.Label
				jsr CS.File.FPutSYA
				
				>LEA.G DOM.Buf
				jsr CS.File.FPutSYA
				
				>LDYA L.EOL
				jsr CS.File.FPutSYA
				jmp CS.File.Close
*--------------------------------------
CS.SHW			>LDYA L.Netstart			Write network startup shell script
				jsr CS.File.OpenWR
				bcc .1
				rts

.1				>LDYA L.NS.Hdr
				jsr CS.File.FPutSYA
				
				>LDA.G IFACE.var			range = 0..5
				asl
				tax							X = 0..10

				>LDYA T.NICs,x
				jsr CS.File.FPutSYA

CS.SHW.netd		>LDYA L.NS.networkd
				jsr CS.File.FPutSYA
				
				>LDA.G LIBTCPIP.Var
				beq CS.SHW.etalk
				
				>LDYA L.NS.libtcpip
				jsr CS.File.FPutSYA

CS.SHW.etalk	>LDA.G LIBETALK.Var
				beq CS.SHW.amper

				>LDYA L.NS.libetalk
				jsr CS.File.FPutSYA

cs.SHW.amper	>LDYA L.NS.amper
				jsr CS.File.FPutSYA
				
				>LDA.G TELNET.Var
				beq CS.SHW.httpd
				
				>LDYA L.NS.telnetd
				jsr CS.File.FPutSYA

CS.SHW.httpd	>LDA.G HTTPD.Var
				beq CS.SHW.bbsd

				>LDYA L.NS.httpd
				jsr CS.File.FPutSYA

CS.SHW.bbsd		>LDA.G BBSD.Var
				beq CS.SHW.close

				>LDYA L.NS.bbsd
				jsr CS.File.FPutSYA
CS.SHW.close	jmp CS.File.Close		
*.9				rts				
*--------------------------------------
CS.NETW			>LDYA L.NETWORK			Write network startup system script
				jsr CS.File.OpenWR
				bcc .1

				rts

.1				>LDA.G LIBTCPIP.Var
				bpl CS.NETW.etalk

				>LDYA L.NETWORKIP
				jsr CS.File.FPutSYA

CS.NETW.etalk	>LDA.G LIBETALK.Var
				bpl .9

				>LDYA L.NETWORKET
				jsr CS.File.FPutSYA

.9				jmp CS.File.Close
*--------------------------------------
CS.DOEVENT		sec						do not discard TIMER event
				rts
*--------------------------------------
CS.QUIT			lda hBuf1
				beq .1

				>SYSCALL FreeMem

.1				lda hCTX
				beq .2

				>LIBCALL hLIBTUI,LIBTUI.Close

.2				lda hLIBTUI
				beq .8

				>SYSCALL UnloadLib

.8				clc
				rts
*--------------------------------------
CS.SCRN.Draw	lda hSCRN
				>SYSCALL GetMemPtr
				>STYA ZPPtr1
				>PUSHEA.G SCRN.TitleBuf
				>PUSHW L.SCRN.Title
				>PUSHBI 0
				>SYSCALL sprintf
				lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Draw
				rts
*--------------------------------------
CS.END
*--------------------------------------
LIBTUI			.AZ "libtui"
hLIBTUI			.BS 1
*--------------------------------------
NETSTART		.AZ "${HOME}netstart"
HOSTNAME		.AZ "${ROOT}etc/hostname"
TCPIP.CONF		.AZ "${ROOT}etc/tcpip.conf"
NETWORK			.AZ	"${ROOT}etc/network"
NETWORKIP		.CZ "ipconfig\r"
NETWORKET		.CZ "etconfig\r"
*--------------------------------------
IP.Keywords		.PS "address"
				.PS "netmask"
				.PS "gateway"
				.PS "nameserver"
				.PS "dnsdomain"
				.DA #0
*--------------------------------------
SCRN.Title		.AZ " NetConfig"
SCRN.Status		.AZ " "
SCRN.StatusSv	.AZ " Settings saved successfully"
*--------------------------------------
HOST.Label		.AZ "Hostname:"
*Host.Text		.BS 16
*--------------------------------------
IFACE.Label		.AZ "Interface"
IFACE.List		.AZ "Uthernet"
				.AZ "LanCeGS"
				.AZ "Uthernet2"
				.AZ "Dan2Eth"
				.AZ "UdEth"
				.AZ "UdEth.D (DMA)"
				.DA 0
*--------------------------------------
AUTOIP.Label	.AZ "Auto or Manual IP"
AUTOIP.List		.AZ "Auto/DHCP"
				.AZ "Manual/Static"
				.DA 0
*--------------------------------------
PROTO.Label		.AZ "Protocol"
LIBTCPIP.Label	.AZ "TCP/IP"
LIBETALK.Label	.AZ "Ethertalk"
*--------------------------------------
SERV.Label		.AZ "Services"
TELNET.Label	.AZ "telnetd"
HTTPD.Label		.AZ	"httpd"
BBSD.Label		.AZ "bbsd"
*--------------------------------------
MANUAL.Label	.AZ "MANUAL IP SETTINGS"
IPADDR.Label	.AZ "address "
MASK.Label		.AZ "netmask "
GATEWAY.Label	.AZ "gateway "
NS1.Label		.AZ "nameserver "
NS2.Label		.AZ "nameserver 2"
DOM.Label		.AZ "dnsdomain "
*--------------------------------------
BUTS.Label		.AZ "(^S)ave..."
BUTQ.Label		.AZ "(^Q)uit"
DLGS.Title		.AZ "Save Config"
DLGS.Text		.AZ "Save the system config files?"
DLGS.Label		.AZ "Create NETSTART script in user home directory"
BUT.OK			.AZ " OK "
BUT.Cancel		.AZ "Cancel"
*--------------------------------------
EOL				.CZ "\r"
NS.Hdr			.CZ "#!/bin/sh\r" 
NS.Uth			.CZ "insdrv uthernet.drv 00:0E:3A:12:34:56\r" 
NS.Lanc			.CZ "insdrv lancegs.drv 00:0E:3A:12:34:56\r" 
NS.U2			.CZ "insdrv uthernet2.drv 00:08:DC:12:34:56\r"
NS.Dan2Eth		.CZ "insdrv dan2eth.drv 00:08:DC:12:34:56\r"
NS.Udeth		.CZ "insdrv udeth.drv 00:08:DC:12:34:56\r"
NS.Udeth.D 		.CZ "insdrv udeth.d.drv 00:08:DC:12:34:56\r"
NS.networkd		.CZ "NOHUP networkd "
NS.libtcpip		.CZ "libtcpip "
NS.libetalk		.CZ "libetalk "
NS.amper		.CZ "&\r" 
NS.telnetd		.CZ "NOHUP telnetd 6502 &\r" 
NS.httpd		.CZ "NOHUP httpd &\r" 
NS.bbsd			.CZ "NOHUP bbsd &\r" 
*Str.debug		.AZ "var = " 
IP.Hash			.AZ "#"
HOST.Hdr		.CZ "# Put hostname here (max 15 characters)\r"
*--------------------------------------
				.DUMMY
				.OR 0
DS.START
IFACE.Var		.BS 2
AUTOIP.Var		.BS 2
LIBTCPIP.Var	.BS 1
LIBETALK.Var	.BS 1
TELNET.Var		.BS 1
HTTPD.Var		.BS 1
BBSD.Var		.BS 1
DLGS.Var		.BS 1

HOST.Buf		.BS 16
IPADDR.Buf		.BS 16
MASK.Buf		.BS 16
GATEWAY.Buf		.BS 16
NS1.Buf			.BS 16
NS2.Buf			.BS 16

DOM.Buf			.BS 32

SCRN.TitleBuf	.BS 81

DS.END			.ED
*--------------------------------------
MAN
SAVE usr/src/bin/netconfig.s
ASM
