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
|
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
/***************************************************************************
sh_port.h
SH i/o ports
***************************************************************************/
#include "emu.h"
#include "sh_intc.h"
#include "sh7042.h"
DEFINE_DEVICE_TYPE(SH_PORT16, sh_port16_device, "sh_port16", "SH 16-bits port")
DEFINE_DEVICE_TYPE(SH_PORT32, sh_port32_device, "sh_port32", "SH 32-bits port")
sh_port16_device::sh_port16_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
device_t(mconfig, SH_PORT16, tag, owner, clock),
m_cpu(*this, finder_base::DUMMY_TAG)
{
}
void sh_port16_device::device_start()
{
m_io = m_default_io;
save_item(NAME(m_dr));
save_item(NAME(m_io));
}
void sh_port16_device::device_reset()
{
}
u16 sh_port16_device::dr_r()
{
if(~m_io & ~m_mask)
return (m_dr & m_io) | (m_cpu->do_read_port16(m_index) & ~m_io);
return m_dr;
}
void sh_port16_device::dr_w(offs_t, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_dr);
m_dr &= ~m_mask;
if(m_io)
m_cpu->do_write_port16(m_index, m_dr & m_io, m_io);
}
u16 sh_port16_device::io_r()
{
return m_io;
}
void sh_port16_device::io_w(offs_t, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_io);
m_io &= ~m_mask;
if(m_io)
m_cpu->do_write_port16(m_index, m_dr & m_io, m_io);
}
sh_port32_device::sh_port32_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
device_t(mconfig, SH_PORT32, tag, owner, clock),
m_cpu(*this, finder_base::DUMMY_TAG)
{
}
void sh_port32_device::device_start()
{
m_io = m_default_io;
save_item(NAME(m_dr));
save_item(NAME(m_io));
}
void sh_port32_device::device_reset()
{
}
u32 sh_port32_device::dr_r()
{
if((~m_io) & (~m_mask))
return (m_dr & m_io) | (m_cpu->do_read_port32(m_index) & ~m_io);
return m_dr;
}
void sh_port32_device::dr_w(offs_t, u32 data, u32 mem_mask)
{
COMBINE_DATA(&m_dr);
m_dr &= ~m_mask;
if(m_io)
m_cpu->do_write_port32(m_index, m_dr & m_io, m_io);
}
u32 sh_port32_device::io_r()
{
return m_io;
}
void sh_port32_device::io_w(offs_t, u32 data, u32 mem_mask)
{
COMBINE_DATA(&m_io);
m_io &= ~m_mask;
if(m_io)
m_cpu->do_write_port32(m_index, m_dr & m_io, m_io);
}
|