From: Dan White <dan@whiteaudio.com>
Date: Sun, 1 Feb 2015 20:07:54 +0000 (-0600)
Subject: fix dirMemory access, the array index must be unsigned
X-Git-Tag: cheetah~4
X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=408bca6c2247bd806debfd0626cc32969dbc9d63;p=430.git

fix dirMemory access, the array index must be unsigned
---

diff --git a/msp4th/Makefile b/msp4th/Makefile
index 2ec2a13..40c63a1 100644
--- a/msp4th/Makefile
+++ b/msp4th/Makefile
@@ -70,7 +70,7 @@ OBJECTS = $(SOURCES:.c=.o)
 ASSEMBLYS = $(SOURCES:.c=.lst)
 
 #all: $(TARGET).elf $(TARGET).hex $(TARGET).txt 
-all: $(TARGET).elf $(TARGET).hex $(TARGET).xout $(ASSEMBLYS)
+all: $(TARGET).elf $(TARGET).hex $(TARGET).xout $(ASSEMBLYS) _pc4th
 
 #we .include this, so it doesn't make it to the auto-generated dependencies
 main.o: flashboot.s
diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c
index 4bb3f31..22d4e6f 100644
--- a/msp4th/msp4th.c
+++ b/msp4th/msp4th.c
@@ -1247,14 +1247,14 @@ void execVM(int16_t opcode)
 
         case 41: // @  ( addr -- val ) \ read directly from memory address
             i = TOS >> 1;
-            TOS = dirMemory[i];
+            TOS = dirMemory[(uint16_t)i];
             break;
 
         case 42: // !  ( val addr -- ) \ write directly to memory address words only!
             i = popMathStack();  //  address to write to
             i = i >> 1;
             j = popMathStack();  //  value to write
-            dirMemory[i] = j;
+            dirMemory[(uint16_t)i] = j;
             break;
 
         case 43: // h@  ( -- prog ) \ get end of program code space
@@ -1408,7 +1408,7 @@ GCC_DIAG_ON(int-to-pointer-cast);
         case 66: // +!  ( n addr -- ) \ *addr += n
             i = popMathStack();
             j = popMathStack();
-            dirMemory[i] += j;
+            dirMemory[(uint16_t)i] += j;
             break;
 
         case 67: // roll  ( n -- ) \ nth stack removed and placed on top
diff --git a/msp4th/tests.4th b/msp4th/tests.4th
index b1f84b9..f3e4ac2 100644
--- a/msp4th/tests.4th
+++ b/msp4th/tests.4th
@@ -206,10 +206,9 @@ test-pwrd bar
 
 \    case 41: // @  ( addr -- val ) \ read directly from memory address
 \    case 42: // !  ( val addr -- ) \ write directly to memory address words only!
-\ NOTE: Not working on PC version, fake dirMemory array needs debugging.
-\ 42 0xff00 !
-\ 0xff00 @
-\ 42 cmp
+42 0xff00 !
+0xff00 @
+42 cmp
 
 \    case 43: // h@  ( -- progIdx ) \ get end of program code space
 \ no test