Mercurial > repos > blastem
annotate romdb.c @ 1411:780fbe0b97be
WIP support for handling S3 save RAM when locked on
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 22 Jun 2017 09:49:41 -0700 |
parents | 4cd4aa6be5f6 |
children | 3d7f668dce3d |
rev | line source |
---|---|
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdlib.h> |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <string.h> |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "config.h" |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "romdb.h" |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "util.h" |
1305
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
6 #include "hash.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1091
diff
changeset
|
7 #include "genesis.h" |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
8 #include "menu.h" |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1221
diff
changeset
|
9 #include "xband.h" |
1259
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
10 #include "realtec.h" |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
12 #define DOM_TITLE_START 0x120 |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
13 #define DOM_TITLE_END 0x150 |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
14 #define TITLE_START DOM_TITLE_END |
765
dc54387ee1cd
Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents:
764
diff
changeset
|
15 #define TITLE_END (TITLE_START+48) |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
16 #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
|
17 #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
|
18 #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
|
19 #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
|
20 #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
|
21 #define REGION_START 0x1F0 |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
23 char const *save_type_name(uint8_t save_type) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
24 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
25 if (save_type == SAVE_I2C) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
26 return "EEPROM"; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
27 } else if(save_type == SAVE_NOR) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
28 return "NOR Flash"; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
29 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
30 return "SRAM"; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
31 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
32 |
770 | 33 enum { |
34 I2C_IDLE, | |
35 I2C_START, | |
36 I2C_DEVICE_ACK, | |
37 I2C_ADDRESS_HI, | |
38 I2C_ADDRESS_HI_ACK, | |
39 I2C_ADDRESS, | |
40 I2C_ADDRESS_ACK, | |
41 I2C_READ, | |
42 I2C_READ_ACK, | |
43 I2C_WRITE, | |
44 I2C_WRITE_ACK | |
45 }; | |
46 | |
47 char * i2c_states[] = { | |
48 "idle", | |
49 "start", | |
50 "device ack", | |
51 "address hi", | |
52 "address hi ack", | |
53 "address", | |
54 "address ack", | |
55 "read", | |
56 "read_ack", | |
57 "write", | |
58 "write_ack" | |
59 }; | |
60 | |
61 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
|
62 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
63 state->slave_sda = 1; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
64 state->host_sda = state->scl = 0; |
770 | 65 state->buffer = buffer; |
66 state->size = size; | |
67 state->state = I2C_IDLE; | |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
68 } |
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 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
|
71 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
72 if (state->scl) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
73 if (val & ~state->host_sda) { |
770 | 74 //low to high, stop condition |
75 state->state = I2C_IDLE; | |
76 state->slave_sda = 1; | |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
77 } else if (~val & state->host_sda) { |
770 | 78 //high to low, start condition |
79 state->state = I2C_START; | |
80 state->slave_sda = 1; | |
81 state->counter = 8; | |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
82 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
83 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
84 state->host_sda = val; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
85 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
86 |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
87 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
|
88 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
89 if (val & ~state->scl) { |
770 | 90 //low to high transition |
91 switch (state->state) | |
92 { | |
93 case I2C_START: | |
94 case I2C_ADDRESS_HI: | |
95 case I2C_ADDRESS: | |
96 case I2C_WRITE: | |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
97 state->latch = state->host_sda | state->latch << 1; |
770 | 98 state->counter--; |
99 if (!state->counter) { | |
100 switch (state->state & 0x7F) | |
101 { | |
102 case I2C_START: | |
103 state->state = I2C_DEVICE_ACK; | |
104 break; | |
105 case I2C_ADDRESS_HI: | |
106 state->address = state->latch << 8; | |
107 state->state = I2C_ADDRESS_HI_ACK; | |
108 break; | |
109 case I2C_ADDRESS: | |
110 state->address |= state->latch; | |
111 state->state = I2C_ADDRESS_ACK; | |
112 break; | |
113 case I2C_WRITE: | |
114 state->buffer[state->address] = state->latch; | |
115 state->state = I2C_WRITE_ACK; | |
116 break; | |
117 } | |
118 } | |
119 break; | |
120 case I2C_DEVICE_ACK: | |
121 if (state->latch & 1) { | |
122 state->state = I2C_READ; | |
123 state->counter = 8; | |
938
4c17c7f46331
Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
124 if (state->size < 256) { |
4c17c7f46331
Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
125 state->address = state->latch >> 1; |
4c17c7f46331
Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
126 } |
770 | 127 state->latch = state->buffer[state->address]; |
128 } else { | |
129 if (state->size < 256) { | |
130 state->address = state->latch >> 1; | |
131 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
|
132 } 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
|
133 state->address = (state->latch & 0xE) << 7; |
770 | 134 state->state = I2C_ADDRESS; |
135 } else { | |
136 state->state = I2C_ADDRESS_HI; | |
137 } | |
138 state->counter = 8; | |
139 } | |
140 break; | |
141 case I2C_ADDRESS_HI_ACK: | |
142 state->state = I2C_ADDRESS; | |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
143 state->counter = 8; |
770 | 144 break; |
145 case I2C_ADDRESS_ACK: | |
146 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
|
147 state->address &= state->size-1; |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
148 state->counter = 8; |
770 | 149 break; |
150 case I2C_READ: | |
151 state->counter--; | |
152 if (!state->counter) { | |
153 state->state = I2C_READ_ACK; | |
154 } | |
155 break; | |
156 case I2C_READ_ACK: | |
157 state->state = I2C_READ; | |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
158 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
|
159 state->address++; |
ba38e36559b0
EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents:
777
diff
changeset
|
160 //TODO: page mask |
ba38e36559b0
EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents:
777
diff
changeset
|
161 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
|
162 state->latch = state->buffer[state->address]; |
770 | 163 break; |
164 case I2C_WRITE_ACK: | |
165 state->state = I2C_WRITE; | |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
166 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
|
167 state->address++; |
ba38e36559b0
EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents:
777
diff
changeset
|
168 //TODO: page mask |
ba38e36559b0
EEPROM writes now seem to work for NFL Quarterback Club 96
Michael Pavone <pavone@retrodev.com>
parents:
777
diff
changeset
|
169 state->address &= state->size-1; |
770 | 170 break; |
171 } | |
172 } else if (~val & state->scl) { | |
173 //high to low transition | |
174 switch (state->state & 0x7F) | |
175 { | |
176 case I2C_DEVICE_ACK: | |
177 case I2C_ADDRESS_HI_ACK: | |
178 case I2C_ADDRESS_ACK: | |
179 case I2C_READ_ACK: | |
180 case I2C_WRITE_ACK: | |
181 state->slave_sda = 0; | |
182 break; | |
183 case I2C_READ: | |
184 state->slave_sda = state->latch >> 7; | |
185 state->latch = state->latch << 1; | |
186 break; | |
187 default: | |
188 state->slave_sda = 1; | |
189 break; | |
190 } | |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
191 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
192 state->scl = val; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
193 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
194 |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
195 uint8_t get_sda(eeprom_state *state) |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
196 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
197 return state->host_sda & state->slave_sda; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
198 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
199 |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
200 enum { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
201 NOR_NORMAL, |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
202 NOR_PRODUCTID, |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
203 NOR_BOOTBLOCK |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
204 }; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
205 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
206 enum { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
207 NOR_CMD_IDLE, |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
208 NOR_CMD_AA, |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
209 NOR_CMD_55 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
210 }; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
211 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
212 //Technically this value shoudl be slightly different between NTSC and PAL |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
213 //as it's defined as 200 micro-seconds, not in clock cycles |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
214 #define NOR_WRITE_PAUSE 10690 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
215 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
216 void nor_flash_init(nor_state *state, uint8_t *buffer, uint32_t size, uint32_t page_size, uint16_t product_id, uint8_t bus_flags) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
217 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
218 state->buffer = buffer; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
219 state->page_buffer = malloc(page_size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
220 memset(state->page_buffer, 0xFF, page_size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
221 state->size = size; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
222 state->page_size = page_size; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
223 state->product_id = product_id; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
224 state->last_write_cycle = 0xFFFFFFFF; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
225 state->mode = NOR_NORMAL; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
226 state->cmd_state = NOR_CMD_IDLE; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
227 state->alt_cmd = 0; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
228 state->bus_flags = bus_flags; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
229 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
230 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
231 void nor_run(nor_state *state, uint32_t cycle) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
232 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
233 if (state->last_write_cycle == 0xFFFFFFFF) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
234 return; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
235 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
236 if (cycle - state->last_write_cycle >= NOR_WRITE_PAUSE) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
237 state->last_write_cycle = 0xFFFFFFFF; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
238 for (uint32_t i = 0; i < state->page_size; i++) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
239 state->buffer[state->current_page + i] = state->page_buffer[i]; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
240 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
241 memset(state->page_buffer, 0xFF, state->page_size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
242 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
243 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
244 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
245 uint8_t nor_flash_read_b(uint32_t address, void *vcontext) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
246 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
247 m68k_context *m68k = vcontext; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
248 genesis_context *gen = m68k->system; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
249 nor_state *state = &gen->nor; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
250 if ( |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
251 ((address & 1) && state->bus_flags == RAM_FLAG_EVEN) || |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
252 (!(address & 1) && state->bus_flags == RAM_FLAG_ODD) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
253 ) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
254 return 0xFF; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
255 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
256 if (state->bus_flags != RAM_FLAG_BOTH) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
257 address = address >> 1; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
258 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
259 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
260 nor_run(state, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
261 switch (state->mode) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
262 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
263 case NOR_NORMAL: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
264 return state->buffer[address & (state->size-1)]; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
265 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
266 case NOR_PRODUCTID: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
267 switch (address & (state->size - 1)) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
268 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
269 case 0: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
270 return state->product_id >> 8; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
271 case 1: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
272 return state->product_id; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
273 case 2: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
274 //TODO: Implement boot block protection |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
275 return 0xFE; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
276 default: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
277 return 0xFE; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
278 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
279 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
280 case NOR_BOOTBLOCK: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
281 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
282 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
283 return 0xFF; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
284 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
285 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
286 uint16_t nor_flash_read_w(uint32_t address, void *context) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
287 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
288 uint16_t value = nor_flash_read_b(address, context) << 8; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
289 value |= nor_flash_read_b(address+1, context); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
290 return value; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
291 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
292 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
293 void nor_write_byte(nor_state *state, uint32_t address, uint8_t value, uint32_t cycle) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
294 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
295 switch(state->mode) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
296 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
297 case NOR_NORMAL: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
298 if (state->last_write_cycle != 0xFFFFFFFF) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
299 state->current_page = address & (state->size - 1) & ~(state->page_size - 1); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
300 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
301 state->page_buffer[address & (state->page_size - 1)] = value; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
302 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
303 case NOR_PRODUCTID: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
304 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
305 case NOR_BOOTBLOCK: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
306 //TODO: Implement boot block protection |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
307 state->mode = NOR_NORMAL; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
308 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
309 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
310 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
311 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
312 void *nor_flash_write_b(uint32_t address, void *vcontext, uint8_t value) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
313 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
314 m68k_context *m68k = vcontext; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
315 genesis_context *gen = m68k->system; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
316 nor_state *state = &gen->nor; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
317 if ( |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
318 ((address & 1) && state->bus_flags == RAM_FLAG_EVEN) || |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
319 (!(address & 1) && state->bus_flags == RAM_FLAG_ODD) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
320 ) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
321 return vcontext; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
322 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
323 if (state->bus_flags != RAM_FLAG_BOTH) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
324 address = address >> 1; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
325 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
326 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
327 nor_run(state, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
328 switch (state->cmd_state) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
329 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
330 case NOR_CMD_IDLE: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
331 if (value == 0xAA && (address & (state->size - 1)) == 0x5555) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
332 state->cmd_state = NOR_CMD_AA; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
333 } else { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
334 nor_write_byte(state, address, value, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
335 state->cmd_state = NOR_CMD_IDLE; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
336 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
337 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
338 case NOR_CMD_AA: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
339 if (value == 0x55 && (address & (state->size - 1)) == 0x2AAA) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
340 state->cmd_state = NOR_CMD_55; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
341 } else { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
342 nor_write_byte(state, 0x5555, 0xAA, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
343 nor_write_byte(state, address, value, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
344 state->cmd_state = NOR_CMD_IDLE; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
345 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
346 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
347 case NOR_CMD_55: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
348 if ((address & (state->size - 1)) == 0x5555) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
349 if (state->alt_cmd) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
350 switch(value) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
351 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
352 case 0x10: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
353 puts("UNIMPLEMENTED: NOR flash erase"); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
354 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
355 case 0x20: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
356 puts("UNIMPLEMENTED: NOR flash disable protection"); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
357 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
358 case 0x40: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
359 state->mode = NOR_BOOTBLOCK; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
360 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
361 case 0x60: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
362 state->mode = NOR_PRODUCTID; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
363 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
364 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
365 } else { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
366 switch(value) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
367 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
368 case 0x80: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
369 state->alt_cmd = 1; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
370 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
371 case 0x90: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
372 state->mode = NOR_PRODUCTID; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
373 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
374 case 0xA0: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
375 puts("UNIMPLEMENTED: NOR flash enable protection"); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
376 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
377 case 0xF0: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
378 state->mode = NOR_NORMAL; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
379 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
380 default: |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
381 printf("Unrecognized unshifted NOR flash command %X\n", value); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
382 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
383 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
384 } else { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
385 nor_write_byte(state, 0x5555, 0xAA, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
386 nor_write_byte(state, 0x2AAA, 0x55, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
387 nor_write_byte(state, address, value, m68k->current_cycle); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
388 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
389 state->cmd_state = NOR_CMD_IDLE; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
390 break; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
391 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
392 return vcontext; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
393 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
394 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
395 void *nor_flash_write_w(uint32_t address, void *vcontext, uint16_t value) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
396 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
397 nor_flash_write_b(address, vcontext, value >> 8); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
398 return nor_flash_write_b(address + 1, vcontext, value); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
399 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
400 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
401 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
|
402 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
414 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
|
415 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
416 |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
417 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
|
418 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
419 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
|
420 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
|
421 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
|
422 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 if (address & 1) { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
427 return 0xFF; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
428 } else { |
767
ea525f600b1d
SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
429 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
|
430 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
431 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
|
432 if (address & 1) { |
767
ea525f600b1d
SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
433 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
|
434 } else { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
435 return 0xFF; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
436 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
437 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
438 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
|
439 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
440 |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
441 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
|
442 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 break; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
452 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
|
453 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
|
454 break; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
455 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
|
456 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
|
457 break; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
458 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
459 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
460 return context; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
461 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
462 |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
463 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
|
464 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
465 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
|
466 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
|
467 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
|
468 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
|
469 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
470 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
|
471 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
|
472 break; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
473 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
|
474 if (!(address & 1)) { |
767
ea525f600b1d
SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
475 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
|
476 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
477 break; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
478 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
|
479 if (address & 1) { |
767
ea525f600b1d
SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
480 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
|
481 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
482 break; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
483 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
484 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
485 return context; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
486 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
487 |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
488 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
|
489 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
490 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
|
491 address &= 0xE; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
492 address >>= 1; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
493 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
|
494 if (!address) { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
495 if (value & 1) { |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
496 //Used for games that only use the mapper for SRAM |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
497 context->mem_pointers[gen->mapper_start_index] = NULL; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
498 //For games that need more than 4MB |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
499 for (int i = 4; i < 8; i++) |
776
cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents:
775
diff
changeset
|
500 { |
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
|
501 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
|
502 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
503 } 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
|
504 //Used for games that only use the mapper for SRAM |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1091
diff
changeset
|
505 context->mem_pointers[gen->mapper_start_index] = gen->cart + 0x200000/2; |
776
cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents:
775
diff
changeset
|
506 //For games that need more than 4MB |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
507 for (int i = 4; i < 8; i++) |
776
cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents:
775
diff
changeset
|
508 { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1091
diff
changeset
|
509 context->mem_pointers[gen->mapper_start_index + i] = gen->cart + 0x40000*gen->bank_regs[i]; |
776
cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents:
775
diff
changeset
|
510 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
511 } |
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
|
512 } else { |
1324
2fc444b69351
Minor optimization to avoid invalidating translated code when the bank has not actually changed. Makes a nasty edge case in the 68K debugger slightly less severe when dealing with code that uses banking
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
513 void *new_ptr = gen->cart + 0x40000*value; |
2fc444b69351
Minor optimization to avoid invalidating translated code when the bank has not actually changed. Makes a nasty edge case in the 68K debugger slightly less severe when dealing with code that uses banking
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
514 if (context->mem_pointers[gen->mapper_start_index + address] != new_ptr) { |
2fc444b69351
Minor optimization to avoid invalidating translated code when the bank has not actually changed. Makes a nasty edge case in the 68K debugger slightly less severe when dealing with code that uses banking
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
515 m68k_invalidate_code_range(gen->m68k, address * 0x80000, (address + 1) * 0x80000); |
2fc444b69351
Minor optimization to avoid invalidating translated code when the bank has not actually changed. Makes a nasty edge case in the 68K debugger slightly less severe when dealing with code that uses banking
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
516 context->mem_pointers[gen->mapper_start_index + address] = new_ptr; |
2fc444b69351
Minor optimization to avoid invalidating translated code when the bank has not actually changed. Makes a nasty edge case in the 68K debugger slightly less severe when dealing with code that uses banking
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
517 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
518 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
519 return context; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
520 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
521 |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
522 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
|
523 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
524 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
|
525 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
|
526 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
527 return context; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
528 } |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
529 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
|
530 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
531 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
|
532 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
533 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
|
534 return gen->eeprom_map + i; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
535 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
536 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
537 return NULL; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
538 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
539 |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
540 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
|
541 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
542 genesis_context *gen = ((m68k_context *)context)->system; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
543 eeprom_map *map = find_eeprom_map(address, gen); |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
544 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
|
545 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
|
546 } |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
547 if (map->scl_mask) { |
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
548 set_scl(&gen->eeprom, (value & map->scl_mask) != 0); |
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
549 } |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
550 if (map->sda_write_mask) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
551 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
|
552 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
553 return context; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
554 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
555 |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
556 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
|
557 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
558 genesis_context *gen = ((m68k_context *)context)->system; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
559 eeprom_map *map = find_eeprom_map(address, gen); |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
560 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
|
561 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
|
562 } |
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
|
563 |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
564 uint16_t expanded, mask; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
565 if (address & 1) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
566 expanded = value; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
567 mask = 0xFF; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
568 } else { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
569 expanded = value << 8; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
570 mask = 0xFF00; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
571 } |
772
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
572 if (map->scl_mask & mask) { |
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
573 set_scl(&gen->eeprom, (expanded & map->scl_mask) != 0); |
1b82b282b829
Less broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents:
770
diff
changeset
|
574 } |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
575 if (map->sda_write_mask & mask) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
576 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
|
577 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
578 return context; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
579 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
580 |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
581 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
|
582 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
583 genesis_context *gen = ((m68k_context *)context)->system; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
584 eeprom_map *map = find_eeprom_map(address, gen); |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
585 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
|
586 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
|
587 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
588 uint16_t ret = 0; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
589 if (map->sda_read_bit < 16) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
590 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
|
591 } |
938
4c17c7f46331
Accept address on 128-byte EEPROMs on both read and write
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
592 return ret; |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
593 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
594 |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
595 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
|
596 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
597 genesis_context *gen = ((m68k_context *)context)->system; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
598 eeprom_map *map = find_eeprom_map(address, gen); |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
599 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
|
600 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
|
601 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
602 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
|
603 uint8_t ret = 0; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
604 if (bit < 8) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
605 ret = get_sda(&gen->eeprom) << bit; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
606 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
607 return ret; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
608 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
609 |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 tern_node *load_rom_db() |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 { |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
612 tern_node *db = parse_bundled_config("rom.db"); |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 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
|
614 fatal_error("Failed to load ROM DB\n"); |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 return db; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
619 void free_rom_info(rom_info *info) |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
620 { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
621 free(info->name); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
622 if (info->save_type != SAVE_NONE) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
623 free(info->save_buffer); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
624 if (info->save_type == SAVE_I2C) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
625 free(info->eeprom_map); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
626 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
627 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
628 free(info->map); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
629 free(info->port1_override); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
630 free(info->port2_override); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
631 free(info->ext_override); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
632 free(info->mouse_mode); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
633 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
634 |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
635 char *get_header_name(uint8_t *rom) |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
636 { |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
637 //TODO: Should probably prefer the title field that corresponds to the user's region preference |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 uint8_t *last = rom + TITLE_END - 1; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 uint8_t *src = rom + TITLE_START; |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
640 |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
641 for (;;) |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 { |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
643 while (last > src && (*last <= 0x20 || *last >= 0x80)) |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 { |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
645 last--; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
646 } |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
647 if (last == src) { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
648 if (src == rom + TITLE_START) { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
649 src = rom + DOM_TITLE_START; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
650 last = rom + DOM_TITLE_END - 1; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
651 } else { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
652 return strdup("UNKNOWN"); |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 } |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
654 } else { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
655 last++; |
1031
219de1d64aa1
Fixed a bug in get_header_name that results in a crash if the "International Name" field is blank
Michael Pavone <pavone@retrodev.com>
parents:
1016
diff
changeset
|
656 char *ret = malloc(last - src + 1); |
1006
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
657 uint8_t *dst; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
658 uint8_t last_was_space = 1; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
659 for (dst = ret; src < last; src++) |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
660 { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
661 if (*src >= 0x20 && *src < 0x80) { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
662 if (*src == ' ') { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
663 if (last_was_space) { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
664 continue; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
665 } |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
666 last_was_space = 1; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
667 } else { |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
668 last_was_space = 0; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
669 } |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
670 *(dst++) = *src; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
671 } |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
672 } |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
673 *dst = 0; |
9ab35686a025
Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents:
938
diff
changeset
|
674 return ret; |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 |
1195
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
679 char *region_chars = "JUEW"; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
680 uint8_t region_bits[] = {REGION_J, REGION_U, REGION_E, REGION_J|REGION_U|REGION_E}; |
765
dc54387ee1cd
Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents:
764
diff
changeset
|
681 |
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
|
682 uint8_t translate_region_char(uint8_t c) |
1195
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
683 { |
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
|
684 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
|
685 { |
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
|
686 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
|
687 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
|
688 } |
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
|
689 } |
1195
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
690 uint8_t bin_region = 0; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
691 if (c >= '0' && c <= '9') { |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
692 bin_region = c - '0'; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
693 } else if (c >= 'A' && c <= 'F') { |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
694 bin_region = c - 'A' + 0xA; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
695 } else if (c >= 'a' && c <= 'f') { |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
696 bin_region = c - 'a' + 0xA; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
697 } |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
698 uint8_t ret = 0; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
699 if (bin_region & 8) { |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
700 ret |= REGION_E; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
701 } |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
702 if (bin_region & 4) { |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
703 ret |= REGION_U; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
704 } |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
705 if (bin_region & 1) { |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
706 ret |= REGION_J; |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
707 } |
b8ba086b96ed
Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
708 return ret; |
765
dc54387ee1cd
Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents:
764
diff
changeset
|
709 } |
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
|
710 |
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
|
711 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
|
712 { |
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
|
713 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
|
714 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
|
715 { |
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
|
716 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
|
717 } |
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
|
718 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
|
719 } |
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
|
720 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
721 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
|
722 { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
723 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
|
724 } |
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
|
725 |
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
|
726 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
|
727 { |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
728 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
|
729 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
|
730 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
|
731 } 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
|
732 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
|
733 } 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
|
734 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
|
735 } |
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
|
736 } |
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
|
737 |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
738 uint8_t has_ram_header(uint8_t *rom, uint32_t rom_size) |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
739 { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
740 return rom_size >= (RAM_END + 4) && rom[RAM_ID] == 'R' && rom[RAM_ID + 1] == 'A'; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
741 } |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
742 |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
743 uint32_t read_ram_header(rom_info *info, uint8_t *rom) |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
744 { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
745 uint32_t ram_start = get_u32be(rom + RAM_START); |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
746 uint32_t ram_end = get_u32be(rom + RAM_END); |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
747 uint32_t ram_flags = info->save_type = rom[RAM_FLAGS] & RAM_FLAG_MASK; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
748 ram_start &= 0xFFFFFE; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
749 ram_end |= 1; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
750 info->save_mask = ram_end - ram_start; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
751 uint32_t save_size = info->save_mask + 1; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
752 if (ram_flags != RAM_FLAG_BOTH) { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
753 save_size /= 2; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
754 } |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
755 info->save_size = save_size; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
756 info->save_buffer = malloc(save_size); |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
757 return ram_start; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
758 } |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
759 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
760 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
|
761 { |
777
79b10b421d3c
Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents:
776
diff
changeset
|
762 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
|
763 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
|
764 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
|
765 } 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
|
766 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
|
767 } |
1287
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
768 if (size >= 0x80000 && !memcmp("SEGA SSF", rom + 0x100, 8)) { |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
769 info->mapper_start_index = 0; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
770 info->map_chunks = base_chunks + 9; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
771 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks); |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
772 memset(info->map, 0, sizeof(memmap_chunk)*9); |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
773 memcpy(info->map+9, base_map, sizeof(memmap_chunk) * base_chunks); |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
774 |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
775 info->map[0].start = 0; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
776 info->map[0].end = 0x80000; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
777 info->map[0].mask = 0xFFFFFF; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
778 info->map[0].flags = MMAP_READ; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
779 info->map[0].buffer = rom; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
780 |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
781 if (has_ram_header(rom, size)){ |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
782 read_ram_header(info, rom); |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
783 } |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
784 |
1287
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
785 for (int i = 1; i < 8; i++) |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
786 { |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
787 info->map[i].start = i * 0x80000; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
788 info->map[i].end = (i + 1) * 0x80000; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
789 info->map[i].mask = 0x7FFFF; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
790 info->map[i].buffer = (i + 1) * 0x80000 <= size ? rom + i * 0x80000 : rom; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
791 info->map[i].ptr_index = i; |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
792 info->map[i].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
793 |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
794 info->map[i].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[i] == NULL |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
795 info->map[i].read_8 = (read_8_fun)read_sram_b; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
796 info->map[i].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
797 info->map[i].write_8 = (write_8_fun)write_sram_area_b; |
1287
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
798 |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
799 } |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
800 info->map[8].start = 0xA13000; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
801 info->map[8].end = 0xA13100; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
802 info->map[8].mask = 0xFF; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
803 info->map[8].write_16 = (write_16_fun)write_bank_reg_w; |
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
804 info->map[8].write_8 = (write_8_fun)write_bank_reg_b; |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
805 } else if (has_ram_header(rom, size)) { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
806 uint32_t ram_start = read_ram_header(info, rom); |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
807 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 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
|
812 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
813 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
|
814 info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF; |
1281
34113230fd88
Fix heuristic detection of SRAM for 3MB ROMs with SRAM at the 3MB mark
Michael Pavone <pavone@retrodev.com>
parents:
1259
diff
changeset
|
815 if (info->map[0].end > ram_start) { |
34113230fd88
Fix heuristic detection of SRAM for 3MB ROMs with SRAM at the 3MB mark
Michael Pavone <pavone@retrodev.com>
parents:
1259
diff
changeset
|
816 info->map[0].end = ram_start; |
34113230fd88
Fix heuristic detection of SRAM for 3MB ROMs with SRAM at the 3MB mark
Michael Pavone <pavone@retrodev.com>
parents:
1259
diff
changeset
|
817 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
818 //TODO: ROM mirroring |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
819 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
|
820 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
|
821 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
|
822 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
823 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
|
824 info->map[1].mask = info->save_mask; |
1410
4cd4aa6be5f6
Initial SRAM support for lock-on carts
Michael Pavone <pavone@retrodev.com>
parents:
1409
diff
changeset
|
825 info->map[1].end = ram_start + info->save_mask + 1; |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
826 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
|
827 |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
828 if (info->save_type == RAM_FLAG_ODD) { |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
829 info->map[1].flags |= MMAP_ONLY_ODD; |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
830 } else if (info->save_type == RAM_FLAG_EVEN) { |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
831 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
|
832 } |
767
ea525f600b1d
SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
833 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
|
834 } else { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
835 //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
|
836 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
|
837 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
|
838 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
|
839 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
|
840 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
841 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
|
842 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
|
843 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
|
844 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
|
845 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
|
846 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
|
847 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
|
848 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
|
849 info->map[1].write_8 = (write_8_fun)write_sram_area_b; |
1221
53fc7efdfdab
Fix handling of SRAM overlapping with ROM
Michael Pavone <pavone@retrodev.com>
parents:
1195
diff
changeset
|
850 info->map[1].buffer = rom + 0x200000; |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
851 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
852 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
|
853 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
|
854 last->start = 0xA13000; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
855 last->end = 0xA13100; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
856 last->mask = 0xFF; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
857 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
|
858 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
|
859 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
860 } else { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
861 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
|
862 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
|
863 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
|
864 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
|
865 |
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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 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
|
871 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
872 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
873 |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
874 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
|
875 { |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
876 rom_info info; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
877 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
|
878 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
|
879 add_memmap_header(&info, rom, rom_size, base_map, base_chunks); |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
913
diff
changeset
|
880 info.port1_override = info.port2_override = info.ext_override = info.mouse_mode = NULL; |
765
dc54387ee1cd
Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents:
764
diff
changeset
|
881 return info; |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
882 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
883 |
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
|
884 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
|
885 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
|
886 uint8_t *rom; |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
887 uint8_t *lock_on; |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
888 tern_node *root; |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
889 tern_node *rom_db; |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
890 uint32_t rom_size; |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
891 uint32_t lock_on_size; |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
892 int index; |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
893 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
|
894 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
|
895 } 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
|
896 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
897 void eeprom_read_fun(char *key, tern_val val, uint8_t valtype, void *data) |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
898 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
899 int bit = atoi(key); |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
900 if (bit < 0 || bit > 15) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
901 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
|
902 return; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
903 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
904 if (valtype != TVAL_PTR) { |
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
905 fprintf(stderr, "bit %s has a non-scalar value", key); |
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
906 return; |
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
907 } |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
908 char *pin = val.ptrval; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
909 if (strcmp(pin, "sda")) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
910 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
|
911 return; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
912 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
913 eeprom_map *map = data; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
914 map->sda_read_bit = bit; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
915 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
916 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
917 void eeprom_write_fun(char *key, tern_val val, uint8_t valtype, void *data) |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
918 { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
919 int bit = atoi(key); |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
920 if (bit < 0 || bit > 15) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
921 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
|
922 return; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
923 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
924 if (valtype != TVAL_PTR) { |
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
925 fprintf(stderr, "bit %s has a non-scalar value", key); |
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
926 return; |
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
927 } |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
928 char *pin = val.ptrval; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
929 eeprom_map *map = data; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
930 if (!strcmp(pin, "sda")) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
931 map->sda_write_mask = 1 << bit; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
932 return; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
933 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
934 if (!strcmp(pin, "scl")) { |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
935 map->scl_mask = 1 << bit; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
936 return; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
937 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
938 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
|
939 } |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
940 |
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
|
941 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
|
942 { |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
943 if (!state->info->save_size) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
944 char * size = tern_find_path(state->root, "SRAM\0size\0", TVAL_PTR).ptrval; |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
945 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
|
946 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
|
947 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
948 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
|
949 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
|
950 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
|
951 } |
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
|
952 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
|
953 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
|
954 memset(state->info->save_buffer, 0, state->info->save_size); |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
955 char *bus = tern_find_path(state->root, "SRAM\0bus\0", TVAL_PTR).ptrval; |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
956 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
|
957 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
|
958 } 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
|
959 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
|
960 } 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
|
961 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
|
962 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
963 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
964 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
965 |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
966 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
|
967 { |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
968 if (!state->info->save_size) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
969 char * size = tern_find_path(state->root, "EEPROM\0size\0", TVAL_PTR).ptrval; |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
970 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
|
971 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
|
972 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
973 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
|
974 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
|
975 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
|
976 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
977 char *etype = tern_find_path(state->root, "EEPROM\0type\0", TVAL_PTR).ptrval; |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
978 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
|
979 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
|
980 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
981 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
|
982 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
|
983 } 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
|
984 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
|
985 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
986 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
|
987 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
|
988 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
|
989 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
|
990 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
991 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
992 |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
993 void process_nor_def(char *key, map_iter_state *state) |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
994 { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
995 if (!state->info->save_size) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
996 char *size = tern_find_path(state->root, "NOR\0size\0", TVAL_PTR).ptrval; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
997 if (!size) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
998 fatal_error("ROM DB map entry %d with address %s has device type NOR, but the NOR size is not defined\n", state->index, key); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
999 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1000 state->info->save_size = atoi(size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1001 if (!state->info->save_size) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1002 fatal_error("NOR size %s is invalid\n", size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1003 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1004 char *page_size = tern_find_path(state->root, "NOR\0page_size\0", TVAL_PTR).ptrval; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1005 if (!page_size) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1006 fatal_error("ROM DB map entry %d with address %s has device type NOR, but the NOR page size is not defined\n", state->index, key); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1007 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1008 state->info->save_page_size = atoi(size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1009 if (!state->info->save_page_size) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1010 fatal_error("NOR page size %s is invalid\n", size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1011 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1012 char *product_id = tern_find_path(state->root, "NOR\0product_id\0", TVAL_PTR).ptrval; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1013 if (!product_id) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1014 fatal_error("ROM DB map entry %d with address %s has device type NOR, but the NOR product ID is not defined\n", state->index, key); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1015 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1016 state->info->save_product_id = strtol(product_id, NULL, 16); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1017 char *bus = tern_find_path(state->root, "NOR\0bus\0", TVAL_PTR).ptrval; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1018 if (!strcmp(bus, "odd")) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1019 state->info->save_bus = RAM_FLAG_ODD; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1020 } else if(!strcmp(bus, "even")) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1021 state->info->save_bus = RAM_FLAG_EVEN; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1022 } else { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1023 state->info->save_bus = RAM_FLAG_BOTH; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1024 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1025 state->info->save_type = SAVE_NOR; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1026 state->info->save_buffer = malloc(state->info->save_size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1027 memset(state->info->save_buffer, 0xFF, state->info->save_size); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1028 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1029 } |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1030 |
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
|
1031 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
|
1032 { |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1033 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
|
1034 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
|
1035 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
|
1036 eep_map->sda_read_bit = 0xFF; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1037 tern_node * bits_read = tern_find_node(node, "bits_read"); |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1038 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
|
1039 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
|
1040 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1041 tern_node * bits_write = tern_find_node(node, "bits_write"); |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1042 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
|
1043 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
|
1044 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1045 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
|
1046 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
|
1047 } |
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1048 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1049 void map_iter_fun(char *key, tern_val val, uint8_t valtype, void *data) |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
1050 { |
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
|
1051 map_iter_state *state = data; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1052 if (valtype != TVAL_NODE) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
781
diff
changeset
|
1053 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
|
1054 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1055 tern_node *node = val.ptrval; |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 } |
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
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 map->mask = calc_mask(state->rom_size - offset, start, end); |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1070 } else if (!strcmp(dtype, "LOCK-ON")) { |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1071 rom_info lock_info; |
1408
71b6e2298e4a
Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents:
1395
diff
changeset
|
1072 if (state->lock_on) { |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1073 lock_info = configure_rom(state->rom_db, state->lock_on, state->lock_on_size, NULL, 0, NULL, 0); |
1408
71b6e2298e4a
Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents:
1395
diff
changeset
|
1074 } else if (state->rom_size > start) { |
71b6e2298e4a
Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents:
1395
diff
changeset
|
1075 //This is a bit of a hack to deal with pre-combined S3&K/S2&K ROMs and S&K ROM hacks |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1076 lock_info = configure_rom(state->rom_db, state->rom + start, state->rom_size - start, NULL, 0, NULL, 0); |
1408
71b6e2298e4a
Better handling of S&K lock on support. Pre-combined ROMs and large (>2MB) S&K hacks should now work. Implemented correct behavior from locking on a 4MB cart
Michael Pavone <pavone@retrodev.com>
parents:
1395
diff
changeset
|
1077 } else { |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1078 //skip this entry if there is no lock on cartridge attached |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1079 return; |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1080 } |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1081 uint32_t matching_chunks = 0; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1082 for (int i = 0; i < lock_info.map_chunks; i++) |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1083 { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1084 if (lock_info.map[i].start < 0xC00000 && lock_info.map[i].end > 0x200000) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1085 matching_chunks++; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1086 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1087 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1088 if (matching_chunks == 0) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1089 //Nothing mapped in the relevant range for the lock-on cart, ignore this mapping |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1090 return; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1091 } else if (matching_chunks > 1) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1092 state->info->map_chunks += matching_chunks - 1; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1093 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1094 memset(state->info->map + state->info->map_chunks - (matching_chunks - 1), 0, sizeof(memmap_chunk) * (matching_chunks - 1)); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1095 map = state->info->map + state->index; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1096 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1097 for (int i = 0; i < matching_chunks; i++) |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1098 { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1099 if (lock_info.map[i].start >= 0xC00000 || lock_info.map[i].end <= 0x200000) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1100 continue; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1101 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1102 *map = lock_info.map[i]; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1103 if (map->start < 0x200000) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1104 if (map->buffer) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1105 map->buffer += (0x200000 - map->start) & ((map->flags & MMAP_AUX_BUFF) ? map->aux_mask : map->mask); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1106 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1107 map->start = 0x200000; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1108 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1109 map++; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1110 state->index++; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1111 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1112 if (state->info->save_type == SAVE_NONE && lock_info.save_type != SAVE_NONE) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1113 //main cart has no save device, but lock-on cart does |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1114 if (state->lock_on) { |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1115 state->info->is_save_lock_on = 1; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1116 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1117 state->info->save_buffer = lock_info.save_buffer; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1118 state->info->save_size = lock_info.save_size; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1119 state->info->save_mask = lock_info.save_mask; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1120 state->info->save_page_size = lock_info.save_page_size; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1121 state->info->save_product_id = lock_info.save_product_id; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1122 state->info->save_type = lock_info.save_type; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1123 state->info->save_bus = lock_info.save_bus; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1124 lock_info.save_buffer = NULL; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1125 lock_info.save_type = SAVE_NONE; |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1126 } |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1127 free_rom_info(&lock_info); |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1128 return; |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
1129 } 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
|
1130 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
|
1131 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
|
1132 |
769
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
1133 map->write_16 = write_eeprom_i2c_w; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
1134 map->write_8 = write_eeprom_i2c_b; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
1135 map->read_16 = read_eeprom_i2c_w; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
1136 map->read_8 = read_eeprom_i2c_b; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
1137 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
|
1138 } 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
|
1139 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
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 } 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
|
1145 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
|
1146 } |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
1147 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
|
1148 } 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
|
1149 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
|
1150 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
|
1151 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
|
1152 } |
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
|
1153 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
|
1154 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
|
1155 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
|
1156 char *bus = tern_find_ptr_default(node, "bus", "both"); |
1394
ae3b1721b226
Small fix to handling of the "bus" option in a RAM type ROM DB memory map
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1157 if (!strcmp(bus, "odd")) { |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
1158 map->flags |= MMAP_ONLY_ODD; |
1394
ae3b1721b226
Small fix to handling of the "bus" option in a RAM type ROM DB memory map
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1159 } else if (!strcmp(bus, "even")) { |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
1160 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
|
1161 } 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
|
1162 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
|
1163 } |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1164 } else if (!strcmp(dtype, "NOR")) { |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1165 process_nor_def(key, state); |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1166 |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1167 map->write_16 = nor_flash_write_w; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1168 map->write_8 = nor_flash_write_b; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1169 map->read_16 = nor_flash_read_w; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1170 map->read_8 = nor_flash_read_b; |
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1394
diff
changeset
|
1171 map->mask = 0xFFFFFF; |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1172 } 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
|
1173 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
|
1174 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
|
1175 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
|
1176 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
|
1177 map = state->info->map + state->index; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1178 char *save_device = tern_find_path(node, "save\0device\0", TVAL_PTR).ptrval; |
776
cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents:
775
diff
changeset
|
1179 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
|
1180 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
|
1181 add_eeprom_map(node, start & map->mask, end & map->mask, state); |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1182 } else if (save_device && !strcmp(save_device, "SRAM")) { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1183 process_sram_def(key, state); |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1184 } else if(has_ram_header(state->rom, state->rom_size)) { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1185 //no save definition in ROM DB entry, but there is an SRAM header |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1186 //this support is mostly to handle homebrew that uses the SSF2 product ID |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1187 //in an attempt to signal desire for the full Sega/SSF2 mapper, but also uses SRAM unlike SSF2 |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1188 read_ram_header(state->info, state->rom); |
774
41dc895e85ff
Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
772
diff
changeset
|
1189 } |
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
|
1190 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
|
1191 { |
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
|
1192 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
|
1193 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
|
1194 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
|
1195 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
|
1196 map->ptr_index = state->ptr_index++; |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1197 if (i < 3) { |
1287
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
1198 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE; |
776
cbf97d335444
Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents:
775
diff
changeset
|
1199 } else { |
1287
65f03a0a426a
Add Mega Everdrive style header detection for homebrew using the SSF2 mapper, though without the Mega Everdrive extensions. Properly invalidate translated code on a bank switch when using the SSF2/Sega mapper
Michael Pavone <pavone@retrodev.com>
parents:
1281
diff
changeset
|
1200 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL; |
1409
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1201 if (save_device && !strcmp(save_device, "EEPROM")) { |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1202 map->write_16 = write_eeprom_i2c_w; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1203 map->write_8 = write_eeprom_i2c_b; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1204 map->read_16 = read_eeprom_i2c_w; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1205 map->read_8 = read_eeprom_i2c_b; |
b0e0bb20fc41
Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1408
diff
changeset
|
1206 } 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
|
1207 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
|
1208 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
|
1209 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
|
1210 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
|
1211 } |
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
|
1212 } |
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
|
1213 } |
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
|
1214 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
|
1215 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
|
1216 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
|
1217 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
|
1218 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
|
1219 } 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
|
1220 //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
|
1221 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
|
1222 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
|
1223 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
|
1224 map->read_16 = menu_read_w; |
1305
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1225 } else if (!strcmp(dtype, "fixed")) { |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1226 uint16_t *value = malloc(2); |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1227 map->buffer = value; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1228 map->mask = 0; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1229 map->flags = MMAP_READ; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1230 *value = strtol(tern_find_ptr_default(node, "value", "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
|
1231 } else { |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1232 fatal_error("Invalid device type %s for ROM DB map entry %d with address %s\n", dtype, state->index, key); |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
767
diff
changeset
|
1233 } |
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
|
1234 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
|
1235 } |
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
|
1236 |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1237 rom_info configure_rom(tern_node *rom_db, void *vrom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, memmap_chunk const *base_map, uint32_t base_chunks) |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1238 { |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1239 uint8_t product_id[GAME_ID_LEN+1]; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1240 uint8_t *rom = vrom; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1241 product_id[GAME_ID_LEN] = 0; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1242 for (int i = 0; i < GAME_ID_LEN; i++) |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1243 { |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1244 if (rom[GAME_ID_OFF + i] <= ' ') { |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1245 product_id[i] = 0; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1246 break; |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1247 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1248 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
|
1249 |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1250 } |
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
|
1251 printf("Product ID: %s\n", product_id); |
1305
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1252 uint8_t raw_hash[20]; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1253 sha1(vrom, rom_size, raw_hash); |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1254 uint8_t hex_hash[41]; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1255 bin_to_hex(hex_hash, raw_hash, 20); |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1256 printf("SHA1: %s\n", hex_hash); |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1257 tern_node * entry = tern_find_node(rom_db, hex_hash); |
1305
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1258 if (!entry) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1259 entry = tern_find_node(rom_db, product_id); |
1305
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1287
diff
changeset
|
1260 } |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1261 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
|
1262 puts("Not found in ROM DB, examining header\n"); |
1259
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1263 if (xband_detect(rom, rom_size)) { |
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1264 return xband_configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, base_map, base_chunks); |
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1265 } |
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1266 if (realtec_detect(rom, rom_size)) { |
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1267 return realtec_configure_rom(rom, rom_size, base_map, base_chunks); |
23c94f5266d1
Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1268 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
1269 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
|
1270 } |
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1271 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
|
1272 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
|
1273 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
|
1274 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
|
1275 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
|
1276 } 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
|
1277 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
|
1278 } |
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
|
1279 |
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
|
1280 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
|
1281 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
|
1282 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
|
1283 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
|
1284 { |
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
|
1285 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
|
1286 } |
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
|
1287 } |
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
|
1288 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
|
1289 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
|
1290 } |
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
|
1291 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1292 tern_node *map = tern_find_node(entry, "map"); |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 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
|
1298 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
|
1299 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
|
1300 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
|
1301 info.eeprom_map = NULL; |
4638b88bc72d
Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents:
768
diff
changeset
|
1302 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
|
1303 memset(info.map, 0, sizeof(memmap_chunk) * info.map_chunks); |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1304 map_iter_state state = { |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1305 .info = &info, |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1306 .rom = rom, |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1307 .lock_on = lock_on, |
1411
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1308 .root = entry, |
780fbe0b97be
WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents:
1410
diff
changeset
|
1309 .rom_db = rom_db, |
1016
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1310 .rom_size = rom_size, |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1311 .lock_on_size = lock_on_size, |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1312 .index = 0, |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1313 .num_els = info.map_chunks - base_chunks, |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1314 .ptr_index = 0 |
5fb64487b6e1
Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents:
1006
diff
changeset
|
1315 }; |
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
|
1316 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
|
1317 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
|
1318 } else { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
1319 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
|
1320 } |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
1321 } else { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
765
diff
changeset
|
1322 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
|
1323 } |
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
|
1324 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1324
diff
changeset
|
1325 tern_node *device_overrides = tern_find_node(entry, "device_overrides"); |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1326 if (device_overrides) { |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1327 info.port1_override = tern_find_ptr(device_overrides, "1"); |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1328 info.port2_override = tern_find_ptr(device_overrides, "2"); |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1329 info.ext_override = tern_find_ptr(device_overrides, "ext"); |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1330 } else { |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1331 info.port1_override = info.port2_override = info.ext_override = NULL; |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1332 } |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
913
diff
changeset
|
1333 info.mouse_mode = tern_find_ptr(entry, "mouse_mode"); |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1334 |
764
bb60259e8edf
Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1335 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
|
1336 } |