-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathspecification.cpp
More file actions
157 lines (139 loc) · 7.27 KB
/
Copy pathspecification.cpp
File metadata and controls
157 lines (139 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// File: specification.cpp
/*
Pep9CPU is a CPU simulator for executing microcode sequences to
implement instructions in the instruction set of the Pep/9 computer.
Copyright (C) 2010 J. Stanley Warford, Pepperdine University
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "specification.h"
#include <QDebug>
Specification::Specification()
{
}
MemSpecification::MemSpecification(int memoryAddress, int memoryValue, int numberBytes) {
memAddress = memoryAddress;
memValue = memoryValue;
numBytes = numberBytes;
}
void MemSpecification::setUnitPre(MainMemory *mainMemory, CpuPane *) {
if (numBytes == 1) {
mainMemory->setMemPrecondition(memAddress, memValue);
}
else { // numBytes == 2
mainMemory->setMemPrecondition(memAddress, memValue / 256);
mainMemory->setMemPrecondition(memAddress + 1, memValue % 256);
}
}
bool MemSpecification::testUnitPost(MainMemory *mainMemory, CpuPane *, QString &errorString) {
if (numBytes == 1) {
if (mainMemory->testMemPostcondition(memAddress, memValue)) {
return true;
}
errorString = "// ERROR: Unit test failed for byte Mem[0x" +
QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper() + "].";
return false;
}
else { // numBytes == 2
if ((mainMemory->testMemPostcondition(memAddress, memValue / 256)) && (mainMemory->testMemPostcondition(memAddress + 1, memValue % 256))) {
return true;
}
errorString = "// ERROR: Unit test failed for word Mem[0x" +
QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper() + "].";
return false;
}
}
QString MemSpecification::getSourceCode() {
return "Mem[0x"
+ QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper()
+ "]=0x"
+ (numBytes == 1 ?
QString("%1").arg(memValue, 2, 16, QLatin1Char('0')).toUpper() :
QString("%1").arg(memValue, 4, 16, QLatin1Char('0')).toUpper()) ;
}
RegSpecification::RegSpecification(Enu::EMnemonic registerAddress, int registerValue) {
regAddress = registerAddress;
regValue = registerValue;
}
void RegSpecification::setUnitPre(MainMemory *, CpuPane *cpuPane) {
cpuPane->setRegPrecondition(regAddress, regValue);
}
bool RegSpecification::testUnitPost(MainMemory *, CpuPane *cpuPane, QString &errorString) {
if (cpuPane->testRegPostcondition(regAddress, regValue)) {
return true;
}
switch (regAddress) {
case Enu::A: errorString = "// ERROR: Unit test failed for register A."; return false;
case Enu::X: errorString = "// ERROR: Unit test failed for register X."; return false;
case Enu::SP: errorString = "// ERROR: Unit test failed for register SP."; return false;
case Enu::PC: errorString = "// ERROR: Unit test failed for register PC."; return false;
case Enu::IR: errorString = "// ERROR: Unit test failed for register IR."; return false;
case Enu::T1: errorString = "// ERROR: Unit test failed for register T1."; return false;
case Enu::T2: errorString = "// ERROR: Unit test failed for register T2."; return false;
case Enu::T3: errorString = "// ERROR: Unit test failed for register T3."; return false;
case Enu::T4: errorString = "// ERROR: Unit test failed for register T4."; return false;
case Enu::T5: errorString = "// ERROR: Unit test failed for register T5."; return false;
case Enu::T6: errorString = "// ERROR: Unit test failed for register T6."; return false;
case Enu::MARA: errorString = "// ERROR: Unit test failed for MARA."; return false;
case Enu::MARB: errorString = "// ERROR: Unit test failed for MARB."; return false;
case Enu::MDR: errorString = "// ERROR: Unit test failed for MDR."; return false;
default: return false;
}
}
QString RegSpecification::getSourceCode() {
switch (regAddress) {
case Enu::A: return "A=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::X: return "X=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::SP: return "SP=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::PC: return "PC=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::IR: return "IR=0x" + QString("%1").arg(regValue, 6, 16, QLatin1Char('0')).toUpper();
case Enu::T1: return "T1=0x" + QString("%1").arg(regValue, 2, 16, QLatin1Char('0')).toUpper();
case Enu::T2: return "T2=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::T3: return "T3=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::T4: return "T4=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::T5: return "T5=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::T6: return "T6=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::MARA: return "MARA=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::MARB: return "MARB=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
case Enu::MDR: return "MDR=0x" + QString("%1").arg(regValue, 4, 16, QLatin1Char('0')).toUpper();
default: return "";
}
}
StatusBitSpecification::StatusBitSpecification(Enu::EMnemonic statusBitAddress, bool statusBitValue) {
nzvcsAddress = statusBitAddress;
nzvcsValue = statusBitValue;
}
void StatusBitSpecification::setUnitPre(MainMemory *, CpuPane *cpuPane) {
cpuPane->setStatusPrecondition(nzvcsAddress, nzvcsValue);
}
bool StatusBitSpecification::testUnitPost(MainMemory *, CpuPane *cpuPane, QString &errorString) {
if (cpuPane->testStatusPostcondition(nzvcsAddress, nzvcsValue)) {
return true;
}
switch (nzvcsAddress) {
case Enu::N: errorString = "// ERROR: Unit test failed for status bit N."; return false;
case Enu::Z: errorString = "// ERROR: Unit test failed for status bit Z."; return false;
case Enu::V: errorString = "// ERROR: Unit test failed for status bit V."; return false;
case Enu::C: errorString = "// ERROR: Unit test failed for status bit C."; return false;
case Enu::S: errorString = "// ERROR: Unit test failed for status bit S."; return false;
default: return false;
}
}
QString StatusBitSpecification::getSourceCode() {
switch (nzvcsAddress) {
case Enu::N: return "N=" + QString("%1").arg(nzvcsValue);
case Enu::Z: return "Z=" + QString("%1").arg(nzvcsValue);
case Enu::V: return "V=" + QString("%1").arg(nzvcsValue);
case Enu::C: return "C=" + QString("%1").arg(nzvcsValue);
case Enu::S: return "S=" + QString("%1").arg(nzvcsValue);
default: return "";
}
}