summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/msx/cart/superloderunner.cpp
blob: 30523be115a31cab801ff465b51fcf726fdb19af (plain) (blame)
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
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
#include "emu.h"
#include "superloderunner.h"

namespace {

class msx_cart_superloderunner_device : public device_t, public msx_cart_interface
{
public:
	msx_cart_superloderunner_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
		: device_t(mconfig, MSX_CART_SUPERLODERUNNER, tag, owner, clock)
		, msx_cart_interface(mconfig, *this)
		, m_rombank(*this, "rombank")
	{ }

	virtual std::error_condition initialize_cartridge(std::string &message) override;

protected:
	// device_t implementation
	virtual void device_start() override ATTR_COLD;

private:
	void bank_w(u8 data);

	memory_bank_creator m_rombank;
};

void msx_cart_superloderunner_device::device_start()
{
	// Install evil system wide memory write handler
	memory_space().install_write_handler(0x0000, 0x0000, emu::rw_delegate(*this, FUNC(msx_cart_superloderunner_device::bank_w)));
}

std::error_condition msx_cart_superloderunner_device::initialize_cartridge(std::string &message)
{
	if (!cart_rom_region())
	{
		message = "msx_cart_superloderunner_device: Required region 'rom' was not found.";
		return image_error::INTERNAL;
	}

	if (cart_rom_region()->bytes() != 0x20000)
	{
		message = "msx_cart_superloderunner_device: Region 'rom' has unsupported size.";
		return image_error::INVALIDLENGTH;
	}

	m_rombank->configure_entries(0, 8, cart_rom_region()->base(), 0x4000);

	page(2)->install_read_bank(0x8000, 0xbfff, m_rombank);

	return std::error_condition();
}

void msx_cart_superloderunner_device::bank_w(u8 data)
{
	m_rombank->set_entry(data & 0x07);
}

} // anonymous namespace

DEFINE_DEVICE_TYPE_PRIVATE(MSX_CART_SUPERLODERUNNER, msx_cart_interface, msx_cart_superloderunner_device, "msx_cart_superloderunner", "MSX Cartridge - Super Lode Runner")