From f13263d5ad475df7e0b18a8c5afd56bcb2706421 Mon Sep 17 00:00:00 2001 From: ksherlock Date: Tue, 18 May 2010 03:30:45 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@216 aa027e90-d47c-11dd-86d7-074df07e0730 --- Device/BlockDevice.cpp | 25 +---- Device/BlockDevice.h | 4 - Device/DeviceReader.cpp | 204 ---------------------------------------- Device/DeviceReader.h | 109 --------------------- 4 files changed, 1 insertion(+), 341 deletions(-) delete mode 100644 Device/DeviceReader.cpp delete mode 100644 Device/DeviceReader.h diff --git a/Device/BlockDevice.cpp b/Device/BlockDevice.cpp index 43345ed..a9a12ba 100644 --- a/Device/BlockDevice.cpp +++ b/Device/BlockDevice.cpp @@ -9,8 +9,7 @@ #include -#include -#include + #include @@ -38,19 +37,7 @@ void BlockDevice::zeroBlock(unsigned block) write(block, bp); } -AbstractBlockCache *BlockDevice::blockCache() -{ - if (!_cache) - { - _cache = createBlockCache(); - } - return _cache; -} -AbstractBlockCache *BlockDevice::createBlockCache() -{ - return new BlockCache(this); -} bool BlockDevice::mapped() { @@ -67,13 +54,3 @@ void BlockDevice::sync(TrackSector ts) sync(); } -void *BlockDevice::read(unsigned block) -{ - return NULL; -} - -void *BlockDevice::read(TrackSector ts) -{ - return NULL; -} - diff --git a/Device/BlockDevice.h b/Device/BlockDevice.h index 592bea2..97cd438 100644 --- a/Device/BlockDevice.h +++ b/Device/BlockDevice.h @@ -10,8 +10,6 @@ namespace Device { -class BlockCache; - class BlockDevice { public: @@ -40,8 +38,6 @@ public: protected: BlockDevice(); - friend class BlockCache; - virtual BlockCache *createBlockCache(); }; diff --git a/Device/DeviceReader.cpp b/Device/DeviceReader.cpp deleted file mode 100644 index fceb664..0000000 --- a/Device/DeviceReader.cpp +++ /dev/null @@ -1,204 +0,0 @@ - - -#include - -using namespace Device; - -DeviceReader::~DeviceReader() -{ -} - -void *DeviceReader::read(unsigned block) -{ - return NULL; -} - -void DeviceReader::read(TrackSector ts) -{ - return NULL; -} - -void DeviceReader::mapped() -{ - return false; -} - -#pragma mark - -#pragma mark ProDOS Order - -void ProDOSOrderDeviceReader::read(unsigned block, void *bp) -{ - std::memcpy(bp, read(block), 512); -} - -void ProDOSOrderDeviceReader::read(TrackSector ts, void *bp) -{ - std::memcpy(bp, read(ts), 256); -} - -void *ProDOSOrderDeviceReader::read(unsigned block) -{ - if (block > _blocks) - { - throw ProFUSE::Exception("Invalid block."); - } - return block * 512 + (uint8_t *)_data; -} - - -void *ProDOSOrderDeviceReader::read(TrackSector ts) -{ - unsigned block = (ts.track * 16 + ts.sector) / 2; - - if (block > _blocks) - { - throw ProFUSE::Exception("Invalid track/sector."); - } - - return (ts.track * 16 + ts.sector) * 256 + (uint8_t *)_data; -} - - -void ProDOSOrderDeviceReader::write(unsigned block, const void *bp) -{ - std::memcpy(read(block), bp, 512); -} - -void ProDOSOrderDeviceReader::write(TrackSector ts, const void *bp) -{ - std::memcpy(read(ts), bp, 256); -} - - -#pragma mark - -#pragma mark DOS Order - -const unsigned DOSMap[] = { - 0x00, 0x0e, 0x0d, 0x0c, - 0x0b, 0x0a, 0x09, 0x08, - 0x07, 0x06, 0x05, 0x04, - 0x03, 0x02, 0x01, 0x0f -}; - -void *DOSOrderDeviceReader::read(TrackSector ts) -{ - if (ts.track > _tracks || ts.sector > 16) - { - throw ProFUSE::Exception("Invalid track/sector."); - } - - return (ts.track * 16 + ts.sector) * 256 + (uint8_t *)_data; -} - - -void DOSOrderDeviceReader::read(unsigned block, void *bp) -{ - TrackSector ts(block >> 3, 0); - unsigned sector = (block & 0x07) << 1; - - for (unsigned i = 0; i < 2; ++i) - { - ts.sector = DOSMap[sector]; - std::memcpy(bp, read(ts), 256); - bp = 256 + (uint8_t *)bp; - ++sector; - } -} - - -void DOSOrderDeviceReader::read(TrackSector ts, void *bp) -{ - std::memcpy(bp, read(ts), 256); -} - - -void DOSOrderDeviceReader::write(unsigned block, const void *bp) -{ - TrackSector ts(block >> 3, 0); - unsigned sector = (block & 0x07) << 1; - - for (unsigned i = 0; i < 2; ++i) - { - ts.sector = DOSMap[sector]; - std::memcpy(read(ts), bp, 256); - bp = 256 + (const uint8_t *)bp; - ++sector; - } -} - -void DOSOrderDeviceReader::write(TrackSector ts, const void *bp) -{ - std::memcpy(read(ts), bp, 256); -} - - -#pragma mark - -#pragma mark FileDeviceReader - -FileDeviceReader::FileDeviceReader(int fd, unsigned blocks, bool readOnly) -{ - _fd = fd; - _readOnly = readOnly; - _blocks = blocks; -} - -bool FileDeviceReader::readOnly() -{ - return _readOnly; -} - -void FileDeviceReader::write(unsigned block, const void *bp) -{ - - off_t offset = block * 512; - - size_t ok = ::pwrite(_fd, bp, 512, offset); - - if (ok != 512) - throw ok < 0 - ? POSIXException(__METHOD__ ": Error writing block.", errno) - : Exception(__METHOD__ ": Error writing block."); -} - - -void FileDeviceReader::write(TrackSector ts, const void *bp) -{ - off_t offset = (ts.track * 16 + ts.sector) * 256; - size_t ok = ::pwrite(_fd, bp, 256, offset); - - if (ok != 256) - throw ok < 0 - ? POSIXException(__METHOD__ ": Error writing block.", errno) - : Exception(__METHOD__ ": Error writing block."); -} - - - - - - - - -void FileDeviceReader::read(unsigned block, void *bp) -{ - - off_t offset = block * 512; - - size_t ok = ::pread(_fd, bp, 512, offset); - - if (ok != 512) - throw ok < 0 - ? POSIXException(__METHOD__ ": Error reading block.", errno) - : Exception(__METHOD__ ": Error reading block."); -} - -void FileDeviceReader::read(TrackSector ts, void *bp) -{ - off_t offset = (ts.track * 16 + ts.sector) * 256; - size_t ok = ::pread(_fd, bp, 256, offset); - - if (ok != 256) - throw ok < 0 - ? POSIXException(__METHOD__ ": Error reading block.", errno) - : Exception(__METHOD__ ": Error reading block."); -} diff --git a/Device/DeviceReader.h b/Device/DeviceReader.h deleted file mode 100644 index e2e8c71..0000000 --- a/Device/DeviceReader.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef __DEVICEREADER_H__ -#define __DEVICEREADER_H__ - -#include - -namespace Device { - - -class DeviceReader { - public: - - virtual ~DeviceReader(); - - virtual void read(unsigned block, void *bp) = 0; - virtual void read(TrackSector ts, void *bp) = 0; - - virtual void write(unsigned block, const void *bp) = 0; - virtual void write(TrackSector ts, const void *bp) = 0; - - // direct access -- not always available. - - virtual void *read(unsigned block); - virtual void *read(TrackSector ts); - - virtual bool readOnly() = 0; - virtual bool mapped(); - -}; - -class FileDeviceReader : public DeviceReader { - - // does not assume ownership of fd. - FileDeviceReader(int fd, unsigned blocks, bool readOnly); - //virtual ~FileDeviceReader(); - -public: - - virtual bool readOnly(); - - - virtual void read(unsigned block, void *bp); - virtual void read(TrackSector ts, void *bp); - - virtual void write(unsigned block, const void *bp); - virtual void write(TrackSector ts, const void *bp); - - private: - - int _fd; - unsigned _blocks; - bool _readOnly; -} - -class MappedFileDeviceReader : public DeviceReader { - - protected: - - MappedFileDeviceReader(MappedFile *f, unsigned offset); - - void *_data; - - private: - MappedFile *_file -}; - -class ProDOSOrderDeviceReader : public MappedFileDeviceReader { - public: - - virtual void read(unsigned block, void *bp); - virtual void read(TrackSector ts, void *bp); - - virtual void write(unsigned block, const void *bp); - virtual void write(TrackSector ts, const void *bp); - - virtual void *read(unsigned block); - virtual void *read(TrackSector ts); - - private: - unsigned blocks; -}; - -// 16 sectors only. -class DOSOrderDeviceReader : public MappedFileDeviceReader { - public: - - virtual void read(unsigned block, void *bp); - virtual void read(TrackSector ts, void *bp); - - virtual void write(unsigned block, const void *bp); - virtual void write(TrackSector ts, const void *bp); - - virtual void *read(TrackSector ts); - - private: - unsigned _tracks; -}; - - - -class NibbleDeviceReader : public MappedFileDeviceReader { - - private: - - std::vector _map; -}; - -} - -#endif \ No newline at end of file