annotate system.c @ 2438:bed4d3db8a3f

More flexible loading of Pico storyware assets
author Michael Pavone <pavone@retrodev.com>
date Sun, 11 Feb 2024 11:04:39 -0800
parents 65c2e4d990cc
children 9da3de58410d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #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
3 #include "genesis.h"
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
4 #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
5 #include "sms.h"
2289
92449b47cce8 Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents: 2257
diff changeset
6 #include "mediaplayer.h"
2413
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
7 #include "coleco.h"
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
8 #include "paths.h"
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
9 #include "util.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
10
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
11 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
12 {
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
13 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
14 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
15 }
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
16
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
17 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
18 {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
19 static char *pico_names[] = {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
20 "SEGA PICO", "SEGATOYS PICO", "SEGA TOYS PICO", "SAMSUNG PICO",
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
21 "SEGA IAC", "IMA IKUNOUJYUKU", "IMA IKUNOJYUKU"
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
22 };
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
23 static const int num_pico = sizeof(pico_names)/sizeof(*pico_names);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
24 for (int i = 0; i < num_pico; i++) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
25 if (safe_cmp(pico_names[i], 0x100, media->buffer, media->size)) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
26 return SYSTEM_PICO;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
27 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
28 }
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
29 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
30 //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
31 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
32 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
33 }
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
34 //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
35 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
36 }
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
37 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
38 || 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
39 || 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
40 ) {
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
41 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
42 }
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
43 if (safe_cmp("BLSTEL\x02", 0, media->buffer, media->size)) {
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
44 uint8_t *buffer = media->buffer;
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
45 if (media->size > 9 && buffer[7] == 0) {
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
46 return buffer[8] + 1;
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
47 }
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
48 }
2289
92449b47cce8 Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents: 2257
diff changeset
49 if (
92449b47cce8 Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents: 2257
diff changeset
50 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
51 || 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
52 || 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
53 return SYSTEM_MEDIA_PLAYER;
92449b47cce8 Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents: 2257
diff changeset
54 }
2413
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
55 if (
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
56 (safe_cmp("\xAA\x55", 0, media->buffer, media->size)
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
57 || safe_cmp("\x55\xAA", 0, media->buffer, media->size))
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
58 && media->size > 0xB) {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
59 uint8_t *buffer = media->buffer;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
60 if (((buffer[0xB] << 8) | buffer[0xA]) > 0x8000) {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
61 return SYSTEM_COLECOVISION;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
62 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
63 }
2257
1e626d0ecf9c WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
64
1e626d0ecf9c WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
65
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
66 //TODO: Detect Jaguar ROMs here
2257
1e626d0ecf9c WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
67
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
68 //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
69 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
70 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
71 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
72 }
2257
1e626d0ecf9c WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
73 if (!strcmp("sms", media->extension) || !strcmp("sg", media->extension) || !strcmp("gg", 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
74 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
75 }
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
76 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
77 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
78 }
2413
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
79 if (!strcmp("col", media->extension)) {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
80 return SYSTEM_COLECOVISION;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
81 }
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
82 }
2257
1e626d0ecf9c WIP SG-1000/TMS9918A mode support
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
83
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
84 //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
85 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
86 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
87 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
88 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
89 //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
90 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
91 }
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 }
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 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
94 }
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95
1595
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1201
diff changeset
96 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
97 {
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
98 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
99 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
100 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
101 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
102 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
103 }
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
104 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
105 {
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 case SYSTEM_GENESIS:
1595
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1201
diff changeset
107 return &(alloc_config_genesis(media->buffer, media->size, lock_on, lock_on_size, opts, force_region))->header;
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
108 case SYSTEM_GENESIS_PLAYER:
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
109 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
110 case SYSTEM_SEGACD:
1692
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1595
diff changeset
111 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
112 #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
113 case SYSTEM_SMS:
1595
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1201
diff changeset
114 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
115 case SYSTEM_COLECOVISION:
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2289
diff changeset
116 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
117 #endif
2289
92449b47cce8 Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents: 2257
diff changeset
118 case SYSTEM_MEDIA_PLAYER:
92449b47cce8 Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents: 2257
diff changeset
119 return &(alloc_media_player(media, opts))->header;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
120 case SYSTEM_PICO:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
121 return &(alloc_config_pico(media->buffer, media->size, lock_on, lock_on_size, opts, force_region))->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
122 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
123 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
124 }
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 }
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
126
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
127 system_header *alloc_config_player(system_type stype, event_reader *reader)
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
128 {
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
129 switch(stype)
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
130 {
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
131 case SYSTEM_GENESIS:
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
132 return &(alloc_config_gen_player_reader(reader))->header;
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
133 }
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
134 return NULL;
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1893
diff changeset
135 }
1980
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1946
diff changeset
136
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1946
diff changeset
137 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
138 {
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1946
diff changeset
139 system->force_release = force_release;
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1946
diff changeset
140 system->request_exit(system);
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1946
diff changeset
141 }
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
142
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
143 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
144 {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
145 char *to_free = NULL;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
146 void *buffer = NULL;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
147 uint32_t size = 0;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
148 if (media->zip) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
149 uint32_t i;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
150 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
151 {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
152 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
153 break;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
154 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
155 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
156 if (i < media->zip->num_entries) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
157 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
158 buffer = zip_read(media->zip, i, &zsize);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
159 size = zsize;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
160 if (buffer) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
161 ((uint8_t *)buffer)[size] = 0;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
162 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
163 goto end;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
164 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
165 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
166 if (!is_absolute_path(path)) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
167 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
168 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
169 FILE *f = fopen(path, "rb");
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
170 if (!f) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
171 goto end;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
172 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
173 size = file_size(f);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
174 buffer = calloc(1, size + 1);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
175 size = fread(buffer, 1, size, f);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
176 fclose(f);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
177
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
178 end:
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
179 if (sizeout) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
180 *sizeout = size;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
181 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
182 free(to_free);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
183 return buffer;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
184 }