debug output formatting
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 22 Dec 2017 00:21:29 +0100
changeset 111d1cc6552542
parent 10 efed38f454a0
child 12 1ecfa42ca0d2
debug output formatting
c++/rgb-assembler/rgb-assembler.cpp
     1.1 --- a/c++/rgb-assembler/rgb-assembler.cpp	Fri Dec 22 00:00:04 2017 +0100
     1.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp	Fri Dec 22 00:21:29 2017 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  const command_t CMD_SLEEP = 0xFF;
     1.5  const command_t CMD_COLOR = 0xAA;
     1.6  const command_t CMD_END = 0xED;
     1.7 +const command_t CMD_INVALID = 0x1; // placeholder for unsupported command
     1.8  
     1.9  /**
    1.10   * Reads data on given position in memory and increments the index (position).
    1.11 @@ -59,53 +60,52 @@
    1.12  		write<sleep_t>(memory, a, 255);
    1.13  		write<command_t>(memory, a, CMD_GOTO);
    1.14  		write<address_t>(memory, a, a + 4);
    1.15 -		write<command_t>(memory, a, 1);
    1.16 -		write<command_t>(memory, a, 1);
    1.17 +		write<command_t>(memory, a, CMD_INVALID);
    1.18 +		write<command_t>(memory, a, CMD_INVALID);
    1.19  		write<command_t>(memory, a, CMD_SLEEP);
    1.20  		write<sleep_t>(memory, a, 255);
    1.21  		write<command_t>(memory, a, CMD_COLOR);
    1.22 -		write<color_t>(memory, a, 50);
    1.23 -		write<color_t>(memory, a, 100);
    1.24 -		write<color_t>(memory, a, 150);
    1.25 +		write<color_t>(memory, a, 0);
    1.26 +		write<color_t>(memory, a, 200);
    1.27 +		write<color_t>(memory, a, 255);
    1.28  		write<command_t>(memory, a, CMD_END);
    1.29  	}
    1.30  
    1.31  	for (address_t i = 0; i < MEMORY_SIZE;) {
    1.32 -		wprintf(L"command %d = ", i);
    1.33 +		wprintf(L"command %*d = ", 4, i);
    1.34  		command_t ch = read<command_t>(memory, i);
    1.35 -		wprintf(L"%X\n", ch);
    1.36 +		wprintf(L"%02X  ", ch);
    1.37  
    1.38 -		string command;
    1.39 -		
    1.40  		color_t r;
    1.41  		color_t g;
    1.42  		color_t b;
    1.43  
    1.44 +		sleep_t delay;
    1.45 +
    1.46  		switch (ch) {
    1.47  			case CMD_GOTO:
    1.48  				i = read<address_t>(memory, i);
    1.49 -				command.append("GOTO ");
    1.50 +				wprintf(L"GOTO %*d\n", 5, i);
    1.51  				break;
    1.52  			case CMD_SLEEP:
    1.53 -				command.append("SLEEP");
    1.54 -				this_thread::sleep_for(chrono::milliseconds(read<sleep_t>(memory, i)));
    1.55 +				delay = read<sleep_t>(memory, i);
    1.56 +				wprintf(L"SLEEP %*d ms\n", 4, delay);
    1.57 +				this_thread::sleep_for(chrono::milliseconds(delay));
    1.58  				break;
    1.59  			case CMD_COLOR:
    1.60 -				command.append("COLOR");
    1.61  				r = read<color_t>(memory, i);
    1.62  				g = read<color_t>(memory, i);
    1.63  				b = read<color_t>(memory, i);
    1.64 +				wprintf(L"COLOR  %02X %02X %02X\n", r, g, b);
    1.65  				break;
    1.66  			case CMD_END:
    1.67 -				command.append("END");
    1.68 +				wprintf(L"END\n");
    1.69  				i = MEMORY_SIZE;
    1.70  				break;
    1.71 -
    1.72 +			default:
    1.73 +				wprintf(L"invalid command\n");
    1.74  		}
    1.75  
    1.76 -		if (!command.empty()) {
    1.77 -			wprintf(L"\t%s\n", command.c_str());
    1.78 -		}
    1.79  	}
    1.80  
    1.81  	free(memory);