Mercurial > repos > blastem
diff 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 |
line wrap: on
line diff
--- a/backend.c Thu Oct 19 03:21:24 2017 -0700 +++ b/backend.c Wed Dec 27 13:46:52 2017 -0800 @@ -129,6 +129,108 @@ return 0xFFFF; } +void write_word(uint32_t address, uint16_t value, void **mem_pointers, cpu_options *opts, void *context) +{ + memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); + if (!chunk) { + return; + } + uint32_t offset = (address - chunk->start) & chunk->mask; + if (chunk->flags & MMAP_WRITE) { + uint8_t *base; + if (chunk->flags & MMAP_PTR_IDX) { + base = mem_pointers[chunk->ptr_index]; + } else { + base = chunk->buffer; + } + if (base) { + if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { + offset /= 2; + if (chunk->flags & MMAP_ONLY_EVEN) { + value >>= 16; + } + base[offset] = value; + } else { + *(uint16_t *)(base + offset) = value; + } + return; + } + } + if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_16) { + chunk->write_16(offset, context, value); + } +} + +uint8_t read_byte(uint32_t address, void **mem_pointers, cpu_options *opts, void *context) +{ + memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); + if (!chunk) { + return 0xFF; + } + uint32_t offset = (address - chunk->start) & chunk->mask; + if (chunk->flags & MMAP_READ) { + uint8_t *base; + if (chunk->flags & MMAP_PTR_IDX) { + base = mem_pointers[chunk->ptr_index]; + } else { + base = chunk->buffer; + } + if (base) { + uint16_t val; + if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { + offset /= 2; + } else if (opts->byte_swap || (chunk->flags & MMAP_BYTESWAP)) { + offset ^= 1; + } + return base[offset];; + } + } + if ((!(chunk->flags & MMAP_READ) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->read_8) { + return chunk->read_8(offset, context); + } + return 0xFF; +} + +void write_byte(uint32_t address, uint8_t value, void **mem_pointers, cpu_options *opts, void *context) +{ + memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); + if (!chunk) { + return; + } + uint32_t offset = (address - chunk->start) & chunk->mask; + if (chunk->flags & MMAP_WRITE) { + uint8_t *base; + if (chunk->flags & MMAP_PTR_IDX) { + base = mem_pointers[chunk->ptr_index]; + } else { + base = chunk->buffer; + } + if (base) { + if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { + + if (chunk->flags & MMAP_ONLY_EVEN) { + if (offset & 1) { + return; + } + } else { + if (!(offset & 1)) { + return; + } + } + offset /= 2; + + } else if (opts->byte_swap || (chunk->flags & MMAP_BYTESWAP)) { + offset ^= 1; + } + base[offset] = value; + return; + } + } + if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_8) { + chunk->write_8(offset, context, value); + } +} + uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk) { if (chunk->mask == opts->address_mask) {