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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// license:BSD-3-Clause
// copyright-holders:David Haywood
#include "emu.h"
#include "generalplus_gpl_timebase.h"
#define LOG_TIMEBASE (1U << 1)
#define VERBOSE (0)
#include "logmacro.h"
DEFINE_DEVICE_TYPE(GPL_TIMEBASE, gpl_timebase_device, "gpl_timebase", "Generalplus GPL162xx / GPL951xx System Timebase")
gpl_timebase_device::gpl_timebase_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, GPL_TIMEBASE, tag, owner, clock),
m_timebase_a(*this, "timebase_a"),
m_timebase_b(*this, "timebase_b"),
m_timebase_c(*this, "timebase_c"),
m_updateirqs_cb(*this)
{
}
void gpl_timebase_device::device_start()
{
save_item(NAME(m_timebasea_ctrl));
save_item(NAME(m_timebaseb_ctrl));
save_item(NAME(m_timebasec_ctrl));
save_item(NAME(m_timebase_reset));
}
void gpl_timebase_device::device_reset()
{
m_timebasea_ctrl = 0x0000;
m_timebaseb_ctrl = 0x0000;
m_timebasec_ctrl = 0x0000;
m_timebase_reset = 0x0000;
}
// Timebase ('fixed' frequency timers)
// (each can select from 3 different frequencies, different for each timer)
TIMER_DEVICE_CALLBACK_MEMBER( gpl_timebase_device::timebase_a_cb )
{
// sets bit 15 in m_timebasec_ctrl, also visible (as read only) in P_INT_Status2, bit 8
// uses IRQ7 (FIQ option not available)
m_timebasea_ctrl |= 0x8000;
m_updateirqs_cb(1);
}
// P_TimeBaseA_Ctrl
//
// 15 TMBAIF/C
// 14 TMBAIE
// 13 TMBAEN
// 12
//
// 11
// 10
// 9
// 8
// 7
// 6
// 5
// 4
// 3
// 2
// 1 TMBAS[1]
// 0 TMBAS[0] 00 = Reserved, 01 = 1Hz, 10 = 2Hz, 11 = 4Hz
u16 gpl_timebase_device::timebasea_ctrl_r()
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebasea_ctrl_r\n", machine().describe_context());
return m_timebasea_ctrl;
}
void gpl_timebase_device::timebasea_ctrl_w(u16 data)
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebasea_ctrl_w %04x\n", machine().describe_context(), data);
if (data & 0x8000)
{
m_timebasea_ctrl = data & 0x7fff;
m_updateirqs_cb(1);
}
else
{
m_timebasea_ctrl = data;
}
if ((m_timebasea_ctrl & 0x6000) == 0x6000)
{
switch (m_timebasea_ctrl & 0x0003)
{
case 0x00: m_timebase_a->adjust(attotime::never); break; // invalid
case 0x01: m_timebase_a->adjust(attotime::from_hz(1)); break;
case 0x02: m_timebase_a->adjust(attotime::from_hz(2)); break;
case 0x03: m_timebase_a->adjust(attotime::from_hz(4)); break;
}
}
else
{
m_timebase_a->adjust(attotime::never);
}
}
TIMER_DEVICE_CALLBACK_MEMBER( gpl_timebase_device::timebase_b_cb )
{
// sets bit 15 in m_timebaseb_ctrl, also visible (as read only) in P_INT_Status2, bit 9
// uses IRQ7 (FIQ option not available)
m_timebaseb_ctrl |= 0x8000;
m_updateirqs_cb(1);
}
u16 gpl_timebase_device::timebaseb_ctrl_r()
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebaseb_ctrl_r\n", machine().describe_context());
return m_timebaseb_ctrl;
}
void gpl_timebase_device::timebaseb_ctrl_w(u16 data)
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebaseb_ctrl_w %04x\n", machine().describe_context(), data);
if (data & 0x8000)
{
m_timebaseb_ctrl = data & 0x7fff;
m_updateirqs_cb(1);
}
else
{
m_timebaseb_ctrl = data;
}
if ((m_timebaseb_ctrl & 0x6000) == 0x6000)
{
switch (m_timebaseb_ctrl & 0x0003)
{
case 0x00: m_timebase_b->adjust(attotime::from_hz(8)); break;
case 0x01: m_timebase_b->adjust(attotime::from_hz(16)); break;
case 0x02: m_timebase_b->adjust(attotime::from_hz(32)); break;
case 0x03: m_timebase_b->adjust(attotime::from_hz(64)); break;
}
}
else
{
m_timebase_b->adjust(attotime::never);
}
}
TIMER_DEVICE_CALLBACK_MEMBER( gpl_timebase_device::timebase_c_cb )
{
// sets bit 15 in m_timebasec_ctrl, also visible (as read only) in P_INT_Status2, bit 10
// uses IRQ6 (FIQ option not available)
m_timebasec_ctrl |= 0x8000;
m_updateirqs_cb(1);
}
u16 gpl_timebase_device::timebasec_ctrl_r()
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebasec_ctrl_r\n", machine().describe_context());
return m_timebasec_ctrl;
}
void gpl_timebase_device::timebasec_ctrl_w(u16 data)
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebasec_ctrl_w %04x\n", machine().describe_context(), data);
if (data & 0x8000)
{
m_timebasec_ctrl = data & 0x7fff;
m_updateirqs_cb(1);
}
else
{
m_timebasec_ctrl = data;
}
if ((m_timebasec_ctrl & 0x6000) == 0x6000)
{
switch (m_timebasec_ctrl & 0x0003)
{
case 0x00: m_timebase_c->adjust(attotime::from_hz(128)); break;
case 0x01: m_timebase_c->adjust(attotime::from_hz(256)); break;
case 0x02: m_timebase_c->adjust(attotime::from_hz(512)); break;
case 0x03: m_timebase_c->adjust(attotime::from_hz(1024)); break;
}
}
else
{
m_timebase_c->adjust(attotime::never);
}
}
void gpl_timebase_device::timebase_reset_w(u16 data)
{
LOGMASKED(LOG_TIMEBASE, "%s:sunplus_gcm394_base_device::timebase_reset_w %04x\n", machine().describe_context(), data);
m_timebase_reset = data;
}
void gpl_timebase_device::device_add_mconfig(machine_config &config)
{
TIMER(config, "timebase_a").configure_generic(FUNC(gpl_timebase_device::timebase_a_cb));
TIMER(config, "timebase_b").configure_generic(FUNC(gpl_timebase_device::timebase_b_cb));
TIMER(config, "timebase_c").configure_generic(FUNC(gpl_timebase_device::timebase_c_cb));
}
|