2009-09-04 22:16:00 +00:00
|
|
|
#ifndef __PRODOS_BITMAP_H__
|
|
|
|
#define __PRODOS_BITMAP_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
namespace ProDOS {
|
|
|
|
|
|
|
|
class Bitmap {
|
|
|
|
public:
|
|
|
|
Bitmap(unsigned blocks);
|
|
|
|
~Bitmap();
|
|
|
|
|
|
|
|
bool blockFree(unsigned block) const;
|
|
|
|
bool markBlock(unsigned block, bool inUse);
|
|
|
|
|
|
|
|
unsigned blocks() const;
|
|
|
|
unsigned bitmapBlocks() const;
|
|
|
|
|
2009-09-06 22:11:19 +00:00
|
|
|
unsigned freeBlocks() const;
|
|
|
|
|
|
|
|
int firstFreeBlock(unsigned startingBlock = 0) const;
|
|
|
|
int countUnusedBlocks(unsigned startingBlock = 0, unsigned maxSearch = -1) const;
|
|
|
|
|
|
|
|
int freeBlock(unsigned count = 1) const;
|
|
|
|
|
|
|
|
|
2009-09-04 22:16:00 +00:00
|
|
|
private:
|
|
|
|
static unsigned BlockMask(unsigned block);
|
|
|
|
static unsigned BlockIndex(unsigned block);
|
|
|
|
|
|
|
|
unsigned _blocks;
|
2009-09-06 22:11:19 +00:00
|
|
|
unsigned _freeBlocks;
|
2009-09-04 22:16:00 +00:00
|
|
|
unsigned _bitmapSize;
|
2009-09-06 22:11:19 +00:00
|
|
|
uint8_t *_bitmap;
|
|
|
|
|
2009-09-04 22:16:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline unsigned Bitmap::blocks() const
|
|
|
|
{
|
|
|
|
return _blocks;
|
|
|
|
}
|
|
|
|
|
2009-09-06 22:11:19 +00:00
|
|
|
inline unsigned Bitmap::freeBlocks() const
|
|
|
|
{
|
|
|
|
return _blocks;
|
|
|
|
}
|
|
|
|
|
2009-09-04 22:16:00 +00:00
|
|
|
inline unsigned Bitmap::bitmapBlocks() const
|
|
|
|
{
|
|
|
|
return _bitmapSize >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned Bitmap::BlockMask(unsigned block)
|
|
|
|
{
|
|
|
|
return 0x80 >> (block & 0x07);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned Bitmap::BlockIndex(unsigned block)
|
|
|
|
{
|
|
|
|
return block >> 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Bitmap::blockFree(unsigned block) const
|
|
|
|
{
|
|
|
|
if (block >= _blocks) return false;
|
|
|
|
return (_bitmap[BlockIndex(block)] & BlockMask(block)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|