parametric INCREMENT and DECREMENT
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 24 Dec 2017 00:12:58 +0100
changeset 27835bd4559e5c
parent 26 47ee91579133
child 28 2b2f8a17d63a
parametric INCREMENT and DECREMENT
c++/rgb-assembler/commands/IncrementDecrement.h
c++/rgb-assembler/rgb-assembler.cpp
     1.1 --- a/c++/rgb-assembler/commands/IncrementDecrement.h	Sun Dec 24 00:08:55 2017 +0100
     1.2 +++ b/c++/rgb-assembler/commands/IncrementDecrement.h	Sun Dec 24 00:12:58 2017 +0100
     1.3 @@ -14,8 +14,9 @@
     1.4  class IncrementDecrement : public Command {
     1.5  public:
     1.6  
     1.7 -	IncrementDecrement(const bool increment) {
     1.8 +	IncrementDecrement(const bool increment, octet_t change) {
     1.9  		this->increment = increment;
    1.10 +		this->change = change;
    1.11  	}
    1.12  
    1.13  	void process(octet_t* memory, address_t& index) override {
    1.14 @@ -23,12 +24,13 @@
    1.15  		address_t address_r = address;
    1.16  		address_t address_w = address_r;
    1.17  		octet_t value = read<octet_t>(memory, address_r);
    1.18 -		value = increment ? value + 1 : value - 1;
    1.19 +		value = increment ? value + change : value - change;
    1.20  		write<octet_t>(memory, address_w, value);
    1.21  		wprintf(L"%sCREMENT %*d → %02X\n", (increment ? "IN" : "DE"), 5, address, value);
    1.22  	}
    1.23  private:
    1.24  	bool increment;
    1.25 +	octet_t change;
    1.26  
    1.27  };
    1.28  
     2.1 --- a/c++/rgb-assembler/rgb-assembler.cpp	Sun Dec 24 00:08:55 2017 +0100
     2.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp	Sun Dec 24 00:12:58 2017 +0100
     2.3 @@ -121,10 +121,10 @@
     2.4  		{CMD_SLEEP, make_shared<commands::Sleep>()},
     2.5  		{CMD_END, make_shared<commands::End>()},
     2.6  		{CMD_COLOR, make_shared<commands::Color>()},
     2.7 -		{CMD_INCREMENT, make_shared < commands::IncrementDecrement>(true)},
     2.8 -		{CMD_DECREMENT, make_shared < commands::IncrementDecrement>(false)},
     2.9 +		{CMD_INCREMENT, make_shared < commands::IncrementDecrement>(true, 1)},
    2.10 +		{CMD_DECREMENT, make_shared < commands::IncrementDecrement>(false, 1)},
    2.11  	};
    2.12 -	
    2.13 +
    2.14  
    2.15  	for (address_t i = 0; i < MEMORY_SIZE;) {
    2.16  		wprintf(L"command %*d = ", 4, i);