home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / exec / tasks / trap / trap_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  2.5 KB  |  79 lines

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