6003a768 |
1 | \r |
619b1824 |
2 | // This file is part of the Cyclone 68000 Emulator\r |
3 | \r |
c41b9b97 |
4 | // Copyright (c) 2011 FinalDave (emudave (at) gmail.com)\r |
5 | \r |
619b1824 |
6 | // This code is licensed under the GNU General Public License version 2.0 and the MAME License.\r |
7 | // You can choose the license that has the most advantages for you.\r |
8 | \r |
9 | // SVN repository can be found at http://code.google.com/p/cyclone68000/\r |
10 | \r |
6003a768 |
11 | #include "app.h"\r |
12 | \r |
13 | static unsigned char OpData[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\r |
14 | \r |
15 | static unsigned short CPU_CALL OpRead16(unsigned int a)\r |
16 | {\r |
17 | return (unsigned short)( (OpData[a&15]<<8) | OpData[(a+1)&15] );\r |
18 | }\r |
19 | \r |
20 | // For opcode 'op' use handler 'use'\r |
21 | void OpUse(int op,int use)\r |
22 | {\r |
23 | char text[64]="";\r |
24 | CyJump[op]=use;\r |
25 | \r |
26 | if (op!=use) return;\r |
27 | \r |
28 | // Disassemble opcode\r |
29 | DisaPc=0;\r |
30 | DisaText=text;\r |
31 | DisaWord=OpRead16;\r |
32 | \r |
33 | DisaGet();\r |
34 | ot(";@ ---------- [%.4x] %s uses Op%.4x ----------\n",op,text,use);\r |
35 | }\r |
36 | \r |
37 | void OpFirst()\r |
38 | {\r |
39 | ot(" ldrh r8,[r4],#2 ;@ Fetch first opcode\n");\r |
40 | ot(" ldr pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r |
41 | }\r |
42 | \r |
43 | void OpStart(int op)\r |
44 | {\r |
45 | Cycles=0;\r |
46 | OpUse(op,op); // This opcode obviously uses this handler\r |
47 | ot("Op%.4x%s\n", op, ms?"":":");\r |
48 | }\r |
49 | \r |
50 | void OpEnd()\r |
51 | {\r |
52 | ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");\r |
53 | ot(" subs r5,r5,#%d ;@ Subtract cycles\n",Cycles);\r |
54 | ot(" ldrge pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r |
55 | ot(" b CycloneEnd\n");\r |
56 | ltorg();\r |
57 | ot("\n");\r |
58 | }\r |
59 | \r |
60 | int OpBase(int op)\r |
61 | {\r |
62 | int ea=op&0x3f; // Get Effective Address\r |
63 | if (ea<0x10) return op&~0xf; // Use 1 handler for d0-d7 and a0-a7\r |
64 | if (ea>=0x18 && ea<0x28 && (ea&7)==7) return op; // Specific handler for (a7)+ and -(a7)\r |
65 | if (ea<0x38) return op&~7; // Use 1 handler for (a0)-(a7), etc...\r |
66 | return op;\r |
67 | }\r |
68 | \r |
69 | // Get flags, trashes r2\r |
70 | int OpGetFlags(int subtract,int xbit)\r |
71 | {\r |
72 | ot(" mrs r9,cpsr ;@ r9=flags\n");\r |
73 | \r |
74 | if (subtract) ot(" eor r9,r9,#0x20000000 ;@ Invert carry\n");\r |
75 | \r |
76 | if (Accu&1) if (xbit)\r |
77 | {\r |
78 | ot(" mov r2,r9,lsr #28\n");\r |
79 | ot(" strb r2,[r7,#0x45] ;@ Save X bit\n");\r |
80 | }\r |
81 | return 0;\r |
82 | }\r |
83 | \r |
84 | // -----------------------------------------------------------------\r |
85 | \r |
86 | void OpAny(int op)\r |
87 | {\r |
88 | memset(OpData,0x33,sizeof(OpData));\r |
89 | OpData[0]=(unsigned char)(op>>8);\r |
90 | OpData[1]=(unsigned char)op;\r |
91 | \r |
92 | if ((op&0xf100)==0x0000) OpArith(op);\r |
93 | if ((op&0xc000)==0x0000) OpMove(op);\r |
94 | if ((op&0xf5bf)==0x003c) OpArithSr(op); // Ori/Andi/Eori $nnnn,sr\r |
95 | if ((op&0xf100)==0x0100) OpBtstReg(op);\r |
96 | if ((op&0xff00)==0x0800) OpBtstImm(op);\r |
97 | if ((op&0xf900)==0x4000) OpNeg(op);\r |
98 | if ((op&0xf1c0)==0x41c0) OpLea(op);\r |
99 | if ((op&0xf9c0)==0x40c0) OpMoveSr(op);\r |
100 | if ((op&0xfff8)==0x4840) OpSwap(op);\r |
101 | if ((op&0xffc0)==0x4840) OpPea(op);\r |
102 | if ((op&0xffb8)==0x4880) OpExt(op);\r |
103 | if ((op&0xfb80)==0x4880) OpMovem(op);\r |
104 | if ((op&0xff00)==0x4a00) OpTst(op);\r |
105 | if ((op&0xfff0)==0x4e40) OpTrap(op);\r |
106 | if ((op&0xfff8)==0x4e50) OpLink(op);\r |
107 | if ((op&0xfff8)==0x4e58) OpUnlk(op);\r |
108 | if ((op&0xfff0)==0x4e60) OpMoveUsp(op);\r |
109 | if ((op&0xfff8)==0x4e70) Op4E70(op); // Reset/Rts etc\r |
110 | if ((op&0xff80)==0x4e80) OpJsr(op);\r |
111 | if ((op&0xf000)==0x5000) OpAddq(op);\r |
112 | if ((op&0xf0c0)==0x50c0) OpSet(op);\r |
113 | if ((op&0xf0f8)==0x50c8) OpDbra(op);\r |
114 | if ((op&0xf000)==0x6000) OpBranch(op);\r |
115 | if ((op&0xf100)==0x7000) OpMoveq(op);\r |
116 | if ((op&0xa000)==0x8000) OpArithReg(op); // Or/Sub/And/Add\r |
117 | if ((op&0xb1f0)==0x8100) OpAbcd(op);\r |
118 | if ((op&0xb0c0)==0x80c0) OpMul(op);\r |
119 | if ((op&0x90c0)==0x90c0) OpAritha(op);\r |
120 | if ((op&0xb138)==0x9100) OpAddx(op);\r |
121 | if ((op&0xf000)==0xb000) OpCmpEor(op);\r |
122 | if ((op&0xf130)==0xc100) OpExg(op);\r |
123 | if ((op&0xf000)==0xe000) OpAsr(op); // Asr/l/Ror/l etc\r |
124 | if ((op&0xf8c0)==0xe0c0) OpAsrEa(op);\r |
125 | \r |
126 | }\r |