Previous 199869 Revisions Next

r29566 Saturday 12th April, 2014 at 15:03:34 UTC by Wilbert Pol
sh2.c: Modernised cpu core.  [Wilbert Pol]
[src/emu/cpu]cpu.mak
[src/emu/cpu/sh2]sh2.c sh2.h sh2comn.c sh2comn.h sh2drc.c sh2fe.c
[src/emu/machine]saturn.c
[src/mame/drivers]coolridr.c cps3.c deco_mlc.c psikyosh.c stv.c suprnova.c
[src/mame/includes]cps3.h deco_mlc.h psikyosh.h stv.h suprnova.h
[src/mess/drivers]saturn.c
[src/mess/machine]mega32x.c mega32x.h

trunk/src/emu/cpu/sh2/sh2comn.c
r29565r29566
1717
1818#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
1919
20INLINE sh2_state *GET_SH2(device_t *dev)
21{
22   if (dev->machine().options().drc()) {
23   return *(sh2_state **)downcast<legacy_cpu_device *>(dev)->token();
24   } else {
25   return (sh2_state *)downcast<legacy_cpu_device *>(dev)->token();
26   }
27}
28
2920static const int div_tab[4] = { 3, 5, 7, 0 };
3021
31INLINE UINT32 RL(sh2_state *sh2, offs_t A)
32{
33   if (A >= 0xe0000000) /* I/O */
34      return sh2_internal_r(*sh2->internal, (A & 0x1fc)>>2, 0xffffffff);
3522
36   if (A >= 0xc0000000) /* Cache Data Array */
37      return sh2->program->read_dword(A);
38
39   /*  0x60000000 Cache Address Data Array */
40
41   if (A >= 0x40000000) /* Cache Associative Purge Area */
42      return 0xa5a5a5a5;
43
44   /* 0x20000000 no Cache */
45   /* 0x00000000 read thru Cache if CE bit is 1 */
46   return sh2->program->read_dword(A & AM);
47}
48
49INLINE void WL(sh2_state *sh2, offs_t A, UINT32 V)
23void sh2_device::sh2_timer_resync()
5024{
51   if (A >= 0xe0000000) /* I/O */
52   {
53      sh2_internal_w(*sh2->internal, (A & 0x1fc)>>2, V, 0xffffffff);
54      return;
55   }
25   int divider = div_tab[(m_m[5] >> 8) & 3];
26   UINT64 cur_time = total_cycles();
27   UINT64 add = (cur_time - m_frc_base) >> divider;
5628
57   if (A >= 0xc0000000) /* Cache Data Array */
58   {
59      sh2->program->write_dword(A,V);
60      return;
61   }
62
63   /*  0x60000000 Cache Address Data Array */
64
65   if (A >= 0x40000000) /* Cache Associative Purge Area */
66      return;
67
68   /* 0x20000000 no Cache */
69   /* 0x00000000 read thru Cache if CE bit is 1 */
70   sh2->program->write_dword(A & AM,V);
71}
72
73static void sh2_timer_resync(sh2_state *sh2)
74{
75   int divider = div_tab[(sh2->m[5] >> 8) & 3];
76   UINT64 cur_time = sh2->device->total_cycles();
77   UINT64 add = (cur_time - sh2->frc_base) >> divider;
78
7929   if (add > 0)
8030   {
8131      if(divider)
82         sh2->frc += add;
32         m_frc += add;
8333
84      sh2->frc_base = cur_time;
34      m_frc_base = cur_time;
8535   }
8636}
8737
88static void sh2_timer_activate(sh2_state *sh2)
38void sh2_device::sh2_timer_activate()
8939{
9040   int max_delta = 0xfffff;
9141   UINT16 frc;
9242
93   sh2->timer->adjust(attotime::never);
43   m_timer->adjust(attotime::never);
9444
95   frc = sh2->frc;
96   if(!(sh2->m[4] & OCFA)) {
97      UINT16 delta = sh2->ocra - frc;
45   frc = m_frc;
46   if(!(m_m[4] & OCFA)) {
47      UINT16 delta = m_ocra - frc;
9848      if(delta < max_delta)
9949         max_delta = delta;
10050   }
10151
102   if(!(sh2->m[4] & OCFB) && (sh2->ocra <= sh2->ocrb || !(sh2->m[4] & 0x010000))) {
103      UINT16 delta = sh2->ocrb - frc;
52   if(!(m_m[4] & OCFB) && (m_ocra <= m_ocrb || !(m_m[4] & 0x010000))) {
53      UINT16 delta = m_ocrb - frc;
10454      if(delta < max_delta)
10555         max_delta = delta;
10656   }
10757
108   if(!(sh2->m[4] & OVF) && !(sh2->m[4] & 0x010000)) {
58   if(!(m_m[4] & OVF) && !(m_m[4] & 0x010000)) {
10959      int delta = 0x10000 - frc;
11060      if(delta < max_delta)
11161         max_delta = delta;
11262   }
11363
11464   if(max_delta != 0xfffff) {
115      int divider = div_tab[(sh2->m[5] >> 8) & 3];
65      int divider = div_tab[(m_m[5] >> 8) & 3];
11666      if(divider) {
11767         max_delta <<= divider;
118         sh2->frc_base = sh2->device->total_cycles();
119         sh2->timer->adjust(sh2->device->cycles_to_attotime(max_delta));
68         m_frc_base = total_cycles();
69         m_timer->adjust(cycles_to_attotime(max_delta));
12070      } else {
121         logerror("SH2.%s: Timer event in %d cycles of external clock", sh2->device->tag(), max_delta);
71         logerror("SH2.%s: Timer event in %d cycles of external clock", tag(), max_delta);
12272      }
12373   }
12474}
12575
126
127static TIMER_CALLBACK( sh2_timer_callback )
76TIMER_CALLBACK_MEMBER( sh2_device::sh2_timer_callback )
12877{
129   sh2_state *sh2 = (sh2_state *)ptr;
13078   UINT16 frc;
13179
132   sh2_timer_resync(sh2);
80   sh2_timer_resync();
13381
134   frc = sh2->frc;
82   frc = m_frc;
13583
136   if(frc == sh2->ocrb)
137      sh2->m[4] |= OCFB;
84   if(frc == m_ocrb)
85      m_m[4] |= OCFB;
13886
13987   if(frc == 0x0000)
140      sh2->m[4] |= OVF;
88      m_m[4] |= OVF;
14189
142   if(frc == sh2->ocra)
90   if(frc == m_ocra)
14391   {
144      sh2->m[4] |= OCFA;
92      m_m[4] |= OCFA;
14593
146      if(sh2->m[4] & 0x010000)
147         sh2->frc = 0;
94      if(m_m[4] & 0x010000)
95         m_frc = 0;
14896   }
14997
150   sh2_recalc_irq(sh2);
151   sh2_timer_activate(sh2);
98   sh2_recalc_irq();
99   sh2_timer_activate();
152100}
153101
154102
r29565r29566
176124
177125
178126
179void sh2_notify_dma_data_available(device_t *device)
127void sh2_device::sh2_notify_dma_data_available()
180128{
181   sh2_state *sh2 = GET_SH2(device);
182129   //printf("call notify\n");
183130
184131   for (int dma=0;dma<2;dma++)
185132   {
186      //printf("sh2->dma_timer_active[dma] %04x\n",sh2->dma_timer_active[dma]);
133      //printf("m_dma_timer_active[dma] %04x\n",m_dma_timer_active[dma]);
187134
188      if (sh2->dma_timer_active[dma]==2) // 2 = stalled
135      if (m_dma_timer_active[dma]==2) // 2 = stalled
189136      {
190137      //  printf("resuming stalled dma\n");
191         sh2->dma_timer_active[dma]=1;
192         sh2->dma_current_active_timer[dma]->adjust(attotime::zero, dma);
138         m_dma_timer_active[dma]=1;
139         m_dma_current_active_timer[dma]->adjust(attotime::zero, dma);
193140      }
194141   }
195142
196143}
197144
198void sh2_do_dma(sh2_state *sh2, int dma)
145void sh2_device::sh2_do_dma(int dma)
199146{
200147   UINT32 dmadata;
201148
202149   UINT32 tempsrc, tempdst;
203150
204   if (sh2->active_dma_count[dma] > 0)
151   if (m_active_dma_count[dma] > 0)
205152   {
206153      // process current DMA
207      switch(sh2->active_dma_size[dma])
154      switch(m_active_dma_size[dma])
208155      {
209156      case 0:
210157         {
r29565r29566
212159            // to allow for the callback to check if we can process the DMA at this
213160            // time (we need to know where we're reading / writing to/from)
214161
215            if(sh2->active_dma_incs[dma] == 2)
216               tempsrc = sh2->active_dma_src[dma] - 1;
162            if(m_active_dma_incs[dma] == 2)
163               tempsrc = m_active_dma_src[dma] - 1;
217164            else
218               tempsrc = sh2->active_dma_src[dma];
165               tempsrc = m_active_dma_src[dma];
219166
220            if(sh2->active_dma_incd[dma] == 2)
221               tempdst = sh2->active_dma_dst[dma] - 1;
167            if(m_active_dma_incd[dma] == 2)
168               tempdst = m_active_dma_dst[dma] - 1;
222169            else
223               tempdst = sh2->active_dma_dst[dma];
170               tempdst = m_active_dma_dst[dma];
224171
225            if (sh2->dma_callback_fifo_data_available)
172            if (m_dma_callback_fifo_data_available)
226173            {
227               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
174               int available = m_dma_callback_fifo_data_available(this, tempsrc, tempdst, 0, m_active_dma_size[dma]);
228175
229176               if (!available)
230177               {
231178                  //printf("dma stalled\n");
232                  sh2->dma_timer_active[dma]=2;// mark as stalled
179                  m_dma_timer_active[dma]=2;// mark as stalled
233180                  return;
234181               }
235182            }
236183
237184            #ifdef USE_TIMER_FOR_DMA
238185               //schedule next DMA callback
239            sh2->dma_current_active_timer[dma]->adjust(sh2->device->cycles_to_attotime(2), dma);
186            m_dma_current_active_timer[dma]->adjust(cycles_to_attotime(2), dma);
240187            #endif
241188
242189
243            dmadata = sh2->program->read_byte(tempsrc);
244            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
245            sh2->program->write_byte(tempdst, dmadata);
190            dmadata = m_program->read_byte(tempsrc);
191            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
192            m_program->write_byte(tempdst, dmadata);
246193
247            if(sh2->active_dma_incs[dma] == 2)
248               sh2->active_dma_src[dma] --;
249            if(sh2->active_dma_incd[dma] == 2)
250               sh2->active_dma_dst[dma] --;
194            if(m_active_dma_incs[dma] == 2)
195               m_active_dma_src[dma] --;
196            if(m_active_dma_incd[dma] == 2)
197               m_active_dma_dst[dma] --;
251198
252199
253            if(sh2->active_dma_incs[dma] == 1)
254               sh2->active_dma_src[dma] ++;
255            if(sh2->active_dma_incd[dma] == 1)
256               sh2->active_dma_dst[dma] ++;
200            if(m_active_dma_incs[dma] == 1)
201               m_active_dma_src[dma] ++;
202            if(m_active_dma_incd[dma] == 1)
203               m_active_dma_dst[dma] ++;
257204
258            sh2->active_dma_count[dma] --;
205            m_active_dma_count[dma] --;
259206         }
260207         break;
261208      case 1:
262209         {
263            if(sh2->active_dma_incs[dma] == 2)
264               tempsrc = sh2->active_dma_src[dma] - 2;
210            if(m_active_dma_incs[dma] == 2)
211               tempsrc = m_active_dma_src[dma] - 2;
265212            else
266               tempsrc = sh2->active_dma_src[dma];
213               tempsrc = m_active_dma_src[dma];
267214
268            if(sh2->active_dma_incd[dma] == 2)
269               tempdst = sh2->active_dma_dst[dma] - 2;
215            if(m_active_dma_incd[dma] == 2)
216               tempdst = m_active_dma_dst[dma] - 2;
270217            else
271               tempdst = sh2->active_dma_dst[dma];
218               tempdst = m_active_dma_dst[dma];
272219
273            if (sh2->dma_callback_fifo_data_available)
220            if (m_dma_callback_fifo_data_available)
274221            {
275               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
222               int available = m_dma_callback_fifo_data_available(this, tempsrc, tempdst, 0, m_active_dma_size[dma]);
276223
277224               if (!available)
278225               {
279226                  //printf("dma stalled\n");
280                  sh2->dma_timer_active[dma]=2;// mark as stalled
227                  m_dma_timer_active[dma]=2;// mark as stalled
281228                  return;
282229               }
283230            }
284231
285232            #ifdef USE_TIMER_FOR_DMA
286233               //schedule next DMA callback
287            sh2->dma_current_active_timer[dma]->adjust(sh2->device->cycles_to_attotime(2), dma);
234            m_dma_current_active_timer[dma]->adjust(cycles_to_attotime(2), dma);
288235            #endif
289236
290237            // check: should this really be using read_word_32 / write_word_32?
291            dmadata = sh2->program->read_word(tempsrc);
292            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
293            sh2->program->write_word(tempdst, dmadata);
238            dmadata = m_program->read_word(tempsrc);
239            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
240            m_program->write_word(tempdst, dmadata);
294241
295            if(sh2->active_dma_incs[dma] == 2)
296               sh2->active_dma_src[dma] -= 2;
297            if(sh2->active_dma_incd[dma] == 2)
298               sh2->active_dma_dst[dma] -= 2;
242            if(m_active_dma_incs[dma] == 2)
243               m_active_dma_src[dma] -= 2;
244            if(m_active_dma_incd[dma] == 2)
245               m_active_dma_dst[dma] -= 2;
299246
300            if(sh2->active_dma_incs[dma] == 1)
301               sh2->active_dma_src[dma] += 2;
302            if(sh2->active_dma_incd[dma] == 1)
303               sh2->active_dma_dst[dma] += 2;
247            if(m_active_dma_incs[dma] == 1)
248               m_active_dma_src[dma] += 2;
249            if(m_active_dma_incd[dma] == 1)
250               m_active_dma_dst[dma] += 2;
304251
305            sh2->active_dma_count[dma] --;
252            m_active_dma_count[dma] --;
306253         }
307254         break;
308255      case 2:
309256         {
310            if(sh2->active_dma_incs[dma] == 2)
311               tempsrc = sh2->active_dma_src[dma] - 4;
257            if(m_active_dma_incs[dma] == 2)
258               tempsrc = m_active_dma_src[dma] - 4;
312259            else
313               tempsrc = sh2->active_dma_src[dma];
260               tempsrc = m_active_dma_src[dma];
314261
315            if(sh2->active_dma_incd[dma] == 2)
316               tempdst = sh2->active_dma_dst[dma] - 4;
262            if(m_active_dma_incd[dma] == 2)
263               tempdst = m_active_dma_dst[dma] - 4;
317264            else
318               tempdst = sh2->active_dma_dst[dma];
265               tempdst = m_active_dma_dst[dma];
319266
320            if (sh2->dma_callback_fifo_data_available)
267            if (m_dma_callback_fifo_data_available)
321268            {
322               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
269               int available = m_dma_callback_fifo_data_available(this, tempsrc, tempdst, 0, m_active_dma_size[dma]);
323270
324271               if (!available)
325272               {
326273                  //printf("dma stalled\n");
327                  sh2->dma_timer_active[dma]=2;// mark as stalled
274                  m_dma_timer_active[dma]=2;// mark as stalled
328275                  return;
329276               }
330277            }
331278
332279            #ifdef USE_TIMER_FOR_DMA
333280               //schedule next DMA callback
334            sh2->dma_current_active_timer[dma]->adjust(sh2->device->cycles_to_attotime(2), dma);
281            m_dma_current_active_timer[dma]->adjust(cycles_to_attotime(2), dma);
335282            #endif
336283
337            dmadata = sh2->program->read_dword(tempsrc);
338            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
339            sh2->program->write_dword(tempdst, dmadata);
284            dmadata = m_program->read_dword(tempsrc);
285            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
286            m_program->write_dword(tempdst, dmadata);
340287
341            if(sh2->active_dma_incs[dma] == 2)
342               sh2->active_dma_src[dma] -= 4;
343            if(sh2->active_dma_incd[dma] == 2)
344               sh2->active_dma_dst[dma] -= 4;
288            if(m_active_dma_incs[dma] == 2)
289               m_active_dma_src[dma] -= 4;
290            if(m_active_dma_incd[dma] == 2)
291               m_active_dma_dst[dma] -= 4;
345292
346            if(sh2->active_dma_incs[dma] == 1)
347               sh2->active_dma_src[dma] += 4;
348            if(sh2->active_dma_incd[dma] == 1)
349               sh2->active_dma_dst[dma] += 4;
293            if(m_active_dma_incs[dma] == 1)
294               m_active_dma_src[dma] += 4;
295            if(m_active_dma_incd[dma] == 1)
296               m_active_dma_dst[dma] += 4;
350297
351            sh2->active_dma_count[dma] --;
298            m_active_dma_count[dma] --;
352299         }
353300         break;
354301      case 3:
355302         {
356303            // shouldn't this really be 4 calls here instead?
357304
358            tempsrc = sh2->active_dma_src[dma];
305            tempsrc = m_active_dma_src[dma];
359306
360            if(sh2->active_dma_incd[dma] == 2)
361               tempdst = sh2->active_dma_dst[dma] - 16;
307            if(m_active_dma_incd[dma] == 2)
308               tempdst = m_active_dma_dst[dma] - 16;
362309            else
363               tempdst = sh2->active_dma_dst[dma];
310               tempdst = m_active_dma_dst[dma];
364311
365            if (sh2->dma_callback_fifo_data_available)
312            if (m_dma_callback_fifo_data_available)
366313            {
367               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
314               int available = m_dma_callback_fifo_data_available(this, tempsrc, tempdst, 0, m_active_dma_size[dma]);
368315
369316               if (!available)
370317               {
371318                  //printf("dma stalled\n");
372                  sh2->dma_timer_active[dma]=2;// mark as stalled
319                  m_dma_timer_active[dma]=2;// mark as stalled
373320                  fatalerror("SH2 dma_callback_fifo_data_available == 0 in unsupported mode\n");
374321               }
375322            }
376323
377324            #ifdef USE_TIMER_FOR_DMA
378325               //schedule next DMA callback
379            sh2->dma_current_active_timer[dma]->adjust(sh2->device->cycles_to_attotime(2), dma);
326            m_dma_current_active_timer[dma]->adjust(cycles_to_attotime(2), dma);
380327            #endif
381328
382            dmadata = sh2->program->read_dword(tempsrc);
383            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
384            sh2->program->write_dword(tempdst, dmadata);
329            dmadata = m_program->read_dword(tempsrc);
330            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
331            m_program->write_dword(tempdst, dmadata);
385332
386            dmadata = sh2->program->read_dword(tempsrc+4);
387            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
388            sh2->program->write_dword(tempdst+4, dmadata);
333            dmadata = m_program->read_dword(tempsrc+4);
334            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
335            m_program->write_dword(tempdst+4, dmadata);
389336
390            dmadata = sh2->program->read_dword(tempsrc+8);
391            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
392            sh2->program->write_dword(tempdst+8, dmadata);
337            dmadata = m_program->read_dword(tempsrc+8);
338            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
339            m_program->write_dword(tempdst+8, dmadata);
393340
394            dmadata = sh2->program->read_dword(tempsrc+12);
395            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
396            sh2->program->write_dword(tempdst+12, dmadata);
341            dmadata = m_program->read_dword(tempsrc+12);
342            if (m_dma_callback_kludge) dmadata = m_dma_callback_kludge(this, tempsrc, tempdst, dmadata, m_active_dma_size[dma]);
343            m_program->write_dword(tempdst+12, dmadata);
397344
398            if(sh2->active_dma_incd[dma] == 2)
399               sh2->active_dma_dst[dma] -= 16;
345            if(m_active_dma_incd[dma] == 2)
346               m_active_dma_dst[dma] -= 16;
400347
401            sh2->active_dma_src[dma] += 16;
402            if(sh2->active_dma_incd[dma] == 1)
403               sh2->active_dma_dst[dma] += 16;
348            m_active_dma_src[dma] += 16;
349            if(m_active_dma_incd[dma] == 1)
350               m_active_dma_dst[dma] += 16;
404351
405            sh2->active_dma_count[dma]-=4;
352            m_active_dma_count[dma]-=4;
406353         }
407354         break;
408355      }
r29565r29566
410357   else // the dma is complete
411358   {
412359   //  int dma = param & 1;
413   //  sh2_state *sh2 = (sh2_state *)ptr;
414360
415361      // fever soccer uses cycle-stealing mode, resume the CPU now DMA has finished
416      if (sh2->active_dma_steal[dma])
362      if (m_active_dma_steal[dma])
417363      {
418         sh2->device->resume(SUSPEND_REASON_HALT );
364         resume(SUSPEND_REASON_HALT );
419365      }
420366
421367
422      LOG(("SH2.%s: DMA %d complete\n", sh2->device->tag(), dma));
423      sh2->m[0x63+4*dma] |= 2;
424      sh2->dma_timer_active[dma] = 0;
425      sh2->dma_irq[dma] |= 1;
426      sh2_recalc_irq(sh2);
368      LOG(("SH2.%s: DMA %d complete\n", tag(), dma));
369      m_m[0x63+4*dma] |= 2;
370      m_dma_timer_active[dma] = 0;
371      m_dma_irq[dma] |= 1;
372      sh2_recalc_irq();
427373
428374   }
429375}
430376
431static TIMER_CALLBACK( sh2_dma_current_active_callback )
377TIMER_CALLBACK_MEMBER( sh2_device::sh2_dma_current_active_callback )
432378{
433379   int dma = param & 1;
434   sh2_state *sh2 = (sh2_state *)ptr;
435380
436   sh2_do_dma(sh2, dma);
381   sh2_do_dma(dma);
437382}
438383
439384
440static void sh2_dmac_check(sh2_state *sh2, int dma)
385void sh2_device::sh2_dmac_check(int dma)
441386{
442   if(sh2->m[0x63+4*dma] & sh2->m[0x6c] & 1)
387   if(m_m[0x63+4*dma] & m_m[0x6c] & 1)
443388   {
444      if(!sh2->dma_timer_active[dma] && !(sh2->m[0x63+4*dma] & 2))
389      if(!m_dma_timer_active[dma] && !(m_m[0x63+4*dma] & 2))
445390      {
446         sh2->active_dma_incd[dma] = (sh2->m[0x63+4*dma] >> 14) & 3;
447         sh2->active_dma_incs[dma] = (sh2->m[0x63+4*dma] >> 12) & 3;
448         sh2->active_dma_size[dma] = (sh2->m[0x63+4*dma] >> 10) & 3;
449         sh2->active_dma_steal[dma] = (sh2->m[0x63+4*dma] &0x10);
391         m_active_dma_incd[dma] = (m_m[0x63+4*dma] >> 14) & 3;
392         m_active_dma_incs[dma] = (m_m[0x63+4*dma] >> 12) & 3;
393         m_active_dma_size[dma] = (m_m[0x63+4*dma] >> 10) & 3;
394         m_active_dma_steal[dma] = (m_m[0x63+4*dma] &0x10);
450395
451         if(sh2->active_dma_incd[dma] == 3 || sh2->active_dma_incs[dma] == 3)
396         if(m_active_dma_incd[dma] == 3 || m_active_dma_incs[dma] == 3)
452397         {
453            logerror("SH2: DMA: bad increment values (%d, %d, %d, %04x)\n", sh2->active_dma_incd[dma], sh2->active_dma_incs[dma], sh2->active_dma_size[dma], sh2->m[0x63+4*dma]);
398            logerror("SH2: DMA: bad increment values (%d, %d, %d, %04x)\n", m_active_dma_incd[dma], m_active_dma_incs[dma], m_active_dma_size[dma], m_m[0x63+4*dma]);
454399            return;
455400         }
456         sh2->active_dma_src[dma]   = sh2->m[0x60+4*dma];
457         sh2->active_dma_dst[dma]   = sh2->m[0x61+4*dma];
458         sh2->active_dma_count[dma] = sh2->m[0x62+4*dma];
459         if(!sh2->active_dma_count[dma])
460            sh2->active_dma_count[dma] = 0x1000000;
401         m_active_dma_src[dma]   = m_m[0x60+4*dma];
402         m_active_dma_dst[dma]   = m_m[0x61+4*dma];
403         m_active_dma_count[dma] = m_m[0x62+4*dma];
404         if(!m_active_dma_count[dma])
405            m_active_dma_count[dma] = 0x1000000;
461406
462         LOG(("SH2: DMA %d start %x, %x, %x, %04x, %d, %d, %d\n", dma, sh2->active_dma_src[dma], sh2->active_dma_dst[dma], sh2->active_dma_count[dma], sh2->m[0x63+4*dma], sh2->active_dma_incs[dma], sh2->active_dma_incd[dma], sh2->active_dma_size[dma]));
407         LOG(("SH2: DMA %d start %x, %x, %x, %04x, %d, %d, %d\n", dma, m_active_dma_src[dma], m_active_dma_dst[dma], m_active_dma_count[dma], m_m[0x63+4*dma], m_active_dma_incs[dma], m_active_dma_incd[dma], m_active_dma_size[dma]));
463408
464         sh2->dma_timer_active[dma] = 1;
409         m_dma_timer_active[dma] = 1;
465410
466         sh2->active_dma_src[dma] &= AM;
467         sh2->active_dma_dst[dma] &= AM;
411         m_active_dma_src[dma] &= AM;
412         m_active_dma_dst[dma] &= AM;
468413
469         switch(sh2->active_dma_size[dma])
414         switch(m_active_dma_size[dma])
470415         {
471416         case 0:
472417            break;
473418         case 1:
474            sh2->active_dma_src[dma] &= ~1;
475            sh2->active_dma_dst[dma] &= ~1;
419            m_active_dma_src[dma] &= ~1;
420            m_active_dma_dst[dma] &= ~1;
476421            break;
477422         case 2:
478            sh2->active_dma_src[dma] &= ~3;
479            sh2->active_dma_dst[dma] &= ~3;
423            m_active_dma_src[dma] &= ~3;
424            m_active_dma_dst[dma] &= ~3;
480425            break;
481426         case 3:
482            sh2->active_dma_src[dma] &= ~3;
483            sh2->active_dma_dst[dma] &= ~3;
484            sh2->active_dma_count[dma] &= ~3;
427            m_active_dma_src[dma] &= ~3;
428            m_active_dma_dst[dma] &= ~3;
429            m_active_dma_count[dma] &= ~3;
485430            break;
486431         }
487432
r29565r29566
492437         // start DMA timer
493438
494439         // fever soccer uses cycle-stealing mode, requiring the CPU to be halted
495         if (sh2->active_dma_steal[dma])
440         if (m_active_dma_steal[dma])
496441         {
497442            //printf("cycle stealing DMA\n");
498            sh2->device->suspend(SUSPEND_REASON_HALT, 1 );
443            suspend(SUSPEND_REASON_HALT, 1 );
499444         }
500445
501         sh2->dma_current_active_timer[dma]->adjust(sh2->device->cycles_to_attotime(2), dma);
446         m_dma_current_active_timer[dma]->adjust(cycles_to_attotime(2), dma);
502447#endif
503448
504449      }
505450   }
506451   else
507452   {
508      if(sh2->dma_timer_active[dma])
453      if(m_dma_timer_active[dma])
509454      {
510455         logerror("SH2: DMA %d cancelled in-flight\n", dma);
511         //sh2->dma_complete_timer[dma]->adjust(attotime::never);
512         sh2->dma_current_active_timer[dma]->adjust(attotime::never);
456         //m_dma_complete_timer[dma]->adjust(attotime::never);
457         m_dma_current_active_timer[dma]->adjust(attotime::never);
513458
514         sh2->dma_timer_active[dma] = 0;
459         m_dma_timer_active[dma] = 0;
515460      }
516461   }
517462}
518463
519WRITE32_HANDLER( sh2_internal_w )
464WRITE32_MEMBER( sh2_device::sh2_internal_w )
520465{
521   sh2_state *sh2 = GET_SH2(&space.device());
522466   UINT32 old;
523467
524   if (sh2->isdrc)
468   if (m_isdrc)
525469      offset &= 0x7f;
526470
527471
528   old = sh2->m[offset];
529   COMBINE_DATA(sh2->m+offset);
472   old = m_m[offset];
473   COMBINE_DATA(m_m+offset);
530474
531475   //  if(offset != 0x20)
532476   //      logerror("sh2_internal_w:  Write %08x (%x), %08x @ %08x\n", 0xfffffe00+offset*4, offset, data, mem_mask);
r29565r29566
547491   case 0x04: // TIER, FTCSR, FRC
548492      if((mem_mask & 0x00ffffff) != 0)
549493      {
550         sh2_timer_resync(sh2);
494         sh2_timer_resync();
551495      }
552//      printf("SH2.%s: TIER write %04x @ %04x\n", sh2->device->tag(), data >> 16, mem_mask>>16);
553      sh2->m[4] = (sh2->m[4] & ~(ICF|OCFA|OCFB|OVF)) | (old & sh2->m[4] & (ICF|OCFA|OCFB|OVF));
554      COMBINE_DATA(&sh2->frc);
496//      printf("SH2.%s: TIER write %04x @ %04x\n", m_device->tag(), data >> 16, mem_mask>>16);
497      m_m[4] = (m_m[4] & ~(ICF|OCFA|OCFB|OVF)) | (old & m_m[4] & (ICF|OCFA|OCFB|OVF));
498      COMBINE_DATA(&m_frc);
555499      if((mem_mask & 0x00ffffff) != 0)
556         sh2_timer_activate(sh2);
557      sh2_recalc_irq(sh2);
500         sh2_timer_activate();
501      sh2_recalc_irq();
558502      break;
559503   case 0x05: // OCRx, TCR, TOCR
560//      printf("SH2.%s: TCR write %08x @ %08x\n", sh2->device->tag(), data, mem_mask);
561      sh2_timer_resync(sh2);
562      if(sh2->m[5] & 0x10)
563         sh2->ocrb = (sh2->ocrb & (~mem_mask >> 16)) | ((data & mem_mask) >> 16);
504//      printf("SH2.%s: TCR write %08x @ %08x\n", m_device->tag(), data, mem_mask);
505      sh2_timer_resync();
506      if(m_m[5] & 0x10)
507         m_ocrb = (m_ocrb & (~mem_mask >> 16)) | ((data & mem_mask) >> 16);
564508      else
565         sh2->ocra = (sh2->ocra & (~mem_mask >> 16)) | ((data & mem_mask) >> 16);
566      sh2_timer_activate(sh2);
509         m_ocra = (m_ocra & (~mem_mask >> 16)) | ((data & mem_mask) >> 16);
510      sh2_timer_activate();
567511      break;
568512
569513   case 0x06: // ICR
r29565r29566
573517   case 0x18: // IPRB, VCRA
574518   case 0x19: // VCRB, VCRC
575519   case 0x1a: // VCRD
576      sh2_recalc_irq(sh2);
520      sh2_recalc_irq();
577521      break;
578522
579523      // DMA
r29565r29566
582526
583527      // Watchdog
584528   case 0x20: // WTCNT, RSTCSR
585      if((sh2->m[0x20] & 0xff000000) == 0x5a000000)
586         sh2->wtcnt = (sh2->m[0x20] >> 16) & 0xff;
529      if((m_m[0x20] & 0xff000000) == 0x5a000000)
530         m_wtcnt = (m_m[0x20] >> 16) & 0xff;
587531
588      if((sh2->m[0x20] & 0xff000000) == 0xa5000000)
532      if((m_m[0x20] & 0xff000000) == 0xa5000000)
589533      {
590534         /*
591535         WTCSR
r29565r29566
596540         ---- -xxx Clock select
597541         */
598542
599         sh2->wtcsr = (sh2->m[0x20] >> 16) & 0xff;
543         m_wtcsr = (m_m[0x20] >> 16) & 0xff;
600544      }
601545
602      if((sh2->m[0x20] & 0x0000ff00) == 0x00005a00)
546      if((m_m[0x20] & 0x0000ff00) == 0x00005a00)
603547      {
604548         // -x-- ---- RSTE (1: resets wtcnt when overflows 0: no reset)
605549         // --x- ---- RSTS (0: power-on reset 1: Manual reset)
606550         // ...
607551      }
608552
609      if((sh2->m[0x20] & 0x0000ff00) == 0x0000a500)
553      if((m_m[0x20] & 0x0000ff00) == 0x0000a500)
610554      {
611555         // clear WOVF
612556         // ...
r29565r29566
640584      break;
641585   case 0x41: // DVDNT
642586      {
643         INT32 a = sh2->m[0x41];
644         INT32 b = sh2->m[0x40];
645         LOG(("SH2 '%s' div+mod %d/%d\n", sh2->device->tag(), a, b));
587         INT32 a = m_m[0x41];
588         INT32 b = m_m[0x40];
589         LOG(("SH2 '%s' div+mod %d/%d\n", tag(), a, b));
646590         if (b)
647591         {
648            sh2->m[0x45] = a / b;
649            sh2->m[0x44] = a % b;
592            m_m[0x45] = a / b;
593            m_m[0x44] = a % b;
650594         }
651595         else
652596         {
653            sh2->m[0x42] |= 0x00010000;
654            sh2->m[0x45] = 0x7fffffff;
655            sh2->m[0x44] = 0x7fffffff;
656            sh2_recalc_irq(sh2);
597            m_m[0x42] |= 0x00010000;
598            m_m[0x45] = 0x7fffffff;
599            m_m[0x44] = 0x7fffffff;
600            sh2_recalc_irq();
657601         }
658602         break;
659603      }
660604   case 0x42: // DVCR
661      sh2->m[0x42] = (sh2->m[0x42] & ~0x00001000) | (old & sh2->m[0x42] & 0x00010000);
662      sh2_recalc_irq(sh2);
605      m_m[0x42] = (m_m[0x42] & ~0x00001000) | (old & m_m[0x42] & 0x00010000);
606      sh2_recalc_irq();
663607      break;
664608   case 0x43: // VCRDIV
665      sh2_recalc_irq(sh2);
609      sh2_recalc_irq();
666610      break;
667611   case 0x44: // DVDNTH
668612      break;
669613   case 0x45: // DVDNTL
670614      {
671         INT64 a = sh2->m[0x45] | ((UINT64)(sh2->m[0x44]) << 32);
672         INT64 b = (INT32)sh2->m[0x40];
673         LOG(("SH2 '%s' div+mod %" I64FMT "d/%" I64FMT "d\n", sh2->device->tag(), a, b));
615         INT64 a = m_m[0x45] | ((UINT64)(m_m[0x44]) << 32);
616         INT64 b = (INT32)m_m[0x40];
617         LOG(("SH2 '%s' div+mod %" I64FMT "d/%" I64FMT "d\n", tag(), a, b));
674618         if (b)
675619         {
676620            INT64 q = a / b;
677621            if (q != (INT32)q)
678622            {
679               sh2->m[0x42] |= 0x00010000;
680               sh2->m[0x45] = 0x7fffffff;
681               sh2->m[0x44] = 0x7fffffff;
682               sh2_recalc_irq(sh2);
623               m_m[0x42] |= 0x00010000;
624               m_m[0x45] = 0x7fffffff;
625               m_m[0x44] = 0x7fffffff;
626               sh2_recalc_irq();
683627            }
684628            else
685629            {
686               sh2->m[0x45] = q;
687               sh2->m[0x44] = a % b;
630               m_m[0x45] = q;
631               m_m[0x44] = a % b;
688632            }
689633         }
690634         else
691635         {
692            sh2->m[0x42] |= 0x00010000;
693            sh2->m[0x45] = 0x7fffffff;
694            sh2->m[0x44] = 0x7fffffff;
695            sh2_recalc_irq(sh2);
636            m_m[0x42] |= 0x00010000;
637            m_m[0x45] = 0x7fffffff;
638            m_m[0x44] = 0x7fffffff;
639            sh2_recalc_irq();
696640         }
697641         break;
698642      }
r29565r29566
702646   case 0x61: // DAR0
703647      break;
704648   case 0x62: // DTCR0
705      sh2->m[0x62] &= 0xffffff;
649      m_m[0x62] &= 0xffffff;
706650      break;
707651   case 0x63: // CHCR0
708      sh2->m[0x63] = (sh2->m[0x63] & ~2) | (old & sh2->m[0x63] & 2);
709      sh2_dmac_check(sh2, 0);
652      m_m[0x63] = (m_m[0x63] & ~2) | (old & m_m[0x63] & 2);
653      sh2_dmac_check(0);
710654      break;
711655   case 0x64: // SAR1
712656   case 0x65: // DAR1
713657      break;
714658   case 0x66: // DTCR1
715      sh2->m[0x66] &= 0xffffff;
659      m_m[0x66] &= 0xffffff;
716660      break;
717661   case 0x67: // CHCR1
718      sh2->m[0x67] = (sh2->m[0x67] & ~2) | (old & sh2->m[0x67] & 2);
719      sh2_dmac_check(sh2, 1);
662      m_m[0x67] = (m_m[0x67] & ~2) | (old & m_m[0x67] & 2);
663      sh2_dmac_check(1);
720664      break;
721665   case 0x68: // VCRDMA0
722666   case 0x6a: // VCRDMA1
723      sh2_recalc_irq(sh2);
667      sh2_recalc_irq();
724668      break;
725669   case 0x6c: // DMAOR
726      sh2->m[0x6c] = (sh2->m[0x6c] & ~6) | (old & sh2->m[0x6c] & 6);
727      sh2_dmac_check(sh2, 0);
728      sh2_dmac_check(sh2, 1);
670      m_m[0x6c] = (m_m[0x6c] & ~6) | (old & m_m[0x6c] & 6);
671      sh2_dmac_check(0);
672      sh2_dmac_check(1);
729673      break;
730674
731675      // Bus controller
r29565r29566
744688   }
745689}
746690
747READ32_HANDLER( sh2_internal_r )
691READ32_MEMBER( sh2_device::sh2_internal_r )
748692{
749   sh2_state *sh2 = GET_SH2(&space.device());
750
751   if (sh2->isdrc)
693   if (m_isdrc)
752694   offset &= 0x7f;
753695
754696//  logerror("sh2_internal_r:  Read %08x (%x) @ %08x\n", 0xfffffe00+offset*4, offset, mem_mask);
r29565r29566
757699   case 0x00:
758700      break;
759701   case 0x01:
760      return sh2->m[1] | 0x80000000; // TDRE: Trasmit Data Register Empty. Force it to be '1' for the time being.
702      return m_m[1] | 0x80000000; // TDRE: Trasmit Data Register Empty. Force it to be '1' for the time being.
761703
762704   case 0x04: // TIER, FTCSR, FRC
763705      if ( mem_mask == 0x00ff0000 )
764706      {
765         if ( sh2->ftcsr_read_callback != NULL )
707         if ( m_ftcsr_read_callback != NULL )
766708         {
767            sh2->ftcsr_read_callback( (sh2->m[4] & 0xffff0000) | sh2->frc );
709            m_ftcsr_read_callback( (m_m[4] & 0xffff0000) | m_frc );
768710         }
769711      }
770      sh2_timer_resync(sh2);
771      return (sh2->m[4] & 0xffff0000) | sh2->frc;
712      sh2_timer_resync();
713      return (m_m[4] & 0xffff0000) | m_frc;
772714   case 0x05: // OCRx, TCR, TOCR
773      if(sh2->m[5] & 0x10)
774         return (sh2->ocrb << 16) | (sh2->m[5] & 0xffff);
715      if(m_m[5] & 0x10)
716         return (m_ocrb << 16) | (m_m[5] & 0xffff);
775717      else
776         return (sh2->ocra << 16) | (sh2->m[5] & 0xffff);
718         return (m_ocra << 16) | (m_m[5] & 0xffff);
777719   case 0x06: // ICR
778      return sh2->icr << 16;
720      return m_icr << 16;
779721
780722   case 0x20:
781      return (((sh2->wtcsr | 0x18) & 0xff) << 24)  | ((sh2->wtcnt & 0xff) << 16);
723      return (((m_wtcsr | 0x18) & 0xff) << 24)  | ((m_wtcnt & 0xff) << 16);
782724
783725   case 0x24: // SBYCR, CCR
784      return sh2->m[0x24] & ~0x3000; /* bit 4-5 of CCR are always zero */
726      return m_m[0x24] & ~0x3000; /* bit 4-5 of CCR are always zero */
785727
786728   case 0x38: // ICR, IPRA
787      return (sh2->m[0x38] & 0x7fffffff) | (sh2->nmi_line_state == ASSERT_LINE ? 0 : 0x80000000);
729      return (m_m[0x38] & 0x7fffffff) | (m_nmi_line_state == ASSERT_LINE ? 0 : 0x80000000);
788730
789731   case 0x78: // BCR1
790      return sh2->is_slave ? 0x00008000 : 0;
732      return m_is_slave ? 0x00008000 : 0;
791733
792734   case 0x41: // dvdntl mirrors
793735   case 0x47:
794      return sh2->m[0x45];
736      return m_m[0x45];
795737
796738   case 0x46: // dvdnth mirror
797      return sh2->m[0x44];
739      return m_m[0x44];
798740   }
799   return sh2->m[offset];
741   return m_m[offset];
800742}
801743
802void sh2_set_ftcsr_read_callback(device_t *device, void (*callback)(UINT32))
744void sh2_device::sh2_set_ftcsr_read_callback(void (*callback)(UINT32))
803745{
804   sh2_state *sh2 = GET_SH2(device);
805   sh2->ftcsr_read_callback = callback;
746   m_ftcsr_read_callback = callback;
806747}
807748
808void sh2_set_frt_input(device_t *device, int state)
749void sh2_device::sh2_set_frt_input(int state)
809750{
810   sh2_state *sh2 = GET_SH2(device);
811
812751   if(state == PULSE_LINE)
813752   {
814      sh2_set_frt_input(device, ASSERT_LINE);
815      sh2_set_frt_input(device, CLEAR_LINE);
753      sh2_set_frt_input(ASSERT_LINE);
754      sh2_set_frt_input(CLEAR_LINE);
816755      return;
817756   }
818757
819   if(sh2->frt_input == state) {
758   if(m_frt_input == state) {
820759      return;
821760   }
822761
823   sh2->frt_input = state;
762   m_frt_input = state;
824763
825   if(sh2->m[5] & 0x8000) {
764   if(m_m[5] & 0x8000) {
826765      if(state == CLEAR_LINE) {
827766         return;
828767      }
r29565r29566
832771      }
833772   }
834773
835   sh2_timer_resync(sh2);
836   sh2->icr = sh2->frc;
837   sh2->m[4] |= ICF;
838   //logerror("SH2.%s: ICF activated (%x)\n", sh2->device->tag(), sh2->pc & AM);
839   sh2_recalc_irq(sh2);
774   sh2_timer_resync();
775   m_icr = m_frc;
776   m_m[4] |= ICF;
777   //logerror("SH2.%s: ICF activated (%x)\n", tag(), m_sh2_state->pc & AM);
778   sh2_recalc_irq();
840779}
841780
842void sh2_set_irq_line(sh2_state *sh2, int irqline, int state)
781void sh2_device::sh2_recalc_irq()
843782{
844   if (irqline == INPUT_LINE_NMI)
845   {
846      if (sh2->nmi_line_state == state)
847         return;
848      sh2->nmi_line_state = state;
849
850      if( state == CLEAR_LINE )
851      {
852         LOG(("SH-2 '%s' cleared nmi\n", sh2->device->tag()));
853      }
854      else
855      {
856         LOG(("SH-2 '%s' assert nmi\n", sh2->device->tag()));
857
858         sh2_exception(sh2, "Set IRQ line", 16);
859
860         if (sh2->isdrc)
861            sh2->pending_nmi = 1;
862      }
863   }
864   else
865   {
866      if (sh2->irq_line_state[irqline] == state)
867         return;
868      sh2->irq_line_state[irqline] = state;
869
870      if( state == CLEAR_LINE )
871      {
872         LOG(("SH-2 '%s' cleared irq #%d\n", sh2->device->tag(), irqline));
873         sh2->pending_irq &= ~(1 << irqline);
874      }
875      else
876      {
877         LOG(("SH-2 '%s' assert irq #%d\n", sh2->device->tag(), irqline));
878         sh2->pending_irq |= 1 << irqline;
879         if (sh2->isdrc)
880         {
881         sh2->test_irq = 1;
882         } else {
883         if(sh2->delay)
884            sh2->test_irq = 1;
885         else
886            CHECK_PENDING_IRQ("sh2_set_irq_line");
887         }
888      }
889   }
890}
891
892void sh2_recalc_irq(sh2_state *sh2)
893{
894783   int irq = 0, vector = -1;
895784   int  level;
896785
897786   // Timer irqs
898   if((sh2->m[4]>>8) & sh2->m[4] & (ICF|OCFA|OCFB|OVF))
787   if((m_m[4]>>8) & m_m[4] & (ICF|OCFA|OCFB|OVF))
899788   {
900      level = (sh2->m[0x18] >> 24) & 15;
789      level = (m_m[0x18] >> 24) & 15;
901790      if(level > irq)
902791      {
903         int mask = (sh2->m[4]>>8) & sh2->m[4];
792         int mask = (m_m[4]>>8) & m_m[4];
904793         irq = level;
905794         if(mask & ICF)
906            vector = (sh2->m[0x19] >> 8) & 0x7f;
795            vector = (m_m[0x19] >> 8) & 0x7f;
907796         else if(mask & (OCFA|OCFB))
908            vector = sh2->m[0x19] & 0x7f;
797            vector = m_m[0x19] & 0x7f;
909798         else
910            vector = (sh2->m[0x1a] >> 24) & 0x7f;
799            vector = (m_m[0x1a] >> 24) & 0x7f;
911800      }
912801   }
913802
914803   // DMA irqs
915   if((sh2->m[0x63] & 6) == 6 && sh2->dma_irq[0]) {
916      level = (sh2->m[0x38] >> 8) & 15;
804   if((m_m[0x63] & 6) == 6 && m_dma_irq[0]) {
805      level = (m_m[0x38] >> 8) & 15;
917806      if(level > irq) {
918807         irq = level;
919         sh2->dma_irq[0] &= ~1;
920         vector = (sh2->m[0x68]) & 0x7f;
808         m_dma_irq[0] &= ~1;
809         vector = (m_m[0x68]) & 0x7f;
921810      }
922811   }
923   else if((sh2->m[0x67] & 6) == 6 && sh2->dma_irq[1]) {
924      level = (sh2->m[0x38] >> 8) & 15;
812   else if((m_m[0x67] & 6) == 6 && m_dma_irq[1]) {
813      level = (m_m[0x38] >> 8) & 15;
925814      if(level > irq) {
926815         irq = level;
927         sh2->dma_irq[1] &= ~1;
928         vector = (sh2->m[0x6a]) & 0x7f;
816         m_dma_irq[1] &= ~1;
817         vector = (m_m[0x6a]) & 0x7f;
929818      }
930819   }
931820
932   sh2->internal_irq_level = irq;
933   sh2->internal_irq_vector = vector;
934   sh2->test_irq = 1;
821   m_sh2_state->internal_irq_level = irq;
822   m_internal_irq_vector = vector;
823   m_test_irq = 1;
935824}
936825
937void sh2_exception(sh2_state *sh2, const char *message, int irqline)
826void sh2_device::sh2_exception(const char *message, int irqline)
938827{
939828   int vector;
940829
941830   if (irqline != 16)
942831   {
943      if (irqline <= ((sh2->sr >> 4) & 15)) /* If the cpu forbids this interrupt */
832      if (irqline <= ((m_sh2_state->sr >> 4) & 15)) /* If the cpu forbids this interrupt */
944833         return;
945834
946835      // if this is an sh2 internal irq, use its vector
947      if (sh2->internal_irq_level == irqline)
836      if (m_sh2_state->internal_irq_level == irqline)
948837      {
949         vector = sh2->internal_irq_vector;
838         vector = m_internal_irq_vector;
950839         /* avoid spurious irqs with this (TODO: needs a better fix) */
951         sh2->internal_irq_level = -1;
952         LOG(("SH-2 '%s' exception #%d (internal vector: $%x) after [%s]\n", sh2->device->tag(), irqline, vector, message));
840         m_sh2_state->internal_irq_level = -1;
841         LOG(("SH-2 '%s' exception #%d (internal vector: $%x) after [%s]\n", tag(), irqline, vector, message));
953842      }
954843      else
955844      {
956         if(sh2->m[0x38] & 0x00010000)
845         if(m_m[0x38] & 0x00010000)
957846         {
958            vector = sh2->irq_callback(sh2->device, irqline);
959            LOG(("SH-2 '%s' exception #%d (external vector: $%x) after [%s]\n", sh2->device->tag(), irqline, vector, message));
847            vector = standard_irq_callback(irqline);
848            LOG(("SH-2 '%s' exception #%d (external vector: $%x) after [%s]\n", tag(), irqline, vector, message));
960849         }
961850         else
962851         {
963            sh2->irq_callback(sh2->device, irqline);
852            standard_irq_callback(irqline);
964853            vector = 64 + irqline/2;
965            LOG(("SH-2 '%s' exception #%d (autovector: $%x) after [%s]\n", sh2->device->tag(), irqline, vector, message));
854            LOG(("SH-2 '%s' exception #%d (autovector: $%x) after [%s]\n", tag(), irqline, vector, message));
966855         }
967856      }
968857   }
969858   else
970859   {
971860      vector = 11;
972      LOG(("SH-2 '%s' nmi exception (autovector: $%x) after [%s]\n", sh2->device->tag(), vector, message));
861      LOG(("SH-2 '%s' nmi exception (autovector: $%x) after [%s]\n", tag(), vector, message));
973862   }
974863
975   if (sh2->isdrc)
864   if (m_isdrc)
976865   {
977   sh2->evec = RL( sh2, sh2->vbr + vector * 4 );
978   sh2->evec &= AM;
979   sh2->irqsr = sh2->sr;
866      m_sh2_state->evec = RL( m_sh2_state->vbr + vector * 4 );
867      m_sh2_state->evec &= AM;
868      m_sh2_state->irqsr = m_sh2_state->sr;
980869
981   /* set I flags in SR */
982   if (irqline > SH2_INT_15)
983      sh2->sr = sh2->sr | I;
984   else
985      sh2->sr = (sh2->sr & ~I) | (irqline << 4);
870      /* set I flags in SR */
871      if (irqline > SH2_INT_15)
872         m_sh2_state->sr = m_sh2_state->sr | I;
873      else
874         m_sh2_state->sr = (m_sh2_state->sr & ~I) | (irqline << 4);
986875
987//  printf("sh2_exception [%s] irqline %x evec %x save SR %x new SR %x\n", message, irqline, sh2->evec, sh2->irqsr, sh2->sr);
876//  printf("sh2_exception [%s] irqline %x evec %x save SR %x new SR %x\n", message, irqline, m_sh2_state->evec, m_sh2_state->irqsr, m_sh2_state->sr);
988877   } else {
989   sh2->r[15] -= 4;
990   WL( sh2, sh2->r[15], sh2->sr );     /* push SR onto stack */
991   sh2->r[15] -= 4;
992   WL( sh2, sh2->r[15], sh2->pc );     /* push PC onto stack */
878      m_sh2_state->r[15] -= 4;
879      WL( m_sh2_state->r[15], m_sh2_state->sr );     /* push SR onto stack */
880      m_sh2_state->r[15] -= 4;
881      WL( m_sh2_state->r[15], m_sh2_state->pc );     /* push PC onto stack */
993882
994   /* set I flags in SR */
995   if (irqline > SH2_INT_15)
996      sh2->sr = sh2->sr | I;
997   else
998      sh2->sr = (sh2->sr & ~I) | (irqline << 4);
883      /* set I flags in SR */
884      if (irqline > SH2_INT_15)
885         m_sh2_state->sr = m_sh2_state->sr | I;
886      else
887         m_sh2_state->sr = (m_sh2_state->sr & ~I) | (irqline << 4);
999888
1000   /* fetch PC */
1001   sh2->pc = RL( sh2, sh2->vbr + vector * 4 );
889      /* fetch PC */
890      m_sh2_state->pc = RL( m_sh2_state->vbr + vector * 4 );
1002891   }
1003892
1004   if(sh2->sleep_mode == 1) { sh2->sleep_mode = 2; }
893   if(m_sh2_state->sleep_mode == 1) { m_sh2_state->sleep_mode = 2; }
1005894}
1006895
1007void sh2_common_init(sh2_state *sh2, legacy_cpu_device *device, device_irq_acknowledge_callback irqcallback, bool drc)
1008{
1009   const sh2_cpu_core *conf = (const sh2_cpu_core *)device->static_config();
1010   int i;
1011
1012   sh2->isdrc = drc;
1013   sh2->timer = device->machine().scheduler().timer_alloc(FUNC(sh2_timer_callback), sh2);
1014   sh2->timer->adjust(attotime::never);
1015
1016   sh2->dma_current_active_timer[0] = device->machine().scheduler().timer_alloc(FUNC(sh2_dma_current_active_callback), sh2);
1017   sh2->dma_current_active_timer[0]->adjust(attotime::never);
1018
1019   sh2->dma_current_active_timer[1] = device->machine().scheduler().timer_alloc(FUNC(sh2_dma_current_active_callback), sh2);
1020   sh2->dma_current_active_timer[1]->adjust(attotime::never);
1021
1022   if(conf)
1023   {
1024      sh2->is_slave = conf->is_slave;
1025      sh2->dma_callback_kludge = conf->dma_callback_kludge;
1026      sh2->dma_callback_fifo_data_available = conf->dma_callback_fifo_data_available;
1027   }
1028   else
1029   {
1030      sh2->is_slave = 0;
1031      sh2->dma_callback_kludge = NULL;
1032      sh2->dma_callback_fifo_data_available = NULL;
1033
1034   }
1035   sh2->irq_callback = irqcallback;
1036   sh2->device = device;
1037   sh2->program = &device->space(AS_PROGRAM);
1038   sh2->direct = &sh2->program->direct();
1039   sh2->internal = &device->space(AS_PROGRAM);
1040
1041   device->save_item(NAME(sh2->pc));
1042   device->save_item(NAME(sh2->sr));
1043   device->save_item(NAME(sh2->pr));
1044   device->save_item(NAME(sh2->gbr));
1045   device->save_item(NAME(sh2->vbr));
1046   device->save_item(NAME(sh2->mach));
1047   device->save_item(NAME(sh2->macl));
1048   device->save_item(NAME(sh2->r));
1049   device->save_item(NAME(sh2->ea));
1050   device->save_item(NAME(sh2->delay));
1051   device->save_item(NAME(sh2->cpu_off));
1052   device->save_item(NAME(sh2->dvsr));
1053   device->save_item(NAME(sh2->dvdnth));
1054   device->save_item(NAME(sh2->dvdntl));
1055   device->save_item(NAME(sh2->dvcr));
1056   device->save_item(NAME(sh2->pending_irq));
1057   device->save_item(NAME(sh2->test_irq));
1058   device->save_item(NAME(sh2->pending_nmi));
1059   device->save_item(NAME(sh2->irqline));
1060   device->save_item(NAME(sh2->evec));
1061   device->save_item(NAME(sh2->irqsr));
1062   device->save_item(NAME(sh2->target));
1063   for (i = 0; i < 16; ++i)
1064   {
1065      device->save_item(NAME(sh2->irq_queue[i].irq_vector), i);
1066      device->save_item(NAME(sh2->irq_queue[i].irq_priority), i);
1067   }
1068   device->save_item(NAME(sh2->pcfsel));
1069   device->save_item(NAME(sh2->maxpcfsel));
1070   device->save_item(NAME(sh2->pcflushes));
1071   device->save_item(NAME(sh2->irq_line_state));
1072   device->save_pointer(NAME(sh2->m), 0x200/4);
1073   device->save_item(NAME(sh2->nmi_line_state));
1074   device->save_item(NAME(sh2->frc));
1075   device->save_item(NAME(sh2->ocra));
1076   device->save_item(NAME(sh2->ocrb));
1077   device->save_item(NAME(sh2->icr));
1078   device->save_item(NAME(sh2->frc_base));
1079   device->save_item(NAME(sh2->frt_input));
1080   device->save_item(NAME(sh2->internal_irq_level));
1081   device->save_item(NAME(sh2->internal_irq_vector));
1082   device->save_item(NAME(sh2->dma_timer_active));
1083   device->save_item(NAME(sh2->dma_irq));
1084   device->save_item(NAME(sh2->wtcnt));
1085   device->save_item(NAME(sh2->wtcsr));
1086   device->save_item(NAME(sh2->sleep_mode));
1087}
trunk/src/emu/cpu/sh2/sh2.c
r29565r29566
8282
8383    20010207 Sylvain Glaize (mokona@puupuu.org)
8484
85    - Bug fix in INLINE void MOVBM(UINT32 m, UINT32 n) (see comment)
85    - Bug fix in void MOVBM(UINT32 m, UINT32 n) (see comment)
8686    - Support of full 32 bit addressing (RB, RW, RL and WB, WW, WL functions)
8787        reason : when the two high bits of the address are set, access is
8888        done directly in the cache data array. The SUPER KANEKO NOVA SYSTEM
r29565r29566
110110#include "sh2.h"
111111#include "sh2comn.h"
112112
113CPU_DISASSEMBLE( sh2 );
114113
114/***************************************************************************
115    DEBUGGING
116***************************************************************************/
115117
118#define LOG_UML                     (0) // log UML assembly
119#define LOG_NATIVE                  (0) // log native assembly
120
121#define DISABLE_FAST_REGISTERS              (0) // set to 1 to turn off usage of register caching
122#define SINGLE_INSTRUCTION_MODE             (0)
123
124#define VERBOSE 0
125#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
126
127/***************************************************************************
128    CONSTANTS
129***************************************************************************/
130
131/* size of the execution code cache */
132#define CACHE_SIZE                  (32 * 1024 * 1024)
133
134/* compilation boundaries -- how far back/forward does the analysis extend? */
135#define COMPILE_BACKWARDS_BYTES         64
136#define COMPILE_FORWARDS_BYTES          256
137#define COMPILE_MAX_INSTRUCTIONS        ((COMPILE_BACKWARDS_BYTES/2) + (COMPILE_FORWARDS_BYTES/2))
138#define COMPILE_MAX_SEQUENCE            64
139
140
141const device_type SH1 = &device_creator<sh1_device>;
142const device_type SH2 = &device_creator<sh2_device>;
143
144
145/*-------------------------------------------------
146    sh2_internal_a5 - read handler for
147    SH2 internal map
148-------------------------------------------------*/
149
150READ32_MEMBER(sh2_device::sh2_internal_a5)
151{
152    return 0xa5a5a5a5;
153}
154
155
156/*-------------------------------------------------
157    sh2_internal_map - maps SH2 built-ins
158-------------------------------------------------*/
159
160static ADDRESS_MAP_START( sh2_internal_map, AS_PROGRAM, 32, sh2_device )
161    AM_RANGE(0x40000000, 0xbfffffff) AM_READ(sh2_internal_a5)
162    AM_RANGE(0xe0000000, 0xffffffff) AM_READWRITE(sh2_internal_r, sh2_internal_w)
163ADDRESS_MAP_END
164
165
166sh2_device::sh2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
167   : cpu_device(mconfig, SH2, "SH-2", tag, owner, clock, "sh2", __FILE__)
168   , m_program_config("program", ENDIANNESS_BIG, 32, 32, 0, ADDRESS_MAP_NAME(sh2_internal_map))
169   , m_cpu_type(CPU_TYPE_SH2)
170   , m_cache(CACHE_SIZE + sizeof(internal_sh2_state))
171   , m_drcuml(NULL)
172//   , m_drcuml(*this, m_cache, ( LOG_UML ? DRCUML_OPTION_LOG_UML : 0 ) | ( LOG_NATIVE ? DRCUML_OPTION_LOG_NATIVE : 0 ), 1, 32, 1)
173   , m_drcfe(NULL)
174   , m_drcoptions(0)
175   , m_sh2_state(NULL)
176   , m_entry(NULL)
177   , m_read8(NULL)
178   , m_write8(NULL)
179   , m_read16(NULL)
180   , m_write16(NULL)
181   , m_read32(NULL)
182   , m_write32(NULL)
183   , m_interrupt(NULL)
184   , m_nocode(NULL)
185   , m_out_of_cycles(NULL)
186{
187   m_isdrc = mconfig.options().drc() ? true : false;
188}
189
190
191void sh2_device::device_stop()
192{
193   /* clean up the DRC */
194   if ( m_drcuml )
195   {
196      auto_free(machine(), m_drcuml);
197   }
198}
199
200
201sh2_device::sh2_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source, int cpu_type)
202   : cpu_device(mconfig, type, name, tag, owner, clock, shortname, source)
203   , m_program_config("program", ENDIANNESS_BIG, 32, 32, 0, ADDRESS_MAP_NAME(sh2_internal_map))
204   , m_cpu_type(cpu_type)
205   , m_cache(CACHE_SIZE + sizeof(internal_sh2_state))
206   , m_drcuml(NULL)
207//   , m_drcuml(*this, m_cache, ( LOG_UML ? DRCUML_OPTION_LOG_UML : 0 ) | ( LOG_NATIVE ? DRCUML_OPTION_LOG_NATIVE : 0 ), 1, 32, 1)
208   , m_drcfe(NULL)
209   , m_drcoptions(0)
210   , m_sh2_state(NULL)
211   , m_entry(NULL)
212   , m_read8(NULL)
213   , m_write8(NULL)
214   , m_read16(NULL)
215   , m_write16(NULL)
216   , m_read32(NULL)
217   , m_write32(NULL)
218   , m_interrupt(NULL)
219   , m_nocode(NULL)
220   , m_out_of_cycles(NULL)
221{
222   m_isdrc = mconfig.options().drc() ? true : false;
223}
224
225sh1_device::sh1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
226   : sh2_device(mconfig, SH1, "SH-1", tag, owner, clock, "sh1", __FILE__, CPU_TYPE_SH1 )
227{
228}
229
230
231offs_t sh2_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
232{
233   extern CPU_DISASSEMBLE( sh2 );
234   return CPU_DISASSEMBLE_NAME( sh2 )(this, buffer, pc, oprom, opram, options);
235}
236
237
238void sh2_device::device_config_complete()
239{
240   // inherit a copy of the static data
241   const sh2_cpu_core *intf = reinterpret_cast<const sh2_cpu_core *>(static_config());
242   if (intf != NULL)
243      *static_cast<sh2_cpu_core *>(this) = *intf;
244
245   // or initialize to defaults if none provided
246   else
247   {
248      memset(&dma_callback_kludge, 0, sizeof(dma_callback_kludge));
249      memset(&dma_callback_fifo_data_available, 0, sizeof(dma_callback_fifo_data_available));
250      is_slave = 0;
251   }
252}
253
254
116255/* speed up delay loops, bail out of tight loops */
117256#define BUSY_LOOP_HACKS     1
118257
r29565r29566
120259
121260#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
122261
123INLINE sh2_state *get_safe_token(device_t *device)
124{
125   assert(device != NULL);
126   assert(device->type() == SH1_INT ||
127         device->type() == SH2_INT);
128   return (sh2_state *)downcast<legacy_cpu_device *>(device)->token();
129}
130262
131INLINE UINT8 RB(sh2_state *sh2, offs_t A)
263UINT8 sh2_device::RB(offs_t A)
132264{
133265   if (A >= 0xe0000000)
134      return sh2_internal_r(*sh2->internal, (A & 0x1fc)>>2, 0xff << (((~A) & 3)*8)) >> (((~A) & 3)*8);
266      return sh2_internal_r(*m_internal, (A & 0x1fc)>>2, 0xff << (((~A) & 3)*8)) >> (((~A) & 3)*8);
135267
136268   if (A >= 0xc0000000)
137      return sh2->program->read_byte(A);
269      return m_program->read_byte(A);
138270
139271   if (A >= 0x40000000)
140272      return 0xa5;
141273
142   return sh2->program->read_byte(A & AM);
274   return m_program->read_byte(A & AM);
143275}
144276
145INLINE UINT16 RW(sh2_state *sh2, offs_t A)
277UINT16 sh2_device::RW(offs_t A)
146278{
147279   if (A >= 0xe0000000)
148      return sh2_internal_r(*sh2->internal, (A & 0x1fc)>>2, 0xffff << (((~A) & 2)*8)) >> (((~A) & 2)*8);
280      return sh2_internal_r(*m_internal, (A & 0x1fc)>>2, 0xffff << (((~A) & 2)*8)) >> (((~A) & 2)*8);
149281
150282   if (A >= 0xc0000000)
151      return sh2->program->read_word(A);
283      return m_program->read_word(A);
152284
153285   if (A >= 0x40000000)
154286      return 0xa5a5;
155287
156   return sh2->program->read_word(A & AM);
288   return m_program->read_word(A & AM);
157289}
158290
159INLINE UINT32 RL(sh2_state *sh2, offs_t A)
291UINT32 sh2_device::RL(offs_t A)
160292{
161   if (A >= 0xe0000000)
162      return sh2_internal_r(*sh2->internal, (A & 0x1fc)>>2, 0xffffffff);
293   if (A >= 0xe0000000) /* I/O */
294      return sh2_internal_r(*m_internal, (A & 0x1fc)>>2, 0xffffffff);
163295
164   if (A >= 0xc0000000)
165      return sh2->program->read_dword(A);
296   if (A >= 0xc0000000) /* Cache Data Array */
297      return m_program->read_dword(A);
166298
167   if (A >= 0x40000000)
299   if (A >= 0x40000000) /* Cache Associative Purge Area */
168300      return 0xa5a5a5a5;
169301
170   return sh2->program->read_dword(A & AM);
302   /* 0x20000000 no Cache */
303   /* 0x00000000 read thru Cache if CE bit is 1 */
304   return m_program->read_dword(A & AM);
171305}
172306
173INLINE void WB(sh2_state *sh2, offs_t A, UINT8 V)
307void sh2_device::WB(offs_t A, UINT8 V)
174308{
175309   if (A >= 0xe0000000)
176310   {
177      sh2_internal_w(*sh2->internal, (A & 0x1fc)>>2, V << (((~A) & 3)*8), 0xff << (((~A) & 3)*8));
311      sh2_internal_w(*m_internal, (A & 0x1fc)>>2, V << (((~A) & 3)*8), 0xff << (((~A) & 3)*8));
178312      return;
179313   }
180314
181315   if (A >= 0xc0000000)
182316   {
183      sh2->program->write_byte(A,V);
317      m_program->write_byte(A,V);
184318      return;
185319   }
186320
187321   if (A >= 0x40000000)
188322      return;
189323
190   sh2->program->write_byte(A & AM,V);
324   m_program->write_byte(A & AM,V);
191325}
192326
193INLINE void WW(sh2_state *sh2, offs_t A, UINT16 V)
327void sh2_device::WW(offs_t A, UINT16 V)
194328{
195329   if (A >= 0xe0000000)
196330   {
197      sh2_internal_w(*sh2->internal, (A & 0x1fc)>>2, V << (((~A) & 2)*8), 0xffff << (((~A) & 2)*8));
331      sh2_internal_w(*m_internal, (A & 0x1fc)>>2, V << (((~A) & 2)*8), 0xffff << (((~A) & 2)*8));
198332      return;
199333   }
200334
201335   if (A >= 0xc0000000)
202336   {
203      sh2->program->write_word(A,V);
337      m_program->write_word(A,V);
204338      return;
205339   }
206340
207341   if (A >= 0x40000000)
208342      return;
209343
210   sh2->program->write_word(A & AM,V);
344   m_program->write_word(A & AM,V);
211345}
212346
213INLINE void WL(sh2_state *sh2, offs_t A, UINT32 V)
347void sh2_device::WL(offs_t A, UINT32 V)
214348{
215   if (A >= 0xe0000000)
349   if (A >= 0xe0000000) /* I/O */
216350   {
217      sh2_internal_w(*sh2->internal, (A & 0x1fc)>>2, V, 0xffffffff);
351      sh2_internal_w(*m_internal, (A & 0x1fc)>>2, V, 0xffffffff);
218352      return;
219353   }
220354
221   if (A >= 0xc0000000)
355   if (A >= 0xc0000000) /* Cache Data Array */
222356   {
223      sh2->program->write_dword(A,V);
357      m_program->write_dword(A,V);
224358      return;
225359   }
226360
227   if (A >= 0x40000000)
361   /*  0x60000000 Cache Address Data Array */
362
363   if (A >= 0x40000000) /* Cache Associative Purge Area */
228364      return;
229365
230   sh2->program->write_dword(A & AM,V);
366   /* 0x20000000 no Cache */
367   /* 0x00000000 read thru Cache if CE bit is 1 */
368   m_program->write_dword(A & AM,V);
231369}
232370
233371/*  code                 cycles  t-bit
234372 *  0011 nnnn mmmm 1100  1       -
235373 *  ADD     Rm,Rn
236374 */
237INLINE void ADD(sh2_state *sh2, UINT32 m, UINT32 n)
375void sh2_device::ADD(UINT32 m, UINT32 n)
238376{
239   sh2->r[n] += sh2->r[m];
377   m_sh2_state->r[n] += m_sh2_state->r[m];
240378}
241379
242380/*  code                 cycles  t-bit
243381 *  0111 nnnn iiii iiii  1       -
244382 *  ADD     #imm,Rn
245383 */
246INLINE void ADDI(sh2_state *sh2, UINT32 i, UINT32 n)
384void sh2_device::ADDI(UINT32 i, UINT32 n)
247385{
248   sh2->r[n] += (INT32)(INT16)(INT8)i;
386   m_sh2_state->r[n] += (INT32)(INT16)(INT8)i;
249387}
250388
251389/*  code                 cycles  t-bit
252390 *  0011 nnnn mmmm 1110  1       carry
253391 *  ADDC    Rm,Rn
254392 */
255INLINE void ADDC(sh2_state *sh2, UINT32 m, UINT32 n)
393void sh2_device::ADDC(UINT32 m, UINT32 n)
256394{
257395   UINT32 tmp0, tmp1;
258396
259   tmp1 = sh2->r[n] + sh2->r[m];
260   tmp0 = sh2->r[n];
261   sh2->r[n] = tmp1 + (sh2->sr & T);
397   tmp1 = m_sh2_state->r[n] + m_sh2_state->r[m];
398   tmp0 = m_sh2_state->r[n];
399   m_sh2_state->r[n] = tmp1 + (m_sh2_state->sr & T);
262400   if (tmp0 > tmp1)
263      sh2->sr |= T;
401      m_sh2_state->sr |= T;
264402   else
265      sh2->sr &= ~T;
266   if (tmp1 > sh2->r[n])
267      sh2->sr |= T;
403      m_sh2_state->sr &= ~T;
404   if (tmp1 > m_sh2_state->r[n])
405      m_sh2_state->sr |= T;
268406}
269407
270408/*  code                 cycles  t-bit
271409 *  0011 nnnn mmmm 1111  1       overflow
272410 *  ADDV    Rm,Rn
273411 */
274INLINE void ADDV(sh2_state *sh2, UINT32 m, UINT32 n)
412void sh2_device::ADDV(UINT32 m, UINT32 n)
275413{
276414   INT32 dest, src, ans;
277415
278   if ((INT32) sh2->r[n] >= 0)
416   if ((INT32) m_sh2_state->r[n] >= 0)
279417      dest = 0;
280418   else
281419      dest = 1;
282   if ((INT32) sh2->r[m] >= 0)
420   if ((INT32) m_sh2_state->r[m] >= 0)
283421      src = 0;
284422   else
285423      src = 1;
286424   src += dest;
287   sh2->r[n] += sh2->r[m];
288   if ((INT32) sh2->r[n] >= 0)
425   m_sh2_state->r[n] += m_sh2_state->r[m];
426   if ((INT32) m_sh2_state->r[n] >= 0)
289427      ans = 0;
290428   else
291429      ans = 1;
r29565r29566
293431   if (src == 0 || src == 2)
294432   {
295433      if (ans == 1)
296         sh2->sr |= T;
434         m_sh2_state->sr |= T;
297435      else
298         sh2->sr &= ~T;
436         m_sh2_state->sr &= ~T;
299437   }
300438   else
301      sh2->sr &= ~T;
439      m_sh2_state->sr &= ~T;
302440}
303441
304442/*  code                 cycles  t-bit
305443 *  0010 nnnn mmmm 1001  1       -
306444 *  AND     Rm,Rn
307445 */
308INLINE void AND(sh2_state *sh2, UINT32 m, UINT32 n)
446void sh2_device::AND(UINT32 m, UINT32 n)
309447{
310   sh2->r[n] &= sh2->r[m];
448   m_sh2_state->r[n] &= m_sh2_state->r[m];
311449}
312450
313451
r29565r29566
315453 *  1100 1001 iiii iiii  1       -
316454 *  AND     #imm,R0
317455 */
318INLINE void ANDI(sh2_state *sh2, UINT32 i)
456void sh2_device::ANDI(UINT32 i)
319457{
320   sh2->r[0] &= i;
458   m_sh2_state->r[0] &= i;
321459}
322460
323461/*  code                 cycles  t-bit
324462 *  1100 1101 iiii iiii  1       -
325463 *  AND.B   #imm,@(R0,GBR)
326464 */
327INLINE void ANDM(sh2_state *sh2, UINT32 i)
465void sh2_device::ANDM(UINT32 i)
328466{
329467   UINT32 temp;
330468
331   sh2->ea = sh2->gbr + sh2->r[0];
332   temp = i & RB( sh2, sh2->ea );
333   WB( sh2, sh2->ea, temp );
334   sh2->icount -= 2;
469   m_sh2_state->ea = m_sh2_state->gbr + m_sh2_state->r[0];
470   temp = i & RB( m_sh2_state->ea );
471   WB( m_sh2_state->ea, temp );
472   m_sh2_state->icount -= 2;
335473}
336474
337475/*  code                 cycles  t-bit
338476 *  1000 1011 dddd dddd  3/1     -
339477 *  BF      disp8
340478 */
341INLINE void BF(sh2_state *sh2, UINT32 d)
479void sh2_device::BF(UINT32 d)
342480{
343   if ((sh2->sr & T) == 0)
481   if ((m_sh2_state->sr & T) == 0)
344482   {
345483      INT32 disp = ((INT32)d << 24) >> 24;
346      sh2->pc = sh2->ea = sh2->pc + disp * 2 + 2;
347      sh2->icount -= 2;
484      m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
485      m_sh2_state->icount -= 2;
348486   }
349487}
350488
r29565r29566
352490 *  1000 1111 dddd dddd  3/1     -
353491 *  BFS     disp8
354492 */
355INLINE void BFS(sh2_state *sh2, UINT32 d)
493void sh2_device::BFS(UINT32 d)
356494{
357   if ((sh2->sr & T) == 0)
495   if ((m_sh2_state->sr & T) == 0)
358496   {
359497      INT32 disp = ((INT32)d << 24) >> 24;
360      sh2->delay = sh2->pc;
361      sh2->pc = sh2->ea = sh2->pc + disp * 2 + 2;
362      sh2->icount--;
498      m_delay = m_sh2_state->pc;
499      m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
500      m_sh2_state->icount--;
363501   }
364502}
365503
r29565r29566
367505 *  1010 dddd dddd dddd  2       -
368506 *  BRA     disp12
369507 */
370INLINE void BRA(sh2_state *sh2, UINT32 d)
508void sh2_device::BRA(UINT32 d)
371509{
372510   INT32 disp = ((INT32)d << 20) >> 20;
373511
374512#if BUSY_LOOP_HACKS
375513   if (disp == -2)
376514   {
377      UINT32 next_opcode = RW( sh2, sh2->ppc & AM );
515      UINT32 next_opcode = RW( m_sh2_state->ppc & AM );
378516      /* BRA  $
379517       * NOP
380518       */
381519      if (next_opcode == 0x0009)
382         sh2->icount %= 3;   /* cycles for BRA $ and NOP taken (3) */
520         m_sh2_state->icount %= 3;   /* cycles for BRA $ and NOP taken (3) */
383521   }
384522#endif
385   sh2->delay = sh2->pc;
386   sh2->pc = sh2->ea = sh2->pc + disp * 2 + 2;
387   sh2->icount--;
523   m_delay = m_sh2_state->pc;
524   m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
525   m_sh2_state->icount--;
388526}
389527
390528/*  code                 cycles  t-bit
391529 *  0000 mmmm 0010 0011  2       -
392530 *  BRAF    Rm
393531 */
394INLINE void BRAF(sh2_state *sh2, UINT32 m)
532void sh2_device::BRAF(UINT32 m)
395533{
396   sh2->delay = sh2->pc;
397   sh2->pc += sh2->r[m] + 2;
398   sh2->icount--;
534   m_delay = m_sh2_state->pc;
535   m_sh2_state->pc += m_sh2_state->r[m] + 2;
536   m_sh2_state->icount--;
399537}
400538
401539/*  code                 cycles  t-bit
402540 *  1011 dddd dddd dddd  2       -
403541 *  BSR     disp12
404542 */
405INLINE void BSR(sh2_state *sh2, UINT32 d)
543void sh2_device::BSR(UINT32 d)
406544{
407545   INT32 disp = ((INT32)d << 20) >> 20;
408546
409   sh2->pr = sh2->pc + 2;
410   sh2->delay = sh2->pc;
411   sh2->pc = sh2->ea = sh2->pc + disp * 2 + 2;
412   sh2->icount--;
547   m_sh2_state->pr = m_sh2_state->pc + 2;
548   m_delay = m_sh2_state->pc;
549   m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
550   m_sh2_state->icount--;
413551}
414552
415553/*  code                 cycles  t-bit
416554 *  0000 mmmm 0000 0011  2       -
417555 *  BSRF    Rm
418556 */
419INLINE void BSRF(sh2_state *sh2, UINT32 m)
557void sh2_device::BSRF(UINT32 m)
420558{
421   sh2->pr = sh2->pc + 2;
422   sh2->delay = sh2->pc;
423   sh2->pc += sh2->r[m] + 2;
424   sh2->icount--;
559   m_sh2_state->pr = m_sh2_state->pc + 2;
560   m_delay = m_sh2_state->pc;
561   m_sh2_state->pc += m_sh2_state->r[m] + 2;
562   m_sh2_state->icount--;
425563}
426564
427565/*  code                 cycles  t-bit
428566 *  1000 1001 dddd dddd  3/1     -
429567 *  BT      disp8
430568 */
431INLINE void BT(sh2_state *sh2, UINT32 d)
569void sh2_device::BT(UINT32 d)
432570{
433   if ((sh2->sr & T) != 0)
571   if ((m_sh2_state->sr & T) != 0)
434572   {
435573      INT32 disp = ((INT32)d << 24) >> 24;
436      sh2->pc = sh2->ea = sh2->pc + disp * 2 + 2;
437      sh2->icount -= 2;
574      m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
575      m_sh2_state->icount -= 2;
438576   }
439577}
440578
r29565r29566
442580 *  1000 1101 dddd dddd  2/1     -
443581 *  BTS     disp8
444582 */
445INLINE void BTS(sh2_state *sh2, UINT32 d)
583void sh2_device::BTS(UINT32 d)
446584{
447   if ((sh2->sr & T) != 0)
585   if ((m_sh2_state->sr & T) != 0)
448586   {
449587      INT32 disp = ((INT32)d << 24) >> 24;
450      sh2->delay = sh2->pc;
451      sh2->pc = sh2->ea = sh2->pc + disp * 2 + 2;
452      sh2->icount--;
588      m_delay = m_sh2_state->pc;
589      m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
590      m_sh2_state->icount--;
453591   }
454592}
455593
r29565r29566
457595 *  0000 0000 0010 1000  1       -
458596 *  CLRMAC
459597 */
460INLINE void CLRMAC(sh2_state *sh2)
598void sh2_device::CLRMAC()
461599{
462   sh2->mach = 0;
463   sh2->macl = 0;
600   m_sh2_state->mach = 0;
601   m_sh2_state->macl = 0;
464602}
465603
466604/*  code                 cycles  t-bit
467605 *  0000 0000 0000 1000  1       -
468606 *  CLRT
469607 */
470INLINE void CLRT(sh2_state *sh2)
608void sh2_device::CLRT()
471609{
472   sh2->sr &= ~T;
610   m_sh2_state->sr &= ~T;
473611}
474612
475613/*  code                 cycles  t-bit
476614 *  0011 nnnn mmmm 0000  1       comparison result
477615 *  CMP_EQ  Rm,Rn
478616 */
479INLINE void CMPEQ(sh2_state *sh2, UINT32 m, UINT32 n)
617void sh2_device::CMPEQ(UINT32 m, UINT32 n)
480618{
481   if (sh2->r[n] == sh2->r[m])
482      sh2->sr |= T;
619   if (m_sh2_state->r[n] == m_sh2_state->r[m])
620      m_sh2_state->sr |= T;
483621   else
484      sh2->sr &= ~T;
622      m_sh2_state->sr &= ~T;
485623}
486624
487625/*  code                 cycles  t-bit
488626 *  0011 nnnn mmmm 0011  1       comparison result
489627 *  CMP_GE  Rm,Rn
490628 */
491INLINE void CMPGE(sh2_state *sh2, UINT32 m, UINT32 n)
629void sh2_device::CMPGE(UINT32 m, UINT32 n)
492630{
493   if ((INT32) sh2->r[n] >= (INT32) sh2->r[m])
494      sh2->sr |= T;
631   if ((INT32) m_sh2_state->r[n] >= (INT32) m_sh2_state->r[m])
632      m_sh2_state->sr |= T;
495633   else
496      sh2->sr &= ~T;
634      m_sh2_state->sr &= ~T;
497635}
498636
499637/*  code                 cycles  t-bit
500638 *  0011 nnnn mmmm 0111  1       comparison result
501639 *  CMP_GT  Rm,Rn
502640 */
503INLINE void CMPGT(sh2_state *sh2, UINT32 m, UINT32 n)
641void sh2_device::CMPGT(UINT32 m, UINT32 n)
504642{
505   if ((INT32) sh2->r[n] > (INT32) sh2->r[m])
506      sh2->sr |= T;
643   if ((INT32) m_sh2_state->r[n] > (INT32) m_sh2_state->r[m])
644      m_sh2_state->sr |= T;
507645   else
508      sh2->sr &= ~T;
646      m_sh2_state->sr &= ~T;
509647}
510648
511649/*  code                 cycles  t-bit
512650 *  0011 nnnn mmmm 0110  1       comparison result
513651 *  CMP_HI  Rm,Rn
514652 */
515INLINE void CMPHI(sh2_state *sh2, UINT32 m, UINT32 n)
653void sh2_device::CMPHI(UINT32 m, UINT32 n)
516654{
517   if ((UINT32) sh2->r[n] > (UINT32) sh2->r[m])
518      sh2->sr |= T;
655   if ((UINT32) m_sh2_state->r[n] > (UINT32) m_sh2_state->r[m])
656      m_sh2_state->sr |= T;
519657   else
520      sh2->sr &= ~T;
658      m_sh2_state->sr &= ~T;
521659}
522660
523661/*  code                 cycles  t-bit
524662 *  0011 nnnn mmmm 0010  1       comparison result
525663 *  CMP_HS  Rm,Rn
526664 */
527INLINE void CMPHS(sh2_state *sh2, UINT32 m, UINT32 n)
665void sh2_device::CMPHS(UINT32 m, UINT32 n)
528666{
529   if ((UINT32) sh2->r[n] >= (UINT32) sh2->r[m])
530      sh2->sr |= T;
667   if ((UINT32) m_sh2_state->r[n] >= (UINT32) m_sh2_state->r[m])
668      m_sh2_state->sr |= T;
531669   else
532      sh2->sr &= ~T;
670      m_sh2_state->sr &= ~T;
533671}
534672
535673
r29565r29566
537675 *  0100 nnnn 0001 0101  1       comparison result
538676 *  CMP_PL  Rn
539677 */
540INLINE void CMPPL(sh2_state *sh2, UINT32 n)
678void sh2_device::CMPPL(UINT32 n)
541679{
542   if ((INT32) sh2->r[n] > 0)
543      sh2->sr |= T;
680   if ((INT32) m_sh2_state->r[n] > 0)
681      m_sh2_state->sr |= T;
544682   else
545      sh2->sr &= ~T;
683      m_sh2_state->sr &= ~T;
546684}
547685
548686/*  code                 cycles  t-bit
549687 *  0100 nnnn 0001 0001  1       comparison result
550688 *  CMP_PZ  Rn
551689 */
552INLINE void CMPPZ(sh2_state *sh2, UINT32 n)
690void sh2_device::CMPPZ(UINT32 n)
553691{
554   if ((INT32) sh2->r[n] >= 0)
555      sh2->sr |= T;
692   if ((INT32) m_sh2_state->r[n] >= 0)
693      m_sh2_state->sr |= T;
556694   else
557      sh2->sr &= ~T;
695      m_sh2_state->sr &= ~T;
558696}
559697
560698/*  code                 cycles  t-bit
561699 *  0010 nnnn mmmm 1100  1       comparison result
562700 * CMP_STR  Rm,Rn
563701 */
564INLINE void CMPSTR(sh2_state *sh2, UINT32 m, UINT32 n)
702void sh2_device::CMPSTR(UINT32 m, UINT32 n)
565703   {
566704   UINT32 temp;
567705   INT32 HH, HL, LH, LL;
568   temp = sh2->r[n] ^ sh2->r[m];
706   temp = m_sh2_state->r[n] ^ m_sh2_state->r[m];
569707   HH = (temp >> 24) & 0xff;
570708   HL = (temp >> 16) & 0xff;
571709   LH = (temp >> 8) & 0xff;
572710   LL = temp & 0xff;
573711   if (HH && HL && LH && LL)
574   sh2->sr &= ~T;
712   m_sh2_state->sr &= ~T;
575713   else
576   sh2->sr |= T;
714   m_sh2_state->sr |= T;
577715   }
578716
579717
r29565r29566
581719 *  1000 1000 iiii iiii  1       comparison result
582720 *  CMP/EQ #imm,R0
583721 */
584INLINE void CMPIM(sh2_state *sh2, UINT32 i)
722void sh2_device::CMPIM(UINT32 i)
585723{
586724   UINT32 imm = (UINT32)(INT32)(INT16)(INT8)i;
587725
588   if (sh2->r[0] == imm)
589      sh2->sr |= T;
726   if (m_sh2_state->r[0] == imm)
727      m_sh2_state->sr |= T;
590728   else
591      sh2->sr &= ~T;
729      m_sh2_state->sr &= ~T;
592730}
593731
594732/*  code                 cycles  t-bit
595733 *  0010 nnnn mmmm 0111  1       calculation result
596734 *  DIV0S   Rm,Rn
597735 */
598INLINE void DIV0S(sh2_state *sh2, UINT32 m, UINT32 n)
736void sh2_device::DIV0S(UINT32 m, UINT32 n)
599737{
600   if ((sh2->r[n] & 0x80000000) == 0)
601      sh2->sr &= ~Q;
738   if ((m_sh2_state->r[n] & 0x80000000) == 0)
739      m_sh2_state->sr &= ~Q;
602740   else
603      sh2->sr |= Q;
604   if ((sh2->r[m] & 0x80000000) == 0)
605      sh2->sr &= ~M;
741      m_sh2_state->sr |= Q;
742   if ((m_sh2_state->r[m] & 0x80000000) == 0)
743      m_sh2_state->sr &= ~M;
606744   else
607      sh2->sr |= M;
608   if ((sh2->r[m] ^ sh2->r[n]) & 0x80000000)
609      sh2->sr |= T;
745      m_sh2_state->sr |= M;
746   if ((m_sh2_state->r[m] ^ m_sh2_state->r[n]) & 0x80000000)
747      m_sh2_state->sr |= T;
610748   else
611      sh2->sr &= ~T;
749      m_sh2_state->sr &= ~T;
612750}
613751
614752/*  code                 cycles  t-bit
615753 *  0000 0000 0001 1001  1       0
616754 *  DIV0U
617755 */
618INLINE void DIV0U(sh2_state *sh2)
756void sh2_device::DIV0U()
619757{
620   sh2->sr &= ~(M | Q | T);
758   m_sh2_state->sr &= ~(M | Q | T);
621759}
622760
623761/*  code                 cycles  t-bit
624762 *  0011 nnnn mmmm 0100  1       calculation result
625763 *  DIV1 Rm,Rn
626764 */
627INLINE void DIV1(sh2_state *sh2, UINT32 m, UINT32 n)
765void sh2_device::DIV1(UINT32 m, UINT32 n)
628766{
629767   UINT32 tmp0;
630768   UINT32 old_q;
631769
632   old_q = sh2->sr & Q;
633   if (0x80000000 & sh2->r[n])
634      sh2->sr |= Q;
770   old_q = m_sh2_state->sr & Q;
771   if (0x80000000 & m_sh2_state->r[n])
772      m_sh2_state->sr |= Q;
635773   else
636      sh2->sr &= ~Q;
774      m_sh2_state->sr &= ~Q;
637775
638   sh2->r[n] = (sh2->r[n] << 1) | (sh2->sr & T);
776   m_sh2_state->r[n] = (m_sh2_state->r[n] << 1) | (m_sh2_state->sr & T);
639777
640778   if (!old_q)
641779   {
642      if (!(sh2->sr & M))
780      if (!(m_sh2_state->sr & M))
643781      {
644         tmp0 = sh2->r[n];
645         sh2->r[n] -= sh2->r[m];
646         if(!(sh2->sr & Q))
647            if(sh2->r[n] > tmp0)
648               sh2->sr |= Q;
782         tmp0 = m_sh2_state->r[n];
783         m_sh2_state->r[n] -= m_sh2_state->r[m];
784         if(!(m_sh2_state->sr & Q))
785            if(m_sh2_state->r[n] > tmp0)
786               m_sh2_state->sr |= Q;
649787            else
650               sh2->sr &= ~Q;
788               m_sh2_state->sr &= ~Q;
651789         else
652            if(sh2->r[n] > tmp0)
653               sh2->sr &= ~Q;
790            if(m_sh2_state->r[n] > tmp0)
791               m_sh2_state->sr &= ~Q;
654792            else
655               sh2->sr |= Q;
793               m_sh2_state->sr |= Q;
656794      }
657795      else
658796      {
659         tmp0 = sh2->r[n];
660         sh2->r[n] += sh2->r[m];
661         if(!(sh2->sr & Q))
797         tmp0 = m_sh2_state->r[n];
798         m_sh2_state->r[n] += m_sh2_state->r[m];
799         if(!(m_sh2_state->sr & Q))
662800         {
663            if(sh2->r[n] < tmp0)
664               sh2->sr &= ~Q;
801            if(m_sh2_state->r[n] < tmp0)
802               m_sh2_state->sr &= ~Q;
665803            else
666               sh2->sr |= Q;
804               m_sh2_state->sr |= Q;
667805         }
668806         else
669807         {
670            if(sh2->r[n] < tmp0)
671               sh2->sr |= Q;
808            if(m_sh2_state->r[n] < tmp0)
809               m_sh2_state->sr |= Q;
672810            else
673               sh2->sr &= ~Q;
811               m_sh2_state->sr &= ~Q;
674812         }
675813      }
676814   }
677815   else
678816   {
679      if (!(sh2->sr & M))
817      if (!(m_sh2_state->sr & M))
680818      {
681         tmp0 = sh2->r[n];
682         sh2->r[n] += sh2->r[m];
683         if(!(sh2->sr & Q))
684            if(sh2->r[n] < tmp0)
685               sh2->sr |= Q;
819         tmp0 = m_sh2_state->r[n];
820         m_sh2_state->r[n] += m_sh2_state->r[m];
821         if(!(m_sh2_state->sr & Q))
822            if(m_sh2_state->r[n] < tmp0)
823               m_sh2_state->sr |= Q;
686824            else
687               sh2->sr &= ~Q;
825               m_sh2_state->sr &= ~Q;
688826         else
689            if(sh2->r[n] < tmp0)
690               sh2->sr &= ~Q;
827            if(m_sh2_state->r[n] < tmp0)
828               m_sh2_state->sr &= ~Q;
691829            else
692               sh2->sr |= Q;
830               m_sh2_state->sr |= Q;
693831      }
694832      else
695833      {
696         tmp0 = sh2->r[n];
697         sh2->r[n] -= sh2->r[m];
698         if(!(sh2->sr & Q))
699            if(sh2->r[n] > tmp0)
700               sh2->sr &= ~Q;
834         tmp0 = m_sh2_state->r[n];
835         m_sh2_state->r[n] -= m_sh2_state->r[m];
836         if(!(m_sh2_state->sr & Q))
837            if(m_sh2_state->r[n] > tmp0)
838               m_sh2_state->sr &= ~Q;
701839            else
702               sh2->sr |= Q;
840               m_sh2_state->sr |= Q;
703841         else
704            if(sh2->r[n] > tmp0)
705               sh2->sr |= Q;
842            if(m_sh2_state->r[n] > tmp0)
843               m_sh2_state->sr |= Q;
706844            else
707               sh2->sr &= ~Q;
845               m_sh2_state->sr &= ~Q;
708846      }
709847   }
710848
711   tmp0 = (sh2->sr & (Q | M));
849   tmp0 = (m_sh2_state->sr & (Q | M));
712850   if((!tmp0) || (tmp0 == 0x300)) /* if Q == M set T else clear T */
713      sh2->sr |= T;
851      m_sh2_state->sr |= T;
714852   else
715      sh2->sr &= ~T;
853      m_sh2_state->sr &= ~T;
716854}
717855
718856/*  DMULS.L Rm,Rn */
719INLINE void DMULS(sh2_state *sh2, UINT32 m, UINT32 n)
857void sh2_device::DMULS(UINT32 m, UINT32 n)
720858{
721859   UINT32 RnL, RnH, RmL, RmH, Res0, Res1, Res2;
722860   UINT32 temp0, temp1, temp2, temp3;
723861   INT32 tempm, tempn, fnLmL;
724862
725   tempn = (INT32) sh2->r[n];
726   tempm = (INT32) sh2->r[m];
863   tempn = (INT32) m_sh2_state->r[n];
864   tempm = (INT32) m_sh2_state->r[m];
727865   if (tempn < 0)
728866      tempn = 0 - tempn;
729867   if (tempm < 0)
730868      tempm = 0 - tempm;
731   if ((INT32) (sh2->r[n] ^ sh2->r[m]) < 0)
869   if ((INT32) (m_sh2_state->r[n] ^ m_sh2_state->r[m]) < 0)
732870      fnLmL = -1;
733871   else
734872      fnLmL = 0;
r29565r29566
759897      else
760898         Res0 = (~Res0) + 1;
761899   }
762   sh2->mach = Res2;
763   sh2->macl = Res0;
764   sh2->icount--;
900   m_sh2_state->mach = Res2;
901   m_sh2_state->macl = Res0;
902   m_sh2_state->icount--;
765903}
766904
767905/*  DMULU.L Rm,Rn */
768INLINE void DMULU(sh2_state *sh2, UINT32 m, UINT32 n)
906void sh2_device::DMULU(UINT32 m, UINT32 n)
769907{
770908   UINT32 RnL, RnH, RmL, RmH, Res0, Res1, Res2;
771909   UINT32 temp0, temp1, temp2, temp3;
772910
773   RnL = sh2->r[n] & 0x0000ffff;
774   RnH = (sh2->r[n] >> 16) & 0x0000ffff;
775   RmL = sh2->r[m] & 0x0000ffff;
776   RmH = (sh2->r[m] >> 16) & 0x0000ffff;
911   RnL = m_sh2_state->r[n] & 0x0000ffff;
912   RnH = (m_sh2_state->r[n] >> 16) & 0x0000ffff;
913   RmL = m_sh2_state->r[m] & 0x0000ffff;
914   RmH = (m_sh2_state->r[m] >> 16) & 0x0000ffff;
777915   temp0 = RmL * RnL;
778916   temp1 = RmH * RnL;
779917   temp2 = RmL * RnH;
r29565r29566
787925   if (Res0 < temp0)
788926      Res2++;
789927   Res2 = Res2 + ((Res1 >> 16) & 0x0000ffff) + temp3;
790   sh2->mach = Res2;
791   sh2->macl = Res0;
792   sh2->icount--;
928   m_sh2_state->mach = Res2;
929   m_sh2_state->macl = Res0;
930   m_sh2_state->icount--;
793931}
794932
795933/*  DT      Rn */
796INLINE void DT(sh2_state *sh2, UINT32 n)
934void sh2_device::DT(UINT32 n)
797935{
798   sh2->r[n]--;
799   if (sh2->r[n] == 0)
800      sh2->sr |= T;
936   m_sh2_state->r[n]--;
937   if (m_sh2_state->r[n] == 0)
938      m_sh2_state->sr |= T;
801939   else
802      sh2->sr &= ~T;
940      m_sh2_state->sr &= ~T;
803941#if BUSY_LOOP_HACKS
804942   {
805      UINT32 next_opcode = RW( sh2, sh2->ppc & AM );
943      UINT32 next_opcode = RW( m_sh2_state->ppc & AM );
806944      /* DT   Rn
807945       * BF   $-2
808946       */
809947      if (next_opcode == 0x8bfd)
810948      {
811         while (sh2->r[n] > 1 && sh2->icount > 4)
949         while (m_sh2_state->r[n] > 1 && m_sh2_state->icount > 4)
812950         {
813            sh2->r[n]--;
814            sh2->icount -= 4;   /* cycles for DT (1) and BF taken (3) */
951            m_sh2_state->r[n]--;
952            m_sh2_state->icount -= 4;   /* cycles for DT (1) and BF taken (3) */
815953         }
816954      }
817955   }
r29565r29566
819957}
820958
821959/*  EXTS.B  Rm,Rn */
822INLINE void EXTSB(sh2_state *sh2, UINT32 m, UINT32 n)
960void sh2_device::EXTSB(UINT32 m, UINT32 n)
823961{
824   sh2->r[n] = ((INT32)sh2->r[m] << 24) >> 24;
962   m_sh2_state->r[n] = ((INT32)m_sh2_state->r[m] << 24) >> 24;
825963}
826964
827965/*  EXTS.W  Rm,Rn */
828INLINE void EXTSW(sh2_state *sh2, UINT32 m, UINT32 n)
966void sh2_device::EXTSW(UINT32 m, UINT32 n)
829967{
830   sh2->r[n] = ((INT32)sh2->r[m] << 16) >> 16;
968   m_sh2_state->r[n] = ((INT32)m_sh2_state->r[m] << 16) >> 16;
831969}
832970
833971/*  EXTU.B  Rm,Rn */
834INLINE void EXTUB(sh2_state *sh2, UINT32 m, UINT32 n)
972void sh2_device::EXTUB(UINT32 m, UINT32 n)
835973{
836   sh2->r[n] = sh2->r[m] & 0x000000ff;
974   m_sh2_state->r[n] = m_sh2_state->r[m] & 0x000000ff;
837975}
838976
839977/*  EXTU.W  Rm,Rn */
840INLINE void EXTUW(sh2_state *sh2, UINT32 m, UINT32 n)
978void sh2_device::EXTUW(UINT32 m, UINT32 n)
841979{
842   sh2->r[n] = sh2->r[m] & 0x0000ffff;
980   m_sh2_state->r[n] = m_sh2_state->r[m] & 0x0000ffff;
843981}
844982
845983/*  ILLEGAL */
846INLINE void ILLEGAL(sh2_state *sh2)
984void sh2_device::ILLEGAL()
847985{
848   logerror("SH2.%s: Illegal opcode at %08x\n", sh2->device->tag(), sh2->pc - 2);
849   sh2->r[15] -= 4;
850   WL( sh2, sh2->r[15], sh2->sr );     /* push SR onto stack */
851   sh2->r[15] -= 4;
852   WL( sh2, sh2->r[15], sh2->pc - 2 ); /* push PC onto stack */
986   logerror("SH2.%s: Illegal opcode at %08x\n", tag(), m_sh2_state->pc - 2);
987   m_sh2_state->r[15] -= 4;
988   WL( m_sh2_state->r[15], m_sh2_state->sr );     /* push SR onto stack */
989   m_sh2_state->r[15] -= 4;
990   WL( m_sh2_state->r[15], m_sh2_state->pc - 2 ); /* push PC onto stack */
853991
854992   /* fetch PC */
855   sh2->pc = RL( sh2, sh2->vbr + 4 * 4 );
993   m_sh2_state->pc = RL( m_sh2_state->vbr + 4 * 4 );
856994
857995   /* TODO: timing is a guess */
858   sh2->icount -= 5;
996   m_sh2_state->icount -= 5;
859997}
860998
861999
8621000/*  JMP     @Rm */
863INLINE void JMP(sh2_state *sh2, UINT32 m)
1001void sh2_device::JMP(UINT32 m)
8641002{
865   sh2->delay = sh2->pc;
866   sh2->pc = sh2->ea = sh2->r[m];
867   sh2->icount--;
1003   m_delay = m_sh2_state->pc;
1004   m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->r[m];
1005   m_sh2_state->icount--;
8681006}
8691007
8701008/*  JSR     @Rm */
871INLINE void JSR(sh2_state *sh2, UINT32 m)
1009void sh2_device::JSR(UINT32 m)
8721010{
873   sh2->delay = sh2->pc;
874   sh2->pr = sh2->pc + 2;
875   sh2->pc = sh2->ea = sh2->r[m];
876   sh2->icount--;
1011   m_delay = m_sh2_state->pc;
1012   m_sh2_state->pr = m_sh2_state->pc + 2;
1013   m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->r[m];
1014   m_sh2_state->icount--;
8771015}
8781016
8791017
8801018/*  LDC     Rm,SR */
881INLINE void LDCSR(sh2_state *sh2, UINT32 m)
1019void sh2_device::LDCSR(UINT32 m)
8821020{
883   sh2->sr = sh2->r[m] & FLAGS;
884   sh2->test_irq = 1;
1021   m_sh2_state->sr = m_sh2_state->r[m] & FLAGS;
1022   m_test_irq = 1;
8851023}
8861024
8871025/*  LDC     Rm,GBR */
888INLINE void LDCGBR(sh2_state *sh2, UINT32 m)
1026void sh2_device::LDCGBR(UINT32 m)
8891027{
890   sh2->gbr = sh2->r[m];
1028   m_sh2_state->gbr = m_sh2_state->r[m];
8911029}
8921030
8931031/*  LDC     Rm,VBR */
894INLINE void LDCVBR(sh2_state *sh2, UINT32 m)
1032void sh2_device::LDCVBR(UINT32 m)
8951033{
896   sh2->vbr = sh2->r[m];
1034   m_sh2_state->vbr = m_sh2_state->r[m];
8971035}
8981036
8991037/*  LDC.L   @Rm+,SR */
900INLINE void LDCMSR(sh2_state *sh2, UINT32 m)
1038void sh2_device::LDCMSR(UINT32 m)
9011039{
902   sh2->ea = sh2->r[m];
903   sh2->sr = RL( sh2, sh2->ea ) & FLAGS;
904   sh2->r[m] += 4;
905   sh2->icount -= 2;
906   sh2->test_irq = 1;
1040   m_sh2_state->ea = m_sh2_state->r[m];
1041   m_sh2_state->sr = RL( m_sh2_state->ea ) & FLAGS;
1042   m_sh2_state->r[m] += 4;
1043   m_sh2_state->icount -= 2;
1044   m_test_irq = 1;
9071045}
9081046
9091047/*  LDC.L   @Rm+,GBR */
910INLINE void LDCMGBR(sh2_state *sh2, UINT32 m)
1048void sh2_device::LDCMGBR(UINT32 m)
9111049{
912   sh2->ea = sh2->r[m];
913   sh2->gbr = RL( sh2, sh2->ea );
914   sh2->r[m] += 4;
915   sh2->icount -= 2;
1050   m_sh2_state->ea = m_sh2_state->r[m];
1051   m_sh2_state->gbr = RL( m_sh2_state->ea );
1052   m_sh2_state->r[m] += 4;
1053   m_sh2_state->icount -= 2;
9161054}
9171055
9181056/*  LDC.L   @Rm+,VBR */
919INLINE void LDCMVBR(sh2_state *sh2, UINT32 m)
1057void sh2_device::LDCMVBR(UINT32 m)
9201058{
921   sh2->ea = sh2->r[m];
922   sh2->vbr = RL( sh2, sh2->ea );
923   sh2->r[m] += 4;
924   sh2->icount -= 2;
1059   m_sh2_state->ea = m_sh2_state->r[m];
1060   m_sh2_state->vbr = RL( m_sh2_state->ea );
1061   m_sh2_state->r[m] += 4;
1062   m_sh2_state->icount -= 2;
9251063}
9261064
9271065/*  LDS     Rm,MACH */
928INLINE void LDSMACH(sh2_state *sh2, UINT32 m)
1066void sh2_device::LDSMACH(UINT32 m)
9291067{
930   sh2->mach = sh2->r[m];
1068   m_sh2_state->mach = m_sh2_state->r[m];
9311069}
9321070
9331071/*  LDS     Rm,MACL */
934INLINE void LDSMACL(sh2_state *sh2, UINT32 m)
1072void sh2_device::LDSMACL(UINT32 m)
9351073{
936   sh2->macl = sh2->r[m];
1074   m_sh2_state->macl = m_sh2_state->r[m];
9371075}
9381076
9391077/*  LDS     Rm,PR */
940INLINE void LDSPR(sh2_state *sh2, UINT32 m)
1078void sh2_device::LDSPR(UINT32 m)
9411079{
942   sh2->pr = sh2->r[m];
1080   m_sh2_state->pr = m_sh2_state->r[m];
9431081}
9441082
9451083/*  LDS.L   @Rm+,MACH */
946INLINE void LDSMMACH(sh2_state *sh2, UINT32 m)
1084void sh2_device::LDSMMACH(UINT32 m)
9471085{
948   sh2->ea = sh2->r[m];
949   sh2->mach = RL( sh2, sh2->ea );
950   sh2->r[m] += 4;
1086   m_sh2_state->ea = m_sh2_state->r[m];
1087   m_sh2_state->mach = RL( m_sh2_state->ea );
1088   m_sh2_state->r[m] += 4;
9511089}
9521090
9531091/*  LDS.L   @Rm+,MACL */
954INLINE void LDSMMACL(sh2_state *sh2, UINT32 m)
1092void sh2_device::LDSMMACL(UINT32 m)
9551093{
956   sh2->ea = sh2->r[m];
957   sh2->macl = RL( sh2, sh2->ea );
958   sh2->r[m] += 4;
1094   m_sh2_state->ea = m_sh2_state->r[m];
1095   m_sh2_state->macl = RL( m_sh2_state->ea );
1096   m_sh2_state->r[m] += 4;
9591097}
9601098
9611099/*  LDS.L   @Rm+,PR */
962INLINE void LDSMPR(sh2_state *sh2, UINT32 m)
1100void sh2_device::LDSMPR(UINT32 m)
9631101{
964   sh2->ea = sh2->r[m];
965   sh2->pr = RL( sh2, sh2->ea );
966   sh2->r[m] += 4;
1102   m_sh2_state->ea = m_sh2_state->r[m];
1103   m_sh2_state->pr = RL( m_sh2_state->ea );
1104   m_sh2_state->r[m] += 4;
9671105}
9681106
9691107/*  MAC.L   @Rm+,@Rn+ */
970INLINE void MAC_L(sh2_state *sh2, UINT32 m, UINT32 n)
1108void sh2_device::MAC_L(UINT32 m, UINT32 n)
9711109{
9721110   UINT32 RnL, RnH, RmL, RmH, Res0, Res1, Res2;
9731111   UINT32 temp0, temp1, temp2, temp3;
9741112   INT32 tempm, tempn, fnLmL;
9751113
976   tempn = (INT32) RL( sh2, sh2->r[n] );
977   sh2->r[n] += 4;
978   tempm = (INT32) RL( sh2, sh2->r[m] );
979   sh2->r[m] += 4;
1114   tempn = (INT32) RL( m_sh2_state->r[n] );
1115   m_sh2_state->r[n] += 4;
1116   tempm = (INT32) RL( m_sh2_state->r[m] );
1117   m_sh2_state->r[m] += 4;
9801118   if ((INT32) (tempn ^ tempm) < 0)
9811119      fnLmL = -1;
9821120   else
r29565r29566
10121150      else
10131151         Res0 = (~Res0) + 1;
10141152   }
1015   if (sh2->sr & S)
1153   if (m_sh2_state->sr & S)
10161154   {
1017      Res0 = sh2->macl + Res0;
1018      if (sh2->macl > Res0)
1155      Res0 = m_sh2_state->macl + Res0;
1156      if (m_sh2_state->macl > Res0)
10191157         Res2++;
1020      Res2 += (sh2->mach & 0x0000ffff);
1158      Res2 += (m_sh2_state->mach & 0x0000ffff);
10211159      if (((INT32) Res2 < 0) && (Res2 < 0xffff8000))
10221160      {
10231161         Res2 = 0x00008000;
r29565r29566
10281166         Res2 = 0x00007fff;
10291167         Res0 = 0xffffffff;
10301168      }
1031      sh2->mach = Res2;
1032      sh2->macl = Res0;
1169      m_sh2_state->mach = Res2;
1170      m_sh2_state->macl = Res0;
10331171   }
10341172   else
10351173   {
1036      Res0 = sh2->macl + Res0;
1037      if (sh2->macl > Res0)
1174      Res0 = m_sh2_state->macl + Res0;
1175      if (m_sh2_state->macl > Res0)
10381176         Res2++;
1039      Res2 += sh2->mach;
1040      sh2->mach = Res2;
1041      sh2->macl = Res0;
1177      Res2 += m_sh2_state->mach;
1178      m_sh2_state->mach = Res2;
1179      m_sh2_state->macl = Res0;
10421180   }
1043   sh2->icount -= 2;
1181   m_sh2_state->icount -= 2;
10441182}
10451183
10461184/*  MAC.W   @Rm+,@Rn+ */
1047INLINE void MAC_W(sh2_state *sh2, UINT32 m, UINT32 n)
1185void sh2_device::MAC_W(UINT32 m, UINT32 n)
10481186{
10491187   INT32 tempm, tempn, dest, src, ans;
10501188   UINT32 templ;
10511189
1052   tempn = (INT32) RW( sh2, sh2->r[n] );
1053   sh2->r[n] += 2;
1054   tempm = (INT32) RW( sh2, sh2->r[m] );
1055   sh2->r[m] += 2;
1056   templ = sh2->macl;
1190   tempn = (INT32) RW( m_sh2_state->r[n] );
1191   m_sh2_state->r[n] += 2;
1192   tempm = (INT32) RW( m_sh2_state->r[m] );
1193   m_sh2_state->r[m] += 2;
1194   templ = m_sh2_state->macl;
10571195   tempm = ((INT32) (short) tempn * (INT32) (short) tempm);
1058   if ((INT32) sh2->macl >= 0)
1196   if ((INT32) m_sh2_state->macl >= 0)
10591197      dest = 0;
10601198   else
10611199      dest = 1;
r29565r29566
10701208      tempn = 0xffffffff;
10711209   }
10721210   src += dest;
1073   sh2->macl += tempm;
1074   if ((INT32) sh2->macl >= 0)
1211   m_sh2_state->macl += tempm;
1212   if ((INT32) m_sh2_state->macl >= 0)
10751213      ans = 0;
10761214   else
10771215      ans = 1;
10781216   ans += dest;
1079   if (sh2->sr & S)
1217   if (m_sh2_state->sr & S)
10801218   {
10811219      if (ans == 1)
10821220         {
10831221            if (src == 0)
1084               sh2->macl = 0x7fffffff;
1222               m_sh2_state->macl = 0x7fffffff;
10851223            if (src == 2)
1086               sh2->macl = 0x80000000;
1224               m_sh2_state->macl = 0x80000000;
10871225         }
10881226   }
10891227   else
10901228   {
1091      sh2->mach += tempn;
1092      if (templ > sh2->macl)
1093         sh2->mach += 1;
1229      m_sh2_state->mach += tempn;
1230      if (templ > m_sh2_state->macl)
1231         m_sh2_state->mach += 1;
10941232   }
1095   sh2->icount -= 2;
1233   m_sh2_state->icount -= 2;
10961234}
10971235
10981236/*  MOV     Rm,Rn */
1099INLINE void MOV(sh2_state *sh2, UINT32 m, UINT32 n)
1237void sh2_device::MOV(UINT32 m, UINT32 n)
11001238{
1101   sh2->r[n] = sh2->r[m];
1239   m_sh2_state->r[n] = m_sh2_state->r[m];
11021240}
11031241
11041242/*  MOV.B   Rm,@Rn */
1105INLINE void MOVBS(sh2_state *sh2, UINT32 m, UINT32 n)
1243void sh2_device::MOVBS(UINT32 m, UINT32 n)
11061244{
1107   sh2->ea = sh2->r[n];
1108   WB( sh2, sh2->ea, sh2->r[m] & 0x000000ff);
1245   m_sh2_state->ea = m_sh2_state->r[n];
1246   WB( m_sh2_state->ea, m_sh2_state->r[m] & 0x000000ff);
11091247}
11101248
11111249/*  MOV.W   Rm,@Rn */
1112INLINE void MOVWS(sh2_state *sh2, UINT32 m, UINT32 n)
1250void sh2_device::MOVWS(UINT32 m, UINT32 n)
11131251{
1114   sh2->ea = sh2->r[n];
1115   WW( sh2, sh2->ea, sh2->r[m] & 0x0000ffff);
1252   m_sh2_state->ea = m_sh2_state->r[n];
1253   WW( m_sh2_state->ea, m_sh2_state->r[m] & 0x0000ffff);
11161254}
11171255
11181256/*  MOV.L   Rm,@Rn */
1119INLINE void MOVLS(sh2_state *sh2, UINT32 m, UINT32 n)
1257void sh2_device::MOVLS(UINT32 m, UINT32 n)
11201258{
1121   sh2->ea = sh2->r[n];
1122   WL( sh2, sh2->ea, sh2->r[m] );
1259   m_sh2_state->ea = m_sh2_state->r[n];
1260   WL( m_sh2_state->ea, m_sh2_state->r[m] );
11231261}
11241262
11251263/*  MOV.B   @Rm,Rn */
1126INLINE void MOVBL(sh2_state *sh2, UINT32 m, UINT32 n)
1264void sh2_device::MOVBL(UINT32 m, UINT32 n)
11271265{
1128   sh2->ea = sh2->r[m];
1129   sh2->r[n] = (UINT32)(INT32)(INT16)(INT8) RB( sh2, sh2->ea );
1266   m_sh2_state->ea = m_sh2_state->r[m];
1267   m_sh2_state->r[n] = (UINT32)(INT32)(INT16)(INT8) RB( m_sh2_state->ea );
11301268}
11311269
11321270/*  MOV.W   @Rm,Rn */
1133INLINE void MOVWL(sh2_state *sh2, UINT32 m, UINT32 n)
1271void sh2_device::MOVWL(UINT32 m, UINT32 n)
11341272{
1135   sh2->ea = sh2->r[m];
1136   sh2->r[n] = (UINT32)(INT32)(INT16) RW( sh2, sh2->ea );
1273   m_sh2_state->ea = m_sh2_state->r[m];
1274   m_sh2_state->r[n] = (UINT32)(INT32)(INT16) RW( m_sh2_state->ea );
11371275}
11381276
11391277/*  MOV.L   @Rm,Rn */
1140INLINE void MOVLL(sh2_state *sh2, UINT32 m, UINT32 n)
1278void sh2_device::MOVLL(UINT32 m, UINT32 n)
11411279{
1142   sh2->ea = sh2->r[m];
1143   sh2->r[n] = RL( sh2, sh2->ea );
1280   m_sh2_state->ea = m_sh2_state->r[m];
1281   m_sh2_state->r[n] = RL( m_sh2_state->ea );
11441282}
11451283
11461284/*  MOV.B   Rm,@-Rn */
1147INLINE void MOVBM(sh2_state *sh2, UINT32 m, UINT32 n)
1285void sh2_device::MOVBM(UINT32 m, UINT32 n)
11481286{
1149   /* SMG : bug fix, was reading sh2->r[n] */
1150   UINT32 data = sh2->r[m] & 0x000000ff;
1287   /* SMG : bug fix, was reading m_sh2_state->r[n] */
1288   UINT32 data = m_sh2_state->r[m] & 0x000000ff;
11511289
1152   sh2->r[n] -= 1;
1153   WB( sh2, sh2->r[n], data );
1290   m_sh2_state->r[n] -= 1;
1291   WB( m_sh2_state->r[n], data );
11541292}
11551293
11561294/*  MOV.W   Rm,@-Rn */
1157INLINE void MOVWM(sh2_state *sh2, UINT32 m, UINT32 n)
1295void sh2_device::MOVWM(UINT32 m, UINT32 n)
11581296{
1159   UINT32 data = sh2->r[m] & 0x0000ffff;
1297   UINT32 data = m_sh2_state->r[m] & 0x0000ffff;
11601298
1161   sh2->r[n] -= 2;
1162   WW( sh2, sh2->r[n], data );
1299   m_sh2_state->r[n] -= 2;
1300   WW( m_sh2_state->r[n], data );
11631301}
11641302
11651303/*  MOV.L   Rm,@-Rn */
1166INLINE void MOVLM(sh2_state *sh2, UINT32 m, UINT32 n)
1304void sh2_device::MOVLM(UINT32 m, UINT32 n)
11671305{
1168   UINT32 data = sh2->r[m];
1306   UINT32 data = m_sh2_state->r[m];
11691307
1170   sh2->r[n] -= 4;
1171   WL( sh2, sh2->r[n], data );
1308   m_sh2_state->r[n] -= 4;
1309   WL( m_sh2_state->r[n], data );
11721310}
11731311
11741312/*  MOV.B   @Rm+,Rn */
1175INLINE void MOVBP(sh2_state *sh2, UINT32 m, UINT32 n)
1313void sh2_device::MOVBP(UINT32 m, UINT32 n)
11761314{
1177   sh2->r[n] = (UINT32)(INT32)(INT16)(INT8) RB( sh2, sh2->r[m] );
1315   m_sh2_state->r[n] = (UINT32)(INT32)(INT16)(INT8) RB( m_sh2_state->r[m] );
11781316   if (n != m)
1179      sh2->r[m] += 1;
1317      m_sh2_state->r[m] += 1;
11801318}
11811319
11821320/*  MOV.W   @Rm+,Rn */
1183INLINE void MOVWP(sh2_state *sh2, UINT32 m, UINT32 n)
1321void sh2_device::MOVWP(UINT32 m, UINT32 n)
11841322{
1185   sh2->r[n] = (UINT32)(INT32)(INT16) RW( sh2, sh2->r[m] );
1323   m_sh2_state->r[n] = (UINT32)(INT32)(INT16) RW( m_sh2_state->r[m] );
11861324   if (n != m)
1187      sh2->r[m] += 2;
1325      m_sh2_state->r[m] += 2;
11881326}
11891327
11901328/*  MOV.L   @Rm+,Rn */
1191INLINE void MOVLP(sh2_state *sh2, UINT32 m, UINT32 n)
1329void sh2_device::MOVLP(UINT32 m, UINT32 n)
11921330{
1193   sh2->r[n] = RL( sh2, sh2->r[m] );
1331   m_sh2_state->r[n] = RL( m_sh2_state->r[m] );
11941332   if (n != m)
1195      sh2->r[m] += 4;
1333      m_sh2_state->r[m] += 4;
11961334}
11971335
11981336/*  MOV.B   Rm,@(R0,Rn) */
1199INLINE void MOVBS0(sh2_state *sh2, UINT32 m, UINT32 n)
1337void sh2_device::MOVBS0(UINT32 m, UINT32 n)
12001338{
1201   sh2->ea = sh2->r[n] + sh2->r[0];
1202   WB( sh2, sh2->ea, sh2->r[m] & 0x000000ff );
1339   m_sh2_state->ea = m_sh2_state->r[n] + m_sh2_state->r[0];
1340   WB( m_sh2_state->ea, m_sh2_state->r[m] & 0x000000ff );
12031341}
12041342
12051343/*  MOV.W   Rm,@(R0,Rn) */
1206INLINE void MOVWS0(sh2_state *sh2, UINT32 m, UINT32 n)
1344void sh2_device::MOVWS0(UINT32 m, UINT32 n)
12071345{
1208   sh2->ea = sh2->r[n] + sh2->r[0];
1209   WW( sh2, sh2->ea, sh2->r[m] & 0x0000ffff );
1346   m_sh2_state->ea = m_sh2_state->r[n] + m_sh2_state->r[0];
1347   WW( m_sh2_state->ea, m_sh2_state->r[m] & 0x0000ffff );
12101348}
12111349
12121350/*  MOV.L   Rm,@(R0,Rn) */
1213INLINE void MOVLS0(sh2_state *sh2, UINT32 m, UINT32 n)
1351void sh2_device::MOVLS0(UINT32 m, UINT32 n)
12141352{
1215   sh2->ea = sh2->r[n] + sh2->r[0];
1216   WL( sh2, sh2->ea, sh2->r[m] );
1353   m_sh2_state->ea = m_sh2_state->r[n] + m_sh2_state->r[0];
1354   WL( m_sh2_state->ea, m_sh2_state->r[m] );
12171355}
12181356
12191357/*  MOV.B   @(R0,Rm),Rn */
1220INLINE void MOVBL0(sh2_state *sh2, UINT32 m, UINT32 n)
1358void sh2_device::MOVBL0(UINT32 m, UINT32 n)
12211359{
1222   sh2->ea = sh2->r[m] + sh2->r[0];
1223   sh2->r[n] = (UINT32)(INT32)(INT16)(INT8) RB( sh2, sh2->ea );
1360   m_sh2_state->ea = m_sh2_state->r[m] + m_sh2_state->r[0];
1361   m_sh2_state->r[n] = (UINT32)(INT32)(INT16)(INT8) RB( m_sh2_state->ea );
12241362}
12251363
12261364/*  MOV.W   @(R0,Rm),Rn */
1227INLINE void MOVWL0(sh2_state *sh2, UINT32 m, UINT32 n)
1365void sh2_device::MOVWL0(UINT32 m, UINT32 n)
12281366{
1229   sh2->ea = sh2->r[m] + sh2->r[0];
1230   sh2->r[n] = (UINT32)(INT32)(INT16) RW( sh2, sh2->ea );
1367   m_sh2_state->ea = m_sh2_state->r[m] + m_sh2_state->r[0];
1368   m_sh2_state->r[n] = (UINT32)(INT32)(INT16) RW( m_sh2_state->ea );
12311369}
12321370
12331371/*  MOV.L   @(R0,Rm),Rn */
1234INLINE void MOVLL0(sh2_state *sh2, UINT32 m, UINT32 n)
1372void sh2_device::MOVLL0(UINT32 m, UINT32 n)
12351373{
1236   sh2->ea = sh2->r[m] + sh2->r[0];
1237   sh2->r[n] = RL( sh2, sh2->ea );
1374   m_sh2_state->ea = m_sh2_state->r[m] + m_sh2_state->r[0];
1375   m_sh2_state->r[n] = RL( m_sh2_state->ea );
12381376}
12391377
12401378/*  MOV     #imm,Rn */
1241INLINE void MOVI(sh2_state *sh2, UINT32 i, UINT32 n)
1379void sh2_device::MOVI(UINT32 i, UINT32 n)
12421380{
1243   sh2->r[n] = (UINT32)(INT32)(INT16)(INT8) i;
1381   m_sh2_state->r[n] = (UINT32)(INT32)(INT16)(INT8) i;
12441382}
12451383
12461384/*  MOV.W   @(disp8,PC),Rn */
1247INLINE void MOVWI(sh2_state *sh2, UINT32 d, UINT32 n)
1385void sh2_device::MOVWI(UINT32 d, UINT32 n)
12481386{
12491387   UINT32 disp = d & 0xff;
1250   sh2->ea = sh2->pc + disp * 2 + 2;
1251   sh2->r[n] = (UINT32)(INT32)(INT16) RW( sh2, sh2->ea );
1388   m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
1389   m_sh2_state->r[n] = (UINT32)(INT32)(INT16) RW( m_sh2_state->ea );
12521390}
12531391
12541392/*  MOV.L   @(disp8,PC),Rn */
1255INLINE void MOVLI(sh2_state *sh2, UINT32 d, UINT32 n)
1393void sh2_device::MOVLI(UINT32 d, UINT32 n)
12561394{
12571395   UINT32 disp = d & 0xff;
1258   sh2->ea = ((sh2->pc + 2) & ~3) + disp * 4;
1259   sh2->r[n] = RL( sh2, sh2->ea );
1396   m_sh2_state->ea = ((m_sh2_state->pc + 2) & ~3) + disp * 4;
1397   m_sh2_state->r[n] = RL( m_sh2_state->ea );
12601398}
12611399
12621400/*  MOV.B   @(disp8,GBR),R0 */
1263INLINE void MOVBLG(sh2_state *sh2, UINT32 d)
1401void sh2_device::MOVBLG(UINT32 d)
12641402{
12651403   UINT32 disp = d & 0xff;
1266   sh2->ea = sh2->gbr + disp;
1267   sh2->r[0] = (UINT32)(INT32)(INT16)(INT8) RB( sh2, sh2->ea );
1404   m_sh2_state->ea = m_sh2_state->gbr + disp;
1405   m_sh2_state->r[0] = (UINT32)(INT32)(INT16)(INT8) RB( m_sh2_state->ea );
12681406}
12691407
12701408/*  MOV.W   @(disp8,GBR),R0 */
1271INLINE void MOVWLG(sh2_state *sh2, UINT32 d)
1409void sh2_device::MOVWLG(UINT32 d)
12721410{
12731411   UINT32 disp = d & 0xff;
1274   sh2->ea = sh2->gbr + disp * 2;
1275   sh2->r[0] = (INT32)(INT16) RW( sh2, sh2->ea );
1412   m_sh2_state->ea = m_sh2_state->gbr + disp * 2;
1413   m_sh2_state->r[0] = (INT32)(INT16) RW( m_sh2_state->ea );
12761414}
12771415
12781416/*  MOV.L   @(disp8,GBR),R0 */
1279INLINE void MOVLLG(sh2_state *sh2, UINT32 d)
1417void sh2_device::MOVLLG(UINT32 d)
12801418{
12811419   UINT32 disp = d & 0xff;
1282   sh2->ea = sh2->gbr + disp * 4;
1283   sh2->r[0] = RL( sh2, sh2->ea );
1420   m_sh2_state->ea = m_sh2_state->gbr + disp * 4;
1421   m_sh2_state->r[0] = RL( m_sh2_state->ea );
12841422}
12851423
12861424/*  MOV.B   R0,@(disp8,GBR) */
1287INLINE void MOVBSG(sh2_state *sh2, UINT32 d)
1425void sh2_device::MOVBSG(UINT32 d)
12881426{
12891427   UINT32 disp = d & 0xff;
1290   sh2->ea = sh2->gbr + disp;
1291   WB( sh2, sh2->ea, sh2->r[0] & 0x000000ff );
1428   m_sh2_state->ea = m_sh2_state->gbr + disp;
1429   WB( m_sh2_state->ea, m_sh2_state->r[0] & 0x000000ff );
12921430}
12931431
12941432/*  MOV.W   R0,@(disp8,GBR) */
1295INLINE void MOVWSG(sh2_state *sh2, UINT32 d)
1433void sh2_device::MOVWSG(UINT32 d)
12961434{
12971435   UINT32 disp = d & 0xff;
1298   sh2->ea = sh2->gbr + disp * 2;
1299   WW( sh2, sh2->ea, sh2->r[0] & 0x0000ffff );
1436   m_sh2_state->ea = m_sh2_state->gbr + disp * 2;
1437   WW( m_sh2_state->ea, m_sh2_state->r[0] & 0x0000ffff );
13001438}
13011439
13021440/*  MOV.L   R0,@(disp8,GBR) */
1303INLINE void MOVLSG(sh2_state *sh2, UINT32 d)
1441void sh2_device::MOVLSG(UINT32 d)
13041442{
13051443   UINT32 disp = d & 0xff;
1306   sh2->ea = sh2->gbr + disp * 4;
1307   WL( sh2, sh2->ea, sh2->r[0] );
1444   m_sh2_state->ea = m_sh2_state->gbr + disp * 4;
1445   WL( m_sh2_state->ea, m_sh2_state->r[0] );
13081446}
13091447
13101448/*  MOV.B   R0,@(disp4,Rn) */
1311INLINE void MOVBS4(sh2_state *sh2, UINT32 d, UINT32 n)
1449void sh2_device::MOVBS4(UINT32 d, UINT32 n)
13121450{
13131451   UINT32 disp = d & 0x0f;
1314   sh2->ea = sh2->r[n] + disp;
1315   WB( sh2, sh2->ea, sh2->r[0] & 0x000000ff );
1452   m_sh2_state->ea = m_sh2_state->r[n] + disp;
1453   WB( m_sh2_state->ea, m_sh2_state->r[0] & 0x000000ff );
13161454}
13171455
13181456/*  MOV.W   R0,@(disp4,Rn) */
1319INLINE void MOVWS4(sh2_state *sh2, UINT32 d, UINT32 n)
1457void sh2_device::MOVWS4(UINT32 d, UINT32 n)
13201458{
13211459   UINT32 disp = d & 0x0f;
1322   sh2->ea = sh2->r[n] + disp * 2;
1323   WW( sh2, sh2->ea, sh2->r[0] & 0x0000ffff );
1460   m_sh2_state->ea = m_sh2_state->r[n] + disp * 2;
1461   WW( m_sh2_state->ea, m_sh2_state->r[0] & 0x0000ffff );
13241462}
13251463
13261464/* MOV.L Rm,@(disp4,Rn) */
1327INLINE void MOVLS4(sh2_state *sh2, UINT32 m, UINT32 d, UINT32 n)
1465void sh2_device::MOVLS4(UINT32 m, UINT32 d, UINT32 n)
13281466{
13291467   UINT32 disp = d & 0x0f;
1330   sh2->ea = sh2->r[n] + disp * 4;
1331   WL( sh2, sh2->ea, sh2->r[m] );
1468   m_sh2_state->ea = m_sh2_state->r[n] + disp * 4;
1469   WL( m_sh2_state->ea, m_sh2_state->r[m] );
13321470}
13331471
13341472/*  MOV.B   @(disp4,Rm),R0 */
1335INLINE void MOVBL4(sh2_state *sh2, UINT32 m, UINT32 d)
1473void sh2_device::MOVBL4(UINT32 m, UINT32 d)
13361474{
13371475   UINT32 disp = d & 0x0f;
1338   sh2->ea = sh2->r[m] + disp;
1339   sh2->r[0] = (UINT32)(INT32)(INT16)(INT8) RB( sh2, sh2->ea );
1476   m_sh2_state->ea = m_sh2_state->r[m] + disp;
1477   m_sh2_state->r[0] = (UINT32)(INT32)(INT16)(INT8) RB( m_sh2_state->ea );
13401478}
13411479
13421480/*  MOV.W   @(disp4,Rm),R0 */
1343INLINE void MOVWL4(sh2_state *sh2, UINT32 m, UINT32 d)
1481void sh2_device::MOVWL4(UINT32 m, UINT32 d)
13441482{
13451483   UINT32 disp = d & 0x0f;
1346   sh2->ea = sh2->r[m] + disp * 2;
1347   sh2->r[0] = (UINT32)(INT32)(INT16) RW( sh2, sh2->ea );
1484   m_sh2_state->ea = m_sh2_state->r[m] + disp * 2;
1485   m_sh2_state->r[0] = (UINT32)(INT32)(INT16) RW( m_sh2_state->ea );
13481486}
13491487
13501488/*  MOV.L   @(disp4,Rm),Rn */
1351INLINE void MOVLL4(sh2_state *sh2, UINT32 m, UINT32 d, UINT32 n)
1489void sh2_device::MOVLL4(UINT32 m, UINT32 d, UINT32 n)
13521490{
13531491   UINT32 disp = d & 0x0f;
1354   sh2->ea = sh2->r[m] + disp * 4;
1355   sh2->r[n] = RL( sh2, sh2->ea );
1492   m_sh2_state->ea = m_sh2_state->r[m] + disp * 4;
1493   m_sh2_state->r[n] = RL( m_sh2_state->ea );
13561494}
13571495
13581496/*  MOVA    @(disp8,PC),R0 */
1359INLINE void MOVA(sh2_state *sh2, UINT32 d)
1497void sh2_device::MOVA(UINT32 d)
13601498{
13611499   UINT32 disp = d & 0xff;
1362   sh2->ea = ((sh2->pc + 2) & ~3) + disp * 4;
1363   sh2->r[0] = sh2->ea;
1500   m_sh2_state->ea = ((m_sh2_state->pc + 2) & ~3) + disp * 4;
1501   m_sh2_state->r[0] = m_sh2_state->ea;
13641502}
13651503
13661504/*  MOVT    Rn */
1367INLINE void MOVT(sh2_state *sh2, UINT32 n)
1505void sh2_device::MOVT(UINT32 n)
13681506{
1369   sh2->r[n] = sh2->sr & T;
1507   m_sh2_state->r[n] = m_sh2_state->sr & T;
13701508}
13711509
13721510/*  MUL.L   Rm,Rn */
1373INLINE void MULL(sh2_state *sh2, UINT32 m, UINT32 n)
1511void sh2_device::MULL(UINT32 m, UINT32 n)
13741512{
1375   sh2->macl = sh2->r[n] * sh2->r[m];
1376   sh2->icount--;
1513   m_sh2_state->macl = m_sh2_state->r[n] * m_sh2_state->r[m];
1514   m_sh2_state->icount--;
13771515}
13781516
13791517/*  MULS    Rm,Rn */
1380INLINE void MULS(sh2_state *sh2, UINT32 m, UINT32 n)
1518void sh2_device::MULS(UINT32 m, UINT32 n)
13811519{
1382   sh2->macl = (INT16) sh2->r[n] * (INT16) sh2->r[m];
1520   m_sh2_state->macl = (INT16) m_sh2_state->r[n] * (INT16) m_sh2_state->r[m];
13831521}
13841522
13851523/*  MULU    Rm,Rn */
1386INLINE void MULU(sh2_state *sh2, UINT32 m, UINT32 n)
1524void sh2_device::MULU(UINT32 m, UINT32 n)
13871525{
1388   sh2->macl = (UINT16) sh2->r[n] * (UINT16) sh2->r[m];
1526   m_sh2_state->macl = (UINT16) m_sh2_state->r[n] * (UINT16) m_sh2_state->r[m];
13891527}
13901528
13911529/*  NEG     Rm,Rn */
1392INLINE void NEG(sh2_state *sh2, UINT32 m, UINT32 n)
1530void sh2_device::NEG(UINT32 m, UINT32 n)
13931531{
1394   sh2->r[n] = 0 - sh2->r[m];
1532   m_sh2_state->r[n] = 0 - m_sh2_state->r[m];
13951533}
13961534
13971535/*  NEGC    Rm,Rn */
1398INLINE void NEGC(sh2_state *sh2, UINT32 m, UINT32 n)
1536void sh2_device::NEGC(UINT32 m, UINT32 n)
13991537{
14001538   UINT32 temp;
14011539
1402   temp = sh2->r[m];
1403   sh2->r[n] = -temp - (sh2->sr & T);
1404   if (temp || (sh2->sr & T))
1405      sh2->sr |= T;
1540   temp = m_sh2_state->r[m];
1541   m_sh2_state->r[n] = -temp - (m_sh2_state->sr & T);
1542   if (temp || (m_sh2_state->sr & T))
1543      m_sh2_state->sr |= T;
14061544   else
1407      sh2->sr &= ~T;
1545      m_sh2_state->sr &= ~T;
14081546}
14091547
14101548/*  NOP */
1411INLINE void NOP(void)
1549void sh2_device::NOP(void)
14121550{
14131551}
14141552
14151553/*  NOT     Rm,Rn */
1416INLINE void NOT(sh2_state *sh2, UINT32 m, UINT32 n)
1554void sh2_device::NOT(UINT32 m, UINT32 n)
14171555{
1418   sh2->r[n] = ~sh2->r[m];
1556   m_sh2_state->r[n] = ~m_sh2_state->r[m];
14191557}
14201558
14211559/*  OR      Rm,Rn */
1422INLINE void OR(sh2_state *sh2, UINT32 m, UINT32 n)
1560void sh2_device::OR(UINT32 m, UINT32 n)
14231561{
1424   sh2->r[n] |= sh2->r[m];
1562   m_sh2_state->r[n] |= m_sh2_state->r[m];
14251563}
14261564
14271565/*  OR      #imm,R0 */
1428INLINE void ORI(sh2_state *sh2, UINT32 i)
1566void sh2_device::ORI(UINT32 i)
14291567{
1430   sh2->r[0] |= i;
1568   m_sh2_state->r[0] |= i;
14311569}
14321570
14331571/*  OR.B    #imm,@(R0,GBR) */
1434INLINE void ORM(sh2_state *sh2, UINT32 i)
1572void sh2_device::ORM(UINT32 i)
14351573{
14361574   UINT32 temp;
14371575
1438   sh2->ea = sh2->gbr + sh2->r[0];
1439   temp = RB( sh2, sh2->ea );
1576   m_sh2_state->ea = m_sh2_state->gbr + m_sh2_state->r[0];
1577   temp = RB( m_sh2_state->ea );
14401578   temp |= i;
1441   WB( sh2, sh2->ea, temp );
1442   sh2->icount -= 2;
1579   WB( m_sh2_state->ea, temp );
1580   m_sh2_state->icount -= 2;
14431581}
14441582
14451583/*  ROTCL   Rn */
1446INLINE void ROTCL(sh2_state *sh2, UINT32 n)
1584void sh2_device::ROTCL(UINT32 n)
14471585{
14481586   UINT32 temp;
14491587
1450   temp = (sh2->r[n] >> 31) & T;
1451   sh2->r[n] = (sh2->r[n] << 1) | (sh2->sr & T);
1452   sh2->sr = (sh2->sr & ~T) | temp;
1588   temp = (m_sh2_state->r[n] >> 31) & T;
1589   m_sh2_state->r[n] = (m_sh2_state->r[n] << 1) | (m_sh2_state->sr & T);
1590   m_sh2_state->sr = (m_sh2_state->sr & ~T) | temp;
14531591}
14541592
14551593/*  ROTCR   Rn */
1456INLINE void ROTCR(sh2_state *sh2, UINT32 n)
1594void sh2_device::ROTCR(UINT32 n)
14571595{
14581596   UINT32 temp;
1459   temp = (sh2->sr & T) << 31;
1460   if (sh2->r[n] & T)
1461      sh2->sr |= T;
1597   temp = (m_sh2_state->sr & T) << 31;
1598   if (m_sh2_state->r[n] & T)
1599      m_sh2_state->sr |= T;
14621600   else
1463      sh2->sr &= ~T;
1464   sh2->r[n] = (sh2->r[n] >> 1) | temp;
1601      m_sh2_state->sr &= ~T;
1602   m_sh2_state->r[n] = (m_sh2_state->r[n] >> 1) | temp;
14651603}
14661604
14671605/*  ROTL    Rn */
1468INLINE void ROTL(sh2_state *sh2, UINT32 n)
1606void sh2_device::ROTL(UINT32 n)
14691607{
1470   sh2->sr = (sh2->sr & ~T) | ((sh2->r[n] >> 31) & T);
1471   sh2->r[n] = (sh2->r[n] << 1) | (sh2->r[n] >> 31);
1608   m_sh2_state->sr = (m_sh2_state->sr & ~T) | ((m_sh2_state->r[n] >> 31) & T);
1609   m_sh2_state->r[n] = (m_sh2_state->r[n] << 1) | (m_sh2_state->r[n] >> 31);
14721610}
14731611
14741612/*  ROTR    Rn */
1475INLINE void ROTR(sh2_state *sh2, UINT32 n)
1613void sh2_device::ROTR(UINT32 n)
14761614{
1477   sh2->sr = (sh2->sr & ~T) | (sh2->r[n] & T);
1478   sh2->r[n] = (sh2->r[n] >> 1) | (sh2->r[n] << 31);
1615   m_sh2_state->sr = (m_sh2_state->sr & ~T) | (m_sh2_state->r[n] & T);
1616   m_sh2_state->r[n] = (m_sh2_state->r[n] >> 1) | (m_sh2_state->r[n] << 31);
14791617}
14801618
14811619/*  RTE */
1482INLINE void RTE(sh2_state *sh2)
1620void sh2_device::RTE()
14831621{
1484   sh2->ea = sh2->r[15];
1485   sh2->delay = sh2->pc;
1486   sh2->pc = RL( sh2, sh2->ea );
1487   sh2->r[15] += 4;
1488   sh2->ea = sh2->r[15];
1489   sh2->sr = RL( sh2, sh2->ea ) & FLAGS;
1490   sh2->r[15] += 4;
1491   sh2->icount -= 3;
1492   sh2->test_irq = 1;
1622   m_sh2_state->ea = m_sh2_state->r[15];
1623   m_delay = m_sh2_state->pc;
1624   m_sh2_state->pc = RL( m_sh2_state->ea );
1625   m_sh2_state->r[15] += 4;
1626   m_sh2_state->ea = m_sh2_state->r[15];
1627   m_sh2_state->sr = RL( m_sh2_state->ea ) & FLAGS;
1628   m_sh2_state->r[15] += 4;
1629   m_sh2_state->icount -= 3;
1630   m_test_irq = 1;
14931631}
14941632
14951633/*  RTS */
1496INLINE void RTS(sh2_state *sh2)
1634void sh2_device::RTS()
14971635{
1498   sh2->delay = sh2->pc;
1499   sh2->pc = sh2->ea = sh2->pr;
1500   sh2->icount--;
1636   m_delay = m_sh2_state->pc;
1637   m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pr;
1638   m_sh2_state->icount--;
15011639}
15021640
15031641/*  SETT */
1504INLINE void SETT(sh2_state *sh2)
1642void sh2_device::SETT()
15051643{
1506   sh2->sr |= T;
1644   m_sh2_state->sr |= T;
15071645}
15081646
15091647/*  SHAL    Rn      (same as SHLL) */
1510INLINE void SHAL(sh2_state *sh2, UINT32 n)
1648void sh2_device::SHAL(UINT32 n)
15111649{
1512   sh2->sr = (sh2->sr & ~T) | ((sh2->r[n] >> 31) & T);
1513   sh2->r[n] <<= 1;
1650   m_sh2_state->sr = (m_sh2_state->sr & ~T) | ((m_sh2_state->r[n] >> 31) & T);
1651   m_sh2_state->r[n] <<= 1;
15141652}
15151653
15161654/*  SHAR    Rn */
1517INLINE void SHAR(sh2_state *sh2, UINT32 n)
1655void sh2_device::SHAR(UINT32 n)
15181656{
1519   sh2->sr = (sh2->sr & ~T) | (sh2->r[n] & T);
1520   sh2->r[n] = (UINT32)((INT32)sh2->r[n] >> 1);
1657   m_sh2_state->sr = (m_sh2_state->sr & ~T) | (m_sh2_state->r[n] & T);
1658   m_sh2_state->r[n] = (UINT32)((INT32)m_sh2_state->r[n] >> 1);
15211659}
15221660
15231661/*  SHLL    Rn      (same as SHAL) */
1524INLINE void SHLL(sh2_state *sh2, UINT32 n)
1662void sh2_device::SHLL(UINT32 n)
15251663{
1526   sh2->sr = (sh2->sr & ~T) | ((sh2->r[n] >> 31) & T);
1527   sh2->r[n] <<= 1;
1664   m_sh2_state->sr = (m_sh2_state->sr & ~T) | ((m_sh2_state->r[n] >> 31) & T);
1665   m_sh2_state->r[n] <<= 1;
15281666}
15291667
15301668/*  SHLL2   Rn */
1531INLINE void SHLL2(sh2_state *sh2, UINT32 n)
1669void sh2_device::SHLL2(UINT32 n)
15321670{
1533   sh2->r[n] <<= 2;
1671   m_sh2_state->r[n] <<= 2;
15341672}
15351673
15361674/*  SHLL8   Rn */
1537INLINE void SHLL8(sh2_state *sh2, UINT32 n)
1675void sh2_device::SHLL8(UINT32 n)
15381676{
1539   sh2->r[n] <<= 8;
1677   m_sh2_state->r[n] <<= 8;
15401678}
15411679
15421680/*  SHLL16  Rn */
1543INLINE void SHLL16(sh2_state *sh2, UINT32 n)
1681void sh2_device::SHLL16(UINT32 n)
15441682{
1545   sh2->r[n] <<= 16;
1683   m_sh2_state->r[n] <<= 16;
15461684}
15471685
15481686/*  SHLR    Rn */
1549INLINE void SHLR(sh2_state *sh2, UINT32 n)
1687void sh2_device::SHLR(UINT32 n)
15501688{
1551   sh2->sr = (sh2->sr & ~T) | (sh2->r[n] & T);
1552   sh2->r[n] >>= 1;
1689   m_sh2_state->sr = (m_sh2_state->sr & ~T) | (m_sh2_state->r[n] & T);
1690   m_sh2_state->r[n] >>= 1;
15531691}
15541692
15551693/*  SHLR2   Rn */
1556INLINE void SHLR2(sh2_state *sh2, UINT32 n)
1694void sh2_device::SHLR2(UINT32 n)
15571695{
1558   sh2->r[n] >>= 2;
1696   m_sh2_state->r[n] >>= 2;
15591697}
15601698
15611699/*  SHLR8   Rn */
1562INLINE void SHLR8(sh2_state *sh2, UINT32 n)
1700void sh2_device::SHLR8(UINT32 n)
15631701{
1564   sh2->r[n] >>= 8;
1702   m_sh2_state->r[n] >>= 8;
15651703}
15661704
15671705/*  SHLR16  Rn */
1568INLINE void SHLR16(sh2_state *sh2, UINT32 n)
1706void sh2_device::SHLR16(UINT32 n)
15691707{
1570   sh2->r[n] >>= 16;
1708   m_sh2_state->r[n] >>= 16;
15711709}
15721710
15731711/*  SLEEP */
1574INLINE void SLEEP(sh2_state *sh2)
1712void sh2_device::SLEEP()
15751713{
1576   if(sh2->sleep_mode != 2)
1577      sh2->pc -= 2;
1578   sh2->icount -= 2;
1714   if(m_sh2_state->sleep_mode != 2)
1715      m_sh2_state->pc -= 2;
1716   m_sh2_state->icount -= 2;
15791717   /* Wait_for_exception; */
1580   if(sh2->sleep_mode == 0)
1581      sh2->sleep_mode = 1;
1582   else if(sh2->sleep_mode == 2)
1583      sh2->sleep_mode = 0;
1718   if(m_sh2_state->sleep_mode == 0)
1719      m_sh2_state->sleep_mode = 1;
1720   else if(m_sh2_state->sleep_mode == 2)
1721      m_sh2_state->sleep_mode = 0;
15841722}
15851723
15861724/*  STC     SR,Rn */
1587INLINE void STCSR(sh2_state *sh2, UINT32 n)
1725void sh2_device::STCSR(UINT32 n)
15881726{
1589   sh2->r[n] = sh2->sr;
1727   m_sh2_state->r[n] = m_sh2_state->sr;
15901728}
15911729
15921730/*  STC     GBR,Rn */
1593INLINE void STCGBR(sh2_state *sh2, UINT32 n)
1731void sh2_device::STCGBR(UINT32 n)
15941732{
1595   sh2->r[n] = sh2->gbr;
1733   m_sh2_state->r[n] = m_sh2_state->gbr;
15961734}
15971735
15981736/*  STC     VBR,Rn */
1599INLINE void STCVBR(sh2_state *sh2, UINT32 n)
1737void sh2_device::STCVBR(UINT32 n)
16001738{
1601   sh2->r[n] = sh2->vbr;
1739   m_sh2_state->r[n] = m_sh2_state->vbr;
16021740}
16031741
16041742/*  STC.L   SR,@-Rn */
1605INLINE void STCMSR(sh2_state *sh2, UINT32 n)
1743void sh2_device::STCMSR(UINT32 n)
16061744{
1607   sh2->r[n] -= 4;
1608   sh2->ea = sh2->r[n];
1609   WL( sh2, sh2->ea, sh2->sr );
1610   sh2->icount--;
1745   m_sh2_state->r[n] -= 4;
1746   m_sh2_state->ea = m_sh2_state->r[n];
1747   WL( m_sh2_state->ea, m_sh2_state->sr );
1748   m_sh2_state->icount--;
16111749}
16121750
16131751/*  STC.L   GBR,@-Rn */
1614INLINE void STCMGBR(sh2_state *sh2, UINT32 n)
1752void sh2_device::STCMGBR(UINT32 n)
16151753{
1616   sh2->r[n] -= 4;
1617   sh2->ea = sh2->r[n];
1618   WL( sh2, sh2->ea, sh2->gbr );
1619   sh2->icount--;
1754   m_sh2_state->r[n] -= 4;
1755   m_sh2_state->ea = m_sh2_state->r[n];
1756   WL( m_sh2_state->ea, m_sh2_state->gbr );
1757   m_sh2_state->icount--;
16201758}
16211759
16221760/*  STC.L   VBR,@-Rn */
1623INLINE void STCMVBR(sh2_state *sh2, UINT32 n)
1761void sh2_device::STCMVBR(UINT32 n)
16241762{
1625   sh2->r[n] -= 4;
1626   sh2->ea = sh2->r[n];
1627   WL( sh2, sh2->ea, sh2->vbr );
1628   sh2->icount--;
1763   m_sh2_state->r[n] -= 4;
1764   m_sh2_state->ea = m_sh2_state->r[n];
1765   WL( m_sh2_state->ea, m_sh2_state->vbr );
1766   m_sh2_state->icount--;
16291767}
16301768
16311769/*  STS     MACH,Rn */
1632INLINE void STSMACH(sh2_state *sh2, UINT32 n)
1770void sh2_device::STSMACH(UINT32 n)
16331771{
1634   sh2->r[n] = sh2->mach;
1772   m_sh2_state->r[n] = m_sh2_state->mach;
16351773}
16361774
16371775/*  STS     MACL,Rn */
1638INLINE void STSMACL(sh2_state *sh2, UINT32 n)
1776void sh2_device::STSMACL(UINT32 n)
16391777{
1640   sh2->r[n] = sh2->macl;
1778   m_sh2_state->r[n] = m_sh2_state->macl;
16411779}
16421780
16431781/*  STS     PR,Rn */
1644INLINE void STSPR(sh2_state *sh2, UINT32 n)
1782void sh2_device::STSPR(UINT32 n)
16451783{
1646   sh2->r[n] = sh2->pr;
1784   m_sh2_state->r[n] = m_sh2_state->pr;
16471785}
16481786
16491787/*  STS.L   MACH,@-Rn */
1650INLINE void STSMMACH(sh2_state *sh2, UINT32 n)
1788void sh2_device::STSMMACH(UINT32 n)
16511789{
1652   sh2->r[n] -= 4;
1653   sh2->ea = sh2->r[n];
1654   WL( sh2, sh2->ea, sh2->mach );
1790   m_sh2_state->r[n] -= 4;
1791   m_sh2_state->ea = m_sh2_state->r[n];
1792   WL( m_sh2_state->ea, m_sh2_state->mach );
16551793}
16561794
16571795/*  STS.L   MACL,@-Rn */
1658INLINE void STSMMACL(sh2_state *sh2, UINT32 n)
1796void sh2_device::STSMMACL(UINT32 n)
16591797{
1660   sh2->r[n] -= 4;
1661   sh2->ea = sh2->r[n];
1662   WL( sh2, sh2->ea, sh2->macl );
1798   m_sh2_state->r[n] -= 4;
1799   m_sh2_state->ea = m_sh2_state->r[n];
1800   WL( m_sh2_state->ea, m_sh2_state->macl );
16631801}
16641802
16651803/*  STS.L   PR,@-Rn */
1666INLINE void STSMPR(sh2_state *sh2, UINT32 n)
1804void sh2_device::STSMPR(UINT32 n)
16671805{
1668   sh2->r[n] -= 4;
1669   sh2->ea = sh2->r[n];
1670   WL( sh2, sh2->ea, sh2->pr );
1806   m_sh2_state->r[n] -= 4;
1807   m_sh2_state->ea = m_sh2_state->r[n];
1808   WL( m_sh2_state->ea, m_sh2_state->pr );
16711809}
16721810
16731811/*  SUB     Rm,Rn */
1674INLINE void SUB(sh2_state *sh2, UINT32 m, UINT32 n)
1812void sh2_device::SUB(UINT32 m, UINT32 n)
16751813{
1676   sh2->r[n] -= sh2->r[m];
1814   m_sh2_state->r[n] -= m_sh2_state->r[m];
16771815}
16781816
16791817/*  SUBC    Rm,Rn */
1680INLINE void SUBC(sh2_state *sh2, UINT32 m, UINT32 n)
1818void sh2_device::SUBC(UINT32 m, UINT32 n)
16811819{
16821820   UINT32 tmp0, tmp1;
16831821
1684   tmp1 = sh2->r[n] - sh2->r[m];
1685   tmp0 = sh2->r[n];
1686   sh2->r[n] = tmp1 - (sh2->sr & T);
1822   tmp1 = m_sh2_state->r[n] - m_sh2_state->r[m];
1823   tmp0 = m_sh2_state->r[n];
1824   m_sh2_state->r[n] = tmp1 - (m_sh2_state->sr & T);
16871825   if (tmp0 < tmp1)
1688      sh2->sr |= T;
1826      m_sh2_state->sr |= T;
16891827   else
1690      sh2->sr &= ~T;
1691   if (tmp1 < sh2->r[n])
1692      sh2->sr |= T;
1828      m_sh2_state->sr &= ~T;
1829   if (tmp1 < m_sh2_state->r[n])
1830      m_sh2_state->sr |= T;
16931831}
16941832
16951833/*  SUBV    Rm,Rn */
1696INLINE void SUBV(sh2_state *sh2, UINT32 m, UINT32 n)
1834void sh2_device::SUBV(UINT32 m, UINT32 n)
16971835{
16981836   INT32 dest, src, ans;
16991837
1700   if ((INT32) sh2->r[n] >= 0)
1838   if ((INT32) m_sh2_state->r[n] >= 0)
17011839      dest = 0;
17021840   else
17031841      dest = 1;
1704   if ((INT32) sh2->r[m] >= 0)
1842   if ((INT32) m_sh2_state->r[m] >= 0)
17051843      src = 0;
17061844   else
17071845      src = 1;
17081846   src += dest;
1709   sh2->r[n] -= sh2->r[m];
1710   if ((INT32) sh2->r[n] >= 0)
1847   m_sh2_state->r[n] -= m_sh2_state->r[m];
1848   if ((INT32) m_sh2_state->r[n] >= 0)
17111849      ans = 0;
17121850   else
17131851      ans = 1;
r29565r29566
17151853   if (src == 1)
17161854   {
17171855      if (ans == 1)
1718         sh2->sr |= T;
1856         m_sh2_state->sr |= T;
17191857      else
1720         sh2->sr &= ~T;
1858         m_sh2_state->sr &= ~T;
17211859   }
17221860   else
1723      sh2->sr &= ~T;
1861      m_sh2_state->sr &= ~T;
17241862}
17251863
17261864/*  SWAP.B  Rm,Rn */
1727INLINE void SWAPB(sh2_state *sh2, UINT32 m, UINT32 n)
1865void sh2_device::SWAPB(UINT32 m, UINT32 n)
17281866{
17291867   UINT32 temp0, temp1;
17301868
1731   temp0 = sh2->r[m] & 0xffff0000;
1732   temp1 = (sh2->r[m] & 0x000000ff) << 8;
1733   sh2->r[n] = (sh2->r[m] >> 8) & 0x000000ff;
1734   sh2->r[n] = sh2->r[n] | temp1 | temp0;
1869   temp0 = m_sh2_state->r[m] & 0xffff0000;
1870   temp1 = (m_sh2_state->r[m] & 0x000000ff) << 8;
1871   m_sh2_state->r[n] = (m_sh2_state->r[m] >> 8) & 0x000000ff;
1872   m_sh2_state->r[n] = m_sh2_state->r[n] | temp1 | temp0;
17351873}
17361874
17371875/*  SWAP.W  Rm,Rn */
1738INLINE void SWAPW(sh2_state *sh2, UINT32 m, UINT32 n)
1876void sh2_device::SWAPW(UINT32 m, UINT32 n)
17391877{
17401878   UINT32 temp;
17411879
1742   temp = (sh2->r[m] >> 16) & 0x0000ffff;
1743   sh2->r[n] = (sh2->r[m] << 16) | temp;
1880   temp = (m_sh2_state->r[m] >> 16) & 0x0000ffff;
1881   m_sh2_state->r[n] = (m_sh2_state->r[m] << 16) | temp;
17441882}
17451883
17461884/*  TAS.B   @Rn */
1747INLINE void TAS(sh2_state *sh2, UINT32 n)
1885void sh2_device::TAS(UINT32 n)
17481886{
17491887   UINT32 temp;
1750   sh2->ea = sh2->r[n];
1888   m_sh2_state->ea = m_sh2_state->r[n];
17511889   /* Bus Lock enable */
1752   temp = RB( sh2, sh2->ea );
1890   temp = RB( m_sh2_state->ea );
17531891   if (temp == 0)
1754      sh2->sr |= T;
1892      m_sh2_state->sr |= T;
17551893   else
1756      sh2->sr &= ~T;
1894      m_sh2_state->sr &= ~T;
17571895   temp |= 0x80;
17581896   /* Bus Lock disable */
1759   WB( sh2, sh2->ea, temp );
1760   sh2->icount -= 3;
1897   WB( m_sh2_state->ea, temp );
1898   m_sh2_state->icount -= 3;
17611899}
17621900
17631901/*  TRAPA   #imm */
1764INLINE void TRAPA(sh2_state *sh2, UINT32 i)
1902void sh2_device::TRAPA(UINT32 i)
17651903{
17661904   UINT32 imm = i & 0xff;
17671905
1768   sh2->ea = sh2->vbr + imm * 4;
1906   m_sh2_state->ea = m_sh2_state->vbr + imm * 4;
17691907
1770   sh2->r[15] -= 4;
1771   WL( sh2, sh2->r[15], sh2->sr );
1772   sh2->r[15] -= 4;
1773   WL( sh2, sh2->r[15], sh2->pc );
1908   m_sh2_state->r[15] -= 4;
1909   WL( m_sh2_state->r[15], m_sh2_state->sr );
1910   m_sh2_state->r[15] -= 4;
1911   WL( m_sh2_state->r[15], m_sh2_state->pc );
17741912
1775   sh2->pc = RL( sh2, sh2->ea );
1913   m_sh2_state->pc = RL( m_sh2_state->ea );
17761914
1777   sh2->icount -= 7;
1915   m_sh2_state->icount -= 7;
17781916}
17791917
17801918/*  TST     Rm,Rn */
1781INLINE void TST(sh2_state *sh2, UINT32 m, UINT32 n)
1919void sh2_device::TST(UINT32 m, UINT32 n)
17821920{
1783   if ((sh2->r[n] & sh2->r[m]) == 0)
1784      sh2->sr |= T;
1921   if ((m_sh2_state->r[n] & m_sh2_state->r[m]) == 0)
1922      m_sh2_state->sr |= T;
17851923   else
1786      sh2->sr &= ~T;
1924      m_sh2_state->sr &= ~T;
17871925}
17881926
17891927/*  TST     #imm,R0 */
1790INLINE void TSTI(sh2_state *sh2, UINT32 i)
1928void sh2_device::TSTI(UINT32 i)
17911929{
17921930   UINT32 imm = i & 0xff;
17931931
1794   if ((imm & sh2->r[0]) == 0)
1795      sh2->sr |= T;
1932   if ((imm & m_sh2_state->r[0]) == 0)
1933      m_sh2_state->sr |= T;
17961934   else
1797      sh2->sr &= ~T;
1935      m_sh2_state->sr &= ~T;
17981936}
17991937
18001938/*  TST.B   #imm,@(R0,GBR) */
1801INLINE void TSTM(sh2_state *sh2, UINT32 i)
1939void sh2_device::TSTM(UINT32 i)
18021940{
18031941   UINT32 imm = i & 0xff;
18041942
1805   sh2->ea = sh2->gbr + sh2->r[0];
1806   if ((imm & RB( sh2, sh2->ea )) == 0)
1807      sh2->sr |= T;
1943   m_sh2_state->ea = m_sh2_state->gbr + m_sh2_state->r[0];
1944   if ((imm & RB( m_sh2_state->ea )) == 0)
1945      m_sh2_state->sr |= T;
18081946   else
1809      sh2->sr &= ~T;
1810   sh2->icount -= 2;
1947      m_sh2_state->sr &= ~T;
1948   m_sh2_state->icount -= 2;
18111949}
18121950
18131951/*  XOR     Rm,Rn */
1814INLINE void XOR(sh2_state *sh2, UINT32 m, UINT32 n)
1952void sh2_device::XOR(UINT32 m, UINT32 n)
18151953{
1816   sh2->r[n] ^= sh2->r[m];
1954   m_sh2_state->r[n] ^= m_sh2_state->r[m];
18171955}
18181956
18191957/*  XOR     #imm,R0 */
1820INLINE void XORI(sh2_state *sh2, UINT32 i)
1958void sh2_device::XORI(UINT32 i)
18211959{
18221960   UINT32 imm = i & 0xff;
1823   sh2->r[0] ^= imm;
1961   m_sh2_state->r[0] ^= imm;
18241962}
18251963
18261964/*  XOR.B   #imm,@(R0,GBR) */
1827INLINE void XORM(sh2_state *sh2, UINT32 i)
1965void sh2_device::XORM(UINT32 i)
18281966{
18291967   UINT32 imm = i & 0xff;
18301968   UINT32 temp;
18311969
1832   sh2->ea = sh2->gbr + sh2->r[0];
1833   temp = RB( sh2, sh2->ea );
1970   m_sh2_state->ea = m_sh2_state->gbr + m_sh2_state->r[0];
1971   temp = RB( m_sh2_state->ea );
18341972   temp ^= imm;
1835   WB( sh2, sh2->ea, temp );
1836   sh2->icount -= 2;
1973   WB( m_sh2_state->ea, temp );
1974   m_sh2_state->icount -= 2;
18371975}
18381976
18391977/*  XTRCT   Rm,Rn */
1840INLINE void XTRCT(sh2_state *sh2, UINT32 m, UINT32 n)
1978void sh2_device::XTRCT(UINT32 m, UINT32 n)
18411979{
18421980   UINT32 temp;
18431981
1844   temp = (sh2->r[m] << 16) & 0xffff0000;
1845   sh2->r[n] = (sh2->r[n] >> 16) & 0x0000ffff;
1846   sh2->r[n] |= temp;
1982   temp = (m_sh2_state->r[m] << 16) & 0xffff0000;
1983   m_sh2_state->r[n] = (m_sh2_state->r[n] >> 16) & 0x0000ffff;
1984   m_sh2_state->r[n] |= temp;
18471985}
18481986
18491987/*****************************************************************************
18501988 *  OPCODE DISPATCHERS
18511989 *****************************************************************************/
18521990
1853INLINE void op0000(sh2_state *sh2, UINT16 opcode)
1991void sh2_device::op0000(UINT16 opcode)
18541992{
18551993   switch (opcode & 0x3F)
18561994   {
1857   case 0x00: ILLEGAL(sh2);                       break;
1858   case 0x01: ILLEGAL(sh2);                       break;
1859   case 0x02: STCSR(sh2, Rn);                  break;
1860   case 0x03: BSRF(sh2, Rn);                   break;
1861   case 0x04: MOVBS0(sh2, Rm, Rn);             break;
1862   case 0x05: MOVWS0(sh2, Rm, Rn);             break;
1863   case 0x06: MOVLS0(sh2, Rm, Rn);             break;
1864   case 0x07: MULL(sh2, Rm, Rn);               break;
1865   case 0x08: CLRT(sh2);                       break;
1995   case 0x00: ILLEGAL();                       break;
1996   case 0x01: ILLEGAL();                       break;
1997   case 0x02: STCSR(Rn);                  break;
1998   case 0x03: BSRF(Rn);                   break;
1999   case 0x04: MOVBS0(Rm, Rn);             break;
2000   case 0x05: MOVWS0(Rm, Rn);             break;
2001   case 0x06: MOVLS0(Rm, Rn);             break;
2002   case 0x07: MULL(Rm, Rn);               break;
2003   case 0x08: CLRT();                       break;
18662004   case 0x09: NOP();                           break;
1867   case 0x0a: STSMACH(sh2, Rn);                break;
1868   case 0x0b: RTS(sh2);                        break;
1869   case 0x0c: MOVBL0(sh2, Rm, Rn);             break;
1870   case 0x0d: MOVWL0(sh2, Rm, Rn);             break;
1871   case 0x0e: MOVLL0(sh2, Rm, Rn);             break;
1872   case 0x0f: MAC_L(sh2, Rm, Rn);              break;
2005   case 0x0a: STSMACH(Rn);                break;
2006   case 0x0b: RTS();                        break;
2007   case 0x0c: MOVBL0(Rm, Rn);             break;
2008   case 0x0d: MOVWL0(Rm, Rn);             break;
2009   case 0x0e: MOVLL0(Rm, Rn);             break;
2010   case 0x0f: MAC_L(Rm, Rn);              break;
18732011
1874   case 0x10: ILLEGAL(sh2);                       break;
1875   case 0x11: ILLEGAL(sh2);                       break;
1876   case 0x12: STCGBR(sh2, Rn);                 break;
1877   case 0x13: ILLEGAL(sh2);                       break;
1878   case 0x14: MOVBS0(sh2, Rm, Rn);             break;
1879   case 0x15: MOVWS0(sh2, Rm, Rn);             break;
1880   case 0x16: MOVLS0(sh2, Rm, Rn);             break;
1881   case 0x17: MULL(sh2, Rm, Rn);               break;
1882   case 0x18: SETT(sh2);                       break;
1883   case 0x19: DIV0U(sh2);                  break;
1884   case 0x1a: STSMACL(sh2, Rn);                break;
1885   case 0x1b: SLEEP(sh2);                  break;
1886   case 0x1c: MOVBL0(sh2, Rm, Rn);             break;
1887   case 0x1d: MOVWL0(sh2, Rm, Rn);             break;
1888   case 0x1e: MOVLL0(sh2, Rm, Rn);             break;
1889   case 0x1f: MAC_L(sh2, Rm, Rn);              break;
2012   case 0x10: ILLEGAL();                       break;
2013   case 0x11: ILLEGAL();                       break;
2014   case 0x12: STCGBR(Rn);                 break;
2015   case 0x13: ILLEGAL();                       break;
2016   case 0x14: MOVBS0(Rm, Rn);             break;
2017   case 0x15: MOVWS0(Rm, Rn);             break;
2018   case 0x16: MOVLS0(Rm, Rn);             break;
2019   case 0x17: MULL(Rm, Rn);               break;
2020   case 0x18: SETT();                       break;
2021   case 0x19: DIV0U();                  break;
2022   case 0x1a: STSMACL(Rn);                break;
2023   case 0x1b: SLEEP();                  break;
2024   case 0x1c: MOVBL0(Rm, Rn);             break;
2025   case 0x1d: MOVWL0(Rm, Rn);             break;
2026   case 0x1e: MOVLL0(Rm, Rn);             break;
2027   case 0x1f: MAC_L(Rm, Rn);              break;
18902028
1891   case 0x20: ILLEGAL(sh2);                       break;
1892   case 0x21: ILLEGAL(sh2);                       break;
1893   case 0x22: STCVBR(sh2, Rn);                 break;
1894   case 0x23: BRAF(sh2, Rn);                   break;
1895   case 0x24: MOVBS0(sh2, Rm, Rn);             break;
1896   case 0x25: MOVWS0(sh2, Rm, Rn);             break;
1897   case 0x26: MOVLS0(sh2, Rm, Rn);             break;
1898   case 0x27: MULL(sh2, Rm, Rn);               break;
1899   case 0x28: CLRMAC(sh2);                 break;
1900   case 0x29: MOVT(sh2, Rn);                   break;
1901   case 0x2a: STSPR(sh2, Rn);                  break;
1902   case 0x2b: RTE(sh2);                        break;
1903   case 0x2c: MOVBL0(sh2, Rm, Rn);             break;
1904   case 0x2d: MOVWL0(sh2, Rm, Rn);             break;
1905   case 0x2e: MOVLL0(sh2, Rm, Rn);             break;
1906   case 0x2f: MAC_L(sh2, Rm, Rn);              break;
2029   case 0x20: ILLEGAL();                       break;
2030   case 0x21: ILLEGAL();                       break;
2031   case 0x22: STCVBR(Rn);                 break;
2032   case 0x23: BRAF(Rn);                   break;
2033   case 0x24: MOVBS0(Rm, Rn);             break;
2034   case 0x25: MOVWS0(Rm, Rn);             break;
2035   case 0x26: MOVLS0(Rm, Rn);             break;
2036   case 0x27: MULL(Rm, Rn);               break;
2037   case 0x28: CLRMAC();                 break;
2038   case 0x29: MOVT(Rn);                   break;
2039   case 0x2a: STSPR(Rn);                  break;
2040   case 0x2b: RTE();                        break;
2041   case 0x2c: MOVBL0(Rm, Rn);             break;
2042   case 0x2d: MOVWL0(Rm, Rn);             break;
2043   case 0x2e: MOVLL0(Rm, Rn);             break;
2044   case 0x2f: MAC_L(Rm, Rn);              break;
19072045
1908   case 0x30: ILLEGAL(sh2);                       break;
1909   case 0x31: ILLEGAL(sh2);                       break;
1910   case 0x32: ILLEGAL(sh2);                       break;
1911   case 0x33: ILLEGAL(sh2);                       break;
1912   case 0x34: MOVBS0(sh2, Rm, Rn);             break;
1913   case 0x35: MOVWS0(sh2, Rm, Rn);             break;
1914   case 0x36: MOVLS0(sh2, Rm, Rn);             break;
1915   case 0x37: MULL(sh2, Rm, Rn);               break;
1916   case 0x38: ILLEGAL(sh2);                       break;
1917   case 0x39: ILLEGAL(sh2);                       break;
1918   case 0x3c: MOVBL0(sh2, Rm, Rn);             break;
1919   case 0x3d: MOVWL0(sh2, Rm, Rn);             break;
1920   case 0x3e: MOVLL0(sh2, Rm, Rn);             break;
1921   case 0x3f: MAC_L(sh2, Rm, Rn);              break;
1922   case 0x3a: ILLEGAL(sh2);                       break;
1923   case 0x3b: ILLEGAL(sh2);                       break;
2046   case 0x30: ILLEGAL();                       break;
2047   case 0x31: ILLEGAL();                       break;
2048   case 0x32: ILLEGAL();                       break;
2049   case 0x33: ILLEGAL();                       break;
2050   case 0x34: MOVBS0(Rm, Rn);             break;
2051   case 0x35: MOVWS0(Rm, Rn);             break;
2052   case 0x36: MOVLS0(Rm, Rn);             break;
2053   case 0x37: MULL(Rm, Rn);               break;
2054   case 0x38: ILLEGAL();                       break;
2055   case 0x39: ILLEGAL();                       break;
2056   case 0x3c: MOVBL0(Rm, Rn);             break;
2057   case 0x3d: MOVWL0(Rm, Rn);             break;
2058   case 0x3e: MOVLL0(Rm, Rn);             break;
2059   case 0x3f: MAC_L(Rm, Rn);              break;
2060   case 0x3a: ILLEGAL();                       break;
2061   case 0x3b: ILLEGAL();                       break;
19242062
19252063
19262064
19272065   }
19282066}
19292067
1930INLINE void op0001(sh2_state *sh2, UINT16 opcode)
2068void sh2_device::op0001(UINT16 opcode)
19312069{
1932   MOVLS4(sh2, Rm, opcode & 0x0f, Rn);
2070   MOVLS4(Rm, opcode & 0x0f, Rn);
19332071}
19342072
1935INLINE void op0010(sh2_state *sh2, UINT16 opcode)
2073void sh2_device::op0010(UINT16 opcode)
19362074{
19372075   switch (opcode & 15)
19382076   {
1939   case  0: MOVBS(sh2, Rm, Rn);                break;
1940   case  1: MOVWS(sh2, Rm, Rn);                break;
1941   case  2: MOVLS(sh2, Rm, Rn);                break;
1942   case  3: ILLEGAL(sh2);                         break;
1943   case  4: MOVBM(sh2, Rm, Rn);                break;
1944   case  5: MOVWM(sh2, Rm, Rn);                break;
1945   case  6: MOVLM(sh2, Rm, Rn);                break;
1946   case  7: DIV0S(sh2, Rm, Rn);                break;
1947   case  8: TST(sh2, Rm, Rn);                  break;
1948   case  9: AND(sh2, Rm, Rn);                  break;
1949   case 10: XOR(sh2, Rm, Rn);                  break;
1950   case 11: OR(sh2, Rm, Rn);                   break;
1951   case 12: CMPSTR(sh2, Rm, Rn);               break;
1952   case 13: XTRCT(sh2, Rm, Rn);                break;
1953   case 14: MULU(sh2, Rm, Rn);                 break;
1954   case 15: MULS(sh2, Rm, Rn);                 break;
2077   case  0: MOVBS(Rm, Rn);                break;
2078   case  1: MOVWS(Rm, Rn);                break;
2079   case  2: MOVLS(Rm, Rn);                break;
2080   case  3: ILLEGAL();                         break;
2081   case  4: MOVBM(Rm, Rn);                break;
2082   case  5: MOVWM(Rm, Rn);                break;
2083   case  6: MOVLM(Rm, Rn);                break;
2084   case  7: DIV0S(Rm, Rn);                break;
2085   case  8: TST(Rm, Rn);                  break;
2086   case  9: AND(Rm, Rn);                  break;
2087   case 10: XOR(Rm, Rn);                  break;
2088   case 11: OR(Rm, Rn);                   break;
2089   case 12: CMPSTR(Rm, Rn);               break;
2090   case 13: XTRCT(Rm, Rn);                break;
2091   case 14: MULU(Rm, Rn);                 break;
2092   case 15: MULS(Rm, Rn);                 break;
19552093   }
19562094}
19572095
1958INLINE void op0011(sh2_state *sh2, UINT16 opcode)
2096void sh2_device::op0011(UINT16 opcode)
19592097{
19602098   switch (opcode & 15)
19612099   {
1962   case  0: CMPEQ(sh2, Rm, Rn);                break;
1963   case  1: ILLEGAL(sh2);                         break;
1964   case  2: CMPHS(sh2, Rm, Rn);                break;
1965   case  3: CMPGE(sh2, Rm, Rn);                break;
1966   case  4: DIV1(sh2, Rm, Rn);                 break;
1967   case  5: DMULU(sh2, Rm, Rn);                break;
1968   case  6: CMPHI(sh2, Rm, Rn);                break;
1969   case  7: CMPGT(sh2, Rm, Rn);                break;
1970   case  8: SUB(sh2, Rm, Rn);                  break;
1971   case  9: ILLEGAL(sh2);                         break;
1972   case 10: SUBC(sh2, Rm, Rn);                 break;
1973   case 11: SUBV(sh2, Rm, Rn);                 break;
1974   case 12: ADD(sh2, Rm, Rn);                  break;
1975   case 13: DMULS(sh2, Rm, Rn);                break;
1976   case 14: ADDC(sh2, Rm, Rn);                 break;
1977   case 15: ADDV(sh2, Rm, Rn);                 break;
2100   case  0: CMPEQ(Rm, Rn);                break;
2101   case  1: ILLEGAL();                         break;
2102   case  2: CMPHS(Rm, Rn);                break;
2103   case  3: CMPGE(Rm, Rn);                break;
2104   case  4: DIV1(Rm, Rn);                 break;
2105   case  5: DMULU(Rm, Rn);                break;
2106   case  6: CMPHI(Rm, Rn);                break;
2107   case  7: CMPGT(Rm, Rn);                break;
2108   case  8: SUB(Rm, Rn);                  break;
2109   case  9: ILLEGAL();                         break;
2110   case 10: SUBC(Rm, Rn);                 break;
2111   case 11: SUBV(Rm, Rn);                 break;
2112   case 12: ADD(Rm, Rn);                  break;
2113   case 13: DMULS(Rm, Rn);                break;
2114   case 14: ADDC(Rm, Rn);                 break;
2115   case 15: ADDV(Rm, Rn);                 break;
19782116   }
19792117}
19802118
1981INLINE void op0100(sh2_state *sh2, UINT16 opcode)
2119void sh2_device::op0100(UINT16 opcode)
19822120{
19832121   switch (opcode & 0x3F)
19842122   {
1985   case 0x00: SHLL(sh2, Rn);                   break;
1986   case 0x01: SHLR(sh2, Rn);                   break;
1987   case 0x02: STSMMACH(sh2, Rn);               break;
1988   case 0x03: STCMSR(sh2, Rn);                 break;
1989   case 0x04: ROTL(sh2, Rn);                   break;
1990   case 0x05: ROTR(sh2, Rn);                   break;
1991   case 0x06: LDSMMACH(sh2, Rn);               break;
1992   case 0x07: LDCMSR(sh2, Rn);                 break;
1993   case 0x08: SHLL2(sh2, Rn);                  break;
1994   case 0x09: SHLR2(sh2, Rn);                  break;
1995   case 0x0a: LDSMACH(sh2, Rn);                break;
1996   case 0x0b: JSR(sh2, Rn);                    break;
1997   case 0x0c: ILLEGAL(sh2);                       break;
1998   case 0x0d: ILLEGAL(sh2);                       break;
1999   case 0x0e: LDCSR(sh2, Rn);                  break;
2000   case 0x0f: MAC_W(sh2, Rm, Rn);              break;
2123   case 0x00: SHLL(Rn);                   break;
2124   case 0x01: SHLR(Rn);                   break;
2125   case 0x02: STSMMACH(Rn);               break;
2126   case 0x03: STCMSR(Rn);                 break;
2127   case 0x04: ROTL(Rn);                   break;
2128   case 0x05: ROTR(Rn);                   break;
2129   case 0x06: LDSMMACH(Rn);               break;
2130   case 0x07: LDCMSR(Rn);                 break;
2131   case 0x08: SHLL2(Rn);                  break;
2132   case 0x09: SHLR2(Rn);                  break;
2133   case 0x0a: LDSMACH(Rn);                break;
2134   case 0x0b: JSR(Rn);                    break;
2135   case 0x0c: ILLEGAL();                       break;
2136   case 0x0d: ILLEGAL();                       break;
2137   case 0x0e: LDCSR(Rn);                  break;
2138   case 0x0f: MAC_W(Rm, Rn);              break;
20012139
2002   case 0x10: DT(sh2, Rn);                     break;
2003   case 0x11: CMPPZ(sh2, Rn);                  break;
2004   case 0x12: STSMMACL(sh2, Rn);               break;
2005   case 0x13: STCMGBR(sh2, Rn);                break;
2006   case 0x14: ILLEGAL(sh2);                       break;
2007   case 0x15: CMPPL(sh2, Rn);                  break;
2008   case 0x16: LDSMMACL(sh2, Rn);               break;
2009   case 0x17: LDCMGBR(sh2, Rn);                break;
2010   case 0x18: SHLL8(sh2, Rn);                  break;
2011   case 0x19: SHLR8(sh2, Rn);                  break;
2012   case 0x1a: LDSMACL(sh2, Rn);                break;
2013   case 0x1b: TAS(sh2, Rn);                    break;
2014   case 0x1c: ILLEGAL(sh2);                       break;
2015   case 0x1d: ILLEGAL(sh2);                       break;
2016   case 0x1e: LDCGBR(sh2, Rn);                 break;
2017   case 0x1f: MAC_W(sh2, Rm, Rn);              break;
2140   case 0x10: DT(Rn);                     break;
2141   case 0x11: CMPPZ(Rn);                  break;
2142   case 0x12: STSMMACL(Rn);               break;
2143   case 0x13: STCMGBR(Rn);                break;
2144   case 0x14: ILLEGAL();                       break;
2145   case 0x15: CMPPL(Rn);                  break;
2146   case 0x16: LDSMMACL(Rn);               break;
2147   case 0x17: LDCMGBR(Rn);                break;
2148   case 0x18: SHLL8(Rn);                  break;
2149   case 0x19: SHLR8(Rn);                  break;
2150   case 0x1a: LDSMACL(Rn);                break;
2151   case 0x1b: TAS(Rn);                    break;
2152   case 0x1c: ILLEGAL();                       break;
2153   case 0x1d: ILLEGAL();                       break;
2154   case 0x1e: LDCGBR(Rn);                 break;
2155   case 0x1f: MAC_W(Rm, Rn);              break;
20182156
2019   case 0x20: SHAL(sh2, Rn);                   break;
2020   case 0x21: SHAR(sh2, Rn);                   break;
2021   case 0x22: STSMPR(sh2, Rn);                 break;
2022   case 0x23: STCMVBR(sh2, Rn);                break;
2023   case 0x24: ROTCL(sh2, Rn);                  break;
2024   case 0x25: ROTCR(sh2, Rn);                  break;
2025   case 0x26: LDSMPR(sh2, Rn);                 break;
2026   case 0x27: LDCMVBR(sh2, Rn);                break;
2027   case 0x28: SHLL16(sh2, Rn);                 break;
2028   case 0x29: SHLR16(sh2, Rn);                 break;
2029   case 0x2a: LDSPR(sh2, Rn);                  break;
2030   case 0x2b: JMP(sh2, Rn);                    break;
2031   case 0x2c: ILLEGAL(sh2);                       break;
2032   case 0x2d: ILLEGAL(sh2);                       break;
2033   case 0x2e: LDCVBR(sh2, Rn);                 break;
2034   case 0x2f: MAC_W(sh2, Rm, Rn);              break;
2157   case 0x20: SHAL(Rn);                   break;
2158   case 0x21: SHAR(Rn);                   break;
2159   case 0x22: STSMPR(Rn);                 break;
2160   case 0x23: STCMVBR(Rn);                break;
2161   case 0x24: ROTCL(Rn);                  break;
2162   case 0x25: ROTCR(Rn);                  break;
2163   case 0x26: LDSMPR(Rn);                 break;
2164   case 0x27: LDCMVBR(Rn);                break;
2165   case 0x28: SHLL16(Rn);                 break;
2166   case 0x29: SHLR16(Rn);                 break;
2167   case 0x2a: LDSPR(Rn);                  break;
2168   case 0x2b: JMP(Rn);                    break;
2169   case 0x2c: ILLEGAL();                       break;
2170   case 0x2d: ILLEGAL();                       break;
2171   case 0x2e: LDCVBR(Rn);                 break;
2172   case 0x2f: MAC_W(Rm, Rn);              break;
20352173
2036   case 0x30: ILLEGAL(sh2);                       break;
2037   case 0x31: ILLEGAL(sh2);                       break;
2038   case 0x32: ILLEGAL(sh2);                       break;
2039   case 0x33: ILLEGAL(sh2);                       break;
2040   case 0x34: ILLEGAL(sh2);                       break;
2041   case 0x35: ILLEGAL(sh2);                       break;
2042   case 0x36: ILLEGAL(sh2);                       break;
2043   case 0x37: ILLEGAL(sh2);                       break;
2044   case 0x38: ILLEGAL(sh2);                       break;
2045   case 0x39: ILLEGAL(sh2);                       break;
2046   case 0x3a: ILLEGAL(sh2);                       break;
2047   case 0x3b: ILLEGAL(sh2);                       break;
2048   case 0x3c: ILLEGAL(sh2);                       break;
2049   case 0x3d: ILLEGAL(sh2);                       break;
2050   case 0x3e: ILLEGAL(sh2);                       break;
2051   case 0x3f: MAC_W(sh2, Rm, Rn);              break;
2174   case 0x30: ILLEGAL();                       break;
2175   case 0x31: ILLEGAL();                       break;
2176   case 0x32: ILLEGAL();                       break;
2177   case 0x33: ILLEGAL();                       break;
2178   case 0x34: ILLEGAL();                       break;
2179   case 0x35: ILLEGAL();                       break;
2180   case 0x36: ILLEGAL();                       break;
2181   case 0x37: ILLEGAL();                       break;
2182   case 0x38: ILLEGAL();                       break;
2183   case 0x39: ILLEGAL();                       break;
2184   case 0x3a: ILLEGAL();                       break;
2185   case 0x3b: ILLEGAL();                       break;
2186   case 0x3c: ILLEGAL();                       break;
2187   case 0x3d: ILLEGAL();                       break;
2188   case 0x3e: ILLEGAL();                       break;
2189   case 0x3f: MAC_W(Rm, Rn);              break;
20522190
20532191   }
20542192}
20552193
2056INLINE void op0101(sh2_state *sh2, UINT16 opcode)
2194void sh2_device::op0101(UINT16 opcode)
20572195{
2058   MOVLL4(sh2, Rm, opcode & 0x0f, Rn);
2196   MOVLL4(Rm, opcode & 0x0f, Rn);
20592197}
20602198
2061INLINE void op0110(sh2_state *sh2, UINT16 opcode)
2199void sh2_device::op0110(UINT16 opcode)
20622200{
20632201   switch (opcode & 15)
20642202   {
2065   case  0: MOVBL(sh2, Rm, Rn);                break;
2066   case  1: MOVWL(sh2, Rm, Rn);                break;
2067   case  2: MOVLL(sh2, Rm, Rn);                break;
2068   case  3: MOV(sh2, Rm, Rn);                  break;
2069   case  4: MOVBP(sh2, Rm, Rn);                break;
2070   case  5: MOVWP(sh2, Rm, Rn);                break;
2071   case  6: MOVLP(sh2, Rm, Rn);                break;
2072   case  7: NOT(sh2, Rm, Rn);                  break;
2073   case  8: SWAPB(sh2, Rm, Rn);                break;
2074   case  9: SWAPW(sh2, Rm, Rn);                break;
2075   case 10: NEGC(sh2, Rm, Rn);                 break;
2076   case 11: NEG(sh2, Rm, Rn);                  break;
2077   case 12: EXTUB(sh2, Rm, Rn);                break;
2078   case 13: EXTUW(sh2, Rm, Rn);                break;
2079   case 14: EXTSB(sh2, Rm, Rn);                break;
2080   case 15: EXTSW(sh2, Rm, Rn);                break;
2203   case  0: MOVBL(Rm, Rn);                break;
2204   case  1: MOVWL(Rm, Rn);                break;
2205   case  2: MOVLL(Rm, Rn);                break;
2206   case  3: MOV(Rm, Rn);                  break;
2207   case  4: MOVBP(Rm, Rn);                break;
2208   case  5: MOVWP(Rm, Rn);                break;
2209   case  6: MOVLP(Rm, Rn);                break;
2210   case  7: NOT(Rm, Rn);                  break;
2211   case  8: SWAPB(Rm, Rn);                break;
2212   case  9: SWAPW(Rm, Rn);                break;
2213   case 10: NEGC(Rm, Rn);                 break;
2214   case 11: NEG(Rm, Rn);                  break;
2215   case 12: EXTUB(Rm, Rn);                break;
2216   case 13: EXTUW(Rm, Rn);                break;
2217   case 14: EXTSB(Rm, Rn);                break;
2218   case 15: EXTSW(Rm, Rn);                break;
20812219   }
20822220}
20832221
2084INLINE void op0111(sh2_state *sh2, UINT16 opcode)
2222void sh2_device::op0111(UINT16 opcode)
20852223{
2086   ADDI(sh2, opcode & 0xff, Rn);
2224   ADDI(opcode & 0xff, Rn);
20872225}
20882226
2089INLINE void op1000(sh2_state *sh2, UINT16 opcode)
2227void sh2_device::op1000(UINT16 opcode)
20902228{
20912229   switch ( opcode  & (15<<8) )
20922230   {
2093   case  0 << 8: MOVBS4(sh2, opcode & 0x0f, Rm);   break;
2094   case  1 << 8: MOVWS4(sh2, opcode & 0x0f, Rm);   break;
2095   case  2<< 8: ILLEGAL(sh2);                 break;
2096   case  3<< 8: ILLEGAL(sh2);                 break;
2097   case  4<< 8: MOVBL4(sh2, Rm, opcode & 0x0f);    break;
2098   case  5<< 8: MOVWL4(sh2, Rm, opcode & 0x0f);    break;
2099   case  6<< 8: ILLEGAL(sh2);                 break;
2100   case  7<< 8: ILLEGAL(sh2);                 break;
2101   case  8<< 8: CMPIM(sh2, opcode & 0xff);     break;
2102   case  9<< 8: BT(sh2, opcode & 0xff);        break;
2103   case 10<< 8: ILLEGAL(sh2);                 break;
2104   case 11<< 8: BF(sh2, opcode & 0xff);        break;
2105   case 12<< 8: ILLEGAL(sh2);                 break;
2106   case 13<< 8: BTS(sh2, opcode & 0xff);       break;
2107   case 14<< 8: ILLEGAL(sh2);                 break;
2108   case 15<< 8: BFS(sh2, opcode & 0xff);       break;
2231   case  0 << 8: MOVBS4(opcode & 0x0f, Rm);   break;
2232   case  1 << 8: MOVWS4(opcode & 0x0f, Rm);   break;
2233   case  2<< 8: ILLEGAL();                 break;
2234   case  3<< 8: ILLEGAL();                 break;
2235   case  4<< 8: MOVBL4(Rm, opcode & 0x0f);    break;
2236   case  5<< 8: MOVWL4(Rm, opcode & 0x0f);    break;
2237   case  6<< 8: ILLEGAL();                 break;
2238   case  7<< 8: ILLEGAL();                 break;
2239   case  8<< 8: CMPIM(opcode & 0xff);     break;
2240   case  9<< 8: BT(opcode & 0xff);        break;
2241   case 10<< 8: ILLEGAL();                 break;
2242   case 11<< 8: BF(opcode & 0xff);        break;
2243   case 12<< 8: ILLEGAL();                 break;
2244   case 13<< 8: BTS(opcode & 0xff);       break;
2245   case 14<< 8: ILLEGAL();                 break;
2246   case 15<< 8: BFS(opcode & 0xff);       break;
21092247   }
21102248}
21112249
21122250
2113INLINE void op1001(sh2_state *sh2, UINT16 opcode)
2251void sh2_device::op1001(UINT16 opcode)
21142252{
2115   MOVWI(sh2, opcode & 0xff, Rn);
2253   MOVWI(opcode & 0xff, Rn);
21162254}
21172255
2118INLINE void op1010(sh2_state *sh2, UINT16 opcode)
2256void sh2_device::op1010(UINT16 opcode)
21192257{
2120   BRA(sh2, opcode & 0xfff);
2258   BRA(opcode & 0xfff);
21212259}
21222260
2123INLINE void op1011(sh2_state *sh2, UINT16 opcode)
2261void sh2_device::op1011(UINT16 opcode)
21242262{
2125   BSR(sh2, opcode & 0xfff);
2263   BSR(opcode & 0xfff);
21262264}
21272265
2128INLINE void op1100(sh2_state *sh2, UINT16 opcode)
2266void sh2_device::op1100(UINT16 opcode)
21292267{
21302268   switch (opcode & (15<<8))
21312269   {
2132   case  0<<8: MOVBSG(sh2, opcode & 0xff);     break;
2133   case  1<<8: MOVWSG(sh2, opcode & 0xff);     break;
2134   case  2<<8: MOVLSG(sh2, opcode & 0xff);     break;
2135   case  3<<8: TRAPA(sh2, opcode & 0xff);      break;
2136   case  4<<8: MOVBLG(sh2, opcode & 0xff);     break;
2137   case  5<<8: MOVWLG(sh2, opcode & 0xff);     break;
2138   case  6<<8: MOVLLG(sh2, opcode & 0xff);     break;
2139   case  7<<8: MOVA(sh2, opcode & 0xff);       break;
2140   case  8<<8: TSTI(sh2, opcode & 0xff);       break;
2141   case  9<<8: ANDI(sh2, opcode & 0xff);       break;
2142   case 10<<8: XORI(sh2, opcode & 0xff);       break;
2143   case 11<<8: ORI(sh2, opcode & 0xff);            break;
2144   case 12<<8: TSTM(sh2, opcode & 0xff);       break;
2145   case 13<<8: ANDM(sh2, opcode & 0xff);       break;
2146   case 14<<8: XORM(sh2, opcode & 0xff);       break;
2147   case 15<<8: ORM(sh2, opcode & 0xff);            break;
2270   case  0<<8: MOVBSG(opcode & 0xff);     break;
2271   case  1<<8: MOVWSG(opcode & 0xff);     break;
2272   case  2<<8: MOVLSG(opcode & 0xff);     break;
2273   case  3<<8: TRAPA(opcode & 0xff);      break;
2274   case  4<<8: MOVBLG(opcode & 0xff);     break;
2275   case  5<<8: MOVWLG(opcode & 0xff);     break;
2276   case  6<<8: MOVLLG(opcode & 0xff);     break;
2277   case  7<<8: MOVA(opcode & 0xff);       break;
2278   case  8<<8: TSTI(opcode & 0xff);       break;
2279   case  9<<8: ANDI(opcode & 0xff);       break;
2280   case 10<<8: XORI(opcode & 0xff);       break;
2281   case 11<<8: ORI(opcode & 0xff);            break;
2282   case 12<<8: TSTM(opcode & 0xff);       break;
2283   case 13<<8: ANDM(opcode & 0xff);       break;
2284   case 14<<8: XORM(opcode & 0xff);       break;
2285   case 15<<8: ORM(opcode & 0xff);            break;
21482286   }
21492287}
21502288
2151INLINE void op1101(sh2_state *sh2, UINT16 opcode)
2289void sh2_device::op1101(UINT16 opcode)
21522290{
2153   MOVLI(sh2, opcode & 0xff, Rn);
2291   MOVLI(opcode & 0xff, Rn);
21542292}
21552293
2156INLINE void op1110(sh2_state *sh2, UINT16 opcode)
2294void sh2_device::op1110(UINT16 opcode)
21572295{
2158   MOVI(sh2, opcode & 0xff, Rn);
2296   MOVI(opcode & 0xff, Rn);
21592297}
21602298
2161INLINE void op1111(sh2_state *sh2, UINT16 opcode)
2299void sh2_device::op1111(UINT16 opcode)
21622300{
2163   ILLEGAL(sh2);
2301   ILLEGAL();
21642302}
21652303
21662304/*****************************************************************************
21672305 *  MAME CPU INTERFACE
21682306 *****************************************************************************/
21692307
2170static CPU_RESET( sh2 )
2308void sh2_device::device_reset()
21712309{
2172   sh2_state *sh2 = get_safe_token(device);
2173   int  (*dma_callback_kludge)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
2174   int  (*dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
2175   int save_is_slave;
2310   m_sh2_state->ppc = m_sh2_state->pc = m_sh2_state->pr = m_sh2_state->sr = m_sh2_state->gbr = m_sh2_state->vbr = m_sh2_state->mach = m_sh2_state->macl = 0;
2311   m_sh2_state->evec = m_sh2_state->irqsr = 0;
2312   memset(&m_sh2_state->r[0], 0, sizeof(m_sh2_state->r[0])*16);
2313   m_sh2_state->ea = m_delay = m_cpu_off = m_dvsr = m_dvdnth = m_dvdntl = m_dvcr = 0;
2314   m_sh2_state->pending_irq = m_test_irq = 0;
2315   memset(&m_irq_queue[0], 0, sizeof(m_irq_queue[0])*16);
2316   memset(&m_irq_line_state[0], 0, sizeof(m_irq_line_state[0])*17);
2317   m_frc = m_ocra = m_ocrb = m_icr = 0;
2318   m_frc_base = 0;
2319   m_frt_input = m_sh2_state->internal_irq_level = m_internal_irq_vector = 0;
2320   m_dma_timer_active[0] = m_dma_timer_active[1] = 0;
2321   m_dma_irq[0] = m_dma_irq[1] = 0;
21762322
2177   void (*f)(UINT32 data);
2178   device_irq_acknowledge_callback save_irqcallback;
2323   memset(m_m, 0, 0x200);
21792324
2180   f = sh2->ftcsr_read_callback;
2181   save_irqcallback = sh2->irq_callback;
2182   save_is_slave = sh2->is_slave;
2183   dma_callback_kludge = sh2->dma_callback_kludge;
2184   dma_callback_fifo_data_available = sh2->dma_callback_fifo_data_available;
2325   m_sh2_state->pc = RL(0);
2326   m_sh2_state->r[15] = RL(4);
2327   m_sh2_state->sr = I;
2328   m_sh2_state->sleep_mode = 0;
21852329
2186   sh2->ppc = sh2->pc = sh2->pr = sh2->sr = sh2->gbr = sh2->vbr = sh2->mach = sh2->macl = 0;
2187   sh2->evec = sh2->irqsr = 0;
2188   memset(&sh2->r[0], 0, sizeof(sh2->r[0])*16);
2189   sh2->ea = sh2->delay = sh2->cpu_off = sh2->dvsr = sh2->dvdnth = sh2->dvdntl = sh2->dvcr = 0;
2190   sh2->pending_irq = sh2->test_irq = 0;
2191   memset(&sh2->irq_queue[0], 0, sizeof(sh2->irq_queue[0])*16);
2192   memset(&sh2->irq_line_state[0], 0, sizeof(sh2->irq_line_state[0])*17);
2193   sh2->frc = sh2->ocra = sh2->ocrb = sh2->icr = 0;
2194   sh2->frc_base = 0;
2195   sh2->frt_input = sh2->internal_irq_level = sh2->internal_irq_vector = 0;
2196   sh2->dma_timer_active[0] = sh2->dma_timer_active[1] = 0;
2197   sh2->dma_irq[0] = sh2->dma_irq[1] = 0;
2330   m_sh2_state->internal_irq_level = -1;
21982331
2199   sh2->dma_callback_kludge = dma_callback_kludge;
2200   sh2->dma_callback_fifo_data_available = dma_callback_fifo_data_available;
2201   sh2->is_slave = save_is_slave;
2202   sh2->ftcsr_read_callback = f;
2203   sh2->irq_callback = save_irqcallback;
2204   sh2->device = device;
2205
2206   memset(sh2->m, 0, 0x200);
2207
2208   sh2->pc = RL(sh2, 0);
2209   sh2->r[15] = RL(sh2, 4);
2210   sh2->sr = I;
2211   sh2->sleep_mode = 0;
2212
2213   sh2->internal_irq_level = -1;
2332   m_cache_dirty = TRUE;
22142333}
22152334
2216/*-------------------------------------------------
2217    sh1_reset - reset the processor
2218-------------------------------------------------*/
22192335
2220static CPU_RESET( sh1 )
2221{
2222   sh2_state *sh2 = get_safe_token(device);
2223   CPU_RESET_CALL( sh2 );
2224   sh2->cpu_type = CPU_TYPE_SH1;
2225}
2226
22272336/* Execute cycles - returns number of cycles actually run */
2228static CPU_EXECUTE( sh2 )
2337void sh2_device::execute_run()
22292338{
2230   sh2_state *sh2 = get_safe_token(device);
2339   if ( m_isdrc )
2340   {
2341      execute_run_drc();
2342      return;
2343   }
22312344
2232   if (sh2->cpu_off)
2345   if (m_cpu_off)
22332346   {
2234      sh2->icount = 0;
2347      m_sh2_state->icount = 0;
22352348      return;
22362349   }
22372350
22382351   // run any active DMAs now
22392352#ifndef USE_TIMER_FOR_DMA
2240   for ( int i = 0; i < sh2->icount ; i++)
2353   for ( int i = 0; i < m_sh2_state->icount ; i++)
22412354   {
22422355      for( int dma=0;dma<1;dma++)
22432356      {
2244         if (sh2->dma_timer_active[dma])
2245            sh2_do_dma(sh2, dma);
2357         if (m_dma_timer_active[dma])
2358            sh2_do_dma(dma);
22462359      }
22472360   }
22482361#endif
r29565r29566
22512364   {
22522365      UINT32 opcode;
22532366
2254      if (sh2->delay)
2367      if (m_delay)
22552368      {
2256         opcode = sh2->program->read_word(((UINT32)(sh2->delay & AM)));
2257         sh2->pc -= 2;
2369         opcode = m_program->read_word(((UINT32)(m_delay & AM)));
2370         m_sh2_state->pc -= 2;
22582371      }
22592372      else
2260         opcode = sh2->program->read_word(((UINT32)(sh2->pc & AM)));
2373         opcode = m_program->read_word(((UINT32)(m_sh2_state->pc & AM)));
22612374
2262      debugger_instruction_hook(device, sh2->pc);
2375      debugger_instruction_hook(this, m_sh2_state->pc);
22632376
2264      sh2->delay = 0;
2265      sh2->pc += 2;
2266      sh2->ppc = sh2->pc;
2377      m_delay = 0;
2378      m_sh2_state->pc += 2;
2379      m_sh2_state->ppc = m_sh2_state->pc;
22672380
22682381      switch (opcode & ( 15 << 12))
22692382      {
2270      case  0<<12: op0000(sh2, opcode); break;
2271      case  1<<12: op0001(sh2, opcode); break;
2272      case  2<<12: op0010(sh2, opcode); break;
2273      case  3<<12: op0011(sh2, opcode); break;
2274      case  4<<12: op0100(sh2, opcode); break;
2275      case  5<<12: op0101(sh2, opcode); break;
2276      case  6<<12: op0110(sh2, opcode); break;
2277      case  7<<12: op0111(sh2, opcode); break;
2278      case  8<<12: op1000(sh2, opcode); break;
2279      case  9<<12: op1001(sh2, opcode); break;
2280      case 10<<12: op1010(sh2, opcode); break;
2281      case 11<<12: op1011(sh2, opcode); break;
2282      case 12<<12: op1100(sh2, opcode); break;
2283      case 13<<12: op1101(sh2, opcode); break;
2284      case 14<<12: op1110(sh2, opcode); break;
2285      default: op1111(sh2, opcode); break;
2383      case  0<<12: op0000(opcode); break;
2384      case  1<<12: op0001(opcode); break;
2385      case  2<<12: op0010(opcode); break;
2386      case  3<<12: op0011(opcode); break;
2387      case  4<<12: op0100(opcode); break;
2388      case  5<<12: op0101(opcode); break;
2389      case  6<<12: op0110(opcode); break;
2390      case  7<<12: op0111(opcode); break;
2391      case  8<<12: op1000(opcode); break;
2392      case  9<<12: op1001(opcode); break;
2393      case 10<<12: op1010(opcode); break;
2394      case 11<<12: op1011(opcode); break;
2395      case 12<<12: op1100(opcode); break;
2396      case 13<<12: op1101(opcode); break;
2397      case 14<<12: op1110(opcode); break;
2398      default: op1111(opcode); break;
22862399      }
22872400
2288      if(sh2->test_irq && !sh2->delay)
2401      if(m_test_irq && !m_delay)
22892402      {
22902403         CHECK_PENDING_IRQ("mame_sh2_execute");
2291         sh2->test_irq = 0;
2404         m_test_irq = 0;
22922405      }
2293      sh2->icount--;
2294   } while( sh2->icount > 0 );
2406      m_sh2_state->icount--;
2407   } while( m_sh2_state->icount > 0 );
22952408}
22962409
2297static CPU_INIT( sh2 )
2410void sh2_device::device_start()
22982411{
2299   sh2_state *sh2 = get_safe_token(device);
2412   /* allocate the implementation-specific state from the full cache */
2413   m_sh2_state = (internal_sh2_state *)m_cache.alloc_near(sizeof(internal_sh2_state));
23002414
2301   /* initialize the common core parts */
2302   sh2_common_init(sh2, device, irqcallback,false);
2303}
2415   m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_timer_callback), this));
2416   m_timer->adjust(attotime::never);
23042417
2305/**************************************************************************
2306 * Generic set_info
2307 **************************************************************************/
2418   m_dma_current_active_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_dma_current_active_callback), this));
2419   m_dma_current_active_timer[0]->adjust(attotime::never);
23082420
2309static CPU_SET_INFO( sh2 )
2310{
2311   sh2_state *sh2 = get_safe_token(device);
2312   switch (state)
2421   m_dma_current_active_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_dma_current_active_callback), this));
2422   m_dma_current_active_timer[1]->adjust(attotime::never);
2423
2424   m_is_slave = is_slave;
2425   m_dma_callback_kludge = dma_callback_kludge;
2426   m_dma_callback_fifo_data_available = dma_callback_fifo_data_available;
2427
2428   m_program = &space(AS_PROGRAM);
2429   m_direct = &m_program->direct();
2430   m_internal = &space(AS_PROGRAM);
2431
2432   save_item(NAME(m_sh2_state->pc));
2433   save_item(NAME(m_sh2_state->sr));
2434   save_item(NAME(m_sh2_state->pr));
2435   save_item(NAME(m_sh2_state->gbr));
2436   save_item(NAME(m_sh2_state->vbr));
2437   save_item(NAME(m_sh2_state->mach));
2438   save_item(NAME(m_sh2_state->macl));
2439   save_item(NAME(m_sh2_state->r));
2440   save_item(NAME(m_sh2_state->ea));
2441   save_item(NAME(m_delay));
2442   save_item(NAME(m_cpu_off));
2443   save_item(NAME(m_dvsr));
2444   save_item(NAME(m_dvdnth));
2445   save_item(NAME(m_dvdntl));
2446   save_item(NAME(m_dvcr));
2447   save_item(NAME(m_sh2_state->pending_irq));
2448   save_item(NAME(m_test_irq));
2449   save_item(NAME(m_sh2_state->pending_nmi));
2450   save_item(NAME(m_sh2_state->irqline));
2451   save_item(NAME(m_sh2_state->evec));
2452   save_item(NAME(m_sh2_state->irqsr));
2453   save_item(NAME(m_sh2_state->target));
2454   for (int i = 0; i < 16; ++i)
23132455   {
2314      /* --- the following bits of info are set as 64-bit signed integers --- */
2315      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLIN:   sh2_set_irq_line(sh2, SH2_INT_VBLIN, info->i);  break;
2316      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLOUT:  sh2_set_irq_line(sh2, SH2_INT_VBLOUT, info->i); break;
2317      case CPUINFO_INT_INPUT_STATE + SH2_INT_HBLIN:   sh2_set_irq_line(sh2, SH2_INT_HBLIN, info->i);  break;
2318      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER0:  sh2_set_irq_line(sh2, SH2_INT_TIMER0, info->i); break;
2319      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER1:  sh2_set_irq_line(sh2, SH2_INT_TIMER1, info->i); break;
2320      case CPUINFO_INT_INPUT_STATE + SH2_INT_DSP:     sh2_set_irq_line(sh2, SH2_INT_DSP, info->i);        break;
2321      case CPUINFO_INT_INPUT_STATE + SH2_INT_SOUND:   sh2_set_irq_line(sh2, SH2_INT_SOUND, info->i);  break;
2322      case CPUINFO_INT_INPUT_STATE + SH2_INT_SMPC:    sh2_set_irq_line(sh2, SH2_INT_SMPC, info->i);   break;
2323      case CPUINFO_INT_INPUT_STATE + SH2_INT_PAD:     sh2_set_irq_line(sh2, SH2_INT_PAD, info->i);        break;
2324      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA2:    sh2_set_irq_line(sh2, SH2_INT_DMA2, info->i);   break;
2325      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA1:    sh2_set_irq_line(sh2, SH2_INT_DMA1, info->i);   break;
2326      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA0:    sh2_set_irq_line(sh2, SH2_INT_DMA0, info->i);   break;
2327      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMAILL:  sh2_set_irq_line(sh2, SH2_INT_DMAILL, info->i); break;
2328      case CPUINFO_INT_INPUT_STATE + SH2_INT_SPRITE:  sh2_set_irq_line(sh2, SH2_INT_SPRITE, info->i); break;
2329      case CPUINFO_INT_INPUT_STATE + SH2_INT_14:      sh2_set_irq_line(sh2, SH2_INT_14, info->i);     break;
2330      case CPUINFO_INT_INPUT_STATE + SH2_INT_15:      sh2_set_irq_line(sh2, SH2_INT_15, info->i);     break;
2331      case CPUINFO_INT_INPUT_STATE + SH2_INT_ABUS:    sh2_set_irq_line(sh2, SH2_INT_ABUS, info->i);   break;
2332      case CPUINFO_INT_INPUT_STATE + INPUT_LINE_NMI:  sh2_set_irq_line(sh2, INPUT_LINE_NMI, info->i); break;
2333
2334      case CPUINFO_INT_REGISTER + SH2_PC:
2335      case CPUINFO_INT_PC:                            sh2->pc = info->i; sh2->delay = 0;      break;
2336      case CPUINFO_INT_SP:                            sh2->r[15] = info->i;                   break;
2337      case CPUINFO_INT_REGISTER + SH2_PR:             sh2->pr = info->i;                      break;
2338      case CPUINFO_INT_REGISTER + SH2_SR:             sh2->sr = info->i; CHECK_PENDING_IRQ("sh2_set_reg"); break;
2339      case CPUINFO_INT_REGISTER + SH2_GBR:            sh2->gbr = info->i;                     break;
2340      case CPUINFO_INT_REGISTER + SH2_VBR:            sh2->vbr = info->i;                     break;
2341      case CPUINFO_INT_REGISTER + SH2_MACH:           sh2->mach = info->i;                        break;
2342      case CPUINFO_INT_REGISTER + SH2_MACL:           sh2->macl = info->i;                        break;
2343      case CPUINFO_INT_REGISTER + SH2_R0:             sh2->r[ 0] = info->i;                   break;
2344      case CPUINFO_INT_REGISTER + SH2_R1:             sh2->r[ 1] = info->i;                   break;
2345      case CPUINFO_INT_REGISTER + SH2_R2:             sh2->r[ 2] = info->i;                   break;
2346      case CPUINFO_INT_REGISTER + SH2_R3:             sh2->r[ 3] = info->i;                   break;
2347      case CPUINFO_INT_REGISTER + SH2_R4:             sh2->r[ 4] = info->i;                   break;
2348      case CPUINFO_INT_REGISTER + SH2_R5:             sh2->r[ 5] = info->i;                   break;
2349      case CPUINFO_INT_REGISTER + SH2_R6:             sh2->r[ 6] = info->i;                   break;
2350      case CPUINFO_INT_REGISTER + SH2_R7:             sh2->r[ 7] = info->i;                   break;
2351      case CPUINFO_INT_REGISTER + SH2_R8:             sh2->r[ 8] = info->i;                   break;
2352      case CPUINFO_INT_REGISTER + SH2_R9:             sh2->r[ 9] = info->i;                   break;
2353      case CPUINFO_INT_REGISTER + SH2_R10:            sh2->r[10] = info->i;                   break;
2354      case CPUINFO_INT_REGISTER + SH2_R11:            sh2->r[11] = info->i;                   break;
2355      case CPUINFO_INT_REGISTER + SH2_R12:            sh2->r[12] = info->i;                   break;
2356      case CPUINFO_INT_REGISTER + SH2_R13:            sh2->r[13] = info->i;                   break;
2357      case CPUINFO_INT_REGISTER + SH2_R14:            sh2->r[14] = info->i;                   break;
2358      case CPUINFO_INT_REGISTER + SH2_R15:            sh2->r[15] = info->i;                   break;
2359      case CPUINFO_INT_REGISTER + SH2_EA:             sh2->ea = info->i;                      break;
2456      save_item(NAME(m_irq_queue[i].irq_vector), i);
2457      save_item(NAME(m_irq_queue[i].irq_priority), i);
23602458   }
2361}
2459   save_item(NAME(m_pcfsel));
2460   save_item(NAME(m_maxpcfsel));
2461   save_item(NAME(m_pcflushes));
2462   save_item(NAME(m_irq_line_state));
2463   save_item(NAME(m_m));
2464   save_item(NAME(m_nmi_line_state));
2465   save_item(NAME(m_frc));
2466   save_item(NAME(m_ocra));
2467   save_item(NAME(m_ocrb));
2468   save_item(NAME(m_icr));
2469   save_item(NAME(m_frc_base));
2470   save_item(NAME(m_frt_input));
2471   save_item(NAME(m_sh2_state->internal_irq_level));
2472   save_item(NAME(m_internal_irq_vector));
2473   save_item(NAME(m_dma_timer_active));
2474   save_item(NAME(m_dma_irq));
2475   save_item(NAME(m_wtcnt));
2476   save_item(NAME(m_wtcsr));
2477   save_item(NAME(m_sh2_state->sleep_mode));
23622478
2479   state_add( SH2_PC,   "PC",   m_debugger_temp).callimport().callexport().formatstr("%08X");
2480   state_add( SH2_SR,   "SR",   m_sh2_state->sr).callimport().formatstr("%08X");
2481   state_add( SH2_PR,   "PR",   m_sh2_state->pr).formatstr("%08X");
2482   state_add( SH2_GBR,  "GBR",  m_sh2_state->gbr).formatstr("%08X");
2483   state_add( SH2_VBR,  "VBR",  m_sh2_state->vbr).formatstr("%08X");
2484   state_add( SH2_MACH, "MACH", m_sh2_state->mach).formatstr("%08X");
2485   state_add( SH2_MACL, "MACL", m_sh2_state->macl).formatstr("%08X");
2486   state_add( SH2_R0,   "R0",   m_sh2_state->r[ 0]).formatstr("%08X");
2487   state_add( SH2_R1,   "R1",   m_sh2_state->r[ 1]).formatstr("%08X");
2488   state_add( SH2_R2,   "R2",   m_sh2_state->r[ 2]).formatstr("%08X");
2489   state_add( SH2_R3,   "R3",   m_sh2_state->r[ 3]).formatstr("%08X");
2490   state_add( SH2_R4,   "R4",   m_sh2_state->r[ 4]).formatstr("%08X");
2491   state_add( SH2_R5,   "R5",   m_sh2_state->r[ 5]).formatstr("%08X");
2492   state_add( SH2_R6,   "R6",   m_sh2_state->r[ 6]).formatstr("%08X");
2493   state_add( SH2_R7,   "R7",   m_sh2_state->r[ 7]).formatstr("%08X");
2494   state_add( SH2_R8,   "R8",   m_sh2_state->r[ 8]).formatstr("%08X");
2495   state_add( SH2_R9,   "R9",   m_sh2_state->r[ 9]).formatstr("%08X");
2496   state_add( SH2_R10,  "R10",  m_sh2_state->r[10]).formatstr("%08X");
2497   state_add( SH2_R11,  "R11",  m_sh2_state->r[11]).formatstr("%08X");
2498   state_add( SH2_R12,  "R12",  m_sh2_state->r[12]).formatstr("%08X");
2499   state_add( SH2_R13,  "R13",  m_sh2_state->r[13]).formatstr("%08X");
2500   state_add( SH2_R14,  "R14",  m_sh2_state->r[14]).formatstr("%08X");
2501   state_add( SH2_R15,  "R15",  m_sh2_state->r[15]).formatstr("%08X");
2502   state_add( SH2_EA,   "EA",   m_sh2_state->ea).formatstr("%08X");
23632503
2504   state_add( STATE_GENPC, "GENPC", m_sh2_state->pc ).noshow();
2505   state_add( STATE_GENSP, "GENSP", m_sh2_state->r[15] ).noshow();
2506   state_add( STATE_GENPCBASE, "GENPCBASE", m_sh2_state->ppc ).noshow();
2507   state_add( STATE_GENFLAGS, "GENFLAGS", m_sh2_state->sr ).formatstr("%6s").noshow();
23642508
2365/**************************************************************************
2366 * Generic get_info
2367 **************************************************************************/
2509   m_icountptr = &m_sh2_state->icount;
23682510
2369CPU_GET_INFO( sh2_int )
2370{
2371   sh2_state *sh2 = (device != NULL && device->token() != NULL) ? get_safe_token(device) : NULL;
2372   switch (state)
2511   // Clear state
2512   m_sh2_state->ppc = 0;
2513   m_sh2_state->pc = 0;
2514   m_sh2_state->pr = 0;
2515   m_sh2_state->sr = 0;
2516   m_sh2_state->gbr = 0;
2517   m_sh2_state->vbr = 0;
2518   m_sh2_state->mach = 0;
2519   m_sh2_state->macl = 0;
2520   memset(m_sh2_state->r, 0, sizeof(m_sh2_state->r));
2521   m_sh2_state->ea = 0;
2522   m_delay = 0;
2523   m_cpu_off = 0;
2524   m_dvsr = 0;
2525   m_dvdnth = 0;
2526   m_dvdntl = 0;
2527   m_dvcr = 0;
2528   m_sh2_state->pending_irq = 0;
2529   m_test_irq = 0;
2530   m_sh2_state->pending_nmi = 0;
2531   m_sh2_state->irqline = 0;
2532   m_sh2_state->evec = 0;
2533   m_sh2_state->irqsr = 0;
2534   m_sh2_state->target = 0;
2535   memset(m_irq_queue, 0, sizeof(m_irq_queue));
2536   m_maxpcfsel = 0;
2537   memset(m_pcflushes, 0, sizeof(m_pcflushes));
2538   memset(m_irq_line_state, 0, sizeof(m_irq_line_state));
2539   memset(m_m, 0, sizeof(m_m));
2540   m_nmi_line_state = 0;
2541   m_frc = 0;
2542   m_ocra = 0;
2543   m_ocrb = 0;
2544   m_icr = 0;
2545   m_frc_base = 0;
2546   m_frt_input = 0;
2547   m_sh2_state->internal_irq_level = 0;
2548   m_internal_irq_vector = 0;
2549   m_sh2_state->icount = 0;
2550   for ( int i = 0; i < 2; i++ )
23732551   {
2374      /* --- the following bits of info are returned as 64-bit signed integers --- */
2375      case CPUINFO_INT_CONTEXT_SIZE:                  info->i = sizeof(sh2_state);            break;
2376      case CPUINFO_INT_INPUT_LINES:                   info->i = 16;                           break;
2377      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:            info->i = 0;                            break;
2378      case CPUINFO_INT_ENDIANNESS:                    info->i = ENDIANNESS_BIG;                   break;
2379      case CPUINFO_INT_CLOCK_MULTIPLIER:              info->i = 1;                            break;
2380      case CPUINFO_INT_CLOCK_DIVIDER:                 info->i = 1;                            break;
2381      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 2;                            break;
2382      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 2;                            break;
2383      case CPUINFO_INT_MIN_CYCLES:                    info->i = 1;                            break;
2384      case CPUINFO_INT_MAX_CYCLES:                    info->i = 4;                            break;
2552      m_dma_timer_active[i] = 0;
2553      m_dma_irq[i] = 0;
2554      m_active_dma_incs[i] = 0;
2555      m_active_dma_incd[i] = 0;
2556      m_active_dma_size[i] = 0;
2557      m_active_dma_steal[i] = 0;
2558      m_active_dma_src[i] = 0;
2559      m_active_dma_dst[i] = 0;
2560      m_active_dma_count[i] = 0;
2561   }
2562   m_wtcnt = 0;
2563   m_wtcsr = 0;
2564   m_sh2_state->sleep_mode = 0;
2565   m_numcycles = 0;
2566   m_sh2_state->arg0 = 0;
2567   m_arg1 = 0;
2568   m_irq = 0;
2569   m_fastram_select = 0;
2570   memset(m_fastram, 0, sizeof(m_fastram));
23852571
2386      case CPUINFO_INT_DATABUS_WIDTH + AS_PROGRAM:    info->i = 32;                   break;
2387      case CPUINFO_INT_ADDRBUS_WIDTH + AS_PROGRAM: info->i = 32;                  break;
2388      case CPUINFO_INT_ADDRBUS_SHIFT + AS_PROGRAM: info->i = 0;                   break;
2389      case CPUINFO_INT_DATABUS_WIDTH + AS_DATA:   info->i = 0;                    break;
2390      case CPUINFO_INT_ADDRBUS_WIDTH + AS_DATA:   info->i = 0;                    break;
2391      case CPUINFO_INT_ADDRBUS_SHIFT + AS_DATA:   info->i = 0;                    break;
2392      case CPUINFO_INT_DATABUS_WIDTH + AS_IO:     info->i = 0;                    break;
2393      case CPUINFO_INT_ADDRBUS_WIDTH + AS_IO:     info->i = 0;                    break;
2394      case CPUINFO_INT_ADDRBUS_SHIFT + AS_IO:     info->i = 0;                    break;
2572   /* reset per-driver pcflushes */
2573   m_pcfsel = 0;
23952574
2396      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLIN:   info->i = sh2->irq_line_state[SH2_INT_VBLIN]; break;
2397      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLOUT:  info->i = sh2->irq_line_state[SH2_INT_VBLOUT]; break;
2398      case CPUINFO_INT_INPUT_STATE + SH2_INT_HBLIN:   info->i = sh2->irq_line_state[SH2_INT_HBLIN]; break;
2399      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER0:  info->i = sh2->irq_line_state[SH2_INT_TIMER0]; break;
2400      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER1:  info->i = sh2->irq_line_state[SH2_INT_TIMER1]; break;
2401      case CPUINFO_INT_INPUT_STATE + SH2_INT_DSP:     info->i = sh2->irq_line_state[SH2_INT_DSP]; break;
2402      case CPUINFO_INT_INPUT_STATE + SH2_INT_SOUND:   info->i = sh2->irq_line_state[SH2_INT_SOUND]; break;
2403      case CPUINFO_INT_INPUT_STATE + SH2_INT_SMPC:    info->i = sh2->irq_line_state[SH2_INT_SMPC];    break;
2404      case CPUINFO_INT_INPUT_STATE + SH2_INT_PAD:     info->i = sh2->irq_line_state[SH2_INT_PAD]; break;
2405      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA2:    info->i = sh2->irq_line_state[SH2_INT_DMA2];    break;
2406      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA1:    info->i = sh2->irq_line_state[SH2_INT_DMA1];    break;
2407      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA0:    info->i = sh2->irq_line_state[SH2_INT_DMA0];    break;
2408      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMAILL:  info->i = sh2->irq_line_state[SH2_INT_DMAILL]; break;
2409      case CPUINFO_INT_INPUT_STATE + SH2_INT_SPRITE:  info->i = sh2->irq_line_state[SH2_INT_SPRITE]; break;
2410      case CPUINFO_INT_INPUT_STATE + SH2_INT_14:      info->i = sh2->irq_line_state[SH2_INT_14]; break;
2411      case CPUINFO_INT_INPUT_STATE + SH2_INT_15:      info->i = sh2->irq_line_state[SH2_INT_15]; break;
2412      case CPUINFO_INT_INPUT_STATE + SH2_INT_ABUS:    info->i = sh2->irq_line_state[SH2_INT_ABUS];    break;
2413      case CPUINFO_INT_INPUT_STATE + INPUT_LINE_NMI:  info->i = sh2->nmi_line_state;          break;
2575   /* initialize the UML generator */
2576   UINT32 flags = 0;
2577   if (LOG_UML)
2578      flags |= DRCUML_OPTION_LOG_UML;
2579   if (LOG_NATIVE)
2580      flags |= DRCUML_OPTION_LOG_NATIVE;
2581   m_drcuml = auto_alloc(machine(), drcuml_state(*this, m_cache, flags, 1, 32, 1));
24142582
2415      case CPUINFO_INT_PREVIOUSPC:                    info->i = sh2->ppc;                     break;
2583   /* add symbols for our stuff */
2584   m_drcuml->symbol_add(&m_sh2_state->pc, sizeof(m_sh2_state->pc), "pc");
2585   m_drcuml->symbol_add(&m_sh2_state->icount, sizeof(m_sh2_state->icount), "icount");
2586   for (int regnum = 0; regnum < 16; regnum++)
2587   {
2588      char buf[10];
2589      sprintf(buf, "r%d", regnum);
2590      m_drcuml->symbol_add(&m_sh2_state->r[regnum], sizeof(m_sh2_state->r[regnum]), buf);
2591   }
2592   m_drcuml->symbol_add(&m_sh2_state->pr, sizeof(m_sh2_state->pr), "pr");
2593   m_drcuml->symbol_add(&m_sh2_state->sr, sizeof(m_sh2_state->sr), "sr");
2594   m_drcuml->symbol_add(&m_sh2_state->gbr, sizeof(m_sh2_state->gbr), "gbr");
2595   m_drcuml->symbol_add(&m_sh2_state->vbr, sizeof(m_sh2_state->vbr), "vbr");
2596   m_drcuml->symbol_add(&m_sh2_state->macl, sizeof(m_sh2_state->macl), "macl");
2597   m_drcuml->symbol_add(&m_sh2_state->mach, sizeof(m_sh2_state->macl), "mach");
24162598
2417      case CPUINFO_INT_PC:
2418      case CPUINFO_INT_REGISTER + SH2_PC:             info->i = (sh2->delay) ? (sh2->delay & AM) : (sh2->pc & AM); break;
2419      case CPUINFO_INT_SP:                            info->i = sh2->r[15];                   break;
2420      case CPUINFO_INT_REGISTER + SH2_PR:             info->i = sh2->pr;                      break;
2421      case CPUINFO_INT_REGISTER + SH2_SR:             info->i = sh2->sr;                      break;
2422      case CPUINFO_INT_REGISTER + SH2_GBR:            info->i = sh2->gbr;                     break;
2423      case CPUINFO_INT_REGISTER + SH2_VBR:            info->i = sh2->vbr;                     break;
2424      case CPUINFO_INT_REGISTER + SH2_MACH:           info->i = sh2->mach;                        break;
2425      case CPUINFO_INT_REGISTER + SH2_MACL:           info->i = sh2->macl;                        break;
2426      case CPUINFO_INT_REGISTER + SH2_R0:             info->i = sh2->r[ 0];                   break;
2427      case CPUINFO_INT_REGISTER + SH2_R1:             info->i = sh2->r[ 1];                   break;
2428      case CPUINFO_INT_REGISTER + SH2_R2:             info->i = sh2->r[ 2];                   break;
2429      case CPUINFO_INT_REGISTER + SH2_R3:             info->i = sh2->r[ 3];                   break;
2430      case CPUINFO_INT_REGISTER + SH2_R4:             info->i = sh2->r[ 4];                   break;
2431      case CPUINFO_INT_REGISTER + SH2_R5:             info->i = sh2->r[ 5];                   break;
2432      case CPUINFO_INT_REGISTER + SH2_R6:             info->i = sh2->r[ 6];                   break;
2433      case CPUINFO_INT_REGISTER + SH2_R7:             info->i = sh2->r[ 7];                   break;
2434      case CPUINFO_INT_REGISTER + SH2_R8:             info->i = sh2->r[ 8];                   break;
2435      case CPUINFO_INT_REGISTER + SH2_R9:             info->i = sh2->r[ 9];                   break;
2436      case CPUINFO_INT_REGISTER + SH2_R10:            info->i = sh2->r[10];                   break;
2437      case CPUINFO_INT_REGISTER + SH2_R11:            info->i = sh2->r[11];                   break;
2438      case CPUINFO_INT_REGISTER + SH2_R12:            info->i = sh2->r[12];                   break;
2439      case CPUINFO_INT_REGISTER + SH2_R13:            info->i = sh2->r[13];                   break;
2440      case CPUINFO_INT_REGISTER + SH2_R14:            info->i = sh2->r[14];                   break;
2441      case CPUINFO_INT_REGISTER + SH2_R15:            info->i = sh2->r[15];                   break;
2442      case CPUINFO_INT_REGISTER + SH2_EA:             info->i = sh2->ea;                      break;
2599   /* initialize the front-end helper */
2600   m_drcfe = auto_alloc(machine(), sh2_frontend(this, COMPILE_BACKWARDS_BYTES, COMPILE_FORWARDS_BYTES, SINGLE_INSTRUCTION_MODE ? 1 : COMPILE_MAX_SEQUENCE));
24432601
2444      /* --- the following bits of info are returned as pointers to data or functions --- */
2445      case CPUINFO_FCT_SET_INFO:                      info->setinfo = CPU_SET_INFO_NAME(sh2);         break;
2446      case CPUINFO_FCT_INIT:                          info->init = CPU_INIT_NAME(sh2);                    break;
2447      case CPUINFO_FCT_RESET:                         info->reset = CPU_RESET_NAME(sh2);              break;
2448      case CPUINFO_FCT_EXECUTE:                       info->execute = CPU_EXECUTE_NAME(sh2);          break;
2449      case CPUINFO_FCT_BURN:                          info->burn = NULL;                      break;
2450      case CPUINFO_FCT_DISASSEMBLE:                   info->disassemble = CPU_DISASSEMBLE_NAME(sh2);          break;
2451      case CPUINFO_PTR_INSTRUCTION_COUNTER:           info->icount = &sh2->icount;                break;
2602    /* compute the register parameters */
2603    for (int regnum = 0; regnum < 16; regnum++)
2604    {
2605        m_regmap[regnum] = uml::mem(&m_sh2_state->r[regnum]);
2606    }
24522607
2453      /* --- the following bits of info are returned as NULL-terminated strings --- */
2454      case CPUINFO_STR_NAME:                          strcpy(info->s, "SH-2");                break;
2455      case CPUINFO_STR_SHORTNAME:                     strcpy(info->s, "sh2");                break;
2456      case CPUINFO_STR_FAMILY:                    strcpy(info->s, "Hitachi SH7600");      break;
2457      case CPUINFO_STR_VERSION:                   strcpy(info->s, "1.01");                break;
2458      case CPUINFO_STR_SOURCE_FILE:                       strcpy(info->s, __FILE__);              break;
2459      case CPUINFO_STR_CREDITS:                   strcpy(info->s, "Copyright Juergen Buchmueller, all rights reserved."); break;
2608   /* if we have registers to spare, assign r0, r1, r2 to leftovers */
2609   /* WARNING: do not use synthetic registers that are mapped here! */
2610   if (!DISABLE_FAST_REGISTERS)
2611   {
2612      drcbe_info beinfo;
2613      m_drcuml->get_backend_info(beinfo);
2614      if (beinfo.direct_iregs > 4)
2615      {
2616         m_regmap[0] = uml::I4;
2617      }
2618      if (beinfo.direct_iregs > 5)
2619      {
2620         m_regmap[1] = uml::I5;
2621      }
2622      if (beinfo.direct_iregs > 6)
2623      {
2624         m_regmap[2] = uml::I6;
2625      }
2626   }
24602627
2461      case CPUINFO_STR_FLAGS:
2462         sprintf(info->s, "%c%c%d%c%c",
2463               sh2->sr & M ? 'M':'.',
2464               sh2->sr & Q ? 'Q':'.',
2465               (sh2->sr & I) >> 4,
2466               sh2->sr & S ? 'S':'.',
2467               sh2->sr & T ? 'T':'.');
2628   /* mark the cache dirty so it is updated on next execute */
2629   m_cache_dirty = TRUE;
2630}
2631
2632
2633void sh2_device::state_string_export(const device_state_entry &entry, astring &string)
2634{
2635   switch (entry.index())
2636   {
2637      case STATE_GENFLAGS:
2638         string.printf("%c%c%d%c%c",
2639               m_sh2_state->sr & M ? 'M':'.',
2640               m_sh2_state->sr & Q ? 'Q':'.',
2641               (m_sh2_state->sr & I) >> 4,
2642               m_sh2_state->sr & S ? 'S':'.',
2643               m_sh2_state->sr & T ? 'T':'.');
24682644         break;
2645   }
2646}
24692647
2470      case CPUINFO_STR_REGISTER + SH2_PC:             sprintf(info->s, "PC  :%08X", sh2->pc); break;
2471      case CPUINFO_STR_REGISTER + SH2_SR:             sprintf(info->s, "SR  :%08X", sh2->sr); break;
2472      case CPUINFO_STR_REGISTER + SH2_PR:             sprintf(info->s, "PR  :%08X", sh2->pr); break;
2473      case CPUINFO_STR_REGISTER + SH2_GBR:            sprintf(info->s, "GBR :%08X", sh2->gbr); break;
2474      case CPUINFO_STR_REGISTER + SH2_VBR:            sprintf(info->s, "VBR :%08X", sh2->vbr); break;
2475      case CPUINFO_STR_REGISTER + SH2_MACH:           sprintf(info->s, "MACH:%08X", sh2->mach); break;
2476      case CPUINFO_STR_REGISTER + SH2_MACL:           sprintf(info->s, "MACL:%08X", sh2->macl); break;
2477      case CPUINFO_STR_REGISTER + SH2_R0:             sprintf(info->s, "R0  :%08X", sh2->r[ 0]); break;
2478      case CPUINFO_STR_REGISTER + SH2_R1:             sprintf(info->s, "R1  :%08X", sh2->r[ 1]); break;
2479      case CPUINFO_STR_REGISTER + SH2_R2:             sprintf(info->s, "R2  :%08X", sh2->r[ 2]); break;
2480      case CPUINFO_STR_REGISTER + SH2_R3:             sprintf(info->s, "R3  :%08X", sh2->r[ 3]); break;
2481      case CPUINFO_STR_REGISTER + SH2_R4:             sprintf(info->s, "R4  :%08X", sh2->r[ 4]); break;
2482      case CPUINFO_STR_REGISTER + SH2_R5:             sprintf(info->s, "R5  :%08X", sh2->r[ 5]); break;
2483      case CPUINFO_STR_REGISTER + SH2_R6:             sprintf(info->s, "R6  :%08X", sh2->r[ 6]); break;
2484      case CPUINFO_STR_REGISTER + SH2_R7:             sprintf(info->s, "R7  :%08X", sh2->r[ 7]); break;
2485      case CPUINFO_STR_REGISTER + SH2_R8:             sprintf(info->s, "R8  :%08X", sh2->r[ 8]); break;
2486      case CPUINFO_STR_REGISTER + SH2_R9:             sprintf(info->s, "R9  :%08X", sh2->r[ 9]); break;
2487      case CPUINFO_STR_REGISTER + SH2_R10:            sprintf(info->s, "R10 :%08X", sh2->r[10]); break;
2488      case CPUINFO_STR_REGISTER + SH2_R11:            sprintf(info->s, "R11 :%08X", sh2->r[11]); break;
2489      case CPUINFO_STR_REGISTER + SH2_R12:            sprintf(info->s, "R12 :%08X", sh2->r[12]); break;
2490      case CPUINFO_STR_REGISTER + SH2_R13:            sprintf(info->s, "R13 :%08X", sh2->r[13]); break;
2491      case CPUINFO_STR_REGISTER + SH2_R14:            sprintf(info->s, "R14 :%08X", sh2->r[14]); break;
2492      case CPUINFO_STR_REGISTER + SH2_R15:            sprintf(info->s, "R15 :%08X", sh2->r[15]); break;
2493      case CPUINFO_STR_REGISTER + SH2_EA:             sprintf(info->s, "EA  :%08X", sh2->ea);    break;
24942648
2649void sh2_device::state_import(const device_state_entry &entry)
2650{
2651   switch (entry.index())
2652   {
2653      case SH2_PC:
2654         m_sh2_state->pc = m_debugger_temp;
2655         m_delay = 0;
2656         break;
2657
2658      case SH2_SR:
2659         CHECK_PENDING_IRQ("sh2_set_reg");
2660         break;
24952661   }
24962662}
24972663
2498CPU_GET_INFO( sh1_int )
2664
2665void sh2_device::state_export(const device_state_entry &entry)
24992666{
2500   switch (state)
2667   switch (entry.index())
25012668   {
2502      /* --- the following bits of info are returned as pointers to data or functions --- */
2503      case CPUINFO_FCT_RESET:                     info->reset = CPU_RESET_NAME(sh1);              break;
2669      case SH2_PC:
2670         m_debugger_temp = (m_delay) ? (m_delay & AM) : (m_sh2_state->pc & AM);
2671         break;
2672   }
2673}
25042674
2505      /* --- the following bits of info are returned as NULL-terminated strings --- */
2506      case CPUINFO_STR_NAME:                          strcpy(info->s, "SH-1");                break;
2507      case CPUINFO_STR_SHORTNAME:                     strcpy(info->s, "sh1");                break;
25082675
2509      default:                            CPU_GET_INFO_CALL(sh2_int);         break;
2676void sh2_device::execute_set_input(int irqline, int state)
2677{
2678   if (irqline == INPUT_LINE_NMI)
2679   {
2680      if (m_nmi_line_state == state)
2681         return;
2682      m_nmi_line_state = state;
2683
2684      if( state == CLEAR_LINE )
2685      {
2686         LOG(("SH-2 '%s' cleared nmi\n", tag()));
2687      }
2688      else
2689      {
2690         LOG(("SH-2 '%s' assert nmi\n", tag()));
2691
2692         sh2_exception("Set IRQ line", 16);
2693
2694         if (m_isdrc)
2695            m_sh2_state->pending_nmi = 1;
2696      }
25102697   }
2698   else
2699   {
2700      if (m_irq_line_state[irqline] == state)
2701         return;
2702      m_irq_line_state[irqline] = state;
2703
2704      if( state == CLEAR_LINE )
2705      {
2706         LOG(("SH-2 '%s' cleared irq #%d\n", tag(), irqline));
2707         m_sh2_state->pending_irq &= ~(1 << irqline);
2708      }
2709      else
2710      {
2711         LOG(("SH-2 '%s' assert irq #%d\n", tag(), irqline));
2712         m_sh2_state->pending_irq |= 1 << irqline;
2713         if (m_isdrc)
2714         {
2715            m_test_irq = 1;
2716         } else {
2717            if(m_delay)
2718               m_test_irq = 1;
2719            else
2720               CHECK_PENDING_IRQ("sh2_set_irq_line");
2721         }
2722      }
2723   }
25112724}
25122725
2513DEFINE_LEGACY_CPU_DEVICE(SH1_INT, sh1_int);
2514DEFINE_LEGACY_CPU_DEVICE(SH2_INT, sh2_int);
2726#include "sh2comn.c"
2727#include "sh2drc.c"
25152728
2516
2517const device_type SH1 = &legacy_device_creator_drc<sh1_int_device, sh1_drc_device>;
2518const device_type SH2 = &legacy_device_creator_drc<sh2_int_device, sh2_drc_device>;
trunk/src/emu/cpu/sh2/sh2comn.h
r29565r29566
1616// do we use a timer for the DMA, or have it in CPU_EXECUTE
1717#define USE_TIMER_FOR_DMA
1818
19#include "cpu/drcfe.h"
2019#include "cpu/drcuml.h"
2120#include "cpu/drcumlsh.h"
22class sh2_frontend;
2321
2422#define SH2_CODE_XOR(a)     ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(2,0))
2523
26struct irq_entry
27{
28   int irq_vector;
29   int irq_priority;
30};
31
3224enum
3325{
3426   ICF  = 0x00800000,
r29565r29566
6658#define CHECK_PENDING_IRQ(message)              \
6759do {                                            \
6860   int irq = -1;                               \
69   if (sh2->pending_irq & (1 <<  0)) irq = 0;  \
70   if (sh2->pending_irq & (1 <<  1)) irq = 1;  \
71   if (sh2->pending_irq & (1 <<  2)) irq = 2;  \
72   if (sh2->pending_irq & (1 <<  3)) irq = 3;  \
73   if (sh2->pending_irq & (1 <<  4)) irq = 4;  \
74   if (sh2->pending_irq & (1 <<  5)) irq = 5;  \
75   if (sh2->pending_irq & (1 <<  6)) irq = 6;  \
76   if (sh2->pending_irq & (1 <<  7)) irq = 7;  \
77   if (sh2->pending_irq & (1 <<  8)) irq = 8;  \
78   if (sh2->pending_irq & (1 <<  9)) irq = 9;  \
79   if (sh2->pending_irq & (1 << 10)) irq = 10; \
80   if (sh2->pending_irq & (1 << 11)) irq = 11; \
81   if (sh2->pending_irq & (1 << 12)) irq = 12; \
82   if (sh2->pending_irq & (1 << 13)) irq = 13; \
83   if (sh2->pending_irq & (1 << 14)) irq = 14; \
84   if (sh2->pending_irq & (1 << 15)) irq = 15; \
85   if ((sh2->internal_irq_level != -1) && (sh2->internal_irq_level > irq)) irq = sh2->internal_irq_level; \
61   if (m_sh2_state->pending_irq & (1 <<  0)) irq = 0;  \
62   if (m_sh2_state->pending_irq & (1 <<  1)) irq = 1;  \
63   if (m_sh2_state->pending_irq & (1 <<  2)) irq = 2;  \
64   if (m_sh2_state->pending_irq & (1 <<  3)) irq = 3;  \
65   if (m_sh2_state->pending_irq & (1 <<  4)) irq = 4;  \
66   if (m_sh2_state->pending_irq & (1 <<  5)) irq = 5;  \
67   if (m_sh2_state->pending_irq & (1 <<  6)) irq = 6;  \
68   if (m_sh2_state->pending_irq & (1 <<  7)) irq = 7;  \
69   if (m_sh2_state->pending_irq & (1 <<  8)) irq = 8;  \
70   if (m_sh2_state->pending_irq & (1 <<  9)) irq = 9;  \
71   if (m_sh2_state->pending_irq & (1 << 10)) irq = 10; \
72   if (m_sh2_state->pending_irq & (1 << 11)) irq = 11; \
73   if (m_sh2_state->pending_irq & (1 << 12)) irq = 12; \
74   if (m_sh2_state->pending_irq & (1 << 13)) irq = 13; \
75   if (m_sh2_state->pending_irq & (1 << 14)) irq = 14; \
76   if (m_sh2_state->pending_irq & (1 << 15)) irq = 15; \
77   if ((m_sh2_state->internal_irq_level != -1) && (m_sh2_state->internal_irq_level > irq)) irq = m_sh2_state->internal_irq_level; \
8678   if (irq >= 0)                               \
87      sh2_exception(sh2,message,irq);         \
79      sh2_exception(message,irq);         \
8880} while(0)
8981
90/* fast RAM info */
91struct fast_ram_info
92{
93   offs_t              start;                      /* start of the RAM block */
94   offs_t              end;                        /* end of the RAM block */
95   UINT8               readonly;                   /* TRUE if read-only */
96   void *              base;                       /* base in memory where the RAM lives */
97};
9882
99struct sh2_state
100{
101   UINT32  ppc;
102   UINT32  pc;
103   UINT32  pr;
104   UINT32  sr;
105   UINT32  gbr, vbr;
106   UINT32  mach, macl;
107   UINT32  r[16];
108   UINT32  ea;
109   UINT32  delay;
110   UINT32  cpu_off;
111   UINT32  dvsr, dvdnth, dvdntl, dvcr;
112   UINT32  pending_irq;
113   UINT32  test_irq;
114   UINT32  pending_nmi;
115   INT32  irqline;
116   UINT32  evec;               // exception vector for DRC
117   UINT32  irqsr;              // IRQ-time old SR for DRC
118   UINT32 target;              // target for jmp/jsr/etc so the delay slot can't kill it
119   irq_entry     irq_queue[16];
120
121   bool isdrc;
122
123   int pcfsel;                 // last pcflush entry set
124   int maxpcfsel;              // highest valid pcflush entry
125   UINT32 pcflushes[16];           // pcflush entries
126
127   INT8    irq_line_state[17];
128   device_irq_acknowledge_callback irq_callback;
129   legacy_cpu_device *device;
130   address_space *program;
131   direct_read_data *direct;
132   address_space *internal;
133   UINT32 m[0x200/4];
134   INT8  nmi_line_state;
135
136   UINT16  frc;
137   UINT16  ocra, ocrb, icr;
138   UINT64  frc_base;
139
140   int     frt_input;
141   int     internal_irq_level;
142   int     internal_irq_vector;
143   int             icount;
144
145   emu_timer *timer;
146   emu_timer *dma_current_active_timer[2];
147   int     dma_timer_active[2];
148   UINT8  dma_irq[2];
149
150   int active_dma_incs[2];
151   int active_dma_incd[2];
152   int active_dma_size[2];
153   int active_dma_steal[2];
154   UINT32 active_dma_src[2];
155   UINT32 active_dma_dst[2];
156   UINT32 active_dma_count[2];
157   UINT16 wtcnt;
158   UINT8 wtcsr;
159
160   UINT8 sleep_mode;
161
162   int     is_slave, cpu_type;
163   int  (*dma_callback_kludge)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
164   int  (*dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
165
166   void    (*ftcsr_read_callback)(UINT32 data);
167
168   drc_cache *         cache;                  /* pointer to the DRC code cache */
169   drcuml_state *      drcuml;                 /* DRC UML generator state */
170   sh2_frontend *      drcfe;                  /* pointer to the DRC front-end state */
171   UINT32              drcoptions;         /* configurable DRC options */
172
173   /* internal stuff */
174   UINT8               cache_dirty;                /* true if we need to flush the cache */
175
176   /* parameters for subroutines */
177   UINT64              numcycles;              /* return value from gettotalcycles */
178   UINT32              arg0;                   /* print_debug argument 1 */
179   UINT32              arg1;                   /* print_debug argument 2 */
180   UINT32              irq;                /* irq we're taking */
181
182   /* register mappings */
183   uml::parameter      regmap[16];                 /* parameter to register mappings for all 16 integer registers */
184
185   uml::code_handle *  entry;                      /* entry point */
186   uml::code_handle *  read8;                  /* read byte */
187   uml::code_handle *  write8;                 /* write byte */
188   uml::code_handle *  read16;                 /* read half */
189   uml::code_handle *  write16;                    /* write half */
190   uml::code_handle *  read32;                 /* read word */
191   uml::code_handle *  write32;                    /* write word */
192
193   uml::code_handle *  interrupt;              /* interrupt */
194   uml::code_handle *  nocode;                 /* nocode */
195   uml::code_handle *  out_of_cycles;              /* out of cycles exception handler */
196
197   /* fast RAM */
198   UINT32              fastram_select;
199   fast_ram_info       fastram[SH2_MAX_FASTRAM];
200};
201
202class sh2_frontend : public drc_frontend
203{
204public:
205   sh2_frontend(sh2_state &state, UINT32 window_start, UINT32 window_end, UINT32 max_sequence);
206
207protected:
208   virtual bool describe(opcode_desc &desc, const opcode_desc *prev);
209
210private:
211   bool describe_group_0(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
212   bool describe_group_2(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
213   bool describe_group_3(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
214   bool describe_group_4(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
215   bool describe_group_6(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
216   bool describe_group_8(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
217   bool describe_group_12(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
218
219   sh2_state &m_context;
220};
221
222void sh2_common_init(sh2_state *sh2, legacy_cpu_device *device, device_irq_acknowledge_callback irqcallback, bool drc);
223void sh2_recalc_irq(sh2_state *sh2);
224void sh2_set_irq_line(sh2_state *sh2, int irqline, int state);
225void sh2_exception(sh2_state *sh2, const char *message, int irqline);
226void sh2_do_dma(sh2_state *sh2, int dma);
227void sh2_notify_dma_data_available(device_t *device);
228
22983#endif /* __SH2COMN_H__ */
trunk/src/emu/cpu/sh2/sh2.h
r29565r29566
3030#ifndef __SH2_H__
3131#define __SH2_H__
3232
33#include "cpu/drcfe.h"
34#include "cpu/drcuml.h"
3335
36
3437#define SH2_INT_NONE    -1
3538#define SH2_INT_VBLIN   0
3639#define SH2_INT_VBLOUT  1
r29565r29566
6467   int  (*dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
6568};
6669
67DECLARE_LEGACY_CPU_DEVICE(SH1_INT, sh1_int);
68DECLARE_LEGACY_CPU_DEVICE(SH2_INT, sh2_int);
69DECLARE_LEGACY_CPU_DEVICE(SH1_DRC, sh1_drc);
70DECLARE_LEGACY_CPU_DEVICE(SH2_DRC, sh2_drc);
7170
72extern const device_type SH1;
73extern const device_type SH2;
74
75DECLARE_WRITE32_HANDLER( sh2_internal_w );
76DECLARE_READ32_HANDLER( sh2_internal_r );
77
78void sh2_set_ftcsr_read_callback(device_t *device, void (*callback)(UINT32));
79void sh2_set_frt_input(device_t *device, int state);
80
8171/***************************************************************************
8272    COMPILER-SPECIFIC OPTIONS
8373***************************************************************************/
r29565r29566
10393
10494#define SH2_MAX_FASTRAM       4
10595
106void sh2drc_set_options(device_t *device, UINT32 options);
107void sh2drc_add_pcflush(device_t *device, offs_t address);
108void sh2drc_add_fastram(device_t *device, offs_t start, offs_t end, UINT8 readonly, void *base);
96class sh2_frontend;
10997
98class sh2_device : public cpu_device
99            , public sh2_cpu_core
100{
101   friend class sh2_frontend;
102
103public:
104   // construction/destruction
105   sh2_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock);
106   sh2_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source, int cpu_type);
107
108   DECLARE_WRITE32_MEMBER( sh2_internal_w );
109   DECLARE_READ32_MEMBER( sh2_internal_r );
110   DECLARE_READ32_MEMBER(sh2_internal_a5);
111
112   void sh2_set_ftcsr_read_callback(void (*callback)(UINT32));
113   void sh2_set_frt_input(int state);
114   void sh2drc_set_options(UINT32 options);
115   void sh2drc_add_pcflush(offs_t address);
116   void sh2drc_add_fastram(offs_t start, offs_t end, UINT8 readonly, void *base);
117
118   void sh2_notify_dma_data_available();
119
120protected:
121   // device-level overrides
122   virtual void device_config_complete();
123   virtual void device_start();
124   virtual void device_reset();
125   virtual void device_stop();
126
127   // device_execute_interface overrides
128   virtual UINT32 execute_min_cycles() const { return 1; }
129   virtual UINT32 execute_max_cycles() const { return 4; }
130   virtual UINT32 execute_input_lines() const { return 16; }
131   virtual UINT32 execute_default_irq_vector() const { return 0; }
132   virtual void execute_run();
133   virtual void execute_set_input(int inputnum, int state);
134
135   // device_memory_interface overrides
136   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; }
137
138   // device_state_interface overrides
139   virtual void state_import(const device_state_entry &entry);
140   virtual void state_export(const device_state_entry &entry);
141   void state_string_export(const device_state_entry &entry, astring &string);
142
143   // device_disasm_interface overrides
144   virtual UINT32 disasm_min_opcode_bytes() const { return 2; }
145   virtual UINT32 disasm_max_opcode_bytes() const { return 2; }
146   virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
147
148private:
149   address_space_config m_program_config;
150
151   // Data that needs to be stored close to the generated DRC code
152   struct internal_sh2_state
153   {
154      UINT32  ppc;
155      UINT32  pc;
156      UINT32  pr;
157      UINT32  sr;
158      UINT32  gbr;
159      UINT32  vbr;
160      UINT32  mach;
161      UINT32  macl;
162      UINT32  r[16];
163      UINT32  ea;
164      UINT32  pending_irq;
165      UINT32  pending_nmi;
166      INT32   irqline;
167      UINT32  evec;               // exception vector for DRC
168      UINT32  irqsr;              // IRQ-time old SR for DRC
169      UINT32  target;             // target for jmp/jsr/etc so the delay slot can't kill it
170      int     internal_irq_level;
171      int     icount;
172      UINT8   sleep_mode;
173      UINT32  arg0;              /* print_debug argument 1 */
174   };
175
176   UINT32  m_delay;
177   UINT32  m_cpu_off;
178   UINT32  m_dvsr, m_dvdnth, m_dvdntl, m_dvcr;
179   UINT32  m_test_irq;
180   struct
181   {
182      int irq_vector;
183      int irq_priority;
184   } m_irq_queue[16];
185
186   bool m_isdrc;
187
188   int m_pcfsel;                 // last pcflush entry set
189   int m_maxpcfsel;              // highest valid pcflush entry
190   UINT32 m_pcflushes[16];           // pcflush entries
191
192   INT8    m_irq_line_state[17];
193   address_space *m_program;
194protected:
195   direct_read_data *m_direct;
196private:
197   address_space *m_internal;
198   UINT32 m_m[0x200/4];
199   INT8  m_nmi_line_state;
200
201   UINT16  m_frc;
202   UINT16  m_ocra, m_ocrb, m_icr;
203   UINT64  m_frc_base;
204
205   int     m_frt_input;
206   int     m_internal_irq_vector;
207
208   emu_timer *m_timer;
209   emu_timer *m_dma_current_active_timer[2];
210   int     m_dma_timer_active[2];
211   UINT8  m_dma_irq[2];
212
213   int m_active_dma_incs[2];
214   int m_active_dma_incd[2];
215   int m_active_dma_size[2];
216   int m_active_dma_steal[2];
217   UINT32 m_active_dma_src[2];
218   UINT32 m_active_dma_dst[2];
219   UINT32 m_active_dma_count[2];
220   UINT16 m_wtcnt;
221   UINT8 m_wtcsr;
222
223   int     m_is_slave, m_cpu_type;
224   int  (*m_dma_callback_kludge)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
225   int  (*m_dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
226
227   void    (*m_ftcsr_read_callback)(UINT32 data);
228
229   drc_cache           m_cache;                  /* pointer to the DRC code cache */
230   drcuml_state *      m_drcuml;                 /* DRC UML generator state */
231   sh2_frontend *      m_drcfe;                  /* pointer to the DRC front-end state */
232   UINT32              m_drcoptions;         /* configurable DRC options */
233
234   internal_sh2_state *m_sh2_state;
235
236   /* internal stuff */
237   UINT8               m_cache_dirty;                /* true if we need to flush the cache */
238
239   /* parameters for subroutines */
240   UINT64              m_numcycles;              /* return value from gettotalcycles */
241   UINT32              m_arg1;                   /* print_debug argument 2 */
242   UINT32              m_irq;                /* irq we're taking */
243
244   /* register mappings */
245   uml::parameter      m_regmap[16];                 /* parameter to register mappings for all 16 integer registers */
246
247   uml::code_handle *  m_entry;                      /* entry point */
248   uml::code_handle *  m_read8;                  /* read byte */
249   uml::code_handle *  m_write8;                 /* write byte */
250   uml::code_handle *  m_read16;                 /* read half */
251   uml::code_handle *  m_write16;                    /* write half */
252   uml::code_handle *  m_read32;                 /* read word */
253   uml::code_handle *  m_write32;                    /* write word */
254
255   uml::code_handle *  m_interrupt;              /* interrupt */
256   uml::code_handle *  m_nocode;                 /* nocode */
257   uml::code_handle *  m_out_of_cycles;              /* out of cycles exception handler */
258
259   /* fast RAM */
260   UINT32              m_fastram_select;
261   struct
262   {
263      offs_t              start;                      /* start of the RAM block */
264      offs_t              end;                        /* end of the RAM block */
265      UINT8               readonly;                   /* TRUE if read-only */
266      void *              base;                       /* base in memory where the RAM lives */
267   } m_fastram[SH2_MAX_FASTRAM];
268
269   UINT32 m_debugger_temp;
270
271   inline UINT8 RB(offs_t A);
272   inline UINT16 RW(offs_t A);
273   inline UINT32 RL(offs_t A);
274   inline void WB(offs_t A, UINT8 V);
275   inline void WW(offs_t A, UINT16 V);
276   inline void WL(offs_t A, UINT32 V);
277   inline void ADD(UINT32 m, UINT32 n);
278   inline void ADDI(UINT32 i, UINT32 n);
279   inline void ADDC(UINT32 m, UINT32 n);
280   inline void ADDV(UINT32 m, UINT32 n);
281   inline void AND(UINT32 m, UINT32 n);
282   inline void ANDI(UINT32 i);
283   inline void ANDM(UINT32 i);
284   inline void BF(UINT32 d);
285   inline void BFS(UINT32 d);
286   inline void BRA(UINT32 d);
287   inline void BRAF(UINT32 m);
288   inline void BSR(UINT32 d);
289   inline void BSRF(UINT32 m);
290   inline void BT(UINT32 d);
291   inline void BTS(UINT32 d);
292   inline void CLRMAC();
293   inline void CLRT();
294   inline void CMPEQ(UINT32 m, UINT32 n);
295   inline void CMPGE(UINT32 m, UINT32 n);
296   inline void CMPGT(UINT32 m, UINT32 n);
297   inline void CMPHI(UINT32 m, UINT32 n);
298   inline void CMPHS(UINT32 m, UINT32 n);
299   inline void CMPPL(UINT32 n);
300   inline void CMPPZ(UINT32 n);
301   inline void CMPSTR(UINT32 m, UINT32 n);
302   inline void CMPIM(UINT32 i);
303   inline void DIV0S(UINT32 m, UINT32 n);
304   inline void DIV0U();
305   inline void DIV1(UINT32 m, UINT32 n);
306   inline void DMULS(UINT32 m, UINT32 n);
307   inline void DMULU(UINT32 m, UINT32 n);
308   inline void DT(UINT32 n);
309   inline void EXTSB(UINT32 m, UINT32 n);
310   inline void EXTSW(UINT32 m, UINT32 n);
311   inline void EXTUB(UINT32 m, UINT32 n);
312   inline void EXTUW(UINT32 m, UINT32 n);
313   inline void ILLEGAL();
314   inline void JMP(UINT32 m);
315   inline void JSR(UINT32 m);
316   inline void LDCSR(UINT32 m);
317   inline void LDCGBR(UINT32 m);
318   inline void LDCVBR(UINT32 m);
319   inline void LDCMSR(UINT32 m);
320   inline void LDCMGBR(UINT32 m);
321   inline void LDCMVBR(UINT32 m);
322   inline void LDSMACH(UINT32 m);
323   inline void LDSMACL(UINT32 m);
324   inline void LDSPR(UINT32 m);
325   inline void LDSMMACH(UINT32 m);
326   inline void LDSMMACL(UINT32 m);
327   inline void LDSMPR(UINT32 m);
328   inline void MAC_L(UINT32 m, UINT32 n);
329   inline void MAC_W(UINT32 m, UINT32 n);
330   inline void MOV(UINT32 m, UINT32 n);
331   inline void MOVBS(UINT32 m, UINT32 n);
332   inline void MOVWS(UINT32 m, UINT32 n);
333   inline void MOVLS(UINT32 m, UINT32 n);
334   inline void MOVBL(UINT32 m, UINT32 n);
335   inline void MOVWL(UINT32 m, UINT32 n);
336   inline void MOVLL(UINT32 m, UINT32 n);
337   inline void MOVBM(UINT32 m, UINT32 n);
338   inline void MOVWM(UINT32 m, UINT32 n);
339   inline void MOVLM(UINT32 m, UINT32 n);
340   inline void MOVBP(UINT32 m, UINT32 n);
341   inline void MOVWP(UINT32 m, UINT32 n);
342   inline void MOVLP(UINT32 m, UINT32 n);
343   inline void MOVBS0(UINT32 m, UINT32 n);
344   inline void MOVWS0(UINT32 m, UINT32 n);
345   inline void MOVLS0(UINT32 m, UINT32 n);
346   inline void MOVBL0(UINT32 m, UINT32 n);
347   inline void MOVWL0(UINT32 m, UINT32 n);
348   inline void MOVLL0(UINT32 m, UINT32 n);
349   inline void MOVI(UINT32 i, UINT32 n);
350   inline void MOVWI(UINT32 d, UINT32 n);
351   inline void MOVLI(UINT32 d, UINT32 n);
352   inline void MOVBLG(UINT32 d);
353   inline void MOVWLG(UINT32 d);
354   inline void MOVLLG(UINT32 d);
355   inline void MOVBSG(UINT32 d);
356   inline void MOVWSG(UINT32 d);
357   inline void MOVLSG(UINT32 d);
358   inline void MOVBS4(UINT32 d, UINT32 n);
359   inline void MOVWS4(UINT32 d, UINT32 n);
360   inline void MOVLS4(UINT32 m, UINT32 d, UINT32 n);
361   inline void MOVBL4(UINT32 m, UINT32 d);
362   inline void MOVWL4(UINT32 m, UINT32 d);
363   inline void MOVLL4(UINT32 m, UINT32 d, UINT32 n);
364   inline void MOVA(UINT32 d);
365   inline void MOVT(UINT32 n);
366   inline void MULL(UINT32 m, UINT32 n);
367   inline void MULS(UINT32 m, UINT32 n);
368   inline void MULU(UINT32 m, UINT32 n);
369   inline void NEG(UINT32 m, UINT32 n);
370   inline void NEGC(UINT32 m, UINT32 n);
371   inline void NOP(void);
372   inline void NOT(UINT32 m, UINT32 n);
373   inline void OR(UINT32 m, UINT32 n);
374   inline void ORI(UINT32 i);
375   inline void ORM(UINT32 i);
376   inline void ROTCL(UINT32 n);
377   inline void ROTCR(UINT32 n);
378   inline void ROTL(UINT32 n);
379   inline void ROTR(UINT32 n);
380   inline void RTE();
381   inline void RTS();
382   inline void SETT();
383   inline void SHAL(UINT32 n);
384   inline void SHAR(UINT32 n);
385   inline void SHLL(UINT32 n);
386   inline void SHLL2(UINT32 n);
387   inline void SHLL8(UINT32 n);
388   inline void SHLL16(UINT32 n);
389   inline void SHLR(UINT32 n);
390   inline void SHLR2(UINT32 n);
391   inline void SHLR8(UINT32 n);
392   inline void SHLR16(UINT32 n);
393   inline void SLEEP();
394   inline void STCSR(UINT32 n);
395   inline void STCGBR(UINT32 n);
396   inline void STCVBR(UINT32 n);
397   inline void STCMSR(UINT32 n);
398   inline void STCMGBR(UINT32 n);
399   inline void STCMVBR(UINT32 n);
400   inline void STSMACH(UINT32 n);
401   inline void STSMACL(UINT32 n);
402   inline void STSPR(UINT32 n);
403   inline void STSMMACH(UINT32 n);
404   inline void STSMMACL(UINT32 n);
405   inline void STSMPR(UINT32 n);
406   inline void SUB(UINT32 m, UINT32 n);
407   inline void SUBC(UINT32 m, UINT32 n);
408   inline void SUBV(UINT32 m, UINT32 n);
409   inline void SWAPB(UINT32 m, UINT32 n);
410   inline void SWAPW(UINT32 m, UINT32 n);
411   inline void TAS(UINT32 n);
412   inline void TRAPA(UINT32 i);
413   inline void TST(UINT32 m, UINT32 n);
414   inline void TSTI(UINT32 i);
415   inline void TSTM(UINT32 i);
416   inline void XOR(UINT32 m, UINT32 n);
417   inline void XORI(UINT32 i);
418   inline void XORM(UINT32 i);
419   inline void XTRCT(UINT32 m, UINT32 n);
420   inline void op0000(UINT16 opcode);
421   inline void op0001(UINT16 opcode);
422   inline void op0010(UINT16 opcode);
423   inline void op0011(UINT16 opcode);
424   inline void op0100(UINT16 opcode);
425   inline void op0101(UINT16 opcode);
426   inline void op0110(UINT16 opcode);
427   inline void op0111(UINT16 opcode);
428   inline void op1000(UINT16 opcode);
429   inline void op1001(UINT16 opcode);
430   inline void op1010(UINT16 opcode);
431   inline void op1011(UINT16 opcode);
432   inline void op1100(UINT16 opcode);
433   inline void op1101(UINT16 opcode);
434   inline void op1110(UINT16 opcode);
435   inline void op1111(UINT16 opcode);
436   TIMER_CALLBACK_MEMBER( sh2_timer_callback );
437   TIMER_CALLBACK_MEMBER( sh2_dma_current_active_callback );
438   void sh2_timer_resync();
439   void sh2_timer_activate();
440   void sh2_do_dma(int dma);
441   void sh2_exception(const char *message, int irqline);
442   void sh2_dmac_check(int dma);
443   void sh2_recalc_irq();
444
445   /* internal compiler state */
446   struct compiler_state
447   {
448      UINT32          cycles;                     /* accumulated cycles */
449      UINT8           checkints;                  /* need to check interrupts before next instruction */
450      uml::code_label  labelnum;                   /* index for local labels */
451   };
452
453   inline UINT32 epc(const opcode_desc *desc);
454   inline void alloc_handle(drcuml_state *drcuml, uml::code_handle **handleptr, const char *name);
455   inline void load_fast_iregs(drcuml_block *block);
456   inline void save_fast_iregs(drcuml_block *block);
457
458   void code_flush_cache();
459   void execute_run_drc();
460   void code_compile_block(UINT8 mode, offs_t pc);
461   void static_generate_entry_point();
462   void static_generate_nocode_handler();
463   void static_generate_out_of_cycles();
464   void static_generate_memory_accessor(int size, int iswrite, const char *name, uml::code_handle **handleptr);
465   const char *log_desc_flags_to_string(UINT32 flags);
466   void log_register_list(drcuml_state *drcuml, const char *string, const UINT32 *reglist, const UINT32 *regnostarlist);
467   void log_opcode_desc(drcuml_state *drcuml, const opcode_desc *desclist, int indent);
468   void log_add_disasm_comment(drcuml_block *block, UINT32 pc, UINT32 op);
469   void generate_update_cycles(drcuml_block *block, compiler_state *compiler, uml::parameter param, int allow_exception);
470   void generate_checksum_block(drcuml_block *block, compiler_state *compiler, const opcode_desc *seqhead, const opcode_desc *seqlast);
471   void generate_sequence_instruction(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc);
472   void generate_delay_slot(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc);
473   int generate_opcode(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc);
474   int generate_group_0(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
475   int generate_group_2(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
476   int generate_group_3(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, UINT32 ovrpc);
477   int generate_group_4(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
478   int generate_group_6(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
479   int generate_group_8(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
480   int generate_group_12(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
481
482public:
483   void func_printf_probe();
484   void func_unimplemented();
485   void func_fastirq();
486   void func_MAC_W();
487   void func_MAC_L();
488   void func_DIV1();
489   void func_ADDV();
490   void func_SUBV();
491};
492
493
494class sh1_device : public sh2_device
495{
496public:
497   // construction/destruction
498   sh1_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock);
499};
500
501
502class sh2_frontend : public drc_frontend
503{
504public:
505    sh2_frontend(sh2_device *device, UINT32 window_start, UINT32 window_end, UINT32 max_sequence);
506
507protected:
508    virtual bool describe(opcode_desc &desc, const opcode_desc *prev);
509
510private:
511    bool describe_group_0(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
512    bool describe_group_2(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
513    bool describe_group_3(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
514    bool describe_group_4(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
515    bool describe_group_6(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
516    bool describe_group_8(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
517    bool describe_group_12(opcode_desc &desc, const opcode_desc *prev, UINT16 opcode);
518
519   sh2_device *m_sh2;
520};
521
522
523extern const device_type SH1;
524extern const device_type SH2;
525
526
110527#endif /* __SH2_H__ */
trunk/src/emu/cpu/sh2/sh2drc.c
r29565r29566
1212#include "sh2.h"
1313#include "sh2comn.h"
1414
15CPU_DISASSEMBLE( sh2 );
1615extern unsigned DasmSH2(char *buffer, unsigned pc, UINT16 opcode);
1716
1817using namespace uml;
r29565r29566
2120    DEBUGGING
2221***************************************************************************/
2322
24#define LOG_UML                     (0) // log UML assembly
25#define LOG_NATIVE                  (0) // log native assembly
26
2723#define SET_EA                      (0) // makes slower but "shows work" in the EA fake register like the interpreter
2824
29#define DISABLE_FAST_REGISTERS              (0) // set to 1 to turn off usage of register caching
30#define SINGLE_INSTRUCTION_MODE             (0)
31
3225#define ADDSUBV_DIRECT              (0)
3326
34#define VERBOSE 0
35#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
36
3727#if SET_EA
38#define SETEA(x) UML_MOV(block, mem(&sh2->ea), ireg(x))
28#define SETEA(x) UML_MOV(block, mem(&m_sh2_state->ea), ireg(x))
3929#else
4030#define SETEA(x)
4131#endif
r29565r29566
4838#define MAPVAR_PC                   M0
4939#define MAPVAR_CYCLES                   M1
5040
51/* size of the execution code cache */
52#define CACHE_SIZE                  (32 * 1024 * 1024)
53
54/* compilation boundaries -- how far back/forward does the analysis extend? */
55#define COMPILE_BACKWARDS_BYTES         64
56#define COMPILE_FORWARDS_BYTES          256
57#define COMPILE_MAX_INSTRUCTIONS        ((COMPILE_BACKWARDS_BYTES/2) + (COMPILE_FORWARDS_BYTES/2))
58#define COMPILE_MAX_SEQUENCE            64
59
6041/* exit codes */
6142#define EXECUTE_OUT_OF_CYCLES           0
6243#define EXECUTE_MISSING_CODE            1
r29565r29566
6546
6647#define PROBE_ADDRESS                   ~0
6748
68extern int sh2_describe(void *param, opcode_desc *desc, const opcode_desc *prev);
6949
7050/***************************************************************************
7151    MACROS
7252***************************************************************************/
7353
74#define R32(reg)        sh2->regmap[reg]
54#define R32(reg)        m_regmap[reg]
7555
7656/***************************************************************************
77    STRUCTURES & TYPEDEFS
78***************************************************************************/
79
80/* internal compiler state */
81struct compiler_state
82{
83   UINT32          cycles;                     /* accumulated cycles */
84   UINT8           checkints;                  /* need to check interrupts before next instruction */
85   code_label  labelnum;                   /* index for local labels */
86};
87
88/***************************************************************************
89    FUNCTION PROTOTYPES
90***************************************************************************/
91
92static void static_generate_entry_point(sh2_state *sh2);
93static void static_generate_nocode_handler(sh2_state *sh2);
94static void static_generate_out_of_cycles(sh2_state *sh2);
95static void static_generate_memory_accessor(sh2_state *sh2, int size, int iswrite, const char *name, code_handle **handleptr);
96
97static void generate_update_cycles(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, parameter param, int allow_exception);
98static void generate_checksum_block(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *seqhead, const opcode_desc *seqlast);
99static void generate_sequence_instruction(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc);
100static void generate_delay_slot(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc);
101
102static int generate_opcode(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc);
103static int generate_group_0(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
104static int generate_group_2(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
105static int generate_group_3(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, UINT32 ovrpc);
106static int generate_group_4(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
107static int generate_group_6(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
108static int generate_group_8(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
109static int generate_group_12(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc);
110
111static void code_compile_block(sh2_state *sh2, UINT8 mode, offs_t pc);
112
113static void log_opcode_desc(drcuml_state *drcuml, const opcode_desc *desclist, int indent);
114static void log_register_list(drcuml_state *drcuml, const char *string, const UINT32 *reglist, const UINT32 *regnostarlist);
115static void log_add_disasm_comment(drcuml_block *block, UINT32 pc, UINT32 op);
116static const char *log_desc_flags_to_string(UINT32 flags);
117
118static void cfunc_printf_probe(void *param);
119static void cfunc_unimplemented(void *param);
120static void cfunc_fastirq(void *param);
121static void cfunc_MAC_W(void *param);
122static void cfunc_MAC_L(void *param);
123static void cfunc_DIV1(void *param);
124
125/***************************************************************************
12657    INLINE FUNCTIONS
12758***************************************************************************/
12859
129INLINE sh2_state *get_safe_token(device_t *device)
130{
131   assert(device != NULL);
132   assert(device->type() == SH1_DRC ||
133         device->type() == SH2_DRC);
134   return *(sh2_state **)downcast<legacy_cpu_device *>(device)->token();
135}
136
137INLINE UINT16 RW(sh2_state *sh2, offs_t A)
138{
139   if (A >= 0xe0000000)
140      return sh2_internal_r(*sh2->internal, (A & 0x1fc)>>2, 0xffff << (((~A) & 2)*8)) >> (((~A) & 2)*8);
141
142   if (A >= 0xc0000000)
143      return sh2->program->read_word(A);
144
145   return sh2->program->read_word(A & AM);
146}
147
148INLINE UINT32 RL(sh2_state *sh2, offs_t A)
149{
150   if (A >= 0xe0000000)
151      return sh2_internal_r(*sh2->internal, (A & 0x1fc)>>2, 0xffffffff);
152
153   if (A >= 0xc0000000)
154      return sh2->program->read_dword(A);
155
156   return sh2->program->read_dword(A & AM);
157}
158
15960/*-------------------------------------------------
16061    epc - compute the exception PC from a
16162    descriptor
16263-------------------------------------------------*/
16364
164INLINE UINT32 epc(const opcode_desc *desc)
65UINT32 sh2_device::epc(const opcode_desc *desc)
16566{
16667   return (desc->flags & OPFLAG_IN_DELAY_SLOT) ? (desc->pc - 1) : desc->pc;
16768}
r29565r29566
17172    already allocated
17273-------------------------------------------------*/
17374
174INLINE void alloc_handle(drcuml_state *drcuml, code_handle **handleptr, const char *name)
75void sh2_device::alloc_handle(drcuml_state *drcuml, code_handle **handleptr, const char *name)
17576{
17677   if (*handleptr == NULL)
17778      *handleptr = drcuml->handle_alloc(name);
r29565r29566
18283    registers
18384-------------------------------------------------*/
18485
185INLINE void load_fast_iregs(sh2_state *sh2, drcuml_block *block)
86void sh2_device::load_fast_iregs(drcuml_block *block)
18687{
18788   int regnum;
18889
189   for (regnum = 0; regnum < ARRAY_LENGTH(sh2->regmap); regnum++)
90   for (regnum = 0; regnum < ARRAY_LENGTH(m_regmap); regnum++)
19091   {
191      if (sh2->regmap[regnum].is_int_register())
92      if (m_regmap[regnum].is_int_register())
19293      {
193         UML_MOV(block, parameter::make_ireg(sh2->regmap[regnum].ireg()), mem(&sh2->r[regnum]));
94         UML_MOV(block, parameter::make_ireg(m_regmap[regnum].ireg()), mem(&m_sh2_state->r[regnum]));
19495      }
19596   }
19697}
r29565r29566
201102    registers
202103-------------------------------------------------*/
203104
204INLINE void save_fast_iregs(sh2_state *sh2, drcuml_block *block)
105void sh2_device::save_fast_iregs(drcuml_block *block)
205106{
206107   int regnum;
207108
208   for (regnum = 0; regnum < ARRAY_LENGTH(sh2->regmap); regnum++)
109   for (regnum = 0; regnum < ARRAY_LENGTH(m_regmap); regnum++)
209110   {
210      if (sh2->regmap[regnum].is_int_register())
111      if (m_regmap[regnum].is_int_register())
211112      {
212         UML_MOV(block, mem(&sh2->r[regnum]), parameter::make_ireg(sh2->regmap[regnum].ireg()));
113         UML_MOV(block, mem(&m_sh2_state->r[regnum]), parameter::make_ireg(m_regmap[regnum].ireg()));
213114      }
214115   }
215116}
r29565r29566
221122
222123static void cfunc_printf_probe(void *param)
223124{
224   sh2_state *sh2 = (sh2_state *)param;
225   UINT32 pc = sh2->pc;
125   ((sh2_device *)param)->func_printf_probe();
126}
226127
128void sh2_device::func_printf_probe()
129{
130   UINT32 pc = m_sh2_state->pc;
131
227132   printf(" PC=%08X          r0=%08X  r1=%08X  r2=%08X\n",
228133      pc,
229      (UINT32)sh2->r[0],
230      (UINT32)sh2->r[1],
231      (UINT32)sh2->r[2]);
134      (UINT32)m_sh2_state->r[0],
135      (UINT32)m_sh2_state->r[1],
136      (UINT32)m_sh2_state->r[2]);
232137   printf(" r3=%08X  r4=%08X  r5=%08X  r6=%08X\n",
233      (UINT32)sh2->r[3],
234      (UINT32)sh2->r[4],
235      (UINT32)sh2->r[5],
236      (UINT32)sh2->r[6]);
138      (UINT32)m_sh2_state->r[3],
139      (UINT32)m_sh2_state->r[4],
140      (UINT32)m_sh2_state->r[5],
141      (UINT32)m_sh2_state->r[6]);
237142   printf(" r7=%08X  r8=%08X  r9=%08X  r10=%08X\n",
238      (UINT32)sh2->r[7],
239      (UINT32)sh2->r[8],
240      (UINT32)sh2->r[9],
241      (UINT32)sh2->r[10]);
143      (UINT32)m_sh2_state->r[7],
144      (UINT32)m_sh2_state->r[8],
145      (UINT32)m_sh2_state->r[9],
146      (UINT32)m_sh2_state->r[10]);
242147   printf(" r11=%08X  r12=%08X  r13=%08X  r14=%08X\n",
243      (UINT32)sh2->r[11],
244      (UINT32)sh2->r[12],
245      (UINT32)sh2->r[13],
246      (UINT32)sh2->r[14]);
148      (UINT32)m_sh2_state->r[11],
149      (UINT32)m_sh2_state->r[12],
150      (UINT32)m_sh2_state->r[13],
151      (UINT32)m_sh2_state->r[14]);
247152   printf(" r15=%08X  macl=%08X  mach=%08X  gbr=%08X\n",
248      (UINT32)sh2->r[15],
249      (UINT32)sh2->macl,
250      (UINT32)sh2->mach,
251      (UINT32)sh2->gbr);
153      (UINT32)m_sh2_state->r[15],
154      (UINT32)m_sh2_state->macl,
155      (UINT32)m_sh2_state->mach,
156      (UINT32)m_sh2_state->gbr);
252157   printf(" evec %x irqsr %x pc=%08x\n",
253      (UINT32)sh2->evec,
254      (UINT32)sh2->irqsr, (UINT32)sh2->pc);
158      (UINT32)m_sh2_state->evec,
159      (UINT32)m_sh2_state->irqsr, (UINT32)m_sh2_state->pc);
255160}
256161
257162/*-------------------------------------------------
r29565r29566
261166
262167static void cfunc_unimplemented(void *param)
263168{
264   sh2_state *sh2 = (sh2_state *)param;
169   ((sh2_device *)param)->func_unimplemented();
170}
265171
172void sh2_device::func_unimplemented()
173{
266174   // set up an invalid opcode exception
267   sh2->evec = RL( sh2, sh2->vbr + 4 * 4 );
268   sh2->evec &= AM;
269   sh2->irqsr = sh2->sr;
175   m_sh2_state->evec = RL( m_sh2_state->vbr + 4 * 4 );
176   m_sh2_state->evec &= AM;
177   m_sh2_state->irqsr = m_sh2_state->sr;
270178   // claim it's an NMI, because it pretty much is
271   sh2->pending_nmi = 1;
179   m_sh2_state->pending_nmi = 1;
272180}
273181
274182/*-------------------------------------------------
r29565r29566
276184-------------------------------------------------*/
277185static void cfunc_fastirq(void *param)
278186{
279   sh2_state *sh2 = (sh2_state *)param;
280   sh2_exception(sh2, "fastirq",sh2->irqline);
187   ((sh2_device *)param)->func_fastirq();
281188}
282189
190void sh2_device::func_fastirq()
191{
192   sh2_exception("fastirq",m_sh2_state->irqline);
193}
194
283195/*-------------------------------------------------
284196    cfunc_MAC_W - implementation of MAC_W Rm,Rn
285197-------------------------------------------------*/
286198static void cfunc_MAC_W(void *param)
287199{
288   sh2_state *sh2 = (sh2_state *)param;
200   ((sh2_device *)param)->func_MAC_W();
201}
202
203void sh2_device::func_MAC_W()
204{
289205   INT32 tempm, tempn, dest, src, ans;
290206   UINT32 templ;
291207   UINT16 opcode;
292208   int n, m;
293209
294210   // recover the opcode
295   opcode = sh2->arg0;
211   opcode = m_sh2_state->arg0;
296212
297213   // extract the operands
298214   n = Rn;
299215   m = Rm;
300216
301   tempn = (INT32) RW( sh2, sh2->r[n] );
302   sh2->r[n] += 2;
303   tempm = (INT32) RW( sh2, sh2->r[m] );
304   sh2->r[m] += 2;
305   templ = sh2->macl;
217   tempn = (INT32) RW( m_sh2_state->r[n] );
218   m_sh2_state->r[n] += 2;
219   tempm = (INT32) RW( m_sh2_state->r[m] );
220   m_sh2_state->r[m] += 2;
221   templ = m_sh2_state->macl;
306222   tempm = ((INT32) (short) tempn * (INT32) (short) tempm);
307   if ((INT32) sh2->macl >= 0)
223   if ((INT32) m_sh2_state->macl >= 0)
308224      dest = 0;
309225   else
310226      dest = 1;
r29565r29566
319235      tempn = 0xffffffff;
320236   }
321237   src += dest;
322   sh2->macl += tempm;
323   if ((INT32) sh2->macl >= 0)
238   m_sh2_state->macl += tempm;
239   if ((INT32) m_sh2_state->macl >= 0)
324240      ans = 0;
325241   else
326242      ans = 1;
327243   ans += dest;
328   if (sh2->sr & S)
244   if (m_sh2_state->sr & S)
329245   {
330246      if (ans == 1)
331247         {
332            if ((sh2->cpu_type == CPU_TYPE_SH1) && ((src == 0) || (src == 2)))
248            if ((m_cpu_type == CPU_TYPE_SH1) && ((src == 0) || (src == 2)))
333249            {
334               sh2->mach |= 0x00000001;
250               m_sh2_state->mach |= 0x00000001;
335251            }
336252
337253            if (src == 0)
338               sh2->macl = 0x7fffffff;
254               m_sh2_state->macl = 0x7fffffff;
339255            if (src == 2)
340               sh2->macl = 0x80000000;
256               m_sh2_state->macl = 0x80000000;
341257         }
342258   }
343259   else
344260   {
345      sh2->mach += tempn;
346      if (templ > sh2->macl)
347         sh2->mach += 1;
261      m_sh2_state->mach += tempn;
262      if (templ > m_sh2_state->macl)
263         m_sh2_state->mach += 1;
348264
349265      // SH-1 has limited precision
350      if (sh2->cpu_type == CPU_TYPE_SH1)
266      if (m_cpu_type == CPU_TYPE_SH1)
351267      {
352         if ((sh2->mach & 0x200) == 0)
268         if ((m_sh2_state->mach & 0x200) == 0)
353269         {
354            sh2->mach &= 0x3ff;
270            m_sh2_state->mach &= 0x3ff;
355271         }
356272         else
357273         {
358            sh2->mach |= 0xfffffc00;
274            m_sh2_state->mach |= 0xfffffc00;
359275         }
360276      }
361277
r29565r29566
368284-------------------------------------------------*/
369285static void cfunc_MAC_L(void *param)
370286{
371   sh2_state *sh2 = (sh2_state *)param;
287   ((sh2_device *)param)->func_MAC_L();
288}
289
290void sh2_device::func_MAC_L()
291{
372292   UINT32 RnL, RnH, RmL, RmH, Res0, Res1, Res2;
373293   UINT32 temp0, temp1, temp2, temp3;
374294   INT32 tempm, tempn, fnLmL;
r29565r29566
376296   int n, m;
377297
378298   // recover the opcode
379   opcode = sh2->arg0;
299   opcode = m_sh2_state->arg0;
380300
381301   // extract the operands
382302   n = Rn;
383303   m = Rm;
384304
385   tempn = (INT32) RL( sh2, sh2->r[n] );
386   sh2->r[n] += 4;
387   tempm = (INT32) RL( sh2, sh2->r[m] );
388   sh2->r[m] += 4;
305   tempn = (INT32) RL( m_sh2_state->r[n] );
306   m_sh2_state->r[n] += 4;
307   tempm = (INT32) RL( m_sh2_state->r[m] );
308   m_sh2_state->r[m] += 4;
389309   if ((INT32) (tempn ^ tempm) < 0)
390310      fnLmL = -1;
391311   else
r29565r29566
421341      else
422342         Res0 = (~Res0) + 1;
423343   }
424   if (sh2->sr & S)
344   if (m_sh2_state->sr & S)
425345   {
426      Res0 = sh2->macl + Res0;
427      if (sh2->macl > Res0)
346      Res0 = m_sh2_state->macl + Res0;
347      if (m_sh2_state->macl > Res0)
428348         Res2++;
429      Res2 += (sh2->mach & 0x0000ffff);
349      Res2 += (m_sh2_state->mach & 0x0000ffff);
430350      if (((INT32) Res2 < 0) && (Res2 < 0xffff8000))
431351      {
432352         Res2 = 0x00008000;
r29565r29566
437357         Res2 = 0x00007fff;
438358         Res0 = 0xffffffff;
439359      }
440      sh2->mach = Res2;
441      sh2->macl = Res0;
360      m_sh2_state->mach = Res2;
361      m_sh2_state->macl = Res0;
442362   }
443363   else
444364   {
445      Res0 = sh2->macl + Res0;
446      if (sh2->macl > Res0)
365      Res0 = m_sh2_state->macl + Res0;
366      if (m_sh2_state->macl > Res0)
447367         Res2++;
448      Res2 += sh2->mach;
449      sh2->mach = Res2;
450      sh2->macl = Res0;
368      Res2 += m_sh2_state->mach;
369      m_sh2_state->mach = Res2;
370      m_sh2_state->macl = Res0;
451371   }
452372}
453373
r29565r29566
456376-------------------------------------------------*/
457377static void cfunc_DIV1(void *param)
458378{
459   sh2_state *sh2 = (sh2_state *)param;
379   ((sh2_device *)param)->func_DIV1();
380}
381
382void sh2_device::func_DIV1()
383{
460384   UINT32 tmp0;
461385   UINT32 old_q;
462386   UINT16 opcode;
463387   int n, m;
464388
465389   // recover the opcode
466   opcode = sh2->arg0;
390   opcode = m_sh2_state->arg0;
467391
468392   // extract the operands
469393   n = Rn;
470394   m = Rm;
471395
472   old_q = sh2->sr & Q;
473   if (0x80000000 & sh2->r[n])
474      sh2->sr |= Q;
396   old_q = m_sh2_state->sr & Q;
397   if (0x80000000 & m_sh2_state->r[n])
398      m_sh2_state->sr |= Q;
475399   else
476      sh2->sr &= ~Q;
400      m_sh2_state->sr &= ~Q;
477401
478   sh2->r[n] = (sh2->r[n] << 1) | (sh2->sr & T);
402   m_sh2_state->r[n] = (m_sh2_state->r[n] << 1) | (m_sh2_state->sr & T);
479403
480404   if (!old_q)
481405   {
482      if (!(sh2->sr & M))
406      if (!(m_sh2_state->sr & M))
483407      {
484         tmp0 = sh2->r[n];
485         sh2->r[n] -= sh2->r[m];
486         if(!(sh2->sr & Q))
487            if(sh2->r[n] > tmp0)
488               sh2->sr |= Q;
408         tmp0 = m_sh2_state->r[n];
409         m_sh2_state->r[n] -= m_sh2_state->r[m];
410         if(!(m_sh2_state->sr & Q))
411            if(m_sh2_state->r[n] > tmp0)
412               m_sh2_state->sr |= Q;
489413            else
490               sh2->sr &= ~Q;
414               m_sh2_state->sr &= ~Q;
491415         else
492            if(sh2->r[n] > tmp0)
493               sh2->sr &= ~Q;
416            if(m_sh2_state->r[n] > tmp0)
417               m_sh2_state->sr &= ~Q;
494418            else
495               sh2->sr |= Q;
419               m_sh2_state->sr |= Q;
496420      }
497421      else
498422      {
499         tmp0 = sh2->r[n];
500         sh2->r[n] += sh2->r[m];
501         if(!(sh2->sr & Q))
423         tmp0 = m_sh2_state->r[n];
424         m_sh2_state->r[n] += m_sh2_state->r[m];
425         if(!(m_sh2_state->sr & Q))
502426         {
503            if(sh2->r[n] < tmp0)
504               sh2->sr &= ~Q;
427            if(m_sh2_state->r[n] < tmp0)
428               m_sh2_state->sr &= ~Q;
505429            else
506               sh2->sr |= Q;
430               m_sh2_state->sr |= Q;
507431         }
508432         else
509433         {
510            if(sh2->r[n] < tmp0)
511               sh2->sr |= Q;
434            if(m_sh2_state->r[n] < tmp0)
435               m_sh2_state->sr |= Q;
512436            else
513               sh2->sr &= ~Q;
437               m_sh2_state->sr &= ~Q;
514438         }
515439      }
516440   }
517441   else
518442   {
519      if (!(sh2->sr & M))
443      if (!(m_sh2_state->sr & M))
520444      {
521         tmp0 = sh2->r[n];
522         sh2->r[n] += sh2->r[m];
523         if(!(sh2->sr & Q))
524            if(sh2->r[n] < tmp0)
525               sh2->sr |= Q;
445         tmp0 = m_sh2_state->r[n];
446         m_sh2_state->r[n] += m_sh2_state->r[m];
447         if(!(m_sh2_state->sr & Q))
448            if(m_sh2_state->r[n] < tmp0)
449               m_sh2_state->sr |= Q;
526450            else
527               sh2->sr &= ~Q;
451               m_sh2_state->sr &= ~Q;
528452         else
529            if(sh2->r[n] < tmp0)
530               sh2->sr &= ~Q;
453            if(m_sh2_state->r[n] < tmp0)
454               m_sh2_state->sr &= ~Q;
531455            else
532               sh2->sr |= Q;
456               m_sh2_state->sr |= Q;
533457      }
534458      else
535459      {
536         tmp0 = sh2->r[n];
537         sh2->r[n] -= sh2->r[m];
538         if(!(sh2->sr & Q))
539            if(sh2->r[n] > tmp0)
540               sh2->sr &= ~Q;
460         tmp0 = m_sh2_state->r[n];
461         m_sh2_state->r[n] -= m_sh2_state->r[m];
462         if(!(m_sh2_state->sr & Q))
463            if(m_sh2_state->r[n] > tmp0)
464               m_sh2_state->sr &= ~Q;
541465            else
542               sh2->sr |= Q;
466               m_sh2_state->sr |= Q;
543467         else
544            if(sh2->r[n] > tmp0)
545               sh2->sr |= Q;
468            if(m_sh2_state->r[n] > tmp0)
469               m_sh2_state->sr |= Q;
546470            else
547               sh2->sr &= ~Q;
471               m_sh2_state->sr &= ~Q;
548472      }
549473   }
550474
551   tmp0 = (sh2->sr & (Q | M));
475   tmp0 = (m_sh2_state->sr & (Q | M));
552476   if((!tmp0) || (tmp0 == 0x300)) /* if Q == M set T else clear T */
553      sh2->sr |= T;
477      m_sh2_state->sr |= T;
554478   else
555      sh2->sr &= ~T;
479      m_sh2_state->sr &= ~T;
556480}
557481
558482#if (!ADDSUBV_DIRECT)
r29565r29566
561485-------------------------------------------------*/
562486static void cfunc_ADDV(void *param)
563487{
564   sh2_state *sh2 = (sh2_state *)param;
488   ((sh2_device *)param)->func_ADDV();
489}
490
491void sh2_device::func_ADDV()
492{
565493   INT32 dest, src, ans;
566494   UINT16 opcode;
567495   int n, m;
568496
569497   // recover the opcode
570   opcode = sh2->arg0;
498   opcode = m_sh2_state->arg0;
571499
572500   // extract the operands
573501   n = Rn;
574502   m = Rm;
575503
576   if ((INT32) sh2->r[n] >= 0)
504   if ((INT32) m_sh2_state->r[n] >= 0)
577505      dest = 0;
578506   else
579507      dest = 1;
580   if ((INT32) sh2->r[m] >= 0)
508   if ((INT32) m_sh2_state->r[m] >= 0)
581509      src = 0;
582510   else
583511      src = 1;
584512   src += dest;
585   sh2->r[n] += sh2->r[m];
586   if ((INT32) sh2->r[n] >= 0)
513   m_sh2_state->r[n] += m_sh2_state->r[m];
514   if ((INT32) m_sh2_state->r[n] >= 0)
587515      ans = 0;
588516   else
589517      ans = 1;
r29565r29566
591519   if (src == 0 || src == 2)
592520   {
593521      if (ans == 1)
594         sh2->sr |= T;
522         m_sh2_state->sr |= T;
595523      else
596         sh2->sr &= ~T;
524         m_sh2_state->sr &= ~T;
597525   }
598526   else
599      sh2->sr &= ~T;
527      m_sh2_state->sr &= ~T;
600528}
601529
602530/*-------------------------------------------------
r29565r29566
604532-------------------------------------------------*/
605533static void cfunc_SUBV(void *param)
606534{
607   sh2_state *sh2 = (sh2_state *)param;
535   ((sh2_device *)param)->func_SUBV();
536}
537
538void sh2_device::func_SUBV()
539{
608540   INT32 dest, src, ans;
609541   UINT16 opcode;
610542   int n, m;
611543
612544   // recover the opcode
613   opcode = sh2->arg0;
545   opcode = m_sh2_state->arg0;
614546
615547   // extract the operands
616548   n = Rn;
617549   m = Rm;
618550
619   if ((INT32) sh2->r[n] >= 0)
551   if ((INT32) m_sh2_state->r[n] >= 0)
620552      dest = 0;
621553   else
622554      dest = 1;
623   if ((INT32) sh2->r[m] >= 0)
555   if ((INT32) m_sh2_state->r[m] >= 0)
624556      src = 0;
625557   else
626558      src = 1;
627559   src += dest;
628   sh2->r[n] -= sh2->r[m];
629   if ((INT32) sh2->r[n] >= 0)
560   m_sh2_state->r[n] -= m_sh2_state->r[m];
561   if ((INT32) m_sh2_state->r[n] >= 0)
630562      ans = 0;
631563   else
632564      ans = 1;
r29565r29566
634566   if (src == 1)
635567   {
636568      if (ans == 1)
637         sh2->sr |= T;
569         m_sh2_state->sr |= T;
638570      else
639         sh2->sr &= ~T;
571         m_sh2_state->sr &= ~T;
640572   }
641573   else
642      sh2->sr &= ~T;
574      m_sh2_state->sr &= ~T;
643575}
576#else
577void sh2_device::func_ADDV() {}
578void sh2_device::func_SUBV() {}
644579#endif
645580
646581/*-------------------------------------------------
647    sh2_init - initialize the processor
648-------------------------------------------------*/
649
650static CPU_INIT( sh2 )
651{
652   sh2_state *sh2 = get_safe_token(device);
653   drc_cache *cache;
654   drcbe_info beinfo;
655   UINT32 flags = 0;
656   int regnum;
657
658   /* allocate enough space for the cache and the core */
659   cache = auto_alloc(device->machine(), drc_cache(CACHE_SIZE + sizeof(sh2_state)));
660
661   /* allocate the core memory */
662   *(sh2_state **)device->token() = sh2 = (sh2_state *)cache->alloc_near(sizeof(sh2_state));
663   memset(sh2, 0, sizeof(sh2_state));
664
665   /* initialize the common core parts */
666   sh2_common_init(sh2, device, irqcallback,true);
667
668   /* allocate the implementation-specific state from the full cache */
669   sh2->cache = cache;
670
671   /* reset per-driver pcflushes */
672   sh2->pcfsel = 0;
673
674   /* initialize the UML generator */
675   if (LOG_UML)
676      flags |= DRCUML_OPTION_LOG_UML;
677   if (LOG_NATIVE)
678      flags |= DRCUML_OPTION_LOG_NATIVE;
679   sh2->drcuml = auto_alloc(device->machine(), drcuml_state(*device, *cache, flags, 1, 32, 1));
680
681   /* add symbols for our stuff */
682   sh2->drcuml->symbol_add(&sh2->pc, sizeof(sh2->pc), "pc");
683   sh2->drcuml->symbol_add(&sh2->icount, sizeof(sh2->icount), "icount");
684   for (regnum = 0; regnum < 16; regnum++)
685   {
686      char buf[10];
687      sprintf(buf, "r%d", regnum);
688      sh2->drcuml->symbol_add(&sh2->r[regnum], sizeof(sh2->r[regnum]), buf);
689   }
690   sh2->drcuml->symbol_add(&sh2->pr, sizeof(sh2->pr), "pr");
691   sh2->drcuml->symbol_add(&sh2->sr, sizeof(sh2->sr), "sr");
692   sh2->drcuml->symbol_add(&sh2->gbr, sizeof(sh2->gbr), "gbr");
693   sh2->drcuml->symbol_add(&sh2->vbr, sizeof(sh2->vbr), "vbr");
694   sh2->drcuml->symbol_add(&sh2->macl, sizeof(sh2->macl), "macl");
695   sh2->drcuml->symbol_add(&sh2->mach, sizeof(sh2->macl), "mach");
696
697   /* initialize the front-end helper */
698   sh2->drcfe = auto_alloc(device->machine(), sh2_frontend(*sh2, COMPILE_BACKWARDS_BYTES, COMPILE_FORWARDS_BYTES, SINGLE_INSTRUCTION_MODE ? 1 : COMPILE_MAX_SEQUENCE));
699
700   /* compute the register parameters */
701   for (regnum = 0; regnum < 16; regnum++)
702   {
703      sh2->regmap[regnum] = mem(&sh2->r[regnum]);
704   }
705
706   /* if we have registers to spare, assign r0, r1, r2 to leftovers */
707   /* WARNING: do not use synthetic registers that are mapped here! */
708   if (!DISABLE_FAST_REGISTERS)
709   {
710      sh2->drcuml->get_backend_info(beinfo);
711      if (beinfo.direct_iregs > 4)
712      {
713         sh2->regmap[0] = I4;
714      }
715      if (beinfo.direct_iregs > 5)
716      {
717         sh2->regmap[1] = I5;
718      }
719      if (beinfo.direct_iregs > 6)
720      {
721         sh2->regmap[2] = I6;
722      }
723   }
724
725   /* mark the cache dirty so it is updated on next execute */
726   sh2->cache_dirty = TRUE;
727}
728
729/*-------------------------------------------------
730    sh2_exit - cleanup from execution
731-------------------------------------------------*/
732
733static CPU_EXIT( sh2 )
734{
735   sh2_state *sh2 = get_safe_token(device);
736
737   /* clean up the DRC */
738   auto_free(device->machine(), sh2->drcfe);
739   auto_free(device->machine(), sh2->drcuml);
740   auto_free(device->machine(), sh2->cache);
741}
742
743
744/*-------------------------------------------------
745    sh2_reset - reset the processor
746-------------------------------------------------*/
747
748static CPU_RESET( sh2 )
749{
750   sh2_state *sh2 = get_safe_token(device);
751
752   void (*f)(UINT32 data);
753   device_irq_acknowledge_callback save_irqcallback;
754
755   f = sh2->ftcsr_read_callback;
756   save_irqcallback = sh2->irq_callback;
757
758   sh2->ppc = sh2->pc = sh2->pr = sh2->sr = sh2->gbr = sh2->vbr = sh2->mach = sh2->macl = 0;
759   sh2->evec = sh2->irqsr = 0;
760   memset(&sh2->r[0], 0, sizeof(sh2->r[0])*16);
761   sh2->ea = sh2->delay = sh2->cpu_off = sh2->dvsr = sh2->dvdnth = sh2->dvdntl = sh2->dvcr = 0;
762   sh2->pending_irq = sh2->test_irq = 0;
763   memset(&sh2->irq_queue[0], 0, sizeof(sh2->irq_queue[0])*16);
764   memset(&sh2->irq_line_state[0], 0, sizeof(sh2->irq_line_state[0])*17);
765   sh2->frc = sh2->ocra = sh2->ocrb = sh2->icr = 0;
766   sh2->frc_base = 0;
767   sh2->frt_input = sh2->internal_irq_level = sh2->internal_irq_vector = 0;
768   sh2->dma_timer_active[0] = sh2->dma_timer_active[1] = 0;
769   sh2->dma_irq[0] = sh2->dma_irq[1] = 0;
770
771   sh2->ftcsr_read_callback = f;
772   sh2->irq_callback = save_irqcallback;
773   sh2->device = device;
774
775   memset(sh2->m, 0, 0x200);
776
777   sh2->pc = sh2->program->read_dword(0);
778   sh2->r[15] = sh2->program->read_dword(4);
779   sh2->sr = I;
780
781   sh2->internal_irq_level = -1;
782
783   sh2->cache_dirty = TRUE;
784
785   sh2->cpu_type = CPU_TYPE_SH2;
786}
787
788/*-------------------------------------------------
789    sh1_reset - reset the processor
790-------------------------------------------------*/
791
792static CPU_RESET( sh1 )
793{
794   sh2_state *sh2 = get_safe_token(device);
795   CPU_RESET_CALL(sh2);
796   sh2->cpu_type = CPU_TYPE_SH1;
797}
798
799/*-------------------------------------------------
800582    code_flush_cache - flush the cache and
801583    regenerate static code
802584-------------------------------------------------*/
803585
804static void code_flush_cache(sh2_state *sh2)
586void sh2_device::code_flush_cache()
805587{
806   drcuml_state *drcuml = sh2->drcuml;
588   drcuml_state *drcuml = m_drcuml;
807589
808590   /* empty the transient cache contents */
809591   drcuml->reset();
r29565r29566
811593   try
812594   {
813595      /* generate the entry point and out-of-cycles handlers */
814      static_generate_nocode_handler(sh2);
815      static_generate_out_of_cycles(sh2);
816      static_generate_entry_point(sh2);
596      static_generate_nocode_handler();
597      static_generate_out_of_cycles();
598      static_generate_entry_point();
817599
818600      /* add subroutines for memory accesses */
819      static_generate_memory_accessor(sh2, 1, FALSE, "read8", &sh2->read8);
820      static_generate_memory_accessor(sh2, 1, TRUE,  "write8", &sh2->write8);
821      static_generate_memory_accessor(sh2, 2, FALSE, "read16", &sh2->read16);
822      static_generate_memory_accessor(sh2, 2, TRUE,  "write16", &sh2->write16);
823      static_generate_memory_accessor(sh2, 4, FALSE, "read32", &sh2->read32);
824      static_generate_memory_accessor(sh2, 4, TRUE,  "write32", &sh2->write32);
601      static_generate_memory_accessor(1, FALSE, "read8", &m_read8);
602      static_generate_memory_accessor(1, TRUE,  "write8", &m_write8);
603      static_generate_memory_accessor(2, FALSE, "read16", &m_read16);
604      static_generate_memory_accessor(2, TRUE,  "write16", &m_write16);
605      static_generate_memory_accessor(4, FALSE, "read32", &m_read32);
606      static_generate_memory_accessor(4, TRUE,  "write32", &m_write32);
825607   }
826608   catch (drcuml_block::abort_compilation &)
827609   {
828610      fatalerror("Unable to generate SH2 static code\n");
829611   }
830612
831   sh2->cache_dirty = FALSE;
613   m_cache_dirty = FALSE;
832614}
833615
834616/* Execute cycles - returns number of cycles actually run */
835static CPU_EXECUTE( sh2 )
617void sh2_device::execute_run_drc()
836618{
837   sh2_state *sh2 = get_safe_token(device);
838   drcuml_state *drcuml = sh2->drcuml;
619   drcuml_state *drcuml = m_drcuml;
839620   int execute_result;
840621
841622   // run any active DMAs now
842623#ifndef USE_TIMER_FOR_DMA
843   for ( int i = 0; i < sh2->icount ; i++)
624   for ( int i = 0; i < m_sh2_state->icount ; i++)
844625   {
845626      for( int dma=0;dma<1;dma++)
846627      {
847         if (sh2->dma_timer_active[dma])
848            sh2_do_dma(sh2, dma);
628         if (m_dma_timer_active[dma])
629            sh2_do_dma(dma);
849630      }
850631   }
851632#endif
852633
853634   /* reset the cache if dirty */
854   if (sh2->cache_dirty)
855      code_flush_cache(sh2);
635   if (m_cache_dirty)
636      code_flush_cache();
856637
857638   /* execute */
858639   do
859640   {
860641      /* run as much as we can */
861      execute_result = drcuml->execute(*sh2->entry);
642      execute_result = drcuml->execute(*m_entry);
862643
863644      /* if we need to recompile, do it */
864645      if (execute_result == EXECUTE_MISSING_CODE)
865646      {
866         code_compile_block(sh2, 0, sh2->pc);
647         code_compile_block(0, m_sh2_state->pc);
867648      }
868649      else if (execute_result == EXECUTE_UNMAPPED_CODE)
869650      {
870         fatalerror("Attempted to execute unmapped code at PC=%08X\n", sh2->pc);
651         fatalerror("Attempted to execute unmapped code at PC=%08X\n", m_sh2_state->pc);
871652      }
872653      else if (execute_result == EXECUTE_RESET_CACHE)
873654      {
874         code_flush_cache(sh2);
655         code_flush_cache();
875656      }
876657   } while (execute_result != EXECUTE_OUT_OF_CYCLES);
877658}
r29565r29566
881662    given mode at the specified pc
882663-------------------------------------------------*/
883664
884static void code_compile_block(sh2_state *sh2, UINT8 mode, offs_t pc)
665void sh2_device::code_compile_block(UINT8 mode, offs_t pc)
885666{
886   drcuml_state *drcuml = sh2->drcuml;
667   drcuml_state *drcuml = m_drcuml;
887668   compiler_state compiler = { 0 };
888669   const opcode_desc *seqhead, *seqlast;
889670   const opcode_desc *desclist;
r29565r29566
893674   g_profiler.start(PROFILER_DRC_COMPILE);
894675
895676   /* get a description of this sequence */
896   desclist = sh2->drcfe->describe_code(pc);
677   desclist = m_drcfe->describe_code(pc);
897678   if (LOG_UML || LOG_NATIVE)
898679      log_opcode_desc(drcuml, desclist, 0);
899680
r29565r29566
937718            else
938719            {
939720               UML_LABEL(block, seqhead->pc | 0x80000000);                             // label   seqhead->pc | 0x80000000
940               UML_HASHJMP(block, 0, seqhead->pc, *sh2->nocode);
721               UML_HASHJMP(block, 0, seqhead->pc, *m_nocode);
941722                                                                     // hashjmp <mode>,seqhead->pc,nocode
942723               continue;
943724            }
944725
945726            /* validate this code block if we're not pointing into ROM */
946            if (sh2->program->get_write_ptr(seqhead->physpc) != NULL)
947               generate_checksum_block(sh2, block, &compiler, seqhead, seqlast);
727            if (m_program->get_write_ptr(seqhead->physpc) != NULL)
728               generate_checksum_block(block, &compiler, seqhead, seqlast);
948729
949730            /* label this instruction, if it may be jumped to locally */
950731            if (seqhead->flags & OPFLAG_IS_BRANCH_TARGET)
r29565r29566
955736            /* iterate over instructions in the sequence and compile them */
956737            for (curdesc = seqhead; curdesc != seqlast->next(); curdesc = curdesc->next())
957738            {
958               generate_sequence_instruction(sh2, block, &compiler, curdesc, 0xffffffff);
739               generate_sequence_instruction(block, &compiler, curdesc, 0xffffffff);
959740            }
960741
961742            /* if we need to return to the start, do it */
r29565r29566
970751            }
971752
972753            /* count off cycles and go there */
973            generate_update_cycles(sh2, block, &compiler, nextpc, TRUE);                // <subtract cycles>
754            generate_update_cycles(block, &compiler, nextpc, TRUE);                // <subtract cycles>
974755
975756            /* SH2 has no modes */
976757            if (seqlast->next() == NULL || seqlast->next()->pc != nextpc)
977758            {
978               UML_HASHJMP(block, 0, nextpc, *sh2->nocode);
759               UML_HASHJMP(block, 0, nextpc, *m_nocode);
979760            }
980761                                                                     // hashjmp <mode>,nextpc,nocode
981762         }
r29565r29566
987768      }
988769      catch (drcuml_block::abort_compilation &)
989770      {
990         code_flush_cache(sh2);
771         code_flush_cache();
991772      }
992773   }
993774}
r29565r29566
997778    static entry point
998779-------------------------------------------------*/
999780
1000static void static_generate_entry_point(sh2_state *sh2)
781void sh2_device::static_generate_entry_point()
1001782{
1002   drcuml_state *drcuml = sh2->drcuml;
783   drcuml_state *drcuml = m_drcuml;
1003784   code_label skip = 1;
1004785   drcuml_block *block;
1005786
r29565r29566
1007788   block = drcuml->begin_block(200);
1008789
1009790   /* forward references */
1010   alloc_handle(drcuml, &sh2->nocode, "nocode");
1011   alloc_handle(drcuml, &sh2->write32, "write32");     // necessary?
1012   alloc_handle(drcuml, &sh2->entry, "entry");
1013   UML_HANDLE(block, *sh2->entry);                         // handle  entry
791   alloc_handle(drcuml, &m_nocode, "nocode");
792   alloc_handle(drcuml, &m_write32, "write32");     // necessary?
793   alloc_handle(drcuml, &m_entry, "entry");
794   UML_HANDLE(block, *m_entry);                         // handle  entry
1014795
1015796   /* load fast integer registers */
1016   load_fast_iregs(sh2, block);
797   load_fast_iregs(block);
1017798
1018799   /* check for interrupts */
1019   UML_MOV(block, mem(&sh2->irqline), 0xffffffff);     // mov irqline, #-1
1020   UML_CMP(block, mem(&sh2->pending_nmi), 0);          // cmp pending_nmi, #0
800   UML_MOV(block, mem(&m_sh2_state->irqline), 0xffffffff);     // mov irqline, #-1
801   UML_CMP(block, mem(&m_sh2_state->pending_nmi), 0);          // cmp pending_nmi, #0
1021802   UML_JMPc(block, COND_Z, skip+2);                    // jz skip+2
1022803
1023   UML_MOV(block, mem(&sh2->pending_nmi), 0);          // zap pending_nmi
804   UML_MOV(block, mem(&m_sh2_state->pending_nmi), 0);          // zap pending_nmi
1024805   UML_JMP(block, skip+1);                     // and then go take it (evec is already set)
1025806
1026807   UML_LABEL(block, skip+2);                   // skip+2:
1027   UML_MOV(block, mem(&sh2->evec), 0xffffffff);        // mov evec, -1
808   UML_MOV(block, mem(&m_sh2_state->evec), 0xffffffff);        // mov evec, -1
1028809   UML_MOV(block, I0, 0xffffffff);         // mov r0, -1 (r0 = irq)
1029810   UML_AND(block, I1,  I0, 0xffff);                // and r1, 0xffff
1030811
1031   UML_LZCNT(block, I1, mem(&sh2->pending_irq));       // lzcnt r1, r1
812   UML_LZCNT(block, I1, mem(&m_sh2_state->pending_irq));       // lzcnt r1, r1
1032813   UML_CMP(block, I1, 32);             // cmp r1, #32
1033814   UML_JMPc(block, COND_Z, skip+4);                    // jz skip+4
1034815
1035   UML_SUB(block, mem(&sh2->irqline), 31, I1);     // sub irqline, #31, r1
816   UML_SUB(block, mem(&m_sh2_state->irqline), 31, I1);     // sub irqline, #31, r1
1036817
1037818   UML_LABEL(block, skip+4);                   // skip+4:
1038   UML_CMP(block, mem(&sh2->internal_irq_level), 0xffffffff);  // cmp internal_irq_level, #-1
819   UML_CMP(block, mem(&m_sh2_state->internal_irq_level), 0xffffffff);  // cmp internal_irq_level, #-1
1039820   UML_JMPc(block, COND_Z, skip+3);                    // jz skip+3
1040   UML_CMP(block, mem(&sh2->internal_irq_level), mem(&sh2->irqline));      // cmp internal_irq_level, irqline
821   UML_CMP(block, mem(&m_sh2_state->internal_irq_level), mem(&m_sh2_state->irqline));      // cmp internal_irq_level, irqline
1041822   UML_JMPc(block, COND_LE, skip+3);                   // jle skip+3
1042823
1043   UML_MOV(block, mem(&sh2->irqline), mem(&sh2->internal_irq_level));      // mov r0, internal_irq_level
824   UML_MOV(block, mem(&m_sh2_state->irqline), mem(&m_sh2_state->internal_irq_level));      // mov r0, internal_irq_level
1044825
1045826   UML_LABEL(block, skip+3);                   // skip+3:
1046   UML_CMP(block, mem(&sh2->irqline), 0xffffffff);     // cmp irqline, #-1
827   UML_CMP(block, mem(&m_sh2_state->irqline), 0xffffffff);     // cmp irqline, #-1
1047828   UML_JMPc(block, COND_Z, skip+1);                    // jz skip+1
1048   UML_CALLC(block, cfunc_fastirq, sh2);               // callc fastirq
829   UML_CALLC(block, cfunc_fastirq, this);               // callc fastirq
1049830
1050831   UML_LABEL(block, skip+1);                   // skip+1:
1051832
1052   UML_CMP(block, mem(&sh2->evec), 0xffffffff);        // cmp evec, 0xffffffff
833   UML_CMP(block, mem(&m_sh2_state->evec), 0xffffffff);        // cmp evec, 0xffffffff
1053834   UML_JMPc(block, COND_Z, skip);                  // jz skip
1054835
1055836   UML_SUB(block, R32(15), R32(15), 4);            // sub R15, R15, #4
1056837   UML_MOV(block, I0, R32(15));                // mov r0, R15
1057   UML_MOV(block, I1, mem(&sh2->irqsr));           // mov r1, irqsr
1058   UML_CALLH(block, *sh2->write32);                    // call write32
838   UML_MOV(block, I1, mem(&m_sh2_state->irqsr));           // mov r1, irqsr
839   UML_CALLH(block, *m_write32);                    // call write32
1059840
1060841   UML_SUB(block, R32(15), R32(15), 4);            // sub R15, R15, #4
1061842   UML_MOV(block, I0, R32(15));                // mov r0, R15
1062   UML_MOV(block, I1, mem(&sh2->pc));              // mov r1, pc
1063   UML_CALLH(block, *sh2->write32);                    // call write32
843   UML_MOV(block, I1, mem(&m_sh2_state->pc));              // mov r1, pc
844   UML_CALLH(block, *m_write32);                    // call write32
1064845
1065   UML_MOV(block, mem(&sh2->pc), mem(&sh2->evec));             // mov pc, evec
846   UML_MOV(block, mem(&m_sh2_state->pc), mem(&m_sh2_state->evec));             // mov pc, evec
1066847
1067848   UML_LABEL(block, skip);                         // skip:
1068849
1069850   /* generate a hash jump via the current mode and PC */
1070   UML_HASHJMP(block, 0, mem(&sh2->pc), *sh2->nocode);     // hashjmp <mode>,<pc>,nocode
851   UML_HASHJMP(block, 0, mem(&m_sh2_state->pc), *m_nocode);     // hashjmp <mode>,<pc>,nocode
1071852
1072853   block->end();
1073854}
r29565r29566
1077858    exception handler for "out of code"
1078859-------------------------------------------------*/
1079860
1080static void static_generate_nocode_handler(sh2_state *sh2)
861void sh2_device::static_generate_nocode_handler()
1081862{
1082   drcuml_state *drcuml = sh2->drcuml;
863   drcuml_state *drcuml = m_drcuml;
1083864   drcuml_block *block;
1084865
1085866   /* begin generating */
1086867   block = drcuml->begin_block(10);
1087868
1088869   /* generate a hash jump via the current mode and PC */
1089   alloc_handle(drcuml, &sh2->nocode, "nocode");
1090   UML_HANDLE(block, *sh2->nocode);                                    // handle  nocode
870   alloc_handle(drcuml, &m_nocode, "nocode");
871   UML_HANDLE(block, *m_nocode);                                    // handle  nocode
1091872   UML_GETEXP(block, I0);                                  // getexp  i0
1092   UML_MOV(block, mem(&sh2->pc), I0);                              // mov     [pc],i0
1093   save_fast_iregs(sh2, block);
873   UML_MOV(block, mem(&m_sh2_state->pc), I0);                              // mov     [pc],i0
874   save_fast_iregs(block);
1094875   UML_EXIT(block, EXECUTE_MISSING_CODE);                          // exit    EXECUTE_MISSING_CODE
1095876
1096877   block->end();
r29565r29566
1102883    out of cycles exception handler
1103884-------------------------------------------------*/
1104885
1105static void static_generate_out_of_cycles(sh2_state *sh2)
886void sh2_device::static_generate_out_of_cycles()
1106887{
1107   drcuml_state *drcuml = sh2->drcuml;
888   drcuml_state *drcuml = m_drcuml;
1108889   drcuml_block *block;
1109890
1110891   /* begin generating */
1111892   block = drcuml->begin_block(10);
1112893
1113894   /* generate a hash jump via the current mode and PC */
1114   alloc_handle(drcuml, &sh2->out_of_cycles, "out_of_cycles");
1115   UML_HANDLE(block, *sh2->out_of_cycles);                             // handle  out_of_cycles
895   alloc_handle(drcuml, &m_out_of_cycles, "out_of_cycles");
896   UML_HANDLE(block, *m_out_of_cycles);                             // handle  out_of_cycles
1116897   UML_GETEXP(block, I0);                                  // getexp  i0
1117   UML_MOV(block, mem(&sh2->pc), I0);                              // mov     <pc>,i0
1118   save_fast_iregs(sh2,block);
898   UML_MOV(block, mem(&m_sh2_state->pc), I0);                              // mov     <pc>,i0
899   save_fast_iregs(block);
1119900   UML_EXIT(block, EXECUTE_OUT_OF_CYCLES);                         // exit    EXECUTE_OUT_OF_CYCLES
1120901
1121902   block->end();
r29565r29566
1125906    static_generate_memory_accessor
1126907------------------------------------------------------------------*/
1127908
1128static void static_generate_memory_accessor(sh2_state *sh2, int size, int iswrite, const char *name, code_handle **handleptr)
909void sh2_device::static_generate_memory_accessor(int size, int iswrite, const char *name, code_handle **handleptr)
1129910{
1130911   /* on entry, address is in I0; data for writes is in I1 */
1131912   /* on exit, read result is in I0 */
1132913   /* routine trashes I0 */
1133   drcuml_state *drcuml = sh2->drcuml;
914   drcuml_state *drcuml = m_drcuml;
1134915   drcuml_block *block;
1135916   int label = 1;
1136917
r29565r29566
1156937#if 0   // DO NOT ENABLE - SEVERE AARON DAMAGE
1157938   for (int ramnum = 0; ramnum < SH2_MAX_FASTRAM; ramnum++)
1158939   {
1159      if (sh2->fastram[ramnum].base != NULL && (!iswrite || !sh2->fastram[ramnum].readonly))
940      if (m_fastram[ramnum].base != NULL && (!iswrite || !m_fastram[ramnum].readonly))
1160941      {
1161         void *fastbase = (UINT8 *)sh2->fastram[ramnum].base - sh2->fastram[ramnum].start;
942         void *fastbase = (UINT8 *)m_fastram[ramnum].base - m_fastram[ramnum].start;
1162943         UINT32 skip = label++;
1163         if (sh2->fastram[ramnum].end != 0xffffffff)
944         if (m_fastram[ramnum].end != 0xffffffff)
1164945         {
1165            UML_CMP(block, I0, sh2->fastram[ramnum].end);   // cmp     i0,end
946            UML_CMP(block, I0, m_fastram[ramnum].end);   // cmp     i0,end
1166947            UML_JMPc(block, COND_A, skip);                                      // ja      skip
1167948         }
1168         if (sh2->fastram[ramnum].start != 0x00000000)
949         if (m_fastram[ramnum].start != 0x00000000)
1169950         {
1170            UML_CMP(block, I0, sh2->fastram[ramnum].start);// cmp     i0,fastram_start
951            UML_CMP(block, I0, m_fastram[ramnum].start);// cmp     i0,fastram_start
1171952            UML_JMPc(block, COND_B, skip);                                      // jb      skip
1172953         }
1173954
r29565r29566
12591040    flags
12601041-------------------------------------------------*/
12611042
1262static const char *log_desc_flags_to_string(UINT32 flags)
1043const char *sh2_device::log_desc_flags_to_string(UINT32 flags)
12631044{
12641045   static char tempbuf[30];
12651046   char *dest = tempbuf;
r29565r29566
13131094    log_register_list - log a list of GPR registers
13141095-------------------------------------------------*/
13151096
1316static void log_register_list(drcuml_state *drcuml, const char *string, const UINT32 *reglist, const UINT32 *regnostarlist)
1097void sh2_device::log_register_list(drcuml_state *drcuml, const char *string, const UINT32 *reglist, const UINT32 *regnostarlist)
13171098{
13181099   int count = 0;
13191100   int regnum;
r29565r29566
13831164    log_opcode_desc - log a list of descriptions
13841165-------------------------------------------------*/
13851166
1386static void log_opcode_desc(drcuml_state *drcuml, const opcode_desc *desclist, int indent)
1167void sh2_device::log_opcode_desc(drcuml_state *drcuml, const opcode_desc *desclist, int indent)
13871168{
13881169   /* open the file, creating it if necessary */
13891170   if (indent == 0)
r29565r29566
14251206    including disassembly of an SH2 instruction
14261207-------------------------------------------------*/
14271208
1428static void log_add_disasm_comment(drcuml_block *block, UINT32 pc, UINT32 op)
1209void sh2_device::log_add_disasm_comment(drcuml_block *block, UINT32 pc, UINT32 op)
14291210{
14301211#if (LOG_UML)
14311212   char buffer[100];
r29565r29566
14391220    subtract cycles from the icount and generate
14401221    an exception if out
14411222-------------------------------------------------*/
1442static void generate_update_cycles(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, parameter param, int allow_exception)
1223void sh2_device::generate_update_cycles(drcuml_block *block, compiler_state *compiler, parameter param, int allow_exception)
14431224{
14441225   /* check full interrupts if pending */
14451226   if (compiler->checkints)
r29565r29566
14501231      compiler->labelnum += 4;
14511232
14521233      /* check for interrupts */
1453      UML_MOV(block, mem(&sh2->irqline), 0xffffffff);     // mov irqline, #-1
1454      UML_CMP(block, mem(&sh2->pending_nmi), 0);          // cmp pending_nmi, #0
1234      UML_MOV(block, mem(&m_sh2_state->irqline), 0xffffffff);     // mov irqline, #-1
1235      UML_CMP(block, mem(&m_sh2_state->pending_nmi), 0);          // cmp pending_nmi, #0
14551236      UML_JMPc(block, COND_Z, skip+2);                    // jz skip+2
14561237
1457      UML_MOV(block, mem(&sh2->pending_nmi), 0);          // zap pending_nmi
1238      UML_MOV(block, mem(&m_sh2_state->pending_nmi), 0);          // zap pending_nmi
14581239      UML_JMP(block, skip+1);                     // and then go take it (evec is already set)
14591240
14601241      UML_LABEL(block, skip+2);                   // skip+2:
1461      UML_MOV(block, mem(&sh2->evec), 0xffffffff);        // mov evec, -1
1242      UML_MOV(block, mem(&m_sh2_state->evec), 0xffffffff);        // mov evec, -1
14621243      UML_MOV(block, I0, 0xffffffff);         // mov r0, -1 (r0 = irq)
14631244      UML_AND(block, I1,  I0, 0xffff);                // and r1, r0, 0xffff
14641245
1465      UML_LZCNT(block, I1, mem(&sh2->pending_irq));       // lzcnt r1, pending_irq
1246      UML_LZCNT(block, I1, mem(&m_sh2_state->pending_irq));       // lzcnt r1, pending_irq
14661247      UML_CMP(block, I1, 32);             // cmp r1, #32
14671248      UML_JMPc(block, COND_Z, skip+4);                    // jz skip+4
14681249
1469      UML_SUB(block, mem(&sh2->irqline), 31, I1);     // sub irqline, #31, r1
1250      UML_SUB(block, mem(&m_sh2_state->irqline), 31, I1);     // sub irqline, #31, r1
14701251
14711252      UML_LABEL(block, skip+4);                   // skip+4:
1472      UML_CMP(block, mem(&sh2->internal_irq_level), 0xffffffff);  // cmp internal_irq_level, #-1
1253      UML_CMP(block, mem(&m_sh2_state->internal_irq_level), 0xffffffff);  // cmp internal_irq_level, #-1
14731254      UML_JMPc(block, COND_Z, skip+3);                    // jz skip+3
1474      UML_CMP(block, mem(&sh2->internal_irq_level), mem(&sh2->irqline));      // cmp internal_irq_level, irqline
1255      UML_CMP(block, mem(&m_sh2_state->internal_irq_level), mem(&m_sh2_state->irqline));      // cmp internal_irq_level, irqline
14751256      UML_JMPc(block, COND_LE, skip+3);                   // jle skip+3
14761257
1477      UML_MOV(block, mem(&sh2->irqline), mem(&sh2->internal_irq_level));      // mov r0, internal_irq_level
1258      UML_MOV(block, mem(&m_sh2_state->irqline), mem(&m_sh2_state->internal_irq_level));      // mov r0, internal_irq_level
14781259
14791260      UML_LABEL(block, skip+3);                   // skip+3:
1480      UML_CMP(block, mem(&sh2->irqline), 0xffffffff);     // cmp irqline, #-1
1261      UML_CMP(block, mem(&m_sh2_state->irqline), 0xffffffff);     // cmp irqline, #-1
14811262      UML_JMPc(block, COND_Z, skip+1);                    // jz skip+1
1482      UML_CALLC(block, cfunc_fastirq, sh2);               // callc fastirq
1263      UML_CALLC(block, cfunc_fastirq, this);               // callc fastirq
14831264
14841265      UML_LABEL(block, skip+1);                   // skip+1:
1485      UML_CMP(block, mem(&sh2->evec), 0xffffffff);        // cmp evec, 0xffffffff
1266      UML_CMP(block, mem(&m_sh2_state->evec), 0xffffffff);        // cmp evec, 0xffffffff
14861267      UML_JMPc(block, COND_Z, skip);                  // jz skip
14871268
14881269      UML_SUB(block, R32(15), R32(15), 4);            // sub R15, R15, #4
14891270      UML_MOV(block, I0, R32(15));                // mov r0, R15
1490      UML_MOV(block, I1, mem(&sh2->irqsr));           // mov r1, irqsr
1491      UML_CALLH(block, *sh2->write32);                    // call write32
1271      UML_MOV(block, I1, mem(&m_sh2_state->irqsr));           // mov r1, irqsr
1272      UML_CALLH(block, *m_write32);                    // call write32
14921273
14931274      UML_SUB(block, R32(15), R32(15), 4);            // sub R15, R15, #4
14941275      UML_MOV(block, I0, R32(15));                // mov r0, R15
14951276      UML_MOV(block, I1, param);              // mov r1, nextpc
1496      UML_CALLH(block, *sh2->write32);                    // call write32
1277      UML_CALLH(block, *m_write32);                    // call write32
14971278
1498      UML_HASHJMP(block, 0, mem(&sh2->evec), *sh2->nocode);       // hashjmp sh2->evec
1279      UML_HASHJMP(block, 0, mem(&m_sh2_state->evec), *m_nocode);       // hashjmp m_sh2_state->evec
14991280
15001281      UML_LABEL(block, skip);                         // skip:
15011282   }
r29565r29566
15031284   /* account for cycles */
15041285   if (compiler->cycles > 0)
15051286   {
1506      UML_SUB(block, mem(&sh2->icount), mem(&sh2->icount), MAPVAR_CYCLES);    // sub     icount,icount,cycles
1287      UML_SUB(block, mem(&m_sh2_state->icount), mem(&m_sh2_state->icount), MAPVAR_CYCLES);    // sub     icount,icount,cycles
15071288      UML_MAPVAR(block, MAPVAR_CYCLES, 0);                                        // mapvar  cycles,0
15081289      if (allow_exception)
1509         UML_EXHc(block, COND_S, *sh2->out_of_cycles, param);
1290         UML_EXHc(block, COND_S, *m_out_of_cycles, param);
15101291                                                               // exh     out_of_cycles,nextpc
15111292   }
15121293   compiler->cycles = 0;
r29565r29566
15171298    validate a sequence of opcodes
15181299-------------------------------------------------*/
15191300
1520static void generate_checksum_block(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *seqhead, const opcode_desc *seqlast)
1301void sh2_device::generate_checksum_block(drcuml_block *block, compiler_state *compiler, const opcode_desc *seqhead, const opcode_desc *seqlast)
15211302{
15221303   const opcode_desc *curdesc;
15231304   if (LOG_UML)
15241305      block->append_comment("[Validation for %08X]", seqhead->pc);                // comment
15251306
15261307   /* loose verify or single instruction: just compare and fail */
1527   if (!(sh2->drcoptions & SH2DRC_STRICT_VERIFY) || seqhead->next() == NULL)
1308   if (!(m_drcoptions & SH2DRC_STRICT_VERIFY) || seqhead->next() == NULL)
15281309   {
15291310      if (!(seqhead->flags & OPFLAG_VIRTUAL_NOOP))
15301311      {
1531         void *base = sh2->direct->read_decrypted_ptr(seqhead->physpc, SH2_CODE_XOR(0));
1312         void *base = m_direct->read_decrypted_ptr(seqhead->physpc, SH2_CODE_XOR(0));
15321313         UML_LOAD(block, I0, base, 0, SIZE_WORD, SCALE_x2);                          // load    i0,base,word
15331314         UML_CMP(block, I0, seqhead->opptr.w[0]);                        // cmp     i0,*opptr
1534         UML_EXHc(block, COND_NE, *sh2->nocode, epc(seqhead));       // exne    nocode,seqhead->pc
1315         UML_EXHc(block, COND_NE, *m_nocode, epc(seqhead));       // exne    nocode,seqhead->pc
15351316      }
15361317   }
15371318
r29565r29566
15421323      for (curdesc = seqhead->next(); curdesc != seqlast->next(); curdesc = curdesc->next())
15431324         if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP))
15441325         {
1545            base = sh2->direct->read_decrypted_ptr(curdesc->physpc, SH2_CODE_XOR(0));
1326            base = m_direct->read_decrypted_ptr(curdesc->physpc, SH2_CODE_XOR(0));
15461327            UML_LOAD(block, I0, curdesc->opptr.w, 0, SIZE_WORD, SCALE_x2);          // load    i0,*opptr,0,word
15471328            UML_CMP(block, I0, curdesc->opptr.w[0]);                    // cmp     i0,*opptr
1548            UML_EXHc(block, COND_NE, *sh2->nocode, epc(seqhead));   // exne    nocode,seqhead->pc
1329            UML_EXHc(block, COND_NE, *m_nocode, epc(seqhead));   // exne    nocode,seqhead->pc
15491330         }
15501331#else
15511332      UINT32 sum = 0;
1552      void *base = sh2->direct->read_decrypted_ptr(seqhead->physpc, SH2_CODE_XOR(0));
1333      void *base = m_direct->read_decrypted_ptr(seqhead->physpc, SH2_CODE_XOR(0));
15531334      UML_LOAD(block, I0, base, 0, SIZE_WORD, SCALE_x4);                              // load    i0,base,word
15541335      sum += seqhead->opptr.w[0];
15551336      for (curdesc = seqhead->next(); curdesc != seqlast->next(); curdesc = curdesc->next())
15561337         if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP))
15571338         {
1558            base = sh2->direct->read_decrypted_ptr(curdesc->physpc, SH2_CODE_XOR(0));
1339            base = m_direct->read_decrypted_ptr(curdesc->physpc, SH2_CODE_XOR(0));
15591340            UML_LOAD(block, I1, base, 0, SIZE_WORD, SCALE_x2);                      // load    i1,*opptr,word
15601341            UML_ADD(block, I0, I0, I1);                         // add     i0,i0,i1
15611342            sum += curdesc->opptr.w[0];
15621343         }
15631344      UML_CMP(block, I0, sum);                                            // cmp     i0,sum
1564      UML_EXHc(block, COND_NE, *sh2->nocode, epc(seqhead));           // exne    nocode,seqhead->pc
1345      UML_EXHc(block, COND_NE, *m_nocode, epc(seqhead));           // exne    nocode,seqhead->pc
15651346#endif
15661347   }
15671348}
r29565r29566
15721353    for a single instruction in a sequence
15731354-------------------------------------------------*/
15741355
1575static void generate_sequence_instruction(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc)
1356void sh2_device::generate_sequence_instruction(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc)
15761357{
15771358   offs_t expc;
15781359
r29565r29566
15931374   /* if we want a probe, add it here */
15941375   if (desc->pc == PROBE_ADDRESS)
15951376   {
1596      UML_MOV(block, mem(&sh2->pc), desc->pc);                                // mov     [pc],desc->pc
1597      UML_CALLC(block, cfunc_printf_probe, sh2);                                  // callc   cfunc_printf_probe,sh2
1377      UML_MOV(block, mem(&m_sh2_state->pc), desc->pc);                                // mov     [pc],desc->pc
1378      UML_CALLC(block, cfunc_printf_probe, this);                                  // callc   cfunc_printf_probe,sh2
15981379   }
15991380
16001381   /* if we are debugging, call the debugger */
1601   if ((sh2->device->machine().debug_flags & DEBUG_FLAG_ENABLED) != 0)
1382   if ((machine().debug_flags & DEBUG_FLAG_ENABLED) != 0)
16021383   {
1603      UML_MOV(block, mem(&sh2->pc), desc->pc);                                // mov     [pc],desc->pc
1604      save_fast_iregs(sh2, block);
1384      UML_MOV(block, mem(&m_sh2_state->pc), desc->pc);                                // mov     [pc],desc->pc
1385      save_fast_iregs(block);
16051386      UML_DEBUG(block, desc->pc);                                         // debug   desc->pc
16061387   }
16071388   else    // not debug, see what other reasons there are for flushing the PC
16081389   {
1609      if (sh2->drcoptions & SH2DRC_FLUSH_PC)  // always flush?
1390      if (m_drcoptions & SH2DRC_FLUSH_PC)  // always flush?
16101391      {
1611         UML_MOV(block, mem(&sh2->pc), desc->pc);        // mov sh2->pc, desc->pc
1392         UML_MOV(block, mem(&m_sh2_state->pc), desc->pc);        // mov m_sh2_state->pc, desc->pc
16121393      }
16131394      else    // check for driver-selected flushes
16141395      {
16151396         int pcflush;
16161397
1617         for (pcflush = 0; pcflush < sh2->pcfsel; pcflush++)
1398         for (pcflush = 0; pcflush < m_pcfsel; pcflush++)
16181399         {
1619            if (desc->pc == sh2->pcflushes[pcflush])
1400            if (desc->pc == m_pcflushes[pcflush])
16201401            {
1621               UML_MOV(block, mem(&sh2->pc), desc->pc);        // mov sh2->pc, desc->pc
1402               UML_MOV(block, mem(&m_sh2_state->pc), desc->pc);        // mov m_sh2_state->pc, desc->pc
16221403            }
16231404         }
16241405      }
r29565r29566
16281409   /* if we hit an unmapped address, fatal error */
16291410   if (desc->flags & OPFLAG_COMPILER_UNMAPPED)
16301411   {
1631      UML_MOV(block, mem(&sh2->pc), desc->pc);                                // mov     [pc],desc->pc
1632      save_fast_iregs(sh2, block);
1412      UML_MOV(block, mem(&m_sh2_state->pc), desc->pc);                                // mov     [pc],desc->pc
1413      save_fast_iregs(block);
16331414      UML_EXIT(block, EXECUTE_UNMAPPED_CODE);                             // exit    EXECUTE_UNMAPPED_CODE
16341415   }
16351416
r29565r29566
16431424   else if (!(desc->flags & OPFLAG_VIRTUAL_NOOP))
16441425   {
16451426      /* compile the instruction */
1646      if (!generate_opcode(sh2, block, compiler, desc, ovrpc))
1427      if (!generate_opcode(block, compiler, desc, ovrpc))
16471428      {
16481429         // handle an illegal op
1649         UML_MOV(block, mem(&sh2->pc), desc->pc);                            // mov     [pc],desc->pc
1650         UML_MOV(block, mem(&sh2->arg0), desc->opptr.w[0]);                  // mov     [arg0],opcode
1651         UML_CALLC(block, cfunc_unimplemented, sh2);                             // callc   cfunc_unimplemented
1430         UML_MOV(block, mem(&m_sh2_state->pc), desc->pc);                            // mov     [pc],desc->pc
1431         UML_MOV(block, mem(&m_sh2_state->arg0), desc->opptr.w[0]);                  // mov     [arg0],opcode
1432         UML_CALLC(block, cfunc_unimplemented, this);                             // callc   cfunc_unimplemented
16521433      }
16531434   }
16541435}
r29565r29566
16571438    generate_delay_slot
16581439------------------------------------------------------------------*/
16591440
1660static void generate_delay_slot(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc)
1441void sh2_device::generate_delay_slot(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc)
16611442{
16621443   compiler_state compiler_temp = *compiler;
16631444
16641445   /* compile the delay slot using temporary compiler state */
16651446   assert(desc->delay.first() != NULL);
1666   generate_sequence_instruction(sh2, block, &compiler_temp, desc->delay.first(), ovrpc);              // <next instruction>
1447   generate_sequence_instruction(block, &compiler_temp, desc->delay.first(), ovrpc);              // <next instruction>
16671448
16681449   /* update the label */
16691450   compiler->labelnum = compiler_temp.labelnum;
r29565r29566
16741455    opcode
16751456-------------------------------------------------*/
16761457
1677static int generate_opcode(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc)
1458int sh2_device::generate_opcode(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT32 ovrpc)
16781459{
16791460   UINT32 scratch, scratch2;
16801461   INT32 disp;
r29565r29566
16851466   switch (opswitch)
16861467   {
16871468      case  0:
1688         return generate_group_0(sh2, block, compiler, desc, opcode, in_delay_slot, ovrpc);
1469         return generate_group_0(block, compiler, desc, opcode, in_delay_slot, ovrpc);
16891470
16901471      case  1:    // MOVLS4
16911472         scratch = (opcode & 0x0f) * 4;
16921473         UML_ADD(block, I0, R32(Rn), scratch);   // add r0, Rn, scratch
16931474         UML_MOV(block, I1, R32(Rm));        // mov r1, Rm
16941475         SETEA(0);                       // set ea for debug
1695         UML_CALLH(block, *sh2->write32);
1476         UML_CALLH(block, *m_write32);
16961477
16971478         if (!in_delay_slot)
1698            generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1479            generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
16991480         return TRUE;
17001481
17011482      case  2:
1702         return generate_group_2(sh2, block, compiler, desc, opcode, in_delay_slot, ovrpc);
1483         return generate_group_2(block, compiler, desc, opcode, in_delay_slot, ovrpc);
17031484      case  3:
1704         return generate_group_3(sh2, block, compiler, desc, opcode, ovrpc);
1485         return generate_group_3(block, compiler, desc, opcode, ovrpc);
17051486      case  4:
1706         return generate_group_4(sh2, block, compiler, desc, opcode, in_delay_slot, ovrpc);
1487         return generate_group_4(block, compiler, desc, opcode, in_delay_slot, ovrpc);
17071488
17081489      case  5:    // MOVLL4
17091490         scratch = (opcode & 0x0f) * 4;
17101491         UML_ADD(block, I0, R32(Rm), scratch);       // add r0, Rm, scratch
17111492         SETEA(0);                       // set ea for debug
1712         UML_CALLH(block, *sh2->read32);             // call read32
1493         UML_CALLH(block, *m_read32);             // call read32
17131494         UML_MOV(block, R32(Rn), I0);            // mov Rn, r0
17141495
17151496         if (!in_delay_slot)
1716            generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1497            generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
17171498         return TRUE;
17181499
17191500      case  6:
1720         return generate_group_6(sh2, block, compiler, desc, opcode, in_delay_slot, ovrpc);
1501         return generate_group_6(block, compiler, desc, opcode, in_delay_slot, ovrpc);
17211502
17221503      case  7:    // ADDI
17231504         scratch = opcode & 0xff;
r29565r29566
17261507         return TRUE;
17271508
17281509      case  8:
1729         return generate_group_8(sh2, block, compiler, desc, opcode, in_delay_slot, ovrpc);
1510         return generate_group_8(block, compiler, desc, opcode, in_delay_slot, ovrpc);
17301511
17311512      case  9:    // MOVWI
17321513         if (ovrpc == 0xffffffff)
r29565r29566
17381519            scratch = (ovrpc + 2) + ((opcode & 0xff) * 2) + 2;
17391520         }
17401521
1741         if (sh2->drcoptions & SH2DRC_STRICT_PCREL)
1522         if (m_drcoptions & SH2DRC_STRICT_PCREL)
17421523         {
17431524            UML_MOV(block, I0, scratch);            // mov r0, scratch
17441525            SETEA(0);                       // set ea for debug
1745            UML_CALLH(block, *sh2->read16);             // read16(r0, r1)
1526            UML_CALLH(block, *m_read16);             // read16(r0, r1)
17461527            UML_SEXT(block, R32(Rn), I0, SIZE_WORD);            // sext Rn, r0, WORD
17471528         }
17481529         else
17491530         {
1750            scratch2 = (UINT32)(INT32)(INT16) RW(sh2, scratch);
1531            scratch2 = (UINT32)(INT32)(INT16) RW(scratch);
17511532            UML_MOV(block, R32(Rn), scratch2);          // mov Rn, scratch2
17521533         }
17531534
17541535         if (!in_delay_slot)
1755            generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1536            generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
17561537         return TRUE;
17571538
17581539      case 10:    // BRA
17591540         disp = ((INT32)opcode << 20) >> 20;
1760         sh2->ea = (desc->pc + 2) + disp * 2 + 2;            // sh2->ea = pc+4 + disp*2 + 2
1541         m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2;            // m_sh2_state->ea = pc+4 + disp*2 + 2
17611542
1762         generate_delay_slot(sh2, block, compiler, desc, sh2->ea-2);
1543         generate_delay_slot(block, compiler, desc, m_sh2_state->ea-2);
17631544
1764         generate_update_cycles(sh2, block, compiler, sh2->ea, TRUE);    // <subtract cycles>
1765         UML_HASHJMP(block, 0, sh2->ea, *sh2->nocode);   // hashjmp sh2->ea
1545         generate_update_cycles(block, compiler, m_sh2_state->ea, TRUE);    // <subtract cycles>
1546         UML_HASHJMP(block, 0, m_sh2_state->ea, *m_nocode);   // hashjmp m_sh2_state->ea
17661547         return TRUE;
17671548
17681549      case 11:    // BSR
17691550         // panicstr @ 403da22 relies on the delay slot clobbering the PR set by a BSR, so
17701551         // do this before running the delay slot
1771         UML_ADD(block, mem(&sh2->pr), desc->pc, 4); // add sh2->pr, desc->pc, #4 (skip the current insn & delay slot)
1552         UML_ADD(block, mem(&m_sh2_state->pr), desc->pc, 4); // add m_pr, desc->pc, #4 (skip the current insn & delay slot)
17721553
17731554         disp = ((INT32)opcode << 20) >> 20;
1774         sh2->ea = (desc->pc + 2) + disp * 2 + 2;            // sh2->ea = pc+4 + disp*2 + 2
1555         m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2;            // m_sh2_state->ea = pc+4 + disp*2 + 2
17751556
1776         generate_delay_slot(sh2, block, compiler, desc, sh2->ea-2);
1557         generate_delay_slot(block, compiler, desc, m_sh2_state->ea-2);
17771558
1778         generate_update_cycles(sh2, block, compiler, sh2->ea, TRUE);    // <subtract cycles>
1779         UML_HASHJMP(block, 0, sh2->ea, *sh2->nocode);   // hashjmp sh2->ea
1559         generate_update_cycles(block, compiler, m_sh2_state->ea, TRUE);    // <subtract cycles>
1560         UML_HASHJMP(block, 0, m_sh2_state->ea, *m_nocode);   // hashjmp m_sh2_state->ea
17801561         return TRUE;
17811562
17821563      case 12:
1783         return generate_group_12(sh2, block, compiler, desc, opcode, in_delay_slot, ovrpc);
1564         return generate_group_12(block, compiler, desc, opcode, in_delay_slot, ovrpc);
17841565
17851566      case 13:    // MOVLI
17861567         if (ovrpc == 0xffffffff)
r29565r29566
17921573            scratch = ((ovrpc + 4) & ~3) + ((opcode & 0xff) * 4);
17931574         }
17941575
1795         if (sh2->drcoptions & SH2DRC_STRICT_PCREL)
1576         if (m_drcoptions & SH2DRC_STRICT_PCREL)
17961577         {
17971578            UML_MOV(block, I0, scratch);            // mov r0, scratch
1798            UML_CALLH(block, *sh2->read32);             // read32(r0, r1)
1579            UML_CALLH(block, *m_read32);             // read32(r0, r1)
17991580            UML_MOV(block, R32(Rn), I0);            // mov Rn, r0
18001581         }
18011582         else
18021583         {
1803            scratch2 = RL(sh2, scratch);
1584            scratch2 = RL(scratch);
18041585            UML_MOV(block, R32(Rn), scratch2);          // mov Rn, scratch2
18051586         }
18061587
18071588         if (!in_delay_slot)
1808            generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1589            generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
18091590         return TRUE;
18101591
18111592      case 14:    // MOVI
r29565r29566
18211602   return FALSE;
18221603}
18231604
1824static int generate_group_0(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
1605int sh2_device::generate_group_0(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
18251606{
18261607   switch (opcode & 0x3F)
18271608   {
r29565r29566
18461627      return TRUE;
18471628
18481629   case 0x02: // STCSR(Rn);
1849      UML_MOV(block, R32(Rn), mem(&sh2->sr));
1630      UML_MOV(block, R32(Rn), mem(&m_sh2_state->sr));
18501631      return TRUE;
18511632
18521633   case 0x03: // BSRF(Rn);
1853      if (sh2->cpu_type > CPU_TYPE_SH1)
1634      if (m_cpu_type > CPU_TYPE_SH1)
18541635      {
1855         UML_ADD(block, mem(&sh2->target), R32(Rn), 4);  // add target, Rm, #4
1856         UML_ADD(block, mem(&sh2->target), mem(&sh2->target), desc->pc); // add target, target, pc
1636         UML_ADD(block, mem(&m_sh2_state->target), R32(Rn), 4);  // add target, Rm, #4
1637         UML_ADD(block, mem(&m_sh2_state->target), mem(&m_sh2_state->target), desc->pc); // add target, target, pc
18571638
18581639         // 32x Cosmic Carnage @ 6002cb0 relies on the delay slot
18591640         // clobbering the calculated PR, so do it first
1860         UML_ADD(block, mem(&sh2->pr), desc->pc, 4); // add sh2->pr, desc->pc, #4 (skip the current insn & delay slot)
1641         UML_ADD(block, mem(&m_sh2_state->pr), desc->pc, 4); // add m_pr, desc->pc, #4 (skip the current insn & delay slot)
18611642
1862         generate_delay_slot(sh2, block, compiler, desc, sh2->target);
1643         generate_delay_slot(block, compiler, desc, m_sh2_state->target);
18631644
1864         generate_update_cycles(sh2, block, compiler, mem(&sh2->target), TRUE);  // <subtract cycles>
1865         UML_HASHJMP(block, 0, mem(&sh2->target), *sh2->nocode); // jmp target
1645         generate_update_cycles(block, compiler, mem(&m_sh2_state->target), TRUE);  // <subtract cycles>
1646         UML_HASHJMP(block, 0, mem(&m_sh2_state->target), *m_nocode); // jmp target
18661647         return TRUE;
18671648      }
18681649      break;
r29565r29566
18731654   case 0x34: // MOVBS0(Rm, Rn);
18741655      UML_ADD(block, I0, R32(0), R32(Rn));        // add r0, R0, Rn
18751656      UML_AND(block, I1, R32(Rm), 0x000000ff);    // and r1, Rm, 0xff
1876      UML_CALLH(block, *sh2->write8);             // call write8
1657      UML_CALLH(block, *m_write8);             // call write8
18771658
18781659      if (!in_delay_slot)
1879         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1660         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
18801661      return TRUE;
18811662
18821663   case 0x05: // MOVWS0(Rm, Rn);
r29565r29566
18851666   case 0x35: // MOVWS0(Rm, Rn);
18861667      UML_ADD(block, I0, R32(0), R32(Rn));        // add r0, R0, Rn
18871668      UML_AND(block, I1, R32(Rm), 0x0000ffff);    // and r1, Rm, 0xffff
1888      UML_CALLH(block, *sh2->write16);                // call write16
1669      UML_CALLH(block, *m_write16);                // call write16
18891670
18901671      if (!in_delay_slot)
1891         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1672         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
18921673      return TRUE;
18931674
18941675   case 0x06: // MOVLS0(Rm, Rn);
r29565r29566
18971678   case 0x36: // MOVLS0(Rm, Rn);
18981679      UML_ADD(block, I0, R32(0), R32(Rn));        // add r0, R0, Rn
18991680      UML_MOV(block, I1, R32(Rm));            // mov r1, Rm
1900      UML_CALLH(block, *sh2->write32);                // call write32
1681      UML_CALLH(block, *m_write32);                // call write32
19011682
19021683      if (!in_delay_slot)
1903         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1684         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
19041685      return TRUE;
19051686
19061687   case 0x07: // MULL(Rm, Rn);
19071688   case 0x17: // MULL(Rm, Rn);
19081689   case 0x27: // MULL(Rm, Rn);
19091690   case 0x37: // MULL(Rm, Rn);
1910      if (sh2->cpu_type > CPU_TYPE_SH1)
1691      if (m_cpu_type > CPU_TYPE_SH1)
19111692      {
1912         UML_MULU(block, mem(&sh2->macl), mem(&sh2->ea), R32(Rn), R32(Rm));  // mulu macl, ea, Rn, Rm
1693         UML_MULU(block, mem(&m_sh2_state->macl), mem(&m_sh2_state->ea), R32(Rn), R32(Rm));  // mulu macl, ea, Rn, Rm
19131694         return TRUE;
19141695      }
19151696      break;
19161697
19171698   case 0x08: // CLRT();
1918      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and r0, sr, ~T (clear the T bit)
1699      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and r0, sr, ~T (clear the T bit)
19191700      return TRUE;
19201701
19211702   case 0x0a: // STSMACH(Rn);
1922      UML_MOV(block, R32(Rn), mem(&sh2->mach));       // mov Rn, mach
1703      UML_MOV(block, R32(Rn), mem(&m_sh2_state->mach));       // mov Rn, mach
19231704      return TRUE;
19241705
19251706   case 0x0b: // RTS();
1926      UML_MOV(block, mem(&sh2->target), mem(&sh2->pr));   // mov target, pr (in case of d-slot shenanigans)
1707      UML_MOV(block, mem(&m_sh2_state->target), mem(&m_sh2_state->pr));   // mov target, pr (in case of d-slot shenanigans)
19271708
1928      generate_delay_slot(sh2, block, compiler, desc, sh2->target);
1709      generate_delay_slot(block, compiler, desc, m_sh2_state->target);
19291710
1930      generate_update_cycles(sh2, block, compiler, mem(&sh2->target), TRUE);  // <subtract cycles>
1931      UML_HASHJMP(block, 0, mem(&sh2->target), *sh2->nocode);
1711      generate_update_cycles(block, compiler, mem(&m_sh2_state->target), TRUE);  // <subtract cycles>
1712      UML_HASHJMP(block, 0, mem(&m_sh2_state->target), *m_nocode);
19321713      return TRUE;
19331714
19341715   case 0x0c: // MOVBL0(Rm, Rn);
r29565r29566
19361717   case 0x2c: // MOVBL0(Rm, Rn);
19371718   case 0x3c: // MOVBL0(Rm, Rn);
19381719      UML_ADD(block, I0, R32(0), R32(Rm));        // add r0, R0, Rm
1939      UML_CALLH(block, *sh2->read8);              // call read8
1720      UML_CALLH(block, *m_read8);              // call read8
19401721      UML_SEXT(block, R32(Rn), I0, SIZE_BYTE);        // sext Rn, r0, BYTE
19411722
19421723      if (!in_delay_slot)
1943         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1724         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
19441725      return TRUE;
19451726
19461727   case 0x0d: // MOVWL0(Rm, Rn);
r29565r29566
19481729   case 0x2d: // MOVWL0(Rm, Rn);
19491730   case 0x3d: // MOVWL0(Rm, Rn);
19501731      UML_ADD(block, I0, R32(0), R32(Rm));        // add r0, R0, Rm
1951      UML_CALLH(block, *sh2->read16);             // call read16
1732      UML_CALLH(block, *m_read16);             // call read16
19521733      UML_SEXT(block, R32(Rn), I0, SIZE_WORD);        // sext Rn, r0, WORD
19531734
19541735      if (!in_delay_slot)
1955         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1736         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
19561737      return TRUE;
19571738
19581739   case 0x0e: // MOVLL0(Rm, Rn);
r29565r29566
19601741   case 0x2e: // MOVLL0(Rm, Rn);
19611742   case 0x3e: // MOVLL0(Rm, Rn);
19621743      UML_ADD(block, I0, R32(0), R32(Rm));        // add r0, R0, Rm
1963      UML_CALLH(block, *sh2->read32);             // call read32
1744      UML_CALLH(block, *m_read32);             // call read32
19641745      UML_MOV(block, R32(Rn), I0);            // mov Rn, r0
19651746
19661747      if (!in_delay_slot)
1967         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1748         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
19681749      return TRUE;
19691750
19701751   case 0x0f: // MAC_L(Rm, Rn);
19711752   case 0x1f: // MAC_L(Rm, Rn);
19721753   case 0x2f: // MAC_L(Rm, Rn);
19731754   case 0x3f: // MAC_L(Rm, Rn);
1974      if (sh2->cpu_type > CPU_TYPE_SH1)
1755      if (m_cpu_type > CPU_TYPE_SH1)
19751756      {
1976         save_fast_iregs(sh2, block);
1977         UML_MOV(block, mem(&sh2->arg0), desc->opptr.w[0]);
1978         UML_CALLC(block, cfunc_MAC_L, sh2);
1979         load_fast_iregs(sh2, block);
1757         save_fast_iregs(block);
1758         UML_MOV(block, mem(&m_sh2_state->arg0), desc->opptr.w[0]);
1759         UML_CALLC(block, cfunc_MAC_L, this);
1760         load_fast_iregs(block);
19801761         return TRUE;
19811762      }
19821763      break;
19831764
19841765   case 0x12: // STCGBR(Rn);
1985      UML_MOV(block, R32(Rn), mem(&sh2->gbr));        // mov Rn, gbr
1766      UML_MOV(block, R32(Rn), mem(&m_sh2_state->gbr));        // mov Rn, gbr
19861767      return TRUE;
19871768
19881769   case 0x18: // SETT();
1989      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), T); // or sr, sr, T
1770      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), T); // or sr, sr, T
19901771      return TRUE;
19911772
19921773   case 0x19: // DIV0U();
1993      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~(M|Q|T)); // and sr, sr, ~(M|Q|T)
1774      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~(M|Q|T)); // and sr, sr, ~(M|Q|T)
19941775      return TRUE;
19951776
19961777   case 0x1a: // STSMACL(Rn);
1997      UML_MOV(block, R32(Rn), mem(&sh2->macl));       // mov Rn, macl
1778      UML_MOV(block, R32(Rn), mem(&m_sh2_state->macl));       // mov Rn, macl
19981779      return TRUE;
19991780
20001781   case 0x1b: // SLEEP();
2001      UML_MOV(block, I0, mem(&sh2->sleep_mode));                          // mov i0, sleep_mode
1782      UML_MOV(block, I0, mem(&m_sh2_state->sleep_mode));                          // mov i0, sleep_mode
20021783      UML_CMP(block, I0, 0x2);                                            // cmp i0, #2
20031784      UML_JMPc(block, COND_E, compiler->labelnum);                        // beq labelnum
20041785      // sleep mode != 2
2005      UML_MOV(block, mem(&sh2->sleep_mode), 0x1);                         // mov sleep_mode, #1
2006      generate_update_cycles(sh2, block, compiler, desc->pc, TRUE);       // repeat this insn
1786      UML_MOV(block, mem(&m_sh2_state->sleep_mode), 0x1);                         // mov sleep_mode, #1
1787      generate_update_cycles(block, compiler, desc->pc, TRUE);       // repeat this insn
20071788      UML_JMP(block, compiler->labelnum+1);                               // jmp labelnum+1
20081789
20091790      UML_LABEL(block, compiler->labelnum++);                             // labelnum:
20101791      // sleep_mode == 2
2011      UML_MOV(block, mem(&sh2->sleep_mode), 0x0);                         // sleep_mode = 0
2012      generate_update_cycles(sh2, block, compiler, desc->pc+2, TRUE);     // go to next insn
1792      UML_MOV(block, mem(&m_sh2_state->sleep_mode), 0x0);                         // sleep_mode = 0
1793      generate_update_cycles(block, compiler, desc->pc+2, TRUE);     // go to next insn
20131794
20141795      UML_LABEL(block, compiler->labelnum++);                             // labelnum+1:
20151796      return TRUE;
20161797
20171798   case 0x22: // STCVBR(Rn);
2018      UML_MOV(block, R32(Rn), mem(&sh2->vbr));        // mov Rn, vbr
1799      UML_MOV(block, R32(Rn), mem(&m_sh2_state->vbr));        // mov Rn, vbr
20191800      return TRUE;
20201801
20211802   case 0x23: // BRAF(Rn);
2022      if (sh2->cpu_type > CPU_TYPE_SH1)
1803      if (m_cpu_type > CPU_TYPE_SH1)
20231804      {
2024         UML_ADD(block, mem(&sh2->target), R32(Rn), desc->pc+4); // add target, Rn, pc+4
1805         UML_ADD(block, mem(&m_sh2_state->target), R32(Rn), desc->pc+4); // add target, Rn, pc+4
20251806
2026         generate_delay_slot(sh2, block, compiler, desc, sh2->target);
1807         generate_delay_slot(block, compiler, desc, m_sh2_state->target);
20271808
2028         generate_update_cycles(sh2, block, compiler, mem(&sh2->target), TRUE);  // <subtract cycles>
2029         UML_HASHJMP(block, 0, mem(&sh2->target), *sh2->nocode); // jmp target
1809         generate_update_cycles(block, compiler, mem(&m_sh2_state->target), TRUE);  // <subtract cycles>
1810         UML_HASHJMP(block, 0, mem(&m_sh2_state->target), *m_nocode); // jmp target
20301811         return TRUE;
20311812      }
20321813      break;
20331814
20341815   case 0x28: // CLRMAC();
2035      UML_MOV(block, mem(&sh2->macl), 0);     // mov macl, #0
2036      UML_MOV(block, mem(&sh2->mach), 0);     // mov mach, #0
1816      UML_MOV(block, mem(&m_sh2_state->macl), 0);     // mov macl, #0
1817      UML_MOV(block, mem(&m_sh2_state->mach), 0);     // mov mach, #0
20371818      return TRUE;
20381819
20391820   case 0x29: // MOVT(Rn);
2040      UML_AND(block, R32(Rn), mem(&sh2->sr), T);      // and Rn, sr, T
1821      UML_AND(block, R32(Rn), mem(&m_sh2_state->sr), T);      // and Rn, sr, T
20411822      return TRUE;
20421823
20431824   case 0x2a: // STSPR(Rn);
2044      UML_MOV(block, R32(Rn), mem(&sh2->pr));         // mov Rn, pr
1825      UML_MOV(block, R32(Rn), mem(&m_sh2_state->pr));         // mov Rn, pr
20451826      return TRUE;
20461827
20471828   case 0x2b: // RTE();
2048      generate_delay_slot(sh2, block, compiler, desc, 0xffffffff);
1829      generate_delay_slot(block, compiler, desc, 0xffffffff);
20491830
20501831      UML_MOV(block, I0, R32(15));            // mov r0, R15
2051      UML_CALLH(block, *sh2->read32);             // call read32
2052      UML_MOV(block, mem(&sh2->pc), I0);          // mov pc, r0
1832      UML_CALLH(block, *m_read32);             // call read32
1833      UML_MOV(block, mem(&m_sh2_state->pc), I0);          // mov pc, r0
20531834      UML_ADD(block, R32(15), R32(15), 4);        // add R15, R15, #4
20541835
20551836      UML_MOV(block, I0, R32(15));            // mov r0, R15
2056      UML_CALLH(block, *sh2->read32);             // call read32
2057      UML_MOV(block, mem(&sh2->sr), I0);          // mov sr, r0
1837      UML_CALLH(block, *m_read32);             // call read32
1838      UML_MOV(block, mem(&m_sh2_state->sr), I0);          // mov sr, r0
20581839      UML_ADD(block, R32(15), R32(15), 4);        // add R15, R15, #4
20591840
20601841      compiler->checkints = TRUE;
2061      UML_MOV(block, mem(&sh2->ea), mem(&sh2->pc));       // mov ea, pc
2062      generate_update_cycles(sh2, block, compiler, mem(&sh2->ea), TRUE);  // <subtract cycles>
2063      UML_HASHJMP(block, 0, mem(&sh2->pc), *sh2->nocode); // and jump to the "resume PC"
1842      UML_MOV(block, mem(&m_sh2_state->ea), mem(&m_sh2_state->pc));       // mov ea, pc
1843      generate_update_cycles(block, compiler, mem(&m_sh2_state->ea), TRUE);  // <subtract cycles>
1844      UML_HASHJMP(block, 0, mem(&m_sh2_state->pc), *m_nocode); // and jump to the "resume PC"
20641845
20651846      return TRUE;
20661847   }
r29565r29566
20681849   return FALSE;
20691850}
20701851
2071static int generate_group_2(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
1852int sh2_device::generate_group_2(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
20721853{
20731854   switch (opcode & 15)
20741855   {
20751856   case  0: // MOVBS(Rm, Rn);
20761857      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
20771858      UML_AND(block, I1, R32(Rm), 0xff);  // and r1, Rm, 0xff
2078      UML_CALLH(block, *sh2->write8);
1859      UML_CALLH(block, *m_write8);
20791860
20801861      if (!in_delay_slot)
2081         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1862         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
20821863      return TRUE;
20831864
20841865   case  1: // MOVWS(Rm, Rn);
20851866      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
20861867      UML_AND(block, I1, R32(Rm), 0xffff);    // and r1, Rm, 0xffff
2087      UML_CALLH(block, *sh2->write16);
1868      UML_CALLH(block, *m_write16);
20881869
20891870      if (!in_delay_slot)
2090         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1871         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
20911872      return TRUE;
20921873
20931874   case  2: // MOVLS(Rm, Rn);
20941875      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
20951876      UML_MOV(block, I1, R32(Rm));        // mov r1, Rm
2096      UML_CALLH(block, *sh2->write32);
1877      UML_CALLH(block, *m_write32);
20971878
20981879      if (!in_delay_slot)
2099         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1880         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
21001881      return TRUE;
21011882
21021883   case  3:
r29565r29566
21061887      UML_MOV(block, I1, R32(Rm));        // mov r1, Rm
21071888      UML_SUB(block, R32(Rn), R32(Rn), 1);    // sub Rn, Rn, 1
21081889      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2109      UML_CALLH(block, *sh2->write8);         // call write8
1890      UML_CALLH(block, *m_write8);         // call write8
21101891
21111892      if (!in_delay_slot)
2112         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1893         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
21131894      return TRUE;
21141895
21151896   case  5: // MOVWM(Rm, Rn);
21161897      UML_MOV(block, I1, R32(Rm));        // mov r1, Rm
21171898      UML_SUB(block, R32(Rn), R32(Rn), 2);    // sub Rn, Rn, 2
21181899      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2119      UML_CALLH(block, *sh2->write16);            // call write16
1900      UML_CALLH(block, *m_write16);            // call write16
21201901
21211902      if (!in_delay_slot)
2122         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1903         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
21231904      return TRUE;
21241905
21251906   case  6: // MOVLM(Rm, Rn);
21261907      UML_MOV(block, I1, R32(Rm));        // mov r1, Rm
21271908      UML_SUB(block, R32(Rn), R32(Rn), 4);    // sub Rn, Rn, 4
21281909      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2129      UML_CALLH(block, *sh2->write32);            // call write32
1910      UML_CALLH(block, *m_write32);            // call write32
21301911
21311912      if (!in_delay_slot)
2132         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
1913         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
21331914      return TRUE;
21341915
21351916   case 13: // XTRCT(Rm, Rn);
r29565r29566
21431924      return TRUE;
21441925
21451926   case  7: // DIV0S(Rm, Rn);
2146      UML_MOV(block, I0, mem(&sh2->sr));              // move r0, sr
1927      UML_MOV(block, I0, mem(&m_sh2_state->sr));              // move r0, sr
21471928      UML_AND(block, I0, I0, ~(Q|M|T));       // and r0, r0, ~(Q|M|T) (clear the Q,M, and T bits)
21481929
21491930      UML_TEST(block, R32(Rn), 0x80000000);           // test Rn, #0x80000000
r29565r29566
21641945
21651946      UML_OR(block, I0, I0, T);               // or r0, r0, T
21661947      UML_LABEL(block, compiler->labelnum++);             // labelnum:
2167      UML_MOV(block, mem(&sh2->sr), I0);              // mov sr, r0
1948      UML_MOV(block, mem(&m_sh2_state->sr), I0);              // mov sr, r0
21681949      return TRUE;
21691950
21701951   case  8: // TST(Rm, Rn);
2171      UML_AND(block, I0, mem(&sh2->sr), ~T);  // and r0, sr, ~T (clear the T bit)
1952      UML_AND(block, I0, mem(&m_sh2_state->sr), ~T);  // and r0, sr, ~T (clear the T bit)
21721953      UML_TEST(block, R32(Rm), R32(Rn));      // test Rm, Rn
21731954      UML_JMPc(block, COND_NZ, compiler->labelnum);   // jnz compiler->labelnum
21741955
21751956      UML_OR(block, I0, I0, T);   // or r0, r0, T
21761957      UML_LABEL(block, compiler->labelnum++);         // desc->pc:
21771958
2178      UML_MOV(block, mem(&sh2->sr), I0);      // mov sh2->sr, r0
1959      UML_MOV(block, mem(&m_sh2_state->sr), I0);      // mov m_sh2_state->sr, r0
21791960      return TRUE;
21801961
21811962   case 12: // CMPSTR(Rm, Rn);
r29565r29566
21921973
21931974      UML_AND(block, I7, I0, 0xff);   // and r7, r0, #0xff    (LL)
21941975
2195      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T (clear the T bit)
1976      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T (clear the T bit)
21961977
21971978      UML_CMP(block, I1, 0);      // cmp r1, #0
21981979      UML_JMPc(block, COND_Z, compiler->labelnum);    // jnz labelnum
r29565r29566
22041985      UML_JMPc(block, COND_NZ, compiler->labelnum+1); // jnz labelnum
22051986
22061987      UML_LABEL(block, compiler->labelnum++);     // labelnum:
2207      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), T); // or sr, sr, T
1988      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), T); // or sr, sr, T
22081989
22091990      UML_LABEL(block, compiler->labelnum++);     // labelnum+1:
22101991      return TRUE;
r29565r29566
22242005   case 14: // MULU(Rm, Rn);
22252006      UML_AND(block, I0, R32(Rm), 0xffff);                // and r0, Rm, 0xffff
22262007      UML_AND(block, I1, R32(Rn), 0xffff);                // and r1, Rn, 0xffff
2227      UML_MULU(block, mem(&sh2->macl), mem(&sh2->ea), I0, I1);    // mulu macl, ea, r0, r1
2008      UML_MULU(block, mem(&m_sh2_state->macl), mem(&m_sh2_state->ea), I0, I1);    // mulu macl, ea, r0, r1
22282009      return TRUE;
22292010
22302011   case 15: // MULS(Rm, Rn);
22312012      UML_SEXT(block, I0, R32(Rm), SIZE_WORD);                // sext r0, Rm
22322013      UML_SEXT(block, I1, R32(Rn), SIZE_WORD);                // sext r1, Rn
2233      UML_MULS(block, mem(&sh2->macl), mem(&sh2->ea), I0, I1);    // muls macl, ea, r0, r1
2014      UML_MULS(block, mem(&m_sh2_state->macl), mem(&m_sh2_state->ea), I0, I1);    // muls macl, ea, r0, r1
22342015      return TRUE;
22352016   }
22362017
22372018   return FALSE;
22382019}
22392020
2240static int generate_group_3(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, UINT32 ovrpc)
2021int sh2_device::generate_group_3(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, UINT32 ovrpc)
22412022{
22422023   switch (opcode & 15)
22432024   {
22442025   case  0: // CMPEQ(Rm, Rn); (equality)
22452026      UML_CMP(block, R32(Rn), R32(Rm));       // cmp Rn, Rm
22462027      UML_SETc(block, COND_E, I0);            // set E, r0
2247      UML_ROLINS(block, mem(&sh2->sr), I0, 0, 1); // rolins sr, r0, 0, 1
2028      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, 1); // rolins sr, r0, 0, 1
22482029      return TRUE;
22492030
22502031   case  2: // CMPHS(Rm, Rn); (unsigned greater than or equal)
22512032      UML_CMP(block, R32(Rn), R32(Rm));       // cmp Rn, Rm
22522033      UML_SETc(block, COND_AE, I0);       // set AE, r0
2253      UML_ROLINS(block, mem(&sh2->sr), I0, 0, 1); // rolins sr, r0, 0, 1
2034      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, 1); // rolins sr, r0, 0, 1
22542035      return TRUE;
22552036
22562037   case  3: // CMPGE(Rm, Rn); (signed greater than or equal)
22572038      UML_CMP(block, R32(Rn), R32(Rm));       // cmp Rn, Rm
22582039      UML_SETc(block, COND_GE, I0);       // set GE, r0
2259      UML_ROLINS(block, mem(&sh2->sr), I0, 0, 1); // rolins sr, r0, 0, 1
2040      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, 1); // rolins sr, r0, 0, 1
22602041      return TRUE;
22612042
22622043   case  6: // CMPHI(Rm, Rn); (unsigned greater than)
22632044      UML_CMP(block, R32(Rn), R32(Rm));       // cmp Rn, Rm
22642045      UML_SETc(block, COND_A, I0);            // set A, r0
2265      UML_ROLINS(block, mem(&sh2->sr), I0, 0, 1); // rolins sr, r0, 0, 1
2046      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, 1); // rolins sr, r0, 0, 1
22662047      return TRUE;
22672048
22682049   case  7: // CMPGT(Rm, Rn); (signed greater than)
22692050      UML_CMP(block, R32(Rn), R32(Rm));       // cmp Rn, Rm
22702051      UML_SETc(block, COND_G, I0);            // set G, r0
2271      UML_ROLINS(block, mem(&sh2->sr), I0, 0, 1); // rolins sr, r0, 0, 1
2052      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, 1); // rolins sr, r0, 0, 1
22722053      return TRUE;
22732054
22742055   case  1:
r29565r29566
22762057      return FALSE;
22772058
22782059   case  4: // DIV1(Rm, Rn);
2279      save_fast_iregs(sh2, block);
2280      UML_MOV(block, mem(&sh2->arg0), desc->opptr.w[0]);
2281      UML_CALLC(block, cfunc_DIV1, sh2);
2282      load_fast_iregs(sh2, block);
2060      save_fast_iregs(block);
2061      UML_MOV(block, mem(&m_sh2_state->arg0), desc->opptr.w[0]);
2062      UML_CALLC(block, cfunc_DIV1, this);
2063      load_fast_iregs(block);
22832064      return TRUE;
22842065
22852066   case  5: // DMULU(Rm, Rn);
2286      if (sh2->cpu_type > CPU_TYPE_SH1)
2067      if (m_cpu_type > CPU_TYPE_SH1)
22872068      {
2288         UML_MULU(block, mem(&sh2->macl), mem(&sh2->mach), R32(Rn), R32(Rm));
2069         UML_MULU(block, mem(&m_sh2_state->macl), mem(&m_sh2_state->mach), R32(Rn), R32(Rm));
22892070         return TRUE;
22902071      }
22912072      break;
22922073
22932074   case 13: // DMULS(Rm, Rn);
2294      if (sh2->cpu_type > CPU_TYPE_SH1)
2075      if (m_cpu_type > CPU_TYPE_SH1)
22952076      {
2296         UML_MULS(block, mem(&sh2->macl), mem(&sh2->mach), R32(Rn), R32(Rm));
2077         UML_MULS(block, mem(&m_sh2_state->macl), mem(&m_sh2_state->mach), R32(Rn), R32(Rm));
22972078         return TRUE;
22982079      }
22992080      break;
r29565r29566
23072088      return TRUE;
23082089
23092090   case 10: // SUBC(Rm, Rn);
2310      UML_CARRY(block, mem(&sh2->sr), 0); // carry = T (T is bit 0 of SR)
2091      UML_CARRY(block, mem(&m_sh2_state->sr), 0); // carry = T (T is bit 0 of SR)
23112092      UML_SUBB(block, R32(Rn), R32(Rn), R32(Rm)); // addc Rn, Rn, Rm
23122093      UML_SETc(block, COND_C, I0);                // setc    i0, C
2313      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins sr,i0,0,T
2094      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins sr,i0,0,T
23142095      return TRUE;
23152096
23162097   case 11: // SUBV(Rm, Rn);
23172098#if ADDSUBV_DIRECT
23182099      UML_SUB(block, R32(Rn), R32(Rn), R32(Rm));      // sub Rn, Rn, Rm
23192100      UML_SETc(block, COND_V, I0);                    // setc    i0, V
2320      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins [sr],i0,0,T
2101      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins [sr],i0,0,T
23212102#else
2322      save_fast_iregs(sh2, block);
2323      UML_MOV(block, mem(&sh2->arg0), desc->opptr.w[0]);
2324      UML_CALLC(block, cfunc_SUBV, sh2);
2325      load_fast_iregs(sh2, block);
2103      save_fast_iregs(block);
2104      UML_MOV(block, mem(&m_sh2_state->arg0), desc->opptr.w[0]);
2105      UML_CALLC(block, cfunc_SUBV, this);
2106      load_fast_iregs(block);
23262107#endif
23272108      return TRUE;
23282109
23292110   case 14: // ADDC(Rm, Rn);
2330      UML_CARRY(block, mem(&sh2->sr), 0); // carry = T (T is bit 0 of SR)
2111      UML_CARRY(block, mem(&m_sh2_state->sr), 0); // carry = T (T is bit 0 of SR)
23312112      UML_ADDC(block, R32(Rn), R32(Rn), R32(Rm)); // addc Rn, Rn, Rm
23322113      UML_SETc(block, COND_C, I0);                // setc    i0, C
2333      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins sr,i0,0,T
2114      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins sr,i0,0,T
23342115      return TRUE;
23352116
23362117   case 15: // ADDV(Rm, Rn);
23372118#if ADDSUBV_DIRECT
23382119      UML_ADD(block, R32(Rn), R32(Rn), R32(Rm));      // add Rn, Rn, Rm
23392120      UML_SETc(block, COND_V, I0);                    // setc    i0, V
2340      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins [sr],i0,0,T
2121      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins [sr],i0,0,T
23412122#else
2342      save_fast_iregs(sh2, block);
2343      UML_MOV(block, mem(&sh2->arg0), desc->opptr.w[0]);
2344      UML_CALLC(block, cfunc_ADDV, sh2);
2345      load_fast_iregs(sh2, block);
2123      save_fast_iregs(block);
2124      UML_MOV(block, mem(&m_sh2_state->arg0), desc->opptr.w[0]);
2125      UML_CALLC(block, cfunc_ADDV, this);
2126      load_fast_iregs(block);
23462127#endif
23472128      return TRUE;
23482129   }
23492130   return FALSE;
23502131}
23512132
2352static int generate_group_4(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
2133int sh2_device::generate_group_4(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
23532134{
23542135   switch (opcode & 0x3F)
23552136   {
23562137   case 0x00: // SHLL(Rn);
23572138      UML_SHL(block, R32(Rn), R32(Rn), 1);        // shl Rn, Rn, 1
23582139      UML_SETc(block, COND_C, I0);                    // set i0,C
2359      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins [sr],i0,0,T
2140      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins [sr],i0,0,T
23602141      return TRUE;
23612142
23622143   case 0x01: // SHLR(Rn);
23632144      UML_SHR(block, R32(Rn), R32(Rn), 1);        // shr Rn, Rn, 1
23642145      UML_SETc(block, COND_C, I0);                    // set i0,C
2365      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins [sr],i0,0,T
2146      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins [sr],i0,0,T
23662147      return TRUE;
23672148
23682149   case 0x04: // ROTL(Rn);
23692150      UML_ROL(block, R32(Rn), R32(Rn), 1);        // rol Rn, Rn, 1
23702151      UML_SETc(block, COND_C, I0);                    // set i0,C
2371      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins [sr],i0,0,T
2152      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins [sr],i0,0,T
23722153      return TRUE;
23732154
23742155   case 0x05: // ROTR(Rn);
23752156      UML_ROR(block, R32(Rn), R32(Rn), 1);        // ror Rn, Rn, 1
23762157      UML_SETc(block, COND_C, I0);                    // set i0,C
2377      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins [sr],i0,0,T
2158      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins [sr],i0,0,T
23782159      return TRUE;
23792160
23802161   case 0x02: // STSMMACH(Rn);
23812162      UML_SUB(block, R32(Rn), R32(Rn), 4);    // sub Rn, Rn, #4
23822163      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2383      UML_MOV(block, I1, mem(&sh2->mach));    // mov r1, mach
2164      UML_MOV(block, I1, mem(&m_sh2_state->mach));    // mov r1, mach
23842165      SETEA(0);                   // set ea for debug
2385      UML_CALLH(block, *sh2->write32);            // call write32
2166      UML_CALLH(block, *m_write32);            // call write32
23862167
23872168      if (!in_delay_slot)
2388         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2169         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
23892170      return TRUE;
23902171
23912172   case 0x03: // STCMSR(Rn);
23922173      UML_SUB(block, R32(Rn), R32(Rn), 4);    // sub Rn, Rn, #4
23932174      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2394      UML_MOV(block, I1, mem(&sh2->sr));      // mov r1, sr
2175      UML_MOV(block, I1, mem(&m_sh2_state->sr));      // mov r1, sr
23952176      SETEA(0);                   // set ea for debug
2396      UML_CALLH(block, *sh2->write32);            // call write32
2177      UML_CALLH(block, *m_write32);            // call write32
23972178
23982179      if (!in_delay_slot)
2399         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2180         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
24002181      return TRUE;
24012182
24022183   case 0x06: // LDSMMACH(Rn);
24032184      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
24042185      SETEA(0);
2405      UML_CALLH(block, *sh2->read32);         // call read32
2186      UML_CALLH(block, *m_read32);         // call read32
24062187      UML_ADD(block, R32(Rn), R32(Rn), 4);    // add Rn, #4
2407      UML_MOV(block, mem(&sh2->mach), I0);    // mov mach, r0
2188      UML_MOV(block, mem(&m_sh2_state->mach), I0);    // mov mach, r0
24082189
24092190      if (!in_delay_slot)
2410         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2191         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
24112192      return TRUE;
24122193
24132194   case 0x07: // LDCMSR(Rn);
24142195      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
24152196      SETEA(0);
2416      UML_CALLH(block, *sh2->read32);         // call read32
2197      UML_CALLH(block, *m_read32);         // call read32
24172198      UML_ADD(block, R32(Rn), R32(Rn), 4);    // add Rn, #4
2418      UML_MOV(block, mem(&sh2->sr), I0);      // mov sr, r0
2199      UML_MOV(block, mem(&m_sh2_state->sr), I0);      // mov sr, r0
24192200
24202201      compiler->checkints = TRUE;
24212202      if (!in_delay_slot)
2422         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2203         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
24232204      return TRUE;
24242205
24252206
r29565r29566
24482229      return TRUE;
24492230
24502231   case 0x0a: // LDSMACH(Rn);
2451      UML_MOV(block, mem(&sh2->mach), R32(Rn));       // mov mach, Rn
2232      UML_MOV(block, mem(&m_sh2_state->mach), R32(Rn));       // mov mach, Rn
24522233      return TRUE;
24532234
24542235   case 0x0b: // JSR(Rn);
2455      UML_MOV(block, mem(&sh2->target), R32(Rn));     // mov target, Rn
2236      UML_MOV(block, mem(&m_sh2_state->target), R32(Rn));     // mov target, Rn
24562237
2457      UML_ADD(block, mem(&sh2->pr), desc->pc, 4); // add sh2->pr, desc->pc, #4 (skip the current insn & delay slot)
2238      UML_ADD(block, mem(&m_sh2_state->pr), desc->pc, 4); // add m_pr, desc->pc, #4 (skip the current insn & delay slot)
24582239
2459      generate_delay_slot(sh2, block, compiler, desc, sh2->target-4);
2240      generate_delay_slot(block, compiler, desc, m_sh2_state->target-4);
24602241
2461      generate_update_cycles(sh2, block, compiler, mem(&sh2->target), TRUE);  // <subtract cycles>
2462      UML_HASHJMP(block, 0, mem(&sh2->target), *sh2->nocode); // and do the jump
2242      generate_update_cycles(block, compiler, mem(&m_sh2_state->target), TRUE);  // <subtract cycles>
2243      UML_HASHJMP(block, 0, mem(&m_sh2_state->target), *m_nocode); // and do the jump
24632244      return TRUE;
24642245
24652246   case 0x0e: // LDCSR(Rn);
24662247      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
24672248      UML_AND(block, I0, I0, FLAGS);  // and r0, r0, FLAGS
2468      UML_MOV(block, mem(&sh2->sr), I0);
2249      UML_MOV(block, mem(&m_sh2_state->sr), I0);
24692250
24702251      compiler->checkints = TRUE;
24712252      return TRUE;
r29565r29566
24742255   case 0x1f: // MAC_W(Rm, Rn);
24752256   case 0x2f: // MAC_W(Rm, Rn);
24762257   case 0x3f: // MAC_W(Rm, Rn);
2477      save_fast_iregs(sh2, block);
2478      UML_MOV(block, mem(&sh2->arg0), desc->opptr.w[0]);
2479      UML_CALLC(block, cfunc_MAC_W, sh2);
2480      load_fast_iregs(sh2, block);
2258      save_fast_iregs(block);
2259      UML_MOV(block, mem(&m_sh2_state->arg0), desc->opptr.w[0]);
2260      UML_CALLC(block, cfunc_MAC_W, this);
2261      load_fast_iregs(block);
24812262      return TRUE;
24822263
24832264   case 0x10: // DT(Rn);
2484      if (sh2->cpu_type > CPU_TYPE_SH1)
2265      if (m_cpu_type > CPU_TYPE_SH1)
24852266      {
2486         UML_AND(block, I0, mem(&sh2->sr), ~T);  // and r0, sr, ~T (clear the T bit)
2267         UML_AND(block, I0, mem(&m_sh2_state->sr), ~T);  // and r0, sr, ~T (clear the T bit)
24872268         UML_SUB(block, R32(Rn), R32(Rn), 1);    // sub Rn, Rn, 1
24882269         UML_JMPc(block, COND_NZ, compiler->labelnum);   // jz compiler->labelnum
24892270
24902271         UML_OR(block, I0, I0, T);   // or r0, r0, T
24912272         UML_LABEL(block, compiler->labelnum++);         // desc->pc:
24922273
2493         UML_MOV(block, mem(&sh2->sr), I0);      // mov sh2->sr, r0
2274         UML_MOV(block, mem(&m_sh2_state->sr), I0);      // mov m_sh2_state->sr, r0
24942275         return TRUE;
24952276      }
24962277      break;
24972278
24982279   case 0x11: // CMPPZ(Rn);
2499      UML_AND(block, I0, mem(&sh2->sr), ~T);  // and r0, sr, ~T (clear the T bit)
2280      UML_AND(block, I0, mem(&m_sh2_state->sr), ~T);  // and r0, sr, ~T (clear the T bit)
25002281
25012282      UML_CMP(block, R32(Rn), 0);     // cmp Rn, 0
25022283      UML_JMPc(block, COND_S, compiler->labelnum);    // js compiler->labelnum    (if negative)
r29565r29566
25042285      UML_OR(block, I0, I0, T);   // or r0, r0, T
25052286      UML_LABEL(block, compiler->labelnum++);         // desc->pc:
25062287
2507      UML_MOV(block, mem(&sh2->sr), I0);      // mov sh2->sr, r0
2288      UML_MOV(block, mem(&m_sh2_state->sr), I0);      // mov m_sh2_state->sr, r0
25082289      return TRUE;
25092290
25102291   case 0x15: // CMPPL(Rn);
2511      UML_AND(block, I0, mem(&sh2->sr), ~T);  // and r0, sr, ~T (clear the T bit)
2292      UML_AND(block, I0, mem(&m_sh2_state->sr), ~T);  // and r0, sr, ~T (clear the T bit)
25122293
25132294      UML_CMP(block, R32(Rn), 0);     // cmp Rn, 0
25142295
r29565r29566
25182299      UML_OR(block, I0, I0, T);   // or r0, r0, T
25192300
25202301      UML_LABEL(block, compiler->labelnum++);         // desc->pc:
2521      UML_MOV(block, mem(&sh2->sr), I0);      // mov sh2->sr, r0
2302      UML_MOV(block, mem(&m_sh2_state->sr), I0);      // mov m_sh2_state->sr, r0
25222303      return TRUE;
25232304
25242305   case 0x12: // STSMMACL(Rn);
25252306      UML_SUB(block, R32(Rn), R32(Rn), 4);    // sub Rn, Rn, #4
25262307      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2527      UML_MOV(block, I1, mem(&sh2->macl));    // mov r1, macl
2308      UML_MOV(block, I1, mem(&m_sh2_state->macl));    // mov r1, macl
25282309      SETEA(0);                   // set ea for debug
2529      UML_CALLH(block, *sh2->write32);            // call write32
2310      UML_CALLH(block, *m_write32);            // call write32
25302311
25312312      if (!in_delay_slot)
2532         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2313         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
25332314      return TRUE;
25342315
25352316   case 0x13: // STCMGBR(Rn);
25362317      UML_SUB(block, R32(Rn), R32(Rn), 4);    // sub Rn, Rn, #4
25372318      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2538      UML_MOV(block, I1, mem(&sh2->gbr)); // mov r1, gbr
2319      UML_MOV(block, I1, mem(&m_sh2_state->gbr)); // mov r1, gbr
25392320      SETEA(0);                   // set ea for debug
2540      UML_CALLH(block, *sh2->write32);            // call write32
2321      UML_CALLH(block, *m_write32);            // call write32
25412322
25422323      if (!in_delay_slot)
2543         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2324         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
25442325      return TRUE;
25452326
25462327   case 0x16: // LDSMMACL(Rn);
25472328      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
25482329      SETEA(0);
2549      UML_CALLH(block, *sh2->read32);         // call read32
2330      UML_CALLH(block, *m_read32);         // call read32
25502331      UML_ADD(block, R32(Rn), R32(Rn), 4);    // add Rn, #4
2551      UML_MOV(block, mem(&sh2->macl), I0);    // mov macl, r0
2332      UML_MOV(block, mem(&m_sh2_state->macl), I0);    // mov macl, r0
25522333
25532334      if (!in_delay_slot)
2554         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2335         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
25552336      return TRUE;
25562337
25572338   case 0x17: // LDCMGBR(Rn);
25582339      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
25592340      SETEA(0);
2560      UML_CALLH(block, *sh2->read32);         // call read32
2341      UML_CALLH(block, *m_read32);         // call read32
25612342      UML_ADD(block, R32(Rn), R32(Rn), 4);    // add Rn, #4
2562      UML_MOV(block, mem(&sh2->gbr), I0); // mov gbr, r0
2343      UML_MOV(block, mem(&m_sh2_state->gbr), I0); // mov gbr, r0
25632344
25642345      if (!in_delay_slot)
2565         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2346         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
25662347      return TRUE;
25672348
25682349   case 0x1a: // LDSMACL(Rn);
2569      UML_MOV(block, mem(&sh2->macl), R32(Rn));       // mov macl, Rn
2350      UML_MOV(block, mem(&m_sh2_state->macl), R32(Rn));       // mov macl, Rn
25702351      return TRUE;
25712352
25722353   case 0x1b: // TAS(Rn);
25732354      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
25742355      SETEA(0);
2575      UML_CALLH(block, *sh2->read8);          // call read8
2356      UML_CALLH(block, *m_read8);          // call read8
25762357
2577      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T
2358      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T
25782359
25792360      UML_CMP(block, I0, 0);      // cmp r0, #0
25802361      UML_JMPc(block, COND_NZ, compiler->labelnum);   // jnz labelnum
25812362
2582      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), T); // or sr, sr, T
2363      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), T); // or sr, sr, T
25832364
25842365      UML_LABEL(block, compiler->labelnum++);     // labelnum:
25852366
25862367      UML_OR(block, I1, I0, 0x80);    // or r1, r0, #0x80
25872368
25882369      UML_MOV(block, I0, R32(Rn));        // mov r0, Rn
2589      UML_CALLH(block, *sh2->write8);         // write the value back
2370      UML_CALLH(block, *m_write8);         // write the value back
25902371
25912372      if (!in_delay_slot)
2592         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2373         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
25932374      return TRUE;
25942375
25952376   case 0x1e: // LDCGBR(Rn);
2596      UML_MOV(block, mem(&sh2->gbr), R32(Rn));    // mov gbr, Rn
2377      UML_MOV(block, mem(&m_sh2_state->gbr), R32(Rn));    // mov gbr, Rn
25972378      return TRUE;
25982379
25992380   case 0x20: // SHAL(Rn);
2600      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T
2381      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T
26012382      UML_SHR(block, I0, R32(Rn), 31);        // shr r0, Rn, 31
26022383      UML_AND(block, I0, I0, T);      // and r0, r0, T
2603      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), I0);    // or sr, sr, r0
2384      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), I0);    // or sr, sr, r0
26042385      UML_SHL(block, R32(Rn), R32(Rn), 1);        // shl Rn, Rn, 1
26052386      return TRUE;
26062387
26072388   case 0x21: // SHAR(Rn);
2608      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T
2389      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T
26092390      UML_AND(block, I0, R32(Rn), T);     // and r0, Rn, T
2610      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), I0);    // or sr, sr, r0
2391      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), I0);    // or sr, sr, r0
26112392      UML_SAR(block, R32(Rn), R32(Rn), 1);        // sar Rn, Rn, 1
26122393      return TRUE;
26132394
r29565r29566
26152396      UML_SUB(block, R32(Rn), R32(Rn), 4);        // sub Rn, Rn, 4
26162397      UML_MOV(block, I0, R32(Rn));            // mov r0, Rn
26172398      SETEA(0);
2618      UML_MOV(block, I1, mem(&sh2->pr));          // mov r1, pr
2619      UML_CALLH(block, *sh2->write32);                // call write32
2399      UML_MOV(block, I1, mem(&m_sh2_state->pr));          // mov r1, pr
2400      UML_CALLH(block, *m_write32);                // call write32
26202401
26212402      if (!in_delay_slot)
2622         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2403         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
26232404      return TRUE;
26242405
26252406   case 0x23: // STCMVBR(Rn);
26262407      UML_SUB(block, R32(Rn), R32(Rn), 4);        // sub Rn, Rn, 4
26272408      UML_MOV(block, I0, R32(Rn));            // mov r0, Rn
26282409      SETEA(0);
2629      UML_MOV(block, I1, mem(&sh2->vbr));     // mov r1, vbr
2630      UML_CALLH(block, *sh2->write32);                // call write32
2410      UML_MOV(block, I1, mem(&m_sh2_state->vbr));     // mov r1, vbr
2411      UML_CALLH(block, *m_write32);                // call write32
26312412
26322413      if (!in_delay_slot)
2633         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2414         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
26342415      return TRUE;
26352416
26362417   case 0x24: // ROTCL(Rn);
2637      UML_CARRY(block, mem(&sh2->sr), 0);         // carry sr,0
2418      UML_CARRY(block, mem(&m_sh2_state->sr), 0);         // carry sr,0
26382419      UML_ROLC(block, R32(Rn), R32(Rn), 1);           // rolc  Rn,Rn,1
26392420      UML_SETc(block, COND_C, I0);                        // set   i0,C
2640      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins sr,i0,0,T
2421      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins sr,i0,0,T
26412422      return TRUE;
26422423
26432424   case 0x25: // ROTCR(Rn);
2644      UML_CARRY(block, mem(&sh2->sr), 0);         // carry sr,0
2425      UML_CARRY(block, mem(&m_sh2_state->sr), 0);         // carry sr,0
26452426      UML_RORC(block, R32(Rn), R32(Rn), 1);           // rorc  Rn,Rn,1
26462427      UML_SETc(block, COND_C, I0);                        // set   i0,C
2647      UML_ROLINS(block, mem(&sh2->sr), I0, 0, T); // rolins sr,i0,0,T
2428      UML_ROLINS(block, mem(&m_sh2_state->sr), I0, 0, T); // rolins sr,i0,0,T
26482429      return TRUE;
26492430
26502431   case 0x26: // LDSMPR(Rn);
26512432      UML_MOV(block, I0, R32(Rn));            // mov r0, Rn
26522433      SETEA(0);
2653      UML_CALLH(block, *sh2->read32);             // call read32
2654      UML_MOV(block, mem(&sh2->pr), I0);          // mov sh2->pr, r0
2434      UML_CALLH(block, *m_read32);             // call read32
2435      UML_MOV(block, mem(&m_sh2_state->pr), I0);          // mov m_pr, r0
26552436      UML_ADD(block, R32(Rn), R32(Rn), 4);        // add Rn, Rn, #4
26562437
26572438      if (!in_delay_slot)
2658         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2439         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
26592440      return TRUE;
26602441
26612442   case 0x27: // LDCMVBR(Rn);
26622443      UML_MOV(block, I0, R32(Rn));            // mov r0, Rn
26632444      SETEA(0);
2664      UML_CALLH(block, *sh2->read32);             // call read32
2665      UML_MOV(block, mem(&sh2->vbr), I0);     // mov sh2->vbr, r0
2445      UML_CALLH(block, *m_read32);             // call read32
2446      UML_MOV(block, mem(&m_sh2_state->vbr), I0);     // mov m_sh2_state->vbr, r0
26662447      UML_ADD(block, R32(Rn), R32(Rn), 4);        // add Rn, Rn, #4
26672448
26682449      if (!in_delay_slot)
2669         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2450         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
26702451      return TRUE;
26712452
26722453   case 0x2a: // LDSPR(Rn);
2673      UML_MOV(block, mem(&sh2->pr), R32(Rn));         // mov sh2->pr, Rn
2454      UML_MOV(block, mem(&m_sh2_state->pr), R32(Rn));         // mov m_pr, Rn
26742455      return TRUE;
26752456
26762457   case 0x2b: // JMP(Rn);
2677      UML_MOV(block, mem(&sh2->target), R32(Rn));     // mov target, Rn
2458      UML_MOV(block, mem(&m_sh2_state->target), R32(Rn));     // mov target, Rn
26782459
2679      generate_delay_slot(sh2, block, compiler, desc, sh2->target);
2460      generate_delay_slot(block, compiler, desc, m_sh2_state->target);
26802461
2681      generate_update_cycles(sh2, block, compiler, mem(&sh2->target), TRUE);  // <subtract cycles>
2682      UML_HASHJMP(block, 0, mem(&sh2->target), *sh2->nocode); // jmp (target)
2462      generate_update_cycles(block, compiler, mem(&m_sh2_state->target), TRUE);  // <subtract cycles>
2463      UML_HASHJMP(block, 0, mem(&m_sh2_state->target), *m_nocode); // jmp (target)
26832464      return TRUE;
26842465
26852466   case 0x2e: // LDCVBR(Rn);
2686      UML_MOV(block, mem(&sh2->vbr), R32(Rn));        //  mov vbr, Rn
2467      UML_MOV(block, mem(&m_sh2_state->vbr), R32(Rn));        //  mov vbr, Rn
26872468      return TRUE;
26882469
26892470   case 0x0c:
r29565r29566
27142495   return FALSE;
27152496}
27162497
2717static int generate_group_6(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
2498int sh2_device::generate_group_6(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
27182499{
27192500   switch (opcode & 15)
27202501   {
27212502   case  0: // MOVBL(Rm, Rn);
27222503      UML_MOV(block, I0, R32(Rm));        // mov r0, Rm
27232504      SETEA(0);                   // debug: ea = r0
2724      UML_CALLH(block, *sh2->read8);          // call read8
2505      UML_CALLH(block, *m_read8);          // call read8
27252506      UML_SEXT(block, R32(Rn), I0, SIZE_BYTE);    // sext Rn, r0, BYTE
27262507
27272508      if (!in_delay_slot)
2728         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2509         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
27292510      return TRUE;
27302511
27312512   case  1: // MOVWL(Rm, Rn);
27322513      UML_MOV(block, I0, R32(Rm));        // mov r0, Rm
27332514      SETEA(0);                   // debug: ea = r0
2734      UML_CALLH(block, *sh2->read16);         // call read16
2515      UML_CALLH(block, *m_read16);         // call read16
27352516      UML_SEXT(block, R32(Rn), I0, SIZE_WORD);    // sext Rn, r0, WORD
27362517
27372518      if (!in_delay_slot)
2738         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2519         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
27392520      return TRUE;
27402521
27412522   case  2: // MOVLL(Rm, Rn);
27422523      UML_MOV(block, I0, R32(Rm));        // mov r0, Rm
27432524      SETEA(0);                   // debug: ea = r0
2744      UML_CALLH(block, *sh2->read32);         // call read32
2525      UML_CALLH(block, *m_read32);         // call read32
27452526      UML_MOV(block, R32(Rn), I0);        // mov Rn, r0
27462527
27472528      if (!in_delay_slot)
2748         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2529         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
27492530      return TRUE;
27502531
27512532   case  3: // MOV(Rm, Rn);
r29565r29566
27822563
27832564   case  4: // MOVBP(Rm, Rn);
27842565      UML_MOV(block, I0, R32(Rm));        // mov r0, Rm
2785      UML_CALLH(block, *sh2->read8);          // call read8
2566      UML_CALLH(block, *m_read8);          // call read8
27862567      UML_SEXT(block, R32(Rn), I0, SIZE_BYTE);        // sext Rn, r0, BYTE
27872568
27882569      if (Rm != Rn)
27892570         UML_ADD(block, R32(Rm), R32(Rm), 1);    // add Rm, Rm, #1
27902571
27912572      if (!in_delay_slot)
2792         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2573         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
27932574      return TRUE;
27942575
27952576   case  5: // MOVWP(Rm, Rn);
27962577      UML_MOV(block, I0, R32(Rm));        // mov r0, Rm
2797      UML_CALLH(block, *sh2->read16);         // call read16
2578      UML_CALLH(block, *m_read16);         // call read16
27982579      UML_SEXT(block, R32(Rn), I0, SIZE_WORD);        // sext Rn, r0, WORD
27992580
28002581      if (Rm != Rn)
28012582         UML_ADD(block, R32(Rm), R32(Rm), 2);    // add Rm, Rm, #2
28022583
28032584      if (!in_delay_slot)
2804         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2585         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
28052586      return TRUE;
28062587
28072588   case  6: // MOVLP(Rm, Rn);
28082589      UML_MOV(block, I0, R32(Rm));        // mov r0, Rm
2809      UML_CALLH(block, *sh2->read32);         // call read32
2590      UML_CALLH(block, *m_read32);         // call read32
28102591      UML_MOV(block, R32(Rn), I0);        // mov Rn, r0
28112592
28122593      if (Rm != Rn)
28132594         UML_ADD(block, R32(Rm), R32(Rm), 4);    // add Rm, Rm, #4
28142595
28152596      if (!in_delay_slot)
2816         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2597         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
28172598      return TRUE;
28182599
28192600   case  8: // SWAPB(Rm, Rn);
r29565r29566
28272608      return TRUE;
28282609
28292610   case 10: // NEGC(Rm, Rn);
2830      UML_MOV(block, I0, mem(&sh2->sr));      // mov r0, sr (save SR)
2831      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T (clear the T bit)
2611      UML_MOV(block, I0, mem(&m_sh2_state->sr));      // mov r0, sr (save SR)
2612      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T (clear the T bit)
28322613      UML_CARRY(block, I0, 0);    // carry = T (T is bit 0 of SR)
28332614      UML_SUBB(block, R32(Rn), 0, R32(Rm));   // subb Rn, #0, Rm
28342615
28352616      UML_JMPc(block, COND_NC, compiler->labelnum);   // jnc labelnum
28362617
2837      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), T); // or sr, sr, T
2618      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), T); // or sr, sr, T
28382619
28392620      UML_LABEL(block, compiler->labelnum++);     // labelnum:
28402621
r29565r29566
28442625   return FALSE;
28452626}
28462627
2847static int generate_group_8(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
2628int sh2_device::generate_group_8(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
28482629{
28492630   INT32 disp;
28502631   UINT32 udisp;
r29565r29566
28562637      udisp = (opcode & 0x0f);
28572638      UML_ADD(block, I0, R32(Rm), udisp);     // add r0, Rm, udisp
28582639      UML_MOV(block, I1, R32(0));         // mov r1, R0
2859      UML_CALLH(block, *sh2->write8);             // call write8
2640      UML_CALLH(block, *m_write8);             // call write8
28602641
28612642      if (!in_delay_slot)
2862         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2643         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
28632644      return TRUE;
28642645
28652646   case  1 << 8: // MOVWS4(opcode & 0x0f, Rm);
28662647      udisp = (opcode & 0x0f) * 2;
28672648      UML_ADD(block, I0, R32(Rm), udisp);     // add r0, Rm, udisp
28682649      UML_MOV(block, I1, R32(0));         // mov r1, R0
2869      UML_CALLH(block, *sh2->write16);                // call write16
2650      UML_CALLH(block, *m_write16);                // call write16
28702651
28712652      if (!in_delay_slot)
2872         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2653         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
28732654      return TRUE;
28742655
28752656   case  2<< 8:
r29565r29566
28852666      udisp = opcode & 0x0f;
28862667      UML_ADD(block, I0, R32(Rm), udisp);     // add r0, Rm, udisp
28872668      SETEA(0);
2888      UML_CALLH(block, *sh2->read8);              // call read8
2669      UML_CALLH(block, *m_read8);              // call read8
28892670      UML_SEXT(block, R32(0), I0, SIZE_BYTE);         // sext R0, r0, BYTE
28902671
28912672      if (!in_delay_slot)
2892         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2673         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
28932674      return TRUE;
28942675
28952676   case  5<< 8: // MOVWL4(Rm, opcode & 0x0f);
28962677      udisp = (opcode & 0x0f)*2;
28972678      UML_ADD(block, I0, R32(Rm), udisp);     // add r0, Rm, udisp
28982679      SETEA(0);
2899      UML_CALLH(block, *sh2->read16);             // call read16
2680      UML_CALLH(block, *m_read16);             // call read16
29002681      UML_SEXT(block, R32(0), I0, SIZE_WORD);         // sext R0, r0, WORD
29012682
29022683      if (!in_delay_slot)
2903         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2684         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
29042685      return TRUE;
29052686
29062687   case  8<< 8: // CMPIM(opcode & 0xff);
2907      UML_AND(block, I0, mem(&sh2->sr), ~T);  // and r0, sr, ~T (clear the T bit)
2688      UML_AND(block, I0, mem(&m_sh2_state->sr), ~T);  // and r0, sr, ~T (clear the T bit)
29082689
29092690      UML_SEXT(block, I1, opcode&0xff, SIZE_BYTE);    // sext r1, opcode&0xff, BYTE
29102691      UML_CMP(block, I1, R32(0));         // cmp r1, R0
r29565r29566
29132694      UML_OR(block, I0, I0, T);   // or r0, r0, T
29142695
29152696      UML_LABEL(block, compiler->labelnum++);         // labelnum:
2916      UML_MOV(block, mem(&sh2->sr), I0);      // mov sh2->sr, r0
2697      UML_MOV(block, mem(&m_sh2_state->sr), I0);      // mov m_sh2_state->sr, r0
29172698      return TRUE;
29182699
29192700   case  9<< 8: // BT(opcode & 0xff);
2920      UML_TEST(block, mem(&sh2->sr), T);      // test sh2->sr, T
2701      UML_TEST(block, mem(&m_sh2_state->sr), T);      // test m_sh2_state->sr, T
29212702      UML_JMPc(block, COND_Z, compiler->labelnum);    // jz compiler->labelnum
29222703
29232704      disp = ((INT32)opcode << 24) >> 24;
2924      sh2->ea = (desc->pc + 2) + disp * 2 + 2;    // sh2->ea = destination
2705      m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2;    // m_sh2_state->ea = destination
29252706
2926      generate_update_cycles(sh2, block, compiler, sh2->ea, TRUE);    // <subtract cycles>
2927      UML_HASHJMP(block, 0, sh2->ea, *sh2->nocode);   // jmp sh2->ea
2707      generate_update_cycles(block, compiler, m_sh2_state->ea, TRUE);    // <subtract cycles>
2708      UML_HASHJMP(block, 0, m_sh2_state->ea, *m_nocode);   // jmp m_sh2_state->ea
29282709
29292710      UML_LABEL(block, compiler->labelnum++);         // labelnum:
29302711      return TRUE;
29312712
29322713   case 11<< 8: // BF(opcode & 0xff);
2933      UML_TEST(block, mem(&sh2->sr), T);      // test sh2->sr, T
2714      UML_TEST(block, mem(&m_sh2_state->sr), T);      // test m_sh2_state->sr, T
29342715      UML_JMPc(block, COND_NZ, compiler->labelnum);   // jnz compiler->labelnum
29352716
29362717      disp = ((INT32)opcode << 24) >> 24;
2937      sh2->ea = (desc->pc + 2) + disp * 2 + 2;        // sh2->ea = destination
2718      m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2;        // m_sh2_state->ea = destination
29382719
2939      generate_update_cycles(sh2, block, compiler, sh2->ea, TRUE);    // <subtract cycles>
2940      UML_HASHJMP(block, 0, sh2->ea, *sh2->nocode);   // jmp sh2->ea
2720      generate_update_cycles(block, compiler, m_sh2_state->ea, TRUE);    // <subtract cycles>
2721      UML_HASHJMP(block, 0, m_sh2_state->ea, *m_nocode);   // jmp m_sh2_state->ea
29412722
29422723      UML_LABEL(block, compiler->labelnum++);         // labelnum:
29432724      return TRUE;
29442725
29452726   case 13<< 8: // BTS(opcode & 0xff);
2946      if (sh2->cpu_type > CPU_TYPE_SH1)
2727      if (m_cpu_type > CPU_TYPE_SH1)
29472728      {
2948         UML_TEST(block, mem(&sh2->sr), T);      // test sh2->sr, T
2729         UML_TEST(block, mem(&m_sh2_state->sr), T);      // test m_sh2_state->sr, T
29492730         UML_JMPc(block, COND_Z, compiler->labelnum);    // jz compiler->labelnum
29502731
29512732         disp = ((INT32)opcode << 24) >> 24;
2952         sh2->ea = (desc->pc + 2) + disp * 2 + 2;        // sh2->ea = destination
2733         m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2;        // m_sh2_state->ea = destination
29532734
29542735         templabel = compiler->labelnum;         // save our label
29552736         compiler->labelnum++;               // make sure the delay slot doesn't use it
2956         generate_delay_slot(sh2, block, compiler, desc, sh2->ea-2);
2737         generate_delay_slot(block, compiler, desc, m_sh2_state->ea-2);
29572738
2958         generate_update_cycles(sh2, block, compiler, sh2->ea, TRUE);    // <subtract cycles>
2959         UML_HASHJMP(block, 0, sh2->ea, *sh2->nocode);   // jmp sh2->ea
2739         generate_update_cycles(block, compiler, m_sh2_state->ea, TRUE);    // <subtract cycles>
2740         UML_HASHJMP(block, 0, m_sh2_state->ea, *m_nocode);   // jmp m_sh2_state->ea
29602741
29612742         UML_LABEL(block, templabel);            // labelnum:
29622743         return TRUE;
r29565r29566
29642745      break;
29652746
29662747   case 15<< 8: // BFS(opcode & 0xff);
2967      if (sh2->cpu_type > CPU_TYPE_SH1)
2748      if (m_cpu_type > CPU_TYPE_SH1)
29682749      {
2969         UML_TEST(block, mem(&sh2->sr), T);      // test sh2->sr, T
2750         UML_TEST(block, mem(&m_sh2_state->sr), T);      // test m_sh2_state->sr, T
29702751         UML_JMPc(block, COND_NZ, compiler->labelnum);   // jnz compiler->labelnum
29712752
29722753         disp = ((INT32)opcode << 24) >> 24;
2973         sh2->ea = (desc->pc + 2) + disp * 2 + 2;        // sh2->ea = destination
2754         m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2;        // m_sh2_state->ea = destination
29742755
29752756         templabel = compiler->labelnum;         // save our label
29762757         compiler->labelnum++;               // make sure the delay slot doesn't use it
2977         generate_delay_slot(sh2, block, compiler, desc, sh2->ea-2); // delay slot only if the branch is taken
2758         generate_delay_slot(block, compiler, desc, m_sh2_state->ea-2); // delay slot only if the branch is taken
29782759
2979         generate_update_cycles(sh2, block, compiler, sh2->ea, TRUE);    // <subtract cycles>
2980         UML_HASHJMP(block, 0, sh2->ea, *sh2->nocode);   // jmp sh2->ea
2760         generate_update_cycles(block, compiler, m_sh2_state->ea, TRUE);    // <subtract cycles>
2761         UML_HASHJMP(block, 0, m_sh2_state->ea, *m_nocode);   // jmp m_sh2_state->ea
29812762
29822763         UML_LABEL(block, templabel);            // labelnum:
29832764         return TRUE;
r29565r29566
29882769   return FALSE;
29892770}
29902771
2991static int generate_group_12(sh2_state *sh2, drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
2772int sh2_device::generate_group_12(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT16 opcode, int in_delay_slot, UINT32 ovrpc)
29922773{
29932774   UINT32 scratch;
29942775
r29565r29566
29962777   {
29972778   case  0<<8: // MOVBSG(opcode & 0xff);
29982779      scratch = (opcode & 0xff);
2999      UML_ADD(block, I0, mem(&sh2->gbr), scratch);    // add r0, gbr, scratch
2780      UML_ADD(block, I0, mem(&m_sh2_state->gbr), scratch);    // add r0, gbr, scratch
30002781      UML_AND(block, I1, R32(0), 0xff);       // and r1, R0, 0xff
3001      UML_CALLH(block, *sh2->write8);             // call write8
2782      UML_CALLH(block, *m_write8);             // call write8
30022783
30032784      if (!in_delay_slot)
3004         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2785         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
30052786      return TRUE;
30062787
30072788   case  1<<8: // MOVWSG(opcode & 0xff);
30082789      scratch = (opcode & 0xff) * 2;
3009      UML_ADD(block, I0, mem(&sh2->gbr), scratch);    // add r0, gbr, scratch
2790      UML_ADD(block, I0, mem(&m_sh2_state->gbr), scratch);    // add r0, gbr, scratch
30102791      UML_AND(block, I1, R32(0), 0xffff);     // and r1, R0, 0xffff
3011      UML_CALLH(block, *sh2->write16);                // call write16
2792      UML_CALLH(block, *m_write16);                // call write16
30122793
30132794      if (!in_delay_slot)
3014         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2795         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
30152796      return TRUE;
30162797
30172798   case  2<<8: // MOVLSG(opcode & 0xff);
30182799      scratch = (opcode & 0xff) * 4;
3019      UML_ADD(block, I0, mem(&sh2->gbr), scratch);    // add r0, gbr, scratch
2800      UML_ADD(block, I0, mem(&m_sh2_state->gbr), scratch);    // add r0, gbr, scratch
30202801      UML_MOV(block, I1, R32(0));         // mov r1, R0
3021      UML_CALLH(block, *sh2->write32);                // call write32
2802      UML_CALLH(block, *m_write32);                // call write32
30222803
30232804      if (!in_delay_slot)
3024         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2805         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
30252806      return TRUE;
30262807
30272808   case  3<<8: // TRAPA(opcode & 0xff);
30282809      scratch = (opcode & 0xff) * 4;
3029      UML_ADD(block, mem(&sh2->ea), mem(&sh2->vbr), scratch); // add ea, vbr, scratch
2810      UML_ADD(block, mem(&m_sh2_state->ea), mem(&m_sh2_state->vbr), scratch); // add ea, vbr, scratch
30302811
30312812      UML_SUB(block, R32(15), R32(15), 4);            // sub R15, R15, #4
30322813      UML_MOV(block, I0, R32(15));                // mov r0, R15
3033      UML_MOV(block, I1, mem(&sh2->sr));              // mov r1, sr
3034      UML_CALLH(block, *sh2->write32);                    // write32
2814      UML_MOV(block, I1, mem(&m_sh2_state->sr));              // mov r1, sr
2815      UML_CALLH(block, *m_write32);                    // write32
30352816
30362817      UML_SUB(block, R32(15), R32(15), 4);            // sub R15, R15, #4
30372818      UML_MOV(block, I0, R32(15));                // mov r0, R15
30382819      UML_MOV(block, I1, desc->pc+2);             // mov r1, pc+2
3039      UML_CALLH(block, *sh2->write32);                    // write32
2820      UML_CALLH(block, *m_write32);                    // write32
30402821
3041      UML_MOV(block, I0, mem(&sh2->ea));              // mov r0, ea
3042      UML_CALLH(block, *sh2->read32);                 // read32
3043      UML_HASHJMP(block, 0, I0, *sh2->nocode);        // jmp (r0)
2822      UML_MOV(block, I0, mem(&m_sh2_state->ea));              // mov r0, ea
2823      UML_CALLH(block, *m_read32);                 // read32
2824      UML_HASHJMP(block, 0, I0, *m_nocode);        // jmp (r0)
30442825
30452826      return TRUE;
30462827
30472828   case  4<<8: // MOVBLG(opcode & 0xff);
30482829      scratch = (opcode & 0xff);
3049      UML_ADD(block, I0, mem(&sh2->gbr), scratch);    // add r0, gbr, scratch
3050      UML_CALLH(block, *sh2->read8);              // call read16
2830      UML_ADD(block, I0, mem(&m_sh2_state->gbr), scratch);    // add r0, gbr, scratch
2831      UML_CALLH(block, *m_read8);              // call read16
30512832      UML_SEXT(block, R32(0), I0, SIZE_BYTE);         // sext R0, r0, BYTE
30522833
30532834      if (!in_delay_slot)
3054         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2835         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
30552836      return TRUE;
30562837
30572838   case  5<<8: // MOVWLG(opcode & 0xff);
30582839      scratch = (opcode & 0xff) * 2;
3059      UML_ADD(block, I0, mem(&sh2->gbr), scratch);    // add r0, gbr, scratch
3060      UML_CALLH(block, *sh2->read16);             // call read16
2840      UML_ADD(block, I0, mem(&m_sh2_state->gbr), scratch);    // add r0, gbr, scratch
2841      UML_CALLH(block, *m_read16);             // call read16
30612842      UML_SEXT(block, R32(0), I0, SIZE_WORD);         // sext R0, r0, WORD
30622843
30632844      if (!in_delay_slot)
3064         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2845         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
30652846      return TRUE;
30662847
30672848   case  6<<8: // MOVLLG(opcode & 0xff);
30682849      scratch = (opcode & 0xff) * 4;
3069      UML_ADD(block, I0, mem(&sh2->gbr), scratch);    // add r0, gbr, scratch
3070      UML_CALLH(block, *sh2->read32);             // call read32
2850      UML_ADD(block, I0, mem(&m_sh2_state->gbr), scratch);    // add r0, gbr, scratch
2851      UML_CALLH(block, *m_read32);             // call read32
30712852      UML_MOV(block, R32(0), I0);         // mov R0, r0
30722853
30732854      if (!in_delay_slot)
3074         generate_update_cycles(sh2, block, compiler, desc->pc + 2, TRUE);
2855         generate_update_cycles(block, compiler, desc->pc + 2, TRUE);
30752856      return TRUE;
30762857
30772858   case  7<<8: // MOVA(opcode & 0xff);
r29565r29566
30842865   case  8<<8: // TSTI(opcode & 0xff);
30852866      scratch = opcode & 0xff;
30862867
3087      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T (clear the T bit)
2868      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T (clear the T bit)
30882869      UML_AND(block, I0, R32(0), scratch);        // and r0, R0, scratch
30892870      UML_CMP(block, I0, 0);          // cmp r0, #0
30902871      UML_JMPc(block, COND_NZ, compiler->labelnum);       // jnz labelnum
30912872
3092      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), T); // or sr, sr, T
2873      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), T); // or sr, sr, T
30932874
30942875      UML_LABEL(block, compiler->labelnum++);         // labelnum:
30952876      return TRUE;
r29565r29566
31072888      return TRUE;
31082889
31092890   case 12<<8: // TSTM(opcode & 0xff);
3110      UML_AND(block, mem(&sh2->sr), mem(&sh2->sr), ~T);   // and sr, sr, ~T (clear the T bit)
3111      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
3112      UML_CALLH(block, *sh2->read8);              // read8
2891      UML_AND(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), ~T);   // and sr, sr, ~T (clear the T bit)
2892      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
2893      UML_CALLH(block, *m_read8);              // read8
31132894
31142895      UML_AND(block, I0, I0, opcode & 0xff);
31152896      UML_CMP(block, I0, 0);          // cmp r0, #0
31162897      UML_JMPc(block, COND_NZ, compiler->labelnum);       // jnz labelnum
31172898
3118      UML_OR(block, mem(&sh2->sr), mem(&sh2->sr), T); // or sr, sr, T
2899      UML_OR(block, mem(&m_sh2_state->sr), mem(&m_sh2_state->sr), T); // or sr, sr, T
31192900
31202901      UML_LABEL(block, compiler->labelnum++);         // labelnum:
31212902      return TRUE;
31222903
31232904   case 13<<8: // ANDM(opcode & 0xff);
3124      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
3125      UML_CALLH(block, *sh2->read8);              // read8
2905      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
2906      UML_CALLH(block, *m_read8);              // read8
31262907
31272908      UML_AND(block, I1, I0, opcode&0xff);    // and r1, r0, #opcode&0xff
3128      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
2909      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
31292910      SETEA(0);
3130      UML_CALLH(block, *sh2->write8);             // write8
2911      UML_CALLH(block, *m_write8);             // write8
31312912      return TRUE;
31322913
31332914   case 14<<8: // XORM(opcode & 0xff);
3134      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
3135      UML_CALLH(block, *sh2->read8);              // read8
2915      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
2916      UML_CALLH(block, *m_read8);              // read8
31362917
31372918      UML_XOR(block, I1, I0, opcode&0xff);    // xor r1, r0, #opcode&0xff
3138      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
2919      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
31392920      SETEA(0);
3140      UML_CALLH(block, *sh2->write8);             // write8
2921      UML_CALLH(block, *m_write8);             // write8
31412922      return TRUE;
31422923
31432924   case 15<<8: // ORM(opcode & 0xff);
3144      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
3145      UML_CALLH(block, *sh2->read8);              // read8
2925      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
2926      UML_CALLH(block, *m_read8);              // read8
31462927
31472928      UML_OR(block, I1, I0, opcode&0xff); // or r1, r0, #opcode&0xff
3148      UML_ADD(block, I0, R32(0), mem(&sh2->gbr)); // add r0, R0, gbr
2929      UML_ADD(block, I0, R32(0), mem(&m_sh2_state->gbr)); // add r0, R0, gbr
31492930      SETEA(0);
3150      UML_CALLH(block, *sh2->write8);             // write8
2931      UML_CALLH(block, *m_write8);             // write8
31512932      return TRUE;
31522933   }
31532934
r29565r29566
31622943    sh2drc_set_options - configure DRC options
31632944-------------------------------------------------*/
31642945
3165void sh2drc_set_options(device_t *device, UINT32 options)
2946void sh2_device::sh2drc_set_options(UINT32 options)
31662947{
3167   if (!device->machine().options().drc()) return;
3168   sh2_state *sh2 = get_safe_token(device);
3169   sh2->drcoptions = options;
2948   if (!machine().options().drc()) return;
2949   m_drcoptions = options;
31702950}
31712951
31722952
r29565r29566
31752955    the PC must be flushed for speedups to work
31762956-------------------------------------------------*/
31772957
3178void sh2drc_add_pcflush(device_t *device, offs_t address)
2958void sh2_device::sh2drc_add_pcflush(offs_t address)
31792959{
3180   if (!device->machine().options().drc()) return;
3181   sh2_state *sh2 = get_safe_token(device);
2960   if (!machine().options().drc()) return;
31822961
3183   if (sh2->pcfsel < ARRAY_LENGTH(sh2->pcflushes))
3184      sh2->pcflushes[sh2->pcfsel++] = address;
2962   if (m_pcfsel < ARRAY_LENGTH(m_pcflushes))
2963      m_pcflushes[m_pcfsel++] = address;
31852964}
31862965
31872966
r29565r29566
31902969    region
31912970-------------------------------------------------*/
31922971
3193void sh2drc_add_fastram(device_t *device, offs_t start, offs_t end, UINT8 readonly, void *base)
2972void sh2_device::sh2drc_add_fastram(offs_t start, offs_t end, UINT8 readonly, void *base)
31942973{
3195   sh2_state *sh2 = get_safe_token(device);
3196   if (sh2->fastram_select < ARRAY_LENGTH(sh2->fastram))
2974   if (m_fastram_select < ARRAY_LENGTH(m_fastram))
31972975   {
3198      sh2->fastram[sh2->fastram_select].start = start;
3199      sh2->fastram[sh2->fastram_select].end = end;
3200      sh2->fastram[sh2->fastram_select].readonly = readonly;
3201      sh2->fastram[sh2->fastram_select].base = base;
3202      sh2->fastram_select++;
2976      m_fastram[m_fastram_select].start = start;
2977      m_fastram[m_fastram_select].end = end;
2978      m_fastram[m_fastram_select].readonly = readonly;
2979      m_fastram[m_fastram_select].base = base;
2980      m_fastram_select++;
32032981   }
32042982}
32052983
3206/*-------------------------------------------------
3207    sh2_internal_a5 - read handler for
3208    SH2 internal map
3209-------------------------------------------------*/
3210
3211static READ32_HANDLER(sh2_internal_a5)
3212{
3213   return 0xa5a5a5a5;
3214}
3215
3216
3217/*-------------------------------------------------
3218    sh2_internal_map - maps SH2 built-ins
3219-------------------------------------------------*/
3220
3221static ADDRESS_MAP_START( sh2_internal_map, AS_PROGRAM, 32, legacy_cpu_device )
3222   AM_RANGE(0x40000000, 0xbfffffff) AM_READ_LEGACY(sh2_internal_a5)
3223   AM_RANGE(0xe0000000, 0xffffffff) AM_READWRITE_LEGACY(sh2_internal_r, sh2_internal_w)
3224ADDRESS_MAP_END
3225
3226/*-------------------------------------------------
3227    sh2_set_info - set information about a given
3228    CPU instance
3229-------------------------------------------------*/
3230
3231static CPU_SET_INFO( sh2 )
3232{
3233   sh2_state *sh2 = get_safe_token(device);
3234   switch (state)
3235   {
3236      /* --- the following bits of info are set as 64-bit signed integers --- */
3237      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLIN:   sh2_set_irq_line(sh2, SH2_INT_VBLIN, info->i);  break;
3238      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLOUT:  sh2_set_irq_line(sh2, SH2_INT_VBLOUT, info->i); break;
3239      case CPUINFO_INT_INPUT_STATE + SH2_INT_HBLIN:   sh2_set_irq_line(sh2, SH2_INT_HBLIN, info->i);  break;
3240      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER0:  sh2_set_irq_line(sh2, SH2_INT_TIMER0, info->i); break;
3241      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER1:  sh2_set_irq_line(sh2, SH2_INT_TIMER1, info->i); break;
3242      case CPUINFO_INT_INPUT_STATE + SH2_INT_DSP:     sh2_set_irq_line(sh2, SH2_INT_DSP, info->i);        break;
3243      case CPUINFO_INT_INPUT_STATE + SH2_INT_SOUND:   sh2_set_irq_line(sh2, SH2_INT_SOUND, info->i);  break;
3244      case CPUINFO_INT_INPUT_STATE + SH2_INT_SMPC:    sh2_set_irq_line(sh2, SH2_INT_SMPC, info->i);   break;
3245      case CPUINFO_INT_INPUT_STATE + SH2_INT_PAD:     sh2_set_irq_line(sh2, SH2_INT_PAD, info->i);        break;
3246      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA2:    sh2_set_irq_line(sh2, SH2_INT_DMA2, info->i);   break;
3247      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA1:    sh2_set_irq_line(sh2, SH2_INT_DMA1, info->i);   break;
3248      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA0:    sh2_set_irq_line(sh2, SH2_INT_DMA0, info->i);   break;
3249      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMAILL:  sh2_set_irq_line(sh2, SH2_INT_DMAILL, info->i); break;
3250      case CPUINFO_INT_INPUT_STATE + SH2_INT_SPRITE:  sh2_set_irq_line(sh2, SH2_INT_SPRITE, info->i); break;
3251      case CPUINFO_INT_INPUT_STATE + SH2_INT_14:      sh2_set_irq_line(sh2, SH2_INT_14, info->i);     break;
3252      case CPUINFO_INT_INPUT_STATE + SH2_INT_15:      sh2_set_irq_line(sh2, SH2_INT_15, info->i);     break;
3253      case CPUINFO_INT_INPUT_STATE + SH2_INT_ABUS:    sh2_set_irq_line(sh2, SH2_INT_ABUS, info->i);   break;
3254      case CPUINFO_INT_INPUT_STATE + INPUT_LINE_NMI:  sh2_set_irq_line(sh2, INPUT_LINE_NMI, info->i); break;
3255
3256      case CPUINFO_INT_REGISTER + SH2_PC:
3257      case CPUINFO_INT_PC:                            sh2->pc = info->i; sh2->delay = 0;      break;
3258      case CPUINFO_INT_SP:                            sh2->r[15] = info->i;                   break;
3259      case CPUINFO_INT_REGISTER + SH2_PR:             sh2->pr = info->i;                      break;
3260      case CPUINFO_INT_REGISTER + SH2_SR:             sh2->sr = info->i;                  break;
3261      case CPUINFO_INT_REGISTER + SH2_GBR:            sh2->gbr = info->i;                     break;
3262      case CPUINFO_INT_REGISTER + SH2_VBR:            sh2->vbr = info->i;                     break;
3263      case CPUINFO_INT_REGISTER + SH2_MACH:           sh2->mach = info->i;                        break;
3264      case CPUINFO_INT_REGISTER + SH2_MACL:           sh2->macl = info->i;                        break;
3265      case CPUINFO_INT_REGISTER + SH2_R0:             sh2->r[ 0] = info->i;                   break;
3266      case CPUINFO_INT_REGISTER + SH2_R1:             sh2->r[ 1] = info->i;                   break;
3267      case CPUINFO_INT_REGISTER + SH2_R2:             sh2->r[ 2] = info->i;                   break;
3268      case CPUINFO_INT_REGISTER + SH2_R3:             sh2->r[ 3] = info->i;                   break;
3269      case CPUINFO_INT_REGISTER + SH2_R4:             sh2->r[ 4] = info->i;                   break;
3270      case CPUINFO_INT_REGISTER + SH2_R5:             sh2->r[ 5] = info->i;                   break;
3271      case CPUINFO_INT_REGISTER + SH2_R6:             sh2->r[ 6] = info->i;                   break;
3272      case CPUINFO_INT_REGISTER + SH2_R7:             sh2->r[ 7] = info->i;                   break;
3273      case CPUINFO_INT_REGISTER + SH2_R8:             sh2->r[ 8] = info->i;                   break;
3274      case CPUINFO_INT_REGISTER + SH2_R9:             sh2->r[ 9] = info->i;                   break;
3275      case CPUINFO_INT_REGISTER + SH2_R10:            sh2->r[10] = info->i;                   break;
3276      case CPUINFO_INT_REGISTER + SH2_R11:            sh2->r[11] = info->i;                   break;
3277      case CPUINFO_INT_REGISTER + SH2_R12:            sh2->r[12] = info->i;                   break;
3278      case CPUINFO_INT_REGISTER + SH2_R13:            sh2->r[13] = info->i;                   break;
3279      case CPUINFO_INT_REGISTER + SH2_R14:            sh2->r[14] = info->i;                   break;
3280      case CPUINFO_INT_REGISTER + SH2_R15:            sh2->r[15] = info->i;                   break;
3281      case CPUINFO_INT_REGISTER + SH2_EA:             sh2->ea = info->i;                      break;
3282   }
3283}
3284
3285/*-------------------------------------------------
3286    sh2_get_info - return information about a
3287    given CPU instance
3288-------------------------------------------------*/
3289
3290CPU_GET_INFO( sh2_drc )
3291{
3292   sh2_state *sh2 = (device != NULL && device->token() != NULL) ? get_safe_token(device) : NULL;
3293   switch (state)
3294   {
3295      /* --- the following bits of info are returned as 64-bit signed integers --- */
3296      case CPUINFO_INT_CONTEXT_SIZE:                  info->i = sizeof(sh2_state *);              break;
3297      case CPUINFO_INT_INPUT_LINES:                   info->i = 16;                           break;
3298      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:            info->i = 0;                            break;
3299      case CPUINFO_INT_ENDIANNESS:                    info->i = ENDIANNESS_BIG;                   break;
3300      case CPUINFO_INT_CLOCK_MULTIPLIER:              info->i = 1;                            break;
3301      case CPUINFO_INT_CLOCK_DIVIDER:                 info->i = 1;                            break;
3302      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 2;                            break;
3303      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 2;                            break;
3304      case CPUINFO_INT_MIN_CYCLES:                    info->i = 1;                            break;
3305      case CPUINFO_INT_MAX_CYCLES:                    info->i = 4;                            break;
3306
3307      case CPUINFO_INT_DATABUS_WIDTH + AS_PROGRAM:    info->i = 32;                   break;
3308      case CPUINFO_INT_ADDRBUS_WIDTH + AS_PROGRAM: info->i = 32;                  break;
3309      case CPUINFO_INT_ADDRBUS_SHIFT + AS_PROGRAM: info->i = 0;                   break;
3310      case CPUINFO_INT_DATABUS_WIDTH + AS_DATA:   info->i = 0;                    break;
3311      case CPUINFO_INT_ADDRBUS_WIDTH + AS_DATA:   info->i = 0;                    break;
3312      case CPUINFO_INT_ADDRBUS_SHIFT + AS_DATA:   info->i = 0;                    break;
3313      case CPUINFO_INT_DATABUS_WIDTH + AS_IO:     info->i = 0;                    break;
3314      case CPUINFO_INT_ADDRBUS_WIDTH + AS_IO:     info->i = 0;                    break;
3315      case CPUINFO_INT_ADDRBUS_SHIFT + AS_IO:     info->i = 0;                    break;
3316
3317      // Internal maps
3318      case CPUINFO_PTR_INTERNAL_MEMORY_MAP + AS_PROGRAM: info->internal_map32 = ADDRESS_MAP_NAME(sh2_internal_map); break;
3319      case CPUINFO_PTR_INTERNAL_MEMORY_MAP + AS_DATA:    info->internal_map32 = NULL; break;
3320      case CPUINFO_PTR_INTERNAL_MEMORY_MAP + AS_IO:      info->internal_map32 = NULL; break;
3321
3322      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLIN:   info->i = sh2->irq_line_state[SH2_INT_VBLIN]; break;
3323      case CPUINFO_INT_INPUT_STATE + SH2_INT_VBLOUT:  info->i = sh2->irq_line_state[SH2_INT_VBLOUT]; break;
3324      case CPUINFO_INT_INPUT_STATE + SH2_INT_HBLIN:   info->i = sh2->irq_line_state[SH2_INT_HBLIN]; break;
3325      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER0:  info->i = sh2->irq_line_state[SH2_INT_TIMER0]; break;
3326      case CPUINFO_INT_INPUT_STATE + SH2_INT_TIMER1:  info->i = sh2->irq_line_state[SH2_INT_TIMER1]; break;
3327      case CPUINFO_INT_INPUT_STATE + SH2_INT_DSP:     info->i = sh2->irq_line_state[SH2_INT_DSP]; break;
3328      case CPUINFO_INT_INPUT_STATE + SH2_INT_SOUND:   info->i = sh2->irq_line_state[SH2_INT_SOUND]; break;
3329      case CPUINFO_INT_INPUT_STATE + SH2_INT_SMPC:    info->i = sh2->irq_line_state[SH2_INT_SMPC];    break;
3330      case CPUINFO_INT_INPUT_STATE + SH2_INT_PAD:     info->i = sh2->irq_line_state[SH2_INT_PAD]; break;
3331      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA2:    info->i = sh2->irq_line_state[SH2_INT_DMA2];    break;
3332      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA1:    info->i = sh2->irq_line_state[SH2_INT_DMA1];    break;
3333      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMA0:    info->i = sh2->irq_line_state[SH2_INT_DMA0];    break;
3334      case CPUINFO_INT_INPUT_STATE + SH2_INT_DMAILL:  info->i = sh2->irq_line_state[SH2_INT_DMAILL]; break;
3335      case CPUINFO_INT_INPUT_STATE + SH2_INT_SPRITE:  info->i = sh2->irq_line_state[SH2_INT_SPRITE]; break;
3336      case CPUINFO_INT_INPUT_STATE + SH2_INT_14:      info->i = sh2->irq_line_state[SH2_INT_14]; break;
3337      case CPUINFO_INT_INPUT_STATE + SH2_INT_15:      info->i = sh2->irq_line_state[SH2_INT_15]; break;
3338      case CPUINFO_INT_INPUT_STATE + SH2_INT_ABUS:    info->i = sh2->irq_line_state[SH2_INT_ABUS];    break;
3339      case CPUINFO_INT_INPUT_STATE + INPUT_LINE_NMI:  info->i = sh2->nmi_line_state;          break;
3340
3341      case CPUINFO_INT_PREVIOUSPC:                    info->i = sh2->ppc;                     break;
3342
3343      case CPUINFO_INT_PC:
3344      case CPUINFO_INT_REGISTER + SH2_PC:             info->i = (sh2->delay) ? (sh2->delay & AM) : (sh2->pc & AM); break;
3345      case CPUINFO_INT_SP:                            info->i = sh2->r[15];                   break;
3346      case CPUINFO_INT_REGISTER + SH2_PR:             info->i = sh2->pr;                      break;
3347      case CPUINFO_INT_REGISTER + SH2_SR:             info->i = sh2->sr;                      break;
3348      case CPUINFO_INT_REGISTER + SH2_GBR:            info->i = sh2->gbr;                     break;
3349      case CPUINFO_INT_REGISTER + SH2_VBR:            info->i = sh2->vbr;                     break;
3350      case CPUINFO_INT_REGISTER + SH2_MACH:           info->i = sh2->mach;                        break;
3351      case CPUINFO_INT_REGISTER + SH2_MACL:           info->i = sh2->macl;                        break;
3352      case CPUINFO_INT_REGISTER + SH2_R0:             info->i = sh2->r[ 0];                   break;
3353      case CPUINFO_INT_REGISTER + SH2_R1:             info->i = sh2->r[ 1];                   break;
3354      case CPUINFO_INT_REGISTER + SH2_R2:             info->i = sh2->r[ 2];                   break;
3355      case CPUINFO_INT_REGISTER + SH2_R3:             info->i = sh2->r[ 3];                   break;
3356      case CPUINFO_INT_REGISTER + SH2_R4:             info->i = sh2->r[ 4];                   break;
3357      case CPUINFO_INT_REGISTER + SH2_R5:             info->i = sh2->r[ 5];                   break;
3358      case CPUINFO_INT_REGISTER + SH2_R6:             info->i = sh2->r[ 6];                   break;
3359      case CPUINFO_INT_REGISTER + SH2_R7:             info->i = sh2->r[ 7];                   break;
3360      case CPUINFO_INT_REGISTER + SH2_R8:             info->i = sh2->r[ 8];                   break;
3361      case CPUINFO_INT_REGISTER + SH2_R9:             info->i = sh2->r[ 9];                   break;
3362      case CPUINFO_INT_REGISTER + SH2_R10:            info->i = sh2->r[10];                   break;
3363      case CPUINFO_INT_REGISTER + SH2_R11:            info->i = sh2->r[11];                   break;
3364      case CPUINFO_INT_REGISTER + SH2_R12:            info->i = sh2->r[12];                   break;
3365      case CPUINFO_INT_REGISTER + SH2_R13:            info->i = sh2->r[13];                   break;
3366      case CPUINFO_INT_REGISTER + SH2_R14:            info->i = sh2->r[14];                   break;
3367      case CPUINFO_INT_REGISTER + SH2_R15:            info->i = sh2->r[15];                   break;
3368      case CPUINFO_INT_REGISTER + SH2_EA:             info->i = sh2->ea;                      break;
3369
3370      /* --- the following bits of info are returned as pointers to data or functions --- */
3371      case CPUINFO_FCT_SET_INFO:                      info->setinfo = CPU_SET_INFO_NAME(sh2);         break;
3372      case CPUINFO_FCT_INIT:                          info->init = CPU_INIT_NAME(sh2);                    break;
3373      case CPUINFO_FCT_RESET:                         info->reset = CPU_RESET_NAME(sh2);              break;
3374      case CPUINFO_FCT_EXIT:                          info->exit = CPU_EXIT_NAME(sh2);                    break;
3375      case CPUINFO_FCT_EXECUTE:                       info->execute = CPU_EXECUTE_NAME(sh2);          break;
3376      case CPUINFO_FCT_BURN:                          info->burn = NULL;                      break;
3377      case CPUINFO_FCT_DISASSEMBLE:                   info->disassemble = CPU_DISASSEMBLE_NAME(sh2);          break;
3378      case CPUINFO_PTR_INSTRUCTION_COUNTER:           info->icount = &sh2->icount;                break;
3379
3380      /* --- the following bits of info are returned as NULL-terminated strings --- */
3381      case CPUINFO_STR_NAME:                          strcpy(info->s, "SH-2 DRC");                break;
3382      case CPUINFO_STR_SHORTNAME:                          strcpy(info->s, "sh2_drc");                break;
3383      case CPUINFO_STR_FAMILY:                    strcpy(info->s, "Hitachi SuperH RISC");     break;
3384      case CPUINFO_STR_VERSION:                   strcpy(info->s, "2.0");             break;
3385      case CPUINFO_STR_SOURCE_FILE:                       strcpy(info->s, __FILE__);              break;
3386      case CPUINFO_STR_CREDITS:                   strcpy(info->s, "Copyright Nicola Salmoria and the MAME team, all rights reserved."); break;
3387
3388      case CPUINFO_STR_FLAGS:
3389         sprintf(info->s, "%c%c%d%c%c",
3390               sh2->sr & M ? 'M':'.',
3391               sh2->sr & Q ? 'Q':'.',
3392               (sh2->sr & I) >> 4,
3393               sh2->sr & S ? 'S':'.',
3394               sh2->sr & T ? 'T':'.');
3395         break;
3396
3397      case CPUINFO_STR_REGISTER + SH2_PC:             sprintf(info->s, "PC  :%08X", sh2->pc); break;
3398      case CPUINFO_STR_REGISTER + SH2_SR:             sprintf(info->s, "SR  :%08X", sh2->sr); break;
3399      case CPUINFO_STR_REGISTER + SH2_PR:             sprintf(info->s, "PR  :%08X", sh2->pr); break;
3400      case CPUINFO_STR_REGISTER + SH2_GBR:            sprintf(info->s, "GBR :%08X", sh2->gbr); break;
3401      case CPUINFO_STR_REGISTER + SH2_VBR:            sprintf(info->s, "VBR :%08X", sh2->vbr); break;
3402      case CPUINFO_STR_REGISTER + SH2_MACH:           sprintf(info->s, "MACH:%08X", sh2->mach); break;
3403      case CPUINFO_STR_REGISTER + SH2_MACL:           sprintf(info->s, "MACL:%08X", sh2->macl); break;
3404      case CPUINFO_STR_REGISTER + SH2_R0:             sprintf(info->s, "R0  :%08X", sh2->r[ 0]); break;
3405      case CPUINFO_STR_REGISTER + SH2_R1:             sprintf(info->s, "R1  :%08X", sh2->r[ 1]); break;
3406      case CPUINFO_STR_REGISTER + SH2_R2:             sprintf(info->s, "R2  :%08X", sh2->r[ 2]); break;
3407      case CPUINFO_STR_REGISTER + SH2_R3:             sprintf(info->s, "R3  :%08X", sh2->r[ 3]); break;
3408      case CPUINFO_STR_REGISTER + SH2_R4:             sprintf(info->s, "R4  :%08X", sh2->r[ 4]); break;
3409      case CPUINFO_STR_REGISTER + SH2_R5:             sprintf(info->s, "R5  :%08X", sh2->r[ 5]); break;
3410      case CPUINFO_STR_REGISTER + SH2_R6:             sprintf(info->s, "R6  :%08X", sh2->r[ 6]); break;
3411      case CPUINFO_STR_REGISTER + SH2_R7:             sprintf(info->s, "R7  :%08X", sh2->r[ 7]); break;
3412      case CPUINFO_STR_REGISTER + SH2_R8:             sprintf(info->s, "R8  :%08X", sh2->r[ 8]); break;
3413      case CPUINFO_STR_REGISTER + SH2_R9:             sprintf(info->s, "R9  :%08X", sh2->r[ 9]); break;
3414      case CPUINFO_STR_REGISTER + SH2_R10:            sprintf(info->s, "R10 :%08X", sh2->r[10]); break;
3415      case CPUINFO_STR_REGISTER + SH2_R11:            sprintf(info->s, "R11 :%08X", sh2->r[11]); break;
3416      case CPUINFO_STR_REGISTER + SH2_R12:            sprintf(info->s, "R12 :%08X", sh2->r[12]); break;
3417      case CPUINFO_STR_REGISTER + SH2_R13:            sprintf(info->s, "R13 :%08X", sh2->r[13]); break;
3418      case CPUINFO_STR_REGISTER + SH2_R14:            sprintf(info->s, "R14 :%08X", sh2->r[14]); break;
3419      case CPUINFO_STR_REGISTER + SH2_R15:            sprintf(info->s, "R15 :%08X", sh2->r[15]); break;
3420      case CPUINFO_STR_REGISTER + SH2_EA:             sprintf(info->s, "EA  :%08X", sh2->ea);    break;
3421   }
3422}
3423
3424/*-------------------------------------------------
3425    sh1_get_info - return information about a
3426    given CPU instance
3427-------------------------------------------------*/
3428
3429CPU_GET_INFO( sh1_drc )
3430{
3431   switch (state)
3432   {
3433      /* --- the following bits of info are returned as pointers to data or functions --- */
3434      case CPUINFO_FCT_RESET:                     info->reset = CPU_RESET_NAME(sh1);              break;
3435
3436      /* --- the following bits of info are returned as NULL-terminated strings --- */
3437      case CPUINFO_STR_NAME:                          strcpy(info->s, "SH-1 DRC");                break;
3438      case CPUINFO_STR_SHORTNAME:                     strcpy(info->s, "sh1_drc");                break;
3439
3440      default:                            CPU_GET_INFO_CALL(sh2_drc);         break;
3441   }
3442}
3443
3444DEFINE_LEGACY_CPU_DEVICE(SH1_DRC, sh1_drc);
3445DEFINE_LEGACY_CPU_DEVICE(SH2_DRC, sh2_drc);
trunk/src/emu/cpu/sh2/sh2fe.c
r29565r29566
1313#include "sh2comn.h"
1414#include "cpu/drcfe.h"
1515
16
1617/***************************************************************************
1718    INSTRUCTION PARSERS
1819***************************************************************************/
1920
20sh2_frontend::sh2_frontend(sh2_state &state, UINT32 window_start, UINT32 window_end, UINT32 max_sequence)
21   : drc_frontend(*state.device, window_start, window_end, max_sequence),
22      m_context(state)
21sh2_frontend::sh2_frontend(sh2_device *device, UINT32 window_start, UINT32 window_end, UINT32 max_sequence)
22   : drc_frontend(*device, window_start, window_end, max_sequence)
23   , m_sh2(device)
2324{
2425}
2526
r29565r29566
3334   UINT16 opcode;
3435
3536   /* fetch the opcode */
36   opcode = desc.opptr.w[0] = m_context.direct->read_decrypted_word(desc.physpc, SH2_CODE_XOR(0));
37   opcode = desc.opptr.w[0] = m_sh2->m_direct->read_decrypted_word(desc.physpc, SH2_CODE_XOR(0));
3738
3839   /* all instructions are 2 bytes and most are a single cycle */
3940   desc.length = 2;
trunk/src/emu/cpu/cpu.mak
r29565r29566
685685
686686ifneq ($(filter SH2,$(CPUS)),)
687687OBJDIRS += $(CPUOBJ)/sh2
688CPUOBJS += $(CPUOBJ)/sh2/sh2.o $(CPUOBJ)/sh2/sh2comn.o $(CPUOBJ)/sh2/sh2drc.o $(CPUOBJ)/sh2/sh2fe.o $(DRCOBJ)
688CPUOBJS += $(CPUOBJ)/sh2/sh2.o $(CPUOBJ)/sh2/sh2fe.o $(DRCOBJ)
689689DASMOBJS += $(CPUOBJ)/sh2/sh2dasm.o
690690endif
691691
692692$(CPUOBJ)/sh2/sh2.o:    $(CPUSRC)/sh2/sh2.c \
693693         $(CPUSRC)/sh2/sh2.h \
694         $(CPUSRC)/sh2/sh2comn.h
695
696$(CPUOBJ)/sh2/sh2comn.o:  $(CPUSRC)/sh2/sh2comn.c \
694         $(CPUSRC)/sh2/sh2comn.c \
695         $(CPUSRC)/sh2/sh2drc.c \
697696         $(CPUSRC)/sh2/sh2comn.h \
698         $(CPUSRC)/sh2/sh2.h
699
700$(CPUOBJ)/sh2/sh2drc.o: $(CPUSRC)/sh2/sh2drc.c \
701         $(CPUSRC)/sh2/sh2.h \
702         $(CPUSRC)/sh2/sh2comn.h \
703697         $(DRCDEPS)
704698
705699$(CPUOBJ)/sh2/sh2fe.o:  $(CPUSRC)/sh2/sh2fe.c \
trunk/src/emu/machine/saturn.c
r29565r29566
590590   machine().scheduler().boost_interleave(m_minit_boost_timeslice, attotime::from_usec(m_minit_boost));
591591   machine().scheduler().trigger(1000);
592592   machine().scheduler().synchronize(); // force resync
593   sh2_set_frt_input(m_slave, PULSE_LINE);
593   m_slave->sh2_set_frt_input(PULSE_LINE);
594594}
595595
596596WRITE32_MEMBER(saturn_state::sinit_w)
r29565r29566
598598   //logerror("cpu %s (PC=%08X) SINIT write = %08x\n", space.device().tag(), space.device().safe_pc(),data);
599599   machine().scheduler().boost_interleave(m_sinit_boost_timeslice, attotime::from_usec(m_sinit_boost));
600600   machine().scheduler().synchronize(); // force resync
601   sh2_set_frt_input(m_maincpu, PULSE_LINE);
601   m_maincpu->sh2_set_frt_input(PULSE_LINE);
602602}
603603
604604/*
r29565r29566
631631      machine().scheduler().trigger(1000);
632632   }
633633
634   sh2_set_frt_input(m_slave, PULSE_LINE);
634   m_slave->sh2_set_frt_input(PULSE_LINE);
635635}
636636
637637WRITE32_MEMBER(saturn_state::saturn_sinit_w)
r29565r29566
642642   else
643643      machine().scheduler().boost_interleave(m_sinit_boost_timeslice, attotime::from_usec(m_sinit_boost));
644644
645   sh2_set_frt_input(m_maincpu, PULSE_LINE);
645   m_maincpu->sh2_set_frt_input(PULSE_LINE);
646646}
647647
648648
trunk/src/mess/machine/mega32x.c
r29565r29566
575575                  current_fifo_block = fifo_block_b;
576576                  current_fifo_readblock = fifo_block_a;
577577                  // incase we have a stalled DMA in progress, let the SH2 know there is data available
578                  sh2_notify_dma_data_available(m_master_cpu);
579                  sh2_notify_dma_data_available(m_slave_cpu);
578                  m_master_cpu->sh2_notify_dma_data_available();
579                  m_slave_cpu->sh2_notify_dma_data_available();
580580
581581               }
582582               current_fifo_write_pos = 0;
r29565r29566
590590                  current_fifo_block = fifo_block_a;
591591                  current_fifo_readblock = fifo_block_b;
592592                  // incase we have a stalled DMA in progress, let the SH2 know there is data available
593                  sh2_notify_dma_data_available(m_master_cpu);
594                  sh2_notify_dma_data_available(m_slave_cpu);
593                  m_master_cpu->sh2_notify_dma_data_available();
594                  m_slave_cpu->sh2_notify_dma_data_available();
595595
596596               }
597597
r29565r29566
19311931
19321932
19331933// checking if these help brutal, they don't.
1934   sh2drc_set_options(m_master_cpu, SH2DRC_COMPATIBLE_OPTIONS);
1935   sh2drc_set_options(m_slave_cpu, SH2DRC_COMPATIBLE_OPTIONS);
1934   m_master_cpu->sh2drc_set_options(SH2DRC_COMPATIBLE_OPTIONS);
1935   m_slave_cpu->sh2drc_set_options(SH2DRC_COMPATIBLE_OPTIONS);
19361936
19371937
19381938// install these now, otherwise we'll get the following (incorrect) warnings on startup..
trunk/src/mess/machine/mega32x.h
r29565r29566
3131public:
3232   sega_32x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
3333
34   required_device<cpu_device> m_master_cpu;
35   required_device<cpu_device> m_slave_cpu;
34   required_device<sh2_device> m_master_cpu;
35   required_device<sh2_device> m_slave_cpu;
3636   required_device<dac_device> m_lch_pwm;
3737   required_device<dac_device> m_rch_pwm;
3838
trunk/src/mess/drivers/saturn.c
r29565r29566
818818   m_vdp2.pal = (rgn == 12) ? 1 : 0;
819819
820820   // set compatible options
821   sh2drc_set_options(m_maincpu, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
822   sh2drc_set_options(m_slave, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
821   m_maincpu->sh2drc_set_options(SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
822   m_slave->sh2drc_set_options(SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
823823
824824   /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
825825   m_minit_boost = 400;
trunk/src/mame/includes/psikyosh.h
r29565r29566
11#include "video/bufsprite.h"
22#include "machine/eepromser.h"
3#include "cpu/sh2/sh2.h"
34
5
46#define MASTER_CLOCK 57272700   // main oscillator frequency
57
68/* Psikyo PS6406B */
r29565r29566
4951   UINT8          m_alphatable[256];
5052
5153   /* devices */
52   required_device<cpu_device> m_maincpu;
54   required_device<sh2_device> m_maincpu;
5355   required_device<eeprom_serial_93cxx_device> m_eeprom;
5456   required_device<gfxdecode_device> m_gfxdecode;
5557   required_device<screen_device> m_screen;
trunk/src/mame/includes/deco_mlc.h
r29565r29566
11#include "machine/eepromser.h"
22#include "machine/deco146.h"
33#include "sound/ymz280b.h"
4#include "cpu/sh2/sh2.h"
45
6
57class deco_mlc_state : public driver_device
68{
79public:
r29565r29566
6769   void blitRaster(bitmap_rgb32 &bitmap, int rasterMode);
6870   void draw_sprites( const rectangle &cliprect, int scanline, UINT32* dest);
6971   void descramble_sound(  );
70   required_device<cpu_device> m_maincpu;
72   required_device<sh2_device> m_maincpu;
7173   required_device<eeprom_serial_93cxx_device> m_eeprom;
7274   required_device<ymz280b_device> m_ymz;
7375   required_device<gfxdecode_device> m_gfxdecode;
trunk/src/mame/includes/suprnova.h
r29565r29566
1
2#include "cpu/sh2/sh2.h"
3
4
15struct hit_t
26{
37   UINT16 x1p, y1p, z1p, x1s, y1s, z1s;
r29565r29566
3438      m_gfxdecode(*this, "gfxdecode"),
3539      m_palette(*this, "palette") { }
3640
37   required_device<cpu_device> m_maincpu;
41   required_device<sh2_device> m_maincpu;
3842   required_shared_ptr<UINT32> m_spriteram;
3943
4044   sknsspr_device* m_spritegen;
trunk/src/mame/includes/cps3.h
r29565r29566
55****************************************************************************/
66
77#include "machine/intelfsh.h"
8#include "cpu/sh2/sh2.h"
89
910class cps3_state : public driver_device
1011{
r29565r29566
132133                           int transparency, int transparent_color,
133134                           int scalex, int scaley, bitmap_ind8 *pri_buffer, UINT32 pri_mask);
134135
135   required_device<cpu_device> m_maincpu;
136   required_device<sh2_device> m_maincpu;
136137   required_device<gfxdecode_device> m_gfxdecode;
137138   required_device<palette_device> m_palette;
138139};
trunk/src/mame/includes/stv.h
r29565r29566
44#include "cpu/m68000/m68000.h"
55#include "cpu/adsp2100/adsp2100.h"
66#include "cpu/scudsp/scudsp.h"
7#include "cpu/sh2/sh2.h"
78
89#define MAX_FILTERS (24)
910#define MAX_BLOCKS  (200)
r29565r29566
144145   UINT8     m_system_output;
145146   UINT16    m_serial_tx;
146147
147   required_device<cpu_device> m_maincpu;
148   required_device<cpu_device> m_slave;
148   required_device<sh2_device> m_maincpu;
149   required_device<sh2_device> m_slave;
149150   required_device<m68000_base_device> m_audiocpu;
150151   required_device<scudsp_cpu_device> m_scudsp;
151152   optional_device<eeprom_serial_93cxx_device> m_eeprom;
trunk/src/mame/drivers/deco_mlc.c
r29565r29566
835835DRIVER_INIT_MEMBER(deco_mlc_state,avengrgs)
836836{
837837   // init options
838   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
838   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
839839
840840   // set up speed cheat
841   sh2drc_add_pcflush(m_maincpu, 0x3234);
842   sh2drc_add_pcflush(m_maincpu, 0x32dc);
841   m_maincpu->sh2drc_add_pcflush(0x3234);
842   m_maincpu->sh2drc_add_pcflush(0x32dc);
843843
844844   m_mainCpuIsArm = 0;
845845   m_maincpu->space(AS_PROGRAM).install_read_handler(0x01089a0, 0x01089a3, read32_delegate(FUNC(deco_mlc_state::avengrgs_speedup_r),this));
trunk/src/mame/drivers/cps3.c
r29565r29566
799799   if (!m_user5region) m_user5region = auto_alloc_array(machine(), UINT8, USER5REGION_LENGTH);
800800
801801   // set strict verify
802   sh2drc_set_options(m_maincpu, SH2DRC_STRICT_VERIFY);
802   m_maincpu->sh2drc_set_options(SH2DRC_STRICT_VERIFY);
803803
804804   cps3_decrypt_bios();
805805   m_decrypted_gamerom = auto_alloc_array(machine(), UINT32, 0x1000000/4);
trunk/src/mame/drivers/psikyosh.c
r29565r29566
11721172
11731173DRIVER_INIT_MEMBER(psikyosh_state,soldivid)
11741174{
1175   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1175   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
11761176}
11771177
11781178DRIVER_INIT_MEMBER(psikyosh_state,s1945ii)
11791179{
1180   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1180   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
11811181}
11821182
11831183DRIVER_INIT_MEMBER(psikyosh_state,daraku)
11841184{
11851185   UINT8 *RAM = memregion("maincpu")->base();
11861186   membank("bank1")->set_base(&RAM[0x100000]);
1187   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1187   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
11881188}
11891189
11901190DRIVER_INIT_MEMBER(psikyosh_state,sbomberb)
11911191{
1192   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1192   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
11931193}
11941194
11951195DRIVER_INIT_MEMBER(psikyosh_state,gunbird2)
11961196{
11971197   UINT8 *RAM = memregion("maincpu")->base();
11981198   membank("bank1")->set_base(&RAM[0x100000]);
1199   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1199   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
12001200}
12011201
12021202DRIVER_INIT_MEMBER(psikyosh_state,s1945iii)
12031203{
12041204   UINT8 *RAM = memregion("maincpu")->base();
12051205   membank("bank1")->set_base(&RAM[0x100000]);
1206   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1206   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
12071207}
12081208
12091209DRIVER_INIT_MEMBER(psikyosh_state,dragnblz)
12101210{
1211   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1211   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
12121212}
12131213
12141214DRIVER_INIT_MEMBER(psikyosh_state,gnbarich)
12151215{
1216   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1216   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
12171217}
12181218
12191219DRIVER_INIT_MEMBER(psikyosh_state,tgm2)
12201220{
1221   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1221   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
12221222}
12231223
12241224DRIVER_INIT_MEMBER(psikyosh_state,mjgtaste)
12251225{
1226   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
1226   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
12271227   /* needs to install mahjong controls too (can select joystick in test mode tho) */
12281228   m_maincpu->space(AS_PROGRAM).install_read_handler(0x03000000, 0x03000003, read32_delegate(FUNC(psikyosh_state::mjgtaste_input_r),this));
12291229}
trunk/src/mame/drivers/coolridr.c
r29565r29566
344344   UINT32 m_clipvals[2][3];
345345   UINT8  m_clipblitterMode[2]; // hack
346346
347   required_device<cpu_device> m_maincpu;
348   required_device<cpu_device> m_subcpu;
347   required_device<sh2_device> m_maincpu;
348   required_device<sh2_device> m_subcpu;
349349   required_device<cpu_device> m_soundcpu;
350350   //required_device<am9517a_device> m_dmac;
351351
r29565r29566
37043704{
37053705   m_maincpu->space(AS_PROGRAM).install_read_handler(0x60d8894, 0x060d8897, read32_delegate(FUNC(coolridr_state::coolridr_hack2_r), this));
37063706
3707   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
3708   sh2drc_set_options(m_subcpu, SH2DRC_FASTEST_OPTIONS);
3707   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
3708   m_subcpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
37093709}
37103710
37113711GAME( 1995, coolridr,    0, coolridr,    coolridr, coolridr_state,    coolridr, ROT0,  "Sega", "Cool Riders",GAME_IMPERFECT_SOUND) // region is set in test mode, this set is for Japan, USA and Export (all regions)
trunk/src/mame/drivers/suprnova.c
r29565r29566
945945void skns_state::init_skns()
946946{
947947   // init DRC to fastest options
948   sh2drc_set_options(m_maincpu, SH2DRC_FASTEST_OPTIONS);
948   m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
949949}
950950
951951void skns_state::set_drc_pcflush(UINT32 addr)
952952{
953   sh2drc_add_pcflush(m_maincpu, addr);
953   m_maincpu->sh2drc_add_pcflush(addr);
954954}
955955
956956DRIVER_INIT_MEMBER(skns_state,galpani4)   { machine().device<sknsspr_device>("spritegen")->skns_sprite_kludge(-5,-1); init_skns();  }
trunk/src/mame/drivers/stv.c
r29565r29566
359359void stv_state::install_stvbios_speedups( void )
360360{
361361   // flushes 0 & 1 on both CPUs are for the BIOS speedups
362   sh2drc_add_pcflush(m_maincpu, 0x60154b2);
363   sh2drc_add_pcflush(m_maincpu, 0x6013aee);
362   m_maincpu->sh2drc_add_pcflush(0x60154b2);
363   m_maincpu->sh2drc_add_pcflush(0x6013aee);
364364
365   sh2drc_add_pcflush(m_slave, 0x60154b2);
366   sh2drc_add_pcflush(m_slave, 0x6013aee);
365   m_slave->sh2drc_add_pcflush(0x60154b2);
366   m_slave->sh2drc_add_pcflush(0x6013aee);
367367}
368368
369369DRIVER_INIT_MEMBER(stv_state,stv)
r29565r29566
387387   // do strict overwrite verification - maruchan and rsgun crash after coinup without this.
388388   // cottonbm needs strict PCREL
389389   // todo: test what games need this and don't turn it on for them...
390   sh2drc_set_options(m_maincpu, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
391   sh2drc_set_options(m_slave, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
390   m_maincpu->sh2drc_set_options(SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
391   m_slave->sh2drc_set_options(SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
392392
393393   m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x00400000, 0x0040003f, read32_delegate(FUNC(stv_state::stv_ioga_r32),this), write32_delegate(FUNC(stv_state::stv_ioga_w32),this));
394394   m_slave->space(AS_PROGRAM).install_readwrite_handler(0x00400000, 0x0040003f, read32_delegate(FUNC(stv_state::stv_ioga_r32),this), write32_delegate(FUNC(stv_state::stv_ioga_w32),this));
r29565r29566
429429
430430DRIVER_INIT_MEMBER(stv_state,magzun)
431431{
432   sh2drc_add_pcflush(m_maincpu, 0x604bf20);
433   sh2drc_add_pcflush(m_maincpu, 0x604bfbe);
434   sh2drc_add_pcflush(m_maincpu, 0x604c006);
432   m_maincpu->sh2drc_add_pcflush(0x604bf20);
433   m_maincpu->sh2drc_add_pcflush(0x604bfbe);
434   m_maincpu->sh2drc_add_pcflush(0x604c006);
435435
436436   DRIVER_INIT_CALL(stv);
437437
r29565r29566
463463DRIVER_INIT_MEMBER(stv_state,shienryu)
464464{
465465   // master
466   sh2drc_add_pcflush(m_maincpu, 0x60041c6);
466   m_maincpu->sh2drc_add_pcflush(0x60041c6);
467467   // slave
468   sh2drc_add_pcflush(m_slave, 0x600440e);
468   m_slave->sh2drc_add_pcflush(0x600440e);
469469
470470   DRIVER_INIT_CALL(stv);
471471}
r29565r29566
481481*/
482482
483483   // master
484   sh2drc_add_pcflush(m_maincpu, 0x6018640);
484   m_maincpu->sh2drc_add_pcflush(0x6018640);
485485   // slave
486   sh2drc_add_pcflush(m_slave, 0x6018c6e);
486   m_slave->sh2drc_add_pcflush(0x6018c6e);
487487
488488   DRIVER_INIT_CALL(stv);
489489
r29565r29566
510510
511511   (loops for 288688 instructions)
512512*/
513   sh2drc_add_pcflush(m_maincpu, 0x6010160);
513   m_maincpu->sh2drc_add_pcflush(0x6010160);
514514
515515   DRIVER_INIT_CALL(stv);
516516}
r29565r29566
536536
537537DRIVER_INIT_MEMBER(stv_state,puyosun)
538538{
539   sh2drc_add_pcflush(m_maincpu, 0x6021cf0);
539   m_maincpu->sh2drc_add_pcflush(0x6021cf0);
540540
541   sh2drc_add_pcflush(m_slave, 0x60236fe);
541   m_slave->sh2drc_add_pcflush(0x60236fe);
542542
543543   DRIVER_INIT_CALL(stv);
544544
r29565r29566
558558
559559DRIVER_INIT_MEMBER(stv_state,mausuke)
560560{
561   sh2drc_add_pcflush(m_maincpu, 0x60461A0);
561   m_maincpu->sh2drc_add_pcflush(0x60461A0);
562562
563563   DRIVER_INIT_CALL(stv);
564564
r29565r29566
568568
569569DRIVER_INIT_MEMBER(stv_state,cottonbm)
570570{
571//  sh2drc_add_pcflush(m_maincpu, 0x6030ee2);
572//  sh2drc_add_pcflush(m_slave, 0x6032b52);
571//  m_maincpu->sh2drc_add_pcflush(0x6030ee2);
572//  m_slave->sh2drc_add_pcflush(0x6032b52);
573573
574574   DRIVER_INIT_CALL(stv);
575575
r29565r29566
578578
579579DRIVER_INIT_MEMBER(stv_state,cotton2)
580580{
581   sh2drc_add_pcflush(m_maincpu, 0x6031c7a);
582   sh2drc_add_pcflush(m_slave, 0x60338ea);
581   m_maincpu->sh2drc_add_pcflush(0x6031c7a);
582   m_slave->sh2drc_add_pcflush(0x60338ea);
583583
584584   DRIVER_INIT_CALL(stv);
585585
r29565r29566
589589DRIVER_INIT_MEMBER(stv_state,dnmtdeka)
590590{
591591   // install all 3 speedups on both master and slave
592   sh2drc_add_pcflush(m_maincpu, 0x6027c90);
593   sh2drc_add_pcflush(m_maincpu, 0xd04);
594   sh2drc_add_pcflush(m_maincpu, 0x60051f2);
592   m_maincpu->sh2drc_add_pcflush(0x6027c90);
593   m_maincpu->sh2drc_add_pcflush(0xd04);
594   m_maincpu->sh2drc_add_pcflush(0x60051f2);
595595
596   sh2drc_add_pcflush(m_slave, 0x6027c90);
597   sh2drc_add_pcflush(m_slave, 0xd04);
598   sh2drc_add_pcflush(m_slave, 0x60051f2);
596   m_slave->sh2drc_add_pcflush(0x6027c90);
597   m_slave->sh2drc_add_pcflush(0xd04);
598   m_slave->sh2drc_add_pcflush(0x60051f2);
599599
600600   DRIVER_INIT_CALL(stv);
601601}
r29565r29566
603603DRIVER_INIT_MEMBER(stv_state,diehard)
604604{
605605   // install all 3 speedups on both master and slave
606   sh2drc_add_pcflush(m_maincpu, 0x6027c98);
607   sh2drc_add_pcflush(m_maincpu, 0xd04);
608   sh2drc_add_pcflush(m_maincpu, 0x60051f2);
606   m_maincpu->sh2drc_add_pcflush(0x6027c98);
607   m_maincpu->sh2drc_add_pcflush(0xd04);
608   m_maincpu->sh2drc_add_pcflush(0x60051f2);
609609
610   sh2drc_add_pcflush(m_slave, 0x6027c98);
611   sh2drc_add_pcflush(m_slave, 0xd04);
612   sh2drc_add_pcflush(m_slave, 0x60051f2);
610   m_slave->sh2drc_add_pcflush(0x6027c98);
611   m_slave->sh2drc_add_pcflush(0xd04);
612   m_slave->sh2drc_add_pcflush(0x60051f2);
613613
614614   DRIVER_INIT_CALL(stv);
615615}
616616
617617DRIVER_INIT_MEMBER(stv_state,fhboxers)
618618{
619   sh2drc_add_pcflush(m_maincpu, 0x60041c2);
620   sh2drc_add_pcflush(m_maincpu, 0x600bb0a);
621   sh2drc_add_pcflush(m_maincpu, 0x600b31e);
619   m_maincpu->sh2drc_add_pcflush(0x60041c2);
620   m_maincpu->sh2drc_add_pcflush(0x600bb0a);
621   m_maincpu->sh2drc_add_pcflush(0x600b31e);
622622
623623   DRIVER_INIT_CALL(stv);
624624
r29565r29566
627627
628628DRIVER_INIT_MEMBER(stv_state,groovef)
629629{
630   sh2drc_add_pcflush(m_maincpu, 0x6005e7c);
631   sh2drc_add_pcflush(m_maincpu, 0x6005e86);
632   sh2drc_add_pcflush(m_maincpu, 0x60a4970);
630   m_maincpu->sh2drc_add_pcflush(0x6005e7c);
631   m_maincpu->sh2drc_add_pcflush(0x6005e86);
632   m_maincpu->sh2drc_add_pcflush(0x60a4970);
633633
634   sh2drc_add_pcflush(m_slave, 0x60060c2);
634   m_slave->sh2drc_add_pcflush(0x60060c2);
635635
636636   DRIVER_INIT_CALL(stv);
637637
r29565r29566
641641
642642DRIVER_INIT_MEMBER(stv_state,danchih)
643643{
644   sh2drc_add_pcflush(m_maincpu, 0x6028b28);
645   sh2drc_add_pcflush(m_maincpu, 0x6028c8e);
646   sh2drc_add_pcflush(m_slave, 0x602ae26);
644   m_maincpu->sh2drc_add_pcflush(0x6028b28);
645   m_maincpu->sh2drc_add_pcflush(0x6028c8e);
646   m_slave->sh2drc_add_pcflush(0x602ae26);
647647
648648   DRIVER_INIT_CALL(stvmp);
649649
r29565r29566
652652
653653DRIVER_INIT_MEMBER(stv_state,danchiq)
654654{
655   sh2drc_add_pcflush(m_maincpu, 0x6028b28);
656   sh2drc_add_pcflush(m_maincpu, 0x6028c8e);
657   sh2drc_add_pcflush(m_slave, 0x602ae26);
655   m_maincpu->sh2drc_add_pcflush(0x6028b28);
656   m_maincpu->sh2drc_add_pcflush(0x6028c8e);
657   m_slave->sh2drc_add_pcflush(0x602ae26);
658658
659659   DRIVER_INIT_CALL(stv);
660660
r29565r29566
663663
664664DRIVER_INIT_MEMBER(stv_state,astrass)
665665{
666   sh2drc_add_pcflush(m_maincpu, 0x60011ba);
667   sh2drc_add_pcflush(m_maincpu, 0x605b9da);
666   m_maincpu->sh2drc_add_pcflush(0x60011ba);
667   m_maincpu->sh2drc_add_pcflush(0x605b9da);
668668
669669   install_astrass_protection();
670670
r29565r29566
673673
674674DRIVER_INIT_MEMBER(stv_state,thunt)
675675{
676   sh2drc_add_pcflush(m_maincpu, 0x602A024);
677   sh2drc_add_pcflush(m_maincpu, 0x6013EEA);
678   sh2drc_add_pcflush(m_slave, 0x602AAF8);
676   m_maincpu->sh2drc_add_pcflush(0x602A024);
677   m_maincpu->sh2drc_add_pcflush(0x6013EEA);
678   m_slave->sh2drc_add_pcflush(0x602AAF8);
679679
680680   DRIVER_INIT_CALL(stv);
681681
r29565r29566
684684
685685DRIVER_INIT_MEMBER(stv_state,sandor)
686686{
687   sh2drc_add_pcflush(m_maincpu, 0x602a0f8);
688   sh2drc_add_pcflush(m_maincpu, 0x6013fbe);
689   sh2drc_add_pcflush(m_slave, 0x602abcc);
687   m_maincpu->sh2drc_add_pcflush(0x602a0f8);
688   m_maincpu->sh2drc_add_pcflush(0x6013fbe);
689   m_slave->sh2drc_add_pcflush(0x602abcc);
690690
691691   DRIVER_INIT_CALL(stv);
692692   m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(1);
r29565r29566
694694
695695DRIVER_INIT_MEMBER(stv_state,grdforce)
696696{
697   sh2drc_add_pcflush(m_maincpu, 0x6041e32);
698   sh2drc_add_pcflush(m_slave, 0x6043aa2);
697   m_maincpu->sh2drc_add_pcflush(0x6041e32);
698   m_slave->sh2drc_add_pcflush(0x6043aa2);
699699
700700   DRIVER_INIT_CALL(stv);
701701
r29565r29566
704704
705705DRIVER_INIT_MEMBER(stv_state,batmanfr)
706706{
707   sh2drc_add_pcflush(m_maincpu, 0x60121c0);
708   sh2drc_add_pcflush(m_slave, 0x60125bc);
707   m_maincpu->sh2drc_add_pcflush(0x60121c0);
708   m_slave->sh2drc_add_pcflush(0x60125bc);
709709
710710   DRIVER_INIT_CALL(stv);
711711
r29565r29566
718718
719719DRIVER_INIT_MEMBER(stv_state,colmns97)
720720{
721   sh2drc_add_pcflush(m_slave, 0x60298a2);
721   m_slave->sh2drc_add_pcflush(0x60298a2);
722722
723723   DRIVER_INIT_CALL(stv);
724724
r29565r29566
727727
728728DRIVER_INIT_MEMBER(stv_state,winterht)
729729{
730   sh2drc_add_pcflush(m_maincpu, 0x6098aea);
731   sh2drc_add_pcflush(m_slave, 0x609ae4e);
730   m_maincpu->sh2drc_add_pcflush(0x6098aea);
731   m_slave->sh2drc_add_pcflush(0x609ae4e);
732732
733733   DRIVER_INIT_CALL(stv);
734734
r29565r29566
737737
738738DRIVER_INIT_MEMBER(stv_state,seabass)
739739{
740   sh2drc_add_pcflush(m_maincpu, 0x602cbfa);
741   sh2drc_add_pcflush(m_slave, 0x60321ee);
740   m_maincpu->sh2drc_add_pcflush(0x602cbfa);
741   m_slave->sh2drc_add_pcflush(0x60321ee);
742742
743743   DRIVER_INIT_CALL(stv);
744744
r29565r29566
747747
748748DRIVER_INIT_MEMBER(stv_state,vfremix)
749749{
750   sh2drc_add_pcflush(m_maincpu, 0x602c30c);
751   sh2drc_add_pcflush(m_slave, 0x604c332);
750   m_maincpu->sh2drc_add_pcflush(0x602c30c);
751   m_slave->sh2drc_add_pcflush(0x604c332);
752752
753753   DRIVER_INIT_CALL(stv);
754754
r29565r29566
757757
758758DRIVER_INIT_MEMBER(stv_state,sss)
759759{
760   sh2drc_add_pcflush(m_maincpu, 0x6026398);
761   sh2drc_add_pcflush(m_slave, 0x6028cd6);
760   m_maincpu->sh2drc_add_pcflush(0x6026398);
761   m_slave->sh2drc_add_pcflush(0x6028cd6);
762762
763763   install_sss_protection();
764764
r29565r29566
769769
770770DRIVER_INIT_MEMBER(stv_state,othellos)
771771{
772   sh2drc_add_pcflush(m_maincpu, 0x602bcbe);
773   sh2drc_add_pcflush(m_slave, 0x602d92e);
772   m_maincpu->sh2drc_add_pcflush(0x602bcbe);
773   m_slave->sh2drc_add_pcflush(0x602d92e);
774774
775775   DRIVER_INIT_CALL(stv);
776776
r29565r29566
779779
780780DRIVER_INIT_MEMBER(stv_state,sasissu)
781781{
782   sh2drc_add_pcflush(m_slave, 0x60710be);
782   m_slave->sh2drc_add_pcflush(0x60710be);
783783
784784   DRIVER_INIT_CALL(stv);
785785
r29565r29566
788788
789789DRIVER_INIT_MEMBER(stv_state,gaxeduel)
790790{
791//  sh2drc_add_pcflush(m_maincpu, 0x6012ee4);
791//  m_maincpu->sh2drc_add_pcflush(0x6012ee4);
792792
793793   DRIVER_INIT_CALL(stv);
794794}
795795
796796DRIVER_INIT_MEMBER(stv_state,suikoenb)
797797{
798   sh2drc_add_pcflush(m_maincpu, 0x6013f7a);
798   m_maincpu->sh2drc_add_pcflush(0x6013f7a);
799799
800800   DRIVER_INIT_CALL(stv);
801801}
r29565r29566
810810
811811DRIVER_INIT_MEMBER(stv_state,znpwfv)
812812{
813   sh2drc_add_pcflush(m_maincpu, 0x6012ec2);
814   sh2drc_add_pcflush(m_slave, 0x60175a6);
813   m_maincpu->sh2drc_add_pcflush(0x6012ec2);
814   m_slave->sh2drc_add_pcflush(0x60175a6);
815815
816816   DRIVER_INIT_CALL(stv);
817817   m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_nsec(500);
r29565r29566
819819
820820DRIVER_INIT_MEMBER(stv_state,twcup98)
821821{
822   sh2drc_add_pcflush(m_maincpu, 0x605edde);
823   sh2drc_add_pcflush(m_slave, 0x6062bca);
822   m_maincpu->sh2drc_add_pcflush(0x605edde);
823   m_slave->sh2drc_add_pcflush(0x6062bca);
824824
825825   DRIVER_INIT_CALL(stv);
826826   install_twcup98_protection();
r29565r29566
830830
831831DRIVER_INIT_MEMBER(stv_state,smleague)
832832{
833   sh2drc_add_pcflush(m_maincpu, 0x6063bf4);
834   sh2drc_add_pcflush(m_slave, 0x6062bca);
833   m_maincpu->sh2drc_add_pcflush(0x6063bf4);
834   m_slave->sh2drc_add_pcflush(0x6062bca);
835835
836836   DRIVER_INIT_CALL(stv);
837837
r29565r29566
842842
843843DRIVER_INIT_MEMBER(stv_state,finlarch)
844844{
845   sh2drc_add_pcflush(m_maincpu, 0x6064d60);
845   m_maincpu->sh2drc_add_pcflush(0x6064d60);
846846
847847   DRIVER_INIT_CALL(stv);
848848
r29565r29566
853853
854854DRIVER_INIT_MEMBER(stv_state,maruchan)
855855{
856   sh2drc_add_pcflush(m_maincpu, 0x601ba46);
857   sh2drc_add_pcflush(m_slave, 0x601ba46);
856   m_maincpu->sh2drc_add_pcflush(0x601ba46);
857   m_slave->sh2drc_add_pcflush(0x601ba46);
858858
859859   DRIVER_INIT_CALL(stv);
860860
r29565r29566
863863
864864DRIVER_INIT_MEMBER(stv_state,pblbeach)
865865{
866   sh2drc_add_pcflush(m_maincpu, 0x605eb78);
866   m_maincpu->sh2drc_add_pcflush(0x605eb78);
867867
868868   DRIVER_INIT_CALL(stv);
869869}
870870
871871DRIVER_INIT_MEMBER(stv_state,shanhigw)
872872{
873   sh2drc_add_pcflush(m_maincpu, 0x6020c5c);
873   m_maincpu->sh2drc_add_pcflush(0x6020c5c);
874874
875875   DRIVER_INIT_CALL(stv);
876876}
877877
878878DRIVER_INIT_MEMBER(stv_state,elandore)
879879{
880   sh2drc_add_pcflush(m_maincpu, 0x604eac0);
881   sh2drc_add_pcflush(m_slave, 0x605340a);
880   m_maincpu->sh2drc_add_pcflush(0x604eac0);
881   m_slave->sh2drc_add_pcflush(0x605340a);
882882
883883   install_elandore_protection();
884884
r29565r29566
888888
889889DRIVER_INIT_MEMBER(stv_state,rsgun)
890890{
891   sh2drc_add_pcflush(m_maincpu, 0x6034d04);
892   sh2drc_add_pcflush(m_slave, 0x6036152);
891   m_maincpu->sh2drc_add_pcflush(0x6034d04);
892   m_slave->sh2drc_add_pcflush(0x6036152);
893893
894894   install_rsgun_protection();
895895
r29565r29566
915915
916916DRIVER_INIT_MEMBER(stv_state,nameclv3)
917917{
918   sh2drc_add_pcflush(m_maincpu, 0x601eb4c);
919   sh2drc_add_pcflush(m_slave, 0x602b80e);
918   m_maincpu->sh2drc_add_pcflush(0x601eb4c);
919   m_slave->sh2drc_add_pcflush(0x602b80e);
920920
921921   DRIVER_INIT_CALL(stv);
922922}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team