3 #include "core/advdumper.hpp"
4 #include "core/controller.hpp"
5 #include "core/command.hpp"
6 #include "core/dispatch.hpp"
7 #include "core/mainloop.hpp"
8 #include "core/framerate.hpp"
9 #include "core/keymapper.hpp"
10 #include "interface/romtype.hpp"
11 #include "core/loadlib.hpp"
12 #include "lua/lua.hpp"
13 #include "core/mainloop.hpp"
14 #include "core/misc.hpp"
15 #include "core/instance.hpp"
16 #include "core/moviedata.hpp"
17 #include "core/rom.hpp"
18 #include "core/romloader.hpp"
19 #include "core/settings.hpp"
20 #include "core/window.hpp"
21 #include "library/string.hpp"
28 bool hashing_in_progress
= false;
29 uint64_t hashing_left
= 0;
30 int64_t last_update
= 0;
32 void hash_callback(uint64_t left
, uint64_t total
)
34 if(left
== 0xFFFFFFFFFFFFFFFFULL
) {
35 hashing_in_progress
= false;
36 std::cout
<< "Done." << std::endl
;
37 last_update
= get_utime() - 2000000;
40 if(!hashing_in_progress
) {
41 std::cout
<< "Hashing disc images..." << std::flush
;
43 hashing_in_progress
= true;
45 int64_t this_update
= get_utime();
46 if(this_update
< last_update
- 1000000 || this_update
> last_update
+ 1000000) {
47 std::cout
<< ((hashing_left
+ 524288) >> 20) << "..." << std::flush
;
48 last_update
= this_update
;
52 void dump_what_was_loaded(loaded_rom
& r
, moviefile
& f
)
54 std::cout
<< "Core:\t" << r
.rtype
->get_core_identifier() << std::endl
;
55 std::cout
<< "System:\t" << r
.rtype
->get_hname() << std::endl
;
56 std::cout
<< "Region:\t" << r
.region
->get_hname() << std::endl
;
57 for(auto i
= 0; i
< ROM_SLOT_COUNT
; i
++) {
58 std::string risha
= r
.romimg
[i
].sha_256
.read();
59 std::string rxsha
= r
.romxml
[i
].sha_256
.read();
60 std::string fisha
= f
.romimg_sha256
[i
];
61 std::string fxsha
= f
.romxml_sha256
[i
];
62 std::string finam
= r
.romimg
[i
].filename
;
63 std::string fxnam
= r
.romxml
[i
].filename
;
64 std::string nhint
= f
.namehint
[i
];
65 if(risha
!= "" || rxsha
!= "" || fisha
!= "" || fxsha
!= "" || nhint
!= "") {
66 std::cout
<< "ROM slot #" << i
<< ":" << std::endl
;
68 std::cout
<< "\tHint:\t" << nhint
<< std::endl
;
70 std::cout
<< "\tFile:\t" << finam
<< std::endl
;
72 std::cout
<< "\tXFile:\t" << fxnam
<< std::endl
;
73 if(risha
!= "" && fisha
== risha
)
74 std::cout
<< "\tHash:\t" << risha
<< " (matches)" << std::endl
;
75 if(risha
!= "" && fisha
!= risha
)
76 std::cout
<< "\tHash:\t" << risha
<< " (ROM)" << std::endl
;
77 if(fisha
!= "" && fisha
!= risha
)
78 std::cout
<< "\tHash:\t" << risha
<< " (Movie)" << std::endl
;
79 if(rxsha
!= "" && fxsha
== rxsha
)
80 std::cout
<< "\tXHash:\t" << rxsha
<< " (matches)" << std::endl
;
81 if(rxsha
!= "" && fxsha
!= rxsha
)
82 std::cout
<< "\tXHash:\t" << rxsha
<< " (ROM)" << std::endl
;
83 if(fxsha
!= "" && fxsha
!= rxsha
)
84 std::cout
<< "\tXHash:\t" << rxsha
<< " (Movie)" << std::endl
;
90 int main(int argc
, char** argv
)
93 std::vector
<std::string
> cmdline
;
94 for(int i
= 1; i
< argc
; i
++)
95 cmdline
.push_back(argv
[i
]);
100 messages
<< "lsnes version: lsnes rr" << lsnes_version
<< std::endl
;
101 messages
<< "Command line is: ";
102 for(auto k
= cmdline
.begin(); k
!= cmdline
.end(); k
++)
103 messages
<< "\"" << *k
<< "\" ";
104 messages
<< std::endl
;
106 std::string cfgpath
= get_config_path();
107 autoload_libraries();
109 for(auto i
: cmdline
) {
111 if(r
= regex("--firmware-path=(.*)", i
))
113 lsnes_vsetc
.set("firmwarepath", r
[1]);
114 std::cerr
<< "Set firmware path to '" << r
[1] << "'" << std::endl
;
115 } catch(std::exception
& e
) {
116 std::cerr
<< "Can't set firmware path to '" << r
[1] << "': " << e
.what() << std::endl
;
118 if(r
= regex("--rom-path=(.*)", i
))
120 lsnes_vsetc
.set("rompath", r
[1]);
121 std::cerr
<< "Set rompath path to '" << r
[1] << "'" << std::endl
;
122 } catch(std::exception
& e
) {
123 std::cerr
<< "Can't set firmware path to '" << r
[1] << "': " << e
.what() << std::endl
;
125 if(r
= regex("--setting-(.*)=(.*)", i
))
127 lsnes_vset
[r
[1]].str(r
[2]);
128 std::cerr
<< "Set " << r
[1] << " to '" << r
[2] << "'" << std::endl
;
129 } catch(std::exception
& e
) {
130 std::cerr
<< "Can't set " << r
[1] << " to '" << r
[2] << "': " << e
.what()
133 if(r
= regex("--load-library=(.*)", i
))
135 with_loaded_library(*new loadlib::module(loadlib::library(r
[1])));
136 handle_post_loadlibrary();
137 } catch(std::runtime_error
& e
) {
138 std::cerr
<< "Can't load '" << r
[1] << "': " << e
.what() << std::endl
;
142 set_hasher_callback(hash_callback
);
145 for(auto i
: cmdline
) {
146 if(i
.length() > 0 && i
[0] != '-') {
153 std::map
<std::string
, std::string
> tmp
;
154 r
= construct_rom(movfn
, cmdline
);
155 r
.load(tmp
, 1000000000, 0);
156 } catch(std::bad_alloc
& e
) {
158 } catch(std::exception
& e
) {
159 messages
<< "FATAL: Can't load ROM: " << e
.what() << std::endl
;
164 moviefile
* movie
= NULL
;
167 movie
= new moviefile(movfn
, *r
.rtype
);
168 } catch(std::bad_alloc
& e
) {
170 } catch(std::exception
& e
) {
171 messages
<< "FATAL: Can't load movie: " << e
.what() << std::endl
;
176 dump_what_was_loaded(r
, *movie
);
178 lsnes_instance
.mlogic
.release_memory();