home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / MAGAZINE / DDJ9309.ZIP / FPALIB.ZIP / IMLIB.H < prev    next >
C/C++ Source or Header  |  1993-05-12  |  3KB  |  90 lines

  1. /* Extended Integer Arithmetic Library
  2. **
  3. ** Version 1.1
  4. ** Copyright (C) 1990, by Fred Motteler
  5. ** All Rights Reserved
  6. **
  7. ** This is a simple extended integer arithmetic package.
  8. **
  9. ** This version should be K&R, ANSI, and C++ compatible.
  10. **
  11. ** Format:
  12. **
  13. **     byte 0    byte 1    byte 2    ...    byte N
  14. **    ms byte ...    ...    ...    ls byte
  15. **
  16. ** Each routine returns a condition code value:
  17. **
  18. **    0 0 0 0 Z V S C
  19. **    Where Z = result zero if 1
  20. **          V = overflow if 1
  21. **          S = result negative if 1 (if ms bit of result is 1)
  22. **          C = carry
  23. */
  24.  
  25. #define CARRY 1            /* Carry bit is ls bit */
  26. #define SIGN 2            /* Sign bit is next ls bit */
  27. #define OVERFLOW 4        /* Overflow bit is next bit */
  28. #define ZERO 8            /* Zero bit is the next bit */
  29. #define NSIGN 0x80        /* Sign bit mask */
  30.  
  31. /* Pre-declarations for all functions */
  32. #ifdef PROTOTYPES
  33. unsigned char itestm(unsigned char *valuePB, unsigned char condcodeB,
  34.              int nbyteN, int signoneN, int signtwoN);
  35. unsigned char iaddm(unsigned char *sumPB, unsigned char *termPB, int nbyteN);
  36. unsigned char isubm(unsigned char *sumPB, unsigned char *termPB, int nbyteN);
  37. int ucheckm(unsigned char *termPB, int nbyteN);
  38. int ucmpm(unsigned char *firstPB, unsigned char *secondPB, int nbyteN);
  39. void ushftlm(unsigned char *termPB, int nbyteN);
  40. void ushftrm(unsigned char *termPB, int nbyteN);
  41. unsigned char umultm(unsigned char *prodPB, unsigned char *termPB, int nbyteN);
  42. void inegm(unsigned char *valuePB, int nbyteN);
  43. unsigned char smultm(unsigned char *prodPB, unsigned char *termPB, int nbyteN);
  44. unsigned char udivm(unsigned char *dividPB, unsigned char *termPB, int nbyteN);
  45. unsigned char sdivm(unsigned char *dividPB, unsigned char *termPB, int nbyteN);
  46. #else
  47. extern unsigned char iaddm(), isubm(), umultm(), smultm();
  48. extern void ushftlm(), ushftrm(), inegm();
  49. extern unsigned char udivm(), sdivm(), itestm();
  50. extern int ucheckm(), ucmpm();
  51. #endif
  52.  
  53. /* Some compilers may not support "stdlib.h" */
  54. #ifdef MWC
  55. extern char *malloc();
  56. extern char *calloc();
  57. extern void free();
  58. #endif
  59.  
  60. #ifdef MEMTEST
  61. /* Memory allocation / free test functions */
  62.  
  63. #ifdef PROTOTYPES
  64. void fmallinit(void);
  65. int fmallreport(void);
  66. unsigned char *fmalloc(unsigned int sizeN, char *func_nameBP);
  67. unsigned char *fcalloc(unsigned int sizeN, unsigned int objectN, char *func_nameBP);
  68. void ffree(unsigned char *pntrBP);
  69. #else
  70. void fmallinit();        /* Initialize memory allocation table */
  71. int fmallreport();        /* Report on memory allocated */
  72. unsigned char *fmalloc();    /* Allocate block of memory */
  73. unsigned char *fcalloc();    /* Allocate zeroed block of memory */
  74. void ffree();            /* Free memory */
  75. #endif
  76.  
  77. /* Memory allocation /free test macros.
  78. ** Use these macro in place of malloc(), calloc(), and free() to allow
  79. ** error reporting of allocated memory that has not been free'd. */
  80. #define FMALLOC(a,b) fmalloc((a),(b))
  81. #define FCALLOC(a,b,c) fcalloc((a),(b),(c))
  82. #define FFREE(a) ffree((a))
  83.  
  84. #else
  85. /* Macros that default standard memory allocation scheme. */
  86. #define FMALLOC(a,b) malloc((a))
  87. #define FCALLOC(a,b,c) calloc((a),(b))
  88. #define FFREE(a) free((a))
  89. #endif
  90.