comparison 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
comparison
equal deleted inserted replaced
1749:e4fe5a450d05 1750:01236179fc71
1 #include <string.h> 1 #include <string.h>
2 2
3 void z80_read_8(z80_context *context) 3 void z80_read_8(z80_context *context)
4 { 4 {
5 context->cycles += 3 * context->opts->gen.clock_divider; 5 context->cycles += 3 * context->opts->gen.clock_divider;
6 context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context); 6 uint8_t *fast = context->fastmem[context->scratch1 >> 10];
7 if (fast) {
8 context->scratch1 = fast[context->scratch1 & 0x3FF];
9 } else {
10 context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context);
11 }
7 } 12 }
8 13
9 void z80_write_8(z80_context *context) 14 void z80_write_8(z80_context *context)
10 { 15 {
11 context->cycles += 3 * context->opts->gen.clock_divider; 16 context->cycles += 3 * context->opts->gen.clock_divider;
12 write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context); 17 uint8_t *fast = context->fastmem[context->scratch2 >> 10];
18 if (fast) {
19 fast[context->scratch2 & 0x3FF] = context->scratch1;
20 } else {
21 write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context);
22 }
13 } 23 }
14 24
15 void z80_io_read8(z80_context *context) 25 void z80_io_read8(z80_context *context)
16 { 26 {
17 uint32_t tmp_mask = context->opts->gen.address_mask; 27 uint32_t tmp_mask = context->opts->gen.address_mask;
67 z80_context *context = calloc(1, sizeof(z80_context)); 77 z80_context *context = calloc(1, sizeof(z80_context));
68 context->opts = options; 78 context->opts = options;
69 context->io_map = (memmap_chunk *)tmp_io_chunks; 79 context->io_map = (memmap_chunk *)tmp_io_chunks;
70 context->io_chunks = tmp_num_io_chunks; 80 context->io_chunks = tmp_num_io_chunks;
71 context->io_mask = tmp_io_mask; 81 context->io_mask = tmp_io_mask;
82 for(uint32_t address = 0; address < 0x10000; address+=1024)
83 {
84 uint8_t *start = get_native_pointer(address, NULL, &options->gen);
85 if (start) {
86 uint8_t *end = get_native_pointer(address + 1023, NULL, &options->gen);
87 if (end && end - start == 1023) {
88 context->fastmem[address >> 10] = start;
89 }
90 }
91 }
72 return context; 92 return context;
73 } 93 }
74 94