AY: add effects to write to I/O ports

This commit is contained in:
tildearrow 2022-03-26 20:55:43 -05:00
parent e143359b74
commit 73536c0691
7 changed files with 128 additions and 14 deletions

View file

@ -19,6 +19,7 @@
#include "ay8930.h"
#include "../engine.h"
#include "../../ta-log.h"
#include "sound/ay8910.h"
#include <string.h>
#include <math.h>
@ -99,6 +100,12 @@ const char* DivPlatformAY8930::getEffectName(unsigned char effect) {
case 0x29:
return "29xy: Set auto-envelope (x: numerator; y: denominator)";
break;
case 0x2e:
return "2Exx: Write to I/O port A";
break;
case 0x2f:
return "2Fxx: Write to I/O port B";
break;
}
return NULL;
}
@ -141,6 +148,30 @@ void DivPlatformAY8930::acquire(short* bufL, short* bufR, size_t start, size_t l
}
}
void DivPlatformAY8930::updateOutSel(bool immediate) {
if (immediate) {
immWrite(0x07,
~((chan[0].psgMode&1)|
((chan[1].psgMode&1)<<1)|
((chan[2].psgMode&1)<<2)|
((chan[0].psgMode&2)<<2)|
((chan[1].psgMode&2)<<3)|
((chan[2].psgMode&2)<<4)|
((!ioPortA)<<6)|
((!ioPortB)<<7)));
} else {
rWrite(0x07,
~((chan[0].psgMode&1)|
((chan[1].psgMode&1)<<1)|
((chan[2].psgMode&1)<<2)|
((chan[0].psgMode&2)<<2)|
((chan[1].psgMode&2)<<3)|
((chan[2].psgMode&2)<<4)|
((!ioPortA)<<6)|
((!ioPortB)<<7)));
}
}
const unsigned char regPeriodL[3]={
0x0b, 0x10, 0x12
};
@ -262,13 +293,7 @@ void DivPlatformAY8930::tick() {
}
}
rWrite(0x07,
~((chan[0].psgMode&1)|
((chan[1].psgMode&1)<<1)|
((chan[2].psgMode&1)<<2)|
((chan[0].psgMode&2)<<2)|
((chan[1].psgMode&2)<<3)|
((chan[2].psgMode&2)<<4)));
updateOutSel();
for (int i=0; i<32; i++) {
if (pendingWrites[i]!=oldWrites[i]) {
@ -420,6 +445,19 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
chan[c.chan].autoEnvDen=c.value&15;
chan[c.chan].freqChanged=true;
break;
case DIV_CMD_AY_IO_WRITE:
if (c.value) { // port B
ioPortB=true;
portBVal=c.value2;
logI("AY I/O port B write: %x\n",portBVal);
} else { // port A
ioPortA=true;
portAVal=c.value2;
logI("AY I/O port A write: %x\n",portAVal);
}
updateOutSel(true);
immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal));
break;
case DIV_ALWAYS_SET_VOLUME:
return 0;
break;
@ -499,6 +537,11 @@ void DivPlatformAY8930::reset() {
extMode=false;
bank=false;
ioPortA=false;
ioPortB=false;
portAVal=0;
portBVal=0;
immWrite(0x0d,0xa0);
immWrite(0x19,2); // and mask
immWrite(0x1a,0x00); // or mask