OSDN Git Service

[VM] Add vm_template.h . This class, VM_TEMPLATE:: must be mother of VM:: .See fm7...
[csp-qt/common_source_project-fm7.git] / source / src / vm / ay_3_891x.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2006.09.15-
6
7         [ AY-3-8910 / AY-3-8912 / AY-3-8913 ]
8 */
9
10 #ifndef _AY_3_891X_H_
11 #define _AY_3_891X_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_8913)
19 // AY-3-8913: both port a and port b are not supported
20 #elif defined(HAS_AY_3_8912)
21 // AY-3-8912: port b is not supported
22 #define SUPPORT_AY_3_891X_PORT_A
23 #else
24 // AY-3-8910: both port a and port b are supported
25 #define SUPPORT_AY_3_891X_PORT_A
26 #define SUPPORT_AY_3_891X_PORT_B
27 #endif
28 #if defined(SUPPORT_AY_3_891X_PORT_A) || defined(SUPPORT_AY_3_891X_PORT_B)
29 #define SUPPORT_AY_3_891X_PORT
30 #endif
31
32 #ifdef SUPPORT_AY_3_891X_PORT_A
33 #define SIG_AY_3_891X_PORT_A    0
34 #endif
35 #ifdef SUPPORT_AY_3_891X_PORT_B
36 #define SIG_AY_3_891X_PORT_B    1
37 #endif
38 #define SIG_AY_3_891X_MUTE      2
39
40 class AY_3_891X : public DEVICE
41 {
42 private:
43         FM::OPN* opn;
44         int base_decibel_fm, base_decibel_psg;
45         
46         uint8_t ch;
47         uint8_t fnum2;
48         
49 #ifdef SUPPORT_AY_3_891X_PORT
50         struct {
51                 uint8_t wreg;
52                 uint8_t rreg;
53                 bool first;
54                 // output signals
55                 outputs_t outputs;
56         } port[2];
57         uint8_t mode;
58 #endif
59         
60         int chip_clock;
61         bool irq_prev, mute;
62         
63         uint32_t clock_prev;
64         uint32_t clock_accum;
65         uint32_t clock_const;
66         int timer_event_id;
67         
68         uint32_t clock_busy;
69         bool busy;
70         
71         void update_count();
72         void update_event();
73         
74 public:
75         AY_3_891X(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
76         {
77 #ifdef SUPPORT_AY_3_891X_PORT
78                 for(int i = 0; i < 2; i++) {
79                         initialize_output_signals(&port[i].outputs);
80                         port[i].wreg = port[i].rreg = 0;//0xff;
81                 }
82 #endif
83                 base_decibel_fm = base_decibel_psg = 0;
84 #if defined(HAS_AY_3_8910)
85                 set_device_name(_T("AY-3-8910 PSG"));
86 #elif defined(HAS_AY_3_8912)
87                 set_device_name(_T("AY-3-8912 PSG"));
88 #elif defined(HAS_AY_3_8913)
89                 set_device_name(_T("AY-3-8913 PSG"));
90 #else
91                 set_device_name(_T("AY_3_891X PSG"));
92 #endif
93         }
94         ~AY_3_891X() {}
95         
96         // common functions
97         void initialize();
98         void release();
99         void reset();
100         void write_io8(uint32_t addr, uint32_t data);
101         uint32_t read_io8(uint32_t addr);
102         void write_signal(int id, uint32_t data, uint32_t mask);
103         void event_vline(int v, int clock);
104         void event_callback(int event_id, int error);
105         void mix(int32_t* buffer, int cnt);
106         void set_volume(int ch, int decibel_l, int decibel_r);
107         void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame);
108         void decl_state();
109         void save_state(FILEIO* state_fio);
110         bool load_state(FILEIO* state_fio);
111         
112         // unique functions
113 #ifdef SUPPORT_AY_3_891X_PORT_A
114         void set_context_port_a(DEVICE* device, int id, uint32_t mask, int shift)
115         {
116                 register_output_signal(&port[0].outputs, device, id, mask, shift);
117         }
118 #endif
119 #ifdef SUPPORT_AY_3_891X_PORT_B
120         void set_context_port_b(DEVICE* device, int id, uint32_t mask, int shift)
121         {
122                 register_output_signal(&port[1].outputs, device, id, mask, shift);
123         }
124 #endif
125         void initialize_sound(int rate, int clock, int samples, int decibel_fm, int decibel_psg);
126         void set_reg(uint32_t addr, uint32_t data); // for patch
127 };
128
129 #endif
130