# HG changeset patch # User František Kučera # Date 1513962598 -3600 # Node ID 4b4fb847d01ae33471c494c7142c8251f7602706 # Parent 2ab3d728224939e046005869b5616dfa3fdd8481 GOTO_COMPARE diff -r 2ab3d7282249 -r 4b4fb847d01a c++/rgb-assembler/rgb-assembler.cpp --- a/c++/rgb-assembler/rgb-assembler.cpp Fri Dec 22 17:15:15 2017 +0100 +++ b/c++/rgb-assembler/rgb-assembler.cpp Fri Dec 22 18:09:58 2017 +0100 @@ -27,6 +27,16 @@ const command_t CMD_GOTO = 0x70; /** + * Compare values on two addresses and go to one of given three addresses. + * parameter: address_t a + * parameter: address_t b + * parameter: address_t GOTO target when a == b + * parameter: address_t GOTO target when a > b + * parameter: address_t GOTO target when a < b + */ +const command_t CMD_GOTO_COMPARE = 0x80; + +/** * Wait given time in ms. * parameter: sleep_t */ @@ -64,6 +74,8 @@ */ const command_t CMD_INVALID = 0x1; +// TODO: more commands, better numbers + /** * Reads data on given position in memory and increments the index (position). */ @@ -101,7 +113,7 @@ write(memory, a, CMD_SLEEP); write(memory, a, 255); write(memory, a, CMD_GOTO); - write(memory, a, a + 4); + write(memory, a, a + sizeof (address_t) + 2 * sizeof (command_t)); write(memory, a, CMD_INVALID); write(memory, a, CMD_INVALID); write(memory, a, CMD_SLEEP); @@ -115,6 +127,12 @@ write(memory, a, 0); write(memory, a, CMD_DECREMENT); write(memory, a, 0); + write(memory, a, CMD_GOTO_COMPARE); + write(memory, a, 0); + write(memory, a, 0 + sizeof (command_t) + sizeof (sleep_t)); + write(memory, a, a - 3 * sizeof (address_t) - 2 * sizeof (command_t)); + write(memory, a, 0); + write(memory, a, a + sizeof (address_t)); write(memory, a, CMD_END); } @@ -158,6 +176,27 @@ wprintf(L"%sCREMENT %*d → %02X\n", (ch == CMD_INCREMENT ? "IN" : "DE"), 5, address, value); break; } + case CMD_GOTO_COMPARE: + { + address_t aa = read(memory, i); + address_t ab = read(memory, i); + address_t eq = read(memory, i); + address_t gt = read(memory, i); + address_t lt = read(memory, i); + + byte_t a = read(memory, aa); + byte_t b = read(memory, ab); + + if (a == b) { + i = eq; + } else if (a > b) { + i = gt; + } else { + i = lt; + } + wprintf(L"GOTO COMPARE a = %02X, b = %02X, eq = %d, gt = %d, lt = %d → %d\n", a, b, eq, gt, lt, i); + break; + } case CMD_END: { wprintf(L"END\n");