30 : motherBoard(config.getMotherBoard())
36 while ((*hdInUse)[
id]) {
43 name[2] = narrow<char>(
'a' +
id);
58 file =
File(filename, mode);
66 tigerTree.emplace(*
this, filesize, filename.
getResolved());
68 (*hdInUse)[
id] =
true;
85 unsigned id = name[2] -
'a';
86 assert((*hdInUse)[
id]);
87 (*hdInUse)[
id] =
false;
98 file =
File(newFilename);
99 filename = newFilename;
101 tigerTree.emplace(*
this, filesize, filename.
getResolved());
106size_t HD::getNbSectorsImpl()
const
111void HD::readSectorsImpl(
112 std::span<SectorBuffer> buffers,
size_t startSector)
114 file.
seek(startSector *
sizeof(SectorBuffer));
118void HD::writeSectorImpl(
size_t sector,
const SectorBuffer& buf)
120 file.
seek(sector *
sizeof(buf));
122 tigerTree->notifyChange(sector *
sizeof(buf),
sizeof(buf),
126bool HD::isWriteProtectedImpl()
const
131Sha1Sum HD::getSha1SumImpl(FilePool& filePool)
136 return filePool.getSha1Sum(file);
139void HD::showProgress(
size_t position,
size_t maxPosition)
146 if (((now - lastProgressTime) > 1000000) ||
147 ((position == maxPosition) && everDidProgress)) {
148 lastProgressTime = now;
149 auto fraction = float(position) / float(maxPosition);
154 everDidProgress =
true;
161 everDidProgress =
false;
162 auto callback = [
this](
size_t p,
size_t t) { showProgress(p,
t); };
163 return tigerTree->calcHash(callback).toString();
166uint8_t* HD::getData(
size_t offset,
size_t size)
179 size_t sector = offset /
sizeof(SectorBuffer);
180 size_t num = size /
sizeof(SectorBuffer);
181 readSectors(std::span{work.bufs.data(), num}, sector);
182 return work.bufs[0].raw.data();
185bool HD::isCacheStillValid(time_t& cacheTime)
188 bool result = fileTime == cacheTime;
189 cacheTime = fileTime;
193SectorAccessibleDisk* HD::getSectorAccessibleDisk()
198std::string_view HD::getContainerName()
const
203bool HD::diskChanged()
208int HD::insertDisk(
const std::string& newFilename)
213 }
catch (MSXException&) {
220template<
typename Archive>
224 ar.serialize(
"filename", tmp);
225 if constexpr (Archive::IS_LOADER) {
253 bool mismatch =
false;
255 if (ar.versionAtLeast(version, 2)) {
258 if constexpr (!Archive::IS_LOADER) {
261 ar.serialize(
"tthsum", oldTiger);
262 if constexpr (Archive::IS_LOADER) {
264 mismatch = oldTiger != newTiger;
270 if constexpr (!Archive::IS_LOADER) {
273 string oldChecksumStr = oldChecksum.
empty()
276 ar.serialize(
"checksum", oldChecksumStr);
277 oldChecksum = oldChecksumStr.
empty()
281 if constexpr (Archive::IS_LOADER) {
283 mismatch = oldChecksum != newChecksum;
287 if constexpr (Archive::IS_LOADER) {
290 "The content of the hard disk ",
292 " has changed since the time this savestate was "
293 "created. This might result in emulation problems "
294 "or even disk corruption. To prevent the latter, "
295 "the hard disk is now write-protected.");
void printProgress(std::string_view message, float fraction)
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
static std::shared_ptr< HDInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
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...
std::bitset< MAX_HD > HDInUse
const std::string & getName() const
void serialize(Archive &ar, unsigned version)
static constexpr unsigned MAX_HD
void update(UpdateType type, std::string_view name, std::string_view value) override
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()
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)
MSXCliComm & getMSXCliComm()
GlobalSettings & getGlobalSettings()
bool isWriteProtected() const
void readSectors(std::span< SectorBuffer > buffers, size_t startSector) const
virtual Sha1Sum getSha1SumImpl(FilePool &filePool)
Sha1Sum getSha1Sum(FilePool &filePool)
Calculate SHA1 of the content of this disk.
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:
const FileContext & userFileContext()
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
TemporaryString tmpStrCat(Ts &&... ts)