home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / System / Swatch / Development / swatch 1.2 / swatch INIT / post init error / init.error.CODE.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-12  |  2.2 KB  |  98 lines  |  [TEXT/KAHL]

  1. /**
  2.  
  3.     init.error.CODE.c
  4.     Copyright (c) 1990, joe holt
  5.  
  6.  **/
  7.  
  8.  
  9. /**
  10.  
  11.     Compile this code in a separate project.  Set the project type to
  12.     Code Resource, type 'RESP' ID 128.  Once compiled, you can build it
  13.     and merge it into your INIT's resource file ("...project.rsrc") or
  14.     build it into a separate file and use ResEdit to copy it in.  This
  15.     code is independent of the INIT, so it can be used as is for any
  16.     INIT you write.
  17.  
  18.  **/
  19.  
  20.  
  21. /**
  22.  
  23.     ToolScratch is an 8-byte area of low memory used by the Mac toolbox
  24.     and other people as a temporary holding place.
  25.  
  26.  **/
  27.  
  28. extern long        ToolScratch : 0x09CE;
  29.  
  30.  
  31. /**************************************************************************
  32.  ***
  33.  *** void main ( QElemPtr nmReqPtr );
  34.  ***
  35.  *** This is the code resource type 'RESP' which you need to compile
  36.  *** separately and include among your INIT's resources.
  37.  ***
  38.  *** This code is called when the user closes the Notification Manager's
  39.  *** note dialog.  The NM passes to us the address of the NM record which
  40.  *** was set up by StartupError().  We use this to clean up and leave.
  41.  ***
  42.  *** This is written is assembly for size.  If you have problems with
  43.  *** assembly, I s'pose it could be written in C, but the trick at the
  44.  *** end would be hard to duplicate...
  45.  ***
  46.  *** History:
  47.  ***   jhh 18 jun 90 -- response to news posting
  48.  ***
  49.  ***/
  50.  
  51. pascal void
  52. main( QElemPtr nmReqPtr )
  53. {
  54.     asm {
  55.  
  56. /**
  57.  
  58.     First remove the note from the Notification Manager's notification
  59.     queue.
  60.  
  61.  **/
  62.  
  63.             move.l        nmReqPtr, A0
  64.             _NMRemove
  65.  
  66. /**
  67.  
  68.     Grab the string's address from the NM rec and dispose of it.  Then
  69.     get rid of the NM rec itself.
  70.  
  71.  **/
  72.  
  73.             move.l        nmReqPtr, A0
  74.             move.l        OFFSET(NMRec,nmStr)(A0), A0
  75.             _DisposPtr
  76.             move.l        nmReqPtr, A0
  77.             _DisposPtr
  78.  
  79. /**
  80.  
  81.     Now the tricky part.  This code lives within a small block in the
  82.     System Heap which we want to get rid of.  But it's not safe to
  83.     dispose of the very block you're calling from!  So, we create a
  84.     little bit of code in ToolScratch which does the dispose for us
  85.     and execute it last.
  86.  
  87.  **/
  88.  
  89.             move.l        4(A7), A1
  90.             move.l        #ToolScratch, A0
  91.             move.l        A0, 4(A7)
  92.             move.l        #0x2040A01F, (A0)    ; movea.l D0, A0  /   _DisposPtr
  93.             move.w        #0x4ED1, 4(A0)        ; jmp (A1)
  94.             lea            main, A0
  95.             move.l        A0, D0                ; Pascal clobbers A0 when returning
  96.     }
  97. }
  98.