]> Shamusworld >> Repos - virtualjaguar/blob - src/jagdasm.cpp
Support for new timer based execution
[virtualjaguar] / src / jagdasm.cpp
1 #include "jaguar.h"
2
3 #define ROPCODE(a) JaguarReadWord(a)
4
5 uint8 convert_zero[32] =
6 { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 };
7
8 char * condition[32] =
9 {
10         "",
11         "nz,",
12         "z,",
13         "???,",
14         "nc,",
15         "nc nz,",
16         "nc z,",
17         "???,",
18
19         "c,",
20         "c nz,",
21         "c z,",
22         "???,",
23         "???,",
24         "???,",
25         "???,",
26         "???,",
27
28         "???,",
29         "???,",
30         "???,",
31         "???,",
32         "nn,",
33         "nn nz,",
34         "nn z,",
35         "???,",
36
37         "n,",
38         "n nz,",
39         "n z,",
40         "???,",
41         "???,",
42         "???,",
43         "???,",
44         "never,"
45 };
46         
47
48
49 char * signed_16bit(INT16 val)
50 {
51         static char temp[10];
52
53         if (val < 0)
54                 sprintf(temp, "-$%X", -val);
55         else
56                 sprintf(temp, "$%X", val);
57
58         return temp;
59 }
60
61 unsigned dasmjag(int dsp_type, char * buffer, unsigned pc)
62 {
63         int op = ROPCODE(pc);
64         int reg1 = (op >> 5) & 31;
65         int reg2 = op & 31;
66         int size = 2;
67         
68         pc += 2;
69         switch (op >> 10)
70         {
71                 case 0:         sprintf(buffer, "ADD     R%02d,R%02d", reg1, reg2);                                     break;
72                 case 1:         sprintf(buffer, "ADDC    R%02d,R%02d", reg1, reg2);                                     break;
73                 case 2:         sprintf(buffer, "ADDQ    $%X,R%02d", convert_zero[reg1], reg2); break;
74                 case 3:         sprintf(buffer, "ADDQT   $%X,R%02d", convert_zero[reg1], reg2); break;
75                 case 4:         sprintf(buffer, "SUB     R%02d,R%02d", reg1, reg2);                                     break;
76                 case 5:         sprintf(buffer, "SUBC    R%02d,R%02d", reg1, reg2);                                     break;
77                 case 6:         sprintf(buffer, "SUBQ    $%X,R%02d", convert_zero[reg1], reg2); break;
78                 case 7:         sprintf(buffer, "SUBQT   $%X,R%02d", convert_zero[reg1], reg2); break;
79                 case 8:         sprintf(buffer, "NEG     R%02d", reg2);                                                 break;
80                 case 9:         sprintf(buffer, "AND     R%02d,R%02d", reg1, reg2);                                     break;
81                 case 10:        sprintf(buffer, "OR      R%02d,R%02d", reg1, reg2);                                     break;
82                 case 11:        sprintf(buffer, "XOR     R%02d,R%02d", reg1, reg2);                                     break;
83                 case 12:        sprintf(buffer, "NOT     R%02d", reg2);                                                 break;
84                 case 13:        sprintf(buffer, "BTST    $%X,R%02d", reg1, reg2);                                       break;
85                 case 14:        sprintf(buffer, "BSET    $%X,R%02d", reg1, reg2);                                       break;
86                 case 15:        sprintf(buffer, "BCLR    $%X,R%02d", reg1, reg2);                                       break;
87                 case 16:        sprintf(buffer, "MULT    R%02d,R%02d", reg1, reg2);                                     break;
88                 case 17:        sprintf(buffer, "IMULT   R%02d,R%02d", reg1, reg2);                                     break;
89                 case 18:        sprintf(buffer, "IMULTN  R%02d,R%02d", reg1, reg2);                                     break;
90                 case 19:        sprintf(buffer, "RESMAC  R%02d", reg2);                                                 break;
91                 case 20:        sprintf(buffer, "IMACN   R%02d,R%02d", reg1, reg2);                                     break;
92                 case 21:        sprintf(buffer, "DIV     R%02d,R%02d", reg1, reg2);                                     break;
93                 case 22:        sprintf(buffer, "ABS     R%02d", reg2);                                                 break;
94                 case 23:        sprintf(buffer, "SH      R%02d,R%02d", reg1, reg2);                                     break;
95                 case 24:        sprintf(buffer, "SHLQ    $%X,R%02d", 32 - convert_zero[reg1], reg2);    break;
96                 case 25:        sprintf(buffer, "SHRQ    $%X,R%02d", convert_zero[reg1], reg2); break;
97                 case 26:        sprintf(buffer, "SHA     R%02d,R%02d", reg1, reg2);                                     break;
98                 case 27:        sprintf(buffer, "SHARQ   $%X,R%02d", convert_zero[reg1], reg2); break;
99                 case 28:        sprintf(buffer, "ROR     R%02d,R%02d", reg1, reg2);                                     break;
100                 case 29:        sprintf(buffer, "RORQ    $%X,R%02d", convert_zero[reg1], reg2); break;
101                 case 30:        sprintf(buffer, "CMP     R%02d,R%02d", reg1, reg2);                                     break;
102                 case 31:        sprintf(buffer, "CMPQ    %s,R%02d", signed_16bit((INT16)(reg1 << 11) >> 11), reg2);break;
103                 case 32:        if (dsp_type == JAGUAR_GPU)
104                                                 sprintf(buffer, "SAT8    R%02d", reg2);
105                                         else
106                                                 sprintf(buffer, "SUBQMOD $%X,R%02d", convert_zero[reg1], reg2);
107                                         break;
108                 case 33:        if (dsp_type == JAGUAR_GPU)
109                                                 sprintf(buffer, "SAT16   R%02d", reg2);
110                                         else
111                                                 sprintf(buffer, "SAT16S  R%02d", reg2);
112                                         break;
113                 case 34:        sprintf(buffer, "MOVE    R%02d,R%02d", reg1, reg2);                                     break;
114                 case 35:        sprintf(buffer, "MOVEQ   %d,R%02d", reg1, reg2);                                        break;
115                 case 36:        sprintf(buffer, "MOVETA  R%02d,R%02d", reg1, reg2);                                     break;
116                 case 37:        sprintf(buffer, "MOVEFA  R%02d,R%02d", reg1, reg2);                                     break;
117                 case 38:        sprintf(buffer, "MOVEI   $%08X,R%02d", ROPCODE(pc) | (ROPCODE(pc+2)<<16), reg2); size = 6; break;
118                 case 39:        sprintf(buffer, "LOADB   (R%02d),R%02d", reg1, reg2);                                   break;
119                 case 40:        sprintf(buffer, "LOADW   (R%02d),R%02d", reg1, reg2);                                   break;
120                 case 41:        sprintf(buffer, "LOAD    (R%02d),R%02d", reg1, reg2);                                   break;
121                 case 42:        if (dsp_type == JAGUAR_GPU)
122                                                 sprintf(buffer, "LOADP   (R%02d),R%02d", reg1, reg2);
123                                         else
124                                                 sprintf(buffer, "SAT32S  R%02d", reg2);
125                                         break;
126                 case 43:        sprintf(buffer, "LOAD    (R14+$%X),R%02d", convert_zero[reg1]*4, reg2);break;
127                 case 44:        sprintf(buffer, "LOAD    (R15+$%X),R%02d", convert_zero[reg1]*4, reg2);break;
128                 case 45:        sprintf(buffer, "STOREB  R%02d,(R%02d)", reg2, reg1);                           break;
129                 case 46:        sprintf(buffer, "STOREW  R%02d,(R%02d)", reg2, reg1);                           break;
130                 case 47:        sprintf(buffer, "STORE   R%02d,(R%02d)", reg2, reg1);                                   break;
131                 case 48:        if (dsp_type == JAGUAR_GPU)
132                                                 sprintf(buffer, "STOREP  R%02d,(R%02d)", reg2, reg1);
133                                         else
134                                                 sprintf(buffer, "MIRROR  R%02d", reg2);
135                                         break;
136                 case 49:        sprintf(buffer, "STORE   R%02d,(R14+$%X)", reg2, convert_zero[reg1]*4);break;
137                 case 50:        sprintf(buffer, "STORE   R%02d,(R15+$%X)", reg2, convert_zero[reg1]*4);break;
138                 case 51:        sprintf(buffer, "MOVE    PC,R%02d", reg2);                                                      break;
139                 case 52:        sprintf(buffer, "JUMP    %s(R%02d)", condition[reg2], reg1);                    break;
140                 case 53:        sprintf(buffer, "JR      %s%08X", condition[reg2], pc + ((INT8)(reg1 << 3) >> 2)); break;
141                 case 54:        sprintf(buffer, "MMULT   R%02d,R%02d", reg1, reg2);                                     break;
142                 case 55:        sprintf(buffer, "MTOI    R%02d,R%02d", reg1, reg2);                                     break;
143                 case 56:        sprintf(buffer, "NORMI   R%02d,R%02d", reg1, reg2);                                     break;
144                 case 57:        sprintf(buffer, "NOP");                                                                                 break;
145                 case 58:        sprintf(buffer, "LOAD    (R14+R%02d),R%02d", reg1, reg2);                               break;
146                 case 59:        sprintf(buffer, "LOAD    (R15+R%02d),R%02d", reg1, reg2);                               break;
147                 case 60:        sprintf(buffer, "STORE   R%02d,(R14+R%02d)", reg2, reg1);                               break;
148                 case 61:        sprintf(buffer, "STORE   R%02d,(R15+R%02d)", reg2, reg1);                               break;
149                 case 62:        if (dsp_type == JAGUAR_GPU)
150                                                 sprintf(buffer, "SAT24   R%02d", reg2);
151                                         else
152                                                 sprintf(buffer, "illegal");
153                                         break;
154                 case 63:        if (dsp_type == JAGUAR_GPU)
155                                                 sprintf(buffer, (reg1 ? "UNPACK  R%02d" : "PACK    R%02d"), reg2);
156                                         else
157                                                 sprintf(buffer, "ADDQMOD $%X,R%02d", convert_zero[reg1], reg2);
158                                         break;
159         }
160         sprintf(buffer,"%-24s (%04X)", buffer, op);
161
162         return size;
163 }