OSDN Git Service

[VM][EVENT][DEVICE] Add new APIs for recording sound.
[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 #ifdef SUPPORT_WIN32_DLL
19 #define SUPPORT_MAME_FM_DLL
20 //#include "fmdll/fmdll.h"
21 #endif
22 //#if defined(HAS_AY_3_8913)
23 // both port a and port b are not supported
24 //#elif defined(HAS_AY_3_8912)
25 // port b is not supported
26 //#define SUPPORT_YM2203_PORT_A
27 //#else
28 //#define SUPPORT_YM2203_PORT_A
29 //#define SUPPORT_YM2203_PORT_B
30 //#endif
31
32 //#ifdef SUPPORT_YM2203_PORT_A
33 #define SIG_YM2203_PORT_A       0
34 //#endif
35 //#ifdef SUPPORT_YM2203_PORT_B
36 #define SIG_YM2203_PORT_B       1
37 //#endif
38 #define SIG_YM2203_MUTE         2
39
40 class DEBUGGER;
41
42 class YM2203 : public DEVICE
43 {
44 private:
45         DEBUGGER *d_debugger;
46         FM::OPNA* opna;
47         FM::OPN* opn;
48 #ifdef SUPPORT_MAME_FM_DLL
49 //      CFMDLL* fmdll;
50         LPVOID* dllchip;
51 #endif
52         struct {
53                 bool written;
54                 uint8_t data;
55         } port_log[0x200];
56         int base_decibel_fm, base_decibel_psg;
57         int decibel_vol;
58         
59         uint8_t ch;
60         uint8_t fnum2;
61         uint8_t ch1, data1;
62         uint8_t fnum21;
63
64         int32_t right_volume;
65         int32_t left_volume;
66         int32_t v_right_volume;
67         int32_t v_left_volume;
68         struct {
69                 uint8_t wreg;
70                 uint8_t rreg;
71                 bool first;
72                 // output signals
73                 outputs_t outputs;
74         } port[2];
75         uint8_t mode;
76         
77         int chip_clock;
78         bool irq_prev, mute;
79         
80         uint32_t clock_prev;
81         uint32_t clock_accum;
82         uint32_t clock_const;
83         int timer_event_id;
84         
85         uint32_t clock_busy;
86         bool busy;
87
88         bool _HAS_YM_SERIES;
89         bool _HAS_AY_3_8910;
90         bool _HAS_AY_3_8912;
91         bool _HAS_AY_3_8913;
92         bool _SUPPORT_YM2203_PORT_A;
93         bool _SUPPORT_YM2203_PORT_B;
94         uint32_t _amask;
95         void update_count();
96         void update_event();
97 //#ifdef HAS_YM_SERIES
98         // output signals
99         outputs_t outputs_irq;
100         void update_interrupt();
101 //#endif
102 public:
103         YM2203(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
104         {
105                 base_decibel_fm = base_decibel_psg = 0;
106                 decibel_vol = 0 + 5;
107                 _amask = 1;
108                 _HAS_AY_3_8910 = _HAS_AY_3_8912 = _HAS_AY_3_8913 = false;
109                 _HAS_YM_SERIES = false;
110                 _SUPPORT_YM2203_PORT_A = _SUPPORT_YM2203_PORT_B = false;
111                 is_ym2608 = false;
112                 for(int i = 0; i < 2; i++) {
113                         initialize_output_signals(&port[i].outputs);
114                         port[i].wreg = port[i].rreg = 0;//0xff;
115                 }
116                 d_debugger = NULL;
117                 initialize_output_signals(&outputs_irq);
118                 this_device_name[0] = _T('\0');
119         }
120         ~YM2203() {}
121         
122         // common functions
123         void initialize();
124         void release();
125         void reset();
126         void write_io8(uint32_t addr, uint32_t data);
127         uint32_t read_io8(uint32_t addr);
128         void write_signal(int id, uint32_t data, uint32_t mask);
129         uint32_t read_signal(int id);
130         void event_vline(int v, int clock);
131         void event_callback(int event_id, int error);
132         void mix(int32_t* buffer, int cnt);
133         void set_volume(int _ch, int decibel_l, int decibel_r);
134         void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame);
135         // for debugging
136         void write_via_debugger_data8(uint32_t addr, uint32_t data);
137         uint32_t read_via_debugger_data8(uint32_t addr);
138         bool is_debugger_available()
139         {
140                 return true;
141         }
142         void *get_debugger()
143         {
144                 return d_debugger;
145         }
146         uint64_t get_debug_data_addr_space()
147         {
148                 return is_ym2608 ? 0x200 : 0x100;
149         }
150         void write_debug_data8(uint32_t addr, uint32_t data)
151         {
152                 if(addr < (uint32_t)(is_ym2608 ? 0x200 : 0x100)) {
153                         write_via_debugger_data8(addr, data);
154                 }
155         }
156         uint32_t read_debug_data8(uint32_t addr)
157         {
158                 if(addr < (uint32_t)(is_ym2608 ? 0x200 : 0x100)) {
159                         return read_via_debugger_data8(addr);
160                 }
161                 return 0;
162         }
163
164         bool process_state(FILEIO* state_fio, bool loading);
165         // unique functions
166         void set_context_irq(DEVICE* device, int id, uint32_t mask)
167         {
168                 register_output_signal(&outputs_irq, device, id, mask);
169         }
170         void set_context_port_a(DEVICE* device, int id, uint32_t mask, int shift)
171         {
172                 register_output_signal(&port[0].outputs, device, id, mask, shift);
173         }
174         void set_context_port_b(DEVICE* device, int id, uint32_t mask, int shift)
175         {
176                 register_output_signal(&port[1].outputs, device, id, mask, shift);
177         }
178         void set_context_debugger(DEBUGGER* device)
179         {
180                 d_debugger = device;
181         }
182         void initialize_sound(int rate, int clock, int samples, int decibel_fm, int decibel_psg);
183         void set_reg(uint32_t addr, uint32_t data); // for patch
184         bool is_ym2608;
185 };
186
187 #endif
188