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