Debian Codegraph @

android/app/jni/extern/vgsound_emu-modified/vgsound_emu/src/k007232/k007232.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 Konami K007232 core
7 */
8
9 #ifndef _VGSOUND_EMU_SRC_K007232_HPP
10 #define _VGSOUND_EMU_SRC_K007232_HPP
11
12 #pragma once
13
14 #include "../core/core.hpp"
15
16 using namespace vgsound_emu;
17
18 class k007232_intf : public vgsound_emu_core
19 {
20 public:
21 k007232_intf()
22 : vgsound_emu_core("k007232_intf")
23 {
24 }
25
26 // NE pin is executing voice number, and used for per-voice sample bank.
27 virtual u8 read_sample(u8 ne, u32 address) { return 0; }
28
29 // SLEV pin actived when 0x0c register accessed
30 virtual void write_slev(u8 out) {}
31 };
32
33 class k007232_core : public vgsound_emu_core
34 {
35 friend class k007232_intf; // k007232 specific interface
36
37 private:
38 class voice_t : public vgsound_emu_core
39 {
40 public:
41 // constructor
42 voice_t(k007232_core &host)
43 : vgsound_emu_core("k007232_voice")
44 , m_host(host)
45 , m_busy(false)
46 , m_loop(false)
47 , m_pitch(0)
48 , m_start(0)
49 , m_counter(0)
50 , m_addr(0)
51 , m_data(0)
52 , m_out(0)
53 {
54 }
55
56 // internal state
57 void reset();
58 void tick(u8 ne, int cycles);
59
60 // accessors
61 void write(u8 address, u8 data);
62 void keyon();
63
64 // setters
65 inline void set_loop(bool loop) { m_loop = loop; }
66
67 // getters
68 inline s8 out() { return m_out; }
69
70 public:
71 // registers
72 k007232_core &m_host;
73 bool m_busy = false; // busy status
74 bool m_loop = false; // loop flag
75 u16 m_pitch = 0; // pitch, frequency divider
76 u32 m_start = 0; // start position when keyon or loop start position at
77 // when reach end marker if loop enabled
78 u16 m_counter = 0; // frequency counter
79 u32 m_addr = 0; // current address
80 u8 m_data = 0; // current data
81 s8 m_out = 0; // current output (7 bit unsigned)
82 };
83
84 public:
85 // constructor
86 k007232_core(k007232_intf &intf)
87 : vgsound_emu_core("k007232")
88 , m_voice{*this, *this}
89 , m_intf(intf)
90 {
91 m_reg.fill(0);
92 }
93
94 // host accessors
95 void keyon(u8 voice) { m_voice[voice & 1].keyon(); }
96
97 void write(u8 address, u8 data);
98
99 // internal state
100 void reset();
101 void tick(int cycles);
102
103 // output for each voices, ASD/BSD pin
104 inline s32 output(u8 voice) { return m_voice[voice & 1].out(); }
105
106 // getters for debug, trackers, etc
107 inline u8 reg_r(u8 address) { return m_reg[address & 0xf]; }
108
109 public:
110 std::array<voice_t, 2> m_voice;
111
112 k007232_intf &m_intf; // common memory interface
113
114 std::array<u8, 16> m_reg; // register pool
115 };
116
117 #endif