679af8a3 |
1 | #include <stdio.h>\r |
2 | #include "sh2dasm.h"\r |
3 | \r |
4 | typedef int INT32;\r |
5 | typedef unsigned int UINT32;\r |
6 | typedef unsigned short UINT16;\r |
7 | typedef unsigned char UINT8;\r |
8 | \r |
9 | #define DASMFLAG_STEP_OUT 0\r |
10 | #define DASMFLAG_STEP_OVER 0\r |
11 | #define DASMFLAG_STEP_OVER_EXTRA(x) 0\r |
12 | \r |
13 | #define SIGNX8(x) (((INT32)(x) << 24) >> 24)\r |
14 | #define SIGNX12(x) (((INT32)(x) << 20) >> 20)\r |
15 | \r |
16 | #define Rn ((opcode >> 8) & 15)\r |
17 | #define Rm ((opcode >> 4) & 15)\r |
18 | \r |
19 | static const char *const regname[16] = {\r |
20 | "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7",\r |
21 | "R8", "R9", "R10","R11","R12","R13","R14","SP"\r |
22 | };\r |
23 | \r |
24 | static UINT32 op0000(char *buffer, UINT32 pc, UINT16 opcode)\r |
25 | {\r |
26 | UINT32 flags = 0;\r |
27 | switch(opcode & 0x3f)\r |
28 | {\r |
29 | case 0x02:\r |
30 | sprintf(buffer,"STC SR,%s", regname[Rn]);\r |
31 | break;\r |
32 | case 0x03:\r |
33 | sprintf(buffer,"BSRF %s", regname[Rn]);\r |
34 | break;\r |
35 | case 0x08:\r |
36 | sprintf(buffer,"CLRT");\r |
37 | break;\r |
38 | case 0x09:\r |
39 | sprintf(buffer,"NOP");\r |
40 | break;\r |
41 | case 0x0A:\r |
42 | sprintf(buffer,"STS MACH,%s", regname[Rn]);\r |
43 | break;\r |
44 | case 0x0B:\r |
45 | sprintf(buffer,"RTS");\r |
46 | flags = DASMFLAG_STEP_OUT;\r |
47 | break;\r |
48 | case 0x12:\r |
49 | sprintf(buffer,"STS GBR,%s", regname[Rn]);\r |
50 | break;\r |
51 | case 0x18:\r |
52 | sprintf(buffer,"SETT");\r |
53 | break;\r |
54 | case 0x19:\r |
55 | sprintf(buffer,"DIV0U");\r |
56 | break;\r |
57 | case 0x1A:\r |
58 | sprintf(buffer,"STS MACL,%s", regname[Rn]);\r |
59 | break;\r |
60 | case 0x1B:\r |
61 | sprintf(buffer,"SLEEP");\r |
62 | break;\r |
63 | case 0x22:\r |
64 | sprintf(buffer,"STC VBR,%s", regname[Rn]);\r |
65 | break;\r |
66 | case 0x23:\r |
67 | sprintf(buffer,"BRAF %s", regname[Rn]);\r |
68 | break;\r |
69 | case 0x28:\r |
70 | sprintf(buffer,"CLRMAC");\r |
71 | break;\r |
72 | case 0x29:\r |
73 | sprintf(buffer,"MOVT %s", regname[Rn]);\r |
74 | break;\r |
75 | case 0x2A:\r |
76 | sprintf(buffer,"STS PR,%s", regname[Rn]);\r |
77 | break;\r |
78 | case 0x2B:\r |
79 | sprintf(buffer,"RTE");\r |
80 | flags = DASMFLAG_STEP_OUT;\r |
81 | break;\r |
82 | default:\r |
83 | switch(opcode & 15)\r |
84 | {\r |
85 | case 0:\r |
86 | sprintf(buffer, "?????? $%04X", opcode);\r |
87 | break;\r |
88 | case 1:\r |
89 | sprintf(buffer, "?????? $%04X", opcode);\r |
90 | break;\r |
91 | case 2:\r |
92 | sprintf(buffer, "?????? $%04X", opcode);\r |
93 | break;\r |
94 | case 3:\r |
95 | sprintf(buffer, "?????? $%04X", opcode);\r |
96 | break;\r |
97 | case 4:\r |
98 | sprintf(buffer, "MOV.B %s,@(R0,%s)", regname[Rm], regname[Rn]);\r |
99 | break;\r |
100 | case 5:\r |
101 | sprintf(buffer, "MOV.W %s,@(R0,%s)", regname[Rm], regname[Rn]);\r |
102 | break;\r |
103 | case 6:\r |
104 | sprintf(buffer, "MOV.L %s,@(R0,%s)", regname[Rm], regname[Rn]);\r |
105 | break;\r |
106 | case 7:\r |
107 | sprintf(buffer, "MUL.L %s,%s", regname[Rm], regname[Rn]);\r |
108 | break;\r |
109 | case 8:\r |
110 | sprintf(buffer, "?????? $%04X", opcode);\r |
111 | break;\r |
112 | case 9:\r |
113 | sprintf(buffer, "?????? $%04X", opcode);\r |
114 | break;\r |
115 | case 10:\r |
116 | sprintf(buffer, "?????? $%04X", opcode);\r |
117 | break;\r |
118 | case 11:\r |
119 | sprintf(buffer, "?????? $%04X", opcode);\r |
120 | break;\r |
121 | case 12:\r |
122 | sprintf(buffer, "MOV.B @(R0,%s),%s", regname[Rm], regname[Rn]);\r |
123 | break;\r |
124 | case 13:\r |
125 | sprintf(buffer, "MOV.W @(R0,%s),%s", regname[Rm], regname[Rn]);\r |
126 | break;\r |
127 | case 14:\r |
128 | sprintf(buffer, "MOV.L @(R0,%s),%s", regname[Rm], regname[Rn]);\r |
129 | break;\r |
130 | case 15:\r |
131 | sprintf(buffer, "MAC.L @%s+,@%s+", regname[Rn], regname[Rm]);\r |
132 | break;\r |
133 | }\r |
134 | }\r |
135 | return flags;\r |
136 | }\r |
137 | \r |
138 | static UINT32 op0001(char *buffer, UINT32 pc, UINT16 opcode)\r |
139 | {\r |
140 | sprintf(buffer, "MOV.L %s,@($%02X,%s)", regname[Rm], (opcode & 15) * 4, regname[Rn]);\r |
141 | return 0;\r |
142 | }\r |
143 | \r |
144 | static UINT32 op0010(char *buffer, UINT32 pc, UINT16 opcode)\r |
145 | {\r |
146 | switch (opcode & 15)\r |
147 | {\r |
148 | case 0:\r |
149 | sprintf(buffer, "MOV.B %s,@%s", regname[Rm], regname[Rn]);\r |
150 | break;\r |
151 | case 1:\r |
152 | sprintf(buffer, "MOV.W %s,@%s", regname[Rm], regname[Rn]);\r |
153 | break;\r |
154 | case 2:\r |
155 | sprintf(buffer, "MOV.L %s,@%s", regname[Rm], regname[Rn]);\r |
156 | break;\r |
157 | case 3:\r |
158 | sprintf(buffer, "?????? $%04X", opcode);\r |
159 | break;\r |
160 | case 4:\r |
161 | sprintf(buffer, "MOV.B %s,@-%s", regname[Rm], regname[Rn]);\r |
162 | break;\r |
163 | case 5:\r |
164 | sprintf(buffer, "MOV.W %s,@-%s", regname[Rm], regname[Rn]);\r |
165 | break;\r |
166 | case 6:\r |
167 | sprintf(buffer, "MOV.L %s,@-%s", regname[Rm], regname[Rn]);\r |
168 | break;\r |
169 | case 7:\r |
170 | sprintf(buffer, "DIV0S %s,%s", regname[Rm], regname[Rn]);\r |
171 | break;\r |
172 | case 8:\r |
173 | sprintf(buffer, "TST %s,%s", regname[Rm], regname[Rn]);\r |
174 | break;\r |
175 | case 9:\r |
176 | sprintf(buffer, "AND %s,%s", regname[Rm], regname[Rn]);\r |
177 | break;\r |
178 | case 10:\r |
179 | sprintf(buffer, "XOR %s,%s", regname[Rm], regname[Rn]);\r |
180 | break;\r |
181 | case 11:\r |
182 | sprintf(buffer, "OR %s,%s", regname[Rm], regname[Rn]);\r |
183 | break;\r |
184 | case 12:\r |
185 | sprintf(buffer, "CMP/STR %s,%s", regname[Rm], regname[Rn]);\r |
186 | break;\r |
187 | case 13:\r |
188 | sprintf(buffer, "XTRCT %s,%s", regname[Rm], regname[Rn]);\r |
189 | break;\r |
190 | case 14:\r |
191 | sprintf(buffer, "MULU.W %s,%s", regname[Rm], regname[Rn]);\r |
192 | break;\r |
193 | case 15:\r |
194 | sprintf(buffer, "MULS.W %s,%s", regname[Rm], regname[Rn]);\r |
195 | break;\r |
196 | }\r |
197 | return 0;\r |
198 | }\r |
199 | \r |
200 | static UINT32 op0011(char *buffer, UINT32 pc, UINT16 opcode)\r |
201 | {\r |
202 | switch (opcode & 15)\r |
203 | {\r |
204 | case 0:\r |
205 | sprintf(buffer, "CMP/EQ %s,%s", regname[Rm], regname[Rn]);\r |
206 | break;\r |
207 | case 1:\r |
208 | sprintf(buffer, "?????? %s,%s", regname[Rm], regname[Rn]);\r |
209 | break;\r |
210 | case 2:\r |
211 | sprintf(buffer, "CMP/HS %s,%s", regname[Rm], regname[Rn]);\r |
212 | break;\r |
213 | case 3:\r |
214 | sprintf(buffer, "CMP/GE %s,%s", regname[Rm], regname[Rn]);\r |
215 | break;\r |
216 | case 4:\r |
217 | sprintf(buffer, "DIV1 %s,%s", regname[Rm], regname[Rn]);\r |
218 | break;\r |
219 | case 5:\r |
220 | sprintf(buffer, "DMULU.L %s,%s", regname[Rm], regname[Rn]);\r |
221 | break;\r |
222 | case 6:\r |
223 | sprintf(buffer, "CMP/HI %s,%s", regname[Rm], regname[Rn]);\r |
224 | break;\r |
225 | case 7:\r |
226 | sprintf(buffer, "CMP/GT %s,%s", regname[Rm], regname[Rn]);\r |
227 | break;\r |
228 | case 8:\r |
229 | sprintf(buffer, "SUB %s,%s", regname[Rm], regname[Rn]);\r |
230 | break;\r |
231 | case 9:\r |
232 | sprintf(buffer, "?????? %s,%s", regname[Rm], regname[Rn]);\r |
233 | break;\r |
234 | case 10:\r |
235 | sprintf(buffer, "SUBC %s,%s", regname[Rm], regname[Rn]);\r |
236 | break;\r |
237 | case 11:\r |
238 | sprintf(buffer, "SUBV %s,%s", regname[Rm], regname[Rn]);\r |
239 | break;\r |
240 | case 12:\r |
241 | sprintf(buffer, "ADD %s,%s", regname[Rm], regname[Rn]);\r |
242 | break;\r |
243 | case 13:\r |
244 | sprintf(buffer, "DMULS.L %s,%s", regname[Rm], regname[Rn]);\r |
245 | break;\r |
246 | case 14:\r |
247 | sprintf(buffer, "ADDC %s,%s", regname[Rm], regname[Rn]);\r |
248 | break;\r |
249 | case 15:\r |
250 | sprintf(buffer, "ADDV %s,%s", regname[Rm], regname[Rn]);\r |
251 | break;\r |
252 | }\r |
253 | return 0;\r |
254 | }\r |
255 | \r |
256 | static UINT32 op0100(char *buffer, UINT32 pc, UINT16 opcode)\r |
257 | {\r |
258 | UINT32 flags = 0;\r |
259 | switch(opcode & 0x3F)\r |
260 | {\r |
261 | case 0x00:\r |
262 | sprintf(buffer, "SHLL %s", regname[Rn]);\r |
263 | break;\r |
264 | case 0x01:\r |
265 | sprintf(buffer, "SHLR %s", regname[Rn]);\r |
266 | break;\r |
267 | case 0x02:\r |
268 | sprintf(buffer, "STS.L MACH,@-%s", regname[Rn]);\r |
269 | break;\r |
270 | case 0x03:\r |
271 | sprintf(buffer, "STC.L SR,@-%s", regname[Rn]);\r |
272 | break;\r |
273 | case 0x04:\r |
274 | sprintf(buffer, "ROTL %s", regname[Rn]);\r |
275 | break;\r |
276 | case 0x05:\r |
277 | sprintf(buffer, "ROTR %s", regname[Rn]);\r |
278 | break;\r |
279 | case 0x06:\r |
280 | sprintf(buffer, "LDS.L @%s+,MACH", regname[Rn]);\r |
281 | break;\r |
282 | case 0x07:\r |
283 | sprintf(buffer, "LDC.L @%s+,SR", regname[Rn]);\r |
284 | break;\r |
285 | case 0x08:\r |
286 | sprintf(buffer, "SHLL2 %s", regname[Rn]);\r |
287 | break;\r |
288 | case 0x09:\r |
289 | sprintf(buffer, "SHLR2 %s", regname[Rn]);\r |
290 | break;\r |
291 | case 0x0a:\r |
292 | sprintf(buffer, "LDS %s,MACH", regname[Rn]);\r |
293 | break;\r |
294 | case 0x0b:\r |
295 | sprintf(buffer, "JSR %s", regname[Rn]);\r |
296 | flags = DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA(1);\r |
297 | break;\r |
298 | case 0x0e:\r |
299 | sprintf(buffer, "LDC %s,SR", regname[Rn]);\r |
300 | break;\r |
301 | case 0x10:\r |
302 | sprintf(buffer, "DT %s", regname[Rn]);\r |
303 | break;\r |
304 | case 0x11:\r |
305 | sprintf(buffer, "CMP/PZ %s", regname[Rn]);\r |
306 | break;\r |
307 | case 0x12:\r |
308 | sprintf(buffer, "STS.L MACL,@-%s", regname[Rn]);\r |
309 | break;\r |
310 | case 0x13:\r |
311 | sprintf(buffer, "STC.L GBR,@-%s", regname[Rn]);\r |
312 | break;\r |
313 | case 0x15:\r |
314 | sprintf(buffer, "CMP/PL %s", regname[Rn]);\r |
315 | break;\r |
316 | case 0x16:\r |
317 | sprintf(buffer, "LDS.L @%s+,MACL", regname[Rn]);\r |
318 | break;\r |
319 | case 0x17:\r |
320 | sprintf(buffer, "LDC.L @%s+,GBR", regname[Rn]);\r |
321 | break;\r |
322 | case 0x18:\r |
323 | sprintf(buffer, "SHLL8 %s", regname[Rn]);\r |
324 | break;\r |
325 | case 0x19:\r |
326 | sprintf(buffer, "SHLR8 %s", regname[Rn]);\r |
327 | break;\r |
328 | case 0x1a:\r |
329 | sprintf(buffer, "LDS %s,MACL", regname[Rn]);\r |
330 | break;\r |
331 | case 0x1b:\r |
332 | sprintf(buffer, "TAS %s", regname[Rn]);\r |
333 | break;\r |
334 | case 0x1e:\r |
335 | sprintf(buffer, "LDC %s,GBR", regname[Rn]);\r |
336 | break;\r |
337 | case 0x20:\r |
338 | sprintf(buffer, "SHAL %s", regname[Rn]);\r |
339 | break;\r |
340 | case 0x21:\r |
341 | sprintf(buffer, "SHAR %s", regname[Rn]);\r |
342 | break;\r |
343 | case 0x22:\r |
344 | sprintf(buffer, "STS.L PR,@-%s", regname[Rn]);\r |
345 | break;\r |
346 | case 0x23:\r |
347 | sprintf(buffer, "STC.L VBR,@-%s", regname[Rn]);\r |
348 | break;\r |
349 | case 0x24:\r |
350 | sprintf(buffer, "ROTCL %s", regname[Rn]);\r |
351 | break;\r |
352 | case 0x25:\r |
353 | sprintf(buffer, "ROTCR %s", regname[Rn]);\r |
354 | break;\r |
355 | case 0x26:\r |
356 | sprintf(buffer, "LDS.L @%s+,PR", regname[Rn]);\r |
357 | break;\r |
358 | case 0x27:\r |
359 | sprintf(buffer, "LDC.L @%s+,VBR", regname[Rn]);\r |
360 | break;\r |
361 | case 0x28:\r |
362 | sprintf(buffer, "SHLL16 %s", regname[Rn]);\r |
363 | break;\r |
364 | case 0x29:\r |
365 | sprintf(buffer, "SHLR16 %s", regname[Rn]);\r |
366 | break;\r |
367 | case 0x2a:\r |
368 | sprintf(buffer, "LDS %s,PR", regname[Rn]);\r |
369 | break;\r |
370 | case 0x2b:\r |
371 | sprintf(buffer, "JMP %s", regname[Rn]);\r |
372 | break;\r |
373 | case 0x2e:\r |
374 | sprintf(buffer, "LDC %s,VBR", regname[Rn]);\r |
375 | break;\r |
376 | default:\r |
377 | if ((opcode & 15) == 15)\r |
378 | sprintf(buffer, "MAC.W @%s+,@%s+", regname[Rm], regname[Rn]);\r |
379 | else\r |
380 | sprintf(buffer, "?????? $%04X", opcode);\r |
381 | }\r |
382 | return flags;\r |
383 | }\r |
384 | \r |
385 | static UINT32 op0101(char *buffer, UINT32 pc, UINT16 opcode)\r |
386 | {\r |
387 | sprintf(buffer, "MOV.L @($%02X,%s),%s", (opcode & 15) * 4, regname[Rm], regname[Rn]);\r |
388 | return 0;\r |
389 | }\r |
390 | \r |
391 | static UINT32 op0110(char *buffer, UINT32 pc, UINT16 opcode)\r |
392 | \r |
393 | {\r |
394 | switch(opcode & 0xF)\r |
395 | {\r |
396 | case 0x00:\r |
397 | sprintf(buffer, "MOV.B @%s,%s", regname[Rm], regname[Rn]);\r |
398 | break;\r |
399 | case 0x01:\r |
400 | sprintf(buffer, "MOV.W @%s,%s", regname[Rm], regname[Rn]);\r |
401 | break;\r |
402 | case 0x02:\r |
403 | sprintf(buffer, "MOV.L @%s,%s", regname[Rm], regname[Rn]);\r |
404 | break;\r |
405 | case 0x03:\r |
406 | sprintf(buffer, "MOV %s,%s", regname[Rm], regname[Rn]);\r |
407 | break;\r |
408 | case 0x04:\r |
409 | sprintf(buffer, "MOV.B @%s+,%s", regname[Rm], regname[Rn]);\r |
410 | break;\r |
411 | case 0x05:\r |
412 | sprintf(buffer, "MOV.W @%s+,%s", regname[Rm], regname[Rn]);\r |
413 | break;\r |
414 | case 0x06:\r |
415 | sprintf(buffer, "MOV.L @%s+,%s", regname[Rm], regname[Rn]);\r |
416 | break;\r |
417 | case 0x07:\r |
418 | sprintf(buffer, "NOT %s,%s", regname[Rm], regname[Rn]);\r |
419 | break;\r |
420 | case 0x08:\r |
421 | sprintf(buffer, "SWAP.B %s,%s", regname[Rm], regname[Rn]);\r |
422 | break;\r |
423 | case 0x09:\r |
424 | sprintf(buffer, "SWAP.W %s,%s", regname[Rm], regname[Rn]);\r |
425 | break;\r |
426 | case 0x0a:\r |
427 | sprintf(buffer, "NEGC %s,%s", regname[Rm], regname[Rn]);\r |
428 | break;\r |
429 | case 0x0b:\r |
430 | sprintf(buffer, "NEG %s,%s", regname[Rm], regname[Rn]);\r |
431 | break;\r |
432 | case 0x0c:\r |
433 | sprintf(buffer, "EXTU.B %s,%s", regname[Rm], regname[Rn]);\r |
434 | break;\r |
435 | case 0x0d:\r |
436 | sprintf(buffer, "EXTU.W %s,%s", regname[Rm], regname[Rn]);\r |
437 | break;\r |
438 | case 0x0e:\r |
439 | sprintf(buffer, "EXTS.B %s,%s", regname[Rm], regname[Rn]);\r |
440 | break;\r |
441 | case 0x0f:\r |
442 | sprintf(buffer, "EXTS.W %s,%s", regname[Rm], regname[Rn]);\r |
443 | break;\r |
444 | }\r |
445 | return 0;\r |
446 | }\r |
447 | \r |
448 | static UINT32 op0111(char *buffer, UINT32 pc, UINT16 opcode)\r |
449 | {\r |
450 | sprintf(buffer, "ADD #$%02X,%s", opcode & 0xff, regname[Rn]);\r |
451 | return 0;\r |
452 | }\r |
453 | \r |
454 | static UINT32 op1000(char *buffer, UINT32 pc, UINT16 opcode)\r |
455 | {\r |
456 | switch((opcode >> 8) & 15)\r |
457 | {\r |
458 | case 0:\r |
459 | sprintf(buffer, "MOV.B R0,@($%02X,%s)", (opcode & 15), regname[Rm]);\r |
460 | break;\r |
461 | case 1:\r |
462 | sprintf(buffer, "MOV.W R0,@($%02X,%s)", (opcode & 15) * 2, regname[Rm]);\r |
463 | break;\r |
464 | case 4:\r |
465 | sprintf(buffer, "MOV.B @($%02X,%s),R0", (opcode & 15), regname[Rm]);\r |
466 | break;\r |
467 | case 5:\r |
468 | sprintf(buffer, "MOV.W @($%02X,%s),R0", (opcode & 15), regname[Rm]);\r |
469 | break;\r |
470 | case 8:\r |
471 | sprintf(buffer, "CMP/EQ #$%02X,R0", (opcode & 0xff));\r |
472 | break;\r |
473 | case 9:\r |
474 | sprintf(buffer, "BT $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);\r |
475 | break;\r |
476 | case 11:\r |
477 | sprintf(buffer, "BF $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);\r |
478 | break;\r |
479 | case 13:\r |
480 | sprintf(buffer, "BTS $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);\r |
481 | break;\r |
482 | case 15:\r |
483 | sprintf(buffer, "BFS $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);\r |
484 | break;\r |
485 | default :\r |
486 | sprintf(buffer, "invalid $%04X", opcode);\r |
487 | }\r |
488 | return 0;\r |
489 | }\r |
490 | \r |
491 | static UINT32 op1001(char *buffer, UINT32 pc, UINT16 opcode)\r |
492 | {\r |
493 | sprintf(buffer, "MOV.W @($%04X,PC),%s", (opcode & 0xff) * 2, regname[Rn]);\r |
494 | return 0;\r |
495 | }\r |
496 | \r |
497 | static UINT32 op1010(char *buffer, UINT32 pc, UINT16 opcode)\r |
498 | {\r |
499 | sprintf(buffer, "BRA $%08X", SIGNX12(opcode & 0xfff) * 2 + pc + 2);\r |
500 | return 0;\r |
501 | }\r |
502 | \r |
503 | static UINT32 op1011(char *buffer, UINT32 pc, UINT16 opcode)\r |
504 | {\r |
505 | sprintf(buffer, "BSR $%08X", SIGNX12(opcode & 0xfff) * 2 + pc + 2);\r |
506 | return DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA(1);\r |
507 | }\r |
508 | \r |
509 | static UINT32 op1100(char *buffer, UINT32 pc, UINT16 opcode)\r |
510 | {\r |
511 | UINT32 flags = 0;\r |
512 | switch((opcode >> 8) & 15)\r |
513 | {\r |
514 | case 0:\r |
515 | sprintf(buffer, "MOV.B R0,@($%02X,GBR)", opcode & 0xff);\r |
516 | break;\r |
517 | case 1:\r |
518 | sprintf(buffer, "MOV.W R0,@($%04X,GBR)", (opcode & 0xff) * 2);\r |
519 | break;\r |
520 | case 2:\r |
521 | sprintf(buffer, "MOV.L R0,@($%04X,GBR)", (opcode & 0xff) * 4);\r |
522 | break;\r |
523 | case 3:\r |
524 | sprintf(buffer, "TRAPA #$%02X", opcode & 0xff);\r |
525 | flags = DASMFLAG_STEP_OVER;\r |
526 | break;\r |
527 | case 4:\r |
528 | sprintf(buffer, "MOV.B @($%02X,GBR),R0", opcode & 0xff);\r |
529 | break;\r |
530 | case 5:\r |
531 | sprintf(buffer, "MOV.W @($%04X,GBR),R0", (opcode & 0xff) * 2);\r |
532 | break;\r |
533 | case 6:\r |
534 | sprintf(buffer, "MOV.L @($%04X,GBR),R0", (opcode & 0xff) * 4);\r |
535 | break;\r |
536 | case 7:\r |
537 | sprintf(buffer, "MOVA @($%04X,PC),R0", (opcode & 0xff) * 4);\r |
538 | break;\r |
539 | case 8:\r |
540 | sprintf(buffer, "TST #$%02X,R0", opcode & 0xff);\r |
541 | break;\r |
542 | case 9:\r |
543 | sprintf(buffer, "AND #$%02X,R0", opcode & 0xff);\r |
544 | break;\r |
545 | case 10:\r |
546 | sprintf(buffer, "XOR #$%02X,R0", opcode & 0xff);\r |
547 | break;\r |
548 | case 11:\r |
549 | sprintf(buffer, "OR #$%02X,R0", opcode & 0xff);\r |
550 | break;\r |
551 | case 12:\r |
552 | sprintf(buffer, "TST.B #$%02X,@(R0,GBR)", opcode & 0xff);\r |
553 | break;\r |
554 | case 13:\r |
555 | sprintf(buffer, "AND.B #$%02X,@(R0,GBR)", opcode & 0xff);\r |
556 | break;\r |
557 | case 14:\r |
558 | sprintf(buffer, "XOR.B #$%02X,@(R0,GBR)", opcode & 0xff);\r |
559 | break;\r |
560 | case 15:\r |
561 | sprintf(buffer, "OR.B #$%02X,@(R0,GBR)", opcode & 0xff);\r |
562 | break;\r |
563 | }\r |
564 | return flags;\r |
565 | }\r |
566 | \r |
567 | static UINT32 op1101(char *buffer, UINT32 pc, UINT16 opcode)\r |
568 | {\r |
569 | sprintf(buffer, "MOV.L @($%02X,PC),%s ; #$%06x", (opcode * 4) & 0x3ff, regname[Rn],\r |
570 | (pc + ((opcode * 4) & 0x3ff) + 2) & ~3);\r |
571 | return 0;\r |
572 | }\r |
573 | \r |
574 | static UINT32 op1110(char *buffer, UINT32 pc, UINT16 opcode)\r |
575 | {\r |
576 | sprintf(buffer, "MOV #$%02X,%s", (opcode & 0xff), regname[Rn]);\r |
577 | return 0;\r |
578 | }\r |
579 | \r |
580 | static UINT32 op1111(char *buffer, UINT32 pc, UINT16 opcode)\r |
581 | {\r |
582 | sprintf(buffer, "unknown $%04X", opcode);\r |
583 | return 0;\r |
584 | }\r |
585 | \r |
586 | unsigned DasmSH2(char *buffer, unsigned pc, UINT16 opcode)\r |
587 | {\r |
588 | UINT32 flags;\r |
589 | \r |
590 | pc += 2;\r |
591 | \r |
592 | switch((opcode >> 12) & 15)\r |
593 | {\r |
594 | case 0: flags = op0000(buffer,pc,opcode); break;\r |
595 | case 1: flags = op0001(buffer,pc,opcode); break;\r |
596 | case 2: flags = op0010(buffer,pc,opcode); break;\r |
597 | case 3: flags = op0011(buffer,pc,opcode); break;\r |
598 | case 4: flags = op0100(buffer,pc,opcode); break;\r |
599 | case 5: flags = op0101(buffer,pc,opcode); break;\r |
600 | case 6: flags = op0110(buffer,pc,opcode); break;\r |
601 | case 7: flags = op0111(buffer,pc,opcode); break;\r |
602 | case 8: flags = op1000(buffer,pc,opcode); break;\r |
603 | case 9: flags = op1001(buffer,pc,opcode); break;\r |
604 | case 10: flags = op1010(buffer,pc,opcode); break;\r |
605 | case 11: flags = op1011(buffer,pc,opcode); break;\r |
606 | case 12: flags = op1100(buffer,pc,opcode); break;\r |
607 | case 13: flags = op1101(buffer,pc,opcode); break;\r |
608 | case 14: flags = op1110(buffer,pc,opcode); break;\r |
609 | default: flags = op1111(buffer,pc,opcode); break;\r |
610 | }\r |
611 | return 0;//2 | flags | DASMFLAG_SUPPORTED;\r |
612 | }\r |
613 | \r |
614 | #if 0\r |
615 | \r |
616 | #define swab32(x) (((x) << 24) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) | ((x) >> 24))\r |
617 | #define swab16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))\r |
618 | \r |
619 | int main(int argc, char *argv[])\r |
620 | {\r |
621 | unsigned short op;\r |
622 | char buff[256];\r |
623 | unsigned pc;\r |
624 | FILE *f;\r |
625 | int ret;\r |
626 | \r |
627 | if (argv[1] == NULL) {\r |
628 | printf("usage\n%s <file>\n", argv[0]);\r |
629 | return 1;\r |
630 | }\r |
631 | \r |
632 | f = fopen(argv[1], "rb");\r |
633 | if (f == NULL) {\r |
634 | fprintf(stderr, "can't open %s\n", argv[1]);\r |
635 | return 1;\r |
636 | }\r |
637 | \r |
638 | for (pc = 0x140;; pc += 2)\r |
639 | {\r |
640 | fseek(f, pc, SEEK_SET);\r |
641 | \r |
642 | ret = fread(&op, 1, sizeof(op), f);\r |
643 | if (ret != sizeof(op))\r |
644 | break;\r |
645 | \r |
646 | DasmSH2(buff, pc, swab16(op));\r |
647 | printf("%06x %04x %s\n", pc, swab16(op), buff);\r |
648 | }\r |
649 | \r |
650 | fclose(f);\r |
651 | return 0;\r |
652 | }\r |
653 | \r |
654 | #endif\r |