diff options
author | Walter van Niftrik | 2016-03-23 11:11:37 +0100 |
---|---|---|
committer | Walter van Niftrik | 2016-06-06 20:35:49 +0200 |
commit | 4af9f32d3f12badb0573db203c2949ec5173aae6 (patch) | |
tree | 9a58eedc8924c8e7ea99f9879883fef501d9683c /engines/adl | |
parent | ffbc4da0b0b2f26f88ad94f75d84fe6facbcfd52 (diff) | |
download | scummvm-rg350-4af9f32d3f12badb0573db203c2949ec5173aae6.tar.gz scummvm-rg350-4af9f32d3f12badb0573db203c2949ec5173aae6.tar.bz2 scummvm-rg350-4af9f32d3f12badb0573db203c2949ec5173aae6.zip |
ADL: Add disk format abstraction
Diffstat (limited to 'engines/adl')
-rw-r--r-- | engines/adl/disk.cpp | 90 | ||||
-rw-r--r-- | engines/adl/disk.h | 81 | ||||
-rw-r--r-- | engines/adl/module.mk | 1 |
3 files changed, 172 insertions, 0 deletions
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp new file mode 100644 index 0000000000..b91efec1f1 --- /dev/null +++ b/engines/adl/disk.cpp @@ -0,0 +1,90 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/stream.h" + +#include "adl/disk.h" + +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)); +} + +Common::SeekableReadStream *DiskImage_DSK::createReadStream(uint track, uint sector, uint offset, uint size) const { + _f->seek((track * _sectorsPerTrack + sector) * _bytesPerSector + offset); + Common::SeekableReadStream *stream = _f->readStream(size * _bytesPerSector + _bytesPerSector - offset); + + if (_f->eos() || _f->err()) + error("Error reading disk image"); + + return stream; +} + +bool DiskImage_DSK::open(const Common::String &filename) { + assert(!_f->isOpen()); + + if (!_f->open(filename)) + return false; + + uint filesize = _f->size(); + switch (filesize) { + case 143360: + _tracks = 35; + _sectorsPerTrack = 16; + _bytesPerSector = 256; + break; + default: + warning("Unrecognized disk image '%s' of size %d bytes", filename.c_str(), filesize); + } + + return true; +} + +} // End of namespace Adl diff --git a/engines/adl/disk.h b/engines/adl/disk.h new file mode 100644 index 0000000000..0bf57c7661 --- /dev/null +++ b/engines/adl/disk.h @@ -0,0 +1,81 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/ptr.h" +#include "common/file.h" + +#ifndef ADL_DISK_H +#define ADL_DISK_H + +namespace Common { +class SeekableReadStream; +class String; +} + +namespace Adl { + +class DataBlock { +public: + virtual ~DataBlock() { } + + virtual bool isValid() const = 0; + virtual Common::SeekableReadStream *createReadStream() const = 0; +}; + +typedef Common::SharedPtr<DataBlock> DataBlockPtr; + +class DiskImage { +public: + DiskImage(); + virtual ~DiskImage(); + + 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; + +protected: + Common::File *_f; + uint _tracks, _sectorsPerTrack, _bytesPerSector; +}; + +class DiskImageDataBlock : public DataBlock { +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; +}; + +class DiskImage_DSK : public DiskImage { +public: + bool open(const Common::String &filename); + const DataBlockPtr getDataBlock(uint track, uint sector, uint offset, uint size) const; + Common::SeekableReadStream *createReadStream(uint track, uint sector, uint offset = 0, uint size = 0) const; +}; + +} // End of namespace Adl + +#endif diff --git a/engines/adl/module.mk b/engines/adl/module.mk index 7599957806..661d1b1991 100644 --- a/engines/adl/module.mk +++ b/engines/adl/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ adl.o \ adl_v2.o \ detection.o \ + disk.o \ display.o \ graphics.o \ graphics_v1.o \ |