c++/rgb-assembler/commands/IncrementDecrement.h
changeset 26 47ee91579133
parent 23 e85d2bfaff73
child 27 835bd4559e5c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/c++/rgb-assembler/commands/IncrementDecrement.h	Sun Dec 24 00:08:55 2017 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +#pragma once
     1.5 +
     1.6 +#include <wchar.h>
     1.7 +#include <chrono>
     1.8 +#include <thread>
     1.9 +
    1.10 +#include "../Command.h"
    1.11 +#include "../memory.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +namespace commands {
    1.16 +
    1.17 +class IncrementDecrement : public Command {
    1.18 +public:
    1.19 +
    1.20 +	IncrementDecrement(const bool increment) {
    1.21 +		this->increment = increment;
    1.22 +	}
    1.23 +
    1.24 +	void process(octet_t* memory, address_t& index) override {
    1.25 +		address_t address = read<address_t>(memory, index);
    1.26 +		address_t address_r = address;
    1.27 +		address_t address_w = address_r;
    1.28 +		octet_t value = read<octet_t>(memory, address_r);
    1.29 +		value = increment ? value + 1 : value - 1;
    1.30 +		write<octet_t>(memory, address_w, value);
    1.31 +		wprintf(L"%sCREMENT %*d → %02X\n", (increment ? "IN" : "DE"), 5, address, value);
    1.32 +	}
    1.33 +private:
    1.34 +	bool increment;
    1.35 +
    1.36 +};
    1.37 +
    1.38 +}