Amiga FFS writes work.

This commit is contained in:
David Given
2022-08-30 23:13:59 +02:00
parent f382b70cdf
commit 42a350156a
2 changed files with 47 additions and 21 deletions

View File

@@ -147,6 +147,30 @@ public:
return bytes; return bytes;
} }
void putFile(const Path& path, const Bytes& data)
{
AdfMount m(this);
if (path.size() == 0)
throw BadPathException();
auto* vol = m.getVolume();
changeDirButOne(vol, path);
auto* file = adfOpenFile(vol, (char*)path.back().c_str(), (char*)"w");
if (!file)
throw CannotWriteException();
unsigned pos = 0;
while (pos != data.size())
{
long done = adfWriteFile(
file, data.size() - pos, (uint8_t*)data.cbegin() + pos);
pos += done;
}
adfCloseFile(file);
}
private: private:
class AdfEntry class AdfEntry
{ {
@@ -270,7 +294,9 @@ public:
RETCODE adfNativeWriteSector( RETCODE adfNativeWriteSector(
struct Device* dev, int32_t sector, int size, uint8_t* buffer) struct Device* dev, int32_t sector, int size, uint8_t* buffer)
{ {
return RC_OK; Bytes bytes(buffer, size);
putLogicalSector(sector, bytes);
return RC_OK;
} }
private: private:

View File

@@ -75,30 +75,30 @@ public:
&*_fluxSource); &*_fluxSource);
} }
else else
{ {
/* Only a few sectors have changed. Do we need to populate the track? */ /* Only a few sectors have changed. Do we need to populate the
* track? */
if (_loadedtracks.find(trackid) == _loadedtracks.end()) if (_loadedtracks.find(trackid) == _loadedtracks.end())
populateSectors(track, side); populateSectors(track, side);
/* Now merge the loaded track with the changed one, and write the result back. */ /* Now merge the loaded track with the changed one, and write
* the result back. */
Image image; Image image;
for (const unsigned sector : sectors) for (const unsigned sector : sectors)
{ {
auto s = image.put(track, side, sector); auto s = image.put(track, side, sector);
if (_changedSectors.contains(track, side, sector)) if (_changedSectors.contains(track, side, sector))
s->data = _changedSectors.get(track, side, sector)->data; s->data =
else _changedSectors.get(track, side, sector)->data;
s->data = _readSectors.get(track, side, sector)->data; else
} s->data = _readSectors.get(track, side, sector)->data;
}
writeDiskCommand(image, writeDiskCommand(
*_encoder, image, *_encoder, *_fluxSink, &*_decoder, &*_fluxSource);
*_fluxSink, }
&*_decoder,
&*_fluxSource);
}
} }
} }