summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/dmv/k803.c
blob: 7f748cc480679a8f7e2dd9792a2a305862c2a2cc (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
// license:BSD-3-Clause
// copyright-holders:Sandro Ronco
/***************************************************************************

    K803 RTC module

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

#include "emu.h"
#include "k803.h"


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

static MACHINE_CONFIG_FRAGMENT( dmv_k803 )
	MCFG_DEVICE_ADD("rtc", MM58167, XTAL_32_768kHz)
	MCFG_MM58167_IRQ_CALLBACK(WRITELINE(dmv_k803_device, rtc_irq_w))
MACHINE_CONFIG_END

static INPUT_PORTS_START( dmv_k803 )
	PORT_START("DSW")
	PORT_DIPNAME( 0x0f, 0x09, "K803 IFSEL" )  PORT_DIPLOCATION("S:!4,S:!3,S:!2,S:!1")
	PORT_DIPSETTING( 0x00, "0A" )
	PORT_DIPSETTING( 0x01, "0B" )
	PORT_DIPSETTING( 0x02, "1A" )
	PORT_DIPSETTING( 0x03, "1B" )
	PORT_DIPSETTING( 0x04, "2A" )
	PORT_DIPSETTING( 0x05, "2B" )
	PORT_DIPSETTING( 0x06, "3A" )
	PORT_DIPSETTING( 0x07, "3B" )
	PORT_DIPSETTING( 0x08, "4A" )
	PORT_DIPSETTING( 0x09, "4B" )   // default
INPUT_PORTS_END

//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

const device_type DMV_K803 = &device_creator<dmv_k803_device>;


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

//-------------------------------------------------
//  dmv_k803_device - constructor
//-------------------------------------------------

dmv_k803_device::dmv_k803_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
		: device_t(mconfig, DMV_K803, "K803 RTC", tag, owner, clock, "dmv_k803", __FILE__),
		device_dmvslot_interface( mconfig, *this ),
		m_rtc(*this, "rtc"),
		m_dsw(*this, "DSW")
{
}

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

void dmv_k803_device::device_start()
{
	m_bus = static_cast<dmvcart_slot_device*>(owner());
}

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

void dmv_k803_device::device_reset()
{
	m_latch = 0;
	m_rtc_int = CLEAR_LINE;
}

//-------------------------------------------------
//  machine_config_additions - device-specific
//  machine configurations
//-------------------------------------------------

machine_config_constructor dmv_k803_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( dmv_k803 );
}

//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor dmv_k803_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( dmv_k803 );
}

void dmv_k803_device::io_read(address_space &space, int ifsel, offs_t offset, UINT8 &data)
{
	UINT8 dsw = m_dsw->read() & 0x0f;
	if ((dsw >> 1) == ifsel && BIT(offset, 3) == BIT(dsw, 0))
	{
		if (offset & 0x04)
			data = m_rtc->read(space, ((m_latch & 0x07) << 2) | (offset & 0x03));
	}
}

void dmv_k803_device::io_write(address_space &space, int ifsel, offs_t offset, UINT8 data)
{
	UINT8 dsw = m_dsw->read() & 0x0f;
	if ((dsw >> 1) == ifsel && BIT(offset, 3) == BIT(dsw, 0))
	{
		if (offset & 0x04)
			m_rtc->write(space, ((m_latch & 0x07) << 2) | (offset & 0x03), data);
		else
		{
			m_latch = data;
			update_int();
		}
	}
}

WRITE_LINE_MEMBER(dmv_k803_device::rtc_irq_w)
{
	m_rtc_int = state;
	update_int();
}

void dmv_k803_device::update_int()
{
	bool state = ((m_latch & 0x80) && m_rtc_int);
	m_bus->m_out_int_cb(state ? ASSERT_LINE : CLEAR_LINE);
}