OpAny.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #include "app.h"
  2. int opend_op_changes_cycles, opend_check_interrupt, opend_check_trace;
  3. static unsigned char OpData[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  4. static unsigned short OpRead16(unsigned int a)
  5. {
  6. return (unsigned short)( (OpData[a&15]<<8) | OpData[(a+1)&15] );
  7. }
  8. // For opcode 'op' use handler 'use'
  9. void OpUse(int op,int use)
  10. {
  11. char text[64]="";
  12. CyJump[op]=use;
  13. if (op!=use) return;
  14. // Disassemble opcode
  15. DisaPc=0;
  16. DisaText=text;
  17. DisaWord=OpRead16;
  18. DisaGet();
  19. ot(";@ ---------- [%.4x] %s uses Op%.4x ----------\n",op,text,use);
  20. }
  21. void OpStart(int op, int sea, int tea, int op_changes_cycles, int supervisor_check)
  22. {
  23. int last_op_count=arm_op_count;
  24. Cycles=0;
  25. OpUse(op,op); // This opcode obviously uses this handler
  26. ot("Op%.4x%s\n", op, ms?"":":");
  27. if (supervisor_check)
  28. {
  29. // checks for supervisor bit, if not set, jumps to SuperEnd()
  30. // also sets r11 to SR high value, SuperChange() uses this
  31. ot(" ldr r11,[r7,#0x44] ;@ Get SR high\n");
  32. }
  33. if ((sea >= 0x10 && sea != 0x3c) || (tea >= 0x10 && tea != 0x3c))
  34. {
  35. #if MEMHANDLERS_NEED_PREV_PC
  36. ot(" str r4,[r7,#0x50] ;@ Save prev PC + 2\n");
  37. #endif
  38. #if MEMHANDLERS_NEED_CYCLES
  39. ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n");
  40. #endif
  41. }
  42. if (supervisor_check)
  43. {
  44. ot(" tst r11,#0x20 ;@ Check we are in supervisor mode\n");
  45. ot(" beq WrongPrivilegeMode ;@ No\n");
  46. }
  47. if ((sea >= 0x10 && sea != 0x3c) || (tea >= 0x10 && tea != 0x3c)) {
  48. #if MEMHANDLERS_CHANGE_CYCLES
  49. if (op_changes_cycles)
  50. ot(" mov r5,#0\n");
  51. #endif
  52. }
  53. if (last_op_count!=arm_op_count)
  54. ot("\n");
  55. pc_dirty = 1;
  56. opend_op_changes_cycles = opend_check_interrupt = opend_check_trace = 0;
  57. }
  58. void OpEnd(int sea, int tea)
  59. {
  60. int did_fetch=0;
  61. opend_check_trace = opend_check_trace && EMULATE_TRACE;
  62. #if MEMHANDLERS_CHANGE_CYCLES
  63. if ((sea >= 0x10 && sea != 0x3c) || (tea >= 0x10 && tea != 0x3c))
  64. {
  65. if (opend_op_changes_cycles)
  66. {
  67. ot(" ldr r0,[r7,#0x5c] ;@ Load Cycles\n");
  68. ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");
  69. ot(" add r5,r0,r5\n");
  70. did_fetch=1;
  71. }
  72. else
  73. {
  74. ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");
  75. }
  76. }
  77. #endif
  78. if (!did_fetch)
  79. ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");
  80. if (opend_check_trace)
  81. ot(" ldr r1,[r7,#0x44]\n");
  82. ot(" subs r5,r5,#%d ;@ Subtract cycles\n",Cycles);
  83. if (opend_check_trace)
  84. {
  85. ot(";@ CheckTrace:\n");
  86. ot(" tst r1,#0x80\n");
  87. ot(" bne CycloneDoTraceWithChecks\n");
  88. ot(" cmp r5,#0\n");
  89. }
  90. if (opend_check_interrupt)
  91. {
  92. ot(" blt CycloneEnd\n");
  93. ot(";@ CheckInterrupt:\n");
  94. if (!opend_check_trace)
  95. ot(" ldr r1,[r7,#0x44]\n");
  96. ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47]
  97. ot(" ldreq pc,[r6,r8,asl #2] ;@ Jump to next opcode handler\n");
  98. ot(" cmp r0,#6 ;@ irq>6 ?\n");
  99. ot(" andle r1,r1,#7 ;@ Get interrupt mask\n");
  100. ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n");
  101. ot(" ldrle pc,[r6,r8,asl #2] ;@ Jump to next opcode handler\n");
  102. ot(" b CycloneDoInterruptGoBack\n");
  103. }
  104. else
  105. {
  106. ot(" ldrge pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");
  107. ot(" b CycloneEnd\n");
  108. }
  109. ot("\n");
  110. }
  111. int OpBase(int op,int size,int sepa)
  112. {
  113. int ea=op&0x3f; // Get Effective Address
  114. if (ea<0x10) return sepa?(op&~0x7):(op&~0xf); // Use 1 handler for d0-d7 and a0-a7
  115. if (size==0&&(ea==0x1f || ea==0x27)) return op; // Specific handler for (a7)+ and -(a7)
  116. if (ea<0x38) return op&~7; // Use 1 handler for (a0)-(a7), etc...
  117. return op;
  118. }
  119. // Get flags, trashes r2
  120. int OpGetFlags(int subtract,int xbit,int specialz)
  121. {
  122. if (specialz) ot(" orr r2,r9,#0xb0000000 ;@ for old Z\n");
  123. ot(" mrs r9,cpsr ;@ r9=flags\n");
  124. if (specialz) ot(" andeq r9,r9,r2 ;@ fix Z\n");
  125. if (subtract) ot(" eor r9,r9,#0x20000000 ;@ Invert carry\n");
  126. if (xbit)
  127. {
  128. ot(" str r9,[r7,#0x4c] ;@ Save X bit\n");
  129. }
  130. return 0;
  131. }
  132. // -----------------------------------------------------------------
  133. int g_op;
  134. void OpAny(int op)
  135. {
  136. memset(OpData,0x33,sizeof(OpData));
  137. OpData[0]=(unsigned char)(op>>8);
  138. OpData[1]=(unsigned char)op;
  139. g_op=op;
  140. if ((op&0xf100)==0x0000) OpArith(op); // +
  141. if ((op&0xc000)==0x0000) OpMove(op); // +
  142. if ((op&0xf5bf)==0x003c) OpArithSr(op); // + Ori/Andi/Eori $nnnn,sr
  143. if ((op&0xf100)==0x0100) OpBtstReg(op); // +
  144. if ((op&0xf138)==0x0108) OpMovep(op); // +
  145. if ((op&0xff00)==0x0800) OpBtstImm(op); // +
  146. if ((op&0xf900)==0x4000) OpNeg(op); // +
  147. if ((op&0xf140)==0x4100) OpChk(op); // +
  148. if ((op&0xf1c0)==0x41c0) OpLea(op); // +
  149. if ((op&0xf9c0)==0x40c0) OpMoveSr(op); // +
  150. if ((op&0xffc0)==0x4800) OpNbcd(op); // +
  151. if ((op&0xfff8)==0x4840) OpSwap(op); // +
  152. if ((op&0xffc0)==0x4840) OpPea(op); // +
  153. if ((op&0xffb8)==0x4880) OpExt(op); // +
  154. if ((op&0xfb80)==0x4880) OpMovem(op); // +
  155. if ((op&0xff00)==0x4a00) OpTst(op); // +
  156. if ((op&0xffc0)==0x4ac0) OpTas(op); // +
  157. if ((op&0xfff0)==0x4e40) OpTrap(op); // +
  158. if ((op&0xfff8)==0x4e50) OpLink(op); // +
  159. if ((op&0xfff8)==0x4e58) OpUnlk(op); // +
  160. if ((op&0xfff0)==0x4e60) OpMoveUsp(op); // +
  161. if ((op&0xfff8)==0x4e70) Op4E70(op); // + Reset/Rts etc
  162. if ((op&0xfffd)==0x4e70) OpStopReset(op);// +
  163. if ((op&0xff80)==0x4e80) OpJsr(op); // +
  164. if ((op&0xf000)==0x5000) OpAddq(op); // +
  165. if ((op&0xf0c0)==0x50c0) OpSet(op); // +
  166. if ((op&0xf0f8)==0x50c8) OpDbra(op); // +
  167. if ((op&0xf000)==0x6000) OpBranch(op); // +
  168. if ((op&0xf100)==0x7000) OpMoveq(op); // +
  169. if ((op&0xa000)==0x8000) OpArithReg(op); // + Or/Sub/And/Add
  170. if ((op&0xb1f0)==0x8100) OpAbcd(op); // +
  171. if ((op&0xb0c0)==0x80c0) OpMul(op); // +
  172. if ((op&0x90c0)==0x90c0) OpAritha(op); // +
  173. if ((op&0xb130)==0x9100) OpAddx(op); // +
  174. if ((op&0xf000)==0xb000) OpCmpEor(op); // +
  175. if ((op&0xf138)==0xb108) OpCmpm(op); // +
  176. if ((op&0xf130)==0xc100) OpExg(op); // +
  177. if ((op&0xf000)==0xe000) OpAsr(op); // + Asr/l/Ror/l etc
  178. if ((op&0xf8c0)==0xe0c0) OpAsrEa(op); // +
  179. if (op==0xffff)
  180. {
  181. SuperEnd();
  182. }
  183. }