1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Got a bit more explicit about how ports are identified on the 6522.

This commit is contained in:
Thomas Harte 2016-06-26 12:30:01 -04:00
parent 8d9eb30d82
commit d5e50f5ea0
3 changed files with 16 additions and 11 deletions

View File

@ -38,6 +38,11 @@ template <class T> class MOS6522 {
};
public:
enum Port {
A = 0,
B = 1
};
/*! Sets a register value. */
inline void set_register(int address, uint8_t value)
{
@ -47,12 +52,12 @@ template <class T> class MOS6522 {
{
case 0x0:
_registers.output[1] = value;
static_cast<T *>(this)->set_port_output(1, value, _registers.data_direction[1]); // TODO: handshake
static_cast<T *>(this)->set_port_output(Port::B, value, _registers.data_direction[1]); // TODO: handshake
break;
case 0xf:
case 0x1:
_registers.output[0] = value;
static_cast<T *>(this)->set_port_output(0, value, _registers.data_direction[0]); // TODO: handshake
static_cast<T *>(this)->set_port_output(Port::A, value, _registers.data_direction[0]); // TODO: handshake
break;
// // No handshake, so write directly
// _registers.output[0] = value;
@ -117,9 +122,9 @@ template <class T> class MOS6522 {
// printf("6522 %p: %d\n", this, address);
switch(address)
{
case 0x0: return get_port_input(1, _registers.data_direction[1], _registers.output[1]);
case 0x0: return get_port_input(Port::B, _registers.data_direction[1], _registers.output[1]);
case 0xf: // TODO: handshake, latching
case 0x1: return get_port_input(0, _registers.data_direction[0], _registers.output[0]);
case 0x1: return get_port_input(Port::A, _registers.data_direction[0], _registers.output[0]);
case 0x2: return _registers.data_direction[1];
case 0x3: return _registers.data_direction[0];
@ -152,7 +157,7 @@ template <class T> class MOS6522 {
return 0xff;
}
inline void set_control_line_input(int port, int line, bool value)
inline void set_control_line_input(Port port, int line, bool value)
{
}
@ -226,12 +231,12 @@ template <class T> class MOS6522 {
private:
// Expected to be overridden
uint8_t get_port_input(int port) { return 0xff; }
void set_port_output(int port, uint8_t value, uint8_t direction_mask) {}
uint8_t get_port_input(Port port) { return 0xff; }
void set_port_output(Port port, uint8_t value, uint8_t direction_mask) {}
// void set_interrupt_status(bool status) {}
// Input/output multiplexer
uint8_t get_port_input(int port, uint8_t output_mask, uint8_t output)
uint8_t get_port_input(Port port, uint8_t output_mask, uint8_t output)
{
uint8_t input = static_cast<T *>(this)->get_port_input(port);
return (input & ~output_mask) | (output & output_mask);

View File

@ -66,7 +66,7 @@ class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDeleg
}
// to satisfy MOS::MOS6522
uint8_t get_port_input(int port) {
uint8_t get_port_input(Port port) {
if(!port) {
uint8_t result = 0xff;
for(int c = 0; c < 8; c++)
@ -80,7 +80,7 @@ class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDeleg
return 0xff;
}
void set_port_output(int port, uint8_t value, uint8_t mask) {
void set_port_output(Port port, uint8_t value, uint8_t mask) {
if(port)
_activation_mask = (value & mask) | (~mask);
}

View File

@ -23,7 +23,7 @@ class VanillaVIA: public MOS::MOS6522<VanillaVIA> {
irq_line = new_status;
}
uint8_t get_port_input(int port)
uint8_t get_port_input(Port port)
{
return port ? port_b_value : port_a_value;
}