9 typedef uint16_t address_t;
10 typedef uint8_t command_t;
12 const address_t MEMORY_SIZE = 1024;
14 const command_t CMD_GOTO = 100;
15 const command_t CMD_SLEEP = 101;
16 const command_t CMD_END = 102;
19 * Reads the command on given position in memory and increments the index (position).
21 command_t readCommand(command_t * memory, address_t &index) {
22 // TODO: map higher memory to static hardcoded areas or peripherals
23 command_t * value = reinterpret_cast<command_t*> (memory + index);
24 index += sizeof (*value) / sizeof (command_t);
28 address_t readAddress(command_t * memory, address_t &index) {
29 address_t * value = reinterpret_cast<address_t*> (memory + index);
30 index += sizeof (*value) / sizeof (command_t);
34 void writeMemoryChar(command_t(&memory)[MEMORY_SIZE], address_t &index, const int value) {
35 memory[index] = value;
38 void writeCommand(command_t * memory, address_t &index, const command_t value) {
39 // command_t * m = (command_t*) (memory + index);
40 command_t * m = reinterpret_cast<command_t*> (memory + index);
42 index += sizeof (value) / sizeof (command_t);
45 void writeAddress(command_t * memory, address_t &index, const address_t value) {
46 // command_t * m = (command_t*) (memory + index);
47 address_t * m = reinterpret_cast<address_t*> (memory + index);
49 index += sizeof (value) / sizeof (command_t);
52 int main(int argc, char* argv[]) {
54 setlocale(LC_ALL, "");
56 command_t * memory = (command_t*) malloc(MEMORY_SIZE);
60 writeCommand(memory, a, CMD_SLEEP);
61 writeCommand(memory, a, CMD_SLEEP);
62 writeCommand(memory, a, CMD_SLEEP);
63 writeCommand(memory, a, CMD_GOTO);
64 writeAddress(memory, a, 8);
65 writeCommand(memory, a, 1);
66 writeCommand(memory, a, 1);
67 writeCommand(memory, a, CMD_SLEEP);
68 writeCommand(memory, a, CMD_END);
73 for (address_t i = 0; i < MEMORY_SIZE;) {
74 wprintf(L"command %d = ", i);
75 command_t ch = readCommand(memory, i);
82 i = readAddress(memory, i);
83 command.append("GOTO ");
86 command.append("SLEEP");
89 command.append("END");
95 if (!command.empty()) {
96 wprintf(L"\t%s\n", command.c_str());
102 wprintf(L"all done\n");