home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff269.lzh / PropGadget / prop.inc < prev    next >
Text File  |  1989-11-06  |  3KB  |  80 lines

  1. /*  It greater the obstacle, the more glory in overcoming it.  Moliere   */
  2.  
  3. /*          Jerry J. Trantow                                             */
  4. /*          1560 A East Irving Place                                     */
  5. /*          Milwaukee, Wi 53202-1460                                     */
  6.  
  7. /* 30 Nov 88 JJT started program to give correct values for proportional */
  8. /*           Gadget always using the best resolution \w floating point   */
  9. /*  1 Dec 88 Added test for (body==total) instead of /(total+1L)         */
  10. /*  4 Dec 88 Renamed file to Prop.inc                                    */
  11. /* 17 Dec 88 Should be able to use Conditional Operator             */
  12. /*  2 Jan 89 Added (count+body=total) special case             */
  13. /*  4 Jan 89 Initialized index=16 saves an instruction             */
  14. /*  4 Jan 89 Realized I could limit shifts to 16 (any more are wasted)   */
  15. /*  4 Jan 89 Some error is introduced by shifting rather than *0xffff    */
  16. /*  9 Jan 89 Implemented a 32x32=64 bit Multiply for Reverse calculation */
  17. /*           a 64/32=32 bit Divide would simplify the other routine      */
  18. /*           Finished 64/32=64 bit divide                                */
  19. /* 25 Jan 89 Cleaned up the routines                                     */
  20. /* 30 Jan 89 Added 020 Mult routines                                     */
  21. /* 30 Jan 89 NOTE the 020 divide is a 64/32=32 bit divide (not 64 bit)   */
  22. /*  1 Feb 89 Changed over to Harriet Tolly's Names and modified Reverse()*/
  23. /*  1 Feb 89 Added QuadAdd68000 and QuadDiv020 routines             */
  24.  
  25. #ifdef machine=MC68020
  26.   #define QuadMult QuadMult020
  27.   #define QuadDiv  QuadDiv020
  28. #else
  29.   #define QuadMult QuadMult68000
  30.   #define QuadDiv  QuadDiv68000
  31. #endif
  32. /* #define QuadAdd  QuadAdd */        /* no particular advantage w/ 020 */
  33.  
  34. /* Returns proper First value given the current total,body, and pot */
  35. ULONG Prop_Gad_Reverse(total,visible,pot)
  36. FAST ULONG total;
  37. FAST ULONG visible;
  38. FAST ULONG pot;
  39. {
  40.   ULONG quad[2];
  41.  
  42.   QuadMult(pot,(total-visible),&quad[0]); /* 16 bit * 32 bit multiply    */
  43.   QuadAdd(0x8000l,&quad[0]);        /* add 2^15             */
  44.   QuadDiv(&quad[0],0xffffl);        /* divide by 0xffffl        */
  45.   return(quad[1]);            /* answer is low ULONG of QUAD    */ 
  46. }
  47.  
  48. /* This routine calculates the Body and Pot variables for a Prop Gadget */
  49. /* given the Visible,First, and total */
  50. USHORT Prop_Gad_Calculate(visible,first,total,body,pot)
  51. FAST ULONG visible,first,total;
  52. ULONG *body,*pot;
  53. {
  54.   FAST ULONG quad[2];
  55.  
  56.   if ((total==0L)||(visible==total))     /* Null Hypothesis always true */
  57.   {
  58.     *body=0xffffl;
  59.     *pot=0L;
  60. #ifdef LATTICE
  61.     return((USHORT)0);    /* for some unknown Reason Aztec choked on this */
  62. #else
  63.     return();        
  64. #endif
  65.   }
  66.                     /* calculate the BODY    */
  67.   QuadMult(visible,0xffffl,&quad[0]);     /* [visible * 0xffffl]     */
  68.   QuadDiv(&quad[0],total);        /* [visible * 0x10000l] / total    */
  69.   *body=quad[1];                    /* answer is lower 32 bits      */
  70.   
  71.   if (first+visible >= total)    /* check for error or limit of travel */
  72.     *pot=(LONG)0xffffl;
  73.   else
  74.   {                     /* calculate the POT         */
  75.     QuadMult(first,0xffffl,&quad[0]);
  76.     QuadDiv(&quad[0],total-visible); /* [first * 0xffff0000l]/total*/
  77.     *pot=quad[1]; 
  78.   } 
  79. }
  80.