From ac523751c5942ee5e167b3dd5de2e1ef1e2af172 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 9 Feb 2019 11:34:31 -0800 Subject: Optimization to memory access in new Z80 core --- z80_util.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'z80_util.c') diff --git a/z80_util.c b/z80_util.c index e1f0855..1ccc40c 100644 --- a/z80_util.c +++ b/z80_util.c @@ -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 @@ z80_context * init_z80_context(z80_options *options) 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; } -- cgit v1.2.3