From 717c5f6963f57ef01f707f5e6fa7ff6a37ce7240 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 28 Jan 2019 19:24:04 -0800 Subject: Fix zero flag calculation in CPU DSL --- backend.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'backend.c') diff --git a/backend.c b/backend.c index 400b6d8..e8bea75 100644 --- a/backend.c +++ b/backend.c @@ -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) { -- cgit v1.2.3