openMSX
RomPlayBall.cc
Go to the documentation of this file.
1#include "RomPlayBall.hh"
2#include "CacheLine.hh"
3#include "FileOperations.hh"
4#include "serialize.hh"
5
6namespace openmsx {
7
9 : Rom16kBBlocks(config, std::move(rom_))
10 , samplePlayer(
11 "Playball-DAC", "Sony Playball's DAC", config,
12 strCat(FileOperations::stripExtension(rom.getFilename()), '_'),
13 15, "playball/playball_")
14{
15 setUnmapped(0);
16 setRom(1, 0);
17 setRom(2, 1);
19 setUnmapped(3);
20
21 reset(EmuTime::dummy());
22}
23
24void RomPlayBall::reset(EmuTime::param /*time*/)
25{
26 samplePlayer.reset();
27}
28
29byte RomPlayBall::peekMem(word address, EmuTime::param time) const
30{
31 if (address == 0xBFFF) {
32 return samplePlayer.isPlaying() ? 0xFE : 0xFF;
33 } else {
34 return Rom16kBBlocks::peekMem(address, time);
35 }
36}
37
38byte RomPlayBall::readMem(word address, EmuTime::param time)
39{
40 return RomPlayBall::peekMem(address, time);
41}
42
43const byte* RomPlayBall::getReadCacheLine(word address) const
44{
45 if ((address & CacheLine::HIGH) == (0xBFFF & CacheLine::HIGH)) {
46 return nullptr;
47 } else {
48 return Rom16kBBlocks::getReadCacheLine(address);
49 }
50}
51
52void RomPlayBall::writeMem(word address, byte value, EmuTime::param /*time*/)
53{
54 if (address == 0xBFFF) {
55 if ((value <= 14) && !samplePlayer.isPlaying()) {
56 samplePlayer.play(value);
57 }
58 }
59}
60
62{
63 if ((address & CacheLine::HIGH) == (0xBFFF & CacheLine::HIGH)) {
64 return nullptr;
65 } else {
66 return unmappedWrite.data();
67 }
68}
69
70template<typename Archive>
71void RomPlayBall::serialize(Archive& ar, unsigned /*version*/)
72{
73 ar.template serializeBase<Rom16kBBlocks>(*this);
74 ar.serialize("SamplePlayer", samplePlayer);
75}
78
79} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
void invalidateDeviceRCache()
Definition MSXDevice.hh:215
static std::array< byte, 0x10000 > unmappedWrite
Definition MSXDevice.hh:307
void setUnmapped(unsigned region)
Select 'unmapped' memory for this region.
Definition RomBlocks.cc:92
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition RomBlocks.cc:60
void setRom(unsigned region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition RomBlocks.cc:104
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition RomBlocks.cc:72
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
void serialize(Archive &ar, unsigned version)
byte * getWriteCacheLine(word address) override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
void reset(EmuTime::param time) override
This method is called on reset.
RomPlayBall(const DeviceConfig &config, Rom &&rom)
Definition RomPlayBall.cc:8
bool isPlaying() const
Is there currently playing a sample.
void play(unsigned sampleNum)
Start playing a (new) sample.
constexpr unsigned HIGH
Definition CacheLine.hh:10
constexpr unsigned SIZE
Definition CacheLine.hh:7
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
std::string strCat()
Definition strCat.hh:703