Debian Codegraph @

src/engine/platform/ay8930.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 _AY8930_H
21 #define _AY8930_H
22 #include "../dispatch.h"
23 #include "../../fixedQueue.h"
24 #include "sound/ay8910.h"
25
26 class DivPlatformAY8930: public DivDispatch {
27 protected:
28 struct Channel: public SharedChannel<int> {
29 struct Envelope {
30 unsigned char mode;
31 unsigned short period;
32 short slideLow;
33 short slide;
34 Envelope():
35 mode(0),
36 period(0),
37 slideLow(0),
38 slide(0) {}
39 } envelope;
40
41 struct PSGMode {
42 // bit 3: DAC
43 // bit 2: envelope
44 // bit 1: noise
45 // bit 0: tone
46 unsigned char val;
47
48 unsigned char getTone() {
49 return (val&8)?0:(val&1);
50 }
51
52 unsigned char getNoise() {
53 return (val&8)?0:(val&2);
54 }
55
56 unsigned char getEnvelope() {
57 return (val&8)?0:(val&4);
58 }
59
60 PSGMode(unsigned char v=1):
61 val(v) {}
62 };
63 PSGMode curPSGMode;
64 PSGMode nextPSGMode;
65
66 struct DAC {
67 int sample, rate, period, pos, out;
68 bool furnaceDAC, setPos;
69
70 DAC():
71 sample(-1),
72 rate(0),
73 period(0),
74 pos(0),
75 out(0),
76 furnaceDAC(false),
77 setPos(false) {}
78 } dac;
79
80 unsigned char autoEnvNum, autoEnvDen, duty, autoNoiseMode;
81 signed char konCycles, autoNoiseOff;
82 unsigned short fixedFreq;
83 Channel():
84 SharedChannel<int>(31),
85 envelope(Envelope()),
86 curPSGMode(PSGMode(0)),
87 nextPSGMode(PSGMode(1)),
88 dac(DAC()),
89 autoEnvNum(0),
90 autoEnvDen(0),
91 duty(4),
92 autoNoiseMode(0),
93 konCycles(0),
94 autoNoiseOff(0),
95 fixedFreq(0) {}
96 };
97 Channel chan[3];
98 bool isMuted[3];
99 struct QueuedWrite {
100 unsigned short addr;
101 unsigned char val;
102 bool addrOrVal;
103 QueuedWrite(): addr(0), val(0), addrOrVal(false) {}
104 QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {}
105 };
106 FixedQueue<QueuedWrite,128> writes;
107 ay8930_device* ay;
108 DivDispatchOscBuffer* oscBuf[3];
109 unsigned char regPool[32];
110 unsigned char ayNoiseAnd, ayNoiseOr;
111 unsigned char stereoSep;
112 bool bank;
113
114 unsigned char sampleBank;
115
116 int delay;
117 int lastOut[2];
118
119 bool extMode, stereo, clockSel;
120 bool ioPortA, ioPortB;
121 unsigned char portAVal, portBVal;
122
123 short oldWrites[32];
124 short pendingWrites[32];
125
126 void runDAC(int advance);
127 void checkWrites();
128 void updateOutSel(bool immediate=false);
129 void immWrite(unsigned char a, unsigned char v);
130
131 friend void putDispatchChip(void*,int);
132 friend void putDispatchChan(void*,int,int);
133
134 public:
135 void acquireDirect(blip_buffer_t** bb, size_t len);
136 int dispatch(DivCommand c);
137 void* getChanState(int chan);
138 DivDispatchOscBuffer* getOscBuffer(int chan);
139 int mapVelocity(int ch, float vel);
140 float getGain(int ch, int vol);
141 unsigned char* getRegisterPool();
142 int getRegisterPoolSize();
143 void reset();
144 void forceIns();
145 void tick(bool sysTick=true);
146 void muteChannel(int ch, bool mute);
147 void setFlags(const DivConfig& flags);
148 int getOutputCount();
149 bool keyOffAffectsArp(int ch);
150 bool hasAcquireDirect();
151 DivMacroInt* getChanMacroInt(int ch);
152 DivSamplePos getSamplePos(int ch);
153 bool getLegacyAlwaysSetVolume();
154 void notifyInsDeletion(void* ins);
155 void poke(unsigned int addr, unsigned short val);
156 void poke(std::vector<DivRegWrite>& wlist);
157 const char** getRegisterSheet();
158 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
159 void quit();
160 };
161 #endif