# HG changeset patch # User František Kučera # Date 1513898489 -3600 # Node ID 1d1cc6552542237b94fa9c2f0d0b2298d362cd58 # Parent efed38f454a06b784dedd50ee75b5634e29d76e5 debug output formatting diff -r efed38f454a0 -r 1d1cc6552542 c++/rgb-assembler/rgb-assembler.cpp --- a/c++/rgb-assembler/rgb-assembler.cpp Fri Dec 22 00:00:04 2017 +0100 +++ b/c++/rgb-assembler/rgb-assembler.cpp Fri Dec 22 00:21:29 2017 +0100 @@ -20,6 +20,7 @@ const command_t CMD_SLEEP = 0xFF; const command_t CMD_COLOR = 0xAA; const command_t CMD_END = 0xED; +const command_t CMD_INVALID = 0x1; // placeholder for unsupported command /** * Reads data on given position in memory and increments the index (position). @@ -59,53 +60,52 @@ write(memory, a, 255); write(memory, a, CMD_GOTO); write(memory, a, a + 4); - write(memory, a, 1); - write(memory, a, 1); + write(memory, a, CMD_INVALID); + write(memory, a, CMD_INVALID); write(memory, a, CMD_SLEEP); write(memory, a, 255); write(memory, a, CMD_COLOR); - write(memory, a, 50); - write(memory, a, 100); - write(memory, a, 150); + write(memory, a, 0); + write(memory, a, 200); + write(memory, a, 255); write(memory, a, CMD_END); } for (address_t i = 0; i < MEMORY_SIZE;) { - wprintf(L"command %d = ", i); + wprintf(L"command %*d = ", 4, i); command_t ch = read(memory, i); - wprintf(L"%X\n", ch); + wprintf(L"%02X ", ch); - string command; - color_t r; color_t g; color_t b; + sleep_t delay; + switch (ch) { case CMD_GOTO: i = read(memory, i); - command.append("GOTO "); + wprintf(L"GOTO %*d\n", 5, i); break; case CMD_SLEEP: - command.append("SLEEP"); - this_thread::sleep_for(chrono::milliseconds(read(memory, i))); + delay = read(memory, i); + wprintf(L"SLEEP %*d ms\n", 4, delay); + this_thread::sleep_for(chrono::milliseconds(delay)); break; case CMD_COLOR: - command.append("COLOR"); r = read(memory, i); g = read(memory, i); b = read(memory, i); + wprintf(L"COLOR %02X %02X %02X\n", r, g, b); break; case CMD_END: - command.append("END"); + wprintf(L"END\n"); i = MEMORY_SIZE; break; - + default: + wprintf(L"invalid command\n"); } - if (!command.empty()) { - wprintf(L"\t%s\n", command.c_str()); - } } free(memory);