;****************************************************************************
;***									  ***
;*** DLL16A.ASM - windows 32-bit dll					  ***
;***									  ***
;*** By:  Craig Eisler							  ***
;***	  March 17 1991 ... initial implementation			  ***
;***									  ***
;****************************************************************************
.386p

 DGROUP group _NULL,_DATA,DATA,_emu_init_start,_emu_init,_emu_init_end,_BSS

public	pLocalHeap
public	pAtomTable
public	pStackTop
public	pStackMin
public	pStackBot

pLocalHeap	equ	0006H
pAtomTable	equ	0008H
pStackTop	equ	000AH
pStackMin	equ	000CH
pStackBot	equ	000EH


	DOSSEG
memS	equ	1

	.xlist
	include cmacros.inc
	include windows.inc
	.list

FAR_DATA segment byte public 'FAR_DATA' use16
FAR_DATA ends

_BSS	      segment word public 'BSS' use16
_BSS	      ends

DATA	segment word public 'DATA' use16
DATA	ends
_emu_init_start segment word public 'EMU' use16
__emu_init_start label word
_emu_init_start ends

_emu_init segment byte public 'EMU' use16
_emu_init ends

_emu_init_end segment word public 'EMU' use16
__emu_init_end label word
_emu_init_end ends

_NULL	segment para public 'BEGDATA' use16
__nullarea label word
	   dw	0,0
	   dw	5
	   dw	0		; pLocalHeap
	   dw	0		; pAtomTable
__STACKLOW dw	0		; pStackTop: lowest address in stack
__STACKTOP dw	0		; pStackMin:
	   dw	0		; pStackBot: highest address in stack
	public	__nullarea
_NULL	ends

_DATA segment word public 'DATA' use16
;*
;*** externals we need
;*
assume es:nothing
assume ss:nothing
assume ds:dgroup
assume cs:_TEXT

__aaltstkovr dw -1		; alternate stack overflow routine address
__dynend   dw 0 		; top of dynamic data area
__curbrk   dw 0 		; top of usable memory
__psp	   dw 0 		; segment addr of program segment prefix
__osmajor  db 0 		; major DOS version number
__osminor  db 0 		; minor DOS version number
__child    dw 0 		; non-zero => a spawned process is running
__no87	   dw 0 		; always try to use the 8087
__HShift   db 0 		; Huge Shift value
	   db 0 		; slack byte

	public	__dynend
	public	__curbrk
	public	__psp
	public	__osmajor
	public	__osminor
	public	__STACKLOW
	public	__STACKTOP
	public	__child
	public	__no87
	public	__HShift

_DATA ends

externFP <LocalInit>		 ; Windows heap init routine

;*
;*** the windows extender code lies here
;*
_TEXT segment word public 'CODE' use16

public		_small_code_
_small_code_	equ 0

;****************************************************************************
;***									  ***
;*** LibEntry - 16-bit library entry point				  ***
;***									  ***
;****************************************************************************
externNP <LibMain>		 ; startup code
cProc	LibEntry, <PUBLIC,FAR>	 ; entry point into DLL

cBegin
	push	di		 ; handle of the module instance
	push	ds		 ; library data segment
	push	cx		 ; heap size
	push	es		 ; command line segment
	push	si		 ; command line offset
	jcxz	callc		 ; skip heap init
	xor	ax,ax
	cCall	LocalInit <ds, ax, cx>
	or	ax,ax		 ; did it do it ok ?
	jz	error		 ; quit if it failed

callc:
	call	LibMain 	 ; invoke the 'C' routine (result in AX)
	jmp short exit		 ; LibMain is responsible for stack clean up

error:

	pop	si		 ; clean up stack on a LocalInit error
	pop	es
	pop	cx
	pop	ds
	pop	di
	jmp	short exit
__exit_with_msg_:
	mov	ah,04cH 		; DOS call to exit with return code
	int	021h			; back to DOS

	public	__exit_with_msg_
exit:

cEnd

	assume ds:nothing
_TEXT ends
	end LibEntry
