home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / IEEE / src / div0 / lattice / trapc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  936 b   |  60 lines

  1. #include <exec/types.h>
  2. #include <exec/tasks.h>
  3.  
  4. extern    void trapintercept();
  5.  
  6. #define NUM_OF_TRAPS 64
  7.  
  8. void (*localf[NUM_OF_TRAPS])() = {0};
  9.  
  10. struct Task *FindTask();
  11.  
  12. char intercepting=0;
  13. APTR oldtraphandler = 0;
  14. APTR oldtrapdata = 0;
  15.  
  16. void InterceptTrap(n,f)
  17. int n;
  18. void (*f)();
  19. {
  20.     if (intercepting == 0)
  21.     {
  22.         struct Task *t;
  23.         t = FindTask(0);
  24.         oldtraphandler = t->tc_TrapCode;
  25.         oldtrapdata = t->tc_TrapData;
  26.         t->tc_TrapCode = (APTR)(trapintercept);
  27.         /* we don't care about trap data */
  28.     }
  29.     localf[n] = f;
  30.     intercepting++;
  31. }
  32.  
  33. void UnwindTrap(n)
  34. int n;
  35. {
  36.     if (intercepting)
  37.     {
  38.         intercepting--;
  39.         if (intercepting == 0)
  40.         {    /* now remove interceptor */
  41.             struct Task *t = FindTask(0);
  42.             /* restore original trap handler */
  43.             t->tc_TrapData = oldtrapdata;
  44.             t->tc_TrapCode = oldtraphandler;
  45.         }
  46.         localf[n] = 0;
  47.     }
  48.     else
  49.     {
  50.         printf("bad Unwind call\n");
  51.         exit(-1);
  52.     }
  53. }
  54.  
  55. /* supervisor code */
  56. void localtrapintercept()
  57. {
  58. }
  59.  
  60.