COINDEV.C 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #pragma off (unreferenced)
  35. static char rcsid[] = "$Id: coindev.c 2.0 1995/02/27 11:26:39 john Exp $";
  36. #pragma on (unreferenced)
  37. #include <stdio.h>
  38. #include <dos.h>
  39. #include <conio.h>
  40. #include "coindev.h"
  41. int CoinMechPort[3] = { COINMECH1_PORT,
  42. COINMECH2_PORT,
  43. COINMECH3_PORT };
  44. int CoinMechCtrl[3] = { COINMECH1_CTRLMASK,
  45. COINMECH2_CTRLMASK,
  46. COINMECH3_CTRLMASK };
  47. unsigned int CoinMechLastCnt[3];
  48. int coindev_init(CoinMechNumber)
  49. {
  50. int x;
  51. int CoinMechAdj[3] = { COINMECH1_ADJMASK,
  52. COINMECH2_ADJMASK,
  53. COINMECH3_ADJMASK };
  54. /* set up IO port for our special use */
  55. outp(COINMECH_CMDPORT, CoinMechCtrl[CoinMechNumber]);
  56. outp(CoinMechPort[CoinMechNumber], 0);
  57. outp(CoinMechPort[CoinMechNumber], 0);
  58. /* write to the IO board so that the counter eventually gets cleared */
  59. for( x = 10; x > 0; x-- )
  60. {
  61. outp(COINMECH_ADJPORT, CoinMechAdj[CoinMechNumber]);
  62. outp(COINMECH_ADJPORT, 0);
  63. if( coindev_read(CoinMechNumber) == 0 )
  64. {
  65. break;
  66. }
  67. }
  68. CoinMechLastCnt[CoinMechNumber] = 0;
  69. return(x); /* TRUE == CoinMech is cleared; FALSE == CoinMech error! */
  70. }
  71. /* Do a raw read of the specified CoinMech */
  72. unsigned int coindev_read(CoinMechNumber)
  73. {
  74. unsigned int x;
  75. /* read lower byte, then upper byte */
  76. x = (inp(CoinMechPort[CoinMechNumber]));
  77. x += (inp(CoinMechPort[CoinMechNumber]) * 256);
  78. /* conver to usable number */
  79. if( x )
  80. {
  81. x = (65536L - x);
  82. }
  83. return(x);
  84. }
  85. /* read the specified CoinMech and return the */
  86. /* ...number of clicks since the last read */
  87. unsigned int coindev_count(CoinMechNumber)
  88. {
  89. unsigned int x, y;
  90. x = coindev_read(CoinMechNumber);
  91. y = x - CoinMechLastCnt[CoinMechNumber];
  92. CoinMechLastCnt[CoinMechNumber] = x;
  93. return(y);
  94. }
  95.