home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Inc&AD2.1 / includes / utility / hooks.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-11  |  2.2 KB  |  89 lines

  1. #ifndef UTILITY_HOOKS_H
  2. #define UTILITY_HOOKS_H TRUE
  3. /*
  4. **    $VER: hooks.h 36.1 (12.07.90)
  5. **    Includes Release 38.56
  6. **
  7. **    callback hooks
  8. **
  9. **    (C) Copyright 1989-1992 Commodore-Amiga Inc.
  10. **        All Rights Reserved
  11. */
  12.  
  13. #ifndef EXEC_TYPES_H
  14. #include "exec/types.h"
  15. #endif
  16.  
  17. #ifndef EXEC_NODES_H
  18. #include "exec/nodes.h"
  19. #endif
  20.  
  21. /* new standard hook structure */
  22. struct Hook    {
  23.     struct MinNode    h_MinNode;
  24.     ULONG        (*h_Entry)();    /* assembler entry point    */
  25.     ULONG        (*h_SubEntry)();/* often HLL entry point    */
  26.     VOID        *h_Data;    /* owner specific        */
  27. };
  28.  
  29. /*
  30.  * Hook calling conventions:
  31.  *    A0 - pointer to hook data structure itself
  32.  *    A1 - pointer to parameter structure ("message") typically
  33.  *         beginning with a longword command code, which makes
  34.  *         sense in the context in which the hook is being used.
  35.  *    A2 - Hook specific address data ("object," e.g, GadgetInfo)
  36.  *
  37.  * Control will be passed to the routine h_Entry.  For many
  38.  * High-Level Languages (HLL), this will be an assembly language
  39.  * stub which pushes registers on the stack, does other setup,
  40.  * and then calls the function at h_SubEntry.
  41.  *
  42.  * The C standard receiving code is:
  43.  * CDispatcher( hook, object, message )
  44.  *     struct Hook    *hook;
  45.  *     APTR        object;
  46.  *     APTR        message;
  47.  *
  48.  * NOTE that register natural order differs from this convention
  49.  * for C parameter order, which is A0,A2,A1.
  50.  *
  51.  * The assembly language stub for "vanilla" C parameter conventions
  52.  * could be:
  53.  
  54.  _hookEntry:
  55.     move.l    a1,-(sp)        ; push message packet pointer
  56.     move.l    a2,-(sp)        ; push object pointer
  57.     move.l    a0,-(sp)        ; push hook pointer
  58.     move.l    h_SubEntry(a0),a0    ; fetch C entry point ...
  59.     jsr    (a0)            ; ... and call it
  60.     lea    12(sp),sp        ; fix stack
  61.     rts
  62.  
  63.  * with this function as your interface stub, you can write
  64.  * a Hook setup function as:
  65.  
  66.  SetupHook( hook, c_function, userdata )
  67.  struct Hook    *hook;
  68.  ULONG        (*c_function)();
  69.  VOID        *userdata;
  70.  {
  71.     ULONG    (*hookEntry)();
  72.  
  73.     hook->h_Entry =        hookEntry;
  74.     hook->h_SubEntry =    c_function;
  75.     hook->h_Data =            userdata;
  76.  }
  77.  
  78.  * with Lattice C pragmas, you can put the C function in the
  79.  * h_Entry field directly if you declare the function:
  80.  
  81. ULONG __saveds __asm
  82. CDispatcher(    register __a0 struct Hook    *hook,
  83.         register __a2 VOID        *object,
  84.         register __a1 ULONG        *message );
  85.  *
  86.  ****/
  87.  
  88. #endif
  89.