Debian Codegraph @

src/engine/platform/nes.h

raw
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 _NES_H
21 #define _NES_H
22
23 #include "../dispatch.h"
24
25 #include "sound/nes_nsfplay/nes_apu.h"
26 #include "sound/nes_nsfplay/5e01_apu.h"
27 #include "../../fixedQueue.h"
28
29 class DivPlatformNES: public DivDispatch {
30 struct Channel: public SharedChannel<signed char> {
31 int prevFreq;
32 unsigned char duty, sweep, envMode, len;
33 bool sweepChanged, furnaceDac, setPos;
34 Channel():
35 SharedChannel<signed char>(15),
36 prevFreq(65535),
37 duty(0),
38 sweep(8),
39 envMode(3),
40 len(0x1f),
41 sweepChanged(false),
42 furnaceDac(false),
43 setPos(false) {}
44 };
45 Channel chan[5];
46 DivDispatchOscBuffer* oscBuf[5];
47 bool isMuted[5];
48 struct QueuedWrite {
49 unsigned short addr;
50 unsigned char val;
51 QueuedWrite(): addr(0), val(0) {}
52 QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v) {}
53 };
54 FixedQueue<QueuedWrite,128> writes;
55 int dacPeriod, dacRate, dpcmPos;
56 unsigned int dacPos, dacAntiClick;
57 int dacSample;
58 unsigned char* dpcmMem;
59 size_t dpcmMemLen;
60 bool* sampleLoaded;
61 unsigned char dpcmBank;
62 unsigned char sampleBank;
63 unsigned char writeOscBuf;
64 unsigned char apuType;
65 unsigned char linearCount;
66 signed char nextDPCMFreq;
67 signed char nextDPCMDelta;
68 signed char lastDPCMFreq;
69 bool dpcmMode;
70 bool dpcmModeDefault;
71 bool resetSweep;
72 bool dacAntiClickOn;
73 bool useNP;
74 bool goingToLoop;
75 bool countMode;
76 bool isE;
77 struct NESAPU* nes;
78 xgm::NES_APU* nes1_NP;
79 xgm::NES_DMC* nes2_NP;
80 xgm::I5E01_APU* e1_NP;
81 xgm::I5E01_DMC* e2_NP;
82 unsigned char regPool[128];
83 unsigned int* sampleOffDPCM;
84 DivMemoryComposition memCompo;
85
86 friend void putDispatchChip(void*,int);
87 friend void putDispatchChan(void*,int,int);
88
89 void doWrite(int ts, unsigned short addr, unsigned char data);
90 unsigned char calcDPCMRate(int inRate);
91 void acquire_puNES(blip_buffer_t** bb, size_t len);
92 void acquire_NSFPlay(short** buf, size_t len);
93 void acquire_NSFPlayE(short** buf, size_t len);
94
95 public:
96 void acquire(short** buf, size_t len);
97 void acquireDirect(blip_buffer_t** bb, size_t len);
98 int dispatch(DivCommand c);
99 void* getChanState(int chan);
100 DivMacroInt* getChanMacroInt(int ch);
101 DivDispatchOscBuffer* getOscBuffer(int chan);
102 unsigned char* getRegisterPool();
103 int getRegisterPoolSize();
104 void reset();
105 void forceIns();
106 void tick(bool sysTick=true);
107 void muteChannel(int ch, bool mute);
108 bool keyOffAffectsArp(int ch);
109 bool hasAcquireDirect();
110 float getPostAmp();
111 unsigned char readDMC(unsigned short addr);
112 void setNSFPlay(bool use);
113 void set5E01(bool use);
114 void setFlags(const DivConfig& flags);
115 void notifyInsDeletion(void* ins);
116 void poke(unsigned int addr, unsigned short val);
117 void poke(std::vector<DivRegWrite>& wlist);
118 const char** getRegisterSheet();
119 const void* getSampleMem(int index);
120 size_t getSampleMemCapacity(int index);
121 size_t getSampleMemUsage(int index);
122 bool isSampleLoaded(int index, int sample);
123 const DivMemoryComposition* getMemCompo(int index);
124 void renderSamples(int chipID);
125 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
126 void quit();
127 DivPlatformNES();
128 ~DivPlatformNES();
129 };
130
131 #endif