OSDN Git Service

[LIBCPU_NEWDEV] Fix FTBFS.
[csp-qt/common_source_project-fm7.git] / source / src / vm / ym2203.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2006.09.15-
6
7         [ AY-3-8910 / YM2203 / YM2608 ]
8 */
9
10 #ifndef _YM2203_H_
11 #define _YM2203_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16 #include "fmgen/opna.h"
17
18 //#if !(defined(HAS_AY_3_8910) || defined(HAS_AY_3_8912) || defined(HAS_AY_3_8913))
19 //#define HAS_YM_SERIES
20 #ifdef SUPPORT_WIN32_DLL
21 #define SUPPORT_MAME_FM_DLL
22 //#include "fmdll/fmdll.h"
23 #endif
24 //#endif
25
26 //#if defined(HAS_AY_3_8913)
27 // both port a and port b are not supported
28 //#elif defined(HAS_AY_3_8912)
29 // port b is not supported
30 //#define SUPPORT_YM2203_PORT_A
31 //#else
32 //#define SUPPORT_YM2203_PORT_A
33 //#define SUPPORT_YM2203_PORT_B
34 //#endif
35 //#if defined(SUPPORT_YM2203_PORT_A) || defined(SUPPORT_YM2203_PORT_B)
36 //#define SUPPORT_YM2203_PORT
37 //#endif
38
39 //#ifdef SUPPORT_YM2203_PORT_A
40 #define SIG_YM2203_PORT_A       0
41 //#endif
42 //#ifdef SUPPORT_YM2203_PORT_B
43 #define SIG_YM2203_PORT_B       1
44 //#endif
45 #define SIG_YM2203_MUTE         2
46
47 class YM2203 : public DEVICE
48 {
49 private:
50 //#ifdef HAS_YM2608
51         FM::OPNA* opna;
52 //#endif
53         FM::OPN* opn;
54 #ifdef SUPPORT_MAME_FM_DLL
55 //      CFMDLL* fmdll;
56         LPVOID* dllchip;
57         struct {
58                 bool written;
59                 uint8_t data;
60         } port_log[0x200];
61 #endif
62         int base_decibel_fm, base_decibel_psg;
63         int decibel_vol;
64         
65         uint8_t ch;
66         uint8_t fnum2;
67 //#ifdef HAS_YM2608
68         uint8_t ch1, data1;
69         uint8_t fnum21;
70 //#endif
71
72         int32_t right_volume;
73         int32_t left_volume;
74         int32_t v_right_volume;
75         int32_t v_left_volume;
76 //#ifdef SUPPORT_YM2203_PORT
77         struct {
78                 uint8_t wreg;
79                 uint8_t rreg;
80                 bool first;
81                 // output signals
82                 outputs_t outputs;
83         } port[2];
84         uint8_t mode;
85 //#endif
86         
87         int chip_clock;
88         bool irq_prev, mute;
89         
90         uint32_t clock_prev;
91         uint32_t clock_accum;
92         uint32_t clock_const;
93         int timer_event_id;
94         
95         uint32_t clock_busy;
96         bool busy;
97
98         bool _HAS_YM2608;
99         bool _SUPPORT_YM2203_PORT;
100         bool _HAS_YM_SERIES;
101         bool _HAS_AY_3_8910;
102         bool _HAS_AY_3_8912;
103         bool _HAS_AY_3_8913;
104         bool _IS_YM2203_PORT_MODE;
105         uint8_t _YM2203_PORT_MODE;
106         bool _SUPPORT_YM2203_PORT_A;
107         bool _SUPPORT_YM2203_PORT_B;
108         uint32_t _amask;
109         void update_count();
110         void update_event();
111 //#ifdef HAS_YM_SERIES
112         // output signals
113         outputs_t outputs_irq;
114         void update_interrupt();
115 //#endif
116 public:
117         YM2203(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
118         {
119                 base_decibel_fm = base_decibel_psg = 0;
120                 decibel_vol = 0 + 5;
121                 _amask = 1;
122                 _HAS_YM2608 = false;
123                 _HAS_AY_3_8910 = _HAS_AY_3_8912 = _HAS_AY_3_8913 = false;
124                 _SUPPORT_YM2203_PORT = _HAS_YM_SERIES = false;
125                 _IS_YM2203_PORT_MODE = false;
126                 _YM2203_PORT_MODE = 0xff;
127                 _SUPPORT_YM2203_PORT_A = _SUPPORT_YM2203_PORT_B = false;
128                 is_ym2608 = false;
129                 //if(_SUPPORT_YM2203_PORT) {
130                 for(int i = 0; i < 2; i++) {
131                         initialize_output_signals(&port[i].outputs);
132                         port[i].wreg = port[i].rreg = 0;//0xff;
133                 }
134                 initialize_output_signals(&outputs_irq);
135                 //}
136         }
137         ~YM2203() {}
138         
139         // common functions
140         void initialize();
141         void release();
142         void reset();
143         void write_io8(uint32_t addr, uint32_t data);
144         uint32_t read_io8(uint32_t addr);
145         void write_signal(int id, uint32_t data, uint32_t mask);
146         uint32_t read_signal(int id);
147         void event_vline(int v, int clock);
148         void event_callback(int event_id, int error);
149         void mix(int32* buffer, int cnt);
150         void set_volume(int _ch, int decibel_l, int decibel_r);
151         void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame);
152         bool process_state(FILEIO* state_fio, bool loading);
153         // unique functions
154 //#ifdef HAS_YM_SERIES
155         void set_context_irq(DEVICE* device, int id, uint32_t mask)
156         {
157                 register_output_signal(&outputs_irq, device, id, mask);
158         }
159 //#endif
160 //#ifdef SUPPORT_YM2203_PORT_A
161         void set_context_port_a(DEVICE* device, int id, uint32_t mask, int shift)
162         {
163                 register_output_signal(&port[0].outputs, device, id, mask, shift);
164         }
165 //#endif
166 //#ifdef SUPPORT_YM2203_PORT_B
167         void set_context_port_b(DEVICE* device, int id, uint32_t mask, int shift)
168         {
169                 register_output_signal(&port[1].outputs, device, id, mask, shift);
170         }
171 //#endif
172         void initialize_sound(int rate, int clock, int samples, int decibel_fm, int decibel_psg);
173         void set_reg(uint32_t addr, uint32_t data); // for patch
174 //#ifdef HAS_YM2608
175         bool is_ym2608;
176 //#endif
177 };
178
179 #endif
180