]> icculus.org git repositories - btb/d2x.git/blob - main/old/coindev.c
attempt to support d1 for mac mission
[btb/d2x.git] / main / old / coindev.c
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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: coindev.c,v 1.1.1.1 2001-01-19 03:30:05 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19 #include <stdio.h>
20 #include <dos.h>
21 #include <conio.h>
22
23 #include "coindev.h"
24
25 int CoinMechPort[3]  =  { COINMECH1_PORT,
26                           COINMECH2_PORT,
27                           COINMECH3_PORT };
28
29 int CoinMechCtrl[3]  =  { COINMECH1_CTRLMASK,
30                           COINMECH2_CTRLMASK,
31                           COINMECH3_CTRLMASK };
32
33 unsigned int CoinMechLastCnt[3];
34
35
36 int coindev_init(CoinMechNumber)
37 {
38     int x;
39
40     int CoinMechAdj[3]   =  { COINMECH1_ADJMASK,
41                               COINMECH2_ADJMASK,
42                               COINMECH3_ADJMASK };
43
44     /* set up IO port for our special use */
45     outp(COINMECH_CMDPORT, CoinMechCtrl[CoinMechNumber]);
46     outp(CoinMechPort[CoinMechNumber], 0);
47     outp(CoinMechPort[CoinMechNumber], 0);
48
49     /* write to the IO board so that the counter eventually gets cleared */
50     for( x = 10; x > 0; x-- )
51     {
52        outp(COINMECH_ADJPORT, CoinMechAdj[CoinMechNumber]);
53        outp(COINMECH_ADJPORT, 0);
54        if( coindev_read(CoinMechNumber) == 0 )
55        {
56           break;
57        }
58     }
59
60     CoinMechLastCnt[CoinMechNumber] = 0;
61
62     return(x);  /* TRUE == CoinMech is cleared;  FALSE == CoinMech error! */
63 }
64
65
66 /* Do a raw read of the specified CoinMech */
67 unsigned int coindev_read(CoinMechNumber)
68 {
69     unsigned int x;
70
71     /* read lower byte, then upper byte */
72     x  = (inp(CoinMechPort[CoinMechNumber]));
73     x += (inp(CoinMechPort[CoinMechNumber]) * 256);
74
75     /* conver to usable number */
76     if( x )
77     {
78         x = (65536L - x);
79     }
80
81     return(x);
82 }
83
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
91     x = coindev_read(CoinMechNumber);
92     y = x - CoinMechLastCnt[CoinMechNumber];
93
94     CoinMechLastCnt[CoinMechNumber] = x;
95
96     return(y);
97 }
98
99