annotate romdb.c @ 898:2f1157f00dc6

Z80 core is now slightly less broken
author Michael Pavone <pavone@retrodev.com>
date Thu, 26 Nov 2015 00:10:36 -0800
parents 54ffba3768d6
children a5a51465f8b0
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"
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
6 #include "blastem.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"
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8
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
9 #define TITLE_START 0x150
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
10 #define TITLE_END (TITLE_START+48)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 #define GAME_ID_OFF 0x183
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 #define GAME_ID_LEN 8
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
13 #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
14 #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
15 #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
16 #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
17 #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
18 #define REGION_START 0x1F0
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
20 enum {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
21 I2C_IDLE,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
22 I2C_START,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
23 I2C_DEVICE_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
24 I2C_ADDRESS_HI,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
25 I2C_ADDRESS_HI_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
26 I2C_ADDRESS,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
27 I2C_ADDRESS_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
28 I2C_READ,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
29 I2C_READ_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
30 I2C_WRITE,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
31 I2C_WRITE_ACK
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
32 };
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
33
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
34 char * i2c_states[] = {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
35 "idle",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
36 "start",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
37 "device ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
38 "address hi",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
39 "address hi ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
40 "address",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
41 "address ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
42 "read",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
43 "read_ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
44 "write",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
45 "write_ack"
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
46 };
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
47
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
48 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
49 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
50 state->slave_sda = 1;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
51 state->host_sda = state->scl = 0;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
52 state->buffer = buffer;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
53 state->size = size;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
54 state->state = I2C_IDLE;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
55 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
56
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
57 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
58 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
59 if (state->scl) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
60 if (val & ~state->host_sda) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
61 //low to high, stop condition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
62 state->state = I2C_IDLE;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
63 state->slave_sda = 1;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
64 } else if (~val & state->host_sda) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
65 //high to low, start condition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
66 state->state = I2C_START;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
67 state->slave_sda = 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
68 state->counter = 8;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
69 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
70 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
71 state->host_sda = val;
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
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
74 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
75 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
76 if (val & ~state->scl) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
77 //low to high transition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
78 switch (state->state)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
79 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
80 case I2C_START:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
81 case I2C_ADDRESS_HI:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
82 case I2C_ADDRESS:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
83 case I2C_WRITE:
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
84 state->latch = state->host_sda | state->latch << 1;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
85 state->counter--;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
86 if (!state->counter) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
87 switch (state->state & 0x7F)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
88 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
89 case I2C_START:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
90 state->state = I2C_DEVICE_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
91 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
92 case I2C_ADDRESS_HI:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
93 state->address = state->latch << 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
94 state->state = I2C_ADDRESS_HI_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
95 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
96 case I2C_ADDRESS:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
97 state->address |= state->latch;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
98 state->state = I2C_ADDRESS_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
99 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
100 case I2C_WRITE:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
101 state->buffer[state->address] = state->latch;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
102 state->state = I2C_WRITE_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
103 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
104 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
105 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
106 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
107 case I2C_DEVICE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
108 if (state->latch & 1) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
109 state->state = I2C_READ;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
110 state->counter = 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
111 state->latch = state->buffer[state->address];
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
112 } else {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
113 if (state->size < 256) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
114 state->address = state->latch >> 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
115 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
116 } 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
117 state->address = (state->latch & 0xE) << 7;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
118 state->state = I2C_ADDRESS;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
119 } else {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
120 state->state = I2C_ADDRESS_HI;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
121 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
122 state->counter = 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
123 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
124 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
125 case I2C_ADDRESS_HI_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
126 state->state = I2C_ADDRESS;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
127 state->counter = 8;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
128 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
129 case I2C_ADDRESS_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
130 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
131 state->address &= state->size-1;
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_READ:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
135 state->counter--;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
136 if (!state->counter) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
137 state->state = I2C_READ_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
138 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
139 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
140 case I2C_READ_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
141 state->state = I2C_READ;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
142 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
143 state->address++;
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
144 //TODO: page mask
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
145 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
146 state->latch = state->buffer[state->address];
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
147 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
148 case I2C_WRITE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
149 state->state = I2C_WRITE;
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
150 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
151 state->address++;
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
152 //TODO: page mask
ba38e36559b0 EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents: 777
diff changeset
153 state->address &= state->size-1;
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
154 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
155 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
156 } else if (~val & state->scl) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
157 //high to low transition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
158 switch (state->state & 0x7F)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
159 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
160 case I2C_DEVICE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
161 case I2C_ADDRESS_HI_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
162 case I2C_ADDRESS_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
163 case I2C_READ_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
164 case I2C_WRITE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
165 state->slave_sda = 0;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
166 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
167 case I2C_READ:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
168 state->slave_sda = state->latch >> 7;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
169 state->latch = state->latch << 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
170 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
171 default:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
172 state->slave_sda = 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
173 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
174 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
175 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
176 state->scl = val;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
177 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
178
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
179 uint8_t get_sda(eeprom_state *state)
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 return state->host_sda & state->slave_sda;
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
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
184 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
185 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
186 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
187 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
188 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
189 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
190 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
191 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
192 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
193 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
194 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
195 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
196 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
197 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
198 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
199
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
200 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
201 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
202 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
203 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
204 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
205 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
206 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
207 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
208 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
209 if (address & 1) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
210 return 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
211 } else {
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 >> 1];
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
213 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
214 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
215 if (address & 1) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
216 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
217 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
218 return 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
219 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
220 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
221 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
222 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
223
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
224 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
225 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
226 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
227 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
228 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
229 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
230 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
231 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
232 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
233 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
234 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
235 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
236 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
237 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
238 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
239 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
240 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
241 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
242 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
243 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
244 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
245
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
246 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
247 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
248 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
249 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
250 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
251 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
252 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
253 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
254 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
255 break;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
256 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
257 if (!(address & 1)) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
258 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
259 }
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_ODD:
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 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
267 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
268 return context;
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
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
271 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
272 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
273 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
274 address &= 0xE;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
275 address >>= 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
276 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
277 if (!address) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
278 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
279 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
280 {
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
281 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
282 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
283 } 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
284 //Used for games that only use the mapper for 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
285 context->mem_pointers[gen->mapper_start_index] = cart + 0x200000/2;
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 //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
287 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
288 {
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 context->mem_pointers[gen->mapper_start_index + i] = cart + 0x40000*gen->bank_regs[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
290 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
291 }
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
292 } else {
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 context->mem_pointers[gen->mapper_start_index + address] = 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
294 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
295 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
296 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
297
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
298 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
299 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
300 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
301 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
302 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
303 return context;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
304 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
305 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
306 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
307 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
308 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
309 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
310 return gen->eeprom_map + i;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
311 }
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 return NULL;
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
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
316 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
317 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
318 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
319 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
320 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
321 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
322 }
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
323 if (map->scl_mask) {
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
324 set_scl(&gen->eeprom, (value & map->scl_mask) != 0);
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
325 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
326 if (map->sda_write_mask) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
327 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
328 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
329 return context;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
330 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
331
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
332 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
333 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
334 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
335 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
336 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
337 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
338 }
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
339
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
340 uint16_t expanded, mask;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
341 if (address & 1) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
342 expanded = value;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
343 mask = 0xFF;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
344 } else {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
345 expanded = value << 8;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
346 mask = 0xFF00;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
347 }
772
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
348 if (map->scl_mask & mask) {
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
349 set_scl(&gen->eeprom, (expanded & map->scl_mask) != 0);
1b82b282b829 Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 770
diff changeset
350 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
351 if (map->sda_write_mask & mask) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
352 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
353 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
354 return context;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
355 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
356
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
357 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
358 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
359 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
360 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
361 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
362 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
363 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
364 uint16_t ret = 0;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
365 if (map->sda_read_bit < 16) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
366 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
367 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
368 return ret;
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
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
371 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
372 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
373 genesis_context *gen = ((m68k_context *)context)->system;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
374 eeprom_map *map = find_eeprom_map(address, gen);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
375 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
376 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
377 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
378 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
379 uint8_t ret = 0;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
380 if (bit < 8) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
381 ret = get_sda(&gen->eeprom) << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
382 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
383 return ret;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
384 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
385
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
386 tern_node *load_rom_db()
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
387 {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
388 tern_node *db = parse_bundled_config("rom.db");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
389 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
390 fatal_error("Failed to load ROM DB\n");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
392 return db;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
393 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
394
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 char *get_header_name(uint8_t *rom)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
396 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
397 uint8_t *last = rom + TITLE_END - 1;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
398 uint8_t *src = rom + TITLE_START;
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
399
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
400 while (last > src && (*last <= 0x20 || *last >= 0x80))
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
401 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
402 last--;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
403 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
404 if (last == src) {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
405 //TODO: Use other name field
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
406 return strdup("UNKNOWN");
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
407 } else {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
408 last++;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
409 char *ret = malloc(last - (rom + TITLE_START) + 1);
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
410 uint8_t *dst;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
411 for (dst = ret; src < last; src++)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
412 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
413 if (*src >= 0x20 && *src < 0x80) {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
414 *(dst++) = *src;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
415 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
416 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
417 *dst = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
418 return ret;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
419 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
420 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
421
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
422 char *region_chars = "UB4JEA";
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
423 uint8_t region_bits[] = {REGION_U, REGION_U, REGION_U, REGION_J, REGION_E, REGION_E};
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
424
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
425 uint8_t translate_region_char(uint8_t c)
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
426 {
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
427 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
428 {
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
429 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
430 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
431 }
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
432 }
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
433 return 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
434 }
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
435
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
436 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
437 {
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
438 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
439 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
440 {
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
441 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
442 }
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
443 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
444 }
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
445
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
446 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
447 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
448 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
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
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
451 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
452 {
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
453 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
454 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
455 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
456 } 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
457 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
458 } 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
459 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
460 }
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
461 }
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
462
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
463 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
464 {
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
465 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
466 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
467 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
468 } 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
469 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
470 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
471 if (rom[RAM_ID] == 'R' && rom[RAM_ID+1] == 'A') {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
472 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
473 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
474 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
475 ram_start &= 0xFFFFFE;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
476 ram_end |= 1;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
477 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
478 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
479 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
480 save_size /= 2;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
481 }
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
482 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
483 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
484
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
485 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
486 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
487 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
488 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
489
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
490 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
491 info->map[0].end = 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
492 //TODO: ROM mirroring
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
493 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
494 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
495 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
496
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
497 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
498 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
499 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
500 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
501
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
502 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
503 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
504 } 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
505 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
506 }
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
507 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
508 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
509 //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
510 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
511 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
512 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
513 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
514
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
515 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
516 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
517 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
518 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
519 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
520 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
521 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
522 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
523 info->map[1].write_8 = (write_8_fun)write_sram_area_b;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
524 info->map[1].buffer = cart + 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
525
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
526 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
527 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
528 last->start = 0xA13000;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
529 last->end = 0xA13100;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
530 last->mask = 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
531 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
532 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
533 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
534 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
535 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
536 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
537 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
538 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
539
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
540 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
541 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
542 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
543 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
544 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
545 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
546 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
547
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
548 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
549 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
550 rom_info info;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
551 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
552 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
553 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
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
554 return info;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
555 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
556
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
557 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
558 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
559 uint8_t *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
560 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
561 uint32_t rom_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
562 int index;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
563 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
564 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
565 } 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
566
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
567 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
568 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
569 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
570 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
571 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
572 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
573 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
574 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
575 if (strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
576 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
577 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
578 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
579 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
580 map->sda_read_bit = bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
581 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
582
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
583 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
584 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
585 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
586 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
587 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
588 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
589 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
590 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
591 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
592 if (!strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
593 map->sda_write_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
594 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
595 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
596 if (!strcmp(pin, "scl")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
597 map->scl_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
598 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
599 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
600 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
601 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
602
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
603 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
604 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
605 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
606 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
607 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
608 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
609 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
610 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
611 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
612 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
613 }
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
614 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
615 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
616 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
617 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
618 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
619 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
620 } 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
621 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
622 } 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
623 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
624 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
625 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
626 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
627
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
628 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
629 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
630 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
631 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
632 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
633 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
634 }
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
635 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
636 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
637 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
638 }
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
639 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
640 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
641 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
642 }
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
643 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
644 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
645 } 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
646 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
647 }
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
648 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
649 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
650 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
651 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
652 }
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
653 }
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
654
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
655 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
656 {
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
657 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
658 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
659 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
660 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
661 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
662 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
663 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
664 }
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
665 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
666 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
667 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
668 }
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
669 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
670 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
671 }
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
672
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
673 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
674 {
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
675 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
676 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
677 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
678 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
679 }
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
680 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
681 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
682 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
683 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
684 }
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
685 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
686 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
687 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
688 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
689 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
690 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
691 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
692 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
693 map->mask = calc_mask(state->rom_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
694 } 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
695 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
696 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
697
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
698 map->write_16 = write_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
699 map->write_8 = write_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
700 map->read_16 = read_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
701 map->read_8 = read_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
702 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
703 } 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
704 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
705 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
706 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
707 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
708 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
709 } 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
710 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
711 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
712 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
713 } 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
714 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
715 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
716 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
717 }
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
718 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
719 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
720 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
721 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
722 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
723 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
724 } 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
725 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
726 } 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
727 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
728 }
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
729 } 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
730 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
731 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
732 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
733 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
734 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
735 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
736 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
737 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
738 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
739 }
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
740 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
741 {
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
742 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
743 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
744 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
745 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
746 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
747 if (i < 3 || !save_device) {
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
748 map->flags = MMAP_READ | MMAP_PTR_IDX;
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
749 } else {
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
750 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_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
751 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
752 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
753 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
754 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
755 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
756 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
757 } 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
758 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
759 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
760 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
761 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
762 }
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
763 }
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
764 }
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
765 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
766 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
767 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
768 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
769 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
770 } 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
771 //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
772 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
773 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
774 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
775 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
776 } 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
777 fatal_error("Invalid device type 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
778 }
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
779 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
780 }
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
781
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
782 rom_info configure_rom(tern_node *rom_db, void *vrom, 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
783 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
784 uint8_t product_id[GAME_ID_LEN+1];
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
785 uint8_t *rom = vrom;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
786 product_id[GAME_ID_LEN] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
787 for (int i = 0; i < GAME_ID_LEN; i++)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
788 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
789 if (rom[GAME_ID_OFF + i] <= ' ') {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
790 product_id[i] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
791 break;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
792 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
793 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
794
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
795 }
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
796 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
797 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
798 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
799 puts("Not found in ROM DB, examining header\n");
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
800 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
801 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
802 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
803 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
804 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
805 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
806 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
807 } 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
808 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
809 }
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
810
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
811 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
812 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
813 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
814 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
815 {
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
816 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
817 }
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
818 }
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
819 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
820 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
821 }
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
822
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
823 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
824 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
825 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
826 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
827 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
828 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
829 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
830 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
831 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
832 info.eeprom_map = NULL;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
833 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
834 memset(info.map, 0, sizeof(memmap_chunk) * info.map_chunks);
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
835 map_iter_state state = {&info, rom, entry, rom_size, 0, info.map_chunks - base_chunks, 0};
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
836 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
837 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
838 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
839 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
840 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
841 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
842 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
843 }
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
844
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
845 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
846 }