summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/bbc/rom/rtc.cpp
blob: 7d73c24b53ec1fd6006161e76795b823dfa1421c (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/***************************************************************************

    Solidisk Real Time Clock

    http://chrisacorns.computinghistory.org.uk/8bit_Upgrades/Solidisk_RTC.html

    PMS Genie Watch (RTC for the BBC)

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

#include "emu.h"
#include "rtc.h"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(BBC_STLRTC, bbc_stlrtc_device, "bbc_stlrtc", "Solidisk Real Time Clock")
DEFINE_DEVICE_TYPE(BBC_PMSRTC, bbc_pmsrtc_device, "bbc_pmsrtc", "PMS Genie Real Time Clock")


//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void bbc_stlrtc_device::device_add_mconfig(machine_config &config)
{
	MC146818(config, m_rtc, 32.768_kHz_XTAL); // TODO: verify clock
}

void bbc_pmsrtc_device::device_add_mconfig(machine_config &config)
{
	/* Dallas DS1216 SmartWatch RAM */
	DS1315(config, m_rtc, 0);
}

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

//-------------------------------------------------
//  bbc_stlrtc_device - constructor
//-------------------------------------------------

bbc_stlrtc_device::bbc_stlrtc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, BBC_STLRTC, tag, owner, clock)
	, device_bbc_rom_interface(mconfig, *this)
	, m_rtc(*this, "rtc")
{
}

bbc_pmsrtc_device::bbc_pmsrtc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, BBC_PMSRTC, tag, owner, clock)
	, device_bbc_rom_interface(mconfig, *this)
	, m_rtc(*this, "rtc")
{
}

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

void bbc_stlrtc_device::device_start()
{
}

void bbc_pmsrtc_device::device_start()
{
}

//-------------------------------------------------
//  read
//-------------------------------------------------

uint8_t bbc_stlrtc_device::read(offs_t offset)
{
	uint8_t data = get_rom_base()[offset & 0x3fff];

	switch (offset & 0x3fc0)
	{
	case 0x3e00:
		data = m_rtc->read(1);
		break;
	case 0x3e40:
		if (!machine().side_effects_disabled())
			m_rtc->write(0, data);
		break;
	case 0x3e80:
	case 0x3ec0:
		data = m_rtc->read(0);
		break;
	case 0x3f00:
	case 0x3f40:
	case 0x3f80:
	case 0x3fc0:
		if (!machine().side_effects_disabled())
			m_rtc->write(1, data);
		break;
	}
	return data;
}

uint8_t bbc_pmsrtc_device::read(offs_t offset)
{
	uint8_t data = get_rom_base()[offset & 0x1fff];

	switch (offset)
	{
	case 0x00:
		data |= m_rtc->read_0();
		break;
	case 0x01:
		data |= m_rtc->read_1();
		break;
	case 0x04:
		if (m_rtc->chip_enable())
			data = m_rtc->read_data() & 0x01;
		break;
	}
	return data;
}