Previous 15994 Revisions Next

r7497 Friday 5th March, 2010 at 09:04:23 UTC by Fabio Priuli
[SNES] drawing routine rewrite, part 5:
* changed drawing logic: before we were drawing for each line first subscreen BGs and then mainscreen BGs; now we draw for each BGs both subscreen and mainscreen at once.
This fixes most (but not all, unfortunately) hires addsub color problems.
See e.g. Seiken Densetsu character selection screen to see improvements
[src/mame/video]snes.c

src/mame/video/snes.c
r7496r7497
111111
112112struct SCANLINE
113113{
114   int enable, clip;
115
114116   UINT16 buffer[(SNES_SCR_WIDTH * 2)];
115117   UINT8  priority[(SNES_SCR_WIDTH * 2)];
116118   UINT8  layer[(SNES_SCR_WIDTH * 2)];
r7496r7497
237239 *
238240 * Draw tiles with variable bit planes
239241 *****************************************/
240INLINE void snes_draw_tile(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
242INLINE void snes_draw_tile(UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
241243{
242   UINT8 mask, plane[8], window_enabled = 0;
244   UINT8 mask, plane[8];
243245   UINT16 c;
244246   INT16 ii, jj;
245247
r7496r7497
272274         mask >>= 1;
273275      }
274276
277
278      if (!hires)
279      {
280         if (scanlines[SNES_MAINSCREEN].enable)
281         {
282
275283#ifdef SNES_LAYER_DEBUG
276      if (!debug_options.windows_disabled)
284            if (!debug_options.windows_disabled)
277285#endif /* SNES_LAYER_DEBUG */
278      /* Clip to windows */
279      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
280      if (window_enabled)
281         colour &= snes_ppu.clipmasks[layer][ii >> hires];
286            /* Clip to windows */
287            if (scanlines[SNES_MAINSCREEN].clip)
288               colour &= snes_ppu.clipmasks[layer][ii];
282289
283      /* Only draw if we have a colour (0 == transparent) */
284      if (colour)
285      {
286         if ((scanlines[screen].priority[ii >> hires] <= priority) && (ii >= 0))
290            /* Only draw if we have a colour (0 == transparent) */
291            if (colour)
292            {
293               if ((scanlines[SNES_MAINSCREEN].priority[ii] <= priority) && (ii >= 0))
294               {
295                  if (direct_colors)
296                  {
297                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
298                     c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
299                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
300                  }
301                  else
302                     c = snes_cgram[pal + colour];
303
304                  if (snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled) // handle horizontal mosaic
305                  {
306                     int x_mos;
307
308                     //TODO: 512 modes has the h values doubled.
309                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
310                     {
311                        scanlines[SNES_MAINSCREEN].buffer[ii + x_mos] = c;
312                        scanlines[SNES_MAINSCREEN].priority[ii + x_mos] = priority;
313                        scanlines[SNES_MAINSCREEN].layer[ii + x_mos] = layer;
314                     }
315
316                     ii += x_mos - 1;
317                  }
318                  else
319                  {
320                     scanlines[SNES_MAINSCREEN].buffer[ii] = c;
321                     scanlines[SNES_MAINSCREEN].priority[ii] = priority;
322                     scanlines[SNES_MAINSCREEN].layer[ii] = layer;
323                  }
324               }
325            }
326         }
327
328         if (scanlines[SNES_SUBSCREEN].enable)
287329         {
288            if (direct_colors)
330#ifdef SNES_LAYER_DEBUG
331            if (!debug_options.windows_disabled)
332#endif /* SNES_LAYER_DEBUG */
333            /* Clip to windows */
334            if (scanlines[SNES_SUBSCREEN].clip)
335               colour &= snes_ppu.clipmasks[layer][ii];
336
337            /* Only draw if we have a colour (0 == transparent) */
338            if (colour)
289339            {
290               /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
291               c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
292               c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
340               if ((scanlines[SNES_SUBSCREEN].priority[ii] <= priority) && (ii >= 0))
341               {
342                  if (direct_colors)
343                  {
344                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
345                     c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
346                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
347                  }
348                  else
349                     c = snes_cgram[pal + colour];
350
351                  if (snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled) // handle horizontal mosaic
352                  {
353                     int x_mos;
354
355                     //TODO: 512 modes has the h values doubled.
356                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
357                     {
358                        scanlines[SNES_SUBSCREEN].buffer[ii + x_mos] = c;
359                        scanlines[SNES_SUBSCREEN].priority[ii + x_mos] = priority;
360                        scanlines[SNES_SUBSCREEN].layer[ii + x_mos] = layer;
361                     }
362
363                     ii += x_mos - 1;
364                  }
365                  else
366                  {
367                     scanlines[SNES_SUBSCREEN].buffer[ii] = c;
368                     scanlines[SNES_SUBSCREEN].priority[ii] = priority;
369                     scanlines[SNES_SUBSCREEN].layer[ii] = layer;
370                  }
371               }
293372            }
294            else
295               c = snes_cgram[pal + colour];
373         }
374      }
296375
297            if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
376      else /* hires */
377      {
378#ifdef SNES_LAYER_DEBUG
379         if (!debug_options.windows_disabled)
380#endif /* SNES_LAYER_DEBUG */
381         /* Clip to windows */
382         if (scanlines[SNES_MAINSCREEN].clip)
383            colour &= snes_ppu.clipmasks[layer][ii >> hires];
384
385         /* Only draw if we have a colour (0 == transparent) */
386         if (colour)
387         {
388            if ((scanlines[SNES_MAINSCREEN].priority[ii >> hires] <= priority) && (ii >= 0))
298389            {
299               int x_mos;
390               if (direct_colors)
391               {
392                  /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
393                  c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
394                  c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
395               }
396               else
397                  c = snes_cgram[pal + colour];
300398
301               //TODO: 512 modes has the h values doubled.
302               for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
399               if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
303400               {
304                  if (hires)
401                  int x_mos;
402
403                  //TODO: 512 modes has the h values doubled.
404                  for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
305405                  {
306                     if (ii & 1)
406                     if ((ii & 1) && scanlines[SNES_MAINSCREEN].enable)
307407                     {
308408                        scanlines[SNES_MAINSCREEN].buffer[(ii + x_mos) >> 1] = c;
309409                        scanlines[SNES_MAINSCREEN].priority[(ii + x_mos) >> 1] = priority;
310410                        scanlines[SNES_MAINSCREEN].layer[(ii + x_mos) >> 1] = layer;
311411                     }
312                     else
412                     else if (scanlines[SNES_SUBSCREEN].enable)
313413                     {
314414                        scanlines[SNES_SUBSCREEN].buffer[(ii + x_mos) >> 1] = c;
315415                        scanlines[SNES_SUBSCREEN].priority[(ii + x_mos) >> 1] = priority;
316416                        scanlines[SNES_SUBSCREEN].layer[(ii + x_mos) >> 1] = layer;
317417                     }
318418                  }
319                  else
320                  {
321                     scanlines[screen].buffer[ii + x_mos] = c;
322                     scanlines[screen].priority[ii + x_mos] = priority;
323                     scanlines[screen].layer[ii + x_mos] = layer;
324                  }
419                  ii += x_mos - 1;
325420               }
326               ii += x_mos - 1;
327            }
328            else
329            {
330               if (hires)
421               else
331422               {
332                  if (ii & 1)
423                  if ((ii & 1) && scanlines[SNES_MAINSCREEN].enable)
333424                  {
334425                     scanlines[SNES_MAINSCREEN].buffer[ii >> 1] = c;
335426                     scanlines[SNES_MAINSCREEN].priority[ii >> 1] = priority;
336427                     scanlines[SNES_MAINSCREEN].layer[ii >> 1] = layer;
337428                  }
338                  else
429                  else if (scanlines[SNES_SUBSCREEN].enable)
339430                  {
340431                     scanlines[SNES_SUBSCREEN].buffer[ii >> 1] = c;
341432                     scanlines[SNES_SUBSCREEN].priority[ii >> 1] = priority;
342433                     scanlines[SNES_SUBSCREEN].layer[ii >> 1] = layer;
343434                  }
344435               }
345               else
346               {
347                  scanlines[screen].buffer[ii] = c;
348                  scanlines[screen].priority[ii] = priority;
349                  scanlines[screen].layer[ii] = layer;
350               }
351436            }
352437         }
353438      }
r7496r7497
359444 *
360445 * Draw 2 tiles with variable bit planes
361446 *****************************************/
362INLINE void snes_draw_tile_x2(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
447INLINE void snes_draw_tile_x2(UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
363448{
364449   if (flip)
365450   {
366      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors, hires);
367      snes_draw_tile(screen, planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors, hires);
451      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors, hires);
452      snes_draw_tile(planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors, hires);
368453   }
369454   else
370455   {
371      snes_draw_tile(screen, planes, layer, tileaddr, x, priority, flip, pal, direct_colors, hires);
372      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal, direct_colors, hires);
456      snes_draw_tile(planes, layer, tileaddr, x, priority, flip, pal, direct_colors, hires);
457      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal, direct_colors, hires);
373458   }
374459}
375460
r7496r7497
380465 * The same as snes_draw_tile_4() except
381466 * that it takes a blend parameter.
382467 *****************************************/
383INLINE void snes_draw_tile_object(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend, UINT8 wide )
468INLINE void snes_draw_tile_object( UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend )
384469{
385   UINT8 mask, plane[4], window_enabled = 0;
470   UINT8 mask, plane[4];
386471   UINT16 c;
387472   INT16 ii;
388   UINT8 x_shift = wide ? 1 : 0;
389   UINT8 size = wide ? 16 : 8;
390   UINT8 step = wide ? 1 : 0;
391473
392474   plane[0] = snes_vram[tileaddr];
393475   plane[1] = snes_vram[tileaddr + 1];
r7496r7497
399481   else
400482      mask = 0x80;
401483
402   x <<= x_shift;
403   for (ii = x; ii < (x + size); ii += 1 + step)
484   for (ii = x; ii < (x + 8); ii++)
404485   {
405486      UINT8 colour;
406487      if (flip)
r7496r7497
416497         mask >>= 1;
417498      }
418499
500      if (scanlines[SNES_MAINSCREEN].enable)
501      {
502
419503#ifdef SNES_LAYER_DEBUG
420      if (!debug_options.windows_disabled)
504         if (!debug_options.windows_disabled)
421505#endif /* SNES_LAYER_DEBUG */
422      /* Clip to windows */
423      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[SNES_OAM].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled;
424      if (window_enabled)
425         colour &= snes_ppu.clipmasks[SNES_OAM][ii];
506         /* Clip to windows */
507         if (scanlines[SNES_MAINSCREEN].clip)
508            colour &= snes_ppu.clipmasks[SNES_OAM][ii];
426509
427      /* Only draw if we have a colour (0 == transparent) */
428      if (colour)
510         /* Only draw if we have a colour (0 == transparent) */
511         if (colour)
512         {
513            if ((scanlines[SNES_MAINSCREEN].priority[ii] <= priority) && (ii >= 0))
514            {
515               c = snes_cgram[pal + colour];
516
517               scanlines[SNES_MAINSCREEN].buffer[ii] = c;
518               scanlines[SNES_MAINSCREEN].priority[ii] = priority;
519               scanlines[SNES_MAINSCREEN].layer[ii] = SNES_OAM;
520               scanlines[SNES_MAINSCREEN].blend_exception[ii] = blend;
521            }
522         }
523      }
524
525      if (scanlines[SNES_SUBSCREEN].enable)
429526      {
430         if ((scanlines[screen].priority[ii] <= priority) && (ii >= 0))
527
528#ifdef SNES_LAYER_DEBUG
529         if (!debug_options.windows_disabled)
530#endif /* SNES_LAYER_DEBUG */
531         /* Clip to windows */
532         if (scanlines[SNES_SUBSCREEN].clip)
533            colour &= snes_ppu.clipmasks[SNES_OAM][ii];
534
535         /* Only draw if we have a colour (0 == transparent) */
536         if (colour)
431537         {
432            c = snes_cgram[pal + colour];
538            if ((scanlines[SNES_SUBSCREEN].priority[ii] <= priority) && (ii >= 0))
539            {
540               c = snes_cgram[pal + colour];
433541
434            scanlines[screen].buffer[ii] = c;
435            scanlines[screen].priority[ii] = priority;
436            scanlines[screen].layer[ii] = SNES_OAM;
437            scanlines[screen].blend_exception[ii] = blend;
438            if (wide)
439            {
440               scanlines[screen].buffer[ii + 1] = c;
441               scanlines[screen].priority[ii + 1] = priority;
442               scanlines[screen].layer[ii + 1] = SNES_OAM;
443               scanlines[screen].blend_exception[ii + 1] = blend;
542               scanlines[SNES_SUBSCREEN].buffer[ii] = c;
543               scanlines[SNES_SUBSCREEN].priority[ii] = priority;
544               scanlines[SNES_SUBSCREEN].layer[ii] = SNES_OAM;
545               scanlines[SNES_SUBSCREEN].blend_exception[ii] = blend;
444546            }
445547         }
446548      }
r7496r7497
470572   return res;
471573}
472574
473INLINE void snes_update_line( UINT8 screen, UINT8 color_depth, UINT8 hires, UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline, UINT8 offset_per_tile, UINT8 direct_colors )
575INLINE void snes_update_line( UINT8 color_depth, UINT8 hires, UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline, UINT8 offset_per_tile, UINT8 direct_colors )
474576{
475577   UINT32 tmap, tile, xoff, yoff;
476578   UINT16 ii = 0, vflip, hflip, pal;
r7496r7497
492594      return;
493595#endif /* SNES_LAYER_DEBUG */
494596
597   scanlines[SNES_MAINSCREEN].enable = snes_ppu.main_bg_enabled[layer];
598   scanlines[SNES_SUBSCREEN].enable = snes_ppu.sub_bg_enabled[layer];
599   scanlines[SNES_MAINSCREEN].clip = snes_ppu.layer[layer].main_window_enabled;
600   scanlines[SNES_SUBSCREEN].clip = snes_ppu.layer[layer].sub_window_enabled;
601
602   if (!scanlines[SNES_MAINSCREEN].enable && !scanlines[SNES_SUBSCREEN].enable)
603      return;
604
495605   /* Handle Mosaic effects */
496606   if (snes_ppu.layer[layer].mosaic_enabled)
497607      curline -= (curline % (snes_ppu.mosaic_size + 1));
r7496r7497
599709      /* below, only color_planes depends on color_depth */
600710      if (hires)   /* Hi-Res: 2bpp & 4bpp */
601711      {
602         snes_draw_tile_x2(screen, color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii * 2, priority, hflip, pal, direct_colors, hires);
712         snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii * 2, priority, hflip, pal, direct_colors, hires);
603713         ii += 8;
604714      }
605715      else   /* tile_size = 0 */
606716      {
607717         if (tile_size)
608718         {
609            snes_draw_tile_x2(screen, color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
719            snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
610720            ii += 16;
611721         }
612722         else   /* No Hi-Res: 2bpp, 4bpp & 8bpp */
613723         {
614            snes_draw_tile(screen, color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
724            snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
615725            ii += 8;
616726         }
617727      }
r7496r7497
626736 *********************************************/
627737#define MODE7_CLIP(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff))
628738
629static void snes_update_line_mode7(UINT8 screen, UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline )
739static void snes_update_line_mode7( UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline )
630740{
631741   UINT32 tiled;
632742   INT16 ma, mb, mc, md;
633743   INT32 xc, yc, tx, ty, sx, sy, hs, vs, xpos, xdir, x0, y0;
634744   UINT8 priority = priority_a;
635   UINT8 colour = 0, window_enabled = 0;
745   UINT8 colour = 0;
636746   UINT16 *mosaic_x, *mosaic_y;
637747
638748#ifdef SNES_LAYER_DEBUG
r7496r7497
640750      return;
641751#endif /* SNES_LAYER_DEBUG */
642752
753   scanlines[SNES_MAINSCREEN].enable = snes_ppu.main_bg_enabled[layer];
754   scanlines[SNES_SUBSCREEN].enable = snes_ppu.sub_bg_enabled[layer];
755   scanlines[SNES_MAINSCREEN].clip = snes_ppu.layer[layer].main_window_enabled;
756   scanlines[SNES_SUBSCREEN].clip = snes_ppu.layer[layer].sub_window_enabled;
757
758   if (!scanlines[SNES_MAINSCREEN].enable && !scanlines[SNES_SUBSCREEN].enable)
759      return;
760
643761   ma = snes_ppu.mode7.matrix_a;
644762   mb = snes_ppu.mode7.matrix_b;
645763   mc = snes_ppu.mode7.matrix_c;
r7496r7497
734852         colour &= 0x7f;
735853      }
736854
737      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
738      if (window_enabled)
739         colour &= snes_ppu.clipmasks[layer][xpos];
855      if (scanlines[SNES_MAINSCREEN].enable)
856      {
857         if (scanlines[SNES_MAINSCREEN].clip)
858            colour &= snes_ppu.clipmasks[layer][xpos];
740859
741      /* Draw pixel if appropriate */
742      if (scanlines[screen].priority[xpos] <= priority && colour > 0)
860         /* Draw pixel if appropriate */
861         if (scanlines[SNES_MAINSCREEN].priority[xpos] <= priority && colour > 0)
862         {
863            UINT16 clr;
864            /* Direct select, but only outside EXTBG! */
865            if (snes_ppu.direct_color && layer == 0)
866            {
867               /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
868               clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
869            }
870            else
871               clr = snes_cgram[colour];
872
873            scanlines[SNES_MAINSCREEN].buffer[xpos] = clr;
874            scanlines[SNES_MAINSCREEN].priority[xpos] = priority;
875            scanlines[SNES_MAINSCREEN].layer[xpos] = layer;
876         }
877      }
878
879      if (scanlines[SNES_SUBSCREEN].enable)
743880      {
744         UINT16 clr;
745         /* Direct select, but only outside EXTBG! */
746         if (snes_ppu.direct_color && layer == 0)
881         if (scanlines[SNES_SUBSCREEN].clip)
882            colour &= snes_ppu.clipmasks[layer][xpos];
883
884         /* Draw pixel if appropriate */
885         if (scanlines[SNES_SUBSCREEN].priority[xpos] <= priority && colour > 0)
747886         {
748            /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
749            clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
887            UINT16 clr;
888            /* Direct select, but only outside EXTBG! */
889            if (snes_ppu.direct_color && layer == 0)
890            {
891               /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
892               clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
893            }
894            else
895               clr = snes_cgram[colour];
896
897            scanlines[SNES_SUBSCREEN].buffer[xpos] = clr;
898            scanlines[SNES_SUBSCREEN].priority[xpos] = priority;
899            scanlines[SNES_SUBSCREEN].layer[xpos] = layer;
750900         }
751         else
752            clr = snes_cgram[colour];
753
754         scanlines[screen].buffer[xpos] = clr;
755         scanlines[screen].priority[xpos] = priority;
756         scanlines[screen].layer[xpos] = layer;
757901      }
758902   }
759903}
r7496r7497
764908 * Update an entire line of sprites.
765909 * FIXME: We need to support high priority bit
766910 *********************************************/
767static void snes_update_objects( UINT8 screen, UINT8 priority_tbl, UINT16 curline )
911static void snes_update_objects( UINT8 priority_tbl, UINT16 curline )
768912{
769913   INT8 xs, ys;
770   UINT8 line, widemode = 0;
914   UINT8 line;
771915   UINT16 oam_extra, extra;
772916   INT16 oam;
773917   UINT8 range_over = 0, time_over = 0;
r7496r7497
794938      return;
795939#endif /* SNES_LAYER_DEBUG */
796940
797//   if (snes_ppu.mode == 5 || snes_ppu.mode == 6)
798//      widemode = 1;
941   scanlines[SNES_MAINSCREEN].enable = snes_ppu.main_bg_enabled[SNES_OAM];
942   scanlines[SNES_SUBSCREEN].enable = snes_ppu.sub_bg_enabled[SNES_OAM];
943   scanlines[SNES_MAINSCREEN].clip = snes_ppu.layer[SNES_OAM].main_window_enabled;
944   scanlines[SNES_SUBSCREEN].clip = snes_ppu.layer[SNES_OAM].sub_window_enabled;
799945
946   if (!scanlines[SNES_MAINSCREEN].enable && !scanlines[SNES_SUBSCREEN].enable)
947      return;
948
800949   curline /= snes_ppu.interlace;
801950   curline *= snes_ppu.obj_interlace;
802951
r7496r7497
822971      extra <<= 1;
823972      x |= ((extra & 0x80) << 1);
824973      extra <<= 1;
825      y*=snes_ppu.obj_interlace;
974      y *= snes_ppu.obj_interlace;
826975
827976      /* Adjust if past maximum position */
828977      if (y >= snes_ppu.beam.last_visible_line*snes_ppu.interlace)
r7496r7497
8551004            {
8561005               if ((x + (count << 3) < SNES_SCR_WIDTH + 8))
8571006               {
858                  snes_draw_tile_object(screen, charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, widemode);
1007                  snes_draw_tile_object(charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend);
8591008               }
8601009               time_over++;   /* Increase time_over. Should we stop drawing if exceeded 34 tiles? */
8611010            }
r7496r7497
8661015            {
8671016               if ((x + (xs << 3) < SNES_SCR_WIDTH + 8))
8681017               {
869                  snes_draw_tile_object(screen, charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, widemode);
1018                  snes_draw_tile_object(charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend);
8701019               }
8711020               time_over++;   /* Increase time_over. Should we stop drawing if exceeded 34 tiles? */
8721021            }
r7496r7497
8971046 *
8981047 * Update Mode X line.
8991048 *********************************************/
900static void snes_update_mode_0( UINT8 screen, UINT16 curline )
1049static void snes_update_mode_0( UINT16 curline )
9011050{
902   UINT8 *bg_enabled;
903   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
904
9051051#ifdef SNES_LAYER_DEBUG
9061052   if (debug_options.mode_disabled[0])
9071053      return;
9081054#endif /* SNES_LAYER_DEBUG */
9091055
910   if (bg_enabled[3]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 3, SNES_BG4, curline, 0, 0);
911   if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 1, 4, SNES_BG3, curline, 0, 0);
912   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 6, 9, SNES_BG2, curline, 0, 0);
913   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, SNES_BG1, curline, 0, 0);
914   if (bg_enabled[4]) snes_update_objects(screen, 0, curline);
1056   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 3, SNES_BG4, curline, 0, 0);
1057   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 1, 4, SNES_BG3, curline, 0, 0);
1058   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 6, 9, SNES_BG2, curline, 0, 0);
1059   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 7, 10, SNES_BG1, curline, 0, 0);
1060   snes_update_objects(0, curline);
9151061}
9161062
917static void snes_update_mode_1( UINT8 screen, UINT16 curline )
1063static void snes_update_mode_1( UINT16 curline )
9181064{
919   UINT8 *bg_enabled;
920   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
921
9221065#ifdef SNES_LAYER_DEBUG
9231066   if (debug_options.mode_disabled[1])
9241067      return;
r7496r7497
9261069
9271070   if (!snes_ppu.bg3_priority_bit)
9281071   {
929      if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 2, SNES_BG3, curline, 0, 0);
930      if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG2, curline, 0, 0);
931      if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 5, 8, SNES_BG1, curline, 0, 0);
932      if (bg_enabled[4]) snes_update_objects(screen, 1, curline);
1072      snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 2, SNES_BG3, curline, 0, 0);
1073      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG2, curline, 0, 0);
1074      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 5, 8, SNES_BG1, curline, 0, 0);
1075      snes_update_objects(1, curline);
9331076   }
9341077   else
9351078   {
936      if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 9, SNES_BG3, curline, 0, 0);
937      if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 3, 6, SNES_BG2, curline, 0, 0);
938      if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG1, curline, 0, 0);
939      if (bg_enabled[4]) snes_update_objects(screen, 9, curline);
1079      snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 9, SNES_BG3, curline, 0, 0);
1080      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 3, 6, SNES_BG2, curline, 0, 0);
1081      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG1, curline, 0, 0);
1082      snes_update_objects(9, curline);
9401083   }
9411084}
9421085
943static void snes_update_mode_2( UINT8 screen, UINT16 curline )
1086static void snes_update_mode_2( UINT16 curline )
9441087{
945   UINT8 *bg_enabled;
946   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
947
9481088#ifdef SNES_LAYER_DEBUG
9491089   if (debug_options.mode_disabled[2])
9501090      return;
9511091#endif /* SNES_LAYER_DEBUG */
9521092
953   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 1, 0);
954   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, SNES_BG1, curline, 1, 0);
955   if (bg_enabled[4]) snes_update_objects(screen, 2, curline);
1093   snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 1, 0);
1094   snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 2, 6, SNES_BG1, curline, 1, 0);
1095   snes_update_objects(2, curline);
9561096}
9571097
958static void snes_update_mode_3( UINT8 screen, UINT16 curline )
1098static void snes_update_mode_3( UINT16 curline )
9591099{
960   UINT8 *bg_enabled;
961   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
962
9631100#ifdef SNES_LAYER_DEBUG
9641101   if (debug_options.mode_disabled[3])
9651102      return;
9661103#endif /* SNES_LAYER_DEBUG */
9671104
968   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 0, 0);
969   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color);
970   if (bg_enabled[4]) snes_update_objects(screen, 3, curline);
1105   snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 0, 0);
1106   snes_update_line(SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color);
1107   snes_update_objects(3, curline);
9711108}
9721109
973static void snes_update_mode_4( UINT8 screen, UINT16 curline )
1110static void snes_update_mode_4( UINT16 curline )
9741111{
975   UINT8 *bg_enabled;
976   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
977
9781112#ifdef SNES_LAYER_DEBUG
9791113   if (debug_options.mode_disabled[4])
9801114      return;
9811115#endif /* SNES_LAYER_DEBUG */
9821116
983   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 4, SNES_BG2, curline, 0, 0);
984   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color);
985   if (bg_enabled[4]) snes_update_objects(screen, 4, curline);
1117   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 4, SNES_BG2, curline, 0, 0);
1118   snes_update_line(SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color);
1119   snes_update_objects(4, curline);
9861120}
9871121
988static void snes_update_mode_5( UINT8 screen, UINT16 curline )
1122static void snes_update_mode_5( UINT16 curline )
9891123{
990   UINT8 *bg_enabled;
991   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
992
9931124#ifdef SNES_LAYER_DEBUG
9941125   if (debug_options.mode_disabled[5])
9951126      return;
9961127#endif /* SNES_LAYER_DEBUG */
9971128
998   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 1, 0, 4, SNES_BG2, curline, 0, 0);
999   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, SNES_BG1, curline, 0, 0);
1000   if (bg_enabled[4]) snes_update_objects(screen, 5, curline);
1129   snes_update_line(SNES_COLOR_DEPTH_4BPP, 1, 2, 6, SNES_BG1, curline, 0, 0);
1130   snes_update_line(SNES_COLOR_DEPTH_2BPP, 1, 0, 4, SNES_BG2, curline, 0, 0);
1131   snes_update_objects(5, curline);
10011132}
10021133
1003static void snes_update_mode_6( UINT8 screen, UINT16 curline )
1134static void snes_update_mode_6( UINT16 curline )
10041135{
1005   UINT8 *bg_enabled;
1006   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1007
10081136#ifdef SNES_LAYER_DEBUG
10091137   if (debug_options.mode_disabled[6])
10101138      return;
10111139#endif /* SNES_LAYER_DEBUG */
10121140
1013   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, SNES_BG1, curline, 1, 0);
1014   if (bg_enabled[4]) snes_update_objects(screen, 6, curline);
1141   snes_update_line(SNES_COLOR_DEPTH_4BPP, 1, 1, 4, SNES_BG1, curline, 1, 0);
1142   snes_update_objects(6, curline);
10151143}
10161144
1017static void snes_update_mode_7( UINT8 screen, UINT16 curline )
1145static void snes_update_mode_7( UINT16 curline )
10181146{
1019   UINT8 *bg_enabled;
1020   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1021
10221147#ifdef SNES_LAYER_DEBUG
10231148   if (debug_options.mode_disabled[7])
10241149      return;
r7496r7497
10261151
10271152   if (!snes_ppu.mode7.extbg)
10281153   {
1029      if (bg_enabled[0]) snes_update_line_mode7(screen, 1, 1, SNES_BG1, curline);
1030      if (bg_enabled[4]) snes_update_objects(screen, 7, curline);
1154      snes_update_line_mode7(1, 1, SNES_BG1, curline);
1155      snes_update_objects(7, curline);
10311156   }
10321157   else
10331158   {
1034      if (bg_enabled[1]) snes_update_line_mode7(screen, 0, 4, SNES_BG2, curline);
1035      if (bg_enabled[0]) snes_update_line_mode7(screen, 2, 2, SNES_BG1, curline);
1036      if (bg_enabled[4]) snes_update_objects(screen, 8, curline);
1159      snes_update_line_mode7(0, 4, SNES_BG2, curline);
1160      snes_update_line_mode7(2, 2, SNES_BG1, curline);
1161      snes_update_objects(8, curline);
10371162   }
10381163}
10391164
10401165/*********************************************
1041 * snes_draw_screen()
1166 * snes_draw_screens()
10421167 *
10431168 * Draw the whole screen (Mode 0 -> 7).
10441169 *********************************************/
10451170
1046static void snes_draw_screen( UINT8 screen, UINT16 curline )
1171static void snes_draw_screens( UINT16 curline )
10471172{
10481173   switch (snes_ppu.mode)
10491174   {
1050      case 0: snes_update_mode_0(screen, curline); break;      /* Mode 0 */
1051      case 1: snes_update_mode_1(screen, curline); break;      /* Mode 1 */
1052      case 2: snes_update_mode_2(screen, curline); break;      /* Mode 2 - Supports offset per tile */
1053      case 3: snes_update_mode_3(screen, curline); break;      /* Mode 3 - Supports direct colour */
1054      case 4: snes_update_mode_4(screen, curline); break;      /* Mode 4 - Supports offset per tile and direct colour */
1055      case 5: snes_update_mode_5(screen, curline); break;      /* Mode 5 - Supports hires */
1056      case 6: snes_update_mode_6(screen, curline); break;      /* Mode 6 - Supports offset per tile and hires */
1057      case 7: snes_update_mode_7(screen, curline); break;      /* Mode 7 - Supports direct colour */
1175      case 0: snes_update_mode_0(curline); break;      /* Mode 0 */
1176      case 1: snes_update_mode_1(curline); break;      /* Mode 1 */
1177      case 2: snes_update_mode_2(curline); break;      /* Mode 2 - Supports offset per tile */
1178      case 3: snes_update_mode_3(curline); break;      /* Mode 3 - Supports direct colour */
1179      case 4: snes_update_mode_4(curline); break;      /* Mode 4 - Supports offset per tile and direct colour */
1180      case 5: snes_update_mode_5(curline); break;      /* Mode 5 - Supports hires */
1181      case 6: snes_update_mode_6(curline); break;      /* Mode 6 - Supports offset per tile and hires */
1182      case 7: snes_update_mode_7(curline); break;      /* Mode 7 - Supports direct colour */
10581183   }
10591184}
10601185
r7496r7497
12011326         scanlines[SNES_MAINSCREEN].buffer[ii] = snes_cgram[0];
12021327      }
12031328
1204      /* Draw SNES_SUBSCREEN */
1205      snes_draw_screen(SNES_SUBSCREEN, curline);
1329      /* Draw screens */
1330      snes_draw_screens(curline);
12061331
1207      /* Draw SNES_MAINSCREEN */
1208      snes_draw_screen(SNES_MAINSCREEN, curline);
1209
12101332#ifdef SNES_LAYER_DEBUG
12111333      if (snes_dbg_video(machine, bitmap, curline))
12121334      {
r7496r7497
12491371            c = scanlines[SNES_SUBSCREEN].buffer[x];
12501372            scanlines[SNES_SUBSCREEN].buffer[x] = temp_col;
12511373
1252            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1374            if (!scanlines[SNES_SUBSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
12531375               snes_draw_blend_lores(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
12541376
12551377            r = ((c & 0x1f) * fade) >> 4;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team