Debian Codegraph @

BambooTracker/chip/scci/scci_wrapper.cpp

raw
1 /*
2 * Copyright (C) 2021 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "scci_wrapper.hpp"
27 #include "scci.hpp"
28 #include "SCCIDefines.hpp"
29
30 Scci::Scci() : man_(nullptr), chip_(nullptr) {}
31
32 Scci::~Scci()
33 {
34 if (chip_) man_->releaseSoundChip(chip_);
35 if (man_) man_->releaseInstance();
36 }
37
38 bool Scci::createInstance(RealChipInterfaceGeneratorFunc* f)
39 {
40 auto getManager = f ? reinterpret_cast<scci::SCCIFUNC>((*f)()) : nullptr;
41 if (f) delete f;
42 auto man = getManager ? getManager() : nullptr;
43 if (man) {
44 man_ = man;
45 man_->initializeInstance();
46 man_->reset();
47 chip_ = man_->getSoundChip(scci::SC_TYPE_YM2608, scci::SC_CLOCK_7987200);
48 if (!chip_) {
49 man_->releaseInstance();
50 man_ = nullptr;
51 return false;
52 }
53 return true;
54 }
55 else {
56 if (!chip_) return false;
57 man_->releaseSoundChip(chip_);
58 chip_ = nullptr;
59
60 man_->releaseInstance();
61 man_ = nullptr;
62 return false;
63 }
64 }
65
66 bool Scci::hasConnected() const
67 {
68 return (man_ != nullptr);
69 }
70
71 void Scci::reset()
72 {
73 if (chip_) chip_->init();
74 }
75
76 void Scci::setRegister(uint32_t addr, uint8_t data)
77 {
78 if (chip_) chip_->setRegister(addr, data);
79 }