4 typedef signed char INT8;
5 typedef signed short INT16;
6 typedef signed int INT32;
7 typedef unsigned int UINT32;
8 typedef unsigned short UINT16;
9 typedef unsigned char UINT8;
12 unsigned int p32x_sh2_read8(unsigned int a, int id);
13 unsigned int p32x_sh2_read16(unsigned int a, int id);
14 unsigned int p32x_sh2_read32(unsigned int a, int id);
15 void p32x_sh2_write8(unsigned int a, unsigned int d, int id);
16 void p32x_sh2_write16(unsigned int a, unsigned int d, int id);
17 void p32x_sh2_write32(unsigned int a, unsigned int d, int id);
19 #define RB(a) p32x_sh2_read8(a,sh2->is_slave)
20 #define RW(a) p32x_sh2_read16(a,sh2->is_slave)
21 #define RL(a) p32x_sh2_read32(a,sh2->is_slave)
22 #define WB(a,d) p32x_sh2_write8(a,d,sh2->is_slave)
23 #define WW(a,d) p32x_sh2_write16(a,d,sh2->is_slave)
24 #define WL(a,d) p32x_sh2_write32(a,d,sh2->is_slave)
26 // some stuff from sh2comn.h
35 #define FLAGS (M|Q|I|S|T)
37 #define Rn ((opcode>>8)&15)
38 #define Rm ((opcode>>4)&15)
42 void sh2_reset(SH2 *sh2)
45 void *save_irqcallback;
47 save_irqcallback = sh2->irq_callback;
48 save_is_slave = sh2->is_slave;
50 memset(sh2, 0, sizeof(SH2));
52 sh2->is_slave = save_is_slave;
53 sh2->irq_callback = save_irqcallback;
59 sh2->internal_irq_level = -1;
62 /* Execute cycles - returns number of cycles actually run */
63 int sh2_execute(SH2 *sh2_, int cycles)
74 opcode = RW(sh2->delay);
84 switch (opcode & ( 15 << 12))
86 case 0<<12: op0000(opcode); break;
87 case 1<<12: op0001(opcode); break;
88 case 2<<12: op0010(opcode); break;
89 case 3<<12: op0011(opcode); break;
90 case 4<<12: op0100(opcode); break;
91 case 5<<12: op0101(opcode); break;
92 case 6<<12: op0110(opcode); break;
93 case 7<<12: op0111(opcode); break;
94 case 8<<12: op1000(opcode); break;
95 case 9<<12: op1001(opcode); break;
96 case 10<<12: op1010(opcode); break;
97 case 11<<12: op1011(opcode); break;
98 case 12<<12: op1100(opcode); break;
99 case 13<<12: op1101(opcode); break;
100 case 14<<12: op1110(opcode); break;
101 default: op1111(opcode); break;
104 if (sh2->test_irq && !sh2->delay)
106 if (sh2->pending_irq)
107 sh2_irl_irq(sh2, sh2->pending_irq);
112 while (sh2_icount > 0);
114 return cycles - sh2_icount;
117 void sh2_init(SH2 *sh2, int is_slave)
119 memset(sh2, 0, sizeof(*sh2));
120 sh2->is_slave = is_slave;
123 void sh2_irl_irq(SH2 *sh2, int level)
127 sh2->pending_irq = level;
129 if (level <= ((sh2->sr >> 4) & 0x0f))
133 sh2->irq_callback(sh2->is_slave, level);
134 vector = 64 + level/2;
137 WL(sh2->r[15], sh2->sr); /* push SR onto stack */
139 WL(sh2->r[15], sh2->pc); /* push PC onto stack */
141 /* set I flags in SR */
142 sh2->sr = (sh2->sr & ~I) | (level << 4);
145 sh2->pc = RL(sh2->vbr + vector * 4);
147 /* 13 cycles at best */