about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--config.h3
-rw-r--r--emulator.c12
2 files changed, 9 insertions, 6 deletions
diff --git a/config.h b/config.h
index 38d0ce7..19677a0 100644
--- a/config.h
+++ b/config.h
@@ -2,6 +2,7 @@
 #define _CONFIG_H_
 
 #define DEBUG 1
+#define COSMAC_VIP_COMPATIBILITY 1 //if set to != 0 it will change the emulator to work with Cosmac VIP era's games
 //#define STOP_ON_INFINITE_LOOP
 
 #define SCREEN_WIDTH 852
@@ -17,5 +18,7 @@
 
 #define dbgprintf(fmt, ...) \
      do { if(DEBUG) fprintf (stdout, fmt, ##__VA_ARGS__); } while(0)
+#define COSMAC_VIP(code) \
+     do { if(COSMAC_VIP_COMPATIBILITY) code else ; } while(0);
 
 #endif
diff --git a/emulator.c b/emulator.c
index 8fed056..466a9f2 100644
--- a/emulator.c
+++ b/emulator.c
@@ -248,8 +248,8 @@ int emulator_tick(Emulator* emulator)
                     emulator->regs.V[X] -= emulator->regs.V[Y];    
                     break;
                 case 0x6:
-                    emulator->regs.V[X] = emulator->regs.V[X] >> 1;
-                    emulator->regs.VF = N == 0x1 ? 1 : 0;
+                    emulator->regs.VF = emulator->regs.V[X] & 0x1;
+                    emulator->regs.V[X] >>= 1;
                     break;
                 case 0x7:
                     if(emulator->regs.V[Y] > emulator->regs.V[X])
@@ -259,8 +259,8 @@ int emulator_tick(Emulator* emulator)
                     emulator->regs.V[X] = emulator->regs.V[Y] - emulator->regs.V[X];
                     break;
                 case 0xE:
-                    emulator->regs.V[X] = emulator->regs.V[X] << 1;
-                    emulator->regs.VF = first_nibble == 0x1 ? 1 : 0;
+                    emulator->regs.VF = emulator->regs.V[X] >> 7;
+                    emulator->regs.V[X] <<= 1;
                     break;
             default:
                 printf("DEFAULT: Instr: 0x%x\n", instr);
@@ -342,12 +342,12 @@ int emulator_tick(Emulator* emulator)
             case 0x55: //FX55
                 for (int i = 0; i <= X; ++i)
                     emulator->memory[emulator->regs.I + i] = emulator->regs.V[i];
-                emulator->regs.I += X + 1;
+                COSMAC_VIP(emulator->regs.I += X + 1;)
                 break;
             case 0x65: //FX65
                 for (int i = 0; i <= X; ++i)
                     emulator->regs.V[i] = emulator->memory[emulator->regs.I + i];
-                emulator->regs.I += X + 1;
+                COSMAC_VIP(emulator->regs.I += X + 1;)
                 break;
             case 0x15: //FX15
                 dbgprintf("SET THE DELAY TIMER TO V[X]!\n");