mt-32-display.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 19 May 2020 16:01:09 +0200
branchv_0
changeset 0 a7af46af7903
child 1 6733bd832b61
permissions -rw-r--r--
first working version
franta-hg@0
     1
#include <iostream>
franta-hg@0
     2
#include <iomanip>
franta-hg@0
     3
franta-hg@0
     4
/**
franta-hg@0
     5
 * Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32,
franta-hg@0
     6
 * which instructs the unit to show given text on the display.
franta-hg@0
     7
 * 
franta-hg@0
     8
 * Roland MT-32 is capable to display 20 characters.
franta-hg@0
     9
 * Longer messages are silently truncated by the MT-32 unit (this software does not check the length).
franta-hg@0
    10
 * 
franta-hg@0
    11
 * The SysEx message contains a checksum.
franta-hg@0
    12
 * If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds
franta-hg@0
    13
 * and then returns back to the default screen.
franta-hg@0
    14
 * 
franta-hg@0
    15
 * Usage:
franta-hg@0
    16
 *     amidi --port="hw:2,0,0" --send-hex="$(echo -n '   Run GNU/Linux    ' | ./mt-32-display )"
franta-hg@0
    17
 * 
franta-hg@0
    18
 * @param argc
franta-hg@0
    19
 * @param argv
franta-hg@0
    20
 * @return 
franta-hg@0
    21
 */
franta-hg@0
    22
int main(int argc, char**argv) {
franta-hg@0
    23
	std::cout << "f0 41 10 16 12 20 00 00 ";
franta-hg@0
    24
	std::cout << std::hex << std::setfill('0');
franta-hg@0
    25
franta-hg@0
    26
	int sum = 0;
franta-hg@0
    27
franta-hg@0
    28
	// 20 00 00 = display message
franta-hg@0
    29
	sum += 0x20;
franta-hg@0
    30
	sum += 0x00;
franta-hg@0
    31
	sum += 0x00;
franta-hg@0
    32
franta-hg@0
    33
	for (char ch; std::cin.read(&ch, 1).good();) {
franta-hg@0
    34
		std::cout << std::setw(2) << ((int) ch) << " ";
franta-hg@0
    35
		sum += ch;
franta-hg@0
    36
	}
franta-hg@0
    37
franta-hg@0
    38
	sum %= 128;
franta-hg@0
    39
	sum = 128 - sum;
franta-hg@0
    40
	std::cout << std::setw(2) << sum;
franta-hg@0
    41
	std::cout << " f7";
franta-hg@0
    42
franta-hg@0
    43
	std::cout << std::endl;
franta-hg@0
    44
	return 0;
franta-hg@0
    45
}