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