summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/sh/sh7604_bus.cpp
blob: 4a98ab6130a479a76c00582d8e85e161815f62b1 (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
// license:BSD-3-Clause
// copyright-holders:Angelo Salese
/***************************************************************************

  SH7604 BUS Controller

  Lies at 0xffffffe0-0xffffffff


  TODO:
  - Host CPU setter (is_slave and clock are needed);
  - timer clock emulation;
  - fix fatalerrors;
  - bus control stuff, someday;

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

#include "emu.h"
#include "sh7604_bus.h"

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

// device type definition
DEFINE_DEVICE_TYPE(SH7604_BUS, sh7604_bus_device, "sh7604bus", "SH7604 BUS Controller")


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

READ16_MEMBER(sh7604_bus_device::bus_control_1_r)
{
	return (m_bcr1 & 0x1ff7) | (m_is_slave == true ? 0x8000 : 0);
}

WRITE16_MEMBER(sh7604_bus_device::bus_control_1_w)
{
	COMBINE_DATA(&m_bcr1);
	if(m_bcr1 & 0x1000) // ENDIAN
		throw emu_fatalerror("%s: enabled little endian for Area 2\n", tag());
	if(m_bcr1 & 0x0800) // PSHR
		throw emu_fatalerror("%s: enabled partial space share mode\n", tag());
}

READ16_MEMBER(sh7604_bus_device::bus_control_2_r) { return m_bcr2 & 0x00fc; }
WRITE16_MEMBER(sh7604_bus_device::bus_control_2_w)
{
	COMBINE_DATA(&m_bcr2);
	if(m_bcr2 != 0x00fc)
		throw emu_fatalerror("%s: unexpected bus size register set %04x\n", tag(),data);
}

READ16_MEMBER(sh7604_bus_device::wait_control_r) { return m_wcr; }
WRITE16_MEMBER(sh7604_bus_device::wait_control_w) { COMBINE_DATA(&m_wcr); }

READ16_MEMBER(sh7604_bus_device::memory_control_r) { return m_mcr & 0xfefc; }
WRITE16_MEMBER(sh7604_bus_device::memory_control_w) { COMBINE_DATA(&m_mcr); }

READ16_MEMBER(sh7604_bus_device::refresh_timer_status_r)
{
	return m_rtcsr & 0x00f8;
}

WRITE16_MEMBER(sh7604_bus_device::refresh_timer_control_w)
{
	COMBINE_DATA(&m_rtcsr);

	if(m_rtcsr & 0x40)
		throw emu_fatalerror("%s: enabled timer irq register with clock setting = %02x\n",tag(),data & 0x38);
}

READ16_MEMBER(sh7604_bus_device::refresh_timer_counter_r)
{
	throw emu_fatalerror("%s: reading timer counter!\n",tag());
	return 0;
}

WRITE16_MEMBER(sh7604_bus_device::refresh_timer_counter_w)
{
	throw emu_fatalerror("%s: writing timer counter %04x\n",tag(),data);
	//COMBINE_DATA(&m_rtcnt);
}

READ16_MEMBER(sh7604_bus_device::refresh_timer_constant_r)
{
	return m_rtcor & 0xff;
}

WRITE16_MEMBER(sh7604_bus_device::refresh_timer_constant_w)
{
	COMBINE_DATA(&m_rtcor);
}

void sh7604_bus_device::bus_regs(address_map &map)
{
	map(0x00, 0x01).rw(FUNC(sh7604_bus_device::bus_control_1_r), FUNC(sh7604_bus_device::bus_control_1_w));
	map(0x02, 0x03).rw(FUNC(sh7604_bus_device::bus_control_2_r), FUNC(sh7604_bus_device::bus_control_2_w));
	map(0x04, 0x05).rw(FUNC(sh7604_bus_device::wait_control_r), FUNC(sh7604_bus_device::wait_control_w));
	map(0x06, 0x07).rw(FUNC(sh7604_bus_device::memory_control_r), FUNC(sh7604_bus_device::memory_control_w));
	map(0x08, 0x09).rw(FUNC(sh7604_bus_device::refresh_timer_status_r), FUNC(sh7604_bus_device::refresh_timer_control_w));
	map(0x0a, 0x0b).rw(FUNC(sh7604_bus_device::refresh_timer_counter_r), FUNC(sh7604_bus_device::refresh_timer_counter_w));
	map(0x0c, 0x0d).rw(FUNC(sh7604_bus_device::refresh_timer_constant_r), FUNC(sh7604_bus_device::refresh_timer_constant_w));
//  AM_RANGE(0x0e, 0x0f) unmapped, mirror?
}

//-------------------------------------------------
//  sh7604_bus_device - constructor
//-------------------------------------------------

sh7604_bus_device::sh7604_bus_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, SH7604_BUS, tag, owner, clock)
{
}

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

void sh7604_bus_device::device_start()
{
}


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

void sh7604_bus_device::device_reset()
{
	m_bcr1 = 0x03f0;
	m_bcr2 = 0x00fc;
	m_wcr = 0xaaff;
	m_mcr = 0x0000;
	m_rtcsr = 0x0000;
	m_rtcor = 0x0000;
}


//**************************************************************************
//  READ/WRITE HANDLERS
//**************************************************************************

READ32_MEMBER( sh7604_bus_device::read )
{
	// 16 bit access only, TODO
	return space.read_word(offset) & 0xffff;
}

WRITE32_MEMBER( sh7604_bus_device::write )
{
	// TODO: 8 bit access is invalid
	// if accessing bits 16-31, one must write ID = 0xa55a
	if(ACCESSING_BITS_16_31)
	{
		// throw fatalerror if something trips it, presumably the write is going to be ignored
		if((data & 0xffff0000) != 0xa55a0000)
			throw emu_fatalerror("%s: making bus write with ID signature = %04x!\n", tag(),data >> 16);
	}

	space.write_word(offset,data & 0xffff);
}