2023-01-09 02:04:49 +00:00
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// X68000 EMULATOR "XM6"
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp)
|
|
|
|
|
// Copyright (C) 2014-2020 GIMONS
|
2023-01-11 03:08:22 +00:00
|
|
|
|
// Copyright (C) 2022-2023 akuker
|
2023-01-09 02:04:49 +00:00
|
|
|
|
//
|
|
|
|
|
// XM6i
|
|
|
|
|
// Copyright (C) 2010-2015 isaki@NetBSD.org
|
|
|
|
|
//
|
|
|
|
|
// Imported sava's Anex86/T98Next image and MO format support patch.
|
|
|
|
|
// Comments translated to english by akuker.
|
|
|
|
|
//
|
|
|
|
|
// [ DiskTrack and DiskCache ]
|
|
|
|
|
//
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "disk_image/disk_image_handle.h"
|
2023-01-11 03:08:22 +00:00
|
|
|
|
#include <string>
|
2023-01-09 02:04:49 +00:00
|
|
|
|
|
2023-01-09 03:39:07 +00:00
|
|
|
|
using namespace std;
|
|
|
|
|
|
2023-01-09 02:04:49 +00:00
|
|
|
|
class DiskTrack
|
|
|
|
|
{
|
2023-01-11 03:08:22 +00:00
|
|
|
|
private:
|
|
|
|
|
struct {
|
|
|
|
|
int track; // Track Number
|
|
|
|
|
int size; // Sector Size (8=256, 9=512, 10=1024, 11=2048, 12=4096)
|
|
|
|
|
int sectors; // Number of sectors(<0x100)
|
|
|
|
|
uint32_t length; // Data buffer length
|
|
|
|
|
uint8_t* buffer; // Data buffer
|
|
|
|
|
bool init; // Is it initilized?
|
|
|
|
|
bool changed; // Changed flag
|
|
|
|
|
uint32_t maplen; // Changed map length
|
|
|
|
|
bool* changemap; // Changed map
|
|
|
|
|
bool raw; // RAW mode flag
|
|
|
|
|
off_t imgoffset; // Offset to actual data
|
|
|
|
|
} dt;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DiskTrack();
|
|
|
|
|
~DiskTrack();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class DiskCache;
|
|
|
|
|
|
|
|
|
|
void Init(int track, int size, int sectors, bool raw = false, off_t imgoff = 0);
|
|
|
|
|
bool Load(const string& path);
|
|
|
|
|
bool Save(const string& path);
|
|
|
|
|
|
|
|
|
|
// Read / Write
|
|
|
|
|
bool ReadSector(vector<uint8_t>& buf, int sec) const; // Sector Read
|
|
|
|
|
bool WriteSector(const vector<uint8_t>& buf, int sec); // Sector Write
|
|
|
|
|
|
|
|
|
|
// Get track
|
|
|
|
|
int GetTrack() const
|
|
|
|
|
{
|
|
|
|
|
return dt.track;
|
|
|
|
|
}
|
2023-01-09 02:04:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DiskCache : public DiskImageHandle
|
|
|
|
|
{
|
2023-01-11 03:08:22 +00:00
|
|
|
|
public:
|
|
|
|
|
// Internal data definition
|
|
|
|
|
typedef struct {
|
|
|
|
|
DiskTrack* disktrk; // Disk Track
|
|
|
|
|
uint32_t serial; // Serial
|
|
|
|
|
} cache_t;
|
|
|
|
|
|
|
|
|
|
DiskCache(const string& path, int size, uint32_t blocks, off_t imgoff = 0);
|
|
|
|
|
~DiskCache();
|
|
|
|
|
|
|
|
|
|
// Access
|
|
|
|
|
bool Save() override; // Save and release all
|
|
|
|
|
bool ReadSector(vector<uint8_t>& buf, int block) override; // Sector Read
|
|
|
|
|
bool WriteSector(const vector<uint8_t>& buf, int block) override; // Sector Write
|
|
|
|
|
bool GetCache(int index, int& track, uint32_t& serial) const override; // Get cache information
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Number of tracks to cache
|
|
|
|
|
static const int CacheMax = 16;
|
|
|
|
|
|
|
|
|
|
// Internal Management
|
|
|
|
|
void Clear(); // Clear all tracks
|
|
|
|
|
DiskTrack* Assign(int track); // Load track
|
|
|
|
|
bool Load(int index, int track, DiskTrack* disktrk = nullptr); // Load track
|
|
|
|
|
void UpdateSerialNumber(); // Update serial number
|
|
|
|
|
|
|
|
|
|
// Internal data
|
|
|
|
|
array<cache_t, CacheMax> cache; // Cache management
|
|
|
|
|
|
|
|
|
|
uint32_t serial; // Last serial number
|
|
|
|
|
};
|