mirror of https://github.com/akuker/RASCSI.git
Ran formatting tool
This commit is contained in:
parent
8e48e72bf1
commit
9ba4a9243d
|
@ -108,7 +108,7 @@ void Disk::Open(const Filepath& path)
|
|||
|
||||
// Cache initialization
|
||||
assert (!disk.dcache);
|
||||
disk.dcache = DiskImageHandleFactory::CreateFileAccess(path, disk.size, disk.blocks, disk.image_offset);
|
||||
disk.dcache = DiskImageHandleFactory::CreateDiskImageHandle(path, disk.size, disk.blocks, disk.image_offset);
|
||||
|
||||
// Can read/write open
|
||||
Fileio fio;
|
||||
|
|
|
@ -533,7 +533,7 @@ int SCSICD::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
|
|||
// Recreate the disk cache
|
||||
Filepath path;
|
||||
track[index]->GetPath(path);
|
||||
disk.dcache = DiskImageHandleFactory::CreateFileAccess(path, GetSectorSizeShiftCount(), GetBlockCount());
|
||||
disk.dcache = DiskImageHandleFactory::CreateDiskImageHandle(path, GetSectorSizeShiftCount(), GetBlockCount());
|
||||
disk.dcache->SetRawMode(rawfile);
|
||||
|
||||
// Reset data index
|
||||
|
|
|
@ -5,45 +5,50 @@
|
|||
//
|
||||
// Copyright (C) 2022 akuker
|
||||
//
|
||||
// Base class for interfacing with disk images.
|
||||
// Base class for interfacing with disk images.
|
||||
//
|
||||
// [ DiskImageHandle ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "disk_image/disk_image_handle.h"
|
||||
|
||||
DiskImageHandle::DiskImageHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff){
|
||||
DiskImageHandle::DiskImageHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff)
|
||||
{
|
||||
|
||||
serial = 0;
|
||||
serial = 0;
|
||||
sec_path = path;
|
||||
sec_size = size;
|
||||
sec_blocks = blocks;
|
||||
imgoffset = imgoff;
|
||||
}
|
||||
DiskImageHandle::~DiskImageHandle(){
|
||||
|
||||
DiskImageHandle::~DiskImageHandle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
off_t DiskImageHandle::GetSectorOffset(int block){
|
||||
off_t DiskImageHandle::GetSectorOffset(int block)
|
||||
{
|
||||
|
||||
int sector_num = block & 0xff;
|
||||
return (off_t)sector_num << sec_size;
|
||||
}
|
||||
|
||||
off_t DiskImageHandle::GetTrackOffset(int block){
|
||||
off_t DiskImageHandle::GetTrackOffset(int block)
|
||||
{
|
||||
|
||||
// Assuming that all tracks hold 256 sectors
|
||||
int track_num = block >> 8;
|
||||
|
||||
// Calculate offset (previous tracks are considered to hold 256 sectors)
|
||||
off_t offset = ((off_t)track_num << 8);
|
||||
if (cd_raw) {
|
||||
if (cd_raw)
|
||||
{
|
||||
ASSERT(sec_size == 11);
|
||||
offset *= 0x930;
|
||||
offset += 0x10;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
offset <<= sec_size;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
//
|
||||
// Copyright (C) 2022 akuker
|
||||
//
|
||||
// Base class for interfacing with disk images.
|
||||
// Base class for interfacing with disk images.
|
||||
//
|
||||
// [ DiskImageHandle ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -18,28 +18,26 @@
|
|||
class DiskImageHandle
|
||||
{
|
||||
public:
|
||||
DiskImageHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
DiskImageHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
virtual ~DiskImageHandle();
|
||||
|
||||
void SetRawMode(bool raw) { cd_raw = raw; }; // CD-ROM raw mode setting
|
||||
void SetRawMode(bool raw) { cd_raw = raw; }; // CD-ROM raw mode setting
|
||||
|
||||
// Access
|
||||
virtual bool Save() = 0; // Save and release all
|
||||
virtual bool ReadSector(BYTE *buf, int block) = 0; // Sector Read
|
||||
virtual bool WriteSector(const BYTE *buf, int block) = 0; // Sector Write
|
||||
virtual bool GetCache(int index, int& track, DWORD& serial) const = 0; // Get cache information
|
||||
virtual bool Save() = 0; // Save and release all
|
||||
virtual bool ReadSector(BYTE *buf, int block) = 0; // Sector Read
|
||||
virtual bool WriteSector(const BYTE *buf, int block) = 0; // Sector Write
|
||||
virtual bool GetCache(int index, int &track, DWORD &serial) const = 0; // Get cache information
|
||||
|
||||
protected:
|
||||
bool cd_raw = false;
|
||||
DWORD serial; // Last serial number
|
||||
Filepath sec_path; // Path
|
||||
DWORD serial; // Last serial number
|
||||
Filepath sec_path; // Path
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
off_t GetTrackOffset(int block);
|
||||
off_t GetSectorOffset(int block);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
|
||||
#include "disk_image/disk_image_handle.h"
|
||||
|
||||
enum DiskImageHandleType {
|
||||
enum DiskImageHandleType
|
||||
{
|
||||
eRamCache,
|
||||
eMmapFile,
|
||||
ePosixFile,
|
||||
ePosixFile,
|
||||
};
|
||||
|
||||
class DiskImageHandleFactory
|
||||
|
@ -27,7 +28,7 @@ public:
|
|||
static void SetFileAccessMethod(DiskImageHandleType method) { current_access_type = method; };
|
||||
static DiskImageHandleType GetFileAccessMethod() { return current_access_type; };
|
||||
|
||||
static DiskImageHandle *CreateDiskImageHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
static DiskImageHandle *CreateDiskImageHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
|
||||
private:
|
||||
static DiskImageHandleType current_access_type;
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
//
|
||||
// The operating system will do some caching of the data to prevent direct
|
||||
// drive access for each read/write. So, instead of implementing our own
|
||||
// caching mechanism (like in disk_track_cache.h), we just rely on the
|
||||
// caching mechanism (like in disk_track_cache.h), we just rely on the
|
||||
// operating system.
|
||||
//
|
||||
// [ MmapFileAccess ]
|
||||
// [ MmapFilehandle ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -31,39 +31,42 @@
|
|||
// Direct file access that will map the file into virtual memory space
|
||||
//
|
||||
//===========================================================================
|
||||
MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
MmapFileHandle::MmapFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
{
|
||||
ASSERT(blocks > 0);
|
||||
ASSERT(imgoff >= 0);
|
||||
|
||||
fd = open(path.GetPath(), O_RDWR);
|
||||
if(fd < 0){
|
||||
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
|
||||
}
|
||||
LOGWARN("%s opened %s", __PRETTY_FUNCTION__, path.GetPath());
|
||||
fd = open(path.GetPath(), O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
|
||||
}
|
||||
LOGWARN("%s opened %s", __PRETTY_FUNCTION__, path.GetPath());
|
||||
struct stat sb;
|
||||
if(fstat(fd, &sb) < 0){
|
||||
LOGWARN("Unable to run fstat. Errno:%d", errno);
|
||||
}
|
||||
printf("Size: %llu\n", (uint64_t)sb.st_size);
|
||||
if (fstat(fd, &sb) < 0)
|
||||
{
|
||||
LOGWARN("Unable to run fstat. Errno:%d", errno);
|
||||
}
|
||||
printf("Size: %llu\n", (uint64_t)sb.st_size);
|
||||
|
||||
LOGWARN("%s mmap-ed file of size: %llu", __PRETTY_FUNCTION__, (uint64_t)sb.st_size);
|
||||
LOGWARN("%s mmap-ed file of size: %llu", __PRETTY_FUNCTION__, (uint64_t)sb.st_size);
|
||||
|
||||
// int x = EACCES;
|
||||
|
||||
memory_block = (const char*)mmap(NULL, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
memory_block = (const char *)mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
int errno_val = errno;
|
||||
if (memory_block == MAP_FAILED) {
|
||||
LOGWARN("Unabled to memory map file %s", path.GetPath());
|
||||
LOGWARN(" Errno:%d", errno_val);
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
if (memory_block == MAP_FAILED)
|
||||
{
|
||||
LOGWARN("Unabled to memory map file %s", path.GetPath());
|
||||
LOGWARN(" Errno:%d", errno_val);
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
MmapFileHandle::~MmapFileHandle()
|
||||
{
|
||||
munmap((void*)memory_block, sb.st_size);
|
||||
munmap((void *)memory_block, sb.st_size);
|
||||
close(fd);
|
||||
|
||||
// Force the OS to save any cached data to the disk
|
||||
|
@ -97,8 +100,7 @@ bool MmapFileHandle::WriteSector(const BYTE *buf, int block)
|
|||
|
||||
ASSERT((block * sec_size) <= (sb.st_size + sec_size));
|
||||
|
||||
memcpy((void*)&memory_block[(block * sec_size)], buf, sec_size);
|
||||
memcpy((void *)&memory_block[(block * sec_size)], buf, sec_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
// The operating system will do some caching of the data to prevent direct
|
||||
// drive access for each read/write. So, instead of implementing our own
|
||||
// caching mechanism (like in disk_track_cache.h), we just rely on the
|
||||
// caching mechanism (like in disk_track_cache.h), we just rely on the
|
||||
// operating system.
|
||||
//
|
||||
// [ MmapFileHandle ]
|
||||
|
@ -29,23 +29,21 @@ class MmapFileHandle : public DiskImageHandle
|
|||
{
|
||||
|
||||
public:
|
||||
MmapFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
MmapFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
~MmapFileHandle();
|
||||
|
||||
void SetRawMode(BOOL raw); // CD-ROM raw mode setting
|
||||
void SetRawMode(BOOL raw); // CD-ROM raw mode setting
|
||||
|
||||
// Access
|
||||
bool Save() { return true; }; // Save and release all
|
||||
bool ReadSector(BYTE *buf, int block); // Sector Read
|
||||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int& track, DWORD& serial) const { return true; }; // Get cache information
|
||||
|
||||
bool Save() { return true; }; // Save and release all
|
||||
bool ReadSector(BYTE *buf, int block); // Sector Read
|
||||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int &track, DWORD &serial) const { return true; }; // Get cache information
|
||||
|
||||
private:
|
||||
const char *memory_block;
|
||||
struct stat sb;
|
||||
struct stat sb;
|
||||
int fd;
|
||||
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,24 +20,25 @@
|
|||
// Direct file access that will map the file into virtual memory space
|
||||
//
|
||||
//===========================================================================
|
||||
PosixFileHandle::PosixFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
PosixFileHandle::PosixFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
{
|
||||
ASSERT(blocks > 0);
|
||||
ASSERT(imgoff >= 0);
|
||||
|
||||
|
||||
fd = open(path.GetPath(), O_RDWR);
|
||||
if(fd < 0){
|
||||
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
|
||||
return;
|
||||
}
|
||||
fd = open(path.GetPath(), O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
|
||||
return;
|
||||
}
|
||||
struct stat sb;
|
||||
if(fstat(fd, &sb) < 0){
|
||||
LOGWARN("Unable to run fstat. Errno:%d", errno);
|
||||
return;
|
||||
}
|
||||
if (fstat(fd, &sb) < 0)
|
||||
{
|
||||
LOGWARN("Unable to run fstat. Errno:%d", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGWARN("%s opened file of size: %llu", __PRETTY_FUNCTION__, (uint64_t)sb.st_size);
|
||||
LOGWARN("%s opened file of size: %llu", __PRETTY_FUNCTION__, (uint64_t)sb.st_size);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
@ -52,7 +53,8 @@ PosixFileHandle::~PosixFileHandle()
|
|||
|
||||
bool PosixFileHandle::ReadSector(BYTE *buf, int block)
|
||||
{
|
||||
if(!initialized){
|
||||
if (!initialized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -67,18 +69,20 @@ bool PosixFileHandle::ReadSector(BYTE *buf, int block)
|
|||
off_t offset = GetTrackOffset(block);
|
||||
offset += GetSectorOffset(block);
|
||||
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = read(fd, buf,sector_size_bytes);
|
||||
if(result != sector_size_bytes){
|
||||
LOGWARN("%s only read %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = read(fd, buf, sector_size_bytes);
|
||||
if (result != sector_size_bytes)
|
||||
{
|
||||
LOGWARN("%s only read %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PosixFileHandle::WriteSector(const BYTE *buf, int block)
|
||||
{
|
||||
if(!initialized){
|
||||
if (!initialized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -90,17 +94,15 @@ bool PosixFileHandle::WriteSector(const BYTE *buf, int block)
|
|||
|
||||
size_t sector_size_bytes = (size_t)1 << sec_size;
|
||||
|
||||
off_t offset = GetTrackOffset(block);
|
||||
offset += GetSectorOffset(block);
|
||||
off_t offset = GetTrackOffset(block);
|
||||
offset += GetSectorOffset(block);
|
||||
|
||||
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = write(fd, buf,sector_size_bytes);
|
||||
if(result != sector_size_bytes){
|
||||
LOGWARN("%s only wrote %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = write(fd, buf, sector_size_bytes);
|
||||
if (result != sector_size_bytes)
|
||||
{
|
||||
LOGWARN("%s only wrote %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,19 +18,18 @@ class PosixFileHandle : public DiskImageHandle
|
|||
{
|
||||
|
||||
public:
|
||||
PosixFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
PosixFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
~PosixFileHandle();
|
||||
|
||||
void SetRawMode(BOOL raw); // CD-ROM raw mode setting
|
||||
void SetRawMode(BOOL raw); // CD-ROM raw mode setting
|
||||
|
||||
// Access
|
||||
bool Save() { return true; }; // Save and release all
|
||||
bool ReadSector(BYTE *buf, int block); // Sector Read
|
||||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int& track, DWORD& serial) const { return true; }; // Get cache information
|
||||
|
||||
bool Save() { return true; }; // Save and release all
|
||||
bool ReadSector(BYTE *buf, int block); // Sector Read
|
||||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int &track, DWORD &serial) const { return true; }; // Get cache information
|
||||
|
||||
private:
|
||||
int fd;
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue