libsidplayfp 2.15.0
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 "EventScheduler.h"
30
31namespace libsidplayfp
32{
33
34class MOS652X;
35
39class Tod : private Event
40{
41private:
42 enum
43 {
44 TENTHS = 0,
45 SECONDS = 1,
46 MINUTES = 2,
47 HOURS = 3
48 };
49
50private:
52 EventScheduler &eventScheduler;
53
55 MOS652X &parent;
56
57 const uint8_t &cra;
58 const uint8_t &crb;
59
60 event_clock_t cycles;
61 event_clock_t period;
62
63 unsigned int todtickcounter;
64
65 bool isLatched;
66 bool isStopped;
67
68 uint8_t clock[4];
69 uint8_t latch[4];
70 uint8_t alarm[4];
71
72private:
73 inline void checkAlarm();
74
75 inline void updateCounters();
76
77 void event() override;
78
79public:
80 Tod(EventScheduler &scheduler, MOS652X &parent, uint8_t regs[0x10]) :
81 Event("CIA Time of Day"),
82 eventScheduler(scheduler),
83 parent(parent),
84 cra(regs[0x0e]),
85 crb(regs[0x0f]),
86 period(~0), // Dummy
87 todtickcounter(0)
88 {}
89
93 void reset();
94
101 uint8_t read(uint_least8_t reg);
102
111 void write(uint_least8_t reg, uint8_t data);
112
118 void setPeriod(event_clock_t clock) { period = clock * (1 << 7); }
119};
120
121}
122
123#endif
Definition EventScheduler.h:62
Definition Event.h:39
Definition mos652x.h:154
Definition tod.h:40
void reset()
Definition tod.cpp:33
void setPeriod(event_clock_t clock)
Definition tod.h:118
void write(uint_least8_t reg, uint8_t data)
Definition tod.cpp:66
uint8_t read(uint_least8_t reg)
Definition tod.cpp:49