openMSX
MegaFlashRomSCCPlusSD.hh
Go to the documentation of this file.
1#ifndef MEGAFLASHROMSCCPLUSSD_HH
2#define MEGAFLASHROMSCCPLUSSD_HH
3
4#include "MSXDevice.hh"
5#include "MSXMapperIO.hh"
6#include "AmdFlash.hh"
7#include "SCC.hh"
8#include "AY8910.hh"
9#include <array>
10#include <memory>
11
12namespace openmsx {
13
14class CheckedRam;
15class SdCard;
16
17class MegaFlashRomSCCPlusSD final : public MSXDevice
18{
19public:
20 explicit MegaFlashRomSCCPlusSD(const DeviceConfig& config);
21 ~MegaFlashRomSCCPlusSD() override;
22
23 void powerUp(EmuTime::param time) override;
24 void reset(EmuTime::param time) override;
25 [[nodiscard]] byte peekMem(word address, EmuTime::param time) const override;
26 [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
27 [[nodiscard]] const byte* getReadCacheLine(word address) const override;
28 void writeMem(word address, byte value, EmuTime::param time) override;
29 [[nodiscard]] byte* getWriteCacheLine(word address) const override;
30
31 void writeIO(word port, byte value, EmuTime::param time) override;
32
33 template<typename Archive>
34 void serialize(Archive& ar, unsigned version);
35
36private:
37 enum SCCEnable { EN_NONE, EN_SCC, EN_SCCPLUS };
38 [[nodiscard]] SCCEnable getSCCEnable() const;
39 void updateConfigReg(byte value);
40
41 [[nodiscard]] byte getSubSlot(unsigned addr) const;
42
46 void writeToFlash(unsigned addr, byte value);
47 AmdFlash flash;
48 byte subslotReg;
49
50 // subslot 0
51 [[nodiscard]] byte readMemSubSlot0(word address);
52 [[nodiscard]] byte peekMemSubSlot0(word address) const;
53 [[nodiscard]] const byte* getReadCacheLineSubSlot0(word address) const;
54 [[nodiscard]] byte* getWriteCacheLineSubSlot0(word address) const;
55 void writeMemSubSlot0(word address, byte value);
56
57 // subslot 1
58 // mega flash rom scc+
59 [[nodiscard]] byte readMemSubSlot1(word address, EmuTime::param time);
60 [[nodiscard]] byte peekMemSubSlot1(word address, EmuTime::param time) const;
61 [[nodiscard]] const byte* getReadCacheLineSubSlot1(word address) const;
62 [[nodiscard]] byte* getWriteCacheLineSubSlot1(word address) const;
63 void writeMemSubSlot1(word address, byte value, EmuTime::param time);
64 [[nodiscard]] unsigned getFlashAddrSubSlot1(unsigned addr) const;
65
66 SCC scc;
67 AY8910 psg;
68
69 byte mapperReg;
70 [[nodiscard]] bool is64KmapperConfigured() const { return (mapperReg & 0xC0) == 0x40; }
71 [[nodiscard]] bool isKonamiSCCmapperConfigured() const { return (mapperReg & 0xE0) == 0x00; }
72 [[nodiscard]] bool isWritingKonamiBankRegisterDisabled() const { return (mapperReg & 0x08) != 0; }
73 [[nodiscard]] bool isMapperRegisterDisabled() const { return (mapperReg & 0x04) != 0; }
74 [[nodiscard]] bool areBankRegsAndOffsetRegsDisabled() const { return (mapperReg & 0x02) != 0; }
75 [[nodiscard]] bool areKonamiMapperLimitsEnabled() const { return (mapperReg & 0x01) != 0; }
76 unsigned offsetReg;
77
78 byte configReg = 3; // avoid UMR
79 [[nodiscard]] bool isConfigRegDisabled() const { return (configReg & 0x80) != 0; }
80 [[nodiscard]] bool isMemoryMapperEnabled() const { return ((configReg & 0x20) == 0) && checkedRam; }
81 [[nodiscard]] bool isDSKmodeEnabled() const { return (configReg & 0x10) != 0; }
82 [[nodiscard]] bool isPSGalsoMappedToNormalPorts() const { return (configReg & 0x08) != 0; }
83 [[nodiscard]] bool isSlotExpanderEnabled() const { return (configReg & 0x04) == 0; }
84 [[nodiscard]] bool isFlashRomBlockProtectEnabled() const { return (configReg & 0x02) != 0; }
85 [[nodiscard]] bool isFlashRomWriteEnabled() const { return (configReg & 0x01) != 0; }
86
87 std::array<byte, 4> bankRegsSubSlot1;
88 byte psgLatch;
89 byte sccMode;
90 std::array<byte, 4> sccBanks;
91
92 // subslot 2
93 // 512k memory mapper
94 [[nodiscard]] byte readMemSubSlot2(word address);
95 [[nodiscard]] byte peekMemSubSlot2(word address) const;
96 [[nodiscard]] const byte* getReadCacheLineSubSlot2(word address) const;
97 [[nodiscard]] byte* getWriteCacheLineSubSlot2(word address) const;
98 void writeMemSubSlot2(word address, byte value);
99
100 [[nodiscard]] unsigned calcMemMapperAddress(word address) const;
101 [[nodiscard]] unsigned calcAddress(word address) const;
102
103 class MapperIO final : public MSXMapperIOClient {
104 public:
105 MapperIO(MegaFlashRomSCCPlusSD& mega_)
107 , mega(mega_)
108 {
109 }
110
111 [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
112 [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
113 void writeIO(word port, byte value, EmuTime::param time) override;
114 [[nodiscard]] byte getSelectedSegment(byte page) const override;
115
116 private:
118 };
119 const std::unique_ptr<CheckedRam> checkedRam; // can be nullptr
120 const std::unique_ptr<MapperIO> mapperIO; // nullptr iff checkedRam == nullptr
121 std::array<byte, 4> memMapperRegs;
122
123 // subslot 3
124 [[nodiscard]] byte readMemSubSlot3(word address, EmuTime::param time);
125 [[nodiscard]] byte peekMemSubSlot3(word address, EmuTime::param time) const;
126 [[nodiscard]] const byte* getReadCacheLineSubSlot3(word address) const;
127 [[nodiscard]] byte* getWriteCacheLineSubSlot3(word address) const;
128 void writeMemSubSlot3(word address, byte value, EmuTime::param time);
129 [[nodiscard]] unsigned getFlashAddrSubSlot3(unsigned addr) const;
130
131 std::array<byte, 4> bankRegsSubSlot3;
132
133 byte selectedCard;
134 std::array<std::unique_ptr<SdCard>, 2> sdCard;
135};
136
137} // namespace openmsx
138
139#endif
This class implements the AY-3-8910 sound chip.
Definition AY8910.hh:21
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition MSXDevice.cc:70
void serialize(Archive &ar, unsigned version)
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
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.
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
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 writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
This file implemented 3 utility functions:
Definition Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29