1 ; This file is unchanged from the MANX software systems version
2 ; it is included here only to insure that it gets loaded into data
3 ; space first (so that we can avoid destroying the memory variables)
4 ; :ts=8
5 codeseg	segment	para public 'code'
6 	public	$MEMRY
7 	public	_mbot_, sbot, _lowmem_
8 dataseg	segment	para public 'data'
9 $MEMRY	dw	-1
10 	public	errno_
11 errno_	dw	0
12 	public	_dsval_,_csval_
13 _dsval_	dw	0
14 _csval_	dw	0
15 _mbot_	dw	0
16 sbot	dw	0
17 _lowmem_:
18 	extrn	_Uorg_:byte,_Uend_:byte
19 dataseg	ends
20 	public	exitad, exitcs
21 exitad	dw	0
22 exitcs	dw	0
23 
24 	assume	cs:codeseg,ds:dataseg,es:dataseg,ss:dataseg
25 	extrn Croot_:near
26 	public	$begin
27 	public	_exit_
28 $begin	proc	far
29 	mov	bp,dataseg
30 	test	bp,bp
31 	jnz	notcom
32 	mov	bp,ds
33 notcom:
34 	mov	exitcs,ds
35 	mov	bx,[2]	;get top segment
36 	sub	bx,bp		;compute size of Data seg
37 	cmp	bx,4096		;check if greater than 64K
38 	jbe	smallseg
39 	lea	bx,[bp+4096]	;end address of segment (paragraphs)
40 	mov	ax,es
41 	sub	bx,ax		;compute length of segment
42 	mov	ah,4aH		;SETBLOCK system call
43 	int	21H
44 	mov	bx,4096
45 smallseg:
46 	mov	es,bp
47 	mov	cl,4
48 	shl	bx,cl
49 	cli
50 	mov	ss,bp
51 	mov	sp,bx
52 	sti
53 	cld
54 ;		clear uninitialized data
55 	mov	di,offset _Uorg_
56 	mov	cx,offset _Uend_
57 	sub	cx,di
58 	inc	cx
59 	shr	cx,1
60 	jcxz	noclear
61 	sub	ax,ax
62 rep	stosw
63 noclear:
64 ;
65 	mov	es,[2cH]		;get enviroment segment
66 	sub	di,di
67 	mov	cx,7fffH
68 arglook:
69 	mov	ah,es:byte ptr [di]
70 	cmp	ah,'='			;look for null named env. string
71 	je	found_args
72 	test	ah,ah
73 	jz	no_args
74 repne	scasb				;look for null byte
75 	jz	arglook
76 no_args:
77 	mov	cl,[80H]
78 	sub	ch,ch
79 	mov	si,81H
80 	mov	ax,1
81 	jmp	short mov_args
82 ;
83 found_args:
84 	sub	ax,ax
85 	stosb			;zap and skip over '='
86 	mov	si,di
87 	mov	di,es
88 	mov	ds,di
89 mov_args:
90 	push	ax			;first arg # for Croot
91 	mov	es,bp			;reload ES with our real dataseg
92 	mov	di,es:$MEMRY
93 	push	di			;argp for Croot
94 	jcxz	cpy_done
95 cpy_args:				;copy argument string to work buffer
96 	lodsb
97 	test	al,al
98 	jz	cpy_done
99 	stosb
100 	loop	cpy_args
101 cpy_done:
102 	sub	al,al
103 	stosb			;null terminate string
104 	mov	ds,bp			;set DS, now DS, SS, ES are equal
105 	inc	di
106 	and	di,0fffeH		;adjust to word boundary
107 	mov	$MEMRY,di	;save memory allocation info for sbrk()
108 	mov	_mbot_,di
109 	mov	ax,sp
110 	sub	ax,2048		;allow 3Kb of stack space
111 	mov	sbot,ax
112 	mov	_dsval_,ds
113 	mov	_csval_,cs
114 	call	Croot_		;Croot(argp, first)
115 	jmp	short exit
116 _exit_:
117 	pop	ax
118 	pop	ax		;fetch return code
119 exit:
120 	mov	ah,4cH
121 	int	21H
122 	jmp	dword ptr exitad
123 $begin	endp
124 codeseg	ends
125 	end	$begin
126 