2022-04-20 16:52:37 +00:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
|
|
|
* Copyright (C) 2021-2022 tildearrow and contributors
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ES5506_H
|
|
|
|
#define _ES5506_H
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../dispatch.h"
|
|
|
|
#include "../engine.h"
|
|
|
|
#include <queue>
|
|
|
|
#include "../macroInt.h"
|
|
|
|
#include "../sample.h"
|
2022-09-25 09:32:34 +00:00
|
|
|
#include "vgsound_emu/src/es550x/es5506.hpp"
|
2022-04-20 16:52:37 +00:00
|
|
|
|
|
|
|
class DivPlatformES5506: public DivDispatch, public es550x_intf {
|
2022-12-14 05:13:17 +00:00
|
|
|
struct Channel : public SharedChannel<unsigned int> {
|
2022-04-20 16:52:37 +00:00
|
|
|
struct PCM {
|
2022-05-22 09:24:17 +00:00
|
|
|
bool isNoteMap;
|
2022-04-30 14:45:05 +00:00
|
|
|
int index, next;
|
2022-05-10 15:16:20 +00:00
|
|
|
int note;
|
2022-04-26 03:04:23 +00:00
|
|
|
double freqOffs;
|
2022-05-10 15:16:20 +00:00
|
|
|
double nextFreqOffs;
|
2023-01-12 14:31:56 +00:00
|
|
|
bool pause, direction;
|
2022-04-20 16:52:37 +00:00
|
|
|
unsigned int bank;
|
2022-04-26 03:04:23 +00:00
|
|
|
unsigned int start;
|
|
|
|
unsigned int end;
|
|
|
|
unsigned int length;
|
2022-04-20 16:52:37 +00:00
|
|
|
unsigned int loopStart;
|
|
|
|
unsigned int loopEnd;
|
2022-10-22 08:19:39 +00:00
|
|
|
unsigned int nextPos;
|
2022-04-20 16:52:37 +00:00
|
|
|
DivSampleLoopMode loopMode;
|
|
|
|
PCM():
|
2022-05-22 09:24:17 +00:00
|
|
|
isNoteMap(false),
|
2022-04-20 16:52:37 +00:00
|
|
|
index(-1),
|
2022-04-30 14:45:05 +00:00
|
|
|
next(-1),
|
2022-05-10 15:16:20 +00:00
|
|
|
note(0),
|
2022-04-26 03:04:23 +00:00
|
|
|
freqOffs(1.0),
|
2022-05-10 15:16:20 +00:00
|
|
|
nextFreqOffs(1.0),
|
2022-05-17 18:09:55 +00:00
|
|
|
pause(false),
|
2022-12-15 08:35:01 +00:00
|
|
|
direction(false),
|
2022-04-20 16:52:37 +00:00
|
|
|
bank(0),
|
2022-04-26 03:04:23 +00:00
|
|
|
start(0),
|
|
|
|
end(0),
|
|
|
|
length(0),
|
2022-04-20 16:52:37 +00:00
|
|
|
loopStart(0),
|
|
|
|
loopEnd(0),
|
2022-10-22 08:19:39 +00:00
|
|
|
nextPos(0),
|
2022-09-25 09:32:34 +00:00
|
|
|
loopMode(DIV_SAMPLE_LOOP_MAX) {}
|
2022-04-20 16:52:37 +00:00
|
|
|
} pcm;
|
2022-12-13 05:53:00 +00:00
|
|
|
int nextFreq, nextNote, currNote, wave;
|
2022-05-03 18:32:26 +00:00
|
|
|
unsigned int volMacroMax, panMacroMax;
|
2022-12-13 05:53:00 +00:00
|
|
|
bool useWave, isReverseLoop;
|
2022-05-22 09:24:17 +00:00
|
|
|
unsigned int cr;
|
2022-04-30 14:45:05 +00:00
|
|
|
|
2022-05-10 15:16:20 +00:00
|
|
|
struct NoteChanged { // Note changed flags
|
|
|
|
union { // pack flag bits in single byte
|
|
|
|
struct { // flag bits
|
|
|
|
unsigned char offs: 1; // frequency offset
|
|
|
|
unsigned char note: 1; // note
|
|
|
|
unsigned char freq: 1; // base frequency
|
|
|
|
unsigned char dummy: 5; // dummy for bit padding
|
|
|
|
};
|
|
|
|
unsigned char changed; // Packed flags are stored here
|
|
|
|
};
|
|
|
|
|
|
|
|
NoteChanged() :
|
|
|
|
changed(0) {}
|
|
|
|
} noteChanged;
|
|
|
|
|
2022-04-30 14:45:05 +00:00
|
|
|
struct VolChanged { // Volume changed flags
|
|
|
|
union { // pack flag bits in single byte
|
|
|
|
struct { // flag bits
|
|
|
|
unsigned char lVol: 1; // left volume
|
|
|
|
unsigned char rVol: 1; // right volume
|
2023-01-12 14:31:56 +00:00
|
|
|
unsigned char ca: 1; // Channel assignment
|
|
|
|
unsigned char dummy: 5; // dummy for bit padding
|
2022-04-30 14:45:05 +00:00
|
|
|
};
|
|
|
|
unsigned char changed; // Packed flags are stored here
|
|
|
|
};
|
|
|
|
|
|
|
|
VolChanged() :
|
|
|
|
changed(0) {}
|
|
|
|
} volChanged;
|
2022-04-26 03:04:23 +00:00
|
|
|
|
|
|
|
struct FilterChanged { // Filter changed flags
|
|
|
|
union { // pack flag bits in single byte
|
|
|
|
struct { // flag bits
|
|
|
|
unsigned char mode: 1; // Filter mode
|
|
|
|
unsigned char k1: 1; // K1
|
|
|
|
unsigned char k2: 1; // K2
|
|
|
|
unsigned char dummy: 5; // dummy for bit padding
|
|
|
|
};
|
|
|
|
unsigned char changed; // Packed flags are stored here
|
|
|
|
};
|
|
|
|
|
|
|
|
FilterChanged():
|
|
|
|
changed(0) {}
|
|
|
|
} filterChanged;
|
|
|
|
|
|
|
|
struct EnvChanged { // Envelope changed flags
|
|
|
|
union { // pack flag bits in single byte
|
|
|
|
struct { // flag bits
|
|
|
|
unsigned char ecount: 1; // Envelope count
|
|
|
|
unsigned char lVRamp: 1; // Left volume Ramp
|
|
|
|
unsigned char rVRamp: 1; // Right volume Ramp
|
|
|
|
unsigned char k1Ramp: 1; // K1 Ramp w/Slow flag
|
|
|
|
unsigned char k2Ramp: 1; // K2 Ramp w/Slow flag
|
|
|
|
unsigned char dummy: 3; // dummy for bit padding
|
|
|
|
};
|
|
|
|
unsigned char changed; // Packed flags are stored here
|
|
|
|
};
|
|
|
|
|
|
|
|
EnvChanged():
|
|
|
|
changed(0) {}
|
|
|
|
} envChanged;
|
|
|
|
|
2022-05-24 15:52:00 +00:00
|
|
|
struct PCMChanged {
|
2022-05-22 09:24:17 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
unsigned char index: 1; // sample index
|
|
|
|
unsigned char slice: 1; // transwave slice
|
|
|
|
unsigned char position: 1; // sample position in memory
|
|
|
|
unsigned char loopBank: 1; // Loop mode and Bank
|
2022-10-22 08:19:39 +00:00
|
|
|
unsigned char dummy: 4; // dummy for bit padding
|
2022-05-22 09:24:17 +00:00
|
|
|
};
|
|
|
|
unsigned char changed;
|
|
|
|
};
|
2022-10-29 12:49:31 +00:00
|
|
|
PCMChanged():
|
|
|
|
changed(0) {}
|
2022-05-22 09:24:17 +00:00
|
|
|
} pcmChanged;
|
|
|
|
|
2022-10-29 12:49:31 +00:00
|
|
|
struct Overwrite {
|
|
|
|
DivInstrumentES5506::Filter filter;
|
|
|
|
DivInstrumentES5506::Envelope envelope;
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
// overwrited flag
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
unsigned char mode: 1; // filter mode
|
|
|
|
unsigned char k1: 1; // k1
|
|
|
|
unsigned char k2: 1; // k2
|
|
|
|
unsigned char ecount: 1; // envelope count
|
|
|
|
unsigned char lVRamp: 1; // left volume ramp
|
|
|
|
unsigned char rVRamp: 1; // right volume ramp
|
|
|
|
unsigned char k1Ramp: 1; // k1 ramp
|
|
|
|
unsigned char k2Ramp: 1; // k2 ramp
|
|
|
|
};
|
|
|
|
unsigned char overwrited;
|
|
|
|
};
|
|
|
|
State():
|
|
|
|
overwrited(0) {}
|
|
|
|
} state;
|
|
|
|
|
|
|
|
Overwrite():
|
|
|
|
filter(DivInstrumentES5506::Filter()),
|
|
|
|
envelope(DivInstrumentES5506::Envelope()),
|
|
|
|
state(State()) {}
|
|
|
|
} overwrite;
|
|
|
|
|
2023-01-12 14:31:56 +00:00
|
|
|
unsigned char ca;
|
2022-04-26 03:04:23 +00:00
|
|
|
signed int k1Offs, k2Offs;
|
2022-05-03 02:07:50 +00:00
|
|
|
signed int k1Slide, k2Slide;
|
|
|
|
signed int k1Prev, k2Prev;
|
2022-12-13 05:53:00 +00:00
|
|
|
unsigned int lVol, rVol;
|
|
|
|
unsigned int outLVol, outRVol;
|
2022-04-29 17:32:55 +00:00
|
|
|
unsigned int resLVol, resRVol;
|
2022-10-29 12:49:31 +00:00
|
|
|
signed int oscOut;
|
2022-04-20 16:52:37 +00:00
|
|
|
DivInstrumentES5506::Filter filter;
|
|
|
|
DivInstrumentES5506::Envelope envelope;
|
2022-12-14 05:13:17 +00:00
|
|
|
virtual void macroInit(DivInstrument* which) override {
|
|
|
|
SharedChannel<unsigned int>::macroInit(which);
|
2022-04-28 14:30:50 +00:00
|
|
|
if (std.ex1.mode==2) {
|
|
|
|
k1Offs=0;
|
|
|
|
}
|
|
|
|
if (std.ex1.mode==2) {
|
|
|
|
k2Offs=0;
|
|
|
|
}
|
2022-05-03 02:07:50 +00:00
|
|
|
k1Prev=0xffff;
|
|
|
|
k2Prev=0xffff;
|
2022-04-28 14:30:50 +00:00
|
|
|
}
|
2022-04-20 16:52:37 +00:00
|
|
|
Channel():
|
2022-12-14 05:13:17 +00:00
|
|
|
SharedChannel<unsigned int>(0xff),
|
2022-10-29 12:49:31 +00:00
|
|
|
pcm(PCM()),
|
2022-05-10 15:16:20 +00:00
|
|
|
nextFreq(0),
|
|
|
|
nextNote(0),
|
2022-05-31 04:48:35 +00:00
|
|
|
currNote(0),
|
2022-04-26 03:54:11 +00:00
|
|
|
wave(-1),
|
2022-05-03 18:32:26 +00:00
|
|
|
volMacroMax(0xffff),
|
|
|
|
panMacroMax(0xffff),
|
2022-04-28 14:30:50 +00:00
|
|
|
useWave(false),
|
|
|
|
isReverseLoop(false),
|
2022-05-22 09:24:17 +00:00
|
|
|
cr(0),
|
2022-10-29 12:49:31 +00:00
|
|
|
noteChanged(NoteChanged()),
|
|
|
|
volChanged(VolChanged()),
|
|
|
|
filterChanged(FilterChanged()),
|
|
|
|
envChanged(EnvChanged()),
|
|
|
|
pcmChanged(PCMChanged()),
|
|
|
|
overwrite(Overwrite()),
|
2023-01-12 14:31:56 +00:00
|
|
|
ca(0),
|
2022-04-26 03:04:23 +00:00
|
|
|
k1Offs(0),
|
|
|
|
k2Offs(0),
|
2022-05-03 02:07:50 +00:00
|
|
|
k1Slide(0),
|
|
|
|
k2Slide(0),
|
|
|
|
k1Prev(0xffff),
|
|
|
|
k2Prev(0xffff),
|
2022-04-30 14:45:05 +00:00
|
|
|
lVol(0xff),
|
|
|
|
rVol(0xff),
|
2022-04-20 16:52:37 +00:00
|
|
|
outLVol(0xffff),
|
|
|
|
outRVol(0xffff),
|
|
|
|
resLVol(0xffff),
|
2022-05-01 12:26:10 +00:00
|
|
|
resRVol(0xffff),
|
2022-10-29 12:49:31 +00:00
|
|
|
oscOut(0),
|
|
|
|
filter(DivInstrumentES5506::Filter()),
|
2022-12-13 05:53:00 +00:00
|
|
|
envelope(DivInstrumentES5506::Envelope()) {
|
|
|
|
outVol=0xffff;
|
|
|
|
}
|
2022-04-20 16:52:37 +00:00
|
|
|
};
|
|
|
|
Channel chan[32];
|
2022-05-01 12:26:10 +00:00
|
|
|
DivDispatchOscBuffer* oscBuf[32];
|
2022-04-20 16:52:37 +00:00
|
|
|
bool isMuted[32];
|
2022-05-03 02:07:50 +00:00
|
|
|
signed short* sampleMem; // ES5506 uses 16 bit data bus for samples
|
|
|
|
size_t sampleMemLen;
|
2022-09-26 15:01:10 +00:00
|
|
|
unsigned int sampleOffES5506[256];
|
2022-11-30 08:39:43 +00:00
|
|
|
bool sampleLoaded[256];
|
2022-04-20 16:52:37 +00:00
|
|
|
struct QueuedHostIntf {
|
2022-09-25 09:32:34 +00:00
|
|
|
unsigned char state;
|
2022-04-20 16:52:37 +00:00
|
|
|
unsigned char step;
|
|
|
|
unsigned char addr;
|
|
|
|
unsigned int val;
|
|
|
|
unsigned int mask;
|
|
|
|
unsigned int* read;
|
|
|
|
unsigned short delay;
|
|
|
|
bool isRead;
|
|
|
|
QueuedHostIntf(unsigned char s, unsigned char a, unsigned int v, unsigned int m=(unsigned int)(~0), unsigned short d=0):
|
2022-09-25 09:32:34 +00:00
|
|
|
state(0),
|
2022-04-20 16:52:37 +00:00
|
|
|
step(s),
|
|
|
|
addr(a),
|
|
|
|
val(v),
|
|
|
|
mask(m),
|
|
|
|
read(NULL),
|
|
|
|
delay(0),
|
|
|
|
isRead(false) {}
|
2022-09-25 09:32:34 +00:00
|
|
|
QueuedHostIntf(unsigned char st, unsigned char s, unsigned char a, unsigned int* r, unsigned int m=(unsigned int)(~0), unsigned short d=0):
|
|
|
|
state(st),
|
2022-04-20 16:52:37 +00:00
|
|
|
step(s),
|
|
|
|
addr(a),
|
|
|
|
val(0),
|
|
|
|
mask(m),
|
|
|
|
read(r),
|
|
|
|
delay(d),
|
|
|
|
isRead(true) {}
|
|
|
|
};
|
2022-09-25 09:32:34 +00:00
|
|
|
struct QueuedReadState {
|
|
|
|
unsigned int* read;
|
|
|
|
unsigned char state;
|
|
|
|
QueuedReadState(unsigned int* r, unsigned char s):
|
|
|
|
read(r),
|
|
|
|
state(s) {}
|
|
|
|
};
|
2022-04-20 16:52:37 +00:00
|
|
|
std::queue<QueuedHostIntf> hostIntf32;
|
|
|
|
std::queue<QueuedHostIntf> hostIntf8;
|
2022-09-25 09:32:34 +00:00
|
|
|
std::queue<unsigned char> queuedRead;
|
|
|
|
std::queue<QueuedReadState> queuedReadState;
|
2022-04-20 16:52:37 +00:00
|
|
|
int cycle, curPage;
|
|
|
|
unsigned char maskedVal;
|
|
|
|
unsigned int irqv;
|
|
|
|
bool isMasked, isReaded;
|
|
|
|
bool irqTrigger;
|
2022-05-22 09:24:17 +00:00
|
|
|
unsigned int curCR;
|
2022-05-01 12:26:10 +00:00
|
|
|
unsigned char prevChanCycle;
|
2022-04-20 16:52:37 +00:00
|
|
|
|
|
|
|
unsigned char initChanMax, chanMax;
|
|
|
|
|
|
|
|
es5506_core es5506;
|
|
|
|
unsigned char regPool[4*16*128]; // 7 bit page x 16 registers per page x 32 bit per registers
|
|
|
|
|
2022-10-29 12:49:31 +00:00
|
|
|
friend void putDispatchChip(void*,int);
|
2022-04-20 16:52:37 +00:00
|
|
|
friend void putDispatchChan(void*,int,int);
|
|
|
|
|
|
|
|
public:
|
2022-04-27 05:29:53 +00:00
|
|
|
virtual void e_pin(bool state) override; // E output
|
2022-04-20 16:52:37 +00:00
|
|
|
|
|
|
|
virtual void irqb(bool state) override; // IRQB output
|
|
|
|
virtual s16 read_sample(u8 voice, u8 bank, u32 address) override {
|
2022-05-03 02:07:50 +00:00
|
|
|
if (sampleMem==NULL) return 0;
|
|
|
|
return sampleMem[((bank&3)<<21)|(address&0x1fffff)];
|
2022-04-20 16:52:37 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 14:31:56 +00:00
|
|
|
virtual void acquire(short** buf, size_t len) override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual int dispatch(DivCommand c) override;
|
|
|
|
virtual void* getChanState(int chan) override;
|
2022-06-25 15:36:36 +00:00
|
|
|
virtual DivMacroInt* getChanMacroInt(int ch) override;
|
2022-05-01 12:26:10 +00:00
|
|
|
virtual DivDispatchOscBuffer* getOscBuffer(int chan) override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual unsigned char* getRegisterPool() override;
|
|
|
|
virtual int getRegisterPoolSize() override;
|
|
|
|
virtual void reset() override;
|
|
|
|
virtual void forceIns() override;
|
2022-04-26 03:04:23 +00:00
|
|
|
virtual void tick(bool sysTick=true) override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual void muteChannel(int ch, bool mute) override;
|
2023-01-12 14:31:56 +00:00
|
|
|
virtual int getOutputCount() override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual bool keyOffAffectsArp(int ch) override;
|
2022-09-30 11:01:31 +00:00
|
|
|
virtual void setFlags(const DivConfig& flags) override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual void notifyInsChange(int ins) override;
|
|
|
|
virtual void notifyWaveChange(int wave) override;
|
|
|
|
virtual void notifyInsDeletion(void* ins) override;
|
|
|
|
virtual void poke(unsigned int addr, unsigned short val) override;
|
|
|
|
virtual void poke(std::vector<DivRegWrite>& wlist) override;
|
2022-05-03 02:07:50 +00:00
|
|
|
virtual const void* getSampleMem(int index = 0) override;
|
|
|
|
virtual size_t getSampleMemCapacity(int index = 0) override;
|
|
|
|
virtual size_t getSampleMemUsage(int index = 0) override;
|
2022-11-30 08:39:43 +00:00
|
|
|
virtual bool isSampleLoaded(int index, int sample) override;
|
|
|
|
virtual void renderSamples(int sysID) override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual const char** getRegisterSheet() override;
|
2022-09-30 11:01:31 +00:00
|
|
|
virtual int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags) override;
|
2022-04-20 16:52:37 +00:00
|
|
|
virtual void quit() override;
|
|
|
|
DivPlatformES5506():
|
|
|
|
DivDispatch(),
|
|
|
|
es550x_intf(),
|
|
|
|
es5506(*this) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|