Skip to content

Commit fc9f61a

Browse files
committed
bus/bbc/1mhzbus/ramdisc: Fixed check that sector is within RAM size.
1 parent eda6c7b commit fc9f61a

File tree

2 files changed

+76
-103
lines changed

2 files changed

+76
-103
lines changed

src/devices/bus/bbc/1mhzbus/ramdisc.cpp

Lines changed: 72 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,57 @@
1010
1111
**********************************************************************/
1212

13-
1413
#include "emu.h"
1514
#include "ramdisc.h"
1615

16+
#include "machine/nvram.h"
1717

18-
//**************************************************************************
19-
// DEVICE DEFINITIONS
20-
//**************************************************************************
2118

22-
DEFINE_DEVICE_TYPE(BBC_RAMDISC, bbc_ramdisc_device, "bbc_ramdisc", "Morley Electronics RAM Disc");
19+
namespace {
20+
21+
class bbc_ramdisc_device: public device_t, public device_bbc_1mhzbus_interface
22+
{
23+
public:
24+
bbc_ramdisc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
25+
: device_t(mconfig, BBC_RAMDISC, tag, owner, clock)
26+
, device_bbc_1mhzbus_interface(mconfig, *this)
27+
, m_1mhzbus(*this, "1mhzbus")
28+
, m_nvram(*this, "nvram")
29+
, m_ram_size(*this, "SIZE")
30+
, m_power(*this, "POWER")
31+
, m_sector(0)
32+
{
33+
}
34+
35+
DECLARE_INPUT_CHANGED_MEMBER(power_changed);
36+
37+
protected:
38+
// device_t overrides
39+
virtual void device_start() override ATTR_COLD;
40+
41+
// optional information overrides
42+
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
43+
virtual ioport_constructor device_input_ports() const override ATTR_COLD;
44+
virtual const tiny_rom_entry *device_rom_region() const override ATTR_COLD;
45+
46+
virtual uint8_t fred_r(offs_t offset) override;
47+
virtual void fred_w(offs_t offset, uint8_t data) override;
48+
virtual uint8_t jim_r(offs_t offset) override;
49+
virtual void jim_w(offs_t offset, uint8_t data) override;
50+
51+
private:
52+
required_device<bbc_1mhzbus_slot_device> m_1mhzbus;
53+
required_device<nvram_device> m_nvram;
54+
required_ioport m_ram_size;
55+
required_ioport m_power;
56+
57+
std::unique_ptr<uint8_t[]> m_ram;
58+
uint16_t m_sector;
59+
};
2360

2461

2562
//-------------------------------------------------
26-
// INPUT_PORTS( ramdisc )
63+
// input_ports - device-specific input ports
2764
//-------------------------------------------------
2865

2966
static INPUT_PORTS_START(ramdisc)
@@ -37,77 +74,54 @@ static INPUT_PORTS_START(ramdisc)
3774
PORT_CONFSETTING(0x02, "2MB")
3875
INPUT_PORTS_END
3976

40-
//-------------------------------------------------
41-
// input_ports - device-specific input ports
42-
//-------------------------------------------------
43-
4477
ioport_constructor bbc_ramdisc_device::device_input_ports() const
4578
{
4679
return INPUT_PORTS_NAME(ramdisc);
4780
}
4881

82+
4983
//-------------------------------------------------
50-
// ROM( ramdisc )
84+
// rom_region - device-specific ROM region
5185
//-------------------------------------------------
5286

5387
ROM_START(ramdisc)
5488
ROM_REGION(0x4000, "exp_rom", 0)
5589
ROM_LOAD("ramdisc101.rom", 0x0000, 0x4000, CRC(627568c2) SHA1(17e727998756fe35ff451fd2ce1d4b5977be24fc))
5690
ROM_END
5791

92+
const tiny_rom_entry *bbc_ramdisc_device::device_rom_region() const
93+
{
94+
return ROM_NAME(ramdisc);
95+
}
96+
97+
5898
//-------------------------------------------------
5999
// device_add_mconfig - add device configuration
60100
//-------------------------------------------------
61101

62102
void bbc_ramdisc_device::device_add_mconfig(machine_config &config)
63103
{
64-
/* ram disk */
104+
// ram disk
65105
NVRAM(config, "nvram", nvram_device::DEFAULT_NONE);
66106

67107
BBC_1MHZBUS_SLOT(config, m_1mhzbus, DERIVED_CLOCK(1, 1), bbc_1mhzbus_devices, nullptr);
68108
m_1mhzbus->irq_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::irq_w));
69109
m_1mhzbus->nmi_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::nmi_w));
110+
//m_1mhzbus->add_route(ALL_OUTPUTS, DEVICE_SELF_OWNER, 1.0);
70111
}
71112

72-
//-------------------------------------------------
73-
// rom_region - device-specific ROM region
74-
//-------------------------------------------------
75-
76-
const tiny_rom_entry *bbc_ramdisc_device::device_rom_region() const
77-
{
78-
return ROM_NAME(ramdisc);
79-
}
80-
81-
//**************************************************************************
82-
// LIVE DEVICE
83-
//**************************************************************************
84-
85-
//-------------------------------------------------
86-
// bbc_ramdisc_device - constructor
87-
//-------------------------------------------------
88-
89-
bbc_ramdisc_device::bbc_ramdisc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
90-
: device_t(mconfig, BBC_RAMDISC, tag, owner, clock)
91-
, device_bbc_1mhzbus_interface(mconfig, *this)
92-
, m_1mhzbus(*this, "1mhzbus")
93-
, m_nvram(*this, "nvram")
94-
, m_ram_size(*this, "SIZE")
95-
, m_power(*this, "POWER")
96-
, m_sector(0)
97-
{
98-
}
99113

100114
//-------------------------------------------------
101115
// device_start - device-specific startup
102116
//-------------------------------------------------
103117

104118
void bbc_ramdisc_device::device_start()
105119
{
106-
/* define 2mb ram */
120+
// define 2mb ram
107121
m_ram = std::make_unique<uint8_t[]>(0x200000);
108122
m_nvram->set_base(m_ram.get(), 0x200000);
109123

110-
/* register for save states */
124+
// register for save states
111125
save_pointer(NAME(m_ram), 0x200000);
112126
save_item(NAME(m_sector));
113127
}
@@ -119,7 +133,7 @@ void bbc_ramdisc_device::device_start()
119133

120134
INPUT_CHANGED_MEMBER(bbc_ramdisc_device::power_changed)
121135
{
122-
/* clear RAM on power off */
136+
// clear RAM on power off
123137
if (!newval)
124138
{
125139
memset(m_ram.get(), 0xff, 0x200000);
@@ -135,17 +149,17 @@ uint8_t bbc_ramdisc_device::fred_r(offs_t offset)
135149
switch (offset)
136150
{
137151
case 0xc0:
138-
/* sector LSB */
152+
// sector LSB
139153
data = m_sector & 0x00ff;
140154
break;
141155
case 0xc2:
142-
/* sector MSB */
156+
// sector MSB
143157
data = (m_sector & 0xff00) >> 8;
144158
break;
145159
case 0xc1:
146160
case 0xc3:
147-
/* TODO: unknown purpose, must return 0x3f or 0x5f */
148-
data = 0x3f;
161+
// TODO: unknown purpose, must return 0x3f or 0x5f
162+
data = 0x1f | (m_ram_size->read() << 5);
149163
logerror("Read %04x -> %02x\n", offset | 0xfcc0, data);
150164
break;
151165
}
@@ -163,16 +177,16 @@ void bbc_ramdisc_device::fred_w(offs_t offset, uint8_t data)
163177
switch (offset)
164178
{
165179
case 0xc0:
166-
/* sector LSB */
180+
// sector LSB
167181
m_sector = (m_sector & 0xff00) | data;
168182
break;
169183
case 0xc2:
170-
/* sector MSB */
184+
// sector MSB
171185
m_sector = (m_sector & 0x00ff) | (data << 8);
172186
break;
173187
case 0xc1:
174188
case 0xc3:
175-
/* TODO: unknown purpose, always writes 0x00 or 0xff */
189+
// TODO: unknown purpose, always writes 0x00 or 0xff
176190
logerror("Write %04x <- %02x\n", offset | 0xfcc0, data);
177191
break;
178192
}
@@ -185,8 +199,8 @@ uint8_t bbc_ramdisc_device::jim_r(offs_t offset)
185199
{
186200
uint8_t data = 0xff;
187201

188-
/* power on and sector < 2mb */
189-
if (m_power->read() && m_sector < (m_ram_size->read() << 8))
202+
// power on and sector < 2mb
203+
if (m_power->read() && m_sector < (m_ram_size->read() << 12))
190204
{
191205
data &= m_ram[(m_sector << 8) | offset];
192206
}
@@ -198,11 +212,16 @@ uint8_t bbc_ramdisc_device::jim_r(offs_t offset)
198212

199213
void bbc_ramdisc_device::jim_w(offs_t offset, uint8_t data)
200214
{
201-
/* power on and sector < 2mb */
202-
if (m_power->read() && m_sector < (m_ram_size->read() << 8))
215+
// power on and sector < 2mb
216+
if (m_power->read() && m_sector < (m_ram_size->read() << 12))
203217
{
204218
m_ram[(m_sector << 8) | offset] = data;
205219
}
206220

207221
m_1mhzbus->jim_w(offset, data);
208222
}
223+
224+
} // anonymous namespace
225+
226+
227+
DEFINE_DEVICE_TYPE_PRIVATE(BBC_RAMDISC, device_bbc_1mhzbus_interface, bbc_ramdisc_device, "bbc_ramdisc", "Morley Electronics RAM Disc");

src/devices/bus/bbc/1mhzbus/ramdisc.h

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,13 @@
11
// license:BSD-3-Clause
22
// copyright-holders:Nigel Barnes
3-
/**********************************************************************
4-
5-
Morley Electronics RAM Disc
6-
7-
**********************************************************************/
8-
9-
103
#ifndef MAME_BUS_BBC_1MHZBUS_RAMDISC_H
114
#define MAME_BUS_BBC_1MHZBUS_RAMDISC_H
125

13-
#include "1mhzbus.h"
14-
#include "machine/nvram.h"
15-
16-
//**************************************************************************
17-
// TYPE DEFINITIONS
18-
//**************************************************************************
19-
20-
class bbc_ramdisc_device:
21-
public device_t,
22-
public device_bbc_1mhzbus_interface
23-
{
24-
public:
25-
// construction/destruction
26-
bbc_ramdisc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
27-
28-
DECLARE_INPUT_CHANGED_MEMBER(power_changed);
29-
30-
protected:
31-
// device-level overrides
32-
virtual void device_start() override ATTR_COLD;
33-
34-
// optional information overrides
35-
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
36-
virtual ioport_constructor device_input_ports() const override ATTR_COLD;
37-
virtual const tiny_rom_entry *device_rom_region() const override ATTR_COLD;
38-
39-
virtual uint8_t fred_r(offs_t offset) override;
40-
virtual void fred_w(offs_t offset, uint8_t data) override;
41-
virtual uint8_t jim_r(offs_t offset) override;
42-
virtual void jim_w(offs_t offset, uint8_t data) override;
43-
44-
private:
45-
required_device<bbc_1mhzbus_slot_device> m_1mhzbus;
46-
required_device<nvram_device> m_nvram;
47-
required_ioport m_ram_size;
48-
required_ioport m_power;
49-
50-
std::unique_ptr<uint8_t[]> m_ram;
51-
uint16_t m_sector;
52-
};
6+
#pragma once
537

8+
#include "1mhzbus.h"
549

55-
// device type definition
56-
DECLARE_DEVICE_TYPE(BBC_RAMDISC, bbc_ramdisc_device);
5710

11+
DECLARE_DEVICE_TYPE(BBC_RAMDISC, device_bbc_1mhzbus_interface);
5812

59-
#endif /* MAME_BUS_BBC_1MHZBUS_RAMDISC_H */
13+
#endif // MAME_BUS_BBC_1MHZBUS_RAMDISC_H

0 commit comments

Comments
 (0)