Debian Codegraph @

src/hardware/adlib.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: adlib.h,v 1.5 2009-04-28 21:45:43 c2woody Exp $ */
20
21 #ifndef DOSBOX_ADLIB_H
22 #define DOSBOX_ADLIB_H
23
24 #include "dosbox.h"
25 #include "mixer.h"
26 #include "inout.h"
27 #include "setup.h"
28 #include "pic.h"
29 #include "hardware.h"
30
31
32 namespace Adlib {
33
34 struct Timer {
35 double start;
36 double delay;
37 bool enabled, overflow, masked;
38 Bit8u counter;
39 Timer() {
40 masked = false;
41 overflow = false;
42 enabled = false;
43 counter = 0;
44 delay = 0;
45 }
46 //Call update before making any further changes
47 void Update( double time ) {
48 if ( !enabled || !delay )
49 return;
50 double deltaStart = time - start;
51 //Only set the overflow flag when not masked
52 if ( deltaStart >= 0 && !masked ) {
53 overflow = 1;
54 }
55 }
56 //On a reset make sure the start is in sync with the next cycle
57 void Reset(const double& time ) {
58 overflow = false;
59 if ( !delay || !enabled )
60 return;
61 double delta = (time - start);
62 double rem = fmod( delta, delay );
63 double next = delay - rem;
64 start = time + next;
65 }
66 void Stop( ) {
67 enabled = false;
68 }
69 void Start( const double& time, Bits scale ) {
70 //Don't enable again
71 if ( enabled ) {
72 return;
73 }
74 enabled = true;
75 delay = 0.001 * (256 - counter ) * scale;
76 start = time + delay;
77 }
78
79 };
80
81 struct Chip {
82 //Last selected register
83 Timer timer[2];
84 //Check for it being a write to the timer
85 bool Write( Bit32u addr, Bit8u val );
86 //Read the current timer state, will use current double
87 Bit8u Read( );
88 };
89
90 //The type of handler this is
91 typedef enum {
92 MODE_OPL2,
93 MODE_DUALOPL2,
94 MODE_OPL3
95 } Mode;
96
97 class Handler {
98 public:
99 //Write an address to a chip, returns the address the chip sets
100 virtual Bit32u WriteAddr( Bit32u port, Bit8u val ) = 0;
101 //Write to a specific register in the chip
102 virtual void WriteReg( Bit32u addr, Bit8u val ) = 0;
103 //Generate a certain amount of samples
104 virtual void Generate( MixerChannel* chan, Bitu samples ) = 0;
105 //Initialize at a specific sample rate and mode
106 virtual void Init( Bitu rate ) = 0;
107 virtual ~Handler() {
108 }
109 };
110
111 //The cache for 2 chips or an opl3
112 typedef Bit8u RegisterCache[512];
113
114 //Internal class used for dro capturing
115 class Capture;
116
117 class Module: public Module_base {
118 IO_ReadHandleObject ReadHandler[3];
119 IO_WriteHandleObject WriteHandler[3];
120 MixerObject mixerObject;
121
122 //Mode we're running in
123 Mode mode;
124 //Last selected address in the chip for the different modes
125 union {
126 Bit32u normal;
127 Bit8u dual[2];
128 } reg;
129 void CacheWrite( Bit32u reg, Bit8u val );
130 void DualWrite( Bit8u index, Bit8u reg, Bit8u val );
131 public:
132 static OPL_Mode oplmode;
133 MixerChannel* mixerChan;
134 Bit32u lastUsed; //Ticks when adlib was last used to turn of mixing after a few second
135
136 Handler* handler; //Handler that will generate the sound
137 RegisterCache cache;
138 Capture* capture;
139 Chip chip[2];
140
141 //Handle port writes
142 void PortWrite( Bitu port, Bitu val, Bitu iolen );
143 Bitu PortRead( Bitu port, Bitu iolen );
144 void Init( Mode m );
145
146 Module( Section* configuration);
147 ~Module();
148 };
149
150
151 } //Adlib namespace
152
153 #endif