diff backend.c @ 2134:9caebcfeac72

Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
author Michael Pavone <pavone@retrodev.com>
date Fri, 18 Mar 2022 20:49:07 -0700
parents 0013362c320c
children
line wrap: on
line diff
--- a/backend.c	Thu Mar 17 22:41:42 2022 -0700
+++ b/backend.c	Fri Mar 18 20:49:07 2022 -0700
@@ -96,11 +96,23 @@
 				: memmap[chunk].buffer;
 			if (!base) {
 				if (memmap[chunk].flags & MMAP_AUX_BUFF) {
-					return ((uint8_t *)memmap[chunk].buffer) + (address & memmap[chunk].aux_mask);
+					address &= memmap[chunk].aux_mask;
+					if (memmap[chunk].shift > 0) {
+						address <<= memmap[chunk].shift;
+					} else if (memmap[chunk].shift < 0) {
+						address >>= -memmap[chunk].shift;
+					}
+					return ((uint8_t *)memmap[chunk].buffer) + address;
 				}
 				return NULL;
 			}
-			return base + (address & memmap[chunk].mask);
+			address &= memmap[chunk].mask;
+			if (memmap[chunk].shift > 0) {
+				address <<= memmap[chunk].shift;
+			} else if (memmap[chunk].shift < 0) {
+				address >>= -memmap[chunk].shift;
+			}
+			return base + address;
 		}
 	}
 	return NULL;
@@ -121,11 +133,23 @@
 				: memmap[chunk].buffer;
 			if (!base) {
 				if (memmap[chunk].flags & MMAP_AUX_BUFF) {
-					return ((uint8_t *)memmap[chunk].buffer) + (address & memmap[chunk].aux_mask);
+					address &= memmap[chunk].aux_mask;
+					if (memmap[chunk].shift > 0) {
+						address <<= memmap[chunk].shift;
+					} else if (memmap[chunk].shift < 0) {
+						address >>= -memmap[chunk].shift;
+					}
+					return ((uint8_t *)memmap[chunk].buffer) + address;
 				}
 				return NULL;
 			}
-			return base + (address & memmap[chunk].mask);
+			address &= memmap[chunk].mask;
+			if (memmap[chunk].shift > 0) {
+				address <<= memmap[chunk].shift;
+			} else if (memmap[chunk].shift < 0) {
+				address >>= -memmap[chunk].shift;
+			}
+			return base + address;
 		}
 	}
 	return NULL;
@@ -147,6 +171,11 @@
 		}
 		if (base) {
 			uint16_t val;
+			if (chunk->shift > 0) {
+				offset <<= chunk->shift;
+			} else if (chunk->shift < 0){
+				offset >>= chunk->shift;
+			}
 			if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
 				offset /= 2;
 				val = base[offset];
@@ -182,6 +211,11 @@
 			base = chunk->buffer;
 		}
 		if (base) {
+			if (chunk->shift > 0) {
+				offset <<= chunk->shift;
+			} else if (chunk->shift < 0){
+				offset >>= chunk->shift;
+			}
 			if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
 				offset /= 2;
 				if (chunk->flags & MMAP_ONLY_EVEN) {
@@ -214,6 +248,11 @@
 			base = chunk->buffer;
 		}
 		if (base) {
+			if (chunk->shift > 0) {
+				offset <<= chunk->shift;
+			} else if (chunk->shift < 0){
+				offset >>= chunk->shift;
+			}
 			if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
 				if (address & 1) {
 					if (chunk->flags & MMAP_ONLY_EVEN) {
@@ -250,6 +289,11 @@
 			base = chunk->buffer;
 		}
 		if (base) {
+			if (chunk->shift > 0) {
+				offset <<= chunk->shift;
+			} else if (chunk->shift < 0){
+				offset >>= chunk->shift;
+			}
 			if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
 				if (address & 1) {
 					if (chunk->flags & MMAP_ONLY_EVEN) {