home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Extension Shell 1.3 (Source) / Extension Shell #includes / StandaloneCode.h < prev   
Encoding:
C/C++ Source or Header  |  1994-04-06  |  2.1 KB  |  59 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         Standalone Code.h
  3.  
  4.     WRITTEN BY:
  5.         Eric Shapiro (from July 1993 BYTE article, and the supporting source code)
  6.                 
  7.     DESCRIPTION:
  8.         Misc. utilities for THINK C stand-alone 'CODE' resources.
  9.  
  10.     ___________________________________________________________________________
  11. */
  12. #ifndef __STANDALONECODE__
  13. #define __STANDALONECODE__
  14. //=============================================================================
  15. //        Defines                                                                 
  16. //-----------------------------------------------------------------------------
  17. // To be called from main() in an INIT resource that wants to lock itself in
  18. // memory and stay around after its resource file is closed.
  19. #define    LockSelf()            asm {                                                    \
  20.                                 lea            main, A0        ; &main into A0            \
  21.                                 dc.w        _RecoverHandle    ; get handle to self    \
  22.                                 move.l        A0, -(SP)        ; save handle to self    \
  23.                                 dc.w        _HLock            ; lock self             \
  24.                                 dc.w        _DetachResource    ; detach from rez fork    \
  25.                                 }
  26.  
  27.  
  28. // Saves the current value of A4 on the stack, and puts a copy of the address of main
  29. // into A4. Should be called at start of stand-alone code resource to access globals.
  30. #define GetGlobals()        asm {                                                     \
  31.                                 move.l         A4, -(SP)        ; save old A4            \
  32.                                 lea         main, A4         ; get globals            \
  33.                                 }
  34.  
  35.  
  36. // The converse of GetGlobals(). Restore the value of A4                        
  37. #define UngetGlobals()        asm {                                                    \
  38.                                 move.l         (SP)+, A4        ; restore A4 from stack    \
  39.                                 }
  40.  
  41.  
  42. // Save some registers, and retrieve access to our globals via A4. Remove your
  43. // paramaters from the stack into local registers before PatchGetGlobals()
  44. #define PatchGetGlobals()    asm {                                                     \
  45.                                 movem.l     A0-A5/D0-D7, -(SP)    ; save registers    \
  46.                                 lea         main, A4             ; get globals        \
  47.                                 }
  48.  
  49.  
  50. // The converse of PatchGetGlobals. If your return value is held in a global,
  51. // make sure you copy it into a local variable before calling this macro - when
  52. // A4 has been restored, your globals are now longer accessible.
  53. #define PatchUngetGlobals()    asm {                                                    \
  54.                                 movem.l     (SP)+, A0-A5/D0-D7    ; restore registers    \
  55.                                 }
  56.  
  57.  
  58. #endif
  59.