c++/rgb-assembler/commands/IncrementDecrement.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 24 Dec 2017 00:12:58 +0100
changeset 27 835bd4559e5c
parent 26 47ee91579133
child 29 10d6964e7b4a
permissions -rw-r--r--
parametric INCREMENT and DECREMENT
     1 #pragma once
     2 
     3 #include <wchar.h>
     4 #include <chrono>
     5 #include <thread>
     6 
     7 #include "../Command.h"
     8 #include "../memory.h"
     9 
    10 using namespace std;
    11 
    12 namespace commands {
    13 
    14 class IncrementDecrement : public Command {
    15 public:
    16 
    17 	IncrementDecrement(const bool increment, octet_t change) {
    18 		this->increment = increment;
    19 		this->change = change;
    20 	}
    21 
    22 	void process(octet_t* memory, address_t& index) override {
    23 		address_t address = read<address_t>(memory, index);
    24 		address_t address_r = address;
    25 		address_t address_w = address_r;
    26 		octet_t value = read<octet_t>(memory, address_r);
    27 		value = increment ? value + change : value - change;
    28 		write<octet_t>(memory, address_w, value);
    29 		wprintf(L"%sCREMENT %*d → %02X\n", (increment ? "IN" : "DE"), 5, address, value);
    30 	}
    31 private:
    32 	bool increment;
    33 	octet_t change;
    34 
    35 };
    36 
    37 }