Debian Codegraph @

src/engine/platform/amiga.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 _AMIGA_H
21 #define _AMIGA_H
22
23 #include "../dispatch.h"
24 #include "../../fixedQueue.h"
25 #include "../waveSynth.h"
26
27 class DivPlatformAmiga: public DivDispatch {
28 struct Channel: public SharedChannel<signed char> {
29 unsigned short audLen, irLocL, irLocH, irLen;
30 unsigned int audPos;
31 int audSub;
32 unsigned char volPos;
33 int sample, wave;
34 bool useWave, setPos, useV, useP, dmaOn, audDatClock, writeVol, updateWave;
35 DivWaveSynth ws;
36 Channel():
37 SharedChannel<signed char>(64),
38 audLen(0),
39 irLocL(0),
40 irLocH(0),
41 irLen(2),
42 audPos(0),
43 audSub(0),
44 volPos(0),
45 sample(-1),
46 wave(-1),
47 useWave(false),
48 setPos(false),
49 useV(false),
50 useP(false),
51 dmaOn(false),
52 audDatClock(false),
53 writeVol(true),
54 updateWave(true) {}
55 };
56 Channel chan[4];
57 DivDispatchOscBuffer* oscBuf[4];
58 bool isMuted[4];
59 bool bypassLimits;
60 bool amigaModel;
61 bool filterOn;
62 bool updateADKCon;
63 short delay;
64 short oldOut[2];
65
66 struct Amiga {
67 // register state
68 bool audInt[4]; // interrupt on
69 bool audIr[4]; // interrupt request
70 bool audEn[4]; // audio DMA on
71 bool mustDMA[4]; // audio DMA must run
72 bool useP[4]; // period modulation
73 bool useV[4]; // volume modulation
74
75 bool dmaEn;
76
77 unsigned int audLoc[4]; // address
78 unsigned short audLen[4]; // length
79 unsigned short audPer[4]; // period
80 unsigned char audVol[4]; // volume
81 signed char audDat[2][4]; // data
82 signed char nextOut[4];
83 unsigned short nextOut2[4];
84
85
86 // internal state
87 int audTick[4]; // tick of period
88 unsigned int dmaLoc[4]; // address
89 unsigned short dmaLen[4]; // position
90
91 bool audByte[4]; // which byte of audDat to output
92 bool audWord[4]; // for P/V
93 bool incLoc[4]; // whether dmaLoc/dmaLen should be updated
94 unsigned char volPos; // position of volume PWM
95 unsigned short hPos; // horizontal position of beam
96 unsigned char state[4]; // current channel state
97
98 void write(unsigned short addr, unsigned short val);
99
100 Amiga() {
101 memset(this,0,sizeof(*this));
102 }
103 } amiga;
104
105 int filter[2][4];
106 int filtConst;
107 int filtConstOff, filtConstOn;
108 int chipMem, chipMask;
109
110 unsigned char volTable[64][64];
111
112 unsigned int* sampleOff;
113 bool* sampleLoaded;
114
115 unsigned short regPool[256];
116
117 DivMemoryComposition memCompo;
118
119 unsigned char* sampleMem;
120 size_t sampleMemLen;
121
122 int sep1, sep2;
123
124 struct QueuedWrite {
125 unsigned short addr;
126 unsigned short val;
127 QueuedWrite(): addr(0), val(9) {}
128 QueuedWrite(unsigned short a, unsigned short v): addr(a), val(v) {}
129 };
130 FixedQueue<QueuedWrite,512> writes;
131
132 friend void putDispatchChip(void*,int);
133 friend void putDispatchChan(void*,int,int);
134 friend class DivExportAmigaValidation;
135
136 void irq(int ch);
137 void rWrite(unsigned short addr, unsigned short val);
138 void updateWave(int ch);
139
140 public:
141 void acquire(short** buf, size_t len);
142 void acquireDirect(blip_buffer_t** bb, size_t len);
143 void postProcess(short* buf, int outIndex, size_t len, int sampleRate);
144 int dispatch(DivCommand c);
145 void* getChanState(int chan);
146 DivDispatchOscBuffer* getOscBuffer(int chan);
147 unsigned char* getRegisterPool();
148 int getRegisterPoolSize();
149 int getRegisterPoolDepth();
150 void reset();
151 void forceIns();
152 void tick(bool sysTick=true);
153 void muteChannel(int ch, bool mute);
154 int getOutputCount();
155 bool keyOffAffectsArp(int ch);
156 bool hasAcquireDirect();
157 DivMacroInt* getChanMacroInt(int ch);
158 DivSamplePos getSamplePos(int ch);
159 void setFlags(const DivConfig& flags);
160 void notifyInsChange(int ins);
161 void notifyWaveChange(int wave);
162 void notifyInsDeletion(void* ins);
163 void renderSamples(int chipID);
164 void poke(unsigned int addr, unsigned short val);
165 void poke(std::vector<DivRegWrite>& wlist);
166 const char** getRegisterSheet();
167 const void* getSampleMem(int index=0);
168 size_t getSampleMemCapacity(int index=0);
169 size_t getSampleMemUsage(int index=0);
170 bool isSampleLoaded(int index, int sample);
171 const DivMemoryComposition* getMemCompo(int index);
172 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
173 void quit();
174 DivPlatformAmiga();
175 ~DivPlatformAmiga();
176 };
177
178 #endif