-
Notifications
You must be signed in to change notification settings - Fork 0
/
coproc.h
101 lines (98 loc) · 2.58 KB
/
coproc.h
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
// Register Lib Done
#ifndef COPROC
#define COPROC
#include <string>
#include <fstream>
using namespace std;
class Coproc {
protected:
struct CoprocNode {
string name;
float value;
float* address;
CoprocNode* next;
};
string linkFile;
CoprocNode* root;
public:
Coproc(string _linkFile);
void init();
void setCoprocAddress(string registerName, float* ptr);
void setCoprocValue(string registerName, float value);
float getCoprocValue(string registerName);
float* getCoprocAddressValue(string registerName);
};
Coproc::Coproc(string _linkFile) {
this->linkFile = _linkFile;
this->root = nullptr;
}
void Coproc::init() {
ifstream registerList;
registerList.open(this->linkFile);
int countRegister = 1;
CoprocNode* preCoprocNode;
while(!registerList.eof()) {
CoprocNode* newNode = new CoprocNode;
newNode->value = 0;
newNode->address = nullptr;
registerList >> newNode->name;
if(countRegister == 1) {
root = newNode;
newNode->next = nullptr;
countRegister++;
}
else {
newNode->next = root;
root = newNode;
}
}
}
void Coproc::setCoprocAddress(string registerName, float* ptr) {
registerName = getWord(registerName, 1);
CoprocNode* seeker;
seeker = root;
while(seeker != nullptr) {
if(!seeker->name.compare(registerName)) {
seeker->address = ptr;
seeker->value = *(int*)(&seeker->address);
}
seeker = seeker->next;
}
}
void Coproc::setCoprocValue(string registerName, float _value) {
registerName = getWord(registerName, 1);
CoprocNode* seeker;
seeker = root;
while(seeker != nullptr) {
if(!seeker->name.compare(registerName)) {
seeker->value = _value;
seeker->address = (float*)(int)seeker->value;
}
seeker = seeker->next;
}
}
float* Coproc::getCoprocAddressValue(string registerName) {
registerName = getWord(registerName, 1);
CoprocNode* seeker;
seeker = root;
while(seeker != nullptr) {
if(!seeker->name.compare(registerName)) {
return seeker->address;
}
seeker = seeker->next;
}
return nullptr;
}
float Coproc::getCoprocValue(string registerName) {
registerName = getWord(registerName, 1);
CoprocNode* seeker;
seeker = root;
while(seeker != nullptr) {
if(!seeker->name.compare(registerName)) {
return seeker->value;
}
seeker = seeker->next;
}
return 0;
}
#endif