libsidplayfp 1.8.8
tod.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2018 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2009-2014 VICE Project
6 * Copyright 2007-2010 Antti Lankila
7 * Copyright 2000 Simon White
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23
24#ifndef TOD_H
25#define TOD_H
26
27#include <stdint.h>
28
29#include "sidplayfp/event.h"
30
31class MOS6526;
32
36class Tod : private Event
37{
38private:
39 enum
40 {
41 TENTHS = 0,
42 SECONDS = 1,
43 MINUTES = 2,
44 HOURS = 3
45 };
46
47private:
49 EventContext &event_context;
50
52 MOS6526* const parent;
53
54 event_clock_t cycles;
55 event_clock_t period;
56
57 unsigned int todtickcounter;
58
59 uint8_t clock[4];
60 uint8_t latch[4];
61 uint8_t alarm[4];
62
63 const uint8_t &cra;
64 const uint8_t &crb;
65
66 bool isLatched;
67 bool isStopped;
68
69private:
70 inline void checkAlarm();
71
72 inline void updateCounters();
73
74 void event();
75
76public:
77 Tod(EventContext *context, MOS6526* parent, uint8_t regs[0x10]) :
78 Event("CIA Time of Day"),
79 event_context(*context),
80 parent(parent),
81 period(~0), // Dummy
82 todtickcounter(0),
83 cra(regs[0x0e]),
84 crb(regs[0x0f]) {}
85
89 void reset();
90
97 uint8_t read(uint_least8_t reg);
98
107 void write(uint_least8_t reg, uint8_t data);
108
114 void setPeriod(event_clock_t clock) { period = clock * (1 << 7); }
115};
116
117#endif
Definition: event.h:108
Definition: event.h:51
Definition: mos6526.h:104
Definition: tod.h:37
void reset()
Definition: tod.cpp:30
uint8_t read(uint_least8_t reg)
Definition: tod.cpp:46
void write(uint_least8_t reg, uint8_t data)
Definition: tod.cpp:63
void setPeriod(event_clock_t clock)
Definition: tod.h:114