Previous 199869 Revisions Next

r20957 Monday 11th February, 2013 at 20:47:18 UTC by Wilbert Pol
(MESS) amstrad.c: Reduce tagmap lookups (nw)
[src/mess/drivers]amstrad.c
[src/mess/includes]amstrad.h
[src/mess/machine]amstrad.c

trunk/src/mess/machine/amstrad.c
r20956r20957
197197  Prototypes
198198*******************************************************************/
199199
200INLINE void amstrad_update_video( running_machine &machine );
201INLINE void amstrad_plus_update_video( running_machine &machine );
202static void amstrad_rethinkMemory(running_machine &machine);
203
204
205200/* Initialise the palette */
206201PALETTE_INIT_MEMBER(amstrad_state,amstrad_cpc)
207202{
r20956r20957
363358}
364359
365360
366static void amstrad_init_lookups( amstrad_state *state )
361void amstrad_state::amstrad_init_lookups()
367362{
368363   int i;
369364
370365   for ( i = 0; i < 256; i++ )
371366   {
372      state->m_mode0_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x20 ) >> 3 ) | ( ( i & 0x08 ) >> 2 ) | ( ( i & 0x02 ) << 2 );
373      state->m_mode1_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x08 ) >> 2 );
374      state->m_mode2_lookup[i] = ( ( i & 0x80 ) >> 7 );
367      m_mode0_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x20 ) >> 3 ) | ( ( i & 0x08 ) >> 2 ) | ( ( i & 0x02 ) << 2 );
368      m_mode1_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x08 ) >> 2 );
369      m_mode2_lookup[i] = ( ( i & 0x80 ) >> 7 );
375370   }
376371}
377372
378373
379374/* Set the new screen mode (0,1,2,4) from the GateArray */
380static void amstrad_vh_update_mode( amstrad_state *state )
375void amstrad_state::amstrad_vh_update_mode()
381376{
382   if ( state->m_system_type == SYSTEM_PLUS || state->m_system_type == SYSTEM_GX4000 )
377   if ( m_system_type == SYSTEM_PLUS || m_system_type == SYSTEM_GX4000 )
383378   {
384379      /* select a cpc plus mode */
385      switch ( state->m_gate_array.mrer & 0x03 )
380      switch ( m_gate_array.mrer & 0x03 )
386381      {
387382      case 0:     /* Mode 0: 160x200, 16 colours */
388         state->m_gate_array.mode_lookup = state->m_mode0_lookup;
389         state->m_gate_array.max_colour_ticks = 4;
390         state->m_gate_array.ticks_increment = 1;
383         m_gate_array.mode_lookup = m_mode0_lookup;
384         m_gate_array.max_colour_ticks = 4;
385         m_gate_array.ticks_increment = 1;
391386         break;
392387
393388      case 1:     /* Mode 1: 320x200, 4 colous */
394         state->m_gate_array.mode_lookup = state->m_mode1_lookup;
395         state->m_gate_array.max_colour_ticks = 2;
396         state->m_gate_array.ticks_increment = 1;
389         m_gate_array.mode_lookup = m_mode1_lookup;
390         m_gate_array.max_colour_ticks = 2;
391         m_gate_array.ticks_increment = 1;
397392         break;
398393
399394      case 2:     /* Mode 2: 640x200, 2 colours */
400         state->m_gate_array.mode_lookup = state->m_mode2_lookup;
401         state->m_gate_array.max_colour_ticks = 1;
402         state->m_gate_array.ticks_increment = 1;
395         m_gate_array.mode_lookup = m_mode2_lookup;
396         m_gate_array.max_colour_ticks = 1;
397         m_gate_array.ticks_increment = 1;
403398         break;
404399
405400      case 3:     /* Mode 3: 160x200, 4 colours */
406         state->m_gate_array.mode_lookup = state->m_mode0_lookup;
407         state->m_gate_array.max_colour_ticks = 4;
408         state->m_gate_array.ticks_increment = 1;
401         m_gate_array.mode_lookup = m_mode0_lookup;
402         m_gate_array.max_colour_ticks = 4;
403         m_gate_array.ticks_increment = 1;
409404         break;
410405      }
411406   }
412407   else
413408   {
414      if ( state->m_aleste_mode & 0x02 )
409      if ( m_aleste_mode & 0x02 )
415410      {
416411         /* select an aleste mode */
417         switch ( state->m_gate_array.mrer & 0x03 )
412         switch ( m_gate_array.mrer & 0x03 )
418413         {
419414         case 0:     /* Aleste Mode 0 (= Amstrad CPC mode 2): 640x200, 2 colours */
420            state->m_gate_array.mode_lookup = state->m_mode2_lookup;
421            state->m_gate_array.max_colour_ticks = 1;
422            state->m_gate_array.ticks_increment = 1;
415            m_gate_array.mode_lookup = m_mode2_lookup;
416            m_gate_array.max_colour_ticks = 1;
417            m_gate_array.ticks_increment = 1;
423418            break;
424419
425420         case 1:     /* Aleste mode 1 (= Amstrad CPC mode 1): 320x200, 4 colours */
426            state->m_gate_array.mode_lookup = state->m_mode1_lookup;
427            state->m_gate_array.max_colour_ticks = 2;
428            state->m_gate_array.ticks_increment = 1;
421            m_gate_array.mode_lookup = m_mode1_lookup;
422            m_gate_array.max_colour_ticks = 2;
423            m_gate_array.ticks_increment = 1;
429424            break;
430425
431426         case 2:     /* Aleste mode 2: 4 colours */
432            state->m_gate_array.mode_lookup = state->m_mode1_lookup;
433            state->m_gate_array.max_colour_ticks = 1;
434            state->m_gate_array.ticks_increment = 2;
427            m_gate_array.mode_lookup = m_mode1_lookup;
428            m_gate_array.max_colour_ticks = 1;
429            m_gate_array.ticks_increment = 2;
435430            break;
436431
437432         case 3:     /* Aleste mode 3: 16 colours */
438            state->m_gate_array.mode_lookup = state->m_mode0_lookup;
439            state->m_gate_array.max_colour_ticks = 2;
440            state->m_gate_array.ticks_increment = 2;
433            m_gate_array.mode_lookup = m_mode0_lookup;
434            m_gate_array.max_colour_ticks = 2;
435            m_gate_array.ticks_increment = 2;
441436            break;
442437         }
443438      }
444439      else
445440      {
446441         /* select an original cpc mode */
447         switch ( state->m_gate_array.mrer & 0x03 )
442         switch ( m_gate_array.mrer & 0x03 )
448443         {
449444         case 0:     /* Mode 0: 160x200, 16 colours */
450            state->m_gate_array.mode_lookup = state->m_mode0_lookup;
451            state->m_gate_array.max_colour_ticks = 4;
452            state->m_gate_array.ticks_increment = 1;
445            m_gate_array.mode_lookup = m_mode0_lookup;
446            m_gate_array.max_colour_ticks = 4;
447            m_gate_array.ticks_increment = 1;
453448            break;
454449
455450         case 1:     /* Mode 1: 320x200, 4 colous */
456            state->m_gate_array.mode_lookup = state->m_mode1_lookup;
457            state->m_gate_array.max_colour_ticks = 2;
458            state->m_gate_array.ticks_increment = 1;
451            m_gate_array.mode_lookup = m_mode1_lookup;
452            m_gate_array.max_colour_ticks = 2;
453            m_gate_array.ticks_increment = 1;
459454            break;
460455
461456         case 2:     /* Mode 2: 640x200, 2 colours */
462            state->m_gate_array.mode_lookup = state->m_mode2_lookup;
463            state->m_gate_array.max_colour_ticks = 1;
464            state->m_gate_array.ticks_increment = 1;
457            m_gate_array.mode_lookup = m_mode2_lookup;
458            m_gate_array.max_colour_ticks = 1;
459            m_gate_array.ticks_increment = 1;
465460            break;
466461
467462         case 3:     /* Mode 3: 160x200, 4 colours */
468            state->m_gate_array.mode_lookup = state->m_mode0_lookup;
469            state->m_gate_array.max_colour_ticks = 4;
470            state->m_gate_array.ticks_increment = 1;
463            m_gate_array.mode_lookup = m_mode0_lookup;
464            m_gate_array.max_colour_ticks = 4;
465            m_gate_array.ticks_increment = 1;
471466            break;
472467         }
473468      }
r20956r20957
4884834020h   STOP    Stop processing the sound list.
489484*/
490485
491static void amstrad_plus_dma_parse(running_machine &machine, int channel)
486void amstrad_state::amstrad_plus_dma_parse(int channel)
492487{
493   amstrad_state *state = machine.driver_data<amstrad_state>();
494488   unsigned short command;
495489
496   if( state->m_asic.dma_addr[channel] & 0x01)
497      state->m_asic.dma_addr[channel]++;  // align to even address
490   if( m_asic.dma_addr[channel] & 0x01)
491      m_asic.dma_addr[channel]++;  // align to even address
498492
499   if ( state->m_asic.dma_pause[channel] != 0 )
493   if ( m_asic.dma_pause[channel] != 0 )
500494   {  // do nothing, this channel is paused
501      state->m_asic.dma_prescaler[channel]--;
502      if ( state->m_asic.dma_prescaler[channel] == 0 )
495      m_asic.dma_prescaler[channel]--;
496      if ( m_asic.dma_prescaler[channel] == 0 )
503497      {
504         state->m_asic.dma_pause[channel]--;
505         state->m_asic.dma_prescaler[channel] = state->m_asic.ram[0x2c02 + (4*channel)] + 1;
498         m_asic.dma_pause[channel]--;
499         m_asic.dma_prescaler[channel] = m_asic.ram[0x2c02 + (4*channel)] + 1;
506500      }
507501      return;
508502   }
509   command = (state->m_ram->pointer()[state->m_asic.dma_addr[channel]+1] << 8) + state->m_ram->pointer()[state->m_asic.dma_addr[channel]];
510//  logerror("DMA #%i: address %04x: command %04x\n",channel,state->m_asic.dma_addr[channel],command);
503   command = (m_ram->pointer()[m_asic.dma_addr[channel]+1] << 8) + m_ram->pointer()[m_asic.dma_addr[channel]];
504//  logerror("DMA #%i: address %04x: command %04x\n",channel,m_asic.dma_addr[channel],command);
511505   switch (command & 0xf000)
512506   {
513507   case 0x0000:  // Load PSG register
514508      {
515         device_t *ay8910 = state->m_ay;
516         ay8910_address_w(ay8910, state->generic_space(), 0, (command & 0x0f00) >> 8);
517         ay8910_data_w(ay8910, state->generic_space(), 0, command & 0x00ff);
518         ay8910_address_w(ay8910, state->generic_space(), 0, state->m_prev_reg);
509         ay8910_address_w(m_ay, generic_space(), 0, (command & 0x0f00) >> 8);
510         ay8910_data_w(m_ay, generic_space(), 0, command & 0x00ff);
511         ay8910_address_w(m_ay, generic_space(), 0, m_prev_reg);
519512      }
520513      logerror("DMA %i: LOAD %i, %i\n",channel,(command & 0x0f00) >> 8, command & 0x00ff);
521514      break;
522515   case 0x1000:  // Pause for n HSYNCs (0 - 4095)
523      state->m_asic.dma_pause[channel] = (command & 0x0fff) - 1;
516      m_asic.dma_pause[channel] = (command & 0x0fff) - 1;
524517      logerror("DMA %i: PAUSE %i\n",channel,command & 0x0fff);
525518      break;
526519   case 0x2000:  // Beginning of repeat loop
527      state->m_asic.dma_repeat[channel] = state->m_asic.dma_addr[channel];
528      state->m_asic.dma_loopcount[channel] = (command & 0x0fff);
520      m_asic.dma_repeat[channel] = m_asic.dma_addr[channel];
521      m_asic.dma_loopcount[channel] = (command & 0x0fff);
529522      logerror("DMA %i: REPEAT %i\n",channel,command & 0x0fff);
530523      break;
531524   case 0x4000:  // Control functions
532525      if (command & 0x01) // Loop back to last Repeat instruction
533526      {
534         if (state->m_asic.dma_loopcount[channel] > 0)
527         if (m_asic.dma_loopcount[channel] > 0)
535528         {
536            state->m_asic.dma_addr[channel] = state->m_asic.dma_repeat[channel];
537            logerror("DMA %i: LOOP (%i left)\n",channel,state->m_asic.dma_loopcount[channel]);
538            state->m_asic.dma_loopcount[channel]--;
529            m_asic.dma_addr[channel] = m_asic.dma_repeat[channel];
530            logerror("DMA %i: LOOP (%i left)\n",channel,m_asic.dma_loopcount[channel]);
531            m_asic.dma_loopcount[channel]--;
539532         }
540533         else
541534            logerror("DMA %i: LOOP (end)\n",channel);
542535      }
543536      if (command & 0x10) // Cause interrupt
544537      {
545         state->m_plus_irq_cause = channel * 2;
546         state->m_asic.ram[0x2c0f] |= (0x40 >> channel);
547         machine.device("maincpu")->execute().set_input_line(0, ASSERT_LINE);
538         m_plus_irq_cause = channel * 2;
539         m_asic.ram[0x2c0f] |= (0x40 >> channel);
540         m_maincpu->set_input_line(0, ASSERT_LINE);
548541         logerror("DMA %i: INT\n",channel);
549542      }
550543      if (command & 0x20)  // Stop processing on this channel
551544      {
552         state->m_asic.dma_status &= ~(0x01 << channel);
545         m_asic.dma_status &= ~(0x01 << channel);
553546         logerror("DMA %i: STOP\n",channel);
554547      }
555548      break;
556549   default:
557      logerror("DMA: Unknown DMA command - %04x - at address &%04x\n",command,state->m_asic.dma_addr[channel]);
550      logerror("DMA: Unknown DMA command - %04x - at address &%04x\n",command,m_asic.dma_addr[channel]);
558551   }
559   state->m_asic.dma_addr[channel] += 2;  // point to next DMA instruction
552   m_asic.dma_addr[channel] += 2;  // point to next DMA instruction
560553}
561554
562555
563static void amstrad_plus_handle_dma(running_machine &machine)
556void amstrad_state::amstrad_plus_handle_dma()
564557{
565   amstrad_state *state = machine.driver_data<amstrad_state>();
566   if ( state->m_asic.dma_status & 0x01 )  // DMA channel 0
567      amstrad_plus_dma_parse( machine, 0 );
558   if ( m_asic.dma_status & 0x01 )  // DMA channel 0
559   {
560      amstrad_plus_dma_parse( 0 );
561   }
568562
569   if ( state->m_asic.dma_status & 0x02 )  // DMA channel 1
570      amstrad_plus_dma_parse( machine, 1 );
563   if ( m_asic.dma_status & 0x02 )  // DMA channel 1
564   {
565      amstrad_plus_dma_parse( 1 );
566   }
571567
572   if ( state->m_asic.dma_status & 0x04 )  // DMA channel 2
573      amstrad_plus_dma_parse( machine, 2 );
568   if ( m_asic.dma_status & 0x04 )  // DMA channel 2
569   {
570      amstrad_plus_dma_parse( 2 );
571   }
574572}
575573
576574TIMER_CALLBACK_MEMBER(amstrad_state::amstrad_video_update_timer)
577575{
578576   if(param == 1)
579      amstrad_plus_update_video(machine());
577   {
578      amstrad_plus_update_video();
579   }
580580   else
581      amstrad_update_video(machine());
581   {
582      amstrad_update_video();
583   }
582584}
583585
584586/* Set the new colour from the GateArray */
585static void amstrad_vh_update_colour(running_machine &machine, int PenIndex, UINT16 hw_colour_index)
587void amstrad_state::amstrad_vh_update_colour(int PenIndex, UINT16 hw_colour_index)
586588{
587   amstrad_state *state = machine.driver_data<amstrad_state>();
588   if ( state->m_system_type == SYSTEM_PLUS || state->m_system_type == SYSTEM_GX4000 )
589   if ( m_system_type == SYSTEM_PLUS || m_system_type == SYSTEM_GX4000 )
589590   {
590591      int val;
591592
592      machine.scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),state),1);
593      machine().scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),this),1);
593594
594595      /* CPC+/GX4000 - normal palette changes through the Gate Array also makes the corresponding change in the ASIC palette */
595596      val = (amstrad_palette[hw_colour_index] & 0xf00000) >> 16; /* red */
596597      val |= (amstrad_palette[hw_colour_index] & 0x0000f0) >> 4; /* blue */
597      state->m_asic.ram[0x2400+PenIndex*2] = val;
598      m_asic.ram[0x2400+PenIndex*2] = val;
598599      val = (amstrad_palette[hw_colour_index] & 0x00f000) >> 12; /* green */
599      state->m_asic.ram[0x2401+PenIndex*2] = val;
600      m_asic.ram[0x2401+PenIndex*2] = val;
600601   }
601602   else
602603   {
603      machine.scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),state),0);
604      machine().scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),this),0);
604605   }
605   state->m_GateArray_render_colours[PenIndex] = hw_colour_index;
606   m_GateArray_render_colours[PenIndex] = hw_colour_index;
606607}
607608
608609
609static void aleste_vh_update_colour(running_machine &machine, int PenIndex, UINT16 hw_colour_index)
610void amstrad_state::aleste_vh_update_colour(int PenIndex, UINT16 hw_colour_index)
610611{
611   amstrad_state *state = machine.driver_data<amstrad_state>();
612   machine.scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),state),0);
613   state->m_GateArray_render_colours[PenIndex] = hw_colour_index+32;
612   machine().scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),this),0);
613   m_GateArray_render_colours[PenIndex] = hw_colour_index+32;
614614}
615615
616616
617INLINE void amstrad_gate_array_get_video_data( running_machine &machine )
617void amstrad_state::amstrad_gate_array_get_video_data()
618618{
619   amstrad_state *state = machine.driver_data<amstrad_state>();
620   if ( state->m_aleste_mode & 0x02 )
621      state->m_gate_array.address = ( ( state->m_gate_array.ma & 0x2000 ) << 2 ) | ( ( state->m_gate_array.ra & 0x06 ) << 11 ) | ( ( state->m_gate_array.ra & 0x01 ) << 14 ) | ( ( state->m_gate_array.ma & 0x7ff ) << 1 );
619   if ( m_aleste_mode & 0x02 )
620   {
621      m_gate_array.address = ( ( m_gate_array.ma & 0x2000 ) << 2 ) | ( ( m_gate_array.ra & 0x06 ) << 11 ) | ( ( m_gate_array.ra & 0x01 ) << 14 ) | ( ( m_gate_array.ma & 0x7ff ) << 1 );
622   }
622623   else
623      state->m_gate_array.address = ( ( state->m_gate_array.ma & 0x3000 ) << 2 ) | ( ( state->m_gate_array.ra & 0x07 ) << 11 ) | ( ( state->m_gate_array.ma & 0x3ff ) << 1 );
624   state->m_gate_array.data = state->m_ram->pointer()[ state->m_gate_array.address ];
625   state->m_gate_array.colour = state->m_GateArray_render_colours[ state->m_gate_array.mode_lookup[state->m_gate_array.data] ];
626   state->m_gate_array.colour_ticks = state->m_gate_array.max_colour_ticks;
627   state->m_gate_array.ticks = 0;
624   {
625      m_gate_array.address = ( ( m_gate_array.ma & 0x3000 ) << 2 ) | ( ( m_gate_array.ra & 0x07 ) << 11 ) | ( ( m_gate_array.ma & 0x3ff ) << 1 );
626   }
627   m_gate_array.data = m_ram->pointer()[ m_gate_array.address ];
628   m_gate_array.colour = m_GateArray_render_colours[ m_gate_array.mode_lookup[m_gate_array.data] ];
629   m_gate_array.colour_ticks = m_gate_array.max_colour_ticks;
630   m_gate_array.ticks = 0;
628631}
629632
630633
631INLINE void amstrad_update_video( running_machine &machine )
634void amstrad_state::amstrad_update_video()
632635{
633   amstrad_state *state = machine.driver_data<amstrad_state>();
634   attotime now = machine.time();
636   attotime now = machine().time();
635637
636638
637   if ( state->m_gate_array.draw_p )
639   if ( m_gate_array.draw_p )
638640   {
639      UINT32 cycles_passed = (now - state->m_gate_array.last_draw_time ).as_ticks(XTAL_16MHz);
641      UINT32 cycles_passed = (now - m_gate_array.last_draw_time ).as_ticks(XTAL_16MHz);
640642
641643      while( cycles_passed )
642644      {
643         if ( ! state->m_gate_array.de || ( ( state->m_aleste_mode & 0x02 ) && ! ( state->m_aleste_mode & 0x08 ) ) )
645         if ( ! m_gate_array.de || ( ( m_aleste_mode & 0x02 ) && ! ( m_aleste_mode & 0x08 ) ) )
644646         {
645            *state->m_gate_array.draw_p = state->m_GateArray_render_colours[ 16 ];
647            *m_gate_array.draw_p = m_GateArray_render_colours[ 16 ];
646648         }
647649         else
648650         {
649            *state->m_gate_array.draw_p = state->m_gate_array.colour;
650            state->m_gate_array.colour_ticks--;
651            if ( ! state->m_gate_array.colour_ticks )
651            *m_gate_array.draw_p = m_gate_array.colour;
652            m_gate_array.colour_ticks--;
653            if ( ! m_gate_array.colour_ticks )
652654            {
653               state->m_gate_array.data <<= 1;
654               state->m_gate_array.colour = state->m_GateArray_render_colours[ state->m_gate_array.mode_lookup[state->m_gate_array.data] ];
655               state->m_gate_array.colour_ticks = state->m_gate_array.max_colour_ticks;
655               m_gate_array.data <<= 1;
656               m_gate_array.colour = m_GateArray_render_colours[ m_gate_array.mode_lookup[m_gate_array.data] ];
657               m_gate_array.colour_ticks = m_gate_array.max_colour_ticks;
656658            }
657            state->m_gate_array.ticks += state->m_gate_array.ticks_increment;
658            switch( state->m_gate_array.ticks)
659            m_gate_array.ticks += m_gate_array.ticks_increment;
660            switch( m_gate_array.ticks)
659661            {
660662            case 8:
661               state->m_gate_array.data = state->m_ram->pointer()[ state->m_gate_array.address + 1 ];
662               state->m_gate_array.colour = state->m_GateArray_render_colours[ state->m_gate_array.mode_lookup[state->m_gate_array.data] ];
663               m_gate_array.data = m_ram->pointer()[ m_gate_array.address + 1 ];
664               m_gate_array.colour = m_GateArray_render_colours[ m_gate_array.mode_lookup[m_gate_array.data] ];
663665               break;
664666            case 16:
665               state->m_gate_array.ma += 1;                        /* If we were synced with the 6845 mc6845_get_ma should return this value */
666               amstrad_gate_array_get_video_data( machine );
667               m_gate_array.ma += 1;                        /* If we were synced with the 6845 mc6845_get_ma should return this value */
668               amstrad_gate_array_get_video_data();
667669               break;
668670            }
669671         }
670         state->m_gate_array.draw_p++;
672         m_gate_array.draw_p++;
671673         cycles_passed--;
672         state->m_gate_array.line_ticks++;
673         if ( state->m_gate_array.line_ticks > state->m_gate_array.bitmap->width() )
674         m_gate_array.line_ticks++;
675         if ( m_gate_array.line_ticks > m_gate_array.bitmap->width() )
674676         {
675            state->m_gate_array.draw_p = NULL;
677            m_gate_array.draw_p = NULL;
676678            cycles_passed = 0;
677679         }
678680      }
679681   }
680682
681   state->m_gate_array.last_draw_time = now;
683   m_gate_array.last_draw_time = now;
682684}
683685
684686
685INLINE void amstrad_plus_gate_array_get_video_data( running_machine &machine )
687void amstrad_state::amstrad_plus_gate_array_get_video_data()
686688{
687   amstrad_state *state = machine.driver_data<amstrad_state>();
688689   UINT16 caddr;
689   UINT16 ma = ( state->m_gate_array.ma - state->m_asic.split_ma_started ) + state->m_asic.split_ma_base;
690   UINT16 ra = state->m_gate_array.ra + ( ( state->m_asic.ram[0x2804] >> 4 ) & 0x07 );
690   UINT16 ma = ( m_gate_array.ma - m_asic.split_ma_started ) + m_asic.split_ma_base;
691   UINT16 ra = m_gate_array.ra + ( ( m_asic.ram[0x2804] >> 4 ) & 0x07 );
691692
692693   if ( ra > 7 )
693694   {
694      ma += state->m_asic.horiz_disp;
695      ma += m_asic.horiz_disp;
695696   }
696   state->m_gate_array.address = ( ( ma & 0x3000 ) << 2 ) | ( ( state->m_gate_array.ra & 0x07 ) << 11 ) | ( ( ma & 0x3ff ) << 1 );
697   state->m_gate_array.data = state->m_ram->pointer()[ state->m_gate_array.address ];
698   caddr = 0x2400 + state->m_gate_array.mode_lookup[state->m_gate_array.data] * 2;
699   state->m_gate_array.colour = state->m_asic.ram[caddr] + ( state->m_asic.ram[caddr+1] << 8 );
700   state->m_gate_array.colour_ticks = state->m_gate_array.max_colour_ticks;
701   state->m_gate_array.ticks = 0;
697   m_gate_array.address = ( ( ma & 0x3000 ) << 2 ) | ( ( m_gate_array.ra & 0x07 ) << 11 ) | ( ( ma & 0x3ff ) << 1 );
698   m_gate_array.data = m_ram->pointer()[ m_gate_array.address ];
699   caddr = 0x2400 + m_gate_array.mode_lookup[m_gate_array.data] * 2;
700   m_gate_array.colour = m_asic.ram[caddr] + ( m_asic.ram[caddr+1] << 8 );
701   m_gate_array.colour_ticks = m_gate_array.max_colour_ticks;
702   m_gate_array.ticks = 0;
702703}
703704
704705
705INLINE void amstrad_plus_update_video( running_machine &machine )
706void amstrad_state::amstrad_plus_update_video()
706707{
707   amstrad_state *state = machine.driver_data<amstrad_state>();
708   attotime now = machine.time();
708   attotime now = machine().time();
709709
710   if ( state->m_gate_array.draw_p )
710   if ( m_gate_array.draw_p )
711711   {
712      UINT32 cycles_passed = (now - state->m_gate_array.last_draw_time ).as_ticks(XTAL_16MHz);
712      UINT32 cycles_passed = (now - m_gate_array.last_draw_time ).as_ticks(XTAL_16MHz);
713713
714714      while( cycles_passed )
715715      {
716         if ( ! state->m_gate_array.de )
716         if ( ! m_gate_array.de )
717717         {
718            *state->m_gate_array.draw_p = state->m_asic.ram[0x2420] + ( state->m_asic.ram[0x2421] << 8 );
718            *m_gate_array.draw_p = m_asic.ram[0x2420] + ( m_asic.ram[0x2421] << 8 );
719719         }
720720         else
721721         {
722            *state->m_gate_array.draw_p = state->m_gate_array.colour;
722            *m_gate_array.draw_p = m_gate_array.colour;
723723
724            if ( state->m_asic.hscroll )
724            if ( m_asic.hscroll )
725725            {
726               state->m_asic.hscroll--;
727               if ( state->m_asic.hscroll == 0 )
728                  amstrad_plus_gate_array_get_video_data( machine );
726               m_asic.hscroll--;
727               if ( m_asic.hscroll == 0 )
728                  amstrad_plus_gate_array_get_video_data();
729729            }
730730            else
731731            {
732               state->m_gate_array.colour_ticks--;
733               if ( ! state->m_gate_array.colour_ticks )
732               m_gate_array.colour_ticks--;
733               if ( ! m_gate_array.colour_ticks )
734734               {
735735                  UINT16 caddr;
736736
737                  state->m_gate_array.data <<= 1;
738                  caddr = 0x2400 + state->m_gate_array.mode_lookup[state->m_gate_array.data] * 2;
739                  state->m_gate_array.colour = state->m_asic.ram[caddr] + ( state->m_asic.ram[caddr+1] << 8 );
740                  state->m_gate_array.colour_ticks = state->m_gate_array.max_colour_ticks;
737                  m_gate_array.data <<= 1;
738                  caddr = 0x2400 + m_gate_array.mode_lookup[m_gate_array.data] * 2;
739                  m_gate_array.colour = m_asic.ram[caddr] + ( m_asic.ram[caddr+1] << 8 );
740                  m_gate_array.colour_ticks = m_gate_array.max_colour_ticks;
741741               }
742               state->m_gate_array.ticks += state->m_gate_array.ticks_increment;
743               switch( state->m_gate_array.ticks)
742               m_gate_array.ticks += m_gate_array.ticks_increment;
743               switch( m_gate_array.ticks)
744744               {
745745               case 8:
746746                  {
747747                     UINT16 caddr;
748748
749                     state->m_gate_array.data = state->m_ram->pointer()[ state->m_gate_array.address + 1 ];
750                     caddr = 0x2400 + state->m_gate_array.mode_lookup[state->m_gate_array.data] * 2;
751                     state->m_gate_array.colour = state->m_asic.ram[caddr] + ( state->m_asic.ram[caddr+1] << 8 );
749                     m_gate_array.data = m_ram->pointer()[ m_gate_array.address + 1 ];
750                     caddr = 0x2400 + m_gate_array.mode_lookup[m_gate_array.data] * 2;
751                     m_gate_array.colour = m_asic.ram[caddr] + ( m_asic.ram[caddr+1] << 8 );
752752                  }
753753                  break;
754754               case 16:
755                  state->m_gate_array.ma += 1;                        /* If we were synced with the 6845 mc6845_get_ma should return this value */
756                  amstrad_plus_gate_array_get_video_data( machine );
755                  m_gate_array.ma += 1;                        /* If we were synced with the 6845 mc6845_get_ma should return this value */
756                  amstrad_plus_gate_array_get_video_data();
757757                  break;
758758               }
759759            }
760760         }
761         state->m_gate_array.draw_p++;
761         m_gate_array.draw_p++;
762762         cycles_passed--;
763         state->m_gate_array.line_ticks++;
764         if ( state->m_gate_array.line_ticks > state->m_gate_array.bitmap->width() )
763         m_gate_array.line_ticks++;
764         if ( m_gate_array.line_ticks > m_gate_array.bitmap->width() )
765765         {
766            state->m_gate_array.draw_p = NULL;
766            m_gate_array.draw_p = NULL;
767767            cycles_passed = 0;
768768         }
769769      }
770770   }
771771
772   state->m_gate_array.last_draw_time = now;
772   m_gate_array.last_draw_time = now;
773773}
774774
775775
776INLINE void amstrad_plus_update_video_sprites( running_machine &machine )
776void amstrad_state::amstrad_plus_update_video_sprites()
777777{
778   amstrad_state *state = machine.driver_data<amstrad_state>();
779   UINT16  *p = &state->m_gate_array.bitmap->pix16(state->m_gate_array.y, state->m_asic.h_start );
778   UINT16  *p = &m_gate_array.bitmap->pix16(m_gate_array.y, m_asic.h_start );
780779   int i;
781780
782   if ( state->m_gate_array.y < 0 )
781   if ( m_gate_array.y < 0 )
783782      return;
784783
785784   for ( i = 15 * 8; i >= 0; i -= 8 )
786785   {
787      UINT8   xmag = ( state->m_asic.ram[ 0x2000 + i + 4 ] >> 2 ) & 0x03;
788      UINT8   ymag = state->m_asic.ram[ 0x2000 + i + 4 ] & 0x03;
786      UINT8   xmag = ( m_asic.ram[ 0x2000 + i + 4 ] >> 2 ) & 0x03;
787      UINT8   ymag = m_asic.ram[ 0x2000 + i + 4 ] & 0x03;
789788
790789      /* Check if sprite is enabled */
791790      if ( xmag && ymag )
792791      {
793         INT16   spr_x = state->m_asic.ram[ 0x2000 + i ] + ( state->m_asic.ram[ 0x2001 + i ] << 8 );
794         INT16   spr_y = state->m_asic.ram[ 0x2002 + i ] + ( state->m_asic.ram[ 0x2003 + i ] << 8 );
792         INT16   spr_x = m_asic.ram[ 0x2000 + i ] + ( m_asic.ram[ 0x2001 + i ] << 8 );
793         INT16   spr_y = m_asic.ram[ 0x2002 + i ] + ( m_asic.ram[ 0x2003 + i ] << 8 );
795794
796795         xmag -= 1;
797796         ymag -= 1;
798797
799798         /* Check if sprite would appear on this scanline */
800         if ( spr_y <= state->m_asic.vpos && state->m_asic.vpos < spr_y + ( 16 << ymag ) && spr_x < ( state->m_asic.h_end - state->m_asic.h_start ) && spr_x + ( 16 << xmag ) > 0 )
799         if ( spr_y <= m_asic.vpos && m_asic.vpos < spr_y + ( 16 << ymag ) && spr_x < ( m_asic.h_end - m_asic.h_start ) && spr_x + ( 16 << xmag ) > 0 )
801800         {
802            UINT16  spr_addr = i * 32 + ( ( ( state->m_asic.vpos - spr_y ) >> ymag ) * 16 );
801            UINT16  spr_addr = i * 32 + ( ( ( m_asic.vpos - spr_y ) >> ymag ) * 16 );
803802            int     j, k;
804803
805804            for ( j = 0; j < 16; j++ )
r20956r20957
808807               {
809808                  INT16 x = spr_x + ( j << xmag ) + k;
810809
811                  if ( x >= 0 && x < ( state->m_asic.h_end - state->m_asic.h_start ) )
810                  if ( x >= 0 && x < ( m_asic.h_end - m_asic.h_start ) )
812811                  {
813                     UINT8   spr_col = ( state->m_asic.ram[ spr_addr + j ] & 0x0f ) * 2;
812                     UINT8   spr_col = ( m_asic.ram[ spr_addr + j ] & 0x0f ) * 2;
814813
815814                     if ( spr_col )
816                        p[x] = state->m_asic.ram[ 0x2420 + spr_col ] + ( state->m_asic.ram[ 0x2421 + spr_col ] << 8 );
815                        p[x] = m_asic.ram[ 0x2420 + spr_col ] + ( m_asic.ram[ 0x2421 + spr_col ] << 8 );
817816                  }
818817               }
819818            }
r20956r20957
825824
826825WRITE_LINE_MEMBER(amstrad_state::amstrad_hsync_changed)
827826{
828   amstrad_update_video(machine());
827   amstrad_update_video();
829828
830829   /* The gate array reacts to de-assertion of the hsycnc 6845 line */
831830   if ( m_gate_array.hsync && !state )
r20956r20957
851850         {
852851            if (m_gate_array.hsync_counter >= 32)
853852            {
854               machine().device("maincpu")->execute().set_input_line(0, ASSERT_LINE);
853               m_maincpu->set_input_line(0, ASSERT_LINE);
855854            }
856855            m_gate_array.hsync_counter = 0;
857856         }
r20956r20957
860859      if ( m_gate_array.hsync_counter >= 52 )
861860      {
862861         m_gate_array.hsync_counter = 0;
863         machine().device("maincpu")->execute().set_input_line(0, ASSERT_LINE);
862         m_maincpu->set_input_line(0, ASSERT_LINE);
864863      }
865864   }
866865   m_gate_array.hsync = state ? 1 : 0;
r20956r20957
869868
870869WRITE_LINE_MEMBER(amstrad_state::amstrad_plus_hsync_changed)
871870{
872   amstrad_plus_update_video(machine());
871   amstrad_plus_update_video();
873872
874873   if ( m_gate_array.hsync && !state )
875874   {
r20956r20957
896895            {
897896               if( m_asic.pri == 0 || m_asic.enabled == 0)
898897               {
899                  machine().device("maincpu")->execute().set_input_line(0, ASSERT_LINE);
898                  m_maincpu->set_input_line(0, ASSERT_LINE);
900899               }
901900            }
902901            m_gate_array.hsync_counter = 0;
r20956r20957
908907         m_gate_array.hsync_counter = 0;
909908         if ( m_asic.pri == 0 || m_asic.enabled == 0 )
910909         {
911            machine().device("maincpu")->execute().set_input_line(0, ASSERT_LINE);
910            m_maincpu->set_input_line(0, ASSERT_LINE);
912911         }
913912      }
914913
r20956r20957
920919            if ( m_asic.pri == m_asic.vpos - 1 )
921920            {
922921               logerror("PRI: triggered, scanline %d\n",m_asic.pri);
923               machine().device("maincpu")->execute().set_input_line(0, ASSERT_LINE);
922               m_maincpu->set_input_line(0, ASSERT_LINE);
924923               m_plus_irq_cause = 0x06;  // raster interrupt vector
925924               m_gate_array.hsync_counter &= ~0x20;  // ASIC PRI resets the MSB of the raster counter
926925            }
r20956r20957
934933            }
935934         }
936935         // CPC+/GX4000 DMA channels
937         amstrad_plus_handle_dma(machine());  // a DMA command is handled at the leading edge of HSYNC (every 64us)
936         amstrad_plus_handle_dma();  // a DMA command is handled at the leading edge of HSYNC (every 64us)
938937         if(m_asic.de_start != 0)
939938            m_asic.vpos++;
940939      }
r20956r20957
945944
946945WRITE_LINE_MEMBER(amstrad_state::amstrad_vsync_changed)
947946{
948   amstrad_update_video(machine());
947   amstrad_update_video();
949948
950949   if ( ! m_gate_array.vsync && state )
951950   {
r20956r20957
967966
968967WRITE_LINE_MEMBER(amstrad_state::amstrad_plus_vsync_changed)
969968{
970   amstrad_plus_update_video(machine());
969   amstrad_plus_update_video();
971970
972971   if ( ! m_gate_array.vsync && state )
973972   {
r20956r20957
989988
990989WRITE_LINE_MEMBER(amstrad_state::amstrad_de_changed)
991990{
992   amstrad_update_video(machine());
991   amstrad_update_video();
993992
994993   if ( ! m_gate_array.de && state )
995994   {
r20956r20957
999998      m_gate_array.ma = mc6845->get_ma();
1000999      m_gate_array.ra = mc6845->get_ra();
10011000logerror("y = %d; ma = %02x; ra = %02x, address = %04x\n", m_gate_array.y, m_gate_array.ma, m_gate_array.ra, ( ( m_gate_array.ma & 0x3000 ) << 2 ) | ( ( m_gate_array.ra & 0x07 ) << 11 ) | ( ( m_gate_array.ma & 0x3ff ) << 1 ) );
1002      amstrad_gate_array_get_video_data(machine());
1001      amstrad_gate_array_get_video_data();
10031002      m_asic.de_start = 1;
10041003   }
10051004
r20956r20957
10091008
10101009WRITE_LINE_MEMBER(amstrad_state::amstrad_plus_de_changed)
10111010{
1012   amstrad_plus_update_video(machine());
1011   amstrad_plus_update_video();
10131012
10141013   if ( ! m_gate_array.de && state )
10151014   {
10161015      /* DE became active, store the starting MA and RA signals */
1017      mc6845_device *mc6845 = m_crtc;
1018
1019      m_gate_array.ma = mc6845->get_ma();
1020      m_gate_array.ra = mc6845->get_ra();
1016      m_gate_array.ma = m_crtc->get_ma();
1017      m_gate_array.ra = m_crtc->get_ra();
10211018      m_asic.h_start = m_gate_array.line_ticks;
10221019      m_asic.de_start = 1;
10231020
r20956r20957
10381035      m_asic.hscroll = m_asic.ram[0x2804] & 0x0f;
10391036
10401037      if ( m_asic.hscroll == 0 )
1041         amstrad_plus_gate_array_get_video_data(machine());
1038         amstrad_plus_gate_array_get_video_data();
10421039   }
10431040
10441041   if ( m_gate_array.de && ! state )
10451042   {
10461043      m_asic.h_end = m_gate_array.line_ticks;
1047      amstrad_plus_update_video_sprites(machine());
1044      amstrad_plus_update_video_sprites();
10481045   }
10491046
10501047   m_gate_array.de = state ? 1 : 0;
r20956r20957
10531050
10541051VIDEO_START_MEMBER(amstrad_state,amstrad)
10551052{
1056   //screen_device *screen = downcast<screen_device *>(machine().device("screen"));
1053   amstrad_init_lookups();
10571054
1058   amstrad_init_lookups(this);
1059
10601055   m_gate_array.bitmap = auto_bitmap_ind16_alloc( machine(), m_screen->width(), m_screen->height() );
10611056   m_gate_array.hsync_after_vsync_counter = 3;
10621057}
r20956r20957
11411136   amstrad_state *tstate = device->machine().driver_data<amstrad_state>();
11421137
11431138   tstate->m_gate_array.romdis = state;
1144   amstrad_rethinkMemory(device->machine());
1139   tstate->amstrad_rethinkMemory();
11451140}
11461141
11471142WRITE_LINE_DEVICE_HANDLER(cpc_romen)
r20956r20957
11521147      tstate->m_gate_array.mrer &= ~0x04;
11531148   else
11541149      tstate->m_gate_array.mrer |= 0x04;
1155   amstrad_rethinkMemory(device->machine());
1150   tstate->amstrad_rethinkMemory();
11561151}
11571152
11581153
r20956r20957
11621157/*-----------------
11631158  - Set Lower Rom -
11641159  -----------------*/
1165static void amstrad_setLowerRom(running_machine &machine)
1160void amstrad_state::amstrad_setLowerRom()
11661161{
1167   amstrad_state *state = machine.driver_data<amstrad_state>();
11681162   UINT8 *bank_base;
11691163
11701164   /* b2 : "1" Lower rom area disable or "0" Lower rom area enable */
1171   if ( state->m_system_type == SYSTEM_CPC || state->m_system_type == SYSTEM_ALESTE )
1165   if ( m_system_type == SYSTEM_CPC || m_system_type == SYSTEM_ALESTE )
11721166   {
1173      if ((state->m_gate_array.mrer & (1<<2)) == 0 && state->m_gate_array.romdis == 0)
1167      if ((m_gate_array.mrer & (1<<2)) == 0 && m_gate_array.romdis == 0)
11741168      {
1175         bank_base = &state->memregion("maincpu")->base()[0x010000];
1169         bank_base = &m_region_maincpu->base()[0x010000];
11761170      }
11771171      else
11781172      {
1179         if(state->m_aleste_mode & 0x04)
1180            bank_base = state->m_Aleste_RamBanks[0];
1173         if(m_aleste_mode & 0x04)
1174            bank_base = m_Aleste_RamBanks[0];
11811175         else
1182            bank_base = state->m_AmstradCPC_RamBanks[0];
1176            bank_base = m_AmstradCPC_RamBanks[0];
11831177      }
1184      state->membank("bank1")->set_base(bank_base);
1185      state->membank("bank2")->set_base(bank_base+0x02000);
1178      m_bank1->set_base(bank_base);
1179      m_bank2->set_base(bank_base+0x02000);
11861180   }
11871181   else  // CPC+/GX4000
11881182   {
11891183      //address_space &space = state->m_maincpu->space(AS_PROGRAM);
11901184
1191/*      if ( state->m_asic.enabled && ( state->m_asic.rmr2 & 0x18 ) == 0x18 )
1185/*      if ( m_asic.enabled && ( m_asic.rmr2 & 0x18 ) == 0x18 )
11921186        {
1193            space.install_read_handler(0x4000, 0x5fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_4000_r),state));
1194            space.install_read_handler(0x6000, 0x7fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_6000_r),state));
1195            space.install_write_handler(0x4000, 0x5fff, write8_delegate(FUNC(amstrad_state::amstrad_plus_asic_4000_w),state));
1196            space.install_write_handler(0x6000, 0x7fff, write8_delegate(FUNC(amstrad_state::amstrad_plus_asic_6000_w),state));
1187            space.install_read_handler(0x4000, 0x5fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_4000_r),this));
1188            space.install_read_handler(0x6000, 0x7fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_6000_r),this));
1189            space.install_write_handler(0x4000, 0x5fff, write8_delegate(FUNC(amstrad_state::amstrad_plus_asic_4000_w),this));
1190            space.install_write_handler(0x6000, 0x7fff, write8_delegate(FUNC(amstrad_state::amstrad_plus_asic_6000_w),this));
11971191        }
11981192        else
11991193        {
r20956r20957
12031197            space.install_write_bank(0x6000, 0x7fff, "bank12");
12041198        }
12051199*/
1206      if(state->m_AmstradCPC_RamBanks[0] != NULL)
1200      if(m_AmstradCPC_RamBanks[0] != NULL)
12071201      {
1208         state->membank("bank1")->set_base(state->m_AmstradCPC_RamBanks[0]);
1209         state->membank("bank2")->set_base(state->m_AmstradCPC_RamBanks[0]+0x2000);
1210         state->membank("bank3")->set_base(state->m_AmstradCPC_RamBanks[1]);
1211         state->membank("bank4")->set_base(state->m_AmstradCPC_RamBanks[1]+0x2000);
1212         state->membank("bank5")->set_base(state->m_AmstradCPC_RamBanks[2]);
1213         state->membank("bank6")->set_base(state->m_AmstradCPC_RamBanks[2]+0x2000);
1202         m_bank1->set_base(m_AmstradCPC_RamBanks[0]);
1203         m_bank2->set_base(m_AmstradCPC_RamBanks[0]+0x2000);
1204         m_bank3->set_base(m_AmstradCPC_RamBanks[1]);
1205         m_bank4->set_base(m_AmstradCPC_RamBanks[1]+0x2000);
1206         m_bank5->set_base(m_AmstradCPC_RamBanks[2]);
1207         m_bank6->set_base(m_AmstradCPC_RamBanks[2]+0x2000);
12141208      }
12151209
1216      if ( (state->m_gate_array.mrer & (1<<2)) == 0 && state->m_gate_array.romdis == 0)
1210      if ( (m_gate_array.mrer & (1<<2)) == 0 && m_gate_array.romdis == 0)
12171211      {  // ASIC secondary lower ROM selection (bit 5: 1 = enabled)
1218         if ( state->m_asic.enabled )
1212         if ( m_asic.enabled )
12191213         {
1220//              logerror("L-ROM: Lower ROM enabled, cart bank %i\n", state->m_asic.rmr2 & 0x07 );
1221            bank_base = &machine.root_device().memregion("maincpu")->base()[0x4000 * ( state->m_asic.rmr2 & 0x07 )];
1222            switch( state->m_asic.rmr2 & 0x18 )
1214//              logerror("L-ROM: Lower ROM enabled, cart bank %i\n", m_asic.rmr2 & 0x07 );
1215            bank_base = &m_region_maincpu->base()[0x4000 * ( m_asic.rmr2 & 0x07 )];
1216            switch( m_asic.rmr2 & 0x18 )
12231217            {
12241218            case 0x00:
12251219//                  logerror("L-ROM: located at &0000\n");
1226               state->membank("bank1")->set_base(bank_base);
1227               state->membank("bank2")->set_base(bank_base+0x02000);
1220               m_bank1->set_base(bank_base);
1221               m_bank2->set_base(bank_base+0x02000);
12281222               break;
12291223            case 0x08:
12301224//                  logerror("L-ROM: located at &4000\n");
1231               state->membank("bank3")->set_base(bank_base);
1232               state->membank("bank4")->set_base(bank_base+0x02000);
1225               m_bank3->set_base(bank_base);
1226               m_bank4->set_base(bank_base+0x02000);
12331227               break;
12341228            case 0x10:
12351229//                  logerror("L-ROM: located at &8000\n");
1236               state->membank("bank5")->set_base(bank_base);
1237               state->membank("bank6")->set_base(bank_base+0x02000);
1230               m_bank5->set_base(bank_base);
1231               m_bank6->set_base(bank_base+0x02000);
12381232               break;
12391233            case 0x18:
12401234//                  logerror("L-ROM: located at &0000, ASIC registers enabled\n");
1241               state->membank("bank1")->set_base(bank_base);
1242               state->membank("bank2")->set_base(bank_base+0x02000);
1235               m_bank1->set_base(bank_base);
1236               m_bank2->set_base(bank_base+0x02000);
12431237               break;
12441238            }
12451239         }
12461240         else
12471241         {
1248            state->membank( "bank1" )->set_base( machine.root_device().memregion( "maincpu" )->base() );
1249            state->membank( "bank2" )->set_base( machine.root_device().memregion( "maincpu" )->base() + 0x2000 );
1242            m_bank1->set_base( m_region_maincpu->base() );
1243            m_bank2->set_base( m_region_maincpu->base() + 0x2000 );
12501244         }
12511245      }
12521246   }
r20956r20957
12561250/*-----------------
12571251  - Set Upper Rom -
12581252  -----------------*/
1259static void amstrad_setUpperRom(running_machine &machine)
1253void amstrad_state::amstrad_setUpperRom()
12601254{
1261   amstrad_state *state = machine.driver_data<amstrad_state>();
12621255   UINT8 *bank_base = NULL;
12631256
12641257   /* b3 : "1" Upper rom area disable or "0" Upper rom area enable */
1265   if ( ! ( state->m_gate_array.mrer & 0x08 ) && state->m_gate_array.romdis == 0)
1258   if ( ! ( m_gate_array.mrer & 0x08 ) && m_gate_array.romdis == 0)
12661259   {
1267      bank_base = state->m_Amstrad_ROM_Table[ state->m_gate_array.upper_bank ];
1260      bank_base = m_Amstrad_ROM_Table[ m_gate_array.upper_bank ];
12681261   }
12691262   else
12701263   {
1271      if(state->m_aleste_mode & 0x04)
1272         bank_base = state->m_Aleste_RamBanks[3];
1264      if(m_aleste_mode & 0x04)
1265         bank_base = m_Aleste_RamBanks[3];
12731266      else
1274         bank_base = state->m_AmstradCPC_RamBanks[3];
1267         bank_base = m_AmstradCPC_RamBanks[3];
12751268   }
12761269
12771270   if (bank_base)
12781271   {
1279      state->membank("bank7")->set_base(bank_base);
1280      state->membank("bank8")->set_base(bank_base+0x2000);
1272      m_bank7->set_base(bank_base);
1273      m_bank8->set_base(bank_base+0x2000);
12811274   }
12821275}
12831276
r20956r20957
13021295The CPC6128 has a 64k ram expansion built-in, giving 128K of RAM in this system.
13031296In the CPC464,CPC664 and KC compact if a ram expansion is not present, then writing to this port has no effect and the ram will be in the same arrangement as if configuration 0 had been selected.
13041297*/
1305static void AmstradCPC_GA_SetRamConfiguration(running_machine &machine)
1298void amstrad_state::AmstradCPC_GA_SetRamConfiguration()
13061299{
1307   amstrad_state *state = machine.driver_data<amstrad_state>();
1308   int ConfigurationIndex = state->m_GateArray_RamConfiguration & 0x07;
1300   int ConfigurationIndex = m_GateArray_RamConfiguration & 0x07;
13091301   int BankIndex,i;
13101302   unsigned char *BankAddr;
13111303
13121304/* if b5 = 0 */
1313   if(((state->m_GateArray_RamConfiguration) & (1<<5)) == 0)
1305   if(((m_GateArray_RamConfiguration) & (1<<5)) == 0)
13141306   {
13151307      for (i=0;i<4;i++)
13161308      {
13171309         BankIndex = RamConfigurations[(ConfigurationIndex << 2) + i];
1318         BankAddr = state->m_ram->pointer() + (BankIndex << 14);
1319         state->m_Aleste_RamBanks[i] = BankAddr;
1320         state->m_AmstradCPC_RamBanks[i] = BankAddr;
1310         BankAddr = m_ram->pointer() + (BankIndex << 14);
1311         m_Aleste_RamBanks[i] = BankAddr;
1312         m_AmstradCPC_RamBanks[i] = BankAddr;
13211313      }
13221314   }
13231315   else
13241316   {/* Need to add the ram expansion configuration here ! */
13251317   }
1326   amstrad_rethinkMemory(machine);
1318   amstrad_rethinkMemory();
13271319}
13281320
13291321
r20956r20957
14001392      m_asic.ram[offset] = data & 0x0f;
14011393   else
14021394   {
1403      UINT8* RAM = (UINT8*)membank("bank11")->base();
1395      UINT8* RAM = (UINT8*)m_bank11->base();
14041396      RAM[offset] = data;
14051397   }
14061398}
r20956r20957
14791471         if(data & 0x40)
14801472         {
14811473            logerror("ASIC: DMA 0 IRQ acknowledge\n");
1482            machine().device("maincpu")->execute().set_input_line(0, CLEAR_LINE);
1474            m_maincpu->set_input_line(0, CLEAR_LINE);
14831475            m_plus_irq_cause = 0x06;
14841476            m_asic.ram[0x2c0f] &= ~0x40;
14851477         }
14861478         if(data & 0x20)
14871479         {
14881480            logerror("ASIC: DMA 1 IRQ acknowledge\n");
1489            machine().device("maincpu")->execute().set_input_line(0, CLEAR_LINE);
1481            m_maincpu->set_input_line(0, CLEAR_LINE);
14901482            m_plus_irq_cause = 0x06;
14911483            m_asic.ram[0x2c0f] &= ~0x20;
14921484         }
14931485         if(data & 0x10)
14941486         {
14951487            logerror("ASIC: DMA 2 IRQ acknowledge\n");
1496            machine().device("maincpu")->execute().set_input_line(0, CLEAR_LINE);
1488            m_maincpu->set_input_line(0, CLEAR_LINE);
14971489            m_plus_irq_cause = 0x06;
14981490            m_asic.ram[0x2c0f] &= ~0x10;
14991491         }
r20956r20957
15031495   }
15041496   else
15051497   {
1506      UINT8* RAM = (UINT8*)membank("bank12")->base();
1498      UINT8* RAM = (UINT8*)m_bank12->base();
15071499      RAM[offset] = data;
15081500   }
15091501}
r20956r20957
15161508      return m_asic.ram[offset];
15171509   else
15181510   {
1519      UINT8* RAM = (UINT8*)membank("bank3")->base();
1511      UINT8* RAM = (UINT8*)m_bank3->base();
15201512      return RAM[offset];
15211513   }
15221514}
r20956r20957
15301522      // Analogue ports
15311523      if(offset == 0x0808)
15321524      {
1533         return (ioport("analog1")->read() & 0x3f);
1525         return (m_io_analog1->read() & 0x3f);
15341526      }
15351527      if(offset == 0x0809)
15361528      {
1537         return (ioport("analog2")->read() & 0x3f);
1529         return (m_io_analog2->read() & 0x3f);
15381530      }
15391531      if(offset == 0x080a)
15401532      {
1541         return (ioport("analog3")->read() & 0x3f);
1533         return (m_io_analog3->read() & 0x3f);
15421534      }
15431535      if(offset == 0x080b)
15441536      {
1545         return (ioport("analog4")->read() & 0x3f);
1537         return (m_io_analog4->read() & 0x3f);
15461538      }
15471539      if(offset == 0x080c || offset == 0x080e)
15481540      {
r20956r20957
15711563   }
15721564   else
15731565   {
1574      UINT8* RAM = (UINT8*)membank("bank4")->base();
1566      UINT8* RAM = (UINT8*)m_bank4->base();
15751567      return RAM[offset];
15761568   }
15771569}
15781570
15791571
15801572/* used for loading snapshot only ! */
1581static void AmstradCPC_PALWrite(running_machine &machine, int data)
1573void amstrad_state::AmstradCPC_PALWrite(int data)
15821574{
1583   amstrad_state *state = machine.driver_data<amstrad_state>();
15841575   if ((data & 0x0c0)==0x0c0)
15851576   {
1586      state->m_GateArray_RamConfiguration = data;
1587      AmstradCPC_GA_SetRamConfiguration(machine);
1577      m_GateArray_RamConfiguration = data;
1578      AmstradCPC_GA_SetRamConfiguration();
15881579   }
15891580}
15901581
r20956r20957
16091600Note 1 : This function is not available in the Gate-Array, but is performed by a device at the same I/O port address location. In the CPC464,CPC664 and KC compact, this function is performed in a memory-expansion (e.g. Dk'Tronics 64K Ram Expansion), if this expansion is not present then the function is not available. In the CPC6128, this function is performed by a PAL located on the main PCB, or a memory-expansion. In the 464+ and 6128+ this function is performed by the ASIC or a memory expansion. Please read the document on Ram Management for more information.*/
16101601
16111602
1612static void amstrad_GateArray_write(running_machine &machine, UINT8 dataToGateArray)
1603void amstrad_state::amstrad_GateArray_write(UINT8 dataToGateArray)
16131604{
1614   amstrad_state *state = machine.driver_data<amstrad_state>();
16151605/* Get Bit 7 and 6 of the dataToGateArray = Gate Array function selected */
16161606   switch ((dataToGateArray & 0xc0)>>6)
16171607   {
r20956r20957
16281618   case 0x00:
16291619      /* Select Border Number, get b4 */
16301620      /* if b4 = 0 : Select Pen Number, get b3-b0 */
1631      state->m_gate_array.pen_selected = ( dataToGateArray & 0x10 ) ? 0x10 : ( dataToGateArray & 0x0f );
1621      m_gate_array.pen_selected = ( dataToGateArray & 0x10 ) ? 0x10 : ( dataToGateArray & 0x0f );
16321622      break;
16331623
16341624/* Colour selection
r20956r20957
164416341   x     |
164516350   x     |*/
16461636   case 0x01:
1647      amstrad_vh_update_colour( machine, state->m_gate_array.pen_selected, (dataToGateArray & 0x1F));
1637      amstrad_vh_update_colour( m_gate_array.pen_selected, (dataToGateArray & 0x1F));
16481638      break;
16491639
16501640/* Select screen mode and rom configuration
r20956r20957
16781668      /* If bit 5 is enabled on a CPC Plus/GX4000 when the ASIC is unlocked, sets the lower ROM position and cart bank
16791669         b5 = 1, b4b3 = RAM position for lower ROM area and if the ASIC registers are visible at &4000,
16801670         b2b1b0 = cartridge bank to read from lower ROM area (0-7 only) */
1681      if ( state->m_system_type == SYSTEM_PLUS || state->m_system_type == SYSTEM_GX4000 )
1671      if ( m_system_type == SYSTEM_PLUS || m_system_type == SYSTEM_GX4000 )
16821672      {
1683         if ( state->m_asic.enabled && (dataToGateArray & 0x20) )
1673         if ( m_asic.enabled && (dataToGateArray & 0x20) )
16841674         {
1685            state->m_asic.rmr2 = dataToGateArray;
1675            m_asic.rmr2 = dataToGateArray;
16861676         }
16871677         else
16881678         {
1689            state->m_gate_array.mrer = dataToGateArray;
1679            m_gate_array.mrer = dataToGateArray;
16901680         }
16911681      }
16921682      else
16931683      {
1694         state->m_gate_array.mrer = dataToGateArray;
1684         m_gate_array.mrer = dataToGateArray;
16951685      }
16961686
16971687      /* If bit 4 of the "Select screen mode and rom configuration" register of the Gate-Array is set to "1"
16981688       then the interrupt request is cleared and the 6-bit counter is reset to "0".  */
1699      if ( state->m_gate_array.mrer & 0x10 )
1689      if ( m_gate_array.mrer & 0x10 )
17001690      {
1701         state->m_gate_array.hsync_counter = 0;
1702         machine.device("maincpu")->execute().set_input_line(0, CLEAR_LINE);
1691         m_gate_array.hsync_counter = 0;
1692         m_maincpu->set_input_line(0, CLEAR_LINE);
17031693      }
17041694
17051695      /* b3b2 != 0 then change the state of upper or lower rom area and rethink memory */
1706      amstrad_setLowerRom(machine);
1707      amstrad_setUpperRom(machine);
1696      amstrad_setLowerRom();
1697      amstrad_setUpperRom();
17081698
17091699      /* b1b0 mode */
1710      amstrad_vh_update_mode(state);
1700      amstrad_vh_update_mode();
17111701
17121702      break;
17131703
r20956r20957
17191709In the 464+ and 6128+ this function is performed by the ASIC or a memory expansion.
17201710*/
17211711   case 0x03:
1722      state->m_GateArray_RamConfiguration = dataToGateArray;
1712      m_GateArray_RamConfiguration = dataToGateArray;
17231713      break;
17241714
17251715   default:
r20956r20957
17401730   switch(function)
17411731   {
17421732   case 0:  // Pen select (same as Gate Array?)
1743      amstrad_GateArray_write(machine(), data);
1733      amstrad_GateArray_write(data);
17441734      break;
17451735   case 1:  // Colour select (6-bit palette)
1746      aleste_vh_update_colour( machine(), m_gate_array.pen_selected, data & 0x3f );
1736      aleste_vh_update_colour( m_gate_array.pen_selected, data & 0x3f );
17471737      break;
17481738   case 2:  // Screen mode, Upper/Lower ROM select
1749      amstrad_GateArray_write(machine(), data);
1739      amstrad_GateArray_write(data);
17501740      break;
17511741   case 3: // RAM banks
17521742      switch(page)
17531743      {
17541744      case 0:  /* 0x0000 - 0x3fff */
1755         membank("bank1")->set_base(ram+ramptr);
1756         membank("bank2")->set_base(ram+ramptr+0x2000);
1757         membank("bank9")->set_base(ram+ramptr);
1758         membank("bank10")->set_base(ram+ramptr+0x2000);
1745         m_bank1->set_base(ram+ramptr);
1746         m_bank2->set_base(ram+ramptr+0x2000);
1747         m_bank9->set_base(ram+ramptr);
1748         m_bank10->set_base(ram+ramptr+0x2000);
17591749         m_Aleste_RamBanks[0] = ram+ramptr;
17601750         m_aleste_active_page[0] = data;
17611751         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0x0000\n",ramptr,rampage);
17621752         break;
17631753      case 1:  /* 0x4000 - 0x7fff */
1764         membank("bank3")->set_base(ram+ramptr);
1765         membank("bank4")->set_base(ram+ramptr+0x2000);
1766         membank("bank11")->set_base(ram+ramptr);
1767         membank("bank12")->set_base(ram+ramptr+0x2000);
1754         m_bank3->set_base(ram+ramptr);
1755         m_bank4->set_base(ram+ramptr+0x2000);
1756         m_bank11->set_base(ram+ramptr);
1757         m_bank12->set_base(ram+ramptr+0x2000);
17681758         m_Aleste_RamBanks[1] = ram+ramptr;
17691759         m_aleste_active_page[1] = data;
17701760         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0x4000\n",ramptr,rampage);
17711761         break;
17721762      case 2:  /* 0x8000 - 0xbfff */
1773         membank("bank5")->set_base(ram+ramptr);
1774         membank("bank6")->set_base(ram+ramptr+0x2000);
1775         membank("bank13")->set_base(ram+ramptr);
1776         membank("bank14")->set_base(ram+ramptr+0x2000);
1763         m_bank5->set_base(ram+ramptr);
1764         m_bank6->set_base(ram+ramptr+0x2000);
1765         m_bank13->set_base(ram+ramptr);
1766         m_bank14->set_base(ram+ramptr+0x2000);
17771767         m_Aleste_RamBanks[2] = ram+ramptr;
17781768         m_aleste_active_page[2] = data;
17791769         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0x8000\n",ramptr,rampage);
17801770         break;
17811771      case 3:  /* 0xc000 - 0xffff */
1782         membank("bank7")->set_base(ram+ramptr);
1783         membank("bank8")->set_base(ram+ramptr+0x2000);
1784         membank("bank15")->set_base(ram+ramptr);
1785         membank("bank16")->set_base(ram+ramptr+0x2000);
1772         m_bank7->set_base(ram+ramptr);
1773         m_bank8->set_base(ram+ramptr+0x2000);
1774         m_bank15->set_base(ram+ramptr);
1775         m_bank16->set_base(ram+ramptr+0x2000);
17861776         m_Aleste_RamBanks[3] = ram+ramptr;
17871777         m_aleste_active_page[3] = data;
17881778         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0xc000\n",ramptr,rampage);
r20956r20957
18561846
18571847READ8_MEMBER(amstrad_state::amstrad_cpc_io_r)
18581848{
1859   mc6845_device *mc6845 = m_crtc;
1860
18611849   unsigned char data = 0xFF;
18621850   unsigned int r1r0 = (unsigned int)((offset & 0x0300) >> 8);
18631851//  m6845_personality_t crtc_type;
r20956r20957
18821870      switch(r1r0)
18831871      {
18841872      case 0x02:
1885         data = mc6845->status_r( space, 0 );
1873         data = m_crtc->status_r( space, 0 );
18861874#if 0
18871875         /* CRTC Type 1 : Read Status Register
18881876            CRTC Type 3 or 4 : Read from selected internal 6845 register */
r20956r20957
19011889         break;
19021890      case 0x03:
19031891         /* All CRTC type : Read from selected internal 6845 register Read only */
1904         data = mc6845->register_r( space, (offs_t)0 );
1892         data = m_crtc->register_r( space, (offs_t)0 );
19051893         break;
19061894      }
19071895   }
r20956r20957
19911979/* Offset handler for write */
19921980WRITE8_MEMBER(amstrad_state::amstrad_cpc_io_w)
19931981{
1994   mc6845_device *mc6845 = m_crtc;
19951982   cpc_multiface2_device* mface2;
19961983
19971984   if ((offset & (1<<15)) == 0)
r20956r20957
20041991      {
20051992         /* if b15 = 0 and b14 = 1 : Gate-Array Write Selected*/
20061993         if ((offset & (1<<14)) != 0)
2007            amstrad_GateArray_write(machine(), data);
1994            amstrad_GateArray_write(data);
20081995
20091996         /* if b15 = 0 : RAM Configuration Write Selected*/
2010         AmstradCPC_GA_SetRamConfiguration(machine());
1997         AmstradCPC_GA_SetRamConfiguration();
20111998      }
20121999   }
20132000
r20956r20957
20182005      switch ((offset & 0x0300) >> 8) // r1r0
20192006      {
20202007      case 0x00:      /* Select internal 6845 register Write Only */
2021         mc6845->address_w( space, 0, data );
2008         m_crtc->address_w( space, 0, data );
20222009         if ( m_system_type == SYSTEM_PLUS || m_system_type == SYSTEM_GX4000 )
20232010            amstrad_plus_seqcheck(data);
20242011
r20956r20957
20332020            machine().scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),this),1);
20342021         else
20352022            machine().scheduler().timer_set( attotime::from_usec(0), timer_expired_delegate(FUNC(amstrad_state::amstrad_video_update_timer),this),0);
2036         mc6845->register_w( space, 0, data );
2023         m_crtc->register_w( space, 0, data );
20372024
20382025         /* printer port bit 8 */
20392026         if (m_printer_bit8_selected && m_system_type == SYSTEM_PLUS)
20402027         {
2041            centronics_device *printer = m_centronics;
2042            printer->d7_w(BIT(data, 3));
2028            m_centronics->d7_w(BIT(data, 3));
20432029            m_printer_bit8_selected = FALSE;
20442030         }
20452031
r20956r20957
20572043   if ((offset & (1<<13)) == 0)
20582044   {
20592045      m_gate_array.upper_bank = data;
2060      amstrad_setUpperRom(machine());
2046      amstrad_setUpperRom();
20612047   }
20622048
20632049   /* b12 = 0 : Printer port Write Selected*/
r20956r20957
20652051   {
20662052      if ((offset & (1<<12)) == 0)
20672053      {
2068         centronics_device *printer = m_centronics;
2069
20702054         /* CPC has a 7-bit data port, bit 8 is the STROBE signal */
2071         printer->write(space, 0, data & 0x7f);
2072         printer->strobe_w(BIT(data, 7));
2055         m_centronics->write(space, 0, data & 0x7f);
2056         m_centronics->strobe_w(BIT(data, 7));
20732057      }
20742058   }
20752059
r20956r20957
21512135   {
21522136      m_aleste_mode = data;
21532137      logerror("EXTEND: Port &FABF write 0x%02x\n",data);
2154      mc6845->set_clock( ( m_aleste_mode & 0x02 ) ? ( XTAL_16MHz / 8 ) : ( XTAL_16MHz / 16 ) );
2138      m_crtc->set_clock( ( m_aleste_mode & 0x02 ) ? ( XTAL_16MHz / 8 ) : ( XTAL_16MHz / 16 ) );
21552139   }
21562140
21572141   mface2 = dynamic_cast<cpc_multiface2_device*>(get_expansion_device(machine(),"multiface2"));
21582142   if(mface2 != NULL)
21592143   {
21602144      if(mface2->multiface_io_write(offset, data) != 0)
2161         amstrad_rethinkMemory(machine());
2145      {
2146         amstrad_rethinkMemory();
2147      }
21622148   }
21632149}
21642150
21652151
21662152/* load CPCEMU style snapshots */
2167static void amstrad_handle_snapshot(running_machine &machine, unsigned char *pSnapshot)
2153void amstrad_state::amstrad_handle_snapshot(unsigned char *pSnapshot)
21682154{
2169   amstrad_state *state = machine.driver_data<amstrad_state>();
2170   address_space &space = state->m_maincpu->space(AS_PROGRAM);
2171   mc6845_device *mc6845 = state->m_crtc;
2172   device_t *ay8910 = state->m_ay;
2155   address_space &space = m_maincpu->space(AS_PROGRAM);
21732156   int RegData;
21742157   int i;
21752158
21762159   /* init Z80 */
21772160   RegData = (pSnapshot[0x011] & 0x0ff) | ((pSnapshot[0x012] & 0x0ff)<<8);
2178   state->m_maincpu->set_state_int(Z80_AF, RegData);
2161   m_maincpu->set_state_int(Z80_AF, RegData);
21792162
21802163   RegData = (pSnapshot[0x013] & 0x0ff) | ((pSnapshot[0x014] & 0x0ff)<<8);
2181   state->m_maincpu->set_state_int(Z80_BC, RegData);
2164   m_maincpu->set_state_int(Z80_BC, RegData);
21822165
21832166   RegData = (pSnapshot[0x015] & 0x0ff) | ((pSnapshot[0x016] & 0x0ff)<<8);
2184   state->m_maincpu->set_state_int(Z80_DE, RegData);
2167   m_maincpu->set_state_int(Z80_DE, RegData);
21852168
21862169   RegData = (pSnapshot[0x017] & 0x0ff) | ((pSnapshot[0x018] & 0x0ff)<<8);
2187   state->m_maincpu->set_state_int(Z80_HL, RegData);
2170   m_maincpu->set_state_int(Z80_HL, RegData);
21882171
21892172   RegData = (pSnapshot[0x019] & 0x0ff) ;
2190   state->m_maincpu->set_state_int(Z80_R, RegData);
2173   m_maincpu->set_state_int(Z80_R, RegData);
21912174
21922175   RegData = (pSnapshot[0x01a] & 0x0ff);
2193   state->m_maincpu->set_state_int(Z80_I, RegData);
2176   m_maincpu->set_state_int(Z80_I, RegData);
21942177
21952178   if ((pSnapshot[0x01b] & 1)==1)
21962179   {
2197      state->m_maincpu->set_state_int(Z80_IFF1, (UINT64)1);
2180      m_maincpu->set_state_int(Z80_IFF1, (UINT64)1);
21982181   }
21992182   else
22002183   {
2201      state->m_maincpu->set_state_int(Z80_IFF1, (UINT64)0);
2184      m_maincpu->set_state_int(Z80_IFF1, (UINT64)0);
22022185   }
22032186
22042187   if ((pSnapshot[0x01c] & 1)==1)
22052188   {
2206      state->m_maincpu->set_state_int(Z80_IFF2, (UINT64)1);
2189      m_maincpu->set_state_int(Z80_IFF2, (UINT64)1);
22072190   }
22082191   else
22092192   {
2210      state->m_maincpu->set_state_int(Z80_IFF2, (UINT64)0);
2193      m_maincpu->set_state_int(Z80_IFF2, (UINT64)0);
22112194   }
22122195
22132196   RegData = (pSnapshot[0x01d] & 0x0ff) | ((pSnapshot[0x01e] & 0x0ff)<<8);
2214   state->m_maincpu->set_state_int(Z80_IX, RegData);
2197   m_maincpu->set_state_int(Z80_IX, RegData);
22152198
22162199   RegData = (pSnapshot[0x01f] & 0x0ff) | ((pSnapshot[0x020] & 0x0ff)<<8);
2217   state->m_maincpu->set_state_int(Z80_IY, RegData);
2200   m_maincpu->set_state_int(Z80_IY, RegData);
22182201
22192202   RegData = (pSnapshot[0x021] & 0x0ff) | ((pSnapshot[0x022] & 0x0ff)<<8);
2220   state->m_maincpu->set_state_int(Z80_SP, RegData);
2221   state->m_maincpu->set_state_int(STATE_GENSP, RegData);
2203   m_maincpu->set_state_int(Z80_SP, RegData);
2204   m_maincpu->set_state_int(STATE_GENSP, RegData);
22222205
22232206   RegData = (pSnapshot[0x023] & 0x0ff) | ((pSnapshot[0x024] & 0x0ff)<<8);
22242207
2225   state->m_maincpu->set_state_int(Z80_PC, RegData);
2226//  state->m_maincpu->set_state_int(REG_SP, RegData);
2208   m_maincpu->set_state_int(Z80_PC, RegData);
2209//  m_maincpu->set_state_int(REG_SP, RegData);
22272210
22282211   RegData = (pSnapshot[0x025] & 0x0ff);
2229   state->m_maincpu->set_state_int(Z80_IM, RegData);
2212   m_maincpu->set_state_int(Z80_IM, RegData);
22302213
22312214   RegData = (pSnapshot[0x026] & 0x0ff) | ((pSnapshot[0x027] & 0x0ff)<<8);
2232   state->m_maincpu->set_state_int(Z80_AF2, RegData);
2215   m_maincpu->set_state_int(Z80_AF2, RegData);
22332216
22342217   RegData = (pSnapshot[0x028] & 0x0ff) | ((pSnapshot[0x029] & 0x0ff)<<8);
2235   state->m_maincpu->set_state_int(Z80_BC2, RegData);
2218   m_maincpu->set_state_int(Z80_BC2, RegData);
22362219
22372220   RegData = (pSnapshot[0x02a] & 0x0ff) | ((pSnapshot[0x02b] & 0x0ff)<<8);
2238   state->m_maincpu->set_state_int(Z80_DE2, RegData);
2221   m_maincpu->set_state_int(Z80_DE2, RegData);
22392222
22402223   RegData = (pSnapshot[0x02c] & 0x0ff) | ((pSnapshot[0x02d] & 0x0ff)<<8);
2241   state->m_maincpu->set_state_int(Z80_HL2, RegData);
2224   m_maincpu->set_state_int(Z80_HL2, RegData);
22422225
22432226   /* init GA */
22442227   for (i=0; i<17; i++)
22452228   {
2246      amstrad_GateArray_write(machine, i);
2229      amstrad_GateArray_write(i);
22472230
2248      amstrad_GateArray_write(machine, ((pSnapshot[0x02f + i] & 0x01f) | 0x040));
2231      amstrad_GateArray_write(((pSnapshot[0x02f + i] & 0x01f) | 0x040));
22492232   }
22502233
2251   amstrad_GateArray_write(machine, pSnapshot[0x02e] & 0x01f);
2234   amstrad_GateArray_write(pSnapshot[0x02e] & 0x01f);
22522235
2253   amstrad_GateArray_write(machine, ((pSnapshot[0x040] & 0x03f) | 0x080));
2236   amstrad_GateArray_write(((pSnapshot[0x040] & 0x03f) | 0x080));
22542237
2255   AmstradCPC_PALWrite(machine, ((pSnapshot[0x041] & 0x03f) | 0x0c0));
2238   AmstradCPC_PALWrite(((pSnapshot[0x041] & 0x03f) | 0x0c0));
22562239
22572240   /* init CRTC */
22582241   for (i=0; i<18; i++)
22592242   {
2260      mc6845->address_w( space, 0, i );
2261      mc6845->register_w( space, 0, pSnapshot[0x043+i] & 0xff );
2243      m_crtc->address_w( space, 0, i );
2244      m_crtc->register_w( space, 0, pSnapshot[0x043+i] & 0xff );
22622245   }
22632246
2264   mc6845->address_w( space, 0, i );
2247   m_crtc->address_w( space, 0, i );
22652248
22662249   /* upper rom selection */
2267   state->m_gate_array.upper_bank = pSnapshot[0x055];
2250   m_gate_array.upper_bank = pSnapshot[0x055];
22682251
22692252   /* PPI */
2270   state->m_ppi->write(space, 3, pSnapshot[0x059] & 0x0ff);
2253   m_ppi->write(space, 3, pSnapshot[0x059] & 0x0ff);
22712254
2272   state->m_ppi->write(space, 0, pSnapshot[0x056] & 0x0ff);
2273   state->m_ppi->write(space, 1, pSnapshot[0x057] & 0x0ff);
2274   state->m_ppi->write(space, 2, pSnapshot[0x058] & 0x0ff);
2255   m_ppi->write(space, 0, pSnapshot[0x056] & 0x0ff);
2256   m_ppi->write(space, 1, pSnapshot[0x057] & 0x0ff);
2257   m_ppi->write(space, 2, pSnapshot[0x058] & 0x0ff);
22752258
22762259   /* PSG */
22772260   for (i=0; i<16; i++)
22782261   {
2279      ay8910_address_w(ay8910, space, 0, i);
2280      ay8910_data_w(ay8910, space, 0, pSnapshot[0x05b + i] & 0x0ff);
2262      ay8910_address_w(m_ay, space, 0, i);
2263      ay8910_data_w(m_ay, space, 0, pSnapshot[0x05b + i] & 0x0ff);
22812264   }
22822265
2283   ay8910_address_w(ay8910, space, 0, pSnapshot[0x05a]);
2266   ay8910_address_w(m_ay, space, 0, pSnapshot[0x05a]);
22842267
22852268   {
22862269      int MemSize;
r20956r20957
22972280         MemorySize = 64*1024;
22982281      }
22992282
2300      memcpy(state->m_ram->pointer(), &pSnapshot[0x0100], MemorySize);
2283      memcpy(m_ram->pointer(), &pSnapshot[0x0100], MemorySize);
23012284   }
2302   amstrad_rethinkMemory(machine);
2285   amstrad_rethinkMemory();
23032286}
23042287
23052288
r20956r20957
23072290All hardware is reset and the firmware is completely initialized
23082291Once all tables and jumpblocks have been set up,
23092292control is passed to the default entry in rom 0*/
2310static void amstrad_reset_machine(running_machine &machine)
2293void amstrad_state::amstrad_reset_machine()
23112294{
2312   amstrad_state *state = machine.driver_data<amstrad_state>();
23132295   /* enable lower rom (OS rom) */
2314   amstrad_GateArray_write(machine, 0x089);
2296   amstrad_GateArray_write(0x089);
23152297
23162298   /* set ram config 0 */
2317   amstrad_GateArray_write(machine, 0x0c0);
2299   amstrad_GateArray_write(0x0c0);
23182300
23192301   // Get manufacturer name and TV refresh rate from PCB link (dipswitch for mess emulation)
2320   state->m_ppi_port_inputs[amstrad_ppi_PortB] = (((machine.root_device().ioport("solder_links")->read()&MANUFACTURER_NAME)<<1) | (machine.root_device().ioport("solder_links")->read()&TV_REFRESH_RATE));
2302   m_ppi_port_inputs[amstrad_ppi_PortB] = (((m_io_solder_links->read()&MANUFACTURER_NAME)<<1) | (m_io_solder_links->read()&TV_REFRESH_RATE));
23212303
2322   if ( state->m_system_type == SYSTEM_PLUS || state->m_system_type == SYSTEM_GX4000 )
2323      memset(state->m_asic.ram,0,16384);  // clear ASIC RAM
2304   if ( m_system_type == SYSTEM_PLUS || m_system_type == SYSTEM_GX4000 )
2305   {
2306      memset(m_asic.ram,0,16384);  // clear ASIC RAM
2307   }
23242308}
23252309
23262310
23272311/*------------------
23282312  - Rethink Memory -
23292313  ------------------*/
2330static void amstrad_rethinkMemory(running_machine &machine)
2314void amstrad_state::amstrad_rethinkMemory()
23312315{
2332   amstrad_state *state = machine.driver_data<amstrad_state>();
23332316   cpc_multiface2_device* mface2;
23342317   /* the following is used for banked memory read/writes and for setting up
23352318    * opcode and opcode argument reads */
23362319
23372320   /* bank 0 - 0x0000..0x03fff */
2338   amstrad_setLowerRom(machine);
2321   amstrad_setLowerRom();
23392322
23402323   /* bank 1 - 0x04000..0x07fff */
2341   if ( state->m_system_type == SYSTEM_CPC || state->m_system_type == SYSTEM_ALESTE || state->m_asic.enabled == 0 )
2324   if ( m_system_type == SYSTEM_CPC || m_system_type == SYSTEM_ALESTE || m_asic.enabled == 0 )
23422325   {
2343      if(state->m_aleste_mode & 0x04)
2326      if(m_aleste_mode & 0x04)
23442327      {
2345         state->membank("bank3")->set_base(state->m_Aleste_RamBanks[1]);
2346         state->membank("bank4")->set_base(state->m_Aleste_RamBanks[1]+0x2000);
2328         m_bank3->set_base(m_Aleste_RamBanks[1]);
2329         m_bank4->set_base(m_Aleste_RamBanks[1]+0x2000);
23472330         /* bank 2 - 0x08000..0x0bfff */
2348         state->membank("bank5")->set_base(state->m_Aleste_RamBanks[2]);
2349         state->membank("bank6")->set_base(state->m_Aleste_RamBanks[2]+0x2000);
2331         m_bank5->set_base(m_Aleste_RamBanks[2]);
2332         m_bank6->set_base(m_Aleste_RamBanks[2]+0x2000);
23502333      }
23512334      else
23522335      {
2353         state->membank("bank3")->set_base(state->m_AmstradCPC_RamBanks[1]);
2354         state->membank("bank4")->set_base(state->m_AmstradCPC_RamBanks[1]+0x2000);
2336         m_bank3->set_base(m_AmstradCPC_RamBanks[1]);
2337         m_bank4->set_base(m_AmstradCPC_RamBanks[1]+0x2000);
23552338         /* bank 2 - 0x08000..0x0bfff */
2356         state->membank("bank5")->set_base(state->m_AmstradCPC_RamBanks[2]);
2357         state->membank("bank6")->set_base(state->m_AmstradCPC_RamBanks[2]+0x2000);
2339         m_bank5->set_base(m_AmstradCPC_RamBanks[2]);
2340         m_bank6->set_base(m_AmstradCPC_RamBanks[2]+0x2000);
23582341      }
23592342   }
23602343   else
2361      amstrad_setLowerRom(machine);
2344   {
2345      amstrad_setLowerRom();
2346   }
23622347
23632348   /* bank 3 - 0x0c000..0x0ffff */
2364   amstrad_setUpperRom(machine);
2349   amstrad_setUpperRom();
23652350
23662351   /* other banks */
2367   if(state->m_aleste_mode & 0x04)
2352   if(m_aleste_mode & 0x04)
23682353   {
2369      state->membank("bank9")->set_base(state->m_Aleste_RamBanks[0]);
2370      state->membank("bank10")->set_base(state->m_Aleste_RamBanks[0]+0x2000);
2371      state->membank("bank11")->set_base(state->m_Aleste_RamBanks[1]);
2372      state->membank("bank12")->set_base(state->m_Aleste_RamBanks[1]+0x2000);
2373      state->membank("bank13")->set_base(state->m_Aleste_RamBanks[2]);
2374      state->membank("bank14")->set_base(state->m_Aleste_RamBanks[2]+0x2000);
2375      state->membank("bank15")->set_base(state->m_Aleste_RamBanks[3]);
2376      state->membank("bank16")->set_base(state->m_Aleste_RamBanks[3]+0x2000);
2354      m_bank9->set_base(m_Aleste_RamBanks[0]);
2355      m_bank10->set_base(m_Aleste_RamBanks[0]+0x2000);
2356      m_bank11->set_base(m_Aleste_RamBanks[1]);
2357      m_bank12->set_base(m_Aleste_RamBanks[1]+0x2000);
2358      m_bank13->set_base(m_Aleste_RamBanks[2]);
2359      m_bank14->set_base(m_Aleste_RamBanks[2]+0x2000);
2360      m_bank15->set_base(m_Aleste_RamBanks[3]);
2361      m_bank16->set_base(m_Aleste_RamBanks[3]+0x2000);
23772362   }
23782363   else
23792364   {
2380      state->membank("bank9")->set_base(state->m_AmstradCPC_RamBanks[0]);
2381      state->membank("bank10")->set_base(state->m_AmstradCPC_RamBanks[0]+0x2000);
2382      state->membank("bank11")->set_base(state->m_AmstradCPC_RamBanks[1]);
2383      state->membank("bank12")->set_base(state->m_AmstradCPC_RamBanks[1]+0x2000);
2384      state->membank("bank13")->set_base(state->m_AmstradCPC_RamBanks[2]);
2385      state->membank("bank14")->set_base(state->m_AmstradCPC_RamBanks[2]+0x2000);
2386      state->membank("bank15")->set_base(state->m_AmstradCPC_RamBanks[3]);
2387      state->membank("bank16")->set_base(state->m_AmstradCPC_RamBanks[3]+0x2000);
2365      m_bank9->set_base(m_AmstradCPC_RamBanks[0]);
2366      m_bank10->set_base(m_AmstradCPC_RamBanks[0]+0x2000);
2367      m_bank11->set_base(m_AmstradCPC_RamBanks[1]);
2368      m_bank12->set_base(m_AmstradCPC_RamBanks[1]+0x2000);
2369      m_bank13->set_base(m_AmstradCPC_RamBanks[2]);
2370      m_bank14->set_base(m_AmstradCPC_RamBanks[2]+0x2000);
2371      m_bank15->set_base(m_AmstradCPC_RamBanks[3]);
2372      m_bank16->set_base(m_AmstradCPC_RamBanks[3]+0x2000);
23882373   }
23892374
23902375   /* multiface hardware enabled? */
2391   mface2 = dynamic_cast<cpc_multiface2_device*>(get_expansion_device(machine,"multiface2"));
2376   mface2 = dynamic_cast<cpc_multiface2_device*>(get_expansion_device(machine(),"multiface2"));
23922377   if(mface2 != NULL)
23932378   {
23942379      if (mface2->multiface_hardware_enabled())
23952380      {
2396         if((state->m_gate_array.mrer & 0x04) == 0)
2381         if((m_gate_array.mrer & 0x04) == 0)
2382         {
23972383            mface2->multiface_rethink_memory();
2384         }
23982385      }
23992386   }
24002387}
24012388
24022389
2403static void kccomp_reset_machine(running_machine &machine)
2390void amstrad_state::kccomp_reset_machine()
24042391{
24052392   /* enable lower rom (OS rom) */
2406   amstrad_GateArray_write(machine, 0x089);
2393   amstrad_GateArray_write(0x089);
24072394
24082395   /* set ram config 0 */
2409   amstrad_GateArray_write(machine, 0x0c0);
2396   amstrad_GateArray_write(0x0c0);
24102397}
24112398
24122399
r20956r20957
244724341    1         | Select PSG register. When set, the PSG will take the data at PPI Port A and select a register
24482435*/
24492436/* PSG function selected */
2450static void update_psg(running_machine &machine)
2437void amstrad_state::update_psg()
24512438{
2452   amstrad_state *state = machine.driver_data<amstrad_state>();
2453   address_space &space = state->m_maincpu->space(AS_PROGRAM);
2454   device_t *ay8910 = state->m_ay;
2455   mc146818_device *rtc = state->m_rtc;
2439   address_space &space = m_maincpu->space(AS_PROGRAM);
24562440
2457   if(state->m_aleste_mode & 0x20)  // RTC selected
2441   if(m_aleste_mode & 0x20)  // RTC selected
24582442   {
2459      switch(state->m_aleste_rtc_function)
2443      switch(m_aleste_rtc_function)
24602444      {
24612445      case 0x02:  // AS
2462         rtc->write(space, 0,state->m_ppi_port_outputs[amstrad_ppi_PortA]);
2446         m_rtc->write(space, 0,m_ppi_port_outputs[amstrad_ppi_PortA]);
24632447         break;
24642448      case 0x04:  // DS write
2465         rtc->write(space, 1,state->m_ppi_port_outputs[amstrad_ppi_PortA]);
2449         m_rtc->write(space, 1,m_ppi_port_outputs[amstrad_ppi_PortA]);
24662450         break;
24672451      case 0x05:  // DS read
2468         state->m_ppi_port_inputs[amstrad_ppi_PortA] = rtc->read(space, 1);
2452         m_ppi_port_inputs[amstrad_ppi_PortA] = m_rtc->read(space, 1);
24692453         break;
24702454      }
24712455      return;
24722456   }
2473   switch (state->m_Psg_FunctionSelected)
2457   switch (m_Psg_FunctionSelected)
24742458   {
24752459   case 0:
24762460      {/* Inactive */
24772461      } break;
24782462   case 1:
24792463      {/* b6 = 1 ? : Read from selected PSG register and make the register data available to PPI Port A */
2480         state->m_ppi_port_inputs[amstrad_ppi_PortA] = ay8910_r(ay8910, space, 0);
2464         m_ppi_port_inputs[amstrad_ppi_PortA] = ay8910_r(m_ay, space, 0);
24812465      }
24822466      break;
24832467   case 2:
24842468      {/* b7 = 1 ? : Write to selected PSG register and write data to PPI Port A */
2485         ay8910_data_w(ay8910, space, 0, state->m_ppi_port_outputs[amstrad_ppi_PortA]);
2469         ay8910_data_w(m_ay, space, 0, m_ppi_port_outputs[amstrad_ppi_PortA]);
24862470      }
24872471      break;
24882472   case 3:
24892473      {/* b6 and b7 = 1 ? : The register will now be selected and the user can read from or write to it.  The register will remain selected until another is chosen.*/
2490         ay8910_address_w(ay8910, space, 0, state->m_ppi_port_outputs[amstrad_ppi_PortA]);
2491         state->m_prev_reg = state->m_ppi_port_outputs[amstrad_ppi_PortA];
2474         ay8910_address_w(m_ay, space, 0, m_ppi_port_outputs[amstrad_ppi_PortA]);
2475         m_prev_reg = m_ppi_port_outputs[amstrad_ppi_PortA];
24922476      }
24932477      break;
24942478   default:
r20956r20957
25012485/* Read/Write 8255 PPI port A (connected to AY-3-8912 databus) */
25022486READ8_MEMBER(amstrad_state::amstrad_ppi_porta_r)
25032487{
2504   update_psg(machine());
2488   update_psg();
25052489   return m_ppi_port_inputs[amstrad_ppi_PortA];
25062490}
25072491
r20956r20957
25092493WRITE8_MEMBER(amstrad_state::amstrad_ppi_porta_w)
25102494{
25112495   m_ppi_port_outputs[amstrad_ppi_PortA] = data;
2512   update_psg(machine());
2496   update_psg();
25132497}
25142498
25152499
r20956r20957
25532537/* Set b6 with Parallel/Printer port ready */
25542538   if(m_system_type != SYSTEM_GX4000)
25552539   {
2556      centronics_device *printer = m_centronics;
2557      data |= printer->busy_r() << 6;
2540      data |= m_centronics->busy_r() << 6;
25582541   }
25592542/* Set b4-b1 50Hz/60Hz state and manufacturer name defined by links on PCB */
25602543   data |= (m_ppi_port_inputs[amstrad_ppi_PortB] & 0x1e);
r20956r20957
26092592   m_aleste_rtc_function = data & 0x07;
26102593
26112594   /* Perform PSG function */
2612   update_psg(machine());
2595   update_psg();
26132596
26142597   /* b5 Cassette Write data */
26152598   if(m_system_type != SYSTEM_GX4000)
r20956r20957
26442627READ8_MEMBER(amstrad_state::amstrad_psg_porta_read)
26452628{
26462629   /* Read CPC Keyboard
2647   If keyboard matrix line 11-14 are selected, the byte is always &ff.
2630   If keyboard matrix line 11-15 are selected, the byte is always &ff.
26482631   After testing on a real CPC, it is found that these never change, they always return &FF. */
26492632
2650   static const char *const keynames[] = {
2651      "keyboard_row_0", "keyboard_row_1", "keyboard_row_2", "keyboard_row_3", "keyboard_row_4",
2652      "keyboard_row_5", "keyboard_row_6", "keyboard_row_7", "keyboard_row_8", "keyboard_row_9",
2653      "keyboard_row_10"
2633   ioport_port *keyrow[] = {
2634      m_io_keyboard_row_0, m_io_keyboard_row_1, m_io_keyboard_row_2, m_io_keyboard_row_3, m_io_keyboard_row_4,
2635      m_io_keyboard_row_5, m_io_keyboard_row_6, m_io_keyboard_row_7, m_io_keyboard_row_8, m_io_keyboard_row_9,
2636      m_io_keyboard_row_10
26542637   };
26552638
26562639   if ( ( m_ppi_port_outputs[amstrad_ppi_PortC] & 0x0F ) > 10)
r20956r20957
26622645      if(m_aleste_mode == 0x08 && ( m_ppi_port_outputs[amstrad_ppi_PortC] & 0x0F ) == 10)
26632646         return 0xff;
26642647
2665      return machine().root_device().ioport(keynames[m_ppi_port_outputs[amstrad_ppi_PortC] & 0x0F])->read_safe(0) & 0xFF;
2648      if (keyrow[m_ppi_port_outputs[amstrad_ppi_PortC] & 0x0F])
2649      {
2650         return keyrow[m_ppi_port_outputs[amstrad_ppi_PortC] & 0x0F]->read_safe(0) & 0xFF;
2651      }
2652      return 0xFF;
26662653   }
26672654}
26682655
r20956r20957
26792666      m_asic.ram[0x2c0f] &= ~0x80;  // not a raster interrupt, so this bit is reset
26802667      return (m_asic.ram[0x2805] & 0xf8) | m_plus_irq_cause;
26812668   }
2682   machine().device("maincpu")->execute().set_input_line(0, CLEAR_LINE);
2669   m_maincpu->set_input_line(0, CLEAR_LINE);
26832670   m_gate_array.hsync_counter &= 0x1F;
26842671   if ( m_asic.enabled )
26852672   {
r20956r20957
28162803      8,  0,  0,  0,  8,  0,  0,  0,  8,  0,  0,  0,  8,  0,  0,  0
28172804};
28182805
2819static void amstrad_common_init(running_machine &machine)
2806void amstrad_state::amstrad_common_init()
28202807{
2821   amstrad_state *state = machine.driver_data<amstrad_state>();
2822   address_space &space = state->m_maincpu->space(AS_PROGRAM);
2808   address_space &space = m_maincpu->space(AS_PROGRAM);
28232809   device_t* romexp;
28242810   rom_image_device* romimage;
28252811   char str[20];
28262812   int x;
28272813
2828   state->m_aleste_mode = 0;
2814   m_aleste_mode = 0;
28292815
2830   state->m_gate_array.mrer = 0;
2831   state->m_gate_array.vsync = 0;
2832   state->m_gate_array.hsync = 0;
2833   state->m_GateArray_RamConfiguration = 0;
2834   state->m_gate_array.hsync_counter = 2;
2816   m_gate_array.mrer = 0;
2817   m_gate_array.vsync = 0;
2818   m_gate_array.hsync = 0;
2819   m_GateArray_RamConfiguration = 0;
2820   m_gate_array.hsync_counter = 2;
28352821
28362822   space.install_read_bank(0x0000, 0x1fff, "bank1");
28372823   space.install_read_bank(0x2000, 0x3fff, "bank2");
r20956r20957
28582844   space.install_write_bank(0xe000, 0xffff, "bank16");
28592845
28602846   /* Set up ROMs, if we have an expansion device connected */
2861   romexp = get_expansion_device(machine,"rom");
2847   romexp = get_expansion_device(machine(),"rom");
28622848   if(romexp)
28632849   {
28642850      for(x=0;x<6;x++)
r20956r20957
28672853         romimage = romexp->subdevice<rom_image_device>(str);
28682854         if(romimage->base() != NULL)
28692855         {
2870            state->m_Amstrad_ROM_Table[x+1] = romimage->base();
2856            m_Amstrad_ROM_Table[x+1] = romimage->base();
28712857         }
28722858      }
28732859   }
28742860
2875   state->m_maincpu->reset();
2876   if ( state->m_system_type == SYSTEM_CPC || state->m_system_type == SYSTEM_ALESTE )
2877      state->m_maincpu->set_input_line_vector(0, 0xff);
2861   m_maincpu->reset();
2862   if ( m_system_type == SYSTEM_CPC || m_system_type == SYSTEM_ALESTE )
2863      m_maincpu->set_input_line_vector(0, 0xff);
28782864   else
2879      state->m_maincpu->set_input_line_vector(0, 0x00);
2865      m_maincpu->set_input_line_vector(0, 0x00);
28802866
28812867   /* The opcode timing in the Amstrad is different to the opcode
28822868   timing in the core for the Z80 CPU.
r20956r20957
28882874
28892875   /* Using the cool code Juergen has provided, I will override
28902876   the timing tables with the values for the amstrad */
2891   z80_set_cycle_tables(state->m_maincpu,
2877   z80_set_cycle_tables(m_maincpu,
28922878      (const UINT8*)amstrad_cycle_table_op,
28932879      (const UINT8*)amstrad_cycle_table_cb,
28942880      (const UINT8*)amstrad_cycle_table_ed,
r20956r20957
28972883      (const UINT8*)amstrad_cycle_table_ex);
28982884
28992885   /* Juergen is a cool dude! */
2900   state->m_maincpu->set_irq_acknowledge_callback(device_irq_acknowledge_delegate(FUNC(amstrad_state::amstrad_cpu_acknowledge_int),state));
2886   m_maincpu->set_irq_acknowledge_callback(device_irq_acknowledge_delegate(FUNC(amstrad_state::amstrad_cpu_acknowledge_int),this));
29012887}
29022888
29032889TIMER_CALLBACK_MEMBER(amstrad_state::cb_set_resolution)
29042890{
2905//  screen_device *screen = downcast<screen_device *>(m_screen);
29062891   rectangle visarea;
29072892   attoseconds_t refresh;
29082893   int height;
29092894
2910   if ( machine().root_device().ioport( "solder_links" )->read() & 0x10 )
2895   if ( m_io_solder_links->read() & 0x10 )
29112896   {
29122897      /* PAL */
29132898      visarea.set(0, 64 + 640 + 64 - 1, 34, 34 + 15 + 242 + 15 - 1);
r20956r20957
29332918MACHINE_RESET_MEMBER(amstrad_state,amstrad)
29342919{
29352920   int i;
2936   UINT8 *rom = memregion("maincpu")->base();
2921   UINT8 *rom = m_region_maincpu->base();
29372922
29382923   for (i=0; i<256; i++)
29392924   {
r20956r20957
29412926   }
29422927
29432928   m_Amstrad_ROM_Table[7] = &rom[0x018000];
2944   amstrad_common_init(machine());
2945   amstrad_reset_machine(machine());
2929   amstrad_common_init();
2930   amstrad_reset_machine();
29462931//  amstrad_init_palette(machine());
29472932
29482933   m_gate_array.de = 0;
r20956r20957
29562941
29572942MACHINE_START_MEMBER(amstrad_state,plus)
29582943{
2959   m_asic.ram = memregion("user1")->base();  // 16kB RAM for ASIC, memory-mapped registers.
2944   m_asic.ram = m_region_user1->base();  // 16kB RAM for ASIC, memory-mapped registers.
29602945   m_system_type = SYSTEM_PLUS;
29612946}
29622947
r20956r20957
29652950{
29662951   address_space &space = m_maincpu->space(AS_PROGRAM);
29672952   int i;
2968   UINT8 *rom = memregion("maincpu")->base();
2953   UINT8 *rom = m_region_maincpu->base();
29692954
29702955   for (i=0; i<128; i++)  // fill ROM table
29712956   {
r20956r20957
29902975   m_asic.dma_clear = 1;  // by default, DMA interrupts must be cleared by writing to the DSCR (&6c0f)
29912976   m_plus_irq_cause = 6;
29922977
2993   amstrad_common_init(machine());
2994   amstrad_reset_machine(machine());
2978   amstrad_common_init();
2979   amstrad_reset_machine();
29952980   m_asic.ram[0x2805] = 0x01;  // interrupt vector is undefined at startup, except that bit 0 is always 1.
2996   AmstradCPC_GA_SetRamConfiguration(machine());
2997   amstrad_GateArray_write(machine(), 0x081); // Epyx World of Sports requires upper ROM to be enabled by default
2981   AmstradCPC_GA_SetRamConfiguration();
2982   amstrad_GateArray_write(0x081); // Epyx World of Sports requires upper ROM to be enabled by default
29982983
29992984   space.install_read_handler(0x4000, 0x5fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_4000_r),this));
30002985   space.install_read_handler(0x6000, 0x7fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_6000_r),this));
r20956r20957
30072992
30082993MACHINE_START_MEMBER(amstrad_state,gx4000)
30092994{
3010   m_asic.ram = memregion("user1")->base();  // 16kB RAM for ASIC, memory-mapped registers.
2995   m_asic.ram = m_region_user1->base();  // 16kB RAM for ASIC, memory-mapped registers.
30112996   m_system_type = SYSTEM_GX4000;
30122997}
30132998
r20956r20957
30153000{
30163001   address_space &space = m_maincpu->space(AS_PROGRAM);
30173002   int i;
3018   UINT8 *rom = memregion("maincpu")->base();
3003   UINT8 *rom = m_region_maincpu->base();
30193004
30203005   for (i=0; i<128; i++)  // fill ROM table
30213006   {
r20956r20957
30403025   m_asic.dma_clear = 1;  // by default, DMA interrupts must be cleared by writing to the DSCR (&6c0f)
30413026   m_plus_irq_cause = 6;
30423027
3043   amstrad_common_init(machine());
3044   amstrad_reset_machine(machine());
3028   amstrad_common_init();
3029   amstrad_reset_machine();
30453030   m_asic.ram[0x2805] = 0x01;  // interrupt vector is undefined at startup, except that bit 0 is always 1.
3046   AmstradCPC_GA_SetRamConfiguration(machine());
3047   amstrad_GateArray_write(machine(), 0x081); // Epyx World of Sports requires upper ROM to be enabled by default
3031   AmstradCPC_GA_SetRamConfiguration();
3032   amstrad_GateArray_write(0x081); // Epyx World of Sports requires upper ROM to be enabled by default
30483033   //  multiface_init();
30493034   space.install_read_handler(0x4000, 0x5fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_4000_r),this));
30503035   space.install_read_handler(0x6000, 0x7fff, read8_delegate(FUNC(amstrad_state::amstrad_plus_asic_6000_r),this));
r20956r20957
30633048MACHINE_RESET_MEMBER(amstrad_state,kccomp)
30643049{
30653050   int i;
3066   UINT8 *rom = memregion("maincpu")->base();
3051   UINT8 *rom = m_region_maincpu->base();
30673052
30683053   for (i=0; i<256; i++)
30693054   {
30703055      m_Amstrad_ROM_Table[i] = &rom[0x014000];
30713056   }
30723057
3073   amstrad_common_init(machine());
3074   kccomp_reset_machine(machine());
3058   amstrad_common_init();
3059   kccomp_reset_machine();
30753060
30763061   /* bit 1 = /TEST. When 0, KC compact will enter data transfer
30773062   sequence, where another system using the expansion port signals
r20956r20957
30913076MACHINE_RESET_MEMBER(amstrad_state,aleste)
30923077{
30933078   int i;
3094   UINT8 *rom = memregion("maincpu")->base();
3079   UINT8 *rom = m_region_maincpu->base();
30953080
30963081   for (i=0; i<256; i++)
30973082   {
r20956r20957
31003085
31013086   m_Amstrad_ROM_Table[3] = &rom[0x01c000];  // MSX-DOS / BIOS
31023087   m_Amstrad_ROM_Table[7] = &rom[0x018000];  // AMSDOS
3103   amstrad_common_init(machine());
3104   amstrad_reset_machine(machine());
3088   amstrad_common_init();
3089   amstrad_reset_machine();
31053090
31063091   machine().scheduler().timer_set( attotime::zero, timer_expired_delegate(FUNC(amstrad_state::cb_set_resolution),this));
31073092}
r20956r20957
31293114      return IMAGE_INIT_FAIL;
31303115   }
31313116
3132   amstrad_handle_snapshot(image.device().machine(), snapshot);
3117   image.device().machine().driver_data<amstrad_state>()->amstrad_handle_snapshot(snapshot);
31333118   free(snapshot);
31343119   return IMAGE_INIT_PASS;
31353120}
r20956r20957
31523137   int chunksize;                // chunk length, calcaulated from the above
31533138   int ramblock;                 // 16k RAM block chunk is to be loaded in to
31543139   unsigned int bytes_to_read;   // total bytes to read, as mame_feof doesn't react to EOF without trying to go past it.
3155   unsigned char* mem = image.device().machine().root_device().memregion("maincpu")->base();
3140   unsigned char* mem = m_region_maincpu->base();
31563141
31573142   if (image.software_entry() == NULL)
31583143   {
31593144      size = image.length();
3160      temp_copy = auto_alloc_array(image.device().machine(), UINT8, size);
3145      temp_copy = auto_alloc_array(machine(), UINT8, size);
31613146      if (image.fread(temp_copy, size) != size)
31623147      {
31633148         logerror("IMG: failed to read from cart image\n");
3164         auto_free(image.device().machine(), temp_copy);
3149         auto_free(machine(), temp_copy);
31653150         return IMAGE_INIT_FAIL;
31663151      }
31673152   }
31683153   else
31693154   {
31703155      size= image.get_software_region_length("rom");
3171      temp_copy = auto_alloc_array(image.device().machine(), UINT8, size);
3156      temp_copy = auto_alloc_array(machine(), UINT8, size);
31723157      memcpy(temp_copy, image.get_software_region("rom"), size);
31733158   }
31743159
r20956r20957
31903175         if ((size - offset) < 0x4000)
31913176         {
31923177            logerror("BIN: block %i loaded is smaller than 16kB in size\n", offset / 0x4000);
3193            auto_free(image.device().machine(), temp_copy);
3178            auto_free(machine(), temp_copy);
31943179            return IMAGE_INIT_FAIL;
31953180         }
31963181         offset += 0x4000;
r20956r20957
32023187      if (strncmp((char*)(header + 8), "AMS!", 4) != 0)
32033188      {
32043189         logerror("CPR: not an Amstrad CPC cartridge image\n");
3205         auto_free(image.device().machine(), temp_copy);
3190         auto_free(machine(), temp_copy);
32063191         return IMAGE_INIT_FAIL;
32073192      }
32083193
r20956r20957
32603245   else    // CPR carts in our softlist
32613246   {
32623247      logerror("Gamelist cart in RIFF format\n");
3263      auto_free(image.device().machine(), temp_copy);
3248      auto_free(machine(), temp_copy);
32643249      return IMAGE_INIT_FAIL;
32653250   }
32663251
3267   auto_free(image.device().machine(), temp_copy);
3252   auto_free(machine(), temp_copy);
32683253   return IMAGE_INIT_PASS;
32693254}
trunk/src/mess/includes/amstrad.h
r20956r20957
9393{
9494public:
9595   amstrad_state(const machine_config &mconfig, device_type type, const char *tag)
96      : driver_device(mconfig, type, tag),
97         m_maincpu(*this, "maincpu"),
98         m_ay(*this, "ay"),
99         m_fdc(*this, "upd765"),
100         m_crtc(*this, "mc6845"),
101         m_screen(*this, "screen"),
102         m_ppi(*this, "ppi8255"),
103         m_centronics(*this, "centronics"),
104         m_cassette(*this, CASSETTE_TAG),
105         m_ram(*this, RAM_TAG),
106         m_exp(*this, "exp"),
107         m_rtc(*this, "rtc")
108      { }
96      : driver_device(mconfig, type, tag)
97      , m_maincpu(*this, "maincpu")
98      , m_ay(*this, "ay")
99      , m_fdc(*this, "upd765")
100      , m_crtc(*this, "mc6845")
101      , m_screen(*this, "screen")
102      , m_ppi(*this, "ppi8255")
103      , m_centronics(*this, "centronics")
104      , m_cassette(*this, CASSETTE_TAG)
105      , m_ram(*this, RAM_TAG)
106      , m_exp(*this, "exp")
107      , m_rtc(*this, "rtc")
108      , m_region_maincpu(*this, "maincpu")
109      , m_region_user1(*this, "user1")
110      , m_bank1(*this, "bank1")
111      , m_bank2(*this, "bank2")
112      , m_bank3(*this, "bank3")
113      , m_bank4(*this, "bank4")
114      , m_bank5(*this, "bank5")
115      , m_bank6(*this, "bank6")
116      , m_bank7(*this, "bank7")
117      , m_bank8(*this, "bank8")
118      , m_bank9(*this, "bank9")
119      , m_bank10(*this, "bank10")
120      , m_bank11(*this, "bank11")
121      , m_bank12(*this, "bank12")
122      , m_bank13(*this, "bank13")
123      , m_bank14(*this, "bank14")
124      , m_bank15(*this, "bank15")
125      , m_bank16(*this, "bank16")
126      , m_io_keyboard_row_0(*this, "keyboard_row_0")
127      , m_io_keyboard_row_1(*this, "keyboard_row_1")
128      , m_io_keyboard_row_2(*this, "keyboard_row_2")
129      , m_io_keyboard_row_3(*this, "keyboard_row_3")
130      , m_io_keyboard_row_4(*this, "keyboard_row_4")
131      , m_io_keyboard_row_5(*this, "keyboard_row_5")
132      , m_io_keyboard_row_6(*this, "keyboard_row_6")
133      , m_io_keyboard_row_7(*this, "keyboard_row_7")
134      , m_io_keyboard_row_8(*this, "keyboard_row_8")
135      , m_io_keyboard_row_9(*this, "keyboard_row_9")
136      , m_io_keyboard_row_10(*this, "keyboard_row_10")
137      , m_io_solder_links(*this, "solder_links")
138      , m_io_green_display(*this, "green_display")
139      , m_io_analog1(*this, "analog1")
140      , m_io_analog2(*this, "analog2")
141      , m_io_analog3(*this, "analog3")
142      , m_io_analog4(*this, "analog4")
143   { }
109144
110145   required_device<cpu_device> m_maincpu;
111146   required_device<ay8910_device> m_ay;
r20956r20957
193228   IRQ_CALLBACK_MEMBER(amstrad_cpu_acknowledge_int);
194229
195230   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( amstrad_plus_cartridge );
231
232   void amstrad_handle_snapshot(unsigned char *pSnapshot);
233   void amstrad_rethinkMemory();
234
235protected:
236   required_memory_region m_region_maincpu;
237   optional_memory_region m_region_user1;
238   required_memory_bank m_bank1;
239   required_memory_bank m_bank2;
240   required_memory_bank m_bank3;
241   required_memory_bank m_bank4;
242   required_memory_bank m_bank5;
243   required_memory_bank m_bank6;
244   required_memory_bank m_bank7;
245   required_memory_bank m_bank8;
246   required_memory_bank m_bank9;
247   required_memory_bank m_bank10;
248   required_memory_bank m_bank11;
249   required_memory_bank m_bank12;
250   required_memory_bank m_bank13;
251   required_memory_bank m_bank14;
252   required_memory_bank m_bank15;
253   required_memory_bank m_bank16;
254   required_ioport m_io_keyboard_row_0;
255   required_ioport m_io_keyboard_row_1;
256   required_ioport m_io_keyboard_row_2;
257   required_ioport m_io_keyboard_row_3;
258   required_ioport m_io_keyboard_row_4;
259   required_ioport m_io_keyboard_row_5;
260   required_ioport m_io_keyboard_row_6;
261   required_ioport m_io_keyboard_row_7;
262   required_ioport m_io_keyboard_row_8;
263   required_ioport m_io_keyboard_row_9;
264   optional_ioport m_io_keyboard_row_10;
265   required_ioport m_io_solder_links;
266   required_ioport m_io_green_display;
267   optional_ioport m_io_analog1;
268   optional_ioport m_io_analog2;
269   optional_ioport m_io_analog3;
270   optional_ioport m_io_analog4;
271
272   void amstrad_init_lookups();
273   void amstrad_vh_update_mode();
274   void amstrad_plus_dma_parse(int channel);
275   void amstrad_plus_handle_dma();
276   void amstrad_vh_update_colour(int PenIndex, UINT16 hw_colour_index);
277   void aleste_vh_update_colour(int PenIndex, UINT16 hw_colour_index);
278   void amstrad_gate_array_get_video_data();
279   void amstrad_update_video();
280   void amstrad_plus_gate_array_get_video_data();
281   void amstrad_plus_update_video();
282   void amstrad_plus_update_video_sprites();
283   void amstrad_setLowerRom();
284   void amstrad_setUpperRom();
285   void AmstradCPC_GA_SetRamConfiguration();
286   void AmstradCPC_PALWrite(int data);
287   void amstrad_GateArray_write(UINT8 dataToGateArray);
288   void amstrad_reset_machine();
289   void kccomp_reset_machine();
290   void update_psg();
291   void amstrad_common_init();
196292};
197293
198294
trunk/src/mess/drivers/amstrad.c
r20956r20957
293293/* Steph 2000-10-27 I remapped the 'Machine Name' Dip Switches (easier to understand) */
294294INPUT_CHANGED_MEMBER(amstrad_state::cpc_monitor_changed)
295295{
296   if ( (machine().root_device().ioport("green_display")->read()) & 0x01 )
296   if ( (m_io_green_display->read()) & 0x01 )
297297   {
298298      PALETTE_INIT_CALL_MEMBER( amstrad_cpc_green );
299299   }

Previous 199869 Revisions Next


© 1997-2024 The MAME Team