-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (68 loc) · 1.21 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
68
69
70
71
72
73
74
75
#include <iostream>
#include <SDL2/SDL.h>
#include <exception>
#include "src/Exceptions.hpp"
#include "src/Chip8.hpp"
#include "src/Disassembly.hpp"
#define DEFAULT_ROM "welcome.ch8"
using namespace std;
void printUsage();
int main(int argc, char** argv)
{
try {
if (argc == 1)
{
Chip8 c(DEFAULT_ROM);
c.start();
}
else if (argc == 2)
{
Chip8 c(argv[1]);
c.start();
}
else if (argc == 3)
{
string cmd = argv[1];
if (cmd == "-d")
{
Chip8 c(argv[2], true);
c.start();
}
else if (cmd == "-disass")
{
Disassembly d(argv[2]);
d.disass();
}
else
{
throw UnknownCommandArgsException(argv[1]);
}
}
else
{
throw TooManyArgsException();
}
}
catch (const ArgsException & e)
{
cout << e.toString() << endl;
printUsage();
}
catch (const Chip8Exception & e)
{
cout << e.toString() << endl;
}
catch (const exception & e)
{
cout << "An error occured ! (" << e.what() << ")" << endl;
return -1;
}
return 0;
}
void printUsage()
{
cout << "Usage :" << endl;
cout << " chip8.exe [[-d | -disass] rom_path.ch8]" << endl << endl;
cout << " -d : enable debug mode" << endl;
cout << " -disass : disassemble the rom" << endl;
}