Mercurial > repos > blastem
diff z80_util.c @ 1750:01236179fc71
Optimization to memory access in new Z80 core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 09 Feb 2019 11:34:31 -0800 |
parents | 48a43dff4dc0 |
children | d6d4c006a7b3 |
line wrap: on
line diff
--- a/z80_util.c Fri Feb 08 23:09:58 2019 -0800 +++ b/z80_util.c Sat Feb 09 11:34:31 2019 -0800 @@ -3,13 +3,23 @@ void z80_read_8(z80_context *context) { context->cycles += 3 * context->opts->gen.clock_divider; - context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context); + uint8_t *fast = context->fastmem[context->scratch1 >> 10]; + if (fast) { + context->scratch1 = fast[context->scratch1 & 0x3FF]; + } else { + context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context); + } } void z80_write_8(z80_context *context) { context->cycles += 3 * context->opts->gen.clock_divider; - write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context); + uint8_t *fast = context->fastmem[context->scratch2 >> 10]; + if (fast) { + fast[context->scratch2 & 0x3FF] = context->scratch1; + } else { + write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context); + } } void z80_io_read8(z80_context *context) @@ -69,6 +79,16 @@ context->io_map = (memmap_chunk *)tmp_io_chunks; context->io_chunks = tmp_num_io_chunks; context->io_mask = tmp_io_mask; + for(uint32_t address = 0; address < 0x10000; address+=1024) + { + uint8_t *start = get_native_pointer(address, NULL, &options->gen); + if (start) { + uint8_t *end = get_native_pointer(address + 1023, NULL, &options->gen); + if (end && end - start == 1023) { + context->fastmem[address >> 10] = start; + } + } + } return context; }