annotate romdb.c @ 1409:b0e0bb20fc41

Fix and enhance Sega/SSF2 mapper support to handle homebrew and hacks that use it in combination with SRAM
author Michael Pavone <pavone@retrodev.com>
date Mon, 19 Jun 2017 23:27:11 -0700
parents 71b6e2298e4a
children 4cd4aa6be5f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdlib.h>
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <string.h>
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "config.h"
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "romdb.h"
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "util.h"
1305
5ceb316c479a Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents: 1287
diff changeset
6 #include "hash.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1091
diff changeset
7 #include "genesis.h"
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
8 #include "menu.h"
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents: 1221
diff changeset
9 #include "xband.h"
1259
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
10 #include "realtec.h"
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
33 enum {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
34 I2C_IDLE,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
35 I2C_START,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
36 I2C_DEVICE_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
37 I2C_ADDRESS_HI,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
38 I2C_ADDRESS_HI_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
39 I2C_ADDRESS,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
40 I2C_ADDRESS_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
41 I2C_READ,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
42 I2C_READ_ACK,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
43 I2C_WRITE,
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
44 I2C_WRITE_ACK
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
45 };
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
46
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
47 char * i2c_states[] = {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
48 "idle",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
49 "start",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
50 "device ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
51 "address hi",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
52 "address hi ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
53 "address",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
54 "address ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
55 "read",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
56 "read_ack",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
57 "write",
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
58 "write_ack"
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
59 };
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
60
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
65 state->buffer = buffer;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
66 state->size = size;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
74 //low to high, stop condition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
75 state->state = I2C_IDLE;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
78 //high to low, start condition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
79 state->state = I2C_START;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
80 state->slave_sda = 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
90 //low to high transition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
91 switch (state->state)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
92 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
93 case I2C_START:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
94 case I2C_ADDRESS_HI:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
95 case I2C_ADDRESS:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
98 state->counter--;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
99 if (!state->counter) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
100 switch (state->state & 0x7F)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
101 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
102 case I2C_START:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
103 state->state = I2C_DEVICE_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
104 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
105 case I2C_ADDRESS_HI:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
106 state->address = state->latch << 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
107 state->state = I2C_ADDRESS_HI_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
108 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
109 case I2C_ADDRESS:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
110 state->address |= state->latch;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
111 state->state = I2C_ADDRESS_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
112 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
113 case I2C_WRITE:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
114 state->buffer[state->address] = state->latch;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
115 state->state = I2C_WRITE_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
116 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
117 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
118 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
119 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
120 case I2C_DEVICE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
121 if (state->latch & 1) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
122 state->state = I2C_READ;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
127 state->latch = state->buffer[state->address];
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
128 } else {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
129 if (state->size < 256) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
130 state->address = state->latch >> 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
134 state->state = I2C_ADDRESS;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
135 } else {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
136 state->state = I2C_ADDRESS_HI;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
137 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
138 state->counter = 8;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
139 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
140 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
141 case I2C_ADDRESS_HI_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
144 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
145 case I2C_ADDRESS_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
149 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
150 case I2C_READ:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
151 state->counter--;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
152 if (!state->counter) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
153 state->state = I2C_READ_ACK;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
154 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
155 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
156 case I2C_READ_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
163 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
164 case I2C_WRITE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
165 state->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
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
170 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
171 }
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
172 } else if (~val & state->scl) {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
173 //high to low transition
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
174 switch (state->state & 0x7F)
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
175 {
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
176 case I2C_DEVICE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
177 case I2C_ADDRESS_HI_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
178 case I2C_ADDRESS_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
179 case I2C_READ_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
180 case I2C_WRITE_ACK:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
181 state->slave_sda = 0;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
182 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
183 case I2C_READ:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
184 state->slave_sda = state->latch >> 7;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
185 state->latch = state->latch << 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
186 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
187 default:
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
188 state->slave_sda = 1;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
189 break;
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
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
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
619 char *get_header_name(uint8_t *rom)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
620 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
621 //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
622 uint8_t *last = rom + TITLE_END - 1;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
623 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
624
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
625 for (;;)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
626 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
627 while (last > src && (*last <= 0x20 || *last >= 0x80))
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
628 {
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
629 last--;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
630 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
631 if (last == src) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
632 if (src == rom + TITLE_START) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
633 src = rom + DOM_TITLE_START;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
634 last = rom + DOM_TITLE_END - 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
635 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
636 return strdup("UNKNOWN");
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
637 }
1006
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
638 } else {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
639 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
640 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
641 uint8_t *dst;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
642 uint8_t last_was_space = 1;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
643 for (dst = ret; src < last; src++)
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
644 {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
645 if (*src >= 0x20 && *src < 0x80) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
646 if (*src == ' ') {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
647 if (last_was_space) {
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
648 continue;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
649 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
650 last_was_space = 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 last_was_space = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
653 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
654 *(dst++) = *src;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
655 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
656 }
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
657 *dst = 0;
9ab35686a025 Improve parsing of game name from ROM header
Michael Pavone <pavone@retrodev.com>
parents: 938
diff changeset
658 return ret;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
659 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
660 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
661 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
662
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
663 char *region_chars = "JUEW";
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
664 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
665
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
666 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
667 {
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
668 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
669 {
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
670 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
671 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
672 }
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
673 }
1195
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
674 uint8_t bin_region = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
675 if (c >= '0' && c <= '9') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
676 bin_region = c - '0';
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
677 } else if (c >= 'A' && c <= 'F') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
678 bin_region = c - 'A' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
679 } else if (c >= 'a' && c <= 'f') {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
680 bin_region = c - 'a' + 0xA;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
681 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
682 uint8_t ret = 0;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
683 if (bin_region & 8) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
684 ret |= REGION_E;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
685 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
686 if (bin_region & 4) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
687 ret |= REGION_U;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
688 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
689 if (bin_region & 1) {
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
690 ret |= REGION_J;
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
691 }
b8ba086b96ed Improved parsing of cartridge region header
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
692 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
693 }
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
694
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
695 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
696 {
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
697 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
698 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
699 {
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
700 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
701 }
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
702 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
703 }
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
704
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
705 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
706 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
707 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
708 }
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
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
710 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
711 {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
712 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
713 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
714 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
715 } 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
716 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
717 } 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
718 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
719 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
720 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
721
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
722 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
723 {
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
724 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
725 }
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
726
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
727 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
728 {
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
729 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
730 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
731 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
732 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
733 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
734 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
735 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
736 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
737 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
738 }
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 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
740 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
741 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
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
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
744 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
745 {
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
746 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
747 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
748 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
749 } 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
750 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
751 }
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
752 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
753 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
754 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
755 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
756 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
757 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
758
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
759 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
760 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
761 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
762 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
763 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
764
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
765 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
766 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
767 }
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
768
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
769 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
770 {
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[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
772 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
773 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
774 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
775 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
776 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
777
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
778 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
779 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
780 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
781 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
782
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
783 }
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
784 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
785 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
786 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
787 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
788 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
789 } 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
790 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
791
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
792 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
793 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
794 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
795 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
796
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
797 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
798 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
799 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
800 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
801 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
802 //TODO: ROM mirroring
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
803 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
804 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
805 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
806
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
807 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
808 info->map[1].mask = info->save_mask;
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
809 info->map[1].end = ram_start + info->save_size;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
810 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
811
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
812 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
813 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
814 } 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
815 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
816 }
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
817 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
818 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
819 //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
820 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
821 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
822 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
823 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
824
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
825 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
826 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
827 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
828 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
829 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
830 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
831 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
832 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
833 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
834 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
835
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
836 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
837 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
838 last->start = 0xA13000;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
839 last->end = 0xA13100;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
840 last->mask = 0xFF;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
841 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
842 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
843 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
844 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
845 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
846 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
847 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
848 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
849
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
850 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
851 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
852 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
853 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
854 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
855 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
856 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
857
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
858 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
859 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
860 rom_info info;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
861 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
862 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
863 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
864 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
865 return info;
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
866 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
867
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
868 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
869 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
870 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
871 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
872 tern_node *root;
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
873 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
874 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
875 int index;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
876 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
877 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
878 } 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
879
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
880 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
881 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
882 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
883 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
884 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
885 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
886 }
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
887 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
888 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
889 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
890 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
891 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
892 if (strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
893 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
894 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
895 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
896 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
897 map->sda_read_bit = bit;
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
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
900 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
901 {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
902 int bit = atoi(key);
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
903 if (bit < 0 || bit > 15) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
904 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
905 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
906 }
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
907 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
908 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
909 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
910 }
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
911 char *pin = val.ptrval;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
912 eeprom_map *map = data;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
913 if (!strcmp(pin, "sda")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
914 map->sda_write_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
915 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
916 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
917 if (!strcmp(pin, "scl")) {
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
918 map->scl_mask = 1 << bit;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
919 return;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
920 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
921 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
922 }
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
923
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
924 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
925 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
926 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
927 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
928 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
929 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
930 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
931 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
932 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
933 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
934 }
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
935 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
936 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
937 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
938 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
939 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
940 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
941 } 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
942 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
943 } 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
944 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
945 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
946 }
41dc895e85ff Fix map for NFL Quarterback 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
41dc895e85ff Fix map for NFL Quarterback 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 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
950 {
41dc895e85ff Fix map for NFL Quarterback 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 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
952 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
953 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
954 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
955 }
41dc895e85ff Fix map for NFL Quarterback 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 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
957 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
958 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
959 }
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
960 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
961 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
962 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
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 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
965 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
966 } 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
967 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
968 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
969 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
970 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
971 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
972 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
973 }
41dc895e85ff Fix map for NFL Quarterback 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 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
975
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
976 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
977 {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
978 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
979 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
980 if (!size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
981 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
982 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
983 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
984 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
985 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
986 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
987 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
988 if (!page_size) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
989 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
990 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
991 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
992 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
993 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
994 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
995 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
996 if (!product_id) {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
997 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
998 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
999 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
1000 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
1001 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
1002 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
1003 } 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
1004 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
1005 } else {
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
1006 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
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_type = SAVE_NOR;
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
1009 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
1010 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
1011 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
1012 }
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
1013
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
1014 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
1015 {
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 }
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
1024 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
1025 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
1026 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
1027 }
41dc895e85ff Fix map for NFL Quarterback Club 96. Fix default EEPROM value. Initial work for supporing Sega mapper in ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 772
diff changeset
1028 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
1029 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
1030 }
41dc895e85ff Fix map for NFL Quarterback 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
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
1032 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
1033 {
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1034 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
1035 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
1036 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
1037 }
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
1038 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
1039 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
1040 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
1041 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
1042 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
1043 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 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
1052 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
1053 } else if (!strcmp(dtype, "LOCK-ON")) {
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
1054 if (state->lock_on) {
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
1055 if (state->lock_on_size > offset) {
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
1056 map->mask = calc_mask(state->lock_on_size - offset, start, end);
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
1057 } else {
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
1058 map->mask = calc_mask(state->lock_on_size, start, end);
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
1059 }
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
1060 map->buffer = state->lock_on + (offset & (nearest_pow2(state->lock_on_size) - 1));
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
1061 } 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
1062 //This is a bit of a hack to deal with pre-combined S3&K/S2&K ROMs and S&K ROM hacks
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
1063 map->buffer = state->rom + 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
1064 map->mask = calc_mask(state->rom_size - start, start, end);
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
1065 } 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
1066 //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
1067 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
1068 }
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1069 map->flags = MMAP_READ;
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
1070 } 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
1071 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
1072 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
1073
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1074 map->write_16 = write_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1075 map->write_8 = write_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1076 map->read_16 = read_eeprom_i2c_w;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1077 map->read_8 = read_eeprom_i2c_b;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1078 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
1079 } 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
1080 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
1081 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
1082 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
1083 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
1084 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
1085 } 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
1086 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
1087 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1088 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
1089 } 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
1090 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
1091 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
1092 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
1093 }
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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 } 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
1101 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
1102 } 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
1103 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
1104 }
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
1105 } 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
1106 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
1107
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1394
diff changeset
1108 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
1109 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
1110 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
1111 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
1112 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
1113 } 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
1114 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
1115 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
1116 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
1117 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
1118 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
1119 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
1120 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
1121 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
1122 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
1123 } 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
1124 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
1125 } 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
1126 //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
1127 //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
1128 //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
1129 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
1130 }
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
1131 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
1132 {
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
1133 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
1134 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
1135 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
1136 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
1137 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
1138 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
1139 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
1140 } 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
1141 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
1142 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
1143 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
1144 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
1145 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
1146 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
1147 } 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
1148 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
1149 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
1150 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
1151 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
1152 }
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
1153 }
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
1154 }
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
1155 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
1156 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
1157 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
1158 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
1159 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
1160 } 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
1161 //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
1162 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
1163 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
1164 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
1165 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
1166 } 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
1167 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
1168 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
1169 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
1170 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
1171 *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
1172 } 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
1173 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
1174 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1175 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
1176 }
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
1177
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
1178 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
1179 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1180 uint8_t product_id[GAME_ID_LEN+1];
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1181 uint8_t *rom = vrom;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1182 product_id[GAME_ID_LEN] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1183 for (int i = 0; i < GAME_ID_LEN; i++)
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1184 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1185 if (rom[GAME_ID_OFF + i] <= ' ') {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1186 product_id[i] = 0;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1187 break;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1188 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1189 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
1190
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1191 }
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
1192 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
1193 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
1194 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
1195 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
1196 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
1197 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
1198 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
1199 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
1200 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
1201 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1202 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
1203 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
1204 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
1205 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
1206 }
23c94f5266d1 Support for the Realtec mapper. Needs testing with games besides The Earth Defend
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
1207 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
1208 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
1209 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1210 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
1211 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1212 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
1213 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
1214 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
1215 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
1216 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
1217 } 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
1218 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
1219 }
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
1220
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
1221 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
1222 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
1223 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
1224 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
1225 {
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
1226 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
1227 }
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
1228 }
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
1229 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
1230 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
1231 }
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
1232
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
1233 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
1234 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
1235 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
1236 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
1237 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
1238 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
1239 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
1240 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
1241 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
1242 info.eeprom_map = NULL;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
1243 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
1244 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
1245 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
1246 .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
1247 .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
1248 .lock_on = lock_on,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1249 .root = entry,
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1006
diff changeset
1250 .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
1251 .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
1252 .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
1253 .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
1254 .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
1255 };
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
1256 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
1257 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
1258 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1259 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
1260 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1261 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1262 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
1263 }
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
1264
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
1265 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
1266 if (device_overrides) {
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
1267 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
1268 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
1269 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
1270 } else {
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
1271 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
1272 }
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
1273 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
1274
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1275 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
1276 }