# HG changeset patch # User František Kučera # Date 1514069444 -3600 # Node ID 5ce09de7f9b74ef9bc292e873acc38a364ab2da0 # Parent e24883b00180ff556473993dcc7dfe9e934c0fd6 GOTO_COMPARE in class diff -r e24883b00180 -r 5ce09de7f9b7 c++/rgb-assembler/commands/GotoCompare.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c++/rgb-assembler/commands/GotoCompare.h Sat Dec 23 23:50:44 2017 +0100 @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include "../Command.h" + +namespace commands { + +class GotoCompare : public Command { +public: + + void process(octet_t* memory, address_t& index) override { + address_t aa = read(memory, index); + address_t ab = read(memory, index); + address_t eq = read(memory, index); + address_t gt = read(memory, index); + address_t lt = read(memory, index); + + octet_t a = read(memory, aa); + octet_t b = read(memory, ab); + + if (a == b) index = eq; + else if (a > b) index = gt; + else index = lt; + + wprintf(L"GOTO COMPARE a = %02X, b = %02X, eq = %d, gt = %d, lt = %d → %d\n", a, b, eq, gt, lt, index); + } +private: + +}; + +} diff -r e24883b00180 -r 5ce09de7f9b7 c++/rgb-assembler/nbproject/configurations.xml --- a/c++/rgb-assembler/nbproject/configurations.xml Sat Dec 23 23:47:37 2017 +0100 +++ b/c++/rgb-assembler/nbproject/configurations.xml Sat Dec 23 23:50:44 2017 +0100 @@ -8,6 +8,7 @@ Command.h commands/End.h commands/Goto.h + commands/GotoCompare.h commands/Sleep.h memory.h types.h @@ -55,6 +56,8 @@ + + @@ -93,6 +96,8 @@ + + diff -r e24883b00180 -r 5ce09de7f9b7 c++/rgb-assembler/rgb-assembler.cpp --- a/c++/rgb-assembler/rgb-assembler.cpp Sat Dec 23 23:47:37 2017 +0100 +++ b/c++/rgb-assembler/rgb-assembler.cpp Sat Dec 23 23:50:44 2017 +0100 @@ -9,6 +9,7 @@ #include "memory.h" #include "Command.h" #include "commands/Goto.h" +#include "commands/GotoCompare.h" #include "commands/Sleep.h" #include "commands/End.h" #include "commands/Color.h" @@ -115,6 +116,7 @@ unordered_map> commands = { {CMD_GOTO, make_shared()}, + {CMD_GOTO_COMPARE, make_shared()}, {CMD_SLEEP, make_shared()}, {CMD_END, make_shared()}, {CMD_COLOR, make_shared()}, @@ -147,24 +149,6 @@ wprintf(L"%sCREMENT %*d → %02X\n", (command == 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); - - octet_t a = read(memory, aa); - octet_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; - } default: { wprintf(L"invalid command\n");