-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrl78console.c
83 lines (66 loc) · 1.88 KB
/
rl78console.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* rl78console
* Copyright (C) 2013 Florent de Lamotte <florent.lamotte@univ-ubs.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <usb.h>
#include <sys/select.h>
#include <sys/time.h>
#include <curses.h>
#include <term.h>
#include "rl78com.h"
#define CONTROL(x) ((x) & 0x1F)
void configure_screen () {
SCREEN *s = newterm(NULL, stdin, stdout);
if (s == 0)
exit(-1);
cbreak();
noecho();
keypad(stdscr, TRUE);
setbuf(stdout, NULL);
}
int main(void)
{
struct usb_dev_handle *myhandle;
myhandle = find_rl78();
if (myhandle != NULL) {
fd_set s_rd;
struct timeval delay;
char ch, ch2;
configure_rl78(myhandle);
configure_screen();
while (ch != EOF && ch != CONTROL('d')) {
delay.tv_sec = 0;
delay.tv_usec = 0;
FD_ZERO(&s_rd);
FD_SET(fileno(stdin), &s_rd);
select(fileno(stdin)+1, &s_rd, NULL, NULL, &delay);
if (FD_ISSET (fileno(stdin), &s_rd)) {
ch=getch();
if (ch != EOF && ch != CONTROL('d'))
rl78_write(myhandle, &ch, 1, 100);
}
int ret = rl78_read(myhandle, &ch2, 1, 50);
if (ret >= 0) {
putchar (ch2);
}
}
usb_close(myhandle);
endwin();
}
return 0;
}