c++/rgb-assembler/commands/GotoCompare.h
changeset 31 b997cbf9e30b
parent 29 10d6964e7b4a
child 33 ff150572e8c0
     1.1 --- a/c++/rgb-assembler/commands/GotoCompare.h	Sun Dec 24 00:47:34 2017 +0100
     1.2 +++ b/c++/rgb-assembler/commands/GotoCompare.h	Mon Dec 25 00:24:07 2017 +0100
     1.3 @@ -27,24 +27,31 @@
     1.4  class GotoCompare : public Command {
     1.5  public:
     1.6  
     1.7 -	void process(octet_t* memory, address_t& index) override {
     1.8 -		address_t aa = read<address_t>(memory, index);
     1.9 -		address_t ab = read<address_t>(memory, index);
    1.10 -		address_t eq = read<address_t>(memory, index);
    1.11 -		address_t gt = read<address_t>(memory, index);
    1.12 -		address_t lt = read<address_t>(memory, index);
    1.13 +	void process(Memory &memory) override {
    1.14 +		address_t aa = memory.read<address_t>();
    1.15 +		address_t ab = memory.read<address_t>();
    1.16 +		address_t eq = memory.read<address_t>();
    1.17 +		address_t gt = memory.read<address_t>();
    1.18 +		address_t lt = memory.read<address_t>();
    1.19  
    1.20 -		octet_t a = read<octet_t>(memory, aa);
    1.21 -		octet_t b = read<octet_t>(memory, ab);
    1.22 +		address_t originalAddress = memory.getIndex();
    1.23 +		// TODO: add to Memory methods read(address_t) and write(address_t, T)
    1.24 +		memory.setIndex(aa);
    1.25 +		octet_t a = memory.read<octet_t>();
    1.26 +		memory.setIndex(ab);
    1.27 +		octet_t b = memory.read<octet_t>();
    1.28 +		memory.setIndex(originalAddress);
    1.29 +
    1.30 +		address_t index;
    1.31  
    1.32  		if (a == b) index = eq;
    1.33  		else if (a > b) index = gt;
    1.34  		else index = lt;
    1.35  
    1.36 +		memory.setIndex(index);
    1.37 +
    1.38  		wprintf(L"GOTO COMPARE  a = %02X, b = %02X, eq = %d, gt = %d, lt = %d → %d\n", a, b, eq, gt, lt, index);
    1.39  	}
    1.40 -private:
    1.41 -
    1.42  };
    1.43  
    1.44  }