OXYGENHUB
◆ main openmsx / src / memory / RomColecoMegaCart.cc
1.7 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "RomColecoMegaCart.hh"
2
3
#include "CacheLine.hh"
4
#include "MSXException.hh"
5
#include "serialize.hh"
6
7
#include "one_of.hh"
8
9
// information source:
10
// https://github.com/openMSX/openMSX/files/2118720/MegaCart.FAQ.V1-2.pdf
11
12
namespace openmsx {
13
14
RomColecoMegaCart::RomColecoMegaCart(const DeviceConfig& config, Rom&& rom_)
15
	: Rom16kBBlocks(config, std::move(rom_))
16
{
17
	if (auto size = rom.size() / 1024;
18
	    size != one_of(128u, 256u, 512u, 1024u)) {
19
		throw MSXException(
20
			"MegaCart only supports ROMs of 128kB, 256kB, 512kB and 1024kB "
21
			"size and not of ", size, "kB.");
22
	}
23
	reset(EmuTime::dummy());
24
}
25
26
void RomColecoMegaCart::reset(EmuTime /*time*/)
27
{
28
	setUnmapped(0);
29
	setUnmapped(1);
30
	// The first 16K of the cartridge (CV 8000h-BFFFh) is fixed and will
31
	// always contain the highest/last 16K segment of the EPROM.
32
	setRom(2, unsigned(-1)); // select last block
33
	setRom(3, 0);
34
	invalidateDeviceRCache(0xFFC0 & CacheLine::HIGH, CacheLine::SIZE);
35
}
36
37
byte RomColecoMegaCart::readMem(uint16_t address, EmuTime time)
38
{
39
	// The last 64 locations will switch banks (FFC0-FFFF). If you have
40
	// fewer than 64 banks, then the strobe addresses simply repeat where
41
	// they end. If you have 16 banks, then bank 0 can be strobed at FFC0,
42
	// FFD0, FFE0, or FFF0.
43
	if (address >= 0xFFC0) {
44
		setRom(3, address); // mirroring is handled in superclass
45
		invalidateDeviceRCache(0xFFC0 & CacheLine::HIGH, CacheLine::SIZE);
46
	}
47
	return Rom16kBBlocks::readMem(address, time);
48
}
49
50
const byte* RomColecoMegaCart::getReadCacheLine(uint16_t start) const
51
{
52
	if (start >= (0xFFC0 & CacheLine::HIGH)) {
53
		return nullptr;
54
	} else {
55
		return Rom16kBBlocks::getReadCacheLine(start);
56
	}
57
}
58
59
REGISTER_MSXDEVICE(RomColecoMegaCart, "RomColecoMegaCart");
60
61
} // namespace openmsx