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,64 @@
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 LCD_H
13
+#define LCD_H
14
+
15
+#include <QObject>
16
+#include <QVector>
17
+
18
+#ifdef CHAR_WIDTH
19
+#undef CHAR_WIDTH
20
+#endif
21
+
22
+//! This class contains LCD functions and buffer
23
+class LCD : public QObject
24
+{
25
+	Q_OBJECT
26
+
27
+	public:
28
+		static const int CHAR_WIDTH = 8; //!< Width of the char in pixels
29
+		static const int CHAR_HEIGHT = 8; //!< Height of the char in pixels
30
+
31
+		static const int WIDTH = 40; //!< Chars per row
32
+		static const int HEIGHT = 30; //!< Chars per column
33
+
34
+		static const int COLOR_MASK = 0x0f; //!< Char color mask, two colors per byte
35
+		static const int COLOR_SHIFT = 4; //!< Char color shift, background color is high 4 bits, foreground color is low 4 bits
36
+
37
+		//! LCD buffer
38
+		struct Buffer
39
+		{
40
+			QVector<QVector<unsigned char>> charData = QVector<QVector<unsigned char>>(HEIGHT, QVector<unsigned char>(WIDTH)); //!< Char buffer
41
+			QVector<QVector<unsigned char>> colorData = QVector<QVector<unsigned char>>(HEIGHT, QVector<unsigned char>(WIDTH)); //!< Background and foreground color buffer
42
+		};
43
+
44
+		LCD(QObject *parent = nullptr);
45
+
46
+		void reset();
47
+
48
+		void refresh();
49
+
50
+		void clear();
51
+		void setChar(unsigned char c, int x, int y, unsigned char charColor, unsigned char backgroundColor);
52
+
53
+		void scroll();
54
+
55
+		void update();
56
+
57
+	private:
58
+		QVector<Buffer> buffer = { Buffer(), Buffer() }; //!< First buffer is using as canvas for painting, the second one is a copy ready to show
59
+
60
+	signals:
61
+		void updateBufferSignal(LCD::Buffer buffer);
62
+};
63
+
64
+#endif