2 #include "mainloop.hpp"
7 #include "keymapper.hpp"
10 #include <snes/snes.hpp>
11 #include <ui-libsnes/libsnes.hpp>
12 #include "framerate.hpp"
13 #if defined(_WIN32) || defined(_WIN64)
18 class my_interfaced
: public SNES::Interface
20 string
path(SNES::Cartridge::Slot slot
, const string
&hint
)
26 class mycommandhandlerd
: public aliasexpand_commandhandler
29 void docommand2(std::string
& cmd
, window
* win
) throw(std::bad_alloc
, std::runtime_error
)
32 win
->message("Unrecognized command: " + cmd
);
36 struct moviefile
generate_movie_template(std::vector
<std::string
> cmdline
, loaded_rom
& r
, window
* win
)
38 struct moviefile movie
;
39 movie
.gametype
= gtype::togametype(r
.rtype
, r
.region
);
40 movie
.rom_sha256
= r
.rom
.sha256
;
41 movie
.romxml_sha256
= r
.rom_xml
.sha256
;
42 movie
.slota_sha256
= r
.slota
.sha256
;
43 movie
.slotaxml_sha256
= r
.slota_xml
.sha256
;
44 movie
.slotb_sha256
= r
.slotb
.sha256
;
45 movie
.slotbxml_sha256
= r
.slotb_xml
.sha256
;
46 movie
.movie_sram
= load_sram_commandline(cmdline
);
47 for(auto i
= cmdline
.begin(); i
!= cmdline
.end(); i
++) {
49 if(o
.length() >= 8 && o
.substr(0, 8) == "--port1=")
50 movie
.port1
= port_type::lookup(o
.substr(8), false).ptype
;
51 if(o
.length() >= 8 && o
.substr(0, 8) == "--port2=")
52 movie
.port2
= port_type::lookup(o
.substr(8), true).ptype
;
53 if(o
.length() >= 11 && o
.substr(0, 11) == "--gamename=")
54 movie
.gamename
= o
.substr(11);
55 if(o
.length() >= 9 && o
.substr(0, 9) == "--author=") {
56 std::string line
= o
.substr(9);
57 fieldsplitter
f(line
);
60 if(full
== "" && nick
== "")
61 throw std::runtime_error("Bad author name, one of full or nickname must be present");
62 movie
.authors
.push_back(std::make_pair(full
, nick
));
71 #if defined(_WIN32) || defined(_WIN64)
72 int SDL_main(int argc
, char** argv
)
74 int main(int argc
, char** argv
)
77 std::vector
<std::string
> cmdline
;
78 for(int i
= 1; i
< argc
; i
++)
79 cmdline
.push_back(argv
[i
]);
80 mycommandhandlerd handler
;
82 SNES::system
.interface
= &intrf
;
88 x
<< snes_library_id() << " (" << SNES::Info::Profile
<< " core)";
89 bsnes_core_version
= x
.str();
93 lua_set_commandhandler(handler
);
95 win
.out() << "BSNES version: " << bsnes_core_version
<< std::endl
;
96 win
.out() << "lsnes version: lsnes rr" << lsnes_version
<< std::endl
;
97 win
.out() << "Command line is: ";
98 for(auto k
= cmdline
.begin(); k
!= cmdline
.end(); k
++)
99 win
.out() << "\"" << *k
<< "\" ";
100 win
.out() << std::endl
;
102 std::string cfgpath
= get_config_path(&win
);
103 create_lsnesrc(&win
);
104 out(&win
) << "Saving per-user data to: " << get_config_path(&win
) << std::endl
;
105 out(&win
) << "--- Running lsnesrc --- " << std::endl
;
106 std::string rc
= "run-script " + cfgpath
+ "/lsnes.rc";
107 handler
.docommand(rc
, &win
);
108 out(&win
) << "--- End running lsnesrc --- " << std::endl
;
110 out(&win
) << "--- Loading ROM ---" << std::endl
;
113 r
= load_rom_from_commandline(cmdline
, &win
);
115 } catch(std::bad_alloc
& e
) {
117 } catch(std::exception
& e
) {
118 win
.out() << "FATAL: Can't load ROM: " << e
.what() << std::endl
;
122 win
.out() << "Detected region: " << gtype::tostring(r
.rtype
, r
.region
) << std::endl
;
123 if(r
.region
== REGION_PAL
)
124 set_nominal_framerate(322445.0/6448.0);
125 else if(r
.region
== REGION_NTSC
)
126 set_nominal_framerate(10738636.0/178683.0);
128 out(&win
) << "--- Internal memory mappings ---" << std::endl
;
129 dump_region_map(&win
);
130 out(&win
) << "--- End of Startup --- " << std::endl
;
134 for(auto i
= cmdline
.begin(); i
!= cmdline
.end(); i
++)
135 if(i
->length() > 0 && (*i
)[0] != '-') {
136 movie
= moviefile(*i
);
140 movie
= generate_movie_template(cmdline
, r
, &win
);
141 main_loop(&win
, r
, movie
);
142 } catch(std::bad_alloc
& e
) {
144 } catch(std::exception
& e
) {
145 win
.message(std::string("Fatal: ") + e
.what());