12 typedef uint16_t address_t;
13 typedef uint8_t command_t;
14 typedef uint8_t sleep_t;
16 const address_t MEMORY_SIZE = 1024;
18 const command_t CMD_GOTO = 0x70;
19 const command_t CMD_SLEEP = 0xFF;
20 const command_t CMD_END = 0xED;
23 * Reads the command on given position in memory and increments the index (position).
25 command_t readCommand(command_t * memory, address_t &index) {
26 // TODO: map higher memory to static hardcoded areas or peripherals
27 command_t * value = reinterpret_cast<command_t*> (memory + index);
28 index += sizeof (*value) / sizeof (command_t);
32 address_t readAddress(command_t * memory, address_t &index) {
33 address_t * value = reinterpret_cast<address_t*> (memory + index);
34 index += sizeof (*value) / sizeof (command_t);
38 sleep_t readSleep(command_t * memory, address_t &index) {
39 // TODO: map higher memory to static hardcoded areas or peripherals
40 sleep_t * value = reinterpret_cast<sleep_t*> (memory + index);
41 index += sizeof (*value) / sizeof (command_t);
45 void writeCommand(command_t * memory, address_t &index, const command_t value) {
46 // command_t * m = (command_t*) (memory + index);
47 command_t * m = reinterpret_cast<command_t*> (memory + index);
49 index += sizeof (value) / sizeof (command_t);
52 void writeAddress(command_t * memory, address_t &index, const address_t value) {
53 // command_t * m = (command_t*) (memory + index);
54 address_t * m = reinterpret_cast<address_t*> (memory + index);
56 index += sizeof (value) / sizeof (command_t);
59 void writeSleep(command_t * memory, address_t &index, const sleep_t value) {
60 // command_t * m = (command_t*) (memory + index);
61 sleep_t * m = reinterpret_cast<sleep_t*> (memory + index);
63 index += sizeof (value) / sizeof (command_t);
66 int main(int argc, char* argv[]) {
68 setlocale(LC_ALL, "");
70 command_t * memory = (command_t*) malloc(MEMORY_SIZE);
74 writeCommand(memory, a, CMD_SLEEP);
75 writeSleep(memory, a, 255);
76 writeCommand(memory, a, CMD_SLEEP);
77 writeSleep(memory, a, 10);
78 writeCommand(memory, a, CMD_SLEEP);
79 writeSleep(memory, a, 255);
80 writeCommand(memory, a, CMD_GOTO);
81 writeAddress(memory, a, a+4);
82 writeCommand(memory, a, 1);
83 writeCommand(memory, a, 1);
84 writeCommand(memory, a, CMD_SLEEP);
85 writeSleep(memory, a, 255);
86 writeCommand(memory, a, CMD_END);
91 for (address_t i = 0; i < MEMORY_SIZE;) {
92 wprintf(L"command %d = ", i);
93 command_t ch = readCommand(memory, i);
100 i = readAddress(memory, i);
101 command.append("GOTO ");
104 command.append("SLEEP");
105 this_thread::sleep_for(chrono::milliseconds(readSleep(memory, i)));
108 command.append("END");
114 if (!command.empty()) {
115 wprintf(L"\t%s\n", command.c_str());
121 wprintf(L"all done\n");