5 typedef unsigned int UINT32;
\r
6 typedef unsigned short UINT16;
\r
7 typedef unsigned char UINT8;
\r
9 #define DASMFLAG_STEP_OUT 0
\r
10 #define DASMFLAG_STEP_OVER 0
\r
11 #define DASMFLAG_STEP_OVER_EXTRA(x) 0
\r
13 #define SIGNX8(x) (((INT32)(x) << 24) >> 24)
\r
14 #define SIGNX12(x) (((INT32)(x) << 20) >> 20)
\r
16 #define Rn ((opcode >> 8) & 15)
\r
17 #define Rm ((opcode >> 4) & 15)
\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
24 static UINT32 op0000(char *buffer, UINT32 pc, UINT16 opcode)
\r
27 switch(opcode & 0x3f)
\r
30 sprintf(buffer,"STC SR,%s", regname[Rn]);
\r
33 sprintf(buffer,"BSRF %s", regname[Rn]);
\r
36 sprintf(buffer,"CLRT");
\r
39 sprintf(buffer,"NOP");
\r
42 sprintf(buffer,"STS MACH,%s", regname[Rn]);
\r
45 sprintf(buffer,"RTS");
\r
46 flags = DASMFLAG_STEP_OUT;
\r
49 sprintf(buffer,"STS GBR,%s", regname[Rn]);
\r
52 sprintf(buffer,"SETT");
\r
55 sprintf(buffer,"DIV0U");
\r
58 sprintf(buffer,"STS MACL,%s", regname[Rn]);
\r
61 sprintf(buffer,"SLEEP");
\r
64 sprintf(buffer,"STC VBR,%s", regname[Rn]);
\r
67 sprintf(buffer,"BRAF %s", regname[Rn]);
\r
70 sprintf(buffer,"CLRMAC");
\r
73 sprintf(buffer,"MOVT %s", regname[Rn]);
\r
76 sprintf(buffer,"STS PR,%s", regname[Rn]);
\r
79 sprintf(buffer,"RTE");
\r
80 flags = DASMFLAG_STEP_OUT;
\r
86 sprintf(buffer, "?????? $%04X", opcode);
\r
89 sprintf(buffer, "?????? $%04X", opcode);
\r
92 sprintf(buffer, "?????? $%04X", opcode);
\r
95 sprintf(buffer, "?????? $%04X", opcode);
\r
98 sprintf(buffer, "MOV.B %s,@(R0,%s)", regname[Rm], regname[Rn]);
\r
101 sprintf(buffer, "MOV.W %s,@(R0,%s)", regname[Rm], regname[Rn]);
\r
104 sprintf(buffer, "MOV.L %s,@(R0,%s)", regname[Rm], regname[Rn]);
\r
107 sprintf(buffer, "MUL.L %s,%s", regname[Rm], regname[Rn]);
\r
110 sprintf(buffer, "?????? $%04X", opcode);
\r
113 sprintf(buffer, "?????? $%04X", opcode);
\r
116 sprintf(buffer, "?????? $%04X", opcode);
\r
119 sprintf(buffer, "?????? $%04X", opcode);
\r
122 sprintf(buffer, "MOV.B @(R0,%s),%s", regname[Rm], regname[Rn]);
\r
125 sprintf(buffer, "MOV.W @(R0,%s),%s", regname[Rm], regname[Rn]);
\r
128 sprintf(buffer, "MOV.L @(R0,%s),%s", regname[Rm], regname[Rn]);
\r
131 sprintf(buffer, "MAC.L @%s+,@%s+", regname[Rn], regname[Rm]);
\r
138 static UINT32 op0001(char *buffer, UINT32 pc, UINT16 opcode)
\r
140 sprintf(buffer, "MOV.L %s,@($%02X,%s)", regname[Rm], (opcode & 15) * 4, regname[Rn]);
\r
144 static UINT32 op0010(char *buffer, UINT32 pc, UINT16 opcode)
\r
146 switch (opcode & 15)
\r
149 sprintf(buffer, "MOV.B %s,@%s", regname[Rm], regname[Rn]);
\r
152 sprintf(buffer, "MOV.W %s,@%s", regname[Rm], regname[Rn]);
\r
155 sprintf(buffer, "MOV.L %s,@%s", regname[Rm], regname[Rn]);
\r
158 sprintf(buffer, "?????? $%04X", opcode);
\r
161 sprintf(buffer, "MOV.B %s,@-%s", regname[Rm], regname[Rn]);
\r
164 sprintf(buffer, "MOV.W %s,@-%s", regname[Rm], regname[Rn]);
\r
167 sprintf(buffer, "MOV.L %s,@-%s", regname[Rm], regname[Rn]);
\r
170 sprintf(buffer, "DIV0S %s,%s", regname[Rm], regname[Rn]);
\r
173 sprintf(buffer, "TST %s,%s", regname[Rm], regname[Rn]);
\r
176 sprintf(buffer, "AND %s,%s", regname[Rm], regname[Rn]);
\r
179 sprintf(buffer, "XOR %s,%s", regname[Rm], regname[Rn]);
\r
182 sprintf(buffer, "OR %s,%s", regname[Rm], regname[Rn]);
\r
185 sprintf(buffer, "CMP/STR %s,%s", regname[Rm], regname[Rn]);
\r
188 sprintf(buffer, "XTRCT %s,%s", regname[Rm], regname[Rn]);
\r
191 sprintf(buffer, "MULU.W %s,%s", regname[Rm], regname[Rn]);
\r
194 sprintf(buffer, "MULS.W %s,%s", regname[Rm], regname[Rn]);
\r
200 static UINT32 op0011(char *buffer, UINT32 pc, UINT16 opcode)
\r
202 switch (opcode & 15)
\r
205 sprintf(buffer, "CMP/EQ %s,%s", regname[Rm], regname[Rn]);
\r
208 sprintf(buffer, "?????? %s,%s", regname[Rm], regname[Rn]);
\r
211 sprintf(buffer, "CMP/HS %s,%s", regname[Rm], regname[Rn]);
\r
214 sprintf(buffer, "CMP/GE %s,%s", regname[Rm], regname[Rn]);
\r
217 sprintf(buffer, "DIV1 %s,%s", regname[Rm], regname[Rn]);
\r
220 sprintf(buffer, "DMULU.L %s,%s", regname[Rm], regname[Rn]);
\r
223 sprintf(buffer, "CMP/HI %s,%s", regname[Rm], regname[Rn]);
\r
226 sprintf(buffer, "CMP/GT %s,%s", regname[Rm], regname[Rn]);
\r
229 sprintf(buffer, "SUB %s,%s", regname[Rm], regname[Rn]);
\r
232 sprintf(buffer, "?????? %s,%s", regname[Rm], regname[Rn]);
\r
235 sprintf(buffer, "SUBC %s,%s", regname[Rm], regname[Rn]);
\r
238 sprintf(buffer, "SUBV %s,%s", regname[Rm], regname[Rn]);
\r
241 sprintf(buffer, "ADD %s,%s", regname[Rm], regname[Rn]);
\r
244 sprintf(buffer, "DMULS.L %s,%s", regname[Rm], regname[Rn]);
\r
247 sprintf(buffer, "ADDC %s,%s", regname[Rm], regname[Rn]);
\r
250 sprintf(buffer, "ADDV %s,%s", regname[Rm], regname[Rn]);
\r
256 static UINT32 op0100(char *buffer, UINT32 pc, UINT16 opcode)
\r
259 switch(opcode & 0x3F)
\r
262 sprintf(buffer, "SHLL %s", regname[Rn]);
\r
265 sprintf(buffer, "SHLR %s", regname[Rn]);
\r
268 sprintf(buffer, "STS.L MACH,@-%s", regname[Rn]);
\r
271 sprintf(buffer, "STC.L SR,@-%s", regname[Rn]);
\r
274 sprintf(buffer, "ROTL %s", regname[Rn]);
\r
277 sprintf(buffer, "ROTR %s", regname[Rn]);
\r
280 sprintf(buffer, "LDS.L @%s+,MACH", regname[Rn]);
\r
283 sprintf(buffer, "LDC.L @%s+,SR", regname[Rn]);
\r
286 sprintf(buffer, "SHLL2 %s", regname[Rn]);
\r
289 sprintf(buffer, "SHLR2 %s", regname[Rn]);
\r
292 sprintf(buffer, "LDS %s,MACH", regname[Rn]);
\r
295 sprintf(buffer, "JSR %s", regname[Rn]);
\r
296 flags = DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA(1);
\r
299 sprintf(buffer, "LDC %s,SR", regname[Rn]);
\r
302 sprintf(buffer, "DT %s", regname[Rn]);
\r
305 sprintf(buffer, "CMP/PZ %s", regname[Rn]);
\r
308 sprintf(buffer, "STS.L MACL,@-%s", regname[Rn]);
\r
311 sprintf(buffer, "STC.L GBR,@-%s", regname[Rn]);
\r
314 sprintf(buffer, "CMP/PL %s", regname[Rn]);
\r
317 sprintf(buffer, "LDS.L @%s+,MACL", regname[Rn]);
\r
320 sprintf(buffer, "LDC.L @%s+,GBR", regname[Rn]);
\r
323 sprintf(buffer, "SHLL8 %s", regname[Rn]);
\r
326 sprintf(buffer, "SHLR8 %s", regname[Rn]);
\r
329 sprintf(buffer, "LDS %s,MACL", regname[Rn]);
\r
332 sprintf(buffer, "TAS %s", regname[Rn]);
\r
335 sprintf(buffer, "LDC %s,GBR", regname[Rn]);
\r
338 sprintf(buffer, "SHAL %s", regname[Rn]);
\r
341 sprintf(buffer, "SHAR %s", regname[Rn]);
\r
344 sprintf(buffer, "STS.L PR,@-%s", regname[Rn]);
\r
347 sprintf(buffer, "STC.L VBR,@-%s", regname[Rn]);
\r
350 sprintf(buffer, "ROTCL %s", regname[Rn]);
\r
353 sprintf(buffer, "ROTCR %s", regname[Rn]);
\r
356 sprintf(buffer, "LDS.L @%s+,PR", regname[Rn]);
\r
359 sprintf(buffer, "LDC.L @%s+,VBR", regname[Rn]);
\r
362 sprintf(buffer, "SHLL16 %s", regname[Rn]);
\r
365 sprintf(buffer, "SHLR16 %s", regname[Rn]);
\r
368 sprintf(buffer, "LDS %s,PR", regname[Rn]);
\r
371 sprintf(buffer, "JMP %s", regname[Rn]);
\r
374 sprintf(buffer, "LDC %s,VBR", regname[Rn]);
\r
377 if ((opcode & 15) == 15)
\r
378 sprintf(buffer, "MAC.W @%s+,@%s+", regname[Rm], regname[Rn]);
\r
380 sprintf(buffer, "?????? $%04X", opcode);
\r
385 static UINT32 op0101(char *buffer, UINT32 pc, UINT16 opcode)
\r
387 sprintf(buffer, "MOV.L @($%02X,%s),%s", (opcode & 15) * 4, regname[Rm], regname[Rn]);
\r
391 static UINT32 op0110(char *buffer, UINT32 pc, UINT16 opcode)
\r
394 switch(opcode & 0xF)
\r
397 sprintf(buffer, "MOV.B @%s,%s", regname[Rm], regname[Rn]);
\r
400 sprintf(buffer, "MOV.W @%s,%s", regname[Rm], regname[Rn]);
\r
403 sprintf(buffer, "MOV.L @%s,%s", regname[Rm], regname[Rn]);
\r
406 sprintf(buffer, "MOV %s,%s", regname[Rm], regname[Rn]);
\r
409 sprintf(buffer, "MOV.B @%s+,%s", regname[Rm], regname[Rn]);
\r
412 sprintf(buffer, "MOV.W @%s+,%s", regname[Rm], regname[Rn]);
\r
415 sprintf(buffer, "MOV.L @%s+,%s", regname[Rm], regname[Rn]);
\r
418 sprintf(buffer, "NOT %s,%s", regname[Rm], regname[Rn]);
\r
421 sprintf(buffer, "SWAP.B %s,%s", regname[Rm], regname[Rn]);
\r
424 sprintf(buffer, "SWAP.W %s,%s", regname[Rm], regname[Rn]);
\r
427 sprintf(buffer, "NEGC %s,%s", regname[Rm], regname[Rn]);
\r
430 sprintf(buffer, "NEG %s,%s", regname[Rm], regname[Rn]);
\r
433 sprintf(buffer, "EXTU.B %s,%s", regname[Rm], regname[Rn]);
\r
436 sprintf(buffer, "EXTU.W %s,%s", regname[Rm], regname[Rn]);
\r
439 sprintf(buffer, "EXTS.B %s,%s", regname[Rm], regname[Rn]);
\r
442 sprintf(buffer, "EXTS.W %s,%s", regname[Rm], regname[Rn]);
\r
448 static UINT32 op0111(char *buffer, UINT32 pc, UINT16 opcode)
\r
450 sprintf(buffer, "ADD #$%02X,%s", opcode & 0xff, regname[Rn]);
\r
454 static UINT32 op1000(char *buffer, UINT32 pc, UINT16 opcode)
\r
456 switch((opcode >> 8) & 15)
\r
459 sprintf(buffer, "MOV.B R0,@($%02X,%s)", (opcode & 15), regname[Rm]);
\r
462 sprintf(buffer, "MOV.W R0,@($%02X,%s)", (opcode & 15) * 2, regname[Rm]);
\r
465 sprintf(buffer, "MOV.B @($%02X,%s),R0", (opcode & 15), regname[Rm]);
\r
468 sprintf(buffer, "MOV.W @($%02X,%s),R0", (opcode & 15), regname[Rm]);
\r
471 sprintf(buffer, "CMP/EQ #$%02X,R0", (opcode & 0xff));
\r
474 sprintf(buffer, "BT $%08x", pc + SIGNX8(opcode & 0xff) * 2 + 2);
\r
477 sprintf(buffer, "BF $%08x", pc + SIGNX8(opcode & 0xff) * 2 + 2);
\r
480 sprintf(buffer, "BTS $%08x", pc + SIGNX8(opcode & 0xff) * 2 + 2);
\r
483 sprintf(buffer, "BFS $%08x", pc + SIGNX8(opcode & 0xff) * 2 + 2);
\r
486 sprintf(buffer, "invalid $%04X", opcode);
\r
491 static UINT32 op1001(char *buffer, UINT32 pc, UINT16 opcode)
\r
493 sprintf(buffer, "MOV.W @($%02X,PC),%s ; @$%08x", (opcode & 0xff) * 2, regname[Rn],
\r
494 pc + (opcode & 0xff) * 2 + 2);
\r
498 static UINT32 op1010(char *buffer, UINT32 pc, UINT16 opcode)
\r
500 sprintf(buffer, "BRA $%08x", SIGNX12(opcode & 0xfff) * 2 + pc + 2);
\r
504 static UINT32 op1011(char *buffer, UINT32 pc, UINT16 opcode)
\r
506 sprintf(buffer, "BSR $%08x", SIGNX12(opcode & 0xfff) * 2 + pc + 2);
\r
507 return DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA(1);
\r
510 static UINT32 op1100(char *buffer, UINT32 pc, UINT16 opcode)
\r
513 switch((opcode >> 8) & 15)
\r
516 sprintf(buffer, "MOV.B R0,@($%02X,GBR)", opcode & 0xff);
\r
519 sprintf(buffer, "MOV.W R0,@($%04X,GBR)", (opcode & 0xff) * 2);
\r
522 sprintf(buffer, "MOV.L R0,@($%04X,GBR)", (opcode & 0xff) * 4);
\r
525 sprintf(buffer, "TRAPA #$%02X", opcode & 0xff);
\r
526 flags = DASMFLAG_STEP_OVER;
\r
529 sprintf(buffer, "MOV.B @($%02X,GBR),R0", opcode & 0xff);
\r
532 sprintf(buffer, "MOV.W @($%04X,GBR),R0", (opcode & 0xff) * 2);
\r
535 sprintf(buffer, "MOV.L @($%04X,GBR),R0", (opcode & 0xff) * 4);
\r
538 sprintf(buffer, "MOVA @($%04X,PC),R0 ; @$%08x", (opcode & 0xff) * 4,
\r
539 ((pc + 2) & ~3) + (opcode & 0xff) * 4);
\r
542 sprintf(buffer, "TST #$%02X,R0", opcode & 0xff);
\r
545 sprintf(buffer, "AND #$%02X,R0", opcode & 0xff);
\r
548 sprintf(buffer, "XOR #$%02X,R0", opcode & 0xff);
\r
551 sprintf(buffer, "OR #$%02X,R0", opcode & 0xff);
\r
554 sprintf(buffer, "TST.B #$%02X,@(R0,GBR)", opcode & 0xff);
\r
557 sprintf(buffer, "AND.B #$%02X,@(R0,GBR)", opcode & 0xff);
\r
560 sprintf(buffer, "XOR.B #$%02X,@(R0,GBR)", opcode & 0xff);
\r
563 sprintf(buffer, "OR.B #$%02X,@(R0,GBR)", opcode & 0xff);
\r
569 static UINT32 op1101(char *buffer, UINT32 pc, UINT16 opcode)
\r
571 sprintf(buffer, "MOV.L @($%02X,PC),%s ; @$%08x", (opcode & 0xff) * 4, regname[Rn],
\r
572 (pc + (opcode & 0xff) * 4 + 2) & ~3);
\r
576 static UINT32 op1110(char *buffer, UINT32 pc, UINT16 opcode)
\r
578 sprintf(buffer, "MOV #$%02X,%s", (opcode & 0xff), regname[Rn]);
\r
582 static UINT32 op1111(char *buffer, UINT32 pc, UINT16 opcode)
\r
584 sprintf(buffer, "unknown $%04X", opcode);
\r
588 unsigned DasmSH2(char *buffer, unsigned pc, UINT16 opcode)
\r
594 switch((opcode >> 12) & 15)
\r
596 case 0: flags = op0000(buffer,pc,opcode); break;
\r
597 case 1: flags = op0001(buffer,pc,opcode); break;
\r
598 case 2: flags = op0010(buffer,pc,opcode); break;
\r
599 case 3: flags = op0011(buffer,pc,opcode); break;
\r
600 case 4: flags = op0100(buffer,pc,opcode); break;
\r
601 case 5: flags = op0101(buffer,pc,opcode); break;
\r
602 case 6: flags = op0110(buffer,pc,opcode); break;
\r
603 case 7: flags = op0111(buffer,pc,opcode); break;
\r
604 case 8: flags = op1000(buffer,pc,opcode); break;
\r
605 case 9: flags = op1001(buffer,pc,opcode); break;
\r
606 case 10: flags = op1010(buffer,pc,opcode); break;
\r
607 case 11: flags = op1011(buffer,pc,opcode); break;
\r
608 case 12: flags = op1100(buffer,pc,opcode); break;
\r
609 case 13: flags = op1101(buffer,pc,opcode); break;
\r
610 case 14: flags = op1110(buffer,pc,opcode); break;
\r
611 default: flags = op1111(buffer,pc,opcode); break;
\r
613 return 0;//2 | flags | DASMFLAG_SUPPORTED;
\r
618 #define swab32(x) (((x) << 24) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) | ((x) >> 24))
\r
619 #define swab16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
\r
621 int main(int argc, char *argv[])
\r
629 if (argv[1] == NULL) {
\r
630 printf("usage\n%s <file>\n", argv[0]);
\r
634 f = fopen(argv[1], "rb");
\r
636 fprintf(stderr, "can't open %s\n", argv[1]);
\r
640 for (pc = 0x140;; pc += 2)
\r
642 fseek(f, pc, SEEK_SET);
\r
644 ret = fread(&op, 1, sizeof(op), f);
\r
645 if (ret != sizeof(op))
\r
648 DasmSH2(buff, pc, swab16(op));
\r
649 printf("%06x %04x %s\n", pc, swab16(op), buff);
\r