c++/rgb-assembler/commands/IncrementDecrement.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 24 Dec 2017 00:08:55 +0100
changeset 26 47ee91579133
parent 23 c++/rgb-assembler/commands/End.h@e85d2bfaff73
child 27 835bd4559e5c
permissions -rw-r--r--
INCREMENT and DECREMENT in class
     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) {
    18 		this->increment = increment;
    19 	}
    20 
    21 	void process(octet_t* memory, address_t& index) override {
    22 		address_t address = read<address_t>(memory, index);
    23 		address_t address_r = address;
    24 		address_t address_w = address_r;
    25 		octet_t value = read<octet_t>(memory, address_r);
    26 		value = increment ? value + 1 : value - 1;
    27 		write<octet_t>(memory, address_w, value);
    28 		wprintf(L"%sCREMENT %*d → %02X\n", (increment ? "IN" : "DE"), 5, address, value);
    29 	}
    30 private:
    31 	bool increment;
    32 
    33 };
    34 
    35 }