# HG changeset patch # User František Kučera # Date 1513873102 -3600 # Node ID b589459129a9c6df592373a4af8e618e9390a1c0 # Parent 1dd99de3b1784250adb01b7af3d4813c63ea3c16 writeAddress() diff -r 1dd99de3b178 -r b589459129a9 c++/rgb-assembler/rgb-assembler.cpp --- a/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 17:06:39 2017 +0100 +++ b/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 17:18:22 2017 +0100 @@ -21,13 +21,13 @@ command_t readCommand(command_t * memory, address_t &index) { // TODO: map higher memory to static hardcoded areas or peripherals command_t * value = reinterpret_cast (memory + index); - index += sizeof (*value); + index += sizeof (*value) / sizeof (command_t); return *value; } address_t readAddress(command_t * memory, address_t &index) { address_t * value = reinterpret_cast (memory + index); - index += sizeof (*value); + index += sizeof (*value) / sizeof (command_t); return *value; } @@ -39,7 +39,14 @@ // command_t * m = (command_t*) (memory + index); command_t * m = reinterpret_cast (memory + index); *m = value; - index += sizeof (value); + index += sizeof (value) / sizeof (command_t); +} + +void writeAddress(command_t * memory, address_t &index, const address_t value) { + // command_t * m = (command_t*) (memory + index); + address_t * m = reinterpret_cast (memory + index); + *m = value; + index += sizeof (value) / sizeof (command_t); } int main(int argc, char* argv[]) { @@ -54,8 +61,7 @@ writeCommand(memory, a, CMD_SLEEP); writeCommand(memory, a, CMD_SLEEP); writeCommand(memory, a, CMD_GOTO); - writeCommand(memory, a, 8); - writeCommand(memory, a, 0); + writeAddress(memory, a, 8); writeCommand(memory, a, 1); writeCommand(memory, a, 1); writeCommand(memory, a, CMD_SLEEP);