Previous 15994 Revisions Next

r4576 Monday 27th April, 2009 at 18:00:28 UTC by Fabio Priuli
Again, number-to-tag conversions in CPU calls. Plus a few readability tweaks and a typo fixed from 0.128u7.
[src/mess/drivers]genesis.c gmaster.c intv.c ip20.c ip22.c jaguar.c jupiter.c
[src/mess/machine]galaxy.c gamecom.c gb.c genesis.c hp48.c intv.c irisha.c jupiter.c
[src/mess/video]galaxy.c gb.c homelab.c hp48.c irisha.c

src/mess/video/homelab.c
r4575r4576
1919{
2020   int x,y,j,b;
2121   UINT8 *gfx = memory_region(screen->machine, "gfx1");
22   const address_space *space = cpu_get_address_space(screen->machine->cpu[0], ADDRESS_SPACE_PROGRAM);
22   const address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
2323
2424   for(y = 0; y < 25; y++ )
2525   {
2626      for(x = 0; x < 40; x++ )
2727      {
28         int code = memory_read_byte(space,0xc000+ x + y*40);     
28         int code = memory_read_byte(space, 0xc000 + x + y*40);     
2929         for(j = 0; j < 8; j++ )
3030         {
3131            for(b = 0; b < 8; b++ )
3232           {
33              *BITMAP_ADDR16(bitmap, y*8+j, x*8+b ) = (gfx[code+j*256] >> (7-b)) & 1;
33              *BITMAP_ADDR16(bitmap, y * 8 + j, x * 8 + b ) = (gfx[code + j * 256] >> (7 - b)) & 1;
3434           }
3535         }
3636      }
r4575r4576
4242{
4343   int x,y,j,b;
4444   UINT8 *gfx = memory_region(screen->machine, "gfx1");
45   const address_space *space = cpu_get_address_space(screen->machine->cpu[0], ADDRESS_SPACE_PROGRAM);
45   const address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
4646
4747   for(y = 0; y < 25; y++ )
4848   {
4949      for(x = 0; x < 80; x++ )
5050      {
51         int code = memory_read_byte(space, 0xf000+ x + y*80);     
51         int code = memory_read_byte(space, 0xf000 + x + y * 80);     
5252         for(j = 0; j < 8; j++ )
5353         {
5454            for(b = 0; b < 8; b++ )
5555           {
56              *BITMAP_ADDR16(bitmap, y*8+j, x*8+b ) = (gfx[code+j*256] >> (7-b)) & 1;
56              *BITMAP_ADDR16(bitmap, y * 8 + j, x * 8 + b ) = (gfx[code + j * 256] >> (7 - b)) & 1;
5757           }
5858         }
5959      }
src/mess/video/hp48.c
r4575r4576
137137
138138VIDEO_UPDATE ( hp48 )
139139{
140   const address_space *space = cpu_get_address_space( cputag_get_cpu(screen->machine, "maincpu"), ADDRESS_SPACE_PROGRAM );
140   const address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
141141   int x, y, xp, i, addr;
142142   int display       = HP48_IO_4(0) >> 3;           /* 1=on, 0=off */
143143   int left_margin   = HP48_IO_4(0) & 7;            /* 0..7 pixels for main bitmap */
src/mess/video/gb.c
r4575r4576
139139};
140140
141141/* Initialise the palettes */
142PALETTE_INIT( gb ) {
142PALETTE_INIT( gb )
143{
143144   int ii;
144   for( ii = 0; ii < 4; ii++) {
145   for( ii = 0; ii < 4; ii++)
146   {
145147      palette_set_color_rgb(machine, ii, palette[ii*3+0], palette[ii*3+1], palette[ii*3+2]);
146148   }
147149}
148150
149PALETTE_INIT( gbp ) {
151PALETTE_INIT( gbp )
152{
150153   int ii;
151   for( ii = 0; ii < 4; ii++) {
154   for( ii = 0; ii < 4; ii++)
155   {
152156      palette_set_color_rgb(machine, ii, palette[(ii + 4)*3+0], palette[(ii + 4)*3+1], palette[(ii + 4)*3+2]);
153157   }
154158}
155159
156PALETTE_INIT( sgb ) {
160PALETTE_INIT( sgb )
161{
157162   int ii, r, g, b;
158163
159   for( ii = 0; ii < 32768; ii++ ) {
164   for( ii = 0; ii < 32768; ii++ )
165   {
160166      r = (ii & 0x1F) << 3;
161167      g = ((ii >> 5) & 0x1F) << 3;
162168      b = ((ii >> 10) & 0x1F) << 3;
r4575r4576
173179      sgb_pal[ii] = 0;
174180}
175181
176PALETTE_INIT( gbc ) {
182PALETTE_INIT( gbc )
183{
177184   int ii, r, g, b;
178185
179   for( ii = 0; ii < 32768; ii++ ) {
186   for( ii = 0; ii < 32768; ii++ )
187   {
180188      r = (ii & 0x1F) << 3;
181189      g = ((ii >> 5) & 0x1F) << 3;
182190      b = ((ii >> 10) & 0x1F) << 3;
r4575r4576
191199      cgb_spal[ii] = 0;
192200}
193201
194PALETTE_INIT( megaduck ) {
202PALETTE_INIT( megaduck )
203{
195204   int ii;
196   for( ii = 0; ii < 4; ii++) {
205   for( ii = 0; ii < 4; ii++)
206   {
197207      palette_set_color_rgb(machine, ii, palette_megaduck[ii*3+0], palette_megaduck[ii*3+1], palette_megaduck[ii*3+2]);
198208   }
199209}
r4575r4576
208218  Select which sprites should be drawn for the current scanline and return the
209219  number of sprites selected.
210220 */
211static void gb_select_sprites( void ) {
221static void gb_select_sprites( void )
222{
212223   int   i, /*yindex,*/ line, height;
213224   UINT8   *oam = gb_oam + 39 * 4;
214225
215226   gb_lcd.sprCount = 0;
216227
217228   /* If video hardware is enabled and sprites are enabled */
218   if ( ( LCDCONT & 0x80 ) && ( LCDCONT & 0x02 ) ) {
229   if ( ( LCDCONT & 0x80 ) && ( LCDCONT & 0x02 ) )
230   {
219231      /* Check for stretched sprites */
220      if ( LCDCONT & 0x04 ) {
232      if ( LCDCONT & 0x04 )
233      {
221234         height = 16;
222      } else {
235      }
236      else
237      {
223238         height = 8;
224239      }
225240
226241      //yindex = gb_lcd.current_line;
227242      line = gb_lcd.current_line + 16;
228243
229      for( i = 39; i >= 0; i-- ) {
230         if ( line >= oam[0] && line < ( oam[0] + height ) && oam[1] && oam[1] < 168 ) {
244      for( i = 39; i >= 0; i-- )
245      {
246         if ( line >= oam[0] && line < ( oam[0] + height ) && oam[1] && oam[1] < 168 )
247         {
231248            /* We limit the sprite count to max 10 here;
232249               proper games should not exceed this... */
233            if ( gb_lcd.sprCount < 10 ) {
250            if ( gb_lcd.sprCount < 10 )
251            {
234252               gb_lcd.sprite[gb_lcd.sprCount] = i;
235253               gb_lcd.sprCount++;
236254            }
r4575r4576
327345   }
328346}
329347
330static void gb_update_scanline( running_machine *machine ) {
348static void gb_update_scanline( running_machine *machine )
349{
331350   bitmap_t *bitmap = tmpbitmap;
332351
333352   profiler_mark(PROFILER_VIDEO);
334353
335354   /* Make sure we're in mode 3 */
336   if ( ( LCDSTAT & 0x03 ) == 0x03 ) {
355   if ( ( LCDSTAT & 0x03 ) == 0x03 )
356   {
337357      /* Calculate number of pixels to render based on time still left on the timer */
338      UINT32 cycles_to_go = cpu_attotime_to_clocks(machine->cpu[0], timer_timeleft( gb_lcd.lcd_timer ) );
358      UINT32 cycles_to_go = cputag_attotime_to_clocks(machine, "maincpu", timer_timeleft( gb_lcd.lcd_timer ) );
339359      int l = 0;
340360
341      if ( gb_lcd.start_x < 0 ) {
361      if ( gb_lcd.start_x < 0 )
362      {
342363         /* Window is enabled if the hardware says so AND the current scanline is
343364          * within the window AND the window X coordinate is <=166 */
344365         gb_lcd.layer[1].enabled = ( ( LCDCONT & 0x20 ) && ( gb_lcd.current_line >= WNDPOSY ) && ( WNDPOSX <= 166 ) ) ? 1 : 0;
r4575r4576
347368          * AND window's X position is >=7 ) ) */
348369         gb_lcd.layer[0].enabled = ( ( LCDCONT & 0x01 ) && ( ( ! gb_lcd.layer[1].enabled ) || ( gb_lcd.layer[1].enabled && ( WNDPOSX >= 7 ) ) ) ) ? 1 : 0;
349370
350         if ( gb_lcd.layer[0].enabled ) {
371         if ( gb_lcd.layer[0].enabled )
372         {
351373            gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF;
352374            gb_lcd.layer[0].bg_map = gb_bgdtab;
353375            gb_lcd.layer[0].bg_tiles = gb_chrgen;
r4575r4576
357379            gb_lcd.layer[0].xend = 160;
358380         }
359381
360         if ( gb_lcd.layer[1].enabled ) {
382         if ( gb_lcd.layer[1].enabled )
383         {
361384            int xpos;
362385
363386            xpos = WNDPOSX - 7;             /* Window is offset by 7 pixels */
r4575r4576
376399         gb_lcd.start_x = 0;
377400      }
378401
379      if ( cycles_to_go < 160 ) {
402      if ( cycles_to_go < 160 )
403      {
380404         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
381405         /* Draw empty pixels when the background is disabled */
382         if ( ! ( LCDCONT & 0x01 ) ) {
406         if ( ! ( LCDCONT & 0x01 ) )
407         {
383408            rectangle r;
384409            r.min_y = r.max_y = gb_lcd.current_line;
385410            r.min_x = gb_lcd.start_x;
386411            r.max_x = gb_lcd.end_x - 1;
387412            bitmap_fill( bitmap, &r , gb_bpal[0]);
388413         }
389         while ( l < 2 ) {
414         while ( l < 2 )
415         {
390416            UINT8   xindex, *map, *tiles;
391417            UINT16   data;
392418            int   i, tile_index;
393419
394            if ( ! gb_lcd.layer[l].enabled ) {
420            if ( ! gb_lcd.layer[l].enabled )
421            {
395422               l++;
396423               continue;
397424            }
r4575r4576
409436            data = tiles[ tile_index ] | ( tiles[ tile_index+1 ] << 8 );
410437            data <<= gb_lcd.layer[l].xshift;
411438
412            while ( i > 0 ) {
413               while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) {
439            while ( i > 0 )
440            {
441               while ( ( gb_lcd.layer[l].xshift < 8 ) && i )
442               {
414443                  register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 );
415444                  gb_plot_pixel( bitmap, xindex, gb_lcd.current_line, gb_bpal[ colour ] );
416445                  bg_zbuf[ xindex ] = colour;
r4575r4576
419448                  gb_lcd.layer[l].xshift++;
420449                  i--;
421450               }
422               if ( gb_lcd.layer[l].xshift == 8 ) {
451               if ( gb_lcd.layer[l].xshift == 8 )
452               {
423453                  /* Take possible changes to SCROLLY into account */
424                  if ( l == 0 ) {
454                  if ( l == 0 )
455                  {
425456                     gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF;
426457                     map = gb_lcd.layer[l].bg_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 );
427458                     tiles = gb_lcd.layer[l].bg_tiles + ( ( gb_lcd.layer[l].bgline & 7 ) << 1 );
r4575r4576
435466            }
436467            l++;
437468         }
438         if ( gb_lcd.end_x == 160 && LCDCONT & 0x02 ) {
469         if ( gb_lcd.end_x == 160 && LCDCONT & 0x02 )
470         {
439471            gb_update_sprites();
440472         }
441473         gb_lcd.start_x = gb_lcd.end_x;
442474      }
443   } else {
444      if ( ! ( LCDCONT & 0x80 ) ) {
475   }
476   else
477   {
478      if ( ! ( LCDCONT & 0x80 ) )
479      {
445480         /* Draw an empty line when LCD is disabled */
446         if ( gb_lcd.previous_line != gb_lcd.current_line ) {
447            if ( gb_lcd.current_line < 144 ) {
481         if ( gb_lcd.previous_line != gb_lcd.current_line )
482         {
483            if ( gb_lcd.current_line < 144 )
484            {
448485               const device_config *screen = video_screen_first(machine->config);
449486               rectangle r = *video_screen_get_visible_area(screen);
450487               r.min_y = r.max_y = gb_lcd.current_line;
r4575r4576
555592   }
556593}
557594
558static void sgb_refresh_border(void) {
595static void sgb_refresh_border(void)
596{
559597   UINT16 data, data2;
560598   UINT16 yidx, xidx, xindex;
561599   UINT8 *map, *tiles, *tiles2;
r4575r4576
564602
565603   map = sgb_tile_map - 64;
566604
567   for( yidx = 0; yidx < 224; yidx++ ) {
605   for( yidx = 0; yidx < 224; yidx++ )
606   {
568607      xindex = 0;
569608      map += (yidx % 8) ? 0 : 64;
570      for( xidx = 0; xidx < 64; xidx+=2 ) {
609      for( xidx = 0; xidx < 64; xidx+=2 )
610      {
571611         if( map[xidx+1] & 0x80 ) /* Vertical flip */
572612            tiles = sgb_tile_data + ( ( 7 - ( yidx % 8 ) ) << 1 );
573613         else /* No vertical flip */
r4575r4576
579619            pal = 1;
580620         pal <<= 4;
581621
582         if( sgb_hack ) { /* A few games do weird stuff */
622         if( sgb_hack )
623         { /* A few games do weird stuff */
583624            UINT8 tileno = map[xidx];
584625            if( tileno >= 128 ) tileno = ((64 + tileno) % 128) + 128;
585626            else tileno = (64 + tileno) % 128;
586627            data = tiles[ tileno * 32 ] | ( tiles[ ( tileno * 32 ) + 1 ] << 8 );
587628            data2 = tiles2[ tileno * 32 ] | ( tiles2[ ( tileno * 32 ) + 1 ] << 8 );
588         } else {
629         }
630         else
631         {
589632            data = tiles[ map[xidx] * 32 ] | ( tiles[ (map[xidx] * 32 ) + 1 ] << 8 );
590633            data2 = tiles2[ map[xidx] * 32 ] | ( tiles2[ (map[xidx] * 32 ) + 1 ] << 8 );
591634         }
592635
593         for( i = 0; i < 8; i++ ) {
636         for( i = 0; i < 8; i++ )
637         {
594638            register UINT8 colour;
595            if( (map[xidx+1] & 0x40) ) { /* Horizontal flip */
639            if( (map[xidx+1] & 0x40) )   /* Horizontal flip */
640            {
596641               colour = ((data  & 0x0001) ? 1 : 0) | ((data  & 0x0100) ? 2 : 0) |
597642                   ((data2 & 0x0001) ? 4 : 0) | ((data2 & 0x0100) ? 8 : 0);
598643               data >>= 1;
599644               data2 >>= 1;
600            } else { /* No horizontal flip */
645            }
646            else   /* No horizontal flip */
647            {
601648               colour = ((data  & 0x0080) ? 1 : 0) | ((data  & 0x8000) ? 2 : 0) |
602649                   ((data2 & 0x0080) ? 4 : 0) | ((data2 & 0x8000) ? 8 : 0);
603650               data <<= 1;
r4575r4576
608655             * scanline, it can obscure the screen even when it shouldn't.
609656             */
610657            if( !((yidx >= SGB_YOFFSET && yidx < SGB_YOFFSET + 144) &&
611               (xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160)) ) {
658               (xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160)) )
659               {
612660               gb_plot_pixel(bitmap, xindex, yidx, sgb_pal[pal + colour]);
613661            }
614662            xindex++;
r4575r4576
617665   }
618666}
619667
620static void sgb_update_scanline( running_machine *machine ) {
668static void sgb_update_scanline( running_machine *machine )
669{
621670   bitmap_t *bitmap = tmpbitmap;
622671
623672   profiler_mark(PROFILER_VIDEO);
624673
625   if ( ( LCDSTAT & 0x03 ) == 0x03 ) {
674   if ( ( LCDSTAT & 0x03 ) == 0x03 )
675   {
626676      /* Calcuate number of pixels to render based on time still left on the timer */
627      UINT32 cycles_to_go = cpu_attotime_to_clocks(machine->cpu[0], timer_timeleft( gb_lcd.lcd_timer ) );
677      UINT32 cycles_to_go = cputag_attotime_to_clocks(machine, "maincpu", timer_timeleft( gb_lcd.lcd_timer ) );
628678      int l = 0;
629679
630      if ( gb_lcd.start_x < 0 ) {
680      if ( gb_lcd.start_x < 0 )
681      {
631682         /* Window is enabled if the hardware says so AND the current scanline is
632683          * within the window AND the window X coordinate is <=166 */
633684         gb_lcd.layer[1].enabled = ((LCDCONT & 0x20) && gb_lcd.current_line >= WNDPOSY && WNDPOSX <= 166) ? 1 : 0;
r4575r4576
636687          * AND window's X position is >=7 ) ) */
637688         gb_lcd.layer[0].enabled = ((LCDCONT & 0x01) && ((!gb_lcd.layer[1].enabled) || (gb_lcd.layer[1].enabled && WNDPOSX >= 7))) ? 1 : 0;
638689
639         if ( gb_lcd.layer[0].enabled ) {
690         if ( gb_lcd.layer[0].enabled )
691         {
640692            gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF;
641693            gb_lcd.layer[0].bg_map = gb_bgdtab;
642694            gb_lcd.layer[0].bg_tiles = gb_chrgen;
r4575r4576
646698            gb_lcd.layer[0].xend = 160;
647699         }
648700
649         if ( gb_lcd.layer[1].enabled ) {
701         if ( gb_lcd.layer[1].enabled )
702         {
650703            int xpos;
651704
652705            /* Window X position is offset by 7 so we'll need to adjust */
r4575r4576
666719         gb_lcd.start_x = 0;
667720      }
668721
669      if ( cycles_to_go == 0 ) {
722      if ( cycles_to_go == 0 )
723      {
670724
671725         /* Does this belong here? or should it be moved to the else block */
672726         /* Handle SGB mask */
673         switch( sgb_window_mask ) {
727         switch( sgb_window_mask )
728         {
674729         case 1: /* Freeze screen */
675730            return;
676731         case 2: /* Blank screen (black) */
r4575r4576
696751         }
697752
698753         /* Draw the "border" if we're on the first line */
699         if ( gb_lcd.current_line == 0 ) {
754         if ( gb_lcd.current_line == 0 )
755         {
700756            sgb_refresh_border();
701757         }
702758      }
703      if ( cycles_to_go < 160 ) {
759      if ( cycles_to_go < 160 )
760      {
704761         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
705762
706763         /* if background or screen disabled clear line */
707         if ( ! ( LCDCONT & 0x01 ) ) {
764         if ( ! ( LCDCONT & 0x01 ) )
765         {
708766            const device_config *screen = video_screen_first(machine->config);
709767            rectangle r = *video_screen_get_visible_area(screen);
710768            r.min_x = SGB_XOFFSET;
r4575r4576
712770            r.min_y = r.max_y = gb_lcd.current_line + SGB_YOFFSET;
713771            bitmap_fill( bitmap, &r , 0);
714772         }
715         while( l < 2 ) {
773         while( l < 2 )
774         {
716775            UINT8   xindex, sgb_palette, *map, *tiles;
717776            UINT16   data;
718777            int   i, tile_index;
719778
720            if ( ! gb_lcd.layer[l].enabled ) {
779            if ( ! gb_lcd.layer[l].enabled )
780            {
721781               l++;
722782               continue;
723783            }
r4575r4576
738798            /* Figure out which palette we're using */
739799            sgb_palette = sgb_pal_map[ ( gb_lcd.end_x - i ) >> 3 ][ gb_lcd.current_line >> 3 ] << 2;
740800
741            while( i > 0 ) {
742               while( ( gb_lcd.layer[l].xshift < 8 ) && i ) {
801            while( i > 0 )
802            {
803               while( ( gb_lcd.layer[l].xshift < 8 ) && i )
804               {
743805                  register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 );
744806                  gb_plot_pixel( bitmap, xindex + SGB_XOFFSET, gb_lcd.current_line + SGB_YOFFSET, sgb_pal[ sgb_palette + gb_bpal[colour]] );
745807                  bg_zbuf[xindex] = colour;
r4575r4576
748810                  gb_lcd.layer[l].xshift++;
749811                  i--;
750812               }
751               if ( gb_lcd.layer[l].xshift == 8 ) {
813               if ( gb_lcd.layer[l].xshift == 8 )
814               {
752815                  /* Take possible changes to SCROLLY into account */
753                  if ( l == 0 ) {
816                  if ( l == 0 )
817                  {
754818                     gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF;
755819                     map = gb_lcd.layer[l].bg_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 );
756820                     tiles = gb_lcd.layer[l].bg_tiles + ( ( gb_lcd.layer[l].bgline & 7 ) << 1 );
r4575r4576
765829            }
766830            l++;
767831         }
768         if ( ( gb_lcd.end_x == 160 ) && ( LCDCONT & 0x02 ) ) {
832         if ( ( gb_lcd.end_x == 160 ) && ( LCDCONT & 0x02 ) )
833         {
769834            sgb_update_sprites();
770835         }
771836         gb_lcd.start_x = gb_lcd.end_x;
772837      }
773   } else {
774      if ( ! ( LCDCONT * 0x80 ) ) {
838   }
839   else
840   {
841      if ( ! ( LCDCONT * 0x80 ) )
842      {
775843         /* if screen disabled clear line */
776         if ( gb_lcd.previous_line != gb_lcd.current_line ) {
844         if ( gb_lcd.previous_line != gb_lcd.current_line )
845         {
777846            /* Also refresh border here??? */
778            if ( gb_lcd.current_line < 144 ) {
847            if ( gb_lcd.current_line < 144 )
848            {
779849               const device_config *screen = video_screen_first(machine->config);
780850               rectangle r = *video_screen_get_visible_area(screen);
781851               r.min_x = SGB_XOFFSET;
r4575r4576
793863
794864/* --- Game Boy Color Specific --- */
795865
796INLINE void cgb_update_sprites ( running_machine *machine ) {
866INLINE void cgb_update_sprites ( running_machine *machine )
867{
797868   bitmap_t *bitmap = tmpbitmap;
798869   UINT8 height, tilemask, line, *oam;
799870   int i, xindex, yindex;
r4575r4576
888959   }
889960}
890961
891static void cgb_update_scanline ( running_machine *machine ) {
962static void cgb_update_scanline ( running_machine *machine )
963{
892964   bitmap_t *bitmap = tmpbitmap;
893965
894966   profiler_mark(PROFILER_VIDEO);
895967
896   if ( ( LCDSTAT & 0x03 ) == 0x03 ) {
968   if ( ( LCDSTAT & 0x03 ) == 0x03 )
969   {
897970      /* Calcuate number of pixels to render based on time still left on the timer */
898      UINT32 cycles_to_go = cpu_attotime_to_clocks(machine->cpu[0], timer_timeleft( gb_lcd.lcd_timer ) );
971      UINT32 cycles_to_go = cputag_attotime_to_clocks(machine, "maincpu", timer_timeleft( gb_lcd.lcd_timer ) );
899972      int l = 0;
900973
901      if ( gb_lcd.start_x < 0 ) {
974      if ( gb_lcd.start_x < 0 )
975      {
902976         /* Window is enabled if the hardware says so AND the current scanline is
903977          * within the window AND the window X coordinate is <=166 */
904978         gb_lcd.layer[1].enabled = ( ( LCDCONT & 0x20 ) && ( gb_lcd.current_line >= WNDPOSY ) && ( WNDPOSX <= 166 ) ) ? 1 : 0;
r4575r4576
907981          * AND window's X position is >=7 ) ) */
908982         gb_lcd.layer[0].enabled = ( ( LCDCONT & 0x01 ) && ( ( ! gb_lcd.layer[1].enabled ) || ( gb_lcd.layer[1].enabled && ( WNDPOSX >= 7 ) ) ) ) ? 1 : 0;
909983
910         if ( gb_lcd.layer[0].enabled ) {
984         if ( gb_lcd.layer[0].enabled )
985         {
911986            gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF;
912987            gb_lcd.layer[0].bg_map = gb_bgdtab;
913988            gb_lcd.layer[0].gbc_map = gbc_bgdtab;
r4575r4576
917992            gb_lcd.layer[0].xend = 160;
918993         }
919994
920         if ( gb_lcd.layer[1].enabled ) {
995         if ( gb_lcd.layer[1].enabled )
996         {
921997            int xpos;
922998
923999            /* Window X position is offset by 7 so we'll need to adust */
r4575r4576
9371013         gb_lcd.start_x = 0;
9381014      }
9391015
940      if ( cycles_to_go < 160 ) {
1016      if ( cycles_to_go < 160 )
1017      {
9411018         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
9421019         /* Draw empty line when the background is disabled */
943         if ( ! ( LCDCONT & 0x01 ) ) {
1020         if ( ! ( LCDCONT & 0x01 ) )
1021         {
9441022            const device_config *screen = video_screen_first(machine->config);
9451023            rectangle r = *video_screen_get_visible_area(screen);
9461024            r.min_y = r.max_y = gb_lcd.current_line;
r4575r4576
9481026            r.max_x = gb_lcd.end_x - 1;
9491027            bitmap_fill( bitmap, &r , ( gbc_mode == GBC_MODE_MONO ) ? 0 : 32767);
9501028         }
951         while ( l < 2 ) {
1029         while ( l < 2 )
1030         {
9521031            UINT8   xindex, *map, *tiles, *gbcmap;
9531032            UINT16   data;
9541033            int   i, tile_index;
9551034
956            if ( ! gb_lcd.layer[l].enabled ) {
1035            if ( ! gb_lcd.layer[l].enabled )
1036            {
9571037               l++;
9581038               continue;
9591039            }
r4575r4576
9621042            tiles = ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x08 ) ? gbc_chrgen : gb_chrgen;
9631043
9641044            /* Check for vertical flip */
965            if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 ) {
1045            if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 )
1046            {
9661047               tiles += ( ( 7 - ( gb_lcd.layer[l].bgline & 0x07 ) ) << 1 );
967            } else {
1048            }
1049            else
1050            {
9681051               tiles += ( ( gb_lcd.layer[l].bgline & 0x07 ) << 1 );
9691052            }
9701053            xindex = gb_lcd.start_x;
r4575r4576
9781061            tile_index = ( map[ gb_lcd.layer[l].xindex ] ^ gb_tile_no_mod ) * 16;
9791062            data = tiles[ tile_index ] | ( tiles[ tile_index + 1 ] << 8 );
9801063            /* Check for horinzontal flip */
981            if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 ) {
1064            if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 )
1065            {
9821066               data >>= gb_lcd.layer[l].xshift;
983            } else {
1067            }
1068            else
1069            {
9841070               data <<= gb_lcd.layer[l].xshift;
9851071            }
9861072
987            while ( i > 0 ) {
988               while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) {
1073            while ( i > 0 )
1074            {
1075               while ( ( gb_lcd.layer[l].xshift < 8 ) && i )
1076               {
9891077                  int colour;
9901078                  /* Check for horinzontal flip */
991                  if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 ) {
1079                  if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 )
1080                  {
9921081                     colour = ( ( data & 0x0100 ) ? 2 : 0 ) | ( ( data & 0x0001 ) ? 1 : 0 );
9931082                     data >>= 1;
994                  } else {
1083                  }
1084                  else
1085                  {
9951086                     colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 );
9961087                     data <<= 1;
9971088                  }
r4575r4576
10011092                  gb_lcd.layer[l].xshift++;
10021093                  i--;
10031094               }
1004               if ( gb_lcd.layer[l].xshift == 8 ) {
1095               if ( gb_lcd.layer[l].xshift == 8 )
1096               {
10051097                  /* Take possible changes to SCROLLY into account */
1006                  if ( l == 0 ) {
1098                  if ( l == 0 )
1099                  {
10071100                     gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF;
10081101                     map = gb_lcd.layer[l].bg_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 );
10091102                     gbcmap = gb_lcd.layer[l].gbc_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 );
r4575r4576
10141107                  tiles = ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x08 ) ? gbc_chrgen : gb_chrgen;
10151108
10161109                  /* Check for vertical flip */
1017                  if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 ) {
1110                  if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 )
1111                  {
10181112                     tiles += ( ( 7 - ( gb_lcd.layer[l].bgline & 0x07 ) ) << 1 );
1019                  } else {
1113                  }
1114                  else
1115                  {
10201116                     tiles += ( ( gb_lcd.layer[l].bgline & 0x07 ) << 1 );
10211117                  }
10221118                  tile_index = ( map[ gb_lcd.layer[l].xindex ] ^ gb_tile_no_mod ) * 16;
r4575r4576
10251121            }
10261122            l++;
10271123         }
1028         if ( gb_lcd.end_x == 160 && ( LCDCONT & 0x02 ) ) {
1124         if ( gb_lcd.end_x == 160 && ( LCDCONT & 0x02 ) )
1125         {
10291126            cgb_update_sprites( machine );
10301127         }
10311128         gb_lcd.start_x = gb_lcd.end_x;
10321129      }
1033   } else {
1034      if ( ! ( LCDCONT & 0x80 ) ) {
1130   }
1131   else
1132   {
1133      if ( ! ( LCDCONT & 0x80 ) )
1134      {
10351135         /* Draw an empty line when LCD is disabled */
1036         if ( gb_lcd.previous_line != gb_lcd.current_line ) {
1037            if ( gb_lcd.current_line < 144 ) {
1136         if ( gb_lcd.previous_line != gb_lcd.current_line )
1137         {
1138            if ( gb_lcd.current_line < 144 )
1139            {
10381140               const device_config *screen = video_screen_first(machine->config);
10391141               rectangle r = *video_screen_get_visible_area(screen);
10401142               r.min_y = r.max_y = gb_lcd.current_line;
r4575r4576
11571259
11581260static TIMER_CALLBACK( gb_video_init_vbl )
11591261{
1160   cpu_set_input_line( machine->cpu[0], VBL_INT, ASSERT_LINE );
1262   cputag_set_input_line( machine, "maincpu", VBL_INT, ASSERT_LINE );
11611263}
11621264
1163void gb_video_init( running_machine *machine, int mode ) {
1265void gb_video_init( running_machine *machine, int mode )
1266{
11641267   int   i;
11651268   int vram_size = 0x2000;
1166   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
1269   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
11671270
11681271   if (mode == GB_VIDEO_CGB) vram_size = 0x4000;
11691272
r4575r4576
11781281   gb_wndtab = gb_vram + 0x1C00;
11791282
11801283   gb_vid_regs[0x06] = 0xFF;
1181   for( i = 0x0c; i < _NR_GB_VID_REGS; i++ ) {
1284   for( i = 0x0c; i < _NR_GB_VID_REGS; i++ )
1285   {
11821286      gb_vid_regs[i] = 0xFF;
11831287   }
11841288
r4575r4576
11901294   WNDPOSX = WNDPOSY = 0x00;
11911295
11921296   /* Initialize palette arrays */
1193   for( i = 0; i < 4; i++ ) {
1297   for( i = 0; i < 4; i++ )
1298   {
11941299      gb_bpal[i] = gb_spal0[i] = gb_spal1[i] = i;
11951300   }
11961301
1197   switch( mode ) {
1302   switch( mode )
1303   {
11981304   case GB_VIDEO_DMG:
11991305      gb_lcd.lcd_timer = timer_alloc(machine,  gb_lcd_timer_proc , NULL);
1200      timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 456), 0);
1306      timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 456), 0);
12011307
12021308      /* set the scanline update function */
12031309      update_scanline = gb_update_scanline;
r4575r4576
12111317      /* set the scanline update function */
12121318      update_scanline = gb_update_scanline;
12131319      /* Initialize part of VRAM. This code must be deleted when we have added the bios dump */
1214      for( i = 1; i < 0x0D; i++ ) {
1320      for( i = 1; i < 0x0D; i++ )
1321      {
12151322         gb_vram[ 0x1903 + i ] = i;
12161323         gb_vram[ 0x1923 + i ] = i + 0x0C;
12171324      }
r4575r4576
12211328      memcpy( gb_oam, mgb_oam_fingerprint, 0x100 );
12221329
12231330      /* Make sure the VBlank interrupt is set when the first instruction gets executed */
1224      timer_set(machine,  cpu_clocks_to_attotime(machine->cpu[0], 1), NULL, 0, gb_video_init_vbl );
1331      timer_set(machine,  cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, gb_video_init_vbl );
12251332
12261333      /* Initialize some video registers */
12271334       gb_video_w( space, 0x0, 0x91 );    /* LCDCONT */
r4575r4576
12321339      CURLINE = gb_lcd.current_line = 0;
12331340      LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x05;
12341341      gb_lcd.mode = 1;
1235      timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 60), GB_LCD_STATE_LY00_M0);
1342      timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 60), GB_LCD_STATE_LY00_M0);
12361343
12371344      break;
12381345   case GB_VIDEO_SGB:
r4575r4576
12421349      update_scanline = sgb_update_scanline;
12431350
12441351      /* Initialize part of VRAM. This code must be deleted when we have added the bios dump */
1245      for( i = 1; i < 0x0D; i++ ) {
1352      for( i = 1; i < 0x0D; i++ )
1353      {
12461354         gb_vram[ 0x1903 + i ] = i;
12471355         gb_vram[ 0x1923 + i ] = i + 0x0C;
12481356      }
12491357      gb_vram[ 0x1910 ] = 0x19;
12501358
12511359      /* Make sure the VBlank interrupt is set when the first instruction gets executed */
1252      timer_set(machine,  cpu_clocks_to_attotime(machine->cpu[0], 1), NULL, 0, gb_video_init_vbl );
1360      timer_set(machine,  cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, gb_video_init_vbl );
12531361
12541362      /* Initialize some video registers */
12551363      gb_video_w( space, 0x0, 0x91 );    /* LCDCONT */
r4575r4576
12601368      CURLINE = gb_lcd.current_line = 0;
12611369      LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x05;
12621370      gb_lcd.mode = 1;
1263      timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 60), GB_LCD_STATE_LY00_M0);
1371      timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 60), GB_LCD_STATE_LY00_M0);
12641372
12651373      break;
12661374   case GB_VIDEO_CGB:
r4575r4576
12811389      gb_lcd.hdma_possible = 0;
12821390
12831391      /* Make sure the VBlank interrupt is set when the first instruction gets executed */
1284      timer_set(machine,  cpu_clocks_to_attotime(machine->cpu[0], 1), NULL, 0, gb_video_init_vbl );
1392      timer_set(machine,  cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, gb_video_init_vbl );
12851393
12861394      /* Initialize some video registers */
12871395      gbc_video_w( space, 0x0, 0x91 );    /* LCDCONT */
r4575r4576
12921400      CURLINE = gb_lcd.current_line = 0x90;
12931401      LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x01;
12941402      gb_lcd.mode = 1;
1295      timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 292), GB_LCD_STATE_LY9X_M1_INC);
1403      timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 292), GB_LCD_STATE_LY9X_M1_INC);
12961404      gb_lcd.oam_locked = UNLOCKED;
12971405      gb_lcd.vram_locked = UNLOCKED;
12981406      gb_lcd.pal_locked = UNLOCKED;
r4575r4576
13001408   }
13011409}
13021410
1303static void gbc_hdma(running_machine *machine, UINT16 length) {
1411static void gbc_hdma(running_machine *machine, UINT16 length)
1412{
13041413   UINT16 src, dst;
1305   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
1414   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
13061415
13071416   src = ((UINT16)HDMA1 << 8) | (HDMA2 & 0xF0);
13081417   dst = ((UINT16)(HDMA3 & 0x1F) << 8) | (HDMA4 & 0xF0);
13091418   dst |= 0x8000;
1310   while( length > 0 ) {
1419   while( length > 0 )
1420   {
13111421      memory_write_byte( space, dst++, memory_read_byte( space, src++ ) );
13121422      length--;
13131423   }
r4575r4576
13161426   HDMA3 = 0x1f & (dst >> 8);
13171427   HDMA4 = dst & 0xF0;
13181428   HDMA5--;
1319   if( (HDMA5 & 0x7f) == 0x7f ) {
1429   if( (HDMA5 & 0x7f) == 0x7f )
1430   {
13201431      HDMA5 = 0xff;
13211432      gb_lcd.hdma_enabled = 0;
13221433   }
13231434}
13241435
1325static void gb_increment_scanline( void ) {
1436static void gb_increment_scanline( void )
1437{
13261438   gb_lcd.current_line = ( gb_lcd.current_line + 1 ) % 154;
1327   if ( LCDCONT & 0x80 ) {
1439   if ( LCDCONT & 0x80 )
1440   {
13281441      CURLINE = gb_lcd.current_line;
13291442   }
1330   if ( gb_lcd.current_line == 0 ) {
1443   if ( gb_lcd.current_line == 0 )
1444   {
13311445      gb_lcd.window_lines_drawn = 0;
13321446   }
13331447}
r4575r4576
13381452
13391453   gb_lcd.state = param;
13401454
1341   if ( LCDCONT & 0x80 ) {
1342      switch( gb_lcd.state ) {
1455   if ( LCDCONT & 0x80 )
1456   {
1457      switch( gb_lcd.state )
1458      {
13431459      case GB_LCD_STATE_LYXX_PRE_M0:   /* Just before switching to mode 0 */
13441460         gb_lcd.mode = 0;
1345         if ( LCDSTAT & 0x08 ) {
1346            if ( ! gb_lcd.mode_irq ) {
1347               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
1461         if ( LCDSTAT & 0x08 )
1462         {
1463            if ( ! gb_lcd.mode_irq )
1464            {
1465               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq )
1466               {
13481467                  gb_lcd.mode_irq = 1;
1349                  cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1468                  cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
13501469               }
1351            } else {
1470            }
1471            else
1472            {
13521473               gb_lcd.mode_irq = 0;
13531474            }
13541475         }
1355         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0);
1476         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0);
13561477         break;
13571478      case GB_LCD_STATE_LYXX_M0:      /* Switch to mode 0 */
13581479         /* update current scanline */
13591480         update_scanline( machine );
13601481         /* Increment the number of window lines drawn if enabled */
1361         if ( gb_lcd.layer[1].enabled ) {
1482         if ( gb_lcd.layer[1].enabled )
1483         {
13621484            gb_lcd.window_lines_drawn++;
13631485         }
13641486         gb_lcd.previous_line = gb_lcd.current_line;
r4575r4576
13731495            than usual.
13741496            The SGB probably has the same bug.
13751497         */
1376         if ( ( SCROLLX & 0x03 ) == 0x03 ) {
1498         if ( ( SCROLLX & 0x03 ) == 0x03 )
1499         {
13771500            gb_lcd.scrollx_adjust += 4;
1378            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_SCX3);
1501            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_SCX3);
13791502            break;
13801503         }
13811504      case GB_LCD_STATE_LYXX_M0_SCX3:
13821505         /* Generate lcd interrupt if requested */
13831506         if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x08 ) &&
1384              ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1385            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1507              ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) )
1508             {
1509            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
13861510         }
1387         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 196 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC);
1511         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 196 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC);
13881512         break;
13891513      case GB_LCD_STATE_LYXX_M0_PRE_INC:   /* Just before incrementing the line counter go to mode 2 internally */
1390         if ( CURLINE < 143 ) {
1514         if ( CURLINE < 143 )
1515         {
13911516            gb_lcd.mode = 2;
13921517            gb_lcd.triggering_mode_irq = ( LCDSTAT & 0x20 ) ? 1 : 0;
1393            if ( gb_lcd.triggering_mode_irq ) {
1394               if ( ! gb_lcd.mode_irq ) {
1395                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
1518            if ( gb_lcd.triggering_mode_irq )
1519            {
1520               if ( ! gb_lcd.mode_irq )
1521               {
1522                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq )
1523                  {
13961524                     gb_lcd.mode_irq = 1;
1397                     cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1525                     cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
13981526                  }
1399               } else {
1527               }
1528               else
1529               {
14001530                  gb_lcd.mode_irq = 0;
14011531               }
14021532            }
14031533         }
1404         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_INC);
1534         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_INC);
14051535         break;
14061536      case GB_LCD_STATE_LYXX_M0_INC:   /* Increment LY, stay in M0 for 4 more cycles */
14071537         gb_increment_scanline();
14081538         gb_lcd.delayed_line_irq = gb_lcd.line_irq;
14091539         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
14101540         gb_lcd.line_irq = 0;
1411         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! gb_lcd.triggering_mode_irq ) {
1541         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! gb_lcd.triggering_mode_irq )
1542         {
14121543            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1413            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1544            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
14141545         }
14151546         /* Reset LY==LYC STAT bit */
14161547         LCDSTAT &= 0xFB;
14171548         /* Check if we're going into VBlank next */
1418         if ( CURLINE == 144 ) {
1419            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1);
1420         } else {
1549         if ( CURLINE == 144 )
1550         {
1551            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1);
1552         }
1553         else
1554         {
14211555            /* Internally switch to mode 2 */
14221556            gb_lcd.mode = 2;
14231557            /* Generate lcd interrupt if requested */
14241558            if ( ! gb_lcd.mode_irq && gb_lcd.triggering_mode_irq &&
1425                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1559                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) )
1560                {
14261561               gb_lcd.mode_irq = 1;
1427               cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1562               cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
14281563            }
1429            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M2);
1564            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M2);
14301565         }
14311566         break;
14321567      case GB_LCD_STATE_LY00_M2:      /* Switch to mode 2 on line #0 */
r4575r4576
14351570         LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02;
14361571         gb_lcd.oam_locked = LOCKED;
14371572         /* Generate lcd interrupt if requested */
1438         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) {
1439            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1573         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq )
1574         {
1575            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
14401576         }
14411577         /* Check for regular compensation of x-scroll register */
14421578         gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0;
14431579         /* Mode 2 lasts approximately 80 clock cycles */
1444         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3);
1580         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3);
14451581         break;
14461582      case GB_LCD_STATE_LYXX_M2:      /* Switch to mode 2 */
14471583         /* Update STAT register to the correct state */
r4575r4576
14491585         gb_lcd.oam_locked = LOCKED;
14501586         /* Generate lcd interrupt if requested */
14511587         if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) ||
1452             ( ! gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_mode_irq ) ) {
1453            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1588             ( ! gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_mode_irq ) )
1589         {
1590            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
14541591         }
14551592         gb_lcd.line_irq = gb_lcd.triggering_line_irq;
14561593         gb_lcd.triggering_mode_irq = 0;
14571594         /* Check if LY==LYC STAT bit should be set */
1458         if ( CURLINE == CMPLINE ) {
1595         if ( CURLINE == CMPLINE )
1596         {
14591597            LCDSTAT |= 0x04;
14601598         }
14611599         /* Check for regular compensation of x-scroll register */
14621600         gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0;
14631601         /* Mode 2 last for approximately 80 clock cycles */
1464         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3);
1602         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3);
14651603         break;
14661604      case GB_LCD_STATE_LYXX_M3:      /* Switch to mode 3 */
14671605         gb_select_sprites();
r4575r4576
14721610         gb_lcd.vram_locked = LOCKED;
14731611         /* Check for compensations of x-scroll register */
14741612         /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */
1475         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0);
1613         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0);
14761614         gb_lcd.start_x = -1;
14771615         break;
14781616      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
1479         if ( CURLINE == 144 ) {
1617         if ( CURLINE == 144 )
1618         {
14801619            /* Trigger VBlank interrupt */
1481            cpu_set_input_line( machine->cpu[0], VBL_INT, HOLD_LINE );
1620            cputag_set_input_line( machine, "maincpu", VBL_INT, HOLD_LINE );
14821621            /* Set VBlank lcdstate */
14831622            gb_lcd.mode = 1;
14841623            LCDSTAT = (LCDSTAT & 0xFC) | 0x01;
14851624            /* Trigger LCD interrupt if requested */
1486            if ( LCDSTAT & 0x10 ) {
1487               cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1625            if ( LCDSTAT & 0x10 )
1626            {
1627               cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
14881628            }
14891629         }
14901630         /* Check if LY==LYC STAT bit should be set */
1491         if ( CURLINE == CMPLINE ) {
1631         if ( CURLINE == CMPLINE )
1632         {
14921633            LCDSTAT |= 0x04;
14931634         }
1494         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1495            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1635         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1636         {
1637            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
14961638         }
1497         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 452), GB_LCD_STATE_LY9X_M1_INC);
1639         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 452), GB_LCD_STATE_LY9X_M1_INC);
14981640         break;
14991641      case GB_LCD_STATE_LY9X_M1_INC:      /* Increment scanline counter */
15001642         gb_increment_scanline();
15011643         gb_lcd.delayed_line_irq = gb_lcd.line_irq;
15021644         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
15031645         gb_lcd.line_irq = 0;
1504         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1646         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1647         {
15051648            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1506            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1649            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
15071650         }
15081651         /* Reset LY==LYC STAT bit */
15091652         LCDSTAT &= 0xFB;
1510         if ( gb_lcd.current_line == 153 ) {
1511            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1);
1512         } else {
1513            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1);
1653         if ( gb_lcd.current_line == 153 )
1654         {
1655            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1);
1656         }
1657         else
1658         {
1659            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1);
15141660         }
15151661         break;
15161662      case GB_LCD_STATE_LY00_M1:      /* we stay in VBlank but current line counter should already be incremented */
15171663         /* Check LY=LYC for line #153 */
1518         if ( gb_lcd.delayed_line_irq ) {
1519            if ( gb_lcd.triggering_line_irq ) {
1520               cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1664         if ( gb_lcd.delayed_line_irq )
1665         {
1666            if ( gb_lcd.triggering_line_irq )
1667            {
1668               cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
15211669            }
15221670         }
15231671         gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq;
1524         if ( CURLINE == CMPLINE ) {
1672         if ( CURLINE == CMPLINE )
1673         {
15251674            LCDSTAT |= 0x04;
15261675         }
15271676         gb_increment_scanline();
15281677         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
15291678         gb_lcd.line_irq = 0;
15301679         LCDSTAT &= 0xFB;
1531         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4/*8*/), GB_LCD_STATE_LY00_M1_1);
1680         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4/*8*/), GB_LCD_STATE_LY00_M1_1);
15321681         break;
15331682      case GB_LCD_STATE_LY00_M1_1:
1534         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1683         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1684         {
15351685            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1536            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1686            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
15371687         }
1538         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1_2);
1688         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1_2);
15391689         break;
15401690      case GB_LCD_STATE_LY00_M1_2:   /* Rest of line #0 during VBlank */
1541         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1691         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1692         {
15421693            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1543            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1694            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
15441695         }
1545         if ( CURLINE == CMPLINE ) {
1696         if ( CURLINE == CMPLINE )
1697         {
15461698            LCDSTAT |= 0x04;
15471699         }
1548         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 444), GB_LCD_STATE_LY00_M0);
1700         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 444), GB_LCD_STATE_LY00_M0);
15491701         break;
15501702      case GB_LCD_STATE_LY00_M0:      /* The STAT register seems to go to 0 for about 4 cycles */
15511703         /* Set Mode 0 lcdstat */
15521704         gb_lcd.mode = 0;
15531705         LCDSTAT = ( LCDSTAT & 0xFC );
1554         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M2);
1706         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M2);
15551707         break;
15561708      }
1557   } else {
1709   }
1710   else
1711   {
15581712      gb_increment_scanline();
1559      if ( gb_lcd.current_line < 144 ) {
1713      if ( gb_lcd.current_line < 144 )
1714      {
15601715         update_scanline( machine );
15611716      }
1562      timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 456), 0);
1717      timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 456), 0);
15631718   }
15641719}
15651720
r4575r4576
15691724
15701725   gb_lcd.state = param;
15711726
1572   if ( LCDCONT & 0x80 ) {
1573      switch( gb_lcd.state ) {
1727   if ( LCDCONT & 0x80 )
1728   {
1729      switch( gb_lcd.state )
1730      {
15741731      case GB_LCD_STATE_LYXX_PRE_M0:   /* Just before switching to mode 0 */
15751732         gb_lcd.mode = 0;
1576         if ( LCDSTAT & 0x08 ) {
1577            if ( ! gb_lcd.mode_irq ) {
1578               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
1733         if ( LCDSTAT & 0x08 )
1734         {
1735            if ( ! gb_lcd.mode_irq )
1736            {
1737               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq )
1738               {
15791739                  gb_lcd.mode_irq = 1;
1580                  cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1740                  cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
15811741               }
1582            } else {
1742            }
1743            else
1744            {
15831745               gb_lcd.mode_irq = 0;
15841746            }
15851747         }
1586         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0);
1748         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0);
15871749         break;
15881750      case GB_LCD_STATE_LYXX_M0:      /* Switch to mode 0 */
15891751         /* update current scanline */
15901752         update_scanline( machine );
15911753         /* Increment the number of window lines drawn if enabled */
1592         if ( gb_lcd.layer[1].enabled ) {
1754         if ( gb_lcd.layer[1].enabled )
1755         {
15931756            gb_lcd.window_lines_drawn++;
15941757         }
15951758         gb_lcd.previous_line = gb_lcd.current_line;
r4575r4576
16051768            The SGB probably has the same bug.
16061769         */
16071770         gb_lcd.triggering_mode_irq = ( LCDSTAT & 0x08 ) ? 1 : 0;
1608         if ( ( SCROLLX & 0x03 ) == 0x03 ) {
1771         if ( ( SCROLLX & 0x03 ) == 0x03 )
1772         {
16091773            gb_lcd.scrollx_adjust += 4;
1610            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_SCX3);
1774            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_SCX3);
16111775            break;
16121776         }
16131777      case GB_LCD_STATE_LYXX_M0_SCX3:
16141778         /* Generate lcd interrupt if requested */
16151779         if ( ! gb_lcd.mode_irq && gb_lcd.triggering_mode_irq &&
1616              ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1617            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1780              ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) )
1781             {
1782            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
16181783            gb_lcd.triggering_mode_irq = 0;
16191784         }
1620         if ( ( SCROLLX & 0x03 ) == 0x03 ) {
1785         if ( ( SCROLLX & 0x03 ) == 0x03 )
1786         {
16211787            gb_lcd.pal_locked = UNLOCKED;
16221788         }
1623         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_GBC_PAL);
1789         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_GBC_PAL);
16241790         break;
16251791      case GB_LCD_STATE_LYXX_M0_GBC_PAL:
16261792         gb_lcd.pal_locked = UNLOCKED;
16271793            /* Check for HBLANK DMA */
1628         if( gb_lcd.hdma_enabled ) {
1794         if( gb_lcd.hdma_enabled )
1795         {
16291796            gbc_hdma(machine, 0x10);
16301797//            cpunum_set_reg( 0, LR35902_DMA_CYCLES, 36 );
1631         } else {
1798         }
1799         else
1800         {
16321801            gb_lcd.hdma_possible = 1;
16331802         }
1634         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 192 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC);
1803         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 192 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC);
16351804         break;
16361805      case GB_LCD_STATE_LYXX_M0_PRE_INC:   /* Just before incrementing the line counter go to mode 2 internally */
16371806         gb_lcd.cmp_line = CMPLINE;
1638         if ( CURLINE < 143 ) {
1807         if ( CURLINE < 143 )
1808         {
16391809            gb_lcd.mode = 2;
1640            if ( LCDSTAT & 0x20 ) {
1641               if ( ! gb_lcd.mode_irq ) {
1642                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
1810            if ( LCDSTAT & 0x20 )
1811            {
1812               if ( ! gb_lcd.mode_irq )
1813               {
1814                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq )
1815                  {
16431816                     gb_lcd.mode_irq = 1;
1644                     cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1817                     cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
16451818                  }
1646               } else {
1819               }
1820               else
1821               {
16471822                  gb_lcd.mode_irq = 0;
16481823               }
16491824            }
16501825         }
1651         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_INC);
1826         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_INC);
16521827         break;
16531828      case GB_LCD_STATE_LYXX_M0_INC:   /* Increment LY, stay in M0 for 4 more cycles */
16541829         gb_increment_scanline();
16551830         gb_lcd.delayed_line_irq = gb_lcd.line_irq;
16561831         gb_lcd.triggering_line_irq = ( ( gb_lcd.cmp_line == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
16571832         gb_lcd.line_irq = 0;
1658         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) {
1833         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) )
1834         {
16591835            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1660            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1836            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
16611837         }
16621838         gb_lcd.hdma_possible = 0;
16631839         /* Check if we're going into VBlank next */
1664         if ( CURLINE == 144 ) {
1665            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1);
1666         } else {
1840         if ( CURLINE == 144 )
1841         {
1842            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1);
1843         }
1844         else
1845         {
16671846            /* Internally switch to mode 2 */
16681847            gb_lcd.mode = 2;
16691848            /* Generate lcd interrupt if requested */
16701849            if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x20 ) &&
1671                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1850                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) )
1851                {
16721852               gb_lcd.mode_irq = 1;
1673               cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1853               cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
16741854            }
1675            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M2);
1855            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M2);
16761856         }
16771857         break;
16781858      case GB_LCD_STATE_LY00_M2:      /* Switch to mode 2 on line #0 */
r4575r4576
16811861         LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02;
16821862         gb_lcd.oam_locked = LOCKED;
16831863         /* Generate lcd interrupt if requested */
1684         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) {
1685            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1864         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq )
1865         {
1866            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
16861867         }
16871868         /* Check for regular compensation of x-scroll register */
16881869         gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0;
16891870         /* Mode 2 lasts approximately 80 clock cycles */
1690         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3);
1871         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3);
16911872         break;
16921873      case GB_LCD_STATE_LYXX_M2:      /* Switch to mode 2 */
16931874         /* Update STAT register to the correct state */
r4575r4576
16951876         gb_lcd.oam_locked = LOCKED;
16961877         /* Generate lcd interrupt if requested */
16971878         if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) ||
1698             ( !gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) ) {
1699            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1879             ( !gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) )
1880             {
1881            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17001882         }
17011883         gb_lcd.line_irq = gb_lcd.triggering_line_irq;
17021884         /* Check if LY==LYC STAT bit should be set */
1703         if ( CURLINE == CMPLINE ) {
1885         if ( CURLINE == CMPLINE )
1886         {
17041887            LCDSTAT |= 0x04;
1705         } else {
1888         }
1889         else
1890         {
17061891            LCDSTAT &= ~0x04;
17071892         }
17081893         /* Check for regular compensation of x-scroll register */
17091894         gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0;
17101895         /* Mode 2 last for approximately 80 clock cycles */
1711         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3);
1896         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3);
17121897         break;
17131898      case GB_LCD_STATE_LYXX_M3:      /* Switch to mode 3 */
17141899         gb_select_sprites();
r4575r4576
17201905         gb_lcd.pal_locked = LOCKED;
17211906         /* Check for compensations of x-scroll register */
17221907         /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */
1723         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0);
1908         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0);
17241909         gb_lcd.start_x = -1;
17251910         break;
17261911      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
1727         if ( CURLINE == 144 ) {
1912         if ( CURLINE == 144 )
1913         {
17281914            /* Trigger VBlank interrupt */
1729            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1915            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17301916            /* Set VBlank lcdstate */
17311917            gb_lcd.mode = 1;
17321918            LCDSTAT = (LCDSTAT & 0xFC) | 0x01;
17331919            /* Trigger LCD interrupt if requested */
1734            if ( LCDSTAT & 0x10 ) {
1735               cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1920            if ( LCDSTAT & 0x10 )
1921            {
1922               cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17361923            }   
17371924         }
17381925         /* Check if LY==LYC STAT bit should be set */
1739         if ( CURLINE == CMPLINE ) {
1926         if ( CURLINE == CMPLINE )
1927         {
17401928            LCDSTAT |= 0x04;
1741         } else {
1929         }
1930         else
1931         {
17421932            LCDSTAT &= ~0x04;
17431933         }
1744         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1745            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1934         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1935         {
1936            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17461937         }
1747         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 452), GB_LCD_STATE_LY9X_M1_INC);
1938         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 452), GB_LCD_STATE_LY9X_M1_INC);
17481939         break;
17491940      case GB_LCD_STATE_LY9X_M1_INC:      /* Increment scanline counter */
17501941         gb_increment_scanline();
17511942         gb_lcd.delayed_line_irq = gb_lcd.line_irq;
17521943         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
17531944         gb_lcd.line_irq = 0;
1754         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1945         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1946         {
17551947            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1756            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1948            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17571949         }
1758         if ( gb_lcd.current_line == 153 ) {
1759            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1);
1760         } else {
1761            timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1);
1950         if ( gb_lcd.current_line == 153 )
1951         {
1952            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1);
1953         }
1954         else
1955         {
1956            timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1);
17621957         }
17631958         break;
17641959      case GB_LCD_STATE_LY00_M1:      /* we stay in VBlank but current line counter should already be incremented */
17651960         /* Check LY=LYC for line #153 */
1766         if ( gb_lcd.delayed_line_irq ) {
1767            if ( gb_lcd.triggering_line_irq ) {
1768               cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1961         if ( gb_lcd.delayed_line_irq )
1962         {
1963            if ( gb_lcd.triggering_line_irq )
1964            {
1965               cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17691966            }
17701967         }
17711968         gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq;
1772         if ( CURLINE == CMPLINE ) {
1969         if ( CURLINE == CMPLINE )
1970         {
17731971            LCDSTAT |= 0x04;
1774         }  else {
1972         } 
1973         else
1974         {
17751975            LCDSTAT &= ~0x04;
17761976         }
17771977         gb_increment_scanline();
17781978         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
17791979         gb_lcd.line_irq = 0;
17801980         LCDSTAT &= 0xFB;
1781         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1_1);
1981         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1_1);
17821982         break;
17831983      case GB_LCD_STATE_LY00_M1_1:
1784         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1984         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1985         {
17851986            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1786            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1987            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17871988         }
1788         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1_2);
1989         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1_2);
17891990         break;
17901991      case GB_LCD_STATE_LY00_M1_2:   /* Rest of line #0 during VBlank */
1791         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1992         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq )
1993         {
17921994            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1793            cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
1995            cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
17941996         }
1795         if ( CURLINE == CMPLINE ) {
1997         if ( CURLINE == CMPLINE )
1998         {
17961999            LCDSTAT |= 0x04;
1797         } else {
2000         }
2001         else
2002         {
17982003            LCDSTAT &= ~0x04;
17992004         }
1800         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 444), GB_LCD_STATE_LY00_M0);
2005         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 444), GB_LCD_STATE_LY00_M0);
18012006         break;
18022007      case GB_LCD_STATE_LY00_M0:      /* The STAT register seems to go to 0 for about 4 cycles */
18032008         /* Set Mode 0 lcdstat */
18042009         gb_lcd.mode = 0;
1805         timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M2);
2010         timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M2);
18062011         break;
18072012      }
1808   } else {
2013   }
2014   else
2015   {
18092016      gb_increment_scanline();
1810      if ( gb_lcd.current_line < 144 ) {
2017      if ( gb_lcd.current_line < 144 )
2018      {
18112019         update_scanline( machine );
18122020      }
1813      timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 456), 0);
2021      timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 456), 0);
18142022   }
18152023}
18162024
1817static void gb_lcd_switch_on( running_machine *machine ) {
2025static void gb_lcd_switch_on( running_machine *machine )
2026{
18182027   gb_lcd.current_line = 0;
18192028   gb_lcd.previous_line = 153;
18202029   gb_lcd.window_lines_drawn = 0;
r4575r4576
18232032   gb_lcd.mode = 0;
18242033   gb_lcd.oam_locked = LOCKED;   /* TODO: Investigate whether this OAM locking is correct. */
18252034   /* Check for LY=LYC coincidence */
1826   if ( CURLINE == CMPLINE ) {
2035   if ( CURLINE == CMPLINE )
2036   {
18272037      LCDSTAT |= 0x04;
18282038      /* Generate lcd interrupt if requested */
1829      if ( LCDSTAT & 0x40 ) {
1830         cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE );
2039      if ( LCDSTAT & 0x40 )
2040      {
2041         cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE );
18312042      }
18322043   }
18332044   gb_lcd.state = GB_LCD_STATE_LY00_M2;
1834   timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3);
2045   timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3);
18352046}
18362047
1837READ8_HANDLER( gb_video_r ) {
2048READ8_HANDLER( gb_video_r )
2049{
18382050   return gb_vid_regs[offset];
18392051}
18402052
1841READ8_HANDLER( gb_vram_r ) {
2053READ8_HANDLER( gb_vram_r )
2054{
18422055   return ( gb_lcd.vram_locked == LOCKED ) ? 0xFF : gb_vram_ptr[offset];
18432056}
18442057
1845WRITE8_HANDLER( gb_vram_w ) {
1846   if ( gb_lcd.vram_locked == LOCKED ) {
2058WRITE8_HANDLER( gb_vram_w )
2059{
2060   if ( gb_lcd.vram_locked == LOCKED )
2061   {
18472062      return;
18482063   }
18492064   gb_vram_ptr[offset] = data;
18502065}
18512066
1852READ8_HANDLER( gb_oam_r ) {
2067READ8_HANDLER( gb_oam_r )
2068{
18532069   return ( gb_lcd.oam_locked == LOCKED ) ? 0xFF : gb_oam[offset];
18542070}
18552071
1856WRITE8_HANDLER( gb_oam_w ) {
1857   if ( gb_lcd.oam_locked == LOCKED || offset >= 0xa0 ) {
2072WRITE8_HANDLER( gb_oam_w )
2073{
2074   if ( gb_lcd.oam_locked == LOCKED || offset >= 0xa0 )
2075   {
18582076      return;
18592077   }
18602078   gb_oam[offset] = data;
18612079}
18622080
1863WRITE8_HANDLER ( gb_video_w ) {
1864   switch (offset) {
2081WRITE8_HANDLER ( gb_video_w )
2082{
2083   switch (offset)
2084   {
18652085   case 0x00:                  /* LCDC - LCD Control */
18662086      gb_chrgen = gb_vram + ((data & 0x10) ? 0x0000 : 0x0800);
18672087      gb_tile_no_mod = (data & 0x10) ? 0x00 : 0x80;
18682088      gb_bgdtab = gb_vram + ((data & 0x08) ? 0x1C00 : 0x1800 );
18692089      gb_wndtab = gb_vram + ((data & 0x40) ? 0x1C00 : 0x1800 );
18702090      /* if LCD controller is switched off, set STAT and LY to 00 */
1871      if ( ! ( data & 0x80 ) ) {
2091      if ( ! ( data & 0x80 ) )
2092      {
18722093         LCDSTAT &= ~0x03;
18732094         CURLINE = 0;
18742095         gb_lcd.oam_locked = UNLOCKED;
18752096         gb_lcd.vram_locked = UNLOCKED;
18762097      }
18772098      /* If LCD is being switched on */
1878      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) {
2099      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) )
2100      {
18792101         gb_lcd_switch_on( space->machine );
18802102      }
18812103      break;
r4575r4576
18862108         Writing to STAT when the LCD controller is active causes a STAT
18872109         interrupt to be triggered.
18882110       */
1889      if ( LCDCONT & 0x80 ) {
2111      if ( LCDCONT & 0x80 )
2112      {
18902113         /* Triggers seen so far:
18912114            - 0x40 -> 0x00 - trigger
18922115            - 0x00 -> 0x08 - trigger
r4575r4576
19072130            ( ! ( LCDSTAT & 0x48 ) && ( data & 0x08 ) ) ||
19082131            ( ( LCDSTAT & 0x60 ) == 0x00 && ( data & 0x60 ) == 0x20 ) ||
19092132            ( ( LCDSTAT & 0x60 ) == 0x20 && ( data & 0x40 ) )
1910            ) ) {
1911               cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE );
2133            ) )
2134         {
2135               cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE );
19122136         }
19132137         /*
19142138            - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger
19152139            - 0x20 -> 0x00/0x10/0x20/0x40 (mode 0, after m2int) - trigger (stat bug)
19162140            - 0x00 -> 0xXX (mode 0) - trigger stat bug
19172141         */
1918         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 ) {
1919            cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE );
2142         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 )
2143         {
2144            cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE );
19202145         }
19212146      }
19222147      break;
19232148   case 0x04:                  /* LY - LCD Y-coordinate */
19242149      return;
19252150   case 0x05:                  /* LYC */
1926      if ( CMPLINE != data ) {
1927         if ( CURLINE == data ) {
1928            if ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_INC && gb_lcd.state != GB_LCD_STATE_LY9X_M1_INC ) {
2151      if ( CMPLINE != data )
2152      {
2153         if ( CURLINE == data )
2154         {
2155            if ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_INC && gb_lcd.state != GB_LCD_STATE_LY9X_M1_INC )
2156            {
19292157               LCDSTAT |= 0x04;
19302158               /* Generate lcd interrupt if requested */
1931               if ( LCDSTAT & 0x40 ) {
1932                  cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE );
2159               if ( LCDSTAT & 0x40 )
2160               {
2161                  cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE );
19332162               }
19342163            }
1935         } else {
2164         }
2165         else
2166         {
19362167            LCDSTAT &= 0xFB;
19372168            gb_lcd.triggering_line_irq = 0;
19382169         }
r4575r4576
19792210   gb_vid_regs[ offset ] = data;
19802211}
19812212
1982READ8_HANDLER( gbc_video_r ) {
1983   switch( offset ) {
2213READ8_HANDLER( gbc_video_r )
2214{
2215   switch( offset )
2216   {
19842217   case 0x11:   /* FF51 */
19852218   case 0x12:   /* FF52 */
19862219   case 0x13:   /* FF53 */
r4575r4576
19882221      return 0xFF;
19892222   case 0x29:   /* FF69 */
19902223   case 0x2B:   /* FF6B */
1991      if ( gb_lcd.pal_locked == LOCKED ) {
2224      if ( gb_lcd.pal_locked == LOCKED )
2225      {
19922226         return 0xFF;
19932227      }
19942228      break;
r4575r4576
19962230   return gb_vid_regs[offset];
19972231}
19982232
1999WRITE8_HANDLER ( gbc_video_w ) {
2233WRITE8_HANDLER ( gbc_video_w )
2234{
20002235   static const UINT16 gbc_to_gb_pal[4] = {32767, 21140, 10570, 0};
20012236   static UINT16 BP = 0, OP = 0;
20022237
2003   switch( offset ) {
2238   switch( offset )
2239   {
20042240   case 0x00:      /* LCDC - LCD Control */
20052241      gb_chrgen = gb_vram + ((data & 0x10) ? 0x0000 : 0x0800);
20062242      gbc_chrgen = gb_vram + ((data & 0x10) ? 0x2000 : 0x2800);
r4575r4576
20102246      gb_wndtab = gb_vram + ((data & 0x40) ? 0x1C00 : 0x1800);
20112247      gbc_wndtab = gb_vram + ((data & 0x40) ? 0x3C00 : 0x3800);
20122248      /* if LCD controller is switched off, set STAT to 00 */
2013      if ( ! ( data & 0x80 ) ) {
2249      if ( ! ( data & 0x80 ) )
2250      {
20142251         LCDSTAT &= ~0x03;
20152252         CURLINE = 0;
20162253         gb_lcd.oam_locked = UNLOCKED;
r4575r4576
20182255         gb_lcd.pal_locked = UNLOCKED;
20192256      }
20202257      /* If LCD is being switched on */
2021      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) {
2258      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) )
2259      {
20222260         gb_lcd_switch_on( space->machine );
20232261      }
20242262      break;
20252263   case 0x01:      /* STAT - LCD Status */
20262264      data = 0x80 | (data & 0x78) | (LCDSTAT & 0x07);
2027      if ( LCDCONT & 0x80 ) {
2265      if ( LCDCONT & 0x80 )
2266      {
20282267         /*
20292268            - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger
20302269         */
2031         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) ) {
2032            cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE );
2270         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) )
2271         {
2272            cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE );
20332273         }
20342274         /* Check if line irqs are being disabled */
2035         if ( ! ( data & 0x40 ) ) {
2275         if ( ! ( data & 0x40 ) )
2276         {
20362277            gb_lcd.delayed_line_irq = 0;
20372278         }
20382279         /* Check if line irqs are being enabled */
2039         if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) {
2040            if ( CMPLINE == CURLINE ) {
2280         if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) )
2281         {
2282            if ( CMPLINE == CURLINE )
2283            {
20412284               gb_lcd.line_irq = 1;
2042               cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE );
2285               cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE );
20432286            }
20442287         }
20452288      }
20462289      break;
20472290   case 0x05:                      /* LYC */
2048      if ( CMPLINE != data ) {
2291      if ( CMPLINE != data )
2292      {
20492293         if ( ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_PRE_INC && CURLINE == data ) ||
2050              ( gb_lcd.state == GB_LCD_STATE_LYXX_M0_INC && gb_lcd.triggering_line_irq ) ) {
2294              ( gb_lcd.state == GB_LCD_STATE_LYXX_M0_INC && gb_lcd.triggering_line_irq ) )
2295             {
20512296            LCDSTAT |= 0x04;
20522297            /* Generate lcd interrupt if requested */
2053            if ( LCDSTAT & 0x40 ) {
2054               cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE );
2298            if ( LCDSTAT & 0x40 )
2299            {
2300               cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE );
20552301            }
2056         } else {
2302         }
2303         else
2304         {
20572305            LCDSTAT &= 0xFB;
20582306            gb_lcd.triggering_line_irq = 0;
20592307            gb_lcd.cmp_line = data;
r4575r4576
20622310      break;
20632311   case 0x07:      /* BGP - GB background palette */
20642312      /* Some GBC games are lazy and still call this */
2065      if( gbc_mode == GBC_MODE_MONO ) {
2313      if( gbc_mode == GBC_MODE_MONO )
2314      {
20662315         update_scanline( space->machine );
20672316         cgb_bpal[0] = gbc_to_gb_pal[(data & 0x03)];
20682317         cgb_bpal[1] = gbc_to_gb_pal[(data & 0x0C) >> 2];
r4575r4576
21262375         data &= 0x7f;
21272376         gb_vid_regs[offset] = data;
21282377         /* Check if HDMA should be immediately performed */
2129         if ( gb_lcd.hdma_possible ) {
2378         if ( gb_lcd.hdma_possible )
2379         {
21302380            gbc_hdma( space->machine, 0x10 );
21312381//            cpunum_set_reg( 0, LR35902_DMA_CYCLES, 36 );
21322382            gb_lcd.hdma_possible = 0;
r4575r4576
21362386   case 0x28:      /* BCPS - Background palette specification */
21372387      break;
21382388   case 0x29:      /* BCPD - background palette data */
2139      if ( gb_lcd.pal_locked == LOCKED ) {
2389      if ( gb_lcd.pal_locked == LOCKED )
2390      {
21402391         return;
21412392      }
21422393      if( GBCBCPS & 0x1 )
r4575r4576
21542405   case 0x2A:      /* OCPS - Object palette specification */
21552406      break;
21562407   case 0x2B:      /* OCPD - Object palette data */
2157      if ( gb_lcd.pal_locked == LOCKED ) {
2408      if ( gb_lcd.pal_locked == LOCKED )
2409      {
21582410         return;
21592411      }
21602412      if( GBCOCPS & 0x1 )
src/mess/video/irisha.c
r4575r4576
1717
1818VIDEO_UPDATE( irisha )
1919{
20    UINT8 code1,code2;
20    UINT8 code1, code2;
2121    UINT8 col;
2222   int y, x, b;
23   const address_space *space = cpu_get_address_space(screen->machine->cpu[0], ADDRESS_SPACE_PROGRAM);
23   const address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
2424   
2525   // draw image
2626   for (y = 0; y < 200; y++)
2727   {
2828      for (x = 0; x < 40; x++)
2929      {
30         code1 = memory_read_byte(space, 0xe000 + x + y*40);
31         code2 = memory_read_byte(space, 0xc000 + x + y*40);
30         code1 = memory_read_byte(space, 0xe000 + x + y * 40);
31         code2 = memory_read_byte(space, 0xc000 + x + y * 40);
3232         for (b = 0; b < 8; b++)
3333         {
3434            col = ((code1 >> b) & 0x01);
35            *BITMAP_ADDR16(bitmap, y, x*8+(7-b)) =  col;
35            *BITMAP_ADDR16(bitmap, y, x * 8 + (7 - b)) =  col;
3636         }
3737      }
3838   }
src/mess/video/galaxy.c
r4575r4576
2020
2121TIMER_CALLBACK( gal_video )
2222{   
23   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
24   int y,x;
25   if (galaxy_interrupts_enabled==TRUE) {
23   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
24   int y, x;
25   if (galaxy_interrupts_enabled == TRUE)
26   {
2627      UINT8 *gfx = memory_region(machine, "gfx1");
2728      UINT8 dat = (gal_latch_value & 0x3c) >> 2;
28      if ((gal_cnt >= 48 * 2) && (gal_cnt < 48 * 210)) { // display on screen just first 208 lines
29      if ((gal_cnt >= 48 * 2) && (gal_cnt < 48 * 210))  // display on screen just first 208 lines
30      {
2931         UINT8 mode = (gal_latch_value >> 1) & 1; // bit 2 latch represents mode
30         UINT16 addr = (cpu_get_reg(machine->cpu[0], Z80_I) << 8) | cpu_get_reg(machine->cpu[0], Z80_R) | ((gal_latch_value & 0x80) ^ 0x80);
31           if (mode == 0){
32         UINT16 addr = (cpu_get_reg(cputag_get_cpu(machine, "maincpu"), Z80_I) << 8) | cpu_get_reg(cputag_get_cpu(machine, "maincpu"), Z80_R) | ((gal_latch_value & 0x80) ^ 0x80);
33           if (mode == 0)
34         {
3235              // Text mode
33              if (first==0 && (cpu_get_reg(machine->cpu[0], Z80_R) & 0x1f) ==0) {
36              if (first == 0 && (cpu_get_reg(cputag_get_cpu(machine, "maincpu"), Z80_R) & 0x1f) == 0)
37            {
3438                 // Due to a fact that on real processor latch value is set at
3539                 // the end of last cycle we need to skip dusplay of double
3640                 // first char in each row
3741                 code = 0x00;
3842                 first = 1;
39            } else {
43            }
44            else
45            {
4046               code = memory_read_byte(space,addr) & 0xbf;
4147               code += (code & 0x80) >> 1;
4248               code = gfx[(code & 0x7f) +(dat << 7 )] ^ 0xff;
r4575r4576
5662         }
5763         else
5864         { // Graphics mode
59              if (first<4 && (cpu_get_reg(machine->cpu[0], Z80_R) & 0x1f) ==0) {
65              if (first < 4 && (cpu_get_reg(cputag_get_cpu(machine, "maincpu"), Z80_R) & 0x1f) == 0)
66            {
6067                 // Due to a fact that on real processor latch value is set at
6168                 // the end of last cycle we need to skip dusplay of 4 times
6269                 // first char in each row
6370                 code = 0x00;
6471                 first++;
65            } else {
72            }
73            else
74            {
6675               code = memory_read_byte(space,addr) ^ 0xff;
6776               first = 0;
6877            }
r4575r4576
7079            x = (gal_cnt % 48) * 8;
7180           
7281            /* hack - until calc of R is fixed in Z80 */
73            if (x==11*8 && y==0) {
82            if (x == 11 * 8 && y == 0)
83            {
7484               start_addr = addr;
7585            }
76            if ((x/8 >=11) && (x/8<44)) {
77               code = memory_read_byte(space,start_addr + y * 32 + (gal_cnt % 48)-11) ^ 0xff;
78            } else {
86            if ((x / 8 >= 11) && (x / 8 < 44))
87            {
88               code = memory_read_byte(space, start_addr + y * 32 + (gal_cnt % 48) - 11) ^ 0xff;
89            }
90            else
91            {
7992               code = 0x00;
8093            }
8194            /* end of hack */
r4575r4576
97110VIDEO_UPDATE( galaxy )
98111{
99112   timer_adjust_periodic(gal_video_timer, attotime_zero, 0, attotime_never);
100   if (galaxy_interrupts_enabled == FALSE) {
101      rectangle black_area = {0,384-1,0,208-1};
113   if (galaxy_interrupts_enabled == FALSE)
114   {
115      rectangle black_area = {0, 384 - 1, 0, 208 - 1};
102116      bitmap_fill(tmpbitmap, &black_area, 0);
103117   }
104118   galaxy_interrupts_enabled = FALSE;
src/mess/machine/hp48.c
r4575r4576
145145
146146static void hp48_pulse_irq( running_machine *machine, int irq_line)
147147{
148   cpu_set_input_line( machine->cpu[0], irq_line, ASSERT_LINE );
149   cpu_set_input_line( machine->cpu[0], irq_line, CLEAR_LINE );   
148   cputag_set_input_line(machine, "maincpu", irq_line, ASSERT_LINE );
149   cputag_set_input_line(machine, "maincpu", irq_line, CLEAR_LINE );   
150150}
151151
152152
r4575r4576
222222   UINT8 data = HP48_IO_8(0x16); /* byte to send */
223223
224224   LOG_SERIAL(( "%05x %f hp48_rs232_send_byte: start sending, data=%02x\n",
225           cpu_get_previouspc(machine->cpu[0]), attotime_to_double(timer_get_time(machine)), data ));
225           cpu_get_previouspc(cputag_get_cpu(machine, "maincpu")), attotime_to_double(timer_get_time(machine)), data ));
226226
227227   /* set byte sending and send buffer full */
228228   hp48_io[0x12] |= 3;
r4575r4576
296296void hp48_reg_out( const device_config *device, int out )
297297{
298298   LOG(( "%05x %f hp48_reg_out: %03x\n",
299         cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)), out ));
299         cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)), out ));
300300
301301   /* bits 0-8: keyboard lines */
302302   hp48_out = out & 0x1ff;
r4575r4576
333333{
334334   int in = hp48_get_in( device->machine );
335335   LOG(( "%05x %f hp48_reg_in: %04x\n",
336         cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)), in ));
336         cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)), in ));
337337   return in;
338338}
339339
r4575r4576
375375/* RSI opcode */
376376void hp48_rsi( const device_config *device )
377377{
378   LOG(( "%05x %f hp48_rsi\n", cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)) ));
378   LOG(( "%05x %f hp48_rsi\n", cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)) ));
379379
380380   /* enables interrupts on key repeat
381381      (normally, there is only one interrupt, when the key is pressed)
r4575r4576
752752{
753753   int i;
754754   int nce2_enable = 1;
755   const address_space* space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
755   const address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
756756
757757   hp48_io_addr = 0x100000;
758758
r4575r4576
855855/* RESET opcode */
856856void hp48_mem_reset( const device_config *device )
857857{
858   LOG(( "%05x %f hp48_mem_reset\n", cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)) ));
858   LOG(( "%05x %f hp48_mem_reset\n", cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)) ));
859859   hp48_reset_modules( device->machine );
860860}
861861
r4575r4576
865865{   
866866   int i;
867867
868   LOG(( "%05x %f hp48_mem_config: %05x\n", cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)), v ));
868   LOG(( "%05x %f hp48_mem_config: %05x\n", cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)), v ));
869869
870870   /* find the highest priority unconfigured module (except non-configurable NCE1)... */
871871   for ( i = 0; i < 5; i++ )
r4575r4576
896896void hp48_mem_unconfig( const device_config *device, int v )
897897{   
898898   int i;
899   LOG(( "%05x %f hp48_mem_unconfig: %05x\n", cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)), v ));
899   LOG(( "%05x %f hp48_mem_unconfig: %05x\n", cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)), v ));
900900
901901   /* find the highest priority fully configured module at address v (except NCE1)... */
902902   for ( i = 0; i < 5; i++ )
r4575r4576
939939   }
940940
941941   LOG(( "%05x %f hp48_mem_id = %02x\n",
942         cpu_get_previouspc(device->machine->cpu[0]), attotime_to_double(timer_get_time(device->machine)), data ));
942         cpu_get_previouspc(cputag_get_cpu(device->machine, "maincpu")), attotime_to_double(timer_get_time(device->machine)), data ));
943943
944944   return data; /* everything is configured */
945945}
src/mess/machine/gb.c
r4575r4576
161161/* #define V_BANK*/         /* Display bank switching debug information */
162162#endif
163163
164static void gb_init_regs(running_machine *machine) {
164static void gb_init_regs(running_machine *machine)
165{
165166   /* Initialize the registers */
166167   SIODATA = 0x00;
167168   SIOCONT = 0x7E;
168169
169   gb_io_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x05, 0x00 );      /* TIMECNT */
170   gb_io_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x06, 0x00 );      /* TIMEMOD */
170   gb_io_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x05, 0x00 );      /* TIMECNT */
171   gb_io_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x06, 0x00 );      /* TIMEMOD */
171172}
172173
173static void gb_rom16_0000( running_machine *machine, UINT8 *addr ) {
174static void gb_rom16_0000( running_machine *machine, UINT8 *addr )
175{
174176   memory_set_bankptr( machine, 5, addr );
175177   memory_set_bankptr( machine, 10, addr + 0x0100 );
176178}
177179
178static void gb_rom16_4000( running_machine *machine, UINT8 *addr ) {
180static void gb_rom16_4000( running_machine *machine, UINT8 *addr )
181{
179182   memory_set_bankptr( machine, 1, addr );
180183   memory_set_bankptr( machine, 4, addr + 0x2000 );
181184}
182185
183static void gb_rom8_4000( running_machine *machine, UINT8 *addr ) {
186static void gb_rom8_4000( running_machine *machine, UINT8 *addr )
187{
184188   memory_set_bankptr( machine, 1, addr );
185189}
186190
187static void gb_rom8_6000( running_machine *machine, UINT8 *addr ) {
191static void gb_rom8_6000( running_machine *machine, UINT8 *addr )
192{
188193   memory_set_bankptr( machine, 4, addr );
189194}
190195
191static void gb_init(running_machine *machine) {
192   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
196static void gb_init(running_machine *machine)
197{
198   const address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM );
193199
194200   /* Initialize the memory banks */
195201   MBC1Mode = 0;
r4575r4576
379385   memory_set_bankptr(machine, 10, ROMMap[ROMBank00] ? ROMMap[ROMBank00] + 0x0100 : gb_dummy_rom_bank + 0x0100);
380386
381387   /* Allocate memory for internal ram */
382   for( ii = 0; ii < 8; ii++ ) {
388   for( ii = 0; ii < 8; ii++ )
389   {
383390      GBC_RAMMap[ii] = mess_ram + CGB_START_RAM_BANKS + ii * 0x1000;
384391      memset (GBC_RAMMap[ii], 0, 0x1000);
385392   }
386   gbc_io2_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x30, 0x00 );
393   gbc_io2_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x30, 0x00 );
387394
388395   /* Initialise registers */
389   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x6C, 0xFE );
390   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x72, 0x00 );
391   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x73, 0x00 );
392   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x74, 0x8F );
393   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x75, 0x00 );
394   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x76, 0x00 );
395   gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x77, 0x00 );
396   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x6C, 0xFE );
397   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x72, 0x00 );
398   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x73, 0x00 );
399   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x74, 0x8F );
400   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x75, 0x00 );
401   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x76, 0x00 );
402   gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x77, 0x00 );
396403
397404   /* Are we in colour or mono mode? */
398405   gbc_mode = GBC_MODE_MONO;
r4575r4576
417424   image_battery_save(devtag_get_device(machine, "cart"), gb_cart_ram, RAMBanks * 0x2000 );
418425}
419426
420static void gb_set_mbc1_banks( running_machine *machine ) {
427static void gb_set_mbc1_banks( running_machine *machine )
428{
421429   gb_rom16_4000( machine, ROMMap[ ROMBank ] );
422430   memory_set_bankptr( machine, 2, RAMMap[ MBC1Mode ? ( ROMBank >> 5 ) : 0 ] );
423431}
r4575r4576
468476     Writing into 3000-3FFF sets the 9th bit
469477   */
470478   logerror( "0x%04X: MBC5 ROM Bank select write 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data );
471   if( offset & 0x1000 ) {
479   if( offset & 0x1000 )
480   {
472481      ROMBank = (ROMBank & 0xFF ) | ( ( data & 0x01 ) << 8 );
473   } else {
482   }
483   else
484   {
474485      ROMBank = (ROMBank & 0x100 ) | data;
475486   }
476487   /* Switch banks */
477488   gb_rom16_4000( space->machine, ROMMap[ROMBank] );
478489}
479490
480static WRITE8_HANDLER( gb_ram_bank_select_mbc6 ) {
491static WRITE8_HANDLER( gb_ram_bank_select_mbc6 )
492{
481493   logerror( "0x%04X: write to mbc6 ram enable area: %04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data );
482494}
483495
484static WRITE8_HANDLER( gb_rom_bank_select_mbc6_1 ) {
496static WRITE8_HANDLER( gb_rom_bank_select_mbc6_1 )
497{
485498   logerror( "0x%04X: write to mbc6 rom area: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x2000 + offset, data );
486   if ( offset & 0x0800 ) {
487      if ( data == 0x00 ) {
499   if ( offset & 0x0800 )
500   {
501      if ( data == 0x00 )
502      {
488503         gb_rom8_4000( space->machine, ROMMap[ROMBank>>1] + ( ( ROMBank & 0x01 ) ? 0x2000 : 0x0000 ) );
489504      }
490   } else {
505   }
506   else
507   {
491508      ROMBank = data;
492509   }
493510}
494511
495static WRITE8_HANDLER( gb_rom_bank_select_mbc6_2 ) {
512static WRITE8_HANDLER( gb_rom_bank_select_mbc6_2 )
513{
496514   logerror( "0x%04X: write to mbc6 rom area: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x3000 + offset, data );
497   if ( offset & 0x0800 ) {
498      if ( data == 0x00 ) {
515   if ( offset & 0x0800 )
516   {
517      if ( data == 0x00 )
518      {
499519         gb_rom8_6000( space->machine, ROMMap[ROMBank00>>1] + ( ( ROMBank00 & 0x01 ) ? 0x2000 : 0x0000 ) );
500520      }
501   } else {
521   }
522   else
523   {
502524      ROMBank00 = data;
503525   }
504526}
505527
506static WRITE8_HANDLER( gb_rom_bank_select_mbc7 ) {
528static WRITE8_HANDLER( gb_rom_bank_select_mbc7 )
529{
507530   logerror( "0x%04X: write to mbc7 rom select register: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x2000 + offset, data );
508531   /* Bit 12 must be set for writing to the mbc register */
509   if ( offset & 0x0100 ) {
532   if ( offset & 0x0100 )
533   {
510534      ROMBank = data;
511535      gb_rom16_4000( space->machine, ROMMap[ROMBank] );
512536   }
513537}
514538
515static WRITE8_HANDLER( gb_rom_bank_unknown_mbc7 ) {
539static WRITE8_HANDLER( gb_rom_bank_unknown_mbc7 )
540{
516541        logerror( "0x%04X: write to mbc7 rom area: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x3000 + offset, data );
517542   /* Bit 12 must be set for writing to the mbc register */
518   if ( offset & 0x0100 ) {
519      switch( offset & 0x7000 ) {
543   if ( offset & 0x0100 )
544   {
545      switch( offset & 0x7000 )
546      {
520547      case 0x0000:   /* 0x3000-0x3fff */
521548      case 0x1000:   /* 0x4000-0x4fff */
522549      case 0x2000:   /* 0x5000-0x5fff */
r4575r4576
527554   }
528555}
529556
530static WRITE8_HANDLER( gb_rom_bank_select_wisdom ) {
557static WRITE8_HANDLER( gb_rom_bank_select_wisdom )
558{
531559   logerror( "0x%04X: wisdom tree mapper write to address 0x%04X\n", cpu_get_pc( space->cpu ), offset );
532560   /* The address determines the bank to select */
533561   ROMBank = ( offset << 1 ) & 0x1FF;
r4575r4576
550578static WRITE8_HANDLER( gb_ram_bank_select_mbc3 )
551579{
552580   logerror( "0x%04X: write mbc3 ram bank select register 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data );
553   if( data & 0x8 ) {   /* RTC banks */
554      if ( CartType & TIMER ) {
581   if( data & 0x8 )
582   {   /* RTC banks */
583      if ( CartType & TIMER )
584      {
555585         MBC3RTCBank = data & 0x07;
556         if ( data < 5 ) {
586         if ( data < 5 )
587         {
557588            memset( MBC3RTCData, MBC3RTCMap[MBC3RTCBank], 0x2000 );
558589            memory_set_bankptr( space->machine, 2, MBC3RTCData );
559590         }
560591      }
561   } else {   /* RAM banks */
592   }
593   else
594   {   /* RAM banks */
562595      RAMBank = data & 0x3;
563596      MBC3RTCBank = 0xFF;
564597      /* Switch banks */
r4575r4576
570603{
571604   logerror( "0x%04X: MBC5 RAM Bank select write 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data );
572605   data &= 0x0F;
573   if( CartType & RUMBLE ) {
606   if( CartType & RUMBLE )
607   {
574608      data &= 0x7;
575609   }
576610   RAMBank = data;
r4575r4576
594628static WRITE8_HANDLER( gb_mem_mode_select_mbc3 )
595629{
596630        logerror( "0x%04X: Write to mbc3 mem mode select register 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data );
597   if( CartType & TIMER ) {
631   if( CartType & TIMER )
632   {
598633      /* FIXME: RTC Latch goes here */
599634      MBC3RTCMap[0] = 50;    /* Seconds */
600635      MBC3RTCMap[1] = 40;    /* Minutes */
r4575r4576
604639   }
605640}
606641
607static WRITE8_HANDLER( gb_ram_tama5 ) {
642static WRITE8_HANDLER( gb_ram_tama5 )
643{
608644   logerror( "0x%04X: TAMA5 write 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0xA000 + offset, data );
609   switch( offset & 0x0001 ) {
645   switch( offset & 0x0001 )
646   {
610647   case 0x0000:    /* Write to data register */
611      switch( gbLastTama5Command ) {
648      switch( gbLastTama5Command )
649      {
612650      case 0x00:      /* Bits 0-3 for rom bank selection */
613651         ROMBank = ( ROMBank & 0xF0 ) | ( data & 0x0F );
614652         gb_rom16_4000( space->machine, ROMMap[ROMBank] );
r4575r4576
630668            /* This address always seems to written last, so we'll just
631669               execute the command here */
632670         gbTama5Address = ( gbTama5Address & 0xF0 ) | ( data & 0x0F );
633         switch ( gbTama5Address & 0xE0 ) {
671         switch ( gbTama5Address & 0xE0 )
672         {
634673         case 0x00:      /* Write memory */
635674            logerror( "Write tama5 memory 0x%02X <- 0x%02X\n", gbTama5Address & 0x1F, gbTama5Byte );
636675            gbTama5Memory[ gbTama5Address & 0x1F ] = gbTama5Byte;
r4575r4576
640679            gbTama5Byte = gbTama5Memory[ gbTama5Address & 0x1F ];
641680            break;
642681         case 0x40:      /* Unknown, some kind of read */
643            if ( ( gbTama5Address & 0x1F ) == 0x12 ) {
682            if ( ( gbTama5Address & 0x1F ) == 0x12 )
683            {
644684               gbTama5Byte = 0xFF;
645685            }
646686         case 0x80:      /* Unknown, some kind of read (when 07=01)/write (when 07=00/02) */
r4575r4576
652692      }
653693      break;
654694   case 0x0001:    /* Write to control register */
655      switch( data ) {
695      switch( data )
696      {
656697      case 0x00:      /* Bits 0-3 for rom bank selection */
657698      case 0x01:      /* Bits 4-7 for rom bank selection */
658699      case 0x04:      /* Data write register lo */
r4575r4576
686727static UINT8 mmm01_bank;
687728static UINT8 mmm01_bank_mask;
688729
689static WRITE8_HANDLER( gb_rom_bank_mmm01_0000_w ) {
730static WRITE8_HANDLER( gb_rom_bank_mmm01_0000_w )
731{
690732   logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x000 );
691   if ( data & 0x40 ) {
733   if ( data & 0x40 )
734   {
692735      mmm01_bank_offset = mmm01_reg1;
693736      memory_set_bankptr( space->machine, 5, ROMMap[ mmm01_bank_offset ] );
694737      memory_set_bankptr( space->machine, 10, ROMMap[ mmm01_bank_offset ] + 0x0100 );
r4575r4576
696739   }
697740}
698741
699static WRITE8_HANDLER( gb_rom_bank_mmm01_2000_w ) {
742static WRITE8_HANDLER( gb_rom_bank_mmm01_2000_w )
743{
700744   logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x2000 );
701745
702746   mmm01_reg1 = data & ROMMask;
703747   mmm01_bank = mmm01_reg1 & mmm01_bank_mask;
704   if ( mmm01_bank == 0 ) {
748   if ( mmm01_bank == 0 )
749   {
705750      mmm01_bank = 1;
706751   }
707752   gb_rom16_4000( space->machine, ROMMap[ mmm01_bank_offset + mmm01_bank ] );
708753}
709754
710static WRITE8_HANDLER( gb_rom_bank_mmm01_4000_w ) {
755static WRITE8_HANDLER( gb_rom_bank_mmm01_4000_w )
756{
711757   logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x4000 );
712758}
713759
714static WRITE8_HANDLER( gb_rom_bank_mmm01_6000_w ) {
760static WRITE8_HANDLER( gb_rom_bank_mmm01_6000_w )
761{
715762   logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x6000 );
716763   /* Not sure if this is correct, Taito Variety Pack sets these values */
717764   /* Momotarou Collection 2 writes 01 and 21 here */
718   switch( data ) {
765   switch( data )
766   {
719767   case 0x30:   mmm01_bank_mask = 0x07;   break;
720768   case 0x38:   mmm01_bank_mask = 0x03;   break;
721769   default:   mmm01_bank_mask = 0xFF; break;
r4575r4576
724772
725773/* Korean MBC1 variant mapping */
726774
727static void gb_set_mbc1_kor_banks( running_machine *machine ) {
728   if ( ROMBank & 0x30 ) {
775static void gb_set_mbc1_kor_banks( running_machine *machine )
776{
777   if ( ROMBank & 0x30 )
778   {
729779      gb_rom16_0000( machine, ROMMap[ ROMBank & 0x30 ] );
730780   }
731781   gb_rom16_4000( machine, ROMMap[ ROMBank ] );
r4575r4576
777827   case 0x01:                  /* SB - Serial transfer data */
778828      break;
779829   case 0x02:                  /* SC - SIO control */
780      switch( data & 0x81 ) {
830      switch( data & 0x81 )
831      {
781832      case 0x00:
782833      case 0x01:
783834      case 0x80:            /* enabled & external clock */
r4575r4576
786837      case 0x81:            /* enabled & internal clock */
787838         SIODATA = 0xFF;
788839         SIOCount = 8;
789         timer_adjust_periodic(gb_serial_timer, cpu_clocks_to_attotime(space->machine->cpu[0], 512), 0, cpu_clocks_to_attotime(space->machine->cpu[0], 512));
840         timer_adjust_periodic(gb_serial_timer, cputag_clocks_to_attotime(space->machine, "maincpu", 512), 0, cputag_clocks_to_attotime(space->machine, "maincpu", 512));
790841         timer_enable( gb_serial_timer, 1 );
791842         break;
792843      }
r4575r4576
799850      return;
800851   case 0x05:                  /* TIMA - Timer counter */
801852      /* Check if the counter is being reloaded in this cycle */
802      if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 ) {
853      if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 )
854      {
803855         data = TIMECNT;
804856      }
805857      break;
806858   case 0x06:                  /* TMA - Timer module */
807859      /* Check if the counter is being reloaded in this cycle */
808      if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 ) {
860      if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 )
861      {
809862         TIMECNT = data;
810863      }
811864      break;
812865   case 0x07:                  /* TAC - Timer control */
813866      data |= 0xF8;
814867      /* Check if timer is just disabled or the timer frequency is changing */
815      if ( ( ! ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) ) || ( ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) && ( data & 0x03 ) != ( TIMEFRQ & 0x03 ) ) ) {
868      if ( ( ! ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) ) || ( ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) && ( data & 0x03 ) != ( TIMEFRQ & 0x03 ) ) )
869      {
816870         /* Check if TIMECNT should be incremented */
817         if ( ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) >= ( gb_timer.shift_cycles >> 1 ) ) {
871         if ( ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) >= ( gb_timer.shift_cycles >> 1 ) )
872         {
818873            gb_timer_increment(space->machine);
819874         }
820875      }
r4575r4576
823878      break;
824879   case 0x0F:                  /* IF - Interrupt flag */
825880      data &= 0x1F;
826      cpu_set_reg( space->machine->cpu[0], LR35902_IF, data );
881      cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IF, data );
827882      break;
828883   }
829884
r4575r4576
832887
833888WRITE8_HANDLER ( gb_io2_w )
834889{
835   if ( offset == 0x10 ) {
890   if ( offset == 0x10 )
891   {
836892      /* disable BIOS ROM */
837893      memory_set_bankptr(space->machine, 5, ROMMap[ROMBank00]);
838   } else {
894   }
895   else
896   {
839897      gb_video_w( space, offset, data );
840898   }
841899}
r4575r4576
13631421/* Interrupt Enable register */
13641422READ8_HANDLER( gb_ie_r )
13651423{
1366   return cpu_get_reg( space->machine->cpu[0], LR35902_IE );
1424   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IE );
13671425}
13681426
13691427WRITE8_HANDLER ( gb_ie_w )
13701428{
1371   cpu_set_reg( space->machine->cpu[0], LR35902_IE, data & 0x1F );
1429   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IE, data & 0x1F );
13721430}
13731431
13741432/* IO read */
r4575r4576
13881446         return gb_io[offset];
13891447      case 0x0F:
13901448         /* Make sure the internal states are up to date */
1391         return 0xE0 | cpu_get_reg( space->machine->cpu[0], LR35902_IF );
1449         return 0xE0 | cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IF );
13921450      default:
13931451         /* It seems unsupported registers return 0xFF */
13941452         return 0xFF;
r4575r4576
14051463   gb_dummy_ram_bank = auto_malloc( 0x2000 );
14061464   memset( gb_dummy_ram_bank, 0x00, 0x2000 );
14071465
1408   for(I = 0; I < MAX_ROMBANK; I++) {
1466   for(I = 0; I < MAX_ROMBANK; I++)
1467   {
14091468      ROMMap[I] = gb_dummy_rom_bank;
14101469   }
1411   for(I = 0; I < MAX_RAMBANK; I++) {
1470   for(I = 0; I < MAX_RAMBANK; I++)
1471   {
14121472      RAMMap[I] = gb_dummy_ram_bank;
14131473   }
14141474   ROMBank00 = 0;
r4575r4576
15571617
15581618   /* Check for presence of a header, and skip that header */
15591619   J = filesize % 0x4000;
1560   if ( J == 512 ) {
1620   if ( J == 512 )
1621   {
15611622      logerror( "Rom-header found, skipping\n" );
15621623      image_fseek( image, J, SEEK_SET );
15631624      filesize -= 512;
15641625   }
15651626
15661627   /* Verify that the file contains 16kb blocks */
1567   if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) ) {
1628   if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) )
1629   {
15681630      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid rom file size" );
15691631      return INIT_FAIL;
15701632   }
r4575r4576
15731635   gb_cart = auto_malloc( filesize );
15741636
15751637   /* Read cartridge */
1576   if ( image_fread( image, gb_cart, filesize ) != filesize ) {
1638   if ( image_fread( image, gb_cart, filesize ) != filesize )
1639   {
15771640      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" );
15781641      return INIT_FAIL;
15791642   }
r4575r4576
15821645   ROMBank00 = 0;
15831646
15841647   /* Check for presence of MMM01 mapper */
1585   if ( filesize >= 0x8000 ) {
1648   if ( filesize >= 0x8000 )
1649   {
15861650      static const UINT8 nintendo_logo[0x18] = {
15871651         0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B,
15881652         0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D,
r4575r4576
15901654      };
15911655      int   bytes_matched = 0;
15921656      gb_header = gb_cart + filesize - 0x8000;
1593      for ( I = 0; I < 0x18; I++ ) {
1594         if ( gb_header[0x0104 + I] == nintendo_logo[I] ) {
1657      for ( I = 0; I < 0x18; I++ )
1658      {
1659         if ( gb_header[0x0104 + I] == nintendo_logo[I] )
1660         {
15951661            bytes_matched++;
15961662         }
15971663      }
1598      if ( bytes_matched == 0x18 && gb_header[0x0147] >= 0x0B && gb_header[0x0147] <= 0x0D ) {
1664      if ( bytes_matched == 0x18 && gb_header[0x0147] >= 0x0B && gb_header[0x0147] <= 0x0D )
1665      {
15991666         ROMBank00 = ( filesize / 0x4000 ) - 2;
16001667         mmm01_bank_offset = ROMBank00;
1601      } else {
1668      }
1669      else
1670      {
16021671         gb_header = gb_cart;
16031672      }
16041673   }
16051674
16061675   /* Fill in our cart details */
1607   switch( gb_header[0x0147] ) {
1676   switch( gb_header[0x0147] )
1677   {
16081678   case 0x00:   MBCType = MBC_NONE;   CartType = 0;            break;
16091679   case 0x01:   MBCType = MBC_MBC1;   CartType = 0;            break;
16101680   case 0x02:   MBCType = MBC_MBC1;   CartType = RAM;            break;
r4575r4576
16401710   }
16411711
16421712   /* Check whether we're dealing with a (possible) Wisdom Tree game here */
1643   if ( gb_header[0x0147] == 0x00 ) {
1713   if ( gb_header[0x0147] == 0x00 )
1714   {
16441715      int count = 0;
1645      for( I = 0x0134; I <= 0x014C; I++ ) {
1716      for( I = 0x0134; I <= 0x014C; I++ )
1717      {
16461718         count += gb_header[I];
16471719      }
1648      if ( count == 0 ) {
1720      if ( count == 0 )
1721      {
16491722         MBCType = MBC_WISDOM;
16501723      }
16511724   }
16521725
16531726   /* Check if we're dealing with a Korean variant of the MBC1 mapper */
1654   if ( MBCType == MBC_MBC1 ) {
1655      if ( gb_header[0x13F] == 0x42 && gb_header[0x140] == 0x32 && gb_header[0x141] == 0x43 && gb_header[0x142] == 0x4B ) {
1727   if ( MBCType == MBC_MBC1 )
1728   {
1729      if ( gb_header[0x13F] == 0x42 && gb_header[0x140] == 0x32 && gb_header[0x141] == 0x43 && gb_header[0x142] == 0x4B )
1730      {
16561731         MBCType = MBC_MBC1_KOR;
16571732      }
16581733   }
1659   if ( MBCType == MBC_UNKNOWN ) {
1734   if ( MBCType == MBC_UNKNOWN )
1735   {
16601736      image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Unknown mapper type" );
16611737      return INIT_FAIL;
16621738   }
1663   if ( MBCType == MBC_MMM01 ) {
1739   if ( MBCType == MBC_MMM01 )
1740   {
16641741//      image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Mapper MMM01 is not supported yet" );
16651742//      return INIT_FAIL;
16661743   }
1667   if ( MBCType == MBC_MBC4 ) {
1744   if ( MBCType == MBC_MBC4 )
1745   {
16681746      image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Mapper MBC4 is not supported yet" );
16691747      return INIT_FAIL;
16701748   }
16711749   /* MBC7 support is still work-in-progress, so only enable it for debug builds */
16721750#ifndef MAME_DEBUG
1673   if ( MBCType == MBC_MBC7 ) {
1751   if ( MBCType == MBC_MBC7 )
1752   {
16741753      image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Mapper MBC7 is not supported yet" );
16751754      return INIT_FAIL;
16761755   }
16771756#endif
16781757
16791758   ROMBanks = filesize / 0x4000;
1680   switch( gb_header[0x0148] ) {
1759   switch( gb_header[0x0148] )
1760   {
16811761   case 0x52:
16821762      reported_rom_banks = 72;
16831763      break;
r4575r4576
16961776      reported_rom_banks = 256;
16971777      break;
16981778   }
1699   if ( ROMBanks != reported_rom_banks && MBCType != MBC_WISDOM ) {
1779   if ( ROMBanks != reported_rom_banks && MBCType != MBC_WISDOM )
1780   {
17001781      logerror( "Warning loading cartridge: Filesize and reported ROM banks don't match.\n" );
17011782   }
17021783
r4575r4576
17281809     96 (1100000)  1011111 (95)
17291810   */
17301811   ROMMask = I - 1;
1731   if ( ( ROMBanks & ROMMask ) != 0 ) {
1732      for( ; I & ROMBanks; I++ ) {
1812   if ( ( ROMBanks & ROMMask ) != 0 )
1813   {
1814      for( ; I & ROMBanks; I++ )
1815      {
17331816         ROMMap[ I ] = ROMMap[ I & ROMMask ];
17341817      }
17351818      ROMMask = I - 1;
17361819   }
17371820
17381821   /* Fill out the remaining rom bank pointers, if any. */
1739   for ( ; I < MAX_ROMBANK; I++ ) {
1822   for ( ; I < MAX_ROMBANK; I++ )
1823   {
17401824      ROMMap[ I ] = ROMMap[ I & ROMMask ];
17411825   }
17421826
r4575r4576
17751859   if( MBCType == MBC_MBC2 )
17761860      RAMBanks = 1;
17771861   /* MBC7 has 512 bytes(?) of internal RAM */
1778   if ( MBCType == MBC_MBC7 ) {
1862   if ( MBCType == MBC_MBC7 )
1863   {
17791864      RAMBanks = 1;
17801865   }
17811866
r4575r4576
17911876
17921877      /* Set up rest of the (mirrored) RAM pages */
17931878      RAMMask = I - 1;
1794      for ( ; I < MAX_RAMBANK; I++ ) {
1879      for ( ; I < MAX_RAMBANK; I++ )
1880      {
17951881         RAMMap[ I ] = RAMMap [ I & RAMMask ];
17961882      }
1797   } else {
1883   }
1884   else
1885   {
17981886      RAMMask = 0;
17991887   }
18001888
18011889   /* If there's an RTC claim memory to store the RTC contents */
1802   if ( CartType & TIMER ) {
1890   if ( CartType & TIMER )
1891   {
18031892      MBC3RTCData = auto_malloc( 0x2000 );
18041893   }
18051894
1806   if ( MBCType == MBC_TAMA5 ) {
1895   if ( MBCType == MBC_TAMA5 )
1896   {
18071897      MBC3RTCData = auto_malloc( 0x2000 );
18081898      memset( gbTama5Memory, 0xFF, sizeof(gbTama5Memory) );
18091899   }
r4575r4576
18281918   /* Decrement number of handled bits */
18291919   SIOCount--;
18301920   /* If all bits done, stop timer and trigger interrupt */
1831   if ( ! SIOCount ) {
1921   if ( ! SIOCount )
1922   {
18321923      SIOCONT &= 0x7F;
18331924      timer_enable( gb_serial_timer, 0 );
1834      cpu_set_input_line(machine->cpu[0], SIO_INT, HOLD_LINE);
1925      cputag_set_input_line(machine, "maincpu", SIO_INT, HOLD_LINE);
18351926   }
18361927}
18371928
1838INLINE void gb_timer_check_irq( running_machine *machine ) {
1929INLINE void gb_timer_check_irq( running_machine *machine )
1930{
18391931   gb_timer.reloading = 0;
1840   if ( gb_timer.triggering_irq ) {
1932   if ( gb_timer.triggering_irq )
1933   {
18411934      gb_timer.triggering_irq = 0;
1842      if ( TIMECNT == 0 ) {
1935      if ( TIMECNT == 0 )
1936      {
18431937         TIMECNT = TIMEMOD;
1844         cpu_set_input_line(machine->cpu[0], TIM_INT, HOLD_LINE );
1938         cputag_set_input_line(machine, "maincpu", TIM_INT, HOLD_LINE );
18451939         gb_timer.reloading = 1;
18461940      }
18471941   }
18481942}
18491943
1850static void gb_timer_increment( running_machine *machine ) {
1944static void gb_timer_increment( running_machine *machine )
1945{
18511946   gb_timer_check_irq(machine);
18521947
18531948   TIMECNT += 1;
1854   if ( TIMECNT == 0 ) {
1949   if ( TIMECNT == 0 )
1950   {
18551951      gb_timer.triggering_irq = 1;
18561952   }
18571953}
18581954
1859void gb_timer_callback(const device_config *device, int cycles) {
1955void gb_timer_callback(const device_config *device, int cycles)
1956{
18601957   UINT16 old_gb_divcount = gb_timer.divcount;
18611958   gb_timer.divcount += cycles;
18621959
18631960   gb_timer_check_irq(device->machine);
18641961
1865   if ( TIMEFRQ & 0x04 ) {
1962   if ( TIMEFRQ & 0x04 )
1963   {
18661964      UINT16 old_count = old_gb_divcount >> gb_timer.shift;
18671965      UINT16 new_count = gb_timer.divcount >> gb_timer.shift;
1868      if ( cycles > gb_timer.shift_cycles ) {
1966      if ( cycles > gb_timer.shift_cycles )
1967      {
18691968         gb_timer_increment(device->machine);
18701969         old_count++;
18711970      }
1872      if ( new_count != old_count ) {
1971      if ( new_count != old_count )
1972      {
18731973         gb_timer_increment(device->machine);
18741974      }
1875      if ( new_count << gb_timer.shift < gb_timer.divcount ) {
1975      if ( new_count << gb_timer.shift < gb_timer.divcount )
1976      {
18761977         gb_timer_check_irq(device->machine);
18771978      }
18781979   }
r4575r4576
18801981
18811982WRITE8_HANDLER ( gbc_io2_w )
18821983{
1883   switch( offset ) {
1984   switch( offset )
1985   {
18841986      case 0x0D:   /* KEY1 - Prepare speed switch */
1885         cpu_set_reg( space->machine->cpu[0], LR35902_SPEED, data );
1987         cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_SPEED, data );
18861988         return;
18871989      case 0x16:   /* RP - Infrared port */
18881990         break;
r4575r4576
18961998   gbc_video_w( space, offset, data );
18971999}
18982000
1899READ8_HANDLER( gbc_io2_r ) {
1900   switch( offset ) {
2001READ8_HANDLER( gbc_io2_r )
2002{
2003   switch( offset )
2004   {
19012005   case 0x0D:   /* KEY1 */
1902      return cpu_get_reg( space->machine->cpu[0], LR35902_SPEED );
2006      return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_SPEED );
19032007   case 0x16:   /* RP - Infrared port */
19042008      break;
19052009   default:
r4575r4576
19622066{
19632067   UINT8 data;
19642068
1965   if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) ) {
2069   if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) )
2070   {
19662071      offset ^= 0x0C;
19672072   }
19682073   data = gb_video_r( space, offset );
r4575r4576
19732078
19742079WRITE8_HANDLER ( megaduck_video_w )
19752080{
1976   if ( !offset ) {
2081   if ( !offset )
2082   {
19772083      data = BITSWAP8(data,7,3,5,4,2,1,0,6);
19782084   }
1979   if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) ) {
2085   if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) )
2086   {
19802087      offset ^= 0x0C;
19812088   }
19822089   gb_video_w(space, offset, data );
r4575r4576
19982105
19992106WRITE8_HANDLER( megaduck_sound_w2 )
20002107{
2001   switch(offset) {
2108   switch(offset)
2109   {
20022110      case 0x00:   gb_sound_w(devtag_get_device(space->machine, "custom"), 0x10, data );   break;
20032111      case 0x01:   gb_sound_w(devtag_get_device(space->machine, "custom"), 0x12, data );   break;
20042112      case 0x02:   gb_sound_w(devtag_get_device(space->machine, "custom"), 0x11, data );   break;
r4575r4576
20592167   filesize = image_length(image);
20602168   ROMBanks = filesize / 0x4000;
20612169
2062   if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) ) {
2170   if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) )
2171   {
20632172      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid rom file size" );
20642173      return INIT_FAIL;
20652174   }
r4575r4576
20682177   gb_cart = auto_malloc( filesize );
20692178
20702179   /* Read cartridge */
2071   if (image_fread (image, gb_cart, filesize) != filesize) {
2180   if (image_fread (image, gb_cart, filesize) != filesize)
2181   {
20722182      image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" );
20732183      return INIT_FAIL;
20742184   }
src/mess/machine/gamecom.c
r4575r4576
6565{
6666   UINT8 val = ( ( gamecom_internal_registers[SM8521_CLKT] & 0x3F ) + 1 ) & 0x3F;
6767   gamecom_internal_registers[SM8521_CLKT] = ( gamecom_internal_registers[SM8521_CLKT] & 0xC0 ) | val;
68   cpu_set_input_line(machine->cpu[0], CK_INT, HOLD_LINE );
68   cputag_set_input_line(machine, "maincpu", CK_INT, HOLD_LINE );
6969}
7070
7171MACHINE_RESET( gamecom )
r4575r4576
9090   gamecom_dma.enabled = 0;
9191
9292   memset( gamecom_internal_registers, 0x00, sizeof(gamecom_internal_registers) );
93   gamecom_internal_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), SM8521_URTT, 0xFF );
94   gamecom_internal_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), SM8521_URTS, 0x42 );
95   gamecom_internal_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), SM8521_WDTC, 0x38 );
93   gamecom_internal_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), SM8521_URTT, 0xFF );
94   gamecom_internal_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), SM8521_URTS, 0x42 );
95   gamecom_internal_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), SM8521_WDTC, 0x38 );
9696}
9797
9898static void gamecom_set_mmu( running_machine *machine, int mmu, UINT8 data )
r4575r4576
138138
139139   if ( stylus_x == column )
140140   {
141      cpu_set_reg( machine->cpu[0], SM8500_P0, row_data[stylus_y] & 0xFF );
142      cpu_set_reg( machine->cpu[0], SM8500_P1, ( cpu_get_reg( machine->cpu[0], SM8500_P1 ) & 0xFC ) | ( ( row_data[stylus_y] >> 8 ) & 0x03 ) );
141      cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P0, row_data[stylus_y] & 0xFF );
142      cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1, ( cpu_get_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1 ) & 0xFC ) | ( ( row_data[stylus_y] >> 8 ) & 0x03 ) );
143143   }
144144   else
145145   {
146      cpu_set_reg( machine->cpu[0], SM8500_P0, 0xFF );
147      cpu_set_reg( machine->cpu[0], SM8500_P1, ( cpu_get_reg( machine->cpu[0], SM8500_P1 ) & 0xFC ) | 0x03 );
146      cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P0, 0xFF );
147      cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1, ( cpu_get_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1 ) & 0xFC ) | 0x03 );
148148   }
149149}
150150
r4575r4576
158158
159159   switch( offset )
160160   {
161   case SM8521_IE0:   cpu_set_reg( space->machine->cpu[0], SM8500_IE0, data ); return;
162   case SM8521_IE1:   cpu_set_reg( space->machine->cpu[0], SM8500_IE1, data ); return;
163   case SM8521_IR0:   cpu_set_reg( space->machine->cpu[0], SM8500_IR0, data ); return;
164   case SM8521_IR1:   cpu_set_reg( space->machine->cpu[0], SM8500_IR1, data ); return;
165   case SM8521_P0:      cpu_set_reg( space->machine->cpu[0], SM8500_P0, data ); return;
166   case SM8521_P1:      cpu_set_reg( space->machine->cpu[0], SM8500_P1, data ); return;
167   case SM8521_P2:      cpu_set_reg( space->machine->cpu[0], SM8500_P2, data );
168            switch( ( cpu_get_reg( space->machine->cpu[0], SM8500_P1 ) << 8 ) | data )
161   case SM8521_IE0:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE0, data ); return;
162   case SM8521_IE1:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE1, data ); return;
163   case SM8521_IR0:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR0, data ); return;
164   case SM8521_IR1:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR1, data ); return;
165   case SM8521_P0:      cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0, data ); return;
166   case SM8521_P1:      cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1, data ); return;
167   case SM8521_P2:      cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2, data );
168            switch( ( cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1 ) << 8 ) | data )
169169            {
170170            case 0xFBFF:   /* column #0 */
171171                  /* P0 bit 0 cleared => 01 */
r4575r4576
227227                  /* P0 bit 7 cleared => 8B (button A) */
228228                  /* P1 bit 0 cleared => 8C (button B) */
229229                  /* P1 bit 1 cleared => 8D (button C) */
230               cpu_set_reg( space->machine->cpu[0], SM8500_P0, input_port_read(space->machine, "IN0") );
231               cpu_set_reg( space->machine->cpu[0], SM8500_P1, ( cpu_get_reg( space->machine->cpu[0], SM8500_P1 ) & 0xFC ) | ( input_port_read(space->machine, "IN1") & 0x03 ) );
230               cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0, input_port_read(space->machine, "IN0") );
231               cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1, ( cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1 ) & 0xFC ) | ( input_port_read(space->machine, "IN1") & 0x03 ) );
232232               break;
233233            case 0xFFFF:   /* keys #2 */
234234                  /* P0 bit 0 cleared => 88 (power) */
r4575r4576
241241                  /* P0 bit 7 cleared => A0 */
242242                  /* P1 bit 0 cleared => A0 */
243243                  /* P1 bit 1 cleared => A0 */
244               cpu_set_reg( space->machine->cpu[0], SM8500_P0, ( cpu_get_reg( space->machine->cpu[0], SM8500_P0 ) & 0xFC ) | ( input_port_read(space->machine, "IN2") & 0x03 ) );
245               cpu_set_reg( space->machine->cpu[0], SM8500_P1, 0xFF );
244               cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0, ( cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0 ) & 0xFC ) | ( input_port_read(space->machine, "IN2") & 0x03 ) );
245               cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1, 0xFF );
246246               break;
247247            }
248248            return;
249249   case SM8521_P3:
250250            /* P3 bit7 clear, bit6 set -> enable cartridge port #0? */
251251            /* P3 bit6 clear, bit7 set -> enable cartridge port #1? */
252            cpu_set_reg( space->machine->cpu[0], SM8500_P3, data );
252            cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3, data );
253253            switch( data & 0xc0 )
254254            {
255255            case 0x40: cartridge = cartridge1; break;
r4575r4576
262262            gamecom_set_mmu( space->machine, 3, gamecom_internal_registers[SM8521_MMU3] );
263263            gamecom_set_mmu( space->machine, 4, gamecom_internal_registers[SM8521_MMU4] );
264264            return;
265   case SM8521_SYS:   cpu_set_reg( space->machine->cpu[0], SM8500_SYS, data ); return;
266   case SM8521_CKC:   cpu_set_reg( space->machine->cpu[0], SM8500_CKC, data ); return;
267   case SM8521_SPH:   cpu_set_reg( space->machine->cpu[0], SM8500_SPH, data ); return;
268   case SM8521_SPL:   cpu_set_reg( space->machine->cpu[0], SM8500_SPL, data ); return;
269   case SM8521_PS0:   cpu_set_reg( space->machine->cpu[0], SM8500_PS0, data ); return;
270   case SM8521_PS1:   cpu_set_reg( space->machine->cpu[0], SM8500_PS1, data ); return;
271   case SM8521_P0C:   cpu_set_reg( space->machine->cpu[0], SM8500_P0C, data ); return;
272   case SM8521_P1C:   cpu_set_reg( space->machine->cpu[0], SM8500_P1C, data ); return;
273   case SM8521_P2C:   cpu_set_reg( space->machine->cpu[0], SM8500_P2C, data ); return;
274   case SM8521_P3C:   cpu_set_reg( space->machine->cpu[0], SM8500_P3C, data ); return;
265   case SM8521_SYS:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SYS, data ); return;
266   case SM8521_CKC:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_CKC, data ); return;
267   case SM8521_SPH:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPH, data ); return;
268   case SM8521_SPL:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPL, data ); return;
269   case SM8521_PS0:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS0, data ); return;
270   case SM8521_PS1:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS1, data ); return;
271   case SM8521_P0C:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0C, data ); return;
272   case SM8521_P1C:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1C, data ); return;
273   case SM8521_P2C:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2C, data ); return;
274   case SM8521_P3C:   cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3C, data ); return;
275275   case SM8521_MMU0:   /* disable bootstrap ROM? most likely not written to on game.com */
276276      logerror( "Write to MMU0\n" );
277277      break;
r4575r4576
397397   case SM8521_R12: case SM8521_R13: case SM8521_R14: case SM8521_R15:
398398      return 0;   /* NPW 22-Dec-2008 - Not sure what to do here */
399399      /*return sm85cpu_mem_readbyte( state, offset );*/
400   case SM8521_IE0:   return cpu_get_reg( space->machine->cpu[0], SM8500_IE0 );
401   case SM8521_IE1:   return cpu_get_reg( space->machine->cpu[0], SM8500_IE1 );
402   case SM8521_IR0:   return cpu_get_reg( space->machine->cpu[0], SM8500_IR0 );
403   case SM8521_IR1:   return cpu_get_reg( space->machine->cpu[0], SM8500_IR1 );
404   case SM8521_P0:      /* logerror( "%X: Read from P0\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( space->machine->cpu[0], SM8500_P0 );
405   case SM8521_P1:      /* logerror( "%X: Read from P1\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( space->machine->cpu[0], SM8500_P1 );
406   case SM8521_P2:      /* logerror( "%X: Read from P2\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( space->machine->cpu[0], SM8500_P2 );
407   case SM8521_P3:      return cpu_get_reg( space->machine->cpu[0], SM8500_P3 );
408   case SM8521_SYS:   return cpu_get_reg( space->machine->cpu[0], SM8500_SYS );
409   case SM8521_CKC:   return cpu_get_reg( space->machine->cpu[0], SM8500_CKC );
410   case SM8521_SPH:   return cpu_get_reg( space->machine->cpu[0], SM8500_SPH );
411   case SM8521_SPL:   return cpu_get_reg( space->machine->cpu[0], SM8500_SPL );
412   case SM8521_PS0:   return cpu_get_reg( space->machine->cpu[0], SM8500_PS0 );
413   case SM8521_PS1:   return cpu_get_reg( space->machine->cpu[0], SM8500_PS1 );
414   case SM8521_P0C:   return cpu_get_reg( space->machine->cpu[0], SM8500_P0C );
415   case SM8521_P1C:   return cpu_get_reg( space->machine->cpu[0], SM8500_P1C );
416   case SM8521_P2C:   return cpu_get_reg( space->machine->cpu[0], SM8500_P2C );
417   case SM8521_P3C:   return cpu_get_reg( space->machine->cpu[0], SM8500_P3C );
400   case SM8521_IE0:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE0 );
401   case SM8521_IE1:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE1 );
402   case SM8521_IR0:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR0 );
403   case SM8521_IR1:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR1 );
404   case SM8521_P0:      /* logerror( "%X: Read from P0\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0 );
405   case SM8521_P1:      /* logerror( "%X: Read from P1\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1 );
406   case SM8521_P2:      /* logerror( "%X: Read from P2\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2 );
407   case SM8521_P3:      return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3 );
408   case SM8521_SYS:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SYS );
409   case SM8521_CKC:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_CKC );
410   case SM8521_SPH:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPH );
411   case SM8521_SPL:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPL );
412   case SM8521_PS0:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS0 );
413   case SM8521_PS1:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS1 );
414   case SM8521_P0C:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0C );
415   case SM8521_P1C:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1C );
416   case SM8521_P2C:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2C );
417   case SM8521_P3C:   return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3C );
418418   case SM8521_TM0D:   return gamecom_timer[0].counter;
419419   case SM8521_TM1D:   return gamecom_timer[1].counter;
420420//   case SM8521_CLKT:   /* bit 0-5 read only, 6-7 read/write */
r4575r4576
490490   case 0x04:
491491      /* Extend RAM->VRAM */
492492      gamecom_dma.source_width = 64;
493      gamecom_dma.source_bank = memory_get_read_ptr(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xE000 );
493      gamecom_dma.source_bank = memory_get_read_ptr(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xE000 );
494494      gamecom_dma.dest_bank = &gamecom_vram[(gamecom_internal_registers[SM8521_DMVP] & 0x02) ? 0x2000 : 0x0000];
495495      break;
496496   case 0x06:
497497      /* VRAM->Extend RAM */
498498      gamecom_dma.source_bank = &gamecom_vram[(gamecom_internal_registers[SM8521_DMVP] & 0x01) ? 0x2000 : 0x0000];
499499      gamecom_dma.dest_width = 64;
500      gamecom_dma.dest_bank = memory_get_read_ptr(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xE000 );
500      gamecom_dma.dest_bank = memory_get_read_ptr(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xE000 );
501501      break;
502502   }
503503   gamecom_dma.source_current = gamecom_dma.source_width * gamecom_dma.source_y;
r4575r4576
604604      gamecom_dma.dest_current = gamecom_dma.dest_line;
605605   }
606606   gamecom_dma.enabled = 0;
607   cpu_set_input_line(device->machine->cpu[0], DMA_INT, HOLD_LINE );
607   cputag_set_input_line(device->machine, "maincpu", DMA_INT, HOLD_LINE );
608608}
609609
610610void gamecom_update_timers( const device_config *device, int cycles )
r4575r4576
619619         if ( gamecom_timer[0].counter == gamecom_timer[0].check_value )
620620         {
621621            gamecom_timer[0].counter = 0;
622            cpu_set_input_line(device->machine->cpu[0], TIM0_INT, HOLD_LINE );
622            cputag_set_input_line(device->machine, "maincpu", TIM0_INT, HOLD_LINE );
623623         }
624624      }
625625   }
r4575r4576
633633         if ( gamecom_timer[1].counter == gamecom_timer[1].check_value )
634634         {
635635            gamecom_timer[1].counter = 0;
636            cpu_set_input_line(device->machine->cpu[0], TIM1_INT, HOLD_LINE );
636            cputag_set_input_line(device->machine, "maincpu", TIM1_INT, HOLD_LINE );
637637         }
638638      }
639639   }
r4575r4576
651651
652652DEVICE_START( gamecom_cart )
653653{
654   internal_ram = device_get_info_ptr(device->machine->cpu[0], CPUINFO_PTR_SM8500_INTERNAL_RAM);
654   internal_ram = devtag_get_info_ptr(device->machine, "maincpu", CPUINFO_PTR_SM8500_INTERNAL_RAM);
655655}
656656
657657DEVICE_IMAGE_LOAD( gamecom_cart )
src/mess/machine/irisha.c
r4575r4576
100100
101101static PIC8259_SET_INT_LINE( irisha_pic_set_int_line )
102102{
103   cpu_set_input_line(device->machine->cpu[0], 0,interrupt ?  HOLD_LINE : CLEAR_LINE);
103   cputag_set_input_line(device->machine, "maincpu", 0, interrupt ?  HOLD_LINE : CLEAR_LINE);
104104}
105105
106106const struct pic8259_interface irisha_pic8259_config = {
src/mess/machine/galaxy.c
r4575r4576
6969
7070static void galaxy_setup_snapshot (running_machine *machine, const UINT8 * data, UINT32 size)
7171{
72   const device_config *cpu = cputag_get_cpu(machine, "maincpu");
73
7274   switch (size)
7375   {
7476      case GALAXY_SNAPSHOT_V1_SIZE:
75         cpu_set_reg(machine->cpu[0], Z80_AF,   data[0x00] | data[0x01]<<8);
76         cpu_set_reg(machine->cpu[0], Z80_BC,   data[0x04] | data[0x05]<<8);
77         cpu_set_reg(machine->cpu[0], Z80_DE,   data[0x08] | data[0x09]<<8);
78         cpu_set_reg(machine->cpu[0], Z80_HL,   data[0x0c] | data[0x0d]<<8);
79         cpu_set_reg(machine->cpu[0], Z80_IX,   data[0x10] | data[0x11]<<8);
80         cpu_set_reg(machine->cpu[0], Z80_IY,   data[0x14] | data[0x15]<<8);
81         cpu_set_reg(machine->cpu[0], Z80_PC,   data[0x18] | data[0x19]<<8);
82         cpu_set_reg(machine->cpu[0], Z80_SP,   data[0x1c] | data[0x1d]<<8);
83         cpu_set_reg(machine->cpu[0], Z80_AF2,  data[0x20] | data[0x21]<<8);
84         cpu_set_reg(machine->cpu[0], Z80_BC2,  data[0x24] | data[0x25]<<8);
85         cpu_set_reg(machine->cpu[0], Z80_DE2,  data[0x28] | data[0x29]<<8);
86         cpu_set_reg(machine->cpu[0], Z80_HL2,  data[0x2c] | data[0x2d]<<8);
87         cpu_set_reg(machine->cpu[0], Z80_IFF1, data[0x30]);
88         cpu_set_reg(machine->cpu[0], Z80_IFF2, data[0x34]);
89         cpu_set_reg(machine->cpu[0], Z80_HALT, data[0x38]);
90         cpu_set_reg(machine->cpu[0], Z80_IM,   data[0x3c]);
91         cpu_set_reg(machine->cpu[0], Z80_I,    data[0x40]);
92         cpu_set_reg(machine->cpu[0], Z80_R,    (data[0x44]&0x7f) | (data[0x48]&0x80));
77         cpu_set_reg(cpu, Z80_AF,   data[0x00] | data[0x01] << 8);
78         cpu_set_reg(cpu, Z80_BC,   data[0x04] | data[0x05] << 8);
79         cpu_set_reg(cpu, Z80_DE,   data[0x08] | data[0x09] << 8);
80         cpu_set_reg(cpu, Z80_HL,   data[0x0c] | data[0x0d] << 8);
81         cpu_set_reg(cpu, Z80_IX,   data[0x10] | data[0x11] << 8);
82         cpu_set_reg(cpu, Z80_IY,   data[0x14] | data[0x15] << 8);
83         cpu_set_reg(cpu, Z80_PC,   data[0x18] | data[0x19] << 8);
84         cpu_set_reg(cpu, Z80_SP,   data[0x1c] | data[0x1d] << 8);
85         cpu_set_reg(cpu, Z80_AF2,  data[0x20] | data[0x21] << 8);
86         cpu_set_reg(cpu, Z80_BC2,  data[0x24] | data[0x25] << 8);
87         cpu_set_reg(cpu, Z80_DE2,  data[0x28] | data[0x29] << 8);
88         cpu_set_reg(cpu, Z80_HL2,  data[0x2c] | data[0x2d] << 8);
89         cpu_set_reg(cpu, Z80_IFF1, data[0x30]);
90         cpu_set_reg(cpu, Z80_IFF2, data[0x34]);
91         cpu_set_reg(cpu, Z80_HALT, data[0x38]);
92         cpu_set_reg(cpu, Z80_IM,   data[0x3c]);
93         cpu_set_reg(cpu, Z80_I,    data[0x40]);
94         cpu_set_reg(cpu, Z80_R,    (data[0x44] & 0x7f) | (data[0x48] & 0x80));
9395
94         memcpy (mess_ram, data+0x084c, (mess_ram_size < 0x1800) ? mess_ram_size : 0x1800);
96         memcpy (mess_ram, data + 0x084c, (mess_ram_size < 0x1800) ? mess_ram_size : 0x1800);
9597
9698         break;
9799      case GALAXY_SNAPSHOT_V2_SIZE:
98         cpu_set_reg(machine->cpu[0], Z80_AF,   data[0x00] | data[0x01]<<8);
99         cpu_set_reg(machine->cpu[0], Z80_BC,   data[0x02] | data[0x03]<<8);
100         cpu_set_reg(machine->cpu[0], Z80_DE,   data[0x04] | data[0x05]<<8);
101         cpu_set_reg(machine->cpu[0], Z80_HL,   data[0x06] | data[0x07]<<8);
102         cpu_set_reg(machine->cpu[0], Z80_IX,   data[0x08] | data[0x09]<<8);
103         cpu_set_reg(machine->cpu[0], Z80_IY,   data[0x0a] | data[0x0b]<<8);
104         cpu_set_reg(machine->cpu[0], Z80_PC,   data[0x0c] | data[0x0d]<<8);
105         cpu_set_reg(machine->cpu[0], Z80_SP,   data[0x0e] | data[0x0f]<<8);
106         cpu_set_reg(machine->cpu[0], Z80_AF2,  data[0x10] | data[0x11]<<8);
107         cpu_set_reg(machine->cpu[0], Z80_BC2,  data[0x12] | data[0x13]<<8);
108         cpu_set_reg(machine->cpu[0], Z80_DE2,  data[0x14] | data[0x15]<<8);
109         cpu_set_reg(machine->cpu[0], Z80_HL2,  data[0x16] | data[0x17]<<8);
100         cpu_set_reg(cpu, Z80_AF,   data[0x00] | data[0x01] << 8);
101         cpu_set_reg(cpu, Z80_BC,   data[0x02] | data[0x03] << 8);
102         cpu_set_reg(cpu, Z80_DE,   data[0x04] | data[0x05] << 8);
103         cpu_set_reg(cpu, Z80_HL,   data[0x06] | data[0x07] << 8);
104         cpu_set_reg(cpu, Z80_IX,   data[0x08] | data[0x09] << 8);
105         cpu_set_reg(cpu, Z80_IY,   data[0x0a] | data[0x0b] << 8);
106         cpu_set_reg(cpu, Z80_PC,   data[0x0c] | data[0x0d] << 8);
107         cpu_set_reg(cpu, Z80_SP,   data[0x0e] | data[0x0f] << 8);
108         cpu_set_reg(cpu, Z80_AF2,  data[0x10] | data[0x11] << 8);
109         cpu_set_reg(cpu, Z80_BC2,  data[0x12] | data[0x13] << 8);
110         cpu_set_reg(cpu, Z80_DE2,  data[0x14] | data[0x15] << 8);
111         cpu_set_reg(cpu, Z80_HL2,  data[0x16] | data[0x17] << 8);
110112
111         cpu_set_reg(machine->cpu[0], Z80_IFF1, data[0x18]&0x01);
112         cpu_set_reg(machine->cpu[0], Z80_IFF2, 0);
113         cpu_set_reg(cpu, Z80_IFF1, data[0x18] & 0x01);
114         cpu_set_reg(cpu, Z80_IFF2, 0);
113115
114         cpu_set_reg(machine->cpu[0], Z80_HALT, 0);
116         cpu_set_reg(cpu, Z80_HALT, 0);
115117
116         cpu_set_reg(machine->cpu[0], Z80_IM,   (data[0x18]>>1)&0x03);
118         cpu_set_reg(cpu, Z80_IM,   (data[0x18] >> 1) & 0x03);
117119
118         cpu_set_reg(machine->cpu[0], Z80_I,    data[0x19]);
119         cpu_set_reg(machine->cpu[0], Z80_R,    data[0x1a]);
120         cpu_set_reg(cpu, Z80_I,    data[0x19]);
121         cpu_set_reg(cpu, Z80_R,    data[0x1a]);
120122
121         memcpy (mess_ram, data+0x0834, (mess_ram_size < 0x1800) ? mess_ram_size : 0x1800);
123         memcpy (mess_ram, data + 0x0834, (mess_ram_size < 0x1800) ? mess_ram_size : 0x1800);
122124
123125         break;
124126   }
125127
126   cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE);
127   cpu_set_input_line(machine->cpu[0], INPUT_LINE_IRQ0, CLEAR_LINE);
128   cpu_set_input_line(cpu, INPUT_LINE_NMI, CLEAR_LINE);
129   cpu_set_input_line(cpu, INPUT_LINE_IRQ0, CLEAR_LINE);
128130}
129131
130132SNAPSHOT_LOAD( galaxy )
r4575r4576
155157
156158DRIVER_INIT( galaxy )
157159{
158   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
159   memory_install_read8_handler(space, 0x2800, 0x2800+mess_ram_size-1, 0, 0, SMH_BANK1);
160   memory_install_write8_handler(space, 0x2800, 0x2800+mess_ram_size-1, 0, 0, SMH_BANK1);
161   memory_set_bankptr(machine,1, mess_ram);
160   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
161   memory_install_read8_handler( space, 0x2800, 0x2800 + mess_ram_size - 1, 0, 0, SMH_BANK1);
162   memory_install_write8_handler(space, 0x2800, 0x2800 + mess_ram_size - 1, 0, 0, SMH_BANK1);
163   memory_set_bankptr(machine, 1, mess_ram);
162164
163   if (mess_ram_size < (6+48)*1024)
165   if (mess_ram_size < (6 + 48) * 1024)
164166   {
165      memory_install_read8_handler(space, 0x2800+mess_ram_size, 0xffff, 0, 0, SMH_NOP);
166      memory_install_write8_handler(space, 0x2800+mess_ram_size, 0xffff, 0, 0, SMH_NOP);
167      memory_install_read8_handler( space, 0x2800 + mess_ram_size, 0xffff, 0, 0, SMH_NOP);
168      memory_install_write8_handler(space, 0x2800 + mess_ram_size, 0xffff, 0, 0, SMH_NOP);
167169   }
168170}
169171
r4575r4576
173175
174176MACHINE_RESET( galaxy )
175177{
176   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
178   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
177179   
178180   /* ROM 2 enable/disable */
179181   memory_install_read8_handler(space, 0x1000, 0x1fff, 0, 0, input_port_read(machine, "ROM2") ? SMH_BANK10 : SMH_NOP);
180182   memory_install_write8_handler(space, 0x1000, 0x1fff, 0, 0, SMH_NOP);
181183   memory_set_bankptr(machine,10, memory_region(machine, "maincpu") + 0x1000);
182184
183   cpu_set_irq_callback(machine->cpu[0], galaxy_irq_callback);
185   cpu_set_irq_callback(cputag_get_cpu(machine, "maincpu"), galaxy_irq_callback);
184186   galaxy_interrupts_enabled = TRUE;
185187
186188   gal_video_timer = timer_alloc(machine, gal_video, NULL);
r4575r4576
195197MACHINE_RESET( galaxyp )
196198{
197199   UINT8 *ROM = memory_region(machine, "maincpu");
198   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
200   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
199201   
200   cpu_set_irq_callback(machine->cpu[0], galaxy_irq_callback);
202   cpu_set_irq_callback(cputag_get_cpu(machine, "maincpu"), galaxy_irq_callback);
201203
202204   ROM[0x0037] = 0x29;
203205   ROM[0x03f9] = 0xcd;
src/mess/machine/intv.c
r4575r4576
505505/* Set Reset and INTR/INTRM Vector */
506506MACHINE_RESET( intv )
507507{
508   cpu_set_input_line_vector(machine->cpu[0], CP1610_RESET, 0x1000);
508   cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), CP1610_RESET, 0x1000);
509509
510510   /* These are actually the same vector, and INTR is unused */
511   cpu_set_input_line_vector(machine->cpu[0], CP1610_INT_INTRM, 0x1004);
512   cpu_set_input_line_vector(machine->cpu[0], CP1610_INT_INTR,  0x1004);
511   cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), CP1610_INT_INTRM, 0x1004);
512   cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), CP1610_INT_INTR,  0x1004);
513513
514514   return;
515515}
r4575r4576
517517
518518static TIMER_CALLBACK(intv_interrupt_complete)
519519{
520   cpu_set_input_line(machine->cpu[0], CP1610_INT_INTRM, CLEAR_LINE);
520   cputag_set_input_line(machine, "maincpu", CP1610_INT_INTRM, CLEAR_LINE);
521521}
522522
523523INTERRUPT_GEN( intv_interrupt )
524524{
525   cpu_set_input_line(device->machine->cpu[0], CP1610_INT_INTRM, ASSERT_LINE);
525   cputag_set_input_line(device->machine, "maincpu", CP1610_INT_INTRM, ASSERT_LINE);
526526   sr1_int_pending = 1;
527   timer_set(device->machine, cpu_clocks_to_attotime(device->machine->cpu[0], 3791), NULL, 0, intv_interrupt_complete);
527   timer_set(device->machine, cputag_clocks_to_attotime(device->machine, "maincpu", 3791), NULL, 0, intv_interrupt_complete);
528528   stic_screenrefresh(device->machine);
529529}
530530
src/mess/machine/jupiter.c
r4575r4576
8383
8484MACHINE_START( jupiter )
8585{
86   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
86   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
8787
8888   logerror("jupiter_init\r\n");
8989   logerror("data: %p\n", jupiter_data);
r4575r4576
242242      jupiter_data_type = JUPITER_NONE;
243243   }
244244}
245
src/mess/machine/genesis.c
r4575r4576
622622      memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000);
623623      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x400000);
624624
625      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130ff, 0, 0, genesis_ssf2_bank_w);
625      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130ff, 0, 0, genesis_ssf2_bank_w);
626626   }
627627
628628   if (cart_type == LIONK3 || cart_type == SKINGKONG)
r4575r4576
630630      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */
631631      memcpy(&ROM[0x200000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */
632632
633      memory_install_readwrite16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw);
634      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w);
633      memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw);
634      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w);
635635   }
636636
637637   if (cart_type == SDK99)
r4575r4576
639639      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x300000); /* default rom */
640640      memcpy(&ROM[0x300000], &ROM[VIRGIN_COPY_GEN], 0x100000); /* default rom */
641641
642      memory_install_readwrite16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw);
643      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w);
642      memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw);
643      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w);
644644   }
645645
646646   if (cart_type == REDCLIFF)
647647   {
648      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r);
649      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r);
648      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r);
649      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r);
650650   }
651651
652652   if (cart_type == REDCL_EN)
r4575r4576
660660
661661      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN + 4], 0x200000); /* default rom */
662662
663      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r);
664      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r);
663      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r);
664      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r);
665665   }
666666
667667   if (cart_type == RADICA)
r4575r4576
669669      memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); // keep a copy for later banking.. making use of huge ROM_REGION allocated to genesis driver
670670      memcpy(&ROM[0x800000], &ROM[VIRGIN_COPY_GEN], 0x400000); // wraparound banking (from hazemd code)
671671      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x400000);
672      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa1307f, 0, 0, radica_bank_select);
672      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa1307f, 0, 0, radica_bank_select);
673673   }
674674
675675   if (cart_type == KOF99)
676676   {
677677      //memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x300000);
678      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, kof99_0xA13000_r);
679      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13002, 0xa13003, 0, 0, kof99_0xA13002_r);
680      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa1303e, 0xa1303f, 0, 0, kof99_00A1303E_r);
678      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, kof99_0xA13000_r);
679      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13002, 0xa13003, 0, 0, kof99_0xA13002_r);
680      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa1303e, 0xa1303f, 0, 0, kof99_00A1303E_r);
681681   }
682682
683683   if (cart_type == SOULBLAD)
684684   {
685      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, soulb_0x400002_r);
686      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, soulb_0x400004_r);
687      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, soulb_0x400006_r);
685      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, soulb_0x400002_r);
686      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, soulb_0x400004_r);
687      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, soulb_0x400006_r);
688688   }
689689
690690   if (cart_type == MJLOVER)
691691   {
692      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r);
693      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r);
692      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r);
693      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r);
694694   }
695695
696696   if (cart_type == SQUIRRELK)
697697   {
698      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_r);
699      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_w);
698      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_r);
699      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_w);
700700   }
701701
702702   if (cart_type == SMOUSE)
703703   {
704      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, smous_prot_r);
704      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, smous_prot_r);
705705   }
706706
707707   if (cart_type == SMB)
708708   {
709      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smbro_prot_r);
709      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smbro_prot_r);
710710   }
711711
712712   if (cart_type == SMB2)
713713   {
714      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smb2_extra_r);
714      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smb2_extra_r);
715715   }
716716
717717   if (cart_type == KAIJU)
r4575r4576
720720      memcpy(&ROM[0x600000], &ROM[VIRGIN_COPY_GEN], 0x200000);
721721      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000);
722722
723      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w);
723      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w);
724724   }
725725
726726   if (cart_type == CHINFIGHT3)
r4575r4576
729729      memcpy(&ROM[0x600000], &ROM[VIRGIN_COPY_GEN], 0x200000);
730730      memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000);
731731
732      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r);
733      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w);
732      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r);
733      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w);
734734   }
735735
736736   if (cart_type == LIONK2)
737737   {
738      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, lion2_prot1_r);
739      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, lion2_prot2_r);
740      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, lion2_prot1_w);
741      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, lion2_prot2_w);
738      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, lion2_prot1_r);
739      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, lion2_prot2_r);
740      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, lion2_prot1_w);
741      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, lion2_prot2_w);
742742   }
743743
744744   if (cart_type == BUGSLIFE)
745745   {
746      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, bugl_extra_r);
746      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, bugl_extra_r);
747747   }
748748
749749   if (cart_type == ELFWOR)
750750   {
751751   /* It return (0x55 @ 0x400000 OR 0xc9 @ 0x400004) AND (0x0f @ 0x400002 OR 0x18 @ 0x400006). It is probably best to add handlers for all 4 addresses. */
752752
753      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, elfwor_0x400000_r);
754      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, elfwor_0x400002_r);
755      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, elfwor_0x400004_r);
756      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, elfwor_0x400006_r);
753      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, elfwor_0x400000_r);
754      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, elfwor_0x400002_r);
755      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, elfwor_0x400004_r);
756      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, elfwor_0x400006_r);
757757   }
758758
759759   if (cart_type == ROCKMANX3)
760760   {
761      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, rx3_extra_r);
761      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, rx3_extra_r);
762762   }
763763
764764   if (cart_type == SBUBBOB)
765765   {
766      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, sbub_extra1_r);
767      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, sbub_extra2_r);
766      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, sbub_extra1_r);
767      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, sbub_extra2_r);
768768   }
769769
770770   if (cart_type == KOF98)
771771   {
772      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x480000, 0x480001, 0, 0, g_kof98_aa_r);
773      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r);
774      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r);
775      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x488880, 0x488881, 0, 0, g_kof98_aa_r);
772      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x480000, 0x480001, 0, 0, g_kof98_aa_r);
773      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r);
774      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r);
775      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x488880, 0x488881, 0, 0, g_kof98_aa_r);
776776
777      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r);
778      memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r);
777      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r);
778      memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r);
779779   }
780780
781781   if (cart_type == REALTEC)
r4575r4576
790790         memcpy(ROM + mirroraddr, ROM + relocate + 0x7e000, 0x002000); /* copy last 8kb across the whole rom region */
791791      }
792792
793      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, realtec_400000_w);
794      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x402000, 0x402001, 0, 0, realtec_402000_w);
795      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x404000, 0x404001, 0, 0, realtec_404000_w);
793      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, realtec_400000_w);
794      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x402000, 0x402001, 0, 0, realtec_402000_w);
795      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x404000, 0x404001, 0, 0, realtec_404000_w);
796796   }
797797
798798   if (cart_type == SUP19IN1)
799799   {
800800      memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); // allow hard reset to menu
801      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank);
801      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank);
802802   }
803803
804804   if (cart_type == SUP15IN1)
805805   {
806806      memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x200000); // allow hard reset to menu
807      memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank);
807      memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank);
808808   }
809809
810810   if (has_sram)
811811   {
812        memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_read);
813        memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_write);
814        memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle);
812        memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_read);
813        memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_write);
814        memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle);
815815   }
816816
817817
818818   /* install NOP handler for TMSS */
819   memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa14000, 0xa14003, 0, 0, genesis_TMSS_bank_w);
819   memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa14000, 0xa14003, 0, 0, genesis_TMSS_bank_w);
820820}
821821
822822
src/mess/drivers/jaguar.c
r4575r4576
101101
102102static MACHINE_RESET( jaguar )
103103{
104   cpu_set_irq_callback(machine->cpu[0], jaguar_irq_callback);
104   cpu_set_irq_callback(cputag_get_cpu(machine, "maincpu"), jaguar_irq_callback);
105105
106106   *((UINT32 *) jaguar_gpu_ram) = 0x3d0dead;
107107
r4575r4576
129129   jaguar_dsp_resume(machine);
130130
131131   /* halt the CPUs */
132   jaguargpu_ctrl_w(machine->cpu[1], G_CTRL, 0, 0);
133   jaguardsp_ctrl_w(machine->cpu[2], D_CTRL, 0, 0);
132   jaguargpu_ctrl_w(cputag_get_cpu(machine, "gpu"), G_CTRL, 0, 0);
133   jaguardsp_ctrl_w(cputag_get_cpu(machine, "audiocpu"), D_CTRL, 0, 0);
134134
135135   /* init the sound system */
136136   cojag_sound_reset(machine);
r4575r4576
148148
149149static READ32_HANDLER( gpuctrl_r )
150150{
151   return jaguargpu_ctrl_r(space->machine->cpu[1], offset);
151   return jaguargpu_ctrl_r(cputag_get_cpu(space->machine, "gpu"), offset);
152152}
153153
154154
155155static WRITE32_HANDLER( gpuctrl_w )
156156{
157   jaguargpu_ctrl_w(space->machine->cpu[1], offset, data, mem_mask);
157   jaguargpu_ctrl_w(cputag_get_cpu(space->machine, "gpu"), offset, data, mem_mask);
158158}
159159
160160
r4575r4576
167167
168168static READ32_HANDLER( dspctrl_r )
169169{
170   return jaguardsp_ctrl_r(space->machine->cpu[1], offset);
170   return jaguardsp_ctrl_r(cputag_get_cpu(space->machine, "audiocpu"), offset);
171171}
172172
173173
174174static WRITE32_HANDLER( dspctrl_w )
175175{
176   jaguardsp_ctrl_w(space->machine->cpu[2], offset, data, mem_mask);
176   jaguardsp_ctrl_w(cputag_get_cpu(space->machine, "audiocpu"), offset, data, mem_mask);
177177}
178178
179179
r4575r4576
462462   MDRV_CPU_CONFIG(gpu_config)
463463   MDRV_CPU_PROGRAM_MAP(gpu_map,0)
464464
465   MDRV_CPU_ADD("dsp", JAGUARDSP, JAGUAR_CLOCK/2)
465   MDRV_CPU_ADD("audiocpu", JAGUARDSP, JAGUAR_CLOCK/2)
466466   MDRV_CPU_CONFIG(dsp_config)
467467   MDRV_CPU_PROGRAM_MAP(dsp_map,0)
468468
r4575r4576
529529   offs_t quickload_begin = 0x4000;
530530   quickload_size = MIN(quickload_size, 0x200000 - quickload_begin);
531531   image_fread(image, &memory_region(image->machine, "maincpu")[quickload_begin], quickload_size);
532   cpu_set_reg(image->machine->cpu[0], REG_GENPC, quickload_begin);
532   cpu_set_reg(cputag_get_cpu(image->machine, "maincpu"), REG_GENPC, quickload_begin);
533533   return INIT_PASS;
534534}
535535
src/mess/drivers/ip22.c
r4575r4576
6969      va_start( v, s_fmt );
7070      vsprintf( buf, s_fmt, v );
7171      va_end( v );
72      logerror( "%08x: %s", cpu_get_pc(machine->cpu[0]), buf );
72      logerror("%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf);
7373   }
7474}
7575
r4575r4576
150150   // if it's not masked, also assert it now at the CPU
151151   if (int3_regs[1] & source_mask)
152152   {
153      cpu_set_input_line(machine->cpu[0], MIPS3_IRQ0, ASSERT_LINE);
153      cputag_set_input_line(machine, "maincpu", MIPS3_IRQ0, ASSERT_LINE);
154154   }
155155}
156156
r4575r4576
162162
163163#ifdef UNUSED_FUNCTION
164164// raise a local1 interrupt
165static void int3_raise_local1_irq(UINT8 source_mask)
165static void int3_raise_local1_irq(running_machine *machine, UINT8 source_mask)
166166{
167167   // signal the interrupt is pending
168168   int3_regs[2] |= source_mask;
r4575r4576
170170   // if it's not masked, also assert it now at the CPU
171171   if (int3_regs[2] & source_mask)
172172   {
173      cpu_set_input_line(Machine->cpu[0], MIPS3_IRQ1, ASSERT_LINE);
173      cputag_set_input_line(machine, "maincpu", MIPS3_IRQ1, ASSERT_LINE);
174174   }
175175}
176176
r4575r4576
321321      // if no local0 interrupts now, clear the input to the CPU
322322      if ((int3_regs[0] & int3_regs[1]) == 0)
323323      {
324         cpu_set_input_line(machine->cpu[0], MIPS3_IRQ0, CLEAR_LINE);
324         cputag_set_input_line(machine, "maincpu", MIPS3_IRQ0, CLEAR_LINE);
325325      }
326326      else
327327      {
328         cpu_set_input_line(machine->cpu[0], MIPS3_IRQ0, ASSERT_LINE);
328         cputag_set_input_line(machine, "maincpu", MIPS3_IRQ0, ASSERT_LINE);
329329      }
330330
331331      // if no local1 interrupts now, clear the input to the CPU
332332      if ((int3_regs[2] & int3_regs[3]) == 0)
333333      {
334         cpu_set_input_line(machine->cpu[0], MIPS3_IRQ1, CLEAR_LINE);
334         cputag_set_input_line(machine, "maincpu", MIPS3_IRQ1, CLEAR_LINE);
335335      }
336336      else
337337      {
338         cpu_set_input_line(machine->cpu[0], MIPS3_IRQ1, ASSERT_LINE);
338         cputag_set_input_line(machine, "maincpu", MIPS3_IRQ1, ASSERT_LINE);
339339      }
340340      break;
341341   case 0xb0/4:
r4575r4576
12021202
12031203static void scsi_irq(running_machine *machine, int state)
12041204{
1205   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
1205   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
12061206
12071207   if (state)
12081208   {
r4575r4576
12201220            int length;
12211221
12221222            rptr = memory_read_dword(space, nHPC_SCSI0Descriptor);
1223            length = memory_read_dword(space, nHPC_SCSI0Descriptor+4) & 0x3fff;
1223            length = memory_read_dword(space, nHPC_SCSI0Descriptor + 4) & 0x3fff;
12241224
12251225/*              mame_printf_info("DMA to device: length %x\n", length);
12261226                mame_printf_info("first words: %08x %08x %08x %08x\n",
src/mess/drivers/gmaster.c
r4575r4576
2828
2929static READ8_HANDLER( gmaster_io_r )
3030{
31    UINT8 data=0;
32    if (gmaster.ports[2]&1) {
33   data=memory_region(space->machine, "maincpu")[0x4000+offset];
34   logerror("%.4x external memory %.4x read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset,data);
35    } else {
36   switch (offset) {
37   case 1:
38       data=gmaster_video.pixels[gmaster_video.y][gmaster_video.x];
39       logerror("%.4x lcd x:%.2x y:%.2x %.4x read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000+offset,data);
40       if (!(gmaster_video.mode)&&gmaster_video.delayed) gmaster_video.x++;
41       gmaster_video.delayed=TRUE;
42       break;
43   default:
44     logerror("%.4x memory %.4x read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset,data);
45   }
31    UINT8 data = 0;
32    if (gmaster.ports[2] & 1)
33   {
34      data = memory_region(space->machine, "maincpu")[0x4000 + offset];
35      logerror("%.4x external memory %.4x read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data);
36    }
37   else
38   {
39      switch (offset)
40      {
41      case 1:
42         data=gmaster_video.pixels[gmaster_video.y][gmaster_video.x];
43         logerror("%.4x lcd x:%.2x y:%.2x %.4x read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000 + offset, data);
44         if (!(gmaster_video.mode) && gmaster_video.delayed)
45            gmaster_video.x++;
46         gmaster_video.delayed = TRUE;
47         break;
48      default:
49         logerror("%.4x memory %.4x read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data);
50      }
4651    }
4752    return data;
4853}
r4575r4576
5156
5257static WRITE8_HANDLER( gmaster_io_w )
5358{
54    if (gmaster.ports[2]&1) {
55   memory_region(space->machine, "maincpu")[0x4000+offset]=data;
56   logerror("%.4x external memory %.4x written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset, data);
57    } else {
58   switch (offset) {
59   case 0:
60       gmaster_video.delayed=FALSE;
61       logerror("%.4x lcd %.4x written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset, data);
62       // e2 af a4 a0 a9 falling block init for both halves
63       if ((data&0xfc)==0xb8) {
64      gmaster_video.index=0;
65      gmaster_video.data[gmaster_video.index]=data;
66      gmaster_video.y=BLITTER_Y;
67       } else if ((data&0xc0)==0) {
68      gmaster_video.x=data;
69       } else if ((data&0xf0)==0xe0) {
70      gmaster_video.mode=(data&0xe)?FALSE:TRUE;
71       }
72       gmaster_video.data[gmaster_video.index]=data;
73       gmaster_video.index=(gmaster_video.index+1)&7;
74       break;
75   case 1:
76       gmaster_video.delayed=FALSE;
77       if (gmaster_video.x<ARRAY_LENGTH(gmaster_video.pixels[0])) // continental galaxy flutlicht
78      gmaster_video.pixels[gmaster_video.y][gmaster_video.x]=data;
79       logerror("%.4x lcd x:%.2x y:%.2x %.4x written %.2x\n",
80           (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000+offset, data);
81       gmaster_video.x++;
59    if (gmaster.ports[2] & 1)
60   {
61      memory_region(space->machine, "maincpu")[0x4000 + offset] = data;
62      logerror("%.4x external memory %.4x written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data);
63    }
64   else
65   {
66      switch (offset)
67      {
68      case 0:
69         gmaster_video.delayed=FALSE;
70         logerror("%.4x lcd %.4x written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data);
71         // e2 af a4 a0 a9 falling block init for both halves
72         if ((data & 0xfc) == 0xb8)
73         {
74            gmaster_video.index = 0;
75            gmaster_video.data[gmaster_video.index] = data;
76            gmaster_video.y = BLITTER_Y;
77         }
78         else if ((data & 0xc0) == 0)
79         {
80            gmaster_video.x = data;
81         }
82         else if ((data & 0xf0) == 0xe0)
83         {
84            gmaster_video.mode = (data & 0xe) ? FALSE : TRUE;
85         }
86         gmaster_video.data[gmaster_video.index] = data;
87         gmaster_video.index = (gmaster_video.index + 1) & 7;
88         break;
89      case 1:
90         gmaster_video.delayed = FALSE;
91         if (gmaster_video.x < ARRAY_LENGTH(gmaster_video.pixels[0])) // continental galaxy flutlicht
92            gmaster_video.pixels[gmaster_video.y][gmaster_video.x] = data;
93         logerror("%.4x lcd x:%.2x y:%.2x %.4x written %.2x\n",
94            (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000 + offset, data);
95         gmaster_video.x++;
8296/* 02 b8 1a
8397   02 bb 1a
8498   02 bb 22
r4575r4576
93107   rr w rr w rr w rr w rr w rr w rr w rr w
94108   4000 ee
95109*/
96       break;
97   default:
98     logerror("%.4x memory %.4x written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset, data);
110         break;
111      default:
112         logerror("%.4x memory %.4x written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data);
99113   }
100114    }
101115}
102116
103117static READ8_HANDLER( gmaster_port_r )
104118{
105//    UINT8 data=gmaster.ports[offset];
106    UINT8 data=0xff;
107    switch (offset) {
108    case UPD7810_PORTA:
109   data=input_port_read(space->machine, "JOY");
110   break;
111    default:
112      logerror("%.4x port %d read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC),offset,data);
119//   UINT8 data = gmaster.ports[offset];
120    UINT8 data = 0xff;
121    switch (offset)
122   {
123   case UPD7810_PORTA:
124      data = input_port_read(space->machine, "JOY");
125      break;
126   default:
127      logerror("%.4x port %d read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), offset, data);
113128    }
114129    return data;
115130}
116131
117132static WRITE8_HANDLER( gmaster_port_w )
118133{
119    gmaster.ports[offset]=data;
120    logerror("%.4x port %d written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), offset, data);
121    switch (offset) {
122    case UPD7810_PORTC:
123   gmaster_video.y=BLITTER_Y;
124   break;
134    gmaster.ports[offset] = data;
135    logerror("%.4x port %d written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), offset, data);
136    switch (offset)
137   {
138      case UPD7810_PORTC:
139         gmaster_video.y = BLITTER_Y;
140         break;
125141    }
126142}
127143
128144static ADDRESS_MAP_START( gmaster_mem, ADDRESS_SPACE_PROGRAM, 8 )
129     AM_RANGE(0x0000, 0x3fff) AM_ROM
130      AM_RANGE( 0x4000, 0x7fff) AM_READWRITE(gmaster_io_r, gmaster_io_w)
131     AM_RANGE(0x8000, 0xfeff) AM_ROM
132      AM_RANGE(0xff00, 0xffff) AM_RAM
145   AM_RANGE(0x0000, 0x3fff) AM_ROM
146   AM_RANGE( 0x4000, 0x7fff) AM_READWRITE(gmaster_io_r, gmaster_io_w)
147   AM_RANGE(0x8000, 0xfeff) AM_ROM
148   AM_RANGE(0xff00, 0xffff) AM_RAM
133149ADDRESS_MAP_END
134150
135151static ADDRESS_MAP_START(gmaster_io, ADDRESS_SPACE_IO, 8)
136     AM_RANGE(UPD7810_PORTA, UPD7810_PORTF) AM_READWRITE(gmaster_port_r, gmaster_port_w )
152   AM_RANGE(UPD7810_PORTA, UPD7810_PORTF) AM_READWRITE(gmaster_port_r, gmaster_port_w )
137153ADDRESS_MAP_END
138154
139155static INPUT_PORTS_START( gmaster )
r4575r4576
141157    PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT)
142158    PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
143159    PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
144    PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP   )
160    PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
145161    PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_NAME("B")
146162    PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("A")
147    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SELECT)  PORT_NAME("select")
148    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START) PORT_NAME("start")
163    PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SELECT) PORT_NAME("Select")
164    PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START) PORT_NAME("Start")
149165INPUT_PORTS_END
150166
151167/* palette in red, green, blue tribles */
r4575r4576
164180{
165181   int i;
166182
167   for ( i = 0; i < 2; i++ ) {
183   for ( i = 0; i < 2; i++ )
184   {
168185      palette_set_color_rgb(machine, i, gmaster_palette[i][0], gmaster_palette[i][1], gmaster_palette[i][2]);
169186   }
170187}
r4575r4576
172189static VIDEO_UPDATE( gmaster )
173190{
174191    int x,y;
175//    plot_box(bitmap, 0, 0, 64/*bitmap->width*/, bitmap->height, 0); //xmess rounds up to 64 pixel
176    for (y=0;y<ARRAY_LENGTH(gmaster_video.pixels); y++) {
177   for (x=0;x<ARRAY_LENGTH(gmaster_video.pixels[0]);x++) {
178     UINT8 d=gmaster_video.pixels[y][x];
179     UINT16 *line;
180     line=BITMAP_ADDR16(bitmap, (y*8), x);
181     line[0]=(d>>0)&1;
182     line=BITMAP_ADDR16(bitmap, (y*8+1), x);
183     line[0]=(d>>1)&1;
184     line=BITMAP_ADDR16(bitmap, (y*8+2), x);
185     line[0]=(d>>2)&1;
186     line=BITMAP_ADDR16(bitmap, (y*8+3), x);
187     line[0]=(d>>3)&1;
188     line=BITMAP_ADDR16(bitmap, (y*8+4), x);
189     line[0]=(d>>4)&1;
190     line=BITMAP_ADDR16(bitmap, (y*8+5), x);
191     line[0]=(d>>5)&1;
192     line=BITMAP_ADDR16(bitmap, (y*8+6), x);
193     line[0]=(d>>6)&1;
194     line=BITMAP_ADDR16(bitmap, (y*8+7), x);
195     line[0]=(d>>7)&1;
196   }
192//   plot_box(bitmap, 0, 0, 64/*bitmap->width*/, bitmap->height, 0); //xmess rounds up to 64 pixel
193    for (y = 0; y < ARRAY_LENGTH(gmaster_video.pixels); y++)
194   {
195      for (x = 0; x < ARRAY_LENGTH(gmaster_video.pixels[0]); x++)
196      {
197         UINT8 d = gmaster_video.pixels[y][x];
198         UINT16 *line;
199
200         line = BITMAP_ADDR16(bitmap, (y * 8), x);
201         line[0] = (d >> 0) & 1;
202         line = BITMAP_ADDR16(bitmap, (y * 8 + 1), x);
203         line[0] = (d >> 1) & 1;
204         line = BITMAP_ADDR16(bitmap, (y * 8 + 2), x);
205         line[0] = (d >> 2) & 1;
206         line = BITMAP_ADDR16(bitmap, (y * 8 + 3), x);
207         line[0] = (d >> 3) & 1;
208         line = BITMAP_ADDR16(bitmap, (y * 8 + 4), x);
209         line[0] = (d >> 4) & 1;
210         line = BITMAP_ADDR16(bitmap, (y * 8 + 5), x);
211         line[0] = (d >> 5) & 1;
212         line = BITMAP_ADDR16(bitmap, (y * 8 + 6), x);
213         line[0] = (d >> 6) & 1;
214         line = BITMAP_ADDR16(bitmap, (y * 8 + 7), x);
215         line[0] = (d >> 7) & 1;
216      }
197217    }
198218    return 0;
199219}
200220
201221static INTERRUPT_GEN( gmaster_interrupt )
202222{
203  cpu_set_input_line(device->machine->cpu[0], UPD7810_INTFE1, ASSERT_LINE);
223   cputag_set_input_line(device->machine, "maincpu", UPD7810_INTFE1, ASSERT_LINE);
204224}
205225
206static const UPD7810_CONFIG config={
207  //    TYPE_78C10, // 78c11 in handheld
208    TYPE_7801, // temporarily until 7810 core fixes synchronized
209    gmaster_io_callback
226static const UPD7810_CONFIG config = {
227//   TYPE_78C10, // 78c11 in handheld
228   TYPE_7801, // temporarily until 7810 core fixes synchronized
229   gmaster_io_callback
210230};
211231
212232static MACHINE_DRIVER_START( gmaster )
r4575r4576
236256
237257ROM_START(gmaster)
238258   ROM_REGION(0x10000,"maincpu", 0)
239     ROM_LOAD("gmaster.bin", 0x0000, 0x1000, CRC(05cc45e5) SHA1(05d73638dea9657ccc2791c0202d9074a4782c1e) )
240//     ROM_CART_LOAD(0, "bin", 0x8000, 0x7f00, 0)
241     ROM_CART_LOAD("cart", 0x8000, 0x8000, 0)
259   ROM_LOAD("gmaster.bin", 0x0000, 0x1000, CRC(05cc45e5) SHA1(05d73638dea9657ccc2791c0202d9074a4782c1e) )
260//   ROM_CART_LOAD(0, "bin", 0x8000, 0x7f00, 0)
261   ROM_CART_LOAD("cart", 0x8000, 0x8000, 0)
242262ROM_END
243263
244264static DRIVER_INIT( gmaster )
245265{
246    memset(&gmaster_video, 0, sizeof(gmaster_video));
247
266   memset(&gmaster_video, 0, sizeof(gmaster_video));
248267}
249268
250269#if 0
r4575r4576
266285      return 1;
267286   }
268287   size=osd_fsize(cartfile);
269   if (size>0x8000) {
288   if (size>0x8000)
289   {
270290       logerror("%s: size %d not yet supported\n",device_filename(IO_CARTSLOT,id), size);
271291       return 1;
272292   }
273293
274   if (osd_fread(cartfile, rom+0x8000, size)!=size) {
294   if (osd_fread(cartfile, rom+0x8000, size)!=size)
295   {
275296      logerror("%s load error\n",device_filename(IO_CARTSLOT,id));
276297      osd_fclose(cartfile);
277298      return 1;
r4575r4576
285306/*    YEAR      NAME            PARENT  MACHINE   INPUT     INIT               
286307     COMPANY                 FULLNAME */
287308CONS( 1990, gmaster,       0,          0, gmaster,  gmaster,    gmaster,   0, "Hartung", "Gamemaster", GAME_IMPERFECT_SOUND)
288
src/mess/drivers/intv.c
r4575r4576
376376
377377static INTERRUPT_GEN( intv_interrupt2 )
378378{
379   cpu_set_input_line(device->machine->cpu[1], 0, ASSERT_LINE);
379   cputag_set_input_line(device->machine, "keyboard", 0, ASSERT_LINE);
380380}
381381
382382static MACHINE_DRIVER_START( intv )
src/mess/drivers/jupiter.c
r4575r4576
250250
251251static TIMER_CALLBACK( jupiter_set_irq_callback )
252252{
253   cpu_set_input_line( machine->cpu[0], 0, ASSERT_LINE );
253   cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE);
254254}
255255
256256
257257static TIMER_CALLBACK( jupiter_clear_irq_callback )
258258{
259   cpu_set_input_line( machine->cpu[0], 0, CLEAR_LINE );
259   cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
260260}
261261
262262
src/mess/drivers/genesis.c
r4575r4576
208208         if (((megadrive_io_data_regs[portnum] & 0x40) == 0x00) && ((data & 0x40) == 0x40))
209209         {
210210            mess_io_stage[portnum]++;
211            timer_adjust_oneshot(mess_io_timeout[portnum], cpu_clocks_to_attotime(machine->cpu[0], 8192), 0);
211            timer_adjust_oneshot(mess_io_timeout[portnum], cputag_clocks_to_attotime(machine, "maincpu", 8192), 0);
212212         }
213213
214214      }
src/mess/drivers/ip20.c
r4575r4576
3838      va_start( v, s_fmt );
3939      vsprintf( buf, s_fmt, v );
4040      va_end( v );
41      logerror( "%08x: %s", cpu_get_pc(machine->cpu[0]), buf );
41      logerror( "%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf );
4242   }
4343}
4444

Previous 15994 Revisions Next


© 1998-2018 The MESS Team