home *** CD-ROM | disk | FTP | other *** search
Modula Definition | 1990-06-14 | 4.2 KB | 112 lines | [TEXT/PMED] |
- DEFINITION MODULE MacBase2; (* P. Fink,ETHZ, 13.08.85 *)
- (* last modified 13.08.85 *)
-
- (* This module MacBase2 contains the 'glue' necessary to write user procedures
- in Modula-2 which can be passed safely to ToolBox routines, e.g. as
- filterprocedures, dialoghooks etc..
- Such procedures can be written in Modula-2 only when obeying special rules,
- using the procedures and magic constants defined here, since it wouldn't work
- the naive way.
-
- This .DEF contains the definitions, the rules and 2 examples.
-
- *)
-
- FROM SYSTEM IMPORT ADDRESS;
-
- EXPORT QUALIFIED
- (* glue procedures: *)
- EnterModula, ExitModula,
-
- (* magic constants for user procedures: *)
- TrackIndexProc, TrackPartProc, DialogFilterProc, UserItemProc,
- SoundProc, SFDlgHookProc, SFFileFilterProc, IOCompletionProc, GrowZoneProc,
- PureProc, CharacterProc, BooleanProc, IntegerProc, LongIntProc,
- ProcPtr,
-
- (* internal variables: *)
- BaseStack, BaseLim, ModA5Reg;
-
- CONST (*constants for the function kind of user procedures:*)
- PureProc=0; CharacterProc=4000h; BooleanProc=2000h; IntegerProc=4000h;
- LongIntProc=8000h;
-
- CONST (*predefined constants for the common user procedures:*)
- TrackIndexProc =0; (*in ControlMgr*)
- TrackPartProc =6;
- DialogFilterProc =12+BooleanProc; (*in DialogMgr*)
- UserItemProc =6;
- SoundProc =2;
- SFFileFilterProc =4+BooleanProc; (*in SFPackage*)
- SFDlgHookProc =6+IntegerProc;
- IOCompletionProc =0; (*in pbfile, DeviceMgr*)
- GrowZoneProc =4+LongIntProc; (*in MemoryMgr*)
-
- TYPE ProcPtr = ADDRESS; (*for passing procedures
- as arguments*)
-
- (* glue procedures: *)
- PROCEDURE EnterModula (procId: CARDINAL);
- PROCEDURE ExitModula (functionValue: ADDRESS);
-
- (*internal data: *)
- VAR
- BaseStack, BaseLim : POINTER TO ADDRESS;
- ModA5Reg : ADDRESS;
-
-
- (*==============================================================================
- Rules:
- 1. use (*$S-*) before your user procedure. this is strictly necessary.
- (it is not necessary in additional procedures which are called by your procedure)
- 2. as the very first statement after BEGIN, use "EnterModula(procId)" where
- "procId" is one of the predefined constants corresponds to the user procedure.
- 3. when you are done, use "ExitModula(ADDRESS(value))".
- This leaves the user procedure, returns back to the Toolbox, and
- passes "value" as the procedure result (if it is a function).
- value is irrelevant for simple procedures (specify 0).
- ExitModula may be called at any point in your program, even in loops etc. .
- 4. use (*$S=*) after your procedure (this is not strictly required).
- 5. use "ProcPtr(myProc)" to pass the procedure in the argument list.
- 6. "procId" in "EnterModula" is a coding of the procedure usage, which contains
- the length of its parameter list in bytes, and bits indicating the
- function kind.
- for the important cases, constants are predefined.
- ==============================================================================
- Example for a pure procedure (see page CM-19/20):
-
- (*$S- turn off stack test *)
- PROCEDURE myAction (theControl: ControlHandle; partCode: INTEGER);
- {.......}
- BEGIN
- EnterModula(TrackPartProc); (* setup Modula-2 environment *)
- {.......}
- ExitModula(0); (* return to the ToolBox *)
- END myAction;
- (*$S= restore stack overflow test *)
-
- {.....}
- TrackControl(theControl, where, ProcPtr(myAction) );
-
- ================================================================================
- Example for a function (see page DL-23/24):
-
-
- (*$S- turn off stack test *)
- PROCEDURE myFilter (theDialog: DialogPtr; VAR theEvent: EventRecord;
- VAR itemHit: INTEGER) : BOOLEAN;
- {.....}
- BEGIN
- EnterModula (DialogFilterProc);
- {.......}
- ExitModula(ADDRESS(TRUE))
- END myFilter;
- (*$S= restore stack overflow test *)
-
- {........}
- ModalDialog(ProcPtr(myFilter),itemHit);
-
- *)
-
- END MacBase2.
-