From 82312d3b5984907ab2286852e7de8735712d1735 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 8 Feb 2021 18:14:08 -0500 Subject: [PATCH] Provide a more convincing version of port output. --- InstructionSets/M50740/Executor.cpp | 16 ++++++++++++---- InstructionSets/M50740/Executor.hpp | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/InstructionSets/M50740/Executor.cpp b/InstructionSets/M50740/Executor.cpp index 5a330cf89..f46becfea 100644 --- a/InstructionSets/M50740/Executor.cpp +++ b/InstructionSets/M50740/Executor.cpp @@ -101,6 +101,11 @@ uint8_t Executor::read(uint16_t address) { } } +void Executor::set_port_output(int port) { + // Force 'output' to a 1 anywhere that a bit is set as input. + port_handler_.set_port_output(port, port_outputs_[port] | ~port_directions_[port]); +} + void Executor::write(uint16_t address, uint8_t value) { // printf("%04x <- %02x\n", address, value); @@ -127,13 +132,16 @@ void Executor::write(uint16_t address, uint8_t value) { case 0xe4: case 0xe8: { const int port = port_remap[(address - 0xe0) >> 1]; port_outputs_[port] = value; - return port_handler_.set_port_output(port, value); + set_port_output(port); } + break; case 0xe1: case 0xe3: - case 0xe5: case 0xe9: - port_directions_[port_remap[(address - 0xe0) >> 1]] = value; - break; + case 0xe5: case 0xe9: { + const int port = port_remap[(address - 0xe0) >> 1]; + port_directions_[port] = value; + set_port_output(port); + } break; // Timers. case 0xf9: prescalers_[0].reload_value = value; break; diff --git a/InstructionSets/M50740/Executor.hpp b/InstructionSets/M50740/Executor.hpp index e34b94885..86dc5a6cf 100644 --- a/InstructionSets/M50740/Executor.hpp +++ b/InstructionSets/M50740/Executor.hpp @@ -159,6 +159,7 @@ class Executor: public CachingExecutor { inline void set_flags(uint8_t); inline uint8_t flags(); template inline void perform_interrupt(); + inline void set_port_output(int port); // MARK: - Execution time