-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsim.cpp
More file actions
124 lines (98 loc) · 2.82 KB
/
Copy pathsim.cpp
File metadata and controls
124 lines (98 loc) · 2.82 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
// File: sim.cpp
/*
Pep8CPU is a CPU simulator for executing microcode sequences to
implement instructions in the instruction set of the Pep/8 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 "sim.h"
#include "enu.h"
#include <QDebug>
using namespace Enu;
QVector<quint8> Sim::Mem(65536);
bool Sim::nBit, Sim::zBit, Sim::vBit, Sim::cBit;
QVector<quint8> Sim::regBank(32);
quint8 Sim::MARA = 0;
quint8 Sim::MARB = 0;
quint8 Sim::MDR = 0;
Enu::MainBusState Sim::mainBusState;
QSet<int> Sim::modifiedBytes;
bool Sim::memReadPrevStep = false;
bool Sim::memWritePrevStep = false;
QList<Code *> Sim::codeList;
int Sim::cycleCount; // used to storing the number of cycles in a simulation
int Sim::microProgramCounter;
int Sim::microCodeCurrentLine;
QStringList Sim::microcodeSourceList;
void Sim::setMicrocodeSourceList() {
Sim::microcodeSourceList.clear();
for (int i = 0; i < Sim::codeList.length(); i++) {
Sim::microcodeSourceList.append(Sim::codeList.at(i)->getSourceCode());
}
}
int Sim::readByte(int memAddr)
{
return Mem[memAddr & 0xffff];
}
void Sim::writeByte(int memAddr, int value)
{
qDebug() << "Wrote byte " << memAddr << " with value " << value;
Mem[memAddr & 0xffff] = value;
modifiedBytes.insert(memAddr & 0xffff);
}
bool Sim::aluFnIsUnary(int fn)
{
switch (fn) {
case 0:
return true;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
return false;
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
return true;
default:
break;
}
return false;
}
bool Sim::atEndOfSim()
{
return microProgramCounter >= cycleCount;
// we use this because of special cases with
// some simulations being very short (2 lines in particular).
// return microCodeCurrentLine + 1 >= codeList.size() - 1; // old and tired
}
void Sim::initMRegs()
{
regBank[22] = 0x00;
regBank[23] = 0x01;
regBank[24] = 0x02;
regBank[25] = 0x03;
regBank[26] = 0x04;
regBank[27] = 0x08;
regBank[28] = 0xFA;
regBank[29] = 0xFC;
regBank[30] = 0xFE;
regBank[31] = 0xFF;
}