Skip to content

Commit

Permalink
Added command line argument to set scale
Browse files Browse the repository at this point in the history
  • Loading branch information
amhndu committed Dec 5, 2016
1 parent bf8fd65 commit 654faaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/Emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace sn
void run(std::string rom_path);
void setVideoWidth(int width);
void setVideoHeight(int height);
void setVideoScale(float scale);
private:
void DMA(Byte page);

Expand Down
16 changes: 15 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ int main(int argc, char** argv)
<< "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"
Expand All @@ -60,6 +62,16 @@ int main(int argc, char** argv)
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;
Expand All @@ -80,8 +92,10 @@ int main(int argc, char** argv)
LOG(sn::Error) << "Setting height from argument failed" << std::endl;
++i;
}
else
else if (argv[i][0] != '-')
path = argv[i];
else
std::cerr << "Unrecognized argument: " << argv[i] << std::endl;
}

if (path.empty())
Expand Down
10 changes: 8 additions & 2 deletions src/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,23 @@ namespace sn

void Emulator::setVideoHeight(int height)
{
m_screenScale = height / 240.f;
m_screenScale = height / float(NESVideoHeight);
LOG(Info) << "Scale: " << m_screenScale << " set. Screen: "
<< int(NESVideoWidth * m_screenScale) << "x" << int(NESVideoHeight * m_screenScale) << std::endl;
}

void Emulator::setVideoWidth(int width)
{
m_screenScale = width / 256.f;
m_screenScale = width / float(NESVideoWidth);
LOG(Info) << "Scale: " << m_screenScale << " set. Screen: "
<< int(NESVideoWidth * m_screenScale) << "x" << int(NESVideoHeight * m_screenScale) << std::endl;

}
void Emulator::setVideoScale(float scale)
{
m_screenScale = scale;
LOG(Info) << "Scale: " << m_screenScale << " set. Screen: "
<< int(NESVideoWidth * m_screenScale) << "x" << int(NESVideoHeight * m_screenScale) << std::endl;
}

}

0 comments on commit 654faaf

Please sign in to comment.