25 : motherBoard(config.getMotherBoard())
31 while ((*hdInUse)[
id]) {
38 name[2] = narrow<char>(
'a' +
id);
45 if (cliImage.empty()) {
53 file =
File(filename, mode);
61 tigerTree.emplace(*
this, filesize, filename.
getResolved());
63 (*hdInUse)[
id] =
true;
80 unsigned id = name[2] -
'a';
81 assert((*hdInUse)[
id]);
82 (*hdInUse)[
id] =
false;
93 file =
File(newFilename);
94 filename = newFilename;
96 tigerTree.emplace(*
this, filesize, filename.
getResolved());
101size_t HD::getNbSectorsImpl()
const
106void HD::readSectorsImpl(
107 std::span<SectorBuffer> buffers,
size_t startSector)
109 file.
seek(startSector *
sizeof(SectorBuffer));
113void HD::writeSectorImpl(
size_t sector,
const SectorBuffer& buf)
115 file.
seek(sector *
sizeof(buf));
117 tigerTree->notifyChange(sector *
sizeof(buf),
sizeof(buf),
121bool HD::isWriteProtectedImpl()
const
126Sha1Sum HD::getSha1SumImpl(FilePool& filePool)
131 return filePool.getSha1Sum(file);
134void HD::showProgress(
size_t position,
size_t maxPosition)
141 if (((now - lastProgressTime) > 1000000) ||
142 ((position == maxPosition) && everDidProgress)) {
143 lastProgressTime = now;
144 int percentage = int((100 * position) / maxPosition);
147 "... ", percentage,
'%');
149 everDidProgress =
true;
156 everDidProgress =
false;
157 auto callback = [
this](
size_t p,
size_t t) { showProgress(p,
t); };
158 return tigerTree->calcHash(callback).toString();
161uint8_t* HD::getData(
size_t offset,
size_t size)
174 size_t sector = offset /
sizeof(SectorBuffer);
175 size_t num =
size /
sizeof(SectorBuffer);
176 readSectors(std::span{work.bufs.data(), num}, sector);
177 return work.bufs[0].raw.data();
180bool HD::isCacheStillValid(time_t& cacheTime)
183 bool result = fileTime == cacheTime;
184 cacheTime = fileTime;
188SectorAccessibleDisk* HD::getSectorAccessibleDisk()
193std::string_view HD::getContainerName()
const
198bool HD::diskChanged()
203int HD::insertDisk(
const std::string& newFilename)
208 }
catch (MSXException&) {
215template<
typename Archive>
219 ar.serialize(
"filename", tmp);
220 if constexpr (Archive::IS_LOADER) {
248 bool mismatch =
false;
250 if (ar.versionAtLeast(version, 2)) {
253 if constexpr (!Archive::IS_LOADER) {
256 ar.serialize(
"tthsum", oldTiger);
257 if constexpr (Archive::IS_LOADER) {
259 mismatch = oldTiger != newTiger;
265 if constexpr (!Archive::IS_LOADER) {
268 string oldChecksumStr = oldChecksum.
empty()
271 ar.serialize(
"checksum", oldChecksumStr);
272 oldChecksum = oldChecksumStr.
empty()
276 if constexpr (Archive::IS_LOADER) {
278 mismatch = oldChecksum != newChecksum;
282 if constexpr (Archive::IS_LOADER) {
285 "The content of the hard disk ",
287 " has changed since the time this savestate was "
288 "created. This might result in emulation problems "
289 "or even disk corruption. To prevent the latter, "
290 "the hard disk 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(std::span< uint8_t > buffer)
Read from file.
void write(std::span< const uint8_t > buffer)
Write to 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.
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 Filename & getImageName() const
void switchImage(const Filename &filename)
HD(const DeviceConfig &config)
std::string getTigerTreeHash()
void getMediaInfo(TclObject &result) override
This method gets called when information is required on the media inserted in the media slot of the p...
const std::string & getName() const
void serialize(Archive &ar, unsigned version)
std::shared_ptr< T > getSharedStuff(std::string_view name, Args &&...args)
Some MSX device parts are shared between several MSX devices (e.g.
Scheduler & getScheduler()
CliComm & getMSXCliComm()
StateChangeDistributor & getStateChangeDistributor()
void registerMediaInfo(std::string_view name, MediaInfoProvider &provider)
Register and unregister providers of media info, for the media info topic.
CommandController & getCommandController()
void unregisterMediaInfo(MediaInfoProvider &provider)
GlobalSettings & getGlobalSettings()
bool isWriteProtected() const
virtual Sha1Sum getSha1SumImpl(FilePool &filePool)
Sha1Sum getSha1Sum(FilePool &filePool)
Calculate SHA1 of the content of this disk.
void readSectors(std::span< SectorBuffer > buffers, size_t startSector)
This class represents the result of a sha1 calculation (a 160-bit value).
std::string toString() const
void addDictKeyValues(Args &&... args)
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)