-
Notifications
You must be signed in to change notification settings - Fork 7
/
main-linux.cpp
73 lines (67 loc) · 1.73 KB
/
main-linux.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <signal.h>
#include "OPL2.h"
#include "demotune.h"
static int interrupted = 0;
static void sigint(int) {
interrupted = 1;
}
int main(int argc, char *argv[])
{
struct parport_list parports = {};
struct parport *selected = NULL;
int i, ret = 1, caps = CAP1284_RAW;
printf("== OPL2LPT test program ==\n\n");
if (ieee1284_find_ports(&parports, 0) != E1284_OK) {
fprintf(stderr, "Cannot get a list of parallel ports\n");
goto err;
}
if (parports.portc == 0) {
fprintf(stderr, "No parallel ports found\n");
goto err;
}
if (parports.portc == 1) {
selected = parports.portv[0];
printf("One parallel port found: %s\n", selected->name);
} else {
printf("Several parallel ports found:\n");
for (i = 0; i < parports.portc; i++)
printf("%2d: %s\n", i+1, parports.portv[i]->name);
while (1) {
printf("Which port? "); fflush(stdout);
scanf("%d", &i);
if (i > 0 && i <= parports.portc) break;
}
selected = parports.portv[i];
}
if (ieee1284_open(selected, F1284_EXCL, &caps) != E1284_OK) {
fprintf(stderr, "Cannot open parallel port\n");
goto err;
}
if (ieee1284_claim(selected) != E1284_OK) {
fprintf(stderr, "Cannot claim parallel port\n");
goto err;
}
extern OPL2 opl2;
opl2.init(selected);
music_setup();
printf("\n\nPress Ctrl-C to stop...");
fflush(stdout);
signal(SIGINT, sigint);
while (!interrupted) {
music_loop();
}
music_shutdown();
printf("\n\n");
ret = 0;
err:
if (selected) ieee1284_close(selected);
if (parports.portc) ieee1284_free_ports(&parports);
return ret;
}