#include <iostream>
#include <iomanip>
/**
* Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32,
* which instructs the unit to show given text on the display.
*
* Roland MT-32 is capable to display 20 characters.
* Longer messages are silently truncated by the MT-32 unit (this software does not check the length).
*
* The SysEx message contains a checksum.
* If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds
* and then returns back to the default screen.
*
* Usage:
* amidi --port="hw:2,0,0" --send-hex="$(echo -n ' Run GNU/Linux ' | ./mt-32-display )"
*
* @param argc
* @param argv
* @return
*/
int main(int argc, char**argv) {
std::cout << "f0 41 10 16 12 20 00 00 ";
std::cout << std::hex << std::setfill('0');
int sum = 0;
// 20 00 00 = display message
sum += 0x20;
sum += 0x00;
sum += 0x00;
for (char ch; std::cin.read(&ch, 1).good();) {
std::cout << std::setw(2) << ((int) ch) << " ";
sum += ch;
}
sum %= 128;
sum = 128 - sum;
std::cout << std::setw(2) << sum;
std::cout << " f7";
std::cout << std::endl;
return 0;
}