forked from amhndu/SimpleNES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
108 lines (99 loc) · 4.25 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "Emulator.h"
#include "Log.h"
#include <string>
#include <sstream>
namespace sn
{
void parseControllerConf(std::string filepath,
std::vector<sf::Keyboard::Key>& p1,
std::vector<sf::Keyboard::Key>& p2);
}
int main(int argc, char** argv)
{
std::ofstream logFile ("simplenes.log"), cpuTraceFile;
sn::TeeStream logTee (logFile, std::cout);
if (logFile.is_open() && logFile.good())
sn::Log::get().setLogStream(logTee);
else
sn::Log::get().setLogStream(std::cout);
sn::Log::get().setLevel(sn::Info);
std::string path;
//Default keybindings
std::vector<sf::Keyboard::Key> p1 {sf::Keyboard::J, sf::Keyboard::K, sf::Keyboard::RShift, sf::Keyboard::Return,
sf::Keyboard::W, sf::Keyboard::S, sf::Keyboard::A, sf::Keyboard::D},
p2 {sf::Keyboard::Numpad5, sf::Keyboard::Numpad6, sf::Keyboard::Numpad8, sf::Keyboard::Numpad9,
sf::Keyboard::Up, sf::Keyboard::Down, sf::Keyboard::Left, sf::Keyboard::Right};
sn::Emulator emulator;
for (int i = 1; i < argc; ++i)
{
std::string arg (argv[i]);
if (arg == "-h" || arg == "--help")
{
std::cout << "SimpleNES is a simple NES emulator.\n"
<< "It can run off .nes images.\n"
<< "Set keybindings with keybindings.conf\n\n"
<< "Usage: SimpleNES [options] rom-path\n\n"
<< "Options:\n"
<< "-h, --help Print this help text and exit\n"
<< "-s, --scale Set video scale. Default: 2.\n"
<< " Scale of 1 corresponds to " << sn::NESVideoWidth << "x" << sn::NESVideoHeight << std::endl
<< "-w, --width Set the width of the emulation screen (height is\n"
<< " set automatically to fit the aspect ratio)\n"
<< "-H, --height Set the height of the emulation screen (width is\n"
<< " set automatically to fit the aspect ratio)\n"
<< " This option is mutually exclusive to --width\n"
<< std::endl;
return 0;
}
else if (std::strcmp(argv[i], "--log-cpu") == 0)
{
sn::Log::get().setLevel(sn::CpuTrace);
cpuTraceFile.open("sn.cpudump");
sn::Log::get().setCpuTraceStream(cpuTraceFile);
LOG(sn::Info) << "CPU logging set." << std::endl;
}
else if (std::strcmp(argv[i], "-s") == 0 || std::strcmp(argv[i], "--scale") == 0)
{
float scale;
std::stringstream ss;
if (i + 1 < argc && ss << argv[i + 1] && ss >> scale)
emulator.setVideoScale(scale);
else
LOG(sn::Error) << "Setting scale from argument failed" << std::endl;
++i;
}
else if (std::strcmp(argv[i], "-w") == 0 || std::strcmp(argv[i], "--width") == 0)
{
int width;
std::stringstream ss;
if (i + 1 < argc && ss << argv[i + 1] && ss >> width)
emulator.setVideoWidth(width);
else
LOG(sn::Error) << "Setting width from argument failed" << std::endl;
++i;
}
else if (std::strcmp(argv[i], "-H") == 0 || std::strcmp(argv[i], "--height") == 0)
{
int height;
std::stringstream ss;
if (i + 1 < argc && ss << argv[i + 1] && ss >> height)
emulator.setVideoHeight(height);
else
LOG(sn::Error) << "Setting height from argument failed" << std::endl;
++i;
}
else if (argv[i][0] != '-')
path = argv[i];
else
std::cerr << "Unrecognized argument: " << argv[i] << std::endl;
}
if (path.empty())
{
std::cout << "Argument required: ROM path" << std::endl;
return 1;
}
sn::parseControllerConf("keybindings.conf", p1, p2);
emulator.setKeys(p1, p2);
emulator.run(path);
return 0;
}