franta-hg@0
|
1 |
#include <cstdlib>
|
franta-hg@0
|
2 |
#include <iostream>
|
franta-hg@0
|
3 |
#include <wchar.h>
|
franta-hg@0
|
4 |
#include <locale.h>
|
franta-hg@0
|
5 |
#include <cstring>
|
franta-hg@0
|
6 |
|
franta-hg@0
|
7 |
using namespace std;
|
franta-hg@0
|
8 |
|
franta-hg@0
|
9 |
typedef uint16_t address_t;
|
franta-hg@0
|
10 |
typedef uint8_t command_t;
|
franta-hg@0
|
11 |
|
franta-hg@0
|
12 |
const address_t MEMORY_SIZE = 1024;
|
franta-hg@0
|
13 |
|
franta-hg@0
|
14 |
const command_t CMD_GOTO = 100;
|
franta-hg@0
|
15 |
const command_t CMD_SLEEP = 101;
|
franta-hg@0
|
16 |
const command_t CMD_END = 102;
|
franta-hg@0
|
17 |
|
franta-hg@1
|
18 |
/**
|
franta-hg@1
|
19 |
* Reads the command on given position in memory and increments the index (position).
|
franta-hg@1
|
20 |
*/
|
franta-hg@1
|
21 |
command_t readCommand(command_t(&memory)[MEMORY_SIZE], address_t &index) {
|
franta-hg@0
|
22 |
// TODO: map higher memory to static hardcoded areas or peripherals
|
franta-hg@1
|
23 |
return memory[index++];
|
franta-hg@0
|
24 |
}
|
franta-hg@0
|
25 |
|
franta-hg@1
|
26 |
void writeMemoryChar(command_t(&memory)[MEMORY_SIZE], address_t &index, const int value) {
|
franta-hg@0
|
27 |
memory[index] = value;
|
franta-hg@0
|
28 |
}
|
franta-hg@0
|
29 |
|
franta-hg@1
|
30 |
void writeMemoryChar(command_t* memory[], address_t &index, const command_t value) {
|
franta-hg@0
|
31 |
*memory[index] = value;
|
franta-hg@0
|
32 |
}
|
franta-hg@0
|
33 |
|
franta-hg@0
|
34 |
int main(int argc, char* argv[]) {
|
franta-hg@0
|
35 |
|
franta-hg@0
|
36 |
setlocale(LC_ALL, "");
|
franta-hg@0
|
37 |
|
franta-hg@0
|
38 |
|
franta-hg@0
|
39 |
command_t memory[MEMORY_SIZE] = {
|
franta-hg@0
|
40 |
CMD_SLEEP,
|
franta-hg@0
|
41 |
CMD_SLEEP,
|
franta-hg@0
|
42 |
CMD_SLEEP,
|
franta-hg@0
|
43 |
CMD_END,
|
franta-hg@0
|
44 |
};
|
franta-hg@0
|
45 |
address_t memorySize = sizeof (memory) / sizeof (*memory);
|
franta-hg@0
|
46 |
|
franta-hg@0
|
47 |
|
franta-hg@1
|
48 |
for (address_t i = 0; i < memorySize;) {
|
franta-hg@0
|
49 |
command_t ch = readCommand(memory, i);
|
franta-hg@0
|
50 |
wprintf(L"command %d = %d\n", i, ch);
|
franta-hg@0
|
51 |
|
franta-hg@0
|
52 |
string command;
|
franta-hg@0
|
53 |
|
franta-hg@0
|
54 |
switch (ch) {
|
franta-hg@0
|
55 |
case CMD_GOTO:
|
franta-hg@0
|
56 |
command.append("GOTO");
|
franta-hg@0
|
57 |
break;
|
franta-hg@0
|
58 |
case CMD_SLEEP:
|
franta-hg@0
|
59 |
command.append("SLEEP");
|
franta-hg@0
|
60 |
break;
|
franta-hg@0
|
61 |
case CMD_END:
|
franta-hg@0
|
62 |
command.append("END");
|
franta-hg@0
|
63 |
i = memorySize;
|
franta-hg@0
|
64 |
break;
|
franta-hg@0
|
65 |
|
franta-hg@0
|
66 |
}
|
franta-hg@0
|
67 |
|
franta-hg@0
|
68 |
if (!command.empty()) {
|
franta-hg@0
|
69 |
wprintf(L"\t%s\n", command.c_str());
|
franta-hg@0
|
70 |
}
|
franta-hg@0
|
71 |
}
|
franta-hg@0
|
72 |
|
franta-hg@0
|
73 |
|
franta-hg@0
|
74 |
|
franta-hg@0
|
75 |
wprintf(L"all done\n");
|
franta-hg@0
|
76 |
return 0;
|
franta-hg@0
|
77 |
}
|
franta-hg@0
|
78 |
|