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
|
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/***************************************************************************
Slogger Click cartridge emulation
http://chrisacorns.computinghistory.org.uk/8bit_Upgrades/Slogger_Click.html
***************************************************************************/
#include "emu.h"
#include "click.h"
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
DEFINE_DEVICE_TYPE(ELECTRON_CLICK, electron_click_device, "electron_click", "Slogger Click (Electron) cartridge")
//-------------------------------------------------
// device_add_mconfig - add device configuration
//-------------------------------------------------
void electron_click_device::device_add_mconfig(machine_config &config)
{
/* rtc */
MC146818(config, m_rtc, 32.768_kHz_XTAL);
m_rtc->irq().set(DEVICE_SELF_OWNER, FUNC(electron_cartslot_device::irq_w));
}
//-------------------------------------------------
// INPUT_PORTS( click )
//-------------------------------------------------
INPUT_PORTS_START(click)
PORT_START("BUTTON")
PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("Click") PORT_CODE(KEYCODE_HOME) PORT_CHANGED_MEMBER(DEVICE_SELF, electron_click_device, click_button, 0)
INPUT_PORTS_END
//-------------------------------------------------
// input_ports - device-specific input ports
//-------------------------------------------------
ioport_constructor electron_click_device::device_input_ports() const
{
return INPUT_PORTS_NAME(click);
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// electron_click_device - constructor
//-------------------------------------------------
electron_click_device::electron_click_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
: device_t(mconfig, ELECTRON_CLICK, tag, owner, clock)
, device_electron_cart_interface(mconfig, *this)
, m_rtc(*this, "rtc")
, m_page_register(0)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void electron_click_device::device_start()
{
save_item(NAME(m_page_register));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void electron_click_device::device_reset()
{
m_page_register = 0;
}
//-------------------------------------------------
// read - cartridge data read
//-------------------------------------------------
uint8_t electron_click_device::read(offs_t offset, int infc, int infd, int romqa, int oe, int oe2)
{
uint8_t data = 0xff;
if (infc)
{
switch (offset & 0xff)
{
case 0xf8:
case 0xf9:
data = m_rtc->read(offset & 0x01);
break;
case 0xfc:
data = m_page_register;
break;
}
}
else if (oe)
{
offs_t rom_page_offset = (m_page_register & 0x03) * 0x2000;
offs_t ram_page_offset = ((m_page_register & 0x0c) >> 2) * 0x2000;
if (offset >= 0x0000 && offset < 0x2000)
{
data = m_rom[rom_page_offset + (offset & 0x1fff)];
}
else if (offset >= 0x2000 && offset < 0x4000)
{
data = m_nvram[ram_page_offset + (offset & 0x1fff)];
}
}
return data;
}
//-------------------------------------------------
// write - cartridge data write
//-------------------------------------------------
void electron_click_device::write(offs_t offset, uint8_t data, int infc, int infd, int romqa, int oe, int oe2)
{
if (infc)
{
switch (offset & 0xff)
{
case 0xf8:
case 0xf9:
m_rtc->write(offset & 0x01, data);
break;
case 0xfc:
m_page_register = data;
break;
}
}
else if (oe)
{
offs_t ram_page_offset = ((m_page_register & 0x0c) >> 2) * 0x2000;
if (offset >= 0x2000 && offset < 0x4000)
{
m_nvram[ram_page_offset + (offset & 0x1fff)] = data;
}
}
}
INPUT_CHANGED_MEMBER(electron_click_device::click_button)
{
if (newval && !oldval)
{
m_slot->irq_w(ASSERT_LINE);
}
else
{
m_slot->irq_w(CLEAR_LINE);
}
}
|