11static size_t getRamSize(
const DeviceConfig& config)
13 int ramSizeInKb = config.getChildDataAsInt(
"sampleram", 512);
23 "Wrong sample RAM size for MoonSound's YMF278. "
24 "Got ", ramSizeInKb,
", but must be one of "
25 "0, 128, 256, 512, 640, 1024 or 2048.");
27 return size_t(ramSizeInKb) * 1024;
30static void setupMemPtrs(
bool mode0, std::span<const uint8_t> rom, std::span<const uint8_t> ram,
31 std::span<YMF278::Block128, 32> memPtrs)
65 for (
auto i :
xrange(16)) {
66 memPtrs[i] = subspan<k128>(rom, i * k128);
69 auto ramPart = [&](
int i) {
70 return (ram.size() >= (i + 1) * k128)
71 ? subspan<k128>(ram, i * k128)
74 if (mode0) [[likely]] {
76 for (
auto i :
xrange(16)) {
77 memPtrs[i + 16] = ramPart(i);
81 for (
auto i :
xrange(12)) {
85 memPtrs[i + 28] = ramPart(i);
92 , ymf278b(getName(), getRamSize(config), config, setupMemPtrs, getCurrentTime())
108 return ymf278b.
readIO(port, time);
113 return ymf278b.
peekIO(port, time);
118 ymf278b.
writeIO(port, value, time);
126template<
typename Archive>
129 ar.template serializeBase<MSXDevice>(*
this);
131 if (ar.versionAtLeast(version, 4)) {
132 ar.serialize(
"ymf278b", ymf278b);
134 assert(Archive::IS_LOADER);
135 if constexpr (std::is_same_v<Archive, XmlInputArchive>) {
#define REGISTER_MSXDEVICE(CLASS, NAME)
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
EmuTime::param getCurrentTime() const
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
MSXMoonSound(const DeviceConfig &config)
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
void serialize(Archive &ar, unsigned version)
void reset(EmuTime::param time) override
This method is called on reset.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void writeIO(word port, byte value, EmuTime::param time)
void powerUp(EmuTime::param time)
void serialize_bw_compat(XmlInputArchive &ar, unsigned version, EmuTime::param time)
byte readIO(word port, EmuTime::param time)
byte peekIO(word port, EmuTime::param time) const
void reset(EmuTime::param time)
static constexpr auto k128
optional_fixed_span< const uint8_t, k128 > Block128
This file implemented 3 utility functions:
uint16_t word
16 bit unsigned integer
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr auto xrange(T e)