2022-02-14 22:12:20 -05:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2023-01-19 19:18:40 -05:00
|
|
|
* Copyright (C) 2021-2023 tildearrow and contributors
|
2022-02-14 22:12:20 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-12-04 23:55:28 -05:00
|
|
|
#ifndef _NES_H
|
|
|
|
#define _NES_H
|
2021-12-04 01:19:54 -05:00
|
|
|
|
|
|
|
#include "../dispatch.h"
|
|
|
|
|
2022-05-02 00:20:20 -04:00
|
|
|
#include "sound/nes_nsfplay/nes_apu.h"
|
|
|
|
|
2021-12-04 01:19:54 -05:00
|
|
|
class DivPlatformNES: public DivDispatch {
|
2022-12-13 02:22:48 -05:00
|
|
|
struct Channel: public SharedChannel<signed char> {
|
2022-12-04 05:58:58 -05:00
|
|
|
int prevFreq;
|
2022-10-25 01:43:03 -04:00
|
|
|
unsigned char duty, sweep, envMode, len;
|
2022-12-04 05:58:58 -05:00
|
|
|
bool sweepChanged, furnaceDac;
|
2021-12-04 01:19:54 -05:00
|
|
|
Channel():
|
2022-12-13 02:22:48 -05:00
|
|
|
SharedChannel<signed char>(15),
|
2021-12-04 02:19:14 -05:00
|
|
|
prevFreq(65535),
|
2021-12-04 01:19:54 -05:00
|
|
|
duty(0),
|
2022-02-01 18:28:48 -05:00
|
|
|
sweep(8),
|
2022-10-25 01:43:03 -04:00
|
|
|
envMode(3),
|
|
|
|
len(0x1f),
|
2021-12-04 01:19:54 -05:00
|
|
|
sweepChanged(false),
|
2022-12-13 13:23:48 -05:00
|
|
|
furnaceDac(false) {}
|
2021-12-04 01:19:54 -05:00
|
|
|
};
|
|
|
|
Channel chan[5];
|
2022-04-30 15:36:12 -04:00
|
|
|
DivDispatchOscBuffer* oscBuf[5];
|
2021-12-18 03:25:42 -05:00
|
|
|
bool isMuted[5];
|
2021-12-14 12:33:26 -05:00
|
|
|
int dacPeriod, dacRate;
|
2022-04-09 19:25:25 -04:00
|
|
|
unsigned int dacPos, dacAntiClick;
|
2021-12-14 12:33:26 -05:00
|
|
|
int dacSample;
|
2022-05-02 03:54:23 -04:00
|
|
|
unsigned char* dpcmMem;
|
|
|
|
size_t dpcmMemLen;
|
2022-11-26 18:44:04 -05:00
|
|
|
bool sampleLoaded[256];
|
2022-05-02 03:54:23 -04:00
|
|
|
unsigned char dpcmBank;
|
2021-12-14 12:33:26 -05:00
|
|
|
unsigned char sampleBank;
|
2022-04-30 15:36:12 -04:00
|
|
|
unsigned char writeOscBuf;
|
2022-01-26 16:07:55 -05:00
|
|
|
unsigned char apuType;
|
2022-05-02 03:54:23 -04:00
|
|
|
bool dpcmMode;
|
2022-04-09 19:25:25 -04:00
|
|
|
bool dacAntiClickOn;
|
2022-05-02 00:20:20 -04:00
|
|
|
bool useNP;
|
2022-09-22 19:43:48 -04:00
|
|
|
bool goingToLoop;
|
2022-10-25 01:43:03 -04:00
|
|
|
bool countMode;
|
2022-01-08 17:44:17 -05:00
|
|
|
struct NESAPU* nes;
|
2022-05-02 00:20:20 -04:00
|
|
|
xgm::NES_APU* nes1_NP;
|
|
|
|
xgm::NES_DMC* nes2_NP;
|
2022-02-21 22:31:27 -05:00
|
|
|
unsigned char regPool[128];
|
2022-09-25 21:07:21 -04:00
|
|
|
unsigned int sampleOffDPCM[256];
|
2021-12-04 01:19:54 -05:00
|
|
|
|
2022-09-23 10:24:02 -04:00
|
|
|
friend void putDispatchChip(void*,int);
|
2022-01-27 00:29:16 -05:00
|
|
|
friend void putDispatchChan(void*,int,int);
|
2021-12-08 01:56:40 -05:00
|
|
|
|
2022-05-02 00:20:20 -04:00
|
|
|
void doWrite(unsigned short addr, unsigned char data);
|
2022-05-02 04:42:40 -04:00
|
|
|
unsigned char calcDPCMRate(int inRate);
|
2023-01-03 01:09:46 -05:00
|
|
|
void acquire_puNES(short** buf, size_t len);
|
|
|
|
void acquire_NSFPlay(short** buf, size_t len);
|
2022-05-02 00:20:20 -04:00
|
|
|
|
2021-12-04 01:19:54 -05:00
|
|
|
public:
|
2023-01-02 04:53:37 -05:00
|
|
|
void acquire(short** buf, size_t len);
|
2021-12-04 01:19:54 -05:00
|
|
|
int dispatch(DivCommand c);
|
2022-01-27 00:29:16 -05:00
|
|
|
void* getChanState(int chan);
|
2022-06-05 19:17:00 -04:00
|
|
|
DivMacroInt* getChanMacroInt(int ch);
|
2022-04-30 15:36:12 -04:00
|
|
|
DivDispatchOscBuffer* getOscBuffer(int chan);
|
2022-02-21 22:31:27 -05:00
|
|
|
unsigned char* getRegisterPool();
|
|
|
|
int getRegisterPoolSize();
|
2021-12-11 13:14:38 -05:00
|
|
|
void reset();
|
2021-12-21 01:29:07 -05:00
|
|
|
void forceIns();
|
2022-04-15 16:01:11 -04:00
|
|
|
void tick(bool sysTick=true);
|
2021-12-18 03:25:42 -05:00
|
|
|
void muteChannel(int ch, bool mute);
|
2021-12-08 00:33:00 -05:00
|
|
|
bool keyOffAffectsArp(int ch);
|
2022-04-09 19:25:25 -04:00
|
|
|
float getPostAmp();
|
2022-05-02 03:12:14 -04:00
|
|
|
unsigned char readDMC(unsigned short addr);
|
2022-05-02 00:20:20 -04:00
|
|
|
void setNSFPlay(bool use);
|
2022-09-29 21:13:40 -04:00
|
|
|
void setFlags(const DivConfig& flags);
|
2022-01-13 19:36:02 -05:00
|
|
|
void notifyInsDeletion(void* ins);
|
2022-02-01 18:08:19 -05:00
|
|
|
void poke(unsigned int addr, unsigned short val);
|
|
|
|
void poke(std::vector<DivRegWrite>& wlist);
|
2022-02-03 18:38:57 -05:00
|
|
|
const char** getRegisterSheet();
|
2022-05-02 03:54:23 -04:00
|
|
|
const void* getSampleMem(int index);
|
|
|
|
size_t getSampleMemCapacity(int index);
|
|
|
|
size_t getSampleMemUsage(int index);
|
2022-11-26 18:44:04 -05:00
|
|
|
bool isSampleLoaded(int index, int sample);
|
2022-11-26 23:50:20 -05:00
|
|
|
void renderSamples(int chipID);
|
2022-09-29 21:13:40 -04:00
|
|
|
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
|
2021-12-15 00:37:27 -05:00
|
|
|
void quit();
|
|
|
|
~DivPlatformNES();
|
2021-12-04 01:19:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|