| 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 _X1_010_H |
| 21 |
#define _X1_010_H |
| 22 |
|
| 23 |
#include "../dispatch.h" |
| 24 |
#include "../engine.h" |
| 25 |
#include "../waveSynth.h" |
| 26 |
#include "vgsound_emu/src/x1_010/x1_010.hpp" |
| 27 |
|
| 28 |
class DivPlatformX1_010: public DivDispatch, public vgsound_emu_mem_intf { |
| 29 |
struct Channel: public SharedChannel<int> { |
| 30 |
struct Envelope { |
| 31 |
struct EnvFlag { |
| 32 |
unsigned char envEnable : 1; |
| 33 |
unsigned char envOneshot : 1; |
| 34 |
unsigned char envSplit : 1; |
| 35 |
unsigned char envHinvR : 1; |
| 36 |
unsigned char envVinvR : 1; |
| 37 |
unsigned char envHinvL : 1; |
| 38 |
unsigned char envVinvL : 1; |
| 39 |
void reset() { |
| 40 |
envEnable=0; |
| 41 |
envOneshot=0; |
| 42 |
envSplit=0; |
| 43 |
envHinvR=0; |
| 44 |
envVinvR=0; |
| 45 |
envHinvL=0; |
| 46 |
envVinvL=0; |
| 47 |
} |
| 48 |
EnvFlag(): |
| 49 |
envEnable(0), |
| 50 |
envOneshot(0), |
| 51 |
envSplit(0), |
| 52 |
envHinvR(0), |
| 53 |
envVinvR(0), |
| 54 |
envHinvL(0), |
| 55 |
envVinvL(0) {} |
| 56 |
}; |
| 57 |
int shape, period, slide, slidefrac; |
| 58 |
EnvFlag flag; |
| 59 |
void reset() { |
| 60 |
shape=-1; |
| 61 |
period=0; |
| 62 |
flag.reset(); |
| 63 |
} |
| 64 |
Envelope(): |
| 65 |
shape(-1), |
| 66 |
period(0), |
| 67 |
slide(0), |
| 68 |
slidefrac(0) {} |
| 69 |
}; |
| 70 |
int fixedFreq; |
| 71 |
int wave, sample; |
| 72 |
unsigned char pan, autoEnvNum, autoEnvDen; |
| 73 |
bool envChanged, furnacePCM, pcm, setPos; |
| 74 |
int lvol, rvol; |
| 75 |
int macroVolMul; |
| 76 |
unsigned char waveBank; |
| 77 |
unsigned int bankSlot; |
| 78 |
Envelope env; |
| 79 |
DivWaveSynth ws; |
| 80 |
void reset() { |
| 81 |
freq=baseFreq=pitch=pitch2=note=0; |
| 82 |
wave=sample=ins=-1; |
| 83 |
pan=255; |
| 84 |
autoEnvNum=autoEnvDen=0; |
| 85 |
active=false; |
| 86 |
insChanged=envChanged=freqChanged=true; |
| 87 |
keyOn=keyOff=inPorta=furnacePCM=pcm=setPos=false; |
| 88 |
vol=outVol=lvol=rvol=15; |
| 89 |
waveBank=0; |
| 90 |
} |
| 91 |
Channel(): |
| 92 |
SharedChannel<int>(15), |
| 93 |
fixedFreq(0), |
| 94 |
wave(-1), |
| 95 |
sample(-1), |
| 96 |
pan(255), |
| 97 |
autoEnvNum(0), |
| 98 |
autoEnvDen(0), |
| 99 |
envChanged(true), |
| 100 |
furnacePCM(false), |
| 101 |
pcm(false), |
| 102 |
setPos(false), |
| 103 |
lvol(15), |
| 104 |
rvol(15), |
| 105 |
macroVolMul(15), |
| 106 |
waveBank(0), |
| 107 |
bankSlot(0) {} |
| 108 |
}; |
| 109 |
Channel chan[16]; |
| 110 |
DivDispatchOscBuffer* oscBuf[16]; |
| 111 |
bool isMuted[16]; |
| 112 |
bool stereo=false; |
| 113 |
unsigned char* sampleMem; |
| 114 |
size_t sampleMemLen; |
| 115 |
unsigned char sampleBank; |
| 116 |
x1_010_core x1_010; |
| 117 |
|
| 118 |
bool isBanked=false; |
| 119 |
unsigned int bankSlot[8]; |
| 120 |
unsigned int* sampleOffX1; |
| 121 |
bool* sampleLoaded; |
| 122 |
|
| 123 |
DivMemoryComposition memCompo; |
| 124 |
|
| 125 |
unsigned char regPool[0x2000]; |
| 126 |
double NoteX1_010(int ch, int note); |
| 127 |
void updateWave(int ch); |
| 128 |
void updateEnvelope(int ch); |
| 129 |
friend void putDispatchChip(void*,int); |
| 130 |
friend void putDispatchChan(void*,int,int); |
| 131 |
public: |
| 132 |
u8 read_byte(u32 address); |
| 133 |
void acquire(short** buf, size_t len); |
| 134 |
int dispatch(DivCommand c); |
| 135 |
void* getChanState(int chan); |
| 136 |
DivMacroInt* getChanMacroInt(int ch); |
| 137 |
unsigned short getPan(int chan); |
| 138 |
DivDispatchOscBuffer* getOscBuffer(int chan); |
| 139 |
unsigned char* getRegisterPool(); |
| 140 |
int getRegisterPoolSize(); |
| 141 |
void reset(); |
| 142 |
void forceIns(); |
| 143 |
void tick(bool sysTick=true); |
| 144 |
void muteChannel(int ch, bool mute); |
| 145 |
int getOutputCount(); |
| 146 |
bool keyOffAffectsArp(int ch); |
| 147 |
float getPostAmp(); |
| 148 |
void setFlags(const DivConfig& flags); |
| 149 |
void notifyWaveChange(int wave); |
| 150 |
void notifyInsDeletion(void* ins); |
| 151 |
void poke(unsigned int addr, unsigned short val); |
| 152 |
void poke(std::vector<DivRegWrite>& wlist); |
| 153 |
const void* getSampleMem(int index = 0); |
| 154 |
size_t getSampleMemCapacity(int index = 0); |
| 155 |
size_t getSampleMemUsage(int index = 0); |
| 156 |
bool isSampleLoaded(int index, int sample); |
| 157 |
const DivMemoryComposition* getMemCompo(int index); |
| 158 |
void renderSamples(int chipID); |
| 159 |
const char** getRegisterSheet(); |
| 160 |
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); |
| 161 |
void quit(); |
| 162 |
DivPlatformX1_010(); |
| 163 |
~DivPlatformX1_010(); |
| 164 |
}; |
| 165 |
|
| 166 |
#endif |