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);
18  setUnmapped(3);
19 
20  reset(EmuTime::dummy());
21 }
22 
23 void RomPlayBall::reset(EmuTime::param /*time*/)
24 {
25  samplePlayer.reset();
26 }
27 
28 byte RomPlayBall::peekMem(word address, EmuTime::param time) const
29 {
30  if (address == 0xBFFF) {
31  return samplePlayer.isPlaying() ? 0xFE : 0xFF;
32  } else {
33  return Rom16kBBlocks::peekMem(address, time);
34  }
35 }
36 
37 byte RomPlayBall::readMem(word address, EmuTime::param time)
38 {
39  return RomPlayBall::peekMem(address, time);
40 }
41 
43 {
44  if ((address & CacheLine::HIGH) == (0xBFFF & CacheLine::HIGH)) {
45  return nullptr;
46  } else {
47  return Rom16kBBlocks::getReadCacheLine(address);
48  }
49 }
50 
51 void RomPlayBall::writeMem(word address, byte value, EmuTime::param /*time*/)
52 {
53  if (address == 0xBFFF) {
54  if ((value <= 14) && !samplePlayer.isPlaying()) {
55  samplePlayer.play(value);
56  }
57  }
58 }
59 
61 {
62  if ((address & CacheLine::HIGH) == (0xBFFF & CacheLine::HIGH)) {
63  return nullptr;
64  } else {
65  return unmappedWrite;
66  }
67 }
68 
69 template<typename Archive>
70 void RomPlayBall::serialize(Archive& ar, unsigned /*version*/)
71 {
72  ar.template serializeBase<Rom16kBBlocks>(*this);
73  ar.serialize("SamplePlayer", samplePlayer);
74 }
76 REGISTER_MSXDEVICE(RomPlayBall, "RomPlayBall");
77 
78 } // namespace openmsx
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:98
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomPlayBall.cc:23
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
Definition: RomPlayBall.cc:60
RomPlayBall(const DeviceConfig &config, Rom &&rom)
Definition: RomPlayBall.cc:8
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
STL namespace.
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomPlayBall.cc:28
void play(unsigned sampleNum)
Start playing a (new) sample.
Definition: SamplePlayer.cc:63
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:42
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:53
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool isPlaying() const
Is there currently playing a sample.
Definition: SamplePlayer.hh:42
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:65
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
string_view stripExtension(string_view path)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:275
void setUnmapped(byte region)
Select &#39;unmapped&#39; memory for this region.
Definition: RomBlocks.cc:85
std::string strCat(Ts &&...ts)
Definition: strCat.hh:573
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomPlayBall.cc:37
void serialize(Archive &ar, unsigned version)
Definition: RomPlayBall.cc:70
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:51