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 
6 namespace 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 
24 void RomPlayBall::reset(EmuTime::param /*time*/)
25 {
26  samplePlayer.reset();
27 }
28 
29 byte 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 
38 byte RomPlayBall::readMem(word address, EmuTime::param time)
39 {
40  return RomPlayBall::peekMem(address, time);
41 }
42 
43 const 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 
52 void 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;
67  }
68 }
69 
70 template<typename Archive>
71 void RomPlayBall::serialize(Archive& ar, unsigned /*version*/)
72 {
73  ar.template serializeBase<Rom16kBBlocks>(*this);
74  ar.serialize("SamplePlayer", samplePlayer);
75 }
78 
79 } // namespace openmsx
openmsx::RomBlocks::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:59
serialize.hh
openmsx::RomPlayBall::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomPlayBall.cc:24
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::YM2413NukeYKT::rom
constexpr Rom rom
Definition: YM2413NukeYKT.cc:71
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::CacheLine::HIGH
constexpr unsigned HIGH
Definition: CacheLine.hh:10
openmsx::RomPlayBall::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomPlayBall.cc:29
openmsx::RomPlayBall
Definition: RomPlayBall.hh:10
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::RomPlayBall::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomPlayBall.cc:43
openmsx::RomPlayBall::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomPlayBall.cc:61
openmsx::RomBlocks::getReadCacheLine
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:71
openmsx::RomBlocks::setRom
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:104
openmsx::RomBlocks::setUnmapped
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:91
openmsx::RomBlocks
Definition: RomBlocks.hh:14
openmsx::SamplePlayer::play
void play(unsigned sampleNum)
Start playing a (new) sample.
Definition: SamplePlayer.cc:63
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::SamplePlayer::reset
void reset()
Definition: SamplePlayer.cc:57
openmsx::CacheLine::SIZE
constexpr unsigned SIZE
Definition: CacheLine.hh:7
CacheLine.hh
openmsx::RomPlayBall::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomPlayBall.cc:71
openmsx::Rom
Definition: Rom.hh:21
openmsx::MSXDevice::invalidateDeviceRCache
void invalidateDeviceRCache()
Definition: MSXDevice.hh:209
FileOperations.hh
openmsx::SamplePlayer::isPlaying
bool isPlaying() const
Is there currently playing a sample.
Definition: SamplePlayer.hh:42
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomPlayBall::writeMem
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.
Definition: RomPlayBall.cc:52
openmsx::RomPlayBall::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomPlayBall.cc:38
openmsx::RomPlayBall::RomPlayBall
RomPlayBall(const DeviceConfig &config, Rom &&rom)
Definition: RomPlayBall.cc:8
strCat
std::string strCat(Ts &&...ts)
Definition: strCat.hh:573
openmsx::FileOperations::stripExtension
string_view stripExtension(string_view path)
Returns the path without extension.
Definition: FileOperations.cc:421
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
RomPlayBall.hh