Debian Codegraph @

src/hardware/mame/sn76496.h

raw symbols SCIP
1 // license:BSD-3-Clause
2 // copyright-holders:Nicola Salmoria
3 #ifndef MAME_SOUND_SN76496_H
4 #define MAME_SOUND_SN76496_H
5
6 #pragma once
7
8
9 DECLARE_DEVICE_TYPE(SN76496, sn76496_device)
10 DECLARE_DEVICE_TYPE(U8106, u8106_device)
11 DECLARE_DEVICE_TYPE(Y2404, y2404_device)
12 DECLARE_DEVICE_TYPE(SN76489, sn76489_device)
13 DECLARE_DEVICE_TYPE(SN76489A, sn76489a_device)
14 DECLARE_DEVICE_TYPE(SN76494, sn76494_device)
15 DECLARE_DEVICE_TYPE(SN94624, sn94624_device)
16 DECLARE_DEVICE_TYPE(NCR8496, ncr8496_device)
17 DECLARE_DEVICE_TYPE(PSSJ3, pssj3_device)
18 DECLARE_DEVICE_TYPE(GAMEGEAR, gamegear_device)
19 DECLARE_DEVICE_TYPE(SEGAPSG, segapsg_device)
20
21 #if 0
22
23
24 #define MCFG_SN76496_READY_HANDLER(cb) \
25 downcast<sn76496_base_device &>(*device).set_ready_handler((DEVCB_##cb));
26
27 #endif
28
29 class sn76496_base_device : public device_t, public device_sound_interface
30 {
31 public:
32 // configuration helpers
33 // template <class Object> devcb_base &set_ready_handler(Object &&cb) { return m_ready_handler.set_callback(std::forward<Object>(cb)); }
34
35 DECLARE_WRITE8_MEMBER( stereo_w );
36 void write(uint8_t data);
37 DECLARE_WRITE8_MEMBER( write );
38 // DECLARE_READ_LINE_MEMBER( ready_r ) { return m_ready_state ? 1 : 0; }
39 // auto ready_cb() { return m_ready_handler.bind(); }
40
41 void convert_samplerate(int32_t target_rate);
42 protected:
43 sn76496_base_device(
44 const machine_config &mconfig,
45 device_type type,
46 const char *tag,
47 int feedbackmask,
48 int noisetap1,
49 int noisetap2,
50 bool negate,
51 bool stereo,
52 int clockdivider,
53 bool ncr,
54 bool sega,
55 device_t *owner,
56 uint32_t clock);
57
58 virtual void device_start();
59 virtual void device_clock_changed();
60 virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
61
62 private:
63 inline bool in_noise_mode();
64 void register_for_save_states();
65 void countdown_cycles();
66
67
68
69 bool m_ready_state;
70
71 //devcb_write_line m_ready_handler;
72
73 //sound_stream* m_sound;
74
75 const int32_t m_feedback_mask; // mask for feedback
76 const int32_t m_whitenoise_tap1; // mask for white noise tap 1 (higher one, usually bit 14)
77 const int32_t m_whitenoise_tap2; // mask for white noise tap 2 (lower one, usually bit 13)
78 const bool m_negate; // output negate flag
79 const bool m_stereo; // whether we're dealing with stereo or not
80 const int32_t m_clock_divider; // clock divider
81 const bool m_ncr_style_psg; // flag to ignore writes to regs 1,3,5,6,7 with bit 7 low
82 const bool m_sega_style_psg; // flag to make frequency zero acts as if it is one more than max (0x3ff+1) or if it acts like 0; the initial register is pointing to 0x3 instead of 0x0; the volume reg is preloaded with 0xF instead of 0x0
83
84 int32_t m_vol_table[16]; // volume table (for 4-bit to db conversion)
85 int32_t m_register[8]; // registers
86 int32_t m_last_register; // last register written
87 int32_t m_volume[4]; // db volume of voice 0-2 and noise
88 uint32_t m_RNG; // noise generator LFSR
89 int32_t m_current_clock;
90 int32_t m_stereo_mask; // the stereo output mask
91 int32_t m_period[4]; // Length of 1/2 of waveform
92 int32_t m_count[4]; // Position within the waveform
93 int32_t m_output[4]; // 1-bit output of each channel, pre-volume
94 int32_t m_cycles_to_ready; // number of cycles until the READY line goes active
95
96 //Modifications for easier sample conversion
97 int32_t sample_rate;
98 //Sample rate conversion
99 int32_t rate_add;
100 int32_t rate_counter;
101 };
102
103 // SN76496: Whitenoise verified, phase verified, periodic verified (by Michael Zapf)
104 class sn76496_device : public sn76496_base_device
105 {
106 public:
107 sn76496_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
108 };
109
110 // U8106 not verified yet. todo: verify; (a custom marked sn76489? only used on mr. do and maybe other universal games)
111 class u8106_device : public sn76496_base_device
112 {
113 public:
114 u8106_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
115 };
116
117 // Y2404 not verified yet. todo: verify; (don't be fooled by the Y, it's a TI chip, not Yamaha)
118 class y2404_device : public sn76496_base_device
119 {
120 public:
121 y2404_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
122 };
123
124 // NCR8496 whitenoise verified, phase verified; verified by ValleyBell & NewRisingSun
125 class sn76489_device : public sn76496_base_device
126 {
127 public:
128 sn76489_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
129 };
130
131 // PSSJ-3 whitenoise verified, phase verified; verified by ValleyBell & NewRisingSun
132 class pssj3_device : public sn76496_base_device
133 {
134 public:
135 pssj3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
136 };
137
138
139 // SN76489A: whitenoise verified, phase verified, periodic verified (by plgdavid)
140 class sn76489a_device : public sn76496_base_device
141 {
142 public:
143 sn76489a_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
144 };
145
146 // SN76494 not verified, (according to datasheet: same as sn76489a but without the /8 divider)
147 class sn76494_device : public sn76496_base_device
148 {
149 public:
150 sn76494_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
151 };
152
153 // SN94624 whitenoise verified, phase verified, period verified; verified by PlgDavid
154 class sn94624_device : public sn76496_base_device
155 {
156 public:
157 sn94624_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
158 };
159
160 // NCR8496 not verified; info from smspower wiki and vgmpf wiki
161 class ncr8496_device : public sn76496_base_device
162 {
163 public:
164 ncr8496_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
165 };
166
167 // Verified by Justin Kerk
168 class gamegear_device : public sn76496_base_device
169 {
170 public:
171 gamegear_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
172 };
173
174 // todo: verify; from smspower wiki, assumed to have same invert as gamegear
175 class segapsg_device : public sn76496_base_device
176 {
177 public:
178 segapsg_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
179 };
180
181 #endif // MAME_SOUND_SN76496_H