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
|
// license:BSD-3-Clause
// copyright-holders:Sandro Ronco
/*****************************************************************************
SPG290 Timer
*****************************************************************************/
#include "emu.h"
#include "spg290_timer.h"
DEFINE_DEVICE_TYPE(SPG290_TIMER, spg290_timer_device, "spg290_timer", "SPG290 Timer")
spg290_timer_device::spg290_timer_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
: device_t(mconfig, SPG290_TIMER, tag, owner, clock)
, m_irq_cb(*this)
, m_enabled(false)
{
}
void spg290_timer_device::device_start()
{
m_irq_cb.resolve_safe();
m_tick_timer = timer_alloc(FUNC(spg290_timer_device::timer_update), this);
save_item(NAME(m_enabled));
save_item(NAME(m_control));
save_item(NAME(m_control2));
save_item(NAME(m_preload));
save_item(NAME(m_counter));
save_item(NAME(m_ccp));
save_item(NAME(m_upcount));
}
void spg290_timer_device::device_reset()
{
m_enabled = false;
m_control = 0;
m_control2 = 0;
m_preload = 0;
m_counter = 0;
m_ccp = 0;
m_upcount = 0;
m_tick_timer->adjust(attotime::never);
m_irq_cb(CLEAR_LINE);
}
void spg290_timer_device::device_clock_changed()
{
if (m_enabled)
m_tick_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock()));
else
m_tick_timer->adjust(attotime::never);
}
TIMER_CALLBACK_MEMBER(spg290_timer_device::timer_update)
{
if (!BIT(m_control, 31))
return;
switch ((m_control2 >> 30) & 0x03)
{
case 0: // Timer Mode
if (m_counter == 0xffff)
{
m_counter = m_preload & 0xffff;
if (BIT(m_control, 27))
{
m_control |= 0x04000000;
m_irq_cb(ASSERT_LINE);
}
}
else
m_counter++;
break;
case 1: // Capture Mode
fatalerror("[%s] %s: unemulated timer Capture Mode\n", tag(), machine().describe_context());
break;
case 2: // Comparison Mode
fatalerror("[%s] %s: unemulated timer Comparison Mode\n", tag(), machine().describe_context());
break;
case 3: // PWM Mode
fatalerror("[%s] %s: unemulated timer PWM Mode\n", tag(), machine().describe_context());
break;
}
}
void spg290_timer_device::control_w(uint32_t data)
{
bool enabled = data & 1;
if (m_enabled != enabled)
{
m_enabled = enabled;
spg290_timer_device::device_clock_changed();
}
if (data & 2)
m_counter = m_preload & 0xffff;
}
uint32_t spg290_timer_device::read(offs_t offset, uint32_t mem_mask)
{
switch (offset << 2)
{
case 0x00: // Control 1
return m_control;
case 0x04: // Control 2
return m_control2;
case 0x08: // Preload
return m_preload;
case 0x0c: // CCP
return m_ccp;
case 0x10: // Upcount
return m_upcount;
default:
logerror("[%s] %s: unknown read %x\n", tag(), machine().describe_context(), offset << 2);
}
return 0;
}
void spg290_timer_device::write(offs_t offset, uint32_t data, uint32_t mem_mask)
{
switch (offset << 2)
{
case 0x00: // Control 1
COMBINE_DATA(&m_control);
if (ACCESSING_BITS_24_31)
{
m_control &= ~(data & 0x04000000); // IRQ ack
if (!(m_control & 0x04000000))
m_irq_cb(CLEAR_LINE);
}
break;
case 0x04: // Control 2
COMBINE_DATA(&m_control2);
break;
case 0x08: // Preload
COMBINE_DATA(&m_preload);
break;
case 0x0c: // CCP
COMBINE_DATA(&m_ccp);
break;
case 0x10: // Upcount
COMBINE_DATA(&m_upcount);
break;
default:
logerror("[%s] %s: unknown write %x = %x\n", tag(), machine().describe_context(), offset << 2, data);
}
}
|