annotate romdb.c @ 1296:4e2007c1d8ab

Change the default screenshot path as per ticket:14
author Michael Pavone <pavone@retrodev.com>
date Tue, 21 Mar 2017 21:59:05 -0700
parents 65f03a0a426a
children 5ceb316c479a
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"
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
6 #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
7 #include "menu.h"
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents: 1221
diff changeset
8 #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
9 #include "realtec.h"
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
11 #define DOM_TITLE_START 0x120
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
12 #define DOM_TITLE_END 0x150
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
13 #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
14 #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
15 #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
16 #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
17 #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
18 #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
19 #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
20 #define REGION_START 0x1F0
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
22 enum {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
23 I2C_IDLE,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
24 I2C_START,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
25 I2C_DEVICE_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
26 I2C_ADDRESS_HI,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
27 I2C_ADDRESS_HI_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
28 I2C_ADDRESS,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
29 I2C_ADDRESS_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
30 I2C_READ,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
31 I2C_READ_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
32 I2C_WRITE,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
33 I2C_WRITE_ACK
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
34 };
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
35
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
36 char * i2c_states[] = {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
37 "idle",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
38 "start",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
39 "device ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
40 "address hi",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
41 "address hi ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
42 "address",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
43 "address ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
44 "read",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
45 "read_ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
46 "write",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
47 "write_ack"
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
48 };
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
49
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
50 void eeprom_init(eeprom_state *state, uint8_t *buffer, uint32_t size)
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
51 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
52 state->slave_sda = 1;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
53 state->host_sda = state->scl = 0;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
54 state->buffer = buffer;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
55 state->size = size;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
56 state->state = I2C_IDLE;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
57 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
58
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
59 void set_host_sda(eeprom_state *state, uint8_t val)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
60 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
61 if (state->scl) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
62 if (val & ~state->host_sda) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
63 //low to high, stop condition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
64 state->state = I2C_IDLE;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
65 state->slave_sda = 1;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
66 } else if (~val & state->host_sda) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
67 //high to low, start condition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
68 state->state = I2C_START;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
69 state->slave_sda = 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
70 state->counter = 8;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
71 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
72 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
73 state->host_sda = val;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
74 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
75
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
76 void set_scl(eeprom_state *state, uint8_t val)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
77 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
78 if (val & ~state->scl) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
79 //low to high transition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
80 switch (state->state)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
81 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
82 case I2C_START:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
83 case I2C_ADDRESS_HI:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
84 case I2C_ADDRESS:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
85 case I2C_WRITE:
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
86 state->latch = state->host_sda | state->latch << 1;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
87 state->counter--;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
88 if (!state->counter) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
89 switch (state->state & 0x7F)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
90 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
91 case I2C_START:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
92 state->state = I2C_DEVICE_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
93 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
94 case I2C_ADDRESS_HI:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
95 state->address = state->latch << 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
96 state->state = I2C_ADDRESS_HI_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
97 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
98 case I2C_ADDRESS:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
99 state->address |= state->latch;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
100 state->state = I2C_ADDRESS_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
101 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
102 case I2C_WRITE:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
103 state->buffer[state->address] = state->latch;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
104 state->state = I2C_WRITE_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
105 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
106 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
107 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
108 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
109 case I2C_DEVICE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
110 if (state->latch & 1) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
111 state->state = I2C_READ;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
112 state->counter = 8;
938
4c17c7f46331 Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
113 if (state->size < 256) {
4c17c7f46331 Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
114 state->address = state->latch >> 1;
4c17c7f46331 Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
115 }
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
116 state->latch = state->buffer[state->address];
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
117 } else {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
118 if (state->size < 256) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
119 state->address = state->latch >> 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
120 state->state = I2C_WRITE;
779
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
121 } else if (state->size < 4096) {
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
122 state->address = (state->latch & 0xE) << 7;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
123 state->state = I2C_ADDRESS;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
124 } else {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
125 state->state = I2C_ADDRESS_HI;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
126 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
127 state->counter = 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
128 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
129 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
130 case I2C_ADDRESS_HI_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
131 state->state = I2C_ADDRESS;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
132 state->counter = 8;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
133 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
134 case I2C_ADDRESS_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
135 state->state = I2C_WRITE;
779
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
136 state->address &= state->size-1;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
137 state->counter = 8;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
138 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
139 case I2C_READ:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
140 state->counter--;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
141 if (!state->counter) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
142 state->state = I2C_READ_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
143 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
144 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
145 case I2C_READ_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
146 state->state = I2C_READ;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
147 state->counter = 8;
779
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
148 state->address++;
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
149 //TODO: page mask
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
150 state->address &= state->size-1;
780
fa2c03fcbb88 EEPROM reads now work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 779
diff changeset
151 state->latch = state->buffer[state->address];
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
152 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
153 case I2C_WRITE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
154 state->state = I2C_WRITE;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
155 state->counter = 8;
779
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
156 state->address++;
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
157 //TODO: page mask
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
158 state->address &= state->size-1;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
159 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
160 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
161 } else if (~val & state->scl) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
162 //high to low transition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
163 switch (state->state & 0x7F)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
164 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
165 case I2C_DEVICE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
166 case I2C_ADDRESS_HI_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
167 case I2C_ADDRESS_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
168 case I2C_READ_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
169 case I2C_WRITE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
170 state->slave_sda = 0;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
171 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
172 case I2C_READ:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
173 state->slave_sda = state->latch >> 7;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
174 state->latch = state->latch << 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
175 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
176 default:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
177 state->slave_sda = 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
178 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
179 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
180 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
181 state->scl = val;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
182 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
183
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
184 uint8_t get_sda(eeprom_state *state)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
185 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
186 return state->host_sda & state->slave_sda;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
187 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
188
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
189 uint16_t read_sram_w(uint32_t address, m68k_context * context)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
190 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
191 genesis_context * gen = context->system;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
192 address &= gen->save_ram_mask;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
193 switch(gen->save_type)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
194 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
195 case RAM_FLAG_BOTH:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
196 return gen->save_storage[address] << 8 | gen->save_storage[address+1];
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
197 case RAM_FLAG_EVEN:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
198 return gen->save_storage[address >> 1] << 8 | 0xFF;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
199 case RAM_FLAG_ODD:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
200 return gen->save_storage[address >> 1] | 0xFF00;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
201 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
202 return 0xFFFF;//We should never get here
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
203 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
204
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
205 uint8_t read_sram_b(uint32_t address, m68k_context * context)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
206 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
207 genesis_context * gen = context->system;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
208 address &= gen->save_ram_mask;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
209 switch(gen->save_type)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
210 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
211 case RAM_FLAG_BOTH:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
212 return gen->save_storage[address];
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
213 case RAM_FLAG_EVEN:
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
214 if (address & 1) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
215 return 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
216 } else {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
217 return gen->save_storage[address >> 1];
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
218 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
219 case RAM_FLAG_ODD:
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
220 if (address & 1) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
221 return gen->save_storage[address >> 1];
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
222 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
223 return 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
224 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
225 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
226 return 0xFF;//We should never get here
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
227 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
228
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
229 m68k_context * write_sram_area_w(uint32_t address, m68k_context * context, uint16_t value)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
230 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
231 genesis_context * gen = context->system;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
232 if ((gen->bank_regs[0] & 0x3) == 1) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
233 address &= gen->save_ram_mask;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
234 switch(gen->save_type)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
235 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
236 case RAM_FLAG_BOTH:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
237 gen->save_storage[address] = value >> 8;
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
238 gen->save_storage[address+1] = value;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
239 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
240 case RAM_FLAG_EVEN:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
241 gen->save_storage[address >> 1] = value >> 8;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
242 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
243 case RAM_FLAG_ODD:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
244 gen->save_storage[address >> 1] = value;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
245 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
246 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
247 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
248 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
249 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
250
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
251 m68k_context * write_sram_area_b(uint32_t address, m68k_context * context, uint8_t value)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
252 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
253 genesis_context * gen = context->system;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
254 if ((gen->bank_regs[0] & 0x3) == 1) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
255 address &= gen->save_ram_mask;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
256 switch(gen->save_type)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
257 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
258 case RAM_FLAG_BOTH:
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
259 gen->save_storage[address] = value;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
260 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
261 case RAM_FLAG_EVEN:
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
262 if (!(address & 1)) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
263 gen->save_storage[address >> 1] = value;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
264 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
265 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
266 case RAM_FLAG_ODD:
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
267 if (address & 1) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
268 gen->save_storage[address >> 1] = value;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
269 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
270 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
271 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
272 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
273 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
274 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
275
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
276 m68k_context * write_bank_reg_w(uint32_t address, m68k_context * context, uint16_t value)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
277 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
278 genesis_context * gen = context->system;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
279 address &= 0xE;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
280 address >>= 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
281 gen->bank_regs[address] = value;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
282 if (!address) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
283 if (value & 1) {
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
284 for (int i = 0; i < 8; i++)
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
285 {
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
286 context->mem_pointers[gen->mapper_start_index + i] = NULL;
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
287 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
288 } else {
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
289 //Used for games that only use the mapper for SRAM
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
290 context->mem_pointers[gen->mapper_start_index] = gen->cart + 0x200000/2;
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
291 //For games that need more than 4MB
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
292 for (int i = 1; i < 8; i++)
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
293 {
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
294 context->mem_pointers[gen->mapper_start_index + i] = gen->cart + 0x40000*gen->bank_regs[i];
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
295 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
296 }
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
297 } else {
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
298 m68k_invalidate_code_range(gen->m68k, address * 0x80000, (address + 1) * 0x80000);
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
299 context->mem_pointers[gen->mapper_start_index + address] = gen->cart + 0x40000*value;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
300 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
301 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
302 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
303
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
304 m68k_context * write_bank_reg_b(uint32_t address, m68k_context * context, uint8_t value)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
305 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
306 if (address & 1) {
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
307 write_bank_reg_w(address, context, value);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
308 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
309 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
310 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
311 eeprom_map *find_eeprom_map(uint32_t address, genesis_context *gen)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
312 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
313 for (int i = 0; i < gen->num_eeprom; i++)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
314 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
315 if (address >= gen->eeprom_map[i].start && address <= gen->eeprom_map[i].end) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
316 return gen->eeprom_map + i;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
317 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
318 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
319 return NULL;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
320 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
321
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
322 void * write_eeprom_i2c_w(uint32_t address, void * context, uint16_t value)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
323 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
324 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
325 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
326 if (!map) {
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
327 fatal_error("Could not find EEPROM map for address %X\n", address);
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
328 }
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
329 if (map->scl_mask) {
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
330 set_scl(&gen->eeprom, (value & map->scl_mask) != 0);
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
331 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
332 if (map->sda_write_mask) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
333 set_host_sda(&gen->eeprom, (value & map->sda_write_mask) != 0);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
334 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
335 return context;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
336 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
337
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
338 void * write_eeprom_i2c_b(uint32_t address, void * context, uint8_t value)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
339 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
340 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
341 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
342 if (!map) {
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
343 fatal_error("Could not find EEPROM map for address %X\n", address);
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
344 }
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
345
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
346 uint16_t expanded, mask;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
347 if (address & 1) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
348 expanded = value;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
349 mask = 0xFF;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
350 } else {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
351 expanded = value << 8;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
352 mask = 0xFF00;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
353 }
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
354 if (map->scl_mask & mask) {
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
355 set_scl(&gen->eeprom, (expanded & map->scl_mask) != 0);
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
356 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
357 if (map->sda_write_mask & mask) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
358 set_host_sda(&gen->eeprom, (expanded & map->sda_write_mask) != 0);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
359 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
360 return context;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
361 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
362
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
363 uint16_t read_eeprom_i2c_w(uint32_t address, void * context)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
364 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
365 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
366 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
367 if (!map) {
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
368 fatal_error("Could not find EEPROM map for address %X\n", address);
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
369 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
370 uint16_t ret = 0;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
371 if (map->sda_read_bit < 16) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
372 ret = get_sda(&gen->eeprom) << map->sda_read_bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
373 }
938
4c17c7f46331 Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
374 return ret;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
375 }
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 uint8_t read_eeprom_i2c_b(uint32_t address, void * context)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
378 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
379 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
380 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
381 if (!map) {
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
382 fatal_error("Could not find EEPROM map for address %X\n", address);
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
383 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
384 uint8_t bit = address & 1 ? map->sda_read_bit : map->sda_read_bit - 8;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
385 uint8_t ret = 0;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
386 if (bit < 8) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
387 ret = get_sda(&gen->eeprom) << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
388 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
389 return ret;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
390 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
391
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
392 tern_node *load_rom_db()
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
393 {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
394 tern_node *db = parse_bundled_config("rom.db");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 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
396 fatal_error("Failed to load ROM DB\n");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
397 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
398 return db;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
399 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
400
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
401 char *get_header_name(uint8_t *rom)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
402 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
403 //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
404 uint8_t *last = rom + TITLE_END - 1;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
405 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
406
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
407 for (;;)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
408 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
409 while (last > src && (*last <= 0x20 || *last >= 0x80))
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
410 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
411 last--;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
412 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
413 if (last == src) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
414 if (src == rom + TITLE_START) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
415 src = rom + DOM_TITLE_START;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
416 last = rom + DOM_TITLE_END - 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
417 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
418 return strdup("UNKNOWN");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
419 }
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
420 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
421 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
422 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
423 uint8_t *dst;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
424 uint8_t last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
425 for (dst = ret; src < last; src++)
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
426 {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
427 if (*src >= 0x20 && *src < 0x80) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
428 if (*src == ' ') {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
429 if (last_was_space) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
430 continue;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
431 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
432 last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
433 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
434 last_was_space = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
435 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
436 *(dst++) = *src;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
437 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
438 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
439 *dst = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
440 return ret;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
441 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
442 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
443 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
444
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
445 char *region_chars = "JUEW";
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
446 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
447
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
448 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
449 {
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
450 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
451 {
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
452 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
453 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
454 }
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
455 }
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
456 uint8_t bin_region = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
457 if (c >= '0' && c <= '9') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
458 bin_region = c - '0';
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
459 } else if (c >= 'A' && c <= 'F') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
460 bin_region = c - 'A' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
461 } else if (c >= 'a' && c <= 'f') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
462 bin_region = c - 'a' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
463 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
464 uint8_t ret = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
465 if (bin_region & 8) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
466 ret |= REGION_E;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
467 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
468 if (bin_region & 4) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
469 ret |= REGION_U;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
470 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
471 if (bin_region & 1) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
472 ret |= REGION_J;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
473 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
474 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
475 }
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
476
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
477 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
478 {
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
479 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
480 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
481 {
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
482 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
483 }
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
484 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
485 }
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
486
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
487 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
488 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
489 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
490 }
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
491
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
492 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
493 {
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 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
495 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
496 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
497 } 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
498 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
499 } 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
500 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
501 }
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
502 }
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
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
504 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
505 {
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
506 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
507 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
508 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
509 } 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
510 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
511 }
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
512 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
513 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
514 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
515 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
516 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
517 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
518
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
519 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
520 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
521 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
522 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
523 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
524
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
525 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
526 {
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
527 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
528 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
529 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
530 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
531 info->map[i].ptr_index = 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
532 info->map[i].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE;
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
533
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
534 }
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
535 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
536 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
537 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
538 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
539 info->map[8].write_8 = (write_8_fun)write_bank_reg_b;
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
540 } else if (rom[RAM_ID] == 'R' && rom[RAM_ID+1] == 'A') {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
541 uint32_t ram_start = get_u32be(rom + RAM_START);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
542 uint32_t ram_end = get_u32be(rom + RAM_END);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
543 uint32_t ram_flags = info->save_type = rom[RAM_FLAGS] & RAM_FLAG_MASK;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
544 ram_start &= 0xFFFFFE;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
545 ram_end |= 1;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
546 info->save_mask = ram_end - ram_start;
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
547 uint32_t save_size = info->save_mask + 1;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
548 if (ram_flags != RAM_FLAG_BOTH) {
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
549 save_size /= 2;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
550 }
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
551 info->save_size = save_size;
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
552 info->save_buffer = malloc(save_size);
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
553
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
554 info->map_chunks = base_chunks + (ram_start >= rom_end ? 2 : 3);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
555 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
556 memset(info->map, 0, sizeof(memmap_chunk)*2);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
557 memcpy(info->map+2, 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
558
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
559 if (ram_start >= rom_end) {
825
e6f2c9dbf6c8 Prevent crashes if game tries to access the ROM area outside of the size of the actual ROM
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
560 info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
1281
34113230fd88 Fix heuristic detection of SRAM for 3MB ROMs with SRAM at the 3MB mark
Michael Pavone <pavone@retrodev.com>
parents: 1259
diff changeset
561 if (info->map[0].end > ram_start) {
34113230fd88 Fix heuristic detection of SRAM for 3MB ROMs with SRAM at the 3MB mark
Michael Pavone <pavone@retrodev.com>
parents: 1259
diff changeset
562 info->map[0].end = ram_start;
34113230fd88 Fix heuristic detection of SRAM for 3MB ROMs with SRAM at the 3MB mark
Michael Pavone <pavone@retrodev.com>
parents: 1259
diff changeset
563 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
564 //TODO: ROM mirroring
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
565 info->map[0].mask = 0xFFFFFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
566 info->map[0].flags = MMAP_READ;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
567 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
568
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
569 info->map[1].start = ram_start;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
570 info->map[1].mask = info->save_mask;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
571 info->map[1].end = ram_end + 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
572 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
573
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
574 if (ram_flags == RAM_FLAG_ODD) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
575 info->map[1].flags |= MMAP_ONLY_ODD;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
576 } else if (ram_flags == RAM_FLAG_EVEN) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
577 info->map[1].flags |= MMAP_ONLY_EVEN;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
578 }
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
579 info->map[1].buffer = info->save_buffer;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
580 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
581 //Assume the standard Sega mapper
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
582 info->map[0].end = 0x200000;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
583 info->map[0].mask = 0xFFFFFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
584 info->map[0].flags = MMAP_READ;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
585 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
586
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
587 info->map[1].start = 0x200000;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
588 info->map[1].end = 0x400000;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
589 info->map[1].mask = 0x1FFFFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
590 info->map[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL;
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
591 info->map[1].ptr_index = info->mapper_start_index = 0;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
592 info->map[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
593 info->map[1].read_8 = (read_8_fun)read_sram_b;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
594 info->map[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
595 info->map[1].write_8 = (write_8_fun)write_sram_area_b;
1221
53fc7efdfdab Fix handling of SRAM overlapping with ROM
Michael Pavone <pavone@retrodev.com>
parents: 1195
diff changeset
596 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
597
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
598 memmap_chunk *last = info->map + info->map_chunks - 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
599 memset(last, 0, sizeof(memmap_chunk));
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
600 last->start = 0xA13000;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
601 last->end = 0xA13100;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
602 last->mask = 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
603 last->write_16 = (write_16_fun)write_bank_reg_w;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
604 last->write_8 = (write_8_fun)write_bank_reg_b;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
605 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
606 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
607 info->map_chunks = base_chunks + 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
608 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
609 memset(info->map, 0, sizeof(memmap_chunk));
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
610 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
611
825
e6f2c9dbf6c8 Prevent crashes if game tries to access the ROM area outside of the size of the actual ROM
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
612 info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000;
e6f2c9dbf6c8 Prevent crashes if game tries to access the ROM area outside of the size of the actual ROM
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
613 info->map[0].mask = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
614 info->map[0].flags = MMAP_READ;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
615 info->map[0].buffer = rom;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
616 info->save_type = SAVE_NONE;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
617 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
618 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
619
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
620 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
621 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
622 rom_info info;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
623 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
624 info.regions = get_header_regions(rom);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
625 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
626 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
627 return info;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
628 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
629
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
630 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
631 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
632 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
633 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
634 tern_node *root;
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
635 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
636 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
637 int index;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
638 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
639 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
640 } 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
641
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
642 void eeprom_read_fun(char *key, tern_val val, void *data)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
643 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
644 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
645 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
646 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
647 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
648 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
649 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
650 if (strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
651 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
652 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
653 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
654 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
655 map->sda_read_bit = bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
656 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
657
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
658 void eeprom_write_fun(char *key, tern_val val, void *data)
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
659 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
660 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
661 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
662 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
663 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
664 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
665 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
666 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
667 if (!strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
668 map->sda_write_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
669 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
670 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
671 if (!strcmp(pin, "scl")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
672 map->scl_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
673 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
674 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
675 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
676 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
677
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
678 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
679 {
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 if (!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
681 char * size = tern_find_path(state->root, "SRAM\0size\0").ptrval;
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 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
683 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
684 }
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
685 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
686 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
687 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
688 }
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
689 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
690 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
691 memset(state->info->save_buffer, 0, 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
692 char *bus = tern_find_path(state->root, "SRAM\0bus\0").ptrval;
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
693 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
694 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
695 } 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
696 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
697 } 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
698 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
699 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
700 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
701 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
702
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
703 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
704 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
705 if (!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
706 char * size = tern_find_path(state->root, "EEPROM\0size\0").ptrval;
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
707 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
708 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
709 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
710 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
711 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
712 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
713 }
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
714 char *etype = tern_find_path(state->root, "EEPROM\0type\0").ptrval;
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
715 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
716 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
717 }
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
718 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
719 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
720 } 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
721 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
722 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
723 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
724 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
725 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
726 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
727 }
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
728 }
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
729
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
730 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
731 {
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
732 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
733 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
734 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
735 eep_map->sda_read_bit = 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
736 tern_node * bits_read = tern_find_ptr(node, "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
737 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
738 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
739 }
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
740 tern_node * bits_write = tern_find_ptr(node, "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
741 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
742 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
743 }
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
744 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
745 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
746 }
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
747
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
748 void map_iter_fun(char *key, tern_val val, void *data)
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 {
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
750 map_iter_state *state = data;
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
751 tern_node *node = tern_get_node(val);
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
752 if (!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
753 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
754 }
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
755 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
756 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
757 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
758 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
759 }
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
760 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
761 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
762 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
763 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
764 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
765 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
766 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
767 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
768 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
769 } else if (!strcmp(dtype, "LOCK-ON")) {
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
770 if (!state->lock_on) {
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
771 //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
772 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
773 }
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
774 map->buffer = state->lock_on + offset;
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
775 map->flags = MMAP_READ;
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
776 map->mask = calc_mask(state->lock_on_size - offset, start, end);
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
777 } 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
778 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
779 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
780
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
781 map->write_16 = write_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
782 map->write_8 = write_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
783 map->read_16 = read_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
784 map->read_8 = read_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
785 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
786 } 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
787 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
788 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
789 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
790 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
791 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
792 } 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
793 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
794 }
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
795 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
796 } 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
797 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
798 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
799 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
800 }
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
801 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
802 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
803 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
804 char *bus = tern_find_ptr_default(node, "bus", "both");
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
805 if (!strcmp(dtype, "odd")) {
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
806 map->flags |= MMAP_ONLY_ODD;
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
807 } else if (!strcmp(dtype, "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
808 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
809 } 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
810 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
811 }
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
812 } 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
813 state->info->mapper_start_index = state->ptr_index++;
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
814 state->info->map_chunks+=7;
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
815 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
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
816 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7);
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
817 map = state->info->map + state->index;
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
818 char *save_device = tern_find_path(node, "save\0device\0").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
819 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
820 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
821 add_eeprom_map(node, start & map->mask, end & map->mask, 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
822 }
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
823 for (int i = 0; i < 7; i++, state->index++, map++)
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
824 {
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
825 map->start = start + i * 0x80000;
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
826 map->end = start + (i + 1) * 0x80000;
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
827 map->mask = 0x7FFFF;
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
828 map->buffer = state->rom + offset + i * 0x80000;
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
829 map->ptr_index = state->ptr_index++;
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
830 if (i < 3 || !save_device) {
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
831 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE;
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
832 } else {
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
833 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
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
834 if (!strcmp(save_device, "SRAM")) {
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
835 process_sram_def(key, state);
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
836 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
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
837 map->read_8 = (read_8_fun)read_sram_b;
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
838 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
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
839 map->write_8 = (write_8_fun)write_sram_area_b;
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
840 } else if (!strcmp(save_device, "EEPROM")) {
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
841 map->write_16 = write_eeprom_i2c_w;
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
842 map->write_8 = write_eeprom_i2c_b;
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
843 map->read_16 = read_eeprom_i2c_w;
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
844 map->read_8 = read_eeprom_i2c_b;
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
845 }
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
846 }
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
847 }
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
848 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
849 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
850 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
851 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
852 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
853 } 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
854 //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
855 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
856 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
857 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
858 map->read_16 = menu_read_w;
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
859 } 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
860 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
861 }
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
862 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
863 }
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
864
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
865 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
866 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
867 uint8_t product_id[GAME_ID_LEN+1];
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
868 uint8_t *rom = vrom;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
869 product_id[GAME_ID_LEN] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
870 for (int i = 0; i < GAME_ID_LEN; i++)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
871 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
872 if (rom[GAME_ID_OFF + i] <= ' ') {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
873 product_id[i] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
874 break;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
875 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
876 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
877
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
878 }
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
879 printf("Product ID: %s\n", product_id);
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
880 tern_node * entry = tern_find_ptr(rom_db, product_id);
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
881 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
882 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
883 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
884 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
885 }
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
886 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
887 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
888 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
889 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
890 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
891 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
892 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
893 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
894 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
895 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
896 } 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
897 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
898 }
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
899
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
900 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
901 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
902 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
903 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
904 {
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
905 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
906 }
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
907 }
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
908 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
909 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
910 }
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
911
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
912 tern_node *map = tern_find_ptr(entry, "map");
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
913 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
914 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
915 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
916 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
917 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
918 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
919 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
920 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
921 info.eeprom_map = NULL;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
922 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
923 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
924 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
925 .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
926 .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
927 .lock_on = lock_on,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
928 .root = entry,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
929 .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
930 .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
931 .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
932 .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
933 .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
934 };
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
935 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
936 memcpy(info.map + state.index, base_map, sizeof(memmap_chunk) * base_chunks);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
937 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
938 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
939 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
940 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
941 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
942 }
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
943
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
944 tern_node *device_overrides = tern_find_ptr(entry, "device_overrides");
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
945 if (device_overrides) {
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
946 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
947 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
948 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
949 } else {
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
950 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
951 }
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
952 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
953
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
954 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
955 }