bugfixes, test_misc2, checkpc options
[picodrive.git] / cpu / Cyclone / OpArith.cpp
index 8280a2b..fe3d40a 100644 (file)
@@ -25,20 +25,21 @@ int OpArith(int op)
 \r
   OpStart(op, sea, tea); Cycles=4;\r
 \r
-  EaCalcReadNoSE((type!=6)?11:-1,0,tea,size,0x003f);\r
+  // imm must be read first\r
   EaCalcReadNoSE(-1,10,sea,size,0);\r
+  EaCalcReadNoSE((type!=6)?11:-1,0,tea,size,0x003f);\r
 \r
   if (size<2) shiftstr=(char *)(size?",asl #16":",asl #24");\r
-  if (size<2) ot("  mov r0,r0,asl %i\n",size?16:24);\r
+  if (size<2) ot("  mov r10,r10,asl #%i\n",size?16:24);\r
 \r
   ot(";@ Do arithmetic:\n");\r
 \r
-  if (type==0) ot("  orr r1,r0,r10%s\n",shiftstr);\r
-  if (type==1) ot("  and r1,r0,r10%s\n",shiftstr);\r
-  if (type==2) ot("  subs r1,r0,r10%s ;@ Defines NZCV\n",shiftstr);\r
-  if (type==3) ot("  adds r1,r0,r10%s ;@ Defines NZCV\n",shiftstr);\r
-  if (type==5) ot("  eor r1,r0,r10%s\n",shiftstr);\r
-  if (type==6) ot("  cmp r0,r10%s ;@ Defines NZCV\n",shiftstr);\r
+  if (type==0) ot("  orr r1,r10,r0%s\n",shiftstr);\r
+  if (type==1) ot("  and r1,r10,r0%s\n",shiftstr);\r
+  if (type==2||type==6)\r
+               ot("  rsbs r1,r10,r0%s ;@ Defines NZCV\n",shiftstr);\r
+  if (type==3) ot("  adds r1,r10,r0%s ;@ Defines NZCV\n",shiftstr);\r
+  if (type==5) ot("  eor r1,r10,r0%s\n",shiftstr);\r
 \r
   if (type<2 || type==5) ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); // 0,1,5\r
 \r
@@ -384,7 +385,7 @@ int OpAbcd(int op)
     ot(";@ Get src/dest EA vals\n");\r
     EaCalc (0,0x000f, sea,0,1);\r
     EaRead (0,    10, sea,0,0x000f,1);\r
-    EaCalcReadNoSE(11,0,dea,0,0x1e00);\r
+    EaCalcReadNoSE(11,0,dea,0,0x0e00);\r
   }\r
   else\r
   {\r
@@ -540,13 +541,11 @@ int OpAritha(int op)
   if(size==2&&(sea<0x10||sea==0x3c)) Cycles+=2;\r
   if(type==1) Cycles=6;\r
 \r
-  // must calculate reg EA first, because of situations like: suba.w (A0)+, A0\r
-  EaCalc (10,0x1e00, dea,2,1);\r
-  EaRead (10,    11, dea,2,0x1e00);\r
-\r
-  EaCalc ( 0,0x003f, sea,size,1);\r
-  EaRead ( 0,     0, sea,size,0x003f,1);\r
+  // to handle suba.w (A0)+, A0 properly, must calc reg EA first\r
+  EaCalcReadNoSE(type!=1?10:-1,11,dea,2,0x0e00);\r
+  EaCalcReadNoSE(-1,0,sea,size,0x003f);\r
 \r
+  if (size<2) ot("  mov r0,r0,asl #%d\n\n",size?16:24);\r
   if (size<2) asr=(char *)(size?",asr #16":",asr #24");\r
 \r
   if (type==0) ot("  sub r11,r11,r0%s\n",asr);\r
@@ -555,7 +554,7 @@ int OpAritha(int op)
   if (type==2) ot("  add r11,r11,r0%s\n",asr);\r
   ot("\n");\r
   \r
-  if (type!=1) EaWrite(10,    11, dea,2,0x0e00,1);\r
+  if (type!=1) EaWrite(10,    11, dea,2,0x0e00);\r
 \r
   OpEnd(sea);\r
 \r
@@ -596,7 +595,7 @@ int OpAddx(int op)
     ot(";@ Get src/dest EA vals\n");\r
     EaCalc (0,0x000f, sea,size,1);\r
     EaRead (0,    11, sea,size,0x000f,1);\r
-    EaCalcReadNoSE(10,0,dea,size,0x1e00);\r
+    EaCalcReadNoSE(10,0,dea,size,0x0e00);\r
   }\r
   else\r
   {\r
@@ -716,11 +715,11 @@ int OpCmpm(int op)
   OpStart(op,sea); Cycles=4;\r
 \r
   ot(";@ Get src operand into r10:\n");\r
-  EaCalc (0,0x1e00, sea,size,1);\r
-  EaRead (0,    10, sea,size,0x000f,1);\r
+  EaCalc (0,0x0007, sea,size,1);\r
+  EaRead (0,    10, sea,size,0x0007,1);\r
 \r
   ot(";@ Get dst operand into r0:\n");\r
-  EaCalcReadNoSE(-1,0,dea,size,0x1e00);\r
+  EaCalcReadNoSE(-1,0,dea,size,0x0e00);\r
 \r
   if (size<2) asl=(char *)(size?",asl #16":",asl #24");\r
 \r