diff options
author | Walter van Niftrik | 2018-01-27 14:06:02 +0100 |
---|---|---|
committer | Walter van Niftrik | 2018-02-02 22:18:25 +0100 |
commit | f0be784fdefca53161eb58e7981c58b92a6c3281 (patch) | |
tree | 043e3ab846587f877dd2fb9253b1247bccdf8aa1 | |
parent | 53f922b1d7b06979f23921af107d2a444848465f (diff) | |
download | scummvm-rg350-f0be784fdefca53161eb58e7981c58b92a6c3281.tar.gz scummvm-rg350-f0be784fdefca53161eb58e7981c58b92a6c3281.tar.bz2 scummvm-rg350-f0be784fdefca53161eb58e7981c58b92a6c3281.zip |
ADL: Add convert_disk debug command
-rw-r--r-- | engines/adl/console.cpp | 39 | ||||
-rw-r--r-- | engines/adl/console.h | 1 | ||||
-rw-r--r-- | engines/adl/disk.h | 1 |
3 files changed, 41 insertions, 0 deletions
diff --git a/engines/adl/console.cpp b/engines/adl/console.cpp index ad3277ffaa..e1242fa64f 100644 --- a/engines/adl/console.cpp +++ b/engines/adl/console.cpp @@ -26,6 +26,7 @@ #include "adl/display.h" #include "adl/graphics.h" #include "adl/adl.h" +#include "adl/disk.h" namespace Adl { @@ -42,6 +43,7 @@ Console::Console(AdlEngine *engine) : GUI::Debugger() { registerCmd("give_item", WRAP_METHOD(Console, Cmd_GiveItem)); registerCmd("vars", WRAP_METHOD(Console, Cmd_Vars)); registerCmd("var", WRAP_METHOD(Console, Cmd_Var)); + registerCmd("convert_disk", WRAP_METHOD(Console, Cmd_ConvertDisk)); } Common::String Console::toAscii(const Common::String &str) { @@ -384,4 +386,41 @@ void Console::printWordMap(const WordMap &wordMap) { debugPrintColumns(words); } +bool Console::Cmd_ConvertDisk(int argc, const char **argv) { + if (argc != 3) { + debugPrintf("Usage: %s <source> <dest>\n", argv[0]); + return true; + } + + DiskImage inDisk; + if (!inDisk.open(argv[1])) { + debugPrintf("Failed to open '%s' for reading\n", argv[1]); + return true; + } + + Common::DumpFile outDisk; + if (!outDisk.open(argv[2])) { + debugPrintf("Failed to open '%s' for writing\n", argv[2]); + return true; + } + + const uint sectors = inDisk.getTracks() * inDisk.getSectorsPerTrack(); + const uint size = sectors * inDisk.getBytesPerSector(); + + byte *const buf = new byte[size]; + + StreamPtr stream(inDisk.createReadStream(0, 0, 0, sectors - 1)); + if (stream->read(buf, size) < size) { + debugPrintf("Failed to read from stream"); + delete[] buf; + return true; + } + + if (outDisk.write(buf, size) < size) + debugPrintf("Failed to write to '%s'", argv[2]); + + delete[] buf; + return true; +} + } // End of namespace Adl diff --git a/engines/adl/console.h b/engines/adl/console.h index 68787e148a..338fc42147 100644 --- a/engines/adl/console.h +++ b/engines/adl/console.h @@ -54,6 +54,7 @@ private: bool Cmd_GiveItem(int argc, const char **argv); bool Cmd_Vars(int argc, const char **argv); bool Cmd_Var(int argc, const char **argv); + bool Cmd_ConvertDisk(int argc, const char **argv); void printItem(const Item &item); void printWordMap(const Common::HashMap<Common::String, uint> &wordMap); diff --git a/engines/adl/disk.h b/engines/adl/disk.h index 6126ef5bbc..d7fb52e588 100644 --- a/engines/adl/disk.h +++ b/engines/adl/disk.h @@ -89,6 +89,7 @@ public: void setSectorLimit(uint sectorLimit) { _sectorLimit = sectorLimit; } // Maximum number of sectors to read per track before stepping uint getBytesPerSector() const { return _bytesPerSector; } uint getSectorsPerTrack() const { return _sectorsPerTrack; } + uint getTracks() const { return _tracks; } protected: class DataBlock : public Adl::DataBlock { |