Debian Codegraph @

src/engine/platform/snes.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 _SNES_H
21 #define _SNES_H
22
23 #include "../dispatch.h"
24 #include "../waveSynth.h"
25 #include "../../fixedQueue.h"
26 #include "sound/snes/SPC_DSP.h"
27
28 class DivPlatformSNES: public DivDispatch {
29 struct Channel: public SharedChannel<int> {
30 unsigned int audPos;
31 int sample, wave;
32 int panL, panR;
33 bool useWave, setPos, noise, echo, pitchMod, invertL, invertR, shallWriteVol, shallWriteEnv;
34 int wtLen;
35 DivInstrumentSNES state;
36 DivWaveSynth ws;
37 Channel():
38 SharedChannel<int>(127),
39 audPos(0),
40 sample(-1),
41 wave(-1),
42 panL(127),
43 panR(127),
44 useWave(false),
45 setPos(false),
46 noise(false),
47 echo(false),
48 pitchMod(false),
49 invertL(false),
50 invertR(false),
51 shallWriteVol(false),
52 shallWriteEnv(false),
53 wtLen(16) {}
54 };
55 Channel chan[8];
56 DivDispatchOscBuffer* oscBuf[8];
57 bool isMuted[8];
58 int globalVolL, globalVolR;
59 unsigned char noiseFreq;
60 signed char delay;
61 signed char echoVolL, echoVolR, echoFeedback;
62 signed char dryVolL, dryVolR;
63 signed char echoFIR[8];
64 unsigned char echoDelay;
65 size_t sampleTableBase;
66 bool writeControl;
67 bool writeNoise;
68 bool writePitchMod;
69 bool writeEcho;
70 bool writeDryVol;
71 bool echoOn;
72 bool interpolationOff;
73 bool antiClick;
74
75 bool initEchoOn;
76 signed char initEchoVolL;
77 signed char initEchoVolR;
78 signed char initEchoFeedback;
79 signed char initEchoFIR[8];
80 unsigned char initEchoDelay;
81 unsigned char initEchoMask;
82
83 struct QueuedWrite {
84 unsigned char addr;
85 unsigned char val;
86 unsigned char delay;
87 unsigned char padding;
88 QueuedWrite(): addr(0), val(0), delay(0), padding(0) {}
89 QueuedWrite(unsigned char a, unsigned char v, unsigned char d=0): addr(a), val(v), delay(d), padding(0) {}
90 };
91 FixedQueue<QueuedWrite,256> writes;
92
93 signed char sampleMem[65536];
94 signed char copyOfSampleMem[65536];
95 size_t sampleMemLen;
96 unsigned int* sampleOff;
97 bool* sampleLoaded;
98 DivMemoryComposition memCompo;
99 unsigned char regPool[0x80];
100 SPC_DSP dsp;
101 friend void putDispatchChan(void*,int,int);
102
103 public:
104 void acquire(short** buf, size_t len);
105 int dispatch(DivCommand c);
106 void* getChanState(int chan);
107 DivMacroInt* getChanMacroInt(int ch);
108 unsigned short getPan(int chan);
109 void getPaired(int ch, std::vector<DivChannelPair>& ret);
110 DivChannelModeHints getModeHints(int chan);
111 DivSamplePos getSamplePos(int ch);
112 DivDispatchOscBuffer* getOscBuffer(int chan);
113 unsigned char* getRegisterPool();
114 int getRegisterPoolSize();
115 void reset();
116 void forceIns();
117 void tick(bool sysTick=true);
118 void muteChannel(int ch, bool mute);
119 int getOutputCount();
120 void notifyInsChange(int ins);
121 void notifyWaveChange(int wave);
122 void setFlags(const DivConfig& flags);
123 void notifyInsDeletion(void* ins);
124 void poke(unsigned int addr, unsigned short val);
125 void poke(std::vector<DivRegWrite>& wlist);
126 const char** getRegisterSheet();
127 const void* getSampleMem(int index = 0);
128 size_t getSampleMemCapacity(int index = 0);
129 size_t getSampleMemUsage(int index = 0);
130 bool isSampleLoaded(int index, int sample);
131 const DivMemoryComposition* getMemCompo(int index);
132 void renderSamples(int chipID);
133 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
134 void quit();
135 DivPlatformSNES();
136 ~DivPlatformSNES();
137 private:
138 void updateWave(int ch);
139 void writeOutVol(int ch);
140 void writeEnv(int ch);
141 void initEcho();
142 };
143
144 #endif