#include "ProgramOptions.hpp" #include "Ex.hpp" #include "cxxopts.hpp" ProgramOptions::ProgramOptions( char const* name, char const* desc, int argc, char const* argv[] ) : mOpt{ std::make_shared( name, desc ) } { mOpt->add_options() ( "h,help", "produce help message" ) ( "i,input", "input file, first implicit agrument", cxxopts::value(), "input" ) ( "w,wav", "wave output file", cxxopts::value(), "wav" ) ( "c,cycles", "number of bus cycles to analyzem -1 for infinite", cxxopts::value()->default_value("-1") ) ( "system", "PAL or NTSC", cxxopts::value()->default_value("PAL") ) ( "r,regdump","dump register when finished" ) ( "f,finish","exit when DSP clears DSPGO" ) ; mOpt-> positional_help("input"). show_positional_help(). parse_positional( { "input" } ); try { mRes = std::make_shared( mOpt->parse( argc, argv ) ); } catch ( std::exception const& e ) { throw Ex{} << "Error parsing command line: " << e.what(); } if ( argc == 1 || mRes->count( "help" ) ) { throw Ex{} << mOpt->help() << "\n"; } if ( mRes->count( "cycles" ) ) { mCycles = ( *mRes )["cycles"].as(); } if ( !mRes->count( "input" ) ) { throw Ex{} << "Input file not specified.\n"; } std::filesystem::path const input = ( *mRes )["input"].as(); if ( !std::filesystem::exists( input ) ) { throw Ex{} << "Input file does not exist.\n"; } if ( mRes->count( "wav" ) ) { mWavOut = std::filesystem::absolute( ( *mRes )["wav"].as() ); } if ( mRes->count( "regdump" ) ) { mDumpRegisters = 1; } if ( mRes->count( "finish" ) ) { mFinish = 1; } mInput = std::filesystem::absolute( input ); { std::string const system = ( *mRes )["system"].as(); if ( system != "PAL" && system != "NTSC" ) { throw Ex{} << "Invalid system: " << system << "\n"; } } } std::filesystem::path ProgramOptions::input() const { return mInput; } std::filesystem::path ProgramOptions::wavOut() const { return mWavOut; } int ProgramOptions::cycles() const { return mCycles; } bool ProgramOptions::isNTSC() const { return ( *mRes )["system"].as() == "NTSC"; } int ProgramOptions::dumpRegisters() const { return mDumpRegisters; } int ProgramOptions::finish() const { return mFinish; }