diff --git a/Core/NES/APU/DeltaModulationChannel.cpp b/Core/NES/APU/DeltaModulationChannel.cpp index 27cf6f6..3337726 100644 --- a/Core/NES/APU/DeltaModulationChannel.cpp +++ b/Core/NES/APU/DeltaModulationChannel.cpp @@ -195,7 +195,15 @@ void DeltaModulationChannel::WriteRam(uint16_t addr, uint8_t value) //"The rate determines for how many CPU cycles happen between changes in the output level during automatic delta-encoded sample playback." //Because BaseApuChannel does not decrement when setting _timer, we need to actually set the value to 1 less than the lookup table - _timer.SetPeriod((NesApu::GetApuRegion(_console) == ConsoleRegion::Ntsc ? _dmcPeriodLookupTableNtsc : _dmcPeriodLookupTablePal)[value & 0x0F] - 1); + { + //famicom-python patch: a rate written in the cycle the timer reloads is the one + //it reloads with (AccuracyCoin "DMC Reload Timing", its hardware answer key) + bool justReloaded = _timer.GetTimer() == _timer.GetPeriod(); + _timer.SetPeriod((NesApu::GetApuRegion(_console) == ConsoleRegion::Ntsc ? _dmcPeriodLookupTableNtsc : _dmcPeriodLookupTablePal)[value & 0x0F] - 1); + if(justReloaded) { + _timer.SetTimer(_timer.GetPeriod()); + } + } if(!_irqEnabled) { _console->GetCpu()->ClearIrqSource(IRQSource::DMC); diff --git a/Core/NES/Mappers/Bandai/BandaiFcg.h b/Core/NES/Mappers/Bandai/BandaiFcg.h index 0b01acd..a96ce25 100644 --- a/Core/NES/Mappers/Bandai/BandaiFcg.h +++ b/Core/NES/Mappers/Bandai/BandaiFcg.h @@ -87,6 +87,10 @@ protected: RemoveRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write); } + //famicom-python patch: the ROM is always selected at $8000; its bank latch powers on + //unspecified, bank 0 here as on the board (Mesen2 left $8000-$BFFF unmapped: open bus) + SelectPrgPage(0, 0); + //Last bank SelectPrgPage(1, 0x0F); } @@ -153,7 +157,9 @@ protected: output |= (_standardEeprom->Read() << 4); } - return output | _console->GetMemoryManager()->GetOpenBus(0xE7); + //famicom-python patch: D3 is the Datach barcode reader's; without one it is open bus + //(INES_Mapper_016.wiki: "xxxE xxxx", all but D4 open bus) + return output | _console->GetMemoryManager()->GetOpenBus(_barcodeReader ? 0xE7 : 0xEF); } void WriteRegister(uint16_t addr, uint8_t value) override diff --git a/Core/NES/Mappers/Mmc3Variants/MMC3_Coolboy.h b/Core/NES/Mappers/Mmc3Variants/MMC3_Coolboy.h index 9afc993..02358e6 100644 --- a/Core/NES/Mappers/Mmc3Variants/MMC3_Coolboy.h +++ b/Core/NES/Mappers/Mmc3Variants/MMC3_Coolboy.h @@ -9,7 +9,9 @@ private: uint8_t _exRegs[4] = {}; protected: - uint16_t RegisterStartAddress() override { return 0x6000; } + //famicom-python patch: odd submappers (MINDKIDS) decode the outer registers at $5000 + //(NES_2.0_Mapper_268.wiki), even ones at $6000 + uint16_t RegisterStartAddress() override { return (_romInfo.SubMapperID & 1) ? 0x5000 : 0x6000; } uint32_t GetChrRamSize() override { return 0x40000; } void Reset(bool softReset) override @@ -91,11 +93,12 @@ protected: void WriteRegister(uint16_t addr, uint8_t value) override { if(addr < 0x8000) { - if(GetState().RegA001 & 0x80) { + if(addr >= 0x6000 && (GetState().RegA001 & 0x80)) { WritePrgRam(addr, value); } - if((_exRegs[3] & 0x90) != 0x80) { + bool outerPort = !(_romInfo.SubMapperID & 1) || addr < 0x6000; + if(outerPort && (_exRegs[3] & 0x90) != 0x80) { _exRegs[addr & 0x03] = value; UpdateState(); } diff --git a/Core/NES/NesCpu.h b/Core/NES/NesCpu.h index 6c0da75..061b455 100644 --- a/Core/NES/NesCpu.h +++ b/Core/NES/NesCpu.h @@ -437,10 +437,15 @@ private: if(_runIrq && !_prevRunIrq) { _runIrq = false; } + //famicom-python patch: the same for an NMI edge seen in the operand cycle + //(perfect6502: a taken same-page branch delays NMI as it does IRQ) + bool holdNmi = _needNmi && !_prevNeedNmi; DummyRead(); if(CheckPageCrossed(PC(), offset)) { DummyRead(); + } else if(holdNmi) { + _prevNeedNmi = false; } SetPC(PC() + offset); diff --git a/Core/NES/NesMemoryManager.cpp b/Core/NES/NesMemoryManager.cpp index be51ad7..2086fe9 100644 --- a/Core/NES/NesMemoryManager.cpp +++ b/Core/NES/NesMemoryManager.cpp @@ -130,7 +130,11 @@ uint8_t NesMemoryManager::Read(uint16_t addr, MemoryOperationType operationType) } _emu->ProcessMemoryRead(addr, value, operationType); - _openBusHandler.SetOpenBus(value, addr == 0x4015); + if(operationType == MemoryOperationType::DmaRead) { + _openBusHandler.SetExternalOpenBus(value); + } else { + _openBusHandler.SetOpenBus(value, addr == 0x4015); + } return value; } diff --git a/Core/NES/OpenBusHandler.h b/Core/NES/OpenBusHandler.h index e016897..d3cf38e 100644 --- a/Core/NES/OpenBusHandler.h +++ b/Core/NES/OpenBusHandler.h @@ -31,7 +31,14 @@ public: __forceinline uint8_t GetInternalOpenBus() { - return _externalOpenBus; + //famicom-python patch: the internal bus, not the external one (AccuracyCoin "Internal Data Bus") + return _internalOpenBus; + } + + __forceinline void SetExternalOpenBus(uint8_t value) + { + //famicom-python patch: a DMA read drives the external bus only + _externalOpenBus = value; } __forceinline void SetOpenBus(uint8_t value, bool setInternalOnly)