aboutsummaryrefslogtreecommitdiff
path: root/engines/adl
diff options
context:
space:
mode:
authorWalter van Niftrik2016-03-26 01:01:10 +0100
committerWalter van Niftrik2016-06-06 20:35:49 +0200
commit7ee183ca481c2729cb703ced3b6a3fa4ad7d73a3 (patch)
tree84315570e13fda3b82e43a627ee5eada22d30b1c /engines/adl
parent02563df42218d103a80e9bc5463cc63909b2f495 (diff)
downloadscummvm-rg350-7ee183ca481c2729cb703ced3b6a3fa4ad7d73a3.tar.gz
scummvm-rg350-7ee183ca481c2729cb703ced3b6a3fa4ad7d73a3.tar.bz2
scummvm-rg350-7ee183ca481c2729cb703ced3b6a3fa4ad7d73a3.zip
ADL: Refactor disk classes
Diffstat (limited to 'engines/adl')
-rw-r--r--engines/adl/adl.h2
-rw-r--r--engines/adl/disk.cpp49
-rw-r--r--engines/adl/disk.h97
-rw-r--r--engines/adl/hires1.cpp2
4 files changed, 75 insertions, 75 deletions
diff --git a/engines/adl/adl.h b/engines/adl/adl.h
index ba803e8f8b..731b7e3078 100644
--- a/engines/adl/adl.h
+++ b/engines/adl/adl.h
@@ -52,8 +52,6 @@ class Speaker;
struct AdlGameDescription;
struct ScriptEnv;
-typedef Common::ScopedPtr<Common::SeekableReadStream> StreamPtr;
-
// Save and restore opcodes
#define IDO_ACT_SAVE 0x0f
#define IDO_ACT_LOAD 0x10
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index b7de55a78e..22a7d7a431 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -28,35 +28,8 @@
namespace Adl {
-DiskImage::DiskImage() :
- _tracks(0),
- _sectorsPerTrack(0),
- _bytesPerSector(0) {
- _f = new Common::File();
-}
-
-DiskImage::~DiskImage() {
- delete _f;
-}
-
-DiskImageDataBlock::DiskImageDataBlock(const DiskImage *disk, uint track, uint sector, uint offset, uint size) :
- _track(track),
- _sector(sector),
- _offset(offset),
- _size(size),
- _disk(disk) { }
-
-bool DiskImageDataBlock::isValid() const {
- return _track != 0 || _sector != 0 || _offset != 0 || _size != 0;
-}
-
-Common::SeekableReadStream *DiskImageDataBlock::createReadStream() const {
- return _disk->createReadStream(_track, _sector, _offset, _size);
-}
-
-// .DSK disk image - 35 tracks, 16 sectors per track, 256 bytes per sector, raw sector layout
const DataBlockPtr DiskImage_DSK::getDataBlock(uint track, uint sector, uint offset, uint size) const {
- return Common::SharedPtr<DiskImageDataBlock>(new DiskImageDataBlock(this, track, sector, offset, size));
+ return Common::SharedPtr<DiskImage::DataBlock>(new DiskImage::DataBlock(this, track, sector, offset, size));
}
Common::SeekableReadStream *DiskImage_DSK::createReadStream(uint track, uint sector, uint offset, uint size) const {
@@ -81,22 +54,20 @@ bool DiskImage_DSK::open(const Common::String &filename) {
_tracks = 35;
_sectorsPerTrack = 16;
_bytesPerSector = 256;
- return true;
+ break;
+ default:
+ warning("Unrecognized disk image '%s' of size %d bytes", filename.c_str(), filesize);
+ return false;
}
- warning("Unrecognized disk image '%s' of size %d bytes", filename.c_str(), filesize);
- return false;
-}
-
-Common::SeekableReadStream *FilesDataBlock::createReadStream() const {
- return _files->createReadStream(_filename, _offset);
+ return true;
}
-const DataBlockPtr PlainFiles::getDataBlock(const Common::String &filename, uint offset) const {
- return Common::SharedPtr<FilesDataBlock>(new FilesDataBlock(this, filename, offset));
+const DataBlockPtr Files_Plain::getDataBlock(const Common::String &filename, uint offset) const {
+ return Common::SharedPtr<Files::DataBlock>(new Files::DataBlock(this, filename, offset));
}
-Common::SeekableReadStream *PlainFiles::createReadStream(const Common::String &filename, uint offset) const {
+Common::SeekableReadStream *Files_Plain::createReadStream(const Common::String &filename, uint offset) const {
Common::File *f(new Common::File());
if (!f->open(filename))
@@ -194,7 +165,7 @@ void Files_DOS33::readVTOC() {
}
const DataBlockPtr Files_DOS33::getDataBlock(const Common::String &filename, uint offset) const {
- return Common::SharedPtr<FilesDataBlock>(new FilesDataBlock(this, filename, offset));
+ return Common::SharedPtr<Files::DataBlock>(new Files::DataBlock(this, filename, offset));
}
Common::SeekableReadStream *Files_DOS33::createReadStreamText(const TOCEntry &entry) const {
diff --git a/engines/adl/disk.h b/engines/adl/disk.h
index 799fa371df..12801ec9e7 100644
--- a/engines/adl/disk.h
+++ b/engines/adl/disk.h
@@ -43,6 +43,7 @@ public:
};
typedef Common::SharedPtr<DataBlock> DataBlockPtr;
+typedef Common::ScopedPtr<Common::SeekableReadStream> StreamPtr;
class Files {
public:
@@ -50,60 +51,90 @@ public:
virtual const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const = 0;
virtual Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const = 0;
-};
-
-class FilesDataBlock : public DataBlock {
-public:
- FilesDataBlock(const Files *files, const Common::String &filename, uint offset) : _files(files), _filename(filename), _offset(offset) { }
-
- bool isValid() const { return true; }
- Common::SeekableReadStream *createReadStream() const;
-
-private:
- const Common::String _filename;
- uint _offset;
- const Files *_files;
-};
-class PlainFiles : public Files {
-public:
- const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const;
- Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const;
+protected:
+ class DataBlock : public Adl::DataBlock {
+ public:
+ DataBlock(const Files *files, const Common::String &filename, uint offset) :
+ _files(files),
+ _filename(filename),
+ _offset(offset) { }
+
+ bool isValid() const {
+ return true;
+ }
+
+ Common::SeekableReadStream *createReadStream() const {
+ return _files->createReadStream(_filename, _offset);
+ }
+
+ private:
+ const Common::String _filename;
+ uint _offset;
+ const Files *_files;
+ };
};
class DiskImage {
public:
- DiskImage();
- virtual ~DiskImage();
+ DiskImage() :
+ _tracks(0),
+ _sectorsPerTrack(0),
+ _bytesPerSector(0) {
+ _f = new Common::File();
+ }
+
+ virtual ~DiskImage() {
+ delete _f;
+ }
virtual bool open(const Common::String &filename) = 0;
- virtual const DataBlockPtr getDataBlock(uint track, uint sector, uint offset, uint size) const = 0;
- virtual Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset, uint size) const = 0;
+ virtual const DataBlockPtr getDataBlock(uint track, uint sector, uint offset = 0, uint size = 0) const = 0;
+ virtual Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset = 0, uint size = 0) const = 0;
protected:
+ class DataBlock : public Adl::DataBlock {
+ public:
+ DataBlock(const DiskImage *disk, uint track, uint sector, uint offset, uint size) :
+ _track(track),
+ _sector(sector),
+ _offset(offset),
+ _size(size),
+ _disk(disk) { }
+
+ bool isValid() const {
+ return _track != 0 || _sector != 0 || _offset != 0 || _size != 0;
+ }
+
+ Common::SeekableReadStream *createReadStream() const {
+ return _disk->createReadStream(_track, _sector, _offset, _size);
+ }
+
+ private:
+ uint _track, _sector, _offset, _size;
+ const DiskImage *_disk;
+ };
+
Common::File *_f;
uint _tracks, _sectorsPerTrack, _bytesPerSector;
};
-class DiskImageDataBlock : public DataBlock {
+// Data in plain files
+class Files_Plain : public Files {
public:
- DiskImageDataBlock(const DiskImage *disk, uint track, uint sector, uint offset, uint size);
-
- bool isValid() const;
- Common::SeekableReadStream *createReadStream() const;
-
-private:
- uint _track, _sector, _offset, _size;
- const DiskImage *_disk;
+ const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const;
+ Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const;
};
+// .DSK disk image - 35 tracks, 16 sectors per track, 256 bytes per sector
class DiskImage_DSK : public DiskImage {
public:
bool open(const Common::String &filename);
- const DataBlockPtr getDataBlock(uint track, uint sector, uint offset, uint size) const;
+ const DataBlockPtr getDataBlock(uint track, uint sector, uint offset = 0, uint size = 0) const;
Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset = 0, uint size = 0) const;
};
+// Data in files contained in Apple DOS 3.3 disk image
class Files_DOS33 : public Files {
public:
Files_DOS33();
@@ -141,7 +172,7 @@ private:
Common::SeekableReadStream *createReadStreamText(const TOCEntry &entry) const;
Common::SeekableReadStream *createReadStreamBinary(const TOCEntry &entry) const;
- DiskImage_DSK *_disk;
+ DiskImage *_disk;
Common::HashMap<Common::String, TOCEntry> _toc;
};
diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp
index 1c46ba6354..8590e8416e 100644
--- a/engines/adl/hires1.cpp
+++ b/engines/adl/hires1.cpp
@@ -133,7 +133,7 @@ void HiRes1Engine::init() {
if (!static_cast<Files_DOS33 *>(_files)->open("MYSTHOUS.DSK"))
error("Failed to open MYSTHOUS.DSK");
} else
- _files = new PlainFiles();
+ _files = new Files_Plain();
_graphics = new Graphics_v1(*_display);