mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-29 12:50:28 +00:00
Takes a first go at handshake and pulse modes.
This commit is contained in:
parent
254132b83d
commit
4367459cf2
@ -113,6 +113,8 @@ template <class T> class MOS6522: public MOS6522Storage {
|
|||||||
void do_phase2();
|
void do_phase2();
|
||||||
T &bus_handler_;
|
T &bus_handler_;
|
||||||
|
|
||||||
|
void access(int address);
|
||||||
|
|
||||||
uint8_t get_port_input(Port port, uint8_t output_mask, uint8_t output);
|
uint8_t get_port_input(Port port, uint8_t output_mask, uint8_t output);
|
||||||
inline void reevaluate_interrupts();
|
inline void reevaluate_interrupts();
|
||||||
};
|
};
|
||||||
|
@ -11,16 +11,33 @@
|
|||||||
namespace MOS {
|
namespace MOS {
|
||||||
namespace MOS6522 {
|
namespace MOS6522 {
|
||||||
|
|
||||||
template <typename T> void MOS6522<T>::set_register(int address, uint8_t value) {
|
template <typename T> void MOS6522<T>::access(int address) {
|
||||||
address &= 0xf;
|
|
||||||
switch(address) {
|
switch(address) {
|
||||||
case 0x0: // Write Port B.
|
case 0x0:
|
||||||
registers_.output[1] = value;
|
// In both handshake and pulse modes, CB2 goes low on any read or write of Port B.
|
||||||
bus_handler_.set_port_output(Port::B, value, registers_.data_direction[1]);
|
if(handshake_modes_[1] != HandshakeMode::None) {
|
||||||
|
|
||||||
if(handshake_modes_[0] != HandshakeMode::None) {
|
|
||||||
bus_handler_.set_control_line_output(Port::B, Line::Two, false);
|
bus_handler_.set_control_line_output(Port::B, Line::Two, false);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xf:
|
||||||
|
case 0x1:
|
||||||
|
// In both handshake and pulse modes, CA2 goes low on any read or write of Port A.
|
||||||
|
if(handshake_modes_[0] != HandshakeMode::None) {
|
||||||
|
bus_handler_.set_control_line_output(Port::A, Line::Two, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> void MOS6522<T>::set_register(int address, uint8_t value) {
|
||||||
|
address &= 0xf;
|
||||||
|
access(address);
|
||||||
|
switch(address) {
|
||||||
|
case 0x0: // Write Port B.
|
||||||
|
// Store locally and communicate outwards.
|
||||||
|
registers_.output[1] = value;
|
||||||
|
bus_handler_.set_port_output(Port::B, value, registers_.data_direction[1]);
|
||||||
|
|
||||||
registers_.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | ((registers_.peripheral_control&0x20) ? 0 : InterruptFlag::CB2ActiveEdge));
|
registers_.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | ((registers_.peripheral_control&0x20) ? 0 : InterruptFlag::CB2ActiveEdge));
|
||||||
reevaluate_interrupts();
|
reevaluate_interrupts();
|
||||||
@ -73,42 +90,40 @@ template <typename T> void MOS6522<T>::set_register(int address, uint8_t value)
|
|||||||
case 0xb:
|
case 0xb:
|
||||||
registers_.auxiliary_control = value;
|
registers_.auxiliary_control = value;
|
||||||
break;
|
break;
|
||||||
case 0xc:
|
case 0xc: {
|
||||||
registers_.peripheral_control = value;
|
registers_.peripheral_control = value;
|
||||||
|
|
||||||
// TODO: simplify below; trying to avoid improper logging of unimplemented warnings in input mode
|
for(int port = 0; port < 2; ++port) {
|
||||||
handshake_modes_[0] = HandshakeMode::None;
|
handshake_modes_[port] = HandshakeMode::None;
|
||||||
switch(value & 0x0e) {
|
switch(value & 0x0e) {
|
||||||
default: LOG("Unimplemented control line CA2 mode " << int((value >> 1)&7)); break;
|
default: break;
|
||||||
|
|
||||||
case 0x00: // Negative interrupt input; set CA2 interrupt on negative CA2 transition, clear on access to Port A register.
|
case 0x00: // Negative interrupt input; set CA2 interrupt on negative CA2 transition, clear on access to Port A register.
|
||||||
case 0x02: // Independent negative interrupt input; set CA2 interrupt on negative transition, don't clear automatically.
|
case 0x02: // Independent negative interrupt input; set CA2 interrupt on negative transition, don't clear automatically.
|
||||||
case 0x04: // Positive interrupt input; set CA2 interrupt on positive CA2 transition, clear on access to Port A register.
|
case 0x04: // Positive interrupt input; set CA2 interrupt on positive CA2 transition, clear on access to Port A register.
|
||||||
case 0x06: // Independent positive interrupt input; set CA2 interrupt on positive transition, don't clear automatically.
|
case 0x06: // Independent positive interrupt input; set CA2 interrupt on positive transition, don't clear automatically.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x08: // Handshake: set CA2 to low on any read or write of Port A; set to high on an active transition of CA1.
|
case 0x08: // Handshake: set CA2 to low on any read or write of Port A; set to high on an active transition of CA1.
|
||||||
handshake_modes_[0] = HandshakeMode::Handshake;
|
handshake_modes_[port] = HandshakeMode::Handshake;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0a: // Pulse output: CA2 is low for one cycle following a read or write of Port A.
|
case 0x0a: // Pulse output: CA2 is low for one cycle following a read or write of Port A.
|
||||||
handshake_modes_[0] = HandshakeMode::Pulse;
|
handshake_modes_[port] = HandshakeMode::Pulse;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0c: // Manual output: CA2 low.
|
case 0x0c: // Manual output: CA2 low.
|
||||||
bus_handler_.set_control_line_output(Port::A, Line::Two, false);
|
bus_handler_.set_control_line_output(Port(port), Line::Two, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0e: // Manual output: CA2 high.
|
case 0x0e: // Manual output: CA2 high.
|
||||||
bus_handler_.set_control_line_output(Port::A, Line::Two, true);
|
bus_handler_.set_control_line_output(Port(port), Line::Two, true);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
value >>= 4;
|
||||||
}
|
}
|
||||||
switch(value & 0xe0) {
|
} break;
|
||||||
default: LOG("Unimplemented control line CB2 mode " << int((value >> 5)&7)); break;
|
|
||||||
case 0xc0: bus_handler_.set_control_line_output(Port::B, Line::Two, false); break;
|
|
||||||
case 0xe0: bus_handler_.set_control_line_output(Port::B, Line::Two, true); break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Interrupt control
|
// Interrupt control
|
||||||
case 0xd:
|
case 0xd:
|
||||||
@ -127,6 +142,7 @@ template <typename T> void MOS6522<T>::set_register(int address, uint8_t value)
|
|||||||
|
|
||||||
template <typename T> uint8_t MOS6522<T>::get_register(int address) {
|
template <typename T> uint8_t MOS6522<T>::get_register(int address) {
|
||||||
address &= 0xf;
|
address &= 0xf;
|
||||||
|
access(address);
|
||||||
switch(address) {
|
switch(address) {
|
||||||
case 0x0:
|
case 0x0:
|
||||||
registers_.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | InterruptFlag::CB2ActiveEdge);
|
registers_.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | InterruptFlag::CB2ActiveEdge);
|
||||||
@ -193,8 +209,9 @@ template <typename T> void MOS6522<T>::set_control_line_input(Port port, Line li
|
|||||||
if( value != control_inputs_[port].line_one &&
|
if( value != control_inputs_[port].line_one &&
|
||||||
value == !!(registers_.peripheral_control & (port ? 0x10 : 0x01))
|
value == !!(registers_.peripheral_control & (port ? 0x10 : 0x01))
|
||||||
) {
|
) {
|
||||||
|
// In handshake mode, any transition on C[A/B]1 sets output high on C[A/B]2.
|
||||||
if(handshake_modes_[port] == HandshakeMode::Handshake) {
|
if(handshake_modes_[port] == HandshakeMode::Handshake) {
|
||||||
// bus_handler_
|
bus_handler_.set_control_line_output(port, Line::Two, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
registers_.interrupt_flags |= port ? InterruptFlag::CB1ActiveEdge : InterruptFlag::CA1ActiveEdge;
|
registers_.interrupt_flags |= port ? InterruptFlag::CB1ActiveEdge : InterruptFlag::CA1ActiveEdge;
|
||||||
@ -237,6 +254,14 @@ template <typename T> void MOS6522<T>::do_phase2() {
|
|||||||
registers_.timer[1] = static_cast<uint16_t>(registers_.next_timer[1]);
|
registers_.timer[1] = static_cast<uint16_t>(registers_.next_timer[1]);
|
||||||
registers_.next_timer[1] = -1;
|
registers_.next_timer[1] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In pulse modes, CA2 and CB2 go high again on the next clock edge.
|
||||||
|
if(handshake_modes_[1] == HandshakeMode::Pulse) {
|
||||||
|
bus_handler_.set_control_line_output(Port::B, Line::Two, true);
|
||||||
|
}
|
||||||
|
if(handshake_modes_[0] == HandshakeMode::Pulse) {
|
||||||
|
bus_handler_.set_control_line_output(Port::A, Line::Two, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void MOS6522<T>::do_phase1() {
|
template <typename T> void MOS6522<T>::do_phase1() {
|
||||||
|
Loading…
Reference in New Issue
Block a user