Previous 15994 Revisions Next

r9193 Monday 20th September, 2010 at 00:13:40 UTC by Miodrag Milanović
Another sync with MAME
[src/emu]sound.c timer.c video.c
[src/emu/cpu/asap]asap.c
[src/emu/machine]6532riot.c 74123.c 7474.c at28c16.c eeprom.c i2cmem.c mb3773.c z80ctc.c z80dart.c z80dma.c z80pio.c z80sio.c z80sti.c
[src/emu/sound]okim6295.c
[src/mame/audio]amiga.c
[src/mame/drivers]alg.c arcadia.c cubocd32.c mquake.c playch10.c segaorun.c segas16a.c segas16b.c segas18.c segaxbd.c segaybd.c ssv.c tetrisp2.c tomcat.c upscope.c vamphalf.c videopkr.c zn.c
[src/mame/includes]amiga.h cubocd32.h leland.h namcos2.h ssv.h
[src/mame/machine]amiga.c atarigen.h cubocd32.c playch10.c
[src/mame/video]amiga.c amigaaga.c
[src/mess/drivers]ami1200.c amiga.c
[src/mess/machine]amigacd.c amigacrt.c amigafdc.c amigakbd.c

src/mame/audio/amiga.c
r9192r9193
6363};
6464
6565
66INLINE amiga_audio *get_safe_token( running_device *device )
67{
68        assert(device != NULL);
69        assert(device->type() == AMIGA);
6670
67/*************************************
68 *
69 *  Globals
70 *
71 *************************************/
71        return (amiga_audio *)downcast<legacy_device_base *>(device)->token();
72}
7273
73static amiga_audio *audio_state;
74
75
76
7774/*************************************
7875 *
7976 *  DMA reload/IRQ signalling
r9192r9193
8683}
8784
8885
89static void dma_reload(audio_channel *chan)
86static void dma_reload(amiga_state *state, audio_channel *chan)
9087{
9188   chan->curlocation = CUSTOM_REG_LONG(REG_AUD0LCH + chan->index * 8);
9289   chan->curlength = CUSTOM_REG(REG_AUD0LEN + chan->index * 8);
r9192r9193
10299 *
103100 *************************************/
104101
105void amiga_audio_data_w(int which, UINT16 data)
102void amiga_audio_data_w(running_device *device, int which, UINT16 data)
106103{
104   amiga_audio *audio_state = get_safe_token(device);
105
107106   audio_state->channel[which].manualmode = TRUE;
108107}
109108
r9192r9193
115114 *
116115 *************************************/
117116
118void amiga_audio_update(void)
117void amiga_audio_update(running_device *device)
119118{
119   amiga_audio *audio_state = get_safe_token(device);
120
120121   stream_update(audio_state->stream);
121122}
122123
r9192r9193
124125
125126static STREAM_UPDATE( amiga_stream_update )
126127{
128   amiga_state *state = device->machine->driver_data<amiga_state>();
127129   amiga_audio *audio = (amiga_audio *)param;
128130   int channum, sampoffs = 0;
129131
r9192r9193
148150   {
149151      audio_channel *chan = &audio->channel[channum];
150152      if (!chan->dmaenabled && ((CUSTOM_REG(REG_DMACON) >> channum) & 1))
151         dma_reload(chan);
153         dma_reload(state, chan);
152154      chan->dmaenabled = (CUSTOM_REG(REG_DMACON) >> channum) & 1;
153155   }
154156
r9192r9193
223225               chan->curlocation++;
224226            if (chan->dmaenabled && !(chan->curlocation & 1))
225227            {
226               CUSTOM_REG(REG_AUD0DAT + channum * 8) = amiga_chip_ram_r(chan->curlocation);
228               CUSTOM_REG(REG_AUD0DAT + channum * 8) = (*state->chip_ram_r)(state, chan->curlocation);
227229               if (chan->curlength != 0)
228230                  chan->curlength--;
229231
230232               /* if we run out of data, reload the dma */
231233               if (chan->curlength == 0)
232                  dma_reload(chan);
234                  dma_reload(state, chan);
233235            }
234236
235237            /* latch the next byte of the sample */
r9192r9193
263265
264266static DEVICE_START( amiga_sound )
265267{
266   running_machine *machine = device->machine;
268   amiga_audio *audio_state = get_safe_token(device);
267269   int i;
268270
269   /* allocate a new audio state */
270   audio_state = (amiga_audio *)downcast<legacy_device_base *>(device)->token();
271271   for (i = 0; i < 4; i++)
272272   {
273273      audio_state->channel[i].index = i;
274      audio_state->channel[i].irq_timer = timer_alloc(machine, signal_irq, NULL);
274      audio_state->channel[i].irq_timer = timer_alloc(device->machine, signal_irq, NULL);
275275   }
276276
277277   /* create the stream */
r9192r9193
284284   switch (state)
285285   {
286286      /* --- the following bits of info are returned as 64-bit signed integers --- */
287      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(*audio_state);               break;
287      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(amiga_audio);               break;
288288
289289      /* --- the following bits of info are returned as pointers to data or functions --- */
290290      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(amiga_sound);   break;
src/mame/machine/cubocd32.c
r9192r9193
2727#define CD_SECTOR_TIME      (1000/((150*1024)/2048))   /* 1X CDROM sector time in msec (300KBps) */
2828
2929
30static struct akiko_def
30typedef struct _akiko_state akiko_state;
31struct _akiko_state
3132{
33   running_machine *machine;
34   address_space *space;
35
3236   /* chunky to planar converter */
3337   UINT32   c2p_input_buffer[8];
3438   UINT32   c2p_output_buffer[8];
r9192r9193
6165   emu_timer *dma_timer;
6266   emu_timer *frame_timer;
6367   running_device *i2cmem;
64} akiko;
68};
6569
6670static TIMER_CALLBACK(akiko_dma_proc);
6771static TIMER_CALLBACK(akiko_frame_proc);
6872
69static void amiga_akiko_exit(running_machine& machine)
73INLINE akiko_state *get_safe_token(running_device *device)
7074{
71   if( akiko.cdrom ) {
72      cdrom_close(akiko.cdrom);
73      akiko.cdrom = (cdrom_file *)NULL;
75   assert(device != NULL);
76   assert(device->type() == AKIKO);
77
78   return (akiko_state *)downcast<legacy_device_base *>(device)->token();
79}
80
81static DEVICE_STOP( akiko )
82{
83   akiko_state *state = get_safe_token(device);
84   if( state->cdrom )
85   {
86      cdrom_close(state->cdrom);
87      state->cdrom = (cdrom_file *)NULL;
7488   }
7589}
7690
77void amiga_akiko_init(running_machine* machine)
91static DEVICE_START( akiko )
7892{
79   akiko.c2p_input_index = 0;
80   akiko.c2p_output_index = 0;
93   running_machine *machine = device->machine;
94   akiko_state *state = get_safe_token(device);
8195
82   akiko.i2c_scl_out = 0;
83   akiko.i2c_scl_dir = 0;
84   akiko.i2c_sda_out = 0;
85   akiko.i2c_sda_dir = 0;
96   state->machine = machine;
97   state->space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
98   state->c2p_input_index = 0;
99   state->c2p_output_index = 0;
86100
87   akiko.cdrom_status[0] = akiko.cdrom_status[1] = 0;
88   akiko.cdrom_address[0] = akiko.cdrom_address[1] = 0;
89   akiko.cdrom_track_index = 0;
90   akiko.cdrom_lba_start = 0;
91   akiko.cdrom_lba_end = 0;
92   akiko.cdrom_lba_cur = 0;
93   akiko.cdrom_readmask = 0;
94   akiko.cdrom_readreqmask = 0;
95   akiko.cdrom_dmacontrol = 0;
96   akiko.cdrom_numtracks = 0;
97   akiko.cdrom_speed = 0;
98   akiko.cdrom_cmd_start = 0;
99   akiko.cdrom_cmd_end = 0;
100   akiko.cdrom_cmd_resp = 0;
101   akiko.cdrom = cdrom_open(get_disk_handle(machine, "cdrom"));
102   akiko.cdrom_toc = NULL;
103   akiko.dma_timer = timer_alloc(machine, akiko_dma_proc, NULL);
104   akiko.frame_timer = timer_alloc(machine, akiko_frame_proc, NULL);
105   akiko.i2cmem = machine->device("i2cmem");
101   state->i2c_scl_out = 0;
102   state->i2c_scl_dir = 0;
103   state->i2c_sda_out = 0;
104   state->i2c_sda_dir = 0;
106105
107   machine->add_notifier(MACHINE_NOTIFY_EXIT, amiga_akiko_exit);
106   state->cdrom_status[0] = state->cdrom_status[1] = 0;
107   state->cdrom_address[0] = state->cdrom_address[1] = 0;
108   state->cdrom_track_index = 0;
109   state->cdrom_lba_start = 0;
110   state->cdrom_lba_end = 0;
111   state->cdrom_lba_cur = 0;
112   state->cdrom_readmask = 0;
113   state->cdrom_readreqmask = 0;
114   state->cdrom_dmacontrol = 0;
115   state->cdrom_numtracks = 0;
116   state->cdrom_speed = 0;
117   state->cdrom_cmd_start = 0;
118   state->cdrom_cmd_end = 0;
119   state->cdrom_cmd_resp = 0;
120   state->cdrom = cdrom_open(get_disk_handle(machine, "cdrom"));
121   state->cdrom_toc = NULL;
122   state->dma_timer = timer_alloc(machine, akiko_dma_proc, state);
123   state->frame_timer = timer_alloc(machine, akiko_frame_proc, state);
124   state->i2cmem = machine->device("i2cmem");
108125
109126   /* create the TOC table */
110   if ( akiko.cdrom != NULL && cdrom_get_last_track(akiko.cdrom) )
127   if ( state->cdrom != NULL && cdrom_get_last_track(state->cdrom) )
111128   {
112129      UINT8 *p;
113      int      i, addrctrl = cdrom_get_adr_control( akiko.cdrom, 0 );
130      int      i, addrctrl = cdrom_get_adr_control( state->cdrom, 0 );
114131      UINT32   discend;
115132
116      discend = cdrom_get_track_start(akiko.cdrom,cdrom_get_last_track(akiko.cdrom)-1);
117      discend += cdrom_get_toc(akiko.cdrom)->tracks[cdrom_get_last_track(akiko.cdrom)-1].frames;
133      discend = cdrom_get_track_start(state->cdrom,cdrom_get_last_track(state->cdrom)-1);
134      discend += cdrom_get_toc(state->cdrom)->tracks[cdrom_get_last_track(state->cdrom)-1].frames;
118135      discend = lba_to_msf(discend);
119136
120      akiko.cdrom_numtracks = cdrom_get_last_track(akiko.cdrom)+3;
137      state->cdrom_numtracks = cdrom_get_last_track(state->cdrom)+3;
121138
122      akiko.cdrom_toc = auto_alloc_array(machine, UINT8, 13*akiko.cdrom_numtracks);
123      memset( akiko.cdrom_toc, 0, 13*akiko.cdrom_numtracks);
139      state->cdrom_toc = auto_alloc_array(machine, UINT8, 13*state->cdrom_numtracks);
140      memset( state->cdrom_toc, 0, 13*state->cdrom_numtracks);
124141
125      p = akiko.cdrom_toc;
142      p = state->cdrom_toc;
126143      p[1] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
127144      p[3] = 0xa0; /* first track */
128145      p[8] = 1;
129146      p += 13;
130147      p[1] = 0x01;
131148      p[3] = 0xa1; /* last track */
132      p[8] = cdrom_get_last_track(akiko.cdrom);
149      p[8] = cdrom_get_last_track(state->cdrom);
133150      p += 13;
134151      p[1] = 0x01;
135152      p[3] = 0xa2; /* disc end */
r9192r9193
138155      p[10] = discend & 0xff;
139156      p += 13;
140157
141      for( i = 0; i < cdrom_get_last_track(akiko.cdrom); i++ )
158      for( i = 0; i < cdrom_get_last_track(state->cdrom); i++ )
142159      {
143         UINT32   trackpos = cdrom_get_track_start(akiko.cdrom,i);
160         UINT32   trackpos = cdrom_get_track_start(state->cdrom,i);
144161
145162         trackpos = lba_to_msf(trackpos);
146         addrctrl = cdrom_get_adr_control( akiko.cdrom, i );
163         addrctrl = cdrom_get_adr_control( state->cdrom, i );
147164
148165         p[1] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
149166         p[3] = dec_2_bcd( i+1 );
r9192r9193
156173   }
157174}
158175
159static void akiko_nvram_write(running_machine *machine, UINT32 data)
176static void akiko_nvram_write(akiko_state *state, UINT32 data)
160177{
161   akiko.i2c_scl_out = BIT(data,31);
162   akiko.i2c_sda_out = BIT(data,30);
163   akiko.i2c_scl_dir = BIT(data,15);
164   akiko.i2c_sda_dir = BIT(data,14);
178   state->i2c_scl_out = BIT(data,31);
179   state->i2c_sda_out = BIT(data,30);
180   state->i2c_scl_dir = BIT(data,15);
181   state->i2c_sda_dir = BIT(data,14);
165182
166   i2cmem_scl_write( akiko.i2cmem, akiko.i2c_scl_out );
167   i2cmem_sda_write( akiko.i2cmem, akiko.i2c_sda_out );
183   i2cmem_scl_write( state->i2cmem, state->i2c_scl_out );
184   i2cmem_sda_write( state->i2cmem, state->i2c_sda_out );
168185}
169186
170static UINT32 akiko_nvram_read(running_machine *machine)
187static UINT32 akiko_nvram_read(akiko_state *state)
171188{
172189   UINT32   v = 0;
173190
174   if ( akiko.i2c_scl_dir )
191   if ( state->i2c_scl_dir )
175192   {
176      v |= akiko.i2c_scl_out << 31;
193      v |= state->i2c_scl_out << 31;
177194   }
178195   else
179196   {
180197      v |= 0 << 31;
181198   }
182199
183   if ( akiko.i2c_sda_dir )
200   if ( state->i2c_sda_dir )
184201   {
185      v |= akiko.i2c_sda_out << 30;
202      v |= state->i2c_sda_out << 30;
186203   }
187204   else
188205   {
189      v |= i2cmem_sda_read( akiko.i2cmem ) << 30;
206      v |= i2cmem_sda_read( state->i2cmem ) << 30;
190207   }
191208
192   v |= akiko.i2c_scl_dir << 15;
193   v |= akiko.i2c_sda_dir << 14;
209   v |= state->i2c_scl_dir << 15;
210   v |= state->i2c_sda_dir << 14;
194211
195212   return v;
196213}
r9192r9193
201218 *
202219 ************************************/
203220
204static void akiko_c2p_write(UINT32 data)
221static void akiko_c2p_write(akiko_state *state, UINT32 data)
205222{
206   akiko.c2p_input_buffer[akiko.c2p_input_index] = data;
207   akiko.c2p_input_index++;
208   akiko.c2p_input_index &= 7;
209   akiko.c2p_output_index = 0;
223   state->c2p_input_buffer[state->c2p_input_index] = data;
224   state->c2p_input_index++;
225   state->c2p_input_index &= 7;
226   state->c2p_output_index = 0;
210227}
211228
212static UINT32 akiko_c2p_read(void)
229static UINT32 akiko_c2p_read(akiko_state *state)
213230{
214231   UINT32 val;
215232
216   if ( akiko.c2p_output_index == 0 )
233   if ( state->c2p_output_index == 0 )
217234   {
218235      int i;
219236
220237      for ( i = 0; i < 8; i++ )
221         akiko.c2p_output_buffer[i] = 0;
238         state->c2p_output_buffer[i] = 0;
222239
223      for (i = 0; i < 8 * 32; i++) {
224         if (akiko.c2p_input_buffer[7 - (i >> 5)] & (1 << (i & 31)))
225            akiko.c2p_output_buffer[i & 7] |= 1 << (i >> 3);
240      for (i = 0; i < 8 * 32; i++)
241      {
242         if (state->c2p_input_buffer[7 - (i >> 5)] & (1 << (i & 31)))
243            state->c2p_output_buffer[i & 7] |= 1 << (i >> 3);
226244      }
227245   }
228   akiko.c2p_input_index = 0;
229   val = akiko.c2p_output_buffer[akiko.c2p_output_index];
230   akiko.c2p_output_index++;
231   akiko.c2p_output_index &= 7;
246   state->c2p_input_index = 0;
247   val = state->c2p_output_buffer[state->c2p_output_index];
248   state->c2p_output_index++;
249   state->c2p_output_index &= 7;
232250   return val;
233251}
234252
r9192r9193
269287 *
270288 ************************************/
271289
272static void akiko_cdda_stop( running_machine *machine )
290static void akiko_cdda_stop(akiko_state *state)
273291{
274   running_device *cdda = cdda_from_cdrom(machine, akiko.cdrom);
292   running_device *cdda = cdda_from_cdrom(state->machine, state->cdrom);
275293
276294   if (cdda != NULL)
277295   {
278296      cdda_stop_audio(cdda);
279      timer_reset( akiko.frame_timer, attotime_never );
297      timer_reset( state->frame_timer, attotime_never );
280298   }
281299}
282300
283static void akiko_cdda_play( running_machine *machine, UINT32 lba, UINT32 num_blocks )
301static void akiko_cdda_play(akiko_state *state, UINT32 lba, UINT32 num_blocks)
284302{
285   running_device *cdda = cdda_from_cdrom(machine, akiko.cdrom);
303   running_device *cdda = cdda_from_cdrom(state->machine, state->cdrom);
286304   if (cdda != NULL)
287305   {
288306      cdda_start_audio(cdda, lba, num_blocks);
289      timer_adjust_oneshot( akiko.frame_timer, ATTOTIME_IN_HZ( 75 ), 0 );
307      timer_adjust_oneshot( state->frame_timer, ATTOTIME_IN_HZ( 75 ), 0 );
290308   }
291309}
292310
293static void akiko_cdda_pause( running_machine *machine, int pause )
311static void akiko_cdda_pause(akiko_state *state, int pause)
294312{
295   running_device *cdda = cdda_from_cdrom(machine, akiko.cdrom);
313   running_device *cdda = cdda_from_cdrom(state->machine, state->cdrom);
296314   if (cdda != NULL)
297315   {
298316      if (cdda_audio_active(cdda) && cdda_audio_paused(cdda) != pause )
r9192r9193
301319
302320         if ( pause )
303321         {
304            timer_reset( akiko.frame_timer, attotime_never );
322            timer_reset( state->frame_timer, attotime_never );
305323         }
306324         else
307325         {
308            timer_adjust_oneshot( akiko.frame_timer, ATTOTIME_IN_HZ( 75 ), 0 );
326            timer_adjust_oneshot( state->frame_timer, ATTOTIME_IN_HZ( 75 ), 0 );
309327         }
310328      }
311329   }
312330}
313331
314static UINT8 akiko_cdda_getstatus( running_machine *machine, UINT32 *lba )
332static UINT8 akiko_cdda_getstatus(akiko_state *state, UINT32 *lba)
315333{
316   running_device *cdda = cdda_from_cdrom(machine, akiko.cdrom);
334   running_device *cdda = cdda_from_cdrom(state->machine, state->cdrom);
317335
318336   if ( lba ) *lba = 0;
319337
r9192r9193
341359   return 0x15;   /* no audio status */
342360}
343361
344static void akiko_set_cd_status( running_machine *machine, UINT32 status )
362static void akiko_set_cd_status(akiko_state *state, UINT32 status)
345363{
346   akiko.cdrom_status[0] |= status;
364   state->cdrom_status[0] |= status;
347365
348   if ( akiko.cdrom_status[0] & akiko.cdrom_status[1] )
366   if ( state->cdrom_status[0] & state->cdrom_status[1] )
349367   {
350368      if (LOG_AKIKO_CD) logerror( "Akiko CD IRQ\n" );
351      amiga_custom_w(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
369      amiga_custom_w(state->space, REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
352370   }
353371}
354372
355373static TIMER_CALLBACK(akiko_frame_proc)
356374{
357   running_device *cdda = cdda_from_cdrom(machine, akiko.cdrom);
375   akiko_state *state = (akiko_state *)param;
376   running_device *cdda = cdda_from_cdrom(machine, state->cdrom);
358377
359378   (void)param;
360379
361380   if (cdda != NULL)
362381   {
363      UINT8   s = akiko_cdda_getstatus(machine, NULL);
382      UINT8   s = akiko_cdda_getstatus(state, NULL);
364383
365384      if ( s == 0x11 )
366385      {
367         akiko_set_cd_status( machine, 0x80000000 );   /* subcode ready */
386         akiko_set_cd_status(state, 0x80000000);   /* subcode ready */
368387      }
369388
370      timer_adjust_oneshot( akiko.frame_timer, ATTOTIME_IN_HZ( 75 ), 0 );
389      timer_adjust_oneshot( state->frame_timer, ATTOTIME_IN_HZ( 75 ), 0 );
371390   }
372391}
373392
r9192r9193
384403
385404static TIMER_CALLBACK(akiko_dma_proc)
386405{
406   akiko_state *state = (akiko_state *)ptr;
387407   UINT8   buf[2352];
388408   int      index;
389409
390   if ( (akiko.cdrom_dmacontrol & 0x04000000) == 0 )
410   if ( (state->cdrom_dmacontrol & 0x04000000) == 0 )
391411      return;
392412
393   if ( akiko.cdrom_readreqmask == 0 )
413   if ( state->cdrom_readreqmask == 0 )
394414      return;
395415
396   index = (akiko.cdrom_lba_cur - akiko.cdrom_lba_start) & 0x0f;
416   index = (state->cdrom_lba_cur - state->cdrom_lba_start) & 0x0f;
397417
398   if ( akiko.cdrom_readreqmask & ( 1 << index ) )
418   if ( state->cdrom_readreqmask & ( 1 << index ) )
399419   {
400      UINT32   track = cdrom_get_track( akiko.cdrom, akiko.cdrom_lba_cur );
401      UINT32   datasize = cdrom_get_toc( akiko.cdrom )->tracks[track].datasize;
402      UINT32   subsize = cdrom_get_toc( akiko.cdrom )->tracks[track].subsize;
420      amiga_state *amiga = machine->driver_data<amiga_state>();
421      UINT32   track = cdrom_get_track( state->cdrom, state->cdrom_lba_cur );
422      UINT32   datasize = cdrom_get_toc( state->cdrom )->tracks[track].datasize;
423      UINT32   subsize = cdrom_get_toc( state->cdrom )->tracks[track].subsize;
403424      int      i;
404425
405      UINT32   curmsf = lba_to_msf( akiko.cdrom_lba_cur );
426      UINT32   curmsf = lba_to_msf( state->cdrom_lba_cur );
406427      memset( buf, 0, 16 );
407428
408      buf[3] = akiko.cdrom_lba_cur - akiko.cdrom_lba_start;
429      buf[3] = state->cdrom_lba_cur - state->cdrom_lba_start;
409430      memset( &buf[4], 0xff, 8 );
410431
411432      buf[12] = (curmsf >> 16) & 0xff;
r9192r9193
414435      buf[15] = 0x01; /* mode1 */
415436
416437      datasize = 2048;
417      if ( !cdrom_read_data( akiko.cdrom, akiko.cdrom_lba_cur, &buf[16], CD_TRACK_MODE1 ) )
438      if ( !cdrom_read_data( state->cdrom, state->cdrom_lba_cur, &buf[16], CD_TRACK_MODE1 ) )
418439      {
419         logerror( "AKIKO: Read error trying to read sector %08x!\n", akiko.cdrom_lba_cur );
440         logerror( "AKIKO: Read error trying to read sector %08x!\n", state->cdrom_lba_cur );
420441         return;
421442      }
422443
423444      if ( subsize )
424445      {
425         if ( !cdrom_read_subcode( akiko.cdrom, akiko.cdrom_lba_cur, &buf[16+datasize] ) )
446         if ( !cdrom_read_subcode( state->cdrom, state->cdrom_lba_cur, &buf[16+datasize] ) )
426447         {
427            logerror( "AKIKO: Read error trying to read subcode for sector %08x!\n", akiko.cdrom_lba_cur );
448            logerror( "AKIKO: Read error trying to read subcode for sector %08x!\n", state->cdrom_lba_cur );
428449            return;
429450         }
430451      }
431452
432      if (LOG_AKIKO_CD) logerror( "DMA: sector %d - address %08x\n", akiko.cdrom_lba_cur, akiko.cdrom_address[0] + (index*4096) );
453      if (LOG_AKIKO_CD) logerror( "DMA: sector %d - address %08x\n", state->cdrom_lba_cur, state->cdrom_address[0] + (index*4096) );
433454
434455      for( i = 0; i < 2352; i += 2 )
435456      {
r9192r9193
439460         data <<= 8;
440461         data |= buf[i+1];
441462
442         amiga_chip_ram_w( akiko.cdrom_address[0] + (index*4096) + i, data );
463         (*amiga->chip_ram_w)( amiga, state->cdrom_address[0] + (index*4096) + i, data );
443464      }
444465
445      akiko.cdrom_readmask |= ( 1 << index );
446      akiko.cdrom_readreqmask &= ~( 1 << index );
447      akiko.cdrom_lba_cur++;
466      state->cdrom_readmask |= ( 1 << index );
467      state->cdrom_readreqmask &= ~( 1 << index );
468      state->cdrom_lba_cur++;
448469   }
449470
450   if ( akiko.cdrom_readreqmask == 0 )
451      akiko_set_cd_status(machine, 0x04000000);
471   if ( state->cdrom_readreqmask == 0 )
472      akiko_set_cd_status(state, 0x04000000);
452473   else
453      timer_adjust_oneshot( akiko.dma_timer, ATTOTIME_IN_USEC( CD_SECTOR_TIME / akiko.cdrom_speed ), 0 );
474      timer_adjust_oneshot( state->dma_timer, ATTOTIME_IN_USEC( CD_SECTOR_TIME / state->cdrom_speed ), 0 );
454475}
455476
456static void akiko_start_dma( void )
477static void akiko_start_dma(akiko_state *state)
457478{
458   if ( akiko.cdrom_readreqmask == 0 )
479   if ( state->cdrom_readreqmask == 0 )
459480      return;
460481
461   if ( akiko.cdrom_lba_start > akiko.cdrom_lba_end )
482   if ( state->cdrom_lba_start > state->cdrom_lba_end )
462483      return;
463484
464   if ( akiko.cdrom_speed == 0 )
485   if ( state->cdrom_speed == 0 )
465486      return;
466487
467   akiko.cdrom_lba_cur = akiko.cdrom_lba_start;
488   state->cdrom_lba_cur = state->cdrom_lba_start;
468489
469   timer_adjust_oneshot( akiko.dma_timer, ATTOTIME_IN_USEC( CD_SECTOR_TIME / akiko.cdrom_speed ), 0 );
490   timer_adjust_oneshot( state->dma_timer, ATTOTIME_IN_USEC( CD_SECTOR_TIME / state->cdrom_speed ), 0 );
470491}
471492
472static void akiko_setup_response( address_space *space, int len, UINT8 *r1 )
493static void akiko_setup_response( akiko_state *state, int len, UINT8 *r1 )
473494{
474   int      resp_addr = akiko.cdrom_address[1];
495   int      resp_addr = state->cdrom_address[1];
475496   UINT8   resp_csum = 0xff;
476497   UINT8   resp_buffer[32];
477498   int      i;
r9192r9193
488509
489510   for( i = 0; i < len; i++ )
490511   {
491      space->write_byte( resp_addr + ((akiko.cdrom_cmd_resp + i) & 0xff), resp_buffer[i] );
512      state->space->write_byte( resp_addr + ((state->cdrom_cmd_resp + i) & 0xff), resp_buffer[i] );
492513   }
493514
494   akiko.cdrom_cmd_resp = (akiko.cdrom_cmd_resp+len) & 0xff;
515   state->cdrom_cmd_resp = (state->cdrom_cmd_resp+len) & 0xff;
495516
496   akiko_set_cd_status( space->machine, 0x10000000 ); /* new data available */
517   akiko_set_cd_status(state, 0x10000000); /* new data available */
497518}
498519
499520static TIMER_CALLBACK( akiko_cd_delayed_cmd )
500521{
522   akiko_state *state = (akiko_state *)ptr;
501523   UINT8   resp[32];
502524   UINT8   cddastatus;
503525
504   if ( akiko.cdrom_status[0] & 0x10000000 )
526   if ( state->cdrom_status[0] & 0x10000000 )
505527      return;
506528
507   cddastatus = akiko_cdda_getstatus(machine, NULL);
529   cddastatus = akiko_cdda_getstatus(state, NULL);
508530
509531   if ( cddastatus == 0x11 || cddastatus == 0x12 )
510532      return;
r9192r9193
516538
517539   if ( param == 0x05 )
518540   {
519      address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
520541      if (LOG_AKIKO_CD) logerror( "AKIKO: Completing Command %d\n", param );
521542
522543      resp[0] = 0x06;
523544
524      if ( akiko.cdrom == NULL || akiko.cdrom_numtracks == 0 )
545      if ( state->cdrom == NULL || state->cdrom_numtracks == 0 )
525546      {
526547         resp[1] = 0x80;
527         akiko_setup_response( space, 15, resp );
548         akiko_setup_response( state, 15, resp );
528549      }
529550      else
530551      {
531552         resp[1] = 0x00;
532         memcpy( &resp[2], &akiko.cdrom_toc[13*akiko.cdrom_track_index], 13 );
553         memcpy( &resp[2], &state->cdrom_toc[13*state->cdrom_track_index], 13 );
533554
534         akiko.cdrom_track_index = ( akiko.cdrom_track_index + 1 ) % akiko.cdrom_numtracks;
555         state->cdrom_track_index = ( state->cdrom_track_index + 1 ) % state->cdrom_numtracks;
535556
536         akiko_setup_response( space, 15, resp );
557         akiko_setup_response( state, 15, resp );
537558      }
538559   }
539560}
540561
541static void akiko_update_cdrom(address_space *space)
562static void akiko_update_cdrom(akiko_state *state)
542563{
543564   UINT8   resp[32], cmdbuf[32];
544565
545   if ( akiko.cdrom_status[0] & 0x10000000 )
566   if ( state->cdrom_status[0] & 0x10000000 )
546567      return;
547568
548   while ( akiko.cdrom_cmd_start != akiko.cdrom_cmd_end )
569   while ( state->cdrom_cmd_start != state->cdrom_cmd_end )
549570   {
550      UINT32   cmd_addr = akiko.cdrom_address[1] + 0x200 + akiko.cdrom_cmd_start;
551      int      cmd = space->read_byte( cmd_addr );
571      UINT32   cmd_addr = state->cdrom_address[1] + 0x200 + state->cdrom_cmd_start;
572      int      cmd = state->space->read_byte( cmd_addr );
552573
553574      memset( resp, 0, sizeof( resp ) );
554575      resp[0] = cmd;
r9192r9193
561582      {
562583         resp[1] = 0x00;
563584
564         if ( akiko_cdda_getstatus(space->machine, NULL) == 0x11 )
585         if ( akiko_cdda_getstatus(state, NULL) == 0x11 )
565586            resp[1] = 0x08;
566587
567         akiko_cdda_pause( space->machine, 1 );
588         akiko_cdda_pause(state, 1);
568589
569         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
590         state->cdrom_cmd_start = (state->cdrom_cmd_start+2) & 0xff;
570591
571         akiko_setup_response( space, 2, resp );
592         akiko_setup_response( state, 2, resp );
572593      }
573594      else if ( cmd == 0x03 ) /* unpause audio (and check audiocd playing status) */
574595      {
575596         resp[1] = 0x00;
576597
577         if ( akiko_cdda_getstatus(space->machine, NULL) == 0x11 )
598         if ( akiko_cdda_getstatus(state, NULL) == 0x11 )
578599            resp[1] = 0x08;
579600
580         akiko_cdda_pause( space->machine, 0 );
601         akiko_cdda_pause(state, 0);
581602
582         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
603         state->cdrom_cmd_start = (state->cdrom_cmd_start+2) & 0xff;
583604
584         akiko_setup_response( space, 2, resp );
605         akiko_setup_response( state, 2, resp );
585606      }
586607      else if ( cmd == 0x04 ) /* seek/read/play cd multi command */
587608      {
r9192r9193
590611
591612         for( i = 0; i < 13; i++ )
592613         {
593            cmdbuf[i] = space->read_byte( cmd_addr );
614            cmdbuf[i] = state->space->read_byte( cmd_addr );
594615            cmd_addr &= 0xffffff00;
595            cmd_addr += ( akiko.cdrom_cmd_start + i + 1 ) & 0xff;
616            cmd_addr += ( state->cdrom_cmd_start + i + 1 ) & 0xff;
596617         }
597618
598         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+13) & 0xff;
619         state->cdrom_cmd_start = (state->cdrom_cmd_start+13) & 0xff;
599620
600         if ( akiko.cdrom == NULL || akiko.cdrom_numtracks == 0 )
621         if ( state->cdrom == NULL || state->cdrom_numtracks == 0 )
601622         {
602623            resp[1] = 0x80;
603            akiko_setup_response( space, 2, resp );
624            akiko_setup_response( state, 2, resp );
604625         }
605626         else
606627         {
607628            startpos = lba_from_triplet( &cmdbuf[1] );
608629            endpos = lba_from_triplet( &cmdbuf[4] );
609630
610            akiko_cdda_stop(space->machine);
631            akiko_cdda_stop(state);
611632
612633            resp[1] = 0x00;
613634
614635            if ( cmdbuf[7] == 0x80 )
615636            {
616               if (LOG_AKIKO_CD) logerror( "%s:AKIKO CD: Data read - start lba: %08x - end lba: %08x\n", cpuexec_describe_context(space->machine), startpos, endpos );
617               akiko.cdrom_speed = (cmdbuf[8] & 0x40) ? 2 : 1;
618               akiko.cdrom_lba_start = startpos;
619               akiko.cdrom_lba_end = endpos;
637               if (LOG_AKIKO_CD) logerror( "%s:AKIKO CD: Data read - start lba: %08x - end lba: %08x\n", cpuexec_describe_context(state->machine), startpos, endpos );
638               state->cdrom_speed = (cmdbuf[8] & 0x40) ? 2 : 1;
639               state->cdrom_lba_start = startpos;
640               state->cdrom_lba_end = endpos;
620641
621642               resp[1] = 0x02;
622643            }
623644            else if ( cmdbuf[10] & 0x04 )
624645            {
625646               logerror( "AKIKO CD: Audio Play - start lba: %08x - end lba: %08x\n", startpos, endpos );
626               akiko_cdda_play( space->machine, startpos, endpos - startpos );
647               akiko_cdda_play(state, startpos, endpos - startpos);
627648               resp[1] = 0x08;
628649            }
629650            else
630651            {
631652               if (LOG_AKIKO_CD) logerror( "AKIKO CD: Seek - start lba: %08x - end lba: %08x\n", startpos, endpos );
632               akiko.cdrom_track_index = 0;
653               state->cdrom_track_index = 0;
633654
634               for( i = 0; i < cdrom_get_last_track(akiko.cdrom); i++ )
655               for( i = 0; i < cdrom_get_last_track(state->cdrom); i++ )
635656               {
636                  if ( startpos <= cdrom_get_track_start( akiko.cdrom, i ) )
657                  if ( startpos <= cdrom_get_track_start( state->cdrom, i ) )
637658                  {
638659                     /* reset to 0 */
639                     akiko.cdrom_track_index = i + 2;
640                     akiko.cdrom_track_index %= akiko.cdrom_numtracks;
660                     state->cdrom_track_index = i + 2;
661                     state->cdrom_track_index %= state->cdrom_numtracks;
641662                     break;
642663                  }
643664               }
644665            }
645666
646            akiko_setup_response( space, 2, resp );
667            akiko_setup_response( state, 2, resp );
647668         }
648669      }
649670      else if ( cmd == 0x05 ) /* read toc */
650671      {
651         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+3) & 0xff;
672         state->cdrom_cmd_start = (state->cdrom_cmd_start+3) & 0xff;
652673
653         timer_set( space->machine, ATTOTIME_IN_MSEC(1), NULL, resp[0], akiko_cd_delayed_cmd );
674         timer_set( state->machine, ATTOTIME_IN_MSEC(1), state, resp[0], akiko_cd_delayed_cmd );
654675
655676         break;
656677      }
r9192r9193
660681
661682         resp[1] = 0x00;
662683
663         (void)akiko_cdda_getstatus( space->machine, &lba );
684         (void)akiko_cdda_getstatus(state, &lba);
664685
665686         if ( lba > 0 )
666687         {
r9192r9193
669690            UINT32   track;
670691            int      addrctrl;
671692
672            track = cdrom_get_track(akiko.cdrom, lba);
673            addrctrl = cdrom_get_adr_control(akiko.cdrom, track);
693            track = cdrom_get_track(state->cdrom, lba);
694            addrctrl = cdrom_get_adr_control(state->cdrom, track);
674695
675696            resp[2] = 0x00;
676697            resp[3] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
r9192r9193
678699            resp[5] = 0; /* index */
679700
680701            disk_pos = lba_to_msf(lba);
681            track_pos = lba_to_msf(lba - cdrom_get_track_start(akiko.cdrom, track));
702            track_pos = lba_to_msf(lba - cdrom_get_track_start(state->cdrom, track));
682703
683704            /* track position */
684705            resp[6] = (track_pos >> 16) & 0xff;
r9192r9193
696717            resp[1] = 0x80;
697718         }
698719
699         akiko_setup_response( space, 15, resp );
720         akiko_setup_response( state, 15, resp );
700721      }
701722      else if ( cmd == 0x07 )   /* check door status */
702723      {
703724         resp[1] = 0x01;
704725
705         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
726         state->cdrom_cmd_start = (state->cdrom_cmd_start+2) & 0xff;
706727
707         if ( akiko.cdrom == NULL || akiko.cdrom_numtracks == 0 )
728         if ( state->cdrom == NULL || state->cdrom_numtracks == 0 )
708729            resp[1] = 0x80;
709730
710         akiko_setup_response( space, 20, resp );
731         akiko_setup_response( state, 20, resp );
711732         break;
712733      }
713734      else
r9192r9193
717738   }
718739}
719740
720READ32_HANDLER(amiga_akiko32_r)
741READ32_DEVICE_HANDLER( amiga_akiko32_r )
721742{
743   akiko_state *state = get_safe_token(device);
744   address_space *space = state->space;
722745   UINT32      retval;
723746
724747   if ( LOG_AKIKO && offset < (0x30/4) )
r9192r9193
729752   switch( offset )
730753   {
731754      case 0x00/4:   /* ID */
732         if ( akiko.cdrom != NULL ) cdda_set_cdrom(space->machine->device("cdda"), akiko.cdrom);
755         if ( state->cdrom != NULL ) cdda_set_cdrom(space->machine->device("cdda"), state->cdrom);
733756         return 0x0000cafe;
734757
735758      case 0x04/4:   /* CDROM STATUS 1 */
736         return akiko.cdrom_status[0];
759         return state->cdrom_status[0];
737760
738761      case 0x08/4:   /* CDROM STATUS 2 */
739         return akiko.cdrom_status[1];
762         return state->cdrom_status[1];
740763
741764      case 0x10/4:   /* CDROM ADDRESS 1 */
742         return akiko.cdrom_address[0];
765         return state->cdrom_address[0];
743766
744767      case 0x14/4:   /* CDROM ADDRESS 2 */
745         return akiko.cdrom_address[1];
768         return state->cdrom_address[1];
746769
747770      case 0x18/4:   /* CDROM COMMAND 1 */
748         akiko_update_cdrom(space);
749         retval = akiko.cdrom_cmd_start;
771         akiko_update_cdrom(state);
772         retval = state->cdrom_cmd_start;
750773         retval <<= 8;
751         retval |= akiko.cdrom_cmd_resp;
774         retval |= state->cdrom_cmd_resp;
752775         retval <<= 8;
753776         return retval;
754777
755778      case 0x1C/4:   /* CDROM COMMAND 2 */
756         akiko_update_cdrom(space);
757         retval = akiko.cdrom_cmd_end;
779         akiko_update_cdrom(state);
780         retval = state->cdrom_cmd_end;
758781         retval <<= 16;
759782         return retval;
760783
761784      case 0x20/4:   /* CDROM DMA SECTOR READ MASK */
762         retval = akiko.cdrom_readmask << 16;
785         retval = state->cdrom_readmask << 16;
763786         return retval;
764787
765788      case 0x24/4:   /* CDROM DMA ENABLE? */
766         retval = akiko.cdrom_dmacontrol;
789         retval = state->cdrom_dmacontrol;
767790         return retval;
768791
769792      case 0x30/4:   /* NVRAM */
770         return akiko_nvram_read(space->machine);
793         return akiko_nvram_read(state);
771794
772795      case 0x38/4:   /* C2P */
773         return akiko_c2p_read();
796         return akiko_c2p_read(state);
774797
775798      default:
776799         break;
r9192r9193
779802   return 0;
780803}
781804
782WRITE32_HANDLER(amiga_akiko32_w)
805WRITE32_DEVICE_HANDLER( amiga_akiko32_w )
783806{
807   akiko_state *state = get_safe_token(device);
808   address_space *space = state->space;
809
784810   if ( LOG_AKIKO && offset < (0x30/4) )
785811   {
786812      logerror( "Writing AKIKO reg %0x [%s] with %08x at PC=%06x\n", offset, get_akiko_reg_name(offset), data, cpu_get_pc(space->cpu) );
r9192r9193
789815   switch( offset )
790816   {
791817      case 0x04/4:   /* CDROM STATUS 1 */
792         akiko.cdrom_status[0] = data;
818         state->cdrom_status[0] = data;
793819         break;
794820
795821      case 0x08/4:   /* CDROM STATUS 2 */
796         akiko.cdrom_status[1] = data;
797         akiko.cdrom_status[0] &= data;
822         state->cdrom_status[1] = data;
823         state->cdrom_status[0] &= data;
798824         break;
799825
800826      case 0x10/4:   /* CDROM ADDRESS 1 */
801         akiko.cdrom_address[0] = data;
827         state->cdrom_address[0] = data;
802828         break;
803829
804830      case 0x14/4:   /* CDROM ADDRESS 2 */
805         akiko.cdrom_address[1] = data;
831         state->cdrom_address[1] = data;
806832         break;
807833
808834      case 0x18/4:   /* CDROM COMMAND 1 */
809835         if ( ACCESSING_BITS_16_23 )
810            akiko.cdrom_cmd_start = ( data >> 16 ) & 0xff;
836            state->cdrom_cmd_start = ( data >> 16 ) & 0xff;
811837
812838         if ( ACCESSING_BITS_8_15 )
813            akiko.cdrom_cmd_resp = ( data >> 8 ) & 0xff;
839            state->cdrom_cmd_resp = ( data >> 8 ) & 0xff;
814840
815         akiko_update_cdrom(space);
841         akiko_update_cdrom(state);
816842         break;
817843
818844      case 0x1C/4:   /* CDROM COMMAND 2 */
819845         if ( ACCESSING_BITS_16_23 )
820            akiko.cdrom_cmd_end = ( data >> 16 ) & 0xff;
846            state->cdrom_cmd_end = ( data >> 16 ) & 0xff;
821847
822         akiko_update_cdrom(space);
848         akiko_update_cdrom(state);
823849         break;
824850
825851      case 0x20/4:   /* CDROM DMA SECTOR READ REQUEST WRITE */
826852         if (LOG_AKIKO_CD) logerror( "Read Req mask W: data %08x - mem mask %08x\n", data, mem_mask );
827853         if ( ACCESSING_BITS_16_31 )
828854         {
829            akiko.cdrom_readreqmask = (data >> 16);
830            akiko.cdrom_readmask = 0;
855            state->cdrom_readreqmask = (data >> 16);
856            state->cdrom_readmask = 0;
831857         }
832858         break;
833859
834860      case 0x24/4:   /* CDROM DMA ENABLE? */
835861         if (LOG_AKIKO_CD) logerror( "DMA enable W: data %08x - mem mask %08x\n", data, mem_mask );
836         if ( ( akiko.cdrom_dmacontrol ^ data ) & 0x04000000 )
862         if ( ( state->cdrom_dmacontrol ^ data ) & 0x04000000 )
837863         {
838864            if ( data & 0x04000000 )
839               akiko_start_dma();
865               akiko_start_dma(state);
840866         }
841         akiko.cdrom_dmacontrol = data;
867         state->cdrom_dmacontrol = data;
842868         break;
843869
844870      case 0x30/4:
845         akiko_nvram_write(space->machine, data);
871         akiko_nvram_write(state, data);
846872         break;
847873
848874      case 0x38/4:
849         akiko_c2p_write(data);
875         akiko_c2p_write(state, data);
850876         break;
851877
852878      default:
853879         break;
854880   }
855881}
882
883/*-------------------------------------------------
884    device definition
885-------------------------------------------------*/
886
887static const char DEVTEMPLATE_SOURCE[] = __FILE__;
888
889#define DEVTEMPLATE_ID(p,s)      p##akiko##s
890#define DEVTEMPLATE_FEATURES   DT_HAS_START | DT_HAS_STOP
891#define DEVTEMPLATE_NAME      "Akiko"
892#define DEVTEMPLATE_FAMILY      "Amiga"
893#include "devtempl.h"
894
895
896DEFINE_LEGACY_DEVICE(AKIKO, akiko);
src/mame/machine/playch10.c
r9192r9193
11#include "emu.h"
22#include "video/ppu2c0x.h"
33#include "machine/rp5h01.h"
4#include "machine/nvram.h"
45#include "includes/playch10.h"
56
67/* prototypes */
r9192r9193
9192      set_videoram_bank(machine, 0, 8, 0, 8);
9293   else pc10_set_videorom_bank(machine, 0, 8, 0, 8);
9394
95   nvram_device *nvram = machine->device<nvram_device>("nvram");
96   if (nvram != NULL)
97      nvram->set_base(memory_region( machine, "cart" ) + 0x6000, 0x1000);
9498}
9599
96100MACHINE_START( playch10_hboard )
src/mame/machine/amiga.c
r9192r9193
4242
4343/*************************************
4444 *
45 *  Type definitions
46 *
47 *************************************/
48
49typedef struct _autoconfig_device autoconfig_device;
50struct _autoconfig_device
51{
52   autoconfig_device *      next;
53   amiga_autoconfig_device   device;
54   offs_t               base;
55};
56
57
58
59/*************************************
60 *
6145 *  Globals
6246 *
6347 *************************************/
6448
65UINT16 *amiga_chip_ram;
66UINT32 *amiga_chip_ram32;
67size_t amiga_chip_ram_size;
68
69UINT16 *amiga_custom_regs;
70UINT16 *amiga_expansion_ram;
71UINT16 *amiga_autoconfig_mem;
72
73static const amiga_machine_interface *amiga_intf;
74
75static autoconfig_device *autoconfig_list;
76static autoconfig_device *cur_autoconfig;
77static emu_timer * amiga_irq_timer;
78static emu_timer * amiga_blitter_timer;
79
8049const char *const amiga_custom_names[0x100] =
8150{
8251   /* 0x000 */
r9192r9193
183152 *
184153 *************************************/
185154
186UINT16 (*amiga_chip_ram_r)(offs_t offset);
187void (*amiga_chip_ram_w)(offs_t offset, UINT16 data);
188
189static UINT16 amiga_chip_ram16_r(offs_t offset)
155static UINT16 amiga_chip_ram16_r(amiga_state *state, offs_t offset)
190156{
191   extern const amiga_machine_interface *amiga_intf;
192   offset &= amiga_intf->chip_ram_mask;
193   return (offset < amiga_chip_ram_size) ? amiga_chip_ram[offset/2] : 0xffff;
157   offset &= state->intf->chip_ram_mask;
158   return (offset < state->chip_ram_size) ? state->chip_ram[offset/2] : 0xffff;
194159}
195160
196static UINT16 amiga_chip_ram32_r(offs_t offset)
161static UINT16 amiga_chip_ram32_r(amiga_state *state, offs_t offset)
197162{
198   extern const amiga_machine_interface *amiga_intf;
199   offset &= amiga_intf->chip_ram_mask;
163   offset &= state->intf->chip_ram_mask;
200164
201   if ( offset < amiga_chip_ram_size )
165   if (offset < state->chip_ram_size)
202166   {
167      UINT32 *amiga_chip_ram32 = (UINT32 *)state->chip_ram;
203168      UINT32   dat = amiga_chip_ram32[offset / 4];
204169
205170      if ( offset & 2 )
r9192r9193
211176   return 0xffff;
212177}
213178
214static void amiga_chip_ram16_w(offs_t offset, UINT16 data)
179static void amiga_chip_ram16_w(amiga_state *state, offs_t offset, UINT16 data)
215180{
216   extern const amiga_machine_interface *amiga_intf;
217   offset &= amiga_intf->chip_ram_mask;
181   offset &= state->intf->chip_ram_mask;
218182
219   if (offset < amiga_chip_ram_size)
220      amiga_chip_ram[offset/2] = data;
183   if (offset < state->chip_ram_size)
184      state->chip_ram[offset/2] = data;
221185}
222186
223static void amiga_chip_ram32_w(offs_t offset, UINT16 data)
187static void amiga_chip_ram32_w(amiga_state *state, offs_t offset, UINT16 data)
224188{
225   extern const amiga_machine_interface *amiga_intf;
226   offset &= amiga_intf->chip_ram_mask;
189   offset &= state->intf->chip_ram_mask;
227190
228   if ( offset < amiga_chip_ram_size )
191   if (offset < state->chip_ram_size)
229192   {
193      UINT32 *amiga_chip_ram32 = (UINT32 *)state->chip_ram;
230194      UINT32   dat = amiga_chip_ram32[offset / 4];
231195
232196      if ( offset & 2 )
r9192r9193
245209}
246210
247211
248void amiga_chip_ram_w8(offs_t offset, UINT8 data)
212void amiga_chip_ram_w8(amiga_state *state, offs_t offset, UINT8 data)
249213{
250214   UINT16 dat;
251215
252   dat = amiga_chip_ram_r(offset);
216   dat = (*state->chip_ram_r)(state, offset);
253217   if (offset & 0x01)
254218   {
255219      dat &= 0xff00;
r9192r9193
260224      dat &= 0x00ff;
261225      dat |= ((UINT16)data) << 8;
262226   }
263   amiga_chip_ram_w(offset,dat);
227   (*state->chip_ram_w)(state, offset, dat);
264228}
265229
266230/*************************************
r9192r9193
271235
272236void amiga_machine_config(running_machine *machine, const amiga_machine_interface *intf)
273237{
274   amiga_intf = intf;
238   amiga_state *state = machine->driver_data<amiga_state>();
239   state->intf = intf;
275240
276241   /* setup chipmem handlers */
277242   if ( IS_AGA(intf) )
278243   {
279      amiga_chip_ram_r = amiga_chip_ram32_r;
280      amiga_chip_ram_w = amiga_chip_ram32_w;
244      state->chip_ram_r = amiga_chip_ram32_r;
245      state->chip_ram_w = amiga_chip_ram32_w;
281246   }
282247   else
283248   {
284      amiga_chip_ram_r = amiga_chip_ram16_r;
285      amiga_chip_ram_w = amiga_chip_ram16_w;
249      state->chip_ram_r = amiga_chip_ram16_r;
250      state->chip_ram_w = amiga_chip_ram16_w;
286251   }
287252
288253   /* setup the timers */
289   amiga_irq_timer = timer_alloc(machine, amiga_irq_proc, NULL);
290   amiga_blitter_timer = timer_alloc(machine, amiga_blitter_proc, NULL);
254   state->irq_timer = timer_alloc(machine, amiga_irq_proc, NULL);
255   state->blitter_timer = timer_alloc(machine, amiga_blitter_proc, NULL);
256
257   state->sound_device = machine->device("amiga");
291258}
292259
293260
294261static void amiga_m68k_reset(running_device *device)
295262{
263   amiga_state *state = device->machine->driver_data<amiga_state>();
296264   address_space *space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM);
297265
298266   logerror("Executed RESET at PC=%06x\n", cpu_get_pc(space->cpu));
r9192r9193
304272   autoconfig_reset(device->machine);
305273
306274   /* set the overlay bit */
307   if ( IS_AGA(amiga_intf) )
275   if ( IS_AGA(state->intf) )
308276   {
309277      space->write_byte( 0xbfa001, 1 );
310278   }
r9192r9193
317285
318286MACHINE_RESET( amiga )
319287{
288   amiga_state *state = machine->driver_data<amiga_state>();
289
320290   /* set m68k reset  function */
321291   m68k_set_reset_callback(machine->device("maincpu"), amiga_m68k_reset);
322292
323293   amiga_m68k_reset(machine->device("maincpu"));
324294
325295   /* call the system-specific callback */
326   if (amiga_intf->reset_callback)
327      (*amiga_intf->reset_callback)(machine);
296   if (state->intf->reset_callback)
297      (*state->intf->reset_callback)(machine);
328298
329299   /* start the scanline timer */
330300   timer_set(machine, machine->primary_screen->time_until_pos(0), NULL, 0, scanline_callback);
r9192r9193
340310
341311static TIMER_CALLBACK( scanline_callback )
342312{
313   amiga_state *state = machine->driver_data<amiga_state>();
343314   int scanline = param;
344315   running_device *cia_0 = machine->device("cia_0");
345316   running_device *cia_1 = machine->device("cia_1");
r9192r9193
354325      mos6526_tod_w(cia_0, 1);
355326
356327      /* call the system-specific callback */
357      if (amiga_intf->scanline0_callback != NULL)
358         (*amiga_intf->scanline0_callback)(machine);
328      if (state->intf->scanline0_callback != NULL)
329         (*state->intf->scanline0_callback)(machine);
359330   }
360331
361332   /* on every scanline, clock the second CIA TOD */
r9192r9193
364335   /* render up to this scanline */
365336   if (!machine->primary_screen->update_partial(scanline))
366337   {
367      if (IS_AGA(amiga_intf))
338      if (IS_AGA(state->intf))
368339         amiga_aga_render_scanline(machine, NULL, scanline);
369340      else
370341         amiga_render_scanline(machine, NULL, scanline);
371342   }
372343
373344   /* force a sound update */
374   amiga_audio_update();
345   amiga_audio_update(state->sound_device);
375346
376347   /* set timer for next line */
377348   scanline = (scanline + 1) % machine->primary_screen->height();
r9192r9193
388359
389360static void update_irqs(running_machine *machine)
390361{
362   amiga_state *state = machine->driver_data<amiga_state>();
391363   int ints = CUSTOM_REG(REG_INTENA) & CUSTOM_REG(REG_INTREQ);
392364
393365   /* Master interrupt switch */
r9192r9193
425397
426398static TIMER_CALLBACK( amiga_irq_proc )
427399{
400   amiga_state *state = machine->driver_data<amiga_state>();
401
428402   update_irqs(machine);
429   timer_reset( amiga_irq_timer, attotime_never);
403   timer_reset( state->irq_timer, attotime_never);
430404}
431405
432406
r9192r9193
459433 *
460434 *************************************/
461435
462static UINT32 blit_ascending(void)
436static UINT32 blit_ascending(amiga_state *state)
463437{
464438   UINT32 shifta = (CUSTOM_REG(REG_BLTCON0) >> 12) & 0xf;
465439   UINT32 shiftb = (CUSTOM_REG(REG_BLTCON1) >> 12) & 0xf;
r9192r9193
482456         /* fetch data for A */
483457         if (CUSTOM_REG(REG_BLTCON0) & 0x0800)
484458         {
485            CUSTOM_REG(REG_BLTADAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTAPTH));
459            CUSTOM_REG(REG_BLTADAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTAPTH));
486460            CUSTOM_REG_LONG(REG_BLTAPTH) += 2;
487461         }
488462
489463         /* fetch data for B */
490464         if (CUSTOM_REG(REG_BLTCON0) & 0x0400)
491465         {
492            CUSTOM_REG(REG_BLTBDAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTBPTH));
466            CUSTOM_REG(REG_BLTBDAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTBPTH));
493467            CUSTOM_REG_LONG(REG_BLTBPTH) += 2;
494468         }
495469
496470         /* fetch data for C */
497471         if (CUSTOM_REG(REG_BLTCON0) & 0x0200)
498472         {
499            CUSTOM_REG(REG_BLTCDAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTCPTH));
473            CUSTOM_REG(REG_BLTCDAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTCPTH));
500474            CUSTOM_REG_LONG(REG_BLTCPTH) += 2;
501475         }
502476
r9192r9193
552526         /* write to the destination */
553527         if (CUSTOM_REG(REG_BLTCON0) & 0x0100)
554528         {
555            amiga_chip_ram_w(CUSTOM_REG_LONG(REG_BLTDPTH), tempd);
529            (*state->chip_ram_w)(state, CUSTOM_REG_LONG(REG_BLTDPTH), tempd);
556530            CUSTOM_REG_LONG(REG_BLTDPTH) += 2;
557531         }
558532      }
r9192r9193
580554 *
581555 *************************************/
582556
583static UINT32 blit_descending(void)
557static UINT32 blit_descending(amiga_state *state)
584558{
585559   UINT32 fill_exclusive = (CUSTOM_REG(REG_BLTCON1) >> 4);
586560   UINT32 fill_inclusive = (CUSTOM_REG(REG_BLTCON1) >> 3);
r9192r9193
607581         /* fetch data for A */
608582         if (CUSTOM_REG(REG_BLTCON0) & 0x0800)
609583         {
610            CUSTOM_REG(REG_BLTADAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTAPTH));
584            CUSTOM_REG(REG_BLTADAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTAPTH));
611585            CUSTOM_REG_LONG(REG_BLTAPTH) -= 2;
612586         }
613587
614588         /* fetch data for B */
615589         if (CUSTOM_REG(REG_BLTCON0) & 0x0400)
616590         {
617            CUSTOM_REG(REG_BLTBDAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTBPTH));
591            CUSTOM_REG(REG_BLTBDAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTBPTH));
618592            CUSTOM_REG_LONG(REG_BLTBPTH) -= 2;
619593         }
620594
621595         /* fetch data for C */
622596         if (CUSTOM_REG(REG_BLTCON0) & 0x0200)
623597         {
624            CUSTOM_REG(REG_BLTCDAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTCPTH));
598            CUSTOM_REG(REG_BLTCDAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTCPTH));
625599            CUSTOM_REG_LONG(REG_BLTCPTH) -= 2;
626600         }
627601
r9192r9193
694668         /* write to the destination */
695669         if (CUSTOM_REG(REG_BLTCON0) & 0x0100)
696670         {
697            amiga_chip_ram_w(CUSTOM_REG_LONG(REG_BLTDPTH), tempd);
671            (*state->chip_ram_w)(state, CUSTOM_REG_LONG(REG_BLTDPTH), tempd);
698672            CUSTOM_REG_LONG(REG_BLTDPTH) -= 2;
699673         }
700674      }
r9192r9193
761735    BLTAMOD = 4 * (dy - dx) and BLTBMOD = 4 * dy.
762736*/
763737
764static UINT32 blit_line(void)
738static UINT32 blit_line(amiga_state *state)
765739{
766740   UINT32 singlemode = (CUSTOM_REG(REG_BLTCON1) & 0x0002) ? 0x0000 : 0xffff;
767741   UINT32 singlemask = 0xffff;
r9192r9193
786760
787761      /* fetch data for C */
788762      if (CUSTOM_REG(REG_BLTCON0) & 0x0200)
789         CUSTOM_REG(REG_BLTCDAT) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BLTCPTH));
763         CUSTOM_REG(REG_BLTCDAT) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BLTCPTH));
790764
791765      /* rotate the A data according to the shift */
792766      tempa = CUSTOM_REG(REG_BLTADAT) >> (CUSTOM_REG(REG_BLTCON0) >> 12);
r9192r9193
837811      blitsum |= tempd;
838812
839813      /* write to the destination */
840      amiga_chip_ram_w(CUSTOM_REG_LONG(REG_BLTDPTH), tempd);
814      (*state->chip_ram_w)(state, CUSTOM_REG_LONG(REG_BLTDPTH), tempd);
841815
842816      /* always increment along the major axis */
843817      if (CUSTOM_REG(REG_BLTCON1) & 0x0010)
r9192r9193
914888
915889static TIMER_CALLBACK( amiga_blitter_proc )
916890{
891   amiga_state *state = machine->driver_data<amiga_state>();
917892   UINT32 blitsum = 0;
918893
919894   /* logging */
r9192r9193
938913   switch (CUSTOM_REG(REG_BLTCON1) & 0x0003)
939914   {
940915      case 0:   /* ascending */
941         blitsum = blit_ascending();
916         blitsum = blit_ascending(state);
942917         break;
943918
944919      case 2:   /* descending */
945         blitsum = blit_descending();
920         blitsum = blit_descending(state);
946921         break;
947922
948923      case 1:   /* line */
949924      case 3:
950         blitsum = blit_line();
925         blitsum = blit_line(state);
951926         break;
952927   }
953928
r9192r9193
962937   amiga_custom_w(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), REG_INTREQ, 0x8000 | INTENA_BLIT, 0xffff);
963938
964939   /* reset the blitter timer */
965   timer_reset( amiga_blitter_timer, attotime_never);
940   timer_reset( state->blitter_timer, attotime_never);
966941}
967942
968943
r9192r9193
975950
976951static void blitter_setup(address_space *space)
977952{
953   amiga_state *state = space->machine->driver_data<amiga_state>();
978954   int ticks, width, height, blittime;
979955
980956   /* is there another blitting in progress? */
r9192r9193
1019995   }
1020996
1021997   /* AGA has twice the bus bandwidth, so blits take half the time */
1022   if ( IS_AGA(amiga_intf) )
998   if ( IS_AGA(state->intf) )
1023999      blittime /= 2;
10241000
10251001   /* signal blitter busy */
10261002   CUSTOM_REG(REG_DMACON) |= 0x4000;
10271003
10281004   /* set a timer */
1029   timer_adjust_oneshot( amiga_blitter_timer, downcast<cpu_device *>(space->cpu)->cycles_to_attotime( blittime ), 0);
1005   timer_adjust_oneshot( state->blitter_timer, downcast<cpu_device *>(space->cpu)->cycles_to_attotime( blittime ), 0);
10301006}
10311007
10321008
r9192r9193
11321108
11331109static void custom_reset(running_machine *machine)
11341110{
1111   amiga_state *state = machine->driver_data<amiga_state>();
11351112   int clock = cputag_get_clock(machine, "maincpu");
11361113   UINT16   vidmode = (clock == AMIGA_68000_NTSC_CLOCK || clock == AMIGA_68EC020_NTSC_CLOCK ) ? 0x1000 : 0x0000; /* NTSC or PAL? */
11371114
r9192r9193
11411118   CUSTOM_REG(REG_VPOSR) = vidmode;
11421119   CUSTOM_REG(REG_SERDATR) = 0x3000;
11431120
1144   switch (amiga_intf->chip_ram_mask)
1121   switch (state->intf->chip_ram_mask)
11451122   {
11461123      case ANGUS_CHIP_RAM_MASK:
11471124      case FAT_ANGUS_CHIP_RAM_MASK:
r9192r9193
11511128      case ECS_CHIP_RAM_MASK:
11521129         CUSTOM_REG(REG_VPOSR) |= 0x2000;
11531130         CUSTOM_REG(REG_DENISEID) = 0x00FC;
1154         if (IS_AGA(amiga_intf))
1131         if (IS_AGA(state->intf))
11551132         {
11561133            CUSTOM_REG(REG_VPOSR) |= 0x0300;
11571134            CUSTOM_REG(REG_DENISEID) = 0x00F8;
r9192r9193
11701147
11711148READ16_HANDLER( amiga_custom_r )
11721149{
1150   amiga_state *state = space->machine->driver_data<amiga_state>();
11731151   UINT16 temp;
11741152
11751153   switch (offset & 0xff)
r9192r9193
11821160
11831161      case REG_VPOSR:
11841162         CUSTOM_REG(REG_VPOSR) &= 0xff00;
1185         if (IS_AGA(amiga_intf))
1186            CUSTOM_REG(REG_VPOSR) |= amiga_aga_gethvpos(*space->machine->primary_screen) >> 16;
1187         else
1188            CUSTOM_REG(REG_VPOSR) |= amiga_gethvpos(*space->machine->primary_screen) >> 16;
1163         CUSTOM_REG(REG_VPOSR) |= amiga_gethvpos(*space->machine->primary_screen) >> 16;
11891164         return CUSTOM_REG(REG_VPOSR);
11901165
11911166      case REG_VHPOSR:
1192         if (IS_AGA(amiga_intf))
1193            return amiga_aga_gethvpos(*space->machine->primary_screen) & 0xffff;
1194         else
1195            return amiga_gethvpos(*space->machine->primary_screen) & 0xffff;
1167         return amiga_gethvpos(*space->machine->primary_screen) & 0xffff;
11961168
11971169      case REG_SERDATR:
11981170         CUSTOM_REG(REG_SERDATR) &= ~0x4000;
r9192r9193
12001172         return CUSTOM_REG(REG_SERDATR);
12011173
12021174      case REG_JOY0DAT:
1203         if (amiga_intf->joy0dat_r != NULL)
1204            return (*amiga_intf->joy0dat_r)(space->machine);
1175         if (state->intf->joy0dat_r != NULL)
1176            return (*state->intf->joy0dat_r)(space->machine);
12051177         return input_port_read_safe(space->machine, "JOY0DAT", 0xffff);
12061178
12071179      case REG_JOY1DAT:
1208         if (amiga_intf->joy1dat_r != NULL)
1209            return (*amiga_intf->joy1dat_r)(space->machine);
1180         if (state->intf->joy1dat_r != NULL)
1181            return (*state->intf->joy1dat_r)(space->machine);
12101182         return input_port_read_safe(space->machine, "JOY1DAT", 0xffff);
12111183
12121184      case REG_ADKCONR:
r9192r9193
12221194         return input_port_read_safe(space->machine, "POT1DAT", 0x0000);
12231195
12241196      case REG_DSKBYTR:
1225         if (amiga_intf->dskbytr_r != NULL)
1226            return (*amiga_intf->dskbytr_r)(space->machine);
1197         if (state->intf->dskbytr_r != NULL)
1198            return (*state->intf->dskbytr_r)(space->machine);
12271199         return 0x0000;
12281200
12291201      case REG_INTENAR:
r9192r9193
12331205         return CUSTOM_REG(REG_INTREQ);
12341206
12351207      case REG_COPJMP1:
1236         if (IS_AGA(amiga_intf))
1237            aga_copper_setpc(CUSTOM_REG_LONG(REG_COP1LCH));
1238         else
1239            copper_setpc(CUSTOM_REG_LONG(REG_COP1LCH));
1208         amiga_copper_setpc(space->machine, CUSTOM_REG_LONG(REG_COP1LCH));
12401209         break;
12411210
12421211      case REG_COPJMP2:
1243         if (IS_AGA(amiga_intf))
1244            aga_copper_setpc(CUSTOM_REG_LONG(REG_COP2LCH));
1245         else
1246            copper_setpc(CUSTOM_REG_LONG(REG_COP2LCH));
1212         amiga_copper_setpc(space->machine, CUSTOM_REG_LONG(REG_COP2LCH));
12471213         break;
12481214
12491215      case REG_CLXDAT:
r9192r9193
12711237
12721238static TIMER_CALLBACK( finish_serial_write )
12731239{
1240   amiga_state *state = machine->driver_data<amiga_state>();
1241
12741242   /* mark the transfer buffer empty */
12751243   CUSTOM_REG(REG_SERDATR) |= 0x3000;
12761244
r9192r9193
12811249
12821250WRITE16_HANDLER( amiga_custom_w )
12831251{
1252   amiga_state *state = space->machine->driver_data<amiga_state>();
12841253   running_device *cia_0;
12851254   running_device *cia_1;
12861255   UINT16 temp;
r9192r9193
12991268         break;
13001269
13011270      case REG_DSKLEN:
1302         if (amiga_intf->dsklen_w != NULL)
1303            (*amiga_intf->dsklen_w)(space->machine, data);
1271         if (state->intf->dsklen_w != NULL)
1272            (*state->intf->dsklen_w)(space->machine, data);
13041273         break;
13051274
13061275      case REG_POTGO:
1307         if (amiga_intf->potgo_w != NULL)
1308            (*amiga_intf->potgo_w)(space->machine, data);
1276         if (state->intf->potgo_w != NULL)
1277            (*state->intf->potgo_w)(space->machine, data);
13091278         break;
13101279
13111280      case REG_SERDAT:
1312         if (amiga_intf->serdat_w != NULL)
1313            (*amiga_intf->serdat_w)(space->machine, data);
1281         if (state->intf->serdat_w != NULL)
1282            (*state->intf->serdat_w)(space->machine, data);
13141283         CUSTOM_REG(REG_SERDATR) &= ~0x3000;
13151284         timer_set(space->machine, amiga_get_serial_char_period(space->machine), NULL, 0, finish_serial_write);
13161285         break;
r9192r9193
13251294         break;
13261295
13271296      case REG_BLTSIZV:   /* ECS-AGA only */
1328         if ( IS_ECS_OR_AGA(amiga_intf) )
1297         if ( IS_ECS_OR_AGA(state->intf) )
13291298         {
13301299            CUSTOM_REG(REG_BLTSIZV) = data & 0x7fff;
13311300            if ( CUSTOM_REG(REG_BLTSIZV) == 0 ) CUSTOM_REG(REG_BLTSIZV) = 0x8000;
r9192r9193
13331302         break;
13341303
13351304      case REG_BLTSIZH:   /* ECS-AGA only */
1336         if ( IS_ECS_OR_AGA(amiga_intf) )
1305         if ( IS_ECS_OR_AGA(state->intf) )
13371306         {
13381307            CUSTOM_REG(REG_BLTSIZH) = data & 0x7ff;
13391308            if ( CUSTOM_REG(REG_BLTSIZH) == 0 ) CUSTOM_REG(REG_BLTSIZH) = 0x800;
r9192r9193
13421311         break;
13431312
13441313      case REG_BLTCON0L:   /* ECS-AGA only */
1345         if ( IS_ECS_OR_AGA(amiga_intf) )
1314         if ( IS_ECS_OR_AGA(state->intf) )
13461315         {
13471316            CUSTOM_REG(REG_BLTCON0) &= 0xff00;
13481317            CUSTOM_REG(REG_BLTCON0) |= data & 0xff;
r9192r9193
13511320
13521321      case REG_SPR0PTH:   case REG_SPR1PTH:   case REG_SPR2PTH:   case REG_SPR3PTH:
13531322      case REG_SPR4PTH:   case REG_SPR5PTH:   case REG_SPR6PTH:   case REG_SPR7PTH:
1354         data &= ( amiga_intf->chip_ram_mask >> 16 );
1323         data &= ( state->intf->chip_ram_mask >> 16 );
13551324         break;
13561325
13571326      case REG_SPR0PTL:   case REG_SPR1PTL:   case REG_SPR2PTL:   case REG_SPR3PTL:
13581327      case REG_SPR4PTL:   case REG_SPR5PTL:   case REG_SPR6PTL:   case REG_SPR7PTL:
1359         if (IS_AGA(amiga_intf))
1360            amiga_aga_sprite_dma_reset((offset - REG_SPR0PTL) / 2);
1361         else
1362            amiga_sprite_dma_reset((offset - REG_SPR0PTL) / 2);
1328         amiga_sprite_dma_reset(space->machine, (offset - REG_SPR0PTL) / 2);
13631329         break;
13641330
13651331      case REG_SPR0CTL:   case REG_SPR1CTL:   case REG_SPR2CTL:   case REG_SPR3CTL:
13661332      case REG_SPR4CTL:   case REG_SPR5CTL:   case REG_SPR6CTL:   case REG_SPR7CTL:
13671333         /* disable comparitor on writes here */
1368         if (IS_AGA(amiga_intf))
1369            amiga_aga_sprite_enable_comparitor((offset - REG_SPR0CTL) / 4, FALSE);
1370         else
1371            amiga_sprite_enable_comparitor((offset - REG_SPR0CTL) / 4, FALSE);
1334         amiga_sprite_enable_comparitor(space->machine, (offset - REG_SPR0CTL) / 4, FALSE);
13721335         break;
13731336
13741337      case REG_SPR0DATA:   case REG_SPR1DATA:   case REG_SPR2DATA:   case REG_SPR3DATA:
13751338      case REG_SPR4DATA:   case REG_SPR5DATA:   case REG_SPR6DATA:   case REG_SPR7DATA:
13761339         /* enable comparitor on writes here */
1377         if (IS_AGA(amiga_intf))
1378            amiga_aga_sprite_enable_comparitor((offset - REG_SPR0DATA) / 4, TRUE);
1379         else
1380            amiga_sprite_enable_comparitor((offset - REG_SPR0DATA) / 4, TRUE);
1340         amiga_sprite_enable_comparitor(space->machine, (offset - REG_SPR0DATA) / 4, TRUE);
13811341         break;
13821342
13831343      case REG_COP1LCH:   case REG_COP2LCH:
1384         data &= ( amiga_intf->chip_ram_mask >> 16 );
1344         data &= ( state->intf->chip_ram_mask >> 16 );
13851345         break;
13861346
13871347      case REG_COPJMP1:
1388         if (IS_AGA(amiga_intf))
1389            aga_copper_setpc(CUSTOM_REG_LONG(REG_COP1LCH));
1390         else
1391            copper_setpc(CUSTOM_REG_LONG(REG_COP1LCH));
1348         amiga_copper_setpc(space->machine, CUSTOM_REG_LONG(REG_COP1LCH));
13921349         break;
13931350
13941351      case REG_COPJMP2:
1395         if (IS_AGA(amiga_intf))
1396            aga_copper_setpc(CUSTOM_REG_LONG(REG_COP2LCH));
1397         else
1398            copper_setpc(CUSTOM_REG_LONG(REG_COP2LCH));
1352         amiga_copper_setpc(space->machine, CUSTOM_REG_LONG(REG_COP2LCH));
13991353         break;
14001354
14011355      case REG_DDFSTRT:
r9192r9193
14131367         break;
14141368
14151369      case REG_DMACON:
1416         amiga_audio_update();
1370         amiga_audio_update(state->sound_device);
14171371
14181372         /* bits BBUSY (14) and BZERO (13) are read-only */
14191373         data &= 0x9fff;
r9192r9193
14211375
14221376         /* if 'blitter-nasty' has been turned on and we have a blit pending, reschedule it */
14231377         if ( ( data & 0x400 ) && ( CUSTOM_REG(REG_DMACON) & 0x4000 ) )
1424            timer_adjust_oneshot( amiga_blitter_timer, downcast<cpu_device *>(space->cpu)->cycles_to_attotime( BLITTER_NASTY_DELAY ), 0);
1378            timer_adjust_oneshot( state->blitter_timer, downcast<cpu_device *>(space->cpu)->cycles_to_attotime( BLITTER_NASTY_DELAY ), 0);
14251379
14261380         break;
14271381
r9192r9193
14321386         CUSTOM_REG(offset) = data;
14331387
14341388         if ( temp & 0x8000  ) /* if we're enabling irq's, delay a bit */
1435            timer_adjust_oneshot( amiga_irq_timer, downcast<cpu_device *>(space->cpu)->cycles_to_attotime( AMIGA_IRQ_DELAY_CYCLES ), 0);
1389            timer_adjust_oneshot( state->irq_timer, downcast<cpu_device *>(space->cpu)->cycles_to_attotime( AMIGA_IRQ_DELAY_CYCLES ), 0);
14361390         else /* if we're disabling irq's, process right away */
14371391            update_irqs(space->machine);
14381392         break;
r9192r9193
14511405         CUSTOM_REG(offset) = data;
14521406
14531407         if ( temp & 0x8000  ) /* if we're generating irq's, delay a bit */
1454            timer_adjust_oneshot( amiga_irq_timer, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime( AMIGA_IRQ_DELAY_CYCLES ), 0);
1408            timer_adjust_oneshot( state->irq_timer, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime( AMIGA_IRQ_DELAY_CYCLES ), 0);
14551409         else /* if we're clearing irq's, process right away */
14561410            update_irqs(space->machine);
14571411         break;
14581412
14591413      case REG_ADKCON:
1460         amiga_audio_update();
1414         amiga_audio_update(state->sound_device);
14611415         data = (data & 0x8000) ? (CUSTOM_REG(offset) | (data & 0x7fff)) : (CUSTOM_REG(offset) & ~(data & 0x7fff));
14621416         break;
14631417
r9192r9193
14651419      case REG_AUD1LCL:   case REG_AUD1LCH:   case REG_AUD1LEN:   case REG_AUD1PER:   case REG_AUD1VOL:
14661420      case REG_AUD2LCL:   case REG_AUD2LCH:   case REG_AUD2LEN:   case REG_AUD2PER:   case REG_AUD2VOL:
14671421      case REG_AUD3LCL:   case REG_AUD3LCH:   case REG_AUD3LEN:   case REG_AUD3PER:   case REG_AUD3VOL:
1468         amiga_audio_update();
1422         amiga_audio_update(state->sound_device);
14691423         break;
14701424
14711425      case REG_AUD0DAT:   case REG_AUD1DAT:   case REG_AUD2DAT:   case REG_AUD3DAT:
1472         amiga_audio_data_w((offset - REG_AUD0DAT) / 8, data);
1426         amiga_audio_data_w(state->sound_device, (offset - REG_AUD0DAT) / 8, data);
14731427         break;
14741428
14751429      case REG_BPL1PTH:   case REG_BPL2PTH:   case REG_BPL3PTH:   case REG_BPL4PTH:
14761430      case REG_BPL5PTH:   case REG_BPL6PTH:
1477         data &= ( amiga_intf->chip_ram_mask >> 16 );
1431         data &= ( state->intf->chip_ram_mask >> 16 );
14781432         break;
14791433
14801434      case REG_BPLCON0:
r9192r9193
14941448      case REG_COLOR20:   case REG_COLOR21:   case REG_COLOR22:   case REG_COLOR23:
14951449      case REG_COLOR24:   case REG_COLOR25:   case REG_COLOR26:   case REG_COLOR27:
14961450      case REG_COLOR28:   case REG_COLOR29:   case REG_COLOR30:   case REG_COLOR31:
1497         if ( IS_AGA(amiga_intf))
1451         if (IS_AGA(state->intf))
14981452         {
1499            aga_palette_write(offset - REG_COLOR00, data);
1453            amiga_aga_palette_write(space->machine, offset - REG_COLOR00, data);
15001454         }
15011455         else
15021456         {
r9192r9193
15061460         break;
15071461      case REG_DIWSTRT:
15081462      case REG_DIWSTOP:
1509         if (IS_AGA(amiga_intf))
1510            aga_diwhigh_written(0);
1463         if (IS_AGA(state->intf))
1464            amiga_aga_diwhigh_written(space->machine, 0);
15111465         break;
15121466      case REG_DIWHIGH:
1513         if (IS_AGA(amiga_intf))
1514            aga_diwhigh_written(1);
1467         if (IS_AGA(state->intf))
1468            amiga_aga_diwhigh_written(space->machine, 1);
15151469         break;
15161470
15171471      default:
15181472         break;
15191473   }
15201474
1521   if (IS_AGA(amiga_intf))
1475   if (IS_AGA(state->intf))
15221476      CUSTOM_REG(offset) = data;
15231477   else
15241478      if (offset <= REG_COLOR31)
r9192r9193
15351489
15361490void amiga_serial_in_w(running_machine *machine, UINT16 data)
15371491{
1492   amiga_state *state = machine->driver_data<amiga_state>();
15381493   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
15391494   int mask = (CUSTOM_REG(REG_SERPER) & 0x8000) ? 0x1ff : 0xff;
15401495
r9192r9193
15561511
15571512attotime amiga_get_serial_char_period(running_machine *machine)
15581513{
1514   amiga_state *state = machine->driver_data<amiga_state>();
15591515   UINT32 divisor = (CUSTOM_REG(REG_SERPER) & 0x7fff) + 1;
15601516   UINT32 baud = cputag_get_clock(machine, "maincpu") / 2 / divisor;
15611517   UINT32 numbits = 2 + ((CUSTOM_REG(REG_SERPER) & 0x8000) ? 9 : 8);
r9192r9193
15721528
15731529void amiga_add_autoconfig(running_machine *machine, const amiga_autoconfig_device *device)
15741530{
1531   amiga_state *state = machine->driver_data<amiga_state>();
15751532   autoconfig_device *dev, **d;
15761533
15771534   /* validate the data */
r9192r9193
15811538   /* allocate memory and link it in at the end of the list */
15821539   dev = auto_alloc(machine, autoconfig_device);
15831540   dev->next = NULL;
1584   for (d = &autoconfig_list; *d; d = &(*d)->next) ;
1541   for (d = &state->autoconfig_list; *d; d = &(*d)->next) ;
15851542   *d = dev;
15861543
15871544   /* fill in the data */
r9192r9193
15991556
16001557static void autoconfig_reset(running_machine *machine)
16011558{
1559   amiga_state *state = machine->driver_data<amiga_state>();
16021560   autoconfig_device *dev;
16031561
16041562   /* uninstall any installed devices */
1605   for (dev = autoconfig_list; dev; dev = dev->next)
1563   for (dev = state->autoconfig_list; dev; dev = dev->next)
16061564      if (dev->base && dev->device.uninstall)
16071565      {
16081566         (*dev->device.uninstall)(machine, dev->base);
r9192r9193
16101568      }
16111569
16121570   /* reset the current autoconfig */
1613   cur_autoconfig = autoconfig_list;
1571   state->cur_autoconfig = state->autoconfig_list;
16141572}
16151573
16161574
r9192r9193
16231581
16241582READ16_HANDLER( amiga_autoconfig_r )
16251583{
1584   amiga_state *state = space->machine->driver_data<amiga_state>();
1585   autoconfig_device *cur_autoconfig = state->cur_autoconfig;
16261586   UINT8 byte;
16271587   int i;
16281588
r9192r9193
17601720
17611721WRITE16_HANDLER( amiga_autoconfig_w )
17621722{
1723   amiga_state *state = space->machine->driver_data<amiga_state>();
1724   autoconfig_device *cur_autoconfig = state->cur_autoconfig;
17631725   int move_to_next = FALSE;
17641726
17651727   logerror("autoconfig_w(%02X) = %04X & %04X\n", offset, data, mem_mask);
r9192r9193
17971759      logerror("Install to %06X\n", cur_autoconfig->base);
17981760      if (cur_autoconfig->base && cur_autoconfig->device.install)
17991761         (*cur_autoconfig->device.install)(space->machine, cur_autoconfig->base);
1800      cur_autoconfig = cur_autoconfig->next;
1762      state->cur_autoconfig = cur_autoconfig->next;
18011763   }
18021764}
18031765
r9192r9193
18091771 *
18101772 *************************************/
18111773
1812const amiga_machine_interface *amiga_get_interface(void)
1774const amiga_machine_interface *amiga_get_interface(running_machine *machine)
18131775{
1814   return amiga_intf;
1776   return machine->driver_data<amiga_state>()->intf;
18151777}
src/mame/machine/atarigen.h
r9192r9193
183183WRITE32_HANDLER( atarigen_eeprom32_w );
184184READ32_HANDLER( atarigen_eeprom_upper32_r );
185185
186NVRAM_HANDLER( atarigen );
187186
188
189187/*---------------------------------------------------------------
190188    SLAPSTIC HANDLING
191189---------------------------------------------------------------*/
src/mame/includes/amiga.h
r9192r9193
1313#include "devlegcy.h"
1414
1515
16/*************************************
17 *
18 *  Debugging
19 *
20 *************************************/
21
22#define LOG_COPPER         0
23#define GUESS_COPPER_OFFSET   0
24#define LOG_SPRITE_DMA      0
25
1626/* A bit of a trick here: some registers are 32-bit. In order to efficiently */
1727/* read them on both big-endian and little-endian systems, we store the custom */
1828/* registers in 32-bit natural order. This means we need to XOR the register */
1929/* address with 1 on little-endian systems. */
20#define CUSTOM_REG(x)         (amiga_custom_regs[BYTE_XOR_BE(x)])
30#define CUSTOM_REG(x)         (state->custom_regs[BYTE_XOR_BE(x)])
2131#define CUSTOM_REG_SIGNED(x)   ((INT16)CUSTOM_REG(x))
22#define CUSTOM_REG_LONG(x)      (*(UINT32 *)&amiga_custom_regs[x])
32#define CUSTOM_REG_LONG(x)      (*(UINT32 *)&state->custom_regs[x])
2333
2434/*
2535    A = Angus
r9192r9193
354364   void      (*uninstall)(running_machine *machine, offs_t base); /* memory uninstallation */
355365};
356366
367typedef struct _autoconfig_device autoconfig_device;
368struct _autoconfig_device
369{
370   autoconfig_device *      next;
371   amiga_autoconfig_device   device;
372   offs_t               base;
373};
357374
358/*----------- defined in machine/amiga.c -----------*/
375class amiga_state : public driver_device
376{
377public:
378   amiga_state(running_machine &machine, const driver_device_config_base &config)
379      : driver_device(machine, config) { }
359380
360extern UINT16 *amiga_chip_ram;
361extern UINT32 *amiga_chip_ram32;
362extern size_t amiga_chip_ram_size;
381   UINT16 *chip_ram;
382   size_t chip_ram_size;
383   UINT16 (*chip_ram_r)(amiga_state *state, offs_t offset);
384   void (*chip_ram_w)(amiga_state *state, offs_t offset, UINT16 data);
385   UINT16 *custom_regs;
363386
364extern UINT16 *amiga_custom_regs;
365extern UINT16 *amiga_expansion_ram;
366extern UINT16 *amiga_autoconfig_mem;
387   const amiga_machine_interface *intf;
388   autoconfig_device *autoconfig_list;
389   autoconfig_device *cur_autoconfig;
390   emu_timer * irq_timer;
391   emu_timer * blitter_timer;
392   running_device *sound_device;
367393
394   /* sprite states */
395   UINT8 sprite_comparitor_enable_mask;
396   UINT8 sprite_dma_reload_mask;
397   UINT8 sprite_dma_live_mask;
398   UINT8 sprite_ctl_written;
399   UINT32 sprite_shiftreg[8];
400   UINT8 sprite_remain[8];
401
402   /* copper states */
403   UINT32 copper_pc;
404   UINT8 copper_waiting;
405   UINT8 copper_waitblit;
406   UINT16 copper_waitval;
407   UINT16 copper_waitmask;
408   UINT16 copper_pending_offset;
409   UINT16 copper_pending_data;
410#if GUESS_COPPER_OFFSET
411   int wait_offset;
412#endif
413
414   /* playfield states */
415   int last_scanline;
416   int ham_color;
417
418   /* misc states */
419   UINT16 genlock_color;
420
421   /* separate 6 in-order bitplanes into 2 x 3-bit bitplanes in two nibbles */
422   UINT8 separate_bitplanes[2][64];
423
424   /* aga */
425   int aga_diwhigh_written;
426   pen_t aga_palette[256];
427   UINT64 aga_bpldat[8];
428   UINT16 aga_sprdata[8][4];
429   UINT16 aga_sprdatb[8][4];
430   int aga_sprite_fetched_words;
431   int aga_sprite_dma_used_words[8];
432};
433
434
435/*----------- defined in machine/amiga.c -----------*/
436
368437extern const char *const amiga_custom_names[0x100];
369438
370extern UINT16 (*amiga_chip_ram_r)(offs_t offset);
371extern void (*amiga_chip_ram_w)(offs_t offset, UINT16 data);
372extern void amiga_chip_ram_w8(offs_t offset, UINT8 data);
439extern void amiga_chip_ram_w8(amiga_state *state, offs_t offset, UINT8 data);
373440
374441void amiga_machine_config(running_machine *machine, const amiga_machine_interface *intf);
375442
r9192r9193
393460void amiga_cia_0_irq(running_device *device, int state);
394461void amiga_cia_1_irq(running_device *device, int state);
395462
396const amiga_machine_interface *amiga_get_interface(void);
463const amiga_machine_interface *amiga_get_interface(running_machine *machine);
397464
398465
399466/*----------- defined in audio/amiga.c -----------*/
400467
401468DECLARE_LEGACY_SOUND_DEVICE(AMIGA, amiga_sound);
402469
403void amiga_audio_update(void);
404void amiga_audio_data_w(int which, UINT16 data);
470void amiga_audio_update(running_device *device);
471void amiga_audio_data_w(running_device *device, int which, UINT16 data);
405472
406473
407474/*----------- defined in video/amiga.c -----------*/
408475
476extern const UINT16 amiga_expand_byte[256];
477
409478PALETTE_INIT( amiga );
410479VIDEO_START( amiga );
411480VIDEO_UPDATE( amiga );
412481
482void amiga_copper_setpc(running_machine *machine, UINT32 pc);
483int amiga_copper_execute_next(running_machine *machine, int xpos);
484
413485UINT32 amiga_gethvpos(screen_device &screen);
414void copper_setpc(UINT32 pc);
415void amiga_set_genlock_color(UINT16 color);
486void amiga_set_genlock_color(running_machine *machine, UINT16 color);
416487void amiga_render_scanline(running_machine *machine, bitmap_t *bitmap, int scanline);
417void amiga_sprite_dma_reset(int which);
418void amiga_sprite_enable_comparitor(int which, int enable);
488void amiga_sprite_dma_reset(running_machine *machine, int which);
489void amiga_sprite_enable_comparitor(running_machine *machine, int which, int enable);
419490
420491/*----------- defined in video/amigaaga.c -----------*/
421492
422493VIDEO_START( amiga_aga );
423494VIDEO_UPDATE( amiga_aga );
424495
425UINT32 amiga_aga_gethvpos(screen_device &screen);
426void aga_copper_setpc(UINT32 pc);
427void amiga_aga_set_genlock_color(UINT16 color);
428496void amiga_aga_render_scanline(running_machine *machine, bitmap_t *bitmap, int scanline);
429void amiga_aga_sprite_dma_reset(int which);
430void amiga_aga_sprite_enable_comparitor(int which, int enable);
431void aga_palette_write(int color_reg, UINT16 data);
432void aga_diwhigh_written(int written);
497void amiga_aga_palette_write(running_machine *machine, int color_reg, UINT16 data);
498void amiga_aga_diwhigh_written(running_machine *machine, int written);
433499
434500#endif /* __AMIGA_H__ */
src/mame/includes/leland.h
r9192r9193
7171
7272WRITE8_HANDLER( leland_battery_ram_w );
7373WRITE8_HANDLER( ataxx_battery_ram_w );
74NVRAM_HANDLER( leland );
7574
7675READ8_HANDLER( leland_master_analog_key_r );
7776WRITE8_HANDLER( leland_master_analog_key_w );
src/mame/includes/ssv.h
r9192r9193
2020   UINT16 irq_enable;
2121   UINT16 *mainram;
2222
23   UINT16 *nvram;
24   size_t nvram_size;
2523   UINT16 *dsp_ram;
2624
2725   UINT16 *eaglshot_gfxram;
src/mame/includes/cubocd32.h
r9192r9193
77#ifndef __CUBOCD32_H__
88#define __CUBOCD32_H__
99
10class cubocd32_state : public amiga_state
11{
12public:
13   cubocd32_state(running_machine &machine, const driver_device_config_base &config)
14      : amiga_state(machine, config) { }
15
16   UINT16 potgo_value;
17   int cd32_shifter[2];
18   void (*input_hack)(running_machine *machine);
19   int oldstate[2];
20};
21
1022/*----------- defined in machine/cubocd32.c -----------*/
1123
12extern void amiga_akiko_init(running_machine* machine);
13extern READ32_HANDLER(amiga_akiko32_r);
14extern WRITE32_HANDLER(amiga_akiko32_w);
24READ32_DEVICE_HANDLER( amiga_akiko32_r );
25WRITE32_DEVICE_HANDLER( amiga_akiko32_w );
1526
27DECLARE_LEGACY_DEVICE(AKIKO, akiko);
28
1629#endif /* __CUBOCD32_H__ */
src/mame/includes/namcos2.h
r9192r9193
148148/**************************************************************/
149149#define NAMCOS2_68K_eeprom_W   namcos2_68k_eeprom_w
150150#define NAMCOS2_68K_eeprom_R   namcos2_68k_eeprom_r
151NVRAM_HANDLER( namcos2 );
152151WRITE16_HANDLER( namcos2_68k_eeprom_w );
153152READ16_HANDLER( namcos2_68k_eeprom_r );
154153
src/mame/video/amiga.c
r9192r9193
1313
1414/*************************************
1515 *
16 *  Debugging
17 *
18 *************************************/
19
20#define LOG_COPPER         0
21#define GUESS_COPPER_OFFSET   0
22#define LOG_SPRITE_DMA      0
23
24
25
26/*************************************
27 *
2816 *  Macros
2917 *
3018 *************************************/
r9192r9193
3523
3624/*************************************
3725 *
38 *  Statics
39 *
40 *************************************/
41
42/* sprite states */
43static UINT8 sprite_comparitor_enable_mask;
44static UINT8 sprite_dma_reload_mask;
45static UINT8 sprite_dma_live_mask;
46static UINT32 sprite_shiftreg[8];
47static UINT8 sprite_remain[8];
48
49/* playfield states */
50static int last_scanline;
51static UINT16 ham_color;
52
53/* copper states */
54static UINT32 copper_pc;
55static UINT8 copper_waiting;
56static UINT8 copper_waitblit;
57static UINT16 copper_waitval;
58static UINT16 copper_waitmask;
59static UINT16 copper_pending_offset;
60static UINT16 copper_pending_data;
61
62/* misc states */
63static UINT16 genlock_color;
64
65#if GUESS_COPPER_OFFSET
66static int wait_offset = 3;
67#endif
68
69
70
71/*************************************
72 *
7326 *  Tables
7427 *
7528 *************************************/
7629
7730/* expand an 8-bit bit pattern into 16 bits, every other bit */
78static const UINT16 expand_byte[256] =
31const UINT16 amiga_expand_byte[256] =
7932{
8033   0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015,
8134   0x0040, 0x0041, 0x0044, 0x0045, 0x0050, 0x0051, 0x0054, 0x0055,
r9192r9193
11265   0x5540, 0x5541, 0x5544, 0x5545, 0x5550, 0x5551, 0x5554, 0x5555
11366};
11467
115/* separate 6 in-order bitplanes into 2 x 3-bit bitplanes in two nibbles */
116static UINT8 separate_bitplanes[2][64];
11768
11869
119
12070/*************************************
12171 *
12272 *  4-4-4 palette init
r9192r9193
14191
14292VIDEO_START( amiga )
14393{
94   amiga_state *state = machine->driver_data<amiga_state>();
14495   int j;
14596
14697   /* generate tables that produce the correct playfield color for dual playfield mode */
r9192r9193
149100      int pf1pix = ((j >> 0) & 1) | ((j >> 1) & 2) | ((j >> 2) & 4);
150101      int pf2pix = ((j >> 1) & 1) | ((j >> 2) & 2) | ((j >> 3) & 4);
151102
152      separate_bitplanes[0][j] = (pf1pix || !pf2pix) ? pf1pix : (pf2pix + 8);
153      separate_bitplanes[1][j] = pf2pix ? (pf2pix + 8) : pf1pix;
103      state->separate_bitplanes[0][j] = (pf1pix || !pf2pix) ? pf1pix : (pf2pix + 8);
104      state->separate_bitplanes[1][j] = pf2pix ? (pf2pix + 8) : pf1pix;
154105   }
155106
107#if GUESS_COPPER_OFFSET
108   state->wait_offset = 3;
109#endif
110
156111   /* reset the genlock color */
157   genlock_color = 0xffff;
112   state->genlock_color = 0xffff;
113
114   state->sprite_ctl_written = 0;
158115}
159116
160117
r9192r9193
167124
168125UINT32 amiga_gethvpos(screen_device &screen)
169126{
170   UINT32 hvpos = (last_scanline << 8) | (screen.hpos() >> 2);
127   amiga_state *state = screen.machine->driver_data<amiga_state>();
128   UINT32 hvpos = (state->last_scanline << 8) | (screen.hpos() >> 2);
171129   UINT32 latchedpos = input_port_read_safe(screen.machine, "HVPOS", 0);
172130
173131   /* if there's no latched position, or if we are in the active display area */
174132   /* but before the latching point, return the live HV position */
175   if ((CUSTOM_REG(REG_BPLCON0) & 0x0008) == 0 || latchedpos == 0 || (last_scanline >= 20 && hvpos < latchedpos))
133   if ((CUSTOM_REG(REG_BPLCON0) & 0x0008) == 0 || latchedpos == 0 || (state->last_scanline >= 20 && hvpos < latchedpos))
176134      return hvpos;
177135
178136   /* otherwise, return the latched position */
r9192r9193
187145 *
188146 *************************************/
189147
190void amiga_set_genlock_color(UINT16 color)
148void amiga_set_genlock_color(running_machine *machine, UINT16 color)
191149{
192   genlock_color = color;
150   amiga_state *state = machine->driver_data<amiga_state>();
151
152   state->genlock_color = color;
193153}
194154
195155
r9192r9193
200160 *
201161 *************************************/
202162
203void copper_setpc(UINT32 pc)
163void amiga_copper_setpc(running_machine *machine, UINT32 pc)
204164{
165   amiga_state *state = machine->driver_data<amiga_state>();
166
205167   if (LOG_COPPER)
206168      logerror("copper_setpc(%06x)\n", pc);
207169
208   copper_pc = pc;
209   copper_waiting = FALSE;
170   state->copper_pc = pc;
171   state->copper_waiting = FALSE;
210172}
211173
212174
213static int copper_execute_next(running_machine *machine, int xpos)
175int amiga_copper_execute_next(running_machine *machine, int xpos)
214176{
177   amiga_state *state = machine->driver_data<amiga_state>();
215178   int word0, word1;
216179
217180   /* bail if not enabled */
r9192r9193
219182      return 511;
220183
221184   /* flush any pending writes */
222   if (copper_pending_offset)
185   if (state->copper_pending_offset)
223186   {
224187      if (LOG_COPPER)
225         logerror("%02X.%02X: Write to %s = %04x\n", last_scanline, xpos / 2, amiga_custom_names[copper_pending_offset & 0xff], copper_pending_data);
188         logerror("%02X.%02X: Write to %s = %04x\n", state->last_scanline, xpos / 2, amiga_custom_names[state->copper_pending_offset & 0xff], state->copper_pending_data);
226189
227      amiga_custom_w(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), copper_pending_offset, copper_pending_data, 0xffff);
228      copper_pending_offset = 0;
190      amiga_custom_w(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), state->copper_pending_offset, state->copper_pending_data, 0xffff);
191      state->copper_pending_offset = 0;
229192   }
230193
231194   /* if we're waiting, check for a breakthrough */
232   if (copper_waiting)
195   if (state->copper_waiting)
233196   {
234      int curpos = (last_scanline << 8) | (xpos >> 1);
197      int curpos = (state->last_scanline << 8) | (xpos >> 1);
235198
236199      /* if we're past the wait time, stop it and hold up 2 cycles */
237      if ((curpos & copper_waitmask) >= (copper_waitval & copper_waitmask) &&
238         (!copper_waitblit || !(CUSTOM_REG(REG_DMACON) & DMACON_BBUSY)))
200      if ((curpos & state->copper_waitmask) >= (state->copper_waitval & state->copper_waitmask) &&
201         (!state->copper_waitblit || !(CUSTOM_REG(REG_DMACON) & DMACON_BBUSY)))
239202      {
240         copper_waiting = FALSE;
203         state->copper_waiting = FALSE;
241204#if GUESS_COPPER_OFFSET
242         return xpos + COPPER_CYCLES_TO_PIXELS(1 + wait_offset);
205         return xpos + COPPER_CYCLES_TO_PIXELS(1 + state->wait_offset);
243206#else
244207         return xpos + COPPER_CYCLES_TO_PIXELS(1 + 3);
245208#endif
246209      }
247210
248211      /* otherwise, see if this line is even a possibility; if not, punt */
249      if (((curpos | 0xff) & copper_waitmask) < (copper_waitval & copper_waitmask))
212      if (((curpos | 0xff) & state->copper_waitmask) < (state->copper_waitval & state->copper_waitmask))
250213         return 511;
251214
252215      /* else just advance another pixel */
r9192r9193
255218   }
256219
257220   /* fetch the first data word */
258   word0 = amiga_chip_ram_r(copper_pc);
259   copper_pc += 2;
221   word0 = (*state->chip_ram_r)(state, state->copper_pc);
222   state->copper_pc += 2;
260223   xpos += COPPER_CYCLES_TO_PIXELS(1);
261224
262225   /* fetch the second data word */
263   word1 = amiga_chip_ram_r(copper_pc);
264   copper_pc += 2;
226   word1 = (*state->chip_ram_r)(state, state->copper_pc);
227   state->copper_pc += 2;
265228   xpos += COPPER_CYCLES_TO_PIXELS(1);
266229
267230   if (LOG_COPPER)
268      logerror("%02X.%02X: Copper inst @ %06x = %04x %04x\n", last_scanline, xpos / 2, copper_pc, word0, word1);
231      logerror("%02X.%02X: Copper inst @ %06x = %04x %04x\n", state->last_scanline, xpos / 2, state->copper_pc, word0, word1);
269232
270233   /* handle a move */
271234   if ((word0 & 1) == 0)
r9192r9193
278241      {
279242         /* write it at the *end* of this instruction's cycles */
280243         /* needed for Arcadia's Fast Break */
281         copper_pending_offset = word0;
282         copper_pending_data = word1;
244         state->copper_pending_offset = word0;
245         state->copper_pending_data = word1;
283246      }
284247
285248      /* illegal writes suspend until next frame */
286249      else
287250      {
288251         if (LOG_COPPER)
289            logerror("%02X.%02X: Aborting copper on illegal write\n", last_scanline, xpos / 2);
252            logerror("%02X.%02X: Aborting copper on illegal write\n", state->last_scanline, xpos / 2);
290253
291         copper_waitval = 0xffff;
292         copper_waitmask = 0xffff;
293         copper_waitblit = FALSE;
294         copper_waiting = TRUE;
254         state->copper_waitval = 0xffff;
255         state->copper_waitmask = 0xffff;
256         state->copper_waitblit = FALSE;
257         state->copper_waiting = TRUE;
295258         return 511;
296259      }
297260   }
298261   else
299262   {
300263      /* extract common wait/skip values */
301      copper_waitval = word0 & 0xfffe;
302      copper_waitmask = word1 | 0x8001;
303      copper_waitblit = (~word1 >> 15) & 1;
264      state->copper_waitval = word0 & 0xfffe;
265      state->copper_waitmask = word1 | 0x8001;
266      state->copper_waitblit = (~word1 >> 15) & 1;
304267
305268      /* handle a wait */
306269      if ((word1 & 1) == 0)
307270      {
308271         if (LOG_COPPER)
309            logerror("  Waiting for %04x & %04x (currently %04x)\n", copper_waitval, copper_waitmask, (last_scanline << 8) | (xpos >> 1));
272            logerror("  Waiting for %04x & %04x (currently %04x)\n", state->copper_waitval, state->copper_waitmask, (state->last_scanline << 8) | (xpos >> 1));
310273
311         copper_waiting = TRUE;
274         state->copper_waiting = TRUE;
312275      }
313276
314277      /* handle a skip */
315278      else
316279      {
317         int curpos = (last_scanline << 8) | (xpos >> 1);
280         int curpos = (state->last_scanline << 8) | (xpos >> 1);
318281
319282         if (LOG_COPPER)
320            logerror("  Skipping if %04x & %04x (currently %04x)\n", copper_waitval, copper_waitmask, (last_scanline << 8) | (xpos >> 1));
283            logerror("  Skipping if %04x & %04x (currently %04x)\n", state->copper_waitval, state->copper_waitmask, (state->last_scanline << 8) | (xpos >> 1));
321284
322285         /* if we're past the wait time, stop it and hold up 2 cycles */
323         if ((curpos & copper_waitmask) >= (copper_waitval & copper_waitmask) &&
324            (!copper_waitblit || !(CUSTOM_REG(REG_DMACON) & DMACON_BBUSY)))
286         if ((curpos & state->copper_waitmask) >= (state->copper_waitval & state->copper_waitmask) &&
287            (!state->copper_waitblit || !(CUSTOM_REG(REG_DMACON) & DMACON_BBUSY)))
325288         {
326289            if (LOG_COPPER)
327290               logerror("  Skipped\n");
328291
329292            /* count the cycles it out have taken to fetch the next instruction */
330            copper_pc += 4;
293            state->copper_pc += 4;
331294            xpos += COPPER_CYCLES_TO_PIXELS(2);
332295         }
333296      }
r9192r9193
345308 *
346309 *************************************/
347310
348void amiga_sprite_dma_reset(int which)
311void amiga_sprite_dma_reset(running_machine *machine, int which)
349312{
350   sprite_dma_reload_mask |= 1 << which;
351   sprite_dma_live_mask |= 1 << which;
313   amiga_state *state = machine->driver_data<amiga_state>();
314
315   if (LOG_SPRITE_DMA) logerror("sprite %d dma reset\n", which );
316   state->sprite_dma_reload_mask |= 1 << which;
317   state->sprite_dma_live_mask |= 1 << which;
352318}
353319
354320
355void amiga_sprite_enable_comparitor(int which, int enable)
321void amiga_sprite_enable_comparitor(running_machine *machine, int which, int enable)
356322{
323   amiga_state *state = machine->driver_data<amiga_state>();
324
325   if (LOG_SPRITE_DMA) logerror("sprite %d comparitor %sable\n", which, enable ? "en" : "dis" );
357326   if (enable)
358327   {
359      sprite_comparitor_enable_mask |= 1 << which;
360      sprite_dma_live_mask &= ~(1 << which);
328      state->sprite_comparitor_enable_mask |= 1 << which;
329      state->sprite_dma_live_mask &= ~(1 << which);
361330   }
362331   else
363      sprite_comparitor_enable_mask &= ~(1 << which);
332   {
333      state->sprite_comparitor_enable_mask &= ~(1 << which);
334      state->sprite_ctl_written |= (1 << which);
335   }
364336}
365337
366338
r9192r9193
371343 *
372344 *************************************/
373345
374static void update_sprite_dma(int scanline)
346INLINE void fetch_sprite_data(amiga_state *state, int scanline, int sprite)
375347{
348   CUSTOM_REG(REG_SPR0DATA + 4 * sprite) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
349   CUSTOM_REG(REG_SPR0DATB + 4 * sprite) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
350   CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
351   if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X\n", scanline, sprite, CUSTOM_REG(REG_SPR0DATA + 4 * sprite), CUSTOM_REG(REG_SPR0DATB + 4 * sprite));
352}
353
354static void update_sprite_dma(amiga_state *state, int scanline)
355{
376356   int dmaenable = (CUSTOM_REG(REG_DMACON) & (DMACON_SPREN | DMACON_DMAEN)) == (DMACON_SPREN | DMACON_DMAEN);
377357   int num, maxdma;
378358
r9192r9193
388368      int vstart, vstop;
389369
390370      /* if we are == VSTOP, fetch new control words */
391      if (dmaenable && (sprite_dma_live_mask & bitmask) && (sprite_dma_reload_mask & bitmask))
371      if (dmaenable && (state->sprite_dma_live_mask & bitmask) && (state->sprite_dma_reload_mask & bitmask))
392372      {
393373         /* disable the sprite */
394         sprite_comparitor_enable_mask &= ~bitmask;
395         sprite_dma_reload_mask &= ~bitmask;
374         state->sprite_comparitor_enable_mask &= ~bitmask;
375         state->sprite_dma_reload_mask &= ~bitmask;
396376
397377         /* fetch data into the control words */
398         CUSTOM_REG(REG_SPR0POS + 4 * num) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 0);
399         CUSTOM_REG(REG_SPR0CTL + 4 * num) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 2);
378         CUSTOM_REG(REG_SPR0POS + 4 * num) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 0);
379         CUSTOM_REG(REG_SPR0CTL + 4 * num) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 2);
400380         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) += 4;
401381         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: pos=%04X ctl=%04X\n", scanline, num, CUSTOM_REG(REG_SPR0POS + 4 * num), CUSTOM_REG(REG_SPR0CTL + 4 * num));
402382      }
r9192r9193
408388      /* if we hit vstart, enable the comparitor */
409389      if (scanline == vstart)
410390      {
411         sprite_comparitor_enable_mask |= 1 << num;
391         state->sprite_comparitor_enable_mask |= 1 << num;
412392         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d comparitor enable\n", scanline, num);
413393      }
414394
415395      /* if we hit vstop, disable the comparitor and trigger a reload for the next scanline */
416396      if (scanline == vstop)
417397      {
418         sprite_comparitor_enable_mask &= ~bitmask;
419         sprite_dma_reload_mask |= 1 << num;
398         state->sprite_ctl_written &= ~bitmask;
399         state->sprite_comparitor_enable_mask &= ~bitmask;
400         state->sprite_dma_reload_mask |= 1 << num;
420401         CUSTOM_REG(REG_SPR0DATA + 4 * num) = 0;      /* just a guess */
421402         CUSTOM_REG(REG_SPR0DATB + 4 * num) = 0;
422403         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d comparitor disable, prepare for reload\n", scanline, num);
423404      }
424405
425406      /* fetch data if this sprite is enabled */
426      if (dmaenable && (sprite_dma_live_mask & bitmask) && (sprite_comparitor_enable_mask & bitmask))
407      if (dmaenable && (state->sprite_dma_live_mask & bitmask) && (state->sprite_comparitor_enable_mask & bitmask))
427408      {
428         CUSTOM_REG(REG_SPR0DATA + 4 * num) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 0);
429         CUSTOM_REG(REG_SPR0DATB + 4 * num) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 2);
430         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) += 4;
431         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X\n", scanline, num, CUSTOM_REG(REG_SPR0DATA + 4 * num), CUSTOM_REG(REG_SPR0DATB + 4 * num));
409         fetch_sprite_data(state, scanline, num);
432410      }
433411   }
434412}
r9192r9193
443421
444422INLINE UINT32 interleave_sprite_data(UINT16 lobits, UINT16 hibits)
445423{
446   return (expand_byte[lobits & 0xff] << 0) | (expand_byte[lobits >> 8] << 16) |
447         (expand_byte[hibits & 0xff] << 1) | (expand_byte[hibits >> 8] << 17);
424   return (amiga_expand_byte[lobits & 0xff] << 0) | (amiga_expand_byte[lobits >> 8] << 16) |
425         (amiga_expand_byte[hibits & 0xff] << 1) | (amiga_expand_byte[hibits >> 8] << 17);
448426}
449427
450428
451static int get_sprite_pixel(int x)
429static int get_sprite_pixel(amiga_state *state, int x)
452430{
453431   int pixels = 0;
454432   int num, pair;
455433
456434   /* loop over sprite channels */
457435   for (num = 0; num < 8; num++)
458      if (sprite_comparitor_enable_mask & (1 << num))
436      if (state->sprite_comparitor_enable_mask & (1 << num))
459437      {
460438         /* if we're not currently clocking, check against hstart */
461         if (sprite_remain[num] == 0)
439         if (state->sprite_remain[num] == 0)
462440         {
463441            int hstart = ((CUSTOM_REG(REG_SPR0POS + 4 * num) & 0xff) << 1) | (CUSTOM_REG(REG_SPR0CTL + 4 * num) & 1);
464442            if (hstart == x)
465443            {
466               sprite_remain[num] = 16;
467               sprite_shiftreg[num] = interleave_sprite_data(CUSTOM_REG(REG_SPR0DATA + 4 * num), CUSTOM_REG(REG_SPR0DATB + 4 * num));
444               state->sprite_remain[num] = 16;
445               state->sprite_shiftreg[num] = interleave_sprite_data(CUSTOM_REG(REG_SPR0DATA + 4 * num), CUSTOM_REG(REG_SPR0DATB + 4 * num));
468446            }
469447         }
470448
471449         /* clock the next pixel if we're doing it */
472         if (sprite_remain[num] != 0)
450         if (state->sprite_remain[num] != 0)
473451         {
474            sprite_remain[num]--;
475            pixels |= (sprite_shiftreg[num] & 0xc0000000) >> (16 + 2 * (7 - num));
476            sprite_shiftreg[num] <<= 2;
452            state->sprite_remain[num]--;
453            pixels |= (state->sprite_shiftreg[num] & 0xc0000000) >> (16 + 2 * (7 - num));
454            state->sprite_shiftreg[num] <<= 2;
477455         }
478456      }
479457
r9192r9193
491469         0x0000, 0x0800, 0x2000, 0x2a00, 0x4000, 0x4c00, 0x7000, 0x7e00
492470      };
493471      int collide;
472      const int esprm = 0x10, osprm = 0x10;
494473
495474      /* OR the two sprite bits together so we only have 1 bit per sprite */
496475      collide = pixels | (pixels >> 1);
r9192r9193
513492                    sprite present bitmask in bits 6-9
514493                    topmost sprite pair index in bits 10-11
515494                */
495            UINT32 result = (collide << 6) | (pair << 10);
516496
517497            /* attached case */
518498            if (CUSTOM_REG(REG_SPR1CTL + 8 * pair) & 0x0080)
519               return (pixels & 0xf) | 0x10 | (collide << 6) | (pair << 10);
499               return (pixels & 0xf) | osprm | result;
520500
521501            /* lower-numbered sprite of pair */
522502            else if (pixels & 3)
523               return (pixels & 3) | 0x10 | (pair << 2) | (collide << 6) | (pair << 10);
503               return (pixels & 3) | esprm | (pair << 2) | result;
524504
525505            /* higher-numbered sprite of pair */
526506            else
527               return ((pixels >> 2) & 3) | 0x10 | (pair << 2) | (collide << 6) | (pair << 10);
507               return ((pixels >> 2) & 3) | osprm | (pair << 2) | result;
528508         }
529509   }
530510
r9192r9193
539519 *
540520 *************************************/
541521
542INLINE UINT8 assemble_odd_bitplanes(int planes, int obitoffs)
522INLINE UINT8 assemble_odd_bitplanes(amiga_state *state, int planes, int obitoffs)
543523{
544524   UINT8 pix = (CUSTOM_REG(REG_BPL1DAT) >> obitoffs) & 1;
545525   if (planes >= 3)
r9192r9193
552532}
553533
554534
555INLINE UINT8 assemble_even_bitplanes(int planes, int ebitoffs)
535INLINE UINT8 assemble_even_bitplanes(amiga_state *state, int planes, int ebitoffs)
556536{
557537   UINT8 pix = 0;
558538   if (planes >= 2)
r9192r9193
568548   return pix;
569549}
570550
551INLINE void fetch_bitplane_data(amiga_state *state, int plane)
552{
553   CUSTOM_REG(REG_BPL1DAT + plane) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2));
554   CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
555}
571556
572557
573558/*************************************
r9192r9193
576561 *
577562 *************************************/
578563
579INLINE int update_ham(int newpix)
564INLINE int update_ham(amiga_state *state, int newpix)
580565{
581566   switch (newpix >> 4)
582567   {
583568      case 0:
584         ham_color = CUSTOM_REG(REG_COLOR00 + (newpix & 0xf));
569         state->ham_color = CUSTOM_REG(REG_COLOR00 + (newpix & 0xf));
585570         break;
586571
587572      case 1:
588         ham_color = (ham_color & 0xff0) | ((newpix & 0xf) << 0);
573         state->ham_color = (state->ham_color & 0xff0) | ((newpix & 0xf) << 0);
589574         break;
590575
591576      case 2:
592         ham_color = (ham_color & 0x0ff) | ((newpix & 0xf) << 8);
577         state->ham_color = (state->ham_color & 0x0ff) | ((newpix & 0xf) << 8);
593578         break;
594579
595580      case 3:
596         ham_color = (ham_color & 0xf0f) | ((newpix & 0xf) << 4);
581         state->ham_color = (state->ham_color & 0xf0f) | ((newpix & 0xf) << 4);
597582         break;
598583   }
599   return ham_color;
584   return state->ham_color;
600585}
601586
602587
r9192r9193
609594
610595void amiga_render_scanline(running_machine *machine, bitmap_t *bitmap, int scanline)
611596{
597   amiga_state *state = machine->driver_data<amiga_state>();
612598   UINT16 save_color0 = CUSTOM_REG(REG_COLOR00);
613599   int ddf_start_pixel = 0, ddf_stop_pixel = 0;
614600   int hires = 0, dualpf = 0, lace = 0, ham = 0;
r9192r9193
624610   int edelay = 0, odelay = 0;
625611   int next_copper_x;
626612   int pl;
613   const int defbitoffs = 15;
627614
628   last_scanline = scanline;
615   state->last_scanline = scanline;
629616
630617   /* on the first scanline, reset the COPPER and HAM color */
631618   if (scanline == 0)
632619   {
633      copper_setpc(CUSTOM_REG_LONG(REG_COP1LCH));
634      ham_color = CUSTOM_REG(REG_COLOR00);
620      amiga_copper_setpc(machine, CUSTOM_REG_LONG(REG_COP1LCH));
621      state->ham_color = CUSTOM_REG(REG_COLOR00);
635622   }
636623
637624   /* update sprite data fetching */
638   update_sprite_dma(scanline);
625   update_sprite_dma(state, scanline);
639626
640627   /* start of a new line, signal we're not done with it and fill up vars */
641628   if (bitmap != NULL)
642629      dst = BITMAP_ADDR16(bitmap, scanline, 0);
643630
644631   /* all sprites off at the start of the line */
645   memset(sprite_remain, 0, sizeof(sprite_remain));
632   memset(state->sprite_remain, 0, sizeof(state->sprite_remain));
646633
647634   /* temporary set color 0 to the genlock color */
648   if (genlock_color != 0xffff)
649      CUSTOM_REG(REG_COLOR00) = genlock_color;
635   if (state->genlock_color != 0xffff)
636      CUSTOM_REG(REG_COLOR00) = state->genlock_color;
650637
651638   /* loop over the line */
652639   next_copper_x = 2;   /* copper runs on odd timeslots */
r9192r9193
659646      {
660647         /* execute the next batch, restoring and re-saving color 0 around it */
661648         CUSTOM_REG(REG_COLOR00) = save_color0;
662         next_copper_x = copper_execute_next(machine, x);
649         next_copper_x = amiga_copper_execute_next(machine, x);
663650         save_color0 = CUSTOM_REG(REG_COLOR00);
664         if (genlock_color != 0xffff)
665            CUSTOM_REG(REG_COLOR00) = genlock_color;
651         if (state->genlock_color != 0xffff)
652            CUSTOM_REG(REG_COLOR00) = state->genlock_color;
666653
667654         /* compute update-related register values */
668655         planes = (CUSTOM_REG(REG_BPLCON0) & (BPLCON0_BPU0 | BPLCON0_BPU1 | BPLCON0_BPU2)) >> 12;
r9192r9193
673660
674661         /* compute the pixel fetch parameters */
675662         ddf_start_pixel = ( CUSTOM_REG(REG_DDFSTRT) & 0xfc ) * 2 + (hires ? 9 : 17);
676         ddf_stop_pixel = ( CUSTOM_REG(REG_DDFSTOP) & 0xfc ) * 2 + (hires ? (9 + 15) : (17 + 15));
663         ddf_stop_pixel = ( CUSTOM_REG(REG_DDFSTOP) & 0xfc ) * 2 + (hires ? (9 + defbitoffs) : (17 + defbitoffs));
677664
678665         if ( ( CUSTOM_REG(REG_DDFSTRT) ^ CUSTOM_REG(REG_DDFSTOP) ) & 0x04 )
679666            ddf_stop_pixel += 8;
680667
681668         /* compute the horizontal start/stop */
682669         hstart = CUSTOM_REG(REG_DIWSTRT) & 0xff;
683         hstop = 0x100 + (CUSTOM_REG(REG_DIWSTOP) & 0xff);
670         hstop = (CUSTOM_REG(REG_DIWSTOP) & 0xff);
671         hstop |= 0x100;
684672
685673         /* compute the vertical start/stop */
686674         vstart = CUSTOM_REG(REG_DIWSTRT) >> 8;
687         vstop = (CUSTOM_REG(REG_DIWSTOP) >> 8) | ((~CUSTOM_REG(REG_DIWSTOP) >> 7) & 0x100);
675         vstop = (CUSTOM_REG(REG_DIWSTOP) >> 8);
676         vstop |= ((~CUSTOM_REG(REG_DIWSTOP) >> 7) & 0x100);
688677
689678         /* extract playfield priorities */
690679         pf1pri = CUSTOM_REG(REG_BPLCON2) & 7;
r9192r9193
708697
709698         if ( hires )
710699         {
711            obitoffs = 15 + ( odelay << 1 );
712            ebitoffs = 15 + ( edelay << 1 );
700            obitoffs = defbitoffs + ( odelay << 1 );
701            ebitoffs = defbitoffs + ( edelay << 1 );
713702         }
714703         else
715704         {
r9192r9193
719708               edelay = ( edelay + 8 ) & 0x0f;
720709            }
721710
722            obitoffs = 15 + odelay;
723            ebitoffs = 15 + edelay;
711            obitoffs = defbitoffs + odelay;
712            ebitoffs = defbitoffs + edelay;
724713         }
725714
726715         for (pl = 0; pl < 6; pl++)
r9192r9193
728717      }
729718
730719      /* need to run the sprite engine every pixel to ensure display */
731      sprpix = get_sprite_pixel(x);
720      sprpix = get_sprite_pixel(state, x);
732721
733722      /* to render, we must have bitplane DMA enabled, at least 1 plane, and be within the */
734723      /* vertical display window */
r9192r9193
741730         if (x >= ddf_start_pixel && x <= ddf_stop_pixel + odelay)
742731         {
743732            /* if we need to fetch more data, do it now */
744            if (obitoffs == 15)
733            if (obitoffs == defbitoffs)
734            {
745735               for (pl = 0; pl < planes; pl += 2)
746736               {
747                  CUSTOM_REG(REG_BPL1DAT + pl) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2));
748                  CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2) += 2;
737                  fetch_bitplane_data(state, pl);
749738               }
739            }
750740
751741            /* now assemble the bits */
752            pfpix0 |= assemble_odd_bitplanes(planes, obitoffs);
742            pfpix0 |= assemble_odd_bitplanes(state, planes, obitoffs);
753743            obitoffs--;
754744
755745            /* for high res, assemble a second set of bits */
r9192r9193
758748               /* reset bit offsets and fetch more data if needed */
759749               if (obitoffs < 0)
760750               {
761                  obitoffs = 15;
751                  obitoffs = defbitoffs;
762752
763753                  for (pl = 0; pl < planes; pl += 2)
764754                  {
765                     CUSTOM_REG(REG_BPL1DAT + pl) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2));
766                     CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2) += 2;
755                     fetch_bitplane_data(state, pl);
767756                  }
768757               }
769758
770               pfpix1 |= assemble_odd_bitplanes(planes, obitoffs);
759               pfpix1 |= assemble_odd_bitplanes(state, planes, obitoffs);
771760               obitoffs--;
772761            }
773762            else
r9192r9193
775764
776765            /* reset bit offsets if needed */
777766            if (obitoffs < 0)
778               obitoffs = 15;
767               obitoffs = defbitoffs;
779768         }
780769
781770         /* fetch the even bits if we are within the fetching region */
782771         if (x >= ddf_start_pixel && x <= ddf_stop_pixel + edelay)
783772         {
784773            /* if we need to fetch more data, do it now */
785            if (ebitoffs == 15)
774            if (ebitoffs == defbitoffs)
775            {
786776               for (pl = 1; pl < planes; pl += 2)
787777               {
788                  CUSTOM_REG(REG_BPL1DAT + pl) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2));
789                  CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2) += 2;
778                  fetch_bitplane_data(state, pl);
790779               }
780            }
791781
792782            /* now assemble the bits */
793            pfpix0 |= assemble_even_bitplanes(planes, ebitoffs);
783            pfpix0 |= assemble_even_bitplanes(state, planes, ebitoffs);
794784            ebitoffs--;
795785
796786            /* for high res, assemble a second set of bits */
r9192r9193
799789               /* reset bit offsets and fetch more data if needed */
800790               if (ebitoffs < 0)
801791               {
802                  ebitoffs = 15;
792                  ebitoffs = defbitoffs;
803793
804794                  for (pl = 1; pl < planes; pl += 2)
805795                  {
806                     CUSTOM_REG(REG_BPL1DAT + pl) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2));
807                     CUSTOM_REG_LONG(REG_BPL1PTH + pl * 2) += 2;
796                     fetch_bitplane_data(state, pl);
808797                  }
809798               }
810799
811               pfpix1 |= assemble_even_bitplanes(planes, ebitoffs);
800               pfpix1 |= assemble_even_bitplanes(state, planes, ebitoffs);
812801               ebitoffs--;
813802            }
814803            else
r9192r9193
816805
817806            /* reset bit offsets if needed */
818807            if (ebitoffs < 0)
819               ebitoffs = 15;
808               ebitoffs = defbitoffs;
820809         }
821810
822811         /* compute playfield/sprite collisions for first pixel */
r9192r9193
840829         /* if we are within the display region, render */
841830         if (dst != NULL && x >= hstart && x < hstop)
842831         {
832            int pix, pri;
833
843834            /* hold-and-modify mode -- assume low-res (hi-res not supported by the hardware) */
844835            if (ham)
845836            {
846837               /* update the HAM color */
847               pfpix0 = update_ham(pfpix0);
838               pfpix0 = update_ham(state, pfpix0);
848839
840               pix = sprpix & 0x1f;
841               pri = (sprpix >> 10);
842
849843               /* sprite has priority */
850               if (sprpix && pf1pri > (sprpix >> 10))
844               if (sprpix && pf1pri > pri)
851845               {
852846                  dst[x*2+0] =
853                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + (sprpix & 0x1f));
847                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + pix);
854848               }
855849
856850               /* playfield has priority */
r9192r9193
864858            /* dual playfield mode */
865859            else if (dualpf)
866860            {
867               int pix;
868
869861               /* mask out the sprite if it doesn't have priority */
870862               pix = sprpix & 0x1f;
863               pri = (sprpix >> 10);
871864               if (pix)
872865               {
873                  if ((pfpix0 & 0x15) && pf1pri <= (sprpix >> 10))
866                  if ((pfpix0 & 0x15) && pf1pri <= pri)
874867                     pix = 0;
875                  if ((pfpix0 & 0x2a) && pf2pri <= (sprpix >> 10))
868                  if ((pfpix0 & 0x2a) && pf2pri <= pri)
876869                     pix = 0;
877870               }
878871
r9192r9193
880873               if (pix)
881874                  dst[x*2+0] = CUSTOM_REG(REG_COLOR00 + pix);
882875               else
883                  dst[x*2+0] = CUSTOM_REG(REG_COLOR00 + separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix0]);
876                  dst[x*2+0] = CUSTOM_REG(REG_COLOR00 + state->separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix0]);
884877
885878               /* mask out the sprite if it doesn't have priority */
886879               pix = sprpix & 0x1f;
887880               if (pix)
888881               {
889                  if ((pfpix1 & 0x15) && pf1pri <= (sprpix >> 10))
882                  if ((pfpix1 & 0x15) && pf1pri <= pri)
890883                     pix = 0;
891                  if ((pfpix1 & 0x2a) && pf2pri <= (sprpix >> 10))
884                  if ((pfpix1 & 0x2a) && pf2pri <= pri)
892885                     pix = 0;
893886               }
894887
r9192r9193
896889               if (pix)
897890                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + pix);
898891               else
899                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix1]);
892                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + state->separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix1]);
900893            }
901894
902895            /* single playfield mode */
903896            else
904897            {
898               pix = sprpix & 0x1f;
899               pri = (sprpix >> 10);
900
905901               /* sprite has priority */
906               if (sprpix && pf1pri > (sprpix >> 10))
902               if (sprpix && pf1pri > pri)
907903               {
908904                  dst[x*2+0] =
909                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + (sprpix & 0x1f));
905                  dst[x*2+1] = CUSTOM_REG(REG_COLOR00 + pix);
910906               }
911907
912908               /* playfield has priority */
r9192r9193
961957   if (machine->primary_screen->frame_number() % 64 == 0 && scanline == 0)
962958   {
963959      if (input_code_pressed(machine, KEYCODE_Q))
964         popmessage("%d", wait_offset -= 1);
960         popmessage("%d", state->wait_offset -= 1);
965961      if (input_code_pressed(machine, KEYCODE_W))
966         popmessage("%d", wait_offset += 1);
962         popmessage("%d", state->wait_offset += 1);
967963   }
968964#endif
969965}
src/mame/video/amigaaga.c
r9192r9193
2424
2525/*************************************
2626 *
27 *  Debugging
28 *
29 *************************************/
30
31#define LOG_COPPER         0
32#define GUESS_COPPER_OFFSET   0
33#define LOG_SPRITE_DMA      0
34
35
36
37/*************************************
38 *
39 *  Macros
40 *
41 *************************************/
42
43#define COPPER_CYCLES_TO_PIXELS(x)      (4 * (x))
44
45
46
47/*************************************
48 *
4927 *  Statics
5028 *
5129 *************************************/
5230
53/* palette */
54static pen_t aga_palette[256];
55
56/* AGA bpldat registers */
57static UINT64 aga_bpldat[8];
58
59/* sprite states */
60static UINT8 sprite_comparitor_enable_mask;
61static UINT8 sprite_dma_reload_mask;
62static UINT8 sprite_dma_live_mask;
63static UINT8 sprite_ctl_written;
64static UINT32 sprite_shiftreg[8];
65static UINT8 sprite_remain[8];
66static UINT16 aga_sprdata[8][4];
67static UINT16 aga_sprdatb[8][4];
68static int aga_sprite_fetched_words;
69static int aga_sprite_dma_used_words[8];
70
71/* playfield states */
72static int last_scanline;
73static pen_t ham_color;
74static int diwhigh_written;
75
76/* copper states */
77static UINT32 copper_pc;
78static UINT8 copper_waiting;
79static UINT8 copper_waitblit;
80static UINT16 copper_waitval;
81static UINT16 copper_waitmask;
82static UINT16 copper_pending_offset;
83static UINT16 copper_pending_data;
84
85/* misc states */
86static UINT16 genlock_color;
87
88#if GUESS_COPPER_OFFSET
89static int wait_offset = 3;
90#endif
91
92
93
9431/*************************************
9532 *
96 *  Tables
97 *
98 *************************************/
99
100/* expand an 8-bit bit pattern into 16 bits, every other bit */
101static const UINT16 expand_byte[256] =
102{
103   0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015,
104   0x0040, 0x0041, 0x0044, 0x0045, 0x0050, 0x0051, 0x0054, 0x0055,
105   0x0100, 0x0101, 0x0104, 0x0105, 0x0110, 0x0111, 0x0114, 0x0115,
106   0x0140, 0x0141, 0x0144, 0x0145, 0x0150, 0x0151, 0x0154, 0x0155,
107   0x0400, 0x0401, 0x0404, 0x0405, 0x0410, 0x0411, 0x0414, 0x0415,
108   0x0440, 0x0441, 0x0444, 0x0445, 0x0450, 0x0451, 0x0454, 0x0455,
109   0x0500, 0x0501, 0x0504, 0x0505, 0x0510, 0x0511, 0x0514, 0x0515,
110   0x0540, 0x0541, 0x0544, 0x0545, 0x0550, 0x0551, 0x0554, 0x0555,
111   0x1000, 0x1001, 0x1004, 0x1005, 0x1010, 0x1011, 0x1014, 0x1015,
112   0x1040, 0x1041, 0x1044, 0x1045, 0x1050, 0x1051, 0x1054, 0x1055,
113   0x1100, 0x1101, 0x1104, 0x1105, 0x1110, 0x1111, 0x1114, 0x1115,
114   0x1140, 0x1141, 0x1144, 0x1145, 0x1150, 0x1151, 0x1154, 0x1155,
115   0x1400, 0x1401, 0x1404, 0x1405, 0x1410, 0x1411, 0x1414, 0x1415,
116   0x1440, 0x1441, 0x1444, 0x1445, 0x1450, 0x1451, 0x1454, 0x1455,
117   0x1500, 0x1501, 0x1504, 0x1505, 0x1510, 0x1511, 0x1514, 0x1515,
118   0x1540, 0x1541, 0x1544, 0x1545, 0x1550, 0x1551, 0x1554, 0x1555,
119
120   0x4000, 0x4001, 0x4004, 0x4005, 0x4010, 0x4011, 0x4014, 0x4015,
121   0x4040, 0x4041, 0x4044, 0x4045, 0x4050, 0x4051, 0x4054, 0x4055,
122   0x4100, 0x4101, 0x4104, 0x4105, 0x4110, 0x4111, 0x4114, 0x4115,
123   0x4140, 0x4141, 0x4144, 0x4145, 0x4150, 0x4151, 0x4154, 0x4155,
124   0x4400, 0x4401, 0x4404, 0x4405, 0x4410, 0x4411, 0x4414, 0x4415,
125   0x4440, 0x4441, 0x4444, 0x4445, 0x4450, 0x4451, 0x4454, 0x4455,
126   0x4500, 0x4501, 0x4504, 0x4505, 0x4510, 0x4511, 0x4514, 0x4515,
127   0x4540, 0x4541, 0x4544, 0x4545, 0x4550, 0x4551, 0x4554, 0x4555,
128   0x5000, 0x5001, 0x5004, 0x5005, 0x5010, 0x5011, 0x5014, 0x5015,
129   0x5040, 0x5041, 0x5044, 0x5045, 0x5050, 0x5051, 0x5054, 0x5055,
130   0x5100, 0x5101, 0x5104, 0x5105, 0x5110, 0x5111, 0x5114, 0x5115,
131   0x5140, 0x5141, 0x5144, 0x5145, 0x5150, 0x5151, 0x5154, 0x5155,
132   0x5400, 0x5401, 0x5404, 0x5405, 0x5410, 0x5411, 0x5414, 0x5415,
133   0x5440, 0x5441, 0x5444, 0x5445, 0x5450, 0x5451, 0x5454, 0x5455,
134   0x5500, 0x5501, 0x5504, 0x5505, 0x5510, 0x5511, 0x5514, 0x5515,
135   0x5540, 0x5541, 0x5544, 0x5545, 0x5550, 0x5551, 0x5554, 0x5555
136};
137
138/* separate 6 in-order bitplanes into 2 x 3-bit bitplanes in two nibbles */
139static UINT8 separate_bitplanes[2][64];
140
141/*************************************
142 *
14333 *  Palette
14434 *
14535 *************************************/
14636
147void aga_palette_write(int color_reg, UINT16 data)
37void amiga_aga_palette_write(running_machine *machine, int color_reg, UINT16 data)
14838{
39   amiga_state *state = machine->driver_data<amiga_state>();
40   pen_t *aga_palette = state->aga_palette;
14941   int r,g,b;
15042   int cr,cg,cb;
15143   int color;
r9192r9193
18173
18274VIDEO_START( amiga_aga )
18375{
184   int j;
76   amiga_state *state = machine->driver_data<amiga_state>();
18577
186   /* generate tables that produce the correct playfield color for dual playfield mode */
187   for (j = 0; j < 64; j++)
188   {
189      int pf1pix = ((j >> 0) & 1) | ((j >> 1) & 2) | ((j >> 2) & 4);
190      int pf2pix = ((j >> 1) & 1) | ((j >> 2) & 2) | ((j >> 3) & 4);
78   VIDEO_START_CALL( amiga );
19179
192      separate_bitplanes[0][j] = (pf1pix || !pf2pix) ? pf1pix : (pf2pix + 8);
193      separate_bitplanes[1][j] = pf2pix ? (pf2pix + 8) : pf1pix;
194   }
195
196   /* reset the genlock color */
197   genlock_color = 0xffff;
198
199   sprite_ctl_written = 0;
200   diwhigh_written = 0;
80   state->aga_diwhigh_written = 0;
20181}
20282
20383
20484
20585/*************************************
20686 *
207 *  Beam position
208 *
209 *************************************/
210
211UINT32 amiga_aga_gethvpos(screen_device &screen)
212{
213   UINT32 hvpos = (last_scanline << 8) | (screen.hpos() >> 2);
214   UINT32 latchedpos = input_port_read_safe(screen.machine, "HVPOS", 0);
215
216   /* if there's no latched position, or if we are in the active display area */
217   /* but before the latching point, return the live HV position */
218   if ((CUSTOM_REG(REG_BPLCON0) & 0x0008) == 0 || latchedpos == 0 || (last_scanline >= 20 && hvpos < latchedpos))
219      return hvpos;
220
221   /* otherwise, return the latched position */
222   return latchedpos;
223}
224
225
226
227/*************************************
228 *
229 *  Genlock interaction
230 *
231 *************************************/
232
233void amiga_aga_set_genlock_color(UINT16 color)
234{
235   genlock_color = color;
236}
237
238
239
240/*************************************
241 *
242 *  Copper emulation
243 *
244 *************************************/
245
246void aga_copper_setpc(UINT32 pc)
247{
248   if (LOG_COPPER)
249      logerror("copper_setpc(%06x)\n", pc);
250
251   copper_pc = pc;
252   copper_waiting = FALSE;
253}
254
255static int copper_execute_next(running_machine *machine, int xpos)
256{
257   int word0, word1;
258
259   /* bail if not enabled */
260   if ((CUSTOM_REG(REG_DMACON) & (DMACON_COPEN | DMACON_DMAEN)) != (DMACON_COPEN | DMACON_DMAEN))
261      return 511;
262
263   /* flush any pending writes */
264   if (copper_pending_offset)
265   {
266      if (LOG_COPPER)
267         logerror("%02X.%02X: Write to %s = %04x\n", last_scanline, xpos / 2, amiga_custom_names[copper_pending_offset & 0xff], copper_pending_data);
268
269      amiga_custom_w(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), copper_pending_offset, copper_pending_data, 0xffff);
270      copper_pending_offset = 0;
271   }
272
273   /* if we're waiting, check for a breakthrough */
274   if (copper_waiting)
275   {
276      int curpos = (last_scanline << 8) | (xpos >> 1);
277
278      /* if we're past the wait time, stop it and hold up 2 cycles */
279      if ((curpos & copper_waitmask) >= (copper_waitval & copper_waitmask) &&
280         (!copper_waitblit || !(CUSTOM_REG(REG_DMACON) & DMACON_BBUSY)))
281      {
282         copper_waiting = FALSE;
283#if GUESS_COPPER_OFFSET
284         return xpos + COPPER_CYCLES_TO_PIXELS(1 + wait_offset);
285#else
286         return xpos + COPPER_CYCLES_TO_PIXELS(1 + 3);
287#endif
288      }
289
290      /* otherwise, see if this line is even a possibility; if not, punt */
291      if (((curpos | 0xff) & copper_waitmask) < (copper_waitval & copper_waitmask))
292         return 511;
293
294      /* else just advance another pixel */
295      xpos += COPPER_CYCLES_TO_PIXELS(1);
296      return xpos;
297   }
298
299   /* fetch the first data word */
300   word0 = amiga_chip_ram_r(copper_pc);
301   copper_pc += 2;
302   xpos += COPPER_CYCLES_TO_PIXELS(1);
303
304   /* fetch the second data word */
305   word1 = amiga_chip_ram_r(copper_pc);
306   copper_pc += 2;
307   xpos += COPPER_CYCLES_TO_PIXELS(1);
308
309   if (LOG_COPPER)
310      logerror("%02X.%02X: Copper inst @ %06x = %04x %04x\n", last_scanline, xpos / 2, copper_pc, word0, word1);
311
312   /* handle a move */
313   if ((word0 & 1) == 0)
314   {
315      int min = (CUSTOM_REG(REG_COPCON) & 2) ? 0x20 : 0x40;
316
317      /* do the write if we're allowed */
318      word0 = (word0 >> 1) & 0xff;
319      if (word0 >= min)
320      {
321         /* write it at the *end* of this instruction's cycles */
322         /* needed for Arcadia's Fast Break */
323         copper_pending_offset = word0;
324         copper_pending_data = word1;
325      }
326
327      /* illegal writes suspend until next frame */
328      else
329      {
330         if (LOG_COPPER)
331            logerror("%02X.%02X: Aborting copper on illegal write\n", last_scanline, xpos / 2);
332
333         copper_waitval = 0xffff;
334         copper_waitmask = 0xffff;
335         copper_waitblit = FALSE;
336         copper_waiting = TRUE;
337         return 511;
338      }
339   }
340   else
341   {
342      /* extract common wait/skip values */
343      copper_waitval = word0 & 0xfffe;
344      copper_waitmask = word1 | 0x8001;
345      copper_waitblit = (~word1 >> 15) & 1;
346
347      /* handle a wait */
348      if ((word1 & 1) == 0)
349      {
350         if (LOG_COPPER)
351            logerror("  Waiting for %04x & %04x (currently %04x)\n", copper_waitval, copper_waitmask, (last_scanline << 8) | (xpos >> 1));
352
353         copper_waiting = TRUE;
354      }
355
356      /* handle a skip */
357      else
358      {
359         int curpos = (last_scanline << 8) | (xpos >> 1);
360
361         if (LOG_COPPER)
362            logerror("  Skipping if %04x & %04x (currently %04x)\n", copper_waitval, copper_waitmask, (last_scanline << 8) | (xpos >> 1));
363
364         /* if we're past the wait time, stop it and hold up 2 cycles */
365         if ((curpos & copper_waitmask) >= (copper_waitval & copper_waitmask) &&
366            (!copper_waitblit || !(CUSTOM_REG(REG_DMACON) & DMACON_BBUSY)))
367         {
368            if (LOG_COPPER)
369               logerror("  Skipped\n");
370
371            /* count the cycles it out have taken to fetch the next instruction */
372            copper_pc += 4;
373            xpos += COPPER_CYCLES_TO_PIXELS(2);
374         }
375      }
376   }
377
378   /* advance and consume 8 cycles */
379   return xpos;
380}
381
382
383/*************************************
384 *
385 *  External sprite controls
386 *
387 *************************************/
388
389void amiga_aga_sprite_dma_reset(int which)
390{
391   if (LOG_SPRITE_DMA) logerror("sprite %d dma reset\n", which );
392   sprite_dma_reload_mask |= 1 << which;
393   sprite_dma_live_mask |= 1 << which;
394}
395
396
397void amiga_aga_sprite_enable_comparitor(int which, int enable)
398{
399   if (LOG_SPRITE_DMA) logerror("sprite %d comparitor %sable\n", which, enable ? "en" : "dis" );
400   if (enable)
401   {
402      sprite_comparitor_enable_mask |= 1 << which;
403      sprite_dma_live_mask &= ~(1 << which);
404   }
405   else
406   {
407      sprite_comparitor_enable_mask &= ~(1 << which);
408      sprite_ctl_written |= (1 << which);
409   }
410}
411
412
413
414/*************************************
415 *
41687 *  Per-scanline sprite fetcher
41788 *
41889 *************************************/
41990
420INLINE void fetch_sprite_data(int scanline, int sprite)
91INLINE void fetch_sprite_data(amiga_state *state, int scanline, int sprite)
42192{
42293   switch((CUSTOM_REG(REG_FMODE) >> 2) & 0x03)
42394   {
42495      case 0:
425         aga_sprdata[sprite][0] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
426         aga_sprdatb[sprite][0] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
96         state->aga_sprdata[sprite][0] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
97         state->aga_sprdatb[sprite][0] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
42798         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
428         aga_sprite_fetched_words = 1;
429         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X\n", scanline, sprite, aga_sprdata[sprite][0], aga_sprdatb[sprite][0]);
99         state->aga_sprite_fetched_words = 1;
100         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X\n", scanline, sprite, state->aga_sprdata[sprite][0], state->aga_sprdatb[sprite][0]);
430101         break;
431102      case 1:
432103      case 2:
433         aga_sprdata[sprite][0] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
434         aga_sprdata[sprite][1] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
104         state->aga_sprdata[sprite][0] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
105         state->aga_sprdata[sprite][1] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
435106         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
436         aga_sprdatb[sprite][0] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
437         aga_sprdatb[sprite][1] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
107         state->aga_sprdatb[sprite][0] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
108         state->aga_sprdatb[sprite][1] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
438109         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
439         aga_sprite_fetched_words = 2;
440         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X %04X-%04X\n", scanline, sprite, aga_sprdata[sprite][0], aga_sprdatb[sprite][0], aga_sprdata[sprite][1], aga_sprdatb[sprite][1] );
110         state->aga_sprite_fetched_words = 2;
111         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X %04X-%04X\n", scanline, sprite, state->aga_sprdata[sprite][0], state->aga_sprdatb[sprite][0], state->aga_sprdata[sprite][1], state->aga_sprdatb[sprite][1] );
441112         break;
442113      case 3:
443         aga_sprdata[sprite][0] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
444         aga_sprdata[sprite][1] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
114         state->aga_sprdata[sprite][0] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
115         state->aga_sprdata[sprite][1] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
445116         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
446         aga_sprdata[sprite][2] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
447         aga_sprdata[sprite][3] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
117         state->aga_sprdata[sprite][2] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
118         state->aga_sprdata[sprite][3] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
448119         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
449         aga_sprdatb[sprite][0] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
450         aga_sprdatb[sprite][1] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
120         state->aga_sprdatb[sprite][0] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
121         state->aga_sprdatb[sprite][1] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
451122         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
452         aga_sprdatb[sprite][2] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
453         aga_sprdatb[sprite][3] = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
123         state->aga_sprdatb[sprite][2] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 0);
124         state->aga_sprdatb[sprite][3] = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) + 2);
454125         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * sprite) += 4;
455         aga_sprite_fetched_words = 4;
126         state->aga_sprite_fetched_words = 4;
456127         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d fetch: data=%04X-%04X %04X-%04X %04X-%04X %04X-%04X\n",
457128                              scanline, sprite,
458                              aga_sprdata[sprite][0], aga_sprdatb[sprite][0],
459                              aga_sprdata[sprite][1], aga_sprdatb[sprite][1],
460                              aga_sprdata[sprite][2], aga_sprdatb[sprite][2],
461                              aga_sprdata[sprite][3], aga_sprdatb[sprite][3]);
129                              state->aga_sprdata[sprite][0], state->aga_sprdatb[sprite][0],
130                              state->aga_sprdata[sprite][1], state->aga_sprdatb[sprite][1],
131                              state->aga_sprdata[sprite][2], state->aga_sprdatb[sprite][2],
132                              state->aga_sprdata[sprite][3], state->aga_sprdatb[sprite][3]);
462133         break;
463134   }
464   aga_sprite_dma_used_words[sprite] = 0;
135   state->aga_sprite_dma_used_words[sprite] = 0;
465136}
466137
467static void update_sprite_dma(int scanline)
138static void update_sprite_dma(amiga_state *state, int scanline)
468139{
469140   int dmaenable = (CUSTOM_REG(REG_DMACON) & (DMACON_SPREN | DMACON_DMAEN)) == (DMACON_SPREN | DMACON_DMAEN);
470141   int num, maxdma;
r9192r9193
481152      int vstart, vstop;
482153
483154      /* if we are == VSTOP, fetch new control words */
484      if (dmaenable && (sprite_dma_live_mask & bitmask) && (sprite_dma_reload_mask & bitmask) && !(sprite_ctl_written & bitmask))
155      if (dmaenable && (state->sprite_dma_live_mask & bitmask) && (state->sprite_dma_reload_mask & bitmask) && !(state->sprite_ctl_written & bitmask))
485156      {
486157         /* disable the sprite */
487         sprite_comparitor_enable_mask &= ~bitmask;
488         sprite_dma_reload_mask &= ~bitmask;
158         state->sprite_comparitor_enable_mask &= ~bitmask;
159         state->sprite_dma_reload_mask &= ~bitmask;
489160
490161         /* fetch data into the control words */
491         CUSTOM_REG(REG_SPR0POS + 4 * num) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 0);
492         CUSTOM_REG(REG_SPR0CTL + 4 * num) = amiga_chip_ram_r(CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 2);
162         CUSTOM_REG(REG_SPR0POS + 4 * num) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 0);
163         CUSTOM_REG(REG_SPR0CTL + 4 * num) = (*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) + 2);
493164         CUSTOM_REG_LONG(REG_SPR0PTH + 2 * num) += 4;
494165         /* fetch additional words */
495166         switch((CUSTOM_REG(REG_FMODE) >> 2) & 0x03)
r9192r9193
514185      /* if we hit vstart, enable the comparitor */
515186      if (scanline == vstart)
516187      {
517         sprite_comparitor_enable_mask |= 1 << num;
188         state->sprite_comparitor_enable_mask |= 1 << num;
518189         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d comparitor enable\n", scanline, num);
519190      }
520191
521192      /* if we hit vstop, disable the comparitor and trigger a reload for the next scanline */
522193      if (scanline == vstop)
523194      {
524         sprite_ctl_written &= ~bitmask;
525         sprite_comparitor_enable_mask &= ~bitmask;
526         sprite_dma_reload_mask |= 1 << num;
195         state->sprite_ctl_written &= ~bitmask;
196         state->sprite_comparitor_enable_mask &= ~bitmask;
197         state->sprite_dma_reload_mask |= 1 << num;
527198         CUSTOM_REG(REG_SPR0DATA + 4 * num) = 0;      /* just a guess */
528199         CUSTOM_REG(REG_SPR0DATB + 4 * num) = 0;
529200         if (LOG_SPRITE_DMA) logerror("%3d:sprite %d comparitor disable, prepare for reload\n", scanline, num);
530201      }
531202
532203      /* fetch data if this sprite is enabled */
533      if (dmaenable && (sprite_dma_live_mask & bitmask) && (sprite_comparitor_enable_mask & bitmask))
204      if (dmaenable && (state->sprite_dma_live_mask & bitmask) && (state->sprite_comparitor_enable_mask & bitmask))
534205      {
535         fetch_sprite_data(scanline, num);
206         fetch_sprite_data(state, scanline, num);
536207      }
537208   }
538209}
r9192r9193
547218
548219INLINE UINT32 interleave_sprite_data(UINT16 lobits, UINT16 hibits)
549220{
550   return (expand_byte[lobits & 0xff] << 0) | (expand_byte[lobits >> 8] << 16) |
551         (expand_byte[hibits & 0xff] << 1) | (expand_byte[hibits >> 8] << 17);
221   return (amiga_expand_byte[lobits & 0xff] << 0) | (amiga_expand_byte[lobits >> 8] << 16) |
222         (amiga_expand_byte[hibits & 0xff] << 1) | (amiga_expand_byte[hibits >> 8] << 17);
552223}
553224
554225
555static int get_sprite_pixel(int x)
226static int get_sprite_pixel(amiga_state *state, int x)
556227{
557228   int pixels = 0;
558229   int num, pair;
559230
560231   /* loop over sprite channels */
561232   for (num = 0; num < 8; num++)
562      if (sprite_comparitor_enable_mask & (1 << num))
233      if (state->sprite_comparitor_enable_mask & (1 << num))
563234      {
564235         /* if we're not currently clocking, check against hstart */
565         if (sprite_remain[num] == 0)
236         if (state->sprite_remain[num] == 0)
566237         {
567238            int hstart = ((CUSTOM_REG(REG_SPR0POS + 4 * num) & 0xff) << 1) | (CUSTOM_REG(REG_SPR0CTL + 4 * num) & 1);
568239            if (hstart == x)
569240            {
570               sprite_remain[num] = 16;
571               sprite_shiftreg[num] = interleave_sprite_data(aga_sprdata[num][0], aga_sprdatb[num][0]);
572               aga_sprite_dma_used_words[num] = 1;
241               state->sprite_remain[num] = 16;
242               state->sprite_shiftreg[num] = interleave_sprite_data(state->aga_sprdata[num][0], state->aga_sprdatb[num][0]);
243               state->aga_sprite_dma_used_words[num] = 1;
573244            }
574245         }
575246
576247         /* clock the next pixel if we're doing it */
577         if (sprite_remain[num] != 0)
248         if (state->sprite_remain[num] != 0)
578249         {
579            sprite_remain[num]--;
580            pixels |= (sprite_shiftreg[num] & 0xc0000000) >> (16 + 2 * (7 - num));
581            sprite_shiftreg[num] <<= 2;
250            state->sprite_remain[num]--;
251            pixels |= (state->sprite_shiftreg[num] & 0xc0000000) >> (16 + 2 * (7 - num));
252            state->sprite_shiftreg[num] <<= 2;
582253
583            if (sprite_remain[num] == 0)
254            if (state->sprite_remain[num] == 0)
584255            {
585               if (aga_sprite_dma_used_words[num] < aga_sprite_fetched_words)
256               if (state->aga_sprite_dma_used_words[num] < state->aga_sprite_fetched_words)
586257               {
587                  sprite_remain[num] = 16;
588                  sprite_shiftreg[num] = interleave_sprite_data(aga_sprdata[num][aga_sprite_dma_used_words[num]], aga_sprdatb[num][aga_sprite_dma_used_words[num]]);
589                  aga_sprite_dma_used_words[num]++;
258                  int w = state->aga_sprite_dma_used_words[num];
259                  state->sprite_remain[num] = 16;
260                  state->sprite_shiftreg[num] = interleave_sprite_data(state->aga_sprdata[num][w], state->aga_sprdatb[num][w]);
261                  state->aga_sprite_dma_used_words[num]++;
590262               }
591263            }
592264         }
r9192r9193
630302            /* final result is:
631303                    topmost sprite color in bits 0-7
632304                    sprite present bitmask in bits 8-9
633                    topmost sprite pair index in bits 12-11
305                    topmost sprite pair index in bits 12-13
634306                */
307            UINT32 result = (collide << 8) | (pair << 12);
635308
636309            /* attached case */
637310            if (CUSTOM_REG(REG_SPR1CTL + 8 * pair) & 0x0080)
638               return (pixels & 0xf) | osprm | (collide << 8) | (pair << 12);
311               return (pixels & 0xf) | osprm | result;
639312
640313            /* lower-numbered sprite of pair */
641314            else if (pixels & 3)
642               return (pixels & 3) | esprm | (pair << 2) | (collide << 8) | (pair << 12);
315               return (pixels & 3) | esprm | (pair << 2) | result;
643316
644317            /* higher-numbered sprite of pair */
645318            else
646               return ((pixels >> 2) & 3) | osprm | (pair << 2) | (collide << 8) | (pair << 12);
319               return ((pixels >> 2) & 3) | osprm | (pair << 2) | result;
647320         }
648321   }
649322
r9192r9193
658331 *
659332 *************************************/
660333
661INLINE UINT8 assemble_odd_bitplanes(int planes, int obitoffs)
334INLINE UINT8 assemble_odd_bitplanes(amiga_state *state, int planes, int obitoffs)
662335{
336   UINT64 *aga_bpldat = state->aga_bpldat;
663337   UINT8 pix = (aga_bpldat[0] >> obitoffs) & 1;
664338   if (planes >= 3)
665339   {
r9192r9193
675349}
676350
677351
678INLINE UINT8 assemble_even_bitplanes(int planes, int ebitoffs)
352INLINE UINT8 assemble_even_bitplanes(amiga_state *state, int planes, int ebitoffs)
679353{
680354   UINT8 pix = 0;
681355   if (planes >= 2)
682356   {
357      UINT64 *aga_bpldat = state->aga_bpldat;
683358      pix |= ((aga_bpldat[1] >> ebitoffs) & 1) << 1;
684359      if (planes >= 4)
685360      {
r9192r9193
695370   return pix;
696371}
697372
698INLINE void fetch_bitplane_data(int plane)
373INLINE void fetch_bitplane_data(amiga_state *state, int plane)
699374{
375   UINT64 *aga_bpldat = state->aga_bpldat;
376
700377   switch (CUSTOM_REG(REG_FMODE) & 0x03)
701378   {
702379      case 0:
703         aga_bpldat[plane] = (UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2));
380         aga_bpldat[plane] = (UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2));
704381         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
705382         break;
706383      case 1:
707384      case 2:
708         aga_bpldat[plane] = (UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2)) << 16;
385         aga_bpldat[plane] = (UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2)) << 16;
709386         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
710         aga_bpldat[plane] |= ((UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2)));
387         aga_bpldat[plane] |= ((UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2)));
711388         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
712389         break;
713390      case 3:
714         aga_bpldat[plane] = (UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2)) << 48;
391         aga_bpldat[plane] = (UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2)) << 48;
715392         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
716         aga_bpldat[plane] |= ((UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2))) << 32;
393         aga_bpldat[plane] |= ((UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2))) << 32;
717394         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
718         aga_bpldat[plane] |= ((UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2))) << 16;
395         aga_bpldat[plane] |= ((UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2))) << 16;
719396         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
720         aga_bpldat[plane] |= (UINT64)amiga_chip_ram_r(CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2));
397         aga_bpldat[plane] |= (UINT64)(*state->chip_ram_r)(state, CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2));
721398         CUSTOM_REG_LONG(REG_BPL1PTH + plane * 2) += 2;
722399         break;
723400   }
724401}
725402
726void aga_diwhigh_written(int written)
403void amiga_aga_diwhigh_written(running_machine *machine, int written)
727404{
728   diwhigh_written = written;
405   amiga_state *state = machine->driver_data<amiga_state>();
406
407   state->aga_diwhigh_written = written;
729408}
730409
731410/*************************************
r9192r9193
734413 *
735414 *************************************/
736415
737INLINE int update_ham(int newpix)
416INLINE int update_ham(amiga_state *state, int newpix)
738417{
739418   switch (newpix & 0x03)
740419   {
741420      case 0:
742         ham_color = aga_palette[(newpix >> 2) & 0x3f];
421         state->ham_color = state->aga_palette[(newpix >> 2) & 0x3f];
743422         break;
744423
745424      case 1:
746         ham_color = MAKE_RGB(RGB_RED(ham_color), RGB_GREEN(ham_color), (newpix & 0xfc) | (RGB_BLUE(ham_color) & 0x03));
425         state->ham_color = MAKE_RGB(RGB_RED(state->ham_color), RGB_GREEN(state->ham_color), (newpix & 0xfc) | (RGB_BLUE(state->ham_color) & 0x03));
747426         break;
748427
749428      case 2:
750         ham_color = MAKE_RGB((newpix & 0xfc) | (RGB_RED(ham_color) & 0x03), RGB_GREEN(ham_color), RGB_BLUE(ham_color));
429         state->ham_color = MAKE_RGB((newpix & 0xfc) | (RGB_RED(state->ham_color) & 0x03), RGB_GREEN(state->ham_color), RGB_BLUE(state->ham_color));
751430         break;
752431
753432      case 3:
754         ham_color = MAKE_RGB(RGB_RED(ham_color), (newpix & 0xfc) | (RGB_GREEN(ham_color) & 0x03), RGB_BLUE(ham_color));
433         state->ham_color = MAKE_RGB(RGB_RED(state->ham_color), (newpix & 0xfc) | (RGB_GREEN(state->ham_color) & 0x03), RGB_BLUE(state->ham_color));
755434         break;
756435   }
757   return ham_color;
436   return state->ham_color;
758437}
759438
760439
r9192r9193
767446
768447void amiga_aga_render_scanline(running_machine *machine, bitmap_t *bitmap, int scanline)
769448{
449   amiga_state *state = machine->driver_data<amiga_state>();
770450   UINT16 save_color0 = CUSTOM_REG(REG_COLOR00);
771451   int ddf_start_pixel = 0, ddf_stop_pixel = 0;
772452   int hires = 0, dualpf = 0, lace = 0, ham = 0;
r9192r9193
782462   int edelay = 0, odelay = 0;
783463   int next_copper_x;
784464   int pl;
785   pen_t ham_pix;
786465   int defbitoffs = 0;
466   pen_t *aga_palette = state->aga_palette;
787467
788   last_scanline = scanline;
468   state->last_scanline = scanline;
789469
790470   /* on the first scanline, reset the COPPER and HAM color */
791471   if (scanline == 0)
792472   {
793      aga_copper_setpc(CUSTOM_REG_LONG(REG_COP1LCH));
794      ham_color = CUSTOM_REG(REG_COLOR00);
473      amiga_copper_setpc(machine, CUSTOM_REG_LONG(REG_COP1LCH));
474      state->ham_color = CUSTOM_REG(REG_COLOR00);
795475   }
796476
797477   /* update sprite data fetching */
798   update_sprite_dma(scanline);
478   update_sprite_dma(state, scanline);
799479
800480   /* start of a new line, signal we're not done with it and fill up vars */
801481   if (bitmap != NULL)
802482      dst = BITMAP_ADDR32(bitmap, scanline, 0);
803483
804484   /* all sprites off at the start of the line */
805   memset(sprite_remain, 0, sizeof(sprite_remain));
485   memset(state->sprite_remain, 0, sizeof(state->sprite_remain));
806486
807487   /* temporary set color 0 to the genlock color */
808   if (genlock_color != 0xffff)
809      CUSTOM_REG(REG_COLOR00) = genlock_color;
488   if (state->genlock_color != 0xffff)
489      CUSTOM_REG(REG_COLOR00) = state->genlock_color;
810490
811491   /* loop over the line */
812492   next_copper_x = 2;   /* copper runs on odd timeslots */
r9192r9193
819499      {
820500         /* execute the next batch, restoring and re-saving color 0 around it */
821501         CUSTOM_REG(REG_COLOR00) = save_color0;
822         next_copper_x = copper_execute_next(machine, x);
502         next_copper_x = amiga_copper_execute_next(machine, x);
823503         save_color0 = CUSTOM_REG(REG_COLOR00);
824         if (genlock_color != 0xffff)
825            CUSTOM_REG(REG_COLOR00) = genlock_color;
504         if (state->genlock_color != 0xffff)
505            CUSTOM_REG(REG_COLOR00) = state->genlock_color;
826506
827507         /* compute update-related register values */
828508         planes = (CUSTOM_REG(REG_BPLCON0) & (BPLCON0_BPU0 | BPLCON0_BPU1 | BPLCON0_BPU2)) >> 12;
r9192r9193
854534         hstart = CUSTOM_REG(REG_DIWSTRT) & 0xff;
855535         hstop = (CUSTOM_REG(REG_DIWSTOP) & 0xff);
856536
857         if (diwhigh_written)
537         if (state->aga_diwhigh_written)
858538         {
859539            hstart |= ((CUSTOM_REG(REG_DIWHIGH) >> 5) & 1) << 8;
860540            hstop |= ((CUSTOM_REG(REG_DIWHIGH) >> 13) & 1) << 8;
r9192r9193
872552         /* compute the vertical start/stop */
873553         vstart = CUSTOM_REG(REG_DIWSTRT) >> 8;
874554         vstop = (CUSTOM_REG(REG_DIWSTOP) >> 8);
875         if (diwhigh_written)
555         if (state->aga_diwhigh_written)
876556         {
877557            vstart |= (CUSTOM_REG(REG_DIWHIGH) & 7) << 8;
878558            vstop |= ((CUSTOM_REG(REG_DIWHIGH) >> 8) & 7) << 8;
879559         }
880560         else
881561         {
882            if ((vstop & 0x80) == 0)
883               vstop |= 0x100;
562            vstop |= ((~CUSTOM_REG(REG_DIWSTOP) >> 7) & 0x100);
884563         }
885564
886565         /* extract playfield priorities */
r9192r9193
890569         /* extract collision masks */
891570         ocolmask = (CUSTOM_REG(REG_CLXCON) >> 6) & 0x15;
892571         ecolmask = (CUSTOM_REG(REG_CLXCON) >> 6) & 0x2a;
893
894572      }
895573
896574      /* clear the target pixels to the background color as a starting point */
r9192r9193
922600         }
923601
924602         for (pl = 0; pl < 8; pl++)
925            aga_bpldat[pl] = 0;
603            state->aga_bpldat[pl] = 0;
926604      }
927605
928606      /* need to run the sprite engine every pixel to ensure display */
929      sprpix = get_sprite_pixel(x);
607      sprpix = get_sprite_pixel(state, x);
930608
931609      /* to render, we must have bitplane DMA enabled, at least 1 plane, and be within the */
932610      /* vertical display window */
r9192r9193
943621            {
944622               for (pl = 0; pl < planes; pl += 2)
945623               {
946                  fetch_bitplane_data(pl);
624                  fetch_bitplane_data(state, pl);
947625               }
948626            }
949627
950628            /* now assemble the bits */
951            pfpix0 |= assemble_odd_bitplanes(planes, obitoffs);
629            pfpix0 |= assemble_odd_bitplanes(state, planes, obitoffs);
952630            obitoffs--;
953631
954632            /* for high res, assemble a second set of bits */
r9192r9193
961639
962640                  for (pl = 0; pl < planes; pl += 2)
963641                  {
964                     fetch_bitplane_data(pl);
642                     fetch_bitplane_data(state, pl);
965643                  }
966644               }
967645
968               pfpix1 |= assemble_odd_bitplanes(planes, obitoffs);
646               pfpix1 |= assemble_odd_bitplanes(state, planes, obitoffs);
969647               obitoffs--;
970648            }
971649            else
r9192r9193
984662            {
985663               for (pl = 1; pl < planes; pl += 2)
986664               {
987                  fetch_bitplane_data(pl);
665                  fetch_bitplane_data(state, pl);
988666               }
989667            }
990668
991669            /* now assemble the bits */
992            pfpix0 |= assemble_even_bitplanes(planes, ebitoffs);
670            pfpix0 |= assemble_even_bitplanes(state, planes, ebitoffs);
993671            ebitoffs--;
994672
995673            /* for high res, assemble a second set of bits */
r9192r9193
1002680
1003681                  for (pl = 1; pl < planes; pl += 2)
1004682                  {
1005                     fetch_bitplane_data(pl);
683                     fetch_bitplane_data(state, pl);
1006684                  }
1007685               }
1008686
1009               pfpix1 |= assemble_even_bitplanes(planes, ebitoffs);
687               pfpix1 |= assemble_even_bitplanes(state, planes, ebitoffs);
1010688               ebitoffs--;
1011689            }
1012690            else
r9192r9193
1038716         /* if we are within the display region, render */
1039717         if (dst != NULL && x >= hstart && x < hstop)
1040718         {
719            int pix, pri;
720
1041721            /* hold-and-modify mode -- assume low-res (hi-res not supported by the hardware) */
1042722            if (ham)
1043723            {
1044724               /* update the HAM color */
1045               ham_pix = update_ham(pfpix0);
725               pfpix0 = update_ham(state, pfpix0);
1046726
727               pix = sprpix & 0xff;
728               pri = (sprpix >> 10);
729
1047730               /* sprite has priority */
1048               if (sprpix && pf1pri > (sprpix >> 10))
731               if (sprpix && pf1pri > pri)
1049732               {
1050733                  dst[x*2+0] =
1051                  dst[x*2+1] = aga_palette[sprpix & 0xff];
734                  dst[x*2+1] = aga_palette[pix];
1052735               }
1053736
1054737               /* playfield has priority */
1055738               else
1056739               {
1057740                  dst[x*2+0] =
1058                  dst[x*2+1] = ham_pix;
741                  dst[x*2+1] = pfpix0;
1059742               }
1060743            }
1061744
1062745            /* dual playfield mode */
1063746            else if (dualpf)
1064747            {
1065               int pix;
1066
1067748               /* mask out the sprite if it doesn't have priority */
1068749               pix = sprpix & 0x1f;
750               pri = (sprpix >> 12);
1069751               if (pix)
1070752               {
1071                  if ((pfpix0 & 0x15) && pf1pri <= (sprpix >> 12))
753                  if ((pfpix0 & 0x15) && pf1pri <= pri)
1072754                     pix = 0;
1073                  if ((pfpix0 & 0x2a) && pf2pri <= (sprpix >> 12))
755                  if ((pfpix0 & 0x2a) && pf2pri <= pri)
1074756                     pix = 0;
1075757               }
1076758
r9192r9193
1078760               if (pix)
1079761                  dst[x*2+0] = aga_palette[pix];
1080762               else
1081                  dst[x*2+0] = aga_palette[separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix0]];
763                  dst[x*2+0] = aga_palette[state->separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix0]];
1082764
1083765               /* mask out the sprite if it doesn't have priority */
1084766               pix = sprpix & 0xff;
1085767               if (pix)
1086768               {
1087                  if ((pfpix1 & 0x15) && pf1pri <= (sprpix >> 12))
769                  if ((pfpix1 & 0x15) && pf1pri <= pri)
1088770                     pix = 0;
1089                  if ((pfpix1 & 0x2a) && pf2pri <= (sprpix >> 12))
771                  if ((pfpix1 & 0x2a) && pf2pri <= pri)
1090772                     pix = 0;
1091773               }
1092774
r9192r9193
1094776               if (pix)
1095777                  dst[x*2+1] = aga_palette[pix];
1096778               else
1097                  dst[x*2+1] = aga_palette[separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix1]];
779                  dst[x*2+1] = aga_palette[state->separate_bitplanes[(CUSTOM_REG(REG_BPLCON2) >> 6) & 1][pfpix1]];
1098780            }
1099781
1100782            /* single playfield mode */
1101783            else
1102784            {
785               pix = sprpix & 0xff;
786               pri = (sprpix >> 12);
787
1103788               /* sprite has priority */
1104               if (sprpix && pf1pri > (sprpix >> 12))
789               if (sprpix && pf1pri > pri)
1105790               {
1106791                  dst[x*2+0] =
1107                  dst[x*2+1] = aga_palette[(sprpix & 0xff)];
792                  dst[x*2+1] = aga_palette[pix];
1108793               }
1109794
1110795               /* playfield has priority */
src/mame/drivers/segaxbd.c
r9192r9193
236236#include "includes/segas16.h"
237237#include "cpu/m68000/m68000.h"
238238#include "machine/segaic16.h"
239#include "machine/nvram.h"
239240#include "sound/2151intf.h"
240241#include "sound/segapcm.h"
241242#include "video/segaic16.h"
r9192r9193
248249
249250/*************************************
250251 *
251 *  Statics
252 *
253 *************************************/
254
255static UINT16 *backupram1, *backupram2;
256
257/*************************************
258 *
259252 *  Configuration
260253 *
261254 *************************************/
r9192r9193
714707
715708/*************************************
716709 *
717 *  Capacitor-backed RAM
718 *
719 *************************************/
720
721static NVRAM_HANDLER( xboard )
722{
723   if (read_or_write)
724   {
725      mame_fwrite(file, backupram1, 0x4000);
726      mame_fwrite(file, backupram2, 0x4000);
727   }
728   else if (file)
729   {
730      mame_fread(file, backupram1, 0x4000);
731      mame_fread(file, backupram2, 0x4000);
732   }
733}
734
735
736
737/*************************************
738 *
739710 *  Main CPU memory handlers
740711 *
741712 *************************************/
r9192r9193
744715   ADDRESS_MAP_UNMAP_HIGH
745716   ADDRESS_MAP_GLOBAL_MASK(0x3fffff)
746717   AM_RANGE(0x000000, 0x07ffff) AM_ROM
747   AM_RANGE(0x080000, 0x083fff) AM_MIRROR(0x01c000) AM_RAM AM_SHARE("share1") AM_BASE(&backupram1)
748   AM_RANGE(0x0a0000, 0x0a3fff) AM_MIRROR(0x01c000) AM_RAM AM_SHARE("share2") AM_BASE(&backupram2)
718   AM_RANGE(0x080000, 0x083fff) AM_MIRROR(0x01c000) AM_RAM AM_SHARE("backup1")
719   AM_RANGE(0x0a0000, 0x0a3fff) AM_MIRROR(0x01c000) AM_RAM AM_SHARE("backup2")
749720   AM_RANGE(0x0c0000, 0x0cffff) AM_RAM_WRITE(segaic16_tileram_0_w) AM_BASE(&segaic16_tileram_0)
750721   AM_RANGE(0x0d0000, 0x0d0fff) AM_MIRROR(0x00f000) AM_RAM_WRITE(segaic16_textram_0_w) AM_BASE(&segaic16_textram_0)
751722   AM_RANGE(0x0e0000, 0x0e0007) AM_MIRROR(0x003ff8) AM_DEVREADWRITE("5248_main", segaic16_multiply_r, segaic16_multiply_w)
r9192r9193
767738   AM_RANGE(0x2ec000, 0x2ecfff) AM_MIRROR(0x001000) AM_RAM AM_SHARE("share5") AM_BASE(&segaic16_roadram_0)
768739   AM_RANGE(0x2ee000, 0x2effff) AM_READWRITE(segaic16_road_control_0_r, segaic16_road_control_0_w)
769740//  AM_RANGE(0x2f0000, 0x2f3fff) AM_READWRITE(excs_r, excs_w)
770   AM_RANGE(0x3f8000, 0x3fbfff) AM_RAM AM_SHARE("share1")
771   AM_RANGE(0x3fc000, 0x3fffff) AM_RAM AM_SHARE("share2")
741   AM_RANGE(0x3f8000, 0x3fbfff) AM_RAM AM_SHARE("backup1")
742   AM_RANGE(0x3fc000, 0x3fffff) AM_RAM AM_SHARE("backup2")
772743ADDRESS_MAP_END
773744
774745
r9192r9193
13771348   MDRV_CPU_IO_MAP(sound_portmap)
13781349
13791350   MDRV_MACHINE_RESET(xboard)
1380   MDRV_NVRAM_HANDLER(xboard)
1351   MDRV_NVRAM_ADD_0FILL("backup1")
1352   MDRV_NVRAM_ADD_0FILL("backup2")
13811353   MDRV_QUANTUM_TIME(HZ(6000))
13821354
13831355   MDRV_315_5248_ADD("5248_main")
src/mame/drivers/zn.c
r9192r9193
1515#include "cpu/z80/z80.h"
1616#include "includes/psx.h"
1717#include "machine/at28c16.h"
18#include "machine/nvram.h"
1819#include "machine/mb3773.h"
1920#include "machine/znsec.h"
2021#include "machine/idectrl.h"
r9192r9193
11861187static DRIVER_INIT( coh1000ta )
11871188{
11881189   taitofx1_eeprom_size1 = 0x200; taitofx1_eeprom1 = auto_alloc_array(machine, UINT8,  taitofx1_eeprom_size1 );
1190   machine->device<nvram_device>("eeprom1")->set_base(taitofx1_eeprom1, taitofx1_eeprom_size1);
11891191
11901192   memory_install_read_bank     ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f000000, 0x1f7fffff, 0, 0, "bank1" );     /* banked game rom */
11911193   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb40000, 0x1fb40003, 0, 0, bank_coh1000t_w ); /* bankswitch */
r9192r9193
12021204   zn_machine_init(machine);
12031205}
12041206
1205static NVRAM_HANDLER( coh1000ta )
1206{
1207   if (read_or_write)
1208   {
1209      mame_fwrite(file, taitofx1_eeprom1, taitofx1_eeprom_size1);
1210   }
1211   else if (file)
1212   {
1213      mame_fread(file, taitofx1_eeprom1, taitofx1_eeprom_size1);
1214   }
1215   else
1216   {
1217      memset(taitofx1_eeprom1, 0, taitofx1_eeprom_size1);
1218   }
1219}
1220
12211207static ADDRESS_MAP_START( fx1a_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
12221208   AM_RANGE(0x4000, 0x7fff) AM_ROMBANK("bank10")   /* Fallthrough */
12231209   AM_RANGE(0x0000, 0x7fff) AM_ROM
r9192r9193
12521238   MDRV_CPU_ADD("audiocpu", Z80, 16000000 / 4 )   /* 4 MHz */
12531239   MDRV_CPU_PROGRAM_MAP( fx1a_sound_map)
12541240   MDRV_MACHINE_RESET( coh1000ta )
1255   MDRV_NVRAM_HANDLER( coh1000ta )
1241   MDRV_NVRAM_ADD_0FILL("eeprom1")
12561242
12571243   MDRV_SOUND_ADD("ymsnd", YM2610B, 16000000/2)
12581244   MDRV_SOUND_CONFIG(ym2610_config)
r9192r9193
12881274   taitofx1_eeprom_size1 = 0x400; taitofx1_eeprom1 = auto_alloc_array(machine, UINT8,  taitofx1_eeprom_size1 );
12891275   taitofx1_eeprom_size2 = 0x200; taitofx1_eeprom2 = auto_alloc_array(machine, UINT8,  taitofx1_eeprom_size2 );
12901276
1277   machine->device<nvram_device>("eeprom1")->set_base(taitofx1_eeprom1, taitofx1_eeprom_size1);
1278   machine->device<nvram_device>("eeprom2")->set_base(taitofx1_eeprom2, taitofx1_eeprom_size2);
1279
12911280   memory_install_read_bank     ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f000000, 0x1f7fffff, 0, 0, "bank1" ); /* banked game rom */
12921281   memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb00000, 0x1fb00000 + ( taitofx1_eeprom_size1 - 1 ), 0, 0, "bank2" );
12931282   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb40000, 0x1fb40003, 0, 0, bank_coh1000t_w ); /* bankswitch */
r9192r9193
13071296   zn_machine_init(machine);
13081297}
13091298
1310static NVRAM_HANDLER( coh1000tb )
1311{
1312   if (read_or_write)
1313   {
1314      mame_fwrite(file, taitofx1_eeprom1, taitofx1_eeprom_size1);
1315      mame_fwrite(file, taitofx1_eeprom2, taitofx1_eeprom_size2);
1316   }
1317   else if (file)
1318   {
1319      mame_fread(file, taitofx1_eeprom1, taitofx1_eeprom_size1);
1320      mame_fread(file, taitofx1_eeprom2, taitofx1_eeprom_size2);
1321   }
1322   else
1323   {
1324      memset(taitofx1_eeprom1, 0, taitofx1_eeprom_size1);
1325      memset(taitofx1_eeprom2, 0, taitofx1_eeprom_size2);
1326   }
1327}
1328
1329
13301299static MACHINE_CONFIG_DERIVED( coh1000tb, zn1_2mb_vram )
13311300
13321301   MDRV_MACHINE_RESET( coh1000tb )
1333   MDRV_NVRAM_HANDLER( coh1000tb )
1302   MDRV_NVRAM_ADD_0FILL("eeprom1")
1303   MDRV_NVRAM_ADD_0FILL("eeprom2")
13341304
13351305   MDRV_MB3773_ADD("mb3773")
13361306
src/mame/drivers/tomcat.c
r9192r9193
3030#include "video/vector.h"
3131#include "video/avgdvg.h"
3232#include "machine/timekpr.h"
33#include "machine/nvram.h"
3334#include "machine/6532riot.h"
3435#include "sound/pokey.h"
3536#include "sound/tms5220.h"
r9192r9193
333334   ((UINT16*)tomcat_shared_ram)[0x0003] = 0x0000;
334335
335336   tomcat_nvram = auto_alloc_array(machine, UINT8, 0x800);
337   machine->device<nvram_device>("nvram")->set_base(tomcat_nvram, 0x800);
336338
337339   state_save_register_global_pointer(machine, tomcat_nvram, 0x800);
338340   state_save_register_global(machine, tomcat_control_num);
r9192r9193
342344   dsp_BIO = 0;
343345}
344346
345static NVRAM_HANDLER(tomcat)
346{
347   if (read_or_write)
348      mame_fwrite(file, tomcat_nvram, 0x800);
349   else
350      if (file)
351         mame_fread(file, tomcat_nvram, 0x800);
352      else
353         memset(tomcat_nvram, 0x00, 0x800);
354}
355
356347static const riot6532_interface tomcat_riot6532_intf =
357348{
358349   DEVCB_NULL,
r9192r9193
389380   MDRV_CPU_PROGRAM_MAP( sound_map)
390381
391382   MDRV_RIOT6532_ADD("riot", XTAL_14_31818MHz / 8, tomcat_riot6532_intf)
392
383   
393384   MDRV_QUANTUM_TIME(HZ(4000))
394385
395386   MDRV_MACHINE_START(tomcat)
396387
397   MDRV_NVRAM_HANDLER(tomcat)
388   MDRV_NVRAM_ADD_0FILL("nvram")
398389
399390   MDRV_M48T02_ADD( "m48t02" )
400391
src/mame/drivers/segaybd.c
r9192r9193
2727#include "includes/segas16.h"
2828#include "cpu/m68000/m68000.h"
2929#include "machine/segaic16.h"
30#include "machine/nvram.h"
3031#include "sound/2151intf.h"
3132#include "sound/segapcm.h"
3233#include "video/segaic16.h"
r9192r9193
4849 *
4950 *************************************/
5051
51static UINT16 *backupram;
52
5352/* callbacks to handle output */
5453typedef void (*yboard_output_callback)(UINT16 data);
5554static yboard_output_callback ybd_output_cb1, ybd_output_cb2;
r9192r9193
412411
413412/*************************************
414413 *
415 *  Capacitor-backed RAM
416 *
417 *************************************/
418
419static NVRAM_HANDLER( yboard )
420{
421   if (read_or_write)
422      mame_fwrite(file, backupram, 0x4000);
423   else if (file)
424      mame_fread(file, backupram, 0x4000);
425}
426
427
428
429/*************************************
430 *
431414 *  Main CPU memory handlers
432415 *
433416 *************************************/
r9192r9193
463446   AM_RANGE(0x0c0000, 0x0cffff) AM_RAM AM_SHARE("share1")
464447   AM_RANGE(0x180000, 0x18ffff) AM_RAM AM_BASE(&segaic16_spriteram_1)
465448   AM_RANGE(0x1f8000, 0x1fbfff) AM_RAM
466   AM_RANGE(0x1fc000, 0x1fffff) AM_RAM AM_BASE(&backupram)
449   AM_RANGE(0x1fc000, 0x1fffff) AM_RAM AM_SHARE("backupram")
467450ADDRESS_MAP_END
468451
469452
r9192r9193
10211004
10221005   MDRV_MACHINE_START(yboard)
10231006   MDRV_MACHINE_RESET(yboard)
1024   MDRV_NVRAM_HANDLER(yboard)
1007   MDRV_NVRAM_ADD_0FILL("backupram")
10251008   MDRV_QUANTUM_TIME(HZ(6000))
10261009
10271010   MDRV_TIMER_ADD("int_timer", scanline_callback)
src/mame/drivers/vamphalf.c
r9192r9193
5252#include "cpu/mcs51/mcs51.h"
5353#include "cpu/e132xs/e132xs.h"
5454#include "machine/eeprom.h"
55#include "machine/nvram.h"
5556#include "sound/2151intf.h"
5657#include "sound/okim6295.h"
5758
r9192r9193
636637GFXDECODE_END
637638
638639
639static NVRAM_HANDLER( finalgdr )
640{
641   if (read_or_write)
642   {
643      mame_fwrite(file, finalgdr_backupram, 0x80*0x100);
644   }
645   else
646   {
647      if (file)
648      {
649         mame_fread(file, finalgdr_backupram, 0x80*0x100);
650      }
651   }
652}
653
654640static ADDRESS_MAP_START( qs1000_prg_map, ADDRESS_SPACE_PROGRAM, 8 )
655641   AM_RANGE( 0x0000, 0xffff) AM_ROM
656642ADDRESS_MAP_END
r9192r9193
774760   MDRV_CPU_IO_MAP(finalgdr_io)
775761   MDRV_CPU_VBLANK_INT("screen", irq1_line_hold)
776762
777   MDRV_NVRAM_HANDLER(finalgdr)
763   MDRV_NVRAM_ADD_0FILL("nvram")
778764
779765   MDRV_FRAGMENT_ADD(sound_ym_oki)
780766MACHINE_CONFIG_END
r9192r9193
784770   MDRV_CPU_PROGRAM_MAP(common_32bit_map)
785771   MDRV_CPU_IO_MAP(mrkicker_io)
786772
787   MDRV_NVRAM_HANDLER(finalgdr)
773   MDRV_NVRAM_ADD_0FILL("nvram")
788774
789775   MDRV_FRAGMENT_ADD(sound_ym_oki)
790776MACHINE_CONFIG_END
r9192r9193
18721858   finalgdr_backupram_bank = 1;
18731859   finalgdr_backupram = auto_alloc_array(machine, UINT8, 0x80*0x100);
18741860   memory_install_read32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x005e874, 0x005e877, 0, 0, finalgdr_speedup_r );
1861   machine->device<nvram_device>("nvram")->set_base(finalgdr_backupram, 0x80*0x100);
18751862
18761863   palshift = 0;
18771864   flip_bit = 1; //?
src/mame/drivers/arcadia.c
r9192r9193
5555
5656
5757
58/*************************************
59 *
60 *  Globals
61 *
62 *************************************/
58class arcadia_state : public amiga_state
59{
60public:
61   arcadia_state(running_machine &machine, const driver_device_config_base &config)
62      : amiga_state(machine, config) { }
6363
64static UINT8 coin_counter[2];
64   UINT8 coin_counter[2];
65};
6566
6667
6768
r9192r9193
136137   /* writing a 0 in the low bit clears one of the coins */
137138   if ((data & 1) == 0)
138139   {
140      UINT8 *coin_counter = device->machine->driver_data<arcadia_state>()->coin_counter;
141
139142      if (coin_counter[0] > 0)
140143         coin_counter[0]--;
141144      else if (coin_counter[1] > 0)
r9192r9193
153156
154157static CUSTOM_INPUT( coin_counter_r )
155158{
159   int coin = (FPTR)param;
160   UINT8 *coin_counter = field->port->machine->driver_data<arcadia_state>()->coin_counter;
161
156162   /* return coin counter values */
157   return *(UINT8 *)param & 3;
163   return coin_counter[coin] & 3;
158164}
159165
160166
161167static INPUT_CHANGED( coin_changed_callback )
162168{
163   UINT8 *counter = (UINT8 *)param;
169   int coin = (FPTR)param;
170   UINT8 *coin_counter = field->port->machine->driver_data<arcadia_state>()->coin_counter;
164171
165172   /* check for a 0 -> 1 transition */
166   if (!oldval && newval && *counter < 3)
167      *counter += 1;
173   if (!oldval && newval && coin_counter[coin] < 3)
174      coin_counter[coin] += 1;
168175}
169176
170177
171178static void arcadia_reset_coins(running_machine *machine)
172179{
180   UINT8 *coin_counter = machine->driver_data<arcadia_state>()->coin_counter;
181
173182   /* reset coin counters */
174183   coin_counter[0] = coin_counter[1] = 0;
175184}
r9192r9193
184193
185194static ADDRESS_MAP_START( amiga_map, ADDRESS_SPACE_PROGRAM, 16 )
186195   ADDRESS_MAP_UNMAP_HIGH
187   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram) AM_SIZE(&amiga_chip_ram_size)
196   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(arcadia_state, chip_ram, chip_ram_size)
188197   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
189   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)
198   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(arcadia_state, custom_regs)
190199   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
191200   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)      /* Kickstart BIOS */
192201
r9192r9193
218227   PORT_SERVICE_NO_TOGGLE( 0x02, IP_ACTIVE_LOW )
219228   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
220229   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
221   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(coin_counter_r, &coin_counter[0])
222   PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(coin_counter_r, &coin_counter[1])
230   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(coin_counter_r, 0)
231   PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(coin_counter_r, 1)
223232
224233   PORT_START("JOY0DAT")
225234   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P1JOY")
r9192r9193
249258   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
250259
251260   PORT_START("COINS")
252   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_changed_callback, &coin_counter[0])
253   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(coin_changed_callback, &coin_counter[1])
261   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_changed_callback, 0)
262   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(coin_changed_callback, 1)
254263INPUT_PORTS_END
255264
256265
r9192r9193
287296   DEVCB_NULL
288297};
289298
290static MACHINE_CONFIG_START( arcadia, driver_device )
299static MACHINE_CONFIG_START( arcadia, arcadia_state )
291300
292301   /* basic machine hardware */
293302   MDRV_CPU_ADD("maincpu", M68000, AMIGA_68000_NTSC_CLOCK)
r9192r9193
753762
754763static void arcadia_init(running_machine *machine)
755764{
765   arcadia_state *state = machine->driver_data<arcadia_state>();
756766   static const amiga_machine_interface arcadia_intf =
757767   {
758768      ANGUS_CHIP_RAM_MASK,
r9192r9193
768778   amiga_machine_config(machine, &arcadia_intf);
769779
770780   /* set up memory */
771   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram, 0);
781   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
772782   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
773783
774784   /* OnePlay bios is encrypted, TenPlay is not */
src/mame/drivers/segas16a.c
r9192r9193
152152#include "machine/segacrp2.h"
153153#include "machine/fd1089.h"
154154#include "machine/i8243.h"
155#include "machine/nvram.h"
155156#include "cpu/mcs48/mcs48.h"
156157#include "sound/dac.h"
157158#include "sound/2151intf.h"
r9192r9193
997998
998999/*************************************
9991000 *
1000 *  Capacitor-backed RAM
1001 *
1002 *************************************/
1003
1004static NVRAM_HANDLER( system16a )
1005{
1006   if (read_or_write)
1007      mame_fwrite(file, workram, 0x4000);
1008   else if (file)
1009      mame_fread(file, workram, 0x4000);
1010}
1011
1012
1013
1014/*************************************
1015 *
10161001 *  Main CPU memory handlers
10171002 *
10181003 *************************************/
r9192r9193
10261011   AM_RANGE(0x840000, 0x840fff) AM_MIRROR(0x3bf000) AM_RAM_WRITE(segaic16_paletteram_w) AM_BASE(&segaic16_paletteram)
10271012   AM_RANGE(0xc40000, 0xc43fff) AM_MIRROR(0x39c000) AM_READWRITE(misc_io_r, misc_io_w)
10281013   AM_RANGE(0xc60000, 0xc6ffff) AM_READ(watchdog_reset16_r)
1029   AM_RANGE(0xc70000, 0xc73fff) AM_MIRROR(0x38c000) AM_RAM AM_BASE(&workram)
1014   AM_RANGE(0xc70000, 0xc73fff) AM_MIRROR(0x38c000) AM_RAM AM_BASE(&workram) AM_SHARE("nvram")
10301015ADDRESS_MAP_END
10311016
10321017
r9192r9193
19741959
19751960   MDRV_MACHINE_START(system16a)
19761961   MDRV_MACHINE_RESET(system16a)
1977   MDRV_NVRAM_HANDLER(system16a)
1962   MDRV_NVRAM_ADD_0FILL("nvram")
19781963
19791964   MDRV_PPI8255_ADD( "ppi8255", single_ppi_intf )
19801965
src/mame/drivers/segas18.c
r9192r9193
3333#include "cpu/mcs51/mcs51.h"
3434#include "deprecat.h"
3535#include "machine/segaic16.h"
36#include "machine/nvram.h"
3637#include "includes/segas16.h"
3738#include "includes/genesis.h"
3839#include "sound/2612intf.h"
r9192r9193
178179   state->maincpu = machine->device("maincpu");
179180   state->soundcpu = machine->device("soundcpu");
180181   state->mcu = machine->device("mcu");
182   
183   machine->device<nvram_device>("nvram")->set_base(workram, 0x4000);
181184
182185   state_save_register_global(machine, state->mcu_data);
183186   state_save_register_global(machine, state->lghost_value);
r9192r9193
599602
600603/*************************************
601604 *
602 *  Capacitor-backed RAM
603 *
604 *************************************/
605
606static NVRAM_HANDLER( system18 )
607{
608   if (read_or_write)
609      mame_fwrite(file, workram, 0x4000);
610   else if (file)
611      mame_fread(file, workram, 0x4000);
612}
613
614
615
616/*************************************
617 *
618605 *  Main CPU memory handlers
619606 *
620607 *************************************/
r9192r9193
13001287   MDRV_CPU_IO_MAP(sound_portmap)
13011288
13021289   MDRV_MACHINE_RESET(system18)
1303   MDRV_NVRAM_HANDLER(system18)
1290   MDRV_NVRAM_ADD_0FILL("nvram")
13041291
13051292   /* video hardware */
13061293   MDRV_SCREEN_ADD("screen", RASTER)
src/mame/drivers/segaorun.c
r9192r9193
274274#include "machine/fd1089.h"
275275#include "machine/segaic16.h"
276276#include "machine/8255ppi.h"
277#include "machine/nvram.h"
277278#include "cpu/m68000/m68000.h"
278279#include "sound/2151intf.h"
279280#include "sound/segapcm.h"
r9192r9193
414415   state->soundcpu = machine->device("soundcpu");
415416   state->subcpu = machine->device("sub");
416417   state->ppi8255 = machine->device("ppi8255");
418   
419   machine->device<nvram_device>("nvram")->set_base(workram, 0x8000);
417420
418421   state_save_register_global(machine, state->adc_select);
419422   state_save_register_global(machine, state->vblank_irq_state);
r9192r9193
779782
780783/*************************************
781784 *
782 *  Capacitor-backed RAM
783 *
784 *************************************/
785
786static NVRAM_HANDLER( outrun )
787{
788   if (read_or_write)
789      mame_fwrite(file, workram, 0x8000);
790   else if (file)
791      mame_fread(file, workram, 0x8000);
792}
793
794
795
796/*************************************
797 *
798785 *  Main CPU memory handlers
799786 *
800787 *************************************/
r9192r9193
11611148MACHINE_CONFIG_END
11621149
11631150static MACHINE_CONFIG_DERIVED( outrun, outrun_base )
1164   MDRV_NVRAM_HANDLER(outrun)
1151   MDRV_NVRAM_ADD_0FILL("nvram")
11651152
11661153   MDRV_SEGA16SP_ADD_OUTRUN("segaspr1")
11671154MACHINE_CONFIG_END
11681155
11691156
11701157static MACHINE_CONFIG_DERIVED( shangon, outrun_base )
1171   MDRV_NVRAM_HANDLER(outrun)
1158   MDRV_NVRAM_ADD_0FILL("nvram")
11721159
11731160   MDRV_SCREEN_MODIFY("screen")
11741161   MDRV_SCREEN_RAW_PARAMS(MASTER_CLOCK_25MHz/4, 400, 0, 321, 262, 0, 224)
src/mame/drivers/videopkr.c
r9192r9193
283283#include "emu.h"
284284#include "cpu/mcs48/mcs48.h"
285285#include "cpu/mcs51/mcs51.h"
286#include "machine/nvram.h"
286287#include "sound/ay8910.h"
287288#include "sound/dac.h"
288289#include "videopkr.lh"
r9192r9193
475476   return 0;
476477}
477478
478/********************
479*   NVRAM Handler   *
480********************/
481479
482static NVRAM_HANDLER( videopkr )
483{
484   if (read_or_write)
485   {
486      mame_fwrite(file, data_ram, DATA_NVRAM_SIZE);
487      mame_fwrite(file, &count1, 8);
488      mame_fwrite(file, &count2, 8);
489      mame_fwrite(file, &count3, 8);
490      mame_fwrite(file, &count4, 8);
491
492   }
493   else
494   {
495      if (file)
496      {
497         mame_fread(file, data_ram, DATA_NVRAM_SIZE);
498         mame_fread(file, &count1, 8);
499         mame_fread(file, &count2, 8);
500         mame_fread(file, &count3, 8);
501         mame_fread(file, &count4, 8);
502      }
503      else
504      {
505         memset(data_ram, 0, DATA_NVRAM_SIZE);
506         memset(data_ram, count0, 8);
507         memset(data_ram, count0, 8);
508         memset(data_ram, count0, 8);
509         memset(data_ram, count0, 8);
510      }
511   }
512}
513
514
515480/*************************
516481*      R/W Handlers      *
517482*************************/
r9192r9193
11911156   p1 = 0xff;
11921157   ant_cio = 0;
11931158   count0 = 0;
1159
1160   machine->device<nvram_device>("nvram")->set_base(data_ram, sizeof(data_ram));
11941161}
11951162
11961163static const ay8910_interface ay8910_config =
r9192r9193
12211188   MDRV_CPU_PROGRAM_MAP(i8039_sound_mem)
12221189   MDRV_CPU_IO_MAP(i8039_sound_port)
12231190   MDRV_MACHINE_START(videopkr)
1224   MDRV_NVRAM_HANDLER(videopkr)
1191   MDRV_NVRAM_ADD_0FILL("nvram")
12251192
12261193   MDRV_TIMER_ADD_PERIODIC("t1_timer", sound_t1_callback, HZ(50))
12271194
src/mame/drivers/tetrisp2.c
r9192r9193
3939#include "sound/ymz280b.h"
4040#include "rocknms.lh"
4141#include "includes/tetrisp2.h"
42#include "machine/nvram.h"
4243
4344UINT16 tetrisp2_systemregs[0x10];
4445static UINT16 rocknms_sub_systemregs[0x10];
r9192r9193
222223***************************************************************************/
223224
224225static UINT16 *tetrisp2_nvram;
225static size_t tetrisp2_nvram_size;
226226
227static NVRAM_HANDLER( tetrisp2 )
228{
229   if (read_or_write)
230      mame_fwrite(file,tetrisp2_nvram,tetrisp2_nvram_size);
231   else
232   {
233      if (file)
234         mame_fread(file,tetrisp2_nvram,tetrisp2_nvram_size);
235      else
236      {
237         /* fill in the default values */
238         memset(tetrisp2_nvram,0,tetrisp2_nvram_size);
239      }
240   }
241}
242227
243
244228/* The game only ever writes even bytes and reads odd bytes */
245229static READ16_HANDLER( tetrisp2_nvram_r )
246230{
r9192r9193
322306   AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(tetrisp2_vram_rot_w) AM_BASE(&tetrisp2_vram_rot)   // Rotation
323307   AM_RANGE(0x650000, 0x651fff) AM_RAM_WRITE(tetrisp2_vram_rot_w)                        // Rotation (mirror)
324308   AM_RANGE(0x800000, 0x800003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff)   // Sound
325   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(tetrisp2_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SIZE(&tetrisp2_nvram_size)   // NVRAM
309   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(tetrisp2_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SHARE("nvram")   // NVRAM
326310   AM_RANGE(0x904000, 0x907fff) AM_READWRITE(tetrisp2_nvram_r, tetrisp2_nvram_w)            // NVRAM (mirror)
327311   AM_RANGE(0xb00000, 0xb00001) AM_WRITE(tetrisp2_coincounter_w)                        // Coin Counter
328312   AM_RANGE(0xb20000, 0xb20001) AM_WRITENOP                                       // ???
r9192r9193
384368
385369   AM_RANGE(0x800000, 0x800003) AM_DEVREADWRITE8_MODERN("oki", okim6295_device, read, write, 0x00ff )   // Sound
386370
387   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(tetrisp2_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SIZE(&tetrisp2_nvram_size   )   // NVRAM
371   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(tetrisp2_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SHARE("nvram")   // NVRAM
388372
389373   AM_RANGE(0xb00000, 0xb00001) AM_WRITE(nndmseal_coincounter_w)   // Coin Counter
390374   AM_RANGE(0xb20000, 0xb20001) AM_WRITE(nndmseal_b20000_w)      // ???
r9192r9193
423407   AM_RANGE(0x408000, 0x409fff) AM_RAM                                             // ???
424408   AM_RANGE(0x500000, 0x50ffff) AM_RAM                                             // Line
425409   AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(tetrisp2_vram_rot_w) AM_BASE(&tetrisp2_vram_rot)   // Rotation
426   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(rockn_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SIZE(&tetrisp2_nvram_size)   // NVRAM
410   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(rockn_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SHARE("nvram")   // NVRAM
427411   AM_RANGE(0xa30000, 0xa30001) AM_READWRITE(rockn_soundvolume_r, rockn_soundvolume_w)         // Sound Volume
428412   AM_RANGE(0xa40000, 0xa40003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff)   // Sound
429413   AM_RANGE(0xa44000, 0xa44001) AM_READWRITE(rockn_adpcmbank_r, rockn_adpcmbank_w)            // Sound Bank
r9192r9193
457441   AM_RANGE(0x800000, 0x803fff) AM_RAM_WRITE(tetrisp2_vram_fg_w) AM_BASE(&tetrisp2_vram_fg)   // Foreground
458442   AM_RANGE(0x804000, 0x807fff) AM_RAM_WRITE(tetrisp2_vram_bg_w) AM_BASE(&tetrisp2_vram_bg)   // Background
459443   AM_RANGE(0x808000, 0x809fff) AM_RAM                                             // ???
460   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(rockn_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SIZE(&tetrisp2_nvram_size)   // NVRAM
444   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(rockn_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SHARE("nvram")   // NVRAM
461445   AM_RANGE(0xa30000, 0xa30001) AM_READWRITE(rockn_soundvolume_r, rockn_soundvolume_w)         // Sound Volume
462446   AM_RANGE(0xa40000, 0xa40003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff)   // Sound
463447   AM_RANGE(0xa44000, 0xa44001) AM_READWRITE(rockn_adpcmbank_r, rockn2_adpcmbank_w)         // Sound Bank
r9192r9193
491475   AM_RANGE(0x800000, 0x803fff) AM_RAM_WRITE(tetrisp2_vram_fg_w) AM_BASE(&tetrisp2_vram_fg)   // Foreground
492476   AM_RANGE(0x804000, 0x807fff) AM_RAM_WRITE(tetrisp2_vram_bg_w) AM_BASE(&tetrisp2_vram_bg)   // Background
493477//  AM_RANGE(0x808000, 0x809fff) AM_RAM                                                         // ???
494   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(rockn_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SIZE(&tetrisp2_nvram_size)   // NVRAM
478   AM_RANGE(0x900000, 0x903fff) AM_READWRITE(rockn_nvram_r, tetrisp2_nvram_w) AM_BASE(&tetrisp2_nvram) AM_SHARE("nvram")   // NVRAM
495479   AM_RANGE(0xa30000, 0xa30001) AM_READWRITE(rockn_soundvolume_r, rockn_soundvolume_w)         // Sound Volume
496480   AM_RANGE(0xa40000, 0xa40003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff)   // Sound
497481   AM_RANGE(0xa44000, 0xa44001) AM_READWRITE(rockn_adpcmbank_r, rockn_adpcmbank_w)            // Sound Bank
r9192r9193
11131097   MDRV_CPU_PROGRAM_MAP(tetrisp2_map)
11141098   MDRV_CPU_VBLANK_INT("screen", irq2_line_hold)
11151099
1116   MDRV_NVRAM_HANDLER(tetrisp2)
1100   MDRV_NVRAM_ADD_0FILL("nvram")
11171101   MDRV_WATCHDOG_VBLANK_INIT(8)   /* guess */
11181102
11191103   /* video hardware */
r9192r9193
11461130   MDRV_CPU_PROGRAM_MAP(nndmseal_map)
11471131   MDRV_CPU_VBLANK_INT("screen", irq2_line_hold)
11481132
1149   MDRV_NVRAM_HANDLER(tetrisp2)
1133   MDRV_NVRAM_ADD_0FILL("nvram")
11501134
11511135   /* video hardware */
11521136   MDRV_SCREEN_ADD("screen", RASTER)
r9192r9193
11771161   MDRV_CPU_PROGRAM_MAP(rockn1_map)
11781162   MDRV_CPU_VBLANK_INT("screen", irq2_line_hold)
11791163
1180   MDRV_NVRAM_HANDLER(tetrisp2)
1164   MDRV_NVRAM_ADD_0FILL("nvram")
11811165
11821166   /* video hardware */
11831167   MDRV_SCREEN_ADD("screen", RASTER)
r9192r9193
12091193   MDRV_CPU_PROGRAM_MAP(rockn2_map)
12101194   MDRV_CPU_VBLANK_INT("screen", irq2_line_hold)
12111195
1212   MDRV_NVRAM_HANDLER(tetrisp2)
1196   MDRV_NVRAM_ADD_0FILL("nvram")
12131197
12141198   /* video hardware */
12151199   MDRV_SCREEN_ADD("screen", RASTER)
r9192r9193
12451229   MDRV_CPU_PROGRAM_MAP(rocknms_sub_map)
12461230   MDRV_CPU_VBLANK_INT("lscreen", irq2_line_hold)
12471231
1248   MDRV_NVRAM_HANDLER(tetrisp2)
1232   MDRV_NVRAM_ADD_0FILL("nvram")
12491233
12501234   /* video hardware */
12511235
src/mame/drivers/ssv.c
r9192r9193
184184#include "cpu/v60/v60.h"
185185#include "deprecat.h"
186186#include "machine/eeprom.h"
187#include "machine/nvram.h"
187188#include "sound/es5506.h"
188189#include "includes/ssv.h"
189190
r9192r9193
353354/***************************************************************************
354355
355356
356                            Non-Volatile RAM
357
358
359***************************************************************************/
360
361static NVRAM_HANDLER( ssv )
362{
363   ssv_state *state = machine->driver_data<ssv_state>();
364
365   if (read_or_write)
366      mame_fwrite(file, state->nvram, state->nvram_size);
367   else
368      if (file)
369         mame_fread(file, state->nvram, state->nvram_size);
370}
371
372/***************************************************************************
373
374
375357                                DSP
376358
377359
r9192r9193
454436   AM_RANGE(0x500000, 0x500001) AM_WRITENOP                              // ??
455437   AM_RANGE(0x510000, 0x510001) AM_READ(drifto94_rand_r      )                  // ??
456438   AM_RANGE(0x520000, 0x520001) AM_READ(drifto94_rand_r      )                  // ??
457   AM_RANGE(0x580000, 0x5807ff) AM_RAM AM_BASE_MEMBER(ssv_state, nvram) AM_SIZE_MEMBER(ssv_state, nvram_size)   // NVRAM
439   AM_RANGE(0x580000, 0x5807ff) AM_RAM AM_SHARE("nvram")   // NVRAM
458440   SSV_MAP( 0xc00000 )
459441ADDRESS_MAP_END
460442
r9192r9193
695677//  AM_RANGE(0x210002, 0x210003) AM_WRITENOP                                      // ? 5 at the start
696678//  AM_RANGE(0x280000, 0x280001) AM_READNOP                                       // ? read once, value not used
697679//  AM_RANGE(0x500004, 0x500005) AM_WRITENOP                                      // ? 0,58,18
698   AM_RANGE(0x580000, 0x58ffff) AM_RAM AM_BASE_MEMBER(ssv_state, nvram) AM_SIZE_MEMBER(ssv_state, nvram_size)   // NVRAM
680   AM_RANGE(0x580000, 0x58ffff) AM_RAM AM_SHARE("nvram")   // NVRAM
699681   SSV_MAP( 0xf00000 )
700682ADDRESS_MAP_END
701683
r9192r9193
883865   AM_RANGE(0x500002, 0x500003) AM_READ(sxyreact_ballswitch_r)                     // ?
884866   AM_RANGE(0x500004, 0x500005) AM_READWRITE(sxyreact_dial_r, sxyreact_motor_w)      // Dial Value (serial)
885867   AM_RANGE(0x520000, 0x520001) AM_WRITE(sxyreact_dial_w)                        // Dial Value (advance 1 bit)
886   AM_RANGE(0x580000, 0x58ffff) AM_RAM AM_BASE_MEMBER(ssv_state, nvram) AM_SIZE_MEMBER(ssv_state, nvram_size)   // NVRAM
868   AM_RANGE(0x580000, 0x58ffff) AM_RAM AM_SHARE("nvram")   // NVRAM
887869   SSV_MAP( 0xe00000 )
888870ADDRESS_MAP_END
889871
r9192r9193
10551037   AM_RANGE(0x800000, 0x800001) AM_WRITE(eaglshot_gfxrom_w)
10561038   AM_RANGE(0x900000, 0x900001) AM_WRITE(eaglshot_trackball_w)
10571039   AM_RANGE(0xa00000, 0xbfffff) AM_READ(eaglshot_gfxrom_r)
1058   AM_RANGE(0xc00000, 0xc007ff) AM_RAM AM_BASE_MEMBER(ssv_state, nvram) AM_SIZE_MEMBER(ssv_state, nvram_size)   // NVRAM
1040   AM_RANGE(0xc00000, 0xc007ff) AM_RAM AM_SHARE("nvram")   // NVRAM
10591041   AM_RANGE(0xd00000, 0xd00001) AM_READ(eaglshot_trackball_r)
10601042   SSV_MAP( 0xf00000 )
10611043ADDRESS_MAP_END
r9192r9193
27232705   MDRV_CPU_MODIFY("maincpu")
27242706   MDRV_CPU_PROGRAM_MAP(drifto94_map)
27252707
2726   MDRV_NVRAM_HANDLER(ssv)
2708   MDRV_NVRAM_ADD_0FILL("nvram")
27272709
27282710   /* video hardware */
27292711   MDRV_SCREEN_MODIFY("screen")
r9192r9193
28042786   MDRV_CPU_MODIFY("maincpu")
28052787   MDRV_CPU_PROGRAM_MAP(meosism_map)
28062788
2807   MDRV_NVRAM_HANDLER(ssv)
2789   MDRV_NVRAM_ADD_0FILL("nvram")
28082790
28092791   /* video hardware */
28102792   MDRV_SCREEN_MODIFY("screen")
r9192r9193
28762858   MDRV_CPU_MODIFY("maincpu")
28772859   MDRV_CPU_PROGRAM_MAP(drifto94_map)
28782860
2879   MDRV_NVRAM_HANDLER(ssv)
2861   MDRV_NVRAM_ADD_0FILL("nvram")
28802862   /* video hardware */
28812863   MDRV_SCREEN_MODIFY("screen")
28822864   MDRV_SCREEN_VISIBLE_AREA(0, (0xd6-0x26)*2-1, 0, (0xfe - 0x0e)-1)
r9192r9193
29102892   MDRV_CPU_MODIFY("maincpu")
29112893   MDRV_CPU_PROGRAM_MAP(eaglshot_map)
29122894
2913   MDRV_NVRAM_HANDLER(ssv)
2895   MDRV_NVRAM_ADD_0FILL("nvram")
29142896
29152897   /* video hardware */
29162898   MDRV_SCREEN_MODIFY("screen")
r9192r9193
29282910   MDRV_CPU_MODIFY("maincpu")
29292911   MDRV_CPU_PROGRAM_MAP(sxyreact_map)
29302912
2931   MDRV_NVRAM_HANDLER(ssv)
2913   MDRV_NVRAM_ADD_0FILL("nvram")
29322914
29332915   /* video hardware */
29342916   MDRV_SCREEN_MODIFY("screen")
r9192r9193
29412923   MDRV_CPU_MODIFY("maincpu")
29422924   MDRV_CPU_PROGRAM_MAP(sxyreact_map)
29432925
2944   MDRV_NVRAM_HANDLER(ssv)
2926   MDRV_NVRAM_ADD_0FILL("nvram")
29452927
29462928   /* video hardware */
29472929   MDRV_SCREEN_MODIFY("screen")
r9192r9193
29542936   MDRV_CPU_MODIFY("maincpu")
29552937   MDRV_CPU_PROGRAM_MAP(sxyreact_map)
29562938
2957   MDRV_NVRAM_HANDLER(ssv)
2939   MDRV_NVRAM_ADD_0FILL("nvram")
29582940
29592941   /* video hardware */
29602942   MDRV_SCREEN_MODIFY("screen")
src/mame/drivers/cubocd32.c
r9192r9193
338338#define MGNUMBER_USE_JOY   1
339339
340340
341static void handle_cd32_joystick_cia(UINT8 pra, UINT8 dra);
341static void handle_cd32_joystick_cia(running_machine *machine, UINT8 pra, UINT8 dra);
342342
343343static WRITE32_HANDLER( aga_overlay_w )
344344{
r9192r9193
382382   /* bit 2 = Power Led on Amiga */
383383   set_led_status(device->machine, 0, (data & 2) ? 0 : 1);
384384
385   handle_cd32_joystick_cia(data, mos6526_r(device, 2));
385   handle_cd32_joystick_cia(device->machine, data, mos6526_r(device, 2));
386386}
387387
388388/*************************************
r9192r9193
415415
416416static ADDRESS_MAP_START( cd32_map, ADDRESS_SPACE_PROGRAM, 32 )
417417   ADDRESS_MAP_UNMAP_HIGH
418   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram32) AM_SIZE(&amiga_chip_ram_size)
418   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(cubocd32_state, chip_ram, chip_ram_size)
419419   AM_RANGE(0x800000, 0x800003) AM_READ_PORT("DIPSW1")
420420   AM_RANGE(0x800010, 0x800013) AM_READ_PORT("DIPSW2")
421   AM_RANGE(0xb80000, 0xb8003f) AM_READWRITE(amiga_akiko32_r, amiga_akiko32_w)
421   AM_RANGE(0xb80000, 0xb8003f) AM_DEVREADWRITE("akiko", amiga_akiko32_r, amiga_akiko32_w)
422422   AM_RANGE(0xbfa000, 0xbfa003) AM_WRITE(aga_overlay_w)
423423   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE16(amiga_cia_r, amiga_cia_w, 0xffffffff)
424   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE((UINT32**)&amiga_custom_regs)
424   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE_MEMBER(cubocd32_state, custom_regs)
425425   AM_RANGE(0xe00000, 0xe7ffff) AM_ROM AM_REGION("user1", 0x80000)   /* CD32 Extended ROM */
426426   AM_RANGE(0xa00000, 0xf7ffff) AM_NOP
427427   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0x0)      /* Kickstart */
r9192r9193
433433 *
434434 *************************************/
435435
436static UINT16 potgo_value = 0;
437static int cd32_shifter[2];
438static void (*cubocd32_input_hack)(running_machine *machine) = 0;
439
440436static void cubocd32_potgo_w(running_machine *machine, UINT16 data)
441437{
438   cubocd32_state *state = machine->driver_data<cubocd32_state>();
442439   int i;
443440
444   if (cubocd32_input_hack != NULL)
445      cubocd32_input_hack(machine);
441   if (state->input_hack != NULL)
442      (*state->input_hack)(machine);
446443
447   potgo_value = potgo_value & 0x5500;
448   potgo_value |= data & 0xaa00;
444   state->potgo_value = state->potgo_value & 0x5500;
445   state->potgo_value |= data & 0xaa00;
449446
450    for (i = 0; i < 8; i += 2)
447   for (i = 0; i < 8; i += 2)
451448   {
452449      UINT16 dir = 0x0200 << i;
453450      if (data & dir)
454451      {
455452         UINT16 d = 0x0100 << i;
456         potgo_value &= ~d;
457         potgo_value |= data & d;
453         state->potgo_value &= ~d;
454         state->potgo_value |= data & d;
458455      }
459    }
460    for (i = 0; i < 2; i++)
456   }
457   for (i = 0; i < 2; i++)
461458   {
462       UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
463       UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
464       if ((potgo_value & p5dir) && (potgo_value & p5dat))
465         cd32_shifter[i] = 8;
466    }
459      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
460      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
461      if ((state->potgo_value & p5dir) && (state->potgo_value & p5dat))
462         state->cd32_shifter[i] = 8;
463   }
467464}
468465
469static void handle_cd32_joystick_cia(UINT8 pra, UINT8 dra)
466static void handle_cd32_joystick_cia(running_machine *machine, UINT8 pra, UINT8 dra)
470467{
471    static int oldstate[2];
472    int i;
468   cubocd32_state *state = machine->driver_data<cubocd32_state>();
469   int i;
473470
474    for (i = 0; i < 2; i++)
471   for (i = 0; i < 2; i++)
475472   {
476473      UINT8 but = 0x40 << i;
477474      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
478475      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
479476
480      if (!(potgo_value & p5dir) || !(potgo_value & p5dat))
477      if (!(state->potgo_value & p5dir) || !(state->potgo_value & p5dat))
481478      {
482         if ((dra & but) && (pra & but) != oldstate[i])
479         if ((dra & but) && (pra & but) != state->oldstate[i])
483480         {
484481            if (!(pra & but))
485482            {
486               cd32_shifter[i]--;
487               if (cd32_shifter[i] < 0)
488                  cd32_shifter[i] = 0;
483               state->cd32_shifter[i]--;
484               if (state->cd32_shifter[i] < 0)
485                  state->cd32_shifter[i] = 0;
489486            }
490487         }
491488      }
492      oldstate[i] = pra & but;
493    }
489      state->oldstate[i] = pra & but;
490   }
494491}
495492
496static UINT16 handle_joystick_potgor (running_machine *machine, UINT16 potgor)
493static UINT16 handle_joystick_potgor(running_machine *machine, UINT16 potgor)
497494{
495   cubocd32_state *state = machine->driver_data<cubocd32_state>();
498496   static const char *const player_portname[] = { "P2", "P1" };
499    int i;
497   int i;
500498
501    for (i = 0; i < 2; i++)
499   for (i = 0; i < 2; i++)
502500   {
503501      UINT16 p9dir = 0x0800 << (i * 4); /* output enable P9 */
504502      UINT16 p9dat = 0x0400 << (i * 4); /* data P9 */
505503      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
506504      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
507505
508       /* p5 is floating in input-mode */
509       potgor &= ~p5dat;
510       potgor |= potgo_value & p5dat;
511       if (!(potgo_value & p9dir))
506      /* p5 is floating in input-mode */
507      potgor &= ~p5dat;
508      potgor |= state->potgo_value & p5dat;
509      if (!(state->potgo_value & p9dir))
512510         potgor |= p9dat;
513       /* P5 output and 1 -> shift register is kept reset (Blue button) */
514       if ((potgo_value & p5dir) && (potgo_value & p5dat))
515         cd32_shifter[i] = 8;
516       /* shift at 1 == return one, >1 = return button states */
517       if (cd32_shifter[i] == 0)
511      /* P5 output and 1 -> shift register is kept reset (Blue button) */
512      if ((state->potgo_value & p5dir) && (state->potgo_value & p5dat))
513         state->cd32_shifter[i] = 8;
514      /* shift at 1 == return one, >1 = return button states */
515      if (state->cd32_shifter[i] == 0)
518516         potgor &= ~p9dat; /* shift at zero == return zero */
519      if (cd32_shifter[i] >= 2 && (input_port_read(machine, player_portname[i]) & (1 << (cd32_shifter[i] - 2))))
517      if (state->cd32_shifter[i] >= 2 && (input_port_read(machine, player_portname[i]) & (1 << (state->cd32_shifter[i] - 2))))
520518         potgor &= ~p9dat;
521    }
522    return potgor;
519   }
520   return potgor;
523521}
524522
525523static CUSTOM_INPUT(cubo_input)
526524{
527   return handle_joystick_potgor(field->port->machine, potgo_value) >> 10;
525   cubocd32_state *state = field->port->machine->driver_data<cubocd32_state>();
526   return handle_joystick_potgor(field->port->machine, state->potgo_value) >> 10;
528527}
529528
530529static INPUT_PORTS_START( cd32 )
r9192r9193
10511050   I2CMEM_SLAVE_ADDRESS, NVRAM_PAGE_SIZE, NVRAM_SIZE
10521051};
10531052
1054static MACHINE_CONFIG_START( cd32, driver_device )
1053static MACHINE_CONFIG_START( cd32, cubocd32_state )
10551054
10561055   /* basic machine hardware */
10571056   MDRV_CPU_ADD("maincpu", M68EC020, AMIGA_68EC020_PAL_CLOCK) /* 14.3 Mhz */
10581057   MDRV_CPU_PROGRAM_MAP(cd32_map)
1058   MDRV_DEVICE_ADD("akiko", AKIKO, 0)
10591059
10601060   MDRV_MACHINE_RESET(amiga)
10611061
r9192r9193
10751075   MDRV_VIDEO_UPDATE(amiga_aga)
10761076
10771077   /* sound hardware */
1078    MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
1078   MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
10791079
1080    MDRV_SOUND_ADD("amiga", AMIGA, 3579545)
1081    MDRV_SOUND_ROUTE(0, "lspeaker", 0.25)
1082    MDRV_SOUND_ROUTE(1, "rspeaker", 0.25)
1083    MDRV_SOUND_ROUTE(2, "rspeaker", 0.25)
1084    MDRV_SOUND_ROUTE(3, "lspeaker", 0.25)
1080   MDRV_SOUND_ADD("amiga", AMIGA, 3579545)
1081   MDRV_SOUND_ROUTE(0, "lspeaker", 0.25)
1082   MDRV_SOUND_ROUTE(1, "rspeaker", 0.25)
1083   MDRV_SOUND_ROUTE(2, "rspeaker", 0.25)
1084   MDRV_SOUND_ROUTE(3, "lspeaker", 0.25)
10851085
1086    MDRV_SOUND_ADD( "cdda", CDDA, 0 )
1086   MDRV_SOUND_ADD( "cdda", CDDA, 0 )
10871087   MDRV_SOUND_ROUTE( 0, "lspeaker", 0.50 )
10881088   MDRV_SOUND_ROUTE( 1, "rspeaker", 0.50 )
10891089
r9192r9193
11571157
11581158static DRIVER_INIT( cd32 )
11591159{
1160   cubocd32_state *state = machine->driver_data<cubocd32_state>();
11601161   static const amiga_machine_interface cubocd32_intf =
11611162   {
11621163      AGA_CHIP_RAM_MASK,
r9192r9193
11711172   amiga_machine_config(machine, &cubocd32_intf);
11721173
11731174   /* set up memory */
1174   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram32, 0);
1175   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
11751176   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
11761177
1177   /* intialize akiko */
1178   amiga_akiko_init(machine);
1179
11801178   /* input hack */
1181   cubocd32_input_hack = NULL;
1179   state->input_hack = NULL;
11821180}
11831181
11841182
r9192r9193
11901188
11911189static void cndypuzl_input_hack(running_machine *machine)
11921190{
1193   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1191   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1192
1193   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
11941194   {
1195//      amiga_chip_ram_w(0x051c02, 0x0000);
1195      //(*state->chip_ram_w)(0x051c02, 0x0000);
11961196
11971197      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1198      amiga_chip_ram_w(r_A5 - 0x7ebe, 0x0000);
1198      (*state->chip_ram_w)(state, r_A5 - 0x7ebe, 0x0000);
11991199   }
12001200}
12011201
12021202static DRIVER_INIT(cndypuzl)
12031203{
1204   cubocd32_state *state = machine->driver_data<cubocd32_state>();
12041205   DRIVER_INIT_CALL(cd32);
1205   cubocd32_input_hack = cndypuzl_input_hack;
1206   state->input_hack = cndypuzl_input_hack;
12061207}
12071208
12081209static void haremchl_input_hack(running_machine *machine)
12091210{
1210   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1211   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1212
1213   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
12111214   {
1212//      amiga_chip_ram_w8(0x002907, 0x00);
1215      //amiga_chip_ram_w8(state, 0x002907, 0x00);
12131216
12141217      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1215      UINT32 r_A2 = (amiga_chip_ram_r(r_A5 - 0x7f00 + 0) << 16) | (amiga_chip_ram_r(r_A5 - 0x7f00 + 2));
1216      amiga_chip_ram_w8(r_A2 + 0x1f, 0x00);
1218      UINT32 r_A2 = ((*state->chip_ram_r)(state, r_A5 - 0x7f00 + 0) << 16) | ((*state->chip_ram_r)(state, r_A5 - 0x7f00 + 2));
1219      amiga_chip_ram_w8(state, r_A2 + 0x1f, 0x00);
12171220   }
12181221}
12191222
12201223static DRIVER_INIT(haremchl)
12211224{
1225   cubocd32_state *state = machine->driver_data<cubocd32_state>();
12221226   DRIVER_INIT_CALL(cd32);
1223   cubocd32_input_hack = haremchl_input_hack;
1227   state->input_hack = haremchl_input_hack;
12241228}
12251229
12261230static void lsrquiz_input_hack(running_machine *machine)
12271231{
1228   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1232   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1233
1234   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
12291235   {
1230//      amiga_chip_ram_w8(0x001e1b, 0x00);
1236      //amiga_chip_ram_w8(state, 0x001e1b, 0x00);
12311237
12321238      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1233      UINT32 r_A2 = (amiga_chip_ram_r(r_A5 - 0x7fe0 + 0) << 16) | (amiga_chip_ram_r(r_A5 - 0x7fe0 + 2));
1234      amiga_chip_ram_w8(r_A2 + 0x13, 0x00);
1239      UINT32 r_A2 = ((*state->chip_ram_r)(state, r_A5 - 0x7fe0 + 0) << 16) | ((*state->chip_ram_r)(state, r_A5 - 0x7fe0 + 2));
1240      amiga_chip_ram_w8(state, r_A2 + 0x13, 0x00);
12351241   }
12361242}
12371243
12381244static DRIVER_INIT(lsrquiz)
12391245{
1246   cubocd32_state *state = machine->driver_data<cubocd32_state>();
12401247   DRIVER_INIT_CALL(cd32);
1241   cubocd32_input_hack = lsrquiz_input_hack;
1248   state->input_hack = lsrquiz_input_hack;
12421249}
12431250
12441251/* The hack isn't working if you exit the test mode with P1 button 2 ! */
12451252static void lsrquiz2_input_hack(running_machine *machine)
12461253{
1247   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1254   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1255
1256   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
12481257   {
1249//      amiga_chip_ram_w8(0x046107, 0x00);
1258      //amiga_chip_ram_w8(state, 0x046107, 0x00);
12501259
12511260      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1252      UINT32 r_A2 = (amiga_chip_ram_r(r_A5 - 0x7fdc + 0) << 16) | (amiga_chip_ram_r(r_A5 - 0x7fdc + 2));
1253      amiga_chip_ram_w8(r_A2 + 0x17, 0x00);
1261      UINT32 r_A2 = ((*state->chip_ram_r)(state, r_A5 - 0x7fdc + 0) << 16) | ((*state->chip_ram_r)(state, r_A5 - 0x7fdc + 2));
1262      amiga_chip_ram_w8(state, r_A2 + 0x17, 0x00);
12541263   }
12551264}
12561265
12571266static DRIVER_INIT(lsrquiz2)
12581267{
1268   cubocd32_state *state = machine->driver_data<cubocd32_state>();
12591269   DRIVER_INIT_CALL(cd32);
1260   cubocd32_input_hack = lsrquiz2_input_hack;
1270   state->input_hack = lsrquiz2_input_hack;
12611271}
12621272
12631273static void lasstixx_input_hack(running_machine *machine)
12641274{
1265   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1275   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1276
1277   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
12661278   {
1267//      amiga_chip_ram_w8(0x00281c, 0x00);
1279      //amiga_chip_ram_w8(state, 0x00281c, 0x00);
12681280
12691281      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1270      UINT32 r_A2 = (amiga_chip_ram_r(r_A5 - 0x7fa2 + 0) << 16) | (amiga_chip_ram_r(r_A5 - 0x7fa2 + 2));
1271      amiga_chip_ram_w8(r_A2 + 0x24, 0x00);
1282      UINT32 r_A2 = ((*state->chip_ram_r)(state, r_A5 - 0x7fa2 + 0) << 16) | ((*state->chip_ram_r)(state, r_A5 - 0x7fa2 + 2));
1283      amiga_chip_ram_w8(state, r_A2 + 0x24, 0x00);
12721284   }
12731285}
12741286
12751287static DRIVER_INIT(lasstixx)
12761288{
1289   cubocd32_state *state = machine->driver_data<cubocd32_state>();
12771290   DRIVER_INIT_CALL(cd32);
1278   cubocd32_input_hack = lasstixx_input_hack;
1291   state->input_hack = lasstixx_input_hack;
12791292}
12801293
12811294static void mgnumber_input_hack(running_machine *machine)
12821295{
1283   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1296   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1297
1298   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
12841299   {
1285//      amiga_chip_ram_w(0x04bfa0, 0x0000);
1300      //(*state->chip_ram_w)(0x04bfa0, 0x0000);
12861301
12871302      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1288      amiga_chip_ram_w(r_A5 - 0x7ed8, 0x0000);
1303      (*state->chip_ram_w)(state, r_A5 - 0x7ed8, 0x0000);
12891304   }
12901305}
12911306
12921307static DRIVER_INIT(mgnumber)
12931308{
1309   cubocd32_state *state = machine->driver_data<cubocd32_state>();
12941310   DRIVER_INIT_CALL(cd32);
1295   cubocd32_input_hack = mgnumber_input_hack;
1311   state->input_hack = mgnumber_input_hack;
12961312}
12971313
12981314static void mgprem11_input_hack(running_machine *machine)
12991315{
1300   if(cpu_get_pc(machine->device("maincpu")) < amiga_chip_ram_size)
1316   cubocd32_state *state = machine->driver_data<cubocd32_state>();
1317
1318   if (cpu_get_pc(machine->device("maincpu")) < state->chip_ram_size)
13011319   {
1302//      amiga_chip_ram_w8(0x044f7e, 0x00);
1320      //amiga_chip_ram_w8(state, 0x044f7e, 0x00);
13031321
13041322      UINT32 r_A5 = cpu_get_reg(machine->device("maincpu"), M68K_A5);
1305      amiga_chip_ram_w8(r_A5 - 0x7eca, 0x00);
1323      amiga_chip_ram_w8(state, r_A5 - 0x7eca, 0x00);
13061324   }
13071325}
13081326
13091327static DRIVER_INIT(mgprem11)
13101328{
1329   cubocd32_state *state = machine->driver_data<cubocd32_state>();
13111330   DRIVER_INIT_CALL(cd32);
1312   cubocd32_input_hack = mgprem11_input_hack;
1331   state->input_hack = mgprem11_input_hack;
13131332}
13141333
13151334/***************************************************************************************************/
src/mame/drivers/alg.c
r9192r9193
2929#include "machine/nvram.h"
3030
3131
32static running_device *laserdisc;
33static emu_timer *serial_timer;
34static UINT8 serial_timer_active;
35static UINT16 input_select;
32class alg_state : public amiga_state
33{
34public:
35   alg_state(running_machine &machine, const driver_device_config_base &config)
36      : amiga_state(machine, config) { }
3637
38
39   running_device *laserdisc;
40   emu_timer *serial_timer;
41   UINT8 serial_timer_active;
42   UINT16 input_select;
43};
44
3745static TIMER_CALLBACK( response_timer );
3846
3947
r9192r9193
7482
7583   /* configure pen 4096 as transparent in the renderer and use it for the genlock color */
7684   palette_set_color(machine, 4096, MAKE_ARGB(0,0,0,0));
77   amiga_set_genlock_color(4096);
85   amiga_set_genlock_color(machine, 4096);
7886}
7987
8088
r9192r9193
8795
8896static MACHINE_START( alg )
8997{
90   laserdisc = machine->device("laserdisc");
98   alg_state *state = machine->driver_data<alg_state>();
99   state->laserdisc = machine->device("laserdisc");
91100
92   serial_timer = timer_alloc(machine, response_timer, NULL);
93   serial_timer_active = FALSE;
101   state->serial_timer = timer_alloc(machine, response_timer, NULL);
102   state->serial_timer_active = FALSE;
94103}
95104
96105
r9192r9193
109118
110119static TIMER_CALLBACK( response_timer )
111120{
121   alg_state *state = machine->driver_data<alg_state>();
122
112123   /* if we still have data to send, do it now */
113   if (laserdisc_line_r(laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
124   if (laserdisc_line_r(state->laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
114125   {
115      UINT8 data = laserdisc_data_r(laserdisc);
126      UINT8 data = laserdisc_data_r(state->laserdisc);
116127      if (data != 0x0a)
117128         mame_printf_debug("Sending serial data = %02X\n", data);
118129      amiga_serial_in_w(machine, data);
119130   }
120131
121132   /* if there's more to come, set another timer */
122   if (laserdisc_line_r(laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
123      timer_adjust_oneshot(serial_timer, amiga_get_serial_char_period(machine), 0);
133   if (laserdisc_line_r(state->laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
134      timer_adjust_oneshot(state->serial_timer, amiga_get_serial_char_period(machine), 0);
124135   else
125      serial_timer_active = FALSE;
136      state->serial_timer_active = FALSE;
126137}
127138
128139
129140static void vsync_callback(running_machine *machine)
130141{
142   alg_state *state = machine->driver_data<alg_state>();
143
131144   /* if we have data available, set a timer to read it */
132   if (!serial_timer_active && laserdisc_line_r(laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
145   if (!state->serial_timer_active && laserdisc_line_r(state->laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
133146   {
134      timer_adjust_oneshot(serial_timer, amiga_get_serial_char_period(machine), 0);
135      serial_timer_active = TRUE;
147      timer_adjust_oneshot(state->serial_timer, amiga_get_serial_char_period(machine), 0);
148      state->serial_timer_active = TRUE;
136149   }
137150}
138151
139152
140153static void serial_w(running_machine *machine, UINT16 data)
141154{
155   alg_state *state = machine->driver_data<alg_state>();
156
142157   /* write to the laserdisc player */
143   laserdisc_data_w(laserdisc, data & 0xff);
158   laserdisc_data_w(state->laserdisc, data & 0xff);
144159
145160   /* if we have data available, set a timer to read it */
146   if (!serial_timer_active && laserdisc_line_r(laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
161   if (!state->serial_timer_active && laserdisc_line_r(state->laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
147162   {
148      timer_adjust_oneshot(serial_timer, amiga_get_serial_char_period(machine), 0);
149      serial_timer_active = TRUE;
163      timer_adjust_oneshot(state->serial_timer, amiga_get_serial_char_period(machine), 0);
164      state->serial_timer_active = TRUE;
150165   }
151166}
152167
r9192r9193
160175
161176static void alg_potgo_w(running_machine *machine, UINT16 data)
162177{
178   alg_state *state = machine->driver_data<alg_state>();
179
163180   /* bit 15 controls whether pin 9 is input/output */
164181   /* bit 14 controls the value, which selects which player's controls to read */
165   input_select = (data & 0x8000) ? ((data >> 14) & 1) : 0;
182   state->input_select = (data & 0x8000) ? ((data >> 14) & 1) : 0;
166183}
167184
168185
169186static CUSTOM_INPUT( lightgun_pos_r )
170187{
188   alg_state *state = field->port->machine->driver_data<alg_state>();
171189   int x = 0, y = 0;
172190
173191   /* get the position based on the input select */
174   get_lightgun_pos(*field->port->machine->primary_screen, input_select, &x, &y);
192   get_lightgun_pos(*field->port->machine->primary_screen, state->input_select, &x, &y);
175193   return (y << 8) | (x >> 2);
176194}
177195
178196
179197static CUSTOM_INPUT( lightgun_trigger_r )
180198{
199   alg_state *state = field->port->machine->driver_data<alg_state>();
200
181201   /* read the trigger control based on the input select */
182   return (input_port_read(field->port->machine, "TRIGGERS") >> input_select) & 1;
202   return (input_port_read(field->port->machine, "TRIGGERS") >> state->input_select) & 1;
183203}
184204
185205
186206static CUSTOM_INPUT( lightgun_holster_r )
187207{
208   alg_state *state = field->port->machine->driver_data<alg_state>();
209
188210   /* read the holster control based on the input select */
189   return (input_port_read(field->port->machine, "TRIGGERS") >> (2 + input_select)) & 1;
211   return (input_port_read(field->port->machine, "TRIGGERS") >> (2 + state->input_select)) & 1;
190212}
191213
192214
r9192r9193
257279
258280static ADDRESS_MAP_START( main_map_r1, ADDRESS_SPACE_PROGRAM, 16 )
259281   ADDRESS_MAP_UNMAP_HIGH
260   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram)   AM_SIZE(&amiga_chip_ram_size)
282   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(alg_state, chip_ram, chip_ram_size)
261283   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
262   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)
284   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(alg_state, custom_regs)
263285   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
264286   AM_RANGE(0xfc0000, 0xffffff) AM_ROM AM_REGION("user1", 0)         /* System ROM */
265287
r9192r9193
270292
271293static ADDRESS_MAP_START( main_map_r2, ADDRESS_SPACE_PROGRAM, 16 )
272294   ADDRESS_MAP_UNMAP_HIGH
273   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram)   AM_SIZE(&amiga_chip_ram_size)
295   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(alg_state, chip_ram, chip_ram_size)
274296   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
275   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)
297   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(alg_state, custom_regs)
276298   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
277299   AM_RANGE(0xfc0000, 0xffffff) AM_ROM AM_REGION("user1", 0)         /* System ROM */
278300
r9192r9193
283305
284306static ADDRESS_MAP_START( main_map_picmatic, ADDRESS_SPACE_PROGRAM, 16 )
285307   ADDRESS_MAP_UNMAP_HIGH
286   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram)   AM_SIZE(&amiga_chip_ram_size)
308   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(alg_state, chip_ram, chip_ram_size)
287309   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
288   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)
310   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(alg_state, custom_regs)
289311   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
290312   AM_RANGE(0xfc0000, 0xffffff) AM_ROM AM_REGION("user1", 0)         /* System ROM */
291313
r9192r9193
404426   DEVCB_NULL                        /* port B */
405427};
406428
407static MACHINE_CONFIG_START( alg_r1, driver_device )
429static MACHINE_CONFIG_START( alg_r1, alg_state )
408430
409431   /* basic machine hardware */
410432   MDRV_CPU_ADD("maincpu", M68000, AMIGA_68000_NTSC_CLOCK)
r9192r9193
418440   MDRV_LASERDISC_OVERLAY(amiga, 512*2, 262, BITMAP_FORMAT_INDEXED16)
419441   MDRV_LASERDISC_OVERLAY_CLIP((129-8)*2, (449+8-1)*2, 44-8, 244+8-1)
420442
421    /* video hardware */
443   /* video hardware */
422444   MDRV_LASERDISC_SCREEN_ADD_NTSC("screen", BITMAP_FORMAT_INDEXED16)
423445   MDRV_SCREEN_REFRESH_RATE(59.997)
424446   MDRV_SCREEN_SIZE(512*2, 262)
r9192r9193
658680
659681static void alg_init(running_machine *machine)
660682{
683   alg_state *state = machine->driver_data<alg_state>();
661684   static const amiga_machine_interface alg_intf =
662685   {
663686      ANGUS_CHIP_RAM_MASK,
r9192r9193
672695   amiga_machine_config(machine, &alg_intf);
673696
674697   /* set up memory */
675   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram, 0);
698   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
676699   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
677700}
678701
src/mame/drivers/playch10.c
r9192r9193
294294#include "video/ppu2c0x.h"
295295#include "cpu/z80/z80.h"
296296#include "machine/rp5h01.h"
297#include "machine/nvram.h"
297298#include "sound/dac.h"
298299#include "sound/nes_apu.h"
299300
r9192r9193
336337   ppu2c0x_spriteram_dma( space, space->machine->device("ppu"), source );
337338}
338339
339static NVRAM_HANDLER( playch10 )
340{
341   UINT8 *mem = memory_region( machine, "cart" ) + 0x6000;
342
343   if ( read_or_write )
344      mame_fwrite( file, mem, 0x1000 );
345   else if (file)
346      mame_fread( file, mem, 0x1000 );
347   else
348      memset(mem, 0, 0x1000);
349}
350
351340/* Only used in single monitor bios */
352341static UINT8 *timedata;
353342
r9192r9193
733722MACHINE_CONFIG_END
734723
735724static MACHINE_CONFIG_DERIVED( playchnv, playch10 )
736   MDRV_NVRAM_HANDLER(playch10)
725   MDRV_NVRAM_ADD_0FILL("nvram")
737726MACHINE_CONFIG_END
738727
739728static MACHINE_CONFIG_DERIVED( playch10_hboard, playch10 )
src/mame/drivers/upscope.c
r9192r9193
3030#include "machine/nvram.h"
3131
3232
33class upscope_state : public driver_device
33class upscope_state : public amiga_state
3434{
3535public:
3636   upscope_state(running_machine &machine, const driver_device_config_base &config)
37      : driver_device(machine, config) { }
37      : amiga_state(machine, config) { }
3838
3939   UINT8   m_nvram[0x100];
4040};
r9192r9193
248248
249249static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 16 )
250250   ADDRESS_MAP_UNMAP_HIGH
251   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram)   AM_SIZE(&amiga_chip_ram_size)
251   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(upscope_state, chip_ram, chip_ram_size)
252252   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
253   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)
253   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(upscope_state, custom_regs)
254254   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
255255   AM_RANGE(0xfc0000, 0xffffff) AM_ROM AM_REGION("user1", 0)         /* System ROM */
256256
r9192r9193
321321   MDRV_MACHINE_RESET(amiga)
322322   MDRV_NVRAM_ADD_0FILL("nvram")
323323
324    /* video hardware */
324   /* video hardware */
325325   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
326326
327327   MDRV_SCREEN_ADD("screen", RASTER)
r9192r9193
391391
392392static DRIVER_INIT( upscope )
393393{
394   upscope_state *state = machine->driver_data<upscope_state>();
394395   static const amiga_machine_interface upscope_intf =
395396   {
396397      ANGUS_CHIP_RAM_MASK,
r9192r9193
403404   amiga_machine_config(machine, &upscope_intf);
404405
405406   /* allocate NVRAM */
406   upscope_state *state = machine->driver_data<upscope_state>();
407407   machine->device<nvram_device>("nvram")->set_base(state->m_nvram, sizeof(state->m_nvram));
408408
409409   /* set up memory */
410   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram, 0);
410   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
411411   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
412412}
413413
src/mame/drivers/segas16b.c
r9192r9193
877877#include "machine/fd1089.h"
878878#include "machine/fd1094.h"
879879#include "machine/mc8123.h"
880#include "machine/nvram.h"
880881#include "sound/2151intf.h"
881882#include "sound/2413intf.h"
882883#include "sound/upd7759.h"
r9192r9193
910911static UINT16 *workram;
911912
912913
914
913915/*************************************
914916 *
915917 *  Prototypes
r9192r9193
10821084   /* init the FD1094 */
10831085   fd1094_driver_init(machine, "maincpu", segaic16_memory_mapper_set_decrypted);
10841086
1087   machine->device<nvram_device>("nvram")->set_base(workram, 0x4000);
1088
10851089   state_save_register_global_pointer(machine, segaic16_spriteram_0, 0x00800/2);
10861090   state_save_register_global_pointer(machine, segaic16_paletteram,  0x01000/2);
10871091   state_save_register_global_pointer(machine, segaic16_tileram_0,   0x10000/2);
r9192r9193
17851789
17861790/*************************************
17871791 *
1788 *  Capacitor-backed RAM
1789 *
1790 *************************************/
1791
1792static NVRAM_HANDLER( system16b )
1793{
1794   if (read_or_write)
1795      mame_fwrite(file, workram, 0x4000);
1796   else if (file)
1797      mame_fread(file, workram, 0x4000);
1798}
1799
1800
1801
1802/*************************************
1803 *
18041792 *  Main CPU memory handlers
18051793 *
18061794 *************************************/
r9192r9193
32933281   MDRV_CPU_IO_MAP(sound_portmap)
32943282
32953283   MDRV_MACHINE_RESET(system16b)
3296   MDRV_NVRAM_HANDLER(system16b)
3284   MDRV_NVRAM_ADD_0FILL("nvram")
32973285
32983286   /* video hardware */
32993287   MDRV_GFXDECODE(segas16b)
src/mame/drivers/mquake.c
r9192r9193
140140
141141static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 16 )
142142   ADDRESS_MAP_UNMAP_HIGH
143   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram)   AM_SIZE(&amiga_chip_ram_size)
143   AM_RANGE(0x000000, 0x07ffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, chip_ram, chip_ram_size)
144144   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
145   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)
145   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, custom_regs)
146146   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
147147   AM_RANGE(0xfc0000, 0xffffff) AM_ROM AM_REGION("user1", 0)         /* System ROM */
148148
r9192r9193
357357   DEVCB_NULL
358358};
359359
360static MACHINE_CONFIG_START( mquake, driver_device )
360static MACHINE_CONFIG_START( mquake, amiga_state )
361361
362362   /* basic machine hardware */
363363   MDRV_CPU_ADD("maincpu", M68000, AMIGA_68000_NTSC_CLOCK)
r9192r9193
366366   MDRV_MACHINE_RESET(mquake)
367367   MDRV_NVRAM_ADD_0FILL("nvram")
368368
369    /* video hardware */
369   /* video hardware */
370370   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
371371
372372   MDRV_SCREEN_ADD("screen", RASTER)
r9192r9193
447447
448448static DRIVER_INIT(mquake)
449449{
450   amiga_state *state = machine->driver_data<amiga_state>();
450451   static const amiga_machine_interface mquake_intf =
451452   {
452453      ANGUS_CHIP_RAM_MASK,
r9192r9193
459460   amiga_machine_config(machine, &mquake_intf);
460461
461462   /* set up memory */
462   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram, 0);
463   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
463464   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
464465}
465466
src/emu/cpu/asap/asap.c
r9192r9193
4646
4747
4848//**************************************************************************
49//  DEVICE DEFINITIONS
50//**************************************************************************
51
52const device_type ASAP = asap_device_config::static_alloc_device_config;
53
54
55
56//**************************************************************************
4957//  CONSTANTS
5058//**************************************************************************
5159
r9192r9193
17451753{
17461754   generate_exception(EXCEPTION_TRAPF);
17471755}
1748
1749
1750
1751const device_type ASAP = asap_device_config::static_alloc_device_config;
src/emu/video.c
r9192r9193
7272
7373
7474/***************************************************************************
75    DEVICE DEFINITIONS
76***************************************************************************/
77
78const device_type SCREEN = screen_device_config::static_alloc_device_config;
79
80
81
82/***************************************************************************
7583    TYPE DEFINITIONS
7684***************************************************************************/
7785
r9192r9193
26532661#define BILINEAR_FILTER      1
26542662
26552663#include "rendersw.c"
2656
2657const device_type SCREEN = screen_device_config::static_alloc_device_config;
src/emu/sound/okim6295.c
r9192r9193
4444//  GLOBAL VARIABLES
4545//**************************************************************************
4646
47// devices
48const device_type OKIM6295 = okim6295_device_config::static_alloc_device_config;
49
4750// ADPCM state and tables
4851bool adpcm_state::s_tables_computed = false;
4952const INT8 adpcm_state::s_index_shift[8] = { -1, -1, -1, -1, 2, 4, 6, 8 };
r9192r9193
542545      }
543546   }
544547}
545
546const device_type OKIM6295 = okim6295_device_config::static_alloc_device_config;
src/emu/machine/74123.c
r9192r9193
1515
1616
1717//**************************************************************************
18//  DEVICE DEFINITIONS
19//**************************************************************************
20
21const device_type TTL74123 = ttl74123_device_config::static_alloc_device_config;
22
23
24//**************************************************************************
1825//  DEVICE CONFIGURATION
1926//**************************************************************************
2027
r9192r9193
340347{
341348   set_output();
342349}
343
344const device_type TTL74123 = ttl74123_device_config::static_alloc_device_config;
src/emu/machine/6532riot.c
r9192r9193
1515#include "6532riot.h"
1616
1717
18/***************************************************************************
19    CONSTANTS
20***************************************************************************/
18//**************************************************************************
19//  DEVICE DEFINITIONS
20//**************************************************************************
2121
22const device_type RIOT6532 = riot6532_device_config::static_alloc_device_config;
23
24
25
26//**************************************************************************
27//  CONSTANTS
28//**************************************************************************
29
2230enum
2331{
2432   TIMER_IDLE,
r9192r9193
574582   m_timerstate = TIMER_IDLE;
575583   timer_adjust_oneshot(m_timer, attotime_never, 0);
576584}
577
578const device_type RIOT6532 = riot6532_device_config::static_alloc_device_config;
src/emu/machine/7474.c
r9192r9193
4040#include "emu.h"
4141#include "7474.h"
4242
43
4344//**************************************************************************
45//  DEVICE DEFINITIONS
46//**************************************************************************
47
48const device_type MACHINE_TTL7474 = ttl7474_device_config::static_alloc_device_config;
49
50
51
52//**************************************************************************
4453//  DEVICE CONFIGURATION
4554//**************************************************************************
4655
r9192r9193
319328    m_last_clock = 1;
320329    m_last_output = -1;
321330}
322
323const device_type MACHINE_TTL7474 = ttl7474_device_config::static_alloc_device_config;
src/emu/machine/z80dma.c
r9192r9193
2727#include "cpu/z80/z80daisy.h"
2828
2929
30//**************************************************************************
31//  DEVICE DEFINITIONS
32//**************************************************************************
3033
34const device_type Z80DMA = z80dma_device_config::static_alloc_device_config;
35
36
37
3138//**************************************************************************
3239//  CONSTANTS
3340//**************************************************************************
r9192r9193
897904WRITE_LINE_DEVICE_HANDLER( z80dma_rdy_w ) { downcast<z80dma_device *>(device)->rdy_w(state); }
898905WRITE_LINE_DEVICE_HANDLER( z80dma_wait_w ) { downcast<z80dma_device *>(device)->wait_w(state); }
899906WRITE_LINE_DEVICE_HANDLER( z80dma_bai_w ) { downcast<z80dma_device *>(device)->bai_w(state); }
900
901const device_type Z80DMA = z80dma_device_config::static_alloc_device_config;
src/emu/machine/z80pio.c
r9192r9193
1212#include "cpu/z80/z80daisy.h"
1313
1414
15//**************************************************************************
16//  DEVICE DEFINITIONS
17//**************************************************************************
1518
19const device_type Z80PIO = z80pio_device_config::static_alloc_device_config;
20
21
22
1623//**************************************************************************
1724//  CONSTANTS
1825//**************************************************************************
r9192r9193
878885
879886   BIT(offset, 0) ? z80pio_c_w(device, index, data) : z80pio_d_w(device, index, data);
880887}
881
882const device_type Z80PIO = z80pio_device_config::static_alloc_device_config;
src/emu/machine/i2cmem.c
r9192r9193
5555//  GLOBAL VARIABLES
5656//**************************************************************************
5757
58const device_type I2CMEM = i2cmem_device_config::static_alloc_device_config;
5859
5960static ADDRESS_MAP_START( i2cmem_map8, ADDRESS_SPACE_PROGRAM, 8 )
6061   AM_RANGE(0x0000, 0x0fff) AM_RAM
r9192r9193
603604{
604605   return ( ( ( m_devsel << 7 ) & 0xff00 ) | ( m_byteaddr & 0xff ) ) & address_mask();
605606}
606
607const device_type I2CMEM = i2cmem_device_config::static_alloc_device_config;
src/emu/machine/z80sti.c
r9192r9193
3535
3636
3737//**************************************************************************
38//  DEVICE DEFINITIONS
39//**************************************************************************
40
41const device_type Z80STI = z80sti_device_config::static_alloc_device_config;
42
43
44
45//**************************************************************************
3846//  CONSTANTS
3947//**************************************************************************
4048
r9192r9193
779787WRITE_LINE_DEVICE_HANDLER( z80sti_i5_w ) { downcast<z80sti_device *>(device)->gpip_input(5, state); }
780788WRITE_LINE_DEVICE_HANDLER( z80sti_i6_w ) { downcast<z80sti_device *>(device)->gpip_input(6, state); }
781789WRITE_LINE_DEVICE_HANDLER( z80sti_i7_w ) { downcast<z80sti_device *>(device)->gpip_input(7, state); }
782
783const device_type Z80STI = z80sti_device_config::static_alloc_device_config;
src/emu/machine/mb3773.c
r9192r9193
1414#include "mb3773.h"
1515
1616
17//**************************************************************************
18//  DEVICE DEFINITIONS
19//**************************************************************************
1720
21const device_type MB3773 = mb3773_device_config::static_alloc_device_config;
22
23
24
1825//**************************************************************************
1926//  DEVICE CONFIGURATION
2027//**************************************************************************
r9192r9193
151158{
152159   reinterpret_cast<mb3773_device *>(ptr)->m_machine.schedule_soft_reset();
153160}
154
155
156
157const device_type MB3773 = mb3773_device_config::static_alloc_device_config;
src/emu/machine/z80dart.c
r9192r9193
4444
4545
4646//**************************************************************************
47//  DEVICE DEFINITIONS
48//**************************************************************************
49
50const device_type Z80DART = z80dart_device_config::static_alloc_device_config;
51const device_type Z80SIO0 = z80dart_device_config::static_alloc_device_config; // FIXME
52const device_type Z80SIO1 = z80dart_device_config::static_alloc_device_config; // FIXME
53const device_type Z80SIO2 = z80dart_device_config::static_alloc_device_config; // FIXME
54const device_type Z80SIO3 = z80dart_device_config::static_alloc_device_config; // FIXME
55const device_type Z80SIO4 = z80dart_device_config::static_alloc_device_config; // FIXME
56
57
58
59//**************************************************************************
4760//  CONSTANTS
4861//**************************************************************************
4962
r9192r9193
14881501   else
14891502      z80dart_d_w(device, channel, data);
14901503}
1491
1492const device_type Z80DART = z80dart_device_config::static_alloc_device_config;
1493const device_type Z80SIO0 = z80dart_device_config::static_alloc_device_config; // FIXME
1494const device_type Z80SIO1 = z80dart_device_config::static_alloc_device_config; // FIXME
1495const device_type Z80SIO2 = z80dart_device_config::static_alloc_device_config; // FIXME
1496const device_type Z80SIO3 = z80dart_device_config::static_alloc_device_config; // FIXME
1497const device_type Z80SIO4 = z80dart_device_config::static_alloc_device_config; // FIXME
src/emu/machine/at28c16.c
r9192r9193
2020//  GLOBAL VARIABLES
2121//**************************************************************************
2222
23const device_type AT28C16 = at28c16_device_config::static_alloc_device_config;
2324
2425static ADDRESS_MAP_START( at28c16_map8, ADDRESS_SPACE_PROGRAM, 8 )
2526   AM_RANGE(0x0000, 0x081f) AM_RAM
r9192r9193
333334{
334335   reinterpret_cast<at28c16_device *>(ptr)->m_last_write = -1;
335336}
336
337
338
339const device_type AT28C16 = at28c16_device_config::static_alloc_device_config;
src/emu/machine/eeprom.c
r9192r9193
2424//  GLOBAL VARIABLES
2525//**************************************************************************
2626
27const device_type EEPROM = eeprom_device_config::static_alloc_device_config;
28
2729const eeprom_interface eeprom_interface_93C46 =
2830{
2931   6,            // address bits 6
r9192r9193
594596   }
595597   return (*cmd==0);
596598}
597
598const device_type EEPROM = eeprom_device_config::static_alloc_device_config;
src/emu/machine/z80sio.c
r9192r9193
2525
2626
2727//**************************************************************************
28//  DEVICE DEFINITIONS
29//**************************************************************************
30
31const device_type Z80SIO = z80sio_device_config::static_alloc_device_config;
32
33
34
35//**************************************************************************
2836//  CONSTANTS
2937//**************************************************************************
3038
r9192r9193
898906      case 3: z80sio_c_w(device, 1, data); break;
899907   }
900908}
901
902const device_type Z80SIO = z80sio_device_config::static_alloc_device_config;
src/emu/machine/z80ctc.c
r9192r9193
2727
2828
2929//**************************************************************************
30//  DEVICE DEFINITIONS
31//**************************************************************************
32
33const device_type Z80CTC = z80ctc_device_config::static_alloc_device_config;
34
35
36
37//**************************************************************************
3038//  CONSTANTS
3139//**************************************************************************
3240
r9192r9193
559567WRITE_LINE_DEVICE_HANDLER( z80ctc_trg1_w ) { downcast<z80ctc_device *>(device)->trigger(1, state); }
560568WRITE_LINE_DEVICE_HANDLER( z80ctc_trg2_w ) { downcast<z80ctc_device *>(device)->trigger(2, state); }
561569WRITE_LINE_DEVICE_HANDLER( z80ctc_trg3_w ) { downcast<z80ctc_device *>(device)->trigger(3, state); }
562
563const device_type Z80CTC = z80ctc_device_config::static_alloc_device_config;
src/emu/sound.c
r9192r9193
3838
3939
4040/***************************************************************************
41    DEVICE DEFINITIONS
42***************************************************************************/
43
44const device_type SPEAKER = speaker_device_config::static_alloc_device_config;
45
46
47
48/***************************************************************************
4149    TYPE DEFINITIONS
4250***************************************************************************/
4351
r9192r9193
777785   speaker_device *speaker = index_to_input(machine, index, inputnum);
778786   return (speaker != NULL) ? speaker->input_name(inputnum) : 0;
779787}
780
781const device_type SPEAKER = speaker_device_config::static_alloc_device_config;
src/emu/timer.c
r9192r9193
3636
3737
3838/***************************************************************************
39    DEVICE DEFINITIONS
40***************************************************************************/
41
42const device_type TIMER = timer_device_config::static_alloc_device_config;
43
44
45
46/***************************************************************************
3947    TYPE DEFINITIONS
4048***************************************************************************/
4149
r9192r9193
12651273   // adjust the timer
12661274   timer_adjust_oneshot(m_timer, m_screen->time_until_pos(next_vpos), 0);
12671275}
1268
1269const device_type TIMER = timer_device_config::static_alloc_device_config;
src/mess/machine/amigafdc.c
r9192r9193
224224
225225static int fdc_get_curpos( running_device *device, int drive )
226226{
227   amiga_state *state = device->machine->driver_data<amiga_state>();
227228   double elapsed;
228229   int speed;
229230   int   bytes;
r9192r9193
246247
247248UINT16 amiga_fdc_get_byte (running_device *device)
248249{
250   amiga_state *state = device->machine->driver_data<amiga_state>();
249251   int pos;
250252   int i, drive = -1;
251253   UINT16 ret;
r9192r9193
285287
286288static TIMER_CALLBACK(fdc_sync_proc)
287289{
290   amiga_state *state = machine->driver_data<amiga_state>();
288291   int drive = param;
289292   UINT16         sync = CUSTOM_REG(REG_DSRSYNC);
290293   int            cur_pos;
r9192r9193
339342
340343static TIMER_CALLBACK(fdc_dma_proc)
341344{
345   amiga_state *state = machine->driver_data<amiga_state>();
342346   int drive = param;
343347   amiga_fdc_t *fdc = get_safe_token((running_device*)ptr);
344348
r9192r9193
389393
390394         cur_pos %= ( fdc->fdc_status[drive].tracklen );
391395
392         amiga_chip_ram_w(offset, dat);
396         (*state->chip_ram_w)(state, offset, dat);
393397
394398         offset += 2;
395399      }
r9192r9193
422426}
423427
424428void amiga_fdc_setup_dma( running_device *device ) {
429   amiga_state *state = device->machine->driver_data<amiga_state>();
425430   int i, cur_pos, drive = -1, len_words = 0;
426431   int time = 0;
427432   amiga_fdc_t *fdc = get_safe_token(device);
r9192r9193
657662
658663static TIMER_CALLBACK(fdc_rev_proc)
659664{
665   amiga_state *state = machine->driver_data<amiga_state>();
660666   int drive = param;
661667   int time;
662668   running_device *cia;
src/mess/machine/amigakbd.c
r9192r9193
6565   /* Special case Page UP, which we will use as Action Replay button */
6666   if ( (index == 3) && ( delta & 0x80000000 ) && ( newvalue & 0x80000000 ) )
6767   {
68      const amiga_machine_interface *amiga_intf = amiga_get_interface();
68      const amiga_machine_interface *amiga_intf = amiga_get_interface(field->port->machine);
6969
7070      if ( amiga_intf != NULL && amiga_intf->nmi_callback )
7171      {
src/mess/machine/amigacrt.c
r9192r9193
8888
8989static void amiga_ar1_nmi( running_machine *machine )
9090{
91   amiga_state *state = machine->driver_data<amiga_state>();
9192   /* get the cart's built-in ram */
9293   UINT16 *ar_ram = (UINT16 *)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_write_ptr(0x9fc000);
9394
r9192r9193
107108
108109static WRITE16_HANDLER( amiga_ar1_chipmem_w )
109110{
111   amiga_state *state = space->machine->driver_data<amiga_state>();
110112   int pc = cpu_get_pc(space->cpu);
111113
112114   /* see if we're inside the AR1 rom */
r9192r9193
122124      }
123125   }
124126
125   amiga_chip_ram_w( offset * 2, data );
127   (*state->chip_ram_w)(state, offset * 2, data );
126128}
127129
128130static void amiga_ar1_check_overlay( running_machine *machine )
r9192r9193
216218
217219static READ16_HANDLER( amiga_ar23_mode_r )
218220{
221   amiga_state *state = space->machine->driver_data<amiga_state>();
219222   UINT16 *mem = (UINT16 *)memory_region( space->machine, "user2" );
220223
221224   if ( ACCESSING_BITS_0_7 )
r9192r9193
225228
226229      if ( offset == 0x03 ) /* disable cart oberlay on chip mem */
227230      {
228         UINT32 mirror_mask = amiga_chip_ram_size;
231         UINT32 mirror_mask = state->chip_ram_size;
229232
230233         memory_set_bank(space->machine, "bank1", 0);
231234
r9192r9193
235238         }
236239
237240         /* overlay disabled, map RAM on 0x000000 */
238         memory_install_write_bank(space, 0x000000, amiga_chip_ram_size - 1, 0, mirror_mask, "bank1");
241         memory_install_write_bank(space, 0x000000, state->chip_ram_size - 1, 0, mirror_mask, "bank1");
239242      }
240243   }
241244
r9192r9193
244247
245248static WRITE16_HANDLER( amiga_ar23_chipmem_w )
246249{
250   amiga_state *state = space->machine->driver_data<amiga_state>();
247251   if ( offset == (0x08/2) )
248252   {
249253      if ( amiga_ar23_mode & 1 )
250254         amiga_ar23_freeze(space->machine);
251255   }
252256
253   amiga_chip_ram_w( offset * 2, data );
257   (*state->chip_ram_w)(state, offset * 2, data );
254258}
255259
256260static void amiga_ar23_freeze( running_machine *machine )
257261{
262   amiga_state *state = machine->driver_data<amiga_state>();
258263   int pc = cpu_get_pc(machine->device("maincpu"));
259264
260265   /* only freeze if we're not inside the cart's ROM */
r9192r9193
275280      memory_set_bank(machine, "bank1", 2);
276281
277282      /* writes go to chipram */
278      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x000000, amiga_chip_ram_size - 1, 0, 0, amiga_ar23_chipmem_w);
283      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x000000, state->chip_ram_size - 1, 0, 0, amiga_ar23_chipmem_w);
279284
280285      /* trigger NMI irq */
281286      cputag_set_input_line(machine, "maincpu", 7, PULSE_LINE);
r9192r9193
338343
339344static void amiga_ar23_init( running_machine *machine, int ar3 )
340345{
346   amiga_state *state = machine->driver_data<amiga_state>();
341347   UINT32 mirror = 0x20000, size = 0x1ffff;
342348   void *ar_ram;
343349
r9192r9193
377383   memory_set_bankptr(machine, "bank2", memory_region(machine, "user2"));
378384   memory_set_bankptr(machine, "bank3", ar_ram);
379385
380   memory_configure_bank(machine, "bank1", 0, 2, amiga_chip_ram, 0);
386   memory_configure_bank(machine, "bank1", 0, 2, state->chip_ram, 0);
381387   memory_configure_bank(machine, "bank1", 1, 2, memory_region(machine, "user1"), 0);
382388   memory_configure_bank(machine, "bank1", 2, 2, memory_region(machine, "user2"), 0);
383389
src/mess/machine/amigacd.c
r9192r9193
8787
8888static TIMER_CALLBACK(dmac_dma_proc)
8989{
90   amiga_state *state = machine->driver_data<amiga_state>();
9091   while( dmac_data.wtc > 0 )
9192   {
9293      UINT16   dat16;
r9192r9193
103104      dat16 <<= 8;
104105      dat16 |= dat8;
105106
106      amiga_chip_ram_w(dmac_data.acr, dat16);
107      (*state->chip_ram_w)(state, dmac_data.acr, dat16);
107108
108109      dmac_data.acr += 2;
109110      dmac_data.wtc--;
r9192r9193
451452
452453static TIMER_CALLBACK(tp6525_delayed_irq)
453454{
455   amiga_state *state = machine->driver_data<amiga_state>();
454456   (void)param;
455457
456458   if ( (CUSTOM_REG(REG_INTREQ) & INTENA_PORTS) == 0 )
r9192r9193
465467
466468void amigacd_tpi6525_irq(running_device *device, int level)
467469{
470   amiga_state *state = device->machine->driver_data<amiga_state>();
468471   LOG(( "TPI6525 Interrupt: level = %d\n", level ));
469472
470473   if ( level )
src/mess/drivers/amiga.c
r9192r9193
9494
9595static ADDRESS_MAP_START(amiga_mem, ADDRESS_SPACE_PROGRAM, 16)
9696   ADDRESS_MAP_UNMAP_HIGH
97   AM_RANGE(0x000000, 0x07ffff) AM_MIRROR(0x80000) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram) AM_SIZE(&amiga_chip_ram_size)
97   AM_RANGE(0x000000, 0x07ffff) AM_MIRROR(0x80000) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, chip_ram, chip_ram_size)
9898   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
9999   AM_RANGE(0xc00000, 0xc7ffff) AM_RAM /* slow-mem */
100100   AM_RANGE(0xc80000, 0xcfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w)   /* see Note 1 above */
101   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)   /* Custom Chips */
101   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, custom_regs)   /* Custom Chips */
102102   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
103103   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* System ROM - mirror */
104104ADDRESS_MAP_END
r9192r9193
148148 */
149149
150150static ADDRESS_MAP_START(cdtv_mem, ADDRESS_SPACE_PROGRAM, 16)
151   AM_RANGE(0x000000, 0x0fffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram) AM_SIZE(&amiga_chip_ram_size)
151   AM_RANGE(0x000000, 0x0fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, chip_ram, chip_ram_size)
152152   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
153153   AM_RANGE(0xdc0000, 0xdc003f) AM_READWRITE(amiga_clock_r, amiga_clock_w)
154154   AM_RANGE(0xdc8000, 0xdc87ff) AM_RAM AM_SHARE("nvram")
155   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)   /* Custom Chips */
155   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, custom_regs)   /* Custom Chips */
156156   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
157157   AM_RANGE(0xf00000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* CDTV & System ROM */
158158ADDRESS_MAP_END
r9192r9193
176176ADDRESS_MAP_END
177177
178178static ADDRESS_MAP_START(a1000_mem, ADDRESS_SPACE_PROGRAM, 16)
179   AM_RANGE(0x000000, 0x03ffff) AM_MIRROR(0xc0000) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram) AM_SIZE(&amiga_chip_ram_size)
179   AM_RANGE(0x000000, 0x03ffff) AM_MIRROR(0xc0000) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, chip_ram, chip_ram_size)
180180   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
181181   AM_RANGE(0xc00000, 0xc3ffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) /* See Note 1 above */
182   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)   /* Custom Chips */
182   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, custom_regs)   /* Custom Chips */
183183   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
184184   AM_RANGE(0xf80000, 0xfbffff) AM_ROM AM_REGION("user1", 0)   /* Bootstrap ROM */
185185   AM_RANGE(0xfc0000, 0xffffff) AM_RAMBANK("bank2")   /* Writable Control Store RAM */
r9192r9193
366366   MDRV_CARTSLOT_NOT_MANDATORY
367367MACHINE_CONFIG_END
368368
369static MACHINE_CONFIG_START( ntsc, driver_device )
369static MACHINE_CONFIG_START( ntsc, amiga_state )
370370   /* basic machine hardware */
371371   MDRV_CPU_ADD("maincpu", M68000, AMIGA_68000_NTSC_CLOCK)
372372   MDRV_CPU_PROGRAM_MAP(amiga_mem)
r9192r9193
502502
503503static WRITE8_DEVICE_HANDLER( amiga_cia_0_portA_w )
504504{
505   amiga_state *state = device->machine->driver_data<amiga_state>();
505506   /* switch banks as appropriate */
506507   memory_set_bank(device->machine, "bank1", data & 1);
507508
508509   /* swap the write handlers between ROM and bank 1 based on the bit */
509510   if ((data & 1) == 0) {
510      UINT32 mirror_mask = amiga_chip_ram_size;
511      UINT32 mirror_mask = state->chip_ram_size;
511512
512513      while( (mirror_mask<<1) < 0x100000 ) {
513514         mirror_mask |= ( mirror_mask << 1 );
514515      }
515516
516517      /* overlay disabled, map RAM on 0x000000 */
517      memory_install_write_bank(cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x000000, amiga_chip_ram_size - 1, 0, mirror_mask, "bank1");
518      memory_install_write_bank(cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x000000, state->chip_ram_size - 1, 0, mirror_mask, "bank1");
518519
519520      /* if there is a cart region, check for cart overlay */
520521      if (memory_region(device->machine, "user2") != NULL)
r9192r9193
522523   }
523524   else
524525      /* overlay enabled, map Amiga system ROM on 0x000000 */
525      memory_unmap_write(cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x000000, amiga_chip_ram_size - 1, 0, 0);
526      memory_unmap_write(cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x000000, state->chip_ram_size - 1, 0, 0);
526527
527528   set_led_status( device->machine, 0, ( data & 2 ) ? 0 : 1 ); /* bit 2 = Power Led on Amiga */
528529   output_set_value("power_led", ( data & 2 ) ? 0 : 1);
r9192r9193
563564
564565static void amiga_write_dsklen(running_machine *machine, UINT16 data)
565566{
567   amiga_state *state = machine->driver_data<amiga_state>();
566568   if ( data & 0x8000 ) {
567569      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
568570         amiga_fdc_setup_dma(machine->device("fdc"));
r9192r9193
586588
587589static DRIVER_INIT( amiga )
588590{
591   amiga_state *state = machine->driver_data<amiga_state>();
589592   static const amiga_machine_interface amiga_intf =
590593   {
591594      ANGUS_CHIP_RAM_MASK,
r9192r9193
602605   amiga_machine_config(machine, &amiga_intf);
603606
604607   /* set up memory */
605   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram, 0);
608   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
606609   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
607610
608611   /* initialize cartridge (if present) */
r9192r9193
635638   amiga_machine_config(machine, &amiga_intf);
636639
637640   /* set up memory */
638   memory_configure_bank(1, 0, 1, amiga_chip_ram, 0);
641   memory_configure_bank(1, 0, 1, state->chip_ram, 0);
639642   memory_configure_bank(1, 1, 1, memory_region(machine, "user1"), 0);
640643
641644   /* initialize Action Replay (if present) */
r9192r9193
648651
649652static DRIVER_INIT( cdtv )
650653{
654   amiga_state *state = machine->driver_data<amiga_state>();
651655   static const amiga_machine_interface amiga_intf =
652656   {
653657      ECS_CHIP_RAM_MASK,
r9192r9193
664668   amiga_machine_config(machine, &amiga_intf);
665669
666670   /* set up memory */
667   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram, 0);
671   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
668672   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
669673
670674   /* initialize keyboard - in cdtv we can use a standard Amiga keyboard*/
src/mess/drivers/ami1200.c
r9192r9193
132132
133133static ADDRESS_MAP_START( a1200_map, ADDRESS_SPACE_PROGRAM, 32 )
134134   ADDRESS_MAP_UNMAP_HIGH
135   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram32) AM_SIZE(&amiga_chip_ram_size)
135   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(cubocd32_state, chip_ram, chip_ram_size)
136136   AM_RANGE(0xbfa000, 0xbfa003) AM_WRITE(aga_overlay_w)
137137   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE16(amiga_cia_r, amiga_cia_w, 0xffffffff)
138   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE((UINT32**)&amiga_custom_regs)
138   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE_MEMBER(cubocd32_state, custom_regs)
139139   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE16(amiga_autoconfig_r, amiga_autoconfig_w, 0xffffffff)
140140   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* Kickstart */
141141ADDRESS_MAP_END
142142
143143static ADDRESS_MAP_START( cd32_map, ADDRESS_SPACE_PROGRAM, 32 )
144144   ADDRESS_MAP_UNMAP_HIGH
145   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram32) AM_SIZE(&amiga_chip_ram_size)
146   AM_RANGE(0xb80000, 0xb8003f) AM_READWRITE(amiga_akiko32_r, amiga_akiko32_w)
145   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(cubocd32_state, chip_ram, chip_ram_size)
146   AM_RANGE(0xb80000, 0xb8003f) AM_DEVREADWRITE("akiko", amiga_akiko32_r, amiga_akiko32_w)
147147   AM_RANGE(0xbfa000, 0xbfa003) AM_WRITE(aga_overlay_w)
148148   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE16(amiga_cia_r, amiga_cia_w, 0xffffffff)
149   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE((UINT32**)&amiga_custom_regs)
149   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE_MEMBER(cubocd32_state, custom_regs)
150150   AM_RANGE(0xe00000, 0xe7ffff) AM_ROM AM_REGION("user1", 0x80000)   /* CD32 Extended ROM */
151151   AM_RANGE(0xa00000, 0xf7ffff) AM_NOP
152152   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0x0)      /* Kickstart */
r9192r9193
437437   DEVCB_NULL                           /* port B */
438438};
439439
440static MACHINE_CONFIG_START( a1200n, driver_device )
440static MACHINE_CONFIG_START( a1200n, cubocd32_state )
441441
442442   /* basic machine hardware */
443443   MDRV_CPU_ADD("maincpu", M68EC020, AMIGA_68EC020_NTSC_CLOCK) /* 14.3 Mhz */
r9192r9193
505505   I2CMEM_SLAVE_ADDRESS, NVRAM_PAGE_SIZE, NVRAM_SIZE
506506};
507507
508static MACHINE_CONFIG_START( cd32, driver_device )
508static MACHINE_CONFIG_START( cd32, cubocd32_state )
509509
510510   /* basic machine hardware */
511511   MDRV_CPU_ADD("maincpu", M68EC020, AMIGA_68EC020_NTSC_CLOCK) /* 14.3 Mhz */
r9192r9193
543543   /* cia */
544544   MDRV_MOS8520_ADD("cia_0", AMIGA_68EC020_PAL_CLOCK / 10, cd32_cia_0_intf)
545545   MDRV_MOS8520_ADD("cia_1", AMIGA_68EC020_PAL_CLOCK / 10, cd32_cia_1_intf)
546   
547   MDRV_DEVICE_ADD("akiko", AKIKO, 0)
546548MACHINE_CONFIG_END
547549
548550
r9192r9193
588590
589591static void a1200_write_dsklen(running_machine *machine, UINT16 data)
590592{
593   cubocd32_state *state = machine->driver_data<cubocd32_state>();
591594   if ( data & 0x8000 )
592595   {
593596      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
r9192r9193
598601
599602static DRIVER_INIT( a1200 )
600603{
604   cubocd32_state *state = machine->driver_data<cubocd32_state>();
601605   static const amiga_machine_interface cubocd32_intf =
602606   {
603607      AGA_CHIP_RAM_MASK,
r9192r9193
615619   amiga_machine_config(machine, &cubocd32_intf);
616620
617621   /* set up memory */
618   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram32, 0);
622   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
619623   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
620624
621625   /* initialize keyboard */
r9192r9193
624628
625629static DRIVER_INIT( cd32 )
626630{
631   cubocd32_state *state = machine->driver_data<cubocd32_state>();
627632   static const amiga_machine_interface cubocd32_intf =
628633   {
629634      AGA_CHIP_RAM_MASK,
r9192r9193
641646   amiga_machine_config(machine, &cubocd32_intf);
642647
643648   /* set up memory */
644   memory_configure_bank(machine, "bank1", 0, 1, amiga_chip_ram32, 0);
649   memory_configure_bank(machine, "bank1", 0, 1, state->chip_ram, 0);
645650   memory_configure_bank(machine, "bank1", 1, 1, memory_region(machine, "user1"), 0);
646
647   /* intialize akiko */
648   amiga_akiko_init(machine);
649651}
650652
651653/***************************************************************************************************/

Previous 15994 Revisions Next


© 1998-2018 The MESS Team