Debian Codegraph @

src/engine/platform/tx81z.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 _TX81Z_H
21 #define _TX81Z_H
22
23 #include "fmshared_OPM.h"
24 #include "../../fixedQueue.h"
25 #include "sound/ymfm/ymfm_opz.h"
26
27 class DivTXInterface: public ymfm::ymfm_interface {
28
29 };
30
31 class DivPlatformTX81Z: public DivPlatformOPM {
32 protected:
33 const unsigned short chanOffs[8]={
34 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
35 };
36
37 struct Channel: public FMChannel {
38 unsigned char chVolL, chVolR;
39
40 struct {
41 int baseNoteOverride;
42 bool fixedArp;
43 int arpOff;
44 int pitch2;
45 bool hasOpArp;
46 bool hasOpPitch;
47 } opsState[4];
48
49 void handleArpFmOp(bool& freqChange, int offset=0, int o=0) {
50 DivMacroInt::IntOp& m=this->std.op[o];
51 if (m.ssg.had) {
52 opsState[o].hasOpArp=true;
53
54 if (m.ssg.val<0) {
55 if (!(m.ssg.val&0x40000000)) {
56 opsState[o].baseNoteOverride=(m.ssg.val|0x40000000)+offset;
57 opsState[o].fixedArp=true;
58 } else {
59 opsState[o].arpOff=m.ssg.val;
60 opsState[o].fixedArp=false;
61 }
62 } else {
63 if (m.ssg.val&0x40000000) {
64 opsState[o].baseNoteOverride=(m.ssg.val&(~0x40000000))+offset;
65 opsState[o].fixedArp=true;
66 } else {
67 opsState[o].arpOff=m.ssg.val;
68 opsState[o].fixedArp=false;
69 }
70 }
71 freqChange=true;
72 } else {
73 opsState[o].hasOpArp=false;
74 }
75 }
76
77 void handlePitchFmOp(bool& freqChange, int o) {
78 DivMacroInt::IntOp& m=this->std.op[o];
79
80 if (m.sus.had) {
81 opsState[o].hasOpPitch=true;
82
83 if (m.sus.mode) {
84 opsState[o].pitch2+=m.sus.val;
85 CLAMP_VAR(opsState[o].pitch2,-131071,131071);
86 } else {
87 opsState[o].pitch2=m.sus.val;
88 }
89 freqChange=true;
90 } else {
91 opsState[o].hasOpPitch=false;
92 }
93 }
94 Channel():
95 FMChannel(),
96 chVolL(1),
97 chVolR(1) {
98 memset(opsState,0,sizeof(opsState));
99 }
100 };
101 Channel chan[8];
102 DivDispatchOscBuffer* oscBuf[8];
103 int baseFreqOff;
104 int pcmL, pcmR, pcmCycles;
105 unsigned char amDepth, pmDepth, amDepth2, pmDepth2;
106
107 ymfm::ym2414* fm_ymfm;
108 ymfm::ym2414::output_data out_ymfm;
109 DivTXInterface iface;
110
111 bool extMode;
112
113 bool isMuted[8];
114
115 int octave(int freq);
116 int toFreq(int freq);
117 void commitState(int ch, DivInstrument* ins);
118
119 friend void putDispatchChip(void*,int);
120 public:
121 void acquire(short** buf, size_t len);
122 int dispatch(DivCommand c);
123 void* getChanState(int chan);
124 DivMacroInt* getChanMacroInt(int ch);
125 unsigned short getPan(int chan);
126 DivDispatchOscBuffer* getOscBuffer(int chan);
127 unsigned char* getRegisterPool();
128 int getRegisterPoolSize();
129 void reset();
130 void forceIns();
131 void tick(bool sysTick=true);
132 void muteChannel(int ch, bool mute);
133 void notifyInsChange(int ins);
134 void notifyInsDeletion(void* ins);
135 void setFlags(const DivConfig& flags);
136 int getOutputCount();
137 void poke(unsigned int addr, unsigned short val);
138 void poke(std::vector<DivRegWrite>& wlist);
139 const char** getRegisterSheet();
140 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
141 void quit();
142 ~DivPlatformTX81Z();
143 };
144 #endif