summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/msm6242.h
blob: 3f830070d7d8d22ca9369caf5d3eceec28b3d1bc (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
// license:BSD-3-Clause
// copyright-holders:Nathan Woods
/***************************************************************************

    MSM6242 / RTC-6242x / RTC-7242x Real Time Clock

****************************************************************************
                            _____   _____
                 STD.P   1 |*    \_/     | 18  Vdd
                  /CS0   2 |             | 17  /XT (MSM6242 only)
                   ALE   3 |             | 16  XT  (MSM6242 only)
                    A0   4 |  MSM6242RS  | 15  CS1
                    A1   5 |  RTC62421   | 14  D0
                    A2   6 |  RTC72421   | 13  D1
                    A3   7 |             | 12  D2
                   /RD   8 |             | 11  D3
                   GND   9 |_____________| 10  /WR

                            _____   _____
                 STD.P   1 |*    \_/     | 24  Vdd
                  /CS0   2 |             | 23  /XT (MSM6242 only)
                    NC   3 |             | 22  XT  (MSM6242 only)
                   ALE   4 |             | 21  NC
                    A0   5 |             | 20  CS1
                    NC   6 |  MSM6242GS  | 19  D0
                    A1   7 |  RTC62423   | 18  NC
                    NC   8 |  RTC72423   | 17  NC
                    A2   9 |             | 16  D1
                    A3  10 |             | 15  D2
                   /RD  11 |             | 14  D3
                   GND  12 |_____________| 13  /WR

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

#ifndef MAME_MACHINE_MSM6242_H
#define MAME_MACHINE_MSM6242_H

#pragma once

#include "dirtc.h"


// ======================> msm6242_device

class msm6242_device : public device_t, public device_rtc_interface
{
public:
	// construction/destruction
	msm6242_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

	auto out_int_handler() { return m_out_int_handler.bind(); }

	// I/O operations
	void write(offs_t offset, u8 data);
	u8 read(offs_t offset);

protected:
	msm6242_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);

	// device-level overrides
	virtual void device_start() override ATTR_COLD;
	virtual void device_reset() override ATTR_COLD;
	virtual void device_pre_save() override;
	virtual void device_post_load() override;

	// rtc overrides
	virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override;

private:
	static constexpr int RTC_TICKS = ~0;

	static constexpr u8 IRQ_64THSECOND = 0;
	static constexpr u8 IRQ_SECOND = 1;
	static constexpr u8 IRQ_MINUTE = 2;
	static constexpr u8 IRQ_HOUR = 3;

	// state
	u8                          m_reg[3];
	u8                          m_irq_flag;
	u8                          m_irq_type;
	u16                         m_tick;

	// incidentals
	devcb_write_line m_out_int_handler;
	emu_timer *                 m_timer;
	emu_timer *                 m_timer_irq_clear;
	u64                         m_last_update_time; // last update time, in clock cycles

	// methods
	TIMER_CALLBACK_MEMBER(rtc_timer_callback);
	TIMER_CALLBACK_MEMBER(rtc_irq_pulse_timer_callback);
	u64 current_time();
	void set_irq(bool active);
	void irq(u8 irq_type);
	u64 bump(int rtc_register, u64 delta, u64 register_min, u64 register_range);
	void update_rtc_registers();
	void update_timer();
	u8 get_clock_nibble(int rtc_register, bool high);
	static const char *irq_type_string(u8 irq_type);
};

// ======================> rtc62421_device

class rtc62421_device : public msm6242_device
{
public:
	// construction/destruction
	rtc62421_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
};

// ======================> rtc62423_device

class rtc62423_device : public msm6242_device
{
public:
	// construction/destruction
	rtc62423_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
};

// ======================> rtc72421_device

class rtc72421_device : public msm6242_device
{
public:
	// construction/destruction
	rtc72421_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
};

// ======================> rtc72423_device

class rtc72423_device : public msm6242_device
{
public:
	// construction/destruction
	rtc72423_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
};


// device type definition
DECLARE_DEVICE_TYPE(MSM6242,  msm6242_device)
DECLARE_DEVICE_TYPE(RTC62421, rtc62421_device)
DECLARE_DEVICE_TYPE(RTC62423, rtc62423_device)
DECLARE_DEVICE_TYPE(RTC72421, rtc72421_device)
DECLARE_DEVICE_TYPE(RTC72423, rtc72423_device)


#endif // MAME_MACHINE_MSM6242_H