1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/c++/rgb-assembler/commands/GotoCompare.h Sat Dec 23 23:50:44 2017 +0100
1.3 @@ -0,0 +1,32 @@
1.4 +#pragma once
1.5 +
1.6 +#include <wchar.h>
1.7 +
1.8 +#include "../Command.h"
1.9 +
1.10 +namespace commands {
1.11 +
1.12 +class GotoCompare : public Command {
1.13 +public:
1.14 +
1.15 + void process(octet_t* memory, address_t& index) override {
1.16 + address_t aa = read<address_t>(memory, index);
1.17 + address_t ab = read<address_t>(memory, index);
1.18 + address_t eq = read<address_t>(memory, index);
1.19 + address_t gt = read<address_t>(memory, index);
1.20 + address_t lt = read<address_t>(memory, index);
1.21 +
1.22 + octet_t a = read<octet_t>(memory, aa);
1.23 + octet_t b = read<octet_t>(memory, ab);
1.24 +
1.25 + if (a == b) index = eq;
1.26 + else if (a > b) index = gt;
1.27 + else index = lt;
1.28 +
1.29 + wprintf(L"GOTO COMPARE a = %02X, b = %02X, eq = %d, gt = %d, lt = %d → %d\n", a, b, eq, gt, lt, index);
1.30 + }
1.31 +private:
1.32 +
1.33 +};
1.34 +
1.35 +}
2.1 --- a/c++/rgb-assembler/nbproject/configurations.xml Sat Dec 23 23:47:37 2017 +0100
2.2 +++ b/c++/rgb-assembler/nbproject/configurations.xml Sat Dec 23 23:50:44 2017 +0100
2.3 @@ -8,6 +8,7 @@
2.4 <itemPath>Command.h</itemPath>
2.5 <itemPath>commands/End.h</itemPath>
2.6 <itemPath>commands/Goto.h</itemPath>
2.7 + <itemPath>commands/GotoCompare.h</itemPath>
2.8 <itemPath>commands/Sleep.h</itemPath>
2.9 <itemPath>memory.h</itemPath>
2.10 <itemPath>types.h</itemPath>
2.11 @@ -55,6 +56,8 @@
2.12 </item>
2.13 <item path="commands/Goto.h" ex="false" tool="3" flavor2="0">
2.14 </item>
2.15 + <item path="commands/GotoCompare.h" ex="false" tool="3" flavor2="0">
2.16 + </item>
2.17 <item path="commands/Sleep.h" ex="false" tool="3" flavor2="0">
2.18 </item>
2.19 <item path="memory.h" ex="false" tool="3" flavor2="0">
2.20 @@ -93,6 +96,8 @@
2.21 </item>
2.22 <item path="commands/Goto.h" ex="false" tool="3" flavor2="0">
2.23 </item>
2.24 + <item path="commands/GotoCompare.h" ex="false" tool="3" flavor2="0">
2.25 + </item>
2.26 <item path="commands/Sleep.h" ex="false" tool="3" flavor2="0">
2.27 </item>
2.28 <item path="memory.h" ex="false" tool="3" flavor2="0">
3.1 --- a/c++/rgb-assembler/rgb-assembler.cpp Sat Dec 23 23:47:37 2017 +0100
3.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp Sat Dec 23 23:50:44 2017 +0100
3.3 @@ -9,6 +9,7 @@
3.4 #include "memory.h"
3.5 #include "Command.h"
3.6 #include "commands/Goto.h"
3.7 +#include "commands/GotoCompare.h"
3.8 #include "commands/Sleep.h"
3.9 #include "commands/End.h"
3.10 #include "commands/Color.h"
3.11 @@ -115,6 +116,7 @@
3.12
3.13 unordered_map<command_t, shared_ptr < Command>> commands = {
3.14 {CMD_GOTO, make_shared<commands::Goto>()},
3.15 + {CMD_GOTO_COMPARE, make_shared<commands::GotoCompare>()},
3.16 {CMD_SLEEP, make_shared<commands::Sleep>()},
3.17 {CMD_END, make_shared<commands::End>()},
3.18 {CMD_COLOR, make_shared<commands::Color>()},
3.19 @@ -147,24 +149,6 @@
3.20 wprintf(L"%sCREMENT %*d → %02X\n", (command == CMD_INCREMENT ? "IN" : "DE"), 5, address, value);
3.21 break;
3.22 }
3.23 - case CMD_GOTO_COMPARE:
3.24 - {
3.25 - address_t aa = read<address_t>(memory, i);
3.26 - address_t ab = read<address_t>(memory, i);
3.27 - address_t eq = read<address_t>(memory, i);
3.28 - address_t gt = read<address_t>(memory, i);
3.29 - address_t lt = read<address_t>(memory, i);
3.30 -
3.31 - octet_t a = read<octet_t>(memory, aa);
3.32 - octet_t b = read<octet_t>(memory, ab);
3.33 -
3.34 - if (a == b) i = eq;
3.35 - else if (a > b) i = gt;
3.36 - else i = lt;
3.37 -
3.38 - wprintf(L"GOTO COMPARE a = %02X, b = %02X, eq = %d, gt = %d, lt = %d → %d\n", a, b, eq, gt, lt, i);
3.39 - break;
3.40 - }
3.41 default:
3.42 {
3.43 wprintf(L"invalid command\n");