Debian Codegraph @

android/app/jni/extern/vgsound_emu-modified/vgsound_emu/src/n163/n163.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 Namco 163 Sound emulation core
7 */
8
9 #ifndef _VGSOUND_EMU_SRC_N163_HPP
10 #define _VGSOUND_EMU_SRC_N163_HPP
11
12 #pragma once
13
14 #include "../core/core.hpp"
15
16 using namespace vgsound_emu;
17
18 class n163_core : public vgsound_emu_core
19 {
20 private:
21 // Address latch
22 class addr_latch_t : public vgsound_emu_core
23 {
24 public:
25 addr_latch_t()
26 : vgsound_emu_core("namco_163_addr_latch")
27 , m_addr(0)
28 , m_incr(0)
29 {
30 }
31
32 void reset()
33 {
34 m_addr = 0;
35 m_incr = 0;
36 }
37
38 // accessors
39 inline void write(u8 data)
40 {
41 m_addr = (data >> 0) & 0x7f;
42 m_incr = (data >> 7) & 0x01;
43 }
44
45 inline void addr_inc() { m_addr = (m_addr + 1) & 0x7f; }
46
47 // getters
48 inline u8 addr() { return m_addr; }
49
50 inline bool incr() { return m_incr; }
51
52 private:
53 u8 m_addr : 7;
54 u8 m_incr : 1;
55 };
56
57 public:
58 n163_core()
59 : vgsound_emu_core("namco_163")
60 , m_disable(false)
61 , m_voice_cycle(0x78)
62 , m_addr_latch(addr_latch_t())
63 , m_out(0)
64 , m_multiplex(true)
65 , m_acc(0)
66 {
67 m_ram.fill(0);
68 m_voice_out.fill(0);
69 }
70
71 // accessors, getters, setters
72 void addr_w(u8 data);
73 void data_w(u8 data, bool cpu_access = false);
74 u8 data_r(bool cpu_access = false);
75
76 inline void set_disable(bool disable) { m_disable = disable; }
77
78 // internal state
79 void reset();
80 void tick();
81
82 // sound output pin
83 inline s16 out() { return m_out; }
84
85 // register pool
86 inline u8 reg(u8 addr) { return m_ram[addr & 0x7f]; }
87
88 inline void set_multiplex(bool multiplex = true) { m_multiplex = multiplex; }
89
90 // preview only
91 inline u8 voice_cycle() { return m_voice_cycle; }
92
93 inline s16 voice_out(u8 voice)
94 {
95 return (voice <= ((m_ram[0x7f] >> 4) & 7)) ? m_voice_out[7 - voice] : 0;
96 }
97
98 private:
99 bool m_disable = false;
100 std::array<u8, 0x80> m_ram; // internal 128 byte RAM
101 u8 m_voice_cycle = 0x78; // Voice cycle for processing
102 addr_latch_t m_addr_latch; // address latch
103 s16 m_out = 0; // output
104
105 std::array<s16, 8> m_voice_out; // per-voice output, for preview only
106 // demultiplex related
107 bool m_multiplex = true; // multiplex flag, but less noisy = inaccurate!
108 s16 m_acc = 0; // accumulated output
109 };
110
111 #endif