Merge pull request #225 from cam900/ym2610b
Prepare to experimental support YM2610B and with Extended channel 3 mode, Some additions
This commit is contained in:
commit
acc9b0aa57
22 changed files with 2243 additions and 21 deletions
|
|
@ -32,6 +32,218 @@ static unsigned char konOffs[4]={
|
|||
|
||||
#define CHIP_DIVIDER 32
|
||||
|
||||
const char* regCheatSheetYM2610[]={
|
||||
// SSG
|
||||
"SSG_FreqL_A", "000",
|
||||
"SSG_FreqH_A", "001",
|
||||
"SSG_FreqL_B", "002",
|
||||
"SSG_FreqH_B", "003",
|
||||
"SSG_FreqL_C", "004",
|
||||
"SSG_FreqH_C", "005",
|
||||
"SSG_FreqNoise", "006",
|
||||
"SSG_Enable", "007",
|
||||
"SSG_Volume_A", "008",
|
||||
"SSG_Volume_B", "009",
|
||||
"SSG_Volume_C", "00A",
|
||||
"SSG_FreqL_Env", "00B",
|
||||
"SSG_FreqH_Env", "00C",
|
||||
"SSG_Control_Env", "00D",
|
||||
// ADPCM-B
|
||||
"ADPCMB_Control", "010",
|
||||
"ADPCMB_L_R", "011",
|
||||
"ADPCMB_StartL", "012",
|
||||
"ADPCMB_StartH", "013",
|
||||
"ADPCMB_EndL", "014",
|
||||
"ADPCMB_EndH", "015",
|
||||
"ADPCMB_FreqL", "019",
|
||||
"ADPCMB_FreqH", "01A",
|
||||
"ADPCMB_Volume", "01B",
|
||||
"ADPCM_Flag", "01C",
|
||||
// FM (Common)
|
||||
"FM_Test", "021",
|
||||
"FM_LFOFreq", "022",
|
||||
"ClockA1", "024",
|
||||
"ClockA2", "025",
|
||||
"ClockB", "026",
|
||||
"FM_Control", "027",
|
||||
"FM_NoteCtl", "028",
|
||||
// FM (Channel 1-2)
|
||||
"FM1_Op1_DT_MULT", "031",
|
||||
"FM2_Op1_DT_MULT", "032",
|
||||
"FM1_Op2_DT_MULT", "035",
|
||||
"FM2_Op2_DT_MULT", "036",
|
||||
"FM1_Op3_DT_MULT", "039",
|
||||
"FM2_Op3_DT_MULT", "03A",
|
||||
"FM1_Op4_DT_MULT", "03D",
|
||||
"FM2_Op4_DT_MULT", "03E",
|
||||
"FM1_Op1_TL", "041",
|
||||
"FM2_Op1_TL", "042",
|
||||
"FM1_Op2_TL", "045",
|
||||
"FM2_Op2_TL", "046",
|
||||
"FM1_Op3_TL", "049",
|
||||
"FM2_Op3_TL", "04A",
|
||||
"FM1_Op4_TL", "04D",
|
||||
"FM2_Op4_TL", "04E",
|
||||
"FM1_Op1_KS_AR", "051",
|
||||
"FM2_Op1_KS_AR", "052",
|
||||
"FM1_Op2_KS_AR", "055",
|
||||
"FM2_Op2_KS_AR", "056",
|
||||
"FM1_Op3_KS_AR", "059",
|
||||
"FM2_Op3_KS_AR", "05A",
|
||||
"FM1_Op4_KS_AR", "05D",
|
||||
"FM2_Op4_KS_AR", "05E",
|
||||
"FM1_Op1_AM_DR", "061",
|
||||
"FM2_Op1_AM_DR", "062",
|
||||
"FM1_Op2_AM_DR", "065",
|
||||
"FM2_Op2_AM_DR", "066",
|
||||
"FM1_Op3_AM_DR", "069",
|
||||
"FM2_Op3_AM_DR", "06A",
|
||||
"FM1_Op4_AM_DR", "06D",
|
||||
"FM2_Op4_AM_DR", "06E",
|
||||
"FM1_Op1_SR", "071",
|
||||
"FM2_Op1_SR", "072",
|
||||
"FM1_Op2_SR", "075",
|
||||
"FM2_Op2_SR", "076",
|
||||
"FM1_Op3_SR", "079",
|
||||
"FM2_Op3_SR", "07A",
|
||||
"FM1_Op4_SR", "07D",
|
||||
"FM2_Op4_SR", "07E",
|
||||
"FM1_Op1_SL_RR", "081",
|
||||
"FM2_Op1_SL_RR", "082",
|
||||
"FM1_Op2_SL_RR", "085",
|
||||
"FM2_Op2_SL_RR", "086",
|
||||
"FM1_Op3_SL_RR", "089",
|
||||
"FM2_Op3_SL_RR", "08A",
|
||||
"FM1_Op4_SL_RR", "08D",
|
||||
"FM2_Op4_SL_RR", "08E",
|
||||
"FM1_Op1_SSG_EG", "091",
|
||||
"FM2_Op1_SSG_EG", "092",
|
||||
"FM1_Op2_SSG_EG", "095",
|
||||
"FM2_Op2_SSG_EG", "096",
|
||||
"FM1_Op3_SSG_EG", "099",
|
||||
"FM2_Op3_SSG_EG", "09A",
|
||||
"FM1_Op4_SSG_EG", "09D",
|
||||
"FM2_Op4_SSG_EG", "09E",
|
||||
"FM1_FNum1", "0A1",
|
||||
"FM2_(Op1)FNum1", "0A2",
|
||||
"FM1_FNum2", "0A5",
|
||||
"FM2_(Op1)FNum2", "0A6",
|
||||
"FM2_Op2_FNum1", "0A8",
|
||||
"FM2_Op3_FNum1", "0A9",
|
||||
"FM2_Op4_FNum1", "0AA",
|
||||
"FM2_Op2_FNum2", "0AC",
|
||||
"FM2_Op3_FNum2", "0AD",
|
||||
"FM2_Op4_FNum2", "0AE",
|
||||
"FM1_FB_ALG", "0B1",
|
||||
"FM2_FB_ALG", "0B2",
|
||||
"FM1_Pan_LFO", "0B5",
|
||||
"FM2_Pan_LFO", "0B6",
|
||||
// ADPCM-A
|
||||
"ADPCMA_Control", "100",
|
||||
"ADPCMA_MVol", "101",
|
||||
"ADPCMA_Test", "102",
|
||||
"ADPCMA_Ch1_Vol", "108",
|
||||
"ADPCMA_Ch2_Vol", "109",
|
||||
"ADPCMA_Ch3_Vol", "10A",
|
||||
"ADPCMA_Ch4_Vol", "10B",
|
||||
"ADPCMA_Ch5_Vol", "10C",
|
||||
"ADPCMA_Ch6_Vol", "10D",
|
||||
"ADPCMA_Ch1_StL", "110",
|
||||
"ADPCMA_Ch2_StL", "111",
|
||||
"ADPCMA_Ch3_StL", "112",
|
||||
"ADPCMA_Ch4_StL", "113",
|
||||
"ADPCMA_Ch5_StL", "114",
|
||||
"ADPCMA_Ch6_StL", "115",
|
||||
"ADPCMA_Ch1_StH", "118",
|
||||
"ADPCMA_Ch2_StH", "119",
|
||||
"ADPCMA_Ch3_StH", "11A",
|
||||
"ADPCMA_Ch4_StH", "11B",
|
||||
"ADPCMA_Ch5_StH", "11C",
|
||||
"ADPCMA_Ch6_StH", "11D",
|
||||
"ADPCMA_Ch1_EdL", "120",
|
||||
"ADPCMA_Ch2_EdL", "121",
|
||||
"ADPCMA_Ch3_EdL", "122",
|
||||
"ADPCMA_Ch4_EdL", "123",
|
||||
"ADPCMA_Ch5_EdL", "124",
|
||||
"ADPCMA_Ch6_EdL", "125",
|
||||
"ADPCMA_Ch1_EdH", "128",
|
||||
"ADPCMA_Ch2_EdH", "129",
|
||||
"ADPCMA_Ch3_EdH", "12A",
|
||||
"ADPCMA_Ch4_EdH", "12B",
|
||||
"ADPCMA_Ch5_EdH", "12C",
|
||||
"ADPCMA_Ch6_EdH", "12D",
|
||||
// FM (Channel 3-4)
|
||||
"FM3_Op1_DT_MULT", "131",
|
||||
"FM4_Op1_DT_MULT", "132",
|
||||
"FM3_Op2_DT_MULT", "135",
|
||||
"FM4_Op2_DT_MULT", "136",
|
||||
"FM3_Op3_DT_MULT", "139",
|
||||
"FM4_Op3_DT_MULT", "13A",
|
||||
"FM3_Op4_DT_MULT", "13D",
|
||||
"FM4_Op4_DT_MULT", "13E",
|
||||
"FM3_Op1_TL", "141",
|
||||
"FM4_Op1_TL", "142",
|
||||
"FM3_Op2_TL", "145",
|
||||
"FM4_Op2_TL", "146",
|
||||
"FM3_Op3_TL", "149",
|
||||
"FM4_Op3_TL", "14A",
|
||||
"FM3_Op4_TL", "14D",
|
||||
"FM4_Op4_TL", "14E",
|
||||
"FM3_Op1_KS_AR", "151",
|
||||
"FM4_Op1_KS_AR", "152",
|
||||
"FM3_Op2_KS_AR", "155",
|
||||
"FM4_Op2_KS_AR", "156",
|
||||
"FM3_Op3_KS_AR", "159",
|
||||
"FM4_Op3_KS_AR", "15A",
|
||||
"FM3_Op4_KS_AR", "15D",
|
||||
"FM4_Op4_KS_AR", "15E",
|
||||
"FM3_Op1_AM_DR", "161",
|
||||
"FM4_Op1_AM_DR", "162",
|
||||
"FM3_Op2_AM_DR", "165",
|
||||
"FM4_Op2_AM_DR", "166",
|
||||
"FM3_Op3_AM_DR", "169",
|
||||
"FM4_Op3_AM_DR", "16A",
|
||||
"FM3_Op4_AM_DR", "16D",
|
||||
"FM4_Op4_AM_DR", "16E",
|
||||
"FM3_Op1_SR", "171",
|
||||
"FM4_Op1_SR", "172",
|
||||
"FM3_Op2_SR", "175",
|
||||
"FM4_Op2_SR", "176",
|
||||
"FM3_Op3_SR", "179",
|
||||
"FM4_Op3_SR", "17A",
|
||||
"FM3_Op4_SR", "17D",
|
||||
"FM4_Op4_SR", "17E",
|
||||
"FM3_Op1_SL_RR", "181",
|
||||
"FM4_Op1_SL_RR", "182",
|
||||
"FM3_Op2_SL_RR", "185",
|
||||
"FM4_Op2_SL_RR", "186",
|
||||
"FM3_Op3_SL_RR", "189",
|
||||
"FM4_Op3_SL_RR", "18A",
|
||||
"FM3_Op4_SL_RR", "18D",
|
||||
"FM4_Op4_SL_RR", "18E",
|
||||
"FM3_Op1_SSG_EG", "191",
|
||||
"FM4_Op1_SSG_EG", "192",
|
||||
"FM3_Op2_SSG_EG", "195",
|
||||
"FM4_Op2_SSG_EG", "196",
|
||||
"FM3_Op3_SSG_EG", "199",
|
||||
"FM4_Op3_SSG_EG", "19A",
|
||||
"FM3_Op4_SSG_EG", "19D",
|
||||
"FM4_Op4_SSG_EG", "19E",
|
||||
"FM3_FNum1", "1A1",
|
||||
"FM4_FNum1", "1A2",
|
||||
"FM3_FNum2", "1A5",
|
||||
"FM4_FNum2", "1A6",
|
||||
"FM3_FB_ALG", "1B1",
|
||||
"FM4_FB_ALG", "1B2",
|
||||
"FM3_Pan_LFO", "1B5",
|
||||
"FM4_Pan_LFO", "1B6",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char** DivPlatformYM2610::getRegisterSheet() {
|
||||
return regCheatSheetYM2610;
|
||||
}
|
||||
|
||||
const char* DivPlatformYM2610::getEffectName(unsigned char effect) {
|
||||
switch (effect) {
|
||||
case 0x10:
|
||||
|
|
@ -486,7 +698,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
|
|||
immWrite(0x14,(end>>8)&0xff);
|
||||
immWrite(0x15,end>>16);
|
||||
immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6));
|
||||
immWrite(0x10,0x80); // start
|
||||
immWrite(0x10,(s->loopStart>=0)?0x90:0x80); // start/repeat
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
chan[c.chan].note=c.value;
|
||||
chan[c.chan].baseFreq=NOTE_ADPCMB(chan[c.chan].note);
|
||||
|
|
@ -512,7 +724,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
|
|||
immWrite(0x14,(end>>8)&0xff);
|
||||
immWrite(0x15,end>>16);
|
||||
immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6));
|
||||
immWrite(0x10,0x80); // start
|
||||
immWrite(0x10,(s->loopStart>=0)?0x90:0x80); // start/repeat
|
||||
chan[c.chan].baseFreq=(((unsigned int)s->rate)<<16)/(chipClock/144);
|
||||
chan[c.chan].freqChanged=true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ class DivYM2610Interface: public ymfm::ymfm_interface {
|
|||
|
||||
class DivPlatformYM2610: public DivDispatch {
|
||||
protected:
|
||||
const unsigned short chanOffs[4]={
|
||||
0x01, 0x02, 0x101, 0x102
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
DivInstrumentFM state;
|
||||
unsigned char freqH, freqL;
|
||||
|
|
@ -123,6 +127,7 @@ class DivPlatformYM2610: public DivDispatch {
|
|||
void notifyInsDeletion(void* ins);
|
||||
void poke(unsigned int addr, unsigned short val);
|
||||
void poke(std::vector<DivRegWrite>& wlist);
|
||||
const char** getRegisterSheet();
|
||||
const char* getEffectName(unsigned char effect);
|
||||
int init(DivEngine* parent, int channels, int sugRate, unsigned int flags);
|
||||
void quit();
|
||||
|
|
|
|||
1352
src/engine/platform/ym2610b.cpp
Normal file
1352
src/engine/platform/ym2610b.cpp
Normal file
File diff suppressed because it is too large
Load diff
129
src/engine/platform/ym2610b.h
Normal file
129
src/engine/platform/ym2610b.h
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
* 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 _YM2610B_H
|
||||
#define _YM2610B_H
|
||||
#include "../dispatch.h"
|
||||
#include "../macroInt.h"
|
||||
#include <queue>
|
||||
#include "sound/ymfm/ymfm_opn.h"
|
||||
|
||||
#include "ym2610.h"
|
||||
|
||||
class DivPlatformYM2610B: public DivDispatch {
|
||||
protected:
|
||||
const unsigned short chanOffs[6]={
|
||||
0x00, 0x01, 0x02, 0x100, 0x101, 0x102
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
DivInstrumentFM state;
|
||||
unsigned char freqH, freqL;
|
||||
int freq, baseFreq, pitch, note;
|
||||
unsigned char ins, psgMode, autoEnvNum, autoEnvDen;
|
||||
signed char konCycles;
|
||||
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM;
|
||||
int vol, outVol;
|
||||
unsigned char pan;
|
||||
DivMacroInt std;
|
||||
Channel():
|
||||
freqH(0),
|
||||
freqL(0),
|
||||
freq(0),
|
||||
baseFreq(0),
|
||||
pitch(0),
|
||||
note(0),
|
||||
ins(-1),
|
||||
psgMode(1),
|
||||
autoEnvNum(0),
|
||||
autoEnvDen(0),
|
||||
active(false),
|
||||
insChanged(true),
|
||||
freqChanged(false),
|
||||
keyOn(false),
|
||||
keyOff(false),
|
||||
portaPause(false),
|
||||
inPorta(false),
|
||||
furnacePCM(false),
|
||||
vol(0),
|
||||
outVol(15),
|
||||
pan(3) {}
|
||||
};
|
||||
Channel chan[16];
|
||||
bool isMuted[16];
|
||||
struct QueuedWrite {
|
||||
unsigned short addr;
|
||||
unsigned char val;
|
||||
bool addrOrVal;
|
||||
QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {}
|
||||
};
|
||||
std::queue<QueuedWrite> writes;
|
||||
ymfm::ym2610b* fm;
|
||||
ymfm::ym2610b::output_data fmout;
|
||||
DivYM2610Interface iface;
|
||||
unsigned char regPool[512];
|
||||
unsigned char lastBusy;
|
||||
|
||||
bool dacMode;
|
||||
int dacPeriod;
|
||||
int dacRate;
|
||||
int dacPos;
|
||||
int dacSample;
|
||||
int ayNoiseFreq;
|
||||
unsigned char sampleBank;
|
||||
|
||||
int delay;
|
||||
|
||||
bool extMode;
|
||||
|
||||
short oldWrites[512];
|
||||
short pendingWrites[512];
|
||||
unsigned char ayEnvMode;
|
||||
unsigned short ayEnvPeriod;
|
||||
short ayEnvSlideLow;
|
||||
short ayEnvSlide;
|
||||
|
||||
int octave(int freq);
|
||||
int toFreq(int freq);
|
||||
double NOTE_ADPCMB(int note);
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
|
||||
public:
|
||||
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||
int dispatch(DivCommand c);
|
||||
void* getChanState(int chan);
|
||||
unsigned char* getRegisterPool();
|
||||
int getRegisterPoolSize();
|
||||
void reset();
|
||||
void forceIns();
|
||||
void tick();
|
||||
void muteChannel(int ch, bool mute);
|
||||
bool isStereo();
|
||||
bool keyOffAffectsArp(int ch);
|
||||
void notifyInsChange(int ins);
|
||||
void notifyInsDeletion(void* ins);
|
||||
void poke(unsigned int addr, unsigned short val);
|
||||
void poke(std::vector<DivRegWrite>& wlist);
|
||||
const char** getRegisterSheet();
|
||||
const char* getEffectName(unsigned char effect);
|
||||
int init(DivEngine* parent, int channels, int sugRate, unsigned int flags);
|
||||
void quit();
|
||||
~DivPlatformYM2610B();
|
||||
};
|
||||
#endif
|
||||
337
src/engine/platform/ym2610bext.cpp
Normal file
337
src/engine/platform/ym2610bext.cpp
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ym2610bext.h"
|
||||
#include "../engine.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "ym2610shared.h"
|
||||
|
||||
int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
||||
if (c.chan<2) {
|
||||
return DivPlatformYM2610B::dispatch(c);
|
||||
}
|
||||
if (c.chan>5) {
|
||||
c.chan-=3;
|
||||
return DivPlatformYM2610B::dispatch(c);
|
||||
}
|
||||
int ch=c.chan-2;
|
||||
int ordch=orderedOps[ch];
|
||||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins);
|
||||
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
// TODO: how does this work?!
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
if (opChan[ch].insChanged) {
|
||||
rWrite(baseAddr+0x40,127-(((127-op.tl)*(opChan[ch].vol&0x7f))/127));
|
||||
}
|
||||
}
|
||||
if (opChan[ch].insChanged) {
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
rWrite(baseAddr+0x50,(op.ar&31)|(op.rs<<6));
|
||||
rWrite(baseAddr+0x60,(op.dr&31)|(op.am<<7));
|
||||
rWrite(baseAddr+0x70,op.d2r&31);
|
||||
rWrite(baseAddr+0x80,(op.rr&15)|(op.sl<<4));
|
||||
rWrite(baseAddr+0x90,op.ssgEnv&15);
|
||||
}
|
||||
if (opChan[ch].insChanged) { // TODO how does this work?
|
||||
rWrite(chanOffs[2]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[2]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
}
|
||||
opChan[ch].insChanged=false;
|
||||
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
opChan[ch].baseFreq=NOTE_FREQUENCY(c.value);
|
||||
opChan[ch].freqChanged=true;
|
||||
}
|
||||
opChan[ch].keyOn=true;
|
||||
opChan[ch].active=true;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_NOTE_OFF:
|
||||
opChan[ch].keyOff=true;
|
||||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
break;
|
||||
case DIV_CMD_VOLUME: {
|
||||
opChan[ch].vol=c.value;
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins);
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,127-(((127-op.tl)*(opChan[ch].vol&0x7f))/127));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_GET_VOLUME: {
|
||||
return opChan[ch].vol;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_INSTRUMENT:
|
||||
if (opChan[ch].ins!=c.value || c.value2==1) {
|
||||
opChan[ch].insChanged=true;
|
||||
}
|
||||
opChan[ch].ins=c.value;
|
||||
break;
|
||||
case DIV_CMD_PANNING: {
|
||||
switch (c.value) {
|
||||
case 0x01:
|
||||
opChan[ch].pan=1;
|
||||
break;
|
||||
case 0x10:
|
||||
opChan[ch].pan=2;
|
||||
break;
|
||||
default:
|
||||
opChan[ch].pan=3;
|
||||
break;
|
||||
}
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins);
|
||||
// TODO: ???
|
||||
rWrite(chanOffs[2]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_PITCH: {
|
||||
opChan[ch].pitch=c.value;
|
||||
opChan[ch].freqChanged=true;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_NOTE_PORTA: {
|
||||
int destFreq=NOTE_FREQUENCY(c.value2);
|
||||
int newFreq;
|
||||
bool return2=false;
|
||||
if (destFreq>opChan[ch].baseFreq) {
|
||||
newFreq=opChan[ch].baseFreq+c.value*octave(opChan[ch].baseFreq);
|
||||
if (newFreq>=destFreq) {
|
||||
newFreq=destFreq;
|
||||
return2=true;
|
||||
}
|
||||
} else {
|
||||
newFreq=opChan[ch].baseFreq-c.value*octave(opChan[ch].baseFreq);
|
||||
if (newFreq<=destFreq) {
|
||||
newFreq=destFreq;
|
||||
return2=true;
|
||||
}
|
||||
}
|
||||
if (!opChan[ch].portaPause) {
|
||||
if (octave(opChan[ch].baseFreq)!=octave(newFreq)) {
|
||||
opChan[ch].portaPause=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
opChan[ch].baseFreq=newFreq;
|
||||
opChan[ch].portaPause=false;
|
||||
opChan[ch].freqChanged=true;
|
||||
if (return2) return 2;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_LEGATO: {
|
||||
opChan[ch].baseFreq=NOTE_FREQUENCY(c.value);
|
||||
opChan[ch].freqChanged=true;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_MULT: { // TODO
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins);
|
||||
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_TL: { // TODO
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins);
|
||||
if (isOutput[ins->fm.alg][c.value]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-c.value2)*(opChan[ch].vol&0x7f))/127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,c.value2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_AR: {
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins);
|
||||
if (c.value<0) {
|
||||
for (int i=0; i<4; i++) {
|
||||
DivInstrumentFM::Operator op=ins->fm.op[i];
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[i];
|
||||
rWrite(baseAddr+0x50,(c.value2&31)|(op.rs<<6));
|
||||
}
|
||||
} else {
|
||||
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
rWrite(baseAddr+0x50,(c.value2&31)|(op.rs<<6));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_GET_VOLMAX:
|
||||
return 127;
|
||||
break;
|
||||
case DIV_ALWAYS_SET_VOLUME:
|
||||
return 0;
|
||||
break;
|
||||
case DIV_CMD_PRE_PORTA:
|
||||
break;
|
||||
default:
|
||||
//printf("WARNING: unimplemented command %d\n",c.cmd);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int opChanOffsL[4]={
|
||||
0xa9, 0xaa, 0xa8, 0xa2
|
||||
};
|
||||
|
||||
static int opChanOffsH[4]={
|
||||
0xad, 0xae, 0xac, 0xa6
|
||||
};
|
||||
|
||||
void DivPlatformYM2610BExt::tick() {
|
||||
if (extMode) {
|
||||
bool writeSomething=false;
|
||||
unsigned char writeMask=2;
|
||||
for (int i=0; i<4; i++) {
|
||||
writeMask|=opChan[i].active<<(4+i);
|
||||
if (opChan[i].keyOn || opChan[i].keyOff) {
|
||||
writeSomething=true;
|
||||
writeMask&=~(1<<(4+i));
|
||||
opChan[i].keyOff=false;
|
||||
}
|
||||
}
|
||||
if (writeSomething) {
|
||||
immWrite(0x28,writeMask);
|
||||
}
|
||||
}
|
||||
|
||||
DivPlatformYM2610B::tick();
|
||||
|
||||
bool writeNoteOn=false;
|
||||
unsigned char writeMask=2;
|
||||
if (extMode) for (int i=0; i<4; i++) {
|
||||
if (opChan[i].freqChanged) {
|
||||
opChan[i].freq=parent->calcFreq(opChan[i].baseFreq,opChan[i].pitch);
|
||||
if (opChan[i].freq>262143) opChan[i].freq=262143;
|
||||
int freqt=toFreq(opChan[i].freq);
|
||||
opChan[i].freqH=freqt>>8;
|
||||
opChan[i].freqL=freqt&0xff;
|
||||
immWrite(opChanOffsH[i],opChan[i].freqH);
|
||||
immWrite(opChanOffsL[i],opChan[i].freqL);
|
||||
opChan[i].freqChanged=false;
|
||||
}
|
||||
writeMask|=opChan[i].active<<(4+i);
|
||||
if (opChan[i].keyOn) {
|
||||
writeNoteOn=true;
|
||||
writeMask|=1<<(4+i);
|
||||
opChan[i].keyOn=false;
|
||||
}
|
||||
}
|
||||
if (writeNoteOn) {
|
||||
immWrite(0x28,writeMask);
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformYM2610BExt::muteChannel(int ch, bool mute) {
|
||||
if (ch<2) {
|
||||
DivPlatformYM2610B::muteChannel(ch,mute);
|
||||
return;
|
||||
}
|
||||
if (ch>5) {
|
||||
DivPlatformYM2610B::muteChannel(ch-3,mute);
|
||||
return;
|
||||
}
|
||||
isOpMuted[ch-2]=mute;
|
||||
|
||||
int ordch=orderedOps[ch-2];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch-2].ins);
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
if (isOpMuted[ch-2]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (isOutput[ins->fm.alg][ordch]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-op.tl)*(opChan[ch-2].vol&0x7f))/127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformYM2610BExt::forceIns() {
|
||||
DivPlatformYM2610B::forceIns();
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i].insChanged=true;
|
||||
if (opChan[i].active) {
|
||||
opChan[i].keyOn=true;
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void* DivPlatformYM2610BExt::getChanState(int ch) {
|
||||
if (ch>=6) return &chan[ch-3];
|
||||
if (ch>=2) return &opChan[ch-2];
|
||||
return &chan[ch];
|
||||
}
|
||||
|
||||
void DivPlatformYM2610BExt::reset() {
|
||||
DivPlatformYM2610B::reset();
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i]=DivPlatformYM2610BExt::OpChannel();
|
||||
opChan[i].vol=127;
|
||||
}
|
||||
|
||||
// channel 2 mode
|
||||
immWrite(0x27,0x40);
|
||||
extMode=true;
|
||||
}
|
||||
|
||||
bool DivPlatformYM2610BExt::keyOffAffectsArp(int ch) {
|
||||
return (ch>8);
|
||||
}
|
||||
|
||||
void DivPlatformYM2610BExt::notifyInsChange(int ins) {
|
||||
DivPlatformYM2610B::notifyInsChange(ins);
|
||||
for (int i=0; i<4; i++) {
|
||||
if (opChan[i].ins==ins) {
|
||||
opChan[i].insChanged=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DivPlatformYM2610BExt::init(DivEngine* parent, int channels, int sugRate, unsigned int flags) {
|
||||
DivPlatformYM2610B::init(parent,channels,sugRate,flags);
|
||||
for (int i=0; i<4; i++) {
|
||||
isOpMuted[i]=false;
|
||||
}
|
||||
|
||||
reset();
|
||||
return 19;
|
||||
}
|
||||
|
||||
void DivPlatformYM2610BExt::quit() {
|
||||
DivPlatformYM2610B::quit();
|
||||
}
|
||||
|
||||
DivPlatformYM2610BExt::~DivPlatformYM2610BExt() {
|
||||
}
|
||||
51
src/engine/platform/ym2610bext.h
Normal file
51
src/engine/platform/ym2610bext.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "../dispatch.h"
|
||||
|
||||
#include "ym2610b.h"
|
||||
|
||||
class DivPlatformYM2610BExt: public DivPlatformYM2610B {
|
||||
struct OpChannel {
|
||||
DivMacroInt std;
|
||||
unsigned char freqH, freqL;
|
||||
int freq, baseFreq, pitch;
|
||||
unsigned char ins;
|
||||
signed char konCycles;
|
||||
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause;
|
||||
int vol;
|
||||
unsigned char pan;
|
||||
OpChannel(): freqH(0), freqL(0), freq(0), baseFreq(0), pitch(0), ins(-1), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), portaPause(false), vol(0), pan(3) {}
|
||||
};
|
||||
OpChannel opChan[4];
|
||||
bool isOpMuted[4];
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
public:
|
||||
int dispatch(DivCommand c);
|
||||
void* getChanState(int chan);
|
||||
void reset();
|
||||
void forceIns();
|
||||
void tick();
|
||||
void muteChannel(int ch, bool mute);
|
||||
bool keyOffAffectsArp(int ch);
|
||||
void notifyInsChange(int ins);
|
||||
int init(DivEngine* parent, int channels, int sugRate, unsigned int flags);
|
||||
void quit();
|
||||
~DivPlatformYM2610BExt();
|
||||
};
|
||||
|
|
@ -147,10 +147,6 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
if (return2) return 2;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_SAMPLE_MODE: {
|
||||
// ignored on extended channel 2 mode.
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_LEGATO: {
|
||||
opChan[ch].baseFreq=NOTE_FREQUENCY(c.value);
|
||||
opChan[ch].freqChanged=true;
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
static unsigned short chanOffs[4]={
|
||||
0x01, 0x02, 0x101, 0x102
|
||||
};
|
||||
static unsigned short opOffs[4]={
|
||||
0x00, 0x04, 0x08, 0x0c
|
||||
};
|
||||
|
|
@ -45,4 +42,4 @@ static int orderedOps[4]={
|
|||
#define rWrite(a,v) if (!skipRegisterWrites) {pendingWrites[a]=v;}
|
||||
#define immWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} }
|
||||
|
||||
#define CHIP_FREQBASE 9440540
|
||||
#define CHIP_FREQBASE 9440540
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue