Debian Codegraph @

src/engine/platform/sound/ymz280b.h

raw
1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /**********************************************************************************************
4 *
5 * Yamaha YMZ280B driver
6 * by Aaron Giles
7 *
8 **********************************************************************************************/
9
10 #include <memory>
11
12 #ifndef MAME_SOUND_YMZ280B_H
13 #define MAME_SOUND_YMZ280B_H
14
15 #pragma once
16
17 namespace ymz280b
18 {
19 typedef unsigned char u8;
20 typedef signed char s8;
21 typedef unsigned short u16;
22 typedef signed short s16;
23 typedef unsigned int u32;
24 typedef signed int s32;
25 typedef signed int offs_t;
26 }
27
28 using namespace ymz280b;
29 class ymz280b_device
30 {
31 public:
32 ymz280b_device();
33
34 u8 read(offs_t offset);
35 void write(offs_t offset, u8 data);
36
37 void device_start(u8 *ext_mem);
38 void device_reset();
39
40 void sound_stream_update(s16 **outputs, int samples);
41
42 private:
43 /* struct describing a single playing ADPCM voice */
44 struct YMZ280BVoice
45 {
46 u8 playing; /* 1 if we are actively playing */
47 bool ended; /* indicate voice has ended in case samples_left is 0 */
48
49 u8 keyon; /* 1 if the key is on */
50 u8 looping; /* 1 if looping is enabled */
51 u8 mode; /* current playback mode */
52 u16 fnum; /* frequency */
53 u8 level; /* output level */
54 u8 pan; /* panning */
55
56 u32 start; /* start address, in nibbles */
57 u32 stop; /* stop address, in nibbles */
58 u32 loop_start; /* loop start address, in nibbles */
59 u32 loop_end; /* loop end address, in nibbles */
60 u32 position; /* current position, in nibbles */
61
62 s32 signal; /* current ADPCM signal */
63 s32 step; /* current ADPCM step */
64
65 s32 loop_signal; /* signal at loop start */
66 s32 loop_step; /* step at loop start */
67 u32 loop_count; /* number of loops so far */
68
69 s32 output_left; /* output volume (left) */
70 s32 output_right; /* output volume (right) */
71 s32 output_step; /* step value for frequency conversion */
72 s32 output_pos; /* current fractional position */
73 s16 last_sample; /* last sample output */
74 s16 curr_sample; /* current sample target */
75 u8 irq_schedule; /* 1 if the IRQ state is updated by timer */
76 };
77
78 void update_step(struct YMZ280BVoice *voice);
79 void update_volumes(struct YMZ280BVoice *voice);
80 int generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int samples);
81 int generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int samples);
82 int generate_pcm16(struct YMZ280BVoice *voice, s16 *buffer, int samples);
83 void write_to_register(int data);
84 int compute_status();
85
86 // internal state
87 struct YMZ280BVoice m_voice[8]; /* the 8 voices */
88 u8 m_current_register; /* currently accessible register */
89 u8 m_status_register; /* current status register */
90 u8 m_irq_mask; /* current IRQ mask */
91 u8 m_irq_enable; /* current IRQ enable */
92 u8 m_keyon_enable; /* key on enable */
93 u8 m_ext_mem_enable; /* external memory enable */
94 u8 m_ext_readlatch; /* external memory prefetched data */
95 u32 m_ext_mem_address_hi;
96 u32 m_ext_mem_address_mid;
97 u32 m_ext_mem_address; /* where the CPU can read the ROM */
98
99 u8 *m_ext_mem;
100
101 std::unique_ptr<s16[]> m_scratch;
102 };
103
104 #endif // MAME_SOUND_YMZ280B_H