OXYGENHUB
◆ main openmsx / src / memory / RomPlayBall.cc
1.8 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "RomPlayBall.hh"
2
3
#include "CacheLine.hh"
4
#include "FileOperations.hh"
5
#include "serialize.hh"
6
7
namespace openmsx {
8
9
RomPlayBall::RomPlayBall(const DeviceConfig& config, Rom&& rom_)
10
	: Rom16kBBlocks(config, std::move(rom_))
11
	, samplePlayer(
12
		"Playball-DAC", "Sony Playball's DAC", config,
13
		strCat(FileOperations::stripExtension(rom.getFilename()), '_'),
14
		15, "playball/playball_")
15
{
16
	setUnmapped(0);
17
	setRom(1, 0);
18
	setRom(2, 1);
19
	invalidateDeviceRCache(0xBFFF & CacheLine::HIGH, CacheLine::SIZE);
20
	setUnmapped(3);
21
22
	reset(EmuTime::dummy());
23
}
24
25
void RomPlayBall::reset(EmuTime /*time*/)
26
{
27
	samplePlayer.reset();
28
}
29
30
byte RomPlayBall::peekMem(uint16_t address, EmuTime time) const
31
{
32
	if (address == 0xBFFF) {
33
		return samplePlayer.isPlaying() ? 0xFE : 0xFF;
34
	} else {
35
		return Rom16kBBlocks::peekMem(address, time);
36
	}
37
}
38
39
byte RomPlayBall::readMem(uint16_t address, EmuTime time)
40
{
41
	return RomPlayBall::peekMem(address, time);
42
}
43
44
const byte* RomPlayBall::getReadCacheLine(uint16_t address) const
45
{
46
	if ((address & CacheLine::HIGH) == (0xBFFF & CacheLine::HIGH)) {
47
		return nullptr;
48
	} else {
49
		return Rom16kBBlocks::getReadCacheLine(address);
50
	}
51
}
52
53
void RomPlayBall::writeMem(uint16_t address, byte value, EmuTime /*time*/)
54
{
55
	if (address == 0xBFFF) {
56
		if ((value <= 14) && !samplePlayer.isPlaying()) {
57
			samplePlayer.play(value);
58
		}
59
	}
60
}
61
62
byte* RomPlayBall::getWriteCacheLine(uint16_t address)
63
{
64
	if ((address & CacheLine::HIGH) == (0xBFFF & CacheLine::HIGH)) {
65
		return nullptr;
66
	} else {
67
		return unmappedWrite.data();
68
	}
69
}
70
71
template<typename Archive>
72
void RomPlayBall::serialize(Archive& ar, unsigned /*version*/)
73
{
74
	ar.template serializeBase<Rom16kBBlocks>(*this);
75
	ar.serialize("SamplePlayer", samplePlayer);
76
}
77
INSTANTIATE_SERIALIZE_METHODS(RomPlayBall);
78
REGISTER_MSXDEVICE(RomPlayBall, "RomPlayBall");
79
80
} // namespace openmsx