summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/samcoupe/expansion/dallas.cpp
blob: e7c57fb66cc3ecf800b7411d5248b16984630a01 (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
// license: GPL-2.0+
// copyright-holders: Dirk Best
/***************************************************************************

    Dallas Clock for SAM Coupe

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

#include "emu.h"
#include "dallas.h"


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

DEFINE_DEVICE_TYPE(SAM_DALLAS_CLOCK, sam_dallas_clock_device, "sam_dallas_clock", "Dallas Clock")

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

void sam_dallas_clock_device::device_add_mconfig(machine_config &config)
{
	DS12885(config, m_rtc, 32.768_kHz_XTAL); // should be DS12887 or DS1287
	m_rtc->set_24hrs(true);
}


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

//-------------------------------------------------
//  sam_dallas_clock_device - constructor
//-------------------------------------------------

sam_dallas_clock_device::sam_dallas_clock_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, SAM_DALLAS_CLOCK, tag, owner, clock),
	device_samcoupe_expansion_interface(mconfig, *this),
	m_rtc(*this, "rtc")
{
}

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

void sam_dallas_clock_device::device_start()
{
	// register for savestates
	save_item(NAME(m_print));
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

void sam_dallas_clock_device::print_w(int state)
{
	m_print = state;
}

uint8_t sam_dallas_clock_device::iorq_r(offs_t offset)
{
	uint8_t data = 0xff;

	if (m_print && (offset & 0xfe07) == 0xfe07)
		data &= m_rtc->read((offset >> 8) & 0x01);

	return data;
}

void sam_dallas_clock_device::iorq_w(offs_t offset, uint8_t data)
{
	if (m_print && (offset & 0xfe07) == 0xfe07)
		m_rtc->write((offset >> 8) & 0x01, data);
}