-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
67 lines (60 loc) · 1.12 KB
/
main.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
#include <stdio.h>
#include <unistd.h>
#include "chip8.h"
static char *name;
static Chip8 chip8;
void usage()
{
printf("Usage: %s [options] rom\n", name);
printf("Options:\n");
printf(" -i Instructions per step (default: 10)\n");
printf(" -s Screen scale factor (default: 20)\n");
printf(" -m Mute audio\n");
}
int main(int argc, char* argv[])
{
name = argv[0];
if (argc < 2)
{
usage();
return 1;
}
int c;
while ((c = getopt(argc, argv, "i:s:m")) != -1)
{
switch (c)
{
case 'i':
chip8.instructions_per_step = atoi(optarg);
break;
case 's':
chip8.scaleFactor = atoi(optarg);
break;
case 'm':
chip8.muted = true;
break;
default:
usage();
return 1;
}
}
if (optind != argc-1)
{
usage();
return 1;
}
char *rom = argv[optind];
chip8.loadProgram(rom);
printf("Running at %d instructions per step\n", chip8.instructions_per_step);
chip8.run();
return 0;
}
#ifdef __EMSCRIPTEN__
extern "C"
{
void set_instructions_per_step(int n)
{
chip8.instructions_per_step = n;
}
}
#endif