| 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 _C64_H |
| 21 |
#define _C64_H |
| 22 |
|
| 23 |
#include "../dispatch.h" |
| 24 |
#include "../../fixedQueue.h" |
| 25 |
#include "sound/c64/sid.h" |
| 26 |
#include "sound/c64_fp/SID.h" |
| 27 |
#include "sound/c64_d/dsid.h" |
| 28 |
|
| 29 |
// TODO: |
| 30 |
// - ex3 (special) unify with ex4 (gate/test) |
| 31 |
// - ex4 (test) compatibility |
| 32 |
|
| 33 |
class DivPlatformC64: public DivDispatch { |
| 34 |
struct Channel: public SharedChannel<signed char> { |
| 35 |
int prevFreq, testWhen; |
| 36 |
unsigned int audPos; |
| 37 |
int pcmPos, sample, pcmPeriod, pcmRate, pcmOut; |
| 38 |
unsigned char sweep, wave, attack, decay, sustain, release; |
| 39 |
short duty; |
| 40 |
bool sweepChanged, filter, setPos, pcm; |
| 41 |
bool resetMask, resetFilter, resetDuty, gate, ring, sync, test; |
| 42 |
short pw_slide; |
| 43 |
Channel(): |
| 44 |
SharedChannel<signed char>(15), |
| 45 |
prevFreq(65535), |
| 46 |
testWhen(0), |
| 47 |
audPos(0), |
| 48 |
pcmPos(0), |
| 49 |
sample(-1), |
| 50 |
pcmPeriod(0), |
| 51 |
pcmRate(0), |
| 52 |
pcmOut(15), |
| 53 |
sweep(0), |
| 54 |
wave(0), |
| 55 |
attack(0), |
| 56 |
decay(0), |
| 57 |
sustain(0), |
| 58 |
release(0), |
| 59 |
duty(0), |
| 60 |
sweepChanged(false), |
| 61 |
filter(false), |
| 62 |
setPos(false), |
| 63 |
pcm(false), |
| 64 |
resetMask(false), |
| 65 |
resetFilter(false), |
| 66 |
resetDuty(false), |
| 67 |
gate(true), |
| 68 |
ring(false), |
| 69 |
sync(false), |
| 70 |
test(false), |
| 71 |
pw_slide(0) {} |
| 72 |
}; |
| 73 |
Channel chan[4]; |
| 74 |
DivDispatchOscBuffer* oscBuf[4]; |
| 75 |
bool isMuted[4]; |
| 76 |
float fakeLow[4]; |
| 77 |
float fakeBand[4]; |
| 78 |
float fakeCutTable[2048]; |
| 79 |
struct QueuedWrite { |
| 80 |
unsigned char addr; |
| 81 |
unsigned char val; |
| 82 |
QueuedWrite(): addr(0), val(0) {} |
| 83 |
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {} |
| 84 |
}; |
| 85 |
FixedQueue<QueuedWrite,128> writes; |
| 86 |
|
| 87 |
unsigned char filtControl, filtRes, vol; |
| 88 |
unsigned char writeOscBuf; |
| 89 |
unsigned char sidCore; |
| 90 |
int filtCut, resetTime, initResetTime; |
| 91 |
int pcmCycle, lineRate; |
| 92 |
short cutoff_slide; |
| 93 |
|
| 94 |
bool keyPriority, sidIs6581, needInitTables, no1EUpdate, multiplyRel, macroRace, noSoftPCM; |
| 95 |
unsigned char chanOrder[3]; |
| 96 |
unsigned char testAD, testSR; |
| 97 |
|
| 98 |
SID* sid; |
| 99 |
reSIDfp::SID* sid_fp; |
| 100 |
struct SID_chip* sid_d; |
| 101 |
int coreQuality; |
| 102 |
unsigned char regPool[32]; |
| 103 |
|
| 104 |
friend void putDispatchChip(void*,int); |
| 105 |
friend void putDispatchChan(void*,int,int); |
| 106 |
|
| 107 |
inline short runFakeFilter(unsigned char ch, int in); |
| 108 |
|
| 109 |
void processDAC(int sRate); |
| 110 |
void acquire_classic(short* bufL, short* bufR, size_t start, size_t len); |
| 111 |
void acquire_fp(short* bufL, short* bufR, size_t start, size_t len); |
| 112 |
|
| 113 |
void updateFilter(); |
| 114 |
void updateVolume(); |
| 115 |
public: |
| 116 |
void acquire(short** buf, size_t len); |
| 117 |
int dispatch(DivCommand c); |
| 118 |
void* getChanState(int chan); |
| 119 |
DivDispatchOscBuffer* getOscBuffer(int chan); |
| 120 |
unsigned char* getRegisterPool(); |
| 121 |
int getRegisterPoolSize(); |
| 122 |
void reset(); |
| 123 |
void forceIns(); |
| 124 |
void tick(bool sysTick=true); |
| 125 |
void muteChannel(int ch, bool mute); |
| 126 |
void setFlags(const DivConfig& flags); |
| 127 |
void notifyInsChange(int ins); |
| 128 |
bool getDCOffRequired(); |
| 129 |
bool getWantPreNote(); |
| 130 |
bool isVolGlobal(); |
| 131 |
float getPostAmp(); |
| 132 |
DivMacroInt* getChanMacroInt(int ch); |
| 133 |
void getPaired(int ch, std::vector<DivChannelPair>& ret); |
| 134 |
DivChannelModeHints getModeHints(int chan); |
| 135 |
void notifyInsDeletion(void* ins); |
| 136 |
void poke(unsigned int addr, unsigned short val); |
| 137 |
void poke(std::vector<DivRegWrite>& wlist); |
| 138 |
const char** getRegisterSheet(); |
| 139 |
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); |
| 140 |
void setChipModel(bool is6581); |
| 141 |
void setCore(unsigned char which); |
| 142 |
void setCoreQuality(unsigned char q); |
| 143 |
void setSoftPCM(bool isSoft); |
| 144 |
void quit(); |
| 145 |
~DivPlatformC64(); |
| 146 |
}; |
| 147 |
|
| 148 |
#endif |