diff options
author | Michael Pavone <pavone@retrodev.com> | 2019-01-28 19:24:04 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2019-01-28 19:24:04 -0800 |
commit | 717c5f6963f57ef01f707f5e6fa7ff6a37ce7240 (patch) | |
tree | da0adeb9e3665bcea0bb5c27e5ac726586dd0de8 /backend.c | |
parent | cc50b0eb09a5115507661092727d803d3d7b58f8 (diff) |
Fix zero flag calculation in CPU DSL
Diffstat (limited to 'backend.c')
-rw-r--r-- | backend.c | 67 |
1 files changed, 67 insertions, 0 deletions
@@ -129,6 +129,73 @@ uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, voi return 0xFFFF; } +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->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) { + if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { + if (address & 1) { + if (chunk->flags & MMAP_ONLY_EVEN) { + return 0xFF; + } + } else if (chunk->flags & MMAP_ONLY_ODD) { + return 0xFF; + } + offset /= 2; + } + 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->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 (address & 1) { + if (chunk->flags & MMAP_ONLY_EVEN) { + return; + } + } else if (chunk->flags & MMAP_ONLY_ODD) { + return; + } + offset /= 2; + } + base[offset] = value; + } + } + 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) { |