From 58666b21b3ecf5b3917e4b1a3ac24528ada13161 Mon Sep 17 00:00:00 2001 From: org Date: Thu, 31 Aug 2023 21:42:10 +0300 Subject: [PATCH 1/8] Check whether the device can be connected to the specified port by DeviceID --- Breaknes/BreaksCore/FamicomBoard.cpp | 12 ++++++++++++ Breaknes/BreaksCore/FamicomBoard.h | 1 + Breaknes/BreaksCore/NESBoard.cpp | 12 ++++++++++++ Breaknes/BreaksCore/NESBoard.h | 1 + IO/IO.cpp | 19 ++++++++++++++++++- IO/IO.h | 1 + 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Breaknes/BreaksCore/FamicomBoard.cpp b/Breaknes/BreaksCore/FamicomBoard.cpp index 8524a6e..5981153 100644 --- a/Breaknes/BreaksCore/FamicomBoard.cpp +++ b/Breaknes/BreaksCore/FamicomBoard.cpp @@ -333,6 +333,18 @@ namespace Breaknes return 2; } + std::string FamicomBoardIO::GetPortName(int port) + { + switch (port) + { + case 0: return "Famicom Controller Port 1"; + case 1: return "Famicom Controller Port 2"; + default: + break; + } + return ""; + } + void FamicomBoardIO::GetPortSupportedDevices(int port, std::list& devices) { devices.clear(); diff --git a/Breaknes/BreaksCore/FamicomBoard.h b/Breaknes/BreaksCore/FamicomBoard.h index 40daeb9..61b0ab9 100644 --- a/Breaknes/BreaksCore/FamicomBoard.h +++ b/Breaknes/BreaksCore/FamicomBoard.h @@ -14,6 +14,7 @@ namespace Breaknes FamicomBoardIO(FamicomBoard *board); virtual ~FamicomBoardIO(); int GetPorts() override; + std::string GetPortName(int port) override; void GetPortSupportedDevices(int port, std::list& devices) override; void sim(int port) override; }; diff --git a/Breaknes/BreaksCore/NESBoard.cpp b/Breaknes/BreaksCore/NESBoard.cpp index 1617c8b..cf8470d 100644 --- a/Breaknes/BreaksCore/NESBoard.cpp +++ b/Breaknes/BreaksCore/NESBoard.cpp @@ -332,6 +332,18 @@ namespace Breaknes return 2; } + std::string NESBoardIO::GetPortName(int port) + { + switch (port) + { + case 0: return "NES Controller Port 1"; + case 1: return "NES Controller Port 2"; + default: + break; + } + return ""; + } + void NESBoardIO::GetPortSupportedDevices(int port, std::list& devices) { devices.clear(); diff --git a/Breaknes/BreaksCore/NESBoard.h b/Breaknes/BreaksCore/NESBoard.h index 4ef8538..d5f3bfc 100644 --- a/Breaknes/BreaksCore/NESBoard.h +++ b/Breaknes/BreaksCore/NESBoard.h @@ -11,6 +11,7 @@ namespace Breaknes NESBoardIO(NESBoard *board); virtual ~NESBoardIO(); int GetPorts() override; + std::string GetPortName(int port) override; void GetPortSupportedDevices(int port, std::list& devices) override; void sim(int port) override; }; diff --git a/IO/IO.cpp b/IO/IO.cpp index f9e1d9f..194c793 100644 --- a/IO/IO.cpp +++ b/IO/IO.cpp @@ -98,7 +98,19 @@ namespace IO IOMapped* mapped = GetMappedDeviceByHandle(handle); if (mapped != nullptr) { - mapped->port = port; + std::list supported_devices; + GetPortSupportedDevices(port, supported_devices); + + // Check whether the device can be connected to the specified port by DeviceID + + for (auto it = supported_devices.begin(); it != supported_devices.end(); ++it) { + + if (*it == (DeviceID)mapped->device->GetID()) { + + mapped->port = port; + break; + } + } } } @@ -175,6 +187,11 @@ namespace IO return 0; } + std::string IOSubsystem::GetPortName(int port) + { + return ""; + } + void IOSubsystem::GetPortSupportedDevices(int port, std::list& devices) { devices.clear(); diff --git a/IO/IO.h b/IO/IO.h index e7d88d9..f623b0d 100644 --- a/IO/IO.h +++ b/IO/IO.h @@ -69,6 +69,7 @@ namespace IO #pragma region "Interface for Motherboard implementation" virtual int GetPorts(); + virtual std::string GetPortName(int port); virtual void GetPortSupportedDevices(int port, std::list& devices); virtual void sim(int port); From a933a9e2d9a87f5568a622aa223ddd5ae71f6b9a Mon Sep 17 00:00:00 2001 From: org Date: Thu, 31 Aug 2023 22:11:32 +0300 Subject: [PATCH 2/8] IOConfigPort --- Breaknes/Breaknes/Build/IOConfig.json | 10 ++++++-- Breaknes/Breaknes/FormIOConfig.cs | 33 ++++++++++++++++++++++----- Breaknes/Breaknes/IOConfig.cs | 8 ++++++- Breaknes/Breaknes/IOProcessing.cs | 10 +++++++- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/Breaknes/Breaknes/Build/IOConfig.json b/Breaknes/Breaknes/Build/IOConfig.json index da65dbc..56a9938 100644 --- a/Breaknes/Breaknes/Build/IOConfig.json +++ b/Breaknes/Breaknes/Build/IOConfig.json @@ -7,7 +7,10 @@ "device_id": 1, "name": "P1", "attached": [ - "HVC-CPU-01" + { + "board": "HVC-CPU-01", + "port": 0 + } ], "bindings": [ { @@ -30,7 +33,10 @@ "device_id": 65539, "name": "V1", "attached": [ - "NES-001 (PCB rev. -01 to -04)" + { + "board": "NES-001 (PCB rev. -01 to -04)", + "port": 0 + } ], "bindings": [ { diff --git a/Breaknes/Breaknes/FormIOConfig.cs b/Breaknes/Breaknes/FormIOConfig.cs index 0c952a7..6899044 100644 --- a/Breaknes/Breaknes/FormIOConfig.cs +++ b/Breaknes/Breaknes/FormIOConfig.cs @@ -168,8 +168,18 @@ private void PopulateConnectionStatus(IOConfigDevice device) { for (int i = 0; i < checkedListBox1.Items.Count; i++) { - int pos = Array.IndexOf(device.attached, checkedListBox1.Items[i].ToString()); - checkedListBox1.SetItemCheckState(i, pos >= 0 ? CheckState.Checked : CheckState.Unchecked); + bool attached = false; + + foreach (var port in device.attached) + { + if (port.board == checkedListBox1.Items[i].ToString()) + { + attached = true; + break; + } + } + + checkedListBox1.SetItemCheckState(i, attached ? CheckState.Checked : CheckState.Unchecked); } checkedListBox1.Tag = device; } @@ -181,20 +191,31 @@ private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) if (device == null) return; - List board_list = device.attached.ToList(); + List attached = device.attached.ToList(); string board_name = checkedListBox1.Items[e.Index].ToString(); if (e.CurrentValue == CheckState.Checked) { - board_list.Remove(board_name); + List new_board_list = new(); + + foreach (var port in attached) + { + if (port.board != board_name) + new_board_list.Add(port); + } + + attached = new_board_list; } else { - board_list.Add(board_name); + IOConfigPort port = new(); + port.board = board_name; + port.port = 0; // TODO + attached.Add(port); } - device.attached = board_list.ToArray(); + device.attached = attached.ToArray(); } private void FormIOConfig_KeyDown(object sender, KeyEventArgs e) diff --git a/Breaknes/Breaknes/IOConfig.cs b/Breaknes/Breaknes/IOConfig.cs index 9e09b20..5231ece 100644 --- a/Breaknes/Breaknes/IOConfig.cs +++ b/Breaknes/Breaknes/IOConfig.cs @@ -14,11 +14,17 @@ public class IOConfigInfo public string descr = "This JSON contains a list of IO devices and their Attach/Detach statuses with Motherboard and Bindings with Input API."; } + public class IOConfigPort + { + public string board = ""; + public int port = -1; + } + public class IOConfigDevice { public UInt32 device_id = 0; public string name = ""; - public string[] attached = Array.Empty(); + public IOConfigPort[] attached = Array.Empty(); public IOConfigBinding[] bindings = Array.Empty(); } diff --git a/Breaknes/Breaknes/IOProcessing.cs b/Breaknes/Breaknes/IOProcessing.cs index 9a3cb7f..d6c648e 100644 --- a/Breaknes/Breaknes/IOProcessing.cs +++ b/Breaknes/Breaknes/IOProcessing.cs @@ -14,6 +14,7 @@ namespace Breaknes public class AttachedDevice { public int handle = -1; + public int port = -1; public IOConfigDevice device = new(); public object? opaque = null; } @@ -133,11 +134,17 @@ public void AttachDevicesToBoard(string board_name) foreach (var device in config.devices) { - if (device.attached.Contains(board_name)) + foreach (var port in device.attached) { + if (port.board != board_name) + continue; + int port_num = port.port; + AttachedDevice attached_device = new(); attached_device.device = device; + attached_device.port = port_num; attached_device.handle = BreaksCore.IOCreateInstance(device.device_id); + BreaksCore.IOAttach(port_num, attached_device.handle); // If a virtual device is connected, a modeless dialog must be created @@ -199,6 +206,7 @@ public void DetachDevicesFromBoard() } } + BreaksCore.IODetach(device.port, device.handle); BreaksCore.IODisposeInstance(device.handle); } } From cc1ade3607b63406d9d25cbfa16a26a4cbd94781 Mon Sep 17 00:00:00 2001 From: org Date: Fri, 1 Sep 2023 10:13:05 +0300 Subject: [PATCH 3/8] CD4021UnitTest --- UnitTest/CD4021UnitTest.cpp | 54 +++++++++++++++++++++++++++++++ UnitTest/CD4021UnitTest.h | 15 +++++++++ UnitTest/UnitTest.cpp | 15 +++++++++ UnitTest/UnitTest.sln | 10 ++++++ UnitTest/UnitTest.vcxproj | 5 +++ UnitTest/UnitTest.vcxproj.filters | 6 ++++ UnitTest/pch.h | 3 ++ 7 files changed, 108 insertions(+) create mode 100644 UnitTest/CD4021UnitTest.cpp create mode 100644 UnitTest/CD4021UnitTest.h diff --git a/UnitTest/CD4021UnitTest.cpp b/UnitTest/CD4021UnitTest.cpp new file mode 100644 index 0000000..debf83e --- /dev/null +++ b/UnitTest/CD4021UnitTest.cpp @@ -0,0 +1,54 @@ +#include "pch.h" + +using namespace BaseLogic; +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace UnitTest +{ + CD4021_Test::CD4021_Test() + { + } + + CD4021_Test::~CD4021_Test() + { + } + + bool CD4021_Test::TestSequence(uint8_t test_vector) + { + TriState Q5, Q6, Q7; + TriState clk = TriState::Zero; + TriState par_ser{}; + uint8_t q = 0; + char text[0x100]{}; + + sprintf_s(text, sizeof(text), "Testing CD4021 with vector: 0x%02x\n", test_vector); + Logger::WriteMessage(text); + + // Latch test vector + par_ser = TriState::One; + shift_reg.sim(clk, par_ser, TriState::Zero, test_vector, Q5, Q6, Q7); + + // Test serial output + par_ser = TriState::Zero; + + for (int i = 0; i < 8; i++) { + + clk = TriState::Zero; + shift_reg.sim(clk, par_ser, TriState::Zero, 0, Q5, Q6, Q7); + + sprintf_s(text, sizeof(text), "Q7=%d on clk %d\n", ToByte(Q7), i); + Logger::WriteMessage(text); + + q |= ToByte(Q7) << (7 - i); + + // posedge -> Shift reg + clk = TriState::One; + shift_reg.sim(clk, par_ser, TriState::Zero, 0, Q5, Q6, Q7); + } + + sprintf_s(text, sizeof(text), "Pushed out vector: 0x%02x\n", q); + Logger::WriteMessage(text); + + return test_vector == q; + } +} diff --git a/UnitTest/CD4021UnitTest.h b/UnitTest/CD4021UnitTest.h new file mode 100644 index 0000000..2385056 --- /dev/null +++ b/UnitTest/CD4021UnitTest.h @@ -0,0 +1,15 @@ +#pragma once + +namespace UnitTest +{ + class CD4021_Test + { + IO::CD4021 shift_reg{}; + + public: + CD4021_Test(); + ~CD4021_Test(); + + bool TestSequence(uint8_t test_vector); + }; +} diff --git a/UnitTest/UnitTest.cpp b/UnitTest/UnitTest.cpp index 2910da5..3710e0a 100644 --- a/UnitTest/UnitTest.cpp +++ b/UnitTest/UnitTest.cpp @@ -303,4 +303,19 @@ namespace UnitTest Assert::IsTrue(ut.MegaCyclesTest(21'477272)); } }; + + TEST_CLASS(SmallChipsUnitTest) + { + public: + TEST_METHOD(TestCD4021) + { + UnitTest::CD4021_Test test{}; + Assert::IsTrue(test.TestSequence(0x00)); + Assert::IsTrue(test.TestSequence(0xff)); + Assert::IsTrue(test.TestSequence(0xa5)); + Assert::IsTrue(test.TestSequence(0x5a)); + Assert::IsTrue(test.TestSequence(0xaa)); + Assert::IsTrue(test.TestSequence(0x55)); + } + }; } diff --git a/UnitTest/UnitTest.sln b/UnitTest/UnitTest.sln index a879821..f26d353 100644 --- a/UnitTest/UnitTest.sln +++ b/UnitTest/UnitTest.sln @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BaseLogicLib", "..\Common\B EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JsonLib", "..\Common\JsonLib\Scripts\VS2022\JsonLib.vcxproj", "{8782459B-4E38-4227-AA98-6E7E8E06659C}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IO", "..\IO\Scripts\VS2022\IO.vcxproj", "{AC032844-AE3A-4224-B6CE-451C5DBE80B9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -71,6 +73,14 @@ Global {8782459B-4E38-4227-AA98-6E7E8E06659C}.Release|x64.Build.0 = Release|x64 {8782459B-4E38-4227-AA98-6E7E8E06659C}.Release|x86.ActiveCfg = Release|Win32 {8782459B-4E38-4227-AA98-6E7E8E06659C}.Release|x86.Build.0 = Release|Win32 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Debug|x64.ActiveCfg = Debug|x64 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Debug|x64.Build.0 = Debug|x64 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Debug|x86.ActiveCfg = Debug|Win32 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Debug|x86.Build.0 = Debug|Win32 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Release|x64.ActiveCfg = Release|x64 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Release|x64.Build.0 = Release|x64 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Release|x86.ActiveCfg = Release|Win32 + {AC032844-AE3A-4224-B6CE-451C5DBE80B9}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UnitTest/UnitTest.vcxproj b/UnitTest/UnitTest.vcxproj index a6e374a..e53f3cb 100644 --- a/UnitTest/UnitTest.vcxproj +++ b/UnitTest/UnitTest.vcxproj @@ -161,6 +161,7 @@ + @@ -174,6 +175,7 @@ + @@ -195,6 +197,9 @@ {8782459b-4e38-4227-aa98-6e7e8e06659c} + + {ac032844-ae3a-4224-b6ce-451c5dbe80b9} + diff --git a/UnitTest/UnitTest.vcxproj.filters b/UnitTest/UnitTest.vcxproj.filters index af5f2cc..daba4ca 100644 --- a/UnitTest/UnitTest.vcxproj.filters +++ b/UnitTest/UnitTest.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + @@ -50,6 +53,9 @@ Header Files + + Header Files + diff --git a/UnitTest/pch.h b/UnitTest/pch.h index a6396ea..979a2c0 100644 --- a/UnitTest/pch.h +++ b/UnitTest/pch.h @@ -13,11 +13,14 @@ #include "../BreaksAPU/APUSim/apu.h" #include "../BreaksPPU/PPUSim/ppu.h" +#include "../IO/CD4021.h" + #include "../Common/JsonLib/Json.h" #include "EventLog.h" #include "CoreUnitTest.h" #include "APUTest.h" #include "PPUTest.h" +#include "CD4021UnitTest.h" #include "CppUnitTest.h" From dc075699708811c9d93f47a5b53ba666d9929637 Mon Sep 17 00:00:00 2001 From: org Date: Fri, 1 Sep 2023 10:14:23 +0300 Subject: [PATCH 4/8] Update CD4021UnitTest.cpp --- UnitTest/CD4021UnitTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitTest/CD4021UnitTest.cpp b/UnitTest/CD4021UnitTest.cpp index debf83e..15a98d7 100644 --- a/UnitTest/CD4021UnitTest.cpp +++ b/UnitTest/CD4021UnitTest.cpp @@ -34,7 +34,7 @@ namespace UnitTest for (int i = 0; i < 8; i++) { clk = TriState::Zero; - shift_reg.sim(clk, par_ser, TriState::Zero, 0, Q5, Q6, Q7); + shift_reg.sim(clk, par_ser, TriState::Zero, test_vector, Q5, Q6, Q7); sprintf_s(text, sizeof(text), "Q7=%d on clk %d\n", ToByte(Q7), i); Logger::WriteMessage(text); @@ -43,7 +43,7 @@ namespace UnitTest // posedge -> Shift reg clk = TriState::One; - shift_reg.sim(clk, par_ser, TriState::Zero, 0, Q5, Q6, Q7); + shift_reg.sim(clk, par_ser, TriState::Zero, test_vector, Q5, Q6, Q7); } sprintf_s(text, sizeof(text), "Pushed out vector: 0x%02x\n", q); From bef4220bec9d1ebb39da48fcccf4b2a73a8dd8c6 Mon Sep 17 00:00:00 2001 From: org Date: Fri, 1 Sep 2023 10:33:29 +0300 Subject: [PATCH 5/8] removed Quick check --- Breaknes/BreaksCore/FamicomBoard.cpp | 5 ----- Breaknes/BreaksCore/NESBoard.cpp | 5 ----- IO/CD4021.h | 2 ++ IO/NESController.cpp | 24 ++++++++++++++++++++++++ IO/NESController.h | 7 +++++++ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Breaknes/BreaksCore/FamicomBoard.cpp b/Breaknes/BreaksCore/FamicomBoard.cpp index 5981153..97a9868 100644 --- a/Breaknes/BreaksCore/FamicomBoard.cpp +++ b/Breaknes/BreaksCore/FamicomBoard.cpp @@ -233,11 +233,6 @@ namespace Breaknes void FamicomBoard::IOBinding() { - // Quick check - bool any_io_port_active = nRDP0 == TriState::Zero || nRDP1 == TriState::Zero || OUT_0 == TriState::One; - if (!any_io_port_active) - return; - // First you need to simulate 368s in the direction CPU->Ports p4_inputs[(size_t)BaseBoard::LS368_Input::n_G1] = nRDP0; diff --git a/Breaknes/BreaksCore/NESBoard.cpp b/Breaknes/BreaksCore/NESBoard.cpp index cf8470d..d0986b0 100644 --- a/Breaknes/BreaksCore/NESBoard.cpp +++ b/Breaknes/BreaksCore/NESBoard.cpp @@ -242,11 +242,6 @@ namespace Breaknes void NESBoard::IOBinding() { - // Quick check - bool any_io_port_active = nRDP0 == TriState::Zero || nRDP1 == TriState::Zero || OUT_0 == TriState::One; - if (!any_io_port_active) - return; - // There is no need to simulate 368s on input, they only work in the Port->CPU direction // Call the IO subsystem and it will simulate the controllers and other I/O devices if they are connected diff --git a/IO/CD4021.h b/IO/CD4021.h index efde878..b210f80 100644 --- a/IO/CD4021.h +++ b/IO/CD4021.h @@ -14,5 +14,7 @@ namespace IO BaseLogic::TriState PAR_SER, BaseLogic::TriState SER_IN, uint8_t PAR_IN, BaseLogic::TriState &Q5, BaseLogic::TriState& Q6, BaseLogic::TriState& Q7 ); + + uint8_t get() { return dff; } }; } diff --git a/IO/NESController.cpp b/IO/NESController.cpp index 7fe3bf3..20fd3f8 100644 --- a/IO/NESController.cpp +++ b/IO/NESController.cpp @@ -79,6 +79,11 @@ namespace IO TriState Q6; TriState Q7; + if (trace_enable && latch == TriState::One) { + start_trace = true; + posedge_counter = 0; + } + uint8_t buttons_state = 0; buttons_state |= (states[(size_t)NESControllerState::Right].value & 1) << 0; buttons_state |= (states[(size_t)NESControllerState::Left].value & 1) << 1; @@ -95,5 +100,24 @@ namespace IO outputs[0] = Q7; // pin4 (D0) outputs[1] = TriState::Z; // pin5 (D4) outputs[2] = TriState::Z; // pin6 (D3) + + if (start_trace) { + Trace(inputs, outputs); + } + + if (trace_enable) { + if (IsPosedge(prev_clk, clk)) { + posedge_counter++; + if (posedge_counter >= 8) { + start_trace = false; + } + } + prev_clk = clk; + } + } + + void NESController::Trace(BaseLogic::TriState inputs[], BaseLogic::TriState outputs[]) + { + printf("seq: %d, sr: 0x%02X, Q7: %d\n", (int)posedge_counter, sr.get(), ToByte(outputs[0])); } } diff --git a/IO/NESController.h b/IO/NESController.h index 7f4f0ac..714fa65 100644 --- a/IO/NESController.h +++ b/IO/NESController.h @@ -20,6 +20,13 @@ namespace IO { CD4021 sr{}; + bool trace_enable = false; + bool start_trace = false; + size_t posedge_counter = 0; + BaseLogic::TriState prev_clk = BaseLogic::TriState::X; + + void Trace(BaseLogic::TriState inputs[], BaseLogic::TriState outputs[]); + public: NESController(); virtual ~NESController(); From 85b172f507aedc53f76ee394bc17f46a8b9a15e8 Mon Sep 17 00:00:00 2001 From: org Date: Fri, 1 Sep 2023 10:44:05 +0300 Subject: [PATCH 6/8] OUT_2 --- Breaknes/BreaksCore/FamicomBoard.cpp | 12 +++++++----- Breaknes/BreaksCore/NESBoard.cpp | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Breaknes/BreaksCore/FamicomBoard.cpp b/Breaknes/BreaksCore/FamicomBoard.cpp index 97a9868..713d79d 100644 --- a/Breaknes/BreaksCore/FamicomBoard.cpp +++ b/Breaknes/BreaksCore/FamicomBoard.cpp @@ -71,7 +71,13 @@ namespace Breaknes nRDP1 = outputs[(size_t)APUSim::APU_Output::n_IN1]; OUT_0 = outputs[(size_t)APUSim::APU_Output::OUT_0]; OUT_1 = outputs[(size_t)APUSim::APU_Output::OUT_1]; - OUT_2 = outputs[(size_t)APUSim::APU_Output::OUT_0]; + OUT_2 = outputs[(size_t)APUSim::APU_Output::OUT_2]; + + // IO + + if (io_enabled) { + IOBinding(); + } // pullup (PPU_A[13]); -- wtf? // no pullup on R/W -- wtf? @@ -183,10 +189,6 @@ namespace Breaknes WRAM_Addr = addr_bus & (wram_size - 1); wram->sim(WRAM_nCE, CPU_RnW, TriState::Zero, &WRAM_Addr, &data_bus, data_bus_dirty); - // IO - - IOBinding(); - // Tick CLK = NOT(CLK); diff --git a/Breaknes/BreaksCore/NESBoard.cpp b/Breaknes/BreaksCore/NESBoard.cpp index d0986b0..8f42c1a 100644 --- a/Breaknes/BreaksCore/NESBoard.cpp +++ b/Breaknes/BreaksCore/NESBoard.cpp @@ -70,12 +70,18 @@ namespace Breaknes nRDP1 = outputs[(size_t)APUSim::APU_Output::n_IN1]; OUT_0 = outputs[(size_t)APUSim::APU_Output::OUT_0]; OUT_1 = outputs[(size_t)APUSim::APU_Output::OUT_1]; - OUT_2 = outputs[(size_t)APUSim::APU_Output::OUT_0]; + OUT_2 = outputs[(size_t)APUSim::APU_Output::OUT_2]; Pullup(nRDP0); Pullup(nRDP1); Pullup(OUT_0); + // IO + + if (io_enabled) { + IOBinding(); + } + // pullup (PPU_A[13]); -- wtf? // no pullup on R/W -- wtf? Pullup(CPU_RnW); @@ -187,10 +193,6 @@ namespace Breaknes WRAM_Addr = addr_bus & (wram_size - 1); wram->sim(WRAM_nCE, CPU_RnW, TriState::Zero, &WRAM_Addr, &data_bus, data_bus_dirty); - // IO - - IOBinding(); - // Tick CLK = NOT(CLK); From fe6c87e3efd7803028a86013e8fbc10d755d9218 Mon Sep 17 00:00:00 2001 From: org Date: Fri, 1 Sep 2023 12:08:14 +0300 Subject: [PATCH 7/8] fixed IO pads during reset --- Breaknes/BreaksCore/NESBoard.cpp | 2 +- BreaksAPU/APUSim/pads.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Breaknes/BreaksCore/NESBoard.cpp b/Breaknes/BreaksCore/NESBoard.cpp index 8f42c1a..1833ff0 100644 --- a/Breaknes/BreaksCore/NESBoard.cpp +++ b/Breaknes/BreaksCore/NESBoard.cpp @@ -113,7 +113,7 @@ namespace Breaknes TriState ppu_outputs[(size_t)PPUSim::OutputPad::Max]{}; ppu_inputs[(size_t)PPUSim::InputPad::CLK] = CLK; - ppu_inputs[(size_t)PPUSim::InputPad::n_RES] = pendingReset_PPU ? TriState::Zero : TriState::One;; // NES Board specific ⚠️ + ppu_inputs[(size_t)PPUSim::InputPad::n_RES] = pendingReset_PPU ? TriState::Zero : TriState::One; // NES Board specific ⚠️ ppu_inputs[(size_t)PPUSim::InputPad::RnW] = CPU_RnW; ppu_inputs[(size_t)PPUSim::InputPad::RS0] = FromByte((addr_bus >> 0) & 1); ppu_inputs[(size_t)PPUSim::InputPad::RS1] = FromByte((addr_bus >> 1) & 1); diff --git a/BreaksAPU/APUSim/pads.cpp b/BreaksAPU/APUSim/pads.cpp index 168c9e5..52ac0c3 100644 --- a/BreaksAPU/APUSim/pads.cpp +++ b/BreaksAPU/APUSim/pads.cpp @@ -128,11 +128,19 @@ namespace APUSim { from_pad = NOT(in_latch.nget()); } + else + { + from_pad = TriState::Z; + } if (NOT(rd) == TriState::One) { pad_out = NOT(NOR(out_latch.get(), rd)); } + else + { + pad_out = TriState::Z; + } } void BIDIR::sim_Input(TriState pad_in, TriState& from_pad, TriState rd) From 94522e75056ae7ef400adbfcef9f300ef008c605 Mon Sep 17 00:00:00 2001 From: org Date: Fri, 1 Sep 2023 12:26:06 +0300 Subject: [PATCH 8/8] Set safe signal values for the IO subsystem (until Expansion Port is implemented) --- Breaknes/Breaknes/Build/IOConfig.json | 44 +++++++++++++++++++++++++++ Breaknes/BreaksCore/FamicomBoard.cpp | 6 ++++ Breaknes/BreaksCore/NESBoard.cpp | 6 ++++ 3 files changed, 56 insertions(+) diff --git a/Breaknes/Breaknes/Build/IOConfig.json b/Breaknes/Breaknes/Build/IOConfig.json index 56a9938..963be19 100644 --- a/Breaknes/Breaknes/Build/IOConfig.json +++ b/Breaknes/Breaknes/Build/IOConfig.json @@ -72,6 +72,50 @@ "binding": "NES_A" } ] + }, + { + "device_id": 65537, + "name": "Fami1", + "attached": [ + { + "board": "HVC-CPU-01", + "port": 0 + } + ], + "bindings": [ + { + "actuator_id": 0, + "binding": "Fami1_Up" + }, + { + "actuator_id": 1, + "binding": "Fami1_Down" + }, + { + "actuator_id": 2, + "binding": "Fami1_Left" + }, + { + "actuator_id": 3, + "binding": "Fami1_Right" + }, + { + "actuator_id": 4, + "binding": "Fami1_Select" + }, + { + "actuator_id": 5, + "binding": "Fami1_Start" + }, + { + "actuator_id": 6, + "binding": "Fami1_B" + }, + { + "actuator_id": 7, + "binding": "Fami1_A" + } + ] } ] } \ No newline at end of file diff --git a/Breaknes/BreaksCore/FamicomBoard.cpp b/Breaknes/BreaksCore/FamicomBoard.cpp index 713d79d..ffe8b5f 100644 --- a/Breaknes/BreaksCore/FamicomBoard.cpp +++ b/Breaknes/BreaksCore/FamicomBoard.cpp @@ -22,6 +22,12 @@ namespace Breaknes apu->SetNormalizedOutput(true); io = new FamicomBoardIO(this); + + // Set safe signal values for the IO subsystem (until Expansion Port is implemented) + for (int i = 0; i < 4; i++) { + p2_4017_data[i] = TriState::Z; + } + p2_4016_data = TriState::Z; } FamicomBoard::~FamicomBoard() diff --git a/Breaknes/BreaksCore/NESBoard.cpp b/Breaknes/BreaksCore/NESBoard.cpp index 1833ff0..4293abc 100644 --- a/Breaknes/BreaksCore/NESBoard.cpp +++ b/Breaknes/BreaksCore/NESBoard.cpp @@ -21,6 +21,12 @@ namespace Breaknes io = new NESBoardIO(this); + // Set safe signal values for the IO subsystem (until Expansion Port is implemented) + for (int i = 0; i < 5; i++) { + p4016_data[i] = TriState::Z; + p4017_data[i] = TriState::Z; + } + AddBoardMemDescriptors(); AddDebugInfoProviders(); }