; 1st. February 1989 -- MFB

; ( serious bug corrected - would previously not shell out except
;   under specific memory conditions )

cseg	segment byte
	assume cs:cseg,ds:cseg,es:cseg

	org	100h

	asm	=	4	;dictionary entry flags
	const	=	10h
	immed	=	0
	head	=	0


	cr	=	0dh
	lf	=	0ah

start:
	call 	star
star:	pop	ax
	sub	ax,103h

	push	es
	push	ds
	push	cx	;4th pc
			;must change ds before we can store these
;	push	ax
	mov	cl,4
	shr	ax,cl	;ax contains new DS value
	mov	cx,ds
	add	cx,ax
	mov	ds,cx	;ds now ok for data access

;	pop	dx
;	and	dx,0fh	;dx contains new OFFSET value

	pop	cx	;original cx - do data access
	mov	cxsave,cx
	pop	cx	;original ds
	mov	dssave,cx
	pop	cx	;original es
	mov	essave,cx
	ret

fin:	mov	cx,cxsave
	mov	es,essave
	mov	ax,dssave
	mov	ds,ax
	lodsw
	jmp	ax		;now in INTRO.4TH

dos:	call	start

	mov	(stkseg),ss	;save ss
	mov	(stkptr),sp	;and sp

	mov	ax,(cs:2ch)
	mov	(parblk),ax
	MOV	(ONE),DS		;put segment
	MOV	(TWO),DS		;  addresses
	MOV	(THREE),DS	;    into cmdline and fcb

;	mov	ax,offset envir
;	mov	cl,4
;	shr	ax,cl
;	mov	cx,ds
;	add	cx,ax
;	mov	(parblk),cx

	mov	bx,DS
	mov	es,bx

	mov	dx,offset (pgname)
here:	mov	bx,offset (parblk)
	mov	al,0
	mov	ah,4bh
	int	21h
	mov	ss,(stkseg)
	mov	sp,(stkptr)

	jmp	fin

	dw	0		;back fence to hold count byte etc
				; of pglin
			
pgname	db	'\VED.COM',0  ;This "default" never takes effect --
                          ; see words EDIT and SYS in file DOSXTRA2

	db	10 dup (?)   ;space to patch in longer default name/path

parblk	dw	1234h ; strange non-initialised values for debugging
	dw	offset cmdline
ONE	dw	2345h 
	dw	offset	fcb1
TWO	dw	3456h
	dw	offset	fcb2
THREE	dw	4567h

stkseg	dw	5678h
stkptr	dw	6789h
cxsave	dw	789ah
dssave	dw	89abh
essave	dw	9abch

	dw	0		;back fence to hold count byte etc
				; of uslin
cmdline	db	6,'EDHELP',cr    ; 
	db	10 dup (?)

fcb1	db	0
	db	11 dup ('?')
	db	25 dup (0)

fcb2	db	0
	db	11 dup ('?')
	db	25 dup (0)

;	org	((110h) + ($-start)) - (($-start) mod 10h)

;envir	db	'PATH=',0
;	db	'COMSPEC=C:\COMMAND.COM',0
;	db	0

	db	'binload endproc '

	db 	f - e
e	db	'USLIN'
f	db	immed
	dw	cmdline


	db	d - c
c	db	'PGLIN'
d	db	immed
	dw	pgname

	db	b - a
a	db	'DOS'
b	db	immed
	dw	dos

	db	'endfile '

cseg	ends
	end	start


			