NOT setting upper bits on PUSH PC, minor adjustments
[picodrive.git] / cpu / Cyclone / Main.cpp
index 2f92c5c..5647fb1 100644 (file)
@@ -3,12 +3,14 @@
 \r
 static FILE *AsmFile=NULL;\r
 \r
-static int CycloneVer=0x0086; // Version number of library\r
+static int CycloneVer=0x0087; // Version number of library\r
 int *CyJump=NULL; // Jump table\r
 int ms=USE_MS_SYNTAX; // If non-zero, output in Microsoft ARMASM format\r
 char *Narm[4]={ "b", "h","",""}; // Normal ARM Extensions for operand sizes 0,1,2\r
 char *Sarm[4]={"sb","sh","",""}; // Sign-extend ARM Extensions for operand sizes 0,1,2\r
 int Cycles; // Current cycles for opcode\r
+int pc_dirty; // something changed PC during processing\r
+static int arm_op_count;\r
 \r
 \r
 void ot(const char *format, ...)\r
@@ -21,6 +23,9 @@ void ot(const char *format, ...)
   for(i=0, len=strlen(format); i < len && format[i] != '\n'; i++);\r
   if(i < len-1 && format[len-1] != '\n') printf("\nWARNING: possible improper newline placement:\n%s\n", format);\r
 \r
+  if (format[0] == ' ' && format[1] == ' ' && format[2] != ' ' && format[2] != '.')\r
+    arm_op_count++;\r
+\r
   va_start(valist,format);\r
   if (AsmFile) vfprintf(AsmFile,format,valist);\r
   va_end(valist);\r
@@ -32,6 +37,51 @@ void ltorg()
   else    ot("  .ltorg\n");\r
 }\r
 \r
+#if (CYCLONE_FOR_GENESIS == 2)\r
+// r12=ptr to tas in table, trashes r0,r1\r
+static void ChangeTAS(int norm)\r
+{\r
+  ot("  ldr r0,=Op4ad0%s\n",norm?"_":"");\r
+  ot("  mov r1,#8\n");\r
+  ot("setrtas_loop%i0%s ;@ 4ad0-4ad7\n",norm,ms?"":":");\r
+  ot("  subs r1,r1,#1\n");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  bne setrtas_loop%i0\n",norm);\r
+  ot("  ldr r0,=Op4ad8%s\n",norm?"_":"");\r
+  ot("  mov r1,#7\n");\r
+  ot("setrtas_loop%i1%s ;@ 4ad8-4ade\n",norm,ms?"":":");\r
+  ot("  subs r1,r1,#1\n");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  bne setrtas_loop%i1\n",norm);\r
+  ot("  ldr r0,=Op4adf%s\n",norm?"_":"");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  ldr r0,=Op4ae0%s\n",norm?"_":"");\r
+  ot("  mov r1,#7\n");\r
+  ot("setrtas_loop%i2%s ;@ 4ae0-4ae6\n",norm,ms?"":":");\r
+  ot("  subs r1,r1,#1\n");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  bne setrtas_loop%i2\n",norm);\r
+  ot("  ldr r0,=Op4ae7%s\n",norm?"_":"");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  ldr r0,=Op4ae8%s\n",norm?"_":"");\r
+  ot("  mov r1,#8\n");\r
+  ot("setrtas_loop%i3%s ;@ 4ae8-4aef\n",norm,ms?"":":");\r
+  ot("  subs r1,r1,#1\n");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  bne setrtas_loop%i3\n",norm);\r
+  ot("  ldr r0,=Op4af0%s\n",norm?"_":"");\r
+  ot("  mov r1,#8\n");\r
+  ot("setrtas_loop%i4%s ;@ 4af0-4af7\n",norm,ms?"":":");\r
+  ot("  subs r1,r1,#1\n");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  bne setrtas_loop%i4\n",norm);\r
+  ot("  ldr r0,=Op4af8%s\n",norm?"_":"");\r
+  ot("  str r0,[r12],#4\n");\r
+  ot("  ldr r0,=Op4af9%s\n",norm?"_":"");\r
+  ot("  str r0,[r12],#4\n");\r
+}\r
+#endif\r
+\r
 // trashes all temp regs\r
 static void PrintException(int ints)\r
 {\r
@@ -52,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
@@ -86,18 +137,26 @@ static void PrintException(int ints)
 void CheckInterrupt(int op)\r
 {\r
   ot(";@ CheckInterrupt:\n");\r
-  ot("  ldr r0,[r7,#0x44]\n"); // same as  ldrb r0,[r7,#0x47]\r
-  ot("  movs r0,r0,lsr #24 ;@ Get IRQ level (loading word is faster)\n");\r
+  ot("  ldr r1,[r7,#0x44] ;@ Get SR high T_S__III and irq level\n");\r
+  ot("  movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as  ldrb r0,[r7,#0x47]\r
   ot("  beq NoInts%x\n",op);\r
   ot("  cmp r0,#6 ;@ irq>6 ?\n");\r
-  ot("  ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III\n");\r
   ot("  andle r1,r1,#7 ;@ Get interrupt mask\n");\r
   ot("  cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n");\r
-  ot("  blgt DoInterrupt\n");\r
+  ot("  blgt CycloneDoInterrupt\n");\r
   ot("NoInts%x%s\n", op,ms?"":":");\r
   ot("\n");\r
 }\r
 \r
+void FlushPC(void)\r
+{\r
+#if MEMHANDLERS_NEED_PC\r
+  if (pc_dirty)\r
+    ot("  str r4,[r7,#0x40] ;@ Save PC\n");\r
+#endif\r
+  pc_dirty = 0;\r
+}\r
+\r
 static void PrintFramework()\r
 {\r
   ot(";@ --------------------------- Framework --------------------------\n");\r
@@ -109,22 +168,21 @@ static void PrintFramework()
   ot("  mov r7,r0          ;@ r7 = Pointer to Cpu Context\n");\r
   ot("                     ;@ r0-3 = Temporary registers\n");\r
   ot("  ldrb r9,[r7,#0x46] ;@ r9 = Flags (NZCV)\n");\r
-  ot("  ldr r6,=JumpTab    ;@ r6 = Opcode Jump table\n");\r
+  ot("  ldr r6,=CycloneJumpTab ;@ r6 = Opcode Jump table\n");\r
   ot("  ldr r5,[r7,#0x5c]  ;@ r5 = Cycles\n");\r
   ot("  ldr r4,[r7,#0x40]  ;@ r4 = Current PC + Memory Base\n");\r
   ot("                     ;@ r8 = Current Opcode\n");\r
-  ot("  ldr r0,[r7,#0x44]\n");\r
+  ot("  ldr r1,[r7,#0x44]  ;@ Get SR high T_S__III and irq level\n");\r
   ot("  mov r9,r9,lsl #28  ;@ r9 = Flags 0xf0000000, cpsr format\n");\r
   ot("                     ;@ r10 = Source value / Memory Base\n");\r
   ot("\n");\r
   ot(";@ CheckInterrupt:\n");\r
-  ot("  movs r0,r0,lsr #24 ;@ Get IRQ level\n"); // same as  ldrb r0,[r7,#0x47]\r
+  ot("  movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as  ldrb r0,[r7,#0x47]\r
   ot("  beq NoInts0\n");\r
   ot("  cmp r0,#6 ;@ irq>6 ?\n");\r
-  ot("  ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III\n");\r
   ot("  andle r1,r1,#7 ;@ Get interrupt mask\n");\r
   ot("  cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n");\r
-  ot("  blgt DoInterrupt\n");\r
+  ot("  blgt CycloneDoInterrupt\n");\r
   ot(";@ Check if interrupt used up all the cycles:\n");\r
   ot("  subs r5,r5,#0\n");\r
   ot("  blt CycloneEndNoBack\n");\r
@@ -143,7 +201,14 @@ static void PrintFramework()
   ot("CycloneEnd%s\n", ms?"":":");\r
   ot("  sub r4,r4,#2\n");\r
   ot("CycloneEndNoBack%s\n", ms?"":":");\r
+#if (CYCLONE_FOR_GENESIS == 2)\r
+  ot("  ldr r1,[r7,#0x54]\n");\r
+  ot("  mov r9,r9,lsr #28\n");\r
+  ot("  tst r1,r1\n");\r
+  ot("  bxne r1            ;@ jump to alternative CycloneEnd\n");\r
+#else\r
   ot("  mov r9,r9,lsr #28\n");\r
+#endif\r
   ot("  str r4,[r7,#0x40]  ;@ Save Current PC + Memory Base\n");\r
   ot("  str r5,[r7,#0x5c]  ;@ Save Cycles\n");\r
   ot("  strb r9,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
@@ -161,12 +226,12 @@ static void PrintFramework()
     ot(";@ uncompress jump table\n");\r
     if (ms) ot("CycloneInit\n");\r
     else    ot("CycloneInit:\n");\r
-    ot("  ldr r12,=JumpTab\n");\r
+    ot("  ldr r12,=CycloneJumpTab\n");\r
     ot("  add r0,r12,#0xe000*4 ;@ ctrl code pointer\n");\r
     ot("  ldr r1,[r0,#-4]\n");\r
     ot("  tst r1,r1\n");\r
     ot("  movne pc,lr ;@ already uncompressed\n");\r
-       ot("  add r3,r12,#0xa000*4 ;@ handler table pointer, r12=dest\n");\r
+    ot("  add r3,r12,#0xa000*4 ;@ handler table pointer, r12=dest\n");\r
     ot("unc_loop%s\n", ms?"":":");\r
     ot("  ldrh r1,[r0],#2\n");\r
     ot("  and r2,r1,#0xf\n");\r
@@ -187,7 +252,7 @@ static void PrintFramework()
     ot("  bgt unc_loop_in\n");\r
     ot("  b unc_loop\n");\r
     ot("unc_finish%s\n", ms?"":":");\r
-    ot("  ldr r12,=JumpTab\n");\r
+    ot("  ldr r12,=CycloneJumpTab\n");\r
     ot("  ;@ set a-line and f-line handlers\n");\r
     ot("  add r0,r12,#0xa000*4\n");\r
     ot("  ldr r1,[r0,#4] ;@ a-line handler\n");\r
@@ -213,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
@@ -227,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
@@ -246,16 +312,36 @@ 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
   ot("  bx lr\n");\r
   ot("\n");\r
 \r
+  if (ms) ot("CycloneSetRealTAS\n");\r
+  else    ot("CycloneSetRealTAS:\n");\r
+#if (CYCLONE_FOR_GENESIS == 2)\r
+  ot("  ldr r12,=CycloneJumpTab\n");\r
+  ot("  tst r0,r0\n");\r
+  ot("  add r12,r12,#0x4a00*4\n");\r
+  ot("  add r12,r12,#0x00d0*4\n");\r
+  ot("  beq setrtas_off\n");\r
+  ChangeTAS(1);\r
+  ot("  bx lr\n");\r
+  ot("setrtas_off%s\n",ms?"":":");\r
+  ChangeTAS(0);\r
+  ot("  bx lr\n");\r
+  ltorg();\r
+  ot("\n");\r
+#else\r
+  ot("  bx lr\n");\r
+  ot("\n");\r
+#endif\r
+\r
   ot(";@ DoInterrupt - r0=IRQ number\n");\r
-  ot("DoInterrupt%s\n", ms?"":":");\r
+  ot("CycloneDoInterrupt%s\n", ms?"":":");\r
   ot("  stmdb sp!,{lr} ;@ Push ARM return address\n");\r
 \r
   ot(";@ Get IRQ Vector address:\n");\r
@@ -297,7 +383,6 @@ static void PrintFramework()
   ot("\n");\r
   \r
   ot("Exception%s\n", ms?"":":");\r
-  ot("\n");\r
   ot("  stmdb sp!,{lr} ;@ Preserve ARM return address\n");\r
   PrintException(0);\r
   ot("  ldmia sp!,{pc} ;@ Return\n");\r
@@ -307,23 +392,40 @@ static void PrintFramework()
 // ---------------------------------------------------------------------------\r
 // Call Read(r0), Write(r0,r1) or Fetch(r0)\r
 // Trashes r0-r3,r12,lr\r
-int MemHandler(int type,int size)\r
+int MemHandler(int type,int size,int addrreg)\r
 {\r
   int func=0;\r
   func=0x68+type*0xc+(size<<2); // Find correct offset\r
 \r
-#if MEMHANDLERS_NEED_PC\r
-  ot("  str r4,[r7,#0x40] ;@ Save PC\n");\r
-#endif\r
 #if MEMHANDLERS_NEED_FLAGS\r
   ot("  mov r3,r9,lsr #28\n");\r
   ot("  strb r3,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
 #endif\r
-#if MEMHANDLERS_NEED_CYCLES\r
-  ot("  str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
-#endif\r
+  FlushPC();\r
 \r
-  ot("  mov lr,pc\n");\r
+#if (MEMHANDLERS_ADDR_MASK & 0xff000000)\r
+  ot("  bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0xff000000);\r
+  addrreg=0;\r
+#endif\r
+#if (MEMHANDLERS_ADDR_MASK & 0x00ff0000)\r
+  ot("  bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x00ff0000);\r
+  addrreg=0;\r
+#endif\r
+#if (MEMHANDLERS_ADDR_MASK & 0x0000ff00)\r
+  ot("  bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x0000ff00);\r
+  addrreg=0;\r
+#endif\r
+#if (MEMHANDLERS_ADDR_MASK & 0x000000ff)\r
+  ot("  bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x000000ff);\r
+  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
+  }\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
@@ -335,9 +437,6 @@ int MemHandler(int type,int size)
   else         ot("%d(r0)",   8<<size);\r
   ot(" handler\n");\r
 \r
-#if MEMHANDLERS_CHANGE_CYCLES\r
-  ot("  ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
-#endif\r
 #if MEMHANDLERS_CHANGE_FLAGS\r
   ot("  ldrb r9,[r7,#0x46] ;@ r9 = Load Flags (NZCV)\n");\r
   ot("  mov r9,r9,lsl #28\n");\r
@@ -352,7 +451,7 @@ int MemHandler(int type,int size)
 static void PrintOpcodes()\r
 {\r
   int op=0;\r
\r
+\r
   printf("Creating Opcodes: [");\r
 \r
   ot(";@ ---------------------------- Opcodes ---------------------------\n");\r
@@ -380,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
@@ -406,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
@@ -431,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
@@ -465,90 +567,89 @@ static void PrintJumpTable()
 \r
   ot(";@ -------------------------- Jump Table --------------------------\n");\r
 \r
+  // space for decompressed table\r
+  ot(ms?"  area |.data|, data\n":"  .data\n  .align 4\n\n");\r
+\r
 #if COMPRESS_JUMPTABLE\r
     int handlers=0,reps=0,*indexes,ip,u,out;\r
     // use some weird compression on the jump table\r
-       indexes=(int *)malloc(0x10000*4);\r
-       if(!indexes) { printf("ERROR: out of memory\n"); exit(1); }\r
-       len=0x10000;\r
+    indexes=(int *)malloc(0x10000*4);\r
+    if(!indexes) { printf("ERROR: out of memory\n"); exit(1); }\r
+    len=0x10000;\r
 \r
-       // space for decompressed table\r
-       ot(ms?"  area |.data|, data\n":"  .data\n  .align 4\n\n");\r
-\r
-       ot("JumpTab%s\n", ms?"":":");\r
-       if(ms) {\r
-         for(i = 0; i < 0xa000/8; i++)\r
-           ot("  dcd 0,0,0,0,0,0,0,0\n");\r
-       } else\r
-         ot("  .rept 0x%x\n  .long 0,0,0,0,0,0,0,0\n  .endr\n", 0xa000/8);\r
+    ot("CycloneJumpTab%s\n", ms?"":":");\r
+    if(ms) {\r
+      for(i = 0; i < 0xa000/8; i++)\r
+        ot("  dcd 0,0,0,0,0,0,0,0\n");\r
+    } else\r
+      ot("  .rept 0x%x\n  .long 0,0,0,0,0,0,0,0\n  .endr\n", 0xa000/8);\r
 \r
     // hanlers live in "a-line" part of the table\r
-       // first output nop,a-line,f-line handlers\r
-       ot(ms?"  dcd Op____,Op__al,Op__fl,":"  .long Op____,Op__al,Op__fl,");\r
-       handlers=3;\r
+    // first output nop,a-line,f-line handlers\r
+    ot(ms?"  dcd Op____,Op__al,Op__fl,":"  .long Op____,Op__al,Op__fl,");\r
+    handlers=3;\r
 \r
-       for(i=0;i<len;i++)\r
+    for(i=0;i<len;i++)\r
     {\r
       op=CyJump[i];\r
 \r
-         for(u=i-1; u>=0; u--) if(op == CyJump[u]) break; // already done with this op?\r
-         if(u==-1 && op >= 0) {\r
-               ott("Op%.4x",op," ;@ %.4x\n",i,handlers,2);\r
-               indexes[op] = handlers;\r
-           handlers++;\r
+      for(u=i-1; u>=0; u--) if(op == CyJump[u]) break; // already done with this op?\r
+      if(u==-1 && op >= 0) {\r
+        ott("Op%.4x",op," ;@ %.4x\n",i,handlers,2);\r
+        indexes[op] = handlers;\r
+        handlers++;\r
       }\r
-       }\r
-       if(handlers&7) {\r
-         fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
-         for(i = 8-(handlers&7); i > 0; i--)\r
-           ot(",000000");\r
-         ot("\n");\r
-       }\r
-       if(ms) {\r
-         for(i = (0x4000-handlers)/8; i > 0; i--)\r
-           ot("  dcd 0,0,0,0,0,0,0,0\n");\r
-       } else {\r
-         ot(ms?"":"  .rept 0x%x\n  .long 0,0,0,0,0,0,0,0\n  .endr\n", (0x4000-handlers)/8);\r
-       }\r
+    }\r
+    if(handlers&7) {\r
+      fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
+      for(i = 8-(handlers&7); i > 0; i--)\r
+        ot(",000000");\r
+      ot("\n");\r
+    }\r
+    if(ms) {\r
+      for(i = (0x4000-handlers)/8; i > 0; i--)\r
+        ot("  dcd 0,0,0,0,0,0,0,0\n");\r
+    } else {\r
+      ot(ms?"":"  .rept 0x%x\n  .long 0,0,0,0,0,0,0,0\n  .endr\n", (0x4000-handlers)/8);\r
+    }\r
     printf("total distinct hanlers: %i\n",handlers);\r
-       // output data\r
-       for(i=0,ip=0; i < 0xf000; i++, ip++) {\r
+    // output data\r
+    for(i=0,ip=0; i < 0xf000; i++, ip++) {\r
       op=CyJump[i];\r
-         if(op == -2) {\r
-           // it must skip a-line area, because we keep our data there\r
-           ott("0x%.4x", handlers<<4, "\n",0,ip++,1);\r
-           ott("0x%.4x", 0x1000, "\n",0,ip,1);\r
-               i+=0xfff;\r
-           continue;\r
-         }\r
-         for(reps=1; i < 0xf000; i++, reps++) if(op != CyJump[i+1]) break;\r
-         if(op>=0) out=indexes[op]<<4; else out=0; // unrecognised\r
-         if(reps <= 0xe || reps==0x10) {\r
-           if(reps!=0x10) out|=reps; else out|=0xf; // 0xf means 0x10 (0xf appeared to be unused anyway)\r
-           ott("0x%.4x", out, "\n",0,ip,1);\r
+      if(op == -2) {\r
+        // it must skip a-line area, because we keep our data there\r
+        ott("0x%.4x", handlers<<4, "\n",0,ip++,1);\r
+        ott("0x%.4x", 0x1000, "\n",0,ip,1);\r
+        i+=0xfff;\r
+        continue;\r
+      }\r
+      for(reps=1; i < 0xf000; i++, reps++) if(op != CyJump[i+1]) break;\r
+      if(op>=0) out=indexes[op]<<4; else out=0; // unrecognised\r
+      if(reps <= 0xe || reps==0x10) {\r
+        if(reps!=0x10) out|=reps; else out|=0xf; // 0xf means 0x10 (0xf appeared to be unused anyway)\r
+        ott("0x%.4x", out, "\n",0,ip,1);\r
       } else {\r
-           ott("0x%.4x", out, "\n",0,ip++,1);\r
-           ott("0x%.4x", reps,"\n",0,ip,1);\r
-         }\r
+        ott("0x%.4x", out, "\n",0,ip++,1);\r
+        ott("0x%.4x", reps,"\n",0,ip,1);\r
+      }\r
+    }\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
+    if(ip&7) {\r
+      for(i = 8-(ip&7); i > 0; i--)\r
+        ot(",0x0000");\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
+    } else {\r
+      ot("  .rept 0x%x\n  .long 0,0,0,0,0,0,0,0\n  .endr\n", (0x2000-ip/2)/8+1);\r
     }\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
-       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
-       } else {\r
-         ot("  .rept 0x%x\n  .long 0,0,0,0,0,0,0,0\n  .endr\n", (0x2000-ip/2)/8+1);\r
-       }\r
-       ot("\n");\r
-       free(indexes);\r
+    ot("\n");\r
+    free(indexes);\r
 #else\r
-       ot("JumpTab%s\n", ms?"":":");\r
+    ot("CycloneJumpTab%s\n", ms?"":":");\r
     len=0xfffe; // Hmmm, armasm 2.50.8684 messes up with a 0x10000 long jump table\r
                 // notaz: same thing with GNU as 2.9-psion-98r2 (reloc overflow)\r
                 // this is due to COFF objects using only 2 bytes for reloc count\r
@@ -562,7 +663,7 @@ static void PrintJumpTable()
       else if(op==-3) ott("Op__fl",0, " ;@ %.4x\n",i-7,i,2);\r
       else            ott("Op____",0, " ;@ %.4x\n",i-7,i,2);\r
     }\r
-       if(i&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
+    if(i&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
 \r
     ot("\n");\r
     ot(";@ notaz: we don't want to crash if we run into those 2 missing opcodes\n");\r
@@ -586,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
@@ -602,6 +703,7 @@ static int CycloneMake()
     ot("  export CycloneRun\n");\r
     ot("  export CycloneSetSr\n");\r
     ot("  export CycloneGetSr\n");\r
+    ot("  export CycloneSetRealTAS\n");\r
     ot("  export CycloneVer\n");\r
     ot("\n");\r
     ot("CycloneVer dcd 0x%.4x\n",CycloneVer);\r
@@ -613,16 +715,25 @@ static int CycloneMake()
     ot("  .global CycloneSetSr\n");\r
     ot("  .global CycloneGetSr\n");\r
     ot("  .global CycloneVer\n");\r
+#if (CYCLONE_FOR_GENESIS == 2)\r
+    ot("  .global CycloneSetRealTAS\n");\r
+    ot("  .global CycloneDoInterrupt\n");\r
+    ot("  .global CycloneJumpTab\n");\r
+#endif\r
     ot("CycloneVer: .long 0x%.4x\n",CycloneVer);\r
   }\r
   ot("\n");\r
 \r
   PrintFramework();\r
+  arm_op_count = 0;\r
   PrintOpcodes();\r
+  printf("~%i ARM instructions used for opcode handlers\n", arm_op_count);\r
   PrintJumpTable();\r
 \r
   if (ms) ot("  END\n");\r
 \r
+  ot("\n\n;@ vim:filetype=armasm\n");\r
+\r
   fclose(AsmFile); AsmFile=NULL;\r
 \r
 #if 0\r