summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/icm7170.cpp
blob: 77a507ba8a1a77d2ccf1254f654bcd7021cf2fad (plain) (blame)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/**********************************************************************

    Intersil/Renesas ICM7170 Real Time Clock

*********************************************************************/

#include "emu.h"
#include "icm7170.h"
#include "coreutil.h"

#define VERBOSE (1)
#include "logmacro.h"

DEFINE_DEVICE_TYPE(ICM7170, icm7170_device, "icm7170", "Intersil/Renesas ICM7170 Real Time Clock")

// internal registers
enum
{
	REG_CNT_100TH_SEC = 0,
	REG_CNT_HOURS,
	REG_CNT_MINUTES,
	REG_CNT_SECONDS,
	REG_CNT_MONTH,
	REG_CNT_DAY,
	REG_CNT_YEAR,
	REG_CNT_DAY_OF_WEEK,
	REG_RAM_100TH_SEC,
	REG_RAM_HOURS,
	REG_RAM_MINUTES,
	REG_RAM_SECONDS,
	REG_RAM_MONTH,
	REG_RAM_DAY,
	REG_RAM_YEAR,
	REG_RAM_DAY_OF_WEEK,
	REG_INT_STATUS_AND_MASK,
	REG_COMMAND
};

enum
{
	CMD_REG_TEST_MODE = 0x20,
	CMD_REG_IRQ_ENABLE = 0x10,
	CMD_REG_RUN = 0x08,
	CMD_REG_24_HOUR = 0x04,
	CMD_REG_FREQ_MASK = 0x03
};

enum
{
	IRQ_BIT_GLOBAL = 0x80,
	IRQ_BIT_DAY = 0x40,
	IRQ_BIT_HOUR = 0x20,
	IRQ_BIT_MINUTE = 0x10,
	IRQ_BIT_SECOND = 0x08,
	IRQ_BIT_10TH_SECOND = 0x04,
	IRQ_BIT_100TH_SECOND = 0x02,
	IRQ_BIT_ALARM = 0x01
};

static constexpr int ICM7170_TIMER_ID = 0;

//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  icm7170_device - constructor
//-------------------------------------------------

icm7170_device::icm7170_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, ICM7170, tag, owner, clock),
		device_rtc_interface(mconfig, *this),
		device_nvram_interface(mconfig, *this),
		m_out_irq_cb(*this)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void icm7170_device::device_start()
{
	// resolve callbacks
	m_out_irq_cb.resolve_safe();

	m_timer = timer_alloc(ICM7170_TIMER_ID);
	m_timer->adjust(attotime::never);

	save_item(NAME(m_regs));
}

//-------------------------------------------------
//  device_reset - device-specific reset handling
//-------------------------------------------------

void icm7170_device::device_reset()
{
	m_regs[REG_COMMAND] &= ~CMD_REG_RUN;
	m_irq_status = 0;
	recalc_irqs();
}

//-------------------------------------------------
//  device_timer - handles timer events
//-------------------------------------------------

void icm7170_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
}


//-------------------------------------------------
//  rtc_clock_updated - called when the host time changes
//-------------------------------------------------

void icm7170_device::rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second)
{
	if (m_regs[REG_COMMAND] & CMD_REG_RUN)
	{
		m_regs[REG_CNT_YEAR] = year % 99;
		m_regs[REG_CNT_MONTH] = month;
		m_regs[REG_CNT_DAY] = day;
		m_regs[REG_CNT_DAY_OF_WEEK] = day_of_week;
		m_regs[REG_CNT_HOURS] = hour;
		m_regs[REG_CNT_MINUTES] = minute;
		m_regs[REG_CNT_SECONDS] = second;
	}
}


//-------------------------------------------------
//  nvram_default - called to initialize NVRAM to
//  its default state
//-------------------------------------------------

void icm7170_device::nvram_default()
{
	memset(m_regs, 0, 0x20);
}


//-------------------------------------------------
//  nvram_read - called to read NVRAM from the
//  .nv file
//-------------------------------------------------

void icm7170_device::nvram_read(emu_file &file)
{
	file.read(m_regs, 0x20);
}


//-------------------------------------------------
//  nvram_write - called to write NVRAM to the
//  .nv file
//-------------------------------------------------

void icm7170_device::nvram_write(emu_file &file)
{
	file.write(m_regs, 0x20);
}

// non-inherited device functions
uint8_t icm7170_device::read(offs_t offset)
{
	uint8_t data =  m_regs[offset & 0x1f];

	if ((offset & 0x1f) == REG_INT_STATUS_AND_MASK)
	{
		data = m_irq_status;
	}

	LOG("ICM7170 Register %d Read %02x\n", offset, data);

	return data;
}

void icm7170_device::write(offs_t offset, uint8_t data)
{
	switch (offset & 0x1f)
	{
		case REG_INT_STATUS_AND_MASK:
			m_irq_mask = data;
			LOG("ICM7170 IRQ Mask Write %02x\n", data);
			recalc_irqs();
			break;

		default:
			m_regs[offset & 0x1f] = data;
			LOG("ICM7170 Register %d Write %02x\n", offset & 0x1f, data);
			break;
	}
}

void icm7170_device::recalc_irqs()
{
}