home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / coindev.c < prev    next >
Text File  |  1998-06-08  |  3KB  |  122 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/coindev.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:26:39 $
  18.  * 
  19.  * Routines to read the coin counter.
  20.  * 
  21.  * $Log: coindev.c $
  22.  * Revision 2.0  1995/02/27  11:26:39  john
  23.  * New version 2.0, which has no anonymous unions, builds with
  24.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25.  * 
  26.  * Revision 1.2  1994/09/16  16:15:05  john
  27.  * Added acrade sequencing.
  28.  * 
  29.  * Revision 1.1  1994/09/16  12:56:09  john
  30.  * Initial revision
  31.  * 
  32.  * 
  33.  */
  34.  
  35.  
  36. #pragma off (unreferenced)
  37. static char rcsid[] = "$Id: coindev.c 2.0 1995/02/27 11:26:39 john Exp $";
  38. #pragma on (unreferenced)
  39.  
  40. #include <stdio.h>
  41. #include <dos.h>
  42. #include <conio.h>
  43.  
  44. #include "coindev.h"
  45.  
  46. int CoinMechPort[3]  =  { COINMECH1_PORT,
  47.                           COINMECH2_PORT,
  48.                           COINMECH3_PORT };
  49.  
  50. int CoinMechCtrl[3]  =  { COINMECH1_CTRLMASK,
  51.                           COINMECH2_CTRLMASK,
  52.                           COINMECH3_CTRLMASK };
  53.  
  54. unsigned int CoinMechLastCnt[3];
  55.  
  56.  
  57. int coindev_init(CoinMechNumber)
  58. {
  59.     int x;
  60.  
  61.     int CoinMechAdj[3]   =  { COINMECH1_ADJMASK,
  62.                               COINMECH2_ADJMASK,
  63.                               COINMECH3_ADJMASK };
  64.  
  65.     /* set up IO port for our special use */
  66.     outp(COINMECH_CMDPORT, CoinMechCtrl[CoinMechNumber]);
  67.     outp(CoinMechPort[CoinMechNumber], 0);
  68.     outp(CoinMechPort[CoinMechNumber], 0);
  69.  
  70.     /* write to the IO board so that the counter eventually gets cleared */
  71.     for( x = 10; x > 0; x-- )
  72.     {
  73.        outp(COINMECH_ADJPORT, CoinMechAdj[CoinMechNumber]);
  74.        outp(COINMECH_ADJPORT, 0);
  75.        if( coindev_read(CoinMechNumber) == 0 )
  76.        {
  77.           break;
  78.        }
  79.     }
  80.  
  81.     CoinMechLastCnt[CoinMechNumber] = 0;
  82.  
  83.     return(x);  /* TRUE == CoinMech is cleared;  FALSE == CoinMech error! */
  84. }
  85.  
  86.  
  87. /* Do a raw read of the specified CoinMech */
  88. unsigned int coindev_read(CoinMechNumber)
  89. {
  90.     unsigned int x;
  91.  
  92.     /* read lower byte, then upper byte */
  93.     x  = (inp(CoinMechPort[CoinMechNumber]));
  94.     x += (inp(CoinMechPort[CoinMechNumber]) * 256);
  95.  
  96.     /* conver to usable number */
  97.     if( x )
  98.     {
  99.         x = (65536L - x);
  100.     }
  101.  
  102.     return(x);
  103. }
  104.  
  105.  
  106. /* read the specified CoinMech and return the */
  107. /* ...number of clicks since the last read    */
  108. unsigned int coindev_count(CoinMechNumber)
  109. {
  110.     unsigned int x, y;
  111.  
  112.     x = coindev_read(CoinMechNumber);
  113.     y = x - CoinMechLastCnt[CoinMechNumber];
  114.  
  115.     CoinMechLastCnt[CoinMechNumber] = x;
  116.  
  117.     return(y);
  118. }
  119.  
  120.  
  121. 
  122.