Mercurial > repos > blastem
annotate system.c @ 2688:b42f00a3a937 default tip
Fix default target. Ensure m68k.h and z80.h are built before anything else when no dep info is available
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Mar 2025 21:06:18 -0700 |
parents | c4256ce2c45a |
children |
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* |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
21 #ifdef __ANDROID__ |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
22 #define romopen fopen_wrapper |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
23 #else |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
24 #define romopen fopen |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
25 #endif |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
26 #define romread fread |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
27 #define romseek fseek |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
28 #define romgetc fgetc |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
29 #define romclose fclose |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
30 #else |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
31 #include "zlib/zlib.h" |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
32 #define ROMFILE gzFile |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
33 #ifdef __ANDROID__ |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
34 #define romopen gzopen_wrapper |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
35 #else |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
36 #define romopen gzopen |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2604
diff
changeset
|
37 #endif |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
38 #define romread gzfread |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
39 #define romseek gzseek |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
40 #define romgetc gzgetc |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
41 #define romclose gzclose |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
42 #endif |
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 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
|
45 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
46 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
|
47 *(dst++) = *low << 8 | *high; |
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 return dst; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
50 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
51 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
52 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
|
53 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
54 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
|
55 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
|
56 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
57 size_t filesize = 512 * 1024; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
58 size_t readsize = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
59 uint16_t *dst, *buf; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
60 dst = buf = malloc(filesize); |
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 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
63 size_t read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
64 do { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
65 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
|
66 filesize *= 2; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
67 buf = realloc(buf, filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
68 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
|
69 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
70 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
|
71 if (read > 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
72 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
|
73 readsize += read; |
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 } while(read > 0); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
76 romclose(f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
77 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
78 *buffer = buf; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
79 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
80 return readsize; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
81 } |
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 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
|
84 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
85 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
|
86 int i; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
87 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
|
88 if (header[i] != 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
89 return 0; |
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 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
92 if (i == 8) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
93 if (header[2]) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
94 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
|
95 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
96 return 1; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
97 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
98 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
99 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
100 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
101 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
102 #ifndef IS_LIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
103 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
|
104 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 if (!z) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
109 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
110 } |
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 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
|
113 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
114 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
|
115 if (!ext) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
116 continue; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
117 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
118 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
|
119 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 if (dst->buffer) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
124 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
|
125 size_t offset; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
126 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
|
127 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
128 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
|
129 uint8_t *u8dst = dst->buffer; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
130 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
|
131 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
|
132 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
133 out_size = offset; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
134 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
135 dst->extension = ext; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
136 dst->dir = path_dirname(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
137 if (!dst->dir) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
138 dst->dir = path_current_dir(); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
139 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
140 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
|
141 dst->size = out_size; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
142 dst->zip = z; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
143 return out_size; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
144 } |
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 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
147 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
148 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
149 zip_close(z); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
150 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
151 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
152 #endif |
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 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
|
155 { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
156 uint8_t header[10]; |
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 (dst->zip) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
159 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
|
160 dst->zip = NULL; |
2545
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 dst->orig_path = filename; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
164 char *ext = path_extension(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
165 #ifndef IS_LIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
166 if (ext && !strcasecmp(ext, "zip")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
167 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
168 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
|
169 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
170 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
171 if (ext && !strcasecmp(ext, "iso")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
172 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
173 *stype = SYSTEM_SEGACD; |
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 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
|
176 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
177 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
178 ROMFILE f = romopen(filename, "rb"); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
179 if (!f) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
180 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
181 return 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
182 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
183 #ifndef DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
184 char *to_free = NULL; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 free(ext); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
191 filename = to_free; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
192 ext = path_extension(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
193 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
194 #endif //DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
195 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
196 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
|
197 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
|
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 uint32_t ret = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
201 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
|
202 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
203 *stype = SYSTEM_GENESIS; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
204 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
205 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
|
206 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
207 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
208 if (!ret) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
209 size_t filesize = 512 * 1024; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
210 size_t readsize = sizeof(header); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
211 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
212 char *buf = malloc(filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
213 memcpy(buf, header, readsize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
214 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
215 size_t read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
216 do { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
217 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
|
218 if (read > 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
219 readsize += read; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
220 if (readsize == filesize) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
221 int one_more = romgetc(f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
222 if (one_more >= 0) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
223 filesize *= 2; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
224 buf = realloc(buf, filesize); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
225 buf[readsize++] = one_more; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
226 } else { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
227 read = 0; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
228 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
229 } |
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 } while (read > 0); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
232 dst->buffer = buf; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
233 ret = (uint32_t)readsize; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
234 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
235 dst->dir = path_dirname(filename); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
236 if (!dst->dir) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
237 dst->dir = path_current_dir(); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
238 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
239 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
|
240 dst->extension = ext; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
241 dst->size = ret; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
242 romclose(f); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
243 if (!strcasecmp(dst->extension, "cue")) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
244 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
|
245 ret = dst->size; |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
246 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
247 *stype = SYSTEM_SEGACD; |
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 } 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
|
251 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
|
252 ret = dst->size; |
2545
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
253 if (stype) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
254 *stype = SYSTEM_SEGACD; |
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 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
257 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
258 #ifndef DISABLE_ZLIB |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
259 if (to_free) { |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
260 free(to_free); |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
261 } |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
262 #endif |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
263 |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
264 return ret; |
c076a96f1668
Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents:
2521
diff
changeset
|
265 } |
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
|
266 |
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
|
267 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
|
268 { |
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
|
269 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
|
270 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
|
271 } |
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
|
272 |
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
|
273 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
|
274 { |
2428 | 275 static char *pico_names[] = { |
276 "SEGA PICO", "SEGATOYS PICO", "SEGA TOYS PICO", "SAMSUNG PICO", | |
277 "SEGA IAC", "IMA IKUNOUJYUKU", "IMA IKUNOJYUKU" | |
278 }; | |
279 static const int num_pico = sizeof(pico_names)/sizeof(*pico_names); | |
280 for (int i = 0; i < num_pico; i++) { | |
281 if (safe_cmp(pico_names[i], 0x100, media->buffer, media->size)) { | |
282 return SYSTEM_PICO; | |
283 } | |
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("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
|
286 //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
|
287 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
|
288 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
|
289 } |
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
|
290 //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
|
291 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
|
292 } |
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
|
293 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
|
294 || 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
|
295 || 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
|
296 ) { |
2604
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
297 return strcmp("gg", media->extension) ? SYSTEM_SMS : SYSTEM_GAME_GEAR; |
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
|
298 } |
2459
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
299 if (media->size > 400) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
300 uint8_t *buffer = media->buffer; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
301 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
|
302 int i = 0x81; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
303 for(; i < 0x400; i++) |
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 if (buffer[i] != buffer[0x80]) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
306 break; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
307 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
308 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
309 if (i == 0x400) { |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
310 return SYSTEM_COPERA; |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
311 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
312 } |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
313 } |
1946 | 314 if (safe_cmp("BLSTEL\x02", 0, media->buffer, media->size)) { |
315 uint8_t *buffer = media->buffer; | |
316 if (media->size > 9 && buffer[7] == 0) { | |
317 return buffer[8] + 1; | |
318 } | |
319 } | |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
320 if ( |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
321 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
|
322 || 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
|
323 || 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
|
324 return SYSTEM_MEDIA_PLAYER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
325 } |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
326 if ( |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
327 (safe_cmp("\xAA\x55", 0, media->buffer, media->size) |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
328 || safe_cmp("\x55\xAA", 0, media->buffer, media->size)) |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
329 && media->size > 0xB) { |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
330 uint8_t *buffer = media->buffer; |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
331 if (((buffer[0xB] << 8) | buffer[0xA]) > 0x8000) { |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
332 return SYSTEM_COLECOVISION; |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
333 } |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
334 } |
2257
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
335 |
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
336 |
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
|
337 //TODO: Detect Jaguar ROMs here |
2257
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
338 |
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
|
339 //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
|
340 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
|
341 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
|
342 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
|
343 } |
2604
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
344 if (!strcmp("sms", 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
|
345 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
|
346 } |
2604
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
347 if (!strcmp("gg", media->extension)) { |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
348 return SYSTEM_GAME_GEAR; |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
349 } |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
350 if (!strcmp("sg", media->extension) || !strcmp("sg1", media->extension)) { |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
351 return SYSTEM_SG1000; |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
352 } |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
353 if (!strcmp("sc", media->extension) || !strcmp("sf7", media->extension) || |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
354 !strcmp("sc3", media->extension) |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
355 ) { |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
356 return SYSTEM_SC3000; |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
357 } |
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
|
358 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
|
359 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
|
360 } |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
361 if (!strcmp("col", media->extension)) { |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
362 return SYSTEM_COLECOVISION; |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
363 } |
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
|
364 } |
2257
1e626d0ecf9c
WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
365 |
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
|
366 //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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 //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
|
372 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
|
373 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 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
|
376 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
378 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
|
379 { |
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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 } |
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
|
386 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
|
387 { |
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 case SYSTEM_GENESIS: |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
389 return &(alloc_config_genesis(media->buffer, media->size, lock_on, lock_on_size, opts, force_region))->header; |
1946 | 390 case SYSTEM_GENESIS_PLAYER: |
391 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
|
392 case SYSTEM_SEGACD: |
1692 | 393 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
|
394 #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
|
395 case SYSTEM_SMS: |
2604
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
396 case SYSTEM_GAME_GEAR: |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
397 case SYSTEM_SG1000: |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
398 case SYSTEM_SC3000: |
c768bbd912f1
Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents:
2560
diff
changeset
|
399 return &(alloc_configure_sms(media, stype, opts, force_region))->header; |
2413
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
400 case SYSTEM_COLECOVISION: |
64cf80e683aa
Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
401 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
|
402 #endif |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
403 case SYSTEM_MEDIA_PLAYER: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
2257
diff
changeset
|
404 return &(alloc_media_player(media, opts))->header; |
2428 | 405 case SYSTEM_PICO: |
2459
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
406 case SYSTEM_COPERA: |
cb62730d5c99
Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents:
2457
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 } |
1946 | 412 |
413 system_header *alloc_config_player(system_type stype, event_reader *reader) | |
414 { | |
415 switch(stype) | |
416 { | |
417 case SYSTEM_GENESIS: | |
418 return &(alloc_config_gen_player_reader(reader))->header; | |
419 } | |
420 return NULL; | |
421 } | |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
422 |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
423 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
|
424 { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
425 system->force_release = force_release; |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
426 system->request_exit(system); |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
427 } |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
428 |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
429 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
|
430 { |
2457 | 431 #ifdef IS_LIB |
432 //TODO: Figure out how to handle Pico artwork and similar cases in libretro builds | |
433 return NULL; | |
434 #else | |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
435 char *to_free = NULL; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
436 void *buffer = NULL; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
437 uint32_t size = 0; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
438 if (media->zip) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
439 uint32_t i; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
440 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
|
441 { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
442 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
|
443 break; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
444 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
445 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
446 if (i < media->zip->num_entries) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
447 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
|
448 buffer = zip_read(media->zip, i, &zsize); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
449 size = zsize; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
450 if (buffer) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
451 ((uint8_t *)buffer)[size] = 0; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
452 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
453 goto end; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
454 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
455 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
456 if (!is_absolute_path(path)) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
457 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
|
458 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
459 FILE *f = fopen(path, "rb"); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
460 if (!f) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
461 goto end; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
462 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
463 size = file_size(f); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
464 buffer = calloc(1, size + 1); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
465 size = fread(buffer, 1, size, f); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
466 fclose(f); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
467 |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
468 end: |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
469 if (sizeout) { |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
470 *sizeout = size; |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
471 } |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
472 free(to_free); |
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
473 return buffer; |
2457 | 474 #endif |
2438
bed4d3db8a3f
More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents:
2428
diff
changeset
|
475 } |