RASCSI/cpp/disk_image/disk_image_handle.h

55 lines
1.5 KiB
C
Raw Normal View History

2023-01-09 02:04:49 +00:00
//---------------------------------------------------------------------------
//
// SCSI Target Emulator RaSCSI (*^..^*)
// for Raspberry Pi
//
2023-01-11 03:08:22 +00:00
// Copyright (C) 2022-2023 akuker
2023-01-09 02:04:49 +00:00
//
// Base class for interfacing with disk images.
//
// [ DiskImageHandle ]
//
//---------------------------------------------------------------------------
#pragma once
2023-01-09 03:39:07 +00:00
#include <string>
#include <cstdint>
#include <vector>
2023-01-11 03:08:22 +00:00
#include <string_view>
2023-01-09 03:39:07 +00:00
using namespace std;
2023-01-09 02:04:49 +00:00
class DiskImageHandle
{
public:
2023-01-11 03:08:22 +00:00
DiskImageHandle(string_view path, int size, uint32_t blocks, off_t imgoff = 0);
virtual ~DiskImageHandle() = default;
2023-01-09 02:04:49 +00:00
void SetRawMode(bool raw) { cd_raw = raw; }; // CD-ROM raw mode setting
2023-01-11 03:08:22 +00:00
bool GetRawMode() const {return cd_raw;}
2023-01-09 02:04:49 +00:00
// Access
virtual bool Save() = 0; // Save and release all
2023-01-09 03:39:07 +00:00
virtual bool ReadSector(vector<uint8_t>& buf, int block) = 0; // Sector Read
virtual bool WriteSector(const vector<uint8_t>& buf, int block) = 0; // Sector Write
virtual bool GetCache(int index, int &track, uint32_t &serial) const = 0; // Get cache information
2023-01-09 02:04:49 +00:00
protected:
2023-01-11 03:08:22 +00:00
int GetSectorSize() const {return sec_size;}
int GetBlocksPerSector() const { return sec_blocks;}
string GetPath() const {return sec_path;}
off_t GetImgOffset() const {return imgoffset;}
off_t GetTrackOffset(int block) const;
off_t GetSectorOffset(int block) const;
private:
2023-01-09 02:04:49 +00:00
bool cd_raw = false;
2023-01-09 03:39:07 +00:00
string sec_path; // Path
2023-01-09 02:04:49 +00:00
int sec_size; // Sector Size (8=256, 9=512, 10=1024, 11=2048, 12=4096)
int sec_blocks; // Blocks per sector
off_t imgoffset; // Offset to actual data
};