23 : motherBoard(config.getMotherBoard())
29 while ((*hdInUse)[
id]) {
36 name[2] = char(
'a' +
id);
43 if (cliImage.empty()) {
51 file =
File(filename, mode);
59 tigerTree.emplace(*
this, filesize, filename.
getResolved());
61 (*hdInUse)[
id] =
true;
76 unsigned id = name[2] -
'a';
77 assert((*hdInUse)[
id]);
78 (*hdInUse)[
id] =
false;
83 file =
File(newFilename);
84 filename = newFilename;
86 tigerTree.emplace(*
this, filesize, filename.
getResolved());
91 size_t HD::getNbSectorsImpl()
const
96 void HD::readSectorsImpl(
97 SectorBuffer* buffers,
size_t startSector,
size_t num)
99 file.
seek(startSector *
sizeof(SectorBuffer));
100 file.
read(buffers, num *
sizeof(SectorBuffer));
103 void HD::writeSectorImpl(
size_t sector,
const SectorBuffer& buf)
105 file.
seek(sector *
sizeof(buf));
106 file.
write(&buf,
sizeof(buf));
107 tigerTree->notifyChange(sector *
sizeof(buf),
sizeof(buf),
111 bool HD::isWriteProtectedImpl()
const
116 Sha1Sum HD::getSha1SumImpl(FilePool& filePool)
121 return filePool.getSha1Sum(file);
124 void HD::showProgress(
size_t position,
size_t maxPosition)
131 if (((now - lastProgressTime) > 1000000) ||
132 ((position == maxPosition) && everDidProgress)) {
133 lastProgressTime = now;
134 int percentage = int((100 * position) / maxPosition);
137 "... ", percentage,
'%');
139 everDidProgress =
true;
146 everDidProgress =
false;
147 auto callback = [
this](
size_t p,
size_t t) { showProgress(p,
t); };
148 return tigerTree->calcHash(callback).toString();
151 uint8_t* HD::getData(
size_t offset,
size_t size)
164 size_t sector = offset /
sizeof(SectorBuffer);
165 size_t num =
size /
sizeof(SectorBuffer);
167 return work.bufs[0].raw;
170 bool HD::isCacheStillValid(time_t& cacheTime)
173 bool result = fileTime == cacheTime;
174 cacheTime = fileTime;
178 SectorAccessibleDisk* HD::getSectorAccessibleDisk()
183 std::string_view HD::getContainerName()
const
188 bool HD::diskChanged()
193 int HD::insertDisk(
const std::string& newFilename)
198 }
catch (MSXException&) {
205 template<
typename Archive>
209 ar.serialize(
"filename", tmp);
210 if constexpr (Archive::IS_LOADER) {
238 bool mismatch =
false;
240 if (ar.versionAtLeast(version, 2)) {
243 if constexpr (!Archive::IS_LOADER) {
246 ar.serialize(
"tthsum", oldTiger);
247 if constexpr (Archive::IS_LOADER) {
249 mismatch = oldTiger != newTiger;
255 if constexpr (!Archive::IS_LOADER) {
258 string oldChecksumStr = oldChecksum.
empty()
261 ar.serialize(
"checksum", oldChecksumStr);
262 oldChecksum = oldChecksumStr.
empty()
266 if constexpr (Archive::IS_LOADER) {
268 mismatch = oldChecksum != newChecksum;
272 if constexpr (Archive::IS_LOADER) {
275 "The content of the harddisk ",
277 " has changed since the time this savestate was "
278 "created. This might result in emulation problems "
279 "or even diskcorruption. To prevent the latter, "
280 "the harddisk is now write-protected.");
void printProgress(std::string_view message)
virtual void update(UpdateType type, std::string_view name, std::string_view value)=0
void printWarning(std::string_view message)
const FileContext & getFileContext() const
int getChildDataAsInt(std::string_view name, int defaultValue) const
std::string_view getChildData(std::string_view name) const
void repaint()
Redraw the display.
std::string resolveCreate(std::string_view filename) const
void close()
Close the current file.
void seek(size_t pos)
Move read/write pointer to the specified position.
bool isReadOnly() const
Check if this file is readonly.
void read(void *buffer, size_t num)
Read from file.
time_t getModificationDate()
Get the date/time of last modification.
void truncate(size_t size)
Truncate file size.
bool is_open() const
Return true iff this file handle refers to an open file.
size_t getSize()
Returns the size of this file.
void write(const void *buffer, size_t num)
Write to file.
This class represents a filename.
bool empty() const
Convenience method to test for empty filename.
const std::string & getResolved() const &
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
BooleanSetting & getPowerSetting()
static std::string getImageForId(int id)
const std::string & getName() const
void switchImage(const Filename &filename)
HD(const DeviceConfig &config)
std::string getTigerTreeHash()
void serialize(Archive &ar, unsigned version)
StateChangeDistributor & getStateChangeDistributor()
Scheduler & getScheduler()
CliComm & getMSXCliComm()
CommandController & getCommandController()
std::shared_ptr< T > getSharedStuff(std::string_view name, Args &&...args)
Some MSX device parts are shared between several MSX devices (e.g.
GlobalSettings & getGlobalSettings()
void readSectors(SectorBuffer *buffers, size_t startSector, size_t nbSectors)
Sha1Sum getSha1Sum(FilePool &filepool)
Calculate SHA1 of the content of this disk.
virtual Sha1Sum getSha1SumImpl(FilePool &filepool)
This class represents the result of a sha1 calculation (a 160-bit value).
std::string toString() const
static constexpr size_t BLOCK_SIZE
uint64_t getTime()
Get current (real) time in us.
This file implemented 3 utility functions:
FileContext userFileContext(string_view savePath)
size_t size(std::string_view utf8)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)