Skip to content

Commit

Permalink
OPN: fix out of bounds when using some FM effects
Browse files Browse the repository at this point in the history
on non-FM channels
issue #2286
  • Loading branch information
tildearrow committed Dec 9, 2024
1 parent 5eae178 commit 52a4588
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/engine/platform/ym2203.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RS: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -954,6 +955,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_AM: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -970,6 +972,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -986,6 +989,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SL: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1002,6 +1006,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1018,6 +1023,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_D2R: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1034,6 +1040,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DT: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1050,6 +1057,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SSG: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand Down Expand Up @@ -1086,6 +1094,7 @@ int DivPlatformYM2203::dispatch(DivCommand c) {
}
break;
case DIV_CMD_FM_HARD_RESET:
if (c.chan>=psgChanOffs) break;
chan[c.chan].hardReset=c.value;
break;
case DIV_CMD_MACRO_OFF:
Expand Down
9 changes: 9 additions & 0 deletions src/engine/platform/ym2608.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RS: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1476,6 +1477,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_AM: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1492,6 +1494,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1508,6 +1511,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SL: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1524,6 +1528,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1540,6 +1545,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_D2R: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1556,6 +1562,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DT: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1572,6 +1579,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SSG: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand Down Expand Up @@ -1608,6 +1616,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
}
break;
case DIV_CMD_FM_HARD_RESET:
if (c.chan>=psgChanOffs) break;
chan[c.chan].hardReset=c.value;
break;
case DIV_CMD_MACRO_OFF:
Expand Down
9 changes: 9 additions & 0 deletions src/engine/platform/ym2610.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RS: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1443,6 +1444,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_AM: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1459,6 +1461,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1475,6 +1478,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SL: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1491,6 +1495,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1507,6 +1512,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_D2R: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1523,6 +1529,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DT: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1539,6 +1546,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SSG: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand Down Expand Up @@ -1575,6 +1583,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
}
break;
case DIV_CMD_FM_HARD_RESET:
if (c.chan>=psgChanOffs) break;
chan[c.chan].hardReset=c.value;
break;
case DIV_CMD_MACRO_OFF:
Expand Down
9 changes: 9 additions & 0 deletions src/engine/platform/ym2610b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RS: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1511,6 +1512,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_AM: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1527,6 +1529,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1543,6 +1546,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SL: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1559,6 +1563,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_RR: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1575,6 +1580,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_D2R: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1591,6 +1597,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_DT: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand All @@ -1607,6 +1614,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
break;
}
case DIV_CMD_FM_SSG: {
if (c.chan>=psgChanOffs) break;
if (c.value<0) {
for (int i=0; i<4; i++) {
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
Expand Down Expand Up @@ -1643,6 +1651,7 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
}
break;
case DIV_CMD_FM_HARD_RESET:
if (c.chan>=psgChanOffs) break;
chan[c.chan].hardReset=c.value;
break;
case DIV_CMD_MACRO_OFF:
Expand Down

0 comments on commit 52a4588

Please sign in to comment.