1.1 --- a/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 17:22:55 2017 +0100
1.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 17:52:30 2017 +0100
1.3 @@ -4,10 +4,14 @@
1.4 #include <locale.h>
1.5 #include <cstring>
1.6
1.7 +#include <chrono>
1.8 +#include <thread>
1.9 +
1.10 using namespace std;
1.11
1.12 typedef uint16_t address_t;
1.13 typedef uint8_t command_t;
1.14 +typedef uint8_t sleep_t;
1.15
1.16 const address_t MEMORY_SIZE = 1024;
1.17
1.18 @@ -31,8 +35,11 @@
1.19 return *value;
1.20 }
1.21
1.22 -void writeMemoryChar(command_t(&memory)[MEMORY_SIZE], address_t &index, const int value) {
1.23 - memory[index] = value;
1.24 +sleep_t readSleep(command_t * memory, address_t &index) {
1.25 + // TODO: map higher memory to static hardcoded areas or peripherals
1.26 + sleep_t * value = reinterpret_cast<sleep_t*> (memory + index);
1.27 + index += sizeof (*value) / sizeof (command_t);
1.28 + return *value;
1.29 }
1.30
1.31 void writeCommand(command_t * memory, address_t &index, const command_t value) {
1.32 @@ -49,6 +56,13 @@
1.33 index += sizeof (value) / sizeof (command_t);
1.34 }
1.35
1.36 +void writeSleep(command_t * memory, address_t &index, const sleep_t value) {
1.37 + // command_t * m = (command_t*) (memory + index);
1.38 + sleep_t * m = reinterpret_cast<sleep_t*> (memory + index);
1.39 + *m = value;
1.40 + index += sizeof (value) / sizeof (command_t);
1.41 +}
1.42 +
1.43 int main(int argc, char* argv[]) {
1.44
1.45 setlocale(LC_ALL, "");
1.46 @@ -58,13 +72,17 @@
1.47 {
1.48 address_t a = 0;
1.49 writeCommand(memory, a, CMD_SLEEP);
1.50 + writeSleep(memory, a, 255);
1.51 writeCommand(memory, a, CMD_SLEEP);
1.52 + writeSleep(memory, a, 10);
1.53 writeCommand(memory, a, CMD_SLEEP);
1.54 + writeSleep(memory, a, 255);
1.55 writeCommand(memory, a, CMD_GOTO);
1.56 - writeAddress(memory, a, 8);
1.57 + writeAddress(memory, a, a+4);
1.58 writeCommand(memory, a, 1);
1.59 writeCommand(memory, a, 1);
1.60 writeCommand(memory, a, CMD_SLEEP);
1.61 + writeSleep(memory, a, 255);
1.62 writeCommand(memory, a, CMD_END);
1.63 }
1.64
1.65 @@ -84,6 +102,7 @@
1.66 break;
1.67 case CMD_SLEEP:
1.68 command.append("SLEEP");
1.69 + this_thread::sleep_for(chrono::milliseconds(readSleep(memory, i)));
1.70 break;
1.71 case CMD_END:
1.72 command.append("END");