openMSX
AmdFlash.hh
Go to the documentation of this file.
1#ifndef AMDFLASH_HH
2#define AMDFLASH_HH
3
4#include "MemBuffer.hh"
5#include "openmsx.hh"
6#include "serialize_meta.hh"
7#include <memory>
8#include <span>
9
10namespace openmsx {
11
12class MSXMotherBoard;
13class Rom;
14class SRAM;
15class DeviceConfig;
16
18{
19public:
20 struct SectorInfo {
21 unsigned size;
23 };
24 enum class Addressing {
25 BITS_11,
26 BITS_12,
27 };
28 enum class Load {
29 NORMAL,
30 DONT, // don't load nor save modified flash content
31 };
32
48 AmdFlash(const Rom& rom, std::span<const SectorInfo> sectorInfo,
49 word ID, Addressing addressing,
50 const DeviceConfig& config, Load load = Load::NORMAL);
51 AmdFlash(const std::string& name, std::span<const SectorInfo> sectorInfo,
52 word ID, Addressing addressing,
53 const DeviceConfig& config);
55
56 void reset();
63 void setVppWpPinLow(bool value) { vppWpPinLow = value; }
64
65 [[nodiscard]] unsigned getSize() const { return size; }
66 [[nodiscard]] byte read(unsigned address) const;
67 [[nodiscard]] byte peek(unsigned address) const;
68 void write(unsigned address, byte value);
69 [[nodiscard]] const byte* getReadCacheLine(unsigned address) const;
70
71 template<typename Archive>
72 void serialize(Archive& ar, unsigned version);
73
74//private:
75 struct AmdCmd {
76 unsigned addr;
77 byte value;
78
79 template<typename Archive>
80 void serialize(Archive& ar, unsigned version);
81 };
82
84
85private:
86 void init(const std::string& name, const DeviceConfig& config, Load load, const Rom* rom);
87 struct GetSectorInfoResult { unsigned sector, sectorSize, offset; };
88 [[nodiscard]] GetSectorInfoResult getSectorInfo(unsigned address) const;
89
90 void setState(State newState);
91 [[nodiscard]] bool checkCommandReset();
92 [[nodiscard]] bool checkCommandEraseSector();
93 [[nodiscard]] bool checkCommandEraseChip();
94 [[nodiscard]] bool checkCommandProgramHelper(unsigned numBytes, const byte* cmdSeq, size_t cmdLen);
95 [[nodiscard]] bool checkCommandProgram();
96 [[nodiscard]] bool checkCommandDoubleByteProgram();
97 [[nodiscard]] bool checkCommandQuadrupleByteProgram();
98 [[nodiscard]] bool checkCommandManufacturer();
99 [[nodiscard]] bool partialMatch(size_t len, const byte* dataSeq) const;
100
101 [[nodiscard]] bool isSectorWritable(unsigned sector) const;
102
103private:
104 MSXMotherBoard& motherBoard;
105 std::unique_ptr<SRAM> ram;
106 MemBuffer<int> writeAddress;
107 MemBuffer<const byte*> readAddress;
108 const std::span<const SectorInfo> sectorInfo;
109 const unsigned size;
110 const word ID;
111 const Addressing addressing;
112
113 static constexpr unsigned MAX_CMD_SIZE = 8;
114 AmdCmd cmd[MAX_CMD_SIZE];
115 unsigned cmdIdx;
116 State state = ST_IDLE;
117 bool vppWpPinLow = false; // true = protection on
118};
120
121} // namespace openmsx
122
123#endif
unsigned getSize() const
Definition: AmdFlash.hh:65
void write(unsigned address, byte value)
Definition: AmdFlash.cc:265
void serialize(Archive &ar, unsigned version)
Definition: AmdFlash.cc:404
byte peek(unsigned address) const
Definition: AmdFlash.cc:212
void setVppWpPinLow(bool value)
Setting the Vpp/WP# pin LOW enables a certain kind of write protection of some sectors.
Definition: AmdFlash.hh:63
byte read(unsigned address) const
Definition: AmdFlash.cc:248
AmdFlash(const Rom &rom, std::span< const SectorInfo > sectorInfo, word ID, Addressing addressing, const DeviceConfig &config, Load load=Load::NORMAL)
Create AmdFlash with given configuration.
Definition: AmdFlash.cc:22
const byte * getReadCacheLine(unsigned address) const
Definition: AmdFlash.cc:254
SDLSurfacePtr load(const std::string &filename, bool want32bpp)
Load the given PNG file in a SDL_Surface.
Definition: PNG.cc:95
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
SRAM
Definition: SRAM.cc:147
void serialize(Archive &ar, unsigned version)
Definition: AmdFlash.cc:397