summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/gamate/rom.cpp
blob: 7301b6bdfc78c532a1c5a1d2ce64131c0254407a (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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// license:BSD-3-Clause
// copyright-holders:David Haywood

// this assumes that the regular banked carts don't also have the 4-in-1 logic.

#include "emu.h"
#include "rom.h"

//-------------------------------------------------
//  gamate_rom_device - constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(GAMATE_ROM_PLAIN,         gamate_rom_plain_device,       "gamate_rom_plain",        "GAMATE Cartridge")
DEFINE_DEVICE_TYPE(GAMATE_ROM_BANKED,        gamate_rom_banked_device,      "gamate_rom_banked",       "GAMATE Cartridge with banking")
DEFINE_DEVICE_TYPE(GAMATE_ROM_4IN1,          gamate_rom_4in1_device,        "gamate_rom_4in1",         "GAMATE 4-in-1 Cartridge")


gamate_rom_plain_device::gamate_rom_plain_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_gamate_cart_interface(mconfig, *this),
	m_protection(*this, "protection")
{
}

gamate_rom_plain_device::gamate_rom_plain_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	gamate_rom_plain_device(mconfig, GAMATE_ROM_PLAIN, tag, owner, clock)
{
}

gamate_rom_banked_device::gamate_rom_banked_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	gamate_rom_plain_device(mconfig, GAMATE_ROM_BANKED, tag, owner, clock),
	m_bank(0)
{
}

gamate_rom_banked_device::gamate_rom_banked_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
	gamate_rom_plain_device(mconfig, type, tag, owner, clock),
	m_bank(0)
{
}


gamate_rom_4in1_device::gamate_rom_4in1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	gamate_rom_banked_device(mconfig, GAMATE_ROM_4IN1, tag, owner, clock),
	m_multibank(0)
{
}

//-------------------------------------------------
//  mapper specific start/reset
//-------------------------------------------------

void gamate_rom_banked_device::device_start()
{
	save_item(NAME(m_bank));
}

void gamate_rom_4in1_device::device_start()
{
	gamate_rom_banked_device::device_start();
	save_item(NAME(m_multibank));
}


void gamate_rom_banked_device::device_reset()
{
	m_bank = 0;
}

void gamate_rom_4in1_device::device_reset()
{
	gamate_rom_banked_device::device_reset();
	m_multibank = 0;
}

/*-------------------------------------------------
 mapper specific handlers
 -------------------------------------------------*/


uint8_t gamate_rom_plain_device::read_cart(offs_t offset)
{
	if (m_protection->is_protection_passed())
	{
		return read_rom(offset);
	}
	else
	{
		return m_protection->prot_r() << 1;
	}

	return 0xff;
}

uint8_t gamate_rom_plain_device::read_rom(offs_t offset)
{
	return m_rom[offset & (m_rom_size-1)];
}

uint8_t gamate_rom_banked_device::read_rom(offs_t offset)
{
	if (offset < 0x4000)
	{
		return m_rom[offset & (m_rom_size - 1)];
	}
	else
	{
		return m_rom[((m_bank * 0x4000) + (offset & 0x3fff)) & (m_rom_size - 1)];
	}

	return 0xff;
}

uint8_t gamate_rom_4in1_device::read_rom(offs_t offset)
{
	if (offset < 0x4000)
	{
		return m_rom[((m_multibank * 0x4000) + (offset & 0x3fff)) & (m_rom_size - 1)];
	}
	else
	{
		return m_rom[((m_bank * 0x4000) + (offset & 0x3fff)) & (m_rom_size - 1)];
	}
}

void gamate_rom_plain_device::write_cart(offs_t offset, uint8_t data)
{
	if (m_protection->is_protection_passed())
	{
		write_rom(offset, data);
	}
	else
	{
		m_protection->prot_w((data & 0x04) >> 2);
	}
}

void gamate_rom_plain_device::write_rom(offs_t offset, uint8_t data)
{
	// shouldn't be any write on an unbanked game
	logerror("gamate_rom_plain_device::write_rom %04x %02x\n", offset, data);
}

void gamate_rom_banked_device::write_rom(offs_t offset, uint8_t data)
{
	if (offset == 0x6000)
	{
		m_bank = data;
	}
	else
	{
		logerror("gamate_rom_banked_device::write_rom %04x %02x\n", offset, data);
	}
}

void gamate_rom_4in1_device::write_rom(offs_t offset, uint8_t data)
{
	if (offset == 0x2000)
	{
		m_multibank = data;
	}
	else if (offset == 0x6000)
	{
		m_bank = data;
	}
	else
	{
		logerror("gamate_rom_4in1_device::write_rom %04x %02x\n", offset, data);
	}
}

void gamate_rom_plain_device::device_add_mconfig(machine_config &config)
{
	GAMATE_PROT(config, m_protection, 0);
}


/*-------------------------------------------------
 slot interface
 -------------------------------------------------*/

void gamate_cart(device_slot_interface &device)
{
	device.option_add_internal("plain",       GAMATE_ROM_PLAIN);
	device.option_add_internal("banked",      GAMATE_ROM_BANKED);
	device.option_add_internal("4in1",        GAMATE_ROM_4IN1);
}