diff backend.c @ 744:fc68992cf18d

Merge windows branch with latest changes
author Michael Pavone <pavone@retrodev.com>
date Thu, 28 May 2015 21:19:55 -0700
parents fc04781f4d28
children 329ff62ea391
line wrap: on
line diff
--- a/backend.c	Thu May 28 21:09:33 2015 -0700
+++ b/backend.c	Thu May 28 21:19:55 2015 -0700
@@ -51,3 +51,49 @@
 	}
 }
 
+void * get_native_pointer(uint32_t address, void ** mem_pointers, cpu_options * opts)
+{
+	memmap_chunk const * memmap = opts->memmap;
+	address &= opts->address_mask;
+	for (uint32_t chunk = 0; chunk < opts->memmap_chunks; chunk++)
+	{
+		if (address >= memmap[chunk].start && address < memmap[chunk].end) {
+			if (!(memmap[chunk].flags & MMAP_READ)) {
+				return NULL;
+			}
+			uint8_t * base = memmap[chunk].flags & MMAP_PTR_IDX
+				? mem_pointers[memmap[chunk].ptr_index]
+				: memmap[chunk].buffer;
+			if (!base) {
+				return NULL;
+			}
+			return base + (address & memmap[chunk].mask);
+		}
+	}
+	return NULL;
+}
+
+uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk)
+{
+	if (chunk->mask == opts->address_mask) {
+		return chunk->end - chunk->start;
+	} else {
+		return chunk->mask + 1;
+	}
+}
+
+uint32_t ram_size(cpu_options *opts)
+{
+	uint32_t size = 0;
+	for (int i = 0; i < opts->memmap_chunks; i++)
+	{
+		if ((opts->memmap[i].flags & (MMAP_WRITE | MMAP_CODE)) == (MMAP_WRITE | MMAP_CODE)) {
+			if (opts->memmap[i].mask == opts->address_mask) {
+				size += opts->memmap[i].end - opts->memmap[i].start;
+			} else {
+				size += opts->memmap[i].mask + 1;
+			}
+		}
+	}
+	return size;
+}