-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommands.cpp
131 lines (116 loc) · 2.55 KB
/
Commands.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "Commands.h"
/*
* This c'tor init the memory to the command env.
* Input:
* mem - the mem to work on.
*/
Commands::Commands(MemStore* mem) {
this->_mem = mem;
}
/*
* This function Handle the user input and check which command is appropriate to that input.
* Input:
* command - the user input for handle.
* Output: if the command is exists.
*/
bool Commands::commandsHandler(string command) {
Utilities::toLower(command);
//Help command
if (command == "help") {
CommandsHelp();
return true;
}
//Help with exists opcodes
else if (command == "opc" || command == "opcodes") {
opcodesHelp();
return true;
}
//Print the memory data
else if (command == "mem" || command == "memory") {
printMemory();
return true;
}
//Print the opcodes history
else if (command == "history" || command == "h") {
printHistory();
return true;
}
//Jump to opcode from the history
else if (command == "jmp") {
JMP();
return true;
}
//Clean screen
else if (command == "cls") {
cls();
return true;
}
//exit program
else if (command == "exit") {
exit(0);
return true;
}
return false;
}
/*
* This function print the memory data.
* Output: NULL.
*/
void Commands::printMemory() {
_mem->printMemory();
}
/*
* This function print all the exists commands.
* Output: NULL.
*/
void Commands::CommandsHelp() {
cout << "Commands:" << endl;
cout << "help, opc / opcodes, mem / memory, h / history, JMP, cls, exit" << endl;
}
/*
* This function print all the exists opcodes in the Interpreter.
* Output: NULL.
*/
void Commands::opcodesHelp() {
int i = 1;
for (const auto opcode : Utilities::OpcodesChars) {
cout << opcode.first << " ";
if (i % 7 == 0) {
cout << endl;
}
i++;
}
cout << endl;
}
/*
* This function print the opcodes history.
* Output: NULL.
*/
void Commands::printHistory() {
_mem->printHistory();
}
/*
* This function jump to given place from the opcodes history.
* Output: NULL.
*/
void Commands::JMP() {
string place;
//get place
cout << "Where: ";
getline(cin, place);
ValuesHandler* value = new ValuesHandler(place, _mem);
//runall the opcodes from this place
_mem->jmp(value->handler(true));
}
/*
* This function clean the screen and print the open message.
*/
void Commands::cls() {
system("cls");
cout << " ----------------------------" << endl;
cout << "| Noam Afergan | V5.0.0 |" << endl;
cout << "|----------------------------|" << endl;
cout << "| Assembly-Interpreter |" << endl;
cout << " ----------------------------" << endl;
cout << "(Note: Please start with the help command)" << endl << endl;
}