mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-18 01:07:58 +00:00
Fixed test and added basic implementation of data direction.
This commit is contained in:
parent
eea850cd12
commit
f4915c5ad6
@ -35,17 +35,17 @@ template <class T> class MOS6522 {
|
|||||||
{
|
{
|
||||||
case 0x0:
|
case 0x0:
|
||||||
_registers.output[1] = value;
|
_registers.output[1] = value;
|
||||||
static_cast<T *>(this)->set_port_output(1, value); // TODO: handshake
|
static_cast<T *>(this)->set_port_output(1, value, _registers.data_direction[1]); // TODO: handshake
|
||||||
break;
|
|
||||||
case 0x1:
|
|
||||||
_registers.output[0] = value;
|
|
||||||
static_cast<T *>(this)->set_port_output(0, value); // TODO: handshake
|
|
||||||
break;
|
break;
|
||||||
case 0xf:
|
case 0xf:
|
||||||
// No handshake, so write directly
|
case 0x1:
|
||||||
_registers.output[0] = value;
|
_registers.output[0] = value;
|
||||||
static_cast<T *>(this)->set_port_output(0, value);
|
static_cast<T *>(this)->set_port_output(0, value, _registers.data_direction[0]); // TODO: handshake
|
||||||
break;
|
break;
|
||||||
|
// // No handshake, so write directly
|
||||||
|
// _registers.output[0] = value;
|
||||||
|
// static_cast<T *>(this)->set_port_output(0, value);
|
||||||
|
// break;
|
||||||
|
|
||||||
case 0x2:
|
case 0x2:
|
||||||
_registers.data_direction[1] = value;
|
_registers.data_direction[1] = value;
|
||||||
@ -104,10 +104,9 @@ template <class T> class MOS6522 {
|
|||||||
// printf("6522 %p: %d\n", this, address);
|
// printf("6522 %p: %d\n", this, address);
|
||||||
switch(address)
|
switch(address)
|
||||||
{
|
{
|
||||||
// case 0x0: return (_registers.auxiliary_control & 0x40) ? _registers.input[1] : static_cast<T *>(this)->get_port_input(1);
|
case 0x0: return get_port_input(1, _registers.data_direction[1], _registers.output[1]);
|
||||||
case 0x0: return _registers.output[1];//static_cast<T *>(this)->get_port_input(1);
|
|
||||||
case 0xf: // TODO: handshake, latching
|
case 0xf: // TODO: handshake, latching
|
||||||
case 0x1: return static_cast<T *>(this)->get_port_input(0);
|
case 0x1: return get_port_input(0, _registers.data_direction[0], _registers.output[0]);
|
||||||
|
|
||||||
case 0x2: return _registers.data_direction[1];
|
case 0x2: return _registers.data_direction[1];
|
||||||
case 0x3: return _registers.data_direction[0];
|
case 0x3: return _registers.data_direction[0];
|
||||||
@ -202,11 +201,18 @@ template <class T> class MOS6522 {
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Intended to be overridden
|
// Expected to be overridden
|
||||||
uint8_t get_port_input(int port) { return 0xff; }
|
uint8_t get_port_input(int port) { return 0xff; }
|
||||||
void set_port_output(int port, uint8_t value) {}
|
void set_port_output(int port, uint8_t value, uint8_t direction_mask) {}
|
||||||
// void set_interrupt_status(bool status) {}
|
// 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 input = static_cast<T *>(this)->get_port_input(port);
|
||||||
|
return (input & ~output_mask) | (output & output_mask);
|
||||||
|
}
|
||||||
|
|
||||||
// Phase toggle
|
// Phase toggle
|
||||||
bool _is_phase2;
|
bool _is_phase2;
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDeleg
|
|||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_port_output(int port, uint8_t value) {
|
void set_port_output(int port, uint8_t value, uint8_t mask) {
|
||||||
if(port)
|
if(port)
|
||||||
_activation_mask = value;
|
_activation_mask = (value & mask) | (~mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardVIA() {
|
KeyboardVIA() {
|
||||||
|
@ -98,7 +98,7 @@ class MOS6522Tests: XCTestCase {
|
|||||||
func testDataDirection() {
|
func testDataDirection() {
|
||||||
with6522 {
|
with6522 {
|
||||||
// set low four bits of register B as output, the top four as input
|
// set low four bits of register B as output, the top four as input
|
||||||
$0.setValue(0x0f, forRegister: 2)
|
$0.setValue(0xf0, forRegister: 2)
|
||||||
|
|
||||||
// ask to output 0x8c
|
// ask to output 0x8c
|
||||||
$0.setValue(0x8c, forRegister: 0)
|
$0.setValue(0x8c, forRegister: 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user