home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Exec_Library / Tasks / trap_c.c < prev   
C/C++ Source or Header  |  1992-09-03  |  3KB  |  75 lines

  1. ;/* trap_c.c - Execute me to compile me with SAS C 5.10
  2. LC -b0 -cfistq -v -y -j73 trap_c.c
  3. Blink FROM LIB:c.o,trap_c.o,trap_a.o TO trap LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit ;
  5.  
  6. trap_c.c - C module of sample integer divide-by-zero trap
  7.  
  8.  
  9. Copyright (c) 1992 Commodore-Amiga, Inc.
  10.  
  11. This example is provided in electronic form by Commodore-Amiga, Inc. for
  12. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  13. published by Addison-Wesley (ISBN 0-201-56774-1).
  14.  
  15. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  16. information on the correct usage of the techniques and operating system
  17. functions presented in these examples.  The source and executable code
  18. of these examples may only be distributed in free electronic form, via
  19. bulletin board or as part of a fully non-commercial and freely
  20. redistributable diskette.  Both the source and executable code (including
  21. comments) must be included, without modification, in any copy.  This
  22. example may not be published in printed form or distributed with any
  23. commercial product.  However, the programming techniques and support
  24. routines set forth in these examples may be used in the development
  25. of original executable software products for Commodore Amiga computers.
  26.  
  27. All other rights reserved.
  28.  
  29. This example is provided "as-is" and is subject to change; no
  30. warranties are made.  All use is at your own risk. No liability or
  31. responsibility is assumed.
  32. */
  33.  
  34. #include <exec/types.h>
  35. #include <exec/tasks.h>
  36. #include <clib/exec_protos.h>
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39.  
  40. #ifdef LATTICE
  41. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  42. int chkabort(void) {return(0); }
  43. #endif
  44.  
  45. extern ULONG trapa();           /* assembler trap code in trap_a.asm */
  46.  
  47. APTR oldTrapCode;
  48. ULONG countdiv0;
  49.  
  50. void main(int argc, char **argv)
  51. {
  52.     struct Task *thistask;
  53.     ULONG k,j;
  54.  
  55.     thistask = FindTask(NULL);
  56.  
  57.     /* Save our task's current trap code pointer */
  58.     oldTrapCode = thistask->tc_TrapCode;
  59.  
  60.     /* Point task to our assembler trap handler code.  Ours will just count */
  61.     /* divide-by-zero traps, and pass other traps on to the normal TrapCode */
  62.     thistask->tc_TrapCode = (APTR)trapa;
  63.  
  64.     countdiv0 = 0L;
  65.  
  66.     for(k=0; k<4; k++)            /* Let's divide by zero a few times */
  67.        {
  68.        printf("dividing %ld by zero... ",k);
  69.        j = k/0L;
  70.        printf("did it\n");
  71.        }
  72.     printf("\nDivide by zero happened %ld times\n",countdiv0);
  73.  
  74.     thistask->tc_TrapCode = oldTrapCode;     /* Restore old trap code */
  75. }