home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / mlpmodul.sit / MacLogimoPlus Documentation / DEF3 Files / MacBase2.DEF < prev    next >
Encoding:
Modula Definition  |  1990-06-14  |  4.2 KB  |  112 lines  |  [TEXT/PMED]

  1. DEFINITION MODULE MacBase2; (* P. Fink,ETHZ, 13.08.85 *)
  2.                            (* last modified 13.08.85  *)
  3.  
  4. (* This module MacBase2 contains the 'glue' necessary to write user procedures
  5.    in Modula-2 which can be passed safely to ToolBox routines, e.g. as
  6.    filterprocedures, dialoghooks etc..
  7.    Such procedures can be written in Modula-2 only when obeying special rules,
  8.    using the procedures and magic constants defined here, since it wouldn't work
  9.    the naive way.
  10.  
  11.    This .DEF contains the definitions, the rules and 2 examples.
  12.  
  13.  *)
  14.  
  15.  FROM SYSTEM IMPORT ADDRESS;
  16.  
  17.  EXPORT QUALIFIED
  18.    (* glue procedures: *)
  19.    EnterModula, ExitModula,
  20.  
  21.    (* magic constants for user procedures: *)
  22.    TrackIndexProc, TrackPartProc, DialogFilterProc, UserItemProc,
  23.    SoundProc, SFDlgHookProc, SFFileFilterProc, IOCompletionProc, GrowZoneProc,
  24.    PureProc, CharacterProc, BooleanProc, IntegerProc, LongIntProc,
  25.    ProcPtr,
  26.  
  27.    (* internal variables: *)
  28.    BaseStack, BaseLim, ModA5Reg;
  29.  
  30. CONST (*constants for the function kind of user procedures:*)
  31.      PureProc=0; CharacterProc=4000h; BooleanProc=2000h; IntegerProc=4000h;
  32.      LongIntProc=8000h;
  33.  
  34. CONST (*predefined constants for the common user procedures:*)
  35.     TrackIndexProc        =0;                       (*in ControlMgr*)
  36.     TrackPartProc         =6;
  37.     DialogFilterProc      =12+BooleanProc;          (*in DialogMgr*)
  38.     UserItemProc          =6;
  39.     SoundProc             =2;
  40.     SFFileFilterProc      =4+BooleanProc;           (*in SFPackage*)
  41.     SFDlgHookProc         =6+IntegerProc;
  42.     IOCompletionProc      =0;                       (*in pbfile, DeviceMgr*)
  43.     GrowZoneProc          =4+LongIntProc;           (*in MemoryMgr*)
  44.  
  45. TYPE ProcPtr = ADDRESS;                             (*for passing procedures
  46.                                                       as arguments*)
  47.  
  48. (* glue procedures: *)
  49. PROCEDURE EnterModula (procId: CARDINAL);
  50. PROCEDURE ExitModula  (functionValue: ADDRESS);
  51.  
  52. (*internal data: *)
  53. VAR
  54.     BaseStack, BaseLim : POINTER TO ADDRESS;
  55.     ModA5Reg           : ADDRESS;
  56.  
  57.  
  58. (*==============================================================================
  59.  Rules:
  60.  1. use (*$S-*) before your user procedure. this is strictly necessary.
  61.     (it is not necessary in additional procedures which are called by your procedure)
  62.  2. as the very first statement after BEGIN, use "EnterModula(procId)" where
  63.     "procId" is one of the predefined constants corresponds to the user procedure.
  64.  3. when you are done, use "ExitModula(ADDRESS(value))".
  65.     This leaves the user procedure, returns back to the Toolbox, and
  66.     passes "value" as the procedure result (if it is a function).
  67.     value is irrelevant for simple procedures (specify 0).
  68.     ExitModula may be called at any point in your program, even in loops etc. .
  69.  4. use (*$S=*) after your procedure (this is not strictly required).
  70.  5. use "ProcPtr(myProc)" to pass the procedure in the argument list.
  71.  6. "procId" in "EnterModula" is a coding of the procedure usage, which contains
  72.     the length of its parameter list in bytes, and bits indicating the
  73.     function kind.
  74.     for the important cases, constants are predefined.
  75. ==============================================================================
  76.  Example for a pure procedure (see page CM-19/20):
  77.  
  78.     (*$S- turn off stack test *)
  79.     PROCEDURE myAction (theControl: ControlHandle; partCode: INTEGER);
  80.        {.......}
  81.     BEGIN
  82.        EnterModula(TrackPartProc);       (* setup Modula-2 environment *)
  83.        {.......}
  84.        ExitModula(0);                    (* return to the ToolBox *)
  85.     END myAction;
  86.       (*$S= restore stack overflow test *)
  87.  
  88.     {.....}
  89.     TrackControl(theControl, where, ProcPtr(myAction) );
  90.  
  91. ================================================================================
  92.    Example for a function (see page DL-23/24):
  93.  
  94.  
  95.     (*$S- turn off stack test *)
  96.     PROCEDURE myFilter (theDialog: DialogPtr; VAR theEvent: EventRecord;
  97.       VAR itemHit: INTEGER) : BOOLEAN;
  98.        {.....}
  99.     BEGIN
  100.        EnterModula (DialogFilterProc);
  101.        {.......}
  102.        ExitModula(ADDRESS(TRUE))
  103.     END myFilter;
  104.    (*$S= restore stack overflow test *)
  105.  
  106.    {........}
  107.    ModalDialog(ProcPtr(myFilter),itemHit);
  108.  
  109. *)
  110.  
  111. END MacBase2.
  112.