[Scummvm-git-logs] scummvm master -> 44d9f583e066d5b6ef3f79ed905d39edb40c0740
waltervn
walter at vanniftrik-it.nl
Fri Feb 2 22:39:13 CET 2018
This automated email contains information about 9 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f0be784fde ADL: Add convert_disk debug command
1600c4dbb7 ADL: Do not pad out 13-sector .NIB disks to 16-sector format
b64d8dbf3b ADL: Ignore broken sectors
9f479c9b17 ADL: Add sanity check to track/sector numbers read from NIB
23870196f5 ADL: Refactor disk image handling
3850b115f8 ENGINES: Make AdvancedMetaEngine::detectGame() virtual
b497ec3065 ADL: Implement new detection method for disk images
aba2961899 ADL: Refactor NIB image error handling
44d9f583e0 ADL: Reduce sound volume
Commit: f0be784fdefca53161eb58e7981c58b92a6c3281
https://github.com/scummvm/scummvm/commit/f0be784fdefca53161eb58e7981c58b92a6c3281
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Add convert_disk debug command
Changed paths:
engines/adl/console.cpp
engines/adl/console.h
engines/adl/disk.h
diff --git a/engines/adl/console.cpp b/engines/adl/console.cpp
index ad3277f..e1242fa 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 68787e1..338fc42 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 6126ef5..d7fb52e 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 {
Commit: 1600c4dbb7df1b4c4ef041fe2d032e1467eacf8d
https://github.com/scummvm/scummvm/commit/1600c4dbb7df1b4c4ef041fe2d032e1467eacf8d
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Do not pad out 13-sector .NIB disks to 16-sector format
Changed paths:
engines/adl/disk.cpp
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index 6952fb9..6384daa 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -39,6 +39,38 @@ static Common::SeekableReadStream *readImage(const Common::String &filename) {
return f;
}
+static bool detectDOS33_NIB(const Common::String &filename) {
+ Common::File f;
+
+ if (!f.open(filename))
+ error("Failed to open '%s'", filename.c_str());
+
+ if (f.size() != 232960)
+ error("Unrecognized NIB image '%s' of size %d bytes", filename.c_str(), f.size());
+
+ uint count = 0;
+ uint dos32 = 0, dos33 = 0;
+ uint32 window = 0;
+
+ while (count++ < 6656) {
+ window &= 0xffff;
+ window <<= 8;
+ window |= f.readByte();
+
+ if (f.err() || f.eos())
+ error("Failed to read '%s'", filename.c_str());
+
+ if (window == 0xd5aa96)
+ ++dos33;
+ else if (window == 0xd5aab5)
+ ++dos32;
+ }
+
+ f.close();
+
+ return dos33 > dos32;
+}
+
const uint trackLen = 256 * 26;
// 4-and-4 encoding (odd-even)
@@ -48,7 +80,7 @@ static uint8 read44(byte *buffer, uint &pos) {
return ((ret << 1) | 1) & buffer[pos++ % trackLen];
}
-static Common::SeekableReadStream *readImage_NIB(const Common::String &filename) {
+static Common::SeekableReadStream *readImage_NIB(const Common::String &filename, bool dos33) {
Common::File f;
if (!f.open(filename))
@@ -62,15 +94,13 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename)
// starting at 0x96, 64 is invalid (see below)
const byte c_6and2_lookup[] = { 0, 1, 64, 64, 2, 3, 64, 4, 5, 6, 64, 64, 64, 64, 64, 64, 7, 8, 64, 64, 64, 9, 10, 11, 12, 13, 64, 64, 14, 15, 16, 17, 18, 19, 64, 20, 21, 22, 23, 24, 25, 26, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 27, 64, 28, 29, 30, 64, 64, 64, 31, 64, 64, 32, 33, 64, 34, 35, 36, 37, 38, 39, 40, 64, 64, 64, 64, 64, 41, 42, 43, 64, 44, 45, 46, 47, 48, 49, 50, 64, 64, 51, 52, 53, 54, 55, 56, 64, 57, 58, 59, 60, 61, 62, 63 };
- // we always pad it out
- const uint sectorsPerTrack = 16;
+ const uint sectorsPerTrack = (dos33 ? 16 : 13);
const uint bytesPerSector = 256;
const uint imageSize = 35 * sectorsPerTrack * bytesPerSector;
byte *const diskImage = (byte *)calloc(imageSize, 1);
bool sawAddress = false;
uint8 volNo = 0, track = 0, sector = 0;
- bool newStyle;
byte buffer[trackLen];
uint firstGoodTrackPos = 0;
@@ -92,20 +122,17 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename)
byte prologue = buffer[pos++ % trackLen];
- if (sawAddress && (prologue == 0xb5 || prologue == 0x96)) {
+ if (sawAddress && prologue == (dos33 ? 0x96 : 0xb5)) {
sawAddress = false;
}
if (!sawAddress) {
sawAddress = true;
- newStyle = false;
// We should always find the address field first.
- if (prologue != 0xb5) {
+ if (prologue != (dos33 ? 0x96 : 0xb5)) {
// Accept a DOS 3.3(?) header at the start.
- if (prologue == 0x96) {
- newStyle = true;
- } else if (prologue == 0xad || prologue == 0xfd) {
+ if (prologue == (dos33 ? 0xb5 : 0x96) || prologue == 0xad || prologue == 0xfd) {
sawAddress = false;
continue;
} else {
@@ -136,7 +163,7 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename)
// TODO: we ignore volNo?
byte *output = diskImage + (track * sectorsPerTrack + sector) * bytesPerSector;
- if (newStyle) {
+ if (dos33) {
// We hardcode the DOS 3.3 mapping here. TODO: Do we also need raw/prodos?
int raw2dos[16] = { 0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15 };
sector = raw2dos[sector];
@@ -250,25 +277,30 @@ bool DiskImage::open(const Common::String &filename) {
lcName.toLowercase();
if (lcName.hasSuffix(".dsk")) {
- _stream = readImage(filename);
_tracks = 35;
_sectorsPerTrack = 16;
_bytesPerSector = 256;
- } else if (lcName.hasSuffix(".d13")) {
_stream = readImage(filename);
+ } else if (lcName.hasSuffix(".d13")) {
_tracks = 35;
_sectorsPerTrack = 13;
_bytesPerSector = 256;
+ _stream = readImage(filename);
} else if (lcName.hasSuffix(".nib")) {
- _stream = readImage_NIB(filename);
_tracks = 35;
- _sectorsPerTrack = 16;
+
+ if (detectDOS33_NIB(filename))
+ _sectorsPerTrack = 16;
+ else
+ _sectorsPerTrack = 13;
+
_bytesPerSector = 256;
+ _stream = readImage_NIB(filename, _sectorsPerTrack == 16);
} else if (lcName.hasSuffix(".xfd")) {
- _stream = readImage(filename);
_tracks = 40;
_sectorsPerTrack = 18;
_bytesPerSector = 128;
+ _stream = readImage(filename);
}
int expectedSize = _tracks * _sectorsPerTrack * _bytesPerSector;
Commit: b64d8dbf3be1c58cd07a0f57e2088d496db926bb
https://github.com/scummvm/scummvm/commit/b64d8dbf3be1c58cd07a0f57e2088d496db926bb
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Ignore broken sectors
Changed paths:
engines/adl/disk.cpp
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index 6384daa..6174f6f 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -193,8 +193,10 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
}
byte checksum = buffer[pos++ % trackLen];
- if (checksum < 0x96 || oldVal != c_6and2_lookup[checksum - 0x96])
+ if (checksum < 0x96 || oldVal != c_6and2_lookup[checksum - 0x96]) {
warning("NIB: checksum mismatch @ (%x, %x)", track, sector);
+ continue;
+ }
for (uint n = 0; n < 256; ++n) {
output[n] = inbuffer[86 + n] << 2;
@@ -244,10 +246,14 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
oldVal = val ^ oldVal;
inbuffer[n] = oldVal;
}
- if (!truncated) {
- byte checksum = buffer[pos++ % trackLen];
- if (checksum < 0xaa || oldVal != c_5and3_lookup[checksum - 0xaa])
- warning("NIB: checksum mismatch @ (%x, %x)", track, sector);
+
+ if (truncated)
+ continue;
+
+ byte checksum = buffer[pos++ % trackLen];
+ if (checksum < 0xaa || oldVal != c_5and3_lookup[checksum - 0xaa]) {
+ warning("NIB: checksum mismatch @ (%x, %x)", track, sector);
+ continue;
}
// 8 bytes of nibbles expand to 5 bytes
Commit: 9f479c9b17b9268eafacfdf925c83ba89d92ef10
https://github.com/scummvm/scummvm/commit/9f479c9b17b9268eafacfdf925c83ba89d92ef10
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Add sanity check to track/sector numbers read from NIB
Changed paths:
engines/adl/disk.cpp
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index 6174f6f..a77798c 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -150,6 +150,12 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
continue;
}
+ if (track >= 35 || sector >= sectorsPerTrack) {
+ warning("NIB: sector out of bounds @ (%x, %x)", track, sector);
+ sawAddress = false;
+ continue;
+ }
+
if (!firstGoodTrackPos)
firstGoodTrackPos = pos;
Commit: 23870196f52e1174b35cec6dd6e2119aad44ad3c
https://github.com/scummvm/scummvm/commit/23870196f52e1174b35cec6dd6e2119aad44ad3c
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Refactor disk image handling
Changed paths:
engines/adl/disk.cpp
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index a77798c..ba07f23 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -28,25 +28,9 @@
namespace Adl {
-static Common::SeekableReadStream *readImage(const Common::String &filename) {
- Common::File *f = new Common::File;
-
- if (!f->open(filename)) {
- delete f;
- return nullptr;
- }
-
- return f;
-}
-
-static bool detectDOS33_NIB(const Common::String &filename) {
- Common::File f;
-
- if (!f.open(filename))
- error("Failed to open '%s'", filename.c_str());
-
+static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
if (f.size() != 232960)
- error("Unrecognized NIB image '%s' of size %d bytes", filename.c_str(), f.size());
+ return false;
uint count = 0;
uint dos32 = 0, dos33 = 0;
@@ -58,7 +42,7 @@ static bool detectDOS33_NIB(const Common::String &filename) {
window |= f.readByte();
if (f.err() || f.eos())
- error("Failed to read '%s'", filename.c_str());
+ return false;
if (window == 0xd5aa96)
++dos33;
@@ -66,13 +50,51 @@ static bool detectDOS33_NIB(const Common::String &filename) {
++dos32;
}
- f.close();
-
return dos33 > dos32;
}
const uint trackLen = 256 * 26;
+static bool readSector_NIB(byte outBuf[], const byte inBuf[], uint size, uint &pos, const byte minNibble, const byte lookup[], const uint track, const uint sector) {
+ uint z = trackLen - (pos % trackLen);
+ if (z < size) {
+ memcpy(outBuf, inBuf + (pos % trackLen), z);
+ memcpy(outBuf + z, inBuf, size - z);
+ } else
+ memcpy(outBuf, inBuf + (pos % trackLen), size);
+ pos += size;
+
+ byte oldVal = 0;
+ for (uint n = 0; n < size; ++n) {
+ // expand
+ assert(outBuf[n] >= minNibble); // corrupt file (TODO: assert?)
+ if (outBuf[n] == 0xd5) {
+ // Early end of block.
+ pos -= (size - n);
+ warning("NIB: early end of block @ %x (%d, %d)", n, track, sector);
+ return false;
+ }
+ byte val = lookup[outBuf[n] - minNibble];
+ if (val == 0x40) {
+ // Badly-encoded nibbles, stop trying to decode here.
+ pos -= (size - n);
+ warning("NIB: bad nibble %02x @ %x (%d, %d)", outBuf[n], n, track, sector);
+ return false;
+ }
+ // undo checksum
+ oldVal = val ^ oldVal;
+ outBuf[n] = oldVal;
+ }
+
+ byte checksum = inBuf[pos++ % trackLen];
+ if (checksum < minNibble || oldVal != lookup[checksum - minNibble]) {
+ warning("NIB: checksum mismatch @ (%d, %d)", track, sector);
+ return false;
+ }
+
+ return true;
+}
+
// 4-and-4 encoding (odd-even)
static uint8 read44(byte *buffer, uint &pos) {
// 1s in the other fields, so we can just AND
@@ -80,17 +102,14 @@ static uint8 read44(byte *buffer, uint &pos) {
return ((ret << 1) | 1) & buffer[pos++ % trackLen];
}
-static Common::SeekableReadStream *readImage_NIB(const Common::String &filename, bool dos33) {
- Common::File f;
-
- if (!f.open(filename))
+static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
+ if (f.size() != 232960) {
+ warning("NIB: image '%s' has invalid size of %d bytes", f.getName(), f.size());
return nullptr;
+ }
- if (f.size() != 232960)
- error("Unrecognized NIB image '%s' of size %d bytes", filename.c_str(), f.size());
-
- // starting at 0xaa, 32 is invalid (see below)
- const byte c_5and3_lookup[] = { 32, 0, 32, 1, 2, 3, 32, 32, 32, 32, 32, 4, 5, 6, 32, 32, 7, 8, 32, 9, 10, 11, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 12, 13, 32, 32, 14, 15, 32, 16, 17, 18, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 19, 20, 32, 21, 22, 23, 32, 32, 32, 32, 32, 24, 25, 26, 32, 32, 27, 28, 32, 29, 30, 31 };
+ // starting at 0xaa, 64 is invalid (see below)
+ const byte c_5and3_lookup[] = { 64, 0, 64, 1, 2, 3, 64, 64, 64, 64, 64, 4, 5, 6, 64, 64, 7, 8, 64, 9, 10, 11, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 12, 13, 64, 64, 14, 15, 64, 16, 17, 18, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 19, 20, 64, 21, 22, 23, 64, 64, 64, 64, 64, 24, 25, 26, 64, 64, 27, 28, 64, 29, 30, 31 };
// starting at 0x96, 64 is invalid (see below)
const byte c_6and2_lookup[] = { 0, 1, 64, 64, 2, 3, 64, 4, 5, 6, 64, 64, 64, 64, 64, 64, 7, 8, 64, 64, 64, 9, 10, 11, 12, 13, 64, 64, 14, 15, 16, 17, 18, 19, 64, 20, 21, 22, 23, 24, 25, 26, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 27, 64, 28, 29, 30, 64, 64, 64, 31, 64, 64, 32, 33, 64, 34, 35, 36, 37, 38, 39, 40, 64, 64, 64, 64, 64, 41, 42, 43, 64, 44, 45, 46, 47, 48, 49, 50, 64, 64, 51, 52, 53, 54, 55, 56, 64, 57, 58, 59, 60, 61, 62, 63 };
@@ -132,12 +151,10 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
// We should always find the address field first.
if (prologue != (dos33 ? 0x96 : 0xb5)) {
// Accept a DOS 3.3(?) header at the start.
- if (prologue == (dos33 ? 0xb5 : 0x96) || prologue == 0xad || prologue == 0xfd) {
- sawAddress = false;
- continue;
- } else {
- error("unknown NIB field prologue %02x", prologue);
- }
+ if (prologue != (dos33 ? 0xb5 : 0x96) && prologue != 0xad && prologue != 0xfd)
+ warning("NIB: unknown field prologue %02x", prologue);
+ sawAddress = false;
+ continue;
}
volNo = read44(buffer, pos);
@@ -145,7 +162,7 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
sector = read44(buffer, pos);
uint8 checksum = read44(buffer, pos);
if ((volNo ^ track ^ sector) != checksum) {
- warning("invalid NIB checksum (volNo %d, track %d, sector %d)", volNo, track, sector);
+ warning("NIB: invalid checksum (volNo %d, track %d, sector %d)", volNo, track, sector);
sawAddress = false;
continue;
}
@@ -175,34 +192,10 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
sector = raw2dos[sector];
output = diskImage + (track * sectorsPerTrack + sector) * bytesPerSector;
- // 6-and-2 uses 342 on-disk bytes
byte inbuffer[342];
- uint z = trackLen - (pos % trackLen);
- if (z < 342) {
- memcpy(inbuffer, buffer + (pos % trackLen), z);
- memcpy(inbuffer + z, buffer, 342 - z);
- } else
- memcpy(inbuffer, buffer + (pos % trackLen), 342);
- pos += 342;
-
- byte oldVal = 0;
- for (uint n = 0; n < 342; ++n) {
- // expand
- assert(inbuffer[n] >= 0x96); // corrupt file (TODO: assert?)
- byte val = c_6and2_lookup[inbuffer[n] - 0x96];
- if (val == 0x40) {
- error("NIB: invalid nibble value %02x", inbuffer[n]);
- }
- // undo checksum
- oldVal = val ^ oldVal;
- inbuffer[n] = oldVal;
- }
- byte checksum = buffer[pos++ % trackLen];
- if (checksum < 0x96 || oldVal != c_6and2_lookup[checksum - 0x96]) {
- warning("NIB: checksum mismatch @ (%x, %x)", track, sector);
+ if (!readSector_NIB(inbuffer, buffer, sizeof(inbuffer), pos, 0x96, c_6and2_lookup, track, sector))
continue;
- }
for (uint n = 0; n < 256; ++n) {
output[n] = inbuffer[86 + n] << 2;
@@ -220,47 +213,9 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
} else {
// 5-and-3 uses 410 on-disk bytes, decoding to just over 256 bytes
byte inbuffer[410];
- uint z = trackLen - (pos % trackLen);
- if (z < 410) {
- memcpy(inbuffer, buffer + (pos % trackLen), z);
- memcpy(inbuffer + z, buffer, 410 - z);
- } else
- memcpy(inbuffer, buffer + (pos % trackLen), 410);
- pos += 410;
-
- bool truncated = false;
- byte oldVal = 0;
- for (uint n = 0; n < 410; ++n) {
- // expand
- assert(inbuffer[n] >= 0xaa); // corrupt file (TODO: assert?)
- if (inbuffer[n] == 0xd5) {
- // Early end of block.
- truncated = true;
- pos -= (410 - n);
- warning("NIB: early end of block @ 0x%x (%x, %x)", f.pos(), track, sector);
- break;
- }
- byte val = c_5and3_lookup[inbuffer[n] - 0xaa];
- if (val == 0x20) {
- // Badly-encoded nibbles, stop trying to decode here.
- truncated = true;
- warning("NIB: bad nibble %02x @ 0x%x (%x, %x)", inbuffer[n], f.pos(), track, sector);
- pos -= (410 - n);
- break;
- }
- // undo checksum
- oldVal = val ^ oldVal;
- inbuffer[n] = oldVal;
- }
-
- if (truncated)
- continue;
- byte checksum = buffer[pos++ % trackLen];
- if (checksum < 0xaa || oldVal != c_5and3_lookup[checksum - 0xaa]) {
- warning("NIB: checksum mismatch @ (%x, %x)", track, sector);
+ if (!readSector_NIB(inbuffer, buffer, sizeof(inbuffer), pos, 0xaa, c_5and3_lookup, track, sector))
continue;
- }
// 8 bytes of nibbles expand to 5 bytes
// so we have 51 of these batches (255 bytes), plus 2 bytes of 'leftover' nibbles for byte 256
@@ -285,6 +240,14 @@ static Common::SeekableReadStream *readImage_NIB(const Common::String &filename,
}
bool DiskImage::open(const Common::String &filename) {
+ Common::File *f = new Common::File;
+
+ if (!f->open(filename)) {
+ warning("Failed to open '%s'", filename.c_str());
+ delete f;
+ return false;
+ }
+
Common::String lcName(filename);
lcName.toLowercase();
@@ -292,27 +255,29 @@ bool DiskImage::open(const Common::String &filename) {
_tracks = 35;
_sectorsPerTrack = 16;
_bytesPerSector = 256;
- _stream = readImage(filename);
+ _stream = f;
} else if (lcName.hasSuffix(".d13")) {
_tracks = 35;
_sectorsPerTrack = 13;
_bytesPerSector = 256;
- _stream = readImage(filename);
+ _stream = f;
} else if (lcName.hasSuffix(".nib")) {
_tracks = 35;
- if (detectDOS33_NIB(filename))
+ if (detectDOS33_NIB(*f))
_sectorsPerTrack = 16;
else
_sectorsPerTrack = 13;
_bytesPerSector = 256;
- _stream = readImage_NIB(filename, _sectorsPerTrack == 16);
+ f->seek(0);
+ _stream = readImage_NIB(*f, _sectorsPerTrack == 16);
+ delete f;
} else if (lcName.hasSuffix(".xfd")) {
_tracks = 40;
_sectorsPerTrack = 18;
_bytesPerSector = 128;
- _stream = readImage(filename);
+ _stream = f;
}
int expectedSize = _tracks * _sectorsPerTrack * _bytesPerSector;
Commit: 3850b115f86a7e01fb4902d924eaa94b10328576
https://github.com/scummvm/scummvm/commit/3850b115f86a7e01fb4902d924eaa94b10328576
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ENGINES: Make AdvancedMetaEngine::detectGame() virtual
Changed paths:
engines/advancedDetector.h
diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h
index 61693d1..5160a99 100644
--- a/engines/advancedDetector.h
+++ b/engines/advancedDetector.h
@@ -313,7 +313,7 @@ protected:
* @param extra restrict results to specified extra string (only if kADFlagUseExtraAsHint is set)
* @return list of ADGameDescription pointers corresponding to matched games
*/
- ADGameDescList detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const;
+ virtual ADGameDescList detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const;
/**
* Iterates over all ADFileBasedFallback records inside fileBasedFallback.
Commit: b497ec30655a95134e0db62fff2b2324e58f4ffb
https://github.com/scummvm/scummvm/commit/b497ec30655a95134e0db62fff2b2324e58f4ffb
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Implement new detection method for disk images
Changed paths:
engines/adl/adl_v2.cpp
engines/adl/detection.cpp
engines/adl/detection.h
engines/adl/disk.cpp
engines/adl/disk.h
diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp
index 075c2ef..b142839 100644
--- a/engines/adl/adl_v2.cpp
+++ b/engines/adl/adl_v2.cpp
@@ -48,13 +48,7 @@ AdlEngine_v2::AdlEngine_v2(OSystem *syst, const AdlGameDescription *gd) :
}
Common::String AdlEngine_v2::getDiskImageName(byte volume) const {
- const ADGameFileDescription *ag;
-
- for (ag = _gameDescription->desc.filesDescriptions; ag->fileName; ag++)
- if (ag->fileType == volume)
- return ag->fileName;
-
- error("Disk volume %d not found", volume);
+ return Adl::getDiskImageName(_gameDescription->desc, volume);
}
void AdlEngine_v2::insertDisk(byte volume) {
diff --git a/engines/adl/detection.cpp b/engines/adl/detection.cpp
index 64574ec..60971d5 100644
--- a/engines/adl/detection.cpp
+++ b/engines/adl/detection.cpp
@@ -23,12 +23,16 @@
#include "common/system.h"
#include "common/savefile.h"
#include "common/translation.h"
+#include "common/file.h"
+#include "common/md5.h"
+#include "common/debug.h"
#include "graphics/thumbnail.h"
#include "engines/advancedDetector.h"
#include "adl/detection.h"
+#include "adl/disk.h"
namespace Adl {
@@ -83,8 +87,8 @@ static const PlainGameDescriptor adlGames[] = {
{ 0, 0 }
};
-static const AdlGameDescription gameDescriptions[] = {
- { // Hi-Res Adventure #1: Mystery House - Apple II - 1987 PD release - Plain files
+static const AdlGameDescription gameFileDescriptions[] = {
+ { // Hi-Res Adventure #1: Mystery House - Apple II - 1987 PD release
{
"hires1", 0,
{
@@ -100,11 +104,15 @@ static const AdlGameDescription gameDescriptions[] = {
},
GAME_TYPE_HIRES1
},
- { // Hi-Res Adventure #1: Mystery House - Apple II - 1987 PD release - .DSK format
+ { AD_TABLE_END_MARKER, GAME_TYPE_NONE }
+};
+
+static const AdlGameDescription gameDiskDescriptions[] = {
+ { // Hi-Res Adventure #1: Mystery House - Apple II - Roberta Williams Anthology
{
"hires1", 0,
{
- { "MYSTHOUS.DSK", 0, "34ba05e62bf51404c4475c349ca48921", 143360 },
+ { "mysthous", 0, "54d20eb1ef0084ac3c2d16c31c5b7eb7", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -118,7 +126,7 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires2", 0,
{
- { "WIZARD.DSK", 0, "816fdfc35e25496213c8db40ecf26569", 143360 },
+ { "wizard", 0, "72b114bf8f94fafe5672daac2a70c765", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -132,7 +140,7 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires0", 0,
{
- { "MISSION.NIB", 0, "b158f6f79681d4edd651e1932f9e01d7", 232960 },
+ { "mission", 0, "6bc53f51a3c8ee65c020af55fb8bd875", 116480 },
AD_LISTEND
},
Common::EN_ANY,
@@ -146,7 +154,7 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires3", 0,
{
- { "CRANSTON.D13", 0, "474d92b845337ec189867fac035304c7", 116480 },
+ { "cranston", 0, "e4d35440791a36e55299c7be1ccd2b04", 116480 },
AD_LISTEND
},
Common::EN_ANY,
@@ -160,8 +168,8 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires4", 0,
{
- { "ULYSSESA.DSK", 0, "df21f28ae94440f958dbbcfdfaf0c36e", 143360 },
- { "ULYSSESB.DSK", 1, "c204e8fe265e9534049f3c0f816cc9fc", 143360 },
+ { "ulyssesa", 0, "1eaeb2f1a773ce2d1cb9f16b2ef09049", 143360 },
+ { "ulyssesb", 1, "9fa8552255ae651b252844168b8b6617", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -175,10 +183,10 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires4", 0,
{
- { "ULYS1A.XFD", 0, "26365d2b06509fd21e7a7919e33f7199", 92160 },
- { "ULYS1B.XFD", 0, "37919c72a4103e6f897ee7daa8261d1d", 92160 },
+ { "ulys1b", 0, "bb6aab9a35b41d160b6eefa088165f56", 92160 },
+ { "ulys1a", 0, "c227eeee34d0bacd62b2d6231c409204", 92160 },
// Load 'N' Go Software release XAG-0646 appears to be missing the second disk
- { "ULYS2C.XFD", 0, "ff33830246e65dc71c954acb7fd5621a", 92160 },
+ { "ulys2c", 0, "8c6a76d1767e4ffa2f0118c9c56c0e90", 92160 },
AD_LISTEND
},
Common::EN_ANY,
@@ -192,18 +200,18 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires5", 0,
{
- { "TZONE1A.NIB", 2, "475dedb7396fdcea81c1a2a4046caebe", 232960 },
- { "TZONE1B.NIB", 3, "f8aaea094ebbe41cf4354d9fe2c30d9a", 232960 },
- { "TZONE2C.NIB", 4, "b351a367dc48e776bf08e42a3f50ae74", 232960 },
- { "TZONE2D.NIB", 5, "9583b287a5c95960f5335878102bb8b1", 232960 },
- { "TZONE3E.NIB", 6, "502e42a0cb69ffe4a48cd51c1ff210cf", 232960 },
- { "TZONE3F.NIB", 7, "3d6e0aae15f590b72b6759535b6b7d3c", 232960 },
- { "TZONE4G.NIB", 8, "ede4113a9c9e17745faf71d099808a18", 232960 },
- { "TZONE4H.NIB", 9, "f95dae4aae1155a27f7120230464d4e1", 232960 },
- { "TZONE5I.NIB", 10, "92b3b376877f81a7b7ae426bf1e65456", 232960 },
- { "TZONE5J.NIB", 11, "c9ef796fa596548dbf8f085901f0bac3", 232960 },
- { "TZONE6K.NIB", 12, "2e5323be637002efce1d4c813ae20a3f", 232960 },
- { "TZONE6L.NIB", 13, "7c9268f0ea2d02120c77a46337b3d975", 232960 },
+ { "tzone1a", 2, "731844b1d19c2801e3a5bc61d109af54", 143360 },
+ { "tzone1b", 3, "4eaf8d790e3f93097cca9ddbe863df50", 143360 },
+ { "tzone2c", 4, "e3aa4f56e727339b1ec00978ce9d435b", 143360 },
+ { "tzone2d", 5, "77b8219a380410015c986fa192d4c3bf", 143360 },
+ { "tzone3e", 6, "f7acc03edd8d8aecb90711cd5f9e5593", 143360 },
+ { "tzone3f", 7, "ed74c056976ecea2eab07448c8a72eb8", 143360 },
+ { "tzone4g", 8, "de7bda8a641169fc2dedd8a7b0b7e7de", 143360 },
+ { "tzone4h", 9, "21cf76d97505ff09fff5d5e4711bc47c", 143360 },
+ { "tzone5i", 10, "d665df374e594cd0978b73c3490e5de2", 143360 },
+ { "tzone5j", 11, "5095be23d13201d0897b9169c4e473df", 143360 },
+ { "tzone6k", 12, "bef044503f21af5f0a4088e99aa778b1", 143360 },
+ { "tzone6l", 13, "84801b7c2ab6c09e62a2a0809b94d16a", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -217,10 +225,10 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires6", 0,
{
- { "DARK1A.DSK", 0, "00c2646d6943d1405717332a6f42d493", 143360 },
- { "DARK1B.NIB", 3, "dbedd736617343ade0e6bead8bf2b10c", 232960 },
- { "DARK2A.NIB", 4, "271eb92db107e8d5829437f8ba77991e", 232960 },
- { "DARK2B.NIB", 5, "cb72044a9b391c4285f4752f746bea2e", 232960 },
+ { "dark1a", 0, "9a5968a8f378c84454d88f4cd4e143a9", 143360 },
+ { "dark1b", 3, "1271ff9c3e1bdb4942301dd37dd0ef87", 143360 },
+ { "dark2a", 4, "090e77563add7b4c9ab25f444d727316", 143360 },
+ { "dark2b", 5, "f2db96af0955324900b800505af4d91f", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -233,9 +241,22 @@ static const AdlGameDescription gameDescriptions[] = {
{ AD_TABLE_END_MARKER, GAME_TYPE_NONE }
};
+struct DiskImageExt {
+ Common::Platform platform;
+ const char *extension;
+};
+
+const DiskImageExt diskImageExts[] {
+ { Common::kPlatformApple2, ".nib" },
+ { Common::kPlatformApple2, ".dsk" },
+ { Common::kPlatformApple2, ".d13" },
+ { Common::kPlatformAtari8Bit, ".xfd" },
+ { Common::kPlatformUnknown, nullptr }
+};
+
class AdlMetaEngine : public AdvancedMetaEngine {
public:
- AdlMetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(AdlGameDescription), adlGames, optionsList) { }
+ AdlMetaEngine() : AdvancedMetaEngine(gameFileDescriptions, sizeof(AdlGameDescription), adlGames, optionsList) { }
const char *getName() const {
return "ADL";
@@ -250,6 +271,9 @@ public:
int getMaximumSaveSlot() const { return 'O' - 'A'; }
SaveStateList listSaves(const char *target) const;
void removeSaveState(const char *target, int slot) const;
+ virtual ADGameDescList detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const;
+
+ bool addFileProps(const FileMap &allFiles, Common::String fname, ADFilePropertiesMap &filePropsMap) const;
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const;
};
@@ -369,6 +393,147 @@ void AdlMetaEngine::removeSaveState(const char *target, int slot) const {
g_system->getSavefileManager()->removeSavefile(fileName);
}
+Common::String getDiskImageName(const ADGameDescription &desc, byte volume) {
+ for (uint i = 0; desc.filesDescriptions[i].fileName; ++i) {
+ const ADGameFileDescription &fDesc = desc.filesDescriptions[i];
+
+ if (fDesc.fileType == volume) {
+ for (uint e = 0; e < ARRAYSIZE(diskImageExts); ++e) {
+ if (diskImageExts[e].platform == desc.platform) {
+ Common::String testFileName(fDesc.fileName);
+ testFileName += diskImageExts[e].extension;
+ if (Common::File::exists(testFileName))
+ return testFileName;
+ }
+ }
+
+ error("Failed to find disk image '%s'", fDesc.fileName);
+ }
+ }
+
+ error("Disk volume %d not found", volume);
+}
+
+bool AdlMetaEngine::addFileProps(const FileMap &allFiles, Common::String fname, ADFilePropertiesMap &filePropsMap) const {
+ if (filePropsMap.contains(fname))
+ return true;
+
+ if (!allFiles.contains(fname))
+ return false;
+
+ ADFileProperties fileProps;
+ fileProps.size = computeMD5(allFiles[fname], fileProps.md5, 16384);
+
+ if (fileProps.size != -1) {
+ debug(3, "> '%s': '%s'", fname.c_str(), fileProps.md5.c_str());
+ filePropsMap[fname] = fileProps;
+ }
+
+ return true;
+}
+
+// Based on AdvancedMetaEngine::detectGame
+ADGameDescList AdlMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const {
+ // We run the file-based detector first and then add to the returned list
+ ADGameDescList matched = AdvancedMetaEngine::detectGame(parent, allFiles, language, platform, extra);
+
+ debug(3, "Starting disk image detection in dir '%s'", parent.getPath().c_str());
+
+ ADFilePropertiesMap filesProps;
+ ADGameIdList matchedGameIds;
+ bool gotAnyMatchesWithAllFiles = false;
+
+ for (uint g = 0; gameDiskDescriptions[g].desc.gameId != 0; ++g) {
+ const ADGameDescription &desc = gameDiskDescriptions[g].desc;
+
+ // Skip games that don't meet the language/platform/extra criteria
+ if (language != Common::UNK_LANG && desc.language != Common::UNK_LANG) {
+ if (desc.language != language && !(language == Common::EN_ANY && (desc.flags & ADGF_ADDENGLISH)))
+ continue;
+ }
+
+ if (platform != Common::kPlatformUnknown && desc.platform != Common::kPlatformUnknown && desc.platform != platform)
+ continue;
+
+ if ((_flags & kADFlagUseExtraAsHint) && !extra.empty() && desc.extra != extra)
+ continue;
+
+ bool fileMissing = false;
+ bool allFilesPresent = true;
+ bool hashOrSizeMismatch = false;
+
+ for (uint f = 0; desc.filesDescriptions[f].fileName; ++f) {
+ const ADGameFileDescription &fDesc = desc.filesDescriptions[f];
+ Common::String fileName;
+ bool foundDiskImage = false;
+
+ for (uint e = 0; e < ARRAYSIZE(diskImageExts); ++e) {
+ if (diskImageExts[e].platform == desc.platform) {
+ Common::String testFileName(fDesc.fileName);
+ testFileName += diskImageExts[e].extension;
+
+ if (addFileProps(allFiles, testFileName, filesProps)) {
+ if (foundDiskImage) {
+ warning("Ignoring '%s' (already found '%s')", testFileName.c_str(), fileName.c_str());
+ filesProps.erase(testFileName);
+ } else {
+ foundDiskImage = true;
+ fileName = testFileName;
+ }
+ }
+ }
+ }
+
+ if (!foundDiskImage) {
+ fileMissing = true;
+ allFilesPresent = false;
+ break;
+ }
+
+ if (hashOrSizeMismatch)
+ continue;
+
+ if (fDesc.md5 && fDesc.md5 != filesProps[fileName].md5) {
+ debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fDesc.md5, filesProps[fileName].md5.c_str());
+ fileMissing = true;
+ hashOrSizeMismatch = true;
+ continue;
+ }
+
+ if (fDesc.fileSize != -1 && fDesc.fileSize != filesProps[fileName].size) {
+ debug(3, "Size Mismatch. Skipping");
+ fileMissing = true;
+ hashOrSizeMismatch = true;
+ continue;
+ }
+
+ debug(3, "Matched file: %s", fileName.c_str());
+ }
+
+ if (!fileMissing) {
+ debug(2, "Found game: %s (%s/%s) (%d)", desc.gameId, getPlatformDescription(desc.platform), getLanguageDescription(desc.language), g);
+ matched.push_back(&desc);
+ } else {
+ if (allFilesPresent) {
+ gotAnyMatchesWithAllFiles = true;
+ if (!matchedGameIds.size() || strcmp(matchedGameIds.back(), desc.gameId) != 0)
+ matchedGameIds.push_back(desc.gameId);
+ }
+
+ debug(5, "Skipping game: %s (%s/%s) (%d)", desc.gameId, getPlatformDescription(desc.platform), getLanguageDescription(desc.language), g);
+ }
+ }
+
+ // TODO: This should be improved to handle matched and unknown games together in a single directory
+ if (matched.empty()) {
+ if (!filesProps.empty() && gotAnyMatchesWithAllFiles) {
+ reportUnknown(parent, filesProps, matchedGameIds);
+ }
+ }
+
+ return matched;
+}
+
Engine *HiRes1Engine_create(OSystem *syst, const AdlGameDescription *gd);
Engine *HiRes2Engine_create(OSystem *syst, const AdlGameDescription *gd);
Engine *HiRes0Engine_create(OSystem *syst, const AdlGameDescription *gd);
diff --git a/engines/adl/detection.h b/engines/adl/detection.h
index cb147c7..ac8d834 100644
--- a/engines/adl/detection.h
+++ b/engines/adl/detection.h
@@ -46,6 +46,8 @@ struct AdlGameDescription {
GameType gameType;
};
+Common::String getDiskImageName(const ADGameDescription &desc, byte volume);
+
} // End of namespace Adl
#endif
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index ba07f23..2abfe8b 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -23,11 +23,14 @@
#include "common/stream.h"
#include "common/substream.h"
#include "common/memstream.h"
+#include "common/md5.h"
#include "adl/disk.h"
namespace Adl {
+const uint trackLen = 256 * 26;
+
static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
if (f.size() != 232960)
return false;
@@ -36,7 +39,7 @@ static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
uint dos32 = 0, dos33 = 0;
uint32 window = 0;
- while (count++ < 6656) {
+ while (count++ < trackLen) {
window &= 0xffff;
window <<= 8;
window |= f.readByte();
@@ -53,8 +56,6 @@ static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
return dos33 > dos32;
}
-const uint trackLen = 256 * 26;
-
static bool readSector_NIB(byte outBuf[], const byte inBuf[], uint size, uint &pos, const byte minNibble, const byte lookup[], const uint track, const uint sector) {
uint z = trackLen - (pos % trackLen);
if (z < size) {
@@ -102,8 +103,8 @@ static uint8 read44(byte *buffer, uint &pos) {
return ((ret << 1) | 1) & buffer[pos++ % trackLen];
}
-static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
- if (f.size() != 232960) {
+static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, uint tracks = 35) {
+ if (f.size() != 35 * trackLen) {
warning("NIB: image '%s' has invalid size of %d bytes", f.getName(), f.size());
return nullptr;
}
@@ -115,7 +116,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
const uint sectorsPerTrack = (dos33 ? 16 : 13);
const uint bytesPerSector = 256;
- const uint imageSize = 35 * sectorsPerTrack * bytesPerSector;
+ const uint imageSize = tracks * sectorsPerTrack * bytesPerSector;
byte *const diskImage = (byte *)calloc(imageSize, 1);
bool sawAddress = false;
@@ -127,7 +128,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
while (true) {
if (pos >= trackLen+firstGoodTrackPos) {
- if (f.pos() == f.size())
+ if (f.pos() == (int)(tracks * trackLen))
break;
f.read(buffer, sizeof(buffer));
firstGoodTrackPos = 0;
@@ -167,7 +168,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
continue;
}
- if (track >= 35 || sector >= sectorsPerTrack) {
+ if (track >= tracks || sector >= sectorsPerTrack) {
warning("NIB: sector out of bounds @ (%x, %x)", track, sector);
sawAddress = false;
continue;
@@ -327,6 +328,41 @@ Common::SeekableReadStream *DiskImage::createReadStream(uint track, uint sector,
return new Common::MemoryReadStream(data, bytesToRead, DisposeAfterUse::YES);
}
+int32 computeMD5(const Common::FSNode &node, Common::String &md5, uint32 md5Bytes) {
+ Common::File f;
+
+ if (!f.open(node))
+ return -1;
+
+ if (node.getName().matchString("*.nib", true) && f.size() == 35 * trackLen) {
+ uint lastSector = md5Bytes / 256;
+ uint tracks;
+ bool isDOS33 = detectDOS33_NIB(f);
+
+ if (isDOS33)
+ tracks = (lastSector / 16) + 1;
+ else
+ tracks = (lastSector / 13) + 1;
+
+ // Tracks 1 and 2 are swapped in some copy protections, so we read three tracks when two tracks are needed
+ if (tracks == 2)
+ tracks = 3;
+
+ f.seek(0);
+ Common::SeekableReadStream *stream = readImage_NIB(f, isDOS33, tracks);
+ if (stream) {
+ md5 = Common::computeStreamMD5AsString(*stream, md5Bytes);
+ delete stream;
+ return 35 * (isDOS33 ? 16 : 13) * 256;
+ }
+
+ return -1;
+ } else {
+ md5 = Common::computeStreamMD5AsString(f, md5Bytes);
+ return f.size();
+ }
+}
+
const DataBlockPtr Files_Plain::getDataBlock(const Common::String &filename, uint offset) const {
return Common::SharedPtr<Files::DataBlock>(new Files::DataBlock(this, filename, offset));
}
diff --git a/engines/adl/disk.h b/engines/adl/disk.h
index d7fb52e..0ebe2e0 100644
--- a/engines/adl/disk.h
+++ b/engines/adl/disk.h
@@ -34,6 +34,9 @@ class String;
namespace Adl {
+// Used for disk image detection
+int32 computeMD5(const Common::FSNode &node, Common::String &md5, uint32 md5Bytes);
+
class DataBlock {
public:
virtual ~DataBlock() { }
Commit: aba2961899ef9f27cbc04f9cc56ffa7ee7c9b5a0
https://github.com/scummvm/scummvm/commit/aba2961899ef9f27cbc04f9cc56ffa7ee7c9b5a0
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:25+01:00
Commit Message:
ADL: Refactor NIB image error handling
Changed paths:
engines/adl/detection.cpp
engines/adl/disk.cpp
diff --git a/engines/adl/detection.cpp b/engines/adl/detection.cpp
index 60971d5..505672e 100644
--- a/engines/adl/detection.cpp
+++ b/engines/adl/detection.cpp
@@ -524,7 +524,7 @@ ADGameDescList AdlMetaEngine::detectGame(const Common::FSNode &parent, const Fil
}
}
- // TODO: This should be improved to handle matched and unknown games together in a single directory
+ // TODO: This could be improved to handle matched and unknown games together in a single directory
if (matched.empty()) {
if (!filesProps.empty() && gotAnyMatchesWithAllFiles) {
reportUnknown(parent, filesProps, matchedGameIds);
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index 2abfe8b..b715180 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -24,6 +24,7 @@
#include "common/substream.h"
#include "common/memstream.h"
#include "common/md5.h"
+#include "common/algorithm.h"
#include "adl/disk.h"
@@ -68,20 +69,25 @@ static bool readSector_NIB(byte outBuf[], const byte inBuf[], uint size, uint &p
byte oldVal = 0;
for (uint n = 0; n < size; ++n) {
// expand
- assert(outBuf[n] >= minNibble); // corrupt file (TODO: assert?)
if (outBuf[n] == 0xd5) {
// Early end of block.
pos -= (size - n);
- warning("NIB: early end of block @ %x (%d, %d)", n, track, sector);
+ debug(2, "NIB: early end of block @ %x (%d, %d)", n, track, sector);
return false;
}
- byte val = lookup[outBuf[n] - minNibble];
+
+ byte val = 0x40;
+
+ if (outBuf[n] >= minNibble)
+ val = lookup[outBuf[n] - minNibble];
+
if (val == 0x40) {
// Badly-encoded nibbles, stop trying to decode here.
pos -= (size - n);
- warning("NIB: bad nibble %02x @ %x (%d, %d)", outBuf[n], n, track, sector);
+ debug(2, "NIB: bad nibble %02x @ %x (%d, %d)", outBuf[n], n, track, sector);
return false;
}
+
// undo checksum
oldVal = val ^ oldVal;
outBuf[n] = oldVal;
@@ -89,7 +95,7 @@ static bool readSector_NIB(byte outBuf[], const byte inBuf[], uint size, uint &p
byte checksum = inBuf[pos++ % trackLen];
if (checksum < minNibble || oldVal != lookup[checksum - minNibble]) {
- warning("NIB: checksum mismatch @ (%d, %d)", track, sector);
+ debug(2, "NIB: checksum mismatch @ (%d, %d)", track, sector);
return false;
}
@@ -123,6 +129,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, ui
uint8 volNo = 0, track = 0, sector = 0;
byte buffer[trackLen];
+ Common::Array<bool> goodSectors(tracks * sectorsPerTrack);
uint firstGoodTrackPos = 0;
uint pos = trackLen; // force read
@@ -130,7 +137,13 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, ui
if (pos >= trackLen+firstGoodTrackPos) {
if (f.pos() == (int)(tracks * trackLen))
break;
- f.read(buffer, sizeof(buffer));
+
+ if (f.read(buffer, sizeof(buffer)) < sizeof(buffer)) {
+ warning("NIB: error reading '%s'", f.getName());
+ free(diskImage);
+ return nullptr;
+ }
+
firstGoodTrackPos = 0;
pos = 0;
sawAddress = false;
@@ -153,7 +166,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, ui
if (prologue != (dos33 ? 0x96 : 0xb5)) {
// Accept a DOS 3.3(?) header at the start.
if (prologue != (dos33 ? 0xb5 : 0x96) && prologue != 0xad && prologue != 0xfd)
- warning("NIB: unknown field prologue %02x", prologue);
+ debug(2, "NIB: unknown field prologue %02x", prologue);
sawAddress = false;
continue;
}
@@ -163,13 +176,13 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, ui
sector = read44(buffer, pos);
uint8 checksum = read44(buffer, pos);
if ((volNo ^ track ^ sector) != checksum) {
- warning("NIB: invalid checksum (volNo %d, track %d, sector %d)", volNo, track, sector);
+ debug(2, "NIB: invalid checksum (volNo %d, track %d, sector %d)", volNo, track, sector);
sawAddress = false;
continue;
}
if (track >= tracks || sector >= sectorsPerTrack) {
- warning("NIB: sector out of bounds @ (%x, %x)", track, sector);
+ debug(2, "NIB: sector out of bounds @ (%d, %d)", track, sector);
sawAddress = false;
continue;
}
@@ -235,6 +248,19 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, ui
}
output[255] = (inbuffer[409] << 3) | (inbuffer[0] & 0x7);
}
+
+ goodSectors[track * sectorsPerTrack + sector] = true;
+ }
+
+ if (Common::find(goodSectors.begin(), goodSectors.end(), false) != goodSectors.end()) {
+ debugN(1, "NIB: Bad/missing sectors:");
+
+ for (uint i = 0; i < goodSectors.size(); ++i) {
+ if (!goodSectors[i])
+ debugN(1, " (%d, %d)", i / sectorsPerTrack, i % sectorsPerTrack);
+ }
+
+ debugN(1, "\n");
}
return new Common::MemoryReadStream(diskImage, imageSize, DisposeAfterUse::YES);
Commit: 44d9f583e066d5b6ef3f79ed905d39edb40c0740
https://github.com/scummvm/scummvm/commit/44d9f583e066d5b6ef3f79ed905d39edb40c0740
Author: Walter van Niftrik (walter at scummvm.org)
Date: 2018-02-02T22:18:26+01:00
Commit Message:
ADL: Reduce sound volume
Changed paths:
engines/adl/adl.cpp
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp
index 9370363..3654982 100644
--- a/engines/adl/adl.cpp
+++ b/engines/adl/adl.cpp
@@ -484,7 +484,7 @@ bool AdlEngine::playTones(const Tones &tones, bool isMusic, bool allowSkip) cons
Audio::SoundHandle handle;
Audio::AudioStream *stream = new Sound(tones);
- g_system->getMixer()->playStream((isMusic ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType), &handle, stream);
+ g_system->getMixer()->playStream((isMusic ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType), &handle, stream, -1, 25);
while (!g_engine->shouldQuit() && g_system->getMixer()->isSoundHandleActive(handle)) {
Common::Event event;
More information about the Scummvm-git-logs
mailing list