Small refactor for AY(s) driving bus for 6522 PortA

This commit is contained in:
tomcw 2024-01-06 18:20:33 +00:00
parent 4ab60cebf8
commit 0888a25710
4 changed files with 51 additions and 36 deletions

View File

@ -43,6 +43,7 @@ void SY6522::Reset(const bool powerCycle)
memset(&m_regs, 0, sizeof(Regs));
m_regs.TIMER1_LATCH.w = 0xffff; // Some random value (but pick $ffff so it's deterministic)
// . NB. if it's too small (< ~$0007) then MB detection routines will fail!
m_isBusDriven = false;
}
CpuCreateCriticalSection(); // Reset() called by SY6522 global ctor, so explicitly create CPU's CriticalSection
@ -336,7 +337,7 @@ bool SY6522::IsTimer2Underflowed(BYTE reg)
//-----------------------------------------------------------------------------
BYTE SY6522::Read(BYTE nReg, bool isDrivingBus/*=false*/)
BYTE SY6522::Read(BYTE nReg)
{
BYTE nValue = 0x00;
@ -346,7 +347,7 @@ BYTE SY6522::Read(BYTE nReg, bool isDrivingBus/*=false*/)
nValue = m_regs.ORB | (m_regs.DDRB ^ 0xff); // Input bits read back as 1's (GH#1260)
break;
case 0x01: // IRA
nValue = m_regs.ORA | (isDrivingBus ? 0x00 : (m_regs.DDRA ^ 0xff)); // NB. Inputs bits driven by AY8913 if in PSG READ mode
nValue = m_regs.ORA | (m_isBusDriven ? 0x00 : (m_regs.DDRA ^ 0xff)); // NB. Inputs bits driven by AY8913 if in PSG READ mode
break;
case 0x02: // DDRB
nValue = m_regs.DDRB;

View File

@ -3,7 +3,7 @@
class SY6522
{
public:
SY6522(UINT slot, bool isMegaAudio) : m_slot(slot), m_isMegaAudio(isMegaAudio)
SY6522(UINT slot, bool isMegaAudio) : m_slot(slot), m_isMegaAudio(isMegaAudio), m_isBusDriven(false)
{
for (UINT i = 0; i < kNumTimersPer6522; i++)
m_syncEvent[i] = NULL;
@ -54,8 +54,9 @@ public:
void GetRegs(BYTE regs[SIZE_6522_REGS]) { memcpy(&regs[0], (BYTE*)&m_regs, SIZE_6522_REGS); } // For debugger
void SetRegIRA(BYTE reg) { m_regs.ORA = reg; }
bool IsTimer1IrqDelay(void) { return m_timer1IrqDelay ? true : false; }
void SetBusBeingDriven(bool state) { m_isBusDriven = state; }
BYTE Read(BYTE nReg, bool isDrivingBus = false);
BYTE Read(BYTE nReg);
void Write(BYTE nReg, BYTE nValue);
void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
@ -144,6 +145,7 @@ private:
class SyncEvent* m_syncEvent[kNumTimersPer6522];
UINT m_slot;
bool m_isMegaAudio;
bool m_isBusDriven;
static const UINT kExtraMegaAudioTimerCycles = kExtraTimerCycles + 1;
};

View File

@ -252,7 +252,7 @@ void MockingboardCard::WriteToORB(BYTE subunit, BYTE subunitForAY/*=0*/)
AY8913_Write(subunit, AY8913_DEVICE_B, value);
if (nAY_CS == 0)
m_MBSubUnit[subunit].isDrivingBus = false;
m_MBSubUnit[subunit].SetBusState(false);
}
else
{
@ -310,28 +310,32 @@ void MockingboardCard::AY8913_Write(BYTE subunit, BYTE ay, BYTE value)
break;
case AY_READ: // 5: READ FROM PSG (need to set DDRA to input)
pMB->isDrivingBus = true; // Initially default to true
{
bool busState = true; // Initially default to true
if (QueryType() != CT_MegaAudio)
{
if (pMB->isChipSelected[ay] && pMB->isAYLatchedAddressValid[ay])
r6522.SetRegIRA(AYReadReg(subunit, ay, pMB->nAYCurrentRegister[ay]) & (r6522.GetReg(SY6522::rDDRA) ^ 0xff));
else
pMB->isDrivingBus = false;
}
else
{
r6522.SetRegIRA(0x00); // Reads not supported. Bus not driven.
pMB->isDrivingBus = false;
}
if (m_phasorEnable && m_phasorMode == PH_Phasor) // GH#1192
{
if (ay == AY8913_DEVICE_A)
if (QueryType() != CT_MegaAudio)
{
if (pMB->isChipSelected[AY8913_DEVICE_B] && pMB->isAYLatchedAddressValid[AY8913_DEVICE_B])
r6522.SetRegIRA(r6522.GetReg(SY6522::rORA) | (AYReadReg(subunit, AY8913_DEVICE_B, pMB->nAYCurrentRegister[AY8913_DEVICE_B]) & (r6522.GetReg(SY6522::rDDRA) ^ 0xff)));
if (pMB->isChipSelected[ay] && pMB->isAYLatchedAddressValid[ay])
r6522.SetRegIRA(AYReadReg(subunit, ay, pMB->nAYCurrentRegister[ay]) & (r6522.GetReg(SY6522::rDDRA) ^ 0xff));
else
busState = false;
}
else
{
r6522.SetRegIRA(0x00); // Reads not supported. Bus not driven.
busState = false;
}
if (m_phasorEnable && m_phasorMode == PH_Phasor) // GH#1192
{
if (ay == AY8913_DEVICE_A)
{
if (pMB->isChipSelected[AY8913_DEVICE_B] && pMB->isAYLatchedAddressValid[AY8913_DEVICE_B])
r6522.SetRegIRA(r6522.GetReg(SY6522::rORA) | (AYReadReg(subunit, AY8913_DEVICE_B, pMB->nAYCurrentRegister[AY8913_DEVICE_B]) & (r6522.GetReg(SY6522::rDDRA) ^ 0xff)));
}
}
pMB->SetBusState(busState);
}
break;
@ -383,7 +387,7 @@ void MockingboardCard::AY8913_Write(BYTE subunit, BYTE ay, BYTE value)
state = nAYFunc;
if (state == AY_INACTIVE) // Mockingboard or Phasor(any mode) will read PortA inputs as high.
pMB->isDrivingBus = false;
pMB->SetBusState(false);
}
//-----------------------------------------------------------------------------
@ -641,10 +645,10 @@ BYTE MockingboardCard::IOReadInternal(WORD PC, WORD nAddr, BYTE bWrite, BYTE nVa
BYTE nRes = 0;
if (CS & 1)
nRes |= m_MBSubUnit[SY6522_DEVICE_A].sy6522.Read(nAddr & 0xf, m_MBSubUnit[SY6522_DEVICE_A].isDrivingBus);
nRes |= m_MBSubUnit[SY6522_DEVICE_A].sy6522.Read(nAddr & 0xf);
if (CS & 2)
nRes |= m_MBSubUnit[SY6522_DEVICE_B].sy6522.Read(nAddr & 0xf, m_MBSubUnit[SY6522_DEVICE_B].isDrivingBus);
nRes |= m_MBSubUnit[SY6522_DEVICE_B].sy6522.Read(nAddr & 0xf);
bool bAccessedDevice = (CS & 3) ? true : false;
@ -671,7 +675,7 @@ BYTE MockingboardCard::IOReadInternal(WORD PC, WORD nAddr, BYTE bWrite, BYTE nVa
// NB. Mockingboard: SSI263.bit7 not readable (TODO: check this with real h/w)
const BYTE subunit = QueryType() == CT_SDMusic ? SY6522_DEVICE_A : !(nAddr & 0x80) ? SY6522_DEVICE_A : SY6522_DEVICE_B;
const BYTE reg = nAddr & 0xf;
return m_MBSubUnit[subunit].sy6522.Read(reg, m_MBSubUnit[subunit].isDrivingBus);
return m_MBSubUnit[subunit].sy6522.Read(reg);
}
//-----------------------------------------------------------------------------
@ -1236,7 +1240,7 @@ void MockingboardCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
yamlSaveHelper.SaveHexUint8(SS_YAML_KEY_AY_CURR_REG, pMB->nAYCurrentRegister[0]); // save all 8 bits (even though top 4 bits should be 0)
yamlSaveHelper.SaveBool(SS_YAML_KEY_CS_A, pMB->isChipSelected[0]);
yamlSaveHelper.SaveBool(SS_YAML_KEY_LATCH_ADDR_VALID_A, pMB->isAYLatchedAddressValid[0]);
yamlSaveHelper.SaveBool(SS_YAML_KEY_BUS_DRIVEN, pMB->isDrivingBus);
yamlSaveHelper.SaveBool(SS_YAML_KEY_BUS_DRIVEN, pMB->isBusDriven);
}
}
@ -1303,9 +1307,10 @@ bool MockingboardCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version
pMB->isAYLatchedAddressValid[0] = yamlLoadHelper.LoadBool(SS_YAML_KEY_LATCH_ADDR_VALID_A);
}
pMB->isDrivingBus = (pMB->state[0] == AY_READ);
bool busState = (pMB->state[0] == AY_READ);
if (version >= 11)
pMB->isDrivingBus = yamlLoadHelper.LoadBool(SS_YAML_KEY_BUS_DRIVEN);
busState = yamlLoadHelper.LoadBool(SS_YAML_KEY_BUS_DRIVEN);
pMB->SetBusState(busState);
yamlLoadHelper.PopMap();
}
@ -1347,7 +1352,7 @@ void MockingboardCard::Phasor_SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
yamlSaveHelper.SaveBool(SS_YAML_KEY_LATCH_ADDR_VALID_A, pMB->isAYLatchedAddressValid[0]);
yamlSaveHelper.SaveBool(SS_YAML_KEY_LATCH_ADDR_VALID_B, pMB->isAYLatchedAddressValid[1]);
yamlSaveHelper.SaveBool(SS_YAML_KEY_BUS_DRIVEN, pMB->isDrivingBus);
yamlSaveHelper.SaveBool(SS_YAML_KEY_BUS_DRIVEN, pMB->isBusDriven);
}
}
@ -1442,9 +1447,10 @@ bool MockingboardCard::Phasor_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT
pMB->isAYLatchedAddressValid[1] = yamlLoadHelper.LoadBool(SS_YAML_KEY_LATCH_ADDR_VALID_B);
}
pMB->isDrivingBus = (pMB->state[0] == AY_READ || pMB->state[1] == AY_READ);
bool busState = (pMB->state[0] == AY_READ || pMB->state[1] == AY_READ);
if (version >= 11)
pMB->isDrivingBus = yamlLoadHelper.LoadBool(SS_YAML_KEY_BUS_DRIVEN);
busState = yamlLoadHelper.LoadBool(SS_YAML_KEY_BUS_DRIVEN);
pMB->SetBusState(busState);
yamlLoadHelper.PopMap();
}

View File

@ -87,7 +87,7 @@ private:
MockingboardUnitState_e state[NUM_AY8913_PER_SUBUNIT]; // AY's PSG function
bool isAYLatchedAddressValid[NUM_AY8913_PER_SUBUNIT];
bool isChipSelected[NUM_AY8913_PER_SUBUNIT];
bool isDrivingBus;
bool isBusDriven;
MB_SUBUNIT(UINT slot, SS_CARDTYPE type) : sy6522(slot, type == CT_MegaAudio), ssi263(slot)
{
@ -103,7 +103,13 @@ private:
isAYLatchedAddressValid[0] = isAYLatchedAddressValid[1] = false; // after AY reset
isChipSelected[0] = type == CT_Phasor ? false : true; // Only Phasor is false, all other MB variants are true
isChipSelected[1] = false;
isDrivingBus = false;
SetBusState(false);
}
void SetBusState(bool state)
{
isBusDriven = state;
sy6522.SetBusBeingDriven(state);
}
};