1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/***************************************************************************
AICA-RTC sub-device
TODO:
- move this inside AICA sound core once that'll get modernized
***************************************************************************/
#include "emu.h"
#include "machine/aicartc.h"
//**************************************************************************
// GLOBAL VARIABLES
//**************************************************************************
// device type definition
const device_type AICARTC = &device_creator<aicartc_device>;
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// aicartc_device - constructor
//-------------------------------------------------
aicartc_device::aicartc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, AICARTC, "AICA RTC", tag, owner, clock, "aicartc", __FILE__),
device_rtc_interface(mconfig, *this)
{
}
//-------------------------------------------------
// device_validity_check - perform validity checks
// on this device
//-------------------------------------------------
void aicartc_device::device_validity_check(validity_checker &valid) const
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void aicartc_device::device_start()
{
m_clock_timer = timer_alloc();
m_clock_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock()));
{
UINT32 current_time;
int year_count,cur_year,i;
const int month_to_day_conversion[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
system_time systime;
machine().base_datetime(systime);
/* put the seconds */
current_time = systime.local_time.second;
/* put the minutes */
current_time+= systime.local_time.minute*60;
/* put the hours */
current_time+= systime.local_time.hour*60*60;
/* put the days (note -1) */
current_time+= (systime.local_time.mday-1)*60*60*24;
/* take the current year here for calculating leaps */
cur_year = (systime.local_time.year);
/* take the months - despite popular beliefs, leap years aren't just evenly divisible by 4 */
if(((((cur_year % 4) == 0) && ((cur_year % 100) != 0)) || ((cur_year % 400) == 0)) && systime.local_time.month > 2)
current_time+= (month_to_day_conversion[systime.local_time.month]+1)*60*60*24;
else
current_time+= (month_to_day_conversion[systime.local_time.month])*60*60*24;
/* put the years */
year_count = (cur_year-1949);
for(i=0;i<year_count-1;i++)
current_time += (((((i+1950) % 4) == 0) && (((i+1950) % 100) != 0)) || (((i+1950) % 400) == 0)) ? 60*60*24*366 : 60*60*24*365;
m_rtc_reg_lo = current_time & 0x0000ffff;
m_rtc_reg_hi = (current_time & 0xffff0000) >> 16;
}
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void aicartc_device::device_reset()
{
m_rtc_tick = 0;
}
//-------------------------------------------------
// device_timer - handler timer events
//-------------------------------------------------
void aicartc_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
m_rtc_tick++;
if(m_rtc_tick & 0x8000)
{
m_rtc_tick = 0;
m_rtc_reg_lo++;
if(m_rtc_reg_lo == 0)
m_rtc_reg_hi++;
}
}
//**************************************************************************
// READ/WRITE HANDLERS
//**************************************************************************
READ16_MEMBER( aicartc_device::read )
{
UINT16 res;
res = 0;
switch(offset)
{
case 0:
res = m_rtc_reg_hi; break;
case 1:
res = m_rtc_reg_lo; break;
}
return res;
}
WRITE16_MEMBER( aicartc_device::write )
{
switch(offset)
{
case 0:
if(m_we)
{
COMBINE_DATA(&m_rtc_reg_hi);
// clear write enable here?
}
break;
case 1:
if(m_we)
{
COMBINE_DATA(&m_rtc_reg_lo);
m_rtc_tick = 0; // low register also clears tick count
}
break;
case 2:
m_we = data & 1;
break;
}
}
|