untangle bus/odyssey2/rom.cpp

This commit is contained in:
hap 2020-08-12 00:20:49 +02:00
parent 9baaf19580
commit 19f596c3ad
16 changed files with 166 additions and 143 deletions

View File

@ -1851,7 +1851,7 @@ The C7010 Chess Module had a NSC800 CMOS microprocessor, with 2K RAM and 8K ROM.
<publisher>&lt;homebrew&gt;</publisher>
<info name="programmer" value="Soeren Gust" />
<part name="cart" interface="odyssey_cart">
<feature name="slot" value="o2_rom12" />
<feature name="slot" value="o2_ktaa" />
<dataarea name="rom" size="12288">
<rom name="ktaa.bin" size="12288" crc="4e2cc6d3" sha1="42ad0c57bd16b7f24c242f60b5c0e9988d8dfba8" offset="0" />
</dataarea>

View File

@ -1694,10 +1694,12 @@ if (BUSES["O2"]~=null) then
MAME_DIR .. "src/devices/bus/odyssey2/rom.h",
MAME_DIR .. "src/devices/bus/odyssey2/4in1.cpp",
MAME_DIR .. "src/devices/bus/odyssey2/4in1.h",
MAME_DIR .. "src/devices/bus/odyssey2/rally.cpp",
MAME_DIR .. "src/devices/bus/odyssey2/rally.h",
MAME_DIR .. "src/devices/bus/odyssey2/chess.cpp",
MAME_DIR .. "src/devices/bus/odyssey2/chess.h",
MAME_DIR .. "src/devices/bus/odyssey2/ktaa.cpp",
MAME_DIR .. "src/devices/bus/odyssey2/ktaa.h",
MAME_DIR .. "src/devices/bus/odyssey2/rally.cpp",
MAME_DIR .. "src/devices/bus/odyssey2/rally.h",
MAME_DIR .. "src/devices/bus/odyssey2/voice.cpp",
MAME_DIR .. "src/devices/bus/odyssey2/voice.h",
}

View File

@ -23,7 +23,8 @@ DEFINE_DEVICE_TYPE(O2_ROM_4IN1, o2_4in1_device, "o2_4in1", "Odyssey 2 Videopac 4
//-------------------------------------------------
o2_4in1_device::o2_4in1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
o2_rom_device(mconfig, O2_ROM_4IN1, tag, owner, clock)
device_t(mconfig, O2_ROM_4IN1, tag, owner, clock),
device_o2_cart_interface(mconfig, *this)
{ }
void o2_4in1_device::device_start()
@ -35,7 +36,7 @@ void o2_4in1_device::device_start()
void o2_4in1_device::cart_init()
{
if (m_rom_size != 0x1000)
fatalerror("o2_4in1_device: ROM size must be 4096\n");
fatalerror("o2_4in1_device: ROM size must be 4KB\n");
}

View File

@ -12,12 +12,12 @@
#pragma once
#include "slot.h"
#include "rom.h"
// ======================> o2_4in1_device
class o2_4in1_device : public o2_rom_device
class o2_4in1_device : public device_t,
public device_o2_cart_interface
{
public:
// construction/destruction

View File

@ -24,7 +24,8 @@ DEFINE_DEVICE_TYPE(O2_ROM_CHESS, o2_chess_device, "o2_chess", "Odyssey 2 Videopa
//-------------------------------------------------
o2_chess_device::o2_chess_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
o2_rom_device(mconfig, O2_ROM_CHESS, tag, owner, clock),
device_t(mconfig, O2_ROM_CHESS, tag, owner, clock),
device_o2_cart_interface(mconfig, *this),
m_cpu(*this, "subcpu"),
m_latch(*this, "latch%u", 0)
{ }

View File

@ -12,14 +12,14 @@
#pragma once
#include "slot.h"
#include "rom.h"
#include "cpu/z80/z80.h"
#include "machine/gen_latch.h"
// ======================> o2_chess_device
class o2_chess_device : public o2_rom_device
class o2_chess_device : public device_t,
public device_o2_cart_interface
{
public:
// construction/destruction

View File

@ -0,0 +1,52 @@
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol, Fabio Priuli, hap
/******************************************************************************
Homebrew KTAA(Kill the Attacking Aliens) cartridge emulation
Bankswitched ROM with page size of 3KB.
******************************************************************************/
#include "emu.h"
#include "ktaa.h"
DEFINE_DEVICE_TYPE(O2_ROM_KTAA, o2_ktaa_device, "o2_ktaa", "Odyssey 2 Homebrew KTAA")
//-------------------------------------------------
// o2_ktaa_device - constructor
//-------------------------------------------------
o2_ktaa_device::o2_ktaa_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, O2_ROM_KTAA, tag, owner, clock),
device_o2_cart_interface(mconfig, *this)
{ }
void o2_ktaa_device::device_start()
{
save_item(NAME(m_bank));
}
void o2_ktaa_device::cart_init()
{
if (m_rom_size != 0xc00 && m_rom_size != 0xc00*2 && m_rom_size != 0xc00*4)
fatalerror("o2_ktaa_device: ROM size must be multiple of 3KB\n");
m_bank_mask = (m_rom_size / 0xc00) - 1;
}
//-------------------------------------------------
// mapper specific handlers
//-------------------------------------------------
u8 o2_ktaa_device::read_rom04(offs_t offset)
{
return m_rom[offset + m_bank * 0xc00];
}
u8 o2_ktaa_device::read_rom0c(offs_t offset)
{
return m_rom[offset + 0x800 + m_bank * 0xc00];
}

View File

@ -0,0 +1,45 @@
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol, Fabio Priuli, hap
/**********************************************************************
Homebrew KTAA cartridge emulation
**********************************************************************/
#ifndef MAME_BUS_ODYSSEY2_KTAA_H
#define MAME_BUS_ODYSSEY2_KTAA_H
#pragma once
#include "slot.h"
// ======================> o2_ktaa_device
class o2_ktaa_device : public device_t,
public device_o2_cart_interface
{
public:
// construction/destruction
o2_ktaa_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
protected:
// device-level overrides
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;
virtual void write_p1(u8 data) override { m_bank = data & m_bank_mask; }
private:
u8 m_bank_mask = 0;
u8 m_bank = 0;
};
// device type definition
DECLARE_DEVICE_TYPE(O2_ROM_KTAA, o2_ktaa_device)
#endif // MAME_BUS_ODYSSEY2_KTAA_H

View File

@ -25,7 +25,8 @@ DEFINE_DEVICE_TYPE(O2_ROM_RALLY, o2_rally_device, "o2_rally", "Odyssey 2 Videopa
//-------------------------------------------------
o2_rally_device::o2_rally_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
o2_rom_device(mconfig, O2_ROM_RALLY, tag, owner, clock)
device_t(mconfig, O2_ROM_RALLY, tag, owner, clock),
device_o2_cart_interface(mconfig, *this)
{ }
void o2_rally_device::device_start()

View File

@ -12,12 +12,12 @@
#pragma once
#include "slot.h"
#include "rom.h"
// ======================> o2_rally_device
class o2_rally_device : public o2_rom_device
class o2_rally_device : public device_t,
public device_o2_cart_interface
{
public:
// construction/destruction

View File

@ -1,87 +1,43 @@
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol, Fabio Priuli
/***********************************************************************************************************
// copyright-holders:Wilbert Pol, Fabio Priuli, hap
/******************************************************************************
Standard cartridges emulation, optionally bankswitched up to 8KB.
Magnavox Odyssey cart emulation
***********************************************************************************************************/
******************************************************************************/
#include "emu.h"
#include "rom.h"
DEFINE_DEVICE_TYPE(O2_ROM_STD, o2_rom_device, "o2_rom", "Odyssey 2 Standard Carts")
//-------------------------------------------------
// o2_rom_device - constructor
//-------------------------------------------------
DEFINE_DEVICE_TYPE(O2_ROM_STD, o2_rom_device, "o2_rom", "Odyssey 2 Standard Carts")
DEFINE_DEVICE_TYPE(O2_ROM_12K, o2_rom12_device, "o2_rom12", "Odyssey 2 12K Carts")
DEFINE_DEVICE_TYPE(O2_ROM_16K, o2_rom16_device, "o2_rom16", "Odyssey 2 16K Carts")
o2_rom_device::o2_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, type, tag, owner, clock)
, device_o2_cart_interface(mconfig, *this)
, m_bank_base(0)
{
}
o2_rom_device::o2_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: o2_rom_device(mconfig, O2_ROM_STD, tag, owner, clock)
{
}
o2_rom12_device::o2_rom12_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: o2_rom_device(mconfig, O2_ROM_12K, tag, owner, clock)
{
}
o2_rom16_device::o2_rom16_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: o2_rom_device(mconfig, O2_ROM_16K, tag, owner, clock)
{
}
//-------------------------------------------------
// device_start/device_reset - device-specific startup
//-------------------------------------------------
o2_rom_device::o2_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, O2_ROM_STD, tag, owner, clock),
device_o2_cart_interface(mconfig, *this)
{ }
void o2_rom_device::device_start()
{
save_item(NAME(m_bank_base));
save_item(NAME(m_bank));
}
void o2_rom_device::cart_init()
{
m_cart_mask = (1 << (31 - count_leading_zeros(m_rom_size))) - 1;
}
/*-------------------------------------------------
mapper specific handlers
-------------------------------------------------*/
//-------------------------------------------------
// mapper specific handlers
//-------------------------------------------------
uint8_t o2_rom_device::read_rom04(offs_t offset)
u8 o2_rom_device::read_rom04(offs_t offset)
{
return m_rom[(offset + (m_bank_base & 0x03) * 0x800) & (m_rom_size - 1)];
}
uint8_t o2_rom_device::read_rom0c(offs_t offset)
{
return m_rom[(offset + (m_bank_base & 0x03) * 0x800) & (m_rom_size - 1)];
}
uint8_t o2_rom12_device::read_rom04(offs_t offset)
{
return m_rom[offset + (m_bank_base & 0x03) * 0xc00];
}
uint8_t o2_rom12_device::read_rom0c(offs_t offset)
{
return m_rom[offset + 0x800 + (m_bank_base & 0x03) * 0xc00];
}
uint8_t o2_rom16_device::read_rom04(offs_t offset)
{
return m_rom[offset + 0x400 + (m_bank_base & 0x03) * 0x1000];
}
uint8_t o2_rom16_device::read_rom0c(offs_t offset)
{
return m_rom[offset + 0xc00 + (m_bank_base & 0x03) * 0x1000];
offset = (offset + m_bank * 0x800) & m_cart_mask;
return (offset < m_rom_size) ? m_rom[offset] : 0xff;
}

View File

@ -1,5 +1,11 @@
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol, Fabio Priuli
// copyright-holders:Wilbert Pol, Fabio Priuli, hap
/**********************************************************************
Standard cartridges emulation
**********************************************************************/
#ifndef MAME_BUS_ODYSSEY2_ROM_H
#define MAME_BUS_ODYSSEY2_ROM_H
@ -17,51 +23,23 @@ public:
// construction/destruction
o2_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// reading and writing
virtual uint8_t read_rom04(offs_t offset) override;
virtual uint8_t read_rom0c(offs_t offset) override;
virtual void write_p1(uint8_t data) override { m_bank_base = data & 3; }
protected:
o2_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
// device-level overrides
virtual void device_start() override;
int m_bank_base;
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); }
virtual void write_p1(u8 data) override { m_bank = data & 3; }
private:
u32 m_cart_mask = 0;
u8 m_bank = 0;
};
// ======================> o2_rom12_device
class o2_rom12_device : public o2_rom_device
{
public:
// construction/destruction
o2_rom12_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// reading and writing
virtual uint8_t read_rom04(offs_t offset) override;
virtual uint8_t read_rom0c(offs_t offset) override;
};
// ======================> o2_rom16_device
class o2_rom16_device : public o2_rom_device
{
public:
// construction/destruction
o2_rom16_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// reading and writing
virtual uint8_t read_rom04(offs_t offset) override;
virtual uint8_t read_rom0c(offs_t offset) override;
};
// device type definition
DECLARE_DEVICE_TYPE(O2_ROM_STD, o2_rom_device)
DECLARE_DEVICE_TYPE(O2_ROM_12K, o2_rom12_device)
DECLARE_DEVICE_TYPE(O2_ROM_16K, o2_rom16_device)
#endif // MAME_BUS_ODYSSEY2_ROM_H

View File

@ -114,10 +114,9 @@ struct o2_slot
static const o2_slot slot_list[] =
{
{ O2_STD, "o2_rom" },
{ O2_ROM12, "o2_rom12" },
{ O2_ROM16, "o2_rom16" },
{ O2_4IN1, "o2_4in1" },
{ O2_RALLY, "o2_rally" },
{ O2_KTAA, "o2_ktaa" },
{ O2_CHESS, "o2_chess" },
{ O2_VOICE, "o2_voice" }
};
@ -161,20 +160,14 @@ image_init_result o2_cart_slot_device::call_load()
else
memcpy(m_cart->get_rom_base(), get_software_region("rom"), size);
if (!loaded_through_softlist())
{
m_type = O2_STD;
if (size == 12288)
m_type = O2_ROM12;
if (size == 16384)
m_type = O2_ROM16;
}
else
if (loaded_through_softlist())
{
const char *pcb_name = get_feature("slot");
if (pcb_name)
m_type = o2_get_pcb_id(pcb_name);
}
else
m_type = (size == 16384) ? O2_RALLY : O2_STD;
m_cart->cart_init();
@ -195,13 +188,7 @@ std::string o2_cart_slot_device::get_default_card_software(get_default_card_soft
{
const char *slot_string;
uint32_t size = hook.image_file()->size();
int type = O2_STD;
if (size == 12288)
type = O2_ROM12;
if (size == 16384)
type = O2_ROM16;
int type = (size == 16384) ? O2_RALLY : O2_STD;
slot_string = o2_get_slot(type);
//printf("type: %s\n", slot_string);
@ -254,16 +241,16 @@ uint8_t o2_cart_slot_device::io_read(offs_t offset)
#include "bus/odyssey2/rom.h"
#include "bus/odyssey2/4in1.h"
#include "bus/odyssey2/rally.h"
#include "bus/odyssey2/ktaa.h"
#include "bus/odyssey2/chess.h"
#include "bus/odyssey2/voice.h"
void o2_cart(device_slot_interface &device)
{
device.option_add_internal("o2_rom", O2_ROM_STD);
device.option_add_internal("o2_rom12", O2_ROM_12K);
device.option_add_internal("o2_rom16", O2_ROM_16K);
device.option_add_internal("o2_4in1", O2_ROM_4IN1);
device.option_add_internal("o2_rally", O2_ROM_RALLY);
device.option_add_internal("o2_ktaa", O2_ROM_KTAA);
device.option_add_internal("o2_chess", O2_ROM_CHESS);
device.option_add_internal("o2_voice", O2_ROM_VOICE);
}

View File

@ -17,10 +17,9 @@
enum
{
O2_STD = 0,
O2_ROM12,
O2_ROM16,
O2_4IN1,
O2_RALLY,
O2_KTAA,
O2_CHESS,
O2_VOICE
};

View File

@ -21,7 +21,8 @@ DEFINE_DEVICE_TYPE(O2_ROM_VOICE, o2_voice_device, "o2_voice", "Odyssey 2 The Voi
//-------------------------------------------------
o2_voice_device::o2_voice_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
o2_rom_device(mconfig, O2_ROM_VOICE, tag, owner, clock),
device_t(mconfig, O2_ROM_VOICE, tag, owner, clock),
device_o2_cart_interface(mconfig, *this),
m_speech(*this, "sp0256_speech"),
m_subslot(*this, "subslot")
{ }

View File

@ -12,13 +12,13 @@
#pragma once
#include "slot.h"
#include "rom.h"
#include "sound/sp0256.h"
// ======================> o2_voice_device
class o2_voice_device : public o2_rom_device
class o2_voice_device : public device_t,
public device_o2_cart_interface
{
public:
// construction/destruction