Mercurial > repos > blastem
annotate system.c @ 2593:b0a7b1f708cc
Fix andi to ccr in new 68K core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 09 Feb 2025 16:55:00 -0800 |
parents | 6404643aca38 |
children | c768bbd912f1 |
rev | line source |
---|---|
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
2457 | 2 #include <stdlib.h> |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "system.h" |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "genesis.h" |
1946 | 5 #include "gen_player.h" |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
6 #include "sms.h" |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
7 #include "mediaplayer.h" |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
8 #include "coleco.h" |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
9 #include "paths.h" |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
10 #include "util.h" |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
11 #include "cdimage.h" |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
12 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
13 #define SMD_HEADER_SIZE 512 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
14 #define SMD_MAGIC1 0x03 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
15 #define SMD_MAGIC2 0xAA |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
16 #define SMD_MAGIC3 0xBB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
17 #define SMD_BLOCK_SIZE 0x4000 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
18 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
19 #ifdef DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
20 #define ROMFILE FILE* |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
21 #define romopen fopen |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
22 #define romread fread |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
23 #define romseek fseek |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
24 #define romgetc fgetc |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
25 #define romclose fclose |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
26 #else |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
27 #include "zlib/zlib.h" |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
28 #define ROMFILE gzFile |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
29 #define romopen gzopen |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
30 #define romread gzfread |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
31 #define romseek gzseek |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
32 #define romgetc gzgetc |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
33 #define romclose gzclose |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
34 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
35 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
36 uint16_t *process_smd_block(uint16_t *dst, uint8_t *src, size_t bytes) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
37 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
38 for (uint8_t *low = src, *high = (src+bytes/2), *end = src+bytes; high < end; high++, low++) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
39 *(dst++) = *low << 8 | *high; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
40 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
41 return dst; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
42 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
43 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
44 int load_smd_rom(ROMFILE f, void **buffer) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
45 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
46 uint8_t block[SMD_BLOCK_SIZE]; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
47 romseek(f, SMD_HEADER_SIZE, SEEK_SET); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
48 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
49 size_t filesize = 512 * 1024; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
50 size_t readsize = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
51 uint16_t *dst, *buf; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
52 dst = buf = malloc(filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
53 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
54 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
55 size_t read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
56 do { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
57 if ((readsize + SMD_BLOCK_SIZE > filesize)) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
58 filesize *= 2; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
59 buf = realloc(buf, filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
60 dst = buf + readsize/sizeof(uint16_t); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
61 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
62 read = romread(block, 1, SMD_BLOCK_SIZE, f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
63 if (read > 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
64 dst = process_smd_block(dst, block, read); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
65 readsize += read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
66 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
67 } while(read > 0); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
68 romclose(f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
69 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
70 *buffer = buf; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
71 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
72 return readsize; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
73 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
74 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
75 uint8_t is_smd_format(const char *filename, uint8_t *header) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
76 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
77 if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
78 int i; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
79 for (i = 3; i < 8; i++) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
80 if (header[i] != 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
81 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
82 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
83 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
84 if (i == 8) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
85 if (header[2]) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
86 fatal_error("%s is a split SMD ROM which is not currently supported", filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
87 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
88 return 1; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
89 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
90 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
91 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
92 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
93 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
94 #ifndef IS_LIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
95 uint32_t load_media_zip(const char *filename, system_media *dst) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
96 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
97 static const char *valid_exts[] = {"bin", "md", "gen", "sms", "gg", "rom", "smd", "sg", "sc", "sf7"}; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
98 const uint32_t num_exts = sizeof(valid_exts)/sizeof(*valid_exts); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
99 zip_file *z = zip_open(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
100 if (!z) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
101 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
102 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
103 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
104 for (uint32_t i = 0; i < z->num_entries; i++) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
105 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
106 char *ext = path_extension(z->entries[i].name); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
107 if (!ext) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
108 continue; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
109 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
110 for (uint32_t j = 0; j < num_exts; j++) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
111 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
112 if (!strcasecmp(ext, valid_exts[j])) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
113 size_t out_size = nearest_pow2(z->entries[i].size); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
114 dst->buffer = zip_read(z, i, &out_size); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
115 if (dst->buffer) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
116 if (is_smd_format(z->entries[i].name, dst->buffer)) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
117 size_t offset; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
118 for (offset = 0; offset + SMD_BLOCK_SIZE + SMD_HEADER_SIZE <= out_size; offset += SMD_BLOCK_SIZE) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
119 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
120 uint8_t tmp[SMD_BLOCK_SIZE]; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
121 uint8_t *u8dst = dst->buffer; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
122 memcpy(tmp, u8dst + offset + SMD_HEADER_SIZE, SMD_BLOCK_SIZE); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
123 process_smd_block((void *)(u8dst + offset), tmp, SMD_BLOCK_SIZE); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
124 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
125 out_size = offset; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
126 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
127 dst->extension = ext; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
128 dst->dir = path_dirname(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
129 if (!dst->dir) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
130 dst->dir = path_current_dir(); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
131 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
132 dst->name = basename_no_extension(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
133 dst->size = out_size; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
134 dst->zip = z; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
135 return out_size; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
136 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
137 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
138 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
139 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
140 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
141 zip_close(z); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
142 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
143 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
144 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
145 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
146 uint32_t load_media(char * filename, system_media *dst, system_type *stype) |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
147 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
148 uint8_t header[10]; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
149 #ifndef IS_LIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
150 if (dst->zip) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
151 zip_close(dst->zip); |
2560
6404643aca38
Fix crash when switching between loading ZIP and non-ZIP ROMs
Michael Pavone <pavone@retrodev.com>
parents:
2551
diff
changeset
|
152 dst->zip = NULL; |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
153 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
154 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
155 dst->orig_path = filename; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
156 char *ext = path_extension(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
157 #ifndef IS_LIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
158 if (ext && !strcasecmp(ext, "zip")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
159 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
160 return load_media_zip(filename, dst); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
161 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
162 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
163 if (ext && !strcasecmp(ext, "iso")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
164 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
165 *stype = SYSTEM_SEGACD; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
166 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
167 return make_iso_media(dst, filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
168 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
169 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
170 ROMFILE f = romopen(filename, "rb"); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
171 if (!f) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
172 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
173 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
174 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
175 #ifndef DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
176 char *to_free = NULL; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
177 if (!gzdirect(f) && ext && !strcasecmp(ext, "gz")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
178 size_t without_gz = strlen(filename) - 2; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
179 to_free = calloc(1, without_gz); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
180 memcpy(to_free, filename, without_gz - 1); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
181 to_free[without_gz - 1] = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
182 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
183 filename = to_free; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
184 ext = path_extension(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
185 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
186 #endif //DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
187 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
188 if (sizeof(header) != romread(header, 1, sizeof(header), f)) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
189 fatal_error("Error reading from %s\n", filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
190 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
191 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
192 uint32_t ret = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
193 if (is_smd_format(filename, header)) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
194 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
195 *stype = SYSTEM_GENESIS; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
196 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
197 ret = load_smd_rom(f, &dst->buffer); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
198 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
199 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
200 if (!ret) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
201 size_t filesize = 512 * 1024; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
202 size_t readsize = sizeof(header); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
203 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
204 char *buf = malloc(filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
205 memcpy(buf, header, readsize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
206 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
207 size_t read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
208 do { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
209 read = romread(buf + readsize, 1, filesize - readsize, f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
210 if (read > 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
211 readsize += read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
212 if (readsize == filesize) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
213 int one_more = romgetc(f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
214 if (one_more >= 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
215 filesize *= 2; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
216 buf = realloc(buf, filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
217 buf[readsize++] = one_more; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
218 } else { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
219 read = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
220 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
221 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
222 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
223 } while (read > 0); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
224 dst->buffer = buf; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
225 ret = (uint32_t)readsize; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
226 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
227 dst->dir = path_dirname(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
228 if (!dst->dir) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
229 dst->dir = path_current_dir(); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
230 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
231 dst->name = basename_no_extension(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
232 dst->extension = ext; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
233 dst->size = ret; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
234 romclose(f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
235 if (!strcasecmp(dst->extension, "cue")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
236 if (parse_cue(dst)) { |
2551
c30f0a288ccf
Fix out of bounds buffer access when loading a cue sheet > 2048 bytes via file browser or drag and drop
Michael Pavone <pavone@retrodev.com>
parents:
2545
diff
changeset
|
237 ret = dst->size; |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
238 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
239 *stype = SYSTEM_SEGACD; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
240 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
241 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
242 } else if (!strcasecmp(dst->extension, "toc")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
243 if (parse_toc(dst)) { |
2551
c30f0a288ccf
Fix out of bounds buffer access when loading a cue sheet > 2048 bytes via file browser or drag and drop
Michael Pavone <pavone@retrodev.com>
parents:
2545
diff
changeset
|
244 ret = dst->size; |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
245 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
246 *stype = SYSTEM_SEGACD; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
247 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
248 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
249 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
250 #ifndef DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
251 if (to_free) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
252 free(to_free); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
253 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
254 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
255 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
256 return ret; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
257 } |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
258 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
259 uint8_t safe_cmp(char *str, long offset, uint8_t *buffer, long filesize) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
260 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
261 long len = strlen(str); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
262 return filesize >= offset+len && !memcmp(str, buffer + offset, len); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
263 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
265 system_type detect_system_type(system_media *media) |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 { |
2428 | 267 static char *pico_names[] = { |
268 "SEGA PICO", "SEGATOYS PICO", "SEGA TOYS PICO", "SAMSUNG PICO", | |
269 "SEGA IAC", "IMA IKUNOUJYUKU", "IMA IKUNOJYUKU" | |
270 }; | |
271 static const int num_pico = sizeof(pico_names)/sizeof(*pico_names); | |
272 for (int i = 0; i < num_pico; i++) { | |
273 if (safe_cmp(pico_names[i], 0x100, media->buffer, media->size)) { | |
274 return SYSTEM_PICO; | |
275 } | |
276 } | |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
277 if (safe_cmp("SEGA", 0x100, media->buffer, media->size)) { |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
278 //TODO: support other bootable identifiers |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
279 if (safe_cmp("SEGADISCSYSTEM", 0, media->buffer, media->size)) { |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
280 return SYSTEM_SEGACD; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
281 } |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
282 //TODO: Differentiate between vanilla Genesis and 32X games |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 return SYSTEM_GENESIS; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 } |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
285 if (safe_cmp("TMR SEGA", 0x1FF0, media->buffer, media->size) |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
286 || safe_cmp("TMR SEGA", 0x3FF0, media->buffer, media->size) |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
287 || safe_cmp("TMR SEGA", 0x7FF0, media->buffer, media->size) |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
288 ) { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
289 return SYSTEM_SMS; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
290 } |
2459
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
291 if (media->size > 400) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
292 uint8_t *buffer = media->buffer; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
293 if (!memcmp(buffer + 4, "\x00\x00\x04\x00", 4) && (buffer[0x80] == 0 || buffer[0x80] == 0xFF)) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
294 int i = 0x81; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
295 for(; i < 0x400; i++) |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
296 { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
297 if (buffer[i] != buffer[0x80]) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
298 break; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
299 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
300 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
301 if (i == 0x400) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
302 return SYSTEM_COPERA; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
303 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
304 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
305 } |
1946 | 306 if (safe_cmp("BLSTEL\x02", 0, media->buffer, media->size)) { |
307 uint8_t *buffer = media->buffer; | |
308 if (media->size > 9 && buffer[7] == 0) { | |
309 return buffer[8] + 1; | |
310 } | |
311 } | |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
312 if ( |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
313 safe_cmp("Vgm ", 0, media->buffer, media->size) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
314 || safe_cmp("RIFF", 0, media->buffer, media->size) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
315 || safe_cmp("fLaC", 0, media->buffer, media->size)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
316 return SYSTEM_MEDIA_PLAYER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
317 } |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
318 if ( |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
319 (safe_cmp("\xAA\x55", 0, media->buffer, media->size) |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
320 || safe_cmp("\x55\xAA", 0, media->buffer, media->size)) |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
321 && media->size > 0xB) { |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
322 uint8_t *buffer = media->buffer; |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
323 if (((buffer[0xB] << 8) | buffer[0xA]) > 0x8000) { |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
324 return SYSTEM_COLECOVISION; |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
325 } |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
326 } |
2257
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
327 |
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
328 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
329 //TODO: Detect Jaguar ROMs here |
2257
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
330 |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
331 //Header based detection failed, examine filename for clues |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
332 if (media->extension) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
333 if (!strcmp("md", media->extension) || !strcmp("gen", media->extension)) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
334 return SYSTEM_GENESIS; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
335 } |
2521
8cf7cadc17ee
Initial SC-3000 support
Michael Pavone <pavone@retrodev.com>
parents:
2459
diff
changeset
|
336 if (!strcmp("sms", media->extension) || !strcmp("sg", media->extension) || !strcmp("gg", media->extension) |
8cf7cadc17ee
Initial SC-3000 support
Michael Pavone <pavone@retrodev.com>
parents:
2459
diff
changeset
|
337 || !strcmp("sc", media->extension) || !strcmp("sf7", media->extension)) { |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
338 return SYSTEM_SMS; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
339 } |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
340 if (!strcmp("j64", media->extension)) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
341 return SYSTEM_JAGUAR; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
342 } |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
343 if (!strcmp("col", media->extension)) { |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
344 return SYSTEM_COLECOVISION; |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
345 } |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
346 } |
2257
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
347 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 //More certain checks failed, look for a valid 68K reset vector |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
349 if (media->size >= 8) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
350 char *rom = media->buffer; |
1893
7b62e6805e6a
Only look at low 24-bits of reset vector in ROM type detection heuristic
Michael Pavone <pavone@retrodev.com>
parents:
1595
diff
changeset
|
351 uint32_t reset = rom[5] << 16 | rom[6] << 8 | rom[7]; |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
352 if (!(reset & 1) && reset < media->size) { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 //we have a valid looking reset vector, assume it's a Genesis ROM |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 return SYSTEM_GENESIS; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 return SYSTEM_UNKNOWN; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
360 system_header *alloc_config_system(system_type stype, system_media *media, uint32_t opts, uint8_t force_region) |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 { |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
362 void *lock_on = NULL; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
363 uint32_t lock_on_size = 0; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
364 if (media->chain) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
365 lock_on = media->chain->buffer; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
366 lock_on_size = media->chain->size; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
367 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 switch (stype) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 case SYSTEM_GENESIS: |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
371 return &(alloc_config_genesis(media->buffer, media->size, lock_on, lock_on_size, opts, force_region))->header; |
1946 | 372 case SYSTEM_GENESIS_PLAYER: |
373 return &(alloc_config_gen_player(media->buffer, media->size))->header; | |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
374 case SYSTEM_SEGACD: |
1692 | 375 return &(alloc_config_genesis_cdboot(media, opts, force_region))->header; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
376 #ifndef NO_Z80 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
377 case SYSTEM_SMS: |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
378 return &(alloc_configure_sms(media, opts, force_region))->header; |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
379 case SYSTEM_COLECOVISION: |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
380 return &(alloc_configure_coleco(media))->header; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
381 #endif |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
382 case SYSTEM_MEDIA_PLAYER: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
383 return &(alloc_media_player(media, opts))->header; |
2428 | 384 case SYSTEM_PICO: |
2459
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
385 case SYSTEM_COPERA: |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
386 return &(alloc_config_pico(media->buffer, media->size, lock_on, lock_on_size, opts, force_region, stype))->header; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 default: |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 return NULL; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 } |
1946 | 391 |
392 system_header *alloc_config_player(system_type stype, event_reader *reader) | |
393 { | |
394 switch(stype) | |
395 { | |
396 case SYSTEM_GENESIS: | |
397 return &(alloc_config_gen_player_reader(reader))->header; | |
398 } | |
399 return NULL; | |
400 } | |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
401 |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
402 void system_request_exit(system_header *system, uint8_t force_release) |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
403 { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
404 system->force_release = force_release; |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
405 system->request_exit(system); |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
406 } |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
407 |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
408 void* load_media_subfile(const system_media *media, char *path, uint32_t *sizeout) |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
409 { |
2457 | 410 #ifdef IS_LIB |
411 //TODO: Figure out how to handle Pico artwork and similar cases in libretro builds | |
412 return NULL; | |
413 #else | |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
414 char *to_free = NULL; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
415 void *buffer = NULL; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
416 uint32_t size = 0; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
417 if (media->zip) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
418 uint32_t i; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
419 for (i = 0; i < media->zip->num_entries; i++) |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
420 { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
421 if (!strcasecmp(media->zip->entries[i].name, path)) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
422 break; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
423 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
424 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
425 if (i < media->zip->num_entries) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
426 size_t zsize = media->zip->entries[i].size + 1; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
427 buffer = zip_read(media->zip, i, &zsize); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
428 size = zsize; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
429 if (buffer) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
430 ((uint8_t *)buffer)[size] = 0; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
431 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
432 goto end; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
433 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
434 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
435 if (!is_absolute_path(path)) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
436 to_free = path = path_append(media->dir, path); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
437 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
438 FILE *f = fopen(path, "rb"); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
439 if (!f) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
440 goto end; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
441 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
442 size = file_size(f); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
443 buffer = calloc(1, size + 1); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
444 size = fread(buffer, 1, size, f); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
445 fclose(f); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
446 |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
447 end: |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
448 if (sizeout) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
449 *sizeout = size; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
450 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
451 free(to_free); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
452 return buffer; |
2457 | 453 #endif |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
454 } |