platform ps2, handle audio similar to psp
[picodrive.git] / sh2 / mame / sh2dasm.c
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   @($%02X,PC),%s  ; @$%08x", (opcode & 0xff) * 2, regname[Rn],\r
494                 pc + (opcode & 0xff) * 2 + 2);\r
495         return 0;\r
496 }\r
497 \r
498 static UINT32 op1010(char *buffer, UINT32 pc, UINT16 opcode)\r
499 {\r
500         sprintf(buffer, "BRA     $%08x", SIGNX12(opcode & 0xfff) * 2 + pc + 2);\r
501         return 0;\r
502 }\r
503 \r
504 static UINT32 op1011(char *buffer, UINT32 pc, UINT16 opcode)\r
505 {\r
506         sprintf(buffer, "BSR     $%08x", SIGNX12(opcode & 0xfff) * 2 + pc + 2);\r
507         return DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA(1);\r
508 }\r
509 \r
510 static UINT32 op1100(char *buffer, UINT32 pc, UINT16 opcode)\r
511 {\r
512         UINT32 flags = 0;\r
513         switch((opcode >> 8) & 15)\r
514         {\r
515         case  0:\r
516                 sprintf(buffer, "MOV.B   R0,@($%02X,GBR)", opcode & 0xff);\r
517                 break;\r
518         case  1:\r
519                 sprintf(buffer, "MOV.W   R0,@($%04X,GBR)", (opcode & 0xff) * 2);\r
520                 break;\r
521         case  2:\r
522                 sprintf(buffer, "MOV.L   R0,@($%04X,GBR)", (opcode & 0xff) * 4);\r
523                 break;\r
524         case  3:\r
525                 sprintf(buffer, "TRAPA   #$%02X", opcode & 0xff);\r
526                 flags = DASMFLAG_STEP_OVER;\r
527                 break;\r
528         case  4:\r
529                 sprintf(buffer, "MOV.B   @($%02X,GBR),R0", opcode & 0xff);\r
530                 break;\r
531         case  5:\r
532                 sprintf(buffer, "MOV.W   @($%04X,GBR),R0", (opcode & 0xff) * 2);\r
533                 break;\r
534         case  6:\r
535                 sprintf(buffer, "MOV.L   @($%04X,GBR),R0", (opcode & 0xff) * 4);\r
536                 break;\r
537         case  7:\r
538                 sprintf(buffer, "MOVA    @($%04X,PC),R0  ; @$%08x", (opcode & 0xff) * 4,\r
539                         ((pc + 2) & ~3) + (opcode & 0xff) * 4);\r
540                 break;\r
541         case  8:\r
542                 sprintf(buffer, "TST     #$%02X,R0", opcode & 0xff);\r
543                 break;\r
544         case  9:\r
545                 sprintf(buffer, "AND     #$%02X,R0", opcode & 0xff);\r
546                 break;\r
547         case 10:\r
548                 sprintf(buffer, "XOR     #$%02X,R0", opcode & 0xff);\r
549                 break;\r
550         case 11:\r
551                 sprintf(buffer, "OR      #$%02X,R0", opcode & 0xff);\r
552                 break;\r
553         case 12:\r
554                 sprintf(buffer, "TST.B   #$%02X,@(R0,GBR)", opcode & 0xff);\r
555                 break;\r
556         case 13:\r
557                 sprintf(buffer, "AND.B   #$%02X,@(R0,GBR)", opcode & 0xff);\r
558                 break;\r
559         case 14:\r
560                 sprintf(buffer, "XOR.B   #$%02X,@(R0,GBR)", opcode & 0xff);\r
561                 break;\r
562         case 15:\r
563                 sprintf(buffer, "OR.B    #$%02X,@(R0,GBR)", opcode & 0xff);\r
564                 break;\r
565         }\r
566         return flags;\r
567 }\r
568 \r
569 static UINT32 op1101(char *buffer, UINT32 pc, UINT16 opcode)\r
570 {\r
571         sprintf(buffer, "MOV.L   @($%02X,PC),%s  ; @$%08x", (opcode & 0xff) * 4, regname[Rn],\r
572                 (pc + (opcode & 0xff) * 4 + 2) & ~3);\r
573         return 0;\r
574 }\r
575 \r
576 static UINT32 op1110(char *buffer, UINT32 pc, UINT16 opcode)\r
577 {\r
578         sprintf(buffer, "MOV     #$%02X,%s", (opcode & 0xff), regname[Rn]);\r
579         return 0;\r
580 }\r
581 \r
582 static UINT32 op1111(char *buffer, UINT32 pc, UINT16 opcode)\r
583 {\r
584         sprintf(buffer, "unknown $%04X", opcode);\r
585         return 0;\r
586 }\r
587 \r
588 unsigned DasmSH2(char *buffer, unsigned pc, UINT16 opcode)\r
589 {\r
590         UINT32 flags;\r
591 \r
592         pc += 2;\r
593 \r
594         switch((opcode >> 12) & 15)\r
595         {\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
612         }\r
613         return 0;//2 | flags | DASMFLAG_SUPPORTED;\r
614 }\r
615 \r
616 #if 0\r
617 \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
620 \r
621 int main(int argc, char *argv[])\r
622 {\r
623         unsigned short op;\r
624         char buff[256];\r
625         unsigned pc;\r
626         FILE *f;\r
627         int ret;\r
628 \r
629         if (argv[1] == NULL) {\r
630                 printf("usage\n%s <file>\n", argv[0]);\r
631                 return 1;\r
632         }\r
633 \r
634         f = fopen(argv[1], "rb");\r
635         if (f == NULL) {\r
636                 fprintf(stderr, "can't open %s\n", argv[1]);\r
637                 return 1;\r
638         }\r
639 \r
640         for (pc = 0x140;; pc += 2)\r
641         {\r
642                 fseek(f, pc, SEEK_SET);\r
643 \r
644                 ret = fread(&op, 1, sizeof(op), f);\r
645                 if (ret != sizeof(op))\r
646                         break;\r
647 \r
648                 DasmSH2(buff, pc, swab16(op));\r
649                 printf("%06x %04x %s\n", pc, swab16(op), buff);\r
650         }\r
651 \r
652         fclose(f);\r
653         return 0;\r
654 }\r
655 \r
656 #endif\r