1 /*
2 * Interfaces over Yamaha OPL3 (YMF262) chip emulators
3 *
4 * Copyright (c) 2017-2020 Vitaly Novichkov (Wohlstand)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "nuked_opl3.h"
22 #include "nuked/nukedopl3.h"
23 #include <cstring>
24
NukedOPL3()25 NukedOPL3::NukedOPL3() :
26 OPLChipBaseT()
27 {
28 m_chip = new opl3_chip;
29 setRate(m_rate);
30 }
31
~NukedOPL3()32 NukedOPL3::~NukedOPL3()
33 {
34 opl3_chip *chip_r = reinterpret_cast<opl3_chip*>(m_chip);
35 delete chip_r;
36 }
37
setRate(uint32_t rate)38 void NukedOPL3::setRate(uint32_t rate)
39 {
40 OPLChipBaseT::setRate(rate);
41 opl3_chip *chip_r = reinterpret_cast<opl3_chip*>(m_chip);
42 std::memset(chip_r, 0, sizeof(opl3_chip));
43 OPL3_Reset(chip_r, rate);
44 }
45
reset()46 void NukedOPL3::reset()
47 {
48 OPLChipBaseT::reset();
49 opl3_chip *chip_r = reinterpret_cast<opl3_chip*>(m_chip);
50 std::memset(chip_r, 0, sizeof(opl3_chip));
51 OPL3_Reset(chip_r, m_rate);
52 }
53
writeReg(uint16_t addr,uint8_t data)54 void NukedOPL3::writeReg(uint16_t addr, uint8_t data)
55 {
56 opl3_chip *chip_r = reinterpret_cast<opl3_chip*>(m_chip);
57 OPL3_WriteRegBuffered(chip_r, addr, data);
58 }
59
writePan(uint16_t addr,uint8_t data)60 void NukedOPL3::writePan(uint16_t addr, uint8_t data)
61 {
62 opl3_chip *chip_r = reinterpret_cast<opl3_chip*>(m_chip);
63 OPL3_WritePan(chip_r, addr, data);
64 }
65
nativeGenerate(int16_t * frame)66 void NukedOPL3::nativeGenerate(int16_t *frame)
67 {
68 opl3_chip *chip_r = reinterpret_cast<opl3_chip*>(m_chip);
69 OPL3_Generate(chip_r, frame);
70 }
71
emulatorName()72 const char *NukedOPL3::emulatorName()
73 {
74 return "Nuked OPL3 (v 1.8)";
75 }
76
chipType()77 OPLChipBase::ChipType NukedOPL3::chipType()
78 {
79 return CHIPTYPE_OPL3;
80 }
81