6 #include <unordered_map>
12 #include "commands/Goto.h"
13 #include "commands/GotoCompare.h"
14 #include "commands/Sleep.h"
15 #include "commands/End.h"
16 #include "commands/Color.h"
17 #include "commands/IncrementDecrement.h"
21 int main(int argc, char* argv[]) {
23 setlocale(LC_ALL, "");
25 octet_t * memory = (octet_t*) malloc(MEMORY_SIZE);
27 // Sample program / data:
28 // TODO: load bytes from file, stdin, serial port, network…
31 write<command_t>(memory, a, CMD_SLEEP);
32 write<sleep_t>(memory, a, 255);
33 write<command_t>(memory, a, CMD_SLEEP);
34 write<sleep_t>(memory, a, 10);
35 write<command_t>(memory, a, CMD_SLEEP);
36 write<sleep_t>(memory, a, 255);
37 write<command_t>(memory, a, CMD_GOTO);
38 write<address_t>(memory, a, a + sizeof (address_t) + 2 * sizeof (command_t));
39 write<command_t>(memory, a, CMD_INVALID);
40 write<command_t>(memory, a, CMD_INVALID);
41 write<command_t>(memory, a, CMD_SLEEP);
42 write<sleep_t>(memory, a, 255);
43 write<command_t>(memory, a, CMD_COLOR);
44 write<led_t>(memory, a, 23);
45 write<color_t>(memory, a, 0);
46 write<color_t>(memory, a, 200);
47 write<color_t>(memory, a, 255);
48 write<command_t>(memory, a, CMD_INCREMENT);
49 write<address_t>(memory, a, 0);
50 write<command_t>(memory, a, CMD_DECREMENT);
51 write<address_t>(memory, a, 0);
52 write<command_t>(memory, a, CMD_GOTO_COMPARE);
53 write<address_t>(memory, a, 0);
54 write<address_t>(memory, a, 0 + sizeof (command_t) + sizeof (sleep_t));
55 write<address_t>(memory, a, a - 3 * sizeof (address_t) - 2 * sizeof (command_t));
56 write<address_t>(memory, a, 0);
57 write<address_t>(memory, a, a + sizeof (address_t));
58 write<command_t>(memory, a, CMD_END);
61 unordered_map<command_t, shared_ptr < Command>> commands = {
62 {CMD_GOTO, make_shared<commands::Goto>()},
63 {CMD_GOTO_COMPARE, make_shared<commands::GotoCompare>()},
64 {CMD_SLEEP, make_shared<commands::Sleep>()},
65 {CMD_END, make_shared<commands::End>()},
66 {CMD_COLOR, make_shared<commands::Color>()},
67 {CMD_INCREMENT, make_shared < commands::IncrementDecrement>(true, 1)},
68 {CMD_DECREMENT, make_shared < commands::IncrementDecrement>(false, 1)},
72 for (address_t i = 0; i < MEMORY_SIZE;) {
73 wprintf(L"command %*d = ", 4, i);
74 command_t commandCode = read<command_t>(memory, i);
75 wprintf(L"%02X ", commandCode);
77 shared_ptr<Command> command = commands[commandCode];
80 command->process(memory, i);
82 wprintf(L"invalid command\n");
88 wprintf(L"all done\n");