Debian Codegraph @

src/engine/platform/gbaminmod.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 _GBA_MINMOD_H
21 #define _GBA_MINMOD_H
22
23 #include "../dispatch.h"
24 #include "../waveSynth.h"
25
26 class DivPlatformGBAMinMod: public DivDispatch {
27 struct Channel: public SharedChannel<int> {
28 unsigned char echo;
29 unsigned int audPos, wtLen;
30 int sample, wave;
31 bool useWave, setPos, volChangedL, volChangedR, invertL, invertR;
32 int chPanL, chPanR;
33 int macroVolMul;
34 int macroPanMul;
35 DivWaveSynth ws;
36 Channel():
37 SharedChannel<int>(255),
38 echo(0),
39 audPos(0),
40 wtLen(1),
41 sample(-1),
42 wave(-1),
43 useWave(false),
44 setPos(false),
45 volChangedL(false),
46 volChangedR(false),
47 invertL(false),
48 invertR(false),
49 chPanL(255),
50 chPanR(255),
51 macroVolMul(256),
52 macroPanMul(127) {}
53 };
54 Channel chan[16];
55 DivDispatchOscBuffer* oscBuf[16];
56 bool isMuted[16];
57 unsigned int* sampleOff;
58 bool* sampleLoaded;
59 int volScale;
60 unsigned char chanMax;
61
62 // emulator part
63 unsigned int mixBufs;
64 unsigned int dacDepth;
65 unsigned int sampCycles;
66 unsigned int sampTimer;
67 unsigned int updCycles;
68 unsigned int updTimer;
69 unsigned int updCyclesTotal;
70 unsigned int sampsRendered;
71 signed char mixBuf[15*2][1024];
72 unsigned char mixOut[2][4];
73 short oscOut[16][4];
74 int chanOut[16][2];
75 size_t mixBufPage;
76 size_t mixBufReadPos;
77 size_t mixBufWritePos;
78 size_t mixBufOffset;
79 short sampL, sampR;
80
81 signed char* sampleMem;
82 size_t sampleMemLen;
83 // maximum wavetable length is currently hardcoded to 256
84 unsigned short regPool[16*16];
85 signed char wtMem[256*16];
86 DivMemoryComposition romMemCompo;
87 DivMemoryComposition mixMemCompo;
88 DivMemoryComposition wtMemCompo;
89
90 friend void putDispatchChip(void*,int);
91 friend void putDispatchChan(void*,int,int);
92
93 public:
94 void acquire(short** buf, size_t len);
95 int dispatch(DivCommand c);
96 void* getChanState(int chan);
97 DivMacroInt* getChanMacroInt(int ch);
98 unsigned short getPan(int chan);
99 DivSamplePos getSamplePos(int ch);
100 DivDispatchOscBuffer* getOscBuffer(int chan);
101 unsigned char* getRegisterPool();
102 int getRegisterPoolSize();
103 int getRegisterPoolDepth();
104 void reset();
105 void forceIns();
106 void tick(bool sysTick=true);
107 void muteChannel(int ch, bool mute);
108 int getOutputCount();
109 void notifyInsChange(int ins);
110 void notifyWaveChange(int wave);
111 void notifyInsDeletion(void* ins);
112 void poke(unsigned int addr, unsigned short val);
113 void poke(std::vector<DivRegWrite>& wlist);
114 const char** getRegisterSheet();
115 const void* getSampleMem(int index = 0);
116 size_t getSampleMemCapacity(int index = 0);
117 size_t getSampleMemUsage(int index = 0);
118 bool isSampleLoaded(int index, int sample);
119 const DivMemoryComposition* getMemCompo(int index);
120 void renderSamples(int chipID);
121 void setFlags(const DivConfig& flags);
122 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
123 void quit();
124 DivPlatformGBAMinMod();
125 ~DivPlatformGBAMinMod();
126
127 float maxCPU;
128 private:
129 void updateWave(int ch);
130 // emulator part
131 void resetMixer();
132 };
133
134 #endif