libsidplayfp  1.8.7
tod.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2014 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 
31 class MOS6526;
32 
36 class Tod : private Event
37 {
38 private:
39  enum
40  {
41  TENTHS = 0,
42  SECONDS = 1,
43  MINUTES = 2,
44  HOURS = 3
45  };
46 
47 private:
49  EventContext &event_context;
50 
52  MOS6526* const parent;
53 
54  event_clock_t cycles;
55  event_clock_t period;
56 
57  uint8_t clock[4];
58  uint8_t latch[4];
59  uint8_t alarm[4];
60 
61  const uint8_t &cra;
62  const uint8_t &crb;
63 
64  bool isLatched;
65  bool isStopped;
66 
67 private:
68  inline void checkAlarm();
69 
70  void event();
71 
72 public:
73  Tod(EventContext *context, MOS6526* parent, uint8_t regs[0x10]) :
74  Event("CIA Time of Day"),
75  event_context(*context),
76  parent(parent),
77  period(~0), // Dummy
78  cra(regs[0x0e]),
79  crb(regs[0x0f]) {}
80 
84  void reset();
85 
92  uint8_t read(uint_least8_t reg);
93 
102  void write(uint_least8_t reg, uint8_t data);
103 
109  void setPeriod(event_clock_t clock) { period = clock * (1 << 7); }
110 };
111 
112 #endif
Definition: mos6526.h:103
uint8_t read(uint_least8_t reg)
Definition: tod.cpp:45
Definition: event.h:107
void setPeriod(event_clock_t clock)
Definition: tod.h:109
void reset()
Definition: tod.cpp:30
void write(uint_least8_t reg, uint8_t data)
Definition: tod.cpp:62
Definition: event.h:50
Event(const char *const name)
Definition: event.h:77
Definition: tod.h:36