fixed some portability issues
[picodrive.git] / cpu / fame / famec.c
index 6b147b2..19657fc 100644 (file)
@@ -4,7 +4,7 @@
 /* Autor: Oscar Orallo Pelaez                                               */\r
 /* Fecha de comienzo: 03-10-2006                                            */\r
 /* Ultima actualizacion: 08-10-2006                                         */\r
-/* Based on the excellent FAMEC emulator by Stèphane Dallongueville          */\r
+/* Based on the excellent C68K emulator by Stèphane Dallongueville          */\r
 /****************************************************************************/\r
 \r
 #include <stdio.h>\r
@@ -20,7 +20,7 @@
 #define FAMEC_CHECK_BRANCHES\r
 #define FAMEC_EXTRA_INLINE\r
 // #define FAMEC_DEBUG\r
-//#define FAMEC_NO_GOTOS\r
+#define FAMEC_NO_GOTOS\r
 #define FAMEC_ADR_BITS  24\r
 // #define FAMEC_FETCHBITS 8\r
 #define FAMEC_DATABITS  8\r
@@ -33,7 +33,9 @@
 \r
 \r
 #undef INLINE\r
-#ifndef INLINE\r
+#ifdef _MSC_VER\r
+#define INLINE\r
+#else\r
 #define INLINE __inline__\r
 #endif\r
 \r
@@ -280,11 +282,18 @@ typedef signed int        s32;
        ((u32)PC - BasePC)\r
 \r
 \r
+#ifdef FAMEC_CHECK_BRANCHES\r
+#define FORCE_ALIGNMENT(pc)\r
+#else\r
+#define FORCE_ALIGNMENT(pc) pc&=~1;\r
+#endif\r
+\r
 #ifndef FAMEC_32BIT_PC\r
 \r
 #define SET_PC(A)               \\r
 { \\r
     u32 pc = A; \\r
+    FORCE_ALIGNMENT(pc); \\r
     BasePC = m68kcontext.Fetch[(pc >> M68K_FETCHSFT) & M68K_FETCHMASK];    \\r
     PC = (u16*)((pc & M68K_ADR_MASK) + BasePC);        \\r
 }\r
@@ -294,6 +303,7 @@ typedef signed int  s32;
 #define SET_PC(A)               \\r
 { \\r
     u32 pc = A; \\r
+    FORCE_ALIGNMENT(pc); \\r
     BasePC = m68kcontext.Fetch[(pc >> M68K_FETCHSFT) & M68K_FETCHMASK];    \\r
     BasePC -= pc & 0xFF000000;    \\r
     PC = (u16*)(pc + BasePC); \\r
@@ -734,7 +744,9 @@ static FAMEC_EXTRA_INLINE u32 execute_exception(s32 vect, u32 oldPC, u32 oldSR)
 #ifndef FAMEC_32BIT_PC\r
        newPC&=M68K_ADR_MASK\r
 #endif\r
+#ifdef FAMEC_CHECK_BRANCHES\r
        newPC&=~1; // don't crash on games with bad vector tables\r
+#endif\r
 \r
        // SET_PC(newPC)\r
 \r
@@ -904,9 +916,10 @@ famec_Exec:
 #endif\r
                if (cycles_needed != 0)\r
                {\r
+                       u32 line;\r
                        m68kcontext.io_cycle_counter = cycles_needed;\r
                        cycles_needed = 0;\r
-                       s32 line=interrupt_chk__();\r
+                       line=interrupt_chk__();\r
                        if (line>0)\r
                        {\r
                                if (m68kcontext.iack_handler != NULL)\r
@@ -948,6 +961,7 @@ famec_End:
 #ifdef PICODRIVE_HACK\r
 dualcore_mode:\r
 \r
+       while (1)\r
        {\r
                extern int SekCycleAim, SekCycleCnt, SekCycleAimS68k, SekCycleCntS68k;\r
                #define PS_STEP_M68K ((488<<16)/20) // ~24\r
@@ -989,7 +1003,6 @@ dualcore_mode:
                        }\r
                        cycles = m68kcontext.io_cycle_counter = 0;\r
                }\r
-               goto dualcore_mode;\r
        }\r
 #endif\r
 \r