Article # 593, added by Geoworks, historical record
| first | previous | index | next | last |

Missing C-stub: GeodeForEach



C Routine:  GeodeForEach
Date Fixed: n/a

In the assembly code below is a callback routine called
GeodeEnumCallback, which GeodeForEach calls for each geode it
finds on the list. GeodeEnumCallback does the actual work of
GeodeForEach. You will want to change this to fit your specific
needs.

In your C source code, preferably in a header file, you will
need to add a routine prototype declaration for GeodeForEach and
typedef a structure GeodeEnumParams. The structure can be
used to pass parameters to GeodeEnumCallback. For example,
GEP_geodeHandle should contain a GeodeHandle. (Since you
want to enumerate thru the entire list, you should pass
NullHandle for this element of the structure.) The other
elements can be used as you need them. 


;---------------------begin genum.h-----------------------
void _pascal GeodeForEach( GeodeEnumParams * gep );

typedef struct {
    GeodeHandle GEP_geodeHanle;	/* geode from which to start.
				 * 0 if entire geodes list is
			  	 * to be traversed. */
    word GEP_callbackParamBP;
    word GEP_callbackParamDX;
    word GEP_callbackParamCX;
    word GEP_callbackParamAX;
} GeodeEnumParams;
;---------------------end genum.h-----------------------


;---------------------begin genum.asm-----------------------
include geos.def
include geoworks.def		; contains some GCN list stuff
include geode.def		; contains GeodeGetInfo structs
include Intneral/geodeStr.def	; contains GeodeType structs

global GEODEFOREACH:far		; allow c-stub to be used by externally

; This structure lets us pass register values between the C
; and the assembly routines
GeodeEnumParams	struct
	GEP_geodeHandle		word
        GEP_callbackParamBP	word
	GEP_callbackParamDX	word
        GEP_callbackParamCX	word
        GEP_callbackParamAX	word
GeodeEnumParams	ends


CommonCode	segment resource

SetGeosConvention

COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		GeodeEnumCallback
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PASS:		bx	= handle of geode to process
		ax, cx, dx, bp = data as passed to GeodeForEach
				 or returned from previous callback
		(for this example bx:si = app's optr)

RETURN:		if successful:
			carry set
		(for this example, carry is set by GCNList remove)

DESTROYED:	es, ds
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GeodeEnumCallback	proc	far
	uses	ax, bx, cx, dx, si, di, bp
	.enter

	;
	; Put your call-back code here.
	; You could even call a C function from here.
	; See the Knowledge Base for the article
	; "How to call a C function from assembly" by searching
	; on the keyword "assembly".
	;

	.leave
	ret
GeodeEnumCallback	endp


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		GeodeForEach
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C DECLARATION:	
extern void GeodeForEach(GeodeEnumParams *gep);

DESCRIPTION:
	GeodeForEach sets up the registers for GeodeForEach.
	GeodeForEach enumerates thru the list of launched
	geodes (applications, libraries, and drivers) and
	calls a callback routine for each geode if finds.

	The callback routine must be written in assembly.
	An example of the callback routine is included in
	the assembly module below. You should modify this
	callback routine to meet your specific needs.

PASS:	GeodeEnumParams structure

RETURNS:
	on failure (geode not found) GEP_geodeHandle = NullHandle
	on success GEP_geodeHandle = GeodeHandle of geode and other
		elements of GeodeEnumParams structure filled in.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GEODEFOREACH	proc	far	params:fptr

	uses si, di, ds, es
	.enter

	push	ds		; save real ds

	; load up registers
	lds	si, ss:params	; ds:si <- ptr to params

        mov	bx, ds:[si].GEP_geodeHandle
        mov	bp, ds:[si].GEP_callbackParamBP
        mov	dx, ds:[si].GEP_callbackParamDX
        mov	cx, ds:[si].GEP_callbackParamCX
        mov	ax, ds:[si].GEP_callbackParamAX

	push	si		; save ptr to params
	; di:si = virtual far ptr to callback routine
        mov	di, cs
	mov	si, offset GeodeEnumCallback

        call	GeodeForEach

        ; restor pointer to params and put results there
	pop	si		; ds:si <- ptr to params

        mov	ds:[si].GEP_geodeHandle, bx

	; if no geode found (bx==0), then don't waste time on rest
        tst	bx
        jz	done
        mov	ds:[si].GEP_callbackParamBP, bp
        mov	ds:[si].GEP_callbackParamDX, dx
        mov	ds:[si].GEP_callbackParamCX, cx
        mov	ds:[si].GEP_callbackParamAX, ax

done:
	pop	ds			;restore real DS

	.leave
	ret

GEODEFOREACH	endp


SetDefaultConvention

CommonCode	ends

;---------------------end genum.asm-----------------------