2021-07-18 15:36:13 +00:00
|
|
|
//
|
|
|
|
// 6526Implementation.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/07/2021.
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _526Implementation_h
|
|
|
|
#define _526Implementation_h
|
|
|
|
|
2021-07-18 16:13:56 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2021-07-18 15:36:13 +00:00
|
|
|
namespace MOS {
|
|
|
|
namespace MOS6526 {
|
|
|
|
|
2021-07-18 21:17:41 +00:00
|
|
|
template <typename BusHandlerT, Personality personality>
|
|
|
|
template <int port> void MOS6526<BusHandlerT, personality>::set_port_output() {
|
|
|
|
const uint8_t output = registers_.output[port] | (~registers_.data_direction[port]);
|
|
|
|
port_handler_.set_port_output(Port(port), output);
|
|
|
|
}
|
|
|
|
|
2021-07-19 00:25:04 +00:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2021-07-22 20:09:32 +00:00
|
|
|
template <typename BusHandlerT, Personality personality>
|
|
|
|
void MOS6526<BusHandlerT, personality>::update_interrupts() {
|
|
|
|
}
|
|
|
|
|
2021-07-18 15:36:13 +00:00
|
|
|
template <typename BusHandlerT, Personality personality>
|
|
|
|
void MOS6526<BusHandlerT, personality>::write(int address, uint8_t value) {
|
2021-07-18 16:13:56 +00:00
|
|
|
address &= 0xf;
|
2021-07-18 16:23:47 +00:00
|
|
|
switch(address) {
|
2021-07-18 21:17:41 +00:00
|
|
|
// Port output.
|
|
|
|
case 0:
|
|
|
|
registers_.output[0] = value;
|
|
|
|
set_port_output<0>();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
registers_.output[1] = value;
|
|
|
|
set_port_output<1>();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Port direction.
|
|
|
|
case 2:
|
|
|
|
registers_.data_direction[0] = value;
|
|
|
|
set_port_output<0>();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
registers_.data_direction[1] = value;
|
|
|
|
set_port_output<1>();
|
2021-07-18 16:23:47 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-22 20:09:32 +00:00
|
|
|
// Interrupt control.
|
|
|
|
case 13:
|
|
|
|
registers_.interrupt_control_ = value;
|
|
|
|
update_interrupts();
|
|
|
|
break;
|
|
|
|
|
2021-07-22 23:28:01 +00:00
|
|
|
// Control.
|
|
|
|
case 14:
|
|
|
|
case 15:
|
|
|
|
registers_.control[address - 14] = value;
|
|
|
|
printf("Ignoring control write: %02x to %d\n", value, address);
|
|
|
|
break;
|
|
|
|
|
2021-07-18 16:23:47 +00:00
|
|
|
default:
|
|
|
|
printf("Unhandled 6526 write: %02x to %d\n", value, address);
|
2021-07-22 23:28:01 +00:00
|
|
|
// assert(false);
|
2021-07-18 16:23:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-18 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename BusHandlerT, Personality personality>
|
|
|
|
uint8_t MOS6526<BusHandlerT, personality>::read(int address) {
|
2021-07-18 16:13:56 +00:00
|
|
|
address &= 0xf;
|
2021-07-18 16:23:47 +00:00
|
|
|
switch(address) {
|
2021-07-22 20:09:32 +00:00
|
|
|
case 0: return get_port_input<0>();
|
|
|
|
case 1: return get_port_input<1>();
|
|
|
|
case 13: return registers_.interrupt_control_;
|
2021-07-18 21:17:41 +00:00
|
|
|
|
2021-07-18 16:23:47 +00:00
|
|
|
case 2: case 3:
|
2021-07-22 20:09:32 +00:00
|
|
|
return registers_.data_direction[address - 2];
|
|
|
|
|
2021-07-22 23:28:01 +00:00
|
|
|
case 14: case 15:
|
|
|
|
return registers_.control[address - 14];
|
2021-07-18 16:23:47 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unhandled 6526 read from %d\n", address);
|
2021-07-22 23:28:01 +00:00
|
|
|
// assert(false);
|
2021-07-18 16:23:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-18 15:36:13 +00:00
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
|
2021-07-18 15:49:10 +00:00
|
|
|
template <typename BusHandlerT, Personality personality>
|
|
|
|
void MOS6526<BusHandlerT, personality>::run_for(const HalfCycles half_cycles) {
|
|
|
|
(void)half_cycles;
|
|
|
|
}
|
|
|
|
|
2021-07-18 15:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _526Implementation_h */
|