# HG changeset patch # User František Kučera # Date 1513875150 -3600 # Node ID d55ac7dbc2e6f7647c058e4d7386f63fc5319acc # Parent e0a48e475a77ef69acdf5e3a4bb3e30aa22f8a6f SLEEP diff -r e0a48e475a77 -r d55ac7dbc2e6 c++/rgb-assembler/rgb-assembler.cpp --- a/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 17:22:55 2017 +0100 +++ b/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 17:52:30 2017 +0100 @@ -4,10 +4,14 @@ #include #include +#include +#include + using namespace std; typedef uint16_t address_t; typedef uint8_t command_t; +typedef uint8_t sleep_t; const address_t MEMORY_SIZE = 1024; @@ -31,8 +35,11 @@ return *value; } -void writeMemoryChar(command_t(&memory)[MEMORY_SIZE], address_t &index, const int value) { - memory[index] = value; +sleep_t readSleep(command_t * memory, address_t &index) { + // TODO: map higher memory to static hardcoded areas or peripherals + sleep_t * value = reinterpret_cast (memory + index); + index += sizeof (*value) / sizeof (command_t); + return *value; } void writeCommand(command_t * memory, address_t &index, const command_t value) { @@ -49,6 +56,13 @@ index += sizeof (value) / sizeof (command_t); } +void writeSleep(command_t * memory, address_t &index, const sleep_t value) { + // command_t * m = (command_t*) (memory + index); + sleep_t * m = reinterpret_cast (memory + index); + *m = value; + index += sizeof (value) / sizeof (command_t); +} + int main(int argc, char* argv[]) { setlocale(LC_ALL, ""); @@ -58,13 +72,17 @@ { address_t a = 0; writeCommand(memory, a, CMD_SLEEP); + writeSleep(memory, a, 255); writeCommand(memory, a, CMD_SLEEP); + writeSleep(memory, a, 10); writeCommand(memory, a, CMD_SLEEP); + writeSleep(memory, a, 255); writeCommand(memory, a, CMD_GOTO); - writeAddress(memory, a, 8); + writeAddress(memory, a, a+4); writeCommand(memory, a, 1); writeCommand(memory, a, 1); writeCommand(memory, a, CMD_SLEEP); + writeSleep(memory, a, 255); writeCommand(memory, a, CMD_END); } @@ -84,6 +102,7 @@ break; case CMD_SLEEP: command.append("SLEEP"); + this_thread::sleep_for(chrono::milliseconds(readSleep(memory, i))); break; case CMD_END: command.append("END");