tod.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2018 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2009-2014 VICE Project
* Copyright 2007-2010 Antti Lankila
* Copyright 2000 Simon White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TOD_H
#define TOD_H
#include <stdint.h>
#include "EventScheduler.h"
namespace libsidplayfp
{
class MOS652X;
class Tod : private Event
{
private:
enum
{
TENTHS = 0,
SECONDS = 1,
MINUTES = 2,
HOURS = 3
};
private:
EventScheduler &eventScheduler;
MOS652X &parent;
const uint8_t &cra;
const uint8_t &crb;
event_clock_t cycles;
event_clock_t period;
unsigned int todtickcounter;
bool isLatched;
bool isStopped;
uint8_t clock[4];
uint8_t latch[4];
uint8_t alarm[4];
private:
inline void checkAlarm();
inline void updateCounters();
void event();
public:
Tod(EventScheduler &scheduler, MOS652X &parent, uint8_t regs[0x10]) :
Event("CIA Time of Day"),
eventScheduler(scheduler),
parent(parent),
cra(regs[0x0e]),
crb(regs[0x0f]),
period(~0), // Dummy
todtickcounter(0)
{}
void reset();
uint8_t read(uint_least8_t reg);
void write(uint_least8_t reg, uint8_t data);
void setPeriod(event_clock_t clock) { period = clock * (1 << 7); }
};
}
#endif
libsidplayfp::EventScheduler
Definition EventScheduler.h:62
libsidplayfp::Event
Definition Event.h:39
libsidplayfp::MOS652X
Definition mos652x.h:154
libsidplayfp::Tod
Definition tod.h:40
libsidplayfp::Tod::reset
void reset()
Definition tod.cpp:33
libsidplayfp::Tod::setPeriod
void setPeriod(event_clock_t clock)
Definition tod.h:118
libsidplayfp::Tod::write
void write(uint_least8_t reg, uint8_t data)
Definition tod.cpp:66
libsidplayfp::Tod::read
uint8_t read(uint_least8_t reg)
Definition tod.cpp:49