final src and Makefile adjustments for PSP release
[picodrive.git] / cpu / Cyclone / OpLogic.cpp
index 7623704..94b0017 100644 (file)
@@ -143,16 +143,8 @@ int OpNeg(int op)
   use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
-  OpStart(op,ea);   Cycles=size<2?4:6;\r
-  if(ea >= 0x10) {\r
-    Cycles*=2;\r
-#if CYCLONE_FOR_GENESIS\r
-    // This is same as in Starscream core, CLR uses only 6 cycles for memory EAs.\r
-    // May be this is similar case as with TAS opcode, but this time the dummy\r
-    // read is ignored somehow? Without this hack Fatal Rewind hangs even in Gens.\r
-    if(type==1&&size<2) Cycles-=2;\r
-#endif\r
-  }\r
+  OpStart(op,ea); Cycles=size<2?4:6;\r
+  if(ea >= 0x10)  Cycles*=2;\r
 \r
   EaCalc (10,0x003f,ea,size,0,0);\r
 \r
@@ -207,6 +199,7 @@ int OpNeg(int op)
     ot("\n");\r
   }\r
 \r
+  if (type==1) eawrite_check_addrerr=1;\r
   EaWrite(10,     1,ea,size,0x003f,0,0);\r
 \r
   OpEnd(ea);\r
@@ -307,7 +300,7 @@ int OpExt(int op)
 int OpSet(int op)\r
 {\r
   int cc=0,ea=0;\r
-  int size=0,use=0;\r
+  int size=0,use=0,changed_cycles=0;\r
   char *cond[16]=\r
   {\r
     "al","", "hi","ls","cc","cs","ne","eq",\r
@@ -325,7 +318,8 @@ int OpSet(int op)
   use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
-  OpStart(op,ea); Cycles=8;\r
+  changed_cycles=ea<8 && cc>=2;\r
+  OpStart(op,ea,0,changed_cycles); Cycles=8;\r
   if (ea<8) Cycles=4;\r
 \r
   if (cc)\r
@@ -359,10 +353,12 @@ int OpSet(int op)
 \r
   ot("\n");\r
 \r
+  eawrite_check_addrerr=1;\r
   EaCalc (0,0x003f, ea,size,0,0);\r
   EaWrite(0,     1, ea,size,0x003f,0,0);\r
 \r
-  OpEnd(ea);\r
+  opend_op_changes_cycles=changed_cycles;\r
+  OpEnd(ea,0);\r
   return 0;\r
 }\r
 \r
@@ -403,7 +399,7 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
       ot("\n");\r
     }\r
 \r
-    if (type==0 && dir) ot("  mov r3,r0 ;@ save old value for V flag calculation\n");\r
+    if (type==0 && dir) ot("  adds r3,r0,#0 ;@ save old value for V flag calculation, also clear V\n");\r
 \r
     ot(";@ Shift register:\n");\r
     if (type==0) ot("  movs r0,r0,%s %s\n",dir?"asl":"asr",pct);\r
@@ -434,7 +430,8 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
       ot("  mov r1,#0x80000000\n");\r
       ot("  ands r3,r3,r1,asr %s\n", pct);\r
       ot("  cmpne r3,r1,asr %s\n", pct);\r
-      ot("  biceq r9,r9,#0x10000000\n");\r
+      ot("  eoreq r1,r0,r3\n"); // above check doesn't catch (-1)<<(32+), so we need this\r
+      ot("  tsteq r1,#0x80000000\n");\r
       ot("  orrne r9,r9,#0x10000000\n");\r
       ot("\n");\r
     }\r
@@ -585,7 +582,6 @@ int OpAsr(int op)
   int count=0,dir=0;\r
   int size=0,usereg=0,type=0;\r
 \r
-  ea=0;\r
   count =(op>>9)&7;\r
   dir   =(op>>8)&1;\r
   size  =(op>>6)&3;\r
@@ -604,7 +600,7 @@ int OpAsr(int op)
 \r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
-  OpStart(op); Cycles=size<2?6:8;\r
+  OpStart(op,ea,0,count<0); Cycles=size<2?6:8;\r
 \r
   EaCalc(10,0x0007, ea,size,1);\r
   EaRead(10,     0, ea,size,0x0007,1);\r
@@ -613,7 +609,8 @@ int OpAsr(int op)
 \r
   EaWrite(10,    0, ea,size,0x0007,1);\r
 \r
-  OpEnd();\r
+  opend_op_changes_cycles = (count<0);\r
+  OpEnd(ea,0);\r
 \r
   return 0;\r
 }\r