mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-09 00:37:27 +00:00
Adds port input.
This commit is contained in:
parent
c425dec4d5
commit
a030d9935e
@ -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 <typename PortHandlerT, Personality personality> class MOS6526:
|
||||
PortHandlerT &port_handler_;
|
||||
|
||||
template <int port> void set_port_output();
|
||||
template <int port> uint8_t get_port_input();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,12 @@ template <int port> void MOS6526<BusHandlerT, personality>::set_port_output() {
|
||||
port_handler_.set_port_output(Port(port), output);
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
template <int port> uint8_t MOS6526<BusHandlerT, personality>::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 <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::write(int address, uint8_t value) {
|
||||
address &= 0xf;
|
||||
@ -56,6 +62,8 @@ template <typename BusHandlerT, Personality personality>
|
||||
uint8_t MOS6526<BusHandlerT, personality>::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];
|
||||
|
@ -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_;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user