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
void invalidateDeviceRCache()
Definition: MSXDevice.hh:211
static std::array< byte, 0x10000 > unmappedWrite
Definition: MSXDevice.hh:303
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:59
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:103
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
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:91
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
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
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
void serialize(Archive &ar, unsigned version)
Definition: RomPlayBall.cc:71
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
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomPlayBall.cc:29
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomPlayBall.cc:24
RomPlayBall(const DeviceConfig &config, Rom &&rom)
Definition: RomPlayBall.cc:8
bool isPlaying() const
Is there currently playing a sample.
Definition: SamplePlayer.hh:42
void play(unsigned sampleNum)
Start playing a (new) sample.
Definition: SamplePlayer.cc:72
constexpr unsigned HIGH
Definition: CacheLine.hh:10
constexpr unsigned SIZE
Definition: CacheLine.hh:7
string_view stripExtension(string_view path)
Returns the path without extension.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021
std::string strCat(Ts &&...ts)
Definition: strCat.hh:542