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