Debian Codegraph @

android/app/jni/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.hpp

raw
1 /*
2 License: Zlib
3 see https://gitlab.com/cam900/vgsound_emu/-/blob/main/LICENSE for more details
4
5 Copyright holder(s): cam900
6 Ensoniq ES5504 emulation core
7 */
8
9 #ifndef _VGSOUND_EMU_SRC_ES5504_HPP
10 #define _VGSOUND_EMU_SRC_ES5504_HPP
11
12 #pragma once
13
14 #include "es550x.hpp"
15
16 // ES5504 specific
17 class es5504_core : public es550x_shared_core
18 {
19 private:
20 // es5504 voice classes
21 class voice_t : public es550x_voice_t
22 {
23 public:
24 // constructor
25 voice_t(es5504_core &host)
26 : es550x_voice_t("es5504_voice", 20, 9, false)
27 , m_host(host)
28 , m_volume(0)
29 , m_out(0)
30 {
31 }
32
33 // internal state
34 virtual void reset() override;
35 virtual void fetch(u8 cycle) override;
36 virtual void tick(u8 voice) override;
37
38 // setters
39 inline void set_volume(u16 volume) { m_volume = volume; }
40
41 // getters
42 inline u16 volume() { return m_volume; }
43
44 inline s32 out() { return m_out; }
45
46 private:
47 void adc_exec();
48
49 // registers
50 es5504_core &m_host;
51 u16 m_volume = 0; // 12 bit Volume
52 s32 m_out = 0; // channel outputs
53 };
54
55 public:
56 // constructor
57 es5504_core(es550x_intf &intf)
58 : es550x_shared_core("es5504", 25, intf)
59 , m_voice{*this, *this, *this, *this, *this, *this, *this, *this, *this,
60 *this, *this, *this, *this, *this, *this, *this, *this, *this,
61 *this, *this, *this, *this, *this, *this, *this}
62 , m_adc(0)
63 {
64 m_out.fill(0);
65 }
66
67 // host interface
68 u16 host_r(u8 address);
69 void host_w(u8 address, u16 data);
70
71 // internal state
72 virtual void reset() override;
73 virtual void tick() override;
74
75 // less cycle accurate, but also less cpu heavy update routine
76 void tick_perf();
77
78 // 16 analog output channels
79 inline s32 out(u8 ch) { return m_out[ch & 0xf]; }
80
81 //-----------------------------------------------------------------
82 //
83 // for preview/debug purpose only, not for serious emulators
84 //
85 //-----------------------------------------------------------------
86
87 // bypass chips host interface for debug purpose only
88 u16 read(u8 address, bool cpu_access = false);
89 void write(u8 address, u16 data, bool cpu_access = false);
90
91 u16 regs_r(u8 page, u8 address, bool cpu_access = false);
92 void regs_w(u8 page, u8 address, u16 data, bool cpu_access = false);
93
94 u16 regs_r(u8 page, u8 address)
95 {
96 u8 prev = m_page;
97 m_page = page;
98 u16 ret = read(address, false);
99 m_page = prev;
100 return ret;
101 }
102
103 // per-voice outputs
104 inline s32 voice_out(u8 voice) { return (voice < 25) ? m_voice[voice].out() : 0; }
105
106 protected:
107 virtual inline u8 max_voices() override { return 25; }
108
109 virtual void voice_tick() override;
110
111 private:
112 std::array<voice_t, 25> m_voice; // 25 voices
113 u16 m_adc = 0; // ADC register
114 std::array<s32, 16> m_out; // 16 channel outputs
115 };
116
117 #endif