annotate romdb.c @ 2493:b62336ceb626 default tip

Kinda hacky fix to make sure Nuklear has the right GL context
author Michael Pavone <pavone@retrodev.com>
date Wed, 17 Apr 2024 22:18:45 -0700
parents 8171409b62ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdlib.h>
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <string.h>
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "config.h"
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "romdb.h"
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "util.h"
1305
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
6 #include "hash.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1091
diff changeset
7 #include "genesis.h"
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
8 #include "menu.h"
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents: 1221
diff changeset
9 #include "xband.h"
1259
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
10 #include "realtec.h"
1414
d94855080529 Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents: 1413
diff changeset
11 #include "nor.h"
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents: 1414
diff changeset
12 #include "sega_mapper.h"
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
13 #include "multi_game.h"
1513
8f3b6a64b658 Initial work on MegaWiFi support
Michael Pavone <pavone@retrodev.com>
parents: 1470
diff changeset
14 #include "megawifi.h"
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
15 #include "jcart.h"
1548
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
16 #include "blastem.h"
2253
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
17 #include "sft_mapper.h"
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
19 #define DOM_TITLE_START 0x120
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
20 #define DOM_TITLE_END 0x150
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
21 #define TITLE_START DOM_TITLE_END
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
22 #define TITLE_END (TITLE_START+48)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
23 #define ROM_END 0x1A4
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
24 #define RAM_ID 0x1B0
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
25 #define RAM_FLAGS 0x1B2
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
26 #define RAM_START 0x1B4
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
27 #define RAM_END 0x1B8
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
28 #define REGION_START 0x1F0
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
30 char const *save_type_name(uint8_t save_type)
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
31 {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
32 if (save_type == SAVE_I2C) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
33 return "EEPROM";
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
34 } else if(save_type == SAVE_NOR) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
35 return "NOR Flash";
2027
0f54a898db03 Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents: 1952
diff changeset
36 } else if(save_type == SAVE_HBPT) {
0f54a898db03 Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents: 1952
diff changeset
37 return "Heartbeat Personal Trainer";
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
38 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
39 return "SRAM";
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
40 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
41
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: 1444
diff changeset
42 tern_node *get_rom_db()
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 {
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: 1444
diff changeset
44 static tern_node *db;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 if (!db) {
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: 1444
diff changeset
46 db = parse_bundled_config("rom.db");
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
47 if (!db) {
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
48 fatal_error("Failed to load ROM DB\n");
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
49 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 return db;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
54 void free_rom_info(rom_info *info)
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
55 {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
56 free(info->name);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
57 if (info->save_type != SAVE_NONE) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
58 free(info->save_buffer);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
59 if (info->save_type == SAVE_I2C) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
60 free(info->eeprom_map);
1592
31effaadf877 Fix some memory errors (mostly leaks) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents: 1548
diff changeset
61 } else if (info->save_type == SAVE_NOR) {
31effaadf877 Fix some memory errors (mostly leaks) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents: 1548
diff changeset
62 free(info->nor);
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
63 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
64 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
65 free(info->map);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
66 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
67
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
68 void cart_serialize(system_header *sys, serialize_buffer *buf)
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
69 {
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
70 if (sys->type != SYSTEM_GENESIS) {
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
71 return;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
72 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
73 genesis_context *gen = (genesis_context *)sys;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
74 if (gen->mapper_type == MAPPER_NONE) {
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
75 return;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
76 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
77 start_section(buf, SECTION_MAPPER);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
78 save_int8(buf, gen->mapper_type);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
79 switch(gen->mapper_type)
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
80 {
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
81 case MAPPER_SEGA:
1863
d60f2d7c02a5 Differentiate between the full Sega mapper and the SRAM only one. Fixes crash on save state load for Phantasy Star IV and other games that use the same mapper
Michael Pavone <pavone@retrodev.com>
parents: 1847
diff changeset
82 case MAPPER_SEGA_SRAM:
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
83 case MAPPER_SEGA_MED_V2:
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
84 sega_mapper_serialize(gen, buf);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
85 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
86 case MAPPER_REALTEC:
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
87 realtec_serialize(gen, buf);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
88 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
89 case MAPPER_XBAND:
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
90 xband_serialize(gen, buf);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
91 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
92 case MAPPER_MULTI_GAME:
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
93 multi_game_serialize(gen, buf);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
94 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
95 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
96 end_section(buf);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
97 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
98
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
99 void cart_deserialize(deserialize_buffer *buf, void *vcontext)
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
100 {
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
101 genesis_context *gen = vcontext;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
102 uint8_t mapper_type = load_int8(buf);
1863
d60f2d7c02a5 Differentiate between the full Sega mapper and the SRAM only one. Fixes crash on save state load for Phantasy Star IV and other games that use the same mapper
Michael Pavone <pavone@retrodev.com>
parents: 1847
diff changeset
103 if (mapper_type != gen->mapper_type && (mapper_type != MAPPER_SEGA || gen->mapper_type != MAPPER_SEGA_SRAM)) {
d60f2d7c02a5 Differentiate between the full Sega mapper and the SRAM only one. Fixes crash on save state load for Phantasy Star IV and other games that use the same mapper
Michael Pavone <pavone@retrodev.com>
parents: 1847
diff changeset
104 warning("Mapper type mismatch, skipping load of mapper state\n");
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
105 return;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
106 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
107 switch(gen->mapper_type)
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
108 {
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
109 case MAPPER_SEGA:
1863
d60f2d7c02a5 Differentiate between the full Sega mapper and the SRAM only one. Fixes crash on save state load for Phantasy Star IV and other games that use the same mapper
Michael Pavone <pavone@retrodev.com>
parents: 1847
diff changeset
110 case MAPPER_SEGA_SRAM:
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
111 sega_mapper_deserialize(buf, gen);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
112 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
113 case MAPPER_REALTEC:
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
114 realtec_deserialize(buf, gen);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
115 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
116 case MAPPER_XBAND:
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
117 xband_deserialize(buf, gen);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
118 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
119 case MAPPER_MULTI_GAME:
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
120 multi_game_deserialize(buf, gen);
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
121 break;
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
122 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
123 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
124
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 char *get_header_name(uint8_t *rom)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
127 //TODO: Should probably prefer the title field that corresponds to the user's region preference
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 uint8_t *last = rom + TITLE_END - 1;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 uint8_t *src = rom + TITLE_START;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
130
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
131 for (;;)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
133 while (last > src && (*last <= 0x20 || *last >= 0x80))
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
135 last--;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
136 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
137 if (last == src) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
138 if (src == rom + TITLE_START) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
139 src = rom + DOM_TITLE_START;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
140 last = rom + DOM_TITLE_END - 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
141 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
142 return strdup("UNKNOWN");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
144 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
145 last++;
1031
219de1d64aa1 Fixed a bug in get_header_name that results in a crash if the "International Name" field is blank
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
146 char *ret = malloc(last - src + 1);
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
147 uint8_t *dst;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
148 uint8_t last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
149 for (dst = ret; src < last; src++)
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
150 {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
151 if (*src >= 0x20 && *src < 0x80) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
152 if (*src == ' ') {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
153 if (last_was_space) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
154 continue;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
155 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
156 last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
157 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
158 last_was_space = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
159 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
160 *(dst++) = *src;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
161 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
162 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
163 *dst = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
164 return ret;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
169 char *region_chars = "JUEW";
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
170 uint8_t region_bits[] = {REGION_J, REGION_U, REGION_E, REGION_J|REGION_U|REGION_E};
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
171
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
172 uint8_t translate_region_char(uint8_t c)
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
173 {
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
174 for (int i = 0; i < sizeof(region_bits); i++)
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
175 {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
176 if (c == region_chars[i]) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
177 return region_bits[i];
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
178 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
179 }
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
180 uint8_t bin_region = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
181 if (c >= '0' && c <= '9') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
182 bin_region = c - '0';
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
183 } else if (c >= 'A' && c <= 'F') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
184 bin_region = c - 'A' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
185 } else if (c >= 'a' && c <= 'f') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
186 bin_region = c - 'a' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
187 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
188 uint8_t ret = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
189 if (bin_region & 8) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
190 ret |= REGION_E;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
191 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
192 if (bin_region & 4) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
193 ret |= REGION_U;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
194 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
195 if (bin_region & 1) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
196 ret |= REGION_J;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
197 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
198 return ret;
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
199 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
200
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
201 uint8_t get_header_regions(uint8_t *rom)
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
202 {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
203 uint8_t regions = 0;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
204 for (int i = 0; i < 3; i++)
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
205 {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
206 regions |= translate_region_char(rom[REGION_START + i]);
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
207 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
208 return regions;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
209 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
210
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
211 uint32_t get_u32be(uint8_t *data)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
212 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
213 return *data << 24 | data[1] << 16 | data[2] << 8 | data[3];
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
214 }
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
215
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
216 uint32_t calc_mask(uint32_t src_size, uint32_t start, uint32_t end)
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
217 {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
218 uint32_t map_size = end-start+1;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
219 if (src_size < map_size) {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
220 return nearest_pow2(src_size)-1;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
221 } else if (!start) {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
222 return 0xFFFFFF;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
223 } else {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
224 return nearest_pow2(map_size)-1;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
225 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
226 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
227
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
228 uint8_t has_ram_header(uint8_t *rom, uint32_t rom_size)
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
229 {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
230 return rom_size >= (RAM_END + 4) && rom[RAM_ID] == 'R' && rom[RAM_ID + 1] == 'A';
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
231 }
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
232
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
233 uint32_t read_ram_header(rom_info *info, uint8_t *rom)
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
234 {
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
235 uint32_t ram_start = get_u32be(rom + RAM_START);
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
236 uint32_t ram_end = get_u32be(rom + RAM_END);
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
237 uint32_t ram_flags = info->save_type = rom[RAM_FLAGS] & RAM_FLAG_MASK;
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
238 ram_start &= 0xFFFFFE;
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
239 ram_end |= 1;
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
240 if (ram_start >= 0x800000) {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
241 info->save_buffer = NULL;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
242 return ram_start;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
243 }
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
244 info->save_mask = ram_end - ram_start;
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
245 uint32_t save_size = info->save_mask + 1;
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
246 if (ram_flags != RAM_FLAG_BOTH) {
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
247 save_size /= 2;
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
248 }
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
249 info->save_size = save_size;
1847
882746581f17 Make sure on-cart memories are fully initialized in all cases
Michael Pavone <pavone@retrodev.com>
parents: 1822
diff changeset
250 info->save_buffer = calloc(save_size, 1);
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
251 return ram_start;
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
252 }
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
253
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
254 void add_memmap_header(rom_info *info, uint8_t *rom, uint32_t size, memmap_chunk const *base_map, int base_chunks)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
255 {
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
256 uint32_t rom_end = get_u32be(rom + ROM_END) + 1;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
257 uint32_t rom_end_raw = rom_end;
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
258 if (size > rom_end) {
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
259 rom_end = size;
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
260 } else if (rom_end > nearest_pow2(size)) {
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
261 rom_end = nearest_pow2(size);
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
262 }
1898
ebf124803a93 Make sure save_type is properly initialized
Mike Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
263 info->save_type = SAVE_NONE;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
264 uint8_t is_med_ssf = size >= 0x108 && !memcmp("SEGA SSF", rom + 0x100, 8);
2097
0407d812cb4a Fix off-by-one in sega mapper heuristic
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
265 if (is_med_ssf || (size > 0x400000 && rom_end_raw <= 0x400000)) {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
266 if (is_med_ssf && rom_end < 16*1024*1024) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
267 info->rom = rom = realloc(rom, 16*1024*1024);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
268 }
1287
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
269 info->mapper_start_index = 0;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
270 info->mapper_type = is_med_ssf ? MAPPER_SEGA_MED_V2 : MAPPER_SEGA;
1287
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
271 info->map_chunks = base_chunks + 9;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
272 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
273 memset(info->map, 0, sizeof(memmap_chunk)*9);
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
274 memcpy(info->map+9, base_map, sizeof(memmap_chunk) * base_chunks);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
275
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
276 int i;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
277 uint16_t map_flags;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
278 if (is_med_ssf) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
279 i = 0;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
280 map_flags = info->map[i].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
281 info->save_type = RAM_FLAG_BOTH;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
282 info->save_size = 256*1024;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
283 info->save_mask = info->save_size - 1;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
284 info->save_buffer = rom + 16*1024*1024 - 256*1024;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
285 } else {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
286 i = 1;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
287 map_flags = info->map[i].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
288 info->map[0].start = 0;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
289 info->map[0].end = 0x80000;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
290 info->map[0].mask = 0xFFFFFF;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
291 info->map[0].flags = MMAP_READ;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
292 info->map[0].buffer = rom;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
293
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
294 if (has_ram_header(rom, size)){
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
295 read_ram_header(info, rom);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
296 }
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
297 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
298 static const write_8_fun med_w8[] = {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
299 write_med_ram0_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
300 write_med_ram1_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
301 write_med_ram2_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
302 write_med_ram3_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
303 write_med_ram4_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
304 write_med_ram5_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
305 write_med_ram6_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
306 write_med_ram7_b,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
307 };
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
308 static const write_16_fun med_w16[] = {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
309 write_med_ram0_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
310 write_med_ram1_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
311 write_med_ram2_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
312 write_med_ram3_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
313 write_med_ram4_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
314 write_med_ram5_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
315 write_med_ram6_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
316 write_med_ram7_w,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
317 };
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
318
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
319 for (; i < 8; i++)
1287
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
320 {
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
321 info->map[i].start = i * 0x80000;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
322 info->map[i].end = (i + 1) * 0x80000;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
323 info->map[i].mask = 0x7FFFF;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
324 info->map[i].buffer = (i + 1) * 0x80000 <= size ? rom + i * 0x80000 : rom;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
325 info->map[i].ptr_index = i;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
326 info->map[i].flags = map_flags;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
327
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
328 info->map[i].read_16 = is_med_ssf ? NULL : (read_16_fun)read_sram_w;//these will only be called when mem_pointers[i] == NULL
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
329 info->map[i].read_8 = is_med_ssf ? NULL : (read_8_fun)read_sram_b;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
330 if (is_med_ssf) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
331 info->map[i].write_16 = med_w16[i];
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
332 info->map[i].write_8 = med_w8[i];
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
333 } else {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
334 info->map[i].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
335 info->map[i].write_8 = (write_8_fun)write_sram_area_b;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
336 }
1287
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
337 }
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
338 info->map[8].start = 0xA13000;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
339 info->map[8].end = 0xA13100;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
340 info->map[8].mask = 0xFF;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
341 info->map[8].write_16 = (write_16_fun)write_bank_reg_w;
65f03a0a426a Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 1281
diff changeset
342 info->map[8].write_8 = (write_8_fun)write_bank_reg_b;
2340
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2325
diff changeset
343 if (is_med_ssf) {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2325
diff changeset
344 info->map[8].read_16 = med_reg_read_w;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2325
diff changeset
345 info->map[8].read_8 = med_reg_read_b;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2325
diff changeset
346 }
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
347 return;
1794
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
348 } else if(!memcmp("SEGA MEGAWIFI", rom + 0x100, strlen("SEGA MEGAWIFI"))) {
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
349 info->mapper_type = MAPPER_NONE;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
350 info->map_chunks = base_chunks + 2;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
351 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
352 memset(info->map, 0, sizeof(memmap_chunk)*2);
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
353 memcpy(info->map+2, base_map, sizeof(memmap_chunk) * base_chunks);
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
354 info->save_size = 0x400000;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
355 info->save_bus = RAM_FLAG_BOTH;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
356 info->save_type = SAVE_NOR;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
357 info->map[0].start = 0;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
358 info->map[0].end = 0x400000;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
359 info->map[0].mask = 0xFFFFFF;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
360 info->map[0].write_16 = nor_flash_write_w;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
361 info->map[0].write_8 = nor_flash_write_b;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
362 info->map[0].read_16 = nor_flash_read_w;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
363 info->map[0].read_8 = nor_flash_read_b;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
364 info->map[0].flags = MMAP_READ_CODE | MMAP_CODE;
1847
882746581f17 Make sure on-cart memories are fully initialized in all cases
Michael Pavone <pavone@retrodev.com>
parents: 1822
diff changeset
365 info->map[0].buffer = info->save_buffer = calloc(info->save_size, 1);
1794
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
366 uint32_t init_size = size < info->save_size ? size : info->save_size;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
367 memcpy(info->save_buffer, rom, init_size);
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
368 byteswap_rom(info->save_size, (uint16_t *)info->save_buffer);
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
369 info->nor = calloc(1, sizeof(nor_state));
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
370 nor_flash_init(info->nor, info->save_buffer, info->save_size, 128, 0xDA45, RAM_FLAG_BOTH);
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
371 info->nor->cmd_address1 = 0xAAB;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
372 info->nor->cmd_address2 = 0x555;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
373 info->map[1].start = 0xA130C0;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
374 info->map[1].end = 0xA130D0;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
375 info->map[1].mask = 0xFFFFFF;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
376 if (!strcmp(
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
377 "on",
1794
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
378 tern_find_path_default(config, "system\0megawifi\0", (tern_val){.ptrval="off"}, TVAL_PTR).ptrval)
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
379 ) {
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
380 info->map[1].write_16 = megawifi_write_w;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
381 info->map[1].write_8 = megawifi_write_b;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
382 info->map[1].read_16 = megawifi_read_w;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
383 info->map[1].read_8 = megawifi_read_b;
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
384 } else {
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
385 warning("ROM uses MegaWiFi, but it is disabled\n");
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
386 }
4cd226288958 Added support for detecting Mega WiFi titles based on a header string
Michael Pavone <pavone@retrodev.com>
parents: 1792
diff changeset
387 return;
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
388 } else if (has_ram_header(rom, size)) {
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
389 uint32_t ram_start = read_ram_header(info, rom);
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
390
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
391 if (info->save_buffer) {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
392 info->map_chunks = base_chunks + (ram_start >= rom_end ? 2 : 3);
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
393 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
394 memset(info->map, 0, sizeof(memmap_chunk)*2);
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
395 memcpy(info->map+2, base_map, sizeof(memmap_chunk) * base_chunks);
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
396
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
397 if (ram_start >= rom_end) {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
398 info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
399 if (info->map[0].end > ram_start) {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
400 info->map[0].end = ram_start;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
401 }
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
402 //TODO: ROM mirroring
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
403 info->map[0].mask = 0xFFFFFF;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
404 info->map[0].flags = MMAP_READ;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
405 info->map[0].buffer = rom;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
406
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
407 info->map[1].start = ram_start;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
408 info->map[1].mask = info->save_mask;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
409 info->map[1].end = ram_start + info->save_mask + 1;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
410 info->map[1].flags = MMAP_READ | MMAP_WRITE;
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
411
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
412 if (info->save_type == RAM_FLAG_ODD) {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
413 info->map[1].flags |= MMAP_ONLY_ODD;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
414 } else if (info->save_type == RAM_FLAG_EVEN) {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
415 info->map[1].flags |= MMAP_ONLY_EVEN;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2027
diff changeset
416 } else {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2027
diff changeset
417 info->map[1].flags |= MMAP_CODE;
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
418 }
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
419 info->map[1].buffer = info->save_buffer;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
420 } else {
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
421 //Assume the standard Sega mapper
1863
d60f2d7c02a5 Differentiate between the full Sega mapper and the SRAM only one. Fixes crash on save state load for Phantasy Star IV and other games that use the same mapper
Michael Pavone <pavone@retrodev.com>
parents: 1847
diff changeset
422 info->mapper_type = MAPPER_SEGA_SRAM;
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
423 info->map[0].end = 0x200000;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
424 info->map[0].mask = 0xFFFFFF;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
425 info->map[0].flags = MMAP_READ;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
426 info->map[0].buffer = rom;
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
427
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
428 info->map[1].start = 0x200000;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
429 info->map[1].end = 0x400000;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
430 info->map[1].mask = 0x1FFFFF;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
431 info->map[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
432 info->map[1].ptr_index = info->mapper_start_index = 0;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
433 info->map[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
434 info->map[1].read_8 = (read_8_fun)read_sram_b;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
435 info->map[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
436 info->map[1].write_8 = (write_8_fun)write_sram_area_b;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
437 info->map[1].buffer = rom + 0x200000;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
438
1916
6ece1e2c7a15 Make sure fallback memory region is always last
Michael Pavone <pavone@retrodev.com>
parents: 1898
diff changeset
439 //Last entry in the base map is a catch all one that needs to be
6ece1e2c7a15 Make sure fallback memory region is always last
Michael Pavone <pavone@retrodev.com>
parents: 1898
diff changeset
440 //after all the other entries
6ece1e2c7a15 Make sure fallback memory region is always last
Michael Pavone <pavone@retrodev.com>
parents: 1898
diff changeset
441 memmap_chunk *unused = info->map + info->map_chunks - 2;
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
442 memmap_chunk *last = info->map + info->map_chunks - 1;
1916
6ece1e2c7a15 Make sure fallback memory region is always last
Michael Pavone <pavone@retrodev.com>
parents: 1898
diff changeset
443 *last = *unused;
6ece1e2c7a15 Make sure fallback memory region is always last
Michael Pavone <pavone@retrodev.com>
parents: 1898
diff changeset
444 last = unused;
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
445 memset(last, 0, sizeof(memmap_chunk));
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
446 last->start = 0xA13000;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
447 last->end = 0xA13100;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
448 last->mask = 0xFF;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
449 last->write_16 = (write_16_fun)write_bank_reg_w;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
450 last->write_8 = (write_8_fun)write_bank_reg_b;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
451 }
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
452 return;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
453 }
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
454 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
455
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
456 info->map_chunks = base_chunks + 1;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
457 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
458 memset(info->map, 0, sizeof(memmap_chunk));
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
459 memcpy(info->map+1, base_map, sizeof(memmap_chunk) * base_chunks);
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
460
1425
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
461 info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
462 info->map[0].mask = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
463 info->map[0].flags = MMAP_READ;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
464 info->map[0].buffer = rom;
49d3c572b3f2 Ignore SRAM in cart header if it is in the upper 8MB of the address space
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
465 info->save_type = SAVE_NONE;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
466 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
467
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
468 rom_info configure_rom_heuristics(uint8_t *rom, uint32_t rom_size, memmap_chunk const *base_map, uint32_t base_chunks)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
469 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
470 rom_info info;
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
471 info.mapper_type = MAPPER_NONE;
2402
49b7ead35482 Fix asan violation that occurs when locking on a cart with its own mapper hardware
Michael Pavone <pavone@retrodev.com>
parents: 2340
diff changeset
472 info.mapper_start_index = 0;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
473 info.name = get_header_name(rom);
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
474 info.regions = get_header_regions(rom);
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
475 info.is_save_lock_on = 0;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
476 info.rom = rom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
477 info.rom_size = rom_size;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
478 info.wants_cd = 0;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
479 for (uint32_t offset = 0x190; offset < rom_size && offset < 0x1A0; offset++)
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
480 {
2161
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
481 uint8_t invalid = 0;
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
482 switch(rom[offset])
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
483 {
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
484 case 'J':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
485 case '6':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
486 case '0':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
487 case 'A':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
488 case '4':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
489 case 'G':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
490 case 'L':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
491 case 'M':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
492 case 'B':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
493 case 'K':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
494 case 'R':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
495 case 'D':
2163
0bf077df45c3 Fix regression in Mode 1 CD detection
Michael Pavone <pavone@retrodev.com>
parents: 2161
diff changeset
496 case 'P':
2161
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
497 //valid device letter
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
498 //TODO: do something with these
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
499 break;
2163
0bf077df45c3 Fix regression in Mode 1 CD detection
Michael Pavone <pavone@retrodev.com>
parents: 2161
diff changeset
500 case ' ':
0bf077df45c3 Fix regression in Mode 1 CD detection
Michael Pavone <pavone@retrodev.com>
parents: 2161
diff changeset
501 //blanks are okay
0bf077df45c3 Fix regression in Mode 1 CD detection
Michael Pavone <pavone@retrodev.com>
parents: 2161
diff changeset
502 break;
2161
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
503 case 'F':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
504 case 'T':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
505 //unreleased peripheral, probably garbage
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
506 invalid = 1;
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
507 break;
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
508 case 'C':
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
509 info.wants_cd = 1;
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
510 break;
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
511 default:
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
512 invalid = 1;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
513 }
2161
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
514 if (invalid) {
6a954675d634 Improved detection of bogus device headers
Michael Pavone <pavone@retrodev.com>
parents: 2159
diff changeset
515 info.wants_cd = 0;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
516 break;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
517 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
518 }
2109
5d575c42fff5 Fix regression in MED extended sega mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2097
diff changeset
519 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
5d575c42fff5 Fix regression in MED extended sega mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2097
diff changeset
520 info.port1_override = info.port2_override = info.ext_override = info.mouse_mode = NULL;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
521
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
522 return info;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
523 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
524
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
525 typedef struct {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
526 rom_info *info;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
527 uint8_t *rom;
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
528 uint8_t *lock_on;
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
529 tern_node *root;
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
530 tern_node *rom_db;
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
531 uint32_t rom_size;
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
532 uint32_t lock_on_size;
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
533 int index;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
534 int num_els;
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
535 uint16_t ptr_index;
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
536 } map_iter_state;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
537
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
538 void eeprom_read_fun(char *key, tern_val val, uint8_t valtype, void *data)
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
539 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
540 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
541 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
542 fprintf(stderr, "bit %s is out of range", key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
543 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
544 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
545 if (valtype != TVAL_PTR) {
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
546 fprintf(stderr, "bit %s has a non-scalar value", key);
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
547 return;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
548 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
549 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
550 if (strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
551 fprintf(stderr, "bit %s is connected to unrecognized read pin %s", key, pin);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
552 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
553 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
554 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
555 map->sda_read_bit = bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
556 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
557
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
558 void eeprom_write_fun(char *key, tern_val val, uint8_t valtype, void *data)
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
559 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
560 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
561 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
562 fprintf(stderr, "bit %s is out of range", key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
563 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
564 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
565 if (valtype != TVAL_PTR) {
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
566 fprintf(stderr, "bit %s has a non-scalar value", key);
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
567 return;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
568 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
569 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
570 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
571 if (!strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
572 map->sda_write_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
573 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
574 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
575 if (!strcmp(pin, "scl")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
576 map->scl_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
577 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
578 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
579 fprintf(stderr, "bit %s is connected to unrecognized write pin %s", key, pin);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
580 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
581
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
582 void process_sram_def(char *key, map_iter_state *state)
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
583 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
584 if (!state->info->save_size) {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
585 char * size = tern_find_path(state->root, "SRAM\0size\0", TVAL_PTR).ptrval;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
586 if (!size) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
587 fatal_error("ROM DB map entry %d with address %s has device type SRAM, but the SRAM size is not defined\n", state->index, key);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
588 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
589 state->info->save_size = atoi(size);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
590 if (!state->info->save_size) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
591 fatal_error("SRAM size %s is invalid\n", size);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
592 }
775
22728a57d7f3 Populate save mask when SRAM is defined in ROM DB rather than cart header
Michael Pavone <pavone@retrodev.com>
parents: 774
diff changeset
593 state->info->save_mask = nearest_pow2(state->info->save_size)-1;
1847
882746581f17 Make sure on-cart memories are fully initialized in all cases
Michael Pavone <pavone@retrodev.com>
parents: 1822
diff changeset
594 state->info->save_buffer = calloc(state->info->save_size, 1);
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
595 char *bus = tern_find_path(state->root, "SRAM\0bus\0", TVAL_PTR).ptrval;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
596 if (!strcmp(bus, "odd")) {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
597 state->info->save_type = RAM_FLAG_ODD;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
598 } else if(!strcmp(bus, "even")) {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
599 state->info->save_type = RAM_FLAG_EVEN;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
600 } else {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
601 state->info->save_type = RAM_FLAG_BOTH;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
602 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
603 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
604 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
605
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
606 void process_eeprom_def(char * key, map_iter_state *state)
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
607 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
608 if (!state->info->save_size) {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
609 char * size = tern_find_path(state->root, "EEPROM\0size\0", TVAL_PTR).ptrval;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
610 if (!size) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
611 fatal_error("ROM DB map entry %d with address %s has device type EEPROM, but the EEPROM size is not defined\n", state->index, key);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
612 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
613 state->info->save_size = atoi(size);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
614 if (!state->info->save_size) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
615 fatal_error("EEPROM size %s is invalid\n", size);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
616 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
617 char *etype = tern_find_path(state->root, "EEPROM\0type\0", TVAL_PTR).ptrval;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
618 if (!etype) {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
619 etype = "i2c";
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
620 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
621 if (!strcmp(etype, "i2c")) {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
622 state->info->save_type = SAVE_I2C;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
623 } else {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
624 fatal_error("EEPROM type %s is invalid\n", etype);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
625 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
626 state->info->save_buffer = malloc(state->info->save_size);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
627 memset(state->info->save_buffer, 0xFF, state->info->save_size);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
628 state->info->eeprom_map = malloc(sizeof(eeprom_map) * state->num_els);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
629 memset(state->info->eeprom_map, 0, sizeof(eeprom_map) * state->num_els);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
630 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
631 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
632
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
633 void process_nor_def(char *key, map_iter_state *state)
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
634 {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
635 if (!state->info->save_size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
636 char *size = tern_find_path(state->root, "NOR\0size\0", TVAL_PTR).ptrval;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
637 if (!size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
638 fatal_error("ROM DB map entry %d with address %s has device type NOR, but the NOR size is not defined\n", state->index, key);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
639 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
640 state->info->save_size = atoi(size);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
641 if (!state->info->save_size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
642 fatal_error("NOR size %s is invalid\n", size);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
643 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
644 char *page_size = tern_find_path(state->root, "NOR\0page_size\0", TVAL_PTR).ptrval;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
645 if (!page_size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
646 fatal_error("ROM DB map entry %d with address %s has device type NOR, but the NOR page size is not defined\n", state->index, key);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
647 }
1519
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
648 uint32_t save_page_size = atoi(page_size);
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
649 if (!save_page_size) {
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
650 fatal_error("NOR page size %s is invalid\n", page_size);
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
651 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
652 char *product_id = tern_find_path(state->root, "NOR\0product_id\0", TVAL_PTR).ptrval;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
653 if (!product_id) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
654 fatal_error("ROM DB map entry %d with address %s has device type NOR, but the NOR product ID is not defined\n", state->index, key);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
655 }
1519
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
656 uint16_t save_product_id = strtol(product_id, NULL, 16);
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
657 char *bus = tern_find_path(state->root, "NOR\0bus\0", TVAL_PTR).ptrval;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
658 if (!strcmp(bus, "odd")) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
659 state->info->save_bus = RAM_FLAG_ODD;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
660 } else if(!strcmp(bus, "even")) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
661 state->info->save_bus = RAM_FLAG_EVEN;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
662 } else {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
663 state->info->save_bus = RAM_FLAG_BOTH;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
664 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
665 state->info->save_type = SAVE_NOR;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
666 state->info->save_buffer = malloc(state->info->save_size);
1519
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
667 char *init = tern_find_path_default(state->root, "NOR\0init\0", (tern_val){.ptrval="FF"}, TVAL_PTR).ptrval;
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
668 if (!strcmp(init, "ROM")) {
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
669 uint32_t init_size = state->rom_size > state->info->save_size ? state->info->save_size : state->rom_size;
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
670 memcpy(state->info->save_buffer, state->rom, init_size);
1847
882746581f17 Make sure on-cart memories are fully initialized in all cases
Michael Pavone <pavone@retrodev.com>
parents: 1822
diff changeset
671 if (init_size < state->info->save_size) {
882746581f17 Make sure on-cart memories are fully initialized in all cases
Michael Pavone <pavone@retrodev.com>
parents: 1822
diff changeset
672 memset(state->info->save_buffer + init_size, 0xFF, state->info->save_size - init_size);
882746581f17 Make sure on-cart memories are fully initialized in all cases
Michael Pavone <pavone@retrodev.com>
parents: 1822
diff changeset
673 }
1519
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
674 if (state->info->save_bus == RAM_FLAG_BOTH) {
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
675 byteswap_rom(state->info->save_size, (uint16_t *)state->info->save_buffer);
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
676 }
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
677 } else {
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
678 memset(state->info->save_buffer, strtol(init, NULL, 16), state->info->save_size);
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
679 }
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
680 state->info->nor = calloc(1, sizeof(nor_state));
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
681 nor_flash_init(state->info->nor, state->info->save_buffer, state->info->save_size, save_page_size, save_product_id, state->info->save_bus);
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
682 char *cmd1 = tern_find_path(state->root, "NOR\0cmd_address1\0", TVAL_PTR).ptrval;
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
683 if (cmd1) {
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
684 state->info->nor->cmd_address1 = strtol(cmd1, NULL, 16);
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
685 }
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
686 char *cmd2 = tern_find_path(state->root, "NOR\0cmd_address2\0", TVAL_PTR).ptrval;
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
687 if (cmd2) {
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
688 state->info->nor->cmd_address2 = strtol(cmd2, NULL, 16);
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
689 }
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
690 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
691 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
692
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
693 void add_eeprom_map(tern_node *node, uint32_t start, uint32_t end, map_iter_state *state)
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
694 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
695 eeprom_map *eep_map = state->info->eeprom_map + state->info->num_eeprom;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
696 eep_map->start = start;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
697 eep_map->end = end;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
698 eep_map->sda_read_bit = 0xFF;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
699 tern_node * bits_read = tern_find_node(node, "bits_read");
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
700 if (bits_read) {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
701 tern_foreach(bits_read, eeprom_read_fun, eep_map);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
702 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
703 tern_node * bits_write = tern_find_node(node, "bits_write");
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
704 if (bits_write) {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
705 tern_foreach(bits_write, eeprom_write_fun, eep_map);
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
706 }
1792
52a47611a273 Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents: 1610
diff changeset
707 debug_message("EEPROM address %X: sda read: %X, sda write: %X, scl: %X\n", start, eep_map->sda_read_bit, eep_map->sda_write_mask, eep_map->scl_mask);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
708 state->info->num_eeprom++;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
709 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
710
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
711 char *map_node_common(char *key, tern_val val, uint8_t valtype, map_iter_state *state)
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
712 {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
713 if (valtype != TVAL_NODE) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
714 fatal_error("ROM DB map entry %d with address %s is not a node\n", state->index, key);
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
715 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
716 tern_node *node = val.ptrval;
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
717 uint32_t start = strtol(key, NULL, 16);
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
718 uint32_t end = strtol(tern_find_ptr_default(node, "last", "0"), NULL, 16);
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
719 if (!end || end < start) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 781
diff changeset
720 fatal_error("'last' value is missing or invalid for ROM DB map entry %d with address %s\n", state->index, key);
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
721 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
722 char * dtype = tern_find_ptr_default(node, "device", "ROM");
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
723 uint32_t offset = strtol(tern_find_ptr_default(node, "offset", "0"), NULL, 16);
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
724 memmap_chunk *map = state->info->map + state->index;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
725 map->start = start;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
726 map->end = end + 1;
2340
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2325
diff changeset
727
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
728 if (!strcmp(dtype, "ROM")) {
2150
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
729 uint32_t expanded_size = nearest_pow2(state->rom_size);
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
730 if (offset >= expanded_size) {
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
731 fatal_error("offset of %X is invalid for ROM size of %X in map entry %d with addess %s\n", offset, state->rom_size, state->index, key);
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
732 }
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
733 map->buffer = state->rom + offset;
2150
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
734 map->mask = calc_mask(nearest_pow2(state->rom_size) - offset, start, end);
1470
1e3e0205640f Add support for writeable ROM and an entry for Game no Kanzume Otokuyou using that support as it expects the cart area to be writable
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
735 if (strcmp(tern_find_ptr_default(node, "writeable", "no"), "yes")) {
1e3e0205640f Add support for writeable ROM and an entry for Game no Kanzume Otokuyou using that support as it expects the cart area to be writable
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
736 map->flags = MMAP_READ;
1e3e0205640f Add support for writeable ROM and an entry for Game no Kanzume Otokuyou using that support as it expects the cart area to be writable
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
737 } else {
1e3e0205640f Add support for writeable ROM and an entry for Game no Kanzume Otokuyou using that support as it expects the cart area to be writable
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
738 map->flags = MMAP_READ | MMAP_WRITE | MMAP_CODE;
1e3e0205640f Add support for writeable ROM and an entry for Game no Kanzume Otokuyou using that support as it expects the cart area to be writable
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
739 }
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
740 return NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
741 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
742 if (!strcmp(dtype, "EEPROM")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
743 process_eeprom_def(key, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
744 add_eeprom_map(node, start, end, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
745
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
746 map->write_16 = write_eeprom_i2c_w;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
747 map->write_8 = write_eeprom_i2c_b;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
748 map->read_16 = read_eeprom_i2c_w;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
749 map->read_8 = read_eeprom_i2c_b;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
750 map->mask = 0xFFFFFF;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
751 return NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
752 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
753 if (!strcmp(dtype, "SRAM")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
754 process_sram_def(key, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
755 map->buffer = state->info->save_buffer + offset;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
756 map->flags = MMAP_READ | MMAP_WRITE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
757 uint32_t save_size_mask = state->info->save_size;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
758 if (state->info->save_type == RAM_FLAG_ODD) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
759 map->flags |= MMAP_ONLY_ODD;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
760 save_size_mask *= 2;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
761 } else if(state->info->save_type == RAM_FLAG_EVEN) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
762 map->flags |= MMAP_ONLY_EVEN;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
763 save_size_mask *= 2;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
764 } else {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
765 map->flags |= MMAP_CODE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
766 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
767 map->mask = calc_mask(save_size_mask, start, end);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
768 return NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
769 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
770 if (!strcmp(dtype, "RAM")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
771 uint32_t size = strtol(tern_find_ptr_default(node, "size", "0"), NULL, 16);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
772 if (!size || size > map->end - map->start) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
773 size = map->end - map->start;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
774 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
775 map->buffer = calloc(size, 1);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
776 map->flags = MMAP_READ | MMAP_WRITE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
777 char *bus = tern_find_ptr_default(node, "bus", "both");
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
778 if (!strcmp(bus, "odd")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
779 map->flags |= MMAP_ONLY_ODD;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
780 size *= 2;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
781 } else if (!strcmp(bus, "even")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
782 map->flags |= MMAP_ONLY_EVEN;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
783 size *= 2;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
784 } else {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
785 map->flags |= MMAP_CODE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
786 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
787 map->mask = calc_mask(size, start, end);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
788 return NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
789 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
790 if (!strcmp(dtype, "NOR")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
791 process_nor_def(key, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
792
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
793 map->write_16 = nor_flash_write_w;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
794 map->write_8 = nor_flash_write_b;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
795 map->read_16 = nor_flash_read_w;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
796 map->read_8 = nor_flash_read_b;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
797 if (state->info->save_bus == RAM_FLAG_BOTH) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
798 map->flags |= MMAP_READ_CODE | MMAP_CODE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
799 map->buffer = state->info->save_buffer;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
800 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
801 map->mask = 0xFFFFFF;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
802 return NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
803 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
804 if (!strcmp(dtype, "fixed")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
805 uint16_t *value = malloc(2);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
806 map->buffer = value;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
807 map->mask = 0;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
808 map->flags = MMAP_READ;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
809 *value = strtol(tern_find_ptr_default(node, "value", "0"), NULL, 16);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
810 return NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
811 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
812 return dtype;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
813 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
814
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
815 void map_iter_fun(char *key, tern_val val, uint8_t valtype, void *data)
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
816 {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
817 map_iter_state *state = data;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
818 char *dtype = map_node_common(key, val, valtype, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
819 if (!dtype) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
820 //entry was handled by common function
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
821 state->index++;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
822 return;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
823 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
824 tern_node *node = val.ptrval;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
825 memmap_chunk *map = state->info->map + state->index;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
826 uint32_t offset = strtol(tern_find_ptr_default(node, "offset", "0"), NULL, 16);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
827 if (!strcmp(dtype, "LOCK-ON")) {
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
828 rom_info lock_info;
1408
71b6e2298e4a Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
829 if (state->lock_on) {
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
830 lock_info = configure_rom(state->rom_db, state->lock_on, state->lock_on_size, NULL, 0, NULL, 0);
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
831 } else if (state->rom_size > map->start) {
1408
71b6e2298e4a Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
832 //This is a bit of a hack to deal with pre-combined S3&K/S2&K ROMs and S&K ROM hacks
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
833 lock_info = configure_rom(state->rom_db, state->rom + map->start, state->rom_size - map->start, NULL, 0, NULL, 0);
1408
71b6e2298e4a Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
834 } else {
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
835 //skip this entry if there is no lock on cartridge attached
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
836 return;
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
837 }
2402
49b7ead35482 Fix asan violation that occurs when locking on a cart with its own mapper hardware
Michael Pavone <pavone@retrodev.com>
parents: 2340
diff changeset
838 //TODO: detect if this conflicts with host cart mapper
49b7ead35482 Fix asan violation that occurs when locking on a cart with its own mapper hardware
Michael Pavone <pavone@retrodev.com>
parents: 2340
diff changeset
839 state->info->mapper_start_index = lock_info.mapper_start_index;
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
840 uint32_t matching_chunks = 0;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
841 for (int i = 0; i < lock_info.map_chunks; i++)
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
842 {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
843 if (lock_info.map[i].start < 0xC00000 && lock_info.map[i].end > 0x200000) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
844 matching_chunks++;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
845 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
846 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
847 if (matching_chunks == 0) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
848 //Nothing mapped in the relevant range for the lock-on cart, ignore this mapping
1593
24508cb54f87 Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents: 1592
diff changeset
849 free_rom_info(&lock_info);
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
850 return;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
851 } else if (matching_chunks > 1) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
852 state->info->map_chunks += matching_chunks - 1;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
853 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
854 memset(state->info->map + state->info->map_chunks - (matching_chunks - 1), 0, sizeof(memmap_chunk) * (matching_chunks - 1));
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
855 map = state->info->map + state->index;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
856 }
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
857 for (int i = 0; i < lock_info.map_chunks; i++)
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
858 {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
859 if (lock_info.map[i].start >= 0xC00000 || lock_info.map[i].end <= 0x200000) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
860 continue;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
861 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
862 *map = lock_info.map[i];
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
863 if (map->start < 0x200000) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
864 if (map->buffer) {
2403
8171409b62ef Fix incorrect manipulation of lock-on cart memory map
Michael Pavone <pavone@retrodev.com>
parents: 2402
diff changeset
865 uint32_t mask = (map->flags & MMAP_AUX_BUFF) ? map->aux_mask : map->mask;
8171409b62ef Fix incorrect manipulation of lock-on cart memory map
Michael Pavone <pavone@retrodev.com>
parents: 2402
diff changeset
866 if (mask < 0x3FFFFF) {
8171409b62ef Fix incorrect manipulation of lock-on cart memory map
Michael Pavone <pavone@retrodev.com>
parents: 2402
diff changeset
867 uint8_t *buf = map->buffer;
8171409b62ef Fix incorrect manipulation of lock-on cart memory map
Michael Pavone <pavone@retrodev.com>
parents: 2402
diff changeset
868 buf += (0x200000 - map->start) & mask;
8171409b62ef Fix incorrect manipulation of lock-on cart memory map
Michael Pavone <pavone@retrodev.com>
parents: 2402
diff changeset
869 map->buffer = buf;
8171409b62ef Fix incorrect manipulation of lock-on cart memory map
Michael Pavone <pavone@retrodev.com>
parents: 2402
diff changeset
870 }
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
871 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
872 map->start = 0x200000;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
873 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
874 map++;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
875 state->index++;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
876 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
877 if (state->info->save_type == SAVE_NONE && lock_info.save_type != SAVE_NONE) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
878 //main cart has no save device, but lock-on cart does
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
879 if (state->lock_on) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
880 state->info->is_save_lock_on = 1;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
881 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
882 state->info->save_buffer = lock_info.save_buffer;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
883 state->info->save_size = lock_info.save_size;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
884 state->info->save_mask = lock_info.save_mask;
1519
1f745318f10a Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents: 1513
diff changeset
885 state->info->nor = lock_info.nor;
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
886 state->info->save_type = lock_info.save_type;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
887 state->info->save_bus = lock_info.save_bus;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
888 lock_info.save_buffer = NULL;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
889 lock_info.save_type = SAVE_NONE;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
890 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
891 free_rom_info(&lock_info);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
892 return;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
893 } else if (!strcmp(dtype, "Sega mapper")) {
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
894 state->info->mapper_type = MAPPER_SEGA;
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
895 state->info->mapper_start_index = state->ptr_index++;
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
896 char *variant = tern_find_ptr_default(node, "variant", "full");
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
897 char *save_device = tern_find_path(node, "save\0device\0", TVAL_PTR).ptrval;
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
898 if (save_device && !strcmp(save_device, "EEPROM")) {
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
899 process_eeprom_def(key, state);
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
900 add_eeprom_map(node, map->start & map->mask, (map->end - 1) & map->mask, state);
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
901 } else if (save_device && !strcmp(save_device, "SRAM")) {
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
902 process_sram_def(key, state);
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
903 } else if(has_ram_header(state->rom, state->rom_size)) {
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
904 //no save definition in ROM DB entry, but there is an SRAM header
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
905 //this support is mostly to handle homebrew that uses the SSF2 product ID
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
906 //in an attempt to signal desire for the full Sega/SSF2 mapper, but also uses SRAM unlike SSF2
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
907 read_ram_header(state->info, state->rom);
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
908 }
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
909 if (!strcmp(variant, "save-only")) {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
910 state->info->map_chunks+=1;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
911 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
912 memset(state->info->map + state->info->map_chunks - 1, 0, sizeof(memmap_chunk) * 1);
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
913 map = state->info->map + state->index;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
914 offset &= nearest_pow2(state->rom_size) - 1;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
915 map->buffer = state->rom + offset;
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
916 map->mask = calc_mask(state->rom_size - offset, map->start, map->end - 1);
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
917 map->ptr_index = state->info->mapper_start_index;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
918 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
919 if (save_device && !strcmp(save_device, "EEPROM")) {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
920 map->write_16 = write_eeprom_i2c_w;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
921 map->write_8 = write_eeprom_i2c_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
922 map->read_16 = read_eeprom_i2c_w;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
923 map->read_8 = read_eeprom_i2c_b;
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
924 } else {
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
925 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[ptr_idx] == NULL
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
926 map->read_8 = (read_8_fun)read_sram_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
927 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
928 map->write_8 = (write_8_fun)write_sram_area_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
929 }
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
930 state->index++;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
931 map++;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
932 } else {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
933 state->info->map_chunks+=7;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
934 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
935 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7);
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
936 map = state->info->map + state->index;
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
937 uint32_t start = map->start;
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
938 for (int i = 0; i < 7; i++, state->index++, map++)
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
939 {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
940 map->start = start + i * 0x80000;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
941 map->end = start + (i + 1) * 0x80000;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
942 map->mask = 0x7FFFF;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
943 map->buffer = state->rom + offset + i * 0x80000;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
944 map->ptr_index = state->ptr_index++;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
945 if (i < 3) {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
946 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE;
1409
b0e0bb20fc41 Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1408
diff changeset
947 } else {
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
948 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
949 if (save_device && !strcmp(save_device, "EEPROM")) {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
950 map->write_16 = write_eeprom_i2c_w;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
951 map->write_8 = write_eeprom_i2c_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
952 map->read_16 = read_eeprom_i2c_w;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
953 map->read_8 = read_eeprom_i2c_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
954 } else {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
955 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
956 map->read_8 = (read_8_fun)read_sram_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
957 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
958 map->write_8 = (write_8_fun)write_sram_area_b;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
959 }
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
960 }
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
961 }
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 775
diff changeset
962 }
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
963 map->start = 0xA13000;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
964 map->end = 0xA13100;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
965 map->mask = 0xFF;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
966 map->write_16 = (write_16_fun)write_bank_reg_w;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
967 map->write_8 = (write_8_fun)write_bank_reg_b;
1822
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1810
diff changeset
968 #ifndef IS_LIB
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
969 } else if (!strcmp(dtype, "MENU")) {
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
970 //fake hardware for supporting menu
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
971 map->buffer = NULL;
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
972 map->mask = 0xFF;
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
973 map->write_16 = menu_write_w;
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
974 map->read_16 = menu_read_w;
1822
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1810
diff changeset
975 #endif
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
976 } else if (!strcmp(dtype, "multi-game")) {
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
977 state->info->mapper_type = MAPPER_MULTI_GAME;
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
978 state->info->mapper_start_index = state->ptr_index++;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
979 //make a mirror copy of the ROM so we can efficiently support arbitrary start offsets
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
980 state->rom = realloc(state->rom, state->rom_size * 2);
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
981 memcpy(state->rom + state->rom_size, state->rom, state->rom_size);
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
982 state->rom_size *= 2;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
983 //make room for an extra map entry
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
984 state->info->map_chunks+=1;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
985 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
986 memset(state->info->map + state->info->map_chunks - 1, 0, sizeof(memmap_chunk) * 1);
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
987 map = state->info->map + state->index;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
988 map->buffer = state->rom;
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
989 map->mask = calc_mask(state->rom_size, map->start, map->end - 1);
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
990 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
991 map->ptr_index = state->info->mapper_start_index;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
992 map++;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
993 state->index++;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
994 map->start = 0xA13000;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
995 map->end = 0xA13100;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
996 map->mask = 0xFF;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
997 map->write_16 = write_multi_game_w;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
998 map->write_8 = write_multi_game_b;
1513
8f3b6a64b658 Initial work on MegaWiFi support
Michael Pavone <pavone@retrodev.com>
parents: 1470
diff changeset
999 } else if (!strcmp(dtype, "megawifi")) {
1548
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1000 if (!strcmp(
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1001 "on",
1548
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1002 tern_find_path_default(config, "system\0megawifi\0", (tern_val){.ptrval="off"}, TVAL_PTR).ptrval)
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1003 ) {
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1004 map->write_16 = megawifi_write_w;
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1005 map->write_8 = megawifi_write_b;
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1006 map->read_16 = megawifi_read_w;
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1007 map->read_8 = megawifi_read_b;
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1008 map->mask = 0xFFFFFF;
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1009 } else {
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1010 warning("ROM uses MegaWiFi, but it is disabled\n");
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1011 return;
94ba407a5ec1 Allow MegaWiFi support to be toggled in config file. Defaults to off due to security concerns
Michael Pavone <pavone@retrodev.com>
parents: 1519
diff changeset
1012 }
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1013 } else if (!strcmp(dtype, "jcart")) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1014 state->info->mapper_type = MAPPER_JCART;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1015 map->write_16 = jcart_write_w;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1016 map->write_8 = jcart_write_b;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1017 map->read_16 = jcart_read_w;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1018 map->read_8 = jcart_read_b;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
1019 map->mask = 0xFFFFFF;
2253
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1020 } else if (!strcmp(dtype, "sft-wukong-fixed") || !strcmp(dtype, "sft-wukong-remap")) {
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1021 state->info->mapper_type = MAPPER_SFT_WUKONG;
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1022 uint32_t expanded_size = nearest_pow2(state->rom_size);
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1023 if (offset >= expanded_size) {
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1024 fatal_error("offset of %X is invalid for ROM size of %X in map entry %d with addess %s\n", offset, state->rom_size, state->index, key);
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1025 }
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1026 map->buffer = state->rom + offset;
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1027 map->mask = calc_mask(nearest_pow2(state->rom_size) - offset, map->start, map->end - 1);
2253
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1028 map->write_8 = sft_wukong_write_b;
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1029 map->write_16 = sft_wukong_write_w;
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1030 if (!strcmp(dtype, "sft-wukong-remap")) {
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1031 map->flags = MMAP_READ | MMAP_CODE | MMAP_PTR_IDX;
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1032 state->info->mapper_start_index = state->ptr_index++;
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1033 } else {
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1034 map->flags = MMAP_READ;
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1035 }
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1036 } else {
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1037 fatal_error("Invalid device type %s for ROM DB map entry %d with address %s\n", dtype, state->index, key);
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1038 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1039 state->index++;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1040 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1041
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1042 void handle_io_overrides(tern_node *entry, rom_info *info)
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1043 {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1044 tern_node *device_overrides = tern_find_node(entry, "device_overrides");
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1045 if (device_overrides) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1046 info->port1_override = tern_find_ptr(device_overrides, "1");
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1047 info->port2_override = tern_find_ptr(device_overrides, "2");
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1048 info->ext_override = tern_find_ptr(device_overrides, "ext");
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1049 if (
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1050 info->save_type == SAVE_NONE
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1051 && (
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1052 (info->port1_override && startswith(info->port1_override, "heartbeat_trainer."))
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1053 || (info->port2_override && startswith(info->port2_override, "heartbeat_trainer."))
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1054 || (info->ext_override && startswith(info->ext_override, "heartbeat_trainer."))
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1055 )
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1056 ) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1057 info->save_type = SAVE_HBPT;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1058 info->save_size = atoi(tern_find_path_default(entry, "HeartbeatTrainer\0size\0", (tern_val){.ptrval="512"}, TVAL_PTR).ptrval);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1059 info->save_buffer = calloc(info->save_size + 5 + 8, 1);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1060 memset(info->save_buffer, 0xFF, info->save_size);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1061 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1062 } else {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1063 info->port1_override = info->port2_override = info->ext_override = NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1064 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1065 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1066
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1067 rom_info configure_rom(tern_node *rom_db, void *vrom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, memmap_chunk const *base_map, uint32_t base_chunks)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1068 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1069 uint8_t product_id[GAME_ID_LEN+1];
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1070 uint8_t *rom = vrom;
2150
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1071 uint32_t expanded_size = nearest_pow2(rom_size);
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1072 if (expanded_size > rom_size) {
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1073 //generally carts with odd-sized ROMs have 2 power of 2 sized ROMs with the larger one first
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1074 //TODO: Handle cases in which the 2nd ROM/part is a maller power of 2 than just half the first one
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1075 uint32_t mirror_start = expanded_size >> 1;
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1076 uint32_t mirror_size = expanded_size >> 2;
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1077 if (mirror_start + mirror_size >= rom_size) {
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1078 memcpy(rom + mirror_start + mirror_size, rom + mirror_start, mirror_size);
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1079 }
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2109
diff changeset
1080 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1081 product_id[GAME_ID_LEN] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1082 for (int i = 0; i < GAME_ID_LEN; i++)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1083 {
2253
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1084 if (i >= 3 && rom[GAME_ID_OFF + i] <= ' ') {
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1085 product_id[i] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1086 break;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1087 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1088 product_id[i] = rom[GAME_ID_OFF + i];
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
1089
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1090 }
1792
52a47611a273 Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents: 1610
diff changeset
1091 debug_message("Product ID: %s\n", product_id);
1305
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
1092 uint8_t raw_hash[20];
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
1093 sha1(vrom, rom_size, raw_hash);
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
1094 uint8_t hex_hash[41];
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
1095 bin_to_hex(hex_hash, raw_hash, 20);
1792
52a47611a273 Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents: 1610
diff changeset
1096 debug_message("SHA1: %s\n", hex_hash);
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
1097 tern_node * entry = tern_find_node(rom_db, hex_hash);
1305
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
1098 if (!entry) {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
1099 entry = tern_find_node(rom_db, product_id);
1305
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
1100 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1101 if (!entry) {
2253
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1102 entry = tern_find_node(rom_db, product_id + 3);
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1103 }
fd68fe5f723e Add support for mapper used in Super Fighter Team release of Legend of Wukong
Michael Pavone <pavone@retrodev.com>
parents: 2163
diff changeset
1104 if (!entry) {
1810
73a9d06413bc Restore some newlines in debug output that got lost when fixing GDB remote debugging issue
Michael Pavone <pavone@retrodev.com>
parents: 1794
diff changeset
1105 debug_message("Not found in ROM DB, examining header\n\n");
1259
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1106 if (xband_detect(rom, rom_size)) {
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1107 return xband_configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, base_map, base_chunks);
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1108 }
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1109 if (realtec_detect(rom, rom_size)) {
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1110 return realtec_configure_rom(rom, rom_size, base_map, base_chunks);
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1111 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1112 return configure_rom_heuristics(rom, rom_size, base_map, base_chunks);
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1113 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1114 rom_info info;
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1425
diff changeset
1115 info.mapper_type = MAPPER_NONE;
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1116 info.name = tern_find_ptr(entry, "name");
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1117 if (info.name) {
1810
73a9d06413bc Restore some newlines in debug output that got lost when fixing GDB remote debugging issue
Michael Pavone <pavone@retrodev.com>
parents: 1794
diff changeset
1118 debug_message("Found name: %s\n\n", info.name);
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1119 info.name = strdup(info.name);
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1120 } else {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1121 info.name = get_header_name(rom);
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1122 }
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
1123
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1124 char *dbreg = tern_find_ptr(entry, "regions");
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1125 info.regions = 0;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1126 if (dbreg) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1127 while (*dbreg != 0)
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1128 {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1129 info.regions |= translate_region_char(*(dbreg++));
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1130 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1131 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1132 if (!info.regions) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1133 info.regions = get_header_regions(rom);
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1134 }
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
1135
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
1136 info.is_save_lock_on = 0;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
1137 info.rom = vrom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
1138 info.rom_size = rom_size;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1324
diff changeset
1139 tern_node *map = tern_find_node(entry, "map");
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1140 if (map) {
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
1141 info.save_type = SAVE_NONE;
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1142 info.map_chunks = tern_count(map);
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1143 if (info.map_chunks) {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1144 info.map_chunks += base_chunks;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1145 info.save_buffer = NULL;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1146 info.save_size = 0;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1147 info.map = malloc(sizeof(memmap_chunk) * info.map_chunks);
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1148 info.eeprom_map = NULL;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1149 info.num_eeprom = 0;
774
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
1150 memset(info.map, 0, sizeof(memmap_chunk) * info.map_chunks);
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1151 map_iter_state state = {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1152 .info = &info,
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1153 .rom = rom,
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1154 .lock_on = lock_on,
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
1155 .root = entry,
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
1156 .rom_db = rom_db,
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1157 .rom_size = rom_size,
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1158 .lock_on_size = lock_on_size,
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1159 .index = 0,
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1160 .num_els = info.map_chunks - base_chunks,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1161 .ptr_index = 0
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1162 };
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1163 tern_foreach(map, map_iter_fun, &state);
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1164 memcpy(info.map + state.index, base_map, sizeof(memmap_chunk) * base_chunks);
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
1165 info.rom = state.rom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
1166 info.rom_size = state.rom_size;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1167 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1168 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1169 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1170 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1171 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1172 }
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
1173
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1174 handle_io_overrides(entry, &info);
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 913
diff changeset
1175 info.mouse_mode = tern_find_ptr(entry, "mouse_mode");
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
1176 info.wants_cd = !strcmp(tern_find_ptr_default(entry, "wants_cd", "no"), "yes");
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
1177
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1178 return info;
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1179 }
2320
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1180
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1181 void *sms_sega_mapper_write(uint32_t location, void *vcontext, uint8_t value);
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1182 void *sms_cart_ram_write(uint32_t location, void *vcontext, uint8_t value);
2325
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1183 void *sms_codemasters_bank0_write(uint32_t location, void *vcontext, uint8_t value);
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1184 void *sms_codemasters_bank1_write(uint32_t location, void *vcontext, uint8_t value);
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1185 void *sms_codemasters_bank2_write(uint32_t location, void *vcontext, uint8_t value);
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1186 void map_iter_fun_sms(char *key, tern_val val, uint8_t valtype, void *data)
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1187 {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1188 map_iter_state *state = data;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1189 char *dtype = map_node_common(key, val, valtype, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1190 if (!dtype) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1191 //entry was handled by common function
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1192 state->index++;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1193 return;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1194 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1195 tern_node *node = val.ptrval;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1196 memmap_chunk *map = state->info->map + state->index;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1197 uint32_t offset = strtol(tern_find_ptr_default(node, "offset", "0"), NULL, 16);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1198 if (!strcmp(dtype, "Sega mapper")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1199 state->info->mapper_type = MAPPER_SMS_SEGA;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1200 state->info->mapper_start_index = state->ptr_index++;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1201 char *save_device = tern_find_path(node, "save\0device\0", TVAL_PTR).ptrval;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1202 if (save_device && !strcmp(save_device, "EEPROM")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1203 process_eeprom_def(key, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1204 add_eeprom_map(node, map->start & map->mask, (map->end - 1) & map->mask, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1205 } else if (save_device && !strcmp(save_device, "SRAM")) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1206 process_sram_def(key, state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1207 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1208 state->info->map_chunks += 4;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1209 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1210 map = state->info->map + state->index;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1211 map[0].start = 0;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1212 map[0].end = 0x400;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1213 map[0].mask = 0xFFFF;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1214 map[0].flags = MMAP_READ;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1215 map[0].buffer = state->info->rom;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1216 map[1].start = 0x400;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1217 map[1].end = 0x4000;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1218 map[1].mask = 0x3FFF;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1219 map[1].ptr_index = 0;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1220 map[1].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1221 map[2].start = 0x4000;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1222 map[2].end = 0x8000;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1223 map[2].mask = 0x3FFF;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1224 map[2].ptr_index = 1;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1225 map[2].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1226 map[3].start = 0x8000;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1227 map[3].end = 0xC000;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1228 map[3].mask = 0x3FFF;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1229 map[3].ptr_index = 2;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1230 if (state->info->save_type == RAM_FLAG_ODD || state->info->save_type == RAM_FLAG_EVEN) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1231 map[3].write_8 = sms_cart_ram_write;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1232 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1233 map[3].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1234 map[4].start = 0xFFFC;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1235 map[4].end = 0x10000;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1236 map[4].mask = 3;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1237 map[4].flags = MMAP_READ;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1238 map[4].write_8 = sms_sega_mapper_write;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1239 } else {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1240 fatal_error("Invalid device type %s for ROM DB map entry %d with address %s\n", dtype, state->index, key);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1241 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1242 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1243
2325
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1244 uint8_t has_codemasters_header(uint8_t *rom, uint32_t rom_size)
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1245 {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1246 if (rom_size < 0x8000) {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1247 return 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1248 }
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1249 //Date and time fields should be valid BCD
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1250 for (uint32_t i = 0x7FE1; i < 0x7FE6; i++)
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1251 {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1252 if ((rom[i] & 0xF0) > 0x90) {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1253 return 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1254 }
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1255 if ((rom[i] & 0xF) > 0x9) {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1256 return 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1257 }
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1258 }
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1259 uint16_t checksum = rom[0x7FE6] | rom[0x7FE7] << 8;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1260 uint16_t complement = rom[0x7FE8] | rom[0x7FE9] << 8;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1261 if (complement != (0x10000 - checksum)) {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1262 return 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1263 }
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1264 puts("Detected codemasters mapper");
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1265 return 1;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1266 }
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1267
2320
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1268 void sms_memmap_heuristics(rom_info *info, memmap_chunk const *base_map, uint32_t num_base_chunks)
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1269 {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1270 uint32_t num_chunks = num_base_chunks + (info->rom_size > 0xC000 ? 5 : 1);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1271 memmap_chunk *chunks = calloc(num_chunks, sizeof(memmap_chunk));
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1272 info->map = chunks;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1273 info->map_chunks = num_chunks;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1274 if (info->rom_size > 0xC000) {
2325
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1275 if (has_codemasters_header(info->rom, info->rom_size)) {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1276 info->mapper_type = MAPPER_SMS_CODEMASTERS;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1277 memcpy(chunks + 3, base_map, sizeof(memmap_chunk) * num_base_chunks);
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1278 num_chunks--;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1279 chunks[0].start = 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1280 chunks[0].end = 0x4000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1281 chunks[0].mask = 0x3FFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1282 chunks[0].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1283 chunks[0].ptr_index = 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1284 chunks[0].write_8 = sms_codemasters_bank0_write;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1285 chunks[1].start = 0x4000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1286 chunks[1].end = 0x8000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1287 chunks[1].mask = 0x3FFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1288 chunks[1].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1289 chunks[1].ptr_index = 1;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1290 chunks[1].write_8 = sms_codemasters_bank1_write;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1291 chunks[2].start = 0x8000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1292 chunks[2].end = 0xC000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1293 chunks[2].mask = 0x3FFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1294 chunks[2].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1295 chunks[2].ptr_index = 2;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1296 chunks[2].write_8 = sms_codemasters_bank2_write;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1297 } else {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1298 info->mapper_type = MAPPER_SMS_SEGA;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1299 memcpy(chunks + 4, base_map, sizeof(memmap_chunk) * num_base_chunks);
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1300 chunks[0].start = 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1301 chunks[0].end = 0x400;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1302 chunks[0].mask = 0xFFFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1303 chunks[0].flags = MMAP_READ;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1304 chunks[0].buffer = info->rom;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1305 chunks[1].start = 0x400;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1306 chunks[1].end = 0x4000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1307 chunks[1].mask = 0x3FFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1308 chunks[1].ptr_index = 0;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1309 chunks[1].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1310 chunks[2].start = 0x4000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1311 chunks[2].end = 0x8000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1312 chunks[2].mask = 0x3FFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1313 chunks[2].ptr_index = 1;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1314 chunks[2].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1315 chunks[3].start = 0x8000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1316 chunks[3].end = 0xC000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1317 chunks[3].mask = 0x3FFF;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1318 chunks[3].ptr_index = 2;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1319 chunks[3].flags = MMAP_READ|MMAP_PTR_IDX|MMAP_CODE;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1320 chunks[3].write_8 = sms_cart_ram_write;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1321 chunks[num_chunks - 1].start = 0xFFFC;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1322 chunks[num_chunks - 1].end = 0x10000;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1323 chunks[num_chunks - 1].mask = 3;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1324 chunks[num_chunks - 1].flags = MMAP_READ;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1325 chunks[num_chunks - 1].write_8 = sms_sega_mapper_write;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1326 for (uint32_t i = 4; i < num_chunks - 1; i++)
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1327 {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1328 if (chunks[i].end > 0xFFFC) {
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1329 //mapper regs overlap RAM from base map
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1330 chunks[i].end = 0xFFFC;
26597f9805b4 Initial Codemasters mapper support
Michael Pavone <pavone@retrodev.com>
parents: 2321
diff changeset
1331 }
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1332 }
2320
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1333 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1334 } else {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1335 info->mapper_type = MAPPER_NONE;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1336 memcpy(chunks + 1, base_map, sizeof(memmap_chunk) * num_base_chunks);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1337 chunks[0].start = 0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1338 chunks[0].end = 0xC000;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1339 chunks[0].mask = nearest_pow2(info->rom_size)-1;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1340 chunks[0].flags = MMAP_READ;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1341 chunks[0].buffer = info->rom;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1342 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1343 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1344
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1345 void configure_rom_sms_heuristics(rom_info *info, uint32_t header_offset, memmap_chunk const *base_map, uint32_t num_base_chunks)
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1346 {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1347 sms_memmap_heuristics(info, base_map, num_base_chunks);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1348 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1349
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1350 uint8_t check_sms_sega_header(uint8_t *rom, char *product_code, uint32_t offset)
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1351 {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1352 if (memcmp(rom + offset, "TMR SEGA", strlen("TMR SEGA"))) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1353 return 0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1354 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1355 char *cur = product_code + 4;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1356 uint8_t begin = rom[offset + 0xE] >> 4;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1357 if (begin < 0xA) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1358 *(cur++) = begin + '0';
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1359 } else {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1360 *(cur++) = '1';
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1361 *(cur++) = begin - 0xA + '0';
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1362 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1363 uint8_t *src = rom + offset + 0xD;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1364 for (int i = 0; i < 2; i++, src--)
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1365 {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1366 *(cur++) = (*src >> 4) + '0';
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1367 *(cur++) = (*src & 0xF) + '0';
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1368 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1369 *cur = 0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1370 return 1;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1371 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1372
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1373 rom_info configure_rom_sms(tern_node *rom_db, uint8_t *rom, uint32_t rom_size, memmap_chunk const *base_chunks, uint32_t num_base_chunks)
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1374 {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1375 uint32_t expanded_size = nearest_pow2(rom_size);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1376 if (expanded_size > rom_size) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1377 //generally carts with odd-sized ROMs have 2 power of 2 sized ROMs with the larger one first
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1378 //TODO: Handle cases in which the 2nd ROM/part is a maller power of 2 than just half the first one
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1379 uint32_t mirror_start = expanded_size >> 1;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1380 uint32_t mirror_size = expanded_size >> 2;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1381 if (mirror_start + mirror_size >= rom_size) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1382 memcpy(rom + mirror_start + mirror_size, rom + mirror_start, mirror_size);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1383 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1384 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1385 char product_code[] = "sms:000000";
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1386 uint8_t found_header = 0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1387 uint32_t offset = 0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1388 if (rom_size >= 0x8000) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1389 offset = 0x7FF0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1390 found_header = check_sms_sega_header(rom, product_code, offset);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1391 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1392 if (!found_header && rom_size >= 0x4000) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1393 offset = 0x3FF0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1394 found_header = check_sms_sega_header(rom, product_code, offset);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1395 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1396 if (!found_header && rom_size >= 0x2000) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1397 offset = 0x1FF0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1398 found_header = check_sms_sega_header(rom, product_code, offset);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1399 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1400 debug_message("Product Code: %s\n", product_code);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1401 uint8_t raw_hash[20];
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1402 sha1(rom, rom_size, raw_hash);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1403 uint8_t hex_hash[41];
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1404 bin_to_hex(hex_hash, raw_hash, 20);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1405 debug_message("SHA1: %s\n", hex_hash);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1406 tern_node * entry = tern_find_node(rom_db, hex_hash);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1407 if (!entry) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1408 entry = tern_find_node(rom_db, product_code);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1409 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1410 rom_info info = {0};
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1411 info.rom_size = rom_size;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1412 info.rom = rom;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1413 if (!entry) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1414 debug_message("Not found in ROM DB, examining header\n\n");
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1415 configure_rom_sms_heuristics(&info, offset, base_chunks, num_base_chunks);
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1416 return info;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1417 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1418 char *dbreg = tern_find_ptr(entry, "regions");
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1419 info.regions = 0;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1420 if (dbreg) {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1421 while (*dbreg != 0)
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1422 {
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1423 info.regions |= translate_region_char(*(dbreg++));
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1424 }
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1425 }
2321
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1426 tern_node *map = tern_find_node(entry, "map");
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1427 if (map) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1428 info.save_type = SAVE_NONE;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1429 info.map_chunks = tern_count(map);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1430 if (info.map_chunks) {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1431 info.map_chunks += num_base_chunks;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1432 info.save_buffer = NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1433 info.save_size = 0;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1434 info.map = malloc(sizeof(memmap_chunk) * info.map_chunks);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1435 info.eeprom_map = NULL;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1436 info.num_eeprom = 0;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1437 memset(info.map, 0, sizeof(memmap_chunk) * info.map_chunks);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1438 map_iter_state state = {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1439 .info = &info,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1440 .rom = rom,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1441 .root = entry,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1442 .rom_db = rom_db,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1443 .rom_size = rom_size,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1444 .index = 0,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1445 .num_els = info.map_chunks - num_base_chunks,
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1446 .ptr_index = 0
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1447 };
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1448 tern_foreach(map, map_iter_fun_sms, &state);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1449 memcpy(info.map + state.index, base_chunks, sizeof(memmap_chunk) * num_base_chunks);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1450 info.rom = state.rom;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1451 info.rom_size = state.rom_size;
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1452 } else {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1453 sms_memmap_heuristics(&info, base_chunks, num_base_chunks);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1454 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1455 } else {
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1456 sms_memmap_heuristics(&info, base_chunks, num_base_chunks);
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1457 }
2eda5f81f91e More fully baked ROM db support for SMS
Michael Pavone <pavone@retrodev.com>
parents: 2320
diff changeset
1458 handle_io_overrides(entry, &info);
2320
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1459 return info;
8016dbb0fcde Initial work on ROM DB support for SMS/GG games
Michael Pavone <pavone@retrodev.com>
parents: 2253
diff changeset
1460 }