Mercurial > repos > blastem
comparison backend.c @ 1506:ded16f3d7eb4 mame_interp
Super hacky integration of the version of Musashi from MAME
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 27 Dec 2017 13:46:52 -0800 |
parents | 92e7dafcc0dc |
children | 2455662378ed |
comparison
equal
deleted
inserted
replaced
1471:2e6320d261ff | 1506:ded16f3d7eb4 |
---|---|
127 return chunk->read_16(offset, context); | 127 return chunk->read_16(offset, context); |
128 } | 128 } |
129 return 0xFFFF; | 129 return 0xFFFF; |
130 } | 130 } |
131 | 131 |
132 void write_word(uint32_t address, uint16_t value, void **mem_pointers, cpu_options *opts, void *context) | |
133 { | |
134 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); | |
135 if (!chunk) { | |
136 return; | |
137 } | |
138 uint32_t offset = (address - chunk->start) & chunk->mask; | |
139 if (chunk->flags & MMAP_WRITE) { | |
140 uint8_t *base; | |
141 if (chunk->flags & MMAP_PTR_IDX) { | |
142 base = mem_pointers[chunk->ptr_index]; | |
143 } else { | |
144 base = chunk->buffer; | |
145 } | |
146 if (base) { | |
147 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { | |
148 offset /= 2; | |
149 if (chunk->flags & MMAP_ONLY_EVEN) { | |
150 value >>= 16; | |
151 } | |
152 base[offset] = value; | |
153 } else { | |
154 *(uint16_t *)(base + offset) = value; | |
155 } | |
156 return; | |
157 } | |
158 } | |
159 if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_16) { | |
160 chunk->write_16(offset, context, value); | |
161 } | |
162 } | |
163 | |
164 uint8_t read_byte(uint32_t address, void **mem_pointers, cpu_options *opts, void *context) | |
165 { | |
166 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); | |
167 if (!chunk) { | |
168 return 0xFF; | |
169 } | |
170 uint32_t offset = (address - chunk->start) & chunk->mask; | |
171 if (chunk->flags & MMAP_READ) { | |
172 uint8_t *base; | |
173 if (chunk->flags & MMAP_PTR_IDX) { | |
174 base = mem_pointers[chunk->ptr_index]; | |
175 } else { | |
176 base = chunk->buffer; | |
177 } | |
178 if (base) { | |
179 uint16_t val; | |
180 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { | |
181 offset /= 2; | |
182 } else if (opts->byte_swap || (chunk->flags & MMAP_BYTESWAP)) { | |
183 offset ^= 1; | |
184 } | |
185 return base[offset];; | |
186 } | |
187 } | |
188 if ((!(chunk->flags & MMAP_READ) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->read_8) { | |
189 return chunk->read_8(offset, context); | |
190 } | |
191 return 0xFF; | |
192 } | |
193 | |
194 void write_byte(uint32_t address, uint8_t value, void **mem_pointers, cpu_options *opts, void *context) | |
195 { | |
196 memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); | |
197 if (!chunk) { | |
198 return; | |
199 } | |
200 uint32_t offset = (address - chunk->start) & chunk->mask; | |
201 if (chunk->flags & MMAP_WRITE) { | |
202 uint8_t *base; | |
203 if (chunk->flags & MMAP_PTR_IDX) { | |
204 base = mem_pointers[chunk->ptr_index]; | |
205 } else { | |
206 base = chunk->buffer; | |
207 } | |
208 if (base) { | |
209 if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { | |
210 | |
211 if (chunk->flags & MMAP_ONLY_EVEN) { | |
212 if (offset & 1) { | |
213 return; | |
214 } | |
215 } else { | |
216 if (!(offset & 1)) { | |
217 return; | |
218 } | |
219 } | |
220 offset /= 2; | |
221 | |
222 } else if (opts->byte_swap || (chunk->flags & MMAP_BYTESWAP)) { | |
223 offset ^= 1; | |
224 } | |
225 base[offset] = value; | |
226 return; | |
227 } | |
228 } | |
229 if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_8) { | |
230 chunk->write_8(offset, context, value); | |
231 } | |
232 } | |
233 | |
132 uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk) | 234 uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk) |
133 { | 235 { |
134 if (chunk->mask == opts->address_mask) { | 236 if (chunk->mask == opts->address_mask) { |
135 return chunk->end - chunk->start; | 237 return chunk->end - chunk->start; |
136 } else { | 238 } else { |