-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnec.cpp
More file actions
38 lines (30 loc) · 783 Bytes
/
nec.cpp
File metadata and controls
38 lines (30 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "code.h"
namespace
{
void b2(char c) {
switch (c & 3) {
case 0: *ptr++ = 0b11100101; break;
case 1: *ptr++ = 0b10010001; break;
case 2: *ptr++ = 0b10000101; break;
default: *ptr++ = 0b11100001; *ptr++ = 0b11100001;
}
}
void byte(char c) {
b2(c); b2(c >>= 2); b2(c >>= 2); b2(c >> 2);
}
void nec(char a1, char a2, char c, int leading) {
while (transmitting_());
ptr = buffer;
*ptr++ = -1; *ptr++ = 88; *ptr++ = 21;
*ptr++ = (leading - 1) * 2 + 1; *ptr++ = 14;
byte(a1); byte(a2); byte(c); byte(~c);
*ptr++ = 0b11100001;
transmit_();
}
} // anonymous
namespace user
{
void nec(char a, char c) { ::nec(a, ~a, c, 16); }
void nec_sc(short a, char c) { ::nec(a, a>>8, c, 16); }
void samsung(char a1, char a2, char c) { ::nec(a1, a2, c, 8); }
}