VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
FSDescriptors.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "CoreObject.h"
16#include "DiskTypes.h"
17#include "FSTypes.h"
18
19namespace vc64 {
20
21/* To create a FSDevice, the layout parameters of the represendet device have
22 * to be provided. This is done by passing a structure of type FSDeviceLayout
23 * which contains physical properties such as the number of cylinders and heads
24 * and logical parameters such as the number of sectors per track.
25 *
26 * FSDeviceDescriptors can be obtained in several ways. If a descriptor for
27 * diskette is needed, it can be created by specifiying the disk type. If a
28 * D64 file is given, a suitable device contructor can be created from this
29 * file.
30 */
31
32struct FSDeviceDescriptor : CoreObject {
33
34 // DOS type
35 DOSType dos = DOS_TYPE_NODOS;
36
37 // Number of cylinders
38 isize numCyls = 0;
39
40 // Number of heads
41 isize numHeads = 0;
42
43
44 //
45 // Initializing
46 //
47
48 FSDeviceDescriptor() { }
49
50 // Creates a device descriptor for a standard disk
51 FSDeviceDescriptor(DiskType type, DOSType dos = DOS_TYPE_CBM);
52
53 // Creates a device descriptor from a D64 file
54 FSDeviceDescriptor(const class D64File &d64);
55
56 const char *objectName() const override { return "FSLayout"; }
57
58
59 //
60 // Performing integrity checks
61 //
62
63 bool isCylinderNr(Cylinder c) const { return 1 <= c && c <= numCyls; }
64 bool isHeadNr(Head h) const { return h == 0 || h == 1; }
65 bool isTrackNr(Track t) const { return 1 <= t && t <= numCyls * numHeads; }
66 bool isValidLink(TSLink ref) const;
67
68
69 //
70 // Querying device properties
71 //
72
73 isize numTracks() const { return numCyls * numHeads; }
74 isize speedZone(Cylinder track) const;
75 isize numSectors(Cylinder track) const;
76 isize numBlocks() const;
77
78
79 //
80 // Translating blocks, tracks, sectors, and heads
81 //
82
83 Cylinder cylNr(Track t) const { return t <= numCyls ? t : t - numCyls; }
84 Head headNr(Track t) const { return t <= numCyls ? 0 : 1; }
85 Track trackNr(Cylinder c, Head h) const { return c + h * numCyls; }
86
87 TSLink tsLink(Block b) const;
88 Track trackNr(Block b) const { return tsLink(b).t; }
89 Sector sectorNr(Block b) const { return tsLink(b).s; }
90
91 Block blockNr(TSLink ts) const;
92 Block blockNr(Track t, Sector s) const { return blockNr(TSLink{t,s}); }
93 Block blockNr(Cylinder c, Head h, Sector s) const { return blockNr(trackNr(c,h), s); }
94
95
96 //
97 // Ordering blocks
98 //
99
100public:
101
102 bool nextBlock(Block b, Block *nb) const;
103 TSLink nextBlockRef(TSLink b) const;
104};
105
106}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
@ DOS_TYPE_CBM
C64 CBM file system.
Definition FSTypes.h:29
@ DOS_TYPE_NODOS
No file system.
Definition FSTypes.h:28