Browse code

Update comments and fix the doxygen script

Pawel Jablonski authored on 25/01/2021 22:33:20
Showing 1 changed files
... ...
@@ -11,7 +11,7 @@
11 11
 
12 12
 #include "uromdata.h"
13 13
 
14
-//! Default constructor for creating an empty uRom opcode table
14
+//! Default constructor for creating an empty uROM opcode table
15 15
 URomData::URomData()
16 16
 {
17 17
 	this->data[0].fill(0);
Browse code

Add source code of the uROM generator

Pawel Jablonski authored on 24/01/2021 21:45:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,112 @@
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
+#include "uromdata.h"
13
+
14
+//! Default constructor for creating an empty uRom opcode table
15
+URomData::URomData()
16
+{
17
+	this->data[0].fill(0);
18
+	this->data[1].fill(0);
19
+}
20
+
21
+/**
22
+ * Add an instruction to the uROM opcode table
23
+ *
24
+ * @param instruction Instruction to add
25
+ */
26
+void URomData::addInstruction(const Instruction &instruction)
27
+{
28
+	int opcodeWidth = 1;
29
+
30
+	// Calculate how many consecutive opcodes the instruction uses
31
+	opcodeWidth *= ((instruction.getArg0() == Instruction::Arg::AB) ? 2 : 1);
32
+	opcodeWidth *= ((instruction.getArg0() == Instruction::Arg::ABXY) ? 4 : 1);
33
+
34
+	opcodeWidth *= ((instruction.getArg1() == Instruction::Arg::AB) ? 2 : 1);
35
+	opcodeWidth *= ((instruction.getArg1() == Instruction::Arg::ABXY) ? 4 : 1);
36
+
37
+	// Calculate how many steps is used by the instruction
38
+	int stepQuantity = qMin(instruction.getStepList().size(), INSTRUCTION_CYCLE_QUANTITY);
39
+
40
+	// Add instruction entrys to the opcode table
41
+	for(int i = 0; i < opcodeWidth; i++)
42
+	{
43
+		for(int s = 0; s < stepQuantity; s++)
44
+		{
45
+			// Calculate the base offset of the entry
46
+			int offsetBase = ((static_cast<int>(s) * INSTRUCTION_QUANTITY) + static_cast<int>(instruction.getOpcode()) + i);
47
+			Step step = instruction.getStepList().at(s);
48
+
49
+			// Fill only entries where the carry and the zero flags fit to the selected by instruction
50
+			for(int c = 0; c < 2; c++)
51
+			{
52
+				for(int z = 0; z < 2; z++)
53
+				{
54
+					if(!((instruction.getC() == Instruction::Flag::Any) || (static_cast<int>(instruction.getC()) == c)))
55
+					{
56
+						continue;
57
+					}
58
+
59
+					if(!((instruction.getZ() == Instruction::Flag::Any) || (static_cast<int>(instruction.getZ()) == z)))
60
+					{
61
+						continue;
62
+					}
63
+
64
+					int offset = (offsetBase + (c << ADDRESS_FLAG_C_POSITION) + (z << ADDRESS_FLAG_Z_POSITION));
65
+
66
+					this->data[0][offset] = step.getUCode().getCode0();
67
+					this->data[1][offset] = step.getUCode().getCode1();
68
+				}
69
+			}
70
+		}
71
+	}
72
+}
73
+
74
+/**
75
+ * Save a binary microcode to files
76
+ *
77
+ * @param urom0Path Path to the first output file
78
+ * @param urom1Path Path to the second output file
79
+ *
80
+ * @return Status of the save operation
81
+ */
82
+bool URomData::saveFiles(const QString &urom0Path, const QString &urom1Path)
83
+{
84
+	QFile urom0File(urom0Path);
85
+
86
+	// Try to save the first output file
87
+	if(urom0File.open(QIODevice::WriteOnly))
88
+	{
89
+		urom0File.write(reinterpret_cast<const char *>(this->data[0].constData()), UROM_SIZE);
90
+		urom0File.close();
91
+	}
92
+	else
93
+	{
94
+		return(false);
95
+	}
96
+
97
+	QFile urom1File(urom1Path);
98
+
99
+	// Try to save the second output file
100
+	if(urom1File.open(QIODevice::WriteOnly))
101
+	{
102
+		urom1File.write(reinterpret_cast<const char *>(this->data[1].constData()), UROM_SIZE);
103
+		urom1File.close();
104
+	}
105
+	else
106
+	{
107
+		return(false);
108
+	}
109
+
110
+	return(true);
111
+}
112
+