2 #include "mainloop.hpp"
8 #include "keymapper.hpp"
11 #include <snes/snes.hpp>
12 #include <ui-libsnes/libsnes.hpp>
13 #include "framerate.hpp"
14 #if defined(_WIN32) || defined(_WIN64)
19 class my_interfaced
: public SNES::Interface
21 string
path(SNES::Cartridge::Slot slot
, const string
&hint
)
27 struct moviefile
generate_movie_template(std::vector
<std::string
> cmdline
, loaded_rom
& r
, window
* win
)
29 struct moviefile movie
;
30 movie
.gametype
= gtype::togametype(r
.rtype
, r
.region
);
31 movie
.rom_sha256
= r
.rom
.sha256
;
32 movie
.romxml_sha256
= r
.rom_xml
.sha256
;
33 movie
.slota_sha256
= r
.slota
.sha256
;
34 movie
.slotaxml_sha256
= r
.slota_xml
.sha256
;
35 movie
.slotb_sha256
= r
.slotb
.sha256
;
36 movie
.slotbxml_sha256
= r
.slotb_xml
.sha256
;
37 movie
.movie_sram
= load_sram_commandline(cmdline
);
38 for(auto i
= cmdline
.begin(); i
!= cmdline
.end(); i
++) {
40 if(o
.length() >= 8 && o
.substr(0, 8) == "--port1=")
41 movie
.port1
= port_type::lookup(o
.substr(8), false).ptype
;
42 if(o
.length() >= 8 && o
.substr(0, 8) == "--port2=")
43 movie
.port2
= port_type::lookup(o
.substr(8), true).ptype
;
44 if(o
.length() >= 11 && o
.substr(0, 11) == "--gamename=")
45 movie
.gamename
= o
.substr(11);
46 if(o
.length() >= 9 && o
.substr(0, 9) == "--author=") {
47 std::string line
= o
.substr(9);
48 fieldsplitter
f(line
);
51 if(full
== "" && nick
== "")
52 throw std::runtime_error("Bad author name, one of full or nickname must be present");
53 movie
.authors
.push_back(std::make_pair(full
, nick
));
62 #if defined(_WIN32) || defined(_WIN64)
63 int SDL_main(int argc
, char** argv
)
65 int main(int argc
, char** argv
)
68 std::vector
<std::string
> cmdline
;
69 for(int i
= 1; i
< argc
; i
++)
70 cmdline
.push_back(argv
[i
]);
72 SNES::system
.interface
= &intrf
;
78 x
<< snes_library_id() << " (" << SNES::Info::Profile
<< " core)";
79 bsnes_core_version
= x
.str();
84 win
.out() << "BSNES version: " << bsnes_core_version
<< std::endl
;
85 win
.out() << "lsnes version: lsnes rr" << lsnes_version
<< std::endl
;
86 win
.out() << "Command line is: ";
87 for(auto k
= cmdline
.begin(); k
!= cmdline
.end(); k
++)
88 win
.out() << "\"" << *k
<< "\" ";
89 win
.out() << std::endl
;
91 std::string cfgpath
= get_config_path(&win
);
93 out(&win
) << "Saving per-user data to: " << get_config_path(&win
) << std::endl
;
94 out(&win
) << "--- Running lsnesrc --- " << std::endl
;
95 command::invokeC("run-script " + cfgpath
+ "/lsnes.rc", &win
);
96 out(&win
) << "--- End running lsnesrc --- " << std::endl
;
98 out(&win
) << "--- Loading ROM ---" << std::endl
;
101 r
= load_rom_from_commandline(cmdline
, &win
);
103 } catch(std::bad_alloc
& e
) {
105 } catch(std::exception
& e
) {
106 win
.out() << "FATAL: Can't load ROM: " << e
.what() << std::endl
;
110 win
.out() << "Detected region: " << gtype::tostring(r
.rtype
, r
.region
) << std::endl
;
111 if(r
.region
== REGION_PAL
)
112 set_nominal_framerate(322445.0/6448.0);
113 else if(r
.region
== REGION_NTSC
)
114 set_nominal_framerate(10738636.0/178683.0);
116 out(&win
) << "--- Internal memory mappings ---" << std::endl
;
117 dump_region_map(&win
);
118 out(&win
) << "--- End of Startup --- " << std::endl
;
122 for(auto i
= cmdline
.begin(); i
!= cmdline
.end(); i
++)
123 if(i
->length() > 0 && (*i
)[0] != '-') {
124 movie
= moviefile(*i
);
128 movie
= generate_movie_template(cmdline
, r
, &win
);
129 main_loop(&win
, r
, movie
);
130 } catch(std::bad_alloc
& e
) {
132 } catch(std::exception
& e
) {
133 win
.message(std::string("Fatal: ") + e
.what());