2021-05-12 08:58:55 +00:00
|
|
|
#include "engine.h"
|
|
|
|
|
|
|
|
void DivEngine::nextOrder() {
|
|
|
|
curRow=0;
|
|
|
|
if (++curOrder>=song.ordersLen) {
|
|
|
|
curOrder=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* notes[12]={
|
|
|
|
"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"
|
|
|
|
};
|
|
|
|
|
2021-05-19 07:05:24 +00:00
|
|
|
const char* cmdName[DIV_CMD_MAX]={
|
|
|
|
"NOTE_ON",
|
|
|
|
"NOTE_OFF",
|
|
|
|
"INSTRUMENT",
|
|
|
|
"VOLUME",
|
|
|
|
"GET_VOLUME",
|
|
|
|
"GET_VOLMAX",
|
|
|
|
"NOTE_PORTA",
|
|
|
|
"PITCH",
|
|
|
|
"PANNING",
|
|
|
|
"LEGATO",
|
|
|
|
"PRE_PORTA",
|
|
|
|
|
|
|
|
"SAMPLE_MODE",
|
|
|
|
|
|
|
|
"FM_TL",
|
|
|
|
"FM_AR",
|
|
|
|
"FM_FB",
|
|
|
|
"FM_MULT",
|
|
|
|
"FM_EXTCH",
|
|
|
|
|
|
|
|
"GENESIS_LFO",
|
|
|
|
|
|
|
|
"ARCADE_LFO",
|
|
|
|
|
|
|
|
"STD_NOISE_FREQ",
|
2021-05-28 05:36:25 +00:00
|
|
|
"STD_NOISE_MODE",
|
|
|
|
|
|
|
|
"WAVE",
|
|
|
|
|
|
|
|
"GB_SWEEP_TIME",
|
|
|
|
"GB_SWEEP_DIR",
|
|
|
|
|
|
|
|
"ALWAYS_SET_VOLUME"
|
2021-05-19 07:05:24 +00:00
|
|
|
};
|
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
const char* formatNote(unsigned char note, unsigned char octave) {
|
|
|
|
static char ret[4];
|
|
|
|
if (note==100) {
|
|
|
|
return "OFF";
|
2021-05-13 07:39:26 +00:00
|
|
|
} else if (octave==0 && note==0) {
|
2021-05-12 08:58:55 +00:00
|
|
|
return "---";
|
|
|
|
}
|
|
|
|
snprintf(ret,4,"%s%d",notes[note%12],octave+note/12);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-05-19 07:05:24 +00:00
|
|
|
int DivEngine::dispatchCmd(DivCommand c) {
|
|
|
|
if (view==DIV_STATUS_COMMANDS) {
|
|
|
|
printf("%8d | %d: %s(%d, %d)\n",totalTicks,c.chan,cmdName[c.cmd],c.value,c.value2);
|
|
|
|
}
|
|
|
|
totalCmds++;
|
|
|
|
return dispatch->dispatch(c);
|
|
|
|
}
|
|
|
|
|
2021-05-13 07:39:26 +00:00
|
|
|
bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effectVal) {
|
|
|
|
switch (song.system) {
|
|
|
|
case DIV_SYSTEM_GENESIS:
|
2021-05-16 22:43:10 +00:00
|
|
|
case DIV_SYSTEM_GENESIS_EXT:
|
2021-05-13 07:39:26 +00:00
|
|
|
switch (effect) {
|
|
|
|
case 0x17: // DAC enable
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_MODE,ch,(effectVal>0)));
|
2021-05-13 07:39:26 +00:00
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0x20: // SN noise mode
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 19:18:16 +00:00
|
|
|
case DIV_SYSTEM_SMS:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x20: // SN noise mode
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
2021-05-15 19:18:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-28 05:36:25 +00:00
|
|
|
case DIV_SYSTEM_GB:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x10: // select waveform
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_WAVE,ch,effectVal));
|
|
|
|
break;
|
2021-05-28 06:26:57 +00:00
|
|
|
case 0x11: case 0x12: // duty or noise mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x13: // sweep params
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_GB_SWEEP_TIME,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x14: // sweep direction
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_GB_SWEEP_DIR,ch,effectVal));
|
|
|
|
break;
|
2021-05-28 05:36:25 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-15 08:13:21 +00:00
|
|
|
bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal) {
|
|
|
|
switch (song.system) {
|
|
|
|
case DIV_SYSTEM_GENESIS:
|
2021-05-16 22:43:10 +00:00
|
|
|
case DIV_SYSTEM_GENESIS_EXT:
|
2021-05-15 08:13:21 +00:00
|
|
|
switch (effect) {
|
|
|
|
case 0x11: // FB
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_FB,ch,effectVal&7));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x12: // TL op1
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,0,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x13: // TL op2
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,1,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x14: // TL op3
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,2,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x15: // TL op4
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,3,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x16: // MULT
|
|
|
|
if ((effectVal>>4)>0 && (effectVal>>4)<5) {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_MULT,ch,(effectVal>>4)-1,effectVal&15));
|
2021-05-15 08:13:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x18: // EXT
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_EXTCH,ch,effectVal));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x19: // AR global
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,-1,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1a: // AR op1
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,0,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1b: // AR op2
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,1,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1c: // AR op3
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,2,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1d: // AR op4
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,3,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
void DivEngine::processRow(int i, bool afterDelay) {
|
|
|
|
DivPattern* pat=song.pat[i]->data[curOrder];
|
|
|
|
// pre effects
|
|
|
|
if (!afterDelay) for (int j=0; j<song.pat[i]->effectRows; j++) {
|
|
|
|
short effect=pat->data[curRow][4+(j<<1)];
|
|
|
|
short effectVal=pat->data[curRow][5+(j<<1)];
|
|
|
|
|
|
|
|
if (effectVal==-1) effectVal=0;
|
|
|
|
if (effect==0xed) {
|
|
|
|
chan[i].rowDelay=effectVal+1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// instrument
|
|
|
|
if (pat->data[curRow][2]!=-1) {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_INSTRUMENT,i,pat->data[curRow][2]));
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
// note
|
|
|
|
if (pat->data[curRow][0]==100) {
|
|
|
|
chan[i].note=-1;
|
2021-05-19 07:22:26 +00:00
|
|
|
chan[i].keyOn=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
if (chan[i].stopOnOff) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
chan[i].stopOnOff=false;
|
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,i));
|
2021-05-16 08:03:23 +00:00
|
|
|
} else if (!(pat->data[curRow][0]==0 && pat->data[curRow][1]==0)) {
|
|
|
|
chan[i].note=pat->data[curRow][0]+pat->data[curRow][1]*12;
|
2021-05-26 07:06:40 +00:00
|
|
|
if (!chan[i].keyOn) {
|
|
|
|
chan[i].arp=0;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
chan[i].doNote=true;
|
2021-05-28 05:36:25 +00:00
|
|
|
if (chan[i].arp!=0) {
|
|
|
|
chan[i].arpYield=true;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// volume
|
|
|
|
if (pat->data[curRow][3]!=-1) {
|
2021-05-28 05:36:25 +00:00
|
|
|
if (dispatchCmd(DivCommand(DIV_ALWAYS_SET_VOLUME,i)) || (MIN(chan[i].volMax,chan[i].volume)>>8)!=pat->data[curRow][3]) {
|
2021-05-17 20:06:11 +00:00
|
|
|
chan[i].volume=pat->data[curRow][3]<<8;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
2021-05-17 20:06:11 +00:00
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// effects
|
|
|
|
for (int j=0; j<song.pat[i]->effectRows; j++) {
|
|
|
|
short effect=pat->data[curRow][4+(j<<1)];
|
|
|
|
short effectVal=pat->data[curRow][5+(j<<1)];
|
|
|
|
|
|
|
|
if (effectVal==-1) effectVal=0;
|
|
|
|
|
|
|
|
// per-system effect
|
|
|
|
if (!perSystemEffect(i,effect,effectVal)) switch (effect) {
|
|
|
|
case 0x09: // speed 1
|
|
|
|
song.speed1=effectVal;
|
|
|
|
break;
|
|
|
|
case 0x0f: // speed 2
|
|
|
|
song.speed2=effectVal;
|
|
|
|
break;
|
|
|
|
case 0x0b: // change order
|
|
|
|
changeOrd=effectVal;
|
|
|
|
changePos=0;
|
|
|
|
break;
|
|
|
|
case 0x0d: // next order
|
|
|
|
changeOrd=curOrder+1;
|
|
|
|
changePos=effectVal;
|
|
|
|
break;
|
|
|
|
case 0x08: // panning
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PANNING,i,effectVal));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x01: // ramp up
|
|
|
|
if (effectVal==0) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
} else {
|
|
|
|
chan[i].portaNote=0x60;
|
|
|
|
chan[i].portaSpeed=effectVal;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].portaStop=true;
|
|
|
|
chan[i].nowYouCanStop=false;
|
|
|
|
chan[i].stopOnOff=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: // ramp down
|
|
|
|
if (effectVal==0) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
} else {
|
|
|
|
chan[i].portaNote=0x00;
|
|
|
|
chan[i].portaSpeed=effectVal;
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].portaStop=true;
|
|
|
|
chan[i].nowYouCanStop=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x03: // portamento
|
|
|
|
if (effectVal==0) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
} else {
|
|
|
|
chan[i].portaNote=chan[i].note;
|
|
|
|
chan[i].portaSpeed=effectVal;
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].portaStop=true;
|
2021-05-16 08:03:23 +00:00
|
|
|
chan[i].doNote=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=true;
|
2021-05-28 07:30:09 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PRE_PORTA,i,true));
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x04: // vibrato
|
|
|
|
chan[i].vibratoDepth=effectVal&15;
|
|
|
|
chan[i].vibratoRate=effectVal>>4;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x0a: // volume ramp
|
|
|
|
if (effectVal!=0) {
|
|
|
|
if ((effectVal&15)!=0) {
|
|
|
|
chan[i].volSpeed=-(effectVal&15)*64;
|
|
|
|
} else {
|
|
|
|
chan[i].volSpeed=(effectVal>>4)*64;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chan[i].volSpeed=0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x00: // arpeggio
|
|
|
|
chan[i].arp=effectVal;
|
|
|
|
break;
|
2021-05-18 07:29:17 +00:00
|
|
|
case 0x0c: // retrigger
|
|
|
|
chan[i].rowDelay=effectVal+1;
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
|
2021-05-18 07:53:59 +00:00
|
|
|
case 0xe0: // arp speed
|
|
|
|
song.arpLen=effectVal;
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0xe1: // portamento up
|
|
|
|
chan[i].portaNote=chan[i].note+(effectVal&15);
|
2021-05-18 06:37:14 +00:00
|
|
|
chan[i].portaSpeed=(effectVal>>4)*4;
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].portaStop=true;
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].nowYouCanStop=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=true;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0xe2: // portamento down
|
|
|
|
chan[i].portaNote=chan[i].note-(effectVal&15);
|
2021-05-18 06:37:14 +00:00
|
|
|
chan[i].portaSpeed=(effectVal>>4)*4;
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].portaStop=true;
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].nowYouCanStop=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=true;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
2021-05-18 07:29:17 +00:00
|
|
|
case 0xe3: // vibrato direction
|
|
|
|
chan[i].vibratoDir=effectVal;
|
|
|
|
break;
|
2021-05-18 08:02:47 +00:00
|
|
|
case 0xe4: // vibrato fine
|
|
|
|
chan[i].vibratoFine=effectVal;
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0xe5: // pitch
|
|
|
|
chan[i].pitch=effectVal-0x80;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0xea: // legato mode
|
|
|
|
chan[i].legato=effectVal;
|
|
|
|
break;
|
|
|
|
case 0xec: // delayed note cut
|
2021-05-16 08:20:32 +00:00
|
|
|
chan[i].cut=effectVal+1;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
2021-05-18 07:53:59 +00:00
|
|
|
case 0xee: // external command
|
|
|
|
printf("\x1b[1;36m%d: extern command %d\x1b[m\n",i,effectVal);
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chan[i].doNote) {
|
|
|
|
chan[i].vibratoPos=0;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-16 08:03:23 +00:00
|
|
|
if (chan[i].legato) {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
2021-05-16 08:03:23 +00:00
|
|
|
} else {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_ON,i,chan[i].note,chan[i].volume>>8));
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
chan[i].doNote=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
/*
|
2021-05-19 07:22:26 +00:00
|
|
|
if (!chan[i].keyOn) {
|
2021-05-19 08:09:51 +00:00
|
|
|
if (chan[i].portaStop && chan[i].nowYouCanStop) {
|
2021-05-19 07:22:26 +00:00
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
}
|
2021-05-26 07:34:40 +00:00
|
|
|
}*/
|
2021-05-19 07:22:26 +00:00
|
|
|
chan[i].keyOn=true;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].nowYouCanStop=true;
|
2021-05-16 08:03:23 +00:00
|
|
|
|
|
|
|
// post effects
|
|
|
|
for (int j=0; j<song.pat[i]->effectRows; j++) {
|
|
|
|
short effect=pat->data[curRow][4+(j<<1)];
|
|
|
|
short effectVal=pat->data[curRow][5+(j<<1)];
|
|
|
|
|
|
|
|
if (effectVal==-1) effectVal=0;
|
|
|
|
perSystemPostEffect(i,effect,effectVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
void DivEngine::nextRow() {
|
|
|
|
static char pb[4096];
|
|
|
|
static char pb1[4096];
|
|
|
|
static char pb2[4096];
|
|
|
|
static char pb3[4096];
|
|
|
|
if (++curRow>=song.patLen) {
|
|
|
|
nextOrder();
|
|
|
|
}
|
2021-05-12 10:22:01 +00:00
|
|
|
if (changeOrd>=0) {
|
|
|
|
curRow=changePos;
|
|
|
|
curOrder=changeOrd;
|
|
|
|
if (curOrder>=song.ordersLen) {
|
|
|
|
curOrder=0;
|
|
|
|
}
|
|
|
|
changeOrd=-1;
|
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
|
|
|
|
if (view==DIV_STATUS_PATTERN) {
|
|
|
|
strcpy(pb1,"");
|
|
|
|
strcpy(pb3,"");
|
|
|
|
for (int i=0; i<chans; i++) {
|
|
|
|
snprintf(pb,4095," %.2x",song.orders.ord[i][curOrder]);
|
|
|
|
strcat(pb1,pb);
|
|
|
|
|
|
|
|
DivPattern* pat=song.pat[i]->data[curOrder];
|
|
|
|
snprintf(pb2,4095,"\x1b[37m %s",
|
|
|
|
formatNote(pat->data[curRow][0],pat->data[curRow][1]));
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,pb2);
|
2021-05-19 07:05:24 +00:00
|
|
|
if (pat->data[curRow][3]==-1) {
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
2021-05-19 07:05:24 +00:00
|
|
|
snprintf(pb2,4095,"\x1b[1;32m%.2x",pat->data[curRow][3]);
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
if (pat->data[curRow][2]==-1) {
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
2021-05-19 07:05:24 +00:00
|
|
|
snprintf(pb2,4095,"\x1b[0;36m%.2x",pat->data[curRow][2]);
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
for (int j=0; j<song.pat[i]->effectRows; j++) {
|
|
|
|
if (pat->data[curRow][4+(j<<1)]==-1) {
|
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
|
|
|
snprintf(pb2,4095,"\x1b[1;31m%.2x",pat->data[curRow][4+(j<<1)]);
|
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
|
|
|
if (pat->data[curRow][5+(j<<1)]==-1) {
|
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
|
|
|
snprintf(pb2,4095,"\x1b[1;37m%.2x",pat->data[curRow][5+(j<<1)]);
|
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
printf("| %.2x:%s | \x1b[1;33m%3d%s\x1b[m\n",curOrder,pb1,curRow,pb3);
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2021-05-12 10:22:01 +00:00
|
|
|
|
|
|
|
for (int i=0; i<chans; i++) {
|
2021-05-18 07:29:17 +00:00
|
|
|
chan[i].rowDelay=0;
|
2021-05-16 08:03:23 +00:00
|
|
|
processRow(i,false);
|
2021-05-12 10:22:01 +00:00
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivEngine::nextTick() {
|
|
|
|
if (song.customTempo) {
|
|
|
|
cycles=dispatch->rate/song.hz;
|
|
|
|
} else {
|
|
|
|
if (song.pal) {
|
|
|
|
cycles=dispatch->rate/60;
|
|
|
|
} else {
|
|
|
|
cycles=dispatch->rate/50;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (--ticks<=0) {
|
2021-05-12 10:22:01 +00:00
|
|
|
nextRow();
|
2021-05-12 08:58:55 +00:00
|
|
|
if (speedAB) {
|
|
|
|
ticks=song.speed2*(song.timeBase+1);
|
|
|
|
} else {
|
|
|
|
ticks=song.speed1*(song.timeBase+1);
|
|
|
|
}
|
|
|
|
speedAB=!speedAB;
|
|
|
|
}
|
2021-05-14 08:23:40 +00:00
|
|
|
// process stuff
|
|
|
|
for (int i=0; i<chans; i++) {
|
2021-05-16 08:03:23 +00:00
|
|
|
if (chan[i].rowDelay>0) {
|
|
|
|
if (--chan[i].rowDelay==0) {
|
|
|
|
processRow(i,true);
|
|
|
|
}
|
|
|
|
}
|
2021-05-14 08:23:40 +00:00
|
|
|
if (chan[i].volSpeed!=0) {
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].volume=(chan[i].volume&0xff)|(dispatchCmd(DivCommand(DIV_CMD_GET_VOLUME,i))<<8);
|
2021-05-14 08:23:40 +00:00
|
|
|
chan[i].volume+=chan[i].volSpeed;
|
2021-05-17 20:06:11 +00:00
|
|
|
if (chan[i].volume>chan[i].volMax) {
|
|
|
|
chan[i].volume=chan[i].volMax;
|
2021-05-18 06:52:03 +00:00
|
|
|
chan[i].volSpeed=0;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
2021-05-17 20:06:11 +00:00
|
|
|
} else if (chan[i].volume<0) {
|
|
|
|
chan[i].volSpeed=0;
|
2021-05-18 06:52:03 +00:00
|
|
|
chan[i].volume=chan[i].volMax+1;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
2021-05-17 20:06:11 +00:00
|
|
|
} else {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
2021-05-17 20:06:11 +00:00
|
|
|
}
|
2021-05-14 08:23:40 +00:00
|
|
|
}
|
2021-05-14 19:16:48 +00:00
|
|
|
if (chan[i].vibratoDepth>0) {
|
|
|
|
chan[i].vibratoPos+=chan[i].vibratoRate;
|
2021-05-16 08:03:23 +00:00
|
|
|
if (chan[i].vibratoPos>=64) chan[i].vibratoPos-=64;
|
2021-05-18 07:29:17 +00:00
|
|
|
switch (chan[i].vibratoDir) {
|
|
|
|
case 1: // up
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(MAX(0,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-18 07:29:17 +00:00
|
|
|
break;
|
|
|
|
case 2: // down
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(MIN(0,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-18 07:29:17 +00:00
|
|
|
break;
|
|
|
|
default: // both
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-18 07:29:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-14 19:16:48 +00:00
|
|
|
}
|
|
|
|
if (chan[i].portaSpeed>0) {
|
2021-05-19 07:05:24 +00:00
|
|
|
if (dispatchCmd(DivCommand(DIV_CMD_NOTE_PORTA,i,chan[i].portaSpeed,chan[i].portaNote))==2 && chan[i].portaStop) {
|
2021-05-14 19:16:48 +00:00
|
|
|
chan[i].portaSpeed=0;
|
2021-05-28 07:30:09 +00:00
|
|
|
chan[i].note=chan[i].portaNote;
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
2021-05-14 19:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
if (chan[i].cut>0) {
|
|
|
|
if (--chan[i].cut<1) {
|
|
|
|
chan[i].note=-1;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,i));
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-28 05:36:25 +00:00
|
|
|
if (chan[i].arp!=0 && !chan[i].arpYield && chan[i].portaSpeed<1) {
|
2021-05-18 07:53:59 +00:00
|
|
|
if (--chan[i].arpTicks<1) {
|
|
|
|
chan[i].arpTicks=song.arpLen;
|
|
|
|
chan[i].arpStage++;
|
|
|
|
if (chan[i].arpStage>2) chan[i].arpStage=0;
|
|
|
|
switch (chan[i].arpStage) {
|
|
|
|
case 0:
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note+(chan[i].arp>>4)));
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note+(chan[i].arp&15)));
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
2021-05-28 05:36:25 +00:00
|
|
|
} else {
|
|
|
|
chan[i].arpYield=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
2021-05-14 08:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// system tick
|
2021-05-12 10:22:01 +00:00
|
|
|
dispatch->tick();
|
2021-05-19 07:05:24 +00:00
|
|
|
|
|
|
|
totalTicks++;
|
|
|
|
|
|
|
|
int hz;
|
|
|
|
if (song.customTempo) {
|
|
|
|
hz=song.hz;
|
|
|
|
} else if (song.pal) {
|
|
|
|
hz=60;
|
|
|
|
} else {
|
|
|
|
hz=50;
|
|
|
|
}
|
|
|
|
fprintf(stderr,"\x1b[2K> %d:%.2d:%.2d.%.2d %.2x/%.2x:%.3d/%.3d %4dcmd/s\x1b[G",totalTicks/(hz*3600),(totalTicks/(hz*60))%60,(totalTicks/hz)%60,totalTicks%hz,curOrder,song.ordersLen,curRow,song.patLen,cmdsPerSecond);
|
|
|
|
|
|
|
|
if ((totalTicks%hz)==0) {
|
|
|
|
cmdsPerSecond=totalCmds-lastCmds;
|
|
|
|
lastCmds=totalCmds;
|
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size) {
|
|
|
|
size_t runtotal=blip_clocks_needed(bb[0],size);
|
|
|
|
for (size_t i=0; i<runtotal; i++) {
|
|
|
|
if (--cycles<=0) {
|
|
|
|
nextTick();
|
|
|
|
}
|
|
|
|
dispatch->acquire(temp[0],temp[1]);
|
|
|
|
|
|
|
|
blip_add_delta(bb[0],i,temp[0]-prevSample[0]);
|
|
|
|
blip_add_delta(bb[1],i,temp[1]-prevSample[1]);
|
|
|
|
prevSample[0]=temp[0];
|
|
|
|
prevSample[1]=temp[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
blip_end_frame(bb[0],runtotal);
|
|
|
|
blip_end_frame(bb[1],runtotal);
|
|
|
|
|
|
|
|
blip_read_samples(bb[0],bbOut[0],size,0);
|
|
|
|
blip_read_samples(bb[1],bbOut[1],size,0);
|
|
|
|
|
|
|
|
for (size_t i=0; i<size; i++) {
|
2021-05-13 07:39:26 +00:00
|
|
|
out[0][i]=(float)bbOut[0][i]/16384.0;
|
|
|
|
out[1][i]=(float)bbOut[1][i]/16384.0;
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2021-05-12 10:22:01 +00:00
|
|
|
}
|