]> icculus.org git repositories - btb/d2x.git/blob - main/old/coindev.c
use the orientation parameter of g3_draw_bitmap
[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 #include <stdio.h>
16 #include <dos.h>
17 #include <conio.h>
18
19 #include "coindev.h"
20
21 int CoinMechPort[3]  =  { COINMECH1_PORT,
22                           COINMECH2_PORT,
23                           COINMECH3_PORT };
24
25 int CoinMechCtrl[3]  =  { COINMECH1_CTRLMASK,
26                           COINMECH2_CTRLMASK,
27                           COINMECH3_CTRLMASK };
28
29 unsigned int CoinMechLastCnt[3];
30
31
32 int coindev_init(CoinMechNumber)
33 {
34     int x;
35
36     int CoinMechAdj[3]   =  { COINMECH1_ADJMASK,
37                               COINMECH2_ADJMASK,
38                               COINMECH3_ADJMASK };
39
40     /* set up IO port for our special use */
41     outp(COINMECH_CMDPORT, CoinMechCtrl[CoinMechNumber]);
42     outp(CoinMechPort[CoinMechNumber], 0);
43     outp(CoinMechPort[CoinMechNumber], 0);
44
45     /* write to the IO board so that the counter eventually gets cleared */
46     for( x = 10; x > 0; x-- )
47     {
48        outp(COINMECH_ADJPORT, CoinMechAdj[CoinMechNumber]);
49        outp(COINMECH_ADJPORT, 0);
50        if( coindev_read(CoinMechNumber) == 0 )
51        {
52           break;
53        }
54     }
55
56     CoinMechLastCnt[CoinMechNumber] = 0;
57
58     return(x);  /* TRUE == CoinMech is cleared;  FALSE == CoinMech error! */
59 }
60
61
62 /* Do a raw read of the specified CoinMech */
63 unsigned int coindev_read(CoinMechNumber)
64 {
65     unsigned int x;
66
67     /* read lower byte, then upper byte */
68     x  = (inp(CoinMechPort[CoinMechNumber]));
69     x += (inp(CoinMechPort[CoinMechNumber]) * 256);
70
71     /* conver to usable number */
72     if( x )
73     {
74         x = (65536L - x);
75     }
76
77     return(x);
78 }
79
80
81 /* read the specified CoinMech and return the */
82 /* ...number of clicks since the last read    */
83 unsigned int coindev_count(CoinMechNumber)
84 {
85     unsigned int x, y;
86
87     x = coindev_read(CoinMechNumber);
88     y = x - CoinMechLastCnt[CoinMechNumber];
89
90     CoinMechLastCnt[CoinMechNumber] = x;
91
92     return(y);
93 }
94
95