updated Cyclone not to use r9
[picodrive.git] / cpu / Cyclone / OpMove.cpp
index f0a8ecc..ac2abea 100644 (file)
@@ -7,7 +7,7 @@
 void OpFlagsToReg(int high)\r
 {\r
   ot("  ldr r0,[r7,#0x4c]   ;@ X bit\n");\r
-  ot("  mov r1,r9,lsr #28   ;@ ____NZCV\n");\r
+  ot("  mov r1,r10,lsr #28  ;@ ____NZCV\n");\r
   ot("  eor r2,r1,r1,ror #1 ;@ Bit 0=C^V\n");\r
   ot("  tst r2,#1           ;@ 1 if C!=V\n");\r
   ot("  eorne r1,r1,#3      ;@ ____NZVC\n");\r
@@ -28,7 +28,7 @@ void OpRegToFlags(int high, int srh_reg)
   ot("  tst r1,#1           ;@ 1 if C!=V\n");\r
   ot("  eorne r0,r0,#3      ;@ ___XNZCV\n");\r
   ot("  str r2,[r7,#0x4c]   ;@ Store X bit\n");\r
-  ot("  mov r9,r0,lsl #28   ;@ r9=NZCV...\n");\r
+  ot("  mov r10,r0,lsl #28  ;@ r10=NZCV...\n");\r
 \r
   if (high)\r
   {\r
@@ -126,7 +126,7 @@ int OpMove(int op)
   if (movea==0)\r
   {\r
     ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
-    ot("  mrs r9,cpsr ;@ r9=NZCV flags\n");\r
+    ot("  mrs r10,cpsr ;@ r10=NZCV flags\n");\r
     ot("\n");\r
   }\r
 \r
@@ -135,11 +135,11 @@ int OpMove(int op)
   eawrite_check_addrerr=1;\r
 #if SPLIT_MOVEL_PD\r
   if ((tea&0x38)==0x20 && size==2) { // -(An)\r
-    EaCalc (10,0x0e00,tea,size,0,0);\r
+    EaCalc (8,0x0e00,tea,size,0,0);\r
     ot("  mov r11,r1\n");\r
-    ot("  add r0,r10,#2\n");\r
+    ot("  add r0,r8,#2\n");\r
     EaWrite(0,     1,tea,1,0x0e00,0,0);\r
-    EaWrite(10,   11,tea,1,0x0e00,1);\r
+    EaWrite(8,    11,tea,1,0x0e00,1);\r
   }\r
   else\r
 #endif\r
@@ -276,7 +276,7 @@ int OpArithSr(int op)
 \r
   // note: old srh is already in r11 (done by OpStart)\r
   if (type==0) {\r
-    ot("  orr r9,r9,r0,lsl #28\n");\r
+    ot("  orr r10,r10,r0,lsl #28\n");\r
     ot("  orr r2,r2,r0,lsl #25 ;@ X bit\n");\r
     if (size!=0) {\r
       ot("  orr r1,r11,r0,lsr #8\n");\r
@@ -284,13 +284,13 @@ int OpArithSr(int op)
     }\r
   }\r
   if (type==1) {\r
-    ot("  and r9,r9,r0,lsl #28\n");\r
+    ot("  and r10,r10,r0,lsl #28\n");\r
     ot("  and r2,r2,r0,lsl #25 ;@ X bit\n");\r
     if (size!=0)\r
       ot("  and r1,r11,r0,lsr #8\n");\r
   }\r
   if (type==5) {\r
-    ot("  eor r9,r9,r0,lsl #28\n");\r
+    ot("  eor r10,r10,r0,lsl #28\n");\r
     ot("  eor r2,r2,r0,lsl #25 ;@ X bit\n");\r
     if (size!=0) {\r
       ot("  eor r1,r11,r0,lsr #8\n");\r
@@ -333,10 +333,10 @@ int OpPea(int op)
 \r
   OpStart(op,ea);\r
 \r
-  ot("  ldr r10,[r7,#0x3c]\n");\r
+  ot("  ldr r11,[r7,#0x3c]\n");\r
   EaCalc (1,0x003f, ea,0);\r
   ot("\n");\r
-  ot("  sub r0,r10,#4 ;@ Predecrement A7\n");\r
+  ot("  sub r0,r11,#4 ;@ Predecrement A7\n");\r
   ot("  str r0,[r7,#0x3c] ;@ Save A7\n");\r
   ot("\n");\r
   MemHandler(1,2); // Write 32-bit\r
@@ -376,11 +376,18 @@ int OpMovem(int op)
 \r
   OpStart(op,ea,0,1);\r
 \r
+#if !MEMHANDLERS_NEED_PREV_PC\r
+  // must save PC, need a spare register\r
+  ot("  str r4,[r7,#0x40] ;@ Save PC\n");\r
+#endif\r
+#if !MEMHANDLERS_NEED_CYCLES\r
+  ot("  str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
+#endif\r
   ot("  ldrh r11,[r4],#2 ;@ r11=register mask\n");\r
 \r
-  ot(";@ r10=Register Index*4:\n");\r
-  if (decr) ot("  mov r10,#0x40 ;@ order reversed for -(An)\n");\r
-  else      ot("  mov r10,#-4\n");\r
+  ot(";@ r4=Register Index*4:\n");\r
+  if (decr) ot("  mov r4,#0x40 ;@ order reversed for -(An)\n");\r
+  else      ot("  mov r4,#-4\n");\r
   \r
   ot("\n");\r
   ot(";@ Get the address into r6:\n");\r
@@ -399,7 +406,7 @@ int OpMovem(int op)
 \r
   ot("\n");\r
   ot("Movemloop%.4x%s\n",op, ms?"":":");\r
-  ot("  add r10,r10,#%d ;@ r10=Next Register\n",decr?-4:4);\r
+  ot("  add r4,r4,#%d ;@ r4=Next Register\n",decr?-4:4);\r
   ot("  movs r11,r11,lsr #1\n");\r
   ot("  bcc Movemloop%.4x\n",op);\r
   ot("\n");\r
@@ -411,17 +418,17 @@ int OpMovem(int op)
     ot("  ;@ Copy memory to register:\n",1<<size);\r
     earead_check_addrerr=0; // already checked\r
     EaRead (6,0,ea,size,0x003f);\r
-    ot("  str r0,[r7,r10] ;@ Save value into Dn/An\n");\r
+    ot("  str r0,[r7,r4] ;@ Save value into Dn/An\n");\r
   }\r
   else\r
   {\r
     ot("  ;@ Copy register to memory:\n",1<<size);\r
-    ot("  ldr r1,[r7,r10] ;@ Load value from Dn/An\n");\r
+    ot("  ldr r1,[r7,r4] ;@ Load value from Dn/An\n");\r
 #if SPLIT_MOVEL_PD\r
     if (decr && size==2) { // -(An)\r
       ot("  add r0,r6,#2\n");\r
       EaWrite(0,1,ea,1,0x003f,0,0);\r
-      ot("  ldr r1,[r7,r10] ;@ Load value from Dn/An\n");\r
+      ot("  ldr r1,[r7,r4] ;@ Load value from Dn/An\n");\r
       ot("  mov r0,r6\n");\r
       EaWrite(0,1,ea,1,0x003f,1);\r
     }\r
@@ -447,7 +454,8 @@ int OpMovem(int op)
   }\r
 \r
   ot("NoRegs%.4x%s\n",op, ms?"":":");\r
-  ot("  ldr r6,=CycloneJumpTab ;@ restore Opcode Jump table\n");\r
+  ot("  ldr r4,[r7,#0x40]\n");\r
+  ot("  ldr r6,[r7,#0x54] ;@ restore Opcode Jump table\n");\r
   ot("\n");\r
 \r
   if(dir) { // er\r
@@ -462,7 +470,6 @@ int OpMovem(int op)
 \r
   opend_op_changes_cycles = 1;\r
   OpEnd(ea);\r
-  ltorg();\r
   ot("\n");\r
 \r
   return 0;\r
@@ -514,7 +521,7 @@ int OpMoveq(int op)
   ot("  movs r0,r8,asl #24\n");\r
   ot("  and r1,r8,#0x0e00\n");\r
   ot("  mov r0,r0,asr #24 ;@ Sign extended Quick value\n");\r
-  ot("  mrs r9,cpsr ;@ r9=NZ flags\n");\r
+  ot("  mrs r10,cpsr ;@ r10=NZ flags\n");\r
   ot("  str r0,[r7,r1,lsr #7] ;@ Store into Dn\n");\r
   ot("\n");\r
 \r
@@ -541,15 +548,15 @@ int OpExg(int op)
 \r
   OpStart(op); Cycles=6;\r
 \r
-  ot("  and r10,r8,#0x0e00 ;@ Find T register\n");\r
-  ot("  and r11,r8,#0x000f ;@ Find S register\n");\r
-  if (type==0x48) ot("  orr r10,r10,#0x1000 ;@ T is an address register\n");\r
+  ot("  and r2,r8,#0x0e00 ;@ Find T register\n");\r
+  ot("  and r3,r8,#0x000f ;@ Find S register\n");\r
+  if (type==0x48) ot("  orr r2,r2,#0x1000 ;@ T is an address register\n");\r
   ot("\n");\r
-  ot("  ldr r0,[r7,r10,lsr #7] ;@ Get T\n");\r
-  ot("  ldr r1,[r7,r11,lsl #2] ;@ Get S\n");\r
+  ot("  ldr r0,[r7,r2,lsr #7] ;@ Get T\n");\r
+  ot("  ldr r1,[r7,r3,lsl #2] ;@ Get S\n");\r
   ot("\n");\r
-  ot("  str r0,[r7,r11,lsl #2] ;@ T->S\n");\r
-  ot("  str r1,[r7,r10,lsr #7] ;@ S->T\n");  \r
+  ot("  str r0,[r7,r3,lsl #2] ;@ T->S\n");\r
+  ot("  str r1,[r7,r2,lsr #7] ;@ S->T\n");  \r
   ot("\n");\r
 \r
   OpEnd();\r
@@ -578,44 +585,48 @@ int OpMovep(int op)
 \r
   OpStart(op,ea);\r
   \r
-  if(dir) { // reg to mem\r
+  if(dir) // reg to mem\r
+  {\r
     EaCalcReadNoSE(-1,11,rea,size,0x0e00);\r
 \r
-    EaCalc(10,0x000f,ea,size);\r
+    EaCalc(8,0x000f,ea,size);\r
     if(size==2) { // if operand is long\r
       ot("  mov r1,r11,lsr #24 ;@ first byte\n");\r
-      EaWrite(10,1,ea,0,0x000f); // store first byte\r
-      ot("  add r0,r10,#%i\n",(aadd+=2));\r
+      EaWrite(8,1,ea,0,0x000f); // store first byte\r
+      ot("  add r0,r8,#%i\n",(aadd+=2));\r
       ot("  mov r1,r11,lsr #16 ;@ second byte\n");\r
       EaWrite(0,1,ea,0,0x000f); // store second byte\r
-      ot("  add r0,r10,#%i\n",(aadd+=2));\r
+      ot("  add r0,r8,#%i\n",(aadd+=2));\r
     } else {\r
-      ot("  mov r0,r10\n");\r
+      ot("  mov r0,r8\n");\r
     }\r
     ot("  mov r1,r11,lsr #8 ;@ first or third byte\n");\r
     EaWrite(0,1,ea,0,0x000f);\r
-    ot("  add r0,r10,#%i\n",(aadd+=2));\r
+    ot("  add r0,r8,#%i\n",(aadd+=2));\r
     ot("  and r1,r11,#0xff\n");\r
     EaWrite(0,1,ea,0,0x000f);\r
-  } else { // mem to reg\r
-    EaCalc(10,0x000f,ea,size,1);\r
-    EaRead(10,11,ea,0,0x000f,1); // read first byte\r
-    ot("  add r0,r10,#2\n");\r
+  }\r
+  else // mem to reg\r
+  {\r
+    EaCalc(6,0x000f,ea,size,1);\r
+    EaRead(6,11,ea,0,0x000f,1); // read first byte\r
+    ot("  add r0,r6,#2\n");\r
     EaRead(0,1,ea,0,0x000f,1); // read second byte\r
     if(size==2) { // if operand is long\r
       ot("  orr r11,r11,r1,lsr #8 ;@ second byte\n");\r
-      ot("  add r0,r10,#4\n");\r
+      ot("  add r0,r6,#4\n");\r
       EaRead(0,1,ea,0,0x000f,1);\r
       ot("  orr r11,r11,r1,lsr #16 ;@ third byte\n");\r
-      ot("  add r0,r10,#6\n");\r
+      ot("  add r0,r6,#6\n");\r
       EaRead(0,1,ea,0,0x000f,1);\r
       ot("  orr r1,r11,r1,lsr #24 ;@ fourth byte\n");\r
     } else {\r
       ot("  orr r1,r11,r1,lsr #8 ;@ second byte\n");\r
     }\r
     // store the result\r
-    EaCalc(11,0x0e00,rea,size,1);      // reg number -> r11\r
-    EaWrite(11,1,rea,size,0x0e00,1);\r
+    EaCalc(0,0x0e00,rea,size,1);\r
+    EaWrite(0,1,rea,size,0x0e00,1);\r
+    ot("  ldr r6,[r7,#0x54]\n");\r
   }\r
 \r
   Cycles=(size==2)?24:16;\r
@@ -653,17 +664,17 @@ int OpStopReset(int op)
     Cycles = 132;\r
 #if USE_RESET_CALLBACK\r
     ot("  str r4,[r7,#0x40] ;@ Save PC\n");\r
-    ot("  mov r1,r9,lsr #28\n");\r
+    ot("  mov r1,r10,lsr #28\n");\r
     ot("  strb r1,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
     ot("  str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
     ot("  ldr r11,[r7,#0x90] ;@ ResetCallback\n");\r
     ot("  tst r11,r11\n");\r
     ot("  movne lr,pc\n");\r
     ot("  bxne r11 ;@ call ResetCallback if it is defined\n");\r
-    ot("  ldrb r9,[r7,#0x46] ;@ r9 = Load Flags (NZCV)\n");\r
+    ot("  ldrb r10,[r7,#0x46] ;@ r10 = Load Flags (NZCV)\n");\r
     ot("  ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
     ot("  ldr r4,[r7,#0x40] ;@ Load PC\n");\r
-    ot("  mov r9,r9,lsl #28\n");\r
+    ot("  mov r10,r10,lsl #28\n");\r
     ot("\n");\r
 #endif\r
   }\r