COMMENT @----------------------------------------------------------------------

	Copyright (c) GeoWorks 1989 -- All Rights Reserved

PROJECT:	PC GEOS
FILE:		resource.def

DECLARER:	Kernel, Geode/ and Process/

INTENDED USERS:	No restrictions

REQUIRES:
	-.def

DESCRIPTION:
	This file defines resource structures and routines.

	$Id: resource.def,v 1.1 97/04/04 14:23:47 newdeal Exp $

------------------------------------------------------------------------------@

SetDef	__RESOURCE

ifndef	_FXIP
	_FXIP	equ	FALSE
endif


;	Define a segment for the initialized variables.

idata	segment	word public 'DATA'
idata	ends

;	Define a segment for the uninitialized variables.

udata	segment word public 'BSS'
udata	ends

	dgroup	group	idata, udata
	assume	es:dgroup, ss:dgroup

;--------------------------------------------------------------

StartKernel

global GeodeDuplicateResource:far
global ProcCallModuleRoutine:far
global ProcGetLibraryEntry:far
global ProcCallFixedOrMovable:far

global GeodeGetResourceHandle:far
global GeodeGetGeodeResourceHandle:far
global GeodeGetDGroupDS:far
global GeodeGetDGroupES:far
global ThreadGetDGroupDS:far

global GEODELOADDGROUP:far
global PROCGETLIBRARYENTRY:far
global _ProcCallFixedOrMovable_cdecl:far
global PROCCALLFIXEDORMOVABLE_PASCAL:far
global GEODEDUPLICATERESOURCE:far
global GEODEGETOPTRNS:far
global GEODEGETGEODERESOURCEHANDLE:far

	; Data put on stack by ProcCallModuleRoutine

CallModData	type	3 dup(word)


COMMENT @----------------------------------------------------------------------

	CallMod	routine

	FUNCTION:
		Calls a routine in another code module
	ARGUMENTS:
		routine - name of routine to call. Must have been declared
				extrn.

------------------------------------------------------------------------------@
CallMod		macro	routine
    ifdef routine
        if segment routine eq @CurSeg
	    call	routine
	    exitm
    	endif
    endif
	.assert	type routine eq far, <CallMod to routine but routine not FAR>
	.assert	not (((.type routine) and 0x0801) eq 0x0801), <CallMod to routine but routine not callable>
	.assert	not (((.type routine) and 0x4001) eq 0x4001), <CallMod to routine but routine is a dynamic method handler>
	mov	ax, offset routine
	mov	bx, handle routine
	call	ProcCallModuleRoutine
endm

; like CallMod, but forces the CallMod even if the routine is in the current
; segment.
ForceCallMod		macro	routine
	.assert	type routine eq far, <CallMod to routine but routine not FAR>
	.assert	not (((.type routine) and 0x0801) eq 0x0801), <CallMod to routine but routine not callable>
	.assert	not (((.type routine) and 0x4000) eq 0x4001), <CallMod to routine but routine is a dynamic method handler>
	mov	ax, offset routine
	mov	bx, handle routine
	call	ProcCallModuleRoutine
endm

;-----

GotoMod		macro	routine
    ifdef routine
        if segment routine eq @CurSeg
	    GOTO	routine
	    exitm
	endif
    endif
	.assert type routine eq far, <GotoMod to routine but routine not FAR>
	.assert type @CurProc eq far, <GotoMod from near routine>
	.assert	not (((.type routine) and 0x0801) eq 0x0801), <GotoMod to routine but routine not callable>
	.assert	not (((.type routine) and 0x4001) eq 0x4001), <GotoMod to routine but routine is a dynamic method handler>
	.assert	not (((.type routine) and 0x0401) eq 0x0401), <GotoMod to routine that cannot be jumped to>
	mov	ax, offset routine
	mov	bx, handle routine
	GOTO	ProcCallModuleRoutine
endm

;------
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MACRO:		GetResourceHandleNS

PASS:		resource name, destination register

NOTES:		Optimized for use with register BX.
		This macro should ONLY be used by multi-launchable
		applications.  For single-launchable apps and
		libraries, use:

			mov	bx, handle <resource>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GetResourceHandleNS	macro	resource, reg
ifdif	<reg>,<bx>
	mov	reg, bx
endif
	mov	bx, resid resource
	call	GeodeGetResourceHandle
ifdif	<reg>,<bx>
	xchg	reg, bx
endif

endm

;------

GetResourceSegmentNS	macro	resource, segreg, opt
ifdif	<opt>,<TRASH_BX>
	push	bx
endif
	mov	bx, resid resource
	call	GeodeGetResourceHandle
ifidn	<segreg>,<ds>
	call	MemDerefDS
elseifidn <segreg>,<es>
	call	MemDerefES
else
ErrMessage <GetResourceSegmentNS argument must be ds or es>
endif
ifdif	<opt>,<TRASH_BX>
	pop	bx
endif

endm

;------

;	Macro for getting a resource segment when running on the UI thread.
;
;	pass:
;		ds - pointing at an lmem block owned by the process
;

GetOwnerResourceSegmentNS	macro	resource, segreg, opt
ifdif	<opt>,<TRASH_BX>
	push	bx
endif
	mov	bx, resid resource
	call	GeodeGetResourceHandleFromDS_BX
ifidn	<segreg>,<ds>
	call	MemDerefDS
elseifidn <segreg>,<es>
	call	MemDerefES
else
ErrMessage <GetResourceSegmentNS argument must be ds or es>
endif
ifdif	<opt>,<TRASH_BX>
	pop	bx
endif

endm


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		GetFarPointerNS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Get a valid far pointer to the label specified

PASS:		dest - memory or register pair for label fptr
		func - label to get far pointer of
		opt  - TRASH_BX if BX can be trashed
				not needed if bx is in dest reg
		       NO_VSEG if far pointer will never be used
				outside current code segment, and thus don't
				need to worry about vsegs in XIP'ed geodes
		       TRASH_BX_NO_VSEG if both conditions apply

PSEUDO CODE/STRATEGY:
		If we are to save BX, push and pop around macro

		Then, if 

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	TS	4/ 7/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GetFarPointerNS		macro	dest, func, opt
			local	drl, drh, regargs

_CheckDWordOneArg	<dest>
_ParseDWordArg		<dest>, drl, drh, regargs, <GetFarPointerNS>


if drl ne <bx> and drh ne <bx>
 if <opt> ne <TRASH_BX> and <opt> ne <TRASH_BX_NO_VSEG>

		push	bx

 endif
endif

if _FXIP and <opt> ne <NO_VSEG> and <opt> ne <TRASH_BX_NO_VSEG>

		GetResourceHandleNS	func
		GetVSeg	bx

else
 if segment <func> ne @CurSeg
		GetResourceSegmentNS	drh, func
 else
		mov	drh, cs
 endif

endif

if drl ne <bx> and drh ne <bx>
 if <opt> ne <TRASH_BX> and <opt> ne <TRASH_BX_NO_VSEG>

		push	bx

 endif
endif

		mov	drl, 	offset func
endm


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		GetFarPointer
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Get a valid far pointer to a label specified

PASS:		dest - memory or register pair for label fptr
		func - label to get far pointer of
		opt  - NO_VSEG if far pointer will never be used
				outside current code segment, and thus don't
				need to worry about vsegs in XIP'ed geodes

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	TS	4/ 7/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GetFarPointer		macro	dest, func, opt
			local	drl, drh, regargs

_CheckDWordOneArg	<dest>
_ParseDWordArg		<dest>, drl, drh, regargs, <GetFarPointerNS>

if _FXIP and <opt> ne <NO_VSEG>

		mov	drh, vseg func
else

 if segment func eq @CurSeg
		segmov	drh, cs

 else
		segmov	drh, segment func

 endif

endif

		mov	drl, 	offset func
endm


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		SEGMENT_CS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Evaluates to "cs" in non-xip systems and
		vseg of "cs" in XIP systems

PASS:		nothing

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	TS	4/ 8/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ifdef	_FXIP
if	_FXIP
	SEGMENT_CS	equ	<vseg @CurSeg>
else
	SEGMENT_CS	equ	<cs>
endif
else
	SEGMENT_CS	equ	<cs>
endif



COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		FXIP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Perform a FULL-XIP-specific instruction

PASS:		line	= line of code

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	TS	2/ 2/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
FXIP		macro	line
if _FXIP
		line
endif
		endm


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		NOFXIP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Perform a FULL-XIP-specific instruction

PASS:		line	= line of code

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	TS	2/ 2/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NOFXIP		macro	line
ife	_FXIP
		line
endif
		endm



EndKernel




