Previous 199869 Revisions Next

r26753 Wednesday 25th December, 2013 at 19:39:13 UTC by Wilbert Pol
superfx.c: Modernized cpu core.  [Wilbert Pol]
[src/emu/cpu/superfx]superfx.c superfx.h
[src/mess/machine]sns_sfx.c sns_sfx.h

trunk/src/emu/cpu/superfx/superfx.c
r26752r26753
22#include "debugger.h"
33#include "superfx.h"
44
5struct pixelcache_t
6{
7   UINT16 offset;
8   UINT8 bitpend;
9   UINT8 data[8];
10};
115
12struct cache_t
13{
14   UINT8 buffer[0x200];
15   UINT8 valid[0x20];
16};
6const device_type SUPERFX = &device_creator<superfx_device>;
177
18struct superfx_state
8superfx_device::superfx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
9   : cpu_device(mconfig, SUPERFX, "SuperFX", tag, owner, clock, "superfx", __FILE__)
10   , m_program_config("program", ENDIANNESS_LITTLE, 8, 32, 0)
11   , m_out_irq_func(*this)
1912{
20   superfx_config config;
21
22   devcb_resolved_write_line   out_irq_func;
23
24   UINT8  pipeline;
25   UINT16 ramaddr; // RAM Address
26
27   UINT16 r[16];   // GPRs
28   UINT16 sfr;     // Status Flag Register
29   UINT8  pbr;     // Program Bank Register
30   UINT8  rombr;   // Game Pack ROM Bank Register
31   UINT8  rambr;   // Game Pack RAM Bank Register
32   UINT16 cbr;     // Cache Base Register
33   UINT8  scbr;    // Screen Base Register
34   UINT8  scmr;    // Screen Mode Register
35   UINT8  colr;    // Color Register
36   UINT8  por;     // Plot Option Register
37   UINT8  bramr;   // Back-Up RAM Register
38   UINT8  vcr;     // Version Code Register
39   UINT8  cfgr;    // Config Register
40   UINT8  clsr;    // Clock Select Register
41
42   UINT32 romcl;   // Clock ticks until ROMDR is valid
43   UINT8  romdr;   // ROM Buffer Data Register
44
45   UINT32 ramcl;   // Clock ticks until RAMDR is valid;
46   UINT16 ramar;   // RAM Buffer Address Register
47   UINT8  ramdr;   // RAM Buffer Data Register
48
49   UINT16 *sreg;   // Source Register (From)
50   UINT8  sreg_idx;// Source Register (To), index
51   UINT16 *dreg;   // Destination Register (To)
52   UINT8  dreg_idx;// Destination Register (To), index
53   UINT8  r15_modified;
54
55   UINT8  irq;     // IRQ Pending
56
57   UINT32 cache_access_speed;
58   UINT32 memory_access_speed;
59
60   cache_t cache;
61   pixelcache_t pixelcache[2];
62
63   legacy_cpu_device *device;
64   address_space *program;
65   int icount;
66};
67
68INLINE superfx_state *get_safe_token(device_t *device)
69{
70   assert(device != NULL);
71   assert(device->type() == SUPERFX);
72   return (superfx_state *)downcast<legacy_cpu_device *>(device)->token();
7313}
7414
75/*****************************************************************************/
7615
77INLINE void superfx_regs_reset(superfx_state *cpustate);
78static void superfx_update_speed(superfx_state *cpustate);
79static void superfx_cache_flush(superfx_state *cpustate);
80static UINT8 superfx_cache_mmio_read(superfx_state *cpustate, UINT32 addr);
81static void superfx_cache_mmio_write(superfx_state *cpustate, UINT32 addr, UINT8 data);
82static void superfx_memory_reset(superfx_state *cpustate);
83INLINE UINT8 superfx_bus_read(superfx_state *cpustate, UINT32 addr);
84INLINE void superfx_bus_write(superfx_state *cpustate, UINT32 addr, UINT8 data);
85INLINE void superfx_pixelcache_flush(superfx_state *cpustate, INT32 line);
86INLINE void superfx_plot(superfx_state *cpustate, UINT8 x, UINT8 y);
87static UINT8 superfx_rpix(superfx_state *cpustate, UINT8 r1, UINT8 r2);
88INLINE UINT8 superfx_color(superfx_state *cpustate, UINT8 source);
16#define SUPERFX_SFR_OV_SET      ((m_sfr & SUPERFX_SFR_OV) ? 1 : 0)
17#define SUPERFX_SFR_OV_CLEAR    ((m_sfr & SUPERFX_SFR_OV) ? 0 : 1)
18#define SUPERFX_SFR_S_SET       ((m_sfr & SUPERFX_SFR_S) ? 1 : 0)
19#define SUPERFX_SFR_S_CLEAR     ((m_sfr & SUPERFX_SFR_S) ? 0 : 1)
20#define SUPERFX_SFR_CY_SET      ((m_sfr & SUPERFX_SFR_CY) ? 1 : 0)
21#define SUPERFX_SFR_CY_CLEAR    ((m_sfr & SUPERFX_SFR_CY) ? 0 : 1)
22#define SUPERFX_SFR_Z_SET       ((m_sfr & SUPERFX_SFR_Z) ? 1 : 0)
23#define SUPERFX_SFR_Z_CLEAR     ((m_sfr & SUPERFX_SFR_Z) ? 0 : 1)
8924
90INLINE void superfx_rambuffer_sync(superfx_state *cpustate);
91INLINE UINT8 superfx_rambuffer_read(superfx_state *cpustate, UINT16 addr);
92INLINE void superfx_rambuffer_write(superfx_state *cpustate, UINT16 addr, UINT8 val);
9325
94INLINE void superfx_rombuffer_sync(superfx_state *cpustate);
95INLINE void superfx_rombuffer_update(superfx_state *cpustate);
96INLINE UINT8 superfx_rombuffer_read(superfx_state *cpustate);
97
98INLINE void superfx_gpr_write(superfx_state *cpustate, UINT8 r, UINT16 data);
99INLINE UINT8 superfx_op_read(superfx_state *cpustate, UINT16 addr);
100INLINE UINT8 superfx_peekpipe(superfx_state *cpustate);
101INLINE UINT8 superfx_pipe(superfx_state *cpustate);
102INLINE void superfx_add_clocks_internal(superfx_state *cpustate, UINT32 clocks);
103static void superfx_timing_reset(superfx_state *cpustate);
104
105/*****************************************************************************/
106
107#define SUPERFX_SFR_OV_SET      ((cpustate->sfr & SUPERFX_SFR_OV) ? 1 : 0)
108#define SUPERFX_SFR_OV_CLEAR    ((cpustate->sfr & SUPERFX_SFR_OV) ? 0 : 1)
109#define SUPERFX_SFR_S_SET       ((cpustate->sfr & SUPERFX_SFR_S) ? 1 : 0)
110#define SUPERFX_SFR_S_CLEAR     ((cpustate->sfr & SUPERFX_SFR_S) ? 0 : 1)
111#define SUPERFX_SFR_CY_SET      ((cpustate->sfr & SUPERFX_SFR_CY) ? 1 : 0)
112#define SUPERFX_SFR_CY_CLEAR    ((cpustate->sfr & SUPERFX_SFR_CY) ? 0 : 1)
113#define SUPERFX_SFR_Z_SET       ((cpustate->sfr & SUPERFX_SFR_Z) ? 1 : 0)
114#define SUPERFX_SFR_Z_CLEAR     ((cpustate->sfr & SUPERFX_SFR_Z) ? 0 : 1)
115
116INLINE void superfx_regs_reset(superfx_state *cpustate)
26void superfx_device::superfx_regs_reset()
11727{
118   cpustate->sfr &= ~(SUPERFX_SFR_B | SUPERFX_SFR_ALT3);
28   m_sfr &= ~(SUPERFX_SFR_B | SUPERFX_SFR_ALT3);
11929
120   cpustate->sreg = &cpustate->r[0];
121   cpustate->dreg = &cpustate->r[0];
122   cpustate->dreg_idx = 0;
123   cpustate->sreg_idx = 0;
30   m_sreg = &m_r[0];
31   m_dreg = &m_r[0];
32   m_dreg_idx = 0;
33   m_sreg_idx = 0;
12434}
12535
126static void superfx_update_speed(superfx_state *cpustate)
36void superfx_device::superfx_update_speed()
12737{
128   cpustate->cache_access_speed = (cpustate->clsr ? 1 : 2);
129   cpustate->memory_access_speed = (cpustate->clsr ? 5 : 6);
130   if(cpustate->clsr)
38   m_cache_access_speed = (m_clsr ? 1 : 2);
39   m_memory_access_speed = (m_clsr ? 5 : 6);
40   if(m_clsr)
13141   {
132      cpustate->cfgr &= ~SUPERFX_CFGR_MS0; // Cannot use high-speed multiplication in 21MHz mode
42      m_cfgr &= ~SUPERFX_CFGR_MS0; // Cannot use high-speed multiplication in 21MHz mode
13343   }
13444}
13545
136static void superfx_cache_flush(superfx_state *cpustate)
46void superfx_device::superfx_cache_flush()
13747{
13848   UINT32 n = 0;
13949   for(n = 0; n < 32; n++)
14050   {
141      cpustate->cache.valid[n] = 0;
51      m_cache.valid[n] = 0;
14252   }
14353}
14454
145static UINT8 superfx_cache_mmio_read(superfx_state *cpustate, UINT32 addr)
55UINT8 superfx_device::superfx_cache_mmio_read(UINT32 addr)
14656{
147   addr = (addr + cpustate->cbr) & 0x1ff;
148   return cpustate->cache.buffer[addr];
57   addr = (addr + m_cbr) & 0x1ff;
58   return m_cache.buffer[addr];
14959}
15060
151static void superfx_cache_mmio_write(superfx_state *cpustate, UINT32 addr, UINT8 data)
61void superfx_device::superfx_cache_mmio_write(UINT32 addr, UINT8 data)
15262{
153   addr = (addr + cpustate->cbr) & 0x1ff;
154   cpustate->cache.buffer[addr] = data;
63   addr = (addr + m_cbr) & 0x1ff;
64   m_cache.buffer[addr] = data;
15565   if((addr & 15) == 15)
15666   {
157      cpustate->cache.valid[addr >> 4] = 1;
67      m_cache.valid[addr >> 4] = 1;
15868   }
15969}
16070
161static void superfx_memory_reset(superfx_state *cpustate)
71void superfx_device::superfx_memory_reset()
16272{
16373   UINT32 n = 0;
16474   for(n = 0; n < 0x200; n++)
16575   {
166      cpustate->cache.buffer[n] = 0x00;
76      m_cache.buffer[n] = 0x00;
16777   }
16878   for(n = 0; n < 0x20; n++)
16979   {
170      cpustate->cache.valid[n] = 0;
80      m_cache.valid[n] = 0;
17181   }
17282   for(n = 0; n < 2; n++)
17383   {
174      cpustate->pixelcache[n].offset = ~0;
175      cpustate->pixelcache[n].bitpend = 0x00;
84      m_pixelcache[n].offset = ~0;
85      m_pixelcache[n].bitpend = 0x00;
17686   }
17787}
17888
179INLINE UINT8 superfx_bus_read(superfx_state *cpustate, UINT32 addr)
89UINT8 superfx_device::superfx_bus_read(UINT32 addr)
18090{
181   return cpustate->program->read_byte(addr);
91   return m_program->read_byte(addr);
18292}
18393
184INLINE void superfx_bus_write(superfx_state *cpustate, UINT32 addr, UINT8 data)
94void superfx_device::superfx_bus_write(UINT32 addr, UINT8 data)
18595{
186   cpustate->program->write_byte(addr, data);
96   m_program->write_byte(addr, data);
18797}
18898
189INLINE void superfx_pixelcache_flush(superfx_state *cpustate, INT32 line)
99void superfx_device::superfx_pixelcache_flush(INT32 line)
190100{
191   UINT8 x = cpustate->pixelcache[line].offset << 3;
192   UINT8 y = cpustate->pixelcache[line].offset >> 5;
101   UINT8 x = m_pixelcache[line].offset << 3;
102   UINT8 y = m_pixelcache[line].offset >> 5;
193103   UINT32 cn = 0;
194   UINT32 bpp = 2 << ((cpustate->scmr & SUPERFX_SCMR_MD) - ((cpustate->scmr & SUPERFX_SCMR_MD) >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 };
104   UINT32 bpp = 2 << ((m_scmr & SUPERFX_SCMR_MD) - ((m_scmr & SUPERFX_SCMR_MD) >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 };
195105   UINT32 addr = 0;
196106   UINT32 n = 0;
197107
198   if(cpustate->pixelcache[line].bitpend == 0x00)
108   if(m_pixelcache[line].bitpend == 0x00)
199109   {
200110      return;
201111   }
202112
203   switch(((cpustate->por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (cpustate->scmr & SUPERFX_SCMR_HT_MASK)))
113   switch(((m_por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (m_scmr & SUPERFX_SCMR_HT_MASK)))
204114   {
205115      case SUPERFX_SCMR_HT0:
206116         cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 3);
r26752r26753
216126         break;
217127   }
218128
219   addr = 0x700000 + (cn * (bpp << 3)) + (cpustate->scbr << 10) + ((y & 0x07) * 2);
129   addr = 0x700000 + (cn * (bpp << 3)) + (m_scbr << 10) + ((y & 0x07) * 2);
220130
221131   for(n = 0; n < bpp; n++)
222132   {
r26752r26753
225135      UINT32 x32 = 0;
226136      for(x32 = 0; x32 < 8; x32++)
227137      {
228         data |= ((cpustate->pixelcache[line].data[x32] >> n) & 1) << x32;
138         data |= ((m_pixelcache[line].data[x32] >> n) & 1) << x32;
229139      }
230      if(cpustate->pixelcache[line].bitpend != 0xff)
140      if(m_pixelcache[line].bitpend != 0xff)
231141      {
232         superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
233         data &= cpustate->pixelcache[line].bitpend;
234         data |= superfx_bus_read(cpustate, addr + byte) & ~cpustate->pixelcache[line].bitpend;
142         superfx_add_clocks_internal(m_memory_access_speed);
143         data &= m_pixelcache[line].bitpend;
144         data |= superfx_bus_read(addr + byte) & ~m_pixelcache[line].bitpend;
235145      }
236      superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
237      superfx_bus_write(cpustate, addr + byte, data);
146      superfx_add_clocks_internal(m_memory_access_speed);
147      superfx_bus_write(addr + byte, data);
238148   }
239149
240   cpustate->pixelcache[line].bitpend = 0x00;
150   m_pixelcache[line].bitpend = 0x00;
241151}
242152
243INLINE void superfx_plot(superfx_state *cpustate, UINT8 x, UINT8 y)
153void superfx_device::superfx_plot(UINT8 x, UINT8 y)
244154{
245   UINT8 color = cpustate->colr;
155   UINT8 color = m_colr;
246156   UINT16 offset = (y << 5) + (x >> 3);
247157
248   if((cpustate->por & SUPERFX_POR_DITHER) != 0 && (cpustate->scmr & SUPERFX_SCMR_MD) != 3)
158   if((m_por & SUPERFX_POR_DITHER) != 0 && (m_scmr & SUPERFX_SCMR_MD) != 3)
249159   {
250160      if((x ^ y) & 1)
251161      {
r26752r26753
254164      color &= 0x0f;
255165   }
256166
257   if((cpustate->por & SUPERFX_POR_TRANSPARENT) == 0)
167   if((m_por & SUPERFX_POR_TRANSPARENT) == 0)
258168   {
259      if((cpustate->scmr & SUPERFX_SCMR_MD) == 3)
169      if((m_scmr & SUPERFX_SCMR_MD) == 3)
260170      {
261         if(cpustate->por & SUPERFX_POR_FREEZEHIGH)
171         if(m_por & SUPERFX_POR_FREEZEHIGH)
262172         {
263173            if((color & 0x0f) == 0)
264174            {
r26752r26753
282192      }
283193   }
284194
285   if(offset != cpustate->pixelcache[0].offset)
195   if(offset != m_pixelcache[0].offset)
286196   {
287      superfx_pixelcache_flush(cpustate, 1);
288      cpustate->pixelcache[1] = cpustate->pixelcache[0];
289      cpustate->pixelcache[0].bitpend = 0x00;
290      cpustate->pixelcache[0].offset = offset;
197      superfx_pixelcache_flush(1);
198      m_pixelcache[1] = m_pixelcache[0];
199      m_pixelcache[0].bitpend = 0x00;
200      m_pixelcache[0].offset = offset;
291201   }
292202
293203   x = (x & 7) ^ 7;
294   cpustate->pixelcache[0].data[x] = color;
295   cpustate->pixelcache[0].bitpend |= 1 << x;
296   if(cpustate->pixelcache[0].bitpend == 0xff)
204   m_pixelcache[0].data[x] = color;
205   m_pixelcache[0].bitpend |= 1 << x;
206   if(m_pixelcache[0].bitpend == 0xff)
297207   {
298      superfx_pixelcache_flush(cpustate, 1);
299      cpustate->pixelcache[1] = cpustate->pixelcache[0];
300      cpustate->pixelcache[0].bitpend = 0x00;
208      superfx_pixelcache_flush(1);
209      m_pixelcache[1] = m_pixelcache[0];
210      m_pixelcache[0].bitpend = 0x00;
301211   }
302212}
303213
304static UINT8 superfx_rpix(superfx_state *cpustate, UINT8 x, UINT8 y)
214UINT8 superfx_device::superfx_rpix(UINT8 x, UINT8 y)
305215{
306216   UINT32 cn = 0;
307217   UINT32 bpp = 0;
r26752r26753
309219   UINT8 data = 0x00;
310220   UINT32 n = 0;
311221
312   superfx_pixelcache_flush(cpustate, 1);
313   superfx_pixelcache_flush(cpustate, 0);
222   superfx_pixelcache_flush(1);
223   superfx_pixelcache_flush(0);
314224
315   bpp = 2 << ((cpustate->scmr & SUPERFX_SCMR_MD) - ((cpustate->scmr & SUPERFX_SCMR_MD) >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 };
225   bpp = 2 << ((m_scmr & SUPERFX_SCMR_MD) - ((m_scmr & SUPERFX_SCMR_MD) >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 };
316226
317   switch((cpustate->por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (cpustate->scmr & SUPERFX_SCMR_HT_MASK))
227   switch((m_por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (m_scmr & SUPERFX_SCMR_HT_MASK))
318228   {
319229      case SUPERFX_SCMR_HT0:
320230         cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 3);
r26752r26753
330240         break;
331241   }
332242
333   addr = 0x700000 + (cn * (bpp << 3)) + (cpustate->scbr << 10) + ((y & 0x07) * 2);
243   addr = 0x700000 + (cn * (bpp << 3)) + (m_scbr << 10) + ((y & 0x07) * 2);
334244   x = (x & 7) ^ 7;
335245
336246   for(n = 0; n < bpp; n++)
337247   {
338248      UINT32 byte = ((n >> 1) << 4) + (n & 1);  // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 };
339      superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
340      data |= ((superfx_bus_read(cpustate, addr + byte) >> x) & 1) << n;
249      superfx_add_clocks_internal(m_memory_access_speed);
250      data |= ((superfx_bus_read(addr + byte) >> x) & 1) << n;
341251   }
342252
343253   return data;
344254}
345255
346INLINE UINT8 superfx_color(superfx_state *cpustate, UINT8 source)
256UINT8 superfx_device::superfx_color(UINT8 source)
347257{
348   if(cpustate->por & SUPERFX_POR_HIGHNIBBLE)
258   if(m_por & SUPERFX_POR_HIGHNIBBLE)
349259   {
350      return (cpustate->colr & 0xf0) | (source >> 4);
260      return (m_colr & 0xf0) | (source >> 4);
351261   }
352   if(cpustate->por & SUPERFX_POR_FREEZEHIGH)
262   if(m_por & SUPERFX_POR_FREEZEHIGH)
353263   {
354      return (cpustate->colr & 0xf0) | (source & 0x0f);
264      return (m_colr & 0xf0) | (source & 0x0f);
355265   }
356266   return source;
357267}
358268
359INLINE void superfx_rambuffer_sync(superfx_state *cpustate)
269void superfx_device::superfx_rambuffer_sync()
360270{
361   if(cpustate->ramcl)
271   if(m_ramcl)
362272   {
363      superfx_add_clocks_internal(cpustate, cpustate->ramcl);
273      superfx_add_clocks_internal(m_ramcl);
364274   }
365275}
366276
367INLINE UINT8 superfx_rambuffer_read(superfx_state *cpustate, UINT16 addr)
277UINT8 superfx_device::superfx_rambuffer_read(UINT16 addr)
368278{
369   superfx_rambuffer_sync(cpustate);
370   return superfx_bus_read(cpustate, 0x700000 + (cpustate->rambr << 16) + addr);
279   superfx_rambuffer_sync();
280   return superfx_bus_read(0x700000 + (m_rambr << 16) + addr);
371281}
372282
373INLINE void superfx_rambuffer_write(superfx_state *cpustate, UINT16 addr, UINT8 data)
283void superfx_device::superfx_rambuffer_write(UINT16 addr, UINT8 data)
374284{
375   superfx_rambuffer_sync(cpustate);
376   cpustate->ramcl = cpustate->memory_access_speed;
377   cpustate->ramar = addr;
378   cpustate->ramdr = data;
285   superfx_rambuffer_sync();
286   m_ramcl = m_memory_access_speed;
287   m_ramar = addr;
288   m_ramdr = data;
379289}
380290
381INLINE void superfx_rombuffer_sync(superfx_state *cpustate)
291void superfx_device::superfx_rombuffer_sync()
382292{
383   if(cpustate->romcl)
293   if(m_romcl)
384294   {
385      superfx_add_clocks_internal(cpustate, cpustate->romcl);
295      superfx_add_clocks_internal(m_romcl);
386296   }
387297}
388298
389INLINE void superfx_rombuffer_update(superfx_state *cpustate)
299void superfx_device::superfx_rombuffer_update()
390300{
391   cpustate->sfr |= SUPERFX_SFR_R;
392   cpustate->romcl = cpustate->memory_access_speed;
301   m_sfr |= SUPERFX_SFR_R;
302   m_romcl = m_memory_access_speed;
393303}
394304
395INLINE UINT8 superfx_rombuffer_read(superfx_state *cpustate)
305UINT8 superfx_device::superfx_rombuffer_read()
396306{
397   superfx_rombuffer_sync(cpustate);
398   return cpustate->romdr;
307   superfx_rombuffer_sync();
308   return m_romdr;
399309}
400310
401INLINE void superfx_gpr_write(superfx_state *cpustate, UINT8 r, UINT16 data)
311void superfx_device::superfx_gpr_write(UINT8 r, UINT16 data)
402312{
403   cpustate->r[r] = data;
313   m_r[r] = data;
404314   if(r == 14)
405315   {
406      superfx_rombuffer_update(cpustate);
316      superfx_rombuffer_update();
407317   }
408318   else if(r == 15)
409319   {
410      cpustate->r15_modified = 1;
320      m_r15_modified = 1;
411321   }
412322}
413323
414INLINE UINT8 superfx_op_read(superfx_state *cpustate, UINT16 addr)
324UINT8 superfx_device::superfx_op_read(UINT16 addr)
415325{
416   UINT16 offset = addr - cpustate->cbr;
326   UINT16 offset = addr - m_cbr;
417327   if(offset < 512)
418328   {
419      if(!cpustate->cache.valid[offset >> 4])
329      if(!m_cache.valid[offset >> 4])
420330      {
421331         UINT32 dp = offset & 0xfff0;
422         UINT32 sp = (cpustate->pbr << 16) + ((cpustate->cbr + dp) & 0xfff0);
332         UINT32 sp = (m_pbr << 16) + ((m_cbr + dp) & 0xfff0);
423333         UINT32 n = 0;
424334         for(n = 0; n < 16; n++)
425335         {
426            superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
427            cpustate->cache.buffer[dp++] = superfx_bus_read(cpustate, sp++);
336            superfx_add_clocks_internal(m_memory_access_speed);
337            m_cache.buffer[dp++] = superfx_bus_read(sp++);
428338         }
429         cpustate->cache.valid[offset >> 4] = 1;
339         m_cache.valid[offset >> 4] = 1;
430340      }
431341      else
432342      {
433         superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
343         superfx_add_clocks_internal(m_memory_access_speed);
434344      }
435      return cpustate->cache.buffer[offset];
345      return m_cache.buffer[offset];
436346   }
437347
438   if(cpustate->pbr <= 0x5f)
348   if(m_pbr <= 0x5f)
439349   {
440350      //$[00-5f]:[0000-ffff] ROM
441      superfx_rombuffer_sync(cpustate);
442      superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
443      return superfx_bus_read(cpustate, (cpustate->pbr << 16) + addr);
351      superfx_rombuffer_sync();
352      superfx_add_clocks_internal(m_memory_access_speed);
353      return superfx_bus_read((m_pbr << 16) + addr);
444354   }
445355   else
446356   {
447357      //$[60-7f]:[0000-ffff] RAM
448      superfx_rambuffer_sync(cpustate);
449      superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed);
450      return superfx_bus_read(cpustate, (cpustate->pbr << 16) + addr);
358      superfx_rambuffer_sync();
359      superfx_add_clocks_internal(m_memory_access_speed);
360      return superfx_bus_read((m_pbr << 16) + addr);
451361   }
452362}
453363
454INLINE UINT8 superfx_peekpipe(superfx_state *cpustate)
364UINT8 superfx_device::superfx_peekpipe()
455365{
456   UINT8 result = cpustate->pipeline;
457   cpustate->pipeline = superfx_op_read(cpustate, cpustate->r[15]);
458   cpustate->r15_modified = 0;
366   UINT8 result = m_pipeline;
367   m_pipeline = superfx_op_read(m_r[15]);
368   m_r15_modified = 0;
459369   return result;
460370}
461371
462INLINE UINT8 superfx_pipe(superfx_state *cpustate)
372UINT8 superfx_device::superfx_pipe()
463373{
464   UINT8 result = cpustate->pipeline;
465   cpustate->pipeline = superfx_op_read(cpustate, ++cpustate->r[15]);
466   cpustate->r15_modified = 0;
374   UINT8 result = m_pipeline;
375   m_pipeline = superfx_op_read(++m_r[15]);
376   m_r15_modified = 0;
467377   return result;
468378}
469379
470380/*****************************************************************************/
471381
472382/* reads to SuperFX RAM only happen if this returns 1 */
473int superfx_access_ram(device_t *cpu)
383int superfx_device::access_ram()
474384{
475   superfx_state *cpustate = get_safe_token(cpu);
476
477   if ((cpustate->sfr & SUPERFX_SFR_G) && (cpustate->scmr & SUPERFX_SCMR_RAN))
385   if ((m_sfr & SUPERFX_SFR_G) && (m_scmr & SUPERFX_SCMR_RAN))
478386      return 0;
479387
480388   return 1;
481389}
482390
483391/* reads to SuperFX ROM only happen if this returns 1 */
484int superfx_access_rom(device_t *cpu)
392int superfx_device::access_rom()
485393{
486   superfx_state *cpustate = get_safe_token(cpu);
487
488   if ((cpustate->sfr & SUPERFX_SFR_G) && (cpustate->scmr & SUPERFX_SCMR_RON))
394   if ((m_sfr & SUPERFX_SFR_G) && (m_scmr & SUPERFX_SCMR_RON))
489395      return 0;
490396
491397   return 1;
492398}
493399
494UINT8 superfx_mmio_read(device_t *cpu, UINT32 addr)
400UINT8 superfx_device::mmio_read(UINT32 addr)
495401{
496   superfx_state *cpustate = get_safe_token(cpu);
497
498402   addr &= 0xffff;
499403
500404   if(addr >= 0x3100 && addr <= 0x32ff)
501405   {
502      return superfx_cache_mmio_read(cpustate, addr - 0x3100);
406      return superfx_cache_mmio_read(addr - 0x3100);
503407   }
504408
505409   if(addr >= 0x3000 && addr <= 0x301f)
506410   {
507      return cpustate->r[(addr >> 1) & 0xf] >> ((addr & 1) << 3);
411      return m_r[(addr >> 1) & 0xf] >> ((addr & 1) << 3);
508412   }
509413
510414   switch(addr)
511415   {
512416      case 0x3030:
513         return cpustate->sfr >> 0;
417         return m_sfr >> 0;
514418
515419      case 0x3031:
516420      {
517         UINT8 r = cpustate->sfr >> 8;
518         cpustate->sfr &= ~SUPERFX_SFR_IRQ;
519         cpustate->irq = 0;
520         cpustate->out_irq_func(cpustate->irq);
421         UINT8 r = m_sfr >> 8;
422         m_sfr &= ~SUPERFX_SFR_IRQ;
423         m_irq = 0;
424         m_out_irq_func(m_irq);
521425         return r;
522426      }
523427
524428      case 0x3034:
525         return cpustate->pbr;
429         return m_pbr;
526430
527431      case 0x3036:
528         return cpustate->rombr;
432         return m_rombr;
529433
530434      case 0x303b:
531         return cpustate->vcr;
435         return m_vcr;
532436
533437      case 0x303c:
534         return cpustate->rambr;
438         return m_rambr;
535439
536440      case 0x303e:
537         return cpustate->cbr >> 0;
441         return m_cbr >> 0;
538442
539443      case 0x303f:
540         return cpustate->cbr >> 8;
444         return m_cbr >> 8;
541445   }
542446
543447   return 0;
544448}
545449
546void superfx_mmio_write(device_t *cpu, UINT32 addr, UINT8 data)
450void superfx_device::mmio_write(UINT32 addr, UINT8 data)
547451{
548   superfx_state *cpustate = get_safe_token(cpu);
549
550452   addr &= 0xffff;
551453
552454   //printf( "superfx_mmio_write: %08x = %02x\n", addr, data );
553455
554456   if(addr >= 0x3100 && addr <= 0x32ff)
555457   {
556      superfx_cache_mmio_write(cpustate, addr - 0x3100, data);
458      superfx_cache_mmio_write(addr - 0x3100, data);
557459      return;
558460   }
559461
r26752r26753
562464      UINT32 n = (addr >> 1) & 0xf;
563465      if((addr & 1) == 0)
564466      {
565         cpustate->r[n] = (cpustate->r[n] & 0xff00) | data;
467         m_r[n] = (m_r[n] & 0xff00) | data;
566468      }
567469      else
568470      {
569         cpustate->r[n] = (data << 8) | (cpustate->r[n] & 0xff);
471         m_r[n] = (data << 8) | (m_r[n] & 0xff);
570472      }
571473
572474      if(addr == 0x301f)
573475      {
574         cpustate->sfr |= SUPERFX_SFR_G;
476         m_sfr |= SUPERFX_SFR_G;
575477      }
576478      return;
577479   }
r26752r26753
580482   {
581483      case 0x3030:
582484      {
583         UINT8 g = (cpustate->sfr & SUPERFX_SFR_G) ? 1 : 0;
584         cpustate->sfr = (cpustate->sfr & 0xff00) | (data << 0);
585         if(g == 1 && !(cpustate->sfr & SUPERFX_SFR_G))
485         UINT8 g = (m_sfr & SUPERFX_SFR_G) ? 1 : 0;
486         m_sfr = (m_sfr & 0xff00) | (data << 0);
487         if(g == 1 && !(m_sfr & SUPERFX_SFR_G))
586488         {
587            cpustate->cbr = 0x0000;
588            superfx_cache_flush(cpustate);
489            m_cbr = 0x0000;
490            superfx_cache_flush();
589491         }
590492         break;
591493      }
592494
593495      case 0x3031:
594         cpustate->sfr = (data << 8) | (cpustate->sfr & 0x00ff);
496         m_sfr = (data << 8) | (m_sfr & 0x00ff);
595497         break;
596498
597499      case 0x3033:
598         cpustate->bramr = data & 1;
500         m_bramr = data & 1;
599501         break;
600502
601503      case 0x3034:
602         cpustate->pbr = data & 0x7f;
603         superfx_cache_flush(cpustate);
504         m_pbr = data & 0x7f;
505         superfx_cache_flush();
604506         break;
605507
606508      case 0x3037:
607         cpustate->cfgr = data;
608         superfx_update_speed(cpustate);
509         m_cfgr = data;
510         superfx_update_speed();
609511         break;
610512
611513      case 0x3038:
612         cpustate->scbr = data;
514         m_scbr = data;
613515         break;
614516
615517      case 0x3039:
616         cpustate->clsr = data & 1;
617         superfx_update_speed(cpustate);
518         m_clsr = data & 1;
519         superfx_update_speed();
618520         break;
619521
620522      case 0x303a:
621         cpustate->scmr = data;
523         m_scmr = data;
622524         break;
623525   }
624526}
625527
626INLINE void superfx_add_clocks_internal(superfx_state *cpustate, UINT32 clocks)
528void superfx_device::superfx_add_clocks_internal(UINT32 clocks)
627529{
628   if(cpustate->romcl)
530   if(m_romcl)
629531   {
630      cpustate->romcl -= MIN(clocks, cpustate->romcl);
631      if(cpustate->romcl == 0)
532      m_romcl -= MIN(clocks, m_romcl);
533      if(m_romcl == 0)
632534      {
633         cpustate->sfr &= ~SUPERFX_SFR_R;
634         cpustate->romdr = superfx_bus_read(cpustate, (cpustate->rombr << 16) + cpustate->r[14]);
535         m_sfr &= ~SUPERFX_SFR_R;
536         m_romdr = superfx_bus_read((m_rombr << 16) + m_r[14]);
635537      }
636538   }
637539
638   if(cpustate->ramcl)
540   if(m_ramcl)
639541   {
640      cpustate->ramcl -= MIN(clocks, cpustate->ramcl);
641      if(cpustate->ramcl == 0)
542      m_ramcl -= MIN(clocks, m_ramcl);
543      if(m_ramcl == 0)
642544      {
643         superfx_bus_write(cpustate, 0x700000 + (cpustate->rambr << 16) + cpustate->ramar, cpustate->ramdr);
545         superfx_bus_write(0x700000 + (m_rambr << 16) + m_ramar, m_ramdr);
644546      }
645547   }
646548}
647549
648static void superfx_timing_reset(superfx_state *cpustate)
550void superfx_device::superfx_timing_reset()
649551{
650   superfx_update_speed(cpustate);
651   cpustate->r15_modified = 0;
552   superfx_update_speed();
553   m_r15_modified = 0;
652554
653   cpustate->romcl = 0;
654   cpustate->romdr = 0;
555   m_romcl = 0;
556   m_romdr = 0;
655557
656   cpustate->ramcl = 0;
657   cpustate->ramar = 0;
658   cpustate->ramdr = 0;
558   m_ramcl = 0;
559   m_ramar = 0;
560   m_ramdr = 0;
659561}
660562
661void superfx_add_clocks(device_t *cpu, INT32 clocks)
563void superfx_device::add_clocks(INT32 clocks)
662564{
663   superfx_state *cpustate = get_safe_token(cpu);
664
665   superfx_add_clocks_internal(cpustate, clocks);
565   superfx_add_clocks_internal(clocks);
666566}
667567
668568/*****************************************************************************/
669569
670static void superfx_register_save( legacy_cpu_device *device )
570void superfx_device::device_start()
671571{
672   superfx_state *cpustate = get_safe_token(device);
673   int i;
572   for(int i = 0; i < 16; i++)
573   {
574      m_r[i] = 0;
575   }
674576
675   device->save_item(NAME(cpustate->pipeline));
676   device->save_item(NAME(cpustate->ramaddr));
577   m_sfr = 0;
578   m_pbr = 0;
579   m_rombr = 0;
580   m_rambr = 0;
581   m_cbr = 0;
582   m_scbr = 0;
583   m_scmr = 0;
584   m_colr = 0;
585   m_por = 0;
586   m_bramr = 0;
587   m_vcr = 0x04;
588   m_cfgr = 0;
589   m_clsr = 0;
590   m_pipeline = 0x01; // nop
591   m_ramaddr = 0;
592   m_r15_modified = 0;
593   m_irq = 0;
594   m_cache_access_speed = 0;
595   m_memory_access_speed = 0;
677596
678   device->save_item(NAME(cpustate->r));
679   device->save_item(NAME(cpustate->sfr));
680   device->save_item(NAME(cpustate->pbr));
681   device->save_item(NAME(cpustate->rombr));
682   device->save_item(NAME(cpustate->rambr));
683   device->save_item(NAME(cpustate->cbr));
684   device->save_item(NAME(cpustate->scbr));
685   device->save_item(NAME(cpustate->scmr));
686   device->save_item(NAME(cpustate->colr));
687   device->save_item(NAME(cpustate->por));
688   device->save_item(NAME(cpustate->bramr));
689   device->save_item(NAME(cpustate->vcr));
690   device->save_item(NAME(cpustate->cfgr));
691   device->save_item(NAME(cpustate->clsr));
597   superfx_regs_reset();
598   superfx_memory_reset();
599   superfx_update_speed();
692600
693   device->save_item(NAME(cpustate->romcl));
694   device->save_item(NAME(cpustate->romdr));
601   m_program = &space(AS_PROGRAM);
695602
696   device->save_item(NAME(cpustate->ramcl));
697   device->save_item(NAME(cpustate->ramar));
698   device->save_item(NAME(cpustate->ramdr));
603   m_out_irq_func.resolve();
699604
700   device->save_item(NAME(cpustate->sreg_idx));
701   device->save_item(NAME(cpustate->dreg_idx));
702   device->save_item(NAME(cpustate->r15_modified));
605   save_item(NAME(m_pipeline));
606   save_item(NAME(m_ramaddr));
703607
704   device->save_item(NAME(cpustate->irq));
608   save_item(NAME(m_r));
609   save_item(NAME(m_sfr));
610   save_item(NAME(m_pbr));
611   save_item(NAME(m_rombr));
612   save_item(NAME(m_rambr));
613   save_item(NAME(m_cbr));
614   save_item(NAME(m_scbr));
615   save_item(NAME(m_scmr));
616   save_item(NAME(m_colr));
617   save_item(NAME(m_por));
618   save_item(NAME(m_bramr));
619   save_item(NAME(m_vcr));
620   save_item(NAME(m_cfgr));
621   save_item(NAME(m_clsr));
705622
706   device->save_item(NAME(cpustate->cache_access_speed));
707   device->save_item(NAME(cpustate->memory_access_speed));
623   save_item(NAME(m_romcl));
624   save_item(NAME(m_romdr));
708625
709   device->save_item(NAME(cpustate->cache.buffer));
710   device->save_item(NAME(cpustate->cache.valid));
626   save_item(NAME(m_ramcl));
627   save_item(NAME(m_ramar));
628   save_item(NAME(m_ramdr));
711629
712   for (i = 0; i < 2; i++)
713   {
714      device->save_item(NAME(cpustate->pixelcache[i].offset), i);
715      device->save_item(NAME(cpustate->pixelcache[i].bitpend), i);
716      device->save_item(NAME(cpustate->pixelcache[i].data), i);
717   }
630   save_item(NAME(m_sreg_idx));
631   save_item(NAME(m_dreg_idx));
632   save_item(NAME(m_r15_modified));
718633
719   device->save_item(NAME(cpustate->icount));
720}
634   save_item(NAME(m_irq));
721635
722static CPU_INIT( superfx )
723{
724   int i;
725   superfx_state *cpustate = get_safe_token(device);
636   save_item(NAME(m_cache_access_speed));
637   save_item(NAME(m_memory_access_speed));
726638
727   for(i = 0; i < 16; i++)
639   save_item(NAME(m_cache.buffer));
640   save_item(NAME(m_cache.valid));
641
642   for (int i = 0; i < 2; i++)
728643   {
729      cpustate->r[i] = 0;
644      save_item(NAME(m_pixelcache[i].offset), i);
645      save_item(NAME(m_pixelcache[i].bitpend), i);
646      save_item(NAME(m_pixelcache[i].data), i);
730647   }
731648
732   cpustate->sfr = 0;
733   cpustate->pbr = 0;
734   cpustate->rombr = 0;
735   cpustate->rambr = 0;
736   cpustate->cbr = 0;
737   cpustate->scbr = 0;
738   cpustate->scmr = 0;
739   cpustate->colr = 0;
740   cpustate->por = 0;
741   cpustate->bramr = 0;
742   cpustate->vcr = 0x04;
743   cpustate->cfgr = 0;
744   cpustate->clsr = 0;
745   cpustate->pipeline = 0x01; // nop
746   cpustate->ramaddr = 0;
747   cpustate->r15_modified = 0;
649   save_item(NAME(m_icount));
748650
749   superfx_regs_reset(cpustate);
750   superfx_memory_reset(cpustate);
751   superfx_update_speed(cpustate);
651   state_add( SUPERFX_PC,      "PC",      m_debugger_temp).callimport().callexport().formatstr("%06X");
652   state_add( SUPERFX_DREG,    "DREG",    m_dreg_idx).mask(0xf).formatstr("%02u");
653   state_add( SUPERFX_SREG,    "SREG",    m_sreg_idx).mask(0xf).formatstr("%02u");
654   state_add( SUPERFX_R0,      "R0",      m_r[0]).formatstr("%04X");
655   state_add( SUPERFX_R1,      "R1",      m_r[1]).formatstr("%04X");
656   state_add( SUPERFX_R2,      "R2",      m_r[2]).formatstr("%04X");
657   state_add( SUPERFX_R3,      "R3",      m_r[3]).formatstr("%04X");
658   state_add( SUPERFX_R4,      "R4",      m_r[4]).formatstr("%04X");
659   state_add( SUPERFX_R5,      "R5",      m_r[5]).formatstr("%04X");
660   state_add( SUPERFX_R6,      "R6",      m_r[6]).formatstr("%04X");
661   state_add( SUPERFX_R7,      "R7",      m_r[7]).formatstr("%04X");
662   state_add( SUPERFX_R8,      "R8",      m_r[8]).formatstr("%04X");
663   state_add( SUPERFX_R9,      "R9",      m_r[9]).formatstr("%04X");
664   state_add( SUPERFX_R10,     "R10",     m_r[10]).formatstr("%04X");
665   state_add( SUPERFX_R11,     "R11",     m_r[11]).formatstr("%04X");
666   state_add( SUPERFX_R12,     "R12",     m_r[12]).formatstr("%04X");
667   state_add( SUPERFX_R13,     "R13",     m_r[13]).formatstr("%04X");
668   state_add( SUPERFX_R14,     "R14",     m_r[14]).formatstr("%04X");
669   state_add( SUPERFX_R15,     "R15",     m_r[15]).formatstr("%04X");
670   state_add( SUPERFX_SFR,     "SFR",     m_sfr).formatstr("%04X");
671   state_add( SUPERFX_PBR,     "PBR",     m_pbr).formatstr("%02X");
672   state_add( SUPERFX_ROMBR,   "ROMBR",   m_rombr).formatstr("%02X");
673   state_add( SUPERFX_RAMBR,   "RAMBR",   m_rambr).formatstr("%02X");
674   state_add( SUPERFX_CBR,     "CBR",     m_cbr).formatstr("%04X");
675   state_add( SUPERFX_SCBR,    "SCBR",    m_scbr).formatstr("%02X");
676   state_add( SUPERFX_SCMR,    "SCMR",    m_scmr).formatstr("%02X");
677   state_add( SUPERFX_COLR,    "COLR",    m_colr).formatstr("%02X");
678   state_add( SUPERFX_POR,     "POR",     m_por).formatstr("%02X");
679   state_add( SUPERFX_BRAMR,   "BRAMR",   m_bramr).formatstr("%02X");
680   state_add( SUPERFX_VCR,     "VCR",     m_vcr).formatstr("%02X");
681   state_add( SUPERFX_CFGR,    "CFGR",    m_cfgr).formatstr("%02X");
682   state_add( SUPERFX_CLSR,    "CLSR",    m_clsr).formatstr("%02X");
683   state_add( SUPERFX_ROMCL,   "ROMCL",   m_romcl).formatstr("%08X");
684   state_add( SUPERFX_ROMDR,   "ROMDR",   m_romdr).formatstr("%02X");
685   state_add( SUPERFX_RAMCL,   "RAMCL",   m_ramcl).formatstr("%08X");
686   state_add( SUPERFX_RAMAR,   "RAMAR",   m_ramar).formatstr("%04X");
687   state_add( SUPERFX_RAMDR,   "RAMDR",   m_ramdr).formatstr("%02X");
688   state_add( SUPERFX_RAMADDR, "RAMADDR", m_ramaddr).formatstr("%04X");
752689
753   cpustate->device = device;
754   cpustate->program = &device->space(AS_PROGRAM);
690   m_icountptr = &m_icount;
691}
755692
756   if (device->static_config() != NULL)
693
694void superfx_device::state_import(const device_state_entry &entry)
695{
696   switch (entry.index())
757697   {
758      cpustate->config = *(superfx_config *)device->static_config();
698      case SUPERFX_PC:
699         m_r[15] = m_debugger_temp;
700         break;
759701   }
760
761   cpustate->out_irq_func.resolve(cpustate->config.out_irq_func, *device);
762
763   superfx_register_save(device);
764702}
765703
766static CPU_EXIT( superfx )
704
705void superfx_device::state_export(const device_state_entry &entry)
767706{
707   switch (entry.index())
708   {
709      case STATE_GENPC:
710      case SUPERFX_PC:
711         m_debugger_temp = ( (m_pbr << 16) | m_r[15] ) - 1;
712         break;
713   }
768714}
769715
770static CPU_RESET( superfx )
716
717void superfx_device::device_reset()
771718{
772719   int i;
773720
774   superfx_state *cpustate = get_safe_token(device);
775
776721   for(i = 0; i < 16; i++)
777722   {
778      cpustate->r[i] = 0;
723      m_r[i] = 0;
779724   }
780725
781   cpustate->sfr = 0;
782   cpustate->pbr = 0;
783   cpustate->rombr = 0;
784   cpustate->rambr = 0;
785   cpustate->cbr = 0;
786   cpustate->scbr = 0;
787   cpustate->scmr = 0;
788   cpustate->colr = 0;
789   cpustate->por = 0;
790   cpustate->bramr = 0;
791   cpustate->vcr = 0x04;
792   cpustate->cfgr = 0;
793   cpustate->clsr = 0;
794   cpustate->pipeline = 0x01; // nop
795   cpustate->ramaddr = 0;
726   m_sfr = 0;
727   m_pbr = 0;
728   m_rombr = 0;
729   m_rambr = 0;
730   m_cbr = 0;
731   m_scbr = 0;
732   m_scmr = 0;
733   m_colr = 0;
734   m_por = 0;
735   m_bramr = 0;
736   m_vcr = 0x04;
737   m_cfgr = 0;
738   m_clsr = 0;
739   m_pipeline = 0x01; // nop
740   m_ramaddr = 0;
796741
797   superfx_regs_reset(cpustate);
798   superfx_timing_reset(cpustate);
742   superfx_regs_reset();
743   superfx_timing_reset();
799744}
800745
801INLINE void superfx_dreg_sfr_sz_update(superfx_state *cpustate)
746void superfx_device::superfx_dreg_sfr_sz_update()
802747{
803   cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
804   cpustate->sfr |= (*(cpustate->dreg) & 0x8000) ? SUPERFX_SFR_S : 0;
805   cpustate->sfr |= (*(cpustate->dreg) == 0) ? SUPERFX_SFR_Z : 0;
748   m_sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
749   m_sfr |= (*(m_dreg) & 0x8000) ? SUPERFX_SFR_S : 0;
750   m_sfr |= (*(m_dreg) == 0) ? SUPERFX_SFR_Z : 0;
806751}
807752
808static CPU_EXECUTE( superfx )
753void superfx_device::execute_run()
809754{
810   superfx_state *cpustate = get_safe_token(device);
811755   UINT8 op;
812756
813   if(!(cpustate->sfr & SUPERFX_SFR_G))
757   if(!(m_sfr & SUPERFX_SFR_G))
814758   {
815      superfx_add_clocks_internal(cpustate, 6);
816      cpustate->icount = MIN(cpustate->icount, 0);
759      superfx_add_clocks_internal(6);
760      m_icount = MIN(m_icount, 0);
817761   }
818762
819   while (cpustate->icount > 0 && (cpustate->sfr & SUPERFX_SFR_G))
763   while (m_icount > 0 && (m_sfr & SUPERFX_SFR_G))
820764   {
821      if(!(cpustate->sfr & SUPERFX_SFR_G))
765      if(!(m_sfr & SUPERFX_SFR_G))
822766      {
823         superfx_add_clocks_internal(cpustate, 6);
824         cpustate->icount = MIN(cpustate->icount, 0);
767         superfx_add_clocks_internal(6);
768         m_icount = MIN(m_icount, 0);
825769         break;
826770      }
827771
828      debugger_instruction_hook(device, (cpustate->pbr << 16) | cpustate->r[15]);
772      debugger_instruction_hook(this, (m_pbr << 16) | m_r[15]);
829773
830      op = superfx_peekpipe(cpustate);
774      op = superfx_peekpipe();
831775
832776      switch(op)
833777      {
834778         case 0x00: // STOP
835            if((cpustate->cfgr & SUPERFX_CFGR_IRQ) == 0)
779            if((m_cfgr & SUPERFX_CFGR_IRQ) == 0)
836780            {
837               cpustate->sfr |= SUPERFX_SFR_IRQ;
838               cpustate->irq = 1;
839               cpustate->out_irq_func(cpustate->irq ? ASSERT_LINE : CLEAR_LINE );
781               m_sfr |= SUPERFX_SFR_IRQ;
782               m_irq = 1;
783               m_out_irq_func(m_irq ? ASSERT_LINE : CLEAR_LINE );
840784            }
841            cpustate->sfr &= ~SUPERFX_SFR_G;
842            cpustate->pipeline = 0x01;
843            superfx_regs_reset(cpustate);
785            m_sfr &= ~SUPERFX_SFR_G;
786            m_pipeline = 0x01;
787            superfx_regs_reset();
844788            break;
845789         case 0x01: // NOP
846            superfx_regs_reset(cpustate);
790            superfx_regs_reset();
847791            break;
848792         case 0x02: // CACHE
849            if(cpustate->cbr != (cpustate->r[15] & 0xfff0))
793            if(m_cbr != (m_r[15] & 0xfff0))
850794            {
851               cpustate->cbr = cpustate->r[15] & 0xfff0;
852               superfx_cache_flush(cpustate);
795               m_cbr = m_r[15] & 0xfff0;
796               superfx_cache_flush();
853797            }
854            superfx_regs_reset(cpustate);
798            superfx_regs_reset();
855799            break;
856800         case 0x03: // LSR
857            cpustate->sfr &= ~SUPERFX_SFR_CY;
858            cpustate->sfr |= (*(cpustate->sreg) & 1) ? SUPERFX_SFR_CY : 0;
859            superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) >> 1);
860            superfx_dreg_sfr_sz_update(cpustate);
861            superfx_regs_reset(cpustate);
801            m_sfr &= ~SUPERFX_SFR_CY;
802            m_sfr |= (*(m_sreg) & 1) ? SUPERFX_SFR_CY : 0;
803            superfx_gpr_write(m_dreg_idx, *(m_sreg) >> 1);
804            superfx_dreg_sfr_sz_update();
805            superfx_regs_reset();
862806            break;
863807         case 0x04: // ROL
864808         {
865            UINT16 carry = *(cpustate->sreg) & 0x8000;
866            superfx_gpr_write(cpustate, cpustate->dreg_idx, (*(cpustate->sreg) << 1) | SUPERFX_SFR_CY_SET);
867            cpustate->sfr &= ~SUPERFX_SFR_CY;
868            cpustate->sfr |= carry ? SUPERFX_SFR_CY : 0;
869            superfx_dreg_sfr_sz_update(cpustate);
870            superfx_regs_reset(cpustate);
809            UINT16 carry = *(m_sreg) & 0x8000;
810            superfx_gpr_write(m_dreg_idx, (*(m_sreg) << 1) | SUPERFX_SFR_CY_SET);
811            m_sfr &= ~SUPERFX_SFR_CY;
812            m_sfr |= carry ? SUPERFX_SFR_CY : 0;
813            superfx_dreg_sfr_sz_update();
814            superfx_regs_reset();
871815            break;
872816         }
873817         case 0x05: // BRA
874818         {
875            INT32 e = (INT8)superfx_pipe(cpustate);
876            superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
819            INT32 e = (INT8)superfx_pipe();
820            superfx_gpr_write(15, m_r[15] + e);
877821            break;
878822         }
879823         case 0x06: // BLT
880824         {
881            INT32 e = (INT8)superfx_pipe(cpustate);
825            INT32 e = (INT8)superfx_pipe();
882826            if((SUPERFX_SFR_S_SET ^ SUPERFX_SFR_OV_SET) == 0)
883827            {
884               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
828               superfx_gpr_write(15, m_r[15] + e);
885829            }
886830            break;
887831         }
888832         case 0x07: // BGE
889833         {
890            INT32 e = (INT8)superfx_pipe(cpustate);
834            INT32 e = (INT8)superfx_pipe();
891835            if((SUPERFX_SFR_S_SET ^ SUPERFX_SFR_OV_SET) == 1)
892836            {
893               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
837               superfx_gpr_write(15, m_r[15] + e);
894838            }
895839            break;
896840         }
897841         case 0x08: // BNE
898842         {
899            INT32 e = (INT8)superfx_pipe(cpustate);
843            INT32 e = (INT8)superfx_pipe();
900844            if(SUPERFX_SFR_Z_SET == 0)
901845            {
902               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
846               superfx_gpr_write(15, m_r[15] + e);
903847            }
904848            break;
905849         }
906850         case 0x09: // BEQ
907851         {
908            INT32 e = (INT8)superfx_pipe(cpustate);
852            INT32 e = (INT8)superfx_pipe();
909853            if(SUPERFX_SFR_Z_SET == 1)
910854            {
911               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
855               superfx_gpr_write(15, m_r[15] + e);
912856            }
913857            break;
914858         }
915859         case 0x0a: // BPL
916860         {
917            INT32 e = (INT8)superfx_pipe(cpustate);
861            INT32 e = (INT8)superfx_pipe();
918862            if(SUPERFX_SFR_S_SET == 0)
919863            {
920               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
864               superfx_gpr_write(15, m_r[15] + e);
921865            }
922866            break;
923867         }
924868         case 0x0b: // BMI
925869         {
926            INT32 e = (INT8)superfx_pipe(cpustate);
870            INT32 e = (INT8)superfx_pipe();
927871            if(SUPERFX_SFR_S_SET == 1)
928872            {
929               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
873               superfx_gpr_write(15, m_r[15] + e);
930874            }
931875            break;
932876         }
933877         case 0x0c: // BCC
934878         {
935            INT32 e = (INT8)superfx_pipe(cpustate);
879            INT32 e = (INT8)superfx_pipe();
936880            if(SUPERFX_SFR_CY_SET == 0)
937881            {
938               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
882               superfx_gpr_write(15, m_r[15] + e);
939883            }
940884            break;
941885         }
942886         case 0x0d: // BCS
943887         {
944            INT32 e = (INT8)superfx_pipe(cpustate);
888            INT32 e = (INT8)superfx_pipe();
945889            if(SUPERFX_SFR_CY_SET == 1)
946890            {
947               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
891               superfx_gpr_write(15, m_r[15] + e);
948892            }
949893            break;
950894         }
951895         case 0x0e: // BVC
952896         {
953            INT32 e = (INT8)superfx_pipe(cpustate);
897            INT32 e = (INT8)superfx_pipe();
954898            if(SUPERFX_SFR_OV_SET == 0)
955899            {
956               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
900               superfx_gpr_write(15, m_r[15] + e);
957901            }
958902            break;
959903         }
960904         case 0x0f: // BVS
961905         {
962            INT32 e = (INT8)superfx_pipe(cpustate);
906            INT32 e = (INT8)superfx_pipe();
963907            if(SUPERFX_SFR_OV_SET == 1)
964908            {
965               superfx_gpr_write(cpustate, 15, cpustate->r[15] + e);
909               superfx_gpr_write(15, m_r[15] + e);
966910            }
967911            break;
968912         }
969913
970914         case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
971915         case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: // TO
972            if((cpustate->sfr & SUPERFX_SFR_B) == 0)
916            if((m_sfr & SUPERFX_SFR_B) == 0)
973917            {
974               cpustate->dreg = &cpustate->r[op & 0xf];
975               cpustate->dreg_idx = op & 0xf;
918               m_dreg = &m_r[op & 0xf];
919               m_dreg_idx = op & 0xf;
976920            }
977921            else
978922            {
979               superfx_gpr_write(cpustate, op & 0xf, *(cpustate->sreg));
980               superfx_regs_reset(cpustate);
923               superfx_gpr_write(op & 0xf, *(m_sreg));
924               superfx_regs_reset();
981925            }
982926            break;
983927
984928         case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
985929         case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: // WITH
986            cpustate->sreg = &cpustate->r[op & 0xf];
987            cpustate->sreg_idx = op & 0xf;
988            cpustate->dreg = &cpustate->r[op & 0xf];
989            cpustate->dreg_idx = op & 0xf;
990            cpustate->sfr |= SUPERFX_SFR_B;
930            m_sreg = &m_r[op & 0xf];
931            m_sreg_idx = op & 0xf;
932            m_dreg = &m_r[op & 0xf];
933            m_dreg_idx = op & 0xf;
934            m_sfr |= SUPERFX_SFR_B;
991935            break;
992936
993937         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35:
994938         case 0x36: case 0x37: case 0x38: case 0x39: case 0x3a: case 0x3b:   // STW_IR / STB_IR
995            if((cpustate->sfr & SUPERFX_SFR_ALT1) == 0)
939            if((m_sfr & SUPERFX_SFR_ALT1) == 0)
996940            { // STW_IR
997               cpustate->ramaddr = cpustate->r[op & 0xf];
998               superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 0, (*(cpustate->sreg)) >> 0);
999               superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 1, (*(cpustate->sreg)) >> 8);
1000               superfx_regs_reset(cpustate);
941               m_ramaddr = m_r[op & 0xf];
942               superfx_rambuffer_write(m_ramaddr ^ 0, (*(m_sreg)) >> 0);
943               superfx_rambuffer_write(m_ramaddr ^ 1, (*(m_sreg)) >> 8);
944               superfx_regs_reset();
1001945            }
1002946            else
1003947            { // STB_IR
1004               cpustate->ramaddr = cpustate->r[op & 0xf];
1005               superfx_rambuffer_write(cpustate, cpustate->ramaddr, *(cpustate->sreg));
1006               superfx_regs_reset(cpustate);
948               m_ramaddr = m_r[op & 0xf];
949               superfx_rambuffer_write(m_ramaddr, *(m_sreg));
950               superfx_regs_reset();
1007951            }
1008952            break;
1009953
1010954         case 0x3c: // LOOP
1011            superfx_gpr_write(cpustate, 12, cpustate->r[12] - 1);
1012            cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1013            cpustate->sfr |= (cpustate->r[12] & 0x8000) ? SUPERFX_SFR_S : 0;
1014            cpustate->sfr |= (cpustate->r[12] == 0) ? SUPERFX_SFR_Z : 0;
1015            if(!(cpustate->sfr & SUPERFX_SFR_Z))
955            superfx_gpr_write(12, m_r[12] - 1);
956            m_sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
957            m_sfr |= (m_r[12] & 0x8000) ? SUPERFX_SFR_S : 0;
958            m_sfr |= (m_r[12] == 0) ? SUPERFX_SFR_Z : 0;
959            if(!(m_sfr & SUPERFX_SFR_Z))
1016960            {
1017               superfx_gpr_write(cpustate, 15, cpustate->r[13]);
961               superfx_gpr_write(15, m_r[13]);
1018962            }
1019            superfx_regs_reset(cpustate);
963            superfx_regs_reset();
1020964            break;
1021965         case 0x3d: // ALT1
1022            cpustate->sfr &= ~SUPERFX_SFR_B;
1023            cpustate->sfr |= SUPERFX_SFR_ALT1;
966            m_sfr &= ~SUPERFX_SFR_B;
967            m_sfr |= SUPERFX_SFR_ALT1;
1024968            break;
1025969         case 0x3e: // ALT2
1026            cpustate->sfr &= ~SUPERFX_SFR_B;
1027            cpustate->sfr |= SUPERFX_SFR_ALT2;
970            m_sfr &= ~SUPERFX_SFR_B;
971            m_sfr |= SUPERFX_SFR_ALT2;
1028972            break;
1029973         case 0x3f: // ALT3
1030            cpustate->sfr &= ~SUPERFX_SFR_B;
1031            cpustate->sfr |= SUPERFX_SFR_ALT1;
1032            cpustate->sfr |= SUPERFX_SFR_ALT2;
974            m_sfr &= ~SUPERFX_SFR_B;
975            m_sfr |= SUPERFX_SFR_ALT1;
976            m_sfr |= SUPERFX_SFR_ALT2;
1033977            break;
1034978
1035979         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45:
1036980         case 0x46: case 0x47: case 0x48: case 0x49: case 0x4a: case 0x4b:   // LDW_IR / LDB_IR
1037            if((cpustate->sfr & SUPERFX_SFR_ALT1) == 0)
981            if((m_sfr & SUPERFX_SFR_ALT1) == 0)
1038982            { // LDW_IR
1039983               UINT16 data = 0;
1040               cpustate->ramaddr = cpustate->r[op & 0xf];
1041               data  = superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 0) << 0;
1042               data |= superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 1) << 8;
1043               superfx_gpr_write(cpustate, cpustate->dreg_idx, data);
1044               superfx_regs_reset(cpustate);
984               m_ramaddr = m_r[op & 0xf];
985               data  = superfx_rambuffer_read(m_ramaddr ^ 0) << 0;
986               data |= superfx_rambuffer_read(m_ramaddr ^ 1) << 8;
987               superfx_gpr_write(m_dreg_idx, data);
988               superfx_regs_reset();
1045989            }
1046990            else
1047991            { // LDB_IR
1048               cpustate->ramaddr = cpustate->r[op & 0xf];
1049               superfx_gpr_write(cpustate, cpustate->dreg_idx, superfx_rambuffer_read(cpustate, cpustate->ramaddr));
1050               superfx_regs_reset(cpustate);
992               m_ramaddr = m_r[op & 0xf];
993               superfx_gpr_write(m_dreg_idx, superfx_rambuffer_read(m_ramaddr));
994               superfx_regs_reset();
1051995            }
1052996            break;
1053997
1054998         case 0x4c: // PLOT / RPIX
1055            if((cpustate->sfr & SUPERFX_SFR_ALT1) == 0)
999            if((m_sfr & SUPERFX_SFR_ALT1) == 0)
10561000            { // PLOT
1057               superfx_plot(cpustate, cpustate->r[1], cpustate->r[2]);
1058               superfx_gpr_write(cpustate, 1, cpustate->r[1] + 1);
1059               superfx_regs_reset(cpustate);
1001               superfx_plot(m_r[1], m_r[2]);
1002               superfx_gpr_write(1, m_r[1] + 1);
1003               superfx_regs_reset();
10601004            }
10611005            else
10621006            { // RPIX
1063               superfx_gpr_write(cpustate, cpustate->dreg_idx, superfx_rpix(cpustate, cpustate->r[1], cpustate->r[2]));
1064               superfx_dreg_sfr_sz_update(cpustate);
1065               superfx_regs_reset(cpustate);
1007               superfx_gpr_write(m_dreg_idx, superfx_rpix(m_r[1], m_r[2]));
1008               superfx_dreg_sfr_sz_update();
1009               superfx_regs_reset();
10661010            }
10671011            break;
10681012
10691013         case 0x4d: // SWAP
1070            superfx_gpr_write(cpustate, cpustate->dreg_idx, (*(cpustate->sreg) >> 8) | (*(cpustate->sreg) << 8));
1071            superfx_dreg_sfr_sz_update(cpustate);
1072            superfx_regs_reset(cpustate);
1014            superfx_gpr_write(m_dreg_idx, (*(m_sreg) >> 8) | (*(m_sreg) << 8));
1015            superfx_dreg_sfr_sz_update();
1016            superfx_regs_reset();
10731017            break;
10741018
10751019         case 0x4e: // COLOR / CMODE
1076            if((cpustate->sfr & SUPERFX_SFR_ALT1) == 0)
1020            if((m_sfr & SUPERFX_SFR_ALT1) == 0)
10771021            { // COLOR
1078               cpustate->colr = superfx_color(cpustate, *(cpustate->sreg));
1079               superfx_regs_reset(cpustate);
1022               m_colr = superfx_color(*(m_sreg));
1023               superfx_regs_reset();
10801024            }
10811025            else
10821026            { // CMODE
1083               cpustate->por = *(cpustate->sreg);
1084               superfx_regs_reset(cpustate);
1027               m_por = *(m_sreg);
1028               superfx_regs_reset();
10851029            }
10861030            break;
10871031
10881032         case 0x4f: // NOT
1089            superfx_gpr_write(cpustate, cpustate->dreg_idx, ~(*(cpustate->sreg)));
1090            superfx_dreg_sfr_sz_update(cpustate);
1091            superfx_regs_reset(cpustate);
1033            superfx_gpr_write(m_dreg_idx, ~(*(m_sreg)));
1034            superfx_dreg_sfr_sz_update();
1035            superfx_regs_reset();
10921036            break;
10931037
10941038         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
10951039         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: // ADD / ADC / ADDI / ADCI
10961040         {
1097            INT32 r = *(cpustate->sreg);
1098            cpustate->sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_Z);
1099            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1041            INT32 r = *(m_sreg);
1042            m_sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_Z);
1043            switch(m_sfr & SUPERFX_SFR_ALT)
11001044            {
11011045               case SUPERFX_SFR_ALT0: // ADD
1102                  r += cpustate->r[op & 0xf];
1103                  cpustate->sfr |= (~(*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (cpustate->r[op & 0xf] ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1046                  r += m_r[op & 0xf];
1047                  m_sfr |= (~(*(m_sreg) ^ m_r[op & 0xf]) & (m_r[op & 0xf] ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
11041048                  break;
11051049               case SUPERFX_SFR_ALT1: // ADC
1106                  r += cpustate->r[op & 0xf] + SUPERFX_SFR_CY_SET;
1107                  cpustate->sfr |= (~(*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (cpustate->r[op & 0xf] ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1050                  r += m_r[op & 0xf] + SUPERFX_SFR_CY_SET;
1051                  m_sfr |= (~(*(m_sreg) ^ m_r[op & 0xf]) & (m_r[op & 0xf] ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
11081052                  break;
11091053               case SUPERFX_SFR_ALT2: // ADDI
11101054                  r += op & 0xf;
1111                  cpustate->sfr |= (~(*(cpustate->sreg) ^ (op & 0xf)) & ((op & 0xf) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1055                  m_sfr |= (~(*(m_sreg) ^ (op & 0xf)) & ((op & 0xf) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
11121056                  break;
11131057               case SUPERFX_SFR_ALT3: // ADCI
11141058                  r += (op & 0xf) + SUPERFX_SFR_CY_SET;
1115                  cpustate->sfr |= (~(*(cpustate->sreg) ^ (op & 0xf)) & ((op & 0xf) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1059                  m_sfr |= (~(*(m_sreg) ^ (op & 0xf)) & ((op & 0xf) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
11161060                  break;
11171061            }
1118            cpustate->sfr &= ~SUPERFX_SFR_CY;
1119            cpustate->sfr |= (r & 0x8000) ? SUPERFX_SFR_S : 0;
1120            cpustate->sfr |= (r >= 0x10000) ? SUPERFX_SFR_CY : 0;
1121            cpustate->sfr |= ((UINT16)r == 0) ? SUPERFX_SFR_Z : 0;
1122            superfx_gpr_write(cpustate, cpustate->dreg_idx, r);
1123            superfx_regs_reset(cpustate);
1062            m_sfr &= ~SUPERFX_SFR_CY;
1063            m_sfr |= (r & 0x8000) ? SUPERFX_SFR_S : 0;
1064            m_sfr |= (r >= 0x10000) ? SUPERFX_SFR_CY : 0;
1065            m_sfr |= ((UINT16)r == 0) ? SUPERFX_SFR_Z : 0;
1066            superfx_gpr_write(m_dreg_idx, r);
1067            superfx_regs_reset();
11241068            break;
11251069         }
11261070
r26752r26753
11281072         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: // SUB / SBC / SUBI / CMP
11291073         {
11301074            INT32 r = 0;
1131            cpustate->sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_Z);
1132            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1075            m_sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_Z);
1076            switch(m_sfr & SUPERFX_SFR_ALT)
11331077            {
11341078               case SUPERFX_SFR_ALT0: // SUB
1135                  r = *(cpustate->sreg) - cpustate->r[op & 0xf];
1136                  cpustate->sfr |= ((*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1137                  superfx_gpr_write(cpustate, cpustate->dreg_idx, r);
1079                  r = *(m_sreg) - m_r[op & 0xf];
1080                  m_sfr |= ((*(m_sreg) ^ m_r[op & 0xf]) & (*(m_sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1081                  superfx_gpr_write(m_dreg_idx, r);
11381082                  break;
11391083               case SUPERFX_SFR_ALT1: // SBC
1140                  r = *(cpustate->sreg) - cpustate->r[op & 0xf] - SUPERFX_SFR_CY_CLEAR;
1141                  cpustate->sfr |= ((*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1142                  superfx_gpr_write(cpustate, cpustate->dreg_idx, r);
1084                  r = *(m_sreg) - m_r[op & 0xf] - SUPERFX_SFR_CY_CLEAR;
1085                  m_sfr |= ((*(m_sreg) ^ m_r[op & 0xf]) & (*(m_sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1086                  superfx_gpr_write(m_dreg_idx, r);
11431087                  break;
11441088               case SUPERFX_SFR_ALT2: // SUBI
1145                  r = *(cpustate->sreg) - (op & 0xf);
1146                  cpustate->sfr |= ((*(cpustate->sreg) ^ (op & 0xf)) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1147                  superfx_gpr_write(cpustate, cpustate->dreg_idx, r);
1089                  r = *(m_sreg) - (op & 0xf);
1090                  m_sfr |= ((*(m_sreg) ^ (op & 0xf)) & (*(m_sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1091                  superfx_gpr_write(m_dreg_idx, r);
11481092                  break;
11491093               case SUPERFX_SFR_ALT3: // CMP
1150                  r = *(cpustate->sreg) - cpustate->r[op & 0xf];
1151                  cpustate->sfr |= ((*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
1094                  r = *(m_sreg) - m_r[op & 0xf];
1095                  m_sfr |= ((*(m_sreg) ^ m_r[op & 0xf]) & (*(m_sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0;
11521096                  break;
11531097            }
1154            cpustate->sfr &= ~SUPERFX_SFR_CY;
1155            cpustate->sfr |= (r & 0x8000) ? SUPERFX_SFR_S : 0;
1156            cpustate->sfr |= (r >= 0x0) ? SUPERFX_SFR_CY : 0;
1157            cpustate->sfr |= ((UINT16)r == 0) ? SUPERFX_SFR_Z : 0;
1158            superfx_regs_reset(cpustate);
1098            m_sfr &= ~SUPERFX_SFR_CY;
1099            m_sfr |= (r & 0x8000) ? SUPERFX_SFR_S : 0;
1100            m_sfr |= (r >= 0x0) ? SUPERFX_SFR_CY : 0;
1101            m_sfr |= ((UINT16)r == 0) ? SUPERFX_SFR_Z : 0;
1102            superfx_regs_reset();
11591103            break;
11601104         }
11611105
11621106         case 0x70: // MERGE
1163            superfx_gpr_write(cpustate, cpustate->dreg_idx, (cpustate->r[7] & 0xff00) | (cpustate->r[8] >> 8));
1164            cpustate->sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_CY | SUPERFX_SFR_Z);
1165            cpustate->sfr |= (*(cpustate->dreg) & 0xc0c0) ? SUPERFX_SFR_OV : 0;
1166            cpustate->sfr |= (*(cpustate->dreg) & 0x8080) ? SUPERFX_SFR_S : 0;
1167            cpustate->sfr |= (*(cpustate->dreg) & 0xe0e0) ? SUPERFX_SFR_CY : 0;
1168            cpustate->sfr |= (*(cpustate->dreg) & 0xf0f0) ? SUPERFX_SFR_Z : 0;
1169            superfx_regs_reset(cpustate);
1107            superfx_gpr_write(m_dreg_idx, (m_r[7] & 0xff00) | (m_r[8] >> 8));
1108            m_sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_CY | SUPERFX_SFR_Z);
1109            m_sfr |= (*(m_dreg) & 0xc0c0) ? SUPERFX_SFR_OV : 0;
1110            m_sfr |= (*(m_dreg) & 0x8080) ? SUPERFX_SFR_S : 0;
1111            m_sfr |= (*(m_dreg) & 0xe0e0) ? SUPERFX_SFR_CY : 0;
1112            m_sfr |= (*(m_dreg) & 0xf0f0) ? SUPERFX_SFR_Z : 0;
1113            superfx_regs_reset();
11701114            break;
11711115
11721116         case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77:
11731117         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // AND / BIC / ANDI / BICI
1174            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1118            switch(m_sfr & SUPERFX_SFR_ALT)
11751119            {
11761120               case SUPERFX_SFR_ALT0: // AND
1177                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) & cpustate->r[op & 0xf]);
1121                  superfx_gpr_write(m_dreg_idx, *(m_sreg) & m_r[op & 0xf]);
11781122                  break;
11791123               case SUPERFX_SFR_ALT1: // BIC
1180                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) & ~cpustate->r[op & 0xf]);
1124                  superfx_gpr_write(m_dreg_idx, *(m_sreg) & ~m_r[op & 0xf]);
11811125                  break;
11821126               case SUPERFX_SFR_ALT2: // ANDI
1183                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) & (op & 0xf));
1127                  superfx_gpr_write(m_dreg_idx, *(m_sreg) & (op & 0xf));
11841128                  break;
11851129               case SUPERFX_SFR_ALT3: // BICI
1186                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) & ~(op & 0xf));
1130                  superfx_gpr_write(m_dreg_idx, *(m_sreg) & ~(op & 0xf));
11871131                  break;
11881132            }
1189            superfx_dreg_sfr_sz_update(cpustate);
1190            superfx_regs_reset(cpustate);
1133            superfx_dreg_sfr_sz_update();
1134            superfx_regs_reset();
11911135            break;
11921136
11931137         case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
11941138         case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: // MULT / UMULT / MULTI / UMULTI
1195            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1139            switch(m_sfr & SUPERFX_SFR_ALT)
11961140            {
11971141               case SUPERFX_SFR_ALT0: // MULT
1198                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT8)(*(cpustate->sreg)) * (INT8)(cpustate->r[op & 0xf]));
1142                  superfx_gpr_write(m_dreg_idx, (INT8)(*(m_sreg)) * (INT8)(m_r[op & 0xf]));
11991143                  break;
12001144               case SUPERFX_SFR_ALT1: // UMULT
1201                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (UINT8)(*(cpustate->sreg)) * (UINT8)(cpustate->r[op & 0xf]));
1145                  superfx_gpr_write(m_dreg_idx, (UINT8)(*(m_sreg)) * (UINT8)(m_r[op & 0xf]));
12021146                  break;
12031147               case SUPERFX_SFR_ALT2: // MULTI
1204                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT8)(*(cpustate->sreg)) * (INT8)(op & 0xf));
1148                  superfx_gpr_write(m_dreg_idx, (INT8)(*(m_sreg)) * (INT8)(op & 0xf));
12051149                  break;
12061150               case SUPERFX_SFR_ALT3: // UMULTI
1207                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (UINT8)(*(cpustate->sreg)) * (UINT8)(op & 0xf));
1151                  superfx_gpr_write(m_dreg_idx, (UINT8)(*(m_sreg)) * (UINT8)(op & 0xf));
12081152                  break;
12091153            }
1210            superfx_dreg_sfr_sz_update(cpustate);
1211            superfx_regs_reset(cpustate);
1212            if(!(cpustate->cfgr & SUPERFX_CFGR_MS0))
1154            superfx_dreg_sfr_sz_update();
1155            superfx_regs_reset();
1156            if(!(m_cfgr & SUPERFX_CFGR_MS0))
12131157            {
1214               superfx_add_clocks_internal(cpustate, 2);
1158               superfx_add_clocks_internal(2);
12151159            }
12161160            break;
12171161
12181162         case 0x90: // SBK
1219            superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 0, *(cpustate->sreg) >> 0);
1220            superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 1, *(cpustate->sreg) >> 8);
1221            superfx_regs_reset(cpustate);
1163            superfx_rambuffer_write(m_ramaddr ^ 0, *(m_sreg) >> 0);
1164            superfx_rambuffer_write(m_ramaddr ^ 1, *(m_sreg) >> 8);
1165            superfx_regs_reset();
12221166            break;
12231167
12241168         case 0x91: case 0x92: case 0x93: case 0x94: // LINK
1225            superfx_gpr_write(cpustate, 11, cpustate->r[15] + (op & 0xf));
1226            superfx_regs_reset(cpustate);
1169            superfx_gpr_write(11, m_r[15] + (op & 0xf));
1170            superfx_regs_reset();
12271171            break;
12281172
12291173         case 0x95: // SEX
1230            superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT8)(*(cpustate->sreg)));
1231            superfx_dreg_sfr_sz_update(cpustate);
1232            superfx_regs_reset(cpustate);
1174            superfx_gpr_write(m_dreg_idx, (INT8)(*(m_sreg)));
1175            superfx_dreg_sfr_sz_update();
1176            superfx_regs_reset();
12331177            break;
12341178
12351179         case 0x96: // ASR / DIV2
1236            if((cpustate->sfr & SUPERFX_SFR_ALT1) == 0)
1180            if((m_sfr & SUPERFX_SFR_ALT1) == 0)
12371181            { // ASR
1238               cpustate->sfr &= ~SUPERFX_SFR_CY;
1239               cpustate->sfr |= (*(cpustate->sreg) & 1) ? SUPERFX_SFR_CY : 0;
1240               superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT16)(*(cpustate->sreg)) >> 1);
1241               superfx_dreg_sfr_sz_update(cpustate);
1242               superfx_regs_reset(cpustate);
1182               m_sfr &= ~SUPERFX_SFR_CY;
1183               m_sfr |= (*(m_sreg) & 1) ? SUPERFX_SFR_CY : 0;
1184               superfx_gpr_write(m_dreg_idx, (INT16)(*(m_sreg)) >> 1);
1185               superfx_dreg_sfr_sz_update();
1186               superfx_regs_reset();
12431187            }
12441188            else
12451189            { // DIV2
1246               cpustate->sfr &= ~SUPERFX_SFR_CY;
1247               cpustate->sfr |= (*(cpustate->sreg) & 1) ? SUPERFX_SFR_CY : 0;
1248               superfx_gpr_write(cpustate, cpustate->dreg_idx, ((INT16)(*(cpustate->sreg)) >> 1) + ((UINT32)(*(cpustate->sreg) + 1) >> 16));
1249               superfx_dreg_sfr_sz_update(cpustate);
1250               superfx_regs_reset(cpustate);
1190               m_sfr &= ~SUPERFX_SFR_CY;
1191               m_sfr |= (*(m_sreg) & 1) ? SUPERFX_SFR_CY : 0;
1192               superfx_gpr_write(m_dreg_idx, ((INT16)(*(m_sreg)) >> 1) + ((UINT32)(*(m_sreg) + 1) >> 16));
1193               superfx_dreg_sfr_sz_update();
1194               superfx_regs_reset();
12511195            }
12521196            break;
12531197
12541198         case 0x97: // ROR
12551199         {
1256            UINT16 carry = *(cpustate->sreg) & 1;
1257            superfx_gpr_write(cpustate, cpustate->dreg_idx, (SUPERFX_SFR_CY_SET << 15) | ((UINT16)(*(cpustate->sreg)) >> 1));
1258            cpustate->sfr &= ~SUPERFX_SFR_CY;
1259            cpustate->sfr |= carry ? SUPERFX_SFR_CY : 0;
1260            superfx_dreg_sfr_sz_update(cpustate);
1261            superfx_regs_reset(cpustate);
1200            UINT16 carry = *(m_sreg) & 1;
1201            superfx_gpr_write(m_dreg_idx, (SUPERFX_SFR_CY_SET << 15) | ((UINT16)(*(m_sreg)) >> 1));
1202            m_sfr &= ~SUPERFX_SFR_CY;
1203            m_sfr |= carry ? SUPERFX_SFR_CY : 0;
1204            superfx_dreg_sfr_sz_update();
1205            superfx_regs_reset();
12621206            break;
12631207         }
12641208
12651209         case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: // JMP / LJMP
1266            if((cpustate->sfr & SUPERFX_SFR_ALT1) == 0)
1210            if((m_sfr & SUPERFX_SFR_ALT1) == 0)
12671211            { // JMP
1268               superfx_gpr_write(cpustate, 15, cpustate->r[op & 0xf]);
1269               superfx_regs_reset(cpustate);
1212               superfx_gpr_write(15, m_r[op & 0xf]);
1213               superfx_regs_reset();
12701214            }
12711215            else
12721216            { // LJMP
1273               cpustate->pbr = cpustate->r[op & 0xf] & 0x7f;
1274               superfx_gpr_write(cpustate, 15, *(cpustate->sreg));
1275               cpustate->cbr = cpustate->r[15] & 0xfff0;
1276               superfx_cache_flush(cpustate);
1277               superfx_regs_reset(cpustate);
1217               m_pbr = m_r[op & 0xf] & 0x7f;
1218               superfx_gpr_write(15, *(m_sreg));
1219               m_cbr = m_r[15] & 0xfff0;
1220               superfx_cache_flush();
1221               superfx_regs_reset();
12781222            }
12791223            break;
12801224
12811225         case 0x9e: // LOB
1282            superfx_gpr_write(cpustate, cpustate->dreg_idx, (UINT16)(*(cpustate->sreg)) & 0x00ff);
1283            cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1284            cpustate->sfr |= (*(cpustate->dreg) & 0x80) ? SUPERFX_SFR_S : 0;
1285            cpustate->sfr |= (*(cpustate->dreg) == 0) ? SUPERFX_SFR_Z : 0;
1286            superfx_regs_reset(cpustate);
1226            superfx_gpr_write(m_dreg_idx, (UINT16)(*(m_sreg)) & 0x00ff);
1227            m_sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1228            m_sfr |= (*(m_dreg) & 0x80) ? SUPERFX_SFR_S : 0;
1229            m_sfr |= (*(m_dreg) == 0) ? SUPERFX_SFR_Z : 0;
1230            superfx_regs_reset();
12871231            break;
12881232
12891233         case 0x9f: // FMULT / LMULT
12901234         {
1291            UINT32 result = (INT16)(*(cpustate->sreg)) * (INT16)(cpustate->r[6]);
1292            if(cpustate->sfr & SUPERFX_SFR_ALT1)
1235            UINT32 result = (INT16)(*(m_sreg)) * (INT16)(m_r[6]);
1236            if(m_sfr & SUPERFX_SFR_ALT1)
12931237            { // LMULT
1294               superfx_gpr_write(cpustate, 4, result);
1238               superfx_gpr_write(4, result);
12951239            }
1296            superfx_gpr_write(cpustate, cpustate->dreg_idx, result >> 16);
1297            cpustate->sfr &= ~SUPERFX_SFR_CY;
1298            cpustate->sfr |= (result & 0x8000) ? SUPERFX_SFR_CY : 0;
1299            superfx_dreg_sfr_sz_update(cpustate);
1300            superfx_regs_reset(cpustate);
1301            superfx_add_clocks_internal(cpustate, 4 + ((cpustate->cfgr & SUPERFX_CFGR_MS0) ? 4 : 0));
1240            superfx_gpr_write(m_dreg_idx, result >> 16);
1241            m_sfr &= ~SUPERFX_SFR_CY;
1242            m_sfr |= (result & 0x8000) ? SUPERFX_SFR_CY : 0;
1243            superfx_dreg_sfr_sz_update();
1244            superfx_regs_reset();
1245            superfx_add_clocks_internal(4 + ((m_cfgr & SUPERFX_CFGR_MS0) ? 4 : 0));
13021246            break;
13031247         }
13041248
13051249         case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7:
13061250         case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: // IBT / LMS / SMS / LMS
1307            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1251            switch(m_sfr & SUPERFX_SFR_ALT)
13081252            {
13091253               case SUPERFX_SFR_ALT0: // IBT
1310                  superfx_gpr_write(cpustate, op & 0xf, (INT8)superfx_pipe(cpustate));
1311                  superfx_regs_reset(cpustate);
1254                  superfx_gpr_write(op & 0xf, (INT8)superfx_pipe());
1255                  superfx_regs_reset();
13121256                  break;
13131257               case SUPERFX_SFR_ALT2: // SMS
1314                  cpustate->ramaddr = superfx_pipe(cpustate) << 1;
1315                  superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 0, cpustate->r[op & 0xf] >> 0);
1316                  superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 1, cpustate->r[op & 0xf] >> 8);
1317                  superfx_regs_reset(cpustate);
1258                  m_ramaddr = superfx_pipe() << 1;
1259                  superfx_rambuffer_write(m_ramaddr ^ 0, m_r[op & 0xf] >> 0);
1260                  superfx_rambuffer_write(m_ramaddr ^ 1, m_r[op & 0xf] >> 8);
1261                  superfx_regs_reset();
13181262                  break;
13191263               case SUPERFX_SFR_ALT1: // LMS
13201264               case SUPERFX_SFR_ALT3: // LMS
13211265               {
13221266                  UINT16 data = 0;
1323                  cpustate->ramaddr = superfx_pipe(cpustate) << 1;
1324                  data  = superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 0) << 0;
1325                  data |= superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 1) << 8;
1326                  superfx_gpr_write(cpustate, op & 0xf, data);
1327                  superfx_regs_reset(cpustate);
1267                  m_ramaddr = superfx_pipe() << 1;
1268                  data  = superfx_rambuffer_read(m_ramaddr ^ 0) << 0;
1269                  data |= superfx_rambuffer_read(m_ramaddr ^ 1) << 8;
1270                  superfx_gpr_write(op & 0xf, data);
1271                  superfx_regs_reset();
13281272                  break;
13291273               }
13301274            }
r26752r26753
13321276
13331277         case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
13341278         case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: // FROM
1335            if((cpustate->sfr & SUPERFX_SFR_B) == 0)
1279            if((m_sfr & SUPERFX_SFR_B) == 0)
13361280            {
1337               cpustate->sreg = &(cpustate->r[op & 0xf]);
1338               cpustate->sreg_idx = op & 0xf;
1281               m_sreg = &(m_r[op & 0xf]);
1282               m_sreg_idx = op & 0xf;
13391283            }
13401284            else
13411285            {
1342               superfx_gpr_write(cpustate, cpustate->dreg_idx, cpustate->r[op & 0xf]);
1343               cpustate->sfr &= ~SUPERFX_SFR_OV;
1344               cpustate->sfr |= (*(cpustate->dreg) & 0x80) ? SUPERFX_SFR_OV : 0;
1345               superfx_dreg_sfr_sz_update(cpustate);
1346               superfx_regs_reset(cpustate);
1286               superfx_gpr_write(m_dreg_idx, m_r[op & 0xf]);
1287               m_sfr &= ~SUPERFX_SFR_OV;
1288               m_sfr |= (*(m_dreg) & 0x80) ? SUPERFX_SFR_OV : 0;
1289               superfx_dreg_sfr_sz_update();
1290               superfx_regs_reset();
13471291            }
13481292            break;
13491293
13501294         case 0xc0: // HIB
1351            superfx_gpr_write(cpustate, cpustate->dreg_idx, (*(cpustate->sreg)) >> 8);
1352            cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1353            cpustate->sfr |= (*(cpustate->dreg) & 0x80) ? SUPERFX_SFR_S : 0;
1354            cpustate->sfr |= (*(cpustate->dreg) == 0) ? SUPERFX_SFR_Z : 0;
1355            superfx_regs_reset(cpustate);
1295            superfx_gpr_write(m_dreg_idx, (*(m_sreg)) >> 8);
1296            m_sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1297            m_sfr |= (*(m_dreg) & 0x80) ? SUPERFX_SFR_S : 0;
1298            m_sfr |= (*(m_dreg) == 0) ? SUPERFX_SFR_Z : 0;
1299            superfx_regs_reset();
13561300            break;
13571301
13581302         case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7:
13591303         case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf: // OR / XOR / ORI / XORI
1360            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1304            switch(m_sfr & SUPERFX_SFR_ALT)
13611305            {
13621306               case SUPERFX_SFR_ALT0: // OR
1363                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) | cpustate->r[op & 0xf]);
1307                  superfx_gpr_write(m_dreg_idx, *(m_sreg) | m_r[op & 0xf]);
13641308                  break;
13651309               case SUPERFX_SFR_ALT1: // XOR
1366                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) ^ cpustate->r[op & 0xf]);
1310                  superfx_gpr_write(m_dreg_idx, *(m_sreg) ^ m_r[op & 0xf]);
13671311                  break;
13681312               case SUPERFX_SFR_ALT2: // ORI
1369                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) | (op & 0xf));
1313                  superfx_gpr_write(m_dreg_idx, *(m_sreg) | (op & 0xf));
13701314                  break;
13711315               case SUPERFX_SFR_ALT3: // XORI
1372                  superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) ^ (op & 0xf));
1316                  superfx_gpr_write(m_dreg_idx, *(m_sreg) ^ (op & 0xf));
13731317                  break;
13741318            }
1375            superfx_dreg_sfr_sz_update(cpustate);
1376            superfx_regs_reset(cpustate);
1319            superfx_dreg_sfr_sz_update();
1320            superfx_regs_reset();
13771321            break;
13781322
13791323         case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
13801324         case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde:            // INC
1381            superfx_gpr_write(cpustate, op & 0xf, cpustate->r[op & 0xf] + 1);
1382            cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1383            cpustate->sfr |= (cpustate->r[op & 0xf] & 0x8000) ? SUPERFX_SFR_S : 0;
1384            cpustate->sfr |= (cpustate->r[op & 0xf] == 0) ? SUPERFX_SFR_Z : 0;
1385            superfx_regs_reset(cpustate);
1325            superfx_gpr_write(op & 0xf, m_r[op & 0xf] + 1);
1326            m_sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1327            m_sfr |= (m_r[op & 0xf] & 0x8000) ? SUPERFX_SFR_S : 0;
1328            m_sfr |= (m_r[op & 0xf] == 0) ? SUPERFX_SFR_Z : 0;
1329            superfx_regs_reset();
13861330            break;
13871331
13881332         case 0xdf: // GETC / RAMB / ROMB
1389            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1333            switch(m_sfr & SUPERFX_SFR_ALT)
13901334            {
13911335               case SUPERFX_SFR_ALT0: // GETC
13921336               case SUPERFX_SFR_ALT1: // GETC
1393                  cpustate->colr = superfx_color(cpustate, superfx_rombuffer_read(cpustate));
1394                  superfx_regs_reset(cpustate);
1337                  m_colr = superfx_color(superfx_rombuffer_read());
1338                  superfx_regs_reset();
13951339                  break;
13961340               case SUPERFX_SFR_ALT2: // RAMB
1397                  superfx_rambuffer_sync(cpustate);
1398                  cpustate->rambr = ((*(cpustate->sreg)) & 1) ? 1 : 0;
1399                  superfx_regs_reset(cpustate);
1341                  superfx_rambuffer_sync();
1342                  m_rambr = ((*(m_sreg)) & 1) ? 1 : 0;
1343                  superfx_regs_reset();
14001344                  break;
14011345               case SUPERFX_SFR_ALT3: // ROMB
1402                  superfx_rombuffer_sync(cpustate);
1403                  cpustate->rombr = *(cpustate->sreg) & 0x7f;
1404                  superfx_regs_reset(cpustate);
1346                  superfx_rombuffer_sync();
1347                  m_rombr = *(m_sreg) & 0x7f;
1348                  superfx_regs_reset();
14051349                  break;
14061350            }
14071351            break;
14081352
14091353         case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7:
14101354         case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee:            // DEC
1411            superfx_gpr_write(cpustate, op & 0xf, cpustate->r[op & 0xf] - 1);
1412            cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1413            cpustate->sfr |= (cpustate->r[op & 0xf] & 0x8000) ? SUPERFX_SFR_S : 0;
1414            cpustate->sfr |= (cpustate->r[op & 0xf] == 0) ? SUPERFX_SFR_Z : 0;
1415            superfx_regs_reset(cpustate);
1355            superfx_gpr_write(op & 0xf, m_r[op & 0xf] - 1);
1356            m_sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z);
1357            m_sfr |= (m_r[op & 0xf] & 0x8000) ? SUPERFX_SFR_S : 0;
1358            m_sfr |= (m_r[op & 0xf] == 0) ? SUPERFX_SFR_Z : 0;
1359            superfx_regs_reset();
14161360            break;
14171361
14181362         case 0xef: // GETB / GETBH / GETBL / GETBS
14191363         {
1420            UINT8 byte = superfx_rombuffer_read(cpustate);
1421            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1364            UINT8 byte = superfx_rombuffer_read();
1365            switch(m_sfr & SUPERFX_SFR_ALT)
14221366            {
14231367               case SUPERFX_SFR_ALT0: // GETB
1424                  superfx_gpr_write(cpustate, cpustate->dreg_idx, byte);
1368                  superfx_gpr_write(m_dreg_idx, byte);
14251369                  break;
14261370               case SUPERFX_SFR_ALT1: // GETBH
1427                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (byte << 8) | (*(cpustate->sreg) & 0x00ff));
1371                  superfx_gpr_write(m_dreg_idx, (byte << 8) | (*(m_sreg) & 0x00ff));
14281372                  break;
14291373               case SUPERFX_SFR_ALT2: // GETBL
1430                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (*(cpustate->sreg) & 0xff00) | (byte << 0));
1374                  superfx_gpr_write(m_dreg_idx, (*(m_sreg) & 0xff00) | (byte << 0));
14311375                  break;
14321376               case SUPERFX_SFR_ALT3: // GETBS
1433                  superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT8)byte);
1377                  superfx_gpr_write(m_dreg_idx, (INT8)byte);
14341378                  break;
14351379            }
1436            superfx_regs_reset(cpustate);
1380            superfx_regs_reset();
14371381            break;
14381382         }
14391383
r26752r26753
14411385         case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: // IWT / LM / SM / LM
14421386         {
14431387            UINT16 data;
1444            switch(cpustate->sfr & SUPERFX_SFR_ALT)
1388            switch(m_sfr & SUPERFX_SFR_ALT)
14451389            {
14461390               case SUPERFX_SFR_ALT0: // IWT
1447                  data  = superfx_pipe(cpustate) << 0;
1448                  data |= superfx_pipe(cpustate) << 8;
1449                  superfx_gpr_write(cpustate, op & 0xf, data);
1450                  superfx_regs_reset(cpustate);
1391                  data  = superfx_pipe() << 0;
1392                  data |= superfx_pipe() << 8;
1393                  superfx_gpr_write(op & 0xf, data);
1394                  superfx_regs_reset();
14511395                  break;
14521396               case SUPERFX_SFR_ALT2: // SM
1453                  cpustate->ramaddr  = superfx_pipe(cpustate) << 0;
1454                  cpustate->ramaddr |= superfx_pipe(cpustate) << 8;
1455                  superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 0, cpustate->r[op & 0xf] >> 0);
1456                  superfx_rambuffer_write(cpustate, cpustate->ramaddr ^ 1, cpustate->r[op & 0xf] >> 8);
1457                  superfx_regs_reset(cpustate);
1397                  m_ramaddr  = superfx_pipe() << 0;
1398                  m_ramaddr |= superfx_pipe() << 8;
1399                  superfx_rambuffer_write(m_ramaddr ^ 0, m_r[op & 0xf] >> 0);
1400                  superfx_rambuffer_write(m_ramaddr ^ 1, m_r[op & 0xf] >> 8);
1401                  superfx_regs_reset();
14581402                  break;
14591403               case SUPERFX_SFR_ALT1:
14601404               case SUPERFX_SFR_ALT3: // LM
1461                  cpustate->ramaddr  = superfx_pipe(cpustate) << 0;
1462                  cpustate->ramaddr |= superfx_pipe(cpustate) << 8;
1463                  data  = superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 0) << 0;
1464                  data |= superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 1) << 8;
1465                  superfx_gpr_write(cpustate, op & 0xf, data);
1466                  superfx_regs_reset(cpustate);
1405                  m_ramaddr  = superfx_pipe() << 0;
1406                  m_ramaddr |= superfx_pipe() << 8;
1407                  data  = superfx_rambuffer_read(m_ramaddr ^ 0) << 0;
1408                  data |= superfx_rambuffer_read(m_ramaddr ^ 1) << 8;
1409                  superfx_gpr_write(op & 0xf, data);
1410                  superfx_regs_reset();
14671411                  break;
14681412            }
14691413            break;
14701414         }
14711415      }
14721416
1473      if(!cpustate->r15_modified)
1417      if(!m_r15_modified)
14741418      {
1475         cpustate->r[15]++;
1419         m_r[15]++;
14761420      }
14771421
1478      //printf( " r0:%04x  r1:%04x  r2:%04x  r3:%04x  r4:%04x  r5:%04x  r6:%04x  r7:%04x\n",  cpustate->r[0],  cpustate->r[1],  cpustate->r[2],  cpustate->r[3],  cpustate->r[4],  cpustate->r[5],  cpustate->r[6],  cpustate->r[7] );
1479      //printf( " r8:%04x  r9:%04x r10:%04x r11:%04x r12:%04x r13:%04x r14:%04x r15:%04x\n",  cpustate->r[8],  cpustate->r[9], cpustate->r[10], cpustate->r[11], cpustate->r[12], cpustate->r[13], cpustate->r[14], cpustate->r[15] );
1480      //printf( "sfr:%04x\n", cpustate->sfr );
1422      //printf( " r0:%04x  r1:%04x  r2:%04x  r3:%04x  r4:%04x  r5:%04x  r6:%04x  r7:%04x\n",  m_r[0],  m_r[1],  m_r[2],  m_r[3],  m_r[4],  m_r[5],  m_r[6],  m_r[7] );
1423      //printf( " r8:%04x  r9:%04x r10:%04x r11:%04x r12:%04x r13:%04x r14:%04x r15:%04x\n",  m_r[8],  m_r[9], m_r[10], m_r[11], m_r[12], m_r[13], m_r[14], m_r[15] );
1424      //printf( "sfr:%04x\n", m_sfr );
14811425
1482      --cpustate->icount;
1426      --m_icount;
14831427   }
14841428}
14851429
1486/*****************************************************************************/
14871430
1488CPU_DISASSEMBLE( superfx )
1431offs_t superfx_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
14891432{
1490   superfx_state *cpustate = get_safe_token(device);
1433extern offs_t superfx_dasm_one(char *buffer, offs_t pc, UINT8 op, UINT8 param0, UINT8 param1, UINT16 alt);
14911434
1492   UINT8  op = *(UINT8 *)(opram + 0);
1493   UINT8  param0 = *(UINT8 *)(opram + 1);
1494   UINT8  param1 = *(UINT8 *)(opram + 2);
1495   UINT16 alt = cpustate->sfr & SUPERFX_SFR_ALT;
1435    UINT8  op = *(UINT8 *)(opram + 0);
1436    UINT8  param0 = *(UINT8 *)(opram + 1);
1437    UINT8  param1 = *(UINT8 *)(opram + 2);
1438    UINT16 alt = m_sfr & SUPERFX_SFR_ALT;
14961439
1497   return superfx_dasm_one(buffer, pc, op, param0, param1, alt);
1440    return superfx_dasm_one(buffer, pc, op, param0, param1, alt);
14981441}
14991442
1500/*****************************************************************************/
1501
1502static CPU_SET_INFO( superfx )
1503{
1504   superfx_state *cpustate = get_safe_token(device);
1505
1506   switch (state)
1507   {
1508   /* --- the following bits of info are set as 64-bit signed integers --- */
1509   case CPUINFO_INT_PC:
1510   case CPUINFO_INT_REGISTER + SUPERFX_PC:         cpustate->r[15] = info->i;      break;
1511   case CPUINFO_INT_REGISTER + SUPERFX_DREG:       info->i = cpustate->dreg_idx;   break;
1512   case CPUINFO_INT_REGISTER + SUPERFX_SREG:       info->i = cpustate->sreg_idx;   break;
1513   case CPUINFO_INT_REGISTER + SUPERFX_R0:         cpustate->r[0] = info->i;       break;
1514   case CPUINFO_INT_REGISTER + SUPERFX_R1:         cpustate->r[1] = info->i;       break;
1515   case CPUINFO_INT_REGISTER + SUPERFX_R2:         cpustate->r[2] = info->i;       break;
1516   case CPUINFO_INT_REGISTER + SUPERFX_R3:         cpustate->r[3] = info->i;       break;
1517   case CPUINFO_INT_REGISTER + SUPERFX_R4:         cpustate->r[4] = info->i;       break;
1518   case CPUINFO_INT_REGISTER + SUPERFX_R5:         cpustate->r[5] = info->i;       break;
1519   case CPUINFO_INT_REGISTER + SUPERFX_R6:         cpustate->r[6] = info->i;       break;
1520   case CPUINFO_INT_REGISTER + SUPERFX_R7:         cpustate->r[7] = info->i;       break;
1521   case CPUINFO_INT_REGISTER + SUPERFX_R8:         cpustate->r[8] = info->i;       break;
1522   case CPUINFO_INT_REGISTER + SUPERFX_R9:         cpustate->r[9] = info->i;       break;
1523   case CPUINFO_INT_REGISTER + SUPERFX_R10:        cpustate->r[10] = info->i;      break;
1524   case CPUINFO_INT_REGISTER + SUPERFX_R11:        cpustate->r[11] = info->i;      break;
1525   case CPUINFO_INT_REGISTER + SUPERFX_R12:        cpustate->r[12] = info->i;      break;
1526   case CPUINFO_INT_REGISTER + SUPERFX_R13:        cpustate->r[13] = info->i;      break;
1527   case CPUINFO_INT_REGISTER + SUPERFX_R14:        cpustate->r[14] = info->i;      break;
1528   case CPUINFO_INT_REGISTER + SUPERFX_R15:        cpustate->r[15] = info->i;      break;
1529   case CPUINFO_INT_REGISTER + SUPERFX_SFR:        cpustate->sfr = info->i;        break;
1530   case CPUINFO_INT_REGISTER + SUPERFX_PBR:        cpustate->pbr = info->i;        break;
1531   case CPUINFO_INT_REGISTER + SUPERFX_ROMBR:      cpustate->rombr = info->i;      break;
1532   case CPUINFO_INT_REGISTER + SUPERFX_RAMBR:      cpustate->rambr = info->i;      break;
1533   case CPUINFO_INT_REGISTER + SUPERFX_CBR:        cpustate->cbr = info->i;        break;
1534   case CPUINFO_INT_REGISTER + SUPERFX_SCBR:       cpustate->scbr = info->i;       break;
1535   case CPUINFO_INT_REGISTER + SUPERFX_SCMR:       cpustate->scmr = info->i;       break;
1536   case CPUINFO_INT_REGISTER + SUPERFX_COLR:       cpustate->colr = info->i;       break;
1537   case CPUINFO_INT_REGISTER + SUPERFX_POR:        cpustate->por = info->i;        break;
1538   case CPUINFO_INT_REGISTER + SUPERFX_BRAMR:      cpustate->bramr = info->i;      break;
1539   case CPUINFO_INT_REGISTER + SUPERFX_VCR:        cpustate->vcr = info->i;        break;
1540   case CPUINFO_INT_REGISTER + SUPERFX_CFGR:       cpustate->cfgr = info->i;       break;
1541   case CPUINFO_INT_REGISTER + SUPERFX_CLSR:       cpustate->clsr = info->i;       break;
1542   case CPUINFO_INT_REGISTER + SUPERFX_ROMCL:      cpustate->romcl = info->i;      break;
1543   case CPUINFO_INT_REGISTER + SUPERFX_ROMDR:      cpustate->romdr = info->i;      break;
1544   case CPUINFO_INT_REGISTER + SUPERFX_RAMCL:      cpustate->ramcl = info->i;      break;
1545   case CPUINFO_INT_REGISTER + SUPERFX_RAMAR:      cpustate->ramar = info->i;      break;
1546   case CPUINFO_INT_REGISTER + SUPERFX_RAMDR:      cpustate->ramdr = info->i;      break;
1547   case CPUINFO_INT_REGISTER + SUPERFX_RAMADDR:    cpustate->ramaddr = info->i;    break;
1548   }
1549}
1550
1551CPU_GET_INFO( superfx )
1552{
1553   superfx_state *cpustate = (device != NULL && device->token() != NULL) ? get_safe_token(device) : NULL;
1554
1555   switch(state)
1556   {
1557   /* --- the following bits of info are returned as 64-bit signed integers --- */
1558   case CPUINFO_INT_CONTEXT_SIZE:              info->i = sizeof(superfx_state);                    break;
1559   case CPUINFO_INT_INPUT_LINES:               info->i = 0;                                        break;
1560   case CPUINFO_INT_DEFAULT_IRQ_VECTOR:        info->i = 0;                                        break;
1561   case CPUINFO_INT_ENDIANNESS:                info->i = ENDIANNESS_LITTLE;                        break;
1562   case CPUINFO_INT_CLOCK_MULTIPLIER:          info->i = 1;                                        break;
1563   case CPUINFO_INT_CLOCK_DIVIDER:             info->i = 1;                                        break;
1564   case CPUINFO_INT_MIN_INSTRUCTION_BYTES:     info->i = 1;                                        break;
1565   case CPUINFO_INT_MAX_INSTRUCTION_BYTES:     info->i = 3;                                        break;
1566   case CPUINFO_INT_MIN_CYCLES:                info->i = 1;                                        break;
1567   case CPUINFO_INT_MAX_CYCLES:                info->i = 1;                                        break;
1568
1569   case CPUINFO_INT_DATABUS_WIDTH + AS_PROGRAM:    info->i = 8;                                        break;
1570   case CPUINFO_INT_ADDRBUS_WIDTH + AS_PROGRAM:    info->i = 32;                                       break;
1571   case CPUINFO_INT_ADDRBUS_SHIFT + AS_PROGRAM:    info->i = 0;                                        break;
1572   case CPUINFO_INT_DATABUS_WIDTH + AS_DATA:       info->i = 0;                                        break;
1573   case CPUINFO_INT_ADDRBUS_WIDTH + AS_DATA:       info->i = 0;                                        break;
1574   case CPUINFO_INT_ADDRBUS_SHIFT + AS_DATA:       info->i = 0;                                        break;
1575   case CPUINFO_INT_DATABUS_WIDTH + AS_IO:         info->i = 0;                                        break;
1576   case CPUINFO_INT_ADDRBUS_WIDTH + AS_IO:         info->i = 0;                                        break;
1577   case CPUINFO_INT_ADDRBUS_SHIFT + AS_IO:         info->i = 0;                                        break;
1578
1579   case CPUINFO_INT_PC:    /* intentional fallthrough */
1580   case CPUINFO_INT_REGISTER + SUPERFX_PC:         info->i = ((cpustate->pbr << 16) | cpustate->r[15]) - 1; break;
1581   case CPUINFO_INT_REGISTER + SUPERFX_DREG:       info->i = cpustate->dreg_idx;   break;
1582   case CPUINFO_INT_REGISTER + SUPERFX_SREG:       info->i = cpustate->sreg_idx;   break;
1583   case CPUINFO_INT_REGISTER + SUPERFX_R0:         info->i = cpustate->r[0];       break;
1584   case CPUINFO_INT_REGISTER + SUPERFX_R1:         info->i = cpustate->r[1];       break;
1585   case CPUINFO_INT_REGISTER + SUPERFX_R2:         info->i = cpustate->r[2];       break;
1586   case CPUINFO_INT_REGISTER + SUPERFX_R3:         info->i = cpustate->r[3];       break;
1587   case CPUINFO_INT_REGISTER + SUPERFX_R4:         info->i = cpustate->r[4];       break;
1588   case CPUINFO_INT_REGISTER + SUPERFX_R5:         info->i = cpustate->r[5];       break;
1589   case CPUINFO_INT_REGISTER + SUPERFX_R6:         info->i = cpustate->r[6];       break;
1590   case CPUINFO_INT_REGISTER + SUPERFX_R7:         info->i = cpustate->r[7];       break;
1591   case CPUINFO_INT_REGISTER + SUPERFX_R8:         info->i = cpustate->r[8];       break;
1592   case CPUINFO_INT_REGISTER + SUPERFX_R9:         info->i = cpustate->r[9];       break;
1593   case CPUINFO_INT_REGISTER + SUPERFX_R10:        info->i = cpustate->r[10];      break;
1594   case CPUINFO_INT_REGISTER + SUPERFX_R11:        info->i = cpustate->r[11];      break;
1595   case CPUINFO_INT_REGISTER + SUPERFX_R12:        info->i = cpustate->r[12];      break;
1596   case CPUINFO_INT_REGISTER + SUPERFX_R13:        info->i = cpustate->r[13];      break;
1597   case CPUINFO_INT_REGISTER + SUPERFX_R14:        info->i = cpustate->r[14];      break;
1598   case CPUINFO_INT_REGISTER + SUPERFX_R15:        info->i = cpustate->r[15];      break;
1599   case CPUINFO_INT_REGISTER + SUPERFX_SFR:        info->i = cpustate->sfr;        break;
1600   case CPUINFO_INT_REGISTER + SUPERFX_PBR:        info->i = cpustate->pbr;        break;
1601   case CPUINFO_INT_REGISTER + SUPERFX_ROMBR:      info->i = cpustate->rombr;      break;
1602   case CPUINFO_INT_REGISTER + SUPERFX_RAMBR:      info->i = cpustate->rambr;      break;
1603   case CPUINFO_INT_REGISTER + SUPERFX_CBR:        info->i = cpustate->cbr;        break;
1604   case CPUINFO_INT_REGISTER + SUPERFX_SCBR:       info->i = cpustate->scbr;       break;
1605   case CPUINFO_INT_REGISTER + SUPERFX_SCMR:       info->i = cpustate->scmr;       break;
1606   case CPUINFO_INT_REGISTER + SUPERFX_COLR:       info->i = cpustate->colr;       break;
1607   case CPUINFO_INT_REGISTER + SUPERFX_POR:        info->i = cpustate->por;        break;
1608   case CPUINFO_INT_REGISTER + SUPERFX_BRAMR:      info->i = cpustate->bramr;      break;
1609   case CPUINFO_INT_REGISTER + SUPERFX_VCR:        info->i = cpustate->vcr;        break;
1610   case CPUINFO_INT_REGISTER + SUPERFX_CFGR:       info->i = cpustate->cfgr;       break;
1611   case CPUINFO_INT_REGISTER + SUPERFX_CLSR:       info->i = cpustate->clsr;       break;
1612   case CPUINFO_INT_REGISTER + SUPERFX_ROMCL:      info->i = cpustate->romcl;      break;
1613   case CPUINFO_INT_REGISTER + SUPERFX_ROMDR:      info->i = cpustate->romdr;      break;
1614   case CPUINFO_INT_REGISTER + SUPERFX_RAMCL:      info->i = cpustate->ramcl;      break;
1615   case CPUINFO_INT_REGISTER + SUPERFX_RAMAR:      info->i = cpustate->ramar;      break;
1616   case CPUINFO_INT_REGISTER + SUPERFX_RAMDR:      info->i = cpustate->ramdr;      break;
1617   case CPUINFO_INT_REGISTER + SUPERFX_RAMADDR:    info->i = cpustate->ramaddr;    break;
1618
1619      /* --- the following bits of info are returned as pointers to data or functions --- */
1620   case CPUINFO_FCT_SET_INFO:              info->setinfo = CPU_SET_INFO_NAME(superfx);             break;
1621   case CPUINFO_FCT_INIT:                  info->init = CPU_INIT_NAME(superfx);                    break;
1622   case CPUINFO_FCT_RESET:                 info->reset = CPU_RESET_NAME(superfx);                  break;
1623   case CPUINFO_FCT_EXIT:                  info->exit = CPU_EXIT_NAME(superfx);                    break;
1624   case CPUINFO_FCT_EXECUTE:               info->execute = CPU_EXECUTE_NAME(superfx);              break;
1625   case CPUINFO_FCT_BURN:                  info->burn = NULL;                                      break;
1626   case CPUINFO_FCT_DISASSEMBLE:           info->disassemble = CPU_DISASSEMBLE_NAME(superfx);      break;
1627   case CPUINFO_PTR_INSTRUCTION_COUNTER:   info->icount = &cpustate->icount;                       break;
1628
1629      /* --- the following bits of info are returned as NULL-terminated strings --- */
1630   case CPUINFO_STR_NAME:                          strcpy(info->s, "SuperFX");                     break;
1631   case CPUINFO_STR_SHORTNAME:                     strcpy(info->s, "superfx");                     break;
1632   case CPUINFO_STR_FAMILY:                        strcpy(info->s, "SuperFX");                     break;
1633   case CPUINFO_STR_VERSION:                       strcpy(info->s, "1.0");                         break;
1634   case CPUINFO_STR_SOURCE_FILE:                   strcpy(info->s, __FILE__);                      break;
1635   case CPUINFO_STR_CREDITS:                       strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
1636
1637   case CPUINFO_STR_FLAGS:                         strcpy(info->s, " ");                           break;
1638
1639   case CPUINFO_STR_REGISTER + SUPERFX_PC:         sprintf(info->s, "PC:      %06X", (cpustate->pbr << 16) | cpustate->r[15]); break;
1640   case CPUINFO_STR_REGISTER + SUPERFX_DREG:       sprintf(info->s, "DREG:    R%d",  cpustate->dreg_idx);  break;
1641   case CPUINFO_STR_REGISTER + SUPERFX_SREG:       sprintf(info->s, "SREG:    R%d",  cpustate->sreg_idx);  break;
1642   case CPUINFO_STR_REGISTER + SUPERFX_R0:         sprintf(info->s, "R0:      %04X", cpustate->r[0]);      break;
1643   case CPUINFO_STR_REGISTER + SUPERFX_R1:         sprintf(info->s, "R1:      %04X", cpustate->r[1]);      break;
1644   case CPUINFO_STR_REGISTER + SUPERFX_R2:         sprintf(info->s, "R2:      %04X", cpustate->r[2]);      break;
1645   case CPUINFO_STR_REGISTER + SUPERFX_R3:         sprintf(info->s, "R3:      %04X", cpustate->r[3]);      break;
1646   case CPUINFO_STR_REGISTER + SUPERFX_R4:         sprintf(info->s, "R4:      %04X", cpustate->r[4]);      break;
1647   case CPUINFO_STR_REGISTER + SUPERFX_R5:         sprintf(info->s, "R5:      %04X", cpustate->r[5]);      break;
1648   case CPUINFO_STR_REGISTER + SUPERFX_R6:         sprintf(info->s, "R6:      %04X", cpustate->r[6]);      break;
1649   case CPUINFO_STR_REGISTER + SUPERFX_R7:         sprintf(info->s, "R7:      %04X", cpustate->r[7]);      break;
1650   case CPUINFO_STR_REGISTER + SUPERFX_R8:         sprintf(info->s, "R8:      %04X", cpustate->r[8]);      break;
1651   case CPUINFO_STR_REGISTER + SUPERFX_R9:         sprintf(info->s, "R9:      %04X", cpustate->r[9]);      break;
1652   case CPUINFO_STR_REGISTER + SUPERFX_R10:        sprintf(info->s, "R10:     %04X", cpustate->r[10]);     break;
1653   case CPUINFO_STR_REGISTER + SUPERFX_R11:        sprintf(info->s, "R11:     %04X", cpustate->r[11]);     break;
1654   case CPUINFO_STR_REGISTER + SUPERFX_R12:        sprintf(info->s, "R12:     %04X", cpustate->r[12]);     break;
1655   case CPUINFO_STR_REGISTER + SUPERFX_R13:        sprintf(info->s, "R13:     %04X", cpustate->r[13]);     break;
1656   case CPUINFO_STR_REGISTER + SUPERFX_R14:        sprintf(info->s, "R14:     %04X", cpustate->r[14]);     break;
1657   case CPUINFO_STR_REGISTER + SUPERFX_R15:        sprintf(info->s, "R15:     %04X", cpustate->r[15]);     break;
1658   case CPUINFO_STR_REGISTER + SUPERFX_SFR:        sprintf(info->s, "SFR:     %04X", cpustate->sfr);       break;
1659   case CPUINFO_STR_REGISTER + SUPERFX_PBR:        sprintf(info->s, "PBR:     %02X", cpustate->pbr);       break;
1660   case CPUINFO_STR_REGISTER + SUPERFX_ROMBR:      sprintf(info->s, "ROMBR:   %02X", cpustate->rombr);     break;
1661   case CPUINFO_STR_REGISTER + SUPERFX_RAMBR:      sprintf(info->s, "RAMBR:   %02X", cpustate->rambr);     break;
1662   case CPUINFO_STR_REGISTER + SUPERFX_CBR:        sprintf(info->s, "CBR:     %04X", cpustate->cbr);       break;
1663   case CPUINFO_STR_REGISTER + SUPERFX_SCBR:       sprintf(info->s, "SCBR:    %02X", cpustate->scbr);      break;
1664   case CPUINFO_STR_REGISTER + SUPERFX_SCMR:       sprintf(info->s, "SCMR:    %02X", cpustate->scmr);      break;
1665   case CPUINFO_STR_REGISTER + SUPERFX_COLR:       sprintf(info->s, "COLR     %02X", cpustate->colr);      break;
1666   case CPUINFO_STR_REGISTER + SUPERFX_POR:        sprintf(info->s, "POR:     %02X", cpustate->por);       break;
1667   case CPUINFO_STR_REGISTER + SUPERFX_BRAMR:      sprintf(info->s, "BRAMR:   %02X", cpustate->bramr);     break;
1668   case CPUINFO_STR_REGISTER + SUPERFX_VCR:        sprintf(info->s, "VCR:     %02X", cpustate->vcr);       break;
1669   case CPUINFO_STR_REGISTER + SUPERFX_CFGR:       sprintf(info->s, "CFGR:    %02X", cpustate->cfgr);      break;
1670   case CPUINFO_STR_REGISTER + SUPERFX_CLSR:       sprintf(info->s, "CLSR:    %02X", cpustate->clsr);      break;
1671   case CPUINFO_STR_REGISTER + SUPERFX_ROMCL:      sprintf(info->s, "ROMCL:   %08X", cpustate->romcl);     break;
1672   case CPUINFO_STR_REGISTER + SUPERFX_ROMDR:      sprintf(info->s, "ROMDR:   %02X", cpustate->romdr);     break;
1673   case CPUINFO_STR_REGISTER + SUPERFX_RAMCL:      sprintf(info->s, "RAMCL:   %08X", cpustate->ramcl);     break;
1674   case CPUINFO_STR_REGISTER + SUPERFX_RAMAR:      sprintf(info->s, "RAMAR:   %04X", cpustate->ramar);     break;
1675   case CPUINFO_STR_REGISTER + SUPERFX_RAMDR:      sprintf(info->s, "RAMDR:   %02X", cpustate->ramdr);     break;
1676   case CPUINFO_STR_REGISTER + SUPERFX_RAMADDR:    sprintf(info->s, "RAMADDR: %04X", cpustate->ramaddr);   break;
1677   }
1678}
1679
1680DEFINE_LEGACY_CPU_DEVICE(SUPERFX, superfx);
trunk/src/emu/cpu/superfx/superfx.h
r26752r26753
8383#define SUPERFX_CFGR_IRQ    0x80    // IRQ
8484#define SUPERFX_CFGR_MS0    0x20    // MS0
8585
86struct superfx_config
86
87#define MCFG_SUPERFX_OUT_IRQ(_devcb) \
88   superfx_device::set_out_irq_func(*device, DEVCB2_##_devcb);
89
90
91class superfx_device :  public cpu_device
8792{
88   devcb_write_line    out_irq_func;           /* IRQ changed callback */
93public:
94   // construction/destruction
95   superfx_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock);
96
97   // static configuration helpers
98   template<class _Object> static devcb2_base &set_out_irq_func(device_t &device, _Object object) { return downcast<superfx_device &>(device).m_out_irq_func.set_callback(object); }
99
100   UINT8 mmio_read(UINT32 addr);
101   void mmio_write(UINT32 addr, UINT8 data);
102   void add_clocks(INT32 clocks);
103   int access_ram();
104   int access_rom();
105
106protected:
107   // device-level overrides
108   virtual void device_start();
109   virtual void device_reset();
110
111   // device_execute_interface overrides
112   virtual UINT32 execute_min_cycles() const { return 1; }
113   virtual UINT32 execute_max_cycles() const { return 1; }
114   virtual UINT32 execute_input_lines() const { return 0; }
115   virtual void execute_run();
116
117   // device_memory_interface overrides
118   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; }
119
120   // device_state_interface overrides
121   virtual void state_import(const device_state_entry &entry);
122   virtual void state_export(const device_state_entry &entry);
123
124   // device_disasm_interface overrides
125   virtual UINT32 disasm_min_opcode_bytes() const { return 1; }
126   virtual UINT32 disasm_max_opcode_bytes() const { return 3; }
127   virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
128
129private:
130   address_space_config m_program_config;
131
132   devcb2_write_line   m_out_irq_func;
133
134   UINT8  m_pipeline;
135   UINT16 m_ramaddr; // RAM Address
136
137   UINT16 m_r[16];   // GPRs
138   UINT16 m_sfr;     // Status Flag Register
139   UINT8  m_pbr;     // Program Bank Register
140   UINT8  m_rombr;   // Game Pack ROM Bank Register
141   UINT8  m_rambr;   // Game Pack RAM Bank Register
142   UINT16 m_cbr;     // Cache Base Register
143   UINT8  m_scbr;    // Screen Base Register
144   UINT8  m_scmr;    // Screen Mode Register
145   UINT8  m_colr;    // Color Register
146   UINT8  m_por;     // Plot Option Register
147   UINT8  m_bramr;   // Back-Up RAM Register
148   UINT8  m_vcr;     // Version Code Register
149   UINT8  m_cfgr;    // Config Register
150   UINT8  m_clsr;    // Clock Select Register
151
152   UINT32 m_romcl;   // Clock ticks until ROMDR is valid
153   UINT8  m_romdr;   // ROM Buffer Data Register
154
155   UINT32 m_ramcl;   // Clock ticks until RAMDR is valid;
156   UINT16 m_ramar;   // RAM Buffer Address Register
157   UINT8  m_ramdr;   // RAM Buffer Data Register
158
159   UINT16 *m_sreg;   // Source Register (From)
160   UINT8  m_sreg_idx;// Source Register (To), index
161   UINT16 *m_dreg;   // Destination Register (To)
162   UINT8  m_dreg_idx;// Destination Register (To), index
163   UINT8  m_r15_modified;
164
165   UINT8  m_irq;     // IRQ Pending
166
167   UINT32 m_cache_access_speed;
168   UINT32 m_memory_access_speed;
169
170   struct {
171      UINT8 buffer[0x200];
172      UINT8 valid[0x20];
173   } m_cache;
174   struct {
175      UINT16 offset;
176      UINT8 bitpend;
177      UINT8 data[8];
178   } m_pixelcache[2];
179
180   address_space *m_program;
181   int m_icount;
182
183   UINT32 m_debugger_temp;
184
185   inline void superfx_regs_reset();
186   void superfx_update_speed();
187   void superfx_cache_flush();;
188   UINT8 superfx_cache_mmio_read(UINT32 addr);
189   void superfx_cache_mmio_write(UINT32 addr, UINT8 data);
190   void superfx_memory_reset();
191   inline UINT8 superfx_bus_read(UINT32 addr);
192   inline void superfx_bus_write(UINT32 addr, UINT8 data);
193   inline void superfx_pixelcache_flush(INT32 line);
194   inline void superfx_plot(UINT8 x, UINT8 y);
195   UINT8 superfx_rpix(UINT8 x, UINT8 y);
196   inline UINT8 superfx_color(UINT8 source);
197   inline void superfx_rambuffer_sync();
198   inline UINT8 superfx_rambuffer_read(UINT16 addr);
199   inline void superfx_rambuffer_write(UINT16 addr, UINT8 data);
200   inline void superfx_rombuffer_sync();
201   inline void superfx_rombuffer_update();
202   inline UINT8 superfx_rombuffer_read();
203   inline void superfx_gpr_write(UINT8 r, UINT16 data);
204   inline UINT8 superfx_op_read(UINT16 addr);
205   inline UINT8 superfx_peekpipe();
206   inline UINT8 superfx_pipe();
207   inline void superfx_add_clocks_internal(UINT32 clocks);
208   void superfx_timing_reset();
209   inline void superfx_dreg_sfr_sz_update();
89210};
90#define SUPERFX_CONFIG(name) const superfx_config (name) =
91211
92DECLARE_LEGACY_CPU_DEVICE(SUPERFX, superfx);
93212
94CPU_DISASSEMBLE( superfx );
95extern offs_t superfx_dasm_one(char *buffer, offs_t pc, UINT8 op, UINT8 param0, UINT8 param1, UINT16 alt);
213extern const device_type SUPERFX;
96214
97UINT8 superfx_mmio_read(device_t *cpu, UINT32 addr);
98void superfx_mmio_write(device_t *cpu, UINT32 addr, UINT8 data);
99void superfx_add_clocks(device_t *cpu, INT32 clocks);
100int superfx_access_ram(device_t *cpu);
101int superfx_access_rom(device_t *cpu);
102
103215#endif /* __SUPERFX_H__ */
trunk/src/mess/machine/sns_sfx.c
r26752r26753
8585   machine().device("maincpu")->execute().set_input_line(G65816_LINE_IRQ, state);
8686}
8787
88static SUPERFX_CONFIG( snes_sfx_config )
89{
90   DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, sns_rom_superfx_device, snes_extern_irq_w)  /* IRQ line from cart */
91};
9288
93
9489static MACHINE_CONFIG_FRAGMENT( snes_sfx )
9590   MCFG_CPU_ADD("superfx", SUPERFX, 21480000)  /* 21.48MHz */
9691   MCFG_CPU_PROGRAM_MAP(sfx_map)
97   MCFG_CPU_CONFIG(snes_sfx_config)
92   MCFG_SUPERFX_OUT_IRQ(WRITELINE(sns_rom_superfx_device, snes_extern_irq_w))  /* IRQ line from cart */
9893MACHINE_CONFIG_END
9994
10095machine_config_constructor sns_rom_superfx_device::device_mconfig_additions() const
r26752r26753
10499
105100READ8_MEMBER( sns_rom_superfx_device::chip_read )
106101{
107   return superfx_mmio_read(m_superfx, offset);
102   return m_superfx->mmio_read(offset);
108103}
109104
110105WRITE8_MEMBER( sns_rom_superfx_device::chip_write )
111106{
112   superfx_mmio_write(m_superfx, offset, data);
107   m_superfx->mmio_write(offset, data);
113108}
114109
115110
r26752r26753
124119      return m_rom[rom_bank_map[offset / 0x10000] * 0x8000 + (offset & 0x7fff)];
125120   else if (offset < 0x600000)
126121   {
127      if (superfx_access_rom(m_superfx))
122      if (m_superfx->access_rom())
128123      {
129124         return m_rom[rom_bank_map[(offset - 0x400000) / 0x8000] * 0x8000 + (offset & 0x7fff)];
130125      }
r26752r26753
142137
143138READ8_MEMBER( sns_rom_superfx_device::read_ram )
144139{
145   if (superfx_access_ram(m_superfx))
140   if (m_superfx->access_ram())
146141      return sfx_ram[offset & 0xfffff];
147142   return 0xff;    // should be open bus...
148143}
149144
150145WRITE8_MEMBER( sns_rom_superfx_device::write_ram )
151146{
152   if (superfx_access_ram(m_superfx))
147   if (m_superfx->access_ram())
153148      sfx_ram[offset & 0xfffff] = data;
154149}
trunk/src/mess/machine/sns_sfx.h
r26752r26753
1919   virtual void device_reset();
2020   virtual machine_config_constructor device_mconfig_additions() const;
2121
22   required_device<device_t> m_superfx;
22   required_device<superfx_device> m_superfx;
2323
2424   // additional reading and writing
2525   virtual DECLARE_READ8_MEMBER(read_l);

Previous 199869 Revisions Next


© 1997-2024 The MAME Team