MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / IOWriteInternal

Method IOWriteInternal

source/Mockingboard.cpp:718–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

716}
717
718BYTE MockingboardCard::IOWriteInternal(WORD PC, WORD nAddr, BYTE bWrite, BYTE nValue, ULONG nExecutedCycles)
719{
720 GetCardMgr().GetMockingboardCardMgr().UpdateCycles(nExecutedCycles);
721
722#ifdef _DEBUG
723 if (!IS_APPLE2 && MemCheckINTCXROM())
724 {
725 _ASSERT(0); // Card ROM disabled, so IO_Cxxx() returns the internal ROM
726 return 0;
727 }
728#endif
729
730 // Support 6502/65C02 false-reads of 6522 (GH#52)
731 if ( ((ReadByteFromMemory(PC-2) == 0x91) && GetMainCpu() == CPU_6502) || // sta (zp),y - 6502 only (no-PX variant only) (UTAIIe:4-23)
732 (ReadByteFromMemory(PC-3) == 0x99) || // sta abs16,y - 6502/65C02, but for 65C02 only the no-PX variant that does the false-read (UTAIIe:4-27)
733 (ReadByteFromMemory(PC-3) == 0x9D) ) // sta abs16,x - 6502/65C02, but for 65C02 only the no-PX variant that does the false-read (UTAIIe:4-27)
734 {
735 WORD base;
736 WORD addr16;
737 if (ReadByteFromMemory(PC-2) == 0x91)
738 {
739 BYTE zp = ReadByteFromMemory(PC-1);
740 base = (ReadByteFromMemory(zp) | (ReadByteFromMemory((zp+1)&0xff)<<8));
741 addr16 = base + regs.y;
742 }
743 else
744 {
745 base = ReadWordFromMemory(PC-2);
746 addr16 = base + ((ReadByteFromMemory(PC-3) == 0x99) ? regs.y : regs.x);
747 }
748
749 if (((base ^ addr16) >> 8) == 0) // Only the no-PX variant does the false read (to the same I/O SELECT page)
750 {
751 _ASSERT(addr16 == nAddr);
752 if (addr16 == nAddr) // Check we've reverse looked-up the 6502 opcode correctly
753 {
754 if ( ((nAddr&0xf) == 4) || ((nAddr&0xf) == 8) ) // Only reading 6522 reg-4 or reg-8 actually has an effect
755 IOReadInternal(PC, nAddr, 0, 0, nExecutedCycles);
756 }
757 }
758 }
759
760 if (m_isPhasorCard)
761 {
762 int CS = 0;
763 if (m_phasorMode == PH_Mockingboard)
764 CS = ( ( nAddr & 0x80 ) >> 7 ) + 1; // 1 or 2
765 else if (m_phasorMode == PH_Phasor)
766 CS = ( ( nAddr & 0x80 ) >> 6 ) | ( ( nAddr & 0x10 ) >> 4 ); // 0, 1, 2 or 3
767 else if (m_phasorMode == PH_EchoPlus)
768 CS = 2;
769
770 if (CS & 1)
771 {
772 const BYTE reg = nAddr & 0xf;
773 m_MBSubUnit[SY6522_DEVICE_A].sy6522.Write(reg, nValue);
774 if (reg == SY6522::rORB)
775 WriteToORB(SY6522_DEVICE_A);

Callers 1

IOWriteMethod · 0.80

Calls 6

MemCheckINTCXROMFunction · 0.85
ReadByteFromMemoryFunction · 0.85
ReadWordFromMemoryFunction · 0.85
GetMainCpuFunction · 0.70
UpdateCyclesMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected