libsidplayfp  2.0.2
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 
31 namespace libsidplayfp
32 {
33 
34 class MOS6526;
35 
39 class Tod : private Event
40 {
41 private:
42  enum
43  {
44  TENTHS = 0,
45  SECONDS = 1,
46  MINUTES = 2,
47  HOURS = 3
48  };
49 
50 private:
52  EventScheduler &eventScheduler;
53 
55  MOS6526 &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 
72 private:
73  inline void checkAlarm();
74 
75  inline void updateCounters();
76 
77  void event();
78 
79 public:
80  Tod(EventScheduler &scheduler, MOS6526 &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
libsidplayfp::Tod::read
uint8_t read(uint_least8_t reg)
Definition: tod.cpp:49
libsidplayfp::Tod::write
void write(uint_least8_t reg, uint8_t data)
Definition: tod.cpp:66
libsidplayfp::Tod::setPeriod
void setPeriod(event_clock_t clock)
Definition: tod.h:118
libsidplayfp::MOS6526
Definition: mos6526.h:182
libsidplayfp::EventScheduler
Definition: EventScheduler.h:62
libsidplayfp::Event::Event
Event(const char *const name)
Definition: Event.h:59
libsidplayfp::Tod
Definition: tod.h:40
libsidplayfp::Tod::reset
void reset()
Definition: tod.cpp:33
libsidplayfp::Event
Definition: Event.h:39