comparison backend.c @ 1769:8fe162bdb038 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Fri, 01 Mar 2019 14:17:29 -0800
parents 956c1cce05e2 33ec5df77fac
children e59045f781ce
comparison
equal deleted inserted replaced
1768:63256371046f 1769:8fe162bdb038
93 } 93 }
94 } 94 }
95 return NULL; 95 return NULL;
96 } 96 }
97 97
98 void * get_native_write_pointer(uint32_t address, void ** mem_pointers, cpu_options * opts)
99 {
100 memmap_chunk const * memmap = opts->memmap;
101 address &= opts->address_mask;
102 for (uint32_t chunk = 0; chunk < opts->memmap_chunks; chunk++)
103 {
104 if (address >= memmap[chunk].start && address < memmap[chunk].end) {
105 if (!(memmap[chunk].flags & (MMAP_WRITE))) {
106 return NULL;
107 }
108 uint8_t * base = memmap[chunk].flags & MMAP_PTR_IDX
109 ? mem_pointers[memmap[chunk].ptr_index]
110 : memmap[chunk].buffer;
111 if (!base) {
112 if (memmap[chunk].flags & MMAP_AUX_BUFF) {
113 return memmap[chunk].buffer + (address & memmap[chunk].aux_mask);
114 }
115 return NULL;
116 }
117 return base + (address & memmap[chunk].mask);
118 }
119 }
120 return NULL;
121 }
122
98 uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, void *context) 123 uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, void *context)
99 { 124 {
100 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); 125 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL);
101 if (!chunk) { 126 if (!chunk) {
102 return 0xFFFF; 127 return 0xFFFF;
167 { 192 {
168 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); 193 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL);
169 if (!chunk) { 194 if (!chunk) {
170 return 0xFF; 195 return 0xFF;
171 } 196 }
172 uint32_t offset = (address - chunk->start) & chunk->mask; 197 uint32_t offset = address & chunk->mask;
173 if (chunk->flags & MMAP_READ) { 198 if (chunk->flags & MMAP_READ) {
174 uint8_t *base; 199 uint8_t *base;
175 if (chunk->flags & MMAP_PTR_IDX) { 200 if (chunk->flags & MMAP_PTR_IDX) {
176 base = mem_pointers[chunk->ptr_index]; 201 base = mem_pointers[chunk->ptr_index];
177 } else { 202 } else {
178 base = chunk->buffer; 203 base = chunk->buffer;
179 } 204 }
180 if (base) { 205 if (base) {
181 uint16_t val; 206 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
182 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { 207 if (address & 1) {
183 offset /= 2; 208 if (chunk->flags & MMAP_ONLY_EVEN) {
184 } else if (opts->byte_swap || (chunk->flags & MMAP_BYTESWAP)) { 209 return 0xFF;
185 offset ^= 1; 210 }
186 } 211 } else if (chunk->flags & MMAP_ONLY_ODD) {
187 return base[offset];; 212 return 0xFF;
213 }
214 offset /= 2;
215 }
216 return base[offset];
188 } 217 }
189 } 218 }
190 if ((!(chunk->flags & MMAP_READ) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->read_8) { 219 if ((!(chunk->flags & MMAP_READ) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->read_8) {
191 return chunk->read_8(offset, context); 220 return chunk->read_8(offset, context);
192 } 221 }
197 { 226 {
198 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); 227 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL);
199 if (!chunk) { 228 if (!chunk) {
200 return; 229 return;
201 } 230 }
202 uint32_t offset = (address - chunk->start) & chunk->mask; 231 uint32_t offset = address & chunk->mask;
203 if (chunk->flags & MMAP_WRITE) { 232 if (chunk->flags & MMAP_WRITE) {
204 uint8_t *base; 233 uint8_t *base;
205 if (chunk->flags & MMAP_PTR_IDX) { 234 if (chunk->flags & MMAP_PTR_IDX) {
206 base = mem_pointers[chunk->ptr_index]; 235 base = mem_pointers[chunk->ptr_index];
207 } else { 236 } else {
208 base = chunk->buffer; 237 base = chunk->buffer;
209 } 238 }
210 if (base) { 239 if (base) {
211 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { 240 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
212 241 if (address & 1) {
213 if (chunk->flags & MMAP_ONLY_EVEN) { 242 if (chunk->flags & MMAP_ONLY_EVEN) {
214 if (offset & 1) {
215 return; 243 return;
216 } 244 }
217 } else { 245 } else if (chunk->flags & MMAP_ONLY_ODD) {
218 if (!(offset & 1)) { 246 return;
219 return; 247 }
220 } 248 offset /= 2;
221 }
222 offset /= 2;
223
224 } else if (opts->byte_swap || (chunk->flags & MMAP_BYTESWAP)) {
225 offset ^= 1;
226 } 249 }
227 base[offset] = value; 250 base[offset] = value;
228 return;
229 } 251 }
230 } 252 }
231 if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_8) { 253 if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_8) {
232 chunk->write_8(offset, context, value); 254 chunk->write_8(offset, context, value);
233 } 255 }