1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 20:29:42 +00:00

Implements direction registers.

This commit is contained in:
Thomas Harte 2021-01-28 21:06:11 -05:00
parent f50e8b5106
commit 5eddc92846
2 changed files with 16 additions and 5 deletions

View File

@ -73,8 +73,13 @@ uint8_t Executor::read(uint16_t address) {
// Ports P0P3.
case 0xe0: case 0xe2:
case 0xe4: case 0xe8:
return port_handler_.get_port_input(port_remap[(address - 0xe0) >> 1]);
case 0xe4: case 0xe8: {
const int port = port_remap[(address - 0xe0) >> 1];
const uint8_t input = port_handler_.get_port_input(port);
// In the direction registers, a 0 indicates input, a 1 indicates output.
return (input &~ port_directions_[port]) | (port_outputs_[port] & port_directions_[port]);
}
case 0xe1: case 0xe3:
case 0xe5: case 0xe9:
@ -109,12 +114,15 @@ void Executor::write(uint16_t address, uint8_t value) {
// Ports P0P3.
case 0xe0: case 0xe2:
case 0xe4: case 0xe8:
return port_handler_.set_port_output(port_remap[(address - 0xe0) >> 1], 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);
}
case 0xe1: case 0xe3:
case 0xe5: case 0xe9:
// printf("TODO: Ports P0P3 direction [w %04x %02x]\n", address, value);
port_directions_[port_remap[(address - 0xe0) >> 1]] = value;
break;
// Timers.

View File

@ -136,6 +136,9 @@ class Executor: public CachingExecutor {
bool index_mode_ = false;
bool decimal_mode_ = false;
uint8_t port_directions_[4] = {0xff, 0xff, 0xff, 0xff};
uint8_t port_outputs_[4] = {0xff, 0xff, 0xff, 0xff};
inline uint8_t read(uint16_t address);
inline void write(uint16_t address, uint8_t value);
inline void push(uint8_t value);