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

The 6532 is now a ClockReceiver.

This commit is contained in:
Thomas Harte 2017-07-24 21:57:24 -04:00
parent d056f2e246
commit 2912d7055b
3 changed files with 15 additions and 20 deletions

View File

@ -11,6 +11,7 @@
#include <cstdint>
#include <cstdio>
#include "../ClockReceiver.hpp"
namespace MOS {
@ -25,7 +26,7 @@ namespace MOS {
Consumers should derive their own curiously-recurring-template-pattern subclass,
implementing bus communications as required.
*/
template <class T> class MOS6532 {
template <class T> class MOS6532: public ClockReceiver<MOS6532<T>> {
public:
inline void set_ram(uint16_t address, uint8_t value) { ram_[address&0x7f] = value; }
inline uint8_t get_ram(uint16_t address) { return ram_[address & 0x7f]; }
@ -104,7 +105,9 @@ template <class T> class MOS6532 {
return 0xff;
}
inline void run_for_cycles(unsigned int number_of_cycles) {
inline void run_for(const Cycles &cycles) {
unsigned int number_of_cycles = (unsigned int)cycles.as_int();
// permit counting _to_ zero; counting _through_ zero initiates the other behaviour
if(timer_.value >= number_of_cycles) {
timer_.value -= number_of_cycles;

View File

@ -55,7 +55,7 @@ class Bus {
// RIOT backlog accumulation counter
unsigned int cycles_since_6532_update_;
inline void update_6532() {
mos6532_.run_for_cycles(cycles_since_6532_update_);
mos6532_.run_for(Cycles((int)cycles_since_6532_update_));
cycles_since_6532_update_ = 0;
}
};

View File

@ -11,45 +11,37 @@
class VanillaRIOT: public MOS::MOS6532<VanillaRIOT> {
public:
uint8_t get_port_input(int port)
{
uint8_t get_port_input(int port) {
return input[port];
}
uint8_t input[2];
};
@implementation MOS6532Bridge
{
@implementation MOS6532Bridge {
VanillaRIOT _riot;
}
- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber
{
- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber {
_riot.set_register((int)registerNumber, value);
}
- (uint8_t)valueForRegister:(NSUInteger)registerNumber
{
- (uint8_t)valueForRegister:(NSUInteger)registerNumber {
return _riot.get_register((int)registerNumber);
}
- (void)runForCycles:(NSUInteger)numberOfCycles
{
_riot.run_for_cycles((int)numberOfCycles);
- (void)runForCycles:(NSUInteger)numberOfCycles {
_riot.run_for(Cycles((int)numberOfCycles));
}
- (BOOL)irqLine
{
- (BOOL)irqLine {
return _riot.get_inerrupt_line();
}
- (void)setPortAInput:(uint8_t)portAInput
{
- (void)setPortAInput:(uint8_t)portAInput {
_riot.input[0] = _portAInput = portAInput;
}
- (void)setPortBInput:(uint8_t)portBInput
{
- (void)setPortBInput:(uint8_t)portBInput {
_riot.input[1] = _portBInput = portBInput;
}