diff mame_z80/z80.c @ 1508:2e57910fd641 mame_interp

More efficient memory access when using MAME interpreters
author Michael Pavone <pavone@retrodev.com>
date Sun, 31 Dec 2017 10:03:25 -0800
parents 2455662378ed
children 63256371046f
line wrap: on
line diff
--- a/mame_z80/z80.c	Sat Dec 30 18:27:06 2017 -0800
+++ b/mame_z80/z80.c	Sun Dec 31 10:03:25 2017 -0800
@@ -450,6 +450,10 @@
  ***************************************************************/
 static inline uint8_t rm(z80_device *z80, uint16_t addr)
 {
+	uint16_t index = addr >> 13;
+	if (z80->read_pointers[index]) {
+		return z80->read_pointers[index][addr & 0x1FFF];
+	}
 	return read_byte(addr, (void **)z80->mem_pointers, &z80->options->gen, z80);
 }
 
@@ -467,6 +471,11 @@
  ***************************************************************/
 static inline void wm(z80_device *z80, uint16_t addr, uint8_t value)
 {
+	uint16_t index = addr >> 13;
+	if (z80->write_pointers[index]) {
+		z80->write_pointers[index][addr & 0x1FFF] = value;
+		return;
+	}
 	write_byte(addr, value, (void **)z80->mem_pointers, &z80->options->gen, z80);
 }
 
@@ -3439,6 +3448,26 @@
 	z80->m_cc_xycb = cc_xycb;
 	z80->m_cc_ex = cc_ex;
 	
+	for (uint32_t address = 0; address < (64*1024); address += 8*1024)
+	{
+		z80->read_pointers[address >> 13] = NULL;
+		z80->write_pointers[address >> 13] = NULL;
+		memmap_chunk const *chunk = find_map_chunk(address, &z80->options->gen, 0, NULL);
+		if (!chunk || chunk->end < (address + 8*1024) || (chunk->flags & MMAP_PTR_IDX) || !chunk->buffer) {
+			continue;
+		}
+		void *ptr = get_native_pointer(address, (void **)z80->mem_pointers, &z80->options->gen);
+		if (!ptr) {
+			continue;
+		}
+		if (chunk->flags & MMAP_READ) {
+			z80->read_pointers[address >> 13] = ptr;
+		}
+		if (chunk->flags & MMAP_WRITE) {
+			z80->write_pointers[address >> 13] = ptr;
+		}
+	}
+	
 	return z80;
 }