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  byte peekMem(word address, EmuTime::param time) const override;
25  byte readMem(word address, EmuTime::param time) override;
26  const byte* getReadCacheLine(word address) const override;
27  void writeMem(word address, byte value, EmuTime::param time) override;
28  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  SCCEnable getSCCEnable() const;
38  void updateConfigReg(byte value);
39 
40  byte getSubSlot(unsigned addr) const;
41 
45  void writeToFlash(unsigned addr, byte value);
46  AmdFlash flash;
47  byte subslotReg;
48 
49  // subslot 0
50  byte readMemSubSlot0(word address);
51  byte peekMemSubSlot0(word address) const;
52  const byte* getReadCacheLineSubSlot0(word address) const;
53  byte* getWriteCacheLineSubSlot0(word address) const;
54  void writeMemSubSlot0(word address, byte value);
55 
56  // subslot 1
57  // mega flash rom scc+
58  byte readMemSubSlot1(word address, EmuTime::param time);
59  byte peekMemSubSlot1(word address, EmuTime::param time) const;
60  const byte* getReadCacheLineSubSlot1(word address) const;
61  byte* getWriteCacheLineSubSlot1(word address) const;
62  void writeMemSubSlot1(word address, byte value, EmuTime::param time);
63  unsigned getFlashAddrSubSlot1(unsigned addr) const;
64 
65  SCC scc;
66  AY8910 psg;
67 
68  byte mapperReg;
69  bool is64KmapperConfigured() const { return (mapperReg & 0xC0) == 0x40; }
70  bool isKonamiSCCmapperConfigured() const { return (mapperReg & 0xE0) == 0x00; }
71  bool isWritingKonamiBankRegisterDisabled() const { return (mapperReg & 0x08) != 0; }
72  bool isMapperRegisterDisabled() const { return (mapperReg & 0x04) != 0; }
73  bool areBankRegsAndOffsetRegsDisabled() const { return (mapperReg & 0x02) != 0; }
74  bool areKonamiMapperLimitsEnabled() const { return (mapperReg & 0x01) != 0; }
75  unsigned offsetReg;
76 
77  byte configReg;
78  bool isConfigRegDisabled() const { return (configReg & 0x80) != 0; }
79  bool isMemoryMapperEnabled() const { return ((configReg & 0x20) == 0) && checkedRam; }
80  bool isDSKmodeEnabled() const { return (configReg & 0x10) != 0; }
81  bool isPSGalsoMappedToNormalPorts() const { return (configReg & 0x08) != 0; }
82  bool isSlotExpanderEnabled() const { return (configReg & 0x04) == 0; }
83  bool isFlashRomBlockProtectEnabled() const { return (configReg & 0x02) != 0; }
84  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  byte readMemSubSlot2(word address);
94  byte peekMemSubSlot2(word address) const;
95  const byte* getReadCacheLineSubSlot2(word address) const;
96  byte* getWriteCacheLineSubSlot2(word address) const;
97  void writeMemSubSlot2(word address, byte value);
98 
99  unsigned calcMemMapperAddress(word address) const;
100  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  byte readIO(word port, EmuTime::param time) override;
111  byte peekIO(word port, EmuTime::param time) const override;
112  void writeIO(word port, byte value, EmuTime::param time) override;
113  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  byte readMemSubSlot3(word address, EmuTime::param time);
124  byte peekMemSubSlot3(word address, EmuTime::param time) const;
125  const byte* getReadCacheLineSubSlot3(word address) const;
126  byte* getWriteCacheLineSubSlot3(word address) const;
127  void writeMemSubSlot3(word address, byte value, EmuTime::param time);
128  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
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.
This class implements the AY-3-8910 sound chip.
Definition: AY8910.hh:19
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
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:406
MegaFlashRomSCCPlusSD(const DeviceConfig &config)
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading...
void reset(EmuTime::param time) override
This method is called on reset.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:74
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
virtual byte peekIO(word port, EmuTime::param time) const
Read a byte from a given IO port.
Definition: MSXDevice.cc:417
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
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)