NOT setting upper bits on PUSH PC, minor adjustments
[picodrive.git] / cpu / Cyclone / Main.cpp
index fce0c3d..5647fb1 100644 (file)
@@ -102,9 +102,10 @@ static void PrintException(int ints)
   ot("no_sp_swap%i%s\n",ints,ms?"":":");\r
 \r
   ot("  ldr r10,[r7,#0x60] ;@ Get Memory base\n");\r
-  ot("  mov r1,r4,lsl #8\n");\r
-  ot("  sub r1,r1,r10,lsl #8 ;@ r1 = Old PC\n");\r
-  ot("  mov r1,r1,asr #8 ;@ push sign extended\n");\r
+//  ot("  mov r1,r4,lsl #8\n");\r
+//  ot("  sub r1,r1,r10,lsl #8 ;@ r1 = Old PC\n");\r
+//  ot("  mov r1,r1,asr #8 ;@ push sign extended\n");\r
+  ot("  sub r1,r4,r10 ;@ r1 = Old PC\n");\r
   OpPush32();\r
   OpPushSr(1);\r
   ot("  mov r0,r11\n");\r
@@ -277,6 +278,7 @@ static void PrintFramework()
     ot("  bx lr\n");\r
     ot("\n");\r
 #endif\r
+  // 68k: XNZVC, ARM: NZCV\r
   if (ms) ot("CycloneSetSr\n");\r
   else    ot("CycloneSetSr:\n");\r
   ot("  mov r2,r1,lsr #8\n");\r
@@ -291,8 +293,8 @@ static void PrintFramework()
   ot("  str r3,[r0,#0x3C]\n");\r
   ot("  str r2,[r0,#0x48]\n");\r
   ot("setsr_noswap%s\n",ms?"":":");\r
-  ot("  mov r2,r1,lsr #3\n");\r
-  ot("  strb r2,[r0,#0x45] ;@ the X flag\n");\r
+  ot("  mov r2,r1,lsl #25\n");\r
+  ot("  str r2,[r0,#0x4c] ;@ the X flag\n");\r
   ot("  bic r2,r1,#0xf3\n");\r
   ot("  tst r1,#1\n");\r
   ot("  orrne r2,r2,#2\n");\r
@@ -310,8 +312,8 @@ static void PrintFramework()
   ot("  orrne r2,r2,#2\n");\r
   ot("  tst r1,#2\n");\r
   ot("  orrne r2,r2,#1\n");\r
-  ot("  ldrb r1,[r0,#0x45] ;@ the X flag\n");\r
-  ot("  tst r1,#2\n");\r
+  ot("  ldr r1,[r0,#0x4c] ;@ the X flag\n");\r
+  ot("  tst r1,#0x20000000\n");\r
   ot("  orrne r2,r2,#0x10\n");\r
   ot("  ldrb r1,[r0,#0x44] ;@ the SR high\n");\r
   ot("  orr r0,r2,r1,lsl #8\n");\r
@@ -418,8 +420,12 @@ int MemHandler(int type,int size,int addrreg)
   addrreg=0;\r
 #endif\r
   if (addrreg != 0)\r
+  {\r
+    ot("  add lr,pc,#4\n"); // helps to prevent interlocks\r
     ot("  mov r0,r%i\n", addrreg);\r
-  ot("  mov lr,pc\n");\r
+  }\r
+  else\r
+    ot("  mov lr,pc\n");\r
   ot("  ldr pc,[r7,#0x%x] ;@ Call ",func);\r
 \r
   // Document what we are calling:\r
@@ -473,6 +479,7 @@ static void PrintOpcodes()
   ot("  mov r0,#0x10\n");\r
   ot("  bl Exception\n");\r
 #endif\r
+  ot("\n");\r
   Cycles=34;\r
   OpEnd();\r
 \r
@@ -499,6 +506,7 @@ static void PrintOpcodes()
   ot("  mov r0,#0x28\n");\r
   ot("  bl Exception\n");\r
 #endif\r
+  ot("\n");\r
   Cycles=4;\r
   OpEnd();\r
 \r
@@ -524,6 +532,7 @@ static void PrintOpcodes()
   ot("  mov r0,#0x2c\n");\r
   ot("  bl Exception\n");\r
 #endif\r
+  ot("\n");\r
   Cycles=4;\r
   OpEnd();\r
 \r
@@ -626,12 +635,11 @@ static void PrintJumpTable()
     }\r
     if(ip&1) ott("0x%.4x", 0, "\n",0,ip++,1);\r
     if(ip&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
-    ot("\n");\r
     if(ip&7) {\r
       for(i = 8-(ip&7); i > 0; i--)\r
         ot(",0x0000");\r
-      ot("\n");\r
     }\r
+    ot("\n");\r
     if(ms) {\r
       for(i = (0x2000-ip/2)/8+1; i > 0; i--)\r
         ot("  dcd 0,0,0,0,0,0,0,0\n");\r
@@ -679,7 +687,7 @@ static int CycloneMake()
   ot("\n;@ Dave's Cyclone 68000 Emulator v%x.%.3x - Assembler Output\n\n",CycloneVer>>12,CycloneVer&0xfff);\r
 \r
   ot(";@ (c) Copyright 2003 Dave, All rights reserved.\n");\r
-  ot(";@ some code (c) Copyright 2005-2006 notaz, All rights reserved.\n");\r
+  ot(";@ some code (c) Copyright 2005-2007 notaz, All rights reserved.\n");\r
   ot(";@ Cyclone 68000 is free for non-commercial use.\n\n");\r
   ot(";@ For commercial use, separate licencing terms must be obtained.\n\n");\r
 \r