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 data on given position in memory and increments the index (position).
25 template<typename T> T read(command_t * memory, address_t &index) {
26 // TODO: for addresses: map higher memory to static hardcoded areas or peripherals
27 // TODO: sizeof (command_t) != 1 ?
28 T * value = reinterpret_cast<T*> (memory + index);
29 index += sizeof (*value) / sizeof (command_t);
34 * Writes data to given position in memory and increments the index (position).
36 template<typename T> void write(command_t * memory, address_t &index, const T value) {
37 // TODO: sizeof (command_t) != 1 ?
38 // T * m = (T*) (memory + index);
39 T * m = reinterpret_cast<T*> (memory + index);
41 index += sizeof (value) / sizeof (command_t);
44 int main(int argc, char* argv[]) {
46 setlocale(LC_ALL, "");
48 command_t * memory = (command_t*) malloc(MEMORY_SIZE);
52 write<command_t>(memory, a, CMD_SLEEP);
53 write<sleep_t>(memory, a, 255);
54 write<command_t>(memory, a, CMD_SLEEP);
55 write<sleep_t>(memory, a, 10);
56 write<command_t>(memory, a, CMD_SLEEP);
57 write<sleep_t>(memory, a, 255);
58 write<command_t>(memory, a, CMD_GOTO);
59 write<address_t>(memory, a, a + 4);
60 write<command_t>(memory, a, 1);
61 write<command_t>(memory, a, 1);
62 write<command_t>(memory, a, CMD_SLEEP);
63 write<sleep_t>(memory, a, 255);
64 write<command_t>(memory, a, CMD_END);
67 for (address_t i = 0; i < MEMORY_SIZE;) {
68 wprintf(L"command %d = ", i);
69 command_t ch = read<command_t>(memory, i);
76 i = read<address_t>(memory, i);
77 command.append("GOTO ");
80 command.append("SLEEP");
81 this_thread::sleep_for(chrono::milliseconds(read<sleep_t>(memory, i)));
84 command.append("END");
90 if (!command.empty()) {
91 wprintf(L"\t%s\n", command.c_str());
97 wprintf(L"all done\n");