| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,219 @@ |
| 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 IO_H |
|
| 13 |
+#define IO_H |
|
| 14 |
+ |
|
| 15 |
+#include <QObject> |
|
| 16 |
+#include <QList> |
|
| 17 |
+#include <QVector> |
|
| 18 |
+#include <QDateTime> |
|
| 19 |
+#include <QThread> |
|
| 20 |
+#include <QCoreApplication> |
|
| 21 |
+ |
|
| 22 |
+#include "keyboard.h" |
|
| 23 |
+#include "led.h" |
|
| 24 |
+#include "lcd.h" |
|
| 25 |
+#include "rs232.h" |
|
| 26 |
+#include "rtc.h" |
|
| 27 |
+#include "speaker.h" |
|
| 28 |
+#include "fs.h" |
|
| 29 |
+ |
|
| 30 |
+//! This class contains IO functions. It is a motherboard simulation part for the CPU. |
|
| 31 |
+class IO : public QObject |
|
| 32 |
+{
|
|
| 33 |
+ Q_OBJECT |
|
| 34 |
+ |
|
| 35 |
+ public: |
|
| 36 |
+ static const unsigned char IN_DATA_MASK = 0x0f; //!< Input data mask for the data part of the BUS |
|
| 37 |
+ static const unsigned char IN_CONTROL_MASK = 0xf0; //!< Input data mask for the control bits part of the BUS |
|
| 38 |
+ |
|
| 39 |
+ static const unsigned char IN_CLOCK_BIT = (1 << 4); //!< Input clock control bit |
|
| 40 |
+ static const unsigned char IN_KEYBOARD_READY_BIT = (1 << 5); //!< Input "keyboard has data to read" control bit |
|
| 41 |
+ static const unsigned char IN_RS232_READY_BIT = (1 << 6); //!< Input "RS232 has data to read" control bit |
|
| 42 |
+ static const unsigned char IN_OPERATION_COMPLETE_BIT = (1 << 7); //!< Input operation completed control bit |
|
| 43 |
+ |
|
| 44 |
+ static const unsigned char OUT_DATA_MASK = 0x0f; //!< Output data mask for the data part of the BUS |
|
| 45 |
+ static const unsigned char OUT_CONTROL_MASK = 0xf0; //!< Output data mask for the control bits part of the BUS |
|
| 46 |
+ |
|
| 47 |
+ static const unsigned char OUT_HALF_BIT = (1 << 4); //!< Output "half selector of the byte" control bit |
|
| 48 |
+ static const unsigned char OUT_MODE_BIT = (1 << 5); //!< Output "register selection or data transision mode" control bit |
|
| 49 |
+ static const unsigned char OUT_RW_BIT = (1 << 6); //!< Output read/write control bit |
|
| 50 |
+ static const unsigned char OUT_DATA_READY_BIT = (1 << 7); //!< Input "data is ready to read from output" control bit |
|
| 51 |
+ |
|
| 52 |
+ static const unsigned char REG_SELECT_MASK = 0x0f; //!< Register selection mask |
|
| 53 |
+ |
|
| 54 |
+ static const unsigned char HALF_UP_DATA_MASK = 0xf0; //!< Upper half of the byte mask |
|
| 55 |
+ static const int HALF_DATA_OFFSET = 4; //!< Upper half of the byte offset |
|
| 56 |
+ |
|
| 57 |
+ IO(QObject *parent = nullptr); |
|
| 58 |
+ ~IO() override; |
|
| 59 |
+ |
|
| 60 |
+ IO(const IO &) = delete; |
|
| 61 |
+ IO &operator=(const IO &) = delete; |
|
| 62 |
+ IO(IO &&) = delete; |
|
| 63 |
+ IO &operator=(IO &&) = delete; |
|
| 64 |
+ |
|
| 65 |
+ void reset(); |
|
| 66 |
+ |
|
| 67 |
+ void keyboardKeyPress(int key, Qt::KeyboardModifiers modifiers); |
|
| 68 |
+ void ledSetRun(bool enable); |
|
| 69 |
+ void ledSetError(bool enable); |
|
| 70 |
+ void rs232Receive(const QString &text); |
|
| 71 |
+ void rtcSetDateTime(const QDateTime &dateTime); |
|
| 72 |
+ void speakerSetVolume(unsigned int volume); |
|
| 73 |
+ void fsSetPath(const QString &path); |
|
| 74 |
+ |
|
| 75 |
+ private: |
|
| 76 |
+ //!< List of motherboard's virtual registers |
|
| 77 |
+ enum RegAddress |
|
| 78 |
+ {
|
|
| 79 |
+ REG_KEYBOARD = 0, //!< Keyboard register |
|
| 80 |
+ REG_LED_COMMAND = 1, //!< LED register |
|
| 81 |
+ REG_ADDRESS_LOW = 2, //!< Lower address register |
|
| 82 |
+ REG_ADDRESS_HIGH = 3, //!< Upper address register |
|
| 83 |
+ REG_LCD_COLOR = 4, //!< LCD color register |
|
| 84 |
+ REG_LCD_CHAR = 5, //!< LCD char register |
|
| 85 |
+ REG_LCD_COMMAND = 6, //!< LCD command register |
|
| 86 |
+ REG_RS232_RX = 7, //!< RS232 receive register |
|
| 87 |
+ REG_RS232_TX = 8, //!< RS232 transmit register |
|
| 88 |
+ REG_RTC_FIELD = 9, //!< Real Time Clock data register |
|
| 89 |
+ REG_RTC_COMMAND = 10, //!< Real Time Clock command register |
|
| 90 |
+ REG_SPEAKER_FIELD = 11, //!< Speaker data register |
|
| 91 |
+ REG_SPEAKER_COMMAND = 12, //!< Speaker command register |
|
| 92 |
+ REG_FS_NAME = 13, //!< File System name register |
|
| 93 |
+ REG_FS_DATA = 14, //!< File System data register |
|
| 94 |
+ REG_FS_COMMAND = 15 //!< File System command register |
|
| 95 |
+ }; |
|
| 96 |
+ |
|
| 97 |
+ //!< List of LED commands |
|
| 98 |
+ enum LedCommand |
|
| 99 |
+ {
|
|
| 100 |
+ LED_RUN_OFF = 0, //!< Turn off run LED |
|
| 101 |
+ LED_RUN_ON, //!< Turn on run LED |
|
| 102 |
+ LED_ERROR_OFF, //!< Turn off error LED |
|
| 103 |
+ LED_ERROR_ON //!< Turn on error LED |
|
| 104 |
+ }; |
|
| 105 |
+ |
|
| 106 |
+ //!< List of LCD commands |
|
| 107 |
+ enum LcdCommand |
|
| 108 |
+ {
|
|
| 109 |
+ LCD_CLEAR = 0, //!< Clear the screen |
|
| 110 |
+ LCD_REFRESH, //!< Refresh the screen using data from the framebuffer |
|
| 111 |
+ LCD_SCROLL //!< Scroll up one line up the screen |
|
| 112 |
+ }; |
|
| 113 |
+ |
|
| 114 |
+ //!< List of Real Time Clock fields |
|
| 115 |
+ enum RtcField |
|
| 116 |
+ {
|
|
| 117 |
+ RTC_YEAR = 0, //!< Year |
|
| 118 |
+ RTC_MONTH, //!< Month |
|
| 119 |
+ RTC_DAY, //!< Day |
|
| 120 |
+ RTC_HOUR, //!< Hour |
|
| 121 |
+ RTC_MINUTE, //!< Minute |
|
| 122 |
+ RTC_SECOND //!< Second |
|
| 123 |
+ }; |
|
| 124 |
+ |
|
| 125 |
+ //!< List of Real Time Clock commands |
|
| 126 |
+ enum RtcCommand |
|
| 127 |
+ {
|
|
| 128 |
+ RTC_READ = 0, //!< Read current date and time |
|
| 129 |
+ RTC_WRITE //!< Set current date and time |
|
| 130 |
+ }; |
|
| 131 |
+ |
|
| 132 |
+ //!< List of Speaker fields |
|
| 133 |
+ enum SpeakerField |
|
| 134 |
+ {
|
|
| 135 |
+ SPEAKER_NOTE = 0, //!< Note number |
|
| 136 |
+ SPEAKER_TIME, //!< Time to play |
|
| 137 |
+ SPEAKER_FILL, //!< Percentage fill of the square wave |
|
| 138 |
+ SPEAKER_VOLUME //!< Volume |
|
| 139 |
+ }; |
|
| 140 |
+ |
|
| 141 |
+ //!< List of Speaker commands |
|
| 142 |
+ enum SpeakerCommand |
|
| 143 |
+ {
|
|
| 144 |
+ SPEAKER_CLEAR = 0, //!< Stop playing and clear the buffer |
|
| 145 |
+ SPEAKER_ADD_NOTE, //!< Add note to the buffer and play it |
|
| 146 |
+ }; |
|
| 147 |
+ |
|
| 148 |
+ //!< List of File System commands |
|
| 149 |
+ enum FSCommand |
|
| 150 |
+ {
|
|
| 151 |
+ FS_OPEN_APP = 0, //!< Open an application |
|
| 152 |
+ FS_OPEN_FILE, //!< Open a file |
|
| 153 |
+ FS_LIST_APP, //!< List all applications |
|
| 154 |
+ FS_LIST_FILE, //!< List all files |
|
| 155 |
+ FS_SIZE, //!< Get size of the file |
|
| 156 |
+ FS_READ_BLOCK //!< Read data from the block |
|
| 157 |
+ }; |
|
| 158 |
+ |
|
| 159 |
+ //!< This struct cointains a memory adddress |
|
| 160 |
+ struct Address |
|
| 161 |
+ {
|
|
| 162 |
+ unsigned char low; //!< Lower byte of the address |
|
| 163 |
+ unsigned char high; //!< Upper byte of the address |
|
| 164 |
+ }; |
|
| 165 |
+ |
|
| 166 |
+ unsigned char regSelected; //!< Selected virtual register number |
|
| 167 |
+ |
|
| 168 |
+ //!< This struct contains motherboard's virtual registers buffer |
|
| 169 |
+ struct |
|
| 170 |
+ {
|
|
| 171 |
+ unsigned char keyboard; //!< Keyboard buffer |
|
| 172 |
+ Address address; //!< Address buffer |
|
| 173 |
+ unsigned char lcdForegroundColor; //!< LCD foreground color buffer |
|
| 174 |
+ unsigned char lcdBackgroundColor; //!< LCD background color buffer |
|
| 175 |
+ unsigned char lcdChar; //!< LCD char buffer |
|
| 176 |
+ unsigned char rs232Rx; //!< RS232 receive buffer |
|
| 177 |
+ unsigned char rs232Tx; //!< RS232 transmit bufffer |
|
| 178 |
+ unsigned char rs232TxBufferFree; //!< RS232 transmit free space in buffer counter |
|
| 179 |
+ RTC::DateTime rtcField; //!< Real Time Clock buffer |
|
| 180 |
+ Speaker::Note speakerField; //!< Speaker buffer |
|
| 181 |
+ unsigned char speakerBufferFree; //!< Speaker free space in buffer counter |
|
| 182 |
+ FS::Name fsName; //!< File System name buffer |
|
| 183 |
+ FS::Size fsSize; //!< File System size buffer |
|
| 184 |
+ FS::Block fsBlock; //!< File System data block buffer |
|
| 185 |
+ } reg; |
|
| 186 |
+ |
|
| 187 |
+ volatile unsigned char in; //!< Input register buffer |
|
| 188 |
+ |
|
| 189 |
+ Keyboard keyboard; //!< Keyboard class instance used for emulation motherboard's IO part |
|
| 190 |
+ LED led; //!< LED class instance used for emulation motherboard's IO part |
|
| 191 |
+ LCD lcd; //!< LCD class instance used for emulation motherboard's IO part |
|
| 192 |
+ RS232 rs232; //!< RS232 class instance used for emulation motherboard's IO part |
|
| 193 |
+ RTC rtc; //!< Real Time Clock class instance used for emulation motherboard's IO part |
|
| 194 |
+ Speaker speaker; //!< Speaker class instance used for emulation motherboard's IO part |
|
| 195 |
+ FS fs; //!< File System class instance used for emulation motherboard's IO part |
|
| 196 |
+ |
|
| 197 |
+ signals: |
|
| 198 |
+ void updateLEDRunSignal(bool enable); |
|
| 199 |
+ void updateLEDErrorSignal(bool enable); |
|
| 200 |
+ |
|
| 201 |
+ void updateLCDBufferSignal(LCD::Buffer buffer); |
|
| 202 |
+ |
|
| 203 |
+ void updateRS232TxSignal(unsigned char c); |
|
| 204 |
+ void updateRS232RxSignal(unsigned char c); |
|
| 205 |
+ |
|
| 206 |
+ void updateRTCDateTimeSignal(QDateTime dateTime); |
|
| 207 |
+ |
|
| 208 |
+ void updateSpeakerStatusSignal(int bufferUsed); |
|
| 209 |
+ |
|
| 210 |
+ void inSignal(unsigned char in); |
|
| 211 |
+ |
|
| 212 |
+ public slots: |
|
| 213 |
+ void keyboardDataReadySlot(bool ready); |
|
| 214 |
+ void rs232DataReadySlot(bool ready); |
|
| 215 |
+ |
|
| 216 |
+ void outSlot(unsigned char out); |
|
| 217 |
+}; |
|
| 218 |
+ |
|
| 219 |
+#endif |