start new makefile, migrate to libpicofe
[picodrive.git] / cpu / Cyclone / OpArith.cpp
index 47ff8b1..c05f5fd 100644 (file)
@@ -8,7 +8,7 @@ int OpArith(int op)
   int type=0,size=0;\r
   int sea=0,tea=0;\r
   int use=0;\r
-  char *shiftstr="";\r
+  const char *shiftstr="";\r
 \r
   // Get source and target EA\r
   type=(op>>9)&7; if (type==4 || type>=7) return 1;\r
@@ -103,7 +103,7 @@ int OpAddq(int op)
 \r
   if (size>0 && (ea&0x38)==0x08) size=2; // addq.w #n,An is also 32-bit\r
 \r
-  EaCalcReadNoSE(10,0,ea,size,0x003f);\r
+  EaCalcReadNoSE(11,0,ea,size,0x003f);\r
 \r
   shift=32-(8<<size);\r
 \r
@@ -131,7 +131,7 @@ int OpAddq(int op)
   if ((ea&0x38)!=0x08) OpGetFlags(type,1);\r
   ot("\n");\r
 \r
-  EaWrite(10,     1, ea,size,0x003f,1);\r
+  EaWrite(11,     1, ea,size,0x003f,1);\r
 \r
   OpEnd(ea);\r
 \r
@@ -144,8 +144,8 @@ int OpArithReg(int op)
 {\r
   int use=0;\r
   int type=0,size=0,dir=0,rea=0,ea=0;\r
-  char *asl="";\r
-  char *strop=0;\r
+  const char *asl="";\r
+  const char *strop=0;\r
 \r
   type=(op>>12)&5;\r
   rea =(op>> 9)&7;\r
@@ -166,9 +166,9 @@ int OpArithReg(int op)
 \r
   OpStart(op,ea); Cycles=4;\r
 \r
-  EaCalcReadNoSE(dir?10:-1,0,ea,size,0x003f);\r
+  EaCalcReadNoSE(dir?11:-1,0,ea,size,0x003f);\r
 \r
-  EaCalcReadNoSE(dir?-1:10,1,rea,size,0x0e00);\r
+  EaCalcReadNoSE(dir?-1:11,1,rea,size,0x0e00);\r
 \r
   ot(";@ Do arithmetic:\n");\r
   if (type==0) strop = "orr";\r
@@ -189,8 +189,8 @@ int OpArithReg(int op)
 \r
   ot(";@ Save result:\n");\r
   if (size<2) ot("  mov r1,r1,asr #%d\n",size?16:24);\r
-  if (dir) EaWrite(10, 1, ea,size,0x003f,0,0);\r
-  else     EaWrite(10, 1,rea,size,0x0e00,0,0);\r
+  if (dir) EaWrite(11, 1, ea,size,0x003f,0,0);\r
+  else     EaWrite(11, 1,rea,size,0x0e00,0,0);\r
 \r
   if(rea==ea) {\r
     if(ea<8) Cycles=(size>=2)?8:4; else Cycles+=(size>=2)?26:14;\r
@@ -234,27 +234,27 @@ int OpMul(int op)
 \r
   EaCalcReadNoSE(-1,0,ea,1,0x003f);\r
 \r
-  EaCalc(10,0x0e00,rea, 2);\r
-  EaRead(10,     2,rea, 2,0x0e00);\r
+  EaCalc(11,0x0e00,rea, 2);\r
+  EaRead(11,     2,rea, 2,0x0e00);\r
 \r
   ot("  movs r1,r0,asl #16\n");\r
 \r
   if (type==0) // div\r
   {\r
     // the manual says C is always cleared, but neither Musashi nor FAME do that\r
-    //ot("  bic r9,r9,#0x20000000 ;@ always clear C\n");\r
+    //ot("  bic r10,r10,#0x20000000 ;@ always clear C\n");\r
     ot("  beq divzero%.4x ;@ division by zero\n",op);\r
     ot("\n");\r
     \r
     if (sign)\r
     {\r
-      ot("  mov r11,#0 ;@ r11 = 1 or 2 if the result is negative\n");\r
+      ot("  mov r12,#0 ;@ r12 = 1 or 2 if the result is negative\n");\r
       ot("  tst r2,r2\n");\r
-      ot("  orrmi r11,r11,#2\n");\r
+      ot("  orrmi r12,r12,#2\n");\r
       ot("  rsbmi r2,r2,#0 ;@ Make r2 positive\n");\r
       ot("\n");\r
       ot("  movs r0,r1,asr #16\n");\r
-      ot("  orrmi r11,r11,#1\n");\r
+      ot("  orrmi r12,r12,#1\n");\r
       ot("  rsbmi r0,r0,#0 ;@ Make r0 positive\n");\r
       ot("\n");\r
       ot(";@ detect the nasty 0x80000000 / -1 situation\n");\r
@@ -292,17 +292,17 @@ int OpMul(int op)
     if (sign)\r
     {\r
       // sign correction\r
-      ot("  and r1,r11,#1\n");\r
-      ot("  teq r1,r11,lsr #1\n");\r
+      ot("  and r1,r12,#1\n");\r
+      ot("  teq r1,r12,lsr #1\n");\r
       ot("  rsbne r3,r3,#0 ;@ negate if quotient is negative\n");\r
-      ot("  tst r11,#2\n");\r
+      ot("  tst r12,#2\n");\r
       ot("  rsbne r2,r2,#0 ;@ negate the remainder if divident was negative\n");\r
       ot("\n");\r
 \r
       // signed overflow check\r
       ot("  mov r1,r3,asl #16\n");\r
       ot("  cmp r3,r1,asr #16 ;@ signed overflow?\n");\r
-      ot("  orrne r9,r9,#0x10000000 ;@ set overflow flag\n");\r
+      ot("  orrne r10,r10,#0x10000000 ;@ set overflow flag\n");\r
       ot("  bne endofop%.4x ;@ overflow!\n",op);\r
       ot("\n");\r
       ot("wrendofop%.4x%s\n",op,ms?"":":");\r
@@ -311,7 +311,7 @@ int OpMul(int op)
     {\r
       // overflow check\r
       ot("  movs r1,r3,lsr #16 ;@ check for overflow condition\n");\r
-      ot("  orrne r9,r9,#0x10000000 ;@ set overflow flag\n");\r
+      ot("  orrne r10,r10,#0x10000000 ;@ set overflow flag\n");\r
       ot("  bne endofop%.4x ;@ overflow!\n",op);\r
       ot("\n");\r
     }\r
@@ -338,7 +338,7 @@ int OpMul(int op)
   }\r
   ot("\n");\r
 \r
-  EaWrite(10,    1,rea, 2,0x0e00,1);\r
+  EaWrite(11,    1,rea, 2,0x0e00,1);\r
 \r
   if (type==0) ot("endofop%.4x%s\n",op,ms?"":":");\r
   OpEnd(ea);\r
@@ -346,7 +346,7 @@ int OpMul(int op)
   if (type==0) // div\r
   {\r
     ot("divzero%.4x%s\n",op,ms?"":":");\r
-    ot("  mov r0,#0x14 ;@ Divide by zero\n");\r
+    ot("  mov r0,#5 ;@ Divide by zero\n");\r
     ot("  bl Exception\n");\r
     Cycles+=38;\r
     OpEnd(ea);\r
@@ -392,19 +392,19 @@ int OpAbcd(int op)
   {\r
     ot(";@ Get src/dest EA vals\n");\r
     EaCalc (0,0x000f, sea,0,1);\r
-    EaRead (0,    10, sea,0,0x000f,1);\r
+    EaRead (0,     6, sea,0,0x000f,1);\r
     EaCalcReadNoSE(11,0,dea,0,0x0e00);\r
   }\r
   else\r
   {\r
     ot(";@ Get src/dest reg vals\n");\r
-    EaCalcReadNoSE(-1,10,sea,0,0x0007);\r
+    EaCalcReadNoSE(-1,6,sea,0,0x0007);\r
     EaCalcReadNoSE(11,0,dea,0,0x0e00);\r
-    ot("  mov r10,r10,asl #24\n");\r
+    ot("  mov r6,r6,asl #24\n");\r
   }\r
   ot("  mov r1,r0,asl #24\n\n");\r
 \r
-  ot("  bic r9,r9,#0xb1000000 ;@ clear all flags except old Z\n");\r
+  ot("  bic r10,r10,#0xb1000000 ;@ clear all flags except old Z\n");\r
 \r
   if (type)\r
   {\r
@@ -412,59 +412,61 @@ int OpAbcd(int op)
     ot("  mov r3,#0x00f00000\n");\r
     ot("  and r2,r3,r1,lsr #4\n");\r
     ot("  tst r0,#0x20000000\n");\r
-    ot("  and r0,r3,r10,lsr #4\n");\r
+    ot("  and r0,r3,r6,lsr #4\n");\r
     ot("  add r0,r0,r2\n");\r
     ot("  addne r0,r0,#0x00100000\n");\r
 //    ot("  tst r0,#0x00800000\n");\r
-//    ot("  orreq r9,r9,#0x01000000 ;@ Undefined V behavior\n");\r
+//    ot("  orreq r10,r10,#0x01000000 ;@ Undefined V behavior\n");\r
     ot("  cmp r0,#0x00900000\n");\r
     ot("  addhi r0,r0,#0x00600000 ;@ Decimal adjust units\n");\r
 \r
     ot("  mov r2,r1,lsr #28\n");\r
     ot("  add r0,r0,r2,lsl #24\n");\r
-    ot("  mov r2,r10,lsr #28\n");\r
+    ot("  mov r2,r6,lsr #28\n");\r
     ot("  add r0,r0,r2,lsl #24\n");\r
     ot("  cmp r0,#0x09900000\n");\r
-    ot("  orrhi r9,r9,#0x20000000 ;@ C\n");\r
+    ot("  orrhi r10,r10,#0x20000000 ;@ C\n");\r
     ot("  subhi r0,r0,#0x0a000000\n");\r
-//    ot("  and r3,r9,r0,lsr #3 ;@ Undefined V behavior part II\n");\r
-//    ot("  orr r9,r9,r3,lsl #4 ;@ V\n");\r
+//    ot("  and r3,r10,r0,lsr #3 ;@ Undefined V behavior part II\n");\r
+//    ot("  orr r10,r10,r3,lsl #4 ;@ V\n");\r
     ot("  movs r0,r0,lsl #4\n");\r
-    ot("  orrmi r9,r9,#0x90000000 ;@ Undefined N+V behavior\n"); // this is what Musashi really does\r
-    ot("  bicne r9,r9,#0x40000000 ;@ Z flag\n");\r
+    ot("  orrmi r10,r10,#0x90000000 ;@ Undefined N+V behavior\n"); // this is what Musashi really does\r
+    ot("  bicne r10,r10,#0x40000000 ;@ Z flag\n");\r
   }\r
   else\r
   {\r
     ot("  ldr r0,[r7,#0x4c] ;@ Get X bit\n");\r
     ot("  mov r3,#0x00f00000\n");\r
-    ot("  and r2,r3,r10,lsr #4\n");\r
+    ot("  and r2,r3,r6,lsr #4\n");\r
     ot("  tst r0,#0x20000000\n");\r
     ot("  and r0,r3,r1,lsr #4\n");\r
     ot("  sub r0,r0,r2\n");\r
     ot("  subne r0,r0,#0x00100000\n");\r
 //    ot("  tst r0,#0x00800000\n");\r
-//    ot("  orreq r9,r9,#0x01000000 ;@ Undefined V behavior\n");\r
+//    ot("  orreq r10,r10,#0x01000000 ;@ Undefined V behavior\n");\r
     ot("  cmp r0,#0x00900000\n");\r
     ot("  subhi r0,r0,#0x00600000 ;@ Decimal adjust units\n");\r
 \r
     ot("  mov r2,r1,lsr #28\n");\r
     ot("  add r0,r0,r2,lsl #24\n");\r
-    ot("  mov r2,r10,lsr #28\n");\r
+    ot("  mov r2,r6,lsr #28\n");\r
     ot("  sub r0,r0,r2,lsl #24\n");\r
     ot("  cmp r0,#0x09900000\n");\r
-    ot("  orrhi r9,r9,#0xa0000000 ;@ N and C\n");\r
+    ot("  orrhi r10,r10,#0xa0000000 ;@ N and C\n");\r
     ot("  addhi r0,r0,#0x0a000000\n");\r
-//    ot("  and r3,r9,r0,lsr #3 ;@ Undefined V behavior part II\n");\r
-//    ot("  orr r9,r9,r3,lsl #4 ;@ V\n");\r
+//    ot("  and r3,r10,r0,lsr #3 ;@ Undefined V behavior part II\n");\r
+//    ot("  orr r10,r10,r3,lsl #4 ;@ V\n");\r
     ot("  movs r0,r0,lsl #4\n");\r
-//    ot("  orrmi r9,r9,#0x80000000 ;@ Undefined N behavior\n");\r
-    ot("  bicne r9,r9,#0x40000000 ;@ Z flag\n");\r
+//    ot("  orrmi r10,r10,#0x80000000 ;@ Undefined N behavior\n");\r
+    ot("  bicne r10,r10,#0x40000000 ;@ Z flag\n");\r
   }\r
 \r
-  ot("  str r9,[r7,#0x4c] ;@ Save X bit\n");\r
+  ot("  str r10,[r7,#0x4c] ;@ Save X bit\n");\r
   ot("\n");\r
 \r
   EaWrite(11,     0, dea,0,0x0e00,1);\r
+\r
+  ot("  ldr r6,[r7,#0x54]\n");\r
   OpEnd(sea,dea);\r
 \r
   return 0;\r
@@ -486,11 +488,11 @@ int OpNbcd(int op)
   OpStart(op,ea); Cycles=6;\r
   if(ea >= 8)  Cycles+=2;\r
 \r
-  EaCalcReadNoSE(10,0,ea,0,0x003f);\r
+  EaCalcReadNoSE(6,0,ea,0,0x003f);\r
 \r
   // this is rewrite of Musashi's code\r
   ot("  ldr r2,[r7,#0x4c]\n");\r
-  ot("  bic r9,r9,#0xb0000000 ;@ clear all flags, except Z\n");\r
+  ot("  bic r10,r10,#0xb0000000 ;@ clear all flags, except Z\n");\r
   ot("  mov r0,r0,asl #24\n");\r
   ot("  and r2,r2,#0x20000000\n");\r
   ot("  add r2,r0,r2,lsr #5 ;@ add X\n");\r
@@ -507,19 +509,20 @@ int OpNbcd(int op)
   ot("  addeq r11,r11,#0x10000000\n");\r
   ot("  and r3,r3,r11,lsr #31 ;@ Undefined V behavior part II\n",op);\r
   ot("  movs r1,r11,asr #24\n");\r
-  ot("  bicne r9,r9,#0x40000000 ;@ Z\n");\r
-  ot("  orr r9,r9,r3,lsl #28 ;@ save V\n",op);\r
-  ot("  orr r9,r9,#0x20000000 ;@ C\n");\r
+  ot("  bicne r10,r10,#0x40000000 ;@ Z\n");\r
+  ot("  orr r10,r10,r3,lsl #28 ;@ save V\n",op);\r
+  ot("  orr r10,r10,#0x20000000 ;@ C\n");\r
   ot("\n");\r
 \r
-  EaWrite(10,     1, ea,0,0x3f,0,0);\r
+  EaWrite(6, 1, ea,0,0x3f,0,0);\r
 \r
   ot("finish%.4x%s\n",op,ms?"":":");\r
   ot("  tst r11,r11\n");\r
-  ot("  orrmi r9,r9,#0x80000000 ;@ N\n");\r
-  ot("  str r9,[r7,#0x4c] ;@ Save X\n");\r
+  ot("  orrmi r10,r10,#0x80000000 ;@ N\n");\r
+  ot("  str r10,[r7,#0x4c] ;@ Save X\n");\r
   ot("\n");\r
 \r
+  ot("  ldr r6,[r7,#0x54]\n");\r
   OpEnd(ea);\r
 \r
   return 0;\r
@@ -531,7 +534,7 @@ int OpAritha(int op)
 {\r
   int use=0;\r
   int type=0,size=0,sea=0,dea=0;\r
-  char *asr="";\r
+  const char *asr="";\r
 \r
   // Suba/Cmpa/Adda/(invalid):\r
   type=(op>>13)&3; if (type>=3) return 1;\r
@@ -553,28 +556,29 @@ int OpAritha(int op)
 \r
   // EA calculation order defines how situations like  suba.w (A0)+, A0 get handled.\r
   // different emus act differently in this situation, I couldn't fugure which is right behaviour.\r
-  // This is Musashi's behaviour.\r
-  if (type == 1)\r
+  //if (type == 1)\r
   {\r
     EaCalcReadNoSE(-1,0,sea,size,0x003f);\r
-    EaCalcReadNoSE(type!=1?10:-1,11,dea,2,0x0e00);\r
+    EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00);\r
   }\r
+#if 0\r
   else\r
   {\r
-    EaCalcReadNoSE(type!=1?10:-1,11,dea,2,0x0e00);\r
+    EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00);\r
     EaCalcReadNoSE(-1,0,sea,size,0x003f);\r
   }\r
+#endif\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
-  if (type==1) ot("  cmp r11,r0%s ;@ Defines NZCV\n",asr);\r
+  if (type==0) ot("  sub r1,r1,r0%s\n",asr);\r
+  if (type==1) ot("  cmp r1,r0%s ;@ Defines NZCV\n",asr);\r
   if (type==1) OpGetFlags(1,0); // Get Cmp flags\r
-  if (type==2) ot("  add r11,r11,r0%s\n",asr);\r
+  if (type==2) ot("  add r1,r1,r0%s\n",asr);\r
   ot("\n");\r
-  \r
-  if (type!=1) EaWrite(10,    11, dea,2,0x0e00);\r
+\r
+  if (type!=1) EaWrite(11, 1, dea,2,0x0e00);\r
 \r
   OpEnd(sea);\r
 \r
@@ -587,7 +591,7 @@ int OpAddx(int op)
 {\r
   int use=0;\r
   int type=0,size=0,dea=0,sea=0,mem=0;\r
-  char *asl="";\r
+  const char *asl="";\r
 \r
   type=(op>>14)&1;\r
   dea =(op>> 9)&7;\r
@@ -599,7 +603,7 @@ int OpAddx(int op)
   if (EaCanRead(sea,size)==0) return 1;\r
   if (EaCanWrite(dea)==0) return 1;\r
 \r
-  if(mem) { sea+=0x20; dea+=0x20; }\r
+  if (mem) { sea+=0x20; dea+=0x20; }\r
 \r
   use=op&~0x0e07; // Use same opcode for Dn\r
   if (size==0&&sea==0x27) use|=0x0007; // ___x.b -(a7)\r
@@ -614,15 +618,15 @@ int OpAddx(int op)
   {\r
     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,0x0e00);\r
+    EaRead (0,     6, sea,size,0x000f,1);\r
+    EaCalcReadNoSE(11,0,dea,size,0x0e00);\r
   }\r
   else\r
   {\r
     ot(";@ Get src/dest reg vals\n");\r
-    EaCalcReadNoSE(-1,11,sea,size,0x0007);\r
-    EaCalcReadNoSE(10,0,dea,size,0x0e00);\r
-    if (size<2) ot("  mov r11,r11,asl #%d\n\n",size?16:24);\r
+    EaCalcReadNoSE(-1,6,sea,size,0x0007);\r
+    EaCalcReadNoSE(11,0,dea,size,0x0e00);\r
+    if (size<2) ot("  mov r6,r6,asl #%d\n\n",size?16:24);\r
   }\r
 \r
   if (size<2) asl=(char *)(size?",asl #16":",asl #24");\r
@@ -634,24 +638,25 @@ int OpAddx(int op)
   {\r
     ot(";@ Make sure the carry bit will tip the balance:\n");\r
     ot("  mvn r2,#0\n");\r
-    ot("  orr r11,r11,r2,lsr #%i\n",(size==0)?8:16);\r
+    ot("  orr r6,r6,r2,lsr #%i\n",(size==0)?8:16);\r
     ot("\n");\r
   }\r
 \r
-  if (type==0) ot("  rscs r1,r11,r0%s\n",asl);\r
-  if (type==1) ot("  adcs r1,r11,r0%s\n",asl);\r
-  ot("  orr r3,r9,#0xb0000000 ;@ for old Z\n");\r
+  if (type==0) ot("  rscs r1,r6,r0%s\n",asl);\r
+  if (type==1) ot("  adcs r1,r6,r0%s\n",asl);\r
+  ot("  orr r3,r10,#0xb0000000 ;@ for old Z\n");\r
   OpGetFlags(type==0,1,0); // subtract\r
   if (size<2) {\r
     ot("  movs r2,r1,lsr #%i\n", size?16:24);\r
-    ot("  orreq r9,r9,#0x40000000 ;@ add potentially missed Z\n");\r
+    ot("  orreq r10,r10,#0x40000000 ;@ add potentially missed Z\n");\r
   }\r
-  ot("  andeq r9,r9,r3 ;@ fix Z\n");\r
+  ot("  andeq r10,r10,r3 ;@ fix Z\n");\r
   ot("\n");\r
 \r
   ot(";@ Save result:\n");\r
-  EaWrite(10, 1, dea,size,0x0e00,1);\r
+  EaWrite(11, 1, dea,size,0x0e00,1);\r
 \r
+  ot("  ldr r6,[r7,#0x54]\n");\r
   OpEnd(sea,dea);\r
 \r
   return 0;\r
@@ -663,7 +668,7 @@ int OpCmpEor(int op)
 {\r
   int rea=0,eor=0;\r
   int size=0,ea=0,use=0;\r
-  char *asl="";\r
+  const char *asl="";\r
 \r
   // Get EA and register EA\r
   rea=(op>>9)&7;\r
@@ -690,8 +695,8 @@ int OpCmpEor(int op)
     if(size>=2)  Cycles+=2;\r
   }\r
 \r
-  ot(";@ Get EA into r10 and value into r0:\n");\r
-  EaCalcReadNoSE(eor?10:-1,0,ea,size,0x003f);\r
+  ot(";@ Get EA into r11 and value into r0:\n");\r
+  EaCalcReadNoSE(eor?11:-1,0,ea,size,0x003f);\r
 \r
   ot(";@ Get register operand into r1:\n");\r
   EaCalcReadNoSE(-1,1,rea,size,0x0e00);\r
@@ -710,7 +715,7 @@ int OpCmpEor(int op)
   OpGetFlags(eor==0,0); // Cmp like subtract\r
   ot("\n");\r
 \r
-  if (eor) EaWrite(10, 1,ea,size,0x003f,1);\r
+  if (eor) EaWrite(11, 1,ea,size,0x003f,1);\r
 \r
   OpEnd(ea);\r
   return 0;\r
@@ -720,7 +725,7 @@ int OpCmpEor(int op)
 int OpCmpm(int op)\r
 {\r
   int size=0,sea=0,dea=0,use=0;\r
-  char *asl="";\r
+  const char *asl="";\r
 \r
   // get size, get EAs\r
   size=(op>>6)&3; if (size>=3) return 1;\r
@@ -734,16 +739,16 @@ int OpCmpm(int op)
 \r
   OpStart(op,sea); Cycles=4;\r
 \r
-  ot(";@ Get src operand into r10:\n");\r
+  ot(";@ Get src operand into r11:\n");\r
   EaCalc (0,0x0007, sea,size,1);\r
-  EaRead (0,    10, sea,size,0x0007,1);\r
+  EaRead (0,    11, sea,size,0x0007,1);\r
 \r
   ot(";@ Get dst operand into r0:\n");\r
   EaCalcReadNoSE(-1,0,dea,size,0x0e00);\r
 \r
   if (size<2) asl=(char *)(size?",asl #16":",asl #24");\r
 \r
-  ot("  rsbs r0,r10,r0%s\n",asl);\r
+  ot("  rsbs r0,r11,r0%s\n",asl);\r
   OpGetFlags(1,0); // Cmp like subtract\r
   ot("\n");\r
 \r
@@ -777,7 +782,7 @@ int OpChk(int op)
 \r
   OpStart(op,ea); Cycles=10;\r
 \r
-  ot(";@ Get EA into r10 and value into r0:\n");\r
+  ot(";@ Get value into r0:\n");\r
   EaCalcReadNoSE(-1,0,ea,size,0x003f);\r
 \r
   ot(";@ Get register operand into r1:\n");\r
@@ -787,7 +792,7 @@ int OpChk(int op)
   if (size<2) ot("  mov r1,r1,asl #%d\n\n",size?16:24);\r
 \r
   ot(";@ get flags, including undocumented ones\n");\r
-  ot("  and r3,r9,#0x80000000\n");\r
+  ot("  and r3,r10,#0x80000000\n");\r
   ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
   OpGetFlags(0,0);\r
 \r
@@ -795,16 +800,16 @@ int OpChk(int op)
   ot("  bmi chktrap%.4x\n",op);\r
 \r
   ot(";@ Do arithmetic:\n");\r
-  ot("  bic r9,r9,#0x80000000 ;@ N\n");\r
+  ot("  bic r10,r10,#0x80000000 ;@ N\n");\r
   ot("  cmp r1,r0\n");\r
   ot("  bgt chktrap%.4x\n",op);\r
 \r
   ot(";@ old N remains\n");\r
-  ot("  orr r9,r9,r3\n");\r
+  ot("  orr r10,r10,r3\n");\r
   OpEnd(ea);\r
 \r
   ot("chktrap%.4x%s ;@ CHK exception:\n",op,ms?"":":");\r
-  ot("  mov r0,#0x18\n");\r
+  ot("  mov r0,#6\n");\r
   ot("  bl Exception\n");\r
   Cycles+=40;\r
   OpEnd(ea);\r