| 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 _AY_H |
| 21 |
#define _AY_H |
| 22 |
#include "../dispatch.h" |
| 23 |
#include "../../fixedQueue.h" |
| 24 |
#include "sound/ay8910.h" |
| 25 |
extern "C" { |
| 26 |
#include "sound/atomicssg/ssg.h" |
| 27 |
} |
| 28 |
|
| 29 |
class DivPlatformAY8910: public DivDispatch { |
| 30 |
protected: |
| 31 |
const unsigned char AY8914RegRemap[16]={ |
| 32 |
0,4,1,5,2,6,9,8,11,12,13,3,7,10,14,15 |
| 33 |
}; |
| 34 |
inline unsigned char regRemap(unsigned char reg) { return intellivision?AY8914RegRemap[reg&0x0f]:reg&0x0f; } |
| 35 |
struct Channel: public SharedChannel<int> { |
| 36 |
struct PSGMode { |
| 37 |
// bit 4: timer FX |
| 38 |
// bit 3: DAC |
| 39 |
// bit 2: envelope |
| 40 |
// bit 1: noise |
| 41 |
// bit 0: tone |
| 42 |
unsigned char val; |
| 43 |
|
| 44 |
unsigned char getTone() { |
| 45 |
return (val&8)?0:(val&1); |
| 46 |
} |
| 47 |
|
| 48 |
unsigned char getNoise() { |
| 49 |
return (val&8)?0:(val&2); |
| 50 |
} |
| 51 |
|
| 52 |
unsigned char getEnvelope() { |
| 53 |
return (val&8)?0:(val&4); |
| 54 |
} |
| 55 |
|
| 56 |
unsigned char getTimerFX() { |
| 57 |
return (val&8)?0:(val&16); |
| 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 |
struct TFX { |
| 81 |
int period; |
| 82 |
float counter; |
| 83 |
int offset, den, num, mode, lowBound, out; |
| 84 |
TFX(): |
| 85 |
period(0), |
| 86 |
counter(0), |
| 87 |
offset(1), |
| 88 |
den(1), |
| 89 |
num(1), |
| 90 |
mode(0), |
| 91 |
lowBound(0), |
| 92 |
out(0) {} |
| 93 |
} tfx; |
| 94 |
|
| 95 |
unsigned char autoEnvNum, autoEnvDen; |
| 96 |
signed char konCycles; |
| 97 |
unsigned short fixedFreq; |
| 98 |
Channel(): |
| 99 |
SharedChannel<int>(15), |
| 100 |
curPSGMode(PSGMode(0)), |
| 101 |
nextPSGMode(PSGMode(1)), |
| 102 |
dac(DAC()), |
| 103 |
tfx(TFX()), |
| 104 |
autoEnvNum(0), |
| 105 |
autoEnvDen(0), |
| 106 |
konCycles(0), |
| 107 |
fixedFreq(0) {} |
| 108 |
}; |
| 109 |
Channel chan[3]; |
| 110 |
bool isMuted[3]; |
| 111 |
struct QueuedWrite { |
| 112 |
unsigned short addr; |
| 113 |
unsigned char val; |
| 114 |
bool addrOrVal; |
| 115 |
QueuedWrite(): addr(0), val(0), addrOrVal(false) {} |
| 116 |
QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {} |
| 117 |
}; |
| 118 |
FixedQueue<QueuedWrite,128> writes; |
| 119 |
ay8910_device* ay; |
| 120 |
DivDispatchOscBuffer* oscBuf[3]; |
| 121 |
unsigned char regPool[16]; |
| 122 |
unsigned char lastBusy; |
| 123 |
|
| 124 |
unsigned char sampleBank; |
| 125 |
unsigned char stereoSep; |
| 126 |
unsigned char selCore; |
| 127 |
|
| 128 |
ssg_t ay_atomic; |
| 129 |
|
| 130 |
int delay; |
| 131 |
int lastOut[2]; |
| 132 |
|
| 133 |
bool extMode; |
| 134 |
unsigned int extClock; |
| 135 |
int dacRate; |
| 136 |
unsigned char extDiv; |
| 137 |
unsigned char dacRateDiv; |
| 138 |
|
| 139 |
bool stereo, sunsoft, intellivision, clockSel, yamaha; |
| 140 |
bool ioPortA, ioPortB; |
| 141 |
unsigned char portAVal, portBVal; |
| 142 |
|
| 143 |
short oldWrites[16]; |
| 144 |
short pendingWrites[16]; |
| 145 |
unsigned char ayEnvMode; |
| 146 |
unsigned short ayEnvPeriod; |
| 147 |
short ayEnvSlideLow; |
| 148 |
short ayEnvSlide; |
| 149 |
|
| 150 |
void checkWrites(); |
| 151 |
void updateOutSel(bool immediate=false); |
| 152 |
|
| 153 |
void acquire_mame(blip_buffer_t** bb, size_t len); |
| 154 |
void acquire_atomic(short** buf, size_t len); |
| 155 |
|
| 156 |
friend void putDispatchChip(void*,int); |
| 157 |
friend void putDispatchChan(void*,int,int); |
| 158 |
|
| 159 |
public: |
| 160 |
void runDAC(int runRate=0, int advance=1); |
| 161 |
void runTFX(int runRate=0, int advance=1); |
| 162 |
void setExtClockDiv(unsigned int eclk=COLOR_NTSC, unsigned char ediv=8); |
| 163 |
void acquire(short** buf, size_t len); |
| 164 |
void acquireDirect(blip_buffer_t** bb, size_t len); |
| 165 |
void fillStream(std::vector<DivDelayedWrite>& stream, int sRate, size_t len); |
| 166 |
int dispatch(DivCommand c); |
| 167 |
void* getChanState(int chan); |
| 168 |
DivDispatchOscBuffer* getOscBuffer(int chan); |
| 169 |
int mapVelocity(int ch, float vel); |
| 170 |
float getGain(int ch, int vol); |
| 171 |
unsigned char* getRegisterPool(); |
| 172 |
int getRegisterPoolSize(); |
| 173 |
void setCore(unsigned char core); |
| 174 |
void flushWrites(); |
| 175 |
void reset(); |
| 176 |
void forceIns(); |
| 177 |
void tick(bool sysTick=true); |
| 178 |
void muteChannel(int ch, bool mute); |
| 179 |
void setFlags(const DivConfig& flags); |
| 180 |
int getOutputCount(); |
| 181 |
bool keyOffAffectsArp(int ch); |
| 182 |
bool hasAcquireDirect(); |
| 183 |
DivMacroInt* getChanMacroInt(int ch); |
| 184 |
DivSamplePos getSamplePos(int ch); |
| 185 |
bool getLegacyAlwaysSetVolume(); |
| 186 |
bool getDCOffRequired(); |
| 187 |
void notifyInsDeletion(void* ins); |
| 188 |
void poke(unsigned int addr, unsigned short val); |
| 189 |
void poke(std::vector<DivRegWrite>& wlist); |
| 190 |
const char** getRegisterSheet(); |
| 191 |
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); |
| 192 |
void quit(); |
| 193 |
DivPlatformAY8910(bool useExtMode=false, unsigned int eclk=COLOR_NTSC, unsigned char ediv=8, unsigned char ddiv=24): |
| 194 |
DivDispatch(), |
| 195 |
extMode(useExtMode), |
| 196 |
extClock(eclk), |
| 197 |
extDiv(ediv), |
| 198 |
dacRateDiv(ddiv) {} |
| 199 |
}; |
| 200 |
#endif |