GOTO_COMPARE
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 22 Dec 2017 18:09:58 +0100
changeset 154b4fb847d01a
parent 14 2ab3d7282249
child 16 5c142e9c00e5
GOTO_COMPARE
c++/rgb-assembler/rgb-assembler.cpp
     1.1 --- a/c++/rgb-assembler/rgb-assembler.cpp	Fri Dec 22 17:15:15 2017 +0100
     1.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp	Fri Dec 22 18:09:58 2017 +0100
     1.3 @@ -27,6 +27,16 @@
     1.4  const command_t CMD_GOTO = 0x70;
     1.5  
     1.6  /**
     1.7 + * Compare values on two addresses and go to one of given three addresses.
     1.8 + * parameter: address_t a
     1.9 + * parameter: address_t b
    1.10 + * parameter: address_t GOTO target when a == b
    1.11 + * parameter: address_t GOTO target when a > b
    1.12 + * parameter: address_t GOTO target when a < b
    1.13 + */
    1.14 +const command_t CMD_GOTO_COMPARE = 0x80;
    1.15 +
    1.16 +/**
    1.17   * Wait given time in ms.
    1.18   * parameter: sleep_t
    1.19   */
    1.20 @@ -64,6 +74,8 @@
    1.21   */
    1.22  const command_t CMD_INVALID = 0x1;
    1.23  
    1.24 +// TODO: more commands, better numbers
    1.25 +
    1.26  /**
    1.27   * Reads data on given position in memory and increments the index (position).
    1.28   */
    1.29 @@ -101,7 +113,7 @@
    1.30  		write<command_t>(memory, a, CMD_SLEEP);
    1.31  		write<sleep_t>(memory, a, 255);
    1.32  		write<command_t>(memory, a, CMD_GOTO);
    1.33 -		write<address_t>(memory, a, a + 4);
    1.34 +		write<address_t>(memory, a, a + sizeof (address_t) + 2 * sizeof (command_t));
    1.35  		write<command_t>(memory, a, CMD_INVALID);
    1.36  		write<command_t>(memory, a, CMD_INVALID);
    1.37  		write<command_t>(memory, a, CMD_SLEEP);
    1.38 @@ -115,6 +127,12 @@
    1.39  		write<address_t>(memory, a, 0);
    1.40  		write<command_t>(memory, a, CMD_DECREMENT);
    1.41  		write<address_t>(memory, a, 0);
    1.42 +		write<command_t>(memory, a, CMD_GOTO_COMPARE);
    1.43 +		write<address_t>(memory, a, 0);
    1.44 +		write<address_t>(memory, a, 0 + sizeof (command_t) + sizeof (sleep_t));
    1.45 +		write<address_t>(memory, a, a - 3 * sizeof (address_t) - 2 * sizeof (command_t));
    1.46 +		write<address_t>(memory, a, 0);
    1.47 +		write<address_t>(memory, a, a + sizeof (address_t));
    1.48  		write<command_t>(memory, a, CMD_END);
    1.49  	}
    1.50  
    1.51 @@ -158,6 +176,27 @@
    1.52  				wprintf(L"%sCREMENT %*d → %02X\n", (ch == CMD_INCREMENT ? "IN" : "DE"), 5, address, value);
    1.53  				break;
    1.54  			}
    1.55 +			case CMD_GOTO_COMPARE:
    1.56 +			{
    1.57 +				address_t aa = read<address_t>(memory, i);
    1.58 +				address_t ab = read<address_t>(memory, i);
    1.59 +				address_t eq = read<address_t>(memory, i);
    1.60 +				address_t gt = read<address_t>(memory, i);
    1.61 +				address_t lt = read<address_t>(memory, i);
    1.62 +
    1.63 +				byte_t a = read<byte_t>(memory, aa);
    1.64 +				byte_t b = read<byte_t>(memory, ab);
    1.65 +
    1.66 +				if (a == b) {
    1.67 +					i = eq;
    1.68 +				} else if (a > b) {
    1.69 +					i = gt;
    1.70 +				} else {
    1.71 +					i = lt;
    1.72 +				}
    1.73 +				wprintf(L"GOTO COMPARE  a = %02X, b = %02X, eq = %d, gt = %d, lt = %d → %d\n", a, b, eq, gt, lt, i);
    1.74 +				break;
    1.75 +			}
    1.76  			case CMD_END:
    1.77  			{
    1.78  				wprintf(L"END\n");