1 /*
2  *  Copyright (C) 2002-2009  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.4 2009/04/26 10:33:53 harekiet 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 "mixer.h"
28 #include "setup.h"
29 #include "pic.h"
30 #include "hardware.h"*/
31 
32 
33 namespace Adlib {
34 
35 struct Timer {
36 	double start;
37 	double delay;
38 	bool enabled, overflow, masked;
39 	Bit8u counter;
TimerTimer40 	Timer() {
41 		masked = false;
42 		overflow = false;
43 		enabled = false;
44 		counter = 0;
45 		delay = 0;
46 	}
47 	//Call update before making any further changes
UpdateTimer48 	void Update( double time ) {
49 		if ( !enabled || !delay )
50 			return;
51 		double deltaStart = time - start;
52 		//Only set the overflow flag when not masked
53 		if ( deltaStart >= 0 && !masked ) {
54 			overflow = 1;
55 		}
56 	}
57 	//On a reset make sure the start is in sync with the next cycle
ResetTimer58 	void Reset(const double& time ) {
59 		overflow = false;
60 		if ( !delay || !enabled )
61 			return;
62 		double delta = (time - start);
63 		double rem = fmod( delta, delay );
64 		double next = delay - rem;
65 		start = time + next;
66 	}
StopTimer67 	void Stop( ) {
68 		enabled = false;
69 	}
StartTimer70 	void Start( const double& time, Bits scale ) {
71 		//Don't enable again
72 		if ( enabled ) {
73 			return;
74 		}
75 		enabled = true;
76 		delay = 0.001 * (256 - counter ) * scale;
77 		start = time + delay;
78 	}
79 
80 };
81 
82 struct Chip {
83 	//Last selected register
84 	Timer timer[2];
85 	//Check for it being a write to the timer
86 	bool Write( Bit32u addr, Bit8u val );
87 	//Read the current timer state, will use current double
88 	Bit8u Read( );
89 };
90 
91 //The type of handler this is
92 typedef enum {
93 	MODE_OPL2,
94 	MODE_DUALOPL2,
95 	MODE_OPL3
96 } Mode;
97 
98 /*class Handler {
99 public:
100 	//Write an address to a chip, returns the address the chip sets
101 	virtual Bit32u WriteAddr( Bit32u port, Bit8u val ) = 0;
102 	//Write to a specific register in the chip
103 	virtual void WriteReg( Bit32u addr, Bit8u val ) = 0;
104 	//Generate a certain amount of samples
105 	virtual void Generate( MixerChannel* chan, Bitu samples ) = 0;
106 	//Initialize at a specific sample rate and mode
107 	virtual void Init( Bitu rate ) = 0;
108 	virtual ~Handler() {
109 	}
110 };*/
111 
112 //The cache for 2 chips or an opl3
113 typedef Bit8u RegisterCache[512];
114 
115 //Internal class used for dro capturing
116 class Capture;
117 
118 /*class Module: public Module_base {
119 	IO_ReadHandleObject ReadHandler[3];
120 	IO_WriteHandleObject WriteHandler[3];
121 	MixerObject mixerObject;
122 
123 	//Mode we're running in
124 	Mode mode;
125 	//Last selected address in the chip for the different modes
126 	union {
127 		Bit32u normal;
128 		Bit8u dual[2];
129 	} reg;
130 	void CacheWrite( Bit32u reg, Bit8u val );
131 	void DualWrite( Bit8u index, Bit8u reg, Bit8u val );
132 public:
133 	static OPL_Mode oplmode;
134 	MixerChannel* mixerChan;
135 	Bit32u lastUsed;				//Ticks when adlib was last used to turn of mixing after a few second
136 
137 	Handler* handler;				//Handler that will generate the sound
138 	RegisterCache cache;
139 	Capture* capture;
140 	Chip	chip[2];
141 
142 	//Handle port writes
143 	void PortWrite( Bitu port, Bitu val, Bitu iolen );
144 	Bitu PortRead( Bitu port, Bitu iolen );
145 	void Init( Mode m );
146 
147 	Module( Section* configuration);
148 	~Module();
149 };*/
150 
151 
152 }		//Adlib namespace
153 
154 #endif
155