| 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 |
OKI MSM6295 emulation core |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef _VGSOUND_EMU_SRC_MSM6295_HPP |
| 10 |
#define _VGSOUND_EMU_SRC_MSM6295_HPP |
| 11 |
|
| 12 |
#pragma once |
| 13 |
|
| 14 |
#include "../core/core.hpp" |
| 15 |
#include "../core/util/mem_intf.hpp" |
| 16 |
#include "../core/vox/vox.hpp" |
| 17 |
|
| 18 |
using namespace vgsound_emu; |
| 19 |
|
| 20 |
class msm6295_core : public vox_core |
| 21 |
{ |
| 22 |
friend class vgsound_emu_mem_intf; // common memory interface |
| 23 |
|
| 24 |
private: |
| 25 |
// Internal volume table, 9 step |
| 26 |
const s32 m_volume_table[9] = {32 /* 0.0dB */, |
| 27 |
22 /* -3.2dB */, |
| 28 |
16 /* -6.0dB */, |
| 29 |
11 /* -9.2dB */, |
| 30 |
8 /* -12.0dB */, |
| 31 |
6 /* -14.5dB */, |
| 32 |
4 /* -18.0dB */, |
| 33 |
3 /* -20.5dB */, |
| 34 |
2 /* -24.0dB */}; // scale out to 5 bit for optimization |
| 35 |
|
| 36 |
// msm6295 voice classes |
| 37 |
class voice_t : vox_decoder_t |
| 38 |
{ |
| 39 |
public: |
| 40 |
// constructor |
| 41 |
voice_t(msm6295_core &host) |
| 42 |
: vox_decoder_t(host, false) |
| 43 |
, m_host(host) |
| 44 |
, m_clock(0) |
| 45 |
, m_busy(false) |
| 46 |
, m_command(0) |
| 47 |
, m_addr(0) |
| 48 |
, m_nibble(0) |
| 49 |
, m_end(0) |
| 50 |
, m_volume(0) |
| 51 |
, m_out(0) |
| 52 |
, m_mute(false) |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
// internal state |
| 57 |
virtual void reset() override; |
| 58 |
void tick(); |
| 59 |
|
| 60 |
// Setters |
| 61 |
inline void set_command(u8 command) { m_command = command; } |
| 62 |
|
| 63 |
inline void set_volume(s32 volume) |
| 64 |
{ |
| 65 |
m_volume = (volume < 9) ? m_host.m_volume_table[volume] : 0; |
| 66 |
} |
| 67 |
|
| 68 |
inline void set_mute(bool mute) { m_mute = mute; } |
| 69 |
|
| 70 |
// Getters |
| 71 |
inline bool busy() { return m_busy; } |
| 72 |
|
| 73 |
inline s32 out() { return m_mute ? 0 : m_out; } |
| 74 |
|
| 75 |
private: |
| 76 |
// accessors, getters, setters |
| 77 |
// registers |
| 78 |
msm6295_core &m_host; // host core |
| 79 |
u16 m_clock = 0; // clock counter |
| 80 |
bool m_busy = false; // busy status |
| 81 |
u8 m_command = 0; // current command |
| 82 |
u32 m_addr = 0; // current address |
| 83 |
s8 m_nibble = 0; // current nibble |
| 84 |
u32 m_end = 0; // end address |
| 85 |
s32 m_volume = 0; // volume |
| 86 |
s32 m_out = 0; // output |
| 87 |
// for preview only |
| 88 |
bool m_mute = false; // mute flag |
| 89 |
}; |
| 90 |
|
| 91 |
public: |
| 92 |
// constructor |
| 93 |
msm6295_core(vgsound_emu_mem_intf &intf) |
| 94 |
: vox_core("msm6295") |
| 95 |
, m_voice{*this, *this, *this, *this} |
| 96 |
, m_intf(intf) |
| 97 |
, m_ss(false) |
| 98 |
, m_command(0) |
| 99 |
, m_next_command(0) |
| 100 |
, m_command_pending(false) |
| 101 |
, m_clock(0) |
| 102 |
, m_counter(0) |
| 103 |
, m_out(0) |
| 104 |
, m_out_temp(0) |
| 105 |
{ |
| 106 |
} |
| 107 |
|
| 108 |
// accessors, getters, setters |
| 109 |
u8 busy_r(); |
| 110 |
void command_w(u8 data); |
| 111 |
|
| 112 |
inline void ss_w(bool ss) { m_ss = ss; } // SS pin |
| 113 |
|
| 114 |
// internal state |
| 115 |
void reset(); |
| 116 |
void tick(); |
| 117 |
|
| 118 |
inline s32 out() { return m_out; } // built in 12 bit DAC |
| 119 |
|
| 120 |
// for preview |
| 121 |
inline void voice_mute(u8 voice, bool mute) |
| 122 |
{ |
| 123 |
if (voice < 4) |
| 124 |
{ |
| 125 |
m_voice[voice].set_mute(mute); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
inline s32 voice_out(u8 voice) { return (voice < 4) ? m_voice[voice].out() : 0; } |
| 130 |
|
| 131 |
private: |
| 132 |
std::array<voice_t, 4> m_voice; |
| 133 |
vgsound_emu_mem_intf &m_intf; // common memory interface |
| 134 |
|
| 135 |
bool m_ss = false; // SS pin controls divider, input clock / 33 * (SS ? 5 : 4) |
| 136 |
u8 m_command = 0; // Command byte |
| 137 |
u8 m_next_command = 0; // Next command |
| 138 |
bool m_command_pending = false; // command pending flag |
| 139 |
u16 m_clock = 0; // clock counter |
| 140 |
u16 m_counter = 0; // another clock counter |
| 141 |
s32 m_out = 0; // 12 bit output |
| 142 |
s32 m_out_temp = 0; // temporary buffer of above |
| 143 |
}; |
| 144 |
|
| 145 |
#endif |