Browse code

Add source code of the XiPC emulator

Pawel Jablonski authored on 17/03/2023 16:46:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,75 @@
1
+/*
2
+ * Author: Pawel Jablonski
3
+ * E-mail: pj@xirx.net
4
+ * WWW: xirx.net
5
+ * GIT: git.xirx.net
6
+ *
7
+ * License: You can use this code however you like
8
+ * but leave information about the original author.
9
+ * Code is free for non-commercial and commercial use.
10
+ */
11
+
12
+#ifndef FS_H
13
+#define FS_H
14
+
15
+#include <QObject>
16
+#include <QString>
17
+#include <QByteArray>
18
+#include <QVector>
19
+#include <QFile>
20
+#include <QDir>
21
+#include <QFileInfoList>
22
+#include <QRegularExpression>
23
+
24
+//! This class contains file system functions
25
+class FS : public QObject
26
+{
27
+	Q_OBJECT
28
+
29
+	public:
30
+		static const int NAME_MAX_LENGTH = 12; //!< Maximum name length of the file
31
+
32
+		static const int BLOCK_SIZE = 256; //!<  Virtual block size available to address by communication bus between motherboard and CPU
33
+
34
+		static const int DIR_ENTRY_SIZE = 16; //!< Size of the header with information about file
35
+		static const int DIR_SIZE_FIELD_SIZE = 2; //!< Size of the size field in the header
36
+		static const int DIR_MAX_QUANTITY = 64; //!< Maximum quantity of files in directory
37
+
38
+		static const int FILE_MAX_SIZE = 32768; //!< Maximum size of the file
39
+
40
+		//! This struct contains a name of the file
41
+		struct Name
42
+		{
43
+			QVector<unsigned char> data = QVector<unsigned char>(NAME_MAX_LENGTH + 1); //!< Name of the file
44
+		};
45
+
46
+		//! This struct contains a size of the file
47
+		struct Size
48
+		{
49
+			unsigned char low; //!< Lower byte of the size
50
+			unsigned char high; //!< Higher byte of the size
51
+		};
52
+
53
+		//! This struct contains virtual block data
54
+		struct Block
55
+		{
56
+			QVector<unsigned char> data = QVector<unsigned char>(BLOCK_SIZE); //!< Virtual block data
57
+		};
58
+
59
+		FS(QObject *parent = nullptr);
60
+
61
+		void reset();
62
+
63
+		void setPath(const QString &path);
64
+
65
+		bool open(const QString &dirName, const FS::Name &fileName, FS::Size &size);
66
+		bool list(const QString &dirName, FS::Size &size);
67
+
68
+		void readBlock(FS::Block &block, int number);
69
+
70
+	private:
71
+		QString path; //!< Path to the emulated file system on the local disk
72
+		QByteArray buffer; //!< Buffer used to loading whole file or a list with description of the files
73
+};
74
+
75
+#endif