forked from regarm/u8085
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal8085.cpp
116 lines (108 loc) · 3.13 KB
/
internal8085.cpp
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
#include "internal8085.h"
Internal8085::Internal8085(QObject *parent) :
QObject(parent),
upAddressLimit(0x3000),
lowAddressLimit(0x2000)
{
instructionTypeMapping();
byteCntMapping();
for(int address = lowAddressLimit;address < upAddressLimit;++address){
//qDebug() << address << "\n";
cells[address - lowAddressLimit].resize(8);
}
A.resize(8);
B.resize(8);
C.resize(8);
D.resize(8);
E.resize(8);
F.resize(8);
H.resize(8);
L.resize(8);
PC.resize(16);
SP.resize(16);
rIndexMap[tr("B")] = 0;
rIndexMap[tr("C")] = 1;
rIndexMap[tr("D")] = 2;
rIndexMap[tr("E")] = 3;
rIndexMap[tr("H")] = 4;
rIndexMap[tr("L")] = 5;
rIndexMap[tr("M")] = 6;
rIndexMap[tr("A")] = 7;
rpIndexMap[tr("B")] =0;
rpIndexMap[tr("D")] =1;
rpIndexMap[tr("H")] =2;
rpIndexMap[tr("SP")] =3;
rpsIndexMap[tr("B")] = 0;
rpsIndexMap[tr("D")] = 1;
rpwIndexMap[tr("B")] = 0;
rpwIndexMap[tr("D")] = 1;
rpwIndexMap[tr("H")] = 2;
rpwIndexMap[tr("PSW")] = 3;
regs[0] = &B;
regs[1] = &C;
regs[2] = &D;
regs[3] = &E;
regs[4] = &H;
regs[5] = &L;
regs[6] = NULL;
regs[7] = &A;
regs[8] = &temp;
connect(this, SIGNAL(accumulatorChanged()), this, SLOT(updateFlags()));
}
QString Internal8085::getValueAtCell(int index, bool &ok){
if(index < lowAddressLimit || index >= upAddressLimit){
ok = false;
return tr("");
}
ok = true;
return cells[index - lowAddressLimit].toString();
}
bool Internal8085::setValueAtCell(int index, QString val){
if(index < lowAddressLimit || index >= upAddressLimit){
return false;
}
cells[index - lowAddressLimit].setValue(val);
return true;
}
bool Internal8085::setValueAtCell(int index, int val){
if(index < lowAddressLimit || index >= upAddressLimit){
return false;
}
qDebug() << "in SetValueAtCell";
cells[index - lowAddressLimit].setValue(val);
return true;
}
void Internal8085::flagCChangedByUser(QString val){
setFlagC(val == tr("1"));
}
void Internal8085::flagPChangedByUser(QString val){
setFlagP(val == tr("1"));
}
void Internal8085::flagACChangedByUser(QString val){
setFlagAC(val == tr("1"));
}
void Internal8085::flagZChangedByUser(QString val){
setFlagZ(val == tr("1"));
}
void Internal8085::flagSChangedByUser(QString val){
setFlagS(val == tr("1"));
}
QString Internal8085::getValueOfM(bool &ok){
return getValueAtCell(((H.toInt()<<8) + L.toInt()), ok);
}
bool Internal8085::setValueofM(QString val){
val = val.toUpper().rightJustified(2, QLatin1Char('0'));
return setValueAtCell(((H.toInt()<<8) + L.toInt()), val);
}
void Internal8085::MCellChanged(QString str){
str = str.toUpper().rightJustified(2, QLatin1Char('0'));
int address = (H.toInt() << 8) + L.toInt();
if(address >= lowAddressLimit && address < upAddressLimit){
Register *MCell = &cells[address - lowAddressLimit];
bool ok;
uint64_t val = str.toLongLong(&ok, 16);
for(int i = 0;i < MCell->size();++i){
MCell->setBit(i,(val&(1LL<<(MCell->size() - i - 1))));
}
}
}