-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox256instructions.cpp
More file actions
228 lines (208 loc) · 6.37 KB
/
box256instructions.cpp
File metadata and controls
228 lines (208 loc) · 6.37 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "box256machine.h"
#include <QVector>
#define paramA_r getRParamA(machine,pc)
#define paramB_r getRParamB(machine,pc)
#define paramC_r getRParamC(machine,pc)
#define paramA_w getWParamA(machine,pc)
#define paramB_w getWParamB(machine,pc)
#define paramC_w getWParamC(machine,pc)
Box256Instruction::Box256Instruction()
: accessParamA(AccessMethod::NONE),accessParamB(AccessMethod::NONE), accessParamC(AccessMethod::NONE)
{
}
Box256Instruction::~Box256Instruction(){}
//NOP
Box256InstructionNOP::Box256InstructionNOP() : Box256Instruction(){}
void Box256InstructionNOP::execute(Box256Machine *machine, BOXBYTE pc){}
//MOV
Box256InstructionMOV::Box256InstructionMOV() : Box256Instruction(){}
void Box256InstructionMOV::execute(Box256Machine *machine, BOXBYTE pc)
{
for(int i = paramC_r-1;i>=0;i--)//Work backwards as not to move prior values
{
if(accessParamA==AccessMethod::CONSTANT)
{
machine->writeValue(paramA_r,paramB_w + i);
}else
{
machine->writeValue(machine->getValue(AccessMethod::ADDRESS,paramA_w + i),paramB_w + i);
/*BOXBYTE pA = machine->getValue(AccessMethod::CONSTANT,pc+1);
if(accessParamA==AccessMethod::ADDRESS)
{
BOXBYTE val = machine->getValue(AccessMethod::ADDRESS,pA+i,false);
machine->writeValue(val,paramB_w + i);
}else
{
BOXBYTE addr = machine->getValue(AccessMethod::ADDRESS,pA,false);
BOXBYTE val = machine->getValue(AccessMethod::ADDRESS,addr+i);
machine->writeValue(val,paramB_w + i);
//machine->writeValue(machine->getValue(AccessMethod::ADDRESS,paramA_w + i),paramB_w + i);
}*/
}
}
}
//ADD
Box256InstructionADD::Box256InstructionADD() : Box256Instruction(){}
void Box256InstructionADD::execute(Box256Machine *machine, BOXBYTE pc)
{
machine->writeValue(paramA_r+paramB_r,paramC_w);
}
//SUB
Box256InstructionSUB::Box256InstructionSUB() : Box256Instruction(){}
void Box256InstructionSUB::execute(Box256Machine *machine, BOXBYTE pc)
{
machine->writeValue(paramB_r-paramA_r,paramC_w);
}
//JEQ
Box256InstructionJEQ::Box256InstructionJEQ() : Box256Instruction(){}
void Box256InstructionJEQ::execute(Box256Machine *machine, BOXBYTE pc)
{
if(paramA_r == paramB_r)
{
BOXBYTE pcLoc = machine->getPC(machine->getCurThread());
switch (accessParamC) {
case AccessMethod::CONSTANT:
{
machine->writeValue(machine->getValue(AccessMethod::ADDRESS,pcLoc)+paramC_r-0x4,pcLoc);
break;
}
default:
{
machine->writeValue(paramC_w-0x4,pcLoc);
break;
}
}
}
}
//MUL
Box256InstructionMUL::Box256InstructionMUL() : Box256Instruction(){}
void Box256InstructionMUL::execute(Box256Machine *machine, BOXBYTE pc)
{
machine->writeValue(paramA_r*paramB_r,paramC_w);
}
//DIV
Box256InstructionDIV::Box256InstructionDIV() : Box256Instruction(){}
void Box256InstructionDIV::execute(Box256Machine *machine, BOXBYTE pc)
{
if(paramB_r==0)
{
machine->writeValue(0,paramC_w);
}else
{
machine->writeValue(paramA_r/paramB_r,paramC_w);
}
}
//JMP
Box256InstructionJMP::Box256InstructionJMP() : Box256Instruction(){}
void Box256InstructionJMP::execute(Box256Machine *machine, BOXBYTE pc)
{
BOXBYTE pcLoc = machine->getPC(machine->getCurThread());
switch (accessParamA) {
case AccessMethod::CONSTANT:
{
machine->writeValue(machine->getValue(AccessMethod::ADDRESS,pcLoc)+paramA_r-0x4,pcLoc);
break;
}
default:
{
machine->writeValue(paramA_w-0x4,pcLoc);
break;
}
}
}
//JGR
Box256InstructionJGR::Box256InstructionJGR() : Box256Instruction(){}
void Box256InstructionJGR::execute(Box256Machine *machine, BOXBYTE pc)
{
if(paramA_r > paramB_r)
{
BOXBYTE pcLoc = machine->getPC(machine->getCurThread());
switch (accessParamC) {
case AccessMethod::CONSTANT:
{
machine->writeValue(machine->getValue(AccessMethod::ADDRESS,pcLoc)+paramC_r-0x4,pcLoc);
break;
}
default:
{
machine->writeValue(paramC_w-0x4,pcLoc);
break;
}
}
}
}
//PIX
Box256InstructionPIX::Box256InstructionPIX() : Box256Instruction(){}
void Box256InstructionPIX::execute(Box256Machine *machine, BOXBYTE pc)
{
machine->writePixel(paramB_r,paramA_r);
};
#include <QDebug>
//FLP
Box256InstructionFLP::Box256InstructionFLP() : Box256Instruction(){}
void Box256InstructionFLP::execute(Box256Machine *machine, BOXBYTE pc)
{
int numFLPs = paramC_r;
QVector<BOXBYTE> tmpBytesA, tmpBytesB;
for(int i=0;i<numFLPs;i++){
tmpBytesA.append(machine->getValue(AccessMethod::ADDRESS,paramA_w+i));
tmpBytesB.append(machine->getValue(AccessMethod::ADDRESS,paramB_w+i));
}
for(int i=0;i<numFLPs;i++){
machine->writeValue(tmpBytesA[i],paramB_w+ i);
}
for(int i=0;i<numFLPs;i++){
machine->writeValue(tmpBytesB[i],paramA_w+ i);
}
}
//THR
Box256InstructionTHR::Box256InstructionTHR() : Box256Instruction(){}
void Box256InstructionTHR::execute(Box256Machine *machine, BOXBYTE pc)
{
BOXBYTE pcLoc = machine->getPC(machine->getCurThread());
switch (accessParamA) {
case AccessMethod::CONSTANT:
{
machine->createThread(machine->getValue(AccessMethod::ADDRESS,pcLoc)+paramA_r);
break;
}
default:
{
machine->createThread(paramA_w);
break;
}
}
}
//MOD
Box256InstructionMOD::Box256InstructionMOD() : Box256Instruction(){}
void Box256InstructionMOD::execute(Box256Machine *machine, BOXBYTE pc)
{
if(paramB_r==0)
{
machine->writeValue(0,paramC_w);
}else
{
machine->writeValue(paramA_r % paramB_r,paramC_w);
}
}
//JNE
Box256InstructionJNE::Box256InstructionJNE() : Box256Instruction(){}
void Box256InstructionJNE::execute(Box256Machine *machine, BOXBYTE pc)
{
if(paramA_r != paramB_r)
{
BOXBYTE pcLoc = machine->getPC(machine->getCurThread());
switch (accessParamC) {
case AccessMethod::CONSTANT:
{
machine->writeValue(machine->getValue(AccessMethod::ADDRESS,pcLoc)+paramC_r-0x4,pcLoc);
break;
}
default:
{
machine->writeValue(paramC_w-0x4,pcLoc);
break;
}
}
}
}