Debian Codegraph @

src/engine/platform/nds.h

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef _NDS_H
21 #define _NDS_H
22
23 #include "../dispatch.h"
24 #include "sound/nds.hpp"
25
26 using namespace nds_sound_emu;
27
28 class DivPlatformNDS: public DivDispatch, public nds_sound_intf {
29 struct Channel: public SharedChannel<int> {
30 unsigned int audPos;
31 int sample, wave;
32 int panning, duty;
33 bool setPos, pcm, busy;
34 int macroVolMul;
35 Channel():
36 SharedChannel<int>(127),
37 audPos(0),
38 sample(-1),
39 wave(-1),
40 panning(64),
41 duty(0),
42 setPos(false),
43 pcm(false),
44 busy(false),
45 macroVolMul(64) {}
46 };
47 Channel chan[16];
48 DivDispatchOscBuffer* oscBuf[16];
49 bool isMuted[16];
50 bool isDSi;
51 int globalVolume;
52 int lastOut[2];
53 unsigned int* sampleOff;
54 bool* sampleLoaded;
55 struct QueuedWrite {
56 unsigned short addr;
57 unsigned char size;
58 unsigned int val;
59 QueuedWrite(): addr(0), size(0), val(0) {}
60 QueuedWrite(unsigned short a, unsigned char s, unsigned int v): addr(a), size(s), val(v) {}
61 };
62 FixedQueue<QueuedWrite,2048> writes;
63
64 unsigned char* sampleMem;
65 size_t sampleMemLen;
66 nds_sound_t nds;
67 DivMemoryComposition memCompo;
68 unsigned char regPool[288];
69 friend void putDispatchChip(void*,int);
70 friend void putDispatchChan(void*,int,int);
71
72 public:
73 virtual u8 read_byte(u32 addr) override;
74 virtual void write_byte(u32 addr, u8 data) override;
75
76 virtual void acquireDirect(blip_buffer_t** bb, size_t len) override;
77 virtual void postProcess(short* buf, int outIndex, size_t len, int sampleRate) override;
78 virtual int dispatch(DivCommand c) override;
79 virtual void* getChanState(int chan) override;
80 virtual DivMacroInt* getChanMacroInt(int ch) override;
81 virtual unsigned short getPan(int chan) override;
82 virtual DivDispatchOscBuffer* getOscBuffer(int chan) override;
83 virtual unsigned char* getRegisterPool() override;
84 virtual int getRegisterPoolSize() override;
85 virtual void reset() override;
86 virtual void forceIns() override;
87 virtual void tick(bool sysTick=true) override;
88 virtual void muteChannel(int ch, bool mute) override;
89 virtual float getPostAmp() override;
90 virtual int getOutputCount() override;
91 virtual bool hasAcquireDirect() override;
92 virtual void notifyInsChange(int ins) override;
93 virtual void notifyWaveChange(int wave) override;
94 virtual void notifyInsDeletion(void* ins) override;
95 virtual void poke(unsigned int addr, unsigned short val) override;
96 virtual void poke(std::vector<DivRegWrite>& wlist) override;
97 virtual const char** getRegisterSheet() override;
98 virtual const void* getSampleMem(int index = 0) override;
99 virtual size_t getSampleMemCapacity(int index = 0) override;
100 virtual size_t getSampleMemUsage(int index = 0) override;
101 virtual bool isSampleLoaded(int index, int sample) override;
102 virtual const DivMemoryComposition* getMemCompo(int index) override;
103 virtual void renderSamples(int chipID) override;
104 virtual void setFlags(const DivConfig& flags) override;
105 virtual int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags) override;
106 virtual void quit() override;
107 DivPlatformNDS();
108 ~DivPlatformNDS();
109 private:
110 void writeOutVol(int ch);
111 };
112
113 #endif