Previous 199869 Revisions Next

r21594 Tuesday 5th March, 2013 at 12:53:46 UTC by Miodrag Milanović
some snes modernization (nw)
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/drivers]snes.c

trunk/src/mess/drivers/snes.c
r21593r21594
4040
4141#define MAX_SNES_CART_SIZE 0x600000
4242
43class snes_console_state : public snes_state
44{
45public:
46   snes_console_state(const machine_config &mconfig, device_type type, const char *tag)
47      : snes_state(mconfig, type, tag)
48   { }   
49   
50   DECLARE_READ8_MEMBER( spc_ram_100_r );
51   DECLARE_WRITE8_MEMBER( spc_ram_100_w );
52   UINT8 st010_read_ram(UINT16 addr);
53   void st010_write_ram(UINT16 addr, UINT8 data);
54   DECLARE_READ8_MEMBER( snes_lo_r );
55   DECLARE_READ8_MEMBER( snes_hi_r );
56   DECLARE_WRITE8_MEMBER( snes_lo_w );
57   DECLARE_WRITE8_MEMBER( snes_hi_w );
58   DECLARE_READ8_MEMBER( superfx_r_bank1 );
59   DECLARE_READ8_MEMBER( superfx_r_bank2 );
60   DECLARE_READ8_MEMBER( superfx_r_bank3 );
61   DECLARE_WRITE8_MEMBER( superfx_w_bank3 );
62   CUSTOM_INPUT_MEMBER( snes_mouse_speed_input );
63   CUSTOM_INPUT_MEMBER( snes_superscope_offscreen_input );
64   TIMER_CALLBACK_MEMBER( lightgun_tick );
65   void snes_gun_latch( INT16 x, INT16 y );
66   void snes_input_read_joy( int port );
67   void snes_input_read_mouse( int port );
68   void snes_input_read_superscope( int port );
69   DECLARE_WRITE8_MEMBER(snes_input_read);
70   DECLARE_READ8_MEMBER(snes_oldjoy1_read);
71   DECLARE_READ8_MEMBER(snes_oldjoy2_read);   
72};
4373
4474/*************************************
4575 *
r21593r21594
4777 *
4878 *************************************/
4979
50static READ8_DEVICE_HANDLER( spc_ram_100_r )
80READ8_MEMBER(snes_console_state::spc_ram_100_r )
5181{
52   return spc_ram_r(device, space, offset + 0x100);
82   return spc_ram_r(machine().device("spc700"), space, offset + 0x100);
5383}
5484
55static WRITE8_DEVICE_HANDLER( spc_ram_100_w )
85WRITE8_MEMBER(snes_console_state::spc_ram_100_w )
5686{
57   spc_ram_w(device, space, offset + 0x100, data);
87   spc_ram_w(machine().device("spc700"), space, offset + 0x100, data);
5888}
5989
6090// DSP accessors
61#define dsp_get_sr() state->m_upd7725->snesdsp_read(false)
62#define dsp_get_dr() state->m_upd7725->snesdsp_read(true)
63#define dsp_set_sr(data) state->m_upd7725->snesdsp_write(false, data)
64#define dsp_set_dr(data) state->m_upd7725->snesdsp_write(true, data)
91#define dsp_get_sr() m_upd7725->snesdsp_read(false)
92#define dsp_get_dr() m_upd7725->snesdsp_read(true)
93#define dsp_set_sr(data) m_upd7725->snesdsp_write(false, data)
94#define dsp_set_dr(data) m_upd7725->snesdsp_write(true, data)
6595
66#define st010_get_sr() state->m_upd96050->snesdsp_read(false)
67#define st010_get_dr() state->m_upd96050->snesdsp_read(true)
68#define st010_set_sr(data) state->m_upd96050->snesdsp_write(false, data)
69#define st010_set_dr(data) state->m_upd96050->snesdsp_write(true, data)
96#define st010_get_sr() m_upd96050->snesdsp_read(false)
97#define st010_get_dr() m_upd96050->snesdsp_read(true)
98#define st010_set_sr(data) m_upd96050->snesdsp_write(false, data)
99#define st010_set_dr(data) m_upd96050->snesdsp_write(true, data)
70100
71101// ST-010 and ST-011 RAM interface
72UINT8 st010_read_ram(snes_state *state, UINT16 addr)
102UINT8 snes_console_state::st010_read_ram(UINT16 addr)
73103{
74   UINT16 temp = state->m_upd96050->dataram_r(addr/2);
104   UINT16 temp = m_upd96050->dataram_r(addr/2);
75105   UINT8 res;
76
106   
77107   if (addr & 1)
78108   {
79109      res = temp>>8;
r21593r21594
82112   {
83113      res = temp & 0xff;
84114   }
85
115   
86116   return res;
87117}
88118
89void st010_write_ram(snes_state *state, UINT16 addr, UINT8 data)
119void snes_console_state::st010_write_ram(UINT16 addr, UINT8 data)
90120{
91   UINT16 temp = state->m_upd96050->dataram_r(addr/2);
92
121   UINT16 temp = m_upd96050->dataram_r(addr/2);
122   
93123   if (addr & 1)
94124   {
95125      temp &= 0xff;
r21593r21594
100130      temp &= 0xff00;
101131      temp |= data;
102132   }
103
104   state->m_upd96050->dataram_w(addr/2, temp);
133   
134   m_upd96050->dataram_w(addr/2, temp);
105135}
106136
107137
108static READ8_HANDLER( snes_lo_r )
109{
110   snes_state *state = space.machine().driver_data<snes_state>();
138READ8_MEMBER( snes_console_state::snes_lo_r )
139{   
111140   UINT16 address = offset & 0xffff;
112141
113142   // take care of add-on chip access
114   if (state->m_has_addon_chip == HAS_OBC1
143   if (m_has_addon_chip == HAS_OBC1
115144      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
116145      return obc1_read(space, offset, mem_mask);
117   if (state->m_has_addon_chip == HAS_CX4
146   if (m_has_addon_chip == HAS_CX4
118147      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
119148      return CX4_read(address - 0x6000);
120   if (state->m_has_addon_chip == HAS_RTC
149   if (m_has_addon_chip == HAS_RTC
121150      && (offset < 0x400000 && (address == 0x2800 || address == 0x2801)))
122151      return srtc_read(space, offset);
123   if (state->m_has_addon_chip == HAS_ST010 || state->m_has_addon_chip == HAS_ST011)
152   if (m_has_addon_chip == HAS_ST010 || m_has_addon_chip == HAS_ST011)
124153   {
125154      if (offset >= 0x680000 && offset < 0x700000 && address < 0x1000)
126         return st010_read_ram(state, address);
155         return st010_read_ram(address);
127156      if (offset == 0x600000 || offset == 0x600001)
128157         return (offset & 1) ? st010_get_sr() : st010_get_dr();
129158   }
130   if (state->m_cart[0].mode == SNES_MODE_21 && state->m_has_addon_chip == HAS_DSP1
159   if (m_cart[0].mode == SNES_MODE_21 && m_has_addon_chip == HAS_DSP1
131160      && (offset < 0x200000 && address >= 0x6000 && address < 0x8000))
132161      return (address < 0x7000) ? dsp_get_dr() : dsp_get_sr();
133   if (state->m_cart[0].mode == SNES_MODE_20 && state->m_has_addon_chip == HAS_DSP1)
162   if (m_cart[0].mode == SNES_MODE_20 && m_has_addon_chip == HAS_DSP1)
134163   {
135164      if (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000)
136165         return (address < 0xc000) ? dsp_get_dr() : dsp_get_sr();
137166      if (offset >= 0x600000 && offset < 0x700000 && (offset & 0x8000) == 0x0000)
138167         return (address < 0x4000) ? dsp_get_dr() : dsp_get_sr();
139   }
140   if ((state->m_has_addon_chip == HAS_DSP2 || state->m_has_addon_chip == HAS_DSP3)
168   }   
169   if ((m_has_addon_chip == HAS_DSP2 || m_has_addon_chip == HAS_DSP3)
141170      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
142171      return (address < 0xc000) ? dsp_get_dr() : dsp_get_sr();
143   if (state->m_has_addon_chip == HAS_DSP4
172   if (m_has_addon_chip == HAS_DSP4
144173      && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
145174      return (address < 0xc000) ? dsp_get_dr() : dsp_get_sr();
146   if (state->m_has_addon_chip == HAS_SDD1
175   if (m_has_addon_chip == HAS_SDD1
147176      && (offset < 0x400000 && address >= 0x4800 && address < 0x4808))
148177      return sdd1_mmio_read(space, (UINT32)address);
149   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC)
178   if ((m_has_addon_chip == HAS_SPC7110 || m_has_addon_chip == HAS_SPC7110_RTC)
150179      && offset < 0x400000)
151   {
152      UINT16 limit = (state->m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
180   {   
181      UINT16 limit = (m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
153182      if (address >= 0x4800 && address <= limit)
154183         return spc7110_mmio_read(space, (UINT32)address);
155184      if (offset < 0x10000 && address >= 0x6000 && address < 0x8000)
r21593r21594
157186      if (offset >= 0x300000 && offset < 0x310000 && address >= 0x6000 && address < 0x8000)
158187         return snes_ram[0x306000 + (address & 0x1fff)];
159188   }
160   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC)
189   if ((m_has_addon_chip == HAS_SPC7110 || m_has_addon_chip == HAS_SPC7110_RTC)
161190      && offset >= 0x500000 && offset < 0x510000)
162191      return spc7110_mmio_read(space, 0x4800);
163   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
192   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL
164193      && offset < 0x400000)
165   {
194   {   
166195      if (address >= 0x3000 && address < 0x3300)
167         return superfx_mmio_read(state->m_superfx, address);
168      if (address >= 0x6000 && address < 0x8000)   // here it should be snes_ram[0xe00000+...] but there are mirroring issues
169         return superfx_access_ram(state->m_superfx) ? snes_ram[0xf00000 + (offset & 0x1fff)] : snes_open_bus_r(space, 0);
196         return superfx_mmio_read(m_superfx, address);
197      if (address >= 0x6000 && address < 0x8000)    // here it should be snes_ram[0xe00000+...] but there are mirroring issues
198         return superfx_access_ram(m_superfx) ? snes_ram[0xf00000 + (offset & 0x1fff)] : snes_open_bus_r(space, 0);
170199   }
171   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
200   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL
172201      && offset >= 0x400000 && offset < 0x600000)
173202   {
174      if (superfx_access_rom(state->m_superfx))
203      if (superfx_access_rom(m_superfx))
175204         return snes_ram[offset];
176205      else
177206      {
r21593r21594
182211         return sfx_data[offset & 0x0f];
183212      }
184213   }
185   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
214   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL
186215      && offset >= 0x600000)
187      return superfx_access_ram(state->m_superfx) ? snes_ram[0x800000 + offset] : snes_open_bus_r(space, 0);
188
216      return superfx_access_ram(m_superfx) ? snes_ram[0x800000 + offset] : snes_open_bus_r(space, 0);
217   
189218   // base cart access
190219   if (offset < 0x300000)
191220      return snes_r_bank1(space, offset, 0xff);
r21593r21594
197226      return snes_r_bank4(space, offset - 0x600000, 0xff);
198227   else
199228      return snes_r_bank5(space, offset - 0x700000, 0xff);
200}
229}   
201230
202static READ8_HANDLER( snes_hi_r )
231READ8_MEMBER( snes_console_state::snes_hi_r )
203232{
204   snes_state *state = space.machine().driver_data<snes_state>();
205233   UINT16 address = offset & 0xffff;
206
234   
207235   // take care of add-on chip access
208   if (state->m_has_addon_chip == HAS_OBC1
236   if (m_has_addon_chip == HAS_OBC1
209237      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
210238      return obc1_read(space, offset, mem_mask);
211   if (state->m_has_addon_chip == HAS_CX4
239   if (m_has_addon_chip == HAS_CX4
212240      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
213241      return CX4_read(address - 0x6000);
214   if (state->m_has_addon_chip == HAS_RTC
242   if (m_has_addon_chip == HAS_RTC
215243      && (offset < 0x400000 && (address == 0x2800 || address == 0x2801)))
216244      return srtc_read(space, offset);
217   if (state->m_has_addon_chip == HAS_ST010 || state->m_has_addon_chip == HAS_ST011)
245   if (m_has_addon_chip == HAS_ST010 || m_has_addon_chip == HAS_ST011)
218246   {
219247      if (offset >= 0x680000 && offset < 0x700000 && address < 0x1000)
220         return st010_read_ram(state, address);
248         return st010_read_ram(address);
221249      if (offset == 0x600000 || offset == 0x600001)
222250         return (offset & 1) ? st010_get_sr() : st010_get_dr();
223251   }
224   if (state->m_cart[0].mode == SNES_MODE_21 && state->m_has_addon_chip == HAS_DSP1
252   if (m_cart[0].mode == SNES_MODE_21 && m_has_addon_chip == HAS_DSP1
225253      && (offset < 0x200000 && address >= 0x6000 && address < 0x8000))
226254      return (address < 0x7000) ? dsp_get_dr() : dsp_get_sr();
227   if (state->m_cart[0].mode == SNES_MODE_20 && state->m_has_addon_chip == HAS_DSP1)
255   if (m_cart[0].mode == SNES_MODE_20 && m_has_addon_chip == HAS_DSP1)
228256   {
229257      if (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000)
230258         return (address < 0xc000) ? dsp_get_dr() : dsp_get_sr();
231259      if (offset >= 0x600000 && offset < 0x700000 && (offset & 0x8000) == 0x0000)
232260         return (address < 0x4000) ? dsp_get_dr() : dsp_get_sr();
233261   }
234   if ((state->m_has_addon_chip == HAS_DSP2 || state->m_has_addon_chip == HAS_DSP3)
262   if ((m_has_addon_chip == HAS_DSP2 || m_has_addon_chip == HAS_DSP3)
235263      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
236264      return (address < 0xc000) ? dsp_get_dr() : dsp_get_sr();
237   if (state->m_has_addon_chip == HAS_DSP4
265   if (m_has_addon_chip == HAS_DSP4
238266      && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
239267      return (address < 0xc000) ? dsp_get_dr() : dsp_get_sr();
240   if (state->m_has_addon_chip == HAS_SDD1
268   if (m_has_addon_chip == HAS_SDD1
241269      && (offset < 0x400000 && address >= 0x4800 && address < 0x4808))
242270      return sdd1_mmio_read(space, (UINT32)address);
243   if (state->m_has_addon_chip == HAS_SDD1 && offset >= 0x400000)
271   if (m_has_addon_chip == HAS_SDD1 && offset >= 0x400000)
244272      return sdd1_read(space.machine(), offset - 0x400000);
245   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC)
273   if ((m_has_addon_chip == HAS_SPC7110 || m_has_addon_chip == HAS_SPC7110_RTC)
246274      && offset < 0x400000)
247   {
248      UINT16 limit = (state->m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
275   {   
276      UINT16 limit = (m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
249277      if (address >= 0x4800 && address <= limit)
250278         return spc7110_mmio_read(space, (UINT32)address);
251279      if (offset < 0x10000 && address >= 0x6000 && address < 0x8000)
r21593r21594
253281      if (offset >= 0x300000 && offset < 0x310000 && address >= 0x6000 && address < 0x8000)
254282         return snes_ram[0x306000 + (address & 0x1fff)];
255283   }
256   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC)
284   if ((m_has_addon_chip == HAS_SPC7110 || m_has_addon_chip == HAS_SPC7110_RTC)
257285      && offset >= 0x500000)
258286      return spc7110_bank7_read(space, offset - 0x400000);
259   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
260      return space.read_byte(offset);     // [80-ff] same as [00-7f]
261
287   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL)
288      return space.read_byte(offset);      // [80-ff] same as [00-7f]
289   
262290   // base cart access
263291   if (offset < 0x400000)
264292      return snes_r_bank6(space, offset, 0xff);
265293   else
266294      return snes_r_bank7(space, offset - 0x400000, 0xff);
267}
295}   
268296
269static WRITE8_HANDLER( snes_lo_w )
297WRITE8_MEMBER( snes_console_state::snes_lo_w )
270298{
271   snes_state *state = space.machine().driver_data<snes_state>();
272299   UINT16 address = offset & 0xffff;
273
300   
274301   // take care of add-on chip access
275   if (state->m_has_addon_chip == HAS_OBC1
302   if (m_has_addon_chip == HAS_OBC1
276303      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
277   {   obc1_write(space, offset, data, mem_mask);  return; }
278   if (state->m_has_addon_chip == HAS_CX4
304   {   obc1_write(space, offset, data, mem_mask);   return;   }
305   if (m_has_addon_chip == HAS_CX4
279306      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
280   {   CX4_write(space.machine(), address - 0x6000, data); return; }
281   if (state->m_has_addon_chip == HAS_RTC
307   {   CX4_write(space.machine(), address - 0x6000, data);   return;   }
308   if (m_has_addon_chip == HAS_RTC
282309      && (offset < 0x400000 && (address == 0x2800 || address == 0x2801)))
283   {   srtc_write(space.machine(), offset, data);  return; }
284   if (state->m_has_addon_chip == HAS_ST010 || state->m_has_addon_chip == HAS_ST011)
310   {   srtc_write(space.machine(), offset, data);   return;   }
311   if (m_has_addon_chip == HAS_ST010 || m_has_addon_chip == HAS_ST011)
285312   {
286313      if (offset >= 0x680000 && offset < 0x700000 && address < 0x1000)
287      {   st010_write_ram(state, address, data);  return; }
314      {   st010_write_ram(address, data);   return;   }
288315      if (offset == 0x600000)
289      {   st010_set_dr(data); return; }
316      {   st010_set_dr(data);   return;   }
290317      if (offset == 0x600001)
291      {   st010_set_sr(data); return; }
318      {   st010_set_sr(data);   return;   }
292319   }
293   if (state->m_cart[0].mode == SNES_MODE_21 && state->m_has_addon_chip == HAS_DSP1
320   if (m_cart[0].mode == SNES_MODE_21 && m_has_addon_chip == HAS_DSP1
294321      && (offset < 0x200000 && address >= 0x6000 && address < 0x8000))
295   {   dsp_set_dr(data);   return; }
296   if (state->m_cart[0].mode == SNES_MODE_20 && state->m_has_addon_chip == HAS_DSP1)
322   {   dsp_set_dr(data);   return;   }
323   if (m_cart[0].mode == SNES_MODE_20 && m_has_addon_chip == HAS_DSP1)
297324   {
298325      if (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000)
299      {   dsp_set_dr(data);   return; }
326      {   dsp_set_dr(data);   return;   }
300327      if (offset >= 0x600000 && offset < 0x700000 && (offset & 0x8000) == 0x0000)
301      {   dsp_set_dr(data);   return; }
328      {   dsp_set_dr(data);   return;   }
302329   }
303   if ((state->m_has_addon_chip == HAS_DSP2 || state->m_has_addon_chip == HAS_DSP3)
330   if ((m_has_addon_chip == HAS_DSP2 || m_has_addon_chip == HAS_DSP3)
304331      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
305332   {
306333      if (address < 0xc000)
307      {   dsp_set_dr(data);   return; }
334      {   dsp_set_dr(data);   return;   }
308335      else
309      {   dsp_set_sr(data);   return; }
336      {   dsp_set_sr(data);   return;   }
310337   }
311   if (state->m_has_addon_chip == HAS_DSP4
338   if (m_has_addon_chip == HAS_DSP4
312339      && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
313340   {
314341      if (address < 0xc000)
315      {   dsp_set_dr(data);   return; }
342      {   dsp_set_dr(data);   return;   }
316343      else
317      {   dsp_set_sr(data);   return; }
344      {   dsp_set_sr(data);   return;   }
318345   }
319   if (state->m_has_addon_chip == HAS_SDD1 && offset < 0x400000)
346   if (m_has_addon_chip == HAS_SDD1 && offset < 0x400000)
320347   {
321348      if ((address >= 0x4300 && address < 0x4380) || (address >= 0x4800 && address < 0x4808))
322349      {
r21593r21594
324351            // here we don't return, but we let the w_io happen...
325352      }
326353   }
327   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC) && offset < 0x400000)
328   {
329      UINT16 limit = (state->m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
354   if ((m_has_addon_chip == HAS_SPC7110 || m_has_addon_chip == HAS_SPC7110_RTC) && offset < 0x400000)
355   {   
356      UINT16 limit = (m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
330357      if (address >= 0x4800 && address <= limit)
331      {   spc7110_mmio_write(space.machine(), (UINT32)address, data); return; }
358      {   spc7110_mmio_write(space.machine(), (UINT32)address, data);   return;   }
332359      if (offset < 0x10000 && address >= 0x6000 && address < 0x8000)
333      {   snes_ram[0x306000 + (address & 0x1fff)] = data; return; }
360      {   snes_ram[0x306000 + (address & 0x1fff)] = data;   return;   }
334361      if (offset >= 0x300000 && offset < 0x310000 && address >= 0x6000 && address < 0x8000)
335      {   snes_ram[0x306000 + (address & 0x1fff)] = data; return; }
362      {   snes_ram[0x306000 + (address & 0x1fff)] = data;   return;   }
336363   }
337   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
338         && offset < 0x400000)
339   {
364   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL
365       && offset < 0x400000)
366   {   
340367      if (address >= 0x3000 && address < 0x3300)
341      {   superfx_mmio_write(state->m_superfx, address, data);    return; }
342      if (address >= 0x6000 && address < 0x8000)   // here it should be snes_ram[0xe00000+...] but there are mirroring issues
343      {   snes_ram[0xf00000 + (offset & 0x1fff)] = data;  return; }
368      {   superfx_mmio_write(m_superfx, address, data);   return;   }
369      if (address >= 0x6000 && address < 0x8000)    // here it should be snes_ram[0xe00000+...] but there are mirroring issues
370      {   snes_ram[0xf00000 + (offset & 0x1fff)] = data;   return;   }
344371   }
345   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
372   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL
346373      && offset >= 0x600000)
347   {   snes_ram[0x800000 + offset] = data; return; }
348
374   {   snes_ram[0x800000 + offset] = data;   return;   }
375   
349376   // base cart access
350377   if (offset < 0x300000)
351378      snes_w_bank1(space, offset, data, 0xff);
r21593r21594
357384      snes_w_bank4(space, offset - 0x600000, data, 0xff);
358385   else
359386      snes_w_bank5(space, offset - 0x700000, data, 0xff);
360}
387}   
361388
362static WRITE8_HANDLER( snes_hi_w )
389WRITE8_MEMBER( snes_console_state::snes_hi_w )
363390{
364   snes_state *state = space.machine().driver_data<snes_state>();
365391   UINT16 address = offset & 0xffff;
366
392   
367393   // take care of add-on chip access
368   if (state->m_has_addon_chip == HAS_OBC1
394   if (m_has_addon_chip == HAS_OBC1
369395      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
370   {   obc1_write(space, offset, data, mem_mask);  return; }
371   if (state->m_has_addon_chip == HAS_CX4
396   {   obc1_write(space, offset, data, mem_mask);   return;   }
397   if (m_has_addon_chip == HAS_CX4
372398      && (offset < 0x400000 && address >= 0x6000 && address < 0x8000))
373   {   CX4_write(space.machine(), address - 0x6000, data); return; }
374   if (state->m_has_addon_chip == HAS_RTC
399   {   CX4_write(space.machine(), address - 0x6000, data);   return;   }
400   if (m_has_addon_chip == HAS_RTC
375401      && (offset < 0x400000 && (address == 0x2800 || address == 0x2801)))
376   {   srtc_write(space.machine(), offset, data);  return; }
377   if (state->m_has_addon_chip == HAS_ST010 || state->m_has_addon_chip == HAS_ST011)
402   {   srtc_write(space.machine(), offset, data);   return;   }
403   if (m_has_addon_chip == HAS_ST010 || m_has_addon_chip == HAS_ST011)
378404   {
379405      if (offset >= 0x680000 && offset < 0x700000 && address < 0x1000)
380      {   st010_write_ram(state, address, data);  return; }
406      {   st010_write_ram(address, data);   return;   }
381407      if (offset == 0x600000)
382      {   st010_set_dr(data); return; }
408      {   st010_set_dr(data);   return;   }
383409      if (offset == 0x600001)
384      {   st010_set_sr(data); return; }
410      {   st010_set_sr(data);   return;   }
385411   }
386   if (state->m_cart[0].mode == SNES_MODE_21 && state->m_has_addon_chip == HAS_DSP1
412   if (m_cart[0].mode == SNES_MODE_21 && m_has_addon_chip == HAS_DSP1
387413      && (offset < 0x200000 && address >= 0x6000 && address < 0x8000))
388   {   dsp_set_dr(data);   return; }
389   if (state->m_cart[0].mode == SNES_MODE_20 && state->m_has_addon_chip == HAS_DSP1)
414   {   dsp_set_dr(data);   return;   }
415   if (m_cart[0].mode == SNES_MODE_20 && m_has_addon_chip == HAS_DSP1)
390416   {
391417      if (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000)
392      {   dsp_set_dr(data);   return; }
418      {   dsp_set_dr(data);   return;   }
393419      if (offset >= 0x600000 && offset < 0x700000 && (offset & 0x8000) == 0x0000)
394      {   dsp_set_dr(data);   return; }
395   }
396   if ((state->m_has_addon_chip == HAS_DSP2 || state->m_has_addon_chip == HAS_DSP3)
420      {   dsp_set_dr(data);   return;   }
421   }   
422   if ((m_has_addon_chip == HAS_DSP2 || m_has_addon_chip == HAS_DSP3)
397423      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
398424   {
399425      if (address < 0xc000)
400      {   dsp_set_dr(data);   return; }
426      {   dsp_set_dr(data);   return;   }
401427      else
402      {   dsp_set_sr(data);   return; }
428      {   dsp_set_sr(data);   return;   }
403429   }
404   if (state->m_has_addon_chip == HAS_DSP4
430   if (m_has_addon_chip == HAS_DSP4
405431      && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
406432   {
407433      if (address < 0xc000)
408      {   dsp_set_dr(data);   return; }
434      {   dsp_set_dr(data);   return;   }
409435      else
410      {   dsp_set_sr(data);   return; }
436      {   dsp_set_sr(data);   return;   }
411437   }
412   if (state->m_has_addon_chip == HAS_SDD1 && offset < 0x400000)
438   if (m_has_addon_chip == HAS_SDD1 && offset < 0x400000)
413439   {
414440      if ((address >= 0x4300 && address < 0x4380) || (address >= 0x4800 && address < 0x4808))
415441      {
r21593r21594
417443         // here we don't return, but we let the w_io happen...
418444      }
419445   }
420   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC) && offset < 0x400000)
421   {
422      UINT16 limit = (state->m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
446   if ((m_has_addon_chip == HAS_SPC7110 || m_has_addon_chip == HAS_SPC7110_RTC) && offset < 0x400000)
447   {   
448      UINT16 limit = (m_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
423449      if (address >= 0x4800 && address <= limit)
424      {   spc7110_mmio_write(space.machine(), (UINT32)address, data); return; }
450      {   spc7110_mmio_write(space.machine(), (UINT32)address, data);   return;   }
425451      if (offset < 0x10000 && address >= 0x6000 && address < 0x8000)
426      {   snes_ram[0x306000 + (address & 0x1fff)] = data; return; }
452      {   snes_ram[0x306000 + (address & 0x1fff)] = data;   return;   }
427453      if (offset >= 0x300000 && offset < 0x310000 && address >= 0x6000 && address < 0x8000)
428      {   snes_ram[0x306000 + (address & 0x1fff)] = data; return; }
454      {   snes_ram[0x306000 + (address & 0x1fff)] = data;   return;   }
429455   }
430   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
431   {   space.write_byte(offset, data); return; }       // [80-ff] same as [00-7f]
432
456   if (m_has_addon_chip == HAS_SUPERFX && m_superfx != NULL)
457   {   space.write_byte(offset, data);   return;   }      // [80-ff] same as [00-7f]
458   
433459   // base cart access
434460   if (offset < 0x400000)
435461      snes_w_bank6(space, offset, data, 0xff);
436462   else
437463      snes_w_bank7(space, offset, data - 0x400000, 0xff);
438}
464}   
439465
440static READ8_HANDLER( superfx_r_bank1 )
466READ8_MEMBER( snes_console_state::superfx_r_bank1 )
441467{
442468   return snes_ram[offset | 0x8000];
443469}
444470
445static READ8_HANDLER( superfx_r_bank2 )
471READ8_MEMBER( snes_console_state::superfx_r_bank2 )
446472{
447473   return snes_ram[0x400000 + offset];
448474}
449475
450static READ8_HANDLER( superfx_r_bank3 )
476READ8_MEMBER( snes_console_state::superfx_r_bank3 )
451477{
452478   /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES
453479    has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror
r21593r21594
456482   return snes_ram[0xe00000 + offset];
457483}
458484
459static WRITE8_HANDLER( superfx_w_bank3 )
485WRITE8_MEMBER( snes_console_state::superfx_w_bank3 )
460486{
461487   /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES
462488    has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror
r21593r21594
471497 *
472498 *************************************/
473499
474static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8, snes_state )
475   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_lo_r, snes_lo_w)
500static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8, snes_console_state )
501   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE(snes_lo_r, snes_lo_w)
476502   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
477   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snes_hi_r, snes_hi_w)
503   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_hi_r, snes_hi_w)
478504ADDRESS_MAP_END
479505
480static ADDRESS_MAP_START( superfx_map, AS_PROGRAM, 8, snes_state )
481   AM_RANGE(0x000000, 0x3fffff) AM_READ_LEGACY(superfx_r_bank1)
482   AM_RANGE(0x400000, 0x5fffff) AM_READ_LEGACY(superfx_r_bank2)
483   AM_RANGE(0x600000, 0x7dffff) AM_READWRITE_LEGACY(superfx_r_bank3, superfx_w_bank3)
484   AM_RANGE(0x800000, 0xbfffff) AM_READ_LEGACY(superfx_r_bank1)
485   AM_RANGE(0xc00000, 0xdfffff) AM_READ_LEGACY(superfx_r_bank2)
486   AM_RANGE(0xe00000, 0xffffff) AM_READWRITE_LEGACY(superfx_r_bank3, superfx_w_bank3)
506static ADDRESS_MAP_START( superfx_map, AS_PROGRAM, 8, snes_console_state )
507   AM_RANGE(0x000000, 0x3fffff) AM_READ(superfx_r_bank1)
508   AM_RANGE(0x400000, 0x5fffff) AM_READ(superfx_r_bank2)
509   AM_RANGE(0x600000, 0x7dffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
510   AM_RANGE(0x800000, 0xbfffff) AM_READ(superfx_r_bank1)
511   AM_RANGE(0xc00000, 0xdfffff) AM_READ(superfx_r_bank2)
512   AM_RANGE(0xe00000, 0xffffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
487513ADDRESS_MAP_END
488514
489static ADDRESS_MAP_START( spc_map, AS_PROGRAM, 8, snes_state )
515static ADDRESS_MAP_START( spc_map, AS_PROGRAM, 8, snes_console_state )
490516   AM_RANGE(0x0000, 0x00ef) AM_DEVREADWRITE_LEGACY("spc700", spc_ram_r, spc_ram_w) /* lower 32k ram */
491517   AM_RANGE(0x00f0, 0x00ff) AM_DEVREADWRITE_LEGACY("spc700", spc_io_r, spc_io_w)   /* spc io */
492   AM_RANGE(0x0100, 0xffff) AM_DEVREADWRITE_LEGACY("spc700", spc_ram_100_r, spc_ram_100_w)
518   AM_RANGE(0x0100, 0xffff) AM_READWRITE(spc_ram_100_r, spc_ram_100_w)
493519ADDRESS_MAP_END
494520
495static ADDRESS_MAP_START( dsp_prg_map, AS_PROGRAM, 32, snes_state )
521static ADDRESS_MAP_START( dsp_prg_map, AS_PROGRAM, 32, snes_console_state )
496522   AM_RANGE(0x0000, 0x07ff) AM_ROM AM_REGION("dspprg", 0)
497523ADDRESS_MAP_END
498524
499static ADDRESS_MAP_START( dsp_data_map, AS_DATA, 16, snes_state )
525static ADDRESS_MAP_START( dsp_data_map, AS_DATA, 16, snes_console_state )
500526   AM_RANGE(0x0000, 0x03ff) AM_ROM AM_REGION("dspdata", 0)
501527ADDRESS_MAP_END
502528
503static ADDRESS_MAP_START( setadsp_prg_map, AS_PROGRAM, 32, snes_state )
529static ADDRESS_MAP_START( setadsp_prg_map, AS_PROGRAM, 32, snes_console_state )
504530   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_REGION("dspprg", 0)
505531ADDRESS_MAP_END
506532
507static ADDRESS_MAP_START( setadsp_data_map, AS_DATA, 16, snes_state )
533static ADDRESS_MAP_START( setadsp_data_map, AS_DATA, 16, snes_console_state )
508534   AM_RANGE(0x0000, 0x07ff) AM_ROM AM_REGION("dspdata", 0)
509535ADDRESS_MAP_END
510536
r21593r21594
514540 *
515541 *************************************/
516542
517static CUSTOM_INPUT( snes_mouse_speed_input )
543CUSTOM_INPUT_MEMBER( snes_console_state::snes_mouse_speed_input )
518544{
519   snes_state *state = field.machine().driver_data<snes_state>();
520545   int port = (FPTR)param;
521546
522   if (state->m_oldjoy1_latch & 0x1)
547   if (m_oldjoy1_latch & 0x1)
523548   {
524      state->m_mouse[port].speed++;
525      if ((state->m_mouse[port].speed & 0x03) == 0x03)
526         state->m_mouse[port].speed = 0;
549      m_mouse[port].speed++;
550      if ((m_mouse[port].speed & 0x03) == 0x03)
551         m_mouse[port].speed = 0;
527552   }
528553
529   return state->m_mouse[port].speed;
554   return m_mouse[port].speed;
530555}
531556
532static CUSTOM_INPUT( snes_superscope_offscreen_input )
557CUSTOM_INPUT_MEMBER( snes_console_state::snes_superscope_offscreen_input )
533558{
534   snes_state *state = field.machine().driver_data<snes_state>();
535559   int port = (FPTR)param;
536560   static const char *const portnames[2][3] =
537561         {
r21593r21594
539563            { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" },
540564         };
541565
542   INT16 x = field.machine().root_device().ioport(portnames[port][1])->read();
543   INT16 y = field.machine().root_device().ioport(portnames[port][2])->read();
566   INT16 x = ioport(portnames[port][1])->read();
567   INT16 y = ioport(portnames[port][2])->read();
544568
545569   /* these are the theoretical boundaries, but we currently are always onscreen... */
546   if (x < 0 || x >= SNES_SCR_WIDTH || y < 0 || y >= state->m_ppu.m_beam.last_visible_line)
547      state->m_scope[port].offscreen = 1;
570   if (x < 0 || x >= SNES_SCR_WIDTH || y < 0 || y >= m_ppu.m_beam.last_visible_line)
571      m_scope[port].offscreen = 1;
548572   else
549      state->m_scope[port].offscreen = 0;
573      m_scope[port].offscreen = 0;
550574
551   return state->m_scope[port].offscreen;
575   return m_scope[port].offscreen;
552576}
553577
554static TIMER_CALLBACK( lightgun_tick )
578TIMER_CALLBACK_MEMBER( snes_console_state::lightgun_tick )
555579{
556   if ((machine.root_device().ioport("CTRLSEL")->read() & 0x0f) == 0x03 || (machine.root_device().ioport("CTRLSEL")->read() & 0x0f) == 0x04)   {
580   if ((ioport("CTRLSEL")->read() & 0x0f) == 0x03 || (ioport("CTRLSEL")->read() & 0x0f) == 0x04)   {
557581      /* enable lightpen crosshair */
558      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL);
582      crosshair_set_screen(machine(), 0, CROSSHAIR_SCREEN_ALL);
559583   }
560584   else
561585   {
562586      /* disable lightpen crosshair */
563      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE);
587      crosshair_set_screen(machine(), 0, CROSSHAIR_SCREEN_NONE);
564588   }
565589
566   if ((machine.root_device().ioport("CTRLSEL")->read() & 0xf0) == 0x30 || (machine.root_device().ioport("CTRLSEL")->read() & 0xf0) == 0x40)
590   if ((ioport("CTRLSEL")->read() & 0xf0) == 0x30 || (ioport("CTRLSEL")->read() & 0xf0) == 0x40)
567591   {
568592      /* enable lightpen crosshair */
569      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL);
593      crosshair_set_screen(machine(), 1, CROSSHAIR_SCREEN_ALL);
570594   }
571595   else
572596   {
573597      /* disable lightpen crosshair */
574      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE);
598      crosshair_set_screen(machine(), 1, CROSSHAIR_SCREEN_NONE);
575599   }
576600}
577601
r21593r21594
626650   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
627651   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
628652   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
629   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)0)
653   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM_MEMBER(DEVICE_SELF, snes_console_state, snes_mouse_speed_input, (void *)0)
630654   /* bits 6,7 = mouse buttons */
631655   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Mouse Button Left") PORT_PLAYER(1) PORT_CONDITION("CTRLSEL", 0x0f, EQUALS, 0x02)
632656   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Mouse Button Right") PORT_PLAYER(1) PORT_CONDITION("CTRLSEL", 0x0f, EQUALS, 0x02)
r21593r21594
644668   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
645669   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
646670   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
647   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)1)
671   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM_MEMBER(DEVICE_SELF, snes_console_state, snes_mouse_speed_input, (void *)1)
648672   /* bits 6,7 = mouse buttons */
649673   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Mouse Button Left") PORT_PLAYER(2) PORT_CONDITION("CTRLSEL", 0xf0, EQUALS, 0x20)
650674   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Mouse Button Right") PORT_PLAYER(2) PORT_CONDITION("CTRLSEL", 0xf0, EQUALS, 0x20)
r21593r21594
659683static INPUT_PORTS_START( snes_superscope )
660684   PORT_START("SUPERSCOPE1")
661685   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )    // Noise
662   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)0)
686   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM_MEMBER(DEVICE_SELF, snes_console_state, snes_superscope_offscreen_input, (void *)0)
663687   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
664688   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
665689   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port1 Superscope Pause") PORT_PLAYER(1) PORT_CONDITION("CTRLSEL", 0x0f, EQUALS, 0x03)
r21593r21594
675699
676700   PORT_START("SUPERSCOPE2")
677701   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )    // Noise
678   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)1)
702   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM_MEMBER(DEVICE_SELF, snes_console_state, snes_superscope_offscreen_input, (void *)1)
679703   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
680704   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
681705   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port2 Superscope Pause") PORT_PLAYER(2) PORT_CONDITION("CTRLSEL", 0xf0, EQUALS, 0x30)
r21593r21594
776800 *
777801 *************************************/
778802
779static void snes_gun_latch( running_machine &machine, INT16 x, INT16 y )
803void snes_console_state::snes_gun_latch( INT16 x, INT16 y )
780804{
781   snes_state *state = machine.driver_data<snes_state>();
782805   /* these are the theoretical boundaries */
783806   if (x < 0)
784807      x = 0;
r21593r21594
787810
788811   if (y < 0)
789812      y = 0;
790   if (y > (state->m_ppu.m_beam.last_visible_line - 1))
791      y = state->m_ppu.m_beam.last_visible_line - 1;
813   if (y > (m_ppu.m_beam.last_visible_line - 1))
814      y = m_ppu.m_beam.last_visible_line - 1;
792815
793   state->m_ppu.m_beam.latch_horz = x;
794   state->m_ppu.m_beam.latch_vert = y;
795   state->m_ppu.m_stat78 |= 0x40;
816   m_ppu.m_beam.latch_horz = x;
817   m_ppu.m_beam.latch_vert = y;
818   m_ppu.m_stat78 |= 0x40;
796819}
797820
798static void snes_input_read_joy( running_machine &machine, int port )
821void snes_console_state::snes_input_read_joy( int port )
799822{
800   snes_state *state = machine.driver_data<snes_state>();
801823   static const char *const portnames[2][4] =
802824         {
803825            { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" },
804826            { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" },
805827         };
806828
807   state->m_data1[port] = machine.root_device().ioport(portnames[port][0])->read() | (machine.root_device().ioport(portnames[port][1])->read() << 8);
808   state->m_data2[port] = machine.root_device().ioport(portnames[port][2])->read() | (machine.root_device().ioport(portnames[port][3])->read() << 8);
829   m_data1[port] = ioport(portnames[port][0])->read() | (ioport(portnames[port][1])->read() << 8);
830   m_data2[port] = ioport(portnames[port][2])->read() | (ioport(portnames[port][3])->read() << 8);
809831
810832   // avoid sending signals that could crash games
811833   // if left, no right
812   if (state->m_data1[port] & 0x200)
813      state->m_data1[port] &= ~0x100;
834   if (m_data1[port] & 0x200)
835      m_data1[port] &= ~0x100;
814836   // if up, no down
815   if (state->m_data1[port] & 0x800)
816      state->m_data1[port] &= ~0x400;
837   if (m_data1[port] & 0x800)
838      m_data1[port] &= ~0x400;
817839
818   state->m_joypad[port].buttons = state->m_data1[port];
840   m_joypad[port].buttons = m_data1[port];
819841}
820842
821static void snes_input_read_mouse( running_machine &machine, int port )
843void snes_console_state::snes_input_read_mouse( int port )
822844{
823   snes_state *state = machine.driver_data<snes_state>();
824845   INT16 var;
825846   static const char *const portnames[2][3] =
826847         {
r21593r21594
828849            { "MOUSE2", "MOUSE2_X", "MOUSE2_Y" },
829850         };
830851
831   state->m_mouse[port].buttons = machine.root_device().ioport(portnames[port][0])->read();
832   state->m_mouse[port].x = machine.root_device().ioport(portnames[port][1])->read();
833   state->m_mouse[port].y = machine.root_device().ioport(portnames[port][2])->read();
834   var = state->m_mouse[port].x - state->m_mouse[port].oldx;
852   m_mouse[port].buttons = ioport(portnames[port][0])->read();
853   m_mouse[port].x = ioport(portnames[port][1])->read();
854   m_mouse[port].y = ioport(portnames[port][2])->read();
855   var = m_mouse[port].x - m_mouse[port].oldx;
835856
836857   if (var < -127)
837858   {
838      state->m_mouse[port].deltax = 0xff;
839      state->m_mouse[port].oldx -= 127;
859      m_mouse[port].deltax = 0xff;
860      m_mouse[port].oldx -= 127;
840861   }
841862   else if (var < 0)
842863   {
843      state->m_mouse[port].deltax = 0x80 | (-var);
844      state->m_mouse[port].oldx = state->m_mouse[port].x;
864      m_mouse[port].deltax = 0x80 | (-var);
865      m_mouse[port].oldx = m_mouse[port].x;
845866   }
846867   else if (var > 127)
847868   {
848      state->m_mouse[port].deltax = 0x7f;
849      state->m_mouse[port].oldx += 127;
869      m_mouse[port].deltax = 0x7f;
870      m_mouse[port].oldx += 127;
850871   }
851872   else
852873   {
853      state->m_mouse[port].deltax = var & 0xff;
854      state->m_mouse[port].oldx = state->m_mouse[port].x;
874      m_mouse[port].deltax = var & 0xff;
875      m_mouse[port].oldx = m_mouse[port].x;
855876   }
856877
857   var = state->m_mouse[port].y - state->m_mouse[port].oldy;
878   var = m_mouse[port].y - m_mouse[port].oldy;
858879
859880   if (var < -127)
860881   {
861      state->m_mouse[port].deltay = 0xff;
862      state->m_mouse[port].oldy -= 127;
882      m_mouse[port].deltay = 0xff;
883      m_mouse[port].oldy -= 127;
863884   }
864885   else if (var < 0)
865886   {
866      state->m_mouse[port].deltay = 0x80 | (-var);
867      state->m_mouse[port].oldy = state->m_mouse[port].y;
887      m_mouse[port].deltay = 0x80 | (-var);
888      m_mouse[port].oldy = m_mouse[port].y;
868889   }
869890   else if (var > 127)
870891   {
871      state->m_mouse[port].deltay = 0x7f;
872      state->m_mouse[port].oldy += 127;
892      m_mouse[port].deltay = 0x7f;
893      m_mouse[port].oldy += 127;
873894   }
874895   else
875896   {
876      state->m_mouse[port].deltay = var & 0xff;
877      state->m_mouse[port].oldy = state->m_mouse[port].y;
897      m_mouse[port].deltay = var & 0xff;
898      m_mouse[port].oldy = m_mouse[port].y;
878899   }
879900
880   state->m_data1[port] = state->m_mouse[port].buttons | (0x00 << 8);
881   state->m_data2[port] = 0;
901   m_data1[port] = m_mouse[port].buttons | (0x00 << 8);
902   m_data2[port] = 0;
882903}
883904
884static void snes_input_read_superscope( running_machine &machine, int port )
905void snes_console_state::snes_input_read_superscope( int port )
885906{
886   snes_state *state = machine.driver_data<snes_state>();
887907   static const char *const portnames[2][3] =
888908         {
889909            { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" },
r21593r21594
892912   UINT8 input;
893913
894914   /* first read input bits */
895   state->m_scope[port].x = machine.root_device().ioport(portnames[port][1])->read();
896   state->m_scope[port].y = machine.root_device().ioport(portnames[port][2])->read();
897   input = machine.root_device().ioport(portnames[port][0])->read();
915   m_scope[port].x = ioport(portnames[port][1])->read();
916   m_scope[port].y = ioport(portnames[port][2])->read();
917   input = ioport(portnames[port][0])->read();
898918
899919   /* then start elaborating input bits: only keep old turbo value */
900   state->m_scope[port].buttons &= 0x20;
920   m_scope[port].buttons &= 0x20;
901921
902922   /* set onscreen/offscreen */
903   state->m_scope[port].buttons |= BIT(input, 1);
923   m_scope[port].buttons |= BIT(input, 1);
904924
905925   /* turbo is a switch; toggle is edge sensitive */
906   if (BIT(input, 5) && !state->m_scope[port].turbo_lock)
926   if (BIT(input, 5) && !m_scope[port].turbo_lock)
907927   {
908      state->m_scope[port].buttons ^= 0x20;
909      state->m_scope[port].turbo_lock = 1;
928      m_scope[port].buttons ^= 0x20;
929      m_scope[port].turbo_lock = 1;
910930   }
911931   else if (!BIT(input, 5))
912      state->m_scope[port].turbo_lock = 0;
932      m_scope[port].turbo_lock = 0;
913933
914934   /* fire is a button; if turbo is active, trigger is level sensitive; otherwise it is edge sensitive */
915   if (BIT(input, 7) && (BIT(state->m_scope[port].buttons, 5) || !state->m_scope[port].fire_lock))
935   if (BIT(input, 7) && (BIT(m_scope[port].buttons, 5) || !m_scope[port].fire_lock))
916936   {
917      state->m_scope[port].buttons |= 0x80;
918      state->m_scope[port].fire_lock = 1;
937      m_scope[port].buttons |= 0x80;
938      m_scope[port].fire_lock = 1;
919939   }
920940   else if (!BIT(input, 7))
921      state->m_scope[port].fire_lock = 0;
941      m_scope[port].fire_lock = 0;
922942
923943   /* cursor is a button; it is always level sensitive */
924   state->m_scope[port].buttons |= BIT(input, 6);
944   m_scope[port].buttons |= BIT(input, 6);
925945
926946   /* pause is a button; it is always edge sensitive */
927   if (BIT(input, 4) && !state->m_scope[port].pause_lock)
947   if (BIT(input, 4) && !m_scope[port].pause_lock)
928948   {
929      state->m_scope[port].buttons |= 0x10;
930      state->m_scope[port].pause_lock = 1;
949      m_scope[port].buttons |= 0x10;
950      m_scope[port].pause_lock = 1;
931951   }
932952   else if (!BIT(input, 4))
933      state->m_scope[port].pause_lock = 0;
953      m_scope[port].pause_lock = 0;
934954
935955   /* If we have pressed fire or cursor and we are on-screen and SuperScope is in Port2, then latch video signal.
936956   Notice that we only latch Port2 because its IOBit pin is connected to bit7 of the IO Port, while Port1 has
937957   IOBit pin connected to bit6 of the IO Port, and the latter is not detected by the H/V Counters. In other
938958   words, you can connect SuperScope to Port1, but there is no way SNES could detect its on-screen position */
939   if ((state->m_scope[port].buttons & 0xc0) && !(state->m_scope[port].buttons & 0x02) && port == 1)
940      snes_gun_latch(machine, state->m_scope[port].x, state->m_scope[port].y);
959   if ((m_scope[port].buttons & 0xc0) && !(m_scope[port].buttons & 0x02) && port == 1)
960      snes_gun_latch(m_scope[port].x, m_scope[port].y);
941961
942   state->m_data1[port] = 0xff | (state->m_scope[port].buttons << 8);
943   state->m_data2[port] = 0;
962   m_data1[port] = 0xff | (m_scope[port].buttons << 8);
963   m_data2[port] = 0;
944964}
945965
946static void snes_input_read( running_machine &machine )
966WRITE8_MEMBER(snes_console_state::snes_input_read)
947967{
948   snes_state *state = machine.driver_data<snes_state>();
949   UINT8 ctrl1 = machine.root_device().ioport("CTRLSEL")->read() & 0x0f;
950   UINT8 ctrl2 = (machine.root_device().ioport("CTRLSEL")->read() & 0xf0) >> 4;
968   UINT8 ctrl1 = ioport("CTRLSEL")->read() & 0x0f;
969   UINT8 ctrl2 = (ioport("CTRLSEL")->read() & 0xf0) >> 4;
951970
952971   /* Check if lightgun has been chosen as input: if so, enable crosshair */
953   machine.scheduler().timer_set(attotime::zero, FUNC(lightgun_tick));
972   machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(snes_console_state::lightgun_tick),this));
954973
955974   switch (ctrl1)
956975   {
957976   case 1: /* SNES joypad */
958      snes_input_read_joy(machine, 0);
977      snes_input_read_joy(0);
959978      break;
960979   case 2: /* SNES Mouse */
961      snes_input_read_mouse(machine, 0);
980      snes_input_read_mouse(0);
962981      break;
963982   case 3: /* SNES Superscope */
964      snes_input_read_superscope(machine, 0);
983      snes_input_read_superscope(0);
965984      break;
966985   case 0: /* no controller in port1 */
967986   default:
968      state->m_data1[0] = 0;
969      state->m_data2[0] = 0;
987      m_data1[0] = 0;
988      m_data2[0] = 0;
970989      break;
971990   }
972991
973992   switch (ctrl2)
974993   {
975994   case 1: /* SNES joypad */
976      snes_input_read_joy(machine, 1);
995      snes_input_read_joy(1);
977996      break;
978997   case 2: /* SNES Mouse */
979      snes_input_read_mouse(machine, 1);
998      snes_input_read_mouse(1);
980999      break;
9811000   case 3: /* SNES Superscope */
982      snes_input_read_superscope(machine, 1);
1001      snes_input_read_superscope(1);
9831002      break;
9841003   case 0: /* no controller in port2 */
9851004   default:
986      state->m_data1[1] = 0;
987      state->m_data2[1] = 0;
1005      m_data1[1] = 0;
1006      m_data2[1] = 0;
9881007      break;
9891008   }
9901009
9911010   // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h
9921011   // this actually works like reading the first 16bits from oldjoy1/2 in reverse order
993   if (SNES_CPU_REG_STATE(NMITIMEN) & 1)
1012   if (SNES_CPU_REG(NMITIMEN) & 1)
9941013   {
995      SNES_CPU_REG_STATE(JOY1L) = (state->m_data1[0] & 0x00ff) >> 0;
996      SNES_CPU_REG_STATE(JOY1H) = (state->m_data1[0] & 0xff00) >> 8;
997      SNES_CPU_REG_STATE(JOY2L) = (state->m_data1[1] & 0x00ff) >> 0;
998      SNES_CPU_REG_STATE(JOY2H) = (state->m_data1[1] & 0xff00) >> 8;
999      SNES_CPU_REG_STATE(JOY3L) = (state->m_data2[0] & 0x00ff) >> 0;
1000      SNES_CPU_REG_STATE(JOY3H) = (state->m_data2[0] & 0xff00) >> 8;
1001      SNES_CPU_REG_STATE(JOY4L) = (state->m_data2[1] & 0x00ff) >> 0;
1002      SNES_CPU_REG_STATE(JOY4H) = (state->m_data2[1] & 0xff00) >> 8;
1014      SNES_CPU_REG(JOY1L) = (m_data1[0] & 0x00ff) >> 0;
1015      SNES_CPU_REG(JOY1H) = (m_data1[0] & 0xff00) >> 8;
1016      SNES_CPU_REG(JOY2L) = (m_data1[1] & 0x00ff) >> 0;
1017      SNES_CPU_REG(JOY2H) = (m_data1[1] & 0xff00) >> 8;
1018      SNES_CPU_REG(JOY3L) = (m_data2[0] & 0x00ff) >> 0;
1019      SNES_CPU_REG(JOY3H) = (m_data2[0] & 0xff00) >> 8;
1020      SNES_CPU_REG(JOY4L) = (m_data2[1] & 0x00ff) >> 0;
1021      SNES_CPU_REG(JOY4H) = (m_data2[1] & 0xff00) >> 8;
10031022
10041023      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
1005      state->m_read_idx[0] = 16;
1006      state->m_read_idx[1] = 16;
1024      m_read_idx[0] = 16;
1025      m_read_idx[1] = 16;
10071026   }
10081027
10091028}
10101029
1011static UINT8 snes_oldjoy1_read( running_machine &machine )
1030READ8_MEMBER(snes_console_state::snes_oldjoy1_read)
10121031{
1013   snes_state *state = machine.driver_data<snes_state>();
1014   UINT8 ctrl1 = machine.root_device().ioport("CTRLSEL")->read() & 0x0f;
1032   UINT8 ctrl1 = ioport("CTRLSEL")->read() & 0x0f;
10151033   UINT8 res = 0;
10161034
10171035   switch (ctrl1)
10181036   {
10191037   case 1: /* SNES joypad */
1020      if (state->m_read_idx[0] >= 16)
1038      if (m_read_idx[0] >= 16)
10211039         res = 0x01;
10221040      else
1023         res = (state->m_joypad[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
1041         res = (m_joypad[0].buttons >> (15 - m_read_idx[0]++)) & 0x01;
10241042      break;
10251043   case 2: /* SNES Mouse */
1026      if (state->m_read_idx[0] >= 32)
1044      if (m_read_idx[0] >= 32)
10271045         res = 0x01;
1028      else if (state->m_read_idx[0] >= 24)
1029         res = (state->m_mouse[0].deltax >> (31 - state->m_read_idx[0]++)) & 0x01;
1030      else if (state->m_read_idx[0] >= 16)
1031         res = (state->m_mouse[0].deltay >> (23 - state->m_read_idx[0]++)) & 0x01;
1032      else if (state->m_read_idx[0] >= 8)
1033         res = (state->m_mouse[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
1046      else if (m_read_idx[0] >= 24)
1047         res = (m_mouse[0].deltax >> (31 - m_read_idx[0]++)) & 0x01;
1048      else if (m_read_idx[0] >= 16)
1049         res = (m_mouse[0].deltay >> (23 - m_read_idx[0]++)) & 0x01;
1050      else if (m_read_idx[0] >= 8)
1051         res = (m_mouse[0].buttons >> (15 - m_read_idx[0]++)) & 0x01;
10341052      else
10351053         res = 0;
10361054      break;
10371055   case 3: /* SNES Superscope */
1038      if (state->m_read_idx[0] >= 8)
1056      if (m_read_idx[0] >= 8)
10391057         res = 0x01;
10401058      else
1041         res = (state->m_scope[0].buttons >> (7 - state->m_read_idx[0]++)) & 0x01;
1059         res = (m_scope[0].buttons >> (7 - m_read_idx[0]++)) & 0x01;
10421060      break;
10431061   case 0: /* no controller in port2 */
10441062   default:
r21593r21594
10481066   return res;
10491067}
10501068
1051static UINT8 snes_oldjoy2_read( running_machine &machine )
1069READ8_MEMBER(snes_console_state::snes_oldjoy2_read)
10521070{
1053   snes_state *state = machine.driver_data<snes_state>();
1054   UINT8 ctrl2 = (machine.root_device().ioport("CTRLSEL")->read() & 0xf0) >> 4;
1071   UINT8 ctrl2 = (ioport("CTRLSEL")->read() & 0xf0) >> 4;
10551072   UINT8 res = 0;
10561073
10571074   switch (ctrl2)
10581075   {
10591076   case 1: /* SNES joypad */
1060      if (state->m_read_idx[1] >= 16)
1077      if (m_read_idx[1] >= 16)
10611078         res = 0x01;
10621079      else
1063         res = (state->m_joypad[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
1080         res = (m_joypad[1].buttons >> (15 - m_read_idx[1]++)) & 0x01;
10641081      break;
10651082   case 2: /* SNES Mouse */
1066      if (state->m_read_idx[1] >= 32)
1083      if (m_read_idx[1] >= 32)
10671084         res = 0x01;
1068      else if (state->m_read_idx[1] >= 24)
1069         res = (state->m_mouse[1].deltax >> (31 - state->m_read_idx[1]++)) & 0x01;
1070      else if (state->m_read_idx[1] >= 16)
1071         res = (state->m_mouse[1].deltay >> (23 - state->m_read_idx[1]++)) & 0x01;
1072      else if (state->m_read_idx[1] >= 8)
1073         res = (state->m_mouse[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
1085      else if (m_read_idx[1] >= 24)
1086         res = (m_mouse[1].deltax >> (31 - m_read_idx[1]++)) & 0x01;
1087      else if (m_read_idx[1] >= 16)
1088         res = (m_mouse[1].deltay >> (23 - m_read_idx[1]++)) & 0x01;
1089      else if (m_read_idx[1] >= 8)
1090         res = (m_mouse[1].buttons >> (15 - m_read_idx[1]++)) & 0x01;
10741091      else
10751092         res = 0;
10761093      break;
10771094   case 3: /* SNES Superscope */
1078      if (state->m_read_idx[1] >= 8)
1095      if (m_read_idx[1] >= 8)
10791096         res = 0x01;
10801097      else
1081         res = (state->m_scope[1].buttons >> (7 - state->m_read_idx[1]++)) & 0x01;
1098         res = (m_scope[1].buttons >> (7 - m_read_idx[1]++)) & 0x01;
10821099      break;
10831100   case 0: /* no controller in port2 */
10841101   default:
r21593r21594
10961113
10971114static MACHINE_START( snes_mess )
10981115{
1099   snes_state *state = machine.driver_data<snes_state>();
1116   snes_console_state *state = machine.driver_data<snes_console_state>();
11001117
11011118   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(snes_machine_stop),&machine));
11021119   MACHINE_START_CALL(snes);
1103
1120   
11041121   switch (state->m_has_addon_chip)
11051122   {
11061123      case HAS_SDD1:
r21593r21594
11231140
11241141static MACHINE_RESET( snes_mess )
11251142{
1126   snes_state *state = machine.driver_data<snes_state>();
1143   snes_console_state *state = machine.driver_data<snes_console_state>();
11271144
11281145   MACHINE_RESET_CALL(snes);
11291146
1130   state->m_io_read = snes_input_read;
1131   state->m_oldjoy1_read = snes_oldjoy1_read;
1132   state->m_oldjoy2_read = snes_oldjoy2_read;
1133
1147   state->m_io_read = write8_delegate(FUNC(snes_console_state::snes_input_read),state);
1148   state->m_oldjoy1_read = read8_delegate(FUNC(snes_console_state::snes_oldjoy1_read),state);
1149   state->m_oldjoy2_read = read8_delegate(FUNC(snes_console_state::snes_oldjoy2_read),state);
1150   
11341151   // see if there's a uPD7725 DSP in the machine config
11351152   state->m_upd7725 = machine.device<upd7725_device>("dsp");
1136
1153   
11371154   // if we have a DSP, halt it for the moment
11381155   if (state->m_upd7725)
11391156      machine.device("dsp")->execute().set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
1140
1157   
11411158   // ditto for a uPD96050 (Seta ST-010 or ST-011)
11421159   state->m_upd96050 = machine.device<upd96050_device>("setadsp");
11431160   if (state->m_upd96050)
11441161      machine.device("setadsp")->execute().set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
1145
1162   
11461163   switch (state->m_has_addon_chip)
11471164   {
11481165      case HAS_DSP1:
r21593r21594
11581175            state->m_has_addon_chip = HAS_NONE; // prevent crash trying to access NULL device
11591176         }
11601177         break;
1161
1178         
11621179      case HAS_RTC:
11631180         srtc_init(machine);
11641181         break;
1165
1182         
11661183      case HAS_OBC1:
11671184         obc1_init(machine);
11681185         break;
1169
1186         
11701187      case HAS_ST010:
11711188      case HAS_ST011:
11721189         // cartridge uses the DSP, let 'er rip
r21593r21594
11781195            state->m_has_addon_chip = HAS_NONE; // prevent crash trying to access NULL device
11791196         }
11801197         break;
1181
1198         
11821199      default:
11831200         break;
11841201   }
11851202}
11861203
1187static MACHINE_CONFIG_START( snes_base, snes_state )
1204static MACHINE_CONFIG_START( snes_base, snes_console_state )
11881205
11891206   /* basic machine hardware */
11901207   MCFG_CPU_ADD("maincpu", _5A22, MCLK_NTSC)   /* 2.68 MHz, also 3.58 MHz */
r21593r21594
14641481#include "machine/sns_sufami.h"
14651482#include "machine/sns_upd.h"
14661483
1467class snsnew_state : public snes_state
1484class snsnew_state : public snes_console_state
14681485{
14691486public:
14701487   snsnew_state(const machine_config &mconfig, device_type type, const char *tag)
1471      : snes_state(mconfig, type, tag),
1488      : snes_console_state(mconfig, type, tag),
14721489      m_slotcart(*this, "snsslot")
1473   { }
1490   { }   
1491   
1492   DECLARE_READ8_MEMBER( snes20_hi_r );
1493   DECLARE_WRITE8_MEMBER( snes20_hi_w );
1494   DECLARE_READ8_MEMBER( snes20_lo_r );
1495   DECLARE_WRITE8_MEMBER( snes20_lo_w );
1496   DECLARE_READ8_MEMBER( snes21_lo_r );
1497   DECLARE_WRITE8_MEMBER( snes21_lo_w );
1498   DECLARE_READ8_MEMBER( snes21_hi_r );
1499   DECLARE_WRITE8_MEMBER( snes21_hi_w );
1500   DECLARE_READ8_MEMBER( snesfx_hi_r );
1501   DECLARE_READ8_MEMBER( snesfx_lo_r );
1502   DECLARE_WRITE8_MEMBER( snesfx_hi_w );
1503   DECLARE_WRITE8_MEMBER( snesfx_lo_w );
1504   DECLARE_READ8_MEMBER( snespc7110_hi_r );
1505   DECLARE_READ8_MEMBER( snespc7110_lo_r );
1506   DECLARE_WRITE8_MEMBER( snespc7110_hi_w );
1507   DECLARE_WRITE8_MEMBER( snespc7110_lo_w );
1508   DECLARE_READ8_MEMBER( snesdd1_lo_r );
1509   DECLARE_WRITE8_MEMBER( snesdd1_lo_w );
1510   DECLARE_READ8_MEMBER( snesdd1_hi_r );
1511   DECLARE_WRITE8_MEMBER( snesdd1_hi_w );
1512   DECLARE_READ8_MEMBER( snesbsx_hi_r );
1513   DECLARE_WRITE8_MEMBER( snesbsx_hi_w );
1514   DECLARE_READ8_MEMBER( snesbsx_lo_r );
1515   DECLARE_WRITE8_MEMBER( snesbsx_lo_w );
1516   DECLARE_READ8_MEMBER( snesnew_lo_r );
1517   DECLARE_READ8_MEMBER( snesnew_hi_r );
1518   DECLARE_WRITE8_MEMBER( snesnew_lo_w );
1519   DECLARE_WRITE8_MEMBER( snesnew_hi_w );
14741520
14751521   optional_device<sns_cart_slot_device> m_slotcart;
14761522   int m_type;
r21593r21594
14851531
14861532// LoROM
14871533
1488static READ8_HANDLER( snes20_hi_r )
1534READ8_MEMBER( snsnew_state::snes20_hi_r )
14891535{
1490   snsnew_state *state = space.machine().driver_data<snsnew_state>();
14911536   UINT16 address = offset & 0xffff;
1492
1537   
14931538   if (offset < 0x400000)
14941539   {
14951540      if (address < 0x2000)
r21593r21594
14981543         return snes_r_io(space, address);
14991544      if (address >= 0x6000 && address < 0x8000)
15001545         return snes_open_bus_r(space, 0);
1501      if (address >= 0x8000)
1502         return state->m_slotcart->m_cart->read_h(space, offset);
1546      if (address >= 0x8000)         
1547         return m_slotcart->m_cart->read_h(space, offset);
15031548   }
15041549   else if (offset < 0x700000)
15051550   {
15061551      if (address < 0x8000)
15071552         return snes_open_bus_r(space, 0);
15081553      else
1509         return state->m_slotcart->m_cart->read_h(space, offset);
1554         return m_slotcart->m_cart->read_h(space, offset);
15101555   }
1511
1556   
15121557   // ROM & NVRAM access
1513   return state->m_slotcart->m_cart->read_h(space, offset);
1514}
1558   return m_slotcart->m_cart->read_h(space, offset);
1559}   
15151560
1516static WRITE8_HANDLER( snes20_hi_w )
1561WRITE8_MEMBER( snsnew_state::snes20_hi_w )
15171562{
1518   snsnew_state *state = space.machine().driver_data<snsnew_state>();
15191563   UINT16 address = offset & 0xffff;
15201564   if (offset < 0x400000)
15211565   {
r21593r21594
15241568      if (address >= 0x2000 && address < 0x6000)
15251569         snes_w_io(space, address, data);
15261570   }
1527   else if (offset >= 0x700000)    // NVRAM access
1571   else if (offset >= 0x700000)   // NVRAM access
15281572   {
1529      state->m_slotcart->m_cart->write_h(space, offset, data);
1573      m_slotcart->m_cart->write_h(space, offset, data);
15301574   }
1531}
1575}   
15321576
1533static READ8_HANDLER( snes20_lo_r )
1577READ8_MEMBER( snsnew_state::snes20_lo_r )
15341578{
1535   snsnew_state *state = space.machine().driver_data<snsnew_state>();
15361579   UINT16 address = offset & 0xffff;
1537
1580   
15381581   if (offset < 0x400000)
15391582   {
15401583      if (address < 0x2000)
r21593r21594
15431586         return snes_r_io(space, address);
15441587      if (address >= 0x6000 && address < 0x8000)
15451588         return snes_open_bus_r(space, 0);
1546      if (address >= 0x8000)
1547         return state->m_slotcart->m_cart->read_l(space, offset);
1589      if (address >= 0x8000)         
1590         return m_slotcart->m_cart->read_l(space, offset);
15481591   }
15491592   else if (offset < 0x700000)
15501593   {
15511594      if (address < 0x8000)
15521595         return snes_open_bus_r(space, 0);
15531596      else
1554         return state->m_slotcart->m_cart->read_l(space, offset);
1597         return m_slotcart->m_cart->read_l(space, offset);
15551598   }
1556
1599   
15571600   // ROM & NVRAM access
1558   return state->m_slotcart->m_cart->read_l(space, offset);
1559}
1601   return m_slotcart->m_cart->read_l(space, offset);
1602}   
15601603
1561static WRITE8_HANDLER( snes20_lo_w )
1604WRITE8_MEMBER( snsnew_state::snes20_lo_w )
15621605{
15631606   snes20_hi_w(space, offset, data, 0xff);
1564}
1607}   
15651608
15661609
15671610// HiROM
15681611
1569static READ8_HANDLER( snes21_lo_r )
1612READ8_MEMBER( snsnew_state::snes21_lo_r )
15701613{
1571   snsnew_state *state = space.machine().driver_data<snsnew_state>();
15721614   UINT16 address = offset & 0xffff;
1573
1615   
15741616   if (offset < 0x400000)
15751617   {
15761618      if (address < 0x2000)
r21593r21594
15791621         return snes_r_io(space, address);
15801622      if (address >= 0x6000 && address < 0x8000)
15811623      {
1582         if (state->m_slotcart->m_cart->get_nvram_size())
1624         if (m_slotcart->m_cart->get_nvram_size())
15831625         {
15841626            // read NVRAM, instead
15851627            if (offset >= 0x300000)
1586               return state->m_slotcart->m_cart->read_l(space, offset);
1628               return m_slotcart->m_cart->read_l(space, offset);
15871629         }
15881630         return snes_open_bus_r(space, 0);
15891631      }
15901632      if (address >= 0x8000)
1591         return state->m_slotcart->m_cart->read_l(space, offset);
1633         return m_slotcart->m_cart->read_l(space, offset);
15921634   }
1593
1635   
15941636   // ROM & NVRAM access
1595   return state->m_slotcart->m_cart->read_l(space, offset);
1596}
1637   return m_slotcart->m_cart->read_l(space, offset);
1638}   
15971639
1598static WRITE8_HANDLER( snes21_lo_w )
1640WRITE8_MEMBER( snsnew_state::snes21_lo_w )
15991641{
1600   snsnew_state *state = space.machine().driver_data<snsnew_state>();
16011642   UINT16 address = offset & 0xffff;
16021643   if (offset < 0x400000)
16031644   {
r21593r21594
16071648         snes_w_io(space, address, data);
16081649      if (address >= 0x6000 && address < 0x8000)
16091650      {
1610         if (state->m_slotcart->m_cart->get_nvram_size())
1651         if (m_slotcart->m_cart->get_nvram_size())
16111652         {
16121653            // write to NVRAM, in this case
16131654            if (offset >= 0x300000)
1614               state->m_slotcart->m_cart->write_l(space, offset, data);
1655               m_slotcart->m_cart->write_l(space, offset, data);
16151656         }
16161657      }
16171658   }
1618   else if (offset >= 0x700000)    // NVRAM access
1619      state->m_slotcart->m_cart->write_l(space, offset, data);
1620}
1659   else if (offset >= 0x700000)   // NVRAM access
1660      m_slotcart->m_cart->write_l(space, offset, data);
1661}   
16211662
1622static READ8_HANDLER( snes21_hi_r )
1663READ8_MEMBER( snsnew_state::snes21_hi_r )
16231664{
1624   snsnew_state *state = space.machine().driver_data<snsnew_state>();
16251665   UINT16 address = offset & 0xffff;
1626
1666   
16271667   if (offset < 0x400000)
16281668   {
16291669      if (address < 0x2000)
r21593r21594
16321672         return snes_r_io(space, address);
16331673      if (address >= 0x6000 && address < 0x8000)
16341674      {
1635         if (state->m_slotcart->m_cart->get_nvram_size())
1675         if (m_slotcart->m_cart->get_nvram_size())
16361676         {
16371677            // read NVRAM, instead
16381678            if (offset >= 0x300000)
1639               return  state->m_slotcart->m_cart->read_h(space, offset);
1679               return  m_slotcart->m_cart->read_h(space, offset);
16401680         }
16411681         return snes_open_bus_r(space, 0);
16421682      }
16431683      if (address >= 0x8000)
1644         return state->m_slotcart->m_cart->read_h(space, offset);
1684         return m_slotcart->m_cart->read_h(space, offset);
16451685   }
1646
1686   
16471687   // ROM & NVRAM access
1648   return state->m_slotcart->m_cart->read_h(space, offset);
1649}
1688   return m_slotcart->m_cart->read_h(space, offset);
1689}   
16501690
1651static WRITE8_HANDLER( snes21_hi_w )
1691WRITE8_MEMBER( snsnew_state::snes21_hi_w )
16521692{
1653   snsnew_state *state = space.machine().driver_data<snsnew_state>();
16541693   UINT16 address = offset & 0xffff;
16551694   if (offset < 0x400000)
16561695   {
r21593r21594
16601699         snes_w_io(space, address, data);
16611700      if (address >= 0x6000 && address < 0x8000)
16621701      {
1663         if (state->m_slotcart->m_cart->get_nvram_size())
1702         if (m_slotcart->m_cart->get_nvram_size())
16641703         {
16651704            // write to NVRAM, in this case
16661705            if (offset >= 0x300000)
1667               state->m_slotcart->m_cart->write_h(space, offset, data);
1706               m_slotcart->m_cart->write_h(space, offset, data);
16681707         }
16691708      }
16701709   }
1671   else if (offset >= 0x700000)    // NVRAM access
1672      state->m_slotcart->m_cart->write_h(space, offset, data);
1673}
1710   else if (offset >= 0x700000)   // NVRAM access
1711      m_slotcart->m_cart->write_h(space, offset, data);
1712}   
16741713
16751714// SuperFX / GSU
16761715
1677static READ8_HANDLER( snesfx_hi_r )
1716READ8_MEMBER( snsnew_state::snesfx_hi_r )
16781717{
1679   snsnew_state *state = space.machine().driver_data<snsnew_state>();
16801718   UINT16 address = offset & 0xffff;
1681
1719   
16821720   if (offset < 0x400000)
16831721   {
16841722      if (address < 0x2000)
r21593r21594
16861724      if (address >= 0x2000 && address < 0x6000)
16871725      {
16881726         if (address >= 0x3000 && address < 0x3300)
1689            return state->m_slotcart->m_cart->chip_read(space, offset);
1727            return m_slotcart->m_cart->chip_read(space, offset);
16901728         else
16911729            return snes_r_io(space, address);
16921730      }
16931731      if (address >= 0x6000 && address < 0x8000)
16941732      {
1695         return state->m_slotcart->m_cart->read_h(space, offset);    //RAM
1733         return m_slotcart->m_cart->read_h(space, offset);   //RAM
16961734      }
16971735      if (address >= 0x8000)
1698         return state->m_slotcart->m_cart->read_h(space, offset);    //ROM
1736         return m_slotcart->m_cart->read_h(space, offset);   //ROM
16991737   }
17001738   else if (offset < 0x600000)
1701      return state->m_slotcart->m_cart->read_h(space, offset);    //ROM
1739      return m_slotcart->m_cart->read_h(space, offset);   //ROM
1740   
1741   return m_slotcart->m_cart->read_h(space, offset);   //RAM
1742}   
17021743
1703   return state->m_slotcart->m_cart->read_h(space, offset);    //RAM
1704}
1705
1706static READ8_HANDLER( snesfx_lo_r )
1744READ8_MEMBER( snsnew_state::snesfx_lo_r )
17071745{
1708   snsnew_state *state = space.machine().driver_data<snsnew_state>();
17091746   UINT16 address = offset & 0xffff;
1710
1747   
17111748   if (offset < 0x400000)
17121749   {
17131750      if (address < 0x2000)
r21593r21594
17151752      if (address >= 0x2000 && address < 0x6000)
17161753      {
17171754         if (address >= 0x3000 && address < 0x3300)
1718            return state->m_slotcart->m_cart->chip_read(space, offset);
1755            return m_slotcart->m_cart->chip_read(space, offset);
17191756         else
17201757            return snes_r_io(space, address);
17211758      }
17221759      if (address >= 0x6000 && address < 0x8000)
17231760      {
1724         return state->m_slotcart->m_cart->read_l(space, offset);    //RAM
1761         return m_slotcart->m_cart->read_l(space, offset);   //RAM
17251762      }
17261763      if (address >= 0x8000)
1727         return state->m_slotcart->m_cart->read_l(space, offset);    //ROM
1764         return m_slotcart->m_cart->read_l(space, offset);   //ROM
17281765   }
17291766   else if (offset < 0x600000)
1730      return state->m_slotcart->m_cart->read_l(space, offset);    //ROM
1767      return m_slotcart->m_cart->read_l(space, offset);   //ROM
1768   
1769   return m_slotcart->m_cart->read_l(space, offset);   //RAM
1770}   
17311771
1732   return state->m_slotcart->m_cart->read_l(space, offset);    //RAM
1733}
1734
1735static WRITE8_HANDLER( snesfx_hi_w )
1772WRITE8_MEMBER( snsnew_state::snesfx_hi_w )
17361773{
1737   snsnew_state *state = space.machine().driver_data<snsnew_state>();
17381774   UINT16 address = offset & 0xffff;
17391775   if (offset < 0x400000)
17401776   {
r21593r21594
17431779      if (address >= 0x2000 && address < 0x6000)
17441780      {
17451781         if (address >= 0x3000 && address < 0x3300)
1746            state->m_slotcart->m_cart->chip_write(space, offset, data);
1782            m_slotcart->m_cart->chip_write(space, offset, data);
17471783         else
17481784            snes_w_io(space, address, data);
17491785      }
17501786      if (address >= 0x6000 && address < 0x8000)
1751         state->m_slotcart->m_cart->write_h(space, offset, data);
1787         m_slotcart->m_cart->write_h(space, offset, data);
17521788   }
17531789   else
1754      state->m_slotcart->m_cart->write_h(space, offset, data);
1755}
1790      m_slotcart->m_cart->write_h(space, offset, data);
1791}   
17561792
1757static WRITE8_HANDLER( snesfx_lo_w )
1793WRITE8_MEMBER( snsnew_state::snesfx_lo_w )
17581794{
1759   snsnew_state *state = space.machine().driver_data<snsnew_state>();
17601795   UINT16 address = offset & 0xffff;
17611796   if (offset < 0x400000)
17621797   {
r21593r21594
17651800      if (address >= 0x2000 && address < 0x6000)
17661801      {
17671802         if (address >= 0x3000 && address < 0x3300)
1768            state->m_slotcart->m_cart->chip_write(space, offset, data);
1803            m_slotcart->m_cart->chip_write(space, offset, data);
17691804         else
17701805            snes_w_io(space, address, data);
17711806      }
17721807      if (address >= 0x6000 && address < 0x8000)
1773         state->m_slotcart->m_cart->write_l(space, offset, data);
1808         m_slotcart->m_cart->write_l(space, offset, data);
17741809   }
17751810   else
1776      state->m_slotcart->m_cart->write_l(space, offset, data);
1777}
1811      m_slotcart->m_cart->write_l(space, offset, data);
1812}   
17781813
17791814// SPC-7110
17801815
1781static READ8_HANDLER( snespc7110_hi_r )
1816READ8_MEMBER( snsnew_state::snespc7110_hi_r )
17821817{
1783   snsnew_state *state = space.machine().driver_data<snsnew_state>();
17841818   UINT16 address = offset & 0xffff;
1785
1819   
17861820   if (offset < 0x400000)
17871821   {
17881822      if (address < 0x2000)
17891823         return space.read_byte(0x7e0000 + address);
17901824      if (address >= 0x2000 && address < 0x6000)
17911825      {
1792         UINT16 limit = (state->m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
1826         UINT16 limit = (m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
17931827         if (address >= 0x4800 && address < limit)
1794            return state->m_slotcart->m_cart->chip_read(space, address);
1795
1828            return m_slotcart->m_cart->chip_read(space, address);
1829         
17961830         return snes_r_io(space, address);
17971831      }
17981832      if (address >= 0x6000 && address < 0x8000)
17991833      {
18001834         if (offset < 0x10000)
1801            return state->m_slotcart->m_cart->read_h(space, offset);
1835            return m_slotcart->m_cart->read_h(space, offset);
18021836         if (offset >= 0x300000 && offset < 0x310000)
1803            return state->m_slotcart->m_cart->read_h(space, offset);
1837            return m_slotcart->m_cart->read_h(space, offset);
18041838      }
18051839      if (address >= 0x8000)
1806         return state->m_slotcart->m_cart->read_h(space, offset);
1840         return m_slotcart->m_cart->read_h(space, offset);
18071841   }
1808   return state->m_slotcart->m_cart->read_h(space, offset);
1809}
1842   return m_slotcart->m_cart->read_h(space, offset);
1843}   
18101844
1811static READ8_HANDLER( snespc7110_lo_r )
1845READ8_MEMBER( snsnew_state::snespc7110_lo_r )
18121846{
1813   snsnew_state *state = space.machine().driver_data<snsnew_state>();
18141847   UINT16 address = offset & 0xffff;
1815
1848   
18161849   if (offset < 0x400000)
18171850   {
18181851      if (address < 0x2000)
18191852         return space.read_byte(0x7e0000 + address);
18201853      if (address >= 0x2000 && address < 0x6000)
18211854      {
1822         UINT16 limit = (state->m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
1855         UINT16 limit = (m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
18231856         if (address >= 0x4800 && address < limit)
1824            return state->m_slotcart->m_cart->chip_read(space, address);
1825
1857            return m_slotcart->m_cart->chip_read(space, address);
1858         
18261859         return snes_r_io(space, address);
18271860      }
18281861      if (address >= 0x6000 && address < 0x8000)
18291862      {
18301863         if (offset < 0x10000)
1831            return state->m_slotcart->m_cart->read_l(space, offset);
1864            return m_slotcart->m_cart->read_l(space, offset);
18321865         if (offset >= 0x300000 && offset < 0x310000)
1833            return state->m_slotcart->m_cart->read_l(space, offset);
1866            return m_slotcart->m_cart->read_l(space, offset);
18341867      }
18351868      if (address >= 0x8000)
1836         return state->m_slotcart->m_cart->read_l(space, offset);
1869         return m_slotcart->m_cart->read_l(space, offset);
18371870   }
18381871   if (offset >= 0x500000 && offset < 0x510000)
1839      return state->m_slotcart->m_cart->chip_read(space, 0x4800);
1872      return m_slotcart->m_cart->chip_read(space, 0x4800);
18401873
18411874   return snes_open_bus_r(space, 0);
1842}
1875}   
18431876
1844static WRITE8_HANDLER( snespc7110_hi_w )
1877WRITE8_MEMBER( snsnew_state::snespc7110_hi_w )
18451878{
1846   snsnew_state *state = space.machine().driver_data<snsnew_state>();
18471879   UINT16 address = offset & 0xffff;
18481880   if (offset < 0x400000)
18491881   {
r21593r21594
18511883         space.write_byte(0x7e0000 + address, data);
18521884      if (address >= 0x2000 && address < 0x6000)
18531885      {
1854         UINT16 limit = (state->m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
1886         UINT16 limit = (m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
18551887         if (address >= 0x4800 && address < limit)
18561888         {
1857            state->m_slotcart->m_cart->chip_write(space, address, data);
1889            m_slotcart->m_cart->chip_write(space, address, data);
18581890            return;
18591891         }
18601892         snes_w_io(space, address, data);
r21593r21594
18621894      if (address >= 0x6000 && address < 0x8000)
18631895      {
18641896         if (offset < 0x10000)
1865            state->m_slotcart->m_cart->write_l(space, offset, data);
1897            m_slotcart->m_cart->write_l(space, offset, data);
18661898         if (offset >= 0x300000 && offset < 0x310000)
1867            state->m_slotcart->m_cart->write_l(space, offset, data);
1899            m_slotcart->m_cart->write_l(space, offset, data);
18681900      }
18691901   }
1870}
1902}   
18711903
1872static WRITE8_HANDLER( snespc7110_lo_w )
1904WRITE8_MEMBER( snsnew_state::snespc7110_lo_w )
18731905{
1874   snsnew_state *state = space.machine().driver_data<snsnew_state>();
18751906   UINT16 address = offset & 0xffff;
18761907   if (offset < 0x400000)
18771908   {
r21593r21594
18791910         space.write_byte(0x7e0000 + address, data);
18801911      if (address >= 0x2000 && address < 0x6000)
18811912      {
1882         UINT16 limit = (state->m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
1913         UINT16 limit = (m_slotcart->get_type() == SNES_SPC7110_RTC) ? 0x4843 : 0x4840;
18831914         if (address >= 0x4800 && address < limit)
18841915         {
1885            state->m_slotcart->m_cart->chip_write(space, address, data);
1916            m_slotcart->m_cart->chip_write(space, address, data);
18861917            return;
18871918         }
18881919         snes_w_io(space, address, data);
r21593r21594
18901921      if (address >= 0x6000 && address < 0x8000)
18911922      {
18921923         if (offset < 0x10000)
1893            state->m_slotcart->m_cart->write_l(space, offset, data);
1924            m_slotcart->m_cart->write_l(space, offset, data);
18941925         if (offset >= 0x300000 && offset < 0x310000)
1895            state->m_slotcart->m_cart->write_l(space, offset, data);
1926            m_slotcart->m_cart->write_l(space, offset, data);
18961927      }
18971928   }
1898}
1929}   
18991930
19001931
19011932// S-DD1
19021933
1903static READ8_HANDLER( snesdd1_lo_r )
1934READ8_MEMBER( snsnew_state::snesdd1_lo_r )
19041935{
1905   snsnew_state *state = space.machine().driver_data<snsnew_state>();
19061936   UINT16 address = offset & 0xffff;
1907
1937   
19081938   if (offset < 0x400000)
19091939   {
19101940      if (address < 0x2000)
r21593r21594
19121942      if (address >= 0x2000 && address < 0x6000)
19131943      {
19141944         if (address >= 0x4800 && address < 0x4808)
1915            return state->m_slotcart->m_cart->chip_read(space, address);
1916
1945            return m_slotcart->m_cart->chip_read(space, address);
1946         
19171947         return snes_r_io(space, address);
19181948      }
19191949      if (address >= 0x6000 && address < 0x8000)
19201950         return snes_open_bus_r(space, 0);
19211951      if (address >= 0x8000)
1922         return state->m_slotcart->m_cart->read_l(space, offset);
1952         return m_slotcart->m_cart->read_l(space, offset);
19231953   }
1924
1954   
19251955   // ROM & NVRAM access
1926   return state->m_slotcart->m_cart->read_l(space, offset);
1927}
1956   return m_slotcart->m_cart->read_l(space, offset);
1957}   
19281958
1929static WRITE8_HANDLER( snesdd1_lo_w )
1959WRITE8_MEMBER( snsnew_state::snesdd1_lo_w )
19301960{
1931   snsnew_state *state = space.machine().driver_data<snsnew_state>();
19321961   UINT16 address = offset & 0xffff;
19331962   if (offset < 0x400000)
19341963   {
r21593r21594
19381967      {
19391968         if (address >= 0x4300 && address < 0x4380)
19401969         {
1941            state->m_slotcart->m_cart->chip_write(space, address, data);
1970            m_slotcart->m_cart->chip_write(space, address, data);
19421971            // here we don't return, but we let the w_io happen...
19431972         }
19441973         if (address >= 0x4800 && address < 0x4808)
19451974         {
1946            state->m_slotcart->m_cart->chip_write(space, address, data);
1975            m_slotcart->m_cart->chip_write(space, address, data);
19471976            return;
19481977         }
19491978         snes_w_io(space, address, data);
19501979      }
19511980   }
1952   if (offset >= 0x700000 && address < 0x8000 && state->m_slotcart->m_cart->get_nvram_size())
1953      return state->m_slotcart->m_cart->write_l(space, offset, data);
1954}
1981   if (offset >= 0x700000 && address < 0x8000 && m_slotcart->m_cart->get_nvram_size())
1982      return m_slotcart->m_cart->write_l(space, offset, data);
1983}   
19551984
1956static READ8_HANDLER( snesdd1_hi_r )
1957{
1958   snsnew_state *state = space.machine().driver_data<snsnew_state>();
1959
1985READ8_MEMBER( snsnew_state::snesdd1_hi_r )
1986{   
19601987   if (offset >= 0x400000)
1961      return state->m_slotcart->m_cart->read_h(space, offset);
1962   else
1988      return m_slotcart->m_cart->read_h(space, offset);
1989   else     
19631990      return snesdd1_lo_r(space, offset, 0xff);
1964}
1991}   
19651992
1966static WRITE8_HANDLER( snesdd1_hi_w )
1993WRITE8_MEMBER( snsnew_state::snesdd1_hi_w )
19671994{
19681995   snesdd1_lo_w(space, offset, data, 0xff);
1969}
1996}   
19701997
19711998
19721999// BS-X
19732000
1974static READ8_HANDLER( snesbsx_hi_r )
2001READ8_MEMBER( snsnew_state::snesbsx_hi_r )
19752002{
1976   snsnew_state *state = space.machine().driver_data<snsnew_state>();
19772003   UINT16 address = offset & 0xffff;
1978
2004   
19792005   if (offset < 0x400000)
19802006   {
19812007      if (address < 0x2000)
r21593r21594
19832009      if (address >= 0x2000 && address < 0x6000)
19842010      {
19852011         if (address >= 0x2188 && address < 0x21a0)
1986            return state->m_slotcart->m_cart->chip_read(space, offset);
2012            return m_slotcart->m_cart->chip_read(space, offset);
19872013         if (address >= 0x5000)
1988            return state->m_slotcart->m_cart->chip_read(space, offset);
2014            return m_slotcart->m_cart->chip_read(space, offset);
19892015         return snes_r_io(space, address);
19902016      }
19912017      if (address >= 0x6000 && address < 0x8000)
19922018      {
1993         if (offset >= 0x200000)
1994            return state->m_slotcart->m_cart->read_l(space, offset);
2019         if (offset >= 0x200000)         
2020            return m_slotcart->m_cart->read_l(space, offset);
19952021         else
19962022            return snes_open_bus_r(space, 0);
19972023      }
1998      if (address >= 0x8000)
1999         return state->m_slotcart->m_cart->read_l(space, offset);
2024      if (address >= 0x8000)         
2025         return m_slotcart->m_cart->read_l(space, offset);
20002026   }
2001   return state->m_slotcart->m_cart->read_l(space, offset);
2002}
2027   return m_slotcart->m_cart->read_l(space, offset);
2028}   
20032029
2004static WRITE8_HANDLER( snesbsx_hi_w )
2030WRITE8_MEMBER( snsnew_state::snesbsx_hi_w )
20052031{
2006   snsnew_state *state = space.machine().driver_data<snsnew_state>();
20072032   UINT16 address = offset & 0xffff;
20082033   if (offset < 0x400000)
20092034   {
r21593r21594
20132038      {
20142039         if (address >= 0x2188 && address < 0x21a0)
20152040         {
2016            state->m_slotcart->m_cart->chip_write(space, offset, data);
2041            m_slotcart->m_cart->chip_write(space, offset, data);
20172042            return;
20182043         }
20192044         if (address >= 0x5000)
20202045         {
2021            state->m_slotcart->m_cart->chip_write(space, offset, data);
2046            m_slotcart->m_cart->chip_write(space, offset, data);
20222047            return;
20232048         }
20242049         snes_w_io(space, address, data);
20252050      }
20262051      if (address >= 0x6000 && address < 0x8000)
20272052      {
2028         if (offset >= 0x200000)
2029            return state->m_slotcart->m_cart->write_l(space, offset, data);
2053         if (offset >= 0x200000)         
2054            return m_slotcart->m_cart->write_l(space, offset, data);
20302055      }
2031      if (address >= 0x8000)
2032         return state->m_slotcart->m_cart->write_l(space, offset, data);
2056      if (address >= 0x8000)         
2057         return m_slotcart->m_cart->write_l(space, offset, data);
20332058   }
2034   return state->m_slotcart->m_cart->write_l(space, offset, data);
2035}
2059   return m_slotcart->m_cart->write_l(space, offset, data);
2060}   
20362061
2037static READ8_HANDLER( snesbsx_lo_r )
2062READ8_MEMBER( snsnew_state::snesbsx_lo_r )
20382063{
20392064   return snesbsx_hi_r(space, offset, 0xff);
2040}
2065}   
20412066
2042static WRITE8_HANDLER( snesbsx_lo_w )
2067WRITE8_MEMBER( snsnew_state::snesbsx_lo_w )
20432068{
20442069   snesbsx_hi_w(space, offset, data, 0xff);
2045}
2070}   
20462071
20472072
2048static READ8_HANDLER( snesnew_lo_r )
2073READ8_MEMBER( snsnew_state::snesnew_lo_r )
20492074{
2050   snsnew_state *state = space.machine().driver_data<snsnew_state>();
2051
20522075   // take care of add-on IO
2053   if (state->m_slotcart->get_type() == SNES_DSP
2076   if (m_slotcart->get_type() == SNES_DSP
20542077      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2055      return state->m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2056   else if (state->m_slotcart->get_type() == SNES_DSP_MODE21
2078      return m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2079   else if (m_slotcart->get_type() == SNES_DSP_MODE21
20572080            && (offset < 0x200000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2058      return state->m_slotcart->m_cart->chip_read(space, offset & 0x1fff);
2059   else if (state->m_slotcart->get_type() == SNES_DSP4
2081      return m_slotcart->m_cart->chip_read(space, offset & 0x1fff);
2082   else if (m_slotcart->get_type() == SNES_DSP4
20602083            && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2061      return state->m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2062   else if (state->m_slotcart->get_type() == SNES_OBC1
2084      return m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2085   else if (m_slotcart->get_type() == SNES_OBC1
20632086            && (offset < 0x400000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2064      return state->m_slotcart->m_cart->chip_read(space, offset);
2065   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2087      return m_slotcart->m_cart->chip_read(space, offset);
2088   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
20662089            && (offset >= 0x680000 && offset < 0x700000 && (offset & 0xffff) < 0x1000))
2067      return state->m_slotcart->m_cart->chip_read(space, offset);
2068   else if (state->m_slotcart->get_type() == SNES_SRTC
2090      return m_slotcart->m_cart->chip_read(space, offset);
2091   else if (m_slotcart->get_type() == SNES_SRTC
20692092            && (offset < 0x400000 && (offset & 0xffff) == 0x2800))
2070         return state->m_slotcart->m_cart->chip_read(space, offset & 0xffff);
2093         return m_slotcart->m_cart->chip_read(space, offset & 0xffff);
20712094   else
20722095   {
2073      switch (state->m_type)
2096      switch (m_type)
20742097      {
20752098         case SNES_MODE20:
20762099         case SNES_ST010:
r21593r21594
20842107         case SNES_POKEMON:
20852108         case SNES_BANANA:
20862109            return snes20_lo_r(space, offset, 0xff);
2087
2110           
20882111         case SNES_MODE21:
20892112         case SNES_DSP_MODE21:
20902113         case SNES_SRTC:
20912114         case SNES_BSXHI:
20922115            return snes21_lo_r(space, offset, 0xff);
2093
2116           
20942117         case SNES_SFX:
20952118            return snesfx_lo_r(space, offset, 0xff);
2096
2119           
20972120         case SNES_SPC7110:
20982121         case SNES_SPC7110_RTC:
20992122            return snespc7110_lo_r(space, offset, 0xff);
2100
2123           
21012124         case SNES_SDD1:
21022125            return snesdd1_lo_r(space, offset, 0xff);
2103
2126           
21042127         case SNES_BSX:
21052128            return snesbsx_lo_r(space, offset, 0xff);
21062129      }
21072130   }
21082131   return snes_open_bus_r(space, 0);
2109}
2132}   
21102133
2111static READ8_HANDLER( snesnew_hi_r )
2134READ8_MEMBER( snsnew_state::snesnew_hi_r )
21122135{
2113   snsnew_state *state = space.machine().driver_data<snsnew_state>();
2114
21152136   // take care of add-on IO
2116   if (state->m_slotcart->get_type() == SNES_DSP
2137   if (m_slotcart->get_type() == SNES_DSP
21172138      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2118      return state->m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2119   else if (state->m_slotcart->get_type() == SNES_DSP_MODE21
2139      return m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2140   else if (m_slotcart->get_type() == SNES_DSP_MODE21
21202141            && (offset < 0x200000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2121      return state->m_slotcart->m_cart->chip_read(space, offset & 0x1fff);
2122   else if (state->m_slotcart->get_type() == SNES_DSP4
2142      return m_slotcart->m_cart->chip_read(space, offset & 0x1fff);
2143   else if (m_slotcart->get_type() == SNES_DSP4
21232144            && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2124      return state->m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2125   else if (state->m_slotcart->get_type() == SNES_OBC1
2145      return m_slotcart->m_cart->chip_read(space, offset & 0x7fff);
2146   else if (m_slotcart->get_type() == SNES_OBC1
21262147            && (offset < 0x400000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2127      return state->m_slotcart->m_cart->chip_read(space, offset);
2128   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2148      return m_slotcart->m_cart->chip_read(space, offset);
2149   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
21292150            && (offset >= 0x680000 && offset < 0x700000 && (offset & 0xffff) < 0x1000))
2130      return state->m_slotcart->m_cart->chip_read(space, offset);
2131   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2151      return m_slotcart->m_cart->chip_read(space, offset);
2152   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
21322153          && (offset == 0x600000 || offset == 0x600001))
2133      return state->m_slotcart->m_cart->chip_read(space, offset);
2134   else if (state->m_slotcart->get_type() == SNES_SRTC
2154      return m_slotcart->m_cart->chip_read(space, offset);
2155   else if (m_slotcart->get_type() == SNES_SRTC
21352156            && (offset < 0x400000 && (offset & 0xffff) == 0x2800))
2136         return state->m_slotcart->m_cart->chip_read(space, offset & 0xffff);
2137   else if ((state->m_slotcart->get_type() == SNES_POKEMON || state->m_slotcart->get_type() == SNES_BANANA)
2157         return m_slotcart->m_cart->chip_read(space, offset & 0xffff);
2158   else if ((m_slotcart->get_type() == SNES_POKEMON || m_slotcart->get_type() == SNES_BANANA)
21382159            && (offset & 0x70000) == 0x0000)
21392160   {
2140//      printf("hi read %x\n", offset);
2141      return state->m_slotcart->m_cart->chip_read(space, offset);
2161//      printf("hi read %x\n", offset);
2162      return m_slotcart->m_cart->chip_read(space, offset);
21422163   }
21432164   else
21442165   {
2145      switch (state->m_type)
2166      switch (m_type)
21462167      {
21472168         case SNES_MODE20:
21482169         case SNES_ST010:
r21593r21594
21562177         case SNES_POKEMON:
21572178         case SNES_BANANA:
21582179            return snes20_hi_r(space, offset, 0xff);
2159
2180           
21602181         case SNES_MODE21:
21612182         case SNES_DSP_MODE21:
21622183         case SNES_SRTC:
21632184         case SNES_BSXHI:
21642185            return snes21_hi_r(space, offset, 0xff);
2165
2186           
21662187         case SNES_SFX:
21672188            return snesfx_hi_r(space, offset, 0xff);
2168
2189           
21692190         case SNES_SPC7110:
21702191         case SNES_SPC7110_RTC:
21712192            return snespc7110_hi_r(space, offset, 0xff);
2172
2193           
21732194         case SNES_SDD1:
21742195            return snesdd1_hi_r(space, offset, 0xff);
2175
2196           
21762197         case SNES_BSX:
21772198            return snesbsx_hi_r(space, offset, 0xff);
21782199      }
21792200   }
21802201   return snes_open_bus_r(space, 0);
2181}
2202}   
21822203
2183static WRITE8_HANDLER( snesnew_lo_w )
2204WRITE8_MEMBER( snsnew_state::snesnew_lo_w )
21842205{
2185   snsnew_state *state = space.machine().driver_data<snsnew_state>();
2186
21872206   // take care of add-on IO
2188   if (state->m_slotcart->get_type() == SNES_DSP
2207   if (m_slotcart->get_type() == SNES_DSP
21892208      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2190      state->m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2191   else if (state->m_slotcart->get_type() == SNES_DSP_MODE21
2209      m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2210   else if (m_slotcart->get_type() == SNES_DSP_MODE21
21922211            && (offset < 0x200000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2193      state->m_slotcart->m_cart->chip_write(space, offset & 0x1fff, data);
2194   else if (state->m_slotcart->get_type() == SNES_DSP4
2212      m_slotcart->m_cart->chip_write(space, offset & 0x1fff, data);
2213   else if (m_slotcart->get_type() == SNES_DSP4
21952214            && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2196      state->m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2197   else if (state->m_slotcart->get_type() == SNES_OBC1
2215      m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2216   else if (m_slotcart->get_type() == SNES_OBC1
21982217            && (offset < 0x400000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2199      state->m_slotcart->m_cart->chip_write(space, offset, data);
2200   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2218      m_slotcart->m_cart->chip_write(space, offset, data);
2219   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
22012220            && (offset >= 0x680000 && offset < 0x700000 && (offset & 0xffff) < 0x1000))
2202      state->m_slotcart->m_cart->chip_write(space, offset, data);
2203   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2221      m_slotcart->m_cart->chip_write(space, offset, data);
2222   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
22042223          && (offset == 0x600000 || offset == 0x600001))
2205      state->m_slotcart->m_cart->chip_write(space, offset, data);
2206   else if (state->m_slotcart->get_type() == SNES_SRTC
2224      m_slotcart->m_cart->chip_write(space, offset, data);
2225   else if (m_slotcart->get_type() == SNES_SRTC
22072226            && (offset < 0x400000 && (offset & 0xffff) == 0x2801))
2208      state->m_slotcart->m_cart->chip_write(space, offset & 0xffff, data);
2209   else if (state->m_slotcart->get_type() == SNES_BANANA
2227      m_slotcart->m_cart->chip_write(space, offset & 0xffff, data);
2228   else if (m_slotcart->get_type() == SNES_BANANA
22102229            && (offset & 0x78000) == 0x8000)
22112230   {
22122231//      printf("lo write %x\n", offset);
2213      state->m_slotcart->m_cart->chip_write(space, offset, data);
2232      m_slotcart->m_cart->chip_write(space, offset, data);
22142233   }
22152234   else
22162235   {
2217      switch (state->m_type)
2236      switch (m_type)
22182237      {
22192238         case SNES_MODE20:
22202239         case SNES_ST010:
r21593r21594
22292248         case SNES_BANANA:
22302249            snes20_lo_w(space, offset, data, 0xff);
22312250            break;
2232
2251           
22332252         case SNES_MODE21:
22342253         case SNES_DSP_MODE21:
22352254         case SNES_SRTC:
22362255         case SNES_BSXHI:
22372256            snes21_lo_w(space, offset, data, 0xff);
22382257            break;
2239
2258           
22402259         case SNES_SFX:
22412260            snesfx_lo_w(space, offset, data, 0xff);
22422261            break;
2243
2262           
22442263         case SNES_SPC7110:
22452264         case SNES_SPC7110_RTC:
22462265            snespc7110_lo_w(space, offset, data, 0xff);
22472266            break;
2248
2267           
22492268         case SNES_SDD1:
22502269            snesdd1_lo_w(space, offset, data, 0xff);
22512270            break;
2252
2271           
22532272         case SNES_BSX:
22542273            snesbsx_lo_w(space, offset, data, 0xff);
22552274            break;
22562275      }
22572276   }
2258}
2277}   
22592278
2260static WRITE8_HANDLER( snesnew_hi_w )
2279WRITE8_MEMBER( snsnew_state::snesnew_hi_w )
22612280{
2262   snsnew_state *state = space.machine().driver_data<snsnew_state>();
2263
22642281   // take care of add-on IO
2265   if (state->m_slotcart->get_type() == SNES_DSP
2282   if (m_slotcart->get_type() == SNES_DSP
22662283      && (offset >= 0x200000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2267      state->m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2268   else if (state->m_slotcart->get_type() == SNES_DSP_MODE21
2284      m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2285   else if (m_slotcart->get_type() == SNES_DSP_MODE21
22692286            && (offset < 0x200000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2270      state->m_slotcart->m_cart->chip_write(space, offset & 0x1fff, data);
2271   else if (state->m_slotcart->get_type() == SNES_DSP4
2287      m_slotcart->m_cart->chip_write(space, offset & 0x1fff, data);
2288   else if (m_slotcart->get_type() == SNES_DSP4
22722289            && (offset >= 0x300000 && offset < 0x400000 && (offset & 0x8000) == 0x8000))
2273      state->m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2274   else if (state->m_slotcart->get_type() == SNES_OBC1
2290      m_slotcart->m_cart->chip_write(space, offset & 0x7fff, data);
2291   else if (m_slotcart->get_type() == SNES_OBC1
22752292            && (offset < 0x400000 && (offset & 0xffff) >= 0x6000 && (offset & 0xffff) < 0x8000))
2276      return state->m_slotcart->m_cart->chip_write(space, offset, data);
2277   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2293      return m_slotcart->m_cart->chip_write(space, offset, data);
2294   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
22782295            && (offset >= 0x680000 && offset < 0x700000 && (offset & 0xffff) < 0x1000))
2279      state->m_slotcart->m_cart->chip_write(space, offset, data);
2280   else if ((state->m_slotcart->get_type() == SNES_ST010 || state->m_slotcart->get_type() == SNES_ST011)
2296      m_slotcart->m_cart->chip_write(space, offset, data);
2297   else if ((m_slotcart->get_type() == SNES_ST010 || m_slotcart->get_type() == SNES_ST011)
22812298          && (offset == 0x600000 || offset == 0x600001))
2282      state->m_slotcart->m_cart->chip_write(space, offset, data);
2283   else if (state->m_slotcart->get_type() == SNES_SRTC
2299      m_slotcart->m_cart->chip_write(space, offset, data);
2300   else if (m_slotcart->get_type() == SNES_SRTC
22842301            && (offset < 0x400000 && (offset & 0xffff) == 0x2801))
2285      state->m_slotcart->m_cart->chip_write(space, offset & 0xffff, data);
2286   else if ((state->m_slotcart->get_type() == SNES_POKEMON)
2302      m_slotcart->m_cart->chip_write(space, offset & 0xffff, data);
2303   else if ((m_slotcart->get_type() == SNES_POKEMON)
22872304            && (offset & 0x70000) == 0x0000)
22882305   {
22892306//      printf("hi write %x\n", offset);
2290      state->m_slotcart->m_cart->chip_write(space, offset, data);
2307      m_slotcart->m_cart->chip_write(space, offset, data);
22912308   }
22922309   else
22932310   {
2294      switch (state->m_type)
2311      switch (m_type)
22952312      {
22962313         case SNES_MODE20:
22972314         case SNES_ST010:
r21593r21594
23062323         case SNES_BANANA:
23072324            snes20_hi_w(space, offset, data, 0xff);
23082325            break;
2309
2326           
23102327         case SNES_MODE21:
23112328         case SNES_DSP_MODE21:
23122329         case SNES_SRTC:
23132330         case SNES_BSXHI:
23142331            snes21_hi_w(space, offset, data, 0xff);
23152332            break;
2316
2333           
23172334         case SNES_SFX:
23182335            snesfx_hi_w(space, offset, data, 0xff);
23192336            break;
2320
2337           
23212338         case SNES_SPC7110:
23222339         case SNES_SPC7110_RTC:
23232340            snespc7110_hi_w(space, offset, data, 0xff);
23242341            break;
2325
2342           
23262343         case SNES_SDD1:
23272344            snesdd1_hi_w(space, offset, data, 0xff);
23282345            break;
2329
2346           
23302347         case SNES_BSX:
23312348            snesbsx_hi_w(space, offset, data, 0xff);
23322349            break;
23332350      }
23342351   }
2335}
2352}   
23362353
23372354
23382355static ADDRESS_MAP_START( snesnew_map, AS_PROGRAM, 8, snsnew_state )
2339   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snesnew_lo_r, snesnew_lo_w)
2356   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE(snesnew_lo_r, snesnew_lo_w)
23402357   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
2341   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snesnew_hi_r, snesnew_hi_w)
2358   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snesnew_hi_r, snesnew_hi_w)
23422359ADDRESS_MAP_END
23432360
23442361static SLOT_INTERFACE_START(snes_cart)
23452362   SLOT_INTERFACE_INTERNAL("lorom",         SNS_LOROM)
2346   SLOT_INTERFACE_INTERNAL("lorom_bsx",     SNS_LOROM_BSX) // LoROM + BS-X slot - unsupported
2347   SLOT_INTERFACE_INTERNAL("lorom_cx4",     SNS_LOROM) // Cart + CX4 - unsupported
2363   SLOT_INTERFACE_INTERNAL("lorom_bsx",     SNS_LOROM_BSX)   // LoROM + BS-X slot - unsupported
2364   SLOT_INTERFACE_INTERNAL("lorom_cx4",     SNS_LOROM)   // Cart + CX4 - unsupported
23482365   SLOT_INTERFACE_INTERNAL("lorom_dsp",     SNS_LOROM_NECDSP)
23492366   SLOT_INTERFACE_INTERNAL("lorom_dsp4",    SNS_LOROM_NECDSP)
23502367   SLOT_INTERFACE_INTERNAL("lorom_obc1",    SNS_LOROM_OBC1)
2351   SLOT_INTERFACE_INTERNAL("lorom_sa1",     SNS_LOROM) // Cart + SA1 - unsupported
2368   SLOT_INTERFACE_INTERNAL("lorom_sa1",     SNS_LOROM)   // Cart + SA1 - unsupported
23522369   SLOT_INTERFACE_INTERNAL("lorom_sdd1",    SNS_LOROM_SDD1)
23532370   SLOT_INTERFACE_INTERNAL("lorom_sfx",     SNS_LOROM_SUPERFX)
2354   SLOT_INTERFACE_INTERNAL("lorom_sgb",     SNS_LOROM) // SuperGB base cart - unsupported
2371   SLOT_INTERFACE_INTERNAL("lorom_sgb",     SNS_LOROM)   // SuperGB base cart - unsupported
23552372   SLOT_INTERFACE_INTERNAL("lorom_st010",   SNS_LOROM_SETA10)
23562373   SLOT_INTERFACE_INTERNAL("lorom_st011",   SNS_LOROM_SETA11)
2357   SLOT_INTERFACE_INTERNAL("lorom_st018",   SNS_LOROM) // Cart + ST018 - unsupported
2358   SLOT_INTERFACE_INTERNAL("lorom_sufami",  SNS_LOROM_SUFAMI)  // Sufami Turbo base cart
2374   SLOT_INTERFACE_INTERNAL("lorom_st018",   SNS_LOROM)   // Cart + ST018 - unsupported
2375   SLOT_INTERFACE_INTERNAL("lorom_sufami",  SNS_LOROM_SUFAMI)   // Sufami Turbo base cart
23592376   SLOT_INTERFACE_INTERNAL("hirom",         SNS_HIROM)
2360   SLOT_INTERFACE_INTERNAL("hirom_bsx",     SNS_HIROM_BSX) // HiROM + BS-X slot - unsupported
2377   SLOT_INTERFACE_INTERNAL("hirom_bsx",     SNS_HIROM_BSX)   // HiROM + BS-X slot - unsupported
23612378   SLOT_INTERFACE_INTERNAL("hirom_dsp",     SNS_HIROM_NECDSP)
23622379   SLOT_INTERFACE_INTERNAL("hirom_spc7110", SNS_HIROM_SPC7110)
23632380   SLOT_INTERFACE_INTERNAL("hirom_spcrtc",  SNS_HIROM_SPC7110_RTC)
23642381   SLOT_INTERFACE_INTERNAL("hirom_srtc",    SNS_HIROM_SRTC)
2365   SLOT_INTERFACE_INTERNAL("bsxrom",        SNS_ROM_BSX)   // BS-X base cart - partial support only
2382   SLOT_INTERFACE_INTERNAL("bsxrom",        SNS_ROM_BSX)   // BS-X base cart - partial support only
23662383   // pirate carts
23672384   SLOT_INTERFACE_INTERNAL("lorom_poke",    SNS_LOROM_POKEMON)
23682385SLOT_INTERFACE_END
r21593r21594
23802397   switch (state->m_type)
23812398   {
23822399      case SNES_MODE21:
2383         machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x000000, 0x7dffff, FUNC(snes21_lo_r), FUNC(snes21_lo_w));
2384         machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x800000, 0xffffff, FUNC(snes21_hi_r), FUNC(snes21_hi_w));
2400         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2401         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
23852402         set_5a22_map(*state->m_maincpu);
23862403         break;
23872404      case SNES_DSP_MODE21:
trunk/src/mame/machine/snes.c
r21593r21594
105105
106106TIMER_CALLBACK_MEMBER(snes_state::snes_update_io)
107107{
108   address_space &cpu0space = m_maincpu->space(AS_PROGRAM);
109   m_io_read(cpu0space.machine());
108   m_io_read(m_maincpu->space(AS_PROGRAM),0,0,0);
110109   SNES_CPU_REG(HVBJOY) &= 0xfe;       /* Clear busy bit */
111110
112111   m_io_timer->adjust(attotime::never);
r21593r21594
371370 * mid  - This is the middle byte of a 24 bit value
372371 * high - This is the high byte of a 16 or 24 bit value
373372 */
374READ8_HANDLER( snes_r_io )
373READ8_MEMBER( snes_state::snes_r_io )
375374{
376   snes_state *state = space.machine().driver_data<snes_state>();
377375   UINT8 value = 0;
378376
379377   // PPU accesses are from 2100 to 213f
380378   if (offset >= INIDISP && offset < APU00)
381379   {
382      return state->m_ppu.read(space, offset, SNES_CPU_REG_STATE(WRIO) & 0x80);
380      return m_ppu.read(space, offset, SNES_CPU_REG(WRIO) & 0x80);
383381   }
384382
385383   // APU is mirrored from 2140 to 217f
386384   if (offset >= APU00 && offset < WMDATA)
387385   {
388      return spc_port_out(state->m_spc700, space, offset & 0x3);
386      return spc_port_out(m_spc700, space, offset & 0x3);
389387   }
390388
391389   // DMA accesses are from 4300 to 437f
392390   if (offset >= DMAP0 && offset < 0x4380)
393391   {
394      return state->snes_io_dma_r(space, offset);
392      return snes_io_dma_r(space, offset);
395393   }
396394
397395   /* offset is from 0x000000 */
398396   switch (offset)
399397   {
400398      case WMDATA:    /* Data to read from WRAM */
401         value = space.read_byte(0x7e0000 + state->m_wram_address++);
402         state->m_wram_address &= 0x1ffff;
399         value = space.read_byte(0x7e0000 + m_wram_address++);
400         m_wram_address &= 0x1ffff;
403401         return value;
404402      case OLDJOY1:   /* Data for old NES controllers (JOYSER1) */
405         if (state->m_oldjoy1_latch & 0x1)
403         if (m_oldjoy1_latch & 0x1)
406404            return 0 | (snes_open_bus_r(space, 0) & 0xfc); //correct?
407405
408         value = state->m_oldjoy1_read(space.machine());
406         value = m_oldjoy1_read(space,0,0);
409407
410408         return (value & 0x03) | (snes_open_bus_r(space, 0) & 0xfc); //correct?
411409      case OLDJOY2:   /* Data for old NES controllers (JOYSER2) */
412         if (state->m_oldjoy1_latch & 0x1)
410         if (m_oldjoy1_latch & 0x1)
413411            return 0 | 0x1c | (snes_open_bus_r(space, 0) & 0xe0); //correct?
414412
415         value = state->m_oldjoy2_read(space.machine());
413         value = m_oldjoy2_read(space,0,0);
416414
417415         return value | 0x1c | (snes_open_bus_r(space, 0) & 0xe0); //correct?
418416      case RDNMI:         /* NMI flag by v-blank and version number */
419         value = (SNES_CPU_REG_STATE(RDNMI) & 0x80) | (snes_open_bus_r(space, 0) & 0x70);
420         SNES_CPU_REG_STATE(RDNMI) &= 0x70;   /* NMI flag is reset on read */
417         value = (SNES_CPU_REG(RDNMI) & 0x80) | (snes_open_bus_r(space, 0) & 0x70);
418         SNES_CPU_REG(RDNMI) &= 0x70;   /* NMI flag is reset on read */
421419         return value | 2; //CPU version number
422420      case TIMEUP:        /* IRQ flag by H/V count timer */
423         value = (snes_open_bus_r(space, 0) & 0x7f) | (SNES_CPU_REG_STATE(TIMEUP) & 0x80);
424         state->m_maincpu->set_input_line(G65816_LINE_IRQ, CLEAR_LINE );
425         SNES_CPU_REG_STATE(TIMEUP) = 0;   // flag is cleared on both read and write
421         value = (snes_open_bus_r(space, 0) & 0x7f) | (SNES_CPU_REG(TIMEUP) & 0x80);
422         m_maincpu->set_input_line(G65816_LINE_IRQ, CLEAR_LINE );
423         SNES_CPU_REG(TIMEUP) = 0;   // flag is cleared on both read and write
426424         return value;
427425      case HVBJOY:        /* H/V blank and joypad controller enable */
428426         // electronics test says hcounter 272 is start of hblank, which is beampos 363
429//          if (space.machine().primary_screen->hpos() >= 363) SNES_CPU_REG_STATE(HVBJOY) |= 0x40;
430//              else SNES_CPU_REG_STATE(HVBJOY) &= ~0x40;
431         return (SNES_CPU_REG_STATE(HVBJOY) & 0xc1) | (snes_open_bus_r(space, 0) & 0x3e);
427//          if (space.machine().primary_screen->hpos() >= 363) SNES_CPU_REG(HVBJOY) |= 0x40;
428//              else SNES_CPU_REG(HVBJOY) &= ~0x40;
429         return (SNES_CPU_REG(HVBJOY) & 0xc1) | (snes_open_bus_r(space, 0) & 0x3e);
432430      case RDIO:          /* Programmable I/O port - echos back what's written to WRIO */
433         return SNES_CPU_REG_STATE(WRIO);
431         return SNES_CPU_REG(WRIO);
434432      case JOY1L:         /* Joypad 1 status register (low) */
435433      case JOY1H:         /* Joypad 1 status register (high) */
436434      case JOY2L:         /* Joypad 2 status register (low) */
r21593r21594
439437      case JOY3H:         /* Joypad 3 status register (high) */
440438      case JOY4L:         /* Joypad 4 status register (low) */
441439      case JOY4H:         /* Joypad 4 status register (high) */
442         if(state->m_is_nss && state->m_input_disabled)
440         if(m_is_nss && m_input_disabled)
443441            return 0;
444         return SNES_CPU_REG_STATE(offset);
442         return SNES_CPU_REG(offset);
445443
446444      case 0x4100:        /* NSS Dip-Switches */
447445         {
448            if (state->m_is_nss)
449               return space.machine().root_device().ioport("DSW")->read();
446            if (m_is_nss)
447               return ioport("DSW")->read();
450448
451449            return snes_open_bus_r(space, 0);
452450         }
r21593r21594
471469 * mid  - This is the middle byte of a 24 bit value
472470 * high - This is the high byte of a 16 or 24 bit value
473471 */
474WRITE8_HANDLER( snes_w_io )
472WRITE8_MEMBER( snes_state::snes_w_io )
475473{
476   snes_state *state = space.machine().driver_data<snes_state>();
477
478474   // PPU accesses are from 2100 to 213f
479475   if (offset >= INIDISP && offset < APU00)
480476   {
481      state->m_ppu.write(space, offset, data);
477      m_ppu.write(space, offset, data);
482478      return;
483479   }
484480
r21593r21594
486482   if (offset >= APU00 && offset < WMDATA)
487483   {
488484//      printf("816: %02x to APU @ %d (PC=%06x)\n", data, offset & 3,space.device().safe_pc());
489      spc_port_in(state->m_spc700, space, offset & 0x3, data);
485      spc_port_in(m_spc700, space, offset & 0x3, data);
490486      space.machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(20));
491487      return;
492488   }
r21593r21594
494490   // DMA accesses are from 4300 to 437f
495491   if (offset >= DMAP0 && offset < 0x4380)
496492   {
497      state->snes_io_dma_w(space, offset, data);
493      snes_io_dma_w(space, offset, data);
498494      return;
499495   }
500496
r21593r21594
502498   switch (offset)
503499   {
504500      case WMDATA:    /* Data to write to WRAM */
505         space.write_byte(0x7e0000 + state->m_wram_address++, data );
506         state->m_wram_address &= 0x1ffff;
501         space.write_byte(0x7e0000 + m_wram_address++, data );
502         m_wram_address &= 0x1ffff;
507503         return;
508504      case WMADDL:    /* Address to read/write to wram (low) */
509         state->m_wram_address = (state->m_wram_address & 0xffff00) | (data <<  0);
510         state->m_wram_address &= 0x1ffff;
505         m_wram_address = (m_wram_address & 0xffff00) | (data <<  0);
506         m_wram_address &= 0x1ffff;
511507         return;
512508      case WMADDM:    /* Address to read/write to wram (mid) */
513         state->m_wram_address = (state->m_wram_address & 0xff00ff) | (data <<  8);
514         state->m_wram_address &= 0x1ffff;
509         m_wram_address = (m_wram_address & 0xff00ff) | (data <<  8);
510         m_wram_address &= 0x1ffff;
515511         return;
516512      case WMADDH:    /* Address to read/write to wram (high) */
517         state->m_wram_address = (state->m_wram_address & 0x00ffff) | (data << 16);
518         state->m_wram_address &= 0x1ffff;
513         m_wram_address = (m_wram_address & 0x00ffff) | (data << 16);
514         m_wram_address &= 0x1ffff;
519515         return;
520516      case OLDJOY1:   /* Old NES joystick support */
521         if (((!(data & 0x1)) && (state->m_oldjoy1_latch & 0x1)))
517         if (((!(data & 0x1)) && (m_oldjoy1_latch & 0x1)))
522518         {
523            state->m_read_idx[0] = 0;
524            state->m_read_idx[1] = 0;
519            m_read_idx[0] = 0;
520            m_read_idx[1] = 0;
525521         }
526         if (state->m_is_nss)
522         if (m_is_nss)
527523         {
528            state->m_game_over_flag = (data & 4) >> 2;
524            m_game_over_flag = (data & 4) >> 2;
529525         }
530         state->m_oldjoy1_latch = data;
526         m_oldjoy1_latch = data;
531527         return;
532528      case OLDJOY2:   /* Old NES joystick support */
533529         return;
534530      case NMITIMEN:  /* Flag for v-blank, timer int. and joy read */
535531         if ((data & 0x30) == 0x00)
536532         {
537            state->m_maincpu->set_input_line(G65816_LINE_IRQ, CLEAR_LINE );
538            SNES_CPU_REG_STATE(TIMEUP) = 0;   // clear pending IRQ if irq is disabled here, 3x3 Eyes - Seima Korin Den behaves on this
533            m_maincpu->set_input_line(G65816_LINE_IRQ, CLEAR_LINE );
534            SNES_CPU_REG(TIMEUP) = 0;   // clear pending IRQ if irq is disabled here, 3x3 Eyes - Seima Korin Den behaves on this
539535         }
540         SNES_CPU_REG_STATE(NMITIMEN) = data;
536         SNES_CPU_REG(NMITIMEN) = data;
541537         return;
542538      case WRIO:      /* Programmable I/O port - latches H/V counters on a 0->1 transition */
543         if (!(SNES_CPU_REG_STATE(WRIO) & 0x80) && (data & 0x80))
539         if (!(SNES_CPU_REG(WRIO) & 0x80) && (data & 0x80))
544540         {
545541            // external latch
546            state->m_ppu.latch_counters(space.machine());
542            m_ppu.latch_counters(space.machine());
547543         }
548         SNES_CPU_REG_STATE(WRIO) = data;
544         SNES_CPU_REG(WRIO) = data;
549545         return;
550546      case HTIMEL:    /* H-Count timer settings (low)  */
551         state->m_htime = (state->m_htime & 0xff00) | (data <<  0);
552         state->m_htime &= 0x1ff;
547         m_htime = (m_htime & 0xff00) | (data <<  0);
548         m_htime &= 0x1ff;
553549         return;
554550      case HTIMEH:    /* H-Count timer settings (high) */
555         state->m_htime = (state->m_htime & 0x00ff) | (data <<  8);
556         state->m_htime &= 0x1ff;
551         m_htime = (m_htime & 0x00ff) | (data <<  8);
552         m_htime &= 0x1ff;
557553         return;
558554      case VTIMEL:    /* V-Count timer settings (low)  */
559         state->m_vtime = (state->m_vtime & 0xff00) | (data <<  0);
560         state->m_vtime &= 0x1ff;
555         m_vtime = (m_vtime & 0xff00) | (data <<  0);
556         m_vtime &= 0x1ff;
561557         return;
562558      case VTIMEH:    /* V-Count timer settings (high) */
563         state->m_vtime = (state->m_vtime & 0x00ff) | (data <<  8);
564         state->m_vtime &= 0x1ff;
559         m_vtime = (m_vtime & 0x00ff) | (data <<  8);
560         m_vtime &= 0x1ff;
565561         return;
566562      case MDMAEN:    /* DMA channel designation and trigger */
567         state->dma(space, data);
568         SNES_CPU_REG_STATE(MDMAEN) = 0;   /* Once DMA is done we need to reset all bits to 0 */
563         dma(space, data);
564         SNES_CPU_REG(MDMAEN) = 0;   /* Once DMA is done we need to reset all bits to 0 */
569565         return;
570566      case HDMAEN:    /* HDMA channel designation */
571567         if (data) //if a HDMA is enabled, data is inited at the next scanline
572            space.machine().scheduler().timer_set(space.machine().primary_screen->time_until_pos(state->m_ppu.m_beam.current_vert + 1), timer_expired_delegate(FUNC(snes_state::snes_reset_hdma),state));
573         SNES_CPU_REG_STATE(HDMAEN) = data;
568            space.machine().scheduler().timer_set(space.machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert + 1), timer_expired_delegate(FUNC(snes_state::snes_reset_hdma),this));
569         SNES_CPU_REG(HDMAEN) = data;
574570         return;
575571      case TIMEUP:    // IRQ Flag is cleared on both read and write
576         state->m_maincpu->set_input_line(G65816_LINE_IRQ, CLEAR_LINE );
577         SNES_CPU_REG_STATE(TIMEUP) = 0;
572         m_maincpu->set_input_line(G65816_LINE_IRQ, CLEAR_LINE );
573         SNES_CPU_REG(TIMEUP) = 0;
578574         return;
579575      /* Following are read-only */
580576      case HVBJOY:    /* H/V blank and joypad enable */
r21593r21594
686682/* 0x000000 - 0x2fffff */
687683READ8_HANDLER( snes_r_bank1 )
688684{
685   snes_state *state = space.machine().driver_data<snes_state>();
689686   UINT8 value = 0xff;
690687   UINT16 address = offset & 0xffff;
691688
692689   if (address < 0x2000)                                           /* Mirror of Low RAM */
693690      value = space.read_byte(0x7e0000 + address);
694691   else if (address < 0x6000)                                      /* I/O */
695      value = snes_r_io(space, address);
692      value = state->snes_r_io(space, address);
696693   else if (address < 0x8000)
697694   {
698695      logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %04x\n",space.device().safe_pc(),address);
r21593r21594
714711   if (address < 0x2000)                                           /* Mirror of Low RAM */
715712      value = space.read_byte(0x7e0000 + address);
716713   else if (address < 0x6000)                                      /* I/O */
717      value = snes_r_io(space, address);
714      value = state->snes_r_io(space, address);
718715   else if (address < 0x8000)                                      /* SRAM for mode_21, Reserved othewise */
719716   {
720717      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].sram > 0)
r21593r21594
849846/* 0x000000 - 0x2fffff */
850847WRITE8_HANDLER( snes_w_bank1 )
851848{
849   snes_state *state = space.machine().driver_data<snes_state>();
852850   UINT16 address = offset & 0xffff;
853851
854852   if (address < 0x2000)                           /* Mirror of Low RAM */
855853      space.write_byte(0x7e0000 + address, data);
856854   else if (address < 0x6000)                      /* I/O */
857      snes_w_io(space, address, data);
855      state->snes_w_io(space, address, data);
858856   else if (address < 0x8000)
859857      logerror("snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data);
860858   else
r21593r21594
870868   if (address < 0x2000)                           /* Mirror of Low RAM */
871869      space.write_byte(0x7e0000 + address, data);
872870   else if (address < 0x6000)                      /* I/O */
873      snes_w_io(space, address, data);
871      state->snes_w_io(space, address, data);
874872   else if (address < 0x8000)                      /* SRAM for mode_21, Reserved othewise */
875873   {
876874      if ((state->m_cart[0].mode == SNES_MODE_21) && (state->m_cart[0].sram > 0))
r21593r21594
973971
974972*************************************/
975973
976static void nss_io_read( running_machine &machine )
974WRITE8_MEMBER(snes_state::nss_io_read)
977975{
978   snes_state *state = machine.driver_data<snes_state>();
979976   static const char *const portnames[2][4] =
980977         {
981978            { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" },
r21593r21594
985982
986983   for (port = 0; port < 2; port++)
987984   {
988      state->m_data1[port] = state->ioport(portnames[port][0])->read() | (state->ioport(portnames[port][1])->read() << 8);
989      state->m_data2[port] = state->ioport(portnames[port][2])->read() | (state->ioport(portnames[port][3])->read() << 8);
985      m_data1[port] = ioport(portnames[port][0])->read() | (ioport(portnames[port][1])->read() << 8);
986      m_data2[port] = ioport(portnames[port][2])->read() | (ioport(portnames[port][3])->read() << 8);
990987
991988      // avoid sending signals that could crash games
992989      // if left, no right
993      if (state->m_data1[port] & 0x200)
994         state->m_data1[port] &= ~0x100;
990      if (m_data1[port] & 0x200)
991         m_data1[port] &= ~0x100;
995992      // if up, no down
996      if (state->m_data1[port] & 0x800)
997         state->m_data1[port] &= ~0x400;
993      if (m_data1[port] & 0x800)
994         m_data1[port] &= ~0x400;
998995
999      state->m_joypad[port].buttons = state->m_data1[port];
996      m_joypad[port].buttons = m_data1[port];
1000997   }
1001998
1002999   // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h
10031000   // this actually works like reading the first 16bits from oldjoy1/2 in reverse order
1004   if (SNES_CPU_REG_STATE(NMITIMEN) & 1)
1001   if (SNES_CPU_REG(NMITIMEN) & 1)
10051002   {
1006      SNES_CPU_REG_STATE(JOY1L) = (state->m_data1[0] & 0x00ff) >> 0;
1007      SNES_CPU_REG_STATE(JOY1H) = (state->m_data1[0] & 0xff00) >> 8;
1008      SNES_CPU_REG_STATE(JOY2L) = (state->m_data1[1] & 0x00ff) >> 0;
1009      SNES_CPU_REG_STATE(JOY2H) = (state->m_data1[1] & 0xff00) >> 8;
1010      SNES_CPU_REG_STATE(JOY3L) = (state->m_data2[0] & 0x00ff) >> 0;
1011      SNES_CPU_REG_STATE(JOY3H) = (state->m_data2[0] & 0xff00) >> 8;
1012      SNES_CPU_REG_STATE(JOY4L) = (state->m_data2[1] & 0x00ff) >> 0;
1013      SNES_CPU_REG_STATE(JOY4H) = (state->m_data2[1] & 0xff00) >> 8;
1003      SNES_CPU_REG(JOY1L) = (m_data1[0] & 0x00ff) >> 0;
1004      SNES_CPU_REG(JOY1H) = (m_data1[0] & 0xff00) >> 8;
1005      SNES_CPU_REG(JOY2L) = (m_data1[1] & 0x00ff) >> 0;
1006      SNES_CPU_REG(JOY2H) = (m_data1[1] & 0xff00) >> 8;
1007      SNES_CPU_REG(JOY3L) = (m_data2[0] & 0x00ff) >> 0;
1008      SNES_CPU_REG(JOY3H) = (m_data2[0] & 0xff00) >> 8;
1009      SNES_CPU_REG(JOY4L) = (m_data2[1] & 0x00ff) >> 0;
1010      SNES_CPU_REG(JOY4H) = (m_data2[1] & 0xff00) >> 8;
10141011
10151012      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
1016      state->m_read_idx[0] = 16;
1017      state->m_read_idx[1] = 16;
1013      m_read_idx[0] = 16;
1014      m_read_idx[1] = 16;
10181015   }
10191016
1020   if(state->m_is_nss)
1021      state->m_joy_flag = 0;
1017   if(m_is_nss)
1018      m_joy_flag = 0;
10221019}
10231020
10241021
10251022
1026static UINT8 nss_oldjoy1_read( running_machine &machine )
1023READ8_MEMBER(snes_state::nss_oldjoy1_read)
10271024{
1028   snes_state *state = machine.driver_data<snes_state>();
10291025   UINT8 res;
10301026
1031   if (state->m_read_idx[0] >= 16)
1027   if (m_read_idx[0] >= 16)
10321028      res = 0x01;
10331029   else
1034      res = (state->m_joypad[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
1030      res = (m_joypad[0].buttons >> (15 - m_read_idx[0]++)) & 0x01;
10351031
10361032   return res;
10371033}
10381034
1039static UINT8 nss_oldjoy2_read( running_machine &machine )
1035READ8_MEMBER(snes_state::nss_oldjoy2_read)
10401036{
1041   snes_state *state = machine.driver_data<snes_state>();
10421037   UINT8 res;
10431038
1044   if (state->m_read_idx[1] >= 16)
1039   if (m_read_idx[1] >= 16)
10451040      res = 0x01;
10461041   else
1047      res = (state->m_joypad[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
1042      res = (m_joypad[1].buttons >> (15 - m_read_idx[1]++)) & 0x01;
10481043
10491044   return res;
10501045}
r21593r21594
10811076   state->m_hblank_timer->adjust(machine.primary_screen->time_until_pos(((state->m_ppu.m_stat78 & 0x10) == SNES_NTSC) ? SNES_VTOTAL_NTSC - 1 : SNES_VTOTAL_PAL - 1, state->m_hblank_offset));
10821077}
10831078
1084static void snes_init_ram( running_machine &machine )
1079void snes_state::snes_init_ram()
10851080{
1086   snes_state *state = machine.driver_data<snes_state>();
1087   address_space &cpu0space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1081   address_space &cpu0space = machine().device("maincpu")->memory().space(AS_PROGRAM);
10881082   int i;
10891083
10901084   /* Init work RAM - 0x55 isn't exactly right but it's close */
r21593r21594
10951089   }
10961090
10971091   /* Inititialize registers/variables */
1098   SNES_CPU_REG_STATE(JOY1L) = SNES_CPU_REG_STATE(JOY1H) = 0;
1099   SNES_CPU_REG_STATE(JOY2L) = SNES_CPU_REG_STATE(JOY2H) = 0;
1100   SNES_CPU_REG_STATE(JOY3L) = SNES_CPU_REG_STATE(JOY3H) = 0;
1101   SNES_CPU_REG_STATE(JOY4L) = SNES_CPU_REG_STATE(JOY4H) = 0;
1102   state->m_data1[0] = state->m_data2[0] = state->m_data1[1] = state->m_data2[1] = 0;
1092   SNES_CPU_REG(JOY1L) = SNES_CPU_REG(JOY1H) = 0;
1093   SNES_CPU_REG(JOY2L) = SNES_CPU_REG(JOY2H) = 0;
1094   SNES_CPU_REG(JOY3L) = SNES_CPU_REG(JOY3H) = 0;
1095   SNES_CPU_REG(JOY4L) = SNES_CPU_REG(JOY4H) = 0;
1096   m_data1[0] = m_data2[0] = m_data1[1] = m_data2[1] = 0;
11031097
1104   state->m_io_read = nss_io_read;
1105   state->m_oldjoy1_read = nss_oldjoy1_read;
1106   state->m_oldjoy2_read = nss_oldjoy2_read;
1098   m_io_read = write8_delegate(FUNC(snes_state::nss_io_read),this);
1099   m_oldjoy1_read = read8_delegate(FUNC(snes_state::nss_oldjoy1_read),this);
1100   m_oldjoy2_read = read8_delegate(FUNC(snes_state::nss_oldjoy2_read),this);
11071101
11081102   // set up some known register power-up defaults
1109   SNES_CPU_REG_STATE(WRIO) = 0xff;
1103   SNES_CPU_REG(WRIO) = 0xff;
11101104
11111105   // init frame counter so first line is 0
1112   if (ATTOSECONDS_TO_HZ(machine.primary_screen->frame_period().attoseconds) >= 59)
1113      state->m_ppu.m_beam.current_vert = SNES_VTOTAL_NTSC;
1106   if (ATTOSECONDS_TO_HZ(machine().primary_screen->frame_period().attoseconds) >= 59)
1107      m_ppu.m_beam.current_vert = SNES_VTOTAL_NTSC;
11141108   else
1115      state->m_ppu.m_beam.current_vert = SNES_VTOTAL_PAL;
1109      m_ppu.m_beam.current_vert = SNES_VTOTAL_PAL;
11161110}
11171111
11181112#if 0
r21593r21594
12051199   snes_state *state = machine.driver_data<snes_state>();
12061200   int i;
12071201
1208   snes_init_ram(machine);
1202   state->snes_init_ram();
12091203
12101204   /* init DMA regs to be 0xff */
12111205   for(i = 0; i < 8; i++)
trunk/src/mame/includes/snes.h
r21593r21594
579579   int offscreen;
580580};
581581
582typedef void (*snes_io_read)(running_machine &machine);
583typedef UINT8 (*snes_oldjoy_read)(running_machine &machine);
584
585582class snes_state : public driver_device
586583{
587584public:
r21593r21594
643640   snes_superscope       m_scope[2];
644641
645642   /* input callbacks (to allow MESS to have its own input handlers) */
646   snes_io_read          m_io_read;
647   snes_oldjoy_read      m_oldjoy1_read;
648   snes_oldjoy_read      m_oldjoy2_read;
643   write8_delegate     m_io_read;
644   read8_delegate      m_oldjoy1_read;
645   read8_delegate      m_oldjoy2_read;
649646
650647   /* cart related */
651648   UINT8 m_has_addon_chip;
r21593r21594
681678   void hdma_init(address_space &space);
682679   void hdma_update(address_space &space, int dma);
683680   void hirq_tick();
681   
682   void snes_init_ram();
683   
684   DECLARE_WRITE8_MEMBER(nss_io_read);
685   DECLARE_READ8_MEMBER(nss_oldjoy1_read);
686   DECLARE_READ8_MEMBER(nss_oldjoy2_read);
684687
685688   DECLARE_READ8_MEMBER(snes_io_dma_r);
686689   DECLARE_WRITE8_MEMBER(snes_io_dma_w);
r21593r21594
694697   DECLARE_WRITE_LINE_MEMBER(snes_extern_irq_w);
695698   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(snes_cart);
696699   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(sufami_cart);
700   DECLARE_READ8_MEMBER( snes_r_io );
701   DECLARE_WRITE8_MEMBER( snes_w_io );   
697702};
698703
699704/* Special chips, checked at init and used in memory handlers */
r21593r21594
747752
748753DECLARE_READ8_HANDLER( snes_open_bus_r );
749754
750extern DECLARE_READ8_HANDLER( snes_r_io );
751extern DECLARE_WRITE8_HANDLER( snes_w_io );
752
753755extern DECLARE_READ8_HANDLER( snes_r_bank1 );
754756extern DECLARE_READ8_HANDLER( snes_r_bank2 );
755757extern DECLARE_READ8_HANDLER( snes_r_bank3 );

Previous 199869 Revisions Next


© 1997-2024 The MAME Team