1 | /*****************************************************************************\ |
---|---|
2 | Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. |
3 | This file is licensed under the Snes9x License. |
4 | For further information, consult the LICENSE file in the root directory. |
5 | \*****************************************************************************/ |
6 | |
7 | // JMA compressed file support |
8 | // (c) Copyright 2004-2006 NSRT Team (http://nsrt.edgeemu.com) |
9 | |
10 | |
11 | #include "snes9x.h" |
12 | #include "memmap.h" |
13 | |
14 | #include <vector> |
15 | using namespace std; |
16 | |
17 | #include "s9x-jma.h" |
18 | #include "jma.h" |
19 | |
20 | size_t load_jma_file(const char *filename, unsigned char *buffer) |
21 | { |
22 | try |
23 | { |
24 | JMA::jma_open JMAFile(filename); |
25 | vector<JMA::jma_public_file_info> file_info = JMAFile.get_files_info(); |
26 | |
27 | string our_file_name; |
28 | size_t our_file_size = 0; |
29 | |
30 | for (vector<JMA::jma_public_file_info>::iterator i = file_info.begin(); i != file_info.end(); i++) |
31 | { |
32 | //Check for valid ROM based on size |
33 | if ((i->size <= CMemory::MAX_ROM_SIZE+512) && (i->size > our_file_size)) |
34 | { |
35 | our_file_name = i->name; |
36 | our_file_size = i->size; |
37 | } |
38 | } |
39 | |
40 | if (!our_file_size) |
41 | { |
42 | return(0); |
43 | } |
44 | |
45 | JMAFile.extract_file(our_file_name, buffer); |
46 | |
47 | return(our_file_size); |
48 | } |
49 | catch (JMA::jma_errors jma_error) |
50 | { |
51 | return(0); |
52 | } |
53 | } |
54 |