1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-30 04:50:08 +00:00
CLK/Components/6526/6526.hpp

70 lines
1.6 KiB
C++
Raw Normal View History

2021-07-18 15:36:13 +00:00
//
// 6526.h
// Clock Signal
//
// Created by Thomas Harte on 18/07/2021.
// Copyright © 2021 Thomas Harte. All rights reserved.
//
#ifndef _526_h
#define _526_h
#include <cstdint>
#include "Implementation/6526Storage.hpp"
2021-07-18 15:36:13 +00:00
namespace MOS {
namespace MOS6526 {
enum Port {
A = 0,
B = 1
};
2021-07-18 15:36:13 +00:00
struct PortHandler {
2021-07-19 00:25:04 +00:00
/// Requests the current input value of @c port from the port handler.
uint8_t get_port_input([[maybe_unused]] Port port) {
return 0xff;
}
/// Sets the current output value of @c port; any bits marked as input will be supplied as 1s.
void set_port_output([[maybe_unused]] Port port, [[maybe_unused]] uint8_t value) {}
2021-07-18 15:36:13 +00:00
};
enum class Personality {
// The 6526, used in machines such as the C64, has a BCD time-of-day clock.
P6526,
2021-07-18 15:36:13 +00:00
// The 8250, used in the Amiga, provides a binary time-of-day clock.
P8250,
2021-07-18 15:36:13 +00:00
};
template <typename PortHandlerT, Personality personality> class MOS6526:
private MOS6526Storage
{
2021-07-18 15:36:13 +00:00
public:
MOS6526(PortHandlerT &port_handler) noexcept : port_handler_(port_handler) {}
MOS6526(const MOS6526 &) = delete;
2021-07-18 15:36:13 +00:00
/// Writes @c value to the register at @c address. Only the low two bits of the address are decoded.
void write(int address, uint8_t value);
/// Fetches the value of the register @c address. Only the low two bits of the address are decoded.
uint8_t read(int address);
/// Runs for a specified number of half cycles.
void run_for(const HalfCycles half_cycles);
private:
PortHandlerT &port_handler_;
template <int port> void set_port_output();
2021-07-19 00:25:04 +00:00
template <int port> uint8_t get_port_input();
2021-07-18 15:36:13 +00:00
};
}
}
#include "Implementation/6526Implementation.hpp"
#endif /* _526_h */