From a030d9935e9a3e66635db9d25cf5bce5db742dce Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 18 Jul 2021 20:25:04 -0400 Subject: [PATCH] Adds port input. --- Components/6526/6526.hpp | 8 +++++++- Components/6526/Implementation/6526Implementation.hpp | 8 ++++++++ Components/6526/Implementation/6526Storage.hpp | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Components/6526/6526.hpp b/Components/6526/6526.hpp index c4408a16c..c4edc7e4e 100644 --- a/Components/6526/6526.hpp +++ b/Components/6526/6526.hpp @@ -22,7 +22,12 @@ enum Port { }; struct PortHandler { - /// Sets the current output value of @c port and provides @c direction_mask, indicating which pins are marked as output. + /// Requests the current input value of @c port from the port handler. + uint8_t get_port_input([[maybe_unused]] Port port) { + return 0xff; + } + + /// Sets the current output value of @c port; any bits marked as input will be supplied as 1s. void set_port_output([[maybe_unused]] Port port, [[maybe_unused]] uint8_t value) {} }; @@ -53,6 +58,7 @@ template class MOS6526: PortHandlerT &port_handler_; template void set_port_output(); + template uint8_t get_port_input(); }; } diff --git a/Components/6526/Implementation/6526Implementation.hpp b/Components/6526/Implementation/6526Implementation.hpp index 83d6ff744..008b9c1ac 100644 --- a/Components/6526/Implementation/6526Implementation.hpp +++ b/Components/6526/Implementation/6526Implementation.hpp @@ -21,6 +21,12 @@ template void MOS6526::set_port_output() { port_handler_.set_port_output(Port(port), output); } +template +template uint8_t MOS6526::get_port_input() { + const uint8_t input = port_handler_.get_port_input(Port(port)); + return (input & ~registers_.data_direction[port]) | (registers_.output[port] & registers_.data_direction[port]); +} + template void MOS6526::write(int address, uint8_t value) { address &= 0xf; @@ -56,6 +62,8 @@ template uint8_t MOS6526::read(int address) { address &= 0xf; switch(address) { + case 0: return get_port_input<0>(); + case 1: return get_port_input<1>(); case 2: case 3: return registers_.data_direction[address - 2]; diff --git a/Components/6526/Implementation/6526Storage.hpp b/Components/6526/Implementation/6526Storage.hpp index 4442abb2e..fb8cebcb8 100644 --- a/Components/6526/Implementation/6526Storage.hpp +++ b/Components/6526/Implementation/6526Storage.hpp @@ -16,7 +16,6 @@ struct MOS6526Storage { struct Registers { uint8_t output[2] = {0, 0}; - uint8_t input[2] = {0, 0}; uint8_t data_direction[2] = {0, 0}; } registers_;