summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/odyssey2/rom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/bus/odyssey2/rom.cpp')
-rw-r--r--src/devices/bus/odyssey2/rom.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/devices/bus/odyssey2/rom.cpp b/src/devices/bus/odyssey2/rom.cpp
index 12f8fa9b128..9dcdc480842 100644
--- a/src/devices/bus/odyssey2/rom.cpp
+++ b/src/devices/bus/odyssey2/rom.cpp
@@ -9,13 +9,32 @@ Standard cartridges emulation, optionally bankswitched up to 8KB.
#include "emu.h"
#include "rom.h"
-DEFINE_DEVICE_TYPE(O2_ROM_STD, o2_rom_device, "o2_rom", "Odyssey 2 Standard Carts")
-
+namespace {
//-------------------------------------------------
-// o2_rom_device - constructor
+// initialization
//-------------------------------------------------
+class o2_rom_device : public device_t, public device_o2_cart_interface
+{
+public:
+ o2_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
+
+protected:
+ virtual void device_start() override;
+
+ virtual void cart_init() override;
+
+ virtual u8 read_rom04(offs_t offset) override;
+ virtual u8 read_rom0c(offs_t offset) override { return read_rom04(offset + 0x400); }
+
+ virtual void write_p1(u8 data) override { m_bank = data & 3; }
+
+private:
+ u32 m_cart_mask = 0;
+ u8 m_bank = 0;
+};
+
o2_rom_device::o2_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
device_t(mconfig, O2_ROM_STD, tag, owner, clock),
device_o2_cart_interface(mconfig, *this)
@@ -28,7 +47,7 @@ void o2_rom_device::device_start()
void o2_rom_device::cart_init()
{
- m_cart_mask = (1 << (31 - count_leading_zeros(m_rom.bytes()))) - 1;
+ m_cart_mask = (1 << (31 - count_leading_zeros_32(m_rom_size))) - 1;
}
@@ -39,5 +58,10 @@ void o2_rom_device::cart_init()
u8 o2_rom_device::read_rom04(offs_t offset)
{
offset = (offset + m_bank * 0x800) & m_cart_mask;
- return (offset < m_rom.bytes()) ? m_rom[offset] : 0xff;
+ return (offset < m_rom_size) ? m_rom[offset] : 0xff;
}
+
+} // anonymous namespace
+
+
+DEFINE_DEVICE_TYPE_PRIVATE(O2_ROM_STD, device_o2_cart_interface, o2_rom_device, "o2_rom", "Odyssey 2 Standard Cartridge")