annotate romdb.c @ 1442:59e1dbb795a7

Update README in anticipation of 0.5.1 release
author Michael Pavone <pavone@retrodev.com>
date Fri, 25 Aug 2017 20:12:21 -0700
parents 49d3c572b3f2
children 14a2834d010c
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"
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
15 #define DOM_TITLE_START 0x120
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
16 #define DOM_TITLE_END 0x150
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
17 #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
18 #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
19 #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
20 #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
21 #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
22 #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
23 #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
24 #define REGION_START 0x1F0
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
26 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
27 {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
28 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
29 return "EEPROM";
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
30 } 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
31 return "NOR Flash";
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
32 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
33 return "SRAM";
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
34 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
35
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 tern_node *load_rom_db()
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
38 tern_node *db = parse_bundled_config("rom.db");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 if (!db) {
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
40 fatal_error("Failed to load ROM DB\n");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 return db;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
45 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
46 {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
47 free(info->name);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
48 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
49 free(info->save_buffer);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
50 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
51 free(info->eeprom_map);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
52 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
53 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
54 free(info->map);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
55 free(info->port1_override);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
56 free(info->port2_override);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
57 free(info->ext_override);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
58 free(info->mouse_mode);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
59 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
60
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 char *get_header_name(uint8_t *rom)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
63 //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
64 uint8_t *last = rom + TITLE_END - 1;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 uint8_t *src = rom + TITLE_START;
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
66
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
67 for (;;)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
69 while (last > src && (*last <= 0x20 || *last >= 0x80))
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
71 last--;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
72 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
73 if (last == src) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
74 if (src == rom + TITLE_START) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
75 src = rom + DOM_TITLE_START;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
76 last = rom + DOM_TITLE_END - 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
77 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
78 return strdup("UNKNOWN");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 }
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
80 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
81 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
82 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
83 uint8_t *dst;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
84 uint8_t last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
85 for (dst = ret; src < last; src++)
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
86 {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
87 if (*src >= 0x20 && *src < 0x80) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
88 if (*src == ' ') {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
89 if (last_was_space) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
90 continue;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
91 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
92 last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
93 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
94 last_was_space = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
95 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
96 *(dst++) = *src;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
97 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
98 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
99 *dst = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
100 return ret;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
105 char *region_chars = "JUEW";
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
106 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
107
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
108 uint8_t translate_region_char(uint8_t c)
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
109 {
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
110 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
111 {
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
112 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
113 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
114 }
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
115 }
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
116 uint8_t bin_region = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
117 if (c >= '0' && c <= '9') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
118 bin_region = c - '0';
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
119 } else if (c >= 'A' && c <= 'F') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
120 bin_region = c - 'A' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
121 } else if (c >= 'a' && c <= 'f') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
122 bin_region = c - 'a' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
123 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
124 uint8_t ret = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
125 if (bin_region & 8) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
126 ret |= REGION_E;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
127 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
128 if (bin_region & 4) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
129 ret |= REGION_U;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
130 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
131 if (bin_region & 1) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
132 ret |= REGION_J;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
133 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
134 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
135 }
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
136
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
137 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
138 {
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
139 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
140 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
141 {
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
142 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
143 }
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
144 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
145 }
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
146
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
147 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
148 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
149 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
150 }
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
151
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
152 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
153 {
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
154 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
155 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
156 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
157 } 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
158 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
159 } 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
160 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
161 }
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
162 }
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
163
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
164 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
165 {
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
166 return rom_size >= (RAM_END + 4) && rom[RAM_ID] == 'R' && rom[RAM_ID + 1] == 'A';
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
167 }
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
168
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
169 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
170 {
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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 }
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
180 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
181 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
182 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
183 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
184 }
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
185 info->save_size = save_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
186 info->save_buffer = malloc(save_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
187 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
188 }
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
189
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
190 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
191 {
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
192 uint32_t rom_end = get_u32be(rom + ROM_END) + 1;
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
193 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
194 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
195 } 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
196 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
197 }
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
198 if (size >= 0x80000 && !memcmp("SEGA SSF", rom + 0x100, 8)) {
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
199 info->mapper_start_index = 0;
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
200 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
201 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
202 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
203 memcpy(info->map+9, base_map, sizeof(memmap_chunk) * base_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
204
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
205 info->map[0].start = 0;
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
206 info->map[0].end = 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
207 info->map[0].mask = 0xFFFFFF;
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
208 info->map[0].flags = MMAP_READ;
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
209 info->map[0].buffer = 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
210
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
211 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
212 read_ram_header(info, 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
213 }
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
214
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
215 for (int i = 1; i < 8; i++)
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
216 {
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
217 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
218 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
219 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
220 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
221 info->map[i].ptr_index = i;
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
222 info->map[i].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
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
223
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
224 info->map[i].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[i] == NULL
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
225 info->map[i].read_8 = (read_8_fun)read_sram_b;
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
226 info->map[i].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
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
227 info->map[i].write_8 = (write_8_fun)write_sram_area_b;
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
228
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
229 }
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
230 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
231 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
232 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
233 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
234 info->map[8].write_8 = (write_8_fun)write_bank_reg_b;
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
235 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
236 } 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
237 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
238
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
239 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
240 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
241 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
242 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
243 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
244
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
245 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
246 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
247 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
248 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
249 }
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
250 //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
251 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
252 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
253 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
254
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
255 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
256 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
257 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
258 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
259
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
260 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
261 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
262 } 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
263 info->map[1].flags |= MMAP_ONLY_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
264 }
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
265 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
266 } 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
267 //Assume the standard Sega mapper
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
268 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
269 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
270 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
271 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
272
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
273 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
274 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
275 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
276 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
277 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
278 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
279 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
280 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
281 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
282 info->map[1].buffer = rom + 0x200000;
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
283
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
284 memmap_chunk *last = info->map + info->map_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
285 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
286 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
287 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
288 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
289 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
290 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
291 }
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
292 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
293 }
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
294 }
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
295
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
296 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
297 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
298 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
299 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
300
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
301 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
302 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
303 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
304 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
305 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
306 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
307
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
308 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
309 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
310 rom_info info;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
311 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
312 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
313 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
314 info.rom = rom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
315 info.rom_size = rom_size;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
316 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
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
317 info.port1_override = info.port2_override = info.ext_override = info.mouse_mode = NULL;
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
318 return info;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
319 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
320
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
321 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
322 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
323 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
324 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
325 tern_node *root;
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
326 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
327 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
328 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
329 int index;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
330 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
331 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
332 } 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
333
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
334 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
335 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
336 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
337 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
338 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
339 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
340 }
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
341 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
342 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
343 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
344 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
345 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
346 if (strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
347 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
348 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
349 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
350 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
351 map->sda_read_bit = bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
352 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
353
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
354 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
355 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
356 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
357 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
358 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
359 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
360 }
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
361 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
362 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
363 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
364 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
365 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
366 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
367 if (!strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
368 map->sda_write_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
369 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
370 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
371 if (!strcmp(pin, "scl")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
372 map->scl_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
373 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
374 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
375 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
376 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
377
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
378 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
379 {
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
380 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
381 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
382 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
383 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
384 }
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
385 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
386 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
387 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
388 }
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
389 state->info->save_mask = nearest_pow2(state->info->save_size)-1;
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
390 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
391 memset(state->info->save_buffer, 0, 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
392 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
393 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
394 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
395 } 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
396 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
397 } 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
398 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
399 }
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
400 }
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
401 }
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
402
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
403 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
404 {
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
405 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
406 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
407 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
408 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
409 }
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
410 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
411 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
412 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
413 }
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
414 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
415 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
416 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
417 }
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
418 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
419 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
420 } 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
421 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
422 }
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
423 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
424 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
425 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
426 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
427 }
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
428 }
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
429
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
430 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
431 {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
432 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
433 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
434 if (!size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
435 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
436 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
437 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
438 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
439 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
440 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
441 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
442 if (!page_size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
443 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
444 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
445 state->info->save_page_size = atoi(size);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
446 if (!state->info->save_page_size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
447 fatal_error("NOR page 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
448 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
449 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
450 if (!product_id) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
451 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
452 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
453 state->info->save_product_id = strtol(product_id, NULL, 16);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
454 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
455 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
456 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
457 } 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
458 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
459 } else {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
460 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
461 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
462 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
463 state->info->save_buffer = malloc(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
464 memset(state->info->save_buffer, 0xFF, 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
465 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
466 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
467
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
468 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
469 {
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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 }
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
478 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
479 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
480 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
481 }
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
482 printf("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);
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
483 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
484 }
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
485
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
486 void map_iter_fun(char *key, tern_val val, uint8_t valtype, void *data)
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
487 {
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
488 map_iter_state *state = data;
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
489 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
490 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
491 }
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
492 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
493 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
494 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
495 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
496 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
497 }
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
498 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
499 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
500 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
501 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
502 map->end = end + 1;
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
503 if (!strcmp(dtype, "ROM")) {
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
504 map->buffer = state->rom + offset;
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
505 map->flags = MMAP_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
506 map->mask = calc_mask(state->rom_size - offset, start, end);
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
507 } else 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
508 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
509 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
510 lock_info = configure_rom(state->rom_db, state->lock_on, state->lock_on_size, 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
511 } else if (state->rom_size > start) {
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
512 //This is a bit of a hack to deal with pre-combined S3&K/S2&K ROMs and S&K ROM hacks
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
513 lock_info = configure_rom(state->rom_db, state->rom + start, state->rom_size - 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
514 } 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
515 //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
516 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
517 }
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
518 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
519 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
520 {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
521 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
522 matching_chunks++;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
523 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
524 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
525 if (matching_chunks == 0) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
526 //Nothing mapped in the relevant range for the lock-on cart, ignore this mapping
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
527 return;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
528 } 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
529 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
530 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
531 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
532 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
533 }
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
534 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
535 {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
536 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
537 continue;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
538 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
539 *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
540 if (map->start < 0x200000) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
541 if (map->buffer) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
542 map->buffer += (0x200000 - map->start) & ((map->flags & MMAP_AUX_BUFF) ? map->aux_mask : map->mask);
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
543 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
544 map->start = 0x200000;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
545 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
546 map++;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
547 state->index++;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
548 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
549 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
550 //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
551 if (state->lock_on) {
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
552 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
553 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
554 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
555 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
556 state->info->save_mask = lock_info.save_mask;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
557 state->info->save_page_size = lock_info.save_page_size;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
558 state->info->save_product_id = lock_info.save_product_id;
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
559 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
560 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
561 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
562 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
563 }
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
564 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
565 return;
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
566 } else if (!strcmp(dtype, "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
567 process_eeprom_def(key, 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
568 add_eeprom_map(node, start, end, state);
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
569
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
570 map->write_16 = write_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
571 map->write_8 = write_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
572 map->read_16 = read_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
573 map->read_8 = read_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
574 map->mask = 0xFFFFFF;
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
575 } else if (!strcmp(dtype, "SRAM")) {
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
576 process_sram_def(key, 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
577 map->buffer = state->info->save_buffer + offset;
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
578 map->flags = MMAP_READ | MMAP_WRITE;
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
579 if (state->info->save_type == RAM_FLAG_ODD) {
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
580 map->flags |= MMAP_ONLY_ODD;
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
581 } else if(state->info->save_type == RAM_FLAG_EVEN) {
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
582 map->flags |= MMAP_ONLY_EVEN;
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
583 }
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
584 map->mask = calc_mask(state->info->save_size, start, end);
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
585 } else if (!strcmp(dtype, "RAM")) {
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
586 uint32_t size = strtol(tern_find_ptr_default(node, "size", "0"), NULL, 16);
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
587 if (!size || size > map->end - map->start) {
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
588 size = map->end - map->start;
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
589 }
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
590 map->buffer = malloc(size);
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
591 map->mask = calc_mask(size, start, end);
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
592 map->flags = MMAP_READ | MMAP_WRITE;
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
593 char *bus = tern_find_ptr_default(node, "bus", "both");
1394
ae3b1721b226 Small fix to handling of the "bus" option in a RAM type ROM DB memory map
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
594 if (!strcmp(bus, "odd")) {
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
595 map->flags |= MMAP_ONLY_ODD;
1394
ae3b1721b226 Small fix to handling of the "bus" option in a RAM type ROM DB memory map
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
596 } else if (!strcmp(bus, "even")) {
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
597 map->flags |= MMAP_ONLY_EVEN;
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
598 } else {
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
599 map->flags |= MMAP_CODE;
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
600 }
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
601 } else if (!strcmp(dtype, "NOR")) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
602 process_nor_def(key, state);
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
603
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
604 map->write_16 = nor_flash_write_w;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
605 map->write_8 = nor_flash_write_b;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
606 map->read_16 = nor_flash_read_w;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
607 map->read_8 = nor_flash_read_b;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
608 map->mask = 0xFFFFFF;
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
609 } else if (!strcmp(dtype, "Sega mapper")) {
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
610 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
611 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
612 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
613 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
614 process_eeprom_def(key, 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
615 add_eeprom_map(node, start & map->mask, end & 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
616 } 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
617 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
618 } 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
619 //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
620 //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
621 //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
622 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
623 }
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
624 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
625 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
626 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
627 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
628 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
629 map->start = start;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
630 map->end = end;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
631 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
632 map->buffer = state->rom + offset;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
633 map->mask = calc_mask(state->rom_size - offset, start, end);
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
634 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
635 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
636 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
637 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
638 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
639 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
640 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
641 } else {
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
642 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
643 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
644 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
645 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
646 }
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
647 state->index++;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
648 map++;
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
649 } else {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
650 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
651 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
652 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
653 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
654 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
655 {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
656 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
657 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
658 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
659 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
660 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
661 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
662 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
663 } else {
1413
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
664 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
665 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
666 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
667 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
668 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
669 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
670 } else {
3d7f668dce3d Sonic 3 & Knuckles lock-on is now 100% functional with working saves
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
671 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
672 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
673 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
674 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
675 }
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
676 }
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
677 }
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
678 }
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
679 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
680 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
681 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
682 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
683 map->write_8 = (write_8_fun)write_bank_reg_b;
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
684 } 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
685 //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
686 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
687 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
688 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
689 map->read_16 = menu_read_w;
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
690 } else if (!strcmp(dtype, "fixed")) {
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
691 uint16_t *value = malloc(2);
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
692 map->buffer = value;
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
693 map->mask = 0;
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
694 map->flags = MMAP_READ;
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
695 *value = strtol(tern_find_ptr_default(node, "value", "0"), NULL, 16);
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
696 } else if (!strcmp(dtype, "multi-game")) {
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
697 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
698 //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
699 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
700 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
701 state->rom_size *= 2;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
702 //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
703 state->info->map_chunks+=1;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
704 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
705 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
706 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
707 map->buffer = state->rom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
708 map->mask = calc_mask(state->rom_size, start, end);
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
709 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
710 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
711 map++;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
712 state->index++;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
713 map->start = 0xA13000;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
714 map->end = 0xA13100;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
715 map->mask = 0xFF;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
716 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
717 map->write_8 = write_multi_game_b;
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
718 } 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
719 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
720 }
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 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
722 }
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
723
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
724 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
725 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
726 uint8_t product_id[GAME_ID_LEN+1];
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
727 uint8_t *rom = vrom;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
728 product_id[GAME_ID_LEN] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
729 for (int i = 0; i < GAME_ID_LEN; i++)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
730 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
731 if (rom[GAME_ID_OFF + i] <= ' ') {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
732 product_id[i] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
733 break;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
734 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
735 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
736
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
737 }
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
738 printf("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
739 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
740 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
741 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
742 bin_to_hex(hex_hash, 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
743 printf("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
744 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
745 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
746 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
747 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
748 if (!entry) {
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
749 puts("Not found in ROM DB, examining header\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
750 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
751 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
752 }
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
753 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
754 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
755 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
756 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
757 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
758 rom_info 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
759 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
760 if (info.name) {
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
761 printf("Found name: %s\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
762 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
763 } 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
764 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
765 }
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
766
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
767 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
768 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
769 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
770 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
771 {
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
772 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
773 }
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
774 }
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
775 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
776 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
777 }
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
778
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
779 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
780 info.rom = vrom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
781 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
782 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
783 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
784 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
785 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
786 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
787 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
788 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
789 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
790 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
791 info.eeprom_map = NULL;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
792 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
793 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
794 map_iter_state state = {
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
795 .info = &info,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
796 .rom = rom,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
797 .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
798 .root = entry,
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1410
diff changeset
799 .rom_db = rom_db,
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
800 .rom_size = rom_size,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
801 .lock_on_size = lock_on_size,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
802 .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
803 .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
804 .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
805 };
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
806 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
807 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
808 info.rom = state.rom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
809 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
810 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
811 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
812 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
813 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
814 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
815 }
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
816
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
817 tern_node *device_overrides = tern_find_node(entry, "device_overrides");
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
818 if (device_overrides) {
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
819 info.port1_override = tern_find_ptr(device_overrides, "1");
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
820 info.port2_override = tern_find_ptr(device_overrides, "2");
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
821 info.ext_override = tern_find_ptr(device_overrides, "ext");
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
822 } else {
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
823 info.port1_override = info.port2_override = info.ext_override = NULL;
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
824 }
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
825 info.mouse_mode = tern_find_ptr(entry, "mouse_mode");
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
826
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
827 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
828 }