OSDN Git Service

[VM][STATE] Apply new framework to some VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / ym2151.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2009.03.08-
6
7         [ YM2151 ]
8 */
9
10 #ifndef _YM2151_H_
11 #define _YM2151_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16 #include "fmgen/opm.h"
17
18 #ifdef SUPPORT_WIN32_DLL
19 #define SUPPORT_MAME_FM_DLL
20 //#include "fmdll/fmdll.h"
21 #endif
22
23 #define SIG_YM2151_MUTE         0
24
25 class VM;
26 class EMU;
27 class YM2151 : public DEVICE
28 {
29 private:
30         // output signals
31         outputs_t outputs_irq;
32         
33         FM::OPM* opm;
34 #ifdef SUPPORT_MAME_FM_DLL
35 //      CFMDLL* fmdll;
36         LPVOID* dllchip;
37         struct {
38                 bool written;
39                 uint8_t data;
40         } port_log[0x100];
41 #endif
42         int base_decibel;
43         
44         int chip_clock;
45         uint8_t ch;
46         bool irq_prev, mute;
47         
48         uint32_t clock_prev;
49         uint32_t clock_accum;
50         uint32_t clock_const;
51         int timer_event_id;
52         
53         uint32_t clock_busy;
54         bool busy;
55         
56         void update_count();
57         void update_event();
58         void update_interrupt();
59         
60 public:
61         YM2151(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
62         {
63                 initialize_output_signals(&outputs_irq);
64                 base_decibel = 0;
65                 set_device_name(_T("YM2151 OPM"));
66         }
67         ~YM2151() {}
68         
69         // common functions
70         void initialize();
71         void release();
72         void reset();
73         void write_io8(uint32_t addr, uint32_t data);
74         uint32_t read_io8(uint32_t addr);
75         void write_signal(int id, uint32_t data, uint32_t mask);
76         void event_vline(int v, int clock);
77         void event_callback(int event_id, int error);
78         void mix(int32_t* buffer, int cnt);
79         void set_volume(int ch, int decibel_l, int decibel_r);
80         void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame);
81         bool process_state(FILEIO* state_fio, bool loading);
82         // unique functions
83         void set_context_irq(DEVICE* device, int id, uint32_t mask)
84         {
85                 register_output_signal(&outputs_irq, device, id, mask);
86         }
87         void initialize_sound(int rate, int clock, int samples, int decibel);
88         void set_reg(uint32_t addr, uint32_t data); // for patch
89 };
90
91 #endif
92