Previous 15994 Revisions Next

r7502 Friday 5th March, 2010 at 12:40:27 UTC by Fabio Priuli
Adding back rev 7493->7500
[src/mame/video]snes.c

src/mame/video/snes.c
r7501r7502
108108   { (96*32),  (96*32)+32,  (96*32)+64,  (96*32)+96,  (96*32)+128,  (96*32)+160,  (96*32)+192,  (96*32)+224 },
109109   { (112*32), (112*32)+32, (112*32)+64, (112*32)+96, (112*32)+128, (112*32)+160, (112*32)+192, (112*32)+224 }
110110};
111/* Scroll tables                             32x32      64x32              32x64              64x64 */
112static const UINT16 table_hscroll[4][4] = { {0,0,0,0}, {0,0x800,0,0x800}, {0,0,0,0}, {0,0x800,0,0x800} };
113static const UINT16 table_vscroll[4][4] = { {0,0,0,0}, {0,0,0,0}, {0,0x800,0,0x800}, {0,0x1000,0,0x1000} };
114111
115112struct SCANLINE
116113{
117   UINT16 buffer[(SNES_SCR_WIDTH * 2) + 16];
118   UINT8  priority[(SNES_SCR_WIDTH * 2) + 16];
119   UINT8  layer[(SNES_SCR_WIDTH * 2) + 16];
120   UINT8  blend_exception[(SNES_SCR_WIDTH * 2) + 16];
114   int enable, clip;
115
116   UINT16 buffer[(SNES_SCR_WIDTH * 2)];
117   UINT8  priority[(SNES_SCR_WIDTH * 2)];
118   UINT8  layer[(SNES_SCR_WIDTH * 2)];
119   UINT8  blend_exception[(SNES_SCR_WIDTH * 2)];
121120};
122121
123122static struct SCANLINE scanlines[2];
r7501r7502
136135 * Routine for additive/subtractive blending
137136 * between the main and sub screens.
138137 *****************************************/
139INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 factor, UINT8 clip, UINT8 black_pen_clip )
138
139INLINE void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
140140{
141141   if ((black_pen_clip == SNES_CLIP_ALL2) ||
142      (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset / factor]) ||
143      (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset / factor]))
142      (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) ||
143      (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset]))
144144      *colour = 0; //clip to black before color math
145145
146146   if (clip == SNES_CLIP_ALL2) // blending mode 3 == always OFF
r7501r7502
150150   if (!debug_options.transparency_disabled)
151151#endif /* SNES_LAYER_DEBUG */
152152   if ((clip == SNES_CLIP_ALL) ||
153      (clip == SNES_CLIP_IN  && !snes_ppu.clipmasks[SNES_COLOR][offset / factor]) ||
154      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset / factor]))
153      (clip == SNES_CLIP_IN  && !snes_ppu.clipmasks[SNES_COLOR][offset]) ||
154      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset]))
155155   {
156156      UINT16 r, g, b;
157157      int clip_max = 0;   // if add then clip to 0x1f, if sub then clip to 0
r7501r7502
225225   }
226226}
227227
228INLINE void snes_draw_blend_lores(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
229{
230   snes_draw_blend(offset, colour, 1, clip, black_pen_clip);
231}
232
233INLINE void snes_draw_blend_hires(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
234{
235   snes_draw_blend(offset, colour, 2, clip, black_pen_clip);
236}
237
238228/*****************************************
239229 * snes_draw_tile()
240230 *
241231 * Draw tiles with variable bit planes
242232 *****************************************/
243INLINE void snes_draw_tile(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors )
233
234INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
244235{
245   UINT8 mask, plane[8], window_enabled = 0;
236   UINT8 mask, plane[8];
246237   UINT16 c;
247238   INT16 ii, jj;
248239
r7501r7502
275266         mask >>= 1;
276267      }
277268
269
270      if (!hires)
271      {
272         if (scanlines[SNES_MAINSCREEN].enable)
273         {
274
278275#ifdef SNES_LAYER_DEBUG
279      if (!debug_options.windows_disabled)
276            if (!debug_options.windows_disabled)
280277#endif /* SNES_LAYER_DEBUG */
281      /* Clip to windows */
282      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
283      if (window_enabled)
284         colour &= snes_ppu.clipmasks[layer][ii];
278            /* Clip to windows */
279            if (scanlines[SNES_MAINSCREEN].clip)
280               colour &= snes_ppu.clipmasks[layer][ii];
285281
286      /* Only draw if we have a colour (0 == transparent) */
287      if (colour)
288      {
289         if ((scanlines[screen].priority[ii] <= priority) && (ii >= 0))
282            /* Only draw if we have a colour (0 == transparent) */
283            if (colour)
284            {
285               if ((scanlines[SNES_MAINSCREEN].priority[ii] <= priority) && (ii >= 0))
286               {
287                  if (direct_colors)
288                  {
289                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
290                     c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
291                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
292                  }
293                  else
294                     c = snes_cgram[pal + colour];
295
296                  if (snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled) // handle horizontal mosaic
297                  {
298                     int x_mos;
299
300                     //TODO: 512 modes has the h values doubled.
301                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
302                     {
303                        scanlines[SNES_MAINSCREEN].buffer[ii + x_mos] = c;
304                        scanlines[SNES_MAINSCREEN].priority[ii + x_mos] = priority;
305                        scanlines[SNES_MAINSCREEN].layer[ii + x_mos] = layer;
306                     }
307
308                     ii += x_mos - 1;
309                  }
310                  else
311                  {
312                     scanlines[SNES_MAINSCREEN].buffer[ii] = c;
313                     scanlines[SNES_MAINSCREEN].priority[ii] = priority;
314                     scanlines[SNES_MAINSCREEN].layer[ii] = layer;
315                  }
316               }
317            }
318         }
319
320         if (scanlines[SNES_SUBSCREEN].enable)
290321         {
291            if (direct_colors)
322#ifdef SNES_LAYER_DEBUG
323            if (!debug_options.windows_disabled)
324#endif /* SNES_LAYER_DEBUG */
325            /* Clip to windows */
326            if (scanlines[SNES_SUBSCREEN].clip)
327               colour &= snes_ppu.clipmasks[layer][ii];
328
329            /* Only draw if we have a colour (0 == transparent) */
330            if (colour)
292331            {
293               /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
294               c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
295               c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
332               if ((scanlines[SNES_SUBSCREEN].priority[ii] <= priority) && (ii >= 0))
333               {
334                  if (direct_colors)
335                  {
336                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
337                     c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
338                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
339                  }
340                  else
341                     c = snes_cgram[pal + colour];
342
343                  if (snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled) // handle horizontal mosaic
344                  {
345                     int x_mos;
346
347                     //TODO: 512 modes has the h values doubled.
348                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
349                     {
350                        scanlines[SNES_SUBSCREEN].buffer[ii + x_mos] = c;
351                        scanlines[SNES_SUBSCREEN].priority[ii + x_mos] = priority;
352                        scanlines[SNES_SUBSCREEN].layer[ii + x_mos] = layer;
353                     }
354
355                     ii += x_mos - 1;
356                  }
357                  else
358                  {
359                     scanlines[SNES_SUBSCREEN].buffer[ii] = c;
360                     scanlines[SNES_SUBSCREEN].priority[ii] = priority;
361                     scanlines[SNES_SUBSCREEN].layer[ii] = layer;
362                  }
363               }
296364            }
297            else
298               c = snes_cgram[pal + colour];
365         }
366      }
299367
300            if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
368      else /* hires */
369      {
370#ifdef SNES_LAYER_DEBUG
371         if (!debug_options.windows_disabled)
372#endif /* SNES_LAYER_DEBUG */
373         /* Clip to windows */
374         if (scanlines[SNES_MAINSCREEN].clip)
375            colour &= snes_ppu.clipmasks[layer][ii >> hires];
376
377         /* Only draw if we have a colour (0 == transparent) */
378         if (colour)
379         {
380            if ((scanlines[SNES_MAINSCREEN].priority[ii >> hires] <= priority) && (ii >= 0))
301381            {
302               int x_mos;
382               if (direct_colors)
383               {
384                  /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
385                  c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
386                  c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
387               }
388               else
389                  c = snes_cgram[pal + colour];
303390
304               //TODO: 512 modes has the h values doubled.
305               for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
391               if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
306392               {
307                  scanlines[screen].buffer[ii + x_mos] = c;
308                  scanlines[screen].priority[ii + x_mos] = priority;
309                  scanlines[screen].layer[ii + x_mos] = layer;
393                  int x_mos;
394
395                  //TODO: 512 modes has the h values doubled.
396                  for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
397                  {
398                     if ((ii & 1) && scanlines[SNES_MAINSCREEN].enable)
399                     {
400                        scanlines[SNES_MAINSCREEN].buffer[(ii + x_mos) >> 1] = c;
401                        scanlines[SNES_MAINSCREEN].priority[(ii + x_mos) >> 1] = priority;
402                        scanlines[SNES_MAINSCREEN].layer[(ii + x_mos) >> 1] = layer;
403                     }
404                     else if (scanlines[SNES_SUBSCREEN].enable)
405                     {
406                        scanlines[SNES_SUBSCREEN].buffer[(ii + x_mos) >> 1] = c;
407                        scanlines[SNES_SUBSCREEN].priority[(ii + x_mos) >> 1] = priority;
408                        scanlines[SNES_SUBSCREEN].layer[(ii + x_mos) >> 1] = layer;
409                     }
410                  }
411                  ii += x_mos - 1;
310412               }
311               ii += x_mos - 1;
413               else
414               {
415                  if ((ii & 1) && scanlines[SNES_MAINSCREEN].enable)
416                  {
417                     scanlines[SNES_MAINSCREEN].buffer[ii >> 1] = c;
418                     scanlines[SNES_MAINSCREEN].priority[ii >> 1] = priority;
419                     scanlines[SNES_MAINSCREEN].layer[ii >> 1] = layer;
420                  }
421                  else if (scanlines[SNES_SUBSCREEN].enable)
422                  {
423                     scanlines[SNES_SUBSCREEN].buffer[ii >> 1] = c;
424                     scanlines[SNES_SUBSCREEN].priority[ii >> 1] = priority;
425                     scanlines[SNES_SUBSCREEN].layer[ii >> 1] = layer;
426                  }
427               }
312428            }
313            else
314            {
315               scanlines[screen].buffer[ii] = c;
316               scanlines[screen].priority[ii] = priority;
317               scanlines[screen].layer[ii] = layer;
318            }
319429         }
320430      }
321431   }
r7501r7502
326436 *
327437 * Draw 2 tiles with variable bit planes
328438 *****************************************/
329INLINE void snes_draw_tile_x2(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors )
439
440INLINE void snes_draw_tile_x2( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
330441{
331442   if (flip)
332443   {
333      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors);
334      snes_draw_tile(screen, planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors);
444      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors, hires);
445      snes_draw_tile(planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors, hires);
335446   }
336447   else
337448   {
338      snes_draw_tile(screen, planes, layer, tileaddr, x, priority, flip, pal, direct_colors);
339      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal, direct_colors);
449      snes_draw_tile(planes, layer, tileaddr, x, priority, flip, pal, direct_colors, hires);
450      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal, direct_colors, hires);
340451   }
341452}
342453
r7501r7502
347458 * The same as snes_draw_tile_4() except
348459 * that it takes a blend parameter.
349460 *****************************************/
350INLINE void snes_draw_tile_object(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend, UINT8 wide )
461
462INLINE void snes_draw_tile_object( UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend )
351463{
352   UINT8 mask, plane[4], window_enabled = 0;
464   UINT8 mask, plane[4];
353465   UINT16 c;
354466   INT16 ii;
355   UINT8 x_shift = wide ? 1 : 0;
356   UINT8 size = wide ? 16 : 8;
357   UINT8 step = wide ? 1 : 0;
358467
359468   plane[0] = snes_vram[tileaddr];
360469   plane[1] = snes_vram[tileaddr + 1];
r7501r7502
366475   else
367476      mask = 0x80;
368477
369   x <<= x_shift;
370   for (ii = x; ii < (x + size); ii += 1 + step)
478   for (ii = x; ii < (x + 8); ii++)
371479   {
372480      UINT8 colour;
373481      if (flip)
r7501r7502
383491         mask >>= 1;
384492      }
385493
494      if (scanlines[SNES_MAINSCREEN].enable)
495      {
496
386497#ifdef SNES_LAYER_DEBUG
387      if (!debug_options.windows_disabled)
498         if (!debug_options.windows_disabled)
388499#endif /* SNES_LAYER_DEBUG */
389      /* Clip to windows */
390      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[SNES_OAM].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled;
391      if (window_enabled)
392         colour &= snes_ppu.clipmasks[SNES_OAM][ii];
500         /* Clip to windows */
501         if (scanlines[SNES_MAINSCREEN].clip)
502            colour &= snes_ppu.clipmasks[SNES_OAM][ii];
393503
394      /* Only draw if we have a colour (0 == transparent) */
395      if (colour)
504         /* Only draw if we have a colour (0 == transparent) */
505         if (colour)
506         {
507            if ((scanlines[SNES_MAINSCREEN].priority[ii] <= priority) && (ii >= 0))
508            {
509               c = snes_cgram[pal + colour];
510
511               scanlines[SNES_MAINSCREEN].buffer[ii] = c;
512               scanlines[SNES_MAINSCREEN].priority[ii] = priority;
513               scanlines[SNES_MAINSCREEN].layer[ii] = SNES_OAM;
514               scanlines[SNES_MAINSCREEN].blend_exception[ii] = blend;
515            }
516         }
517      }
518
519      if (scanlines[SNES_SUBSCREEN].enable)
396520      {
397         if ((scanlines[screen].priority[ii] <= priority) && (ii >= 0))
521
522#ifdef SNES_LAYER_DEBUG
523         if (!debug_options.windows_disabled)
524#endif /* SNES_LAYER_DEBUG */
525         /* Clip to windows */
526         if (scanlines[SNES_SUBSCREEN].clip)
527            colour &= snes_ppu.clipmasks[SNES_OAM][ii];
528
529         /* Only draw if we have a colour (0 == transparent) */
530         if (colour)
398531         {
399            c = snes_cgram[pal + colour];
532            if ((scanlines[SNES_SUBSCREEN].priority[ii] <= priority) && (ii >= 0))
533            {
534               c = snes_cgram[pal + colour];
400535
401            scanlines[screen].buffer[ii] = c;
402            scanlines[screen].priority[ii] = priority;
403            scanlines[screen].layer[ii] = SNES_OAM;
404            scanlines[screen].blend_exception[ii] = blend;
405            if (wide)
406            {
407               scanlines[screen].buffer[ii + 1] = c;
408               scanlines[screen].priority[ii + 1] = priority;
409               scanlines[screen].layer[ii + 1] = SNES_OAM;
410               scanlines[screen].blend_exception[ii + 1] = blend;
536               scanlines[SNES_SUBSCREEN].buffer[ii] = c;
537               scanlines[SNES_SUBSCREEN].priority[ii] = priority;
538               scanlines[SNES_SUBSCREEN].layer[ii] = SNES_OAM;
539               scanlines[SNES_SUBSCREEN].blend_exception[ii] = blend;
411540            }
412541         }
413542      }
r7501r7502
419548 *
420549 * Update an entire line of tiles.
421550 *********************************************/
422INLINE 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 )
551
552INLINE UINT32 snes_get_tmap( UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y )
423553{
424   UINT32 tmap, tile;
425   UINT16 ii, vflip, hflip, pal;
554   UINT32 res = base;
555   x  >>= (3 + tile_size);
556   y  >>= (3 + tile_size);
557
558   res += (snes_ppu.layer[layer].tilemap_size & 2) ? ((y & 0x20) << ((snes_ppu.layer[layer].tilemap_size & 1) ? 7 : 6)) : 0;
559   /* Scroll vertically */
560   res += (y & 0x1f) << 6;
561   /* Offset horizontally */
562   res += (snes_ppu.layer[layer].tilemap_size & 1) ? ((x & 0x20) << 6) : 0;
563   /* Scroll horizontally */
564   res += (x & 0x1f) << 1;
565
566   return res;
567}
568
569INLINE 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 )
570{
571   UINT32 tmap, tile, xoff, yoff;
572   UINT16 ii = 0, vflip, hflip, pal;
426573   INT8 tile_line;
427574   UINT8 priority;
428575   /* scrolling */
429   UINT32 basevmap, charaddr;
576   UINT32 charaddr;
430577   UINT16 vscroll, hscroll;
431//  UINT16 offset_per_tile_valid;
432//  UINT8 offset_per_tile_mode;
578   UINT16 opt_bit = (layer == SNES_BG1) ? 13 : (layer == SNES_BG2) ? 14 : 0;
433579   UINT8 vshift, hshift, tile_size;
434580   /* variables depending on color_depth */
435581   UINT8 color_shift = 0;
436582   UINT8 color_planes = 2;
437583   UINT8 tile_divider = 1;
438   UINT8 wrap_around_x; //helper for wrap-around
439584
440585#ifdef SNES_LAYER_DEBUG
441586   if (debug_options.bg_disabled[layer])
442587      return;
588#endif /* SNES_LAYER_DEBUG */
443589
444   if (debug_options.mode_disabled[snes_ppu.mode])
590   scanlines[SNES_MAINSCREEN].enable = snes_ppu.main_bg_enabled[layer];
591   scanlines[SNES_SUBSCREEN].enable = snes_ppu.sub_bg_enabled[layer];
592   scanlines[SNES_MAINSCREEN].clip = snes_ppu.layer[layer].main_window_enabled;
593   scanlines[SNES_SUBSCREEN].clip = snes_ppu.layer[layer].sub_window_enabled;
594
595   if (!scanlines[SNES_MAINSCREEN].enable && !scanlines[SNES_SUBSCREEN].enable)
445596      return;
446#endif /* SNES_LAYER_DEBUG */
447597
448598   /* Handle Mosaic effects */
449599   if (snes_ppu.layer[layer].mosaic_enabled)
r7501r7502
461611   vscroll = ((snes_ppu.layer[layer].voffs & 0x3ff) + curline) >> (3 + tile_size);
462612   vshift = ((snes_ppu.layer[layer].voffs & 0x3ff) + curline) & ((8 << tile_size) - 1);
463613
614   xoff = snes_ppu.layer[layer].hoffs;
615   yoff = snes_ppu.layer[layer].voffs;
616
464617   /* figure out which line to draw */
465618   if (vshift > ((8 << tile_size) - 1))   /* scrolled into the next tile */
466619   {
r7501r7502
474627   tmap = snes_ppu.layer[layer].tilemap << 9;
475628   charaddr = snes_ppu.layer[layer].charmap << 13;
476629
477   /* Offset vertically */
478   tmap += (snes_ppu.layer[layer].tilemap_size & 2) ? ((vscroll & 0x20) << ((snes_ppu.layer[layer].tilemap_size & 1) ? 7 : 6)) : 0;
479   /* Scroll vertically */
480   tmap += (vscroll & 0x1f) << 6;
481   /* Remember this position */
482   basevmap = tmap;
483   /* Offset horizontally */
484   tmap += (snes_ppu.layer[layer].tilemap_size & 1) ? ((hscroll & 0x20) << 6) : 0;
485   /* Scroll horizontally */
486   tmap += (hscroll & 0x1f) << 1;
487
488630   /* set a couple of variables depending on color_dept */
489631   switch (color_depth)
490632   {
r7501r7502
505647         break;
506648   }
507649
508   wrap_around_x = 1;
509
510   for (ii = 0; ii < (66*(hires+1) >> tile_size); ii += 2)
650   while (ii < 256)
511651   {
512      /* Have we scrolled into the next map? */
513      if (wrap_around_x && ((ii >> 1) >= 32 - (hscroll & 0x1f)))
514      {
515         tmap = basevmap + table_hscroll[snes_ppu.layer[layer].tilemap_size & 3][((hscroll >> 5) + 1) & 3];
516         tmap -= ii;
517         wrap_around_x = 0;   /* Make sure we don't do this again */
518      }
519      //if (tmap > 0x10000)
520      //  tmap %= 0x10000;
521
522652      /*
523653        Tilemap format
524654          vhopppcc cccccccc
r7501r7502
528658          ppp  = Tile palette. The number of entries in the palette depends on the Mode and the BG.
529659          cccccccccc = Tile number.
530660        */
531      UINT16 tilemap = snes_vram[tmap + ii] | (snes_vram[tmap + ii + 1] << 8);
661
662      // determine the horizontal position (Bishojo Janshi Suchi Pai & Desert Figther have tile_size & hires == 1)
663      UINT32 xpos = xoff + (ii << (tile_size * hires));
664      UINT32 ypos = yoff + curline;
665
666      if (offset_per_tile != SNES_OPT_NONE)
667      {
668         int opt_x = ii + (xoff & 7);
669         UINT32 haddr = 0, vaddr = 0;
670         UINT16 hval = 0, vval = 0;
671
672            if (opt_x >= 8)
673         {
674            switch (offset_per_tile)
675            {
676            case SNES_OPT_MODE2:
677            case SNES_OPT_MODE6:
678               haddr = snes_get_tmap(SNES_BG3, snes_ppu.layer[SNES_BG3].tile_size, snes_ppu.layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((snes_ppu.layer[SNES_BG3].hoffs & 0x3ff) & ~7), (snes_ppu.layer[SNES_BG3].voffs & 0x3ff));
679               vaddr = snes_get_tmap(SNES_BG3, snes_ppu.layer[SNES_BG3].tile_size, snes_ppu.layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((snes_ppu.layer[SNES_BG3].hoffs & 0x3ff) & ~7), (snes_ppu.layer[SNES_BG3].voffs & 0x3ff) + 8);
680               hval = snes_vram[haddr] | (snes_vram[haddr + 1] << 8);
681               vval = snes_vram[vaddr] | (snes_vram[vaddr + 1] << 8);
682               if (BIT(hval, opt_bit))
683                  xpos = opt_x + (hval & ~7);
684               if (BIT(vval, opt_bit))
685                  ypos = curline + vval;
686               break;
687            case SNES_OPT_MODE4:
688               haddr = snes_get_tmap(SNES_BG3, snes_ppu.layer[SNES_BG3].tile_size, snes_ppu.layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((snes_ppu.layer[SNES_BG3].hoffs & 0x3ff) & ~7), (snes_ppu.layer[SNES_BG3].voffs & 0x3ff));
689               hval = snes_vram[haddr] | (snes_vram[haddr + 1] << 8);
690               if (BIT(hval, opt_bit))
691               {
692                  if (!BIT(hval, 15))
693                     xpos = opt_x + (hval & ~7);
694                  else
695                     ypos = curline + hval;
696               }
697               break;
698            }
699
700         }
701      }
702
703      UINT32 addr = snes_get_tmap(layer, tile_size, tmap, xpos, ypos);
704      UINT16 tilemap = snes_vram[addr] | (snes_vram[addr + 1] << 8);
532705      vflip = BIT(tilemap, 15);
533706      hflip = BIT(tilemap, 14);
534707      priority = BIT(tilemap, 13) ? priority_b : priority_a;
r7501r7502
568741      tile_line <<= 1;
569742
570743      /* below, only color_planes depends on color_depth */
571      if (tile_size)
744      if (hires)   /* Hi-Res: 2bpp & 4bpp */
572745      {
573         snes_draw_tile_x2(screen, color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal, direct_colors);
746         snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii * 2, priority, hflip, pal, direct_colors, hires);
747         ii += 8;
574748      }
575749      else   /* tile_size = 0 */
576750      {
577         if (hires)   /* Hi-Res: 2bpp & 4bpp */
578            snes_draw_tile_x2(screen, color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal, direct_colors);
751         if (tile_size)
752         {
753            snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
754            ii += 16;
755         }
579756         else   /* No Hi-Res: 2bpp, 4bpp & 8bpp */
580            snes_draw_tile(screen, color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal, direct_colors);
757         {
758            snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
759            ii += 8;
760         }
581761      }
582762   }
583763}
r7501r7502
588768 *
589769 * Update an entire line of mode7 tiles.
590770 *********************************************/
771
591772#define MODE7_CLIP(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff))
592773
593static void snes_update_line_mode7(UINT8 screen, UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline )
774static void snes_update_line_mode7( UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline )
594775{
595776   UINT32 tiled;
596777   INT16 ma, mb, mc, md;
597778   INT32 xc, yc, tx, ty, sx, sy, hs, vs, xpos, xdir, x0, y0;
598779   UINT8 priority = priority_a;
599   UINT8 colour = 0, window_enabled = 0;
780   UINT8 colour = 0;
600781   UINT16 *mosaic_x, *mosaic_y;
601782
602783#ifdef SNES_LAYER_DEBUG
603784   if (debug_options.bg_disabled[layer])
604785      return;
786#endif /* SNES_LAYER_DEBUG */
605787
606   if (debug_options.mode_disabled[snes_ppu.mode])
788   scanlines[SNES_MAINSCREEN].enable = snes_ppu.main_bg_enabled[layer];
789   scanlines[SNES_SUBSCREEN].enable = snes_ppu.sub_bg_enabled[layer];
790   scanlines[SNES_MAINSCREEN].clip = snes_ppu.layer[layer].main_window_enabled;
791   scanlines[SNES_SUBSCREEN].clip = snes_ppu.layer[layer].sub_window_enabled;
792
793   if (!scanlines[SNES_MAINSCREEN].enable && !scanlines[SNES_SUBSCREEN].enable)
607794      return;
608#endif /* SNES_LAYER_DEBUG */
609795
610796   ma = snes_ppu.mode7.matrix_a;
611797   mb = snes_ppu.mode7.matrix_b;
r7501r7502
701887         colour &= 0x7f;
702888      }
703889
704      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
705      if (window_enabled)
706         colour &= snes_ppu.clipmasks[layer][xpos];
890      if (scanlines[SNES_MAINSCREEN].enable)
891      {
892         if (scanlines[SNES_MAINSCREEN].clip)
893            colour &= snes_ppu.clipmasks[layer][xpos];
707894
708      /* Draw pixel if appropriate */
709      if (scanlines[screen].priority[xpos] <= priority && colour > 0)
895         /* Draw pixel if appropriate */
896         if (scanlines[SNES_MAINSCREEN].priority[xpos] <= priority && colour > 0)
897         {
898            UINT16 clr;
899            /* Direct select, but only outside EXTBG! */
900            if (snes_ppu.direct_color && layer == 0)
901            {
902               /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
903               clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
904            }
905            else
906               clr = snes_cgram[colour];
907
908            scanlines[SNES_MAINSCREEN].buffer[xpos] = clr;
909            scanlines[SNES_MAINSCREEN].priority[xpos] = priority;
910            scanlines[SNES_MAINSCREEN].layer[xpos] = layer;
911         }
912      }
913
914      if (scanlines[SNES_SUBSCREEN].enable)
710915      {
711         UINT16 clr;
712         /* Direct select, but only outside EXTBG! */
713         if (snes_ppu.direct_color && layer == 0)
916         if (scanlines[SNES_SUBSCREEN].clip)
917            colour &= snes_ppu.clipmasks[layer][xpos];
918
919         /* Draw pixel if appropriate */
920         if (scanlines[SNES_SUBSCREEN].priority[xpos] <= priority && colour > 0)
714921         {
715            /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
716            clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
922            UINT16 clr;
923            /* Direct select, but only outside EXTBG! */
924            if (snes_ppu.direct_color && layer == 0)
925            {
926               /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
927               clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
928            }
929            else
930               clr = snes_cgram[colour];
931
932            scanlines[SNES_SUBSCREEN].buffer[xpos] = clr;
933            scanlines[SNES_SUBSCREEN].priority[xpos] = priority;
934            scanlines[SNES_SUBSCREEN].layer[xpos] = layer;
717935         }
718         else
719            clr = snes_cgram[colour];
720
721         scanlines[screen].buffer[xpos] = clr;
722         scanlines[screen].priority[xpos] = priority;
723         scanlines[screen].layer[xpos] = layer;
724936      }
725937   }
726938}
r7501r7502
731943 * Update an entire line of sprites.
732944 * FIXME: We need to support high priority bit
733945 *********************************************/
734static void snes_update_objects( UINT8 screen, UINT8 priority_tbl, UINT16 curline )
946
947static void snes_update_objects( UINT8 priority_tbl, UINT16 curline )
735948{
736949   INT8 xs, ys;
737   UINT8 line, widemode = 0;
950   UINT8 line;
738951   UINT16 oam_extra, extra;
739952   INT16 oam;
740953   UINT8 range_over = 0, time_over = 0;
r7501r7502
757970   };
758971
759972#ifdef SNES_LAYER_DEBUG
760   if (debug_options.bg_disabled[4])
973   if (debug_options.bg_disabled[SNES_OAM])
761974      return;
762975#endif /* SNES_LAYER_DEBUG */
763976
764   if (snes_ppu.mode == 5 || snes_ppu.mode == 6)
765      widemode = 1;
977   scanlines[SNES_MAINSCREEN].enable = snes_ppu.main_bg_enabled[SNES_OAM];
978   scanlines[SNES_SUBSCREEN].enable = snes_ppu.sub_bg_enabled[SNES_OAM];
979   scanlines[SNES_MAINSCREEN].clip = snes_ppu.layer[SNES_OAM].main_window_enabled;
980   scanlines[SNES_SUBSCREEN].clip = snes_ppu.layer[SNES_OAM].sub_window_enabled;
766981
982   if (!scanlines[SNES_MAINSCREEN].enable && !scanlines[SNES_SUBSCREEN].enable)
983      return;
984
767985   curline /= snes_ppu.interlace;
768986   curline *= snes_ppu.obj_interlace;
769987
r7501r7502
7891007      extra <<= 1;
7901008      x |= ((extra & 0x80) << 1);
7911009      extra <<= 1;
792      y*=snes_ppu.obj_interlace;
1010      y *= snes_ppu.obj_interlace;
7931011
7941012      /* Adjust if past maximum position */
7951013      if (y >= snes_ppu.beam.last_visible_line*snes_ppu.interlace)
r7501r7502
8221040            {
8231041               if ((x + (count << 3) < SNES_SCR_WIDTH + 8))
8241042               {
825                  if (widemode)
826                     snes_draw_tile_object(screen, charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, 1);
827                  else
828                     snes_draw_tile_object(screen, charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, 0);
1043                  snes_draw_tile_object(charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend);
8291044               }
8301045               time_over++;   /* Increase time_over. Should we stop drawing if exceeded 34 tiles? */
8311046            }
r7501r7502
8361051            {
8371052               if ((x + (xs << 3) < SNES_SCR_WIDTH + 8))
8381053               {
839                  if (widemode)
840                     snes_draw_tile_object(screen, charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, 1);
841                  else
842                     snes_draw_tile_object(screen, charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, 0);
1054                  snes_draw_tile_object(charaddr + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend);
8431055               }
8441056               time_over++;   /* Increase time_over. Should we stop drawing if exceeded 34 tiles? */
8451057            }
r7501r7502
8701082 *
8711083 * Update Mode X line.
8721084 *********************************************/
873static void snes_update_mode_0( UINT8 screen, UINT16 curline )
1085
1086static void snes_update_mode_0( UINT16 curline )
8741087{
875   UINT8 *bg_enabled;
876   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1088#ifdef SNES_LAYER_DEBUG
1089   if (debug_options.mode_disabled[0])
1090      return;
1091#endif /* SNES_LAYER_DEBUG */
8771092
878   if (bg_enabled[4]) snes_update_objects(screen, 0, curline);
879   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, SNES_BG1, curline, 0, 0);
880   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 6, 9, SNES_BG2, curline, 0, 0);
881   if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 1, 4, SNES_BG3, curline, 0, 0);
882   if (bg_enabled[3]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 3, SNES_BG4, curline, 0, 0);
1093   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 3, SNES_BG4, curline, SNES_OPT_NONE, 0);
1094   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 1, 4, SNES_BG3, curline, SNES_OPT_NONE, 0);
1095   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 6, 9, SNES_BG2, curline, SNES_OPT_NONE, 0);
1096   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 7, 10, SNES_BG1, curline, SNES_OPT_NONE, 0);
1097   snes_update_objects(0, curline);
8831098}
8841099
885static void snes_update_mode_1( UINT8 screen, UINT16 curline )
1100static void snes_update_mode_1( UINT16 curline )
8861101{
887   UINT8 *bg_enabled;
888   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1102#ifdef SNES_LAYER_DEBUG
1103   if (debug_options.mode_disabled[1])
1104      return;
1105#endif /* SNES_LAYER_DEBUG */
8891106
8901107   if (!snes_ppu.bg3_priority_bit)
8911108   {
892      if (bg_enabled[4]) snes_update_objects(screen, 1, curline);
893      if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 5, 8, SNES_BG1, curline, 0, 0);
894      if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG2, curline, 0, 0);
895      if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 2, SNES_BG3, curline, 0, 0);
1109      snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 2, SNES_BG3, curline, SNES_OPT_NONE, 0);
1110      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG2, curline, SNES_OPT_NONE, 0);
1111      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 5, 8, SNES_BG1, curline, SNES_OPT_NONE, 0);
1112      snes_update_objects(1, curline);
8961113   }
8971114   else
8981115   {
899      if (bg_enabled[4]) snes_update_objects(screen, 9, curline);
900      if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG1, curline, 0, 0);
901      if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 3, 6, SNES_BG2, curline, 0, 0);
902      if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 9, SNES_BG3, curline, 0, 0);
1116      snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 9, SNES_BG3, curline, SNES_OPT_NONE, 0);
1117      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 3, 6, SNES_BG2, curline, SNES_OPT_NONE, 0);
1118      snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG1, curline, SNES_OPT_NONE, 0);
1119      snes_update_objects(9, curline);
9031120   }
9041121}
9051122
906static void snes_update_mode_2( UINT8 screen, UINT16 curline )
1123static void snes_update_mode_2( UINT16 curline )
9071124{
908   UINT8 *bg_enabled;
909   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1125#ifdef SNES_LAYER_DEBUG
1126   if (debug_options.mode_disabled[2])
1127      return;
1128#endif /* SNES_LAYER_DEBUG */
9101129
911   if (bg_enabled[4]) snes_update_objects(screen, 2, curline);
912   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, SNES_BG1, curline, 1, 0);
913   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 1, 0);
1130   snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, SNES_OPT_MODE2, 0);
1131   snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 2, 6, SNES_BG1, curline, SNES_OPT_MODE2, 0);
1132   snes_update_objects(2, curline);
9141133}
9151134
916static void snes_update_mode_3( UINT8 screen, UINT16 curline )
1135static void snes_update_mode_3( UINT16 curline )
9171136{
918   UINT8 *bg_enabled;
919   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1137#ifdef SNES_LAYER_DEBUG
1138   if (debug_options.mode_disabled[3])
1139      return;
1140#endif /* SNES_LAYER_DEBUG */
9201141
921   if (bg_enabled[4]) snes_update_objects(screen, 3, curline);
922   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color);
923   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 0, 0);
1142   snes_update_line(SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, SNES_OPT_NONE, 0);
1143   snes_update_line(SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, SNES_OPT_NONE, snes_ppu.direct_color);
1144   snes_update_objects(3, curline);
9241145}
9251146
926static void snes_update_mode_4( UINT8 screen, UINT16 curline )
1147static void snes_update_mode_4( UINT16 curline )
9271148{
928   UINT8 *bg_enabled;
929   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1149#ifdef SNES_LAYER_DEBUG
1150   if (debug_options.mode_disabled[4])
1151      return;
1152#endif /* SNES_LAYER_DEBUG */
9301153
931   if (bg_enabled[4]) snes_update_objects(screen, 4, curline);
932   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color);
933   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 4, SNES_BG2, curline, 0, 0);
1154   snes_update_line(SNES_COLOR_DEPTH_2BPP, 0, 0, 4, SNES_BG2, curline, SNES_OPT_MODE4, 0);
1155   snes_update_line(SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, SNES_OPT_MODE4, snes_ppu.direct_color);
1156   snes_update_objects(4, curline);
9341157}
9351158
936static void snes_update_mode_5( UINT8 screen, UINT16 curline )
1159static void snes_update_mode_5( UINT16 curline )
9371160{
938   UINT8 *bg_enabled;
939   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1161#ifdef SNES_LAYER_DEBUG
1162   if (debug_options.mode_disabled[5])
1163      return;
1164#endif /* SNES_LAYER_DEBUG */
9401165
941   if (bg_enabled[4]) snes_update_objects(screen, 5, curline);
942   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, SNES_BG1, curline, 0, 0);
943   if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 1, 0, 4, SNES_BG2, curline, 0, 0);
1166   snes_update_line(SNES_COLOR_DEPTH_4BPP, 1, 2, 6, SNES_BG1, curline, SNES_OPT_NONE, 0);
1167   snes_update_line(SNES_COLOR_DEPTH_2BPP, 1, 0, 4, SNES_BG2, curline, SNES_OPT_NONE, 0);
1168   snes_update_objects(5, curline);
9441169}
9451170
946static void snes_update_mode_6( UINT8 screen, UINT16 curline )
1171static void snes_update_mode_6( UINT16 curline )
9471172{
948   UINT8 *bg_enabled;
949   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1173#ifdef SNES_LAYER_DEBUG
1174   if (debug_options.mode_disabled[6])
1175      return;
1176#endif /* SNES_LAYER_DEBUG */
9501177
951   if (bg_enabled[4]) snes_update_objects(screen, 6, curline);
952   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, SNES_BG1, curline, 1, 0);
1178   snes_update_line(SNES_COLOR_DEPTH_4BPP, 1, 1, 4, SNES_BG1, curline, SNES_OPT_MODE6, 0);
1179   snes_update_objects(6, curline);
9531180}
9541181
955static void snes_update_mode_7( UINT8 screen, UINT16 curline )
1182static void snes_update_mode_7( UINT16 curline )
9561183{
957   UINT8 *bg_enabled;
958   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
1184#ifdef SNES_LAYER_DEBUG
1185   if (debug_options.mode_disabled[7])
1186      return;
1187#endif /* SNES_LAYER_DEBUG */
9591188
9601189   if (!snes_ppu.mode7.extbg)
9611190   {
962      if (bg_enabled[4]) snes_update_objects(screen, 7, curline);
963      if (bg_enabled[0]) snes_update_line_mode7(screen, 1, 1, SNES_BG1, curline);
1191      snes_update_line_mode7(1, 1, SNES_BG1, curline);
1192      snes_update_objects(7, curline);
9641193   }
9651194   else
9661195   {
967      if (bg_enabled[4]) snes_update_objects(screen, 8, curline);
968      if (bg_enabled[0]) snes_update_line_mode7(screen, 2, 2, SNES_BG1, curline);
969      if (bg_enabled[1]) snes_update_line_mode7(screen, 0, 4, SNES_BG2, curline);
1196      snes_update_line_mode7(0, 4, SNES_BG2, curline);
1197      snes_update_line_mode7(2, 2, SNES_BG1, curline);
1198      snes_update_objects(8, curline);
9701199   }
9711200}
9721201
9731202/*********************************************
974 * snes_draw_screen()
1203 * snes_draw_screens()
9751204 *
9761205 * Draw the whole screen (Mode 0 -> 7).
9771206 *********************************************/
978static void snes_draw_screen( UINT8 screen, UINT16 curline )
1207
1208static void snes_draw_screens( UINT16 curline )
9791209{
9801210   switch (snes_ppu.mode)
9811211   {
982      case 0: snes_update_mode_0(screen, curline); break;      /* Mode 0 */
983      case 1: snes_update_mode_1(screen, curline); break;      /* Mode 1 */
984      case 2: snes_update_mode_2(screen, curline); break;      /* Mode 2 - Supports offset per tile */
985      case 3: snes_update_mode_3(screen, curline); break;      /* Mode 3 - Supports direct colour */
986      case 4: snes_update_mode_4(screen, curline); break;      /* Mode 4 - Supports offset per tile and direct colour */
987      case 5: snes_update_mode_5(screen, curline); break;      /* Mode 5 - Supports hires */
988      case 6: snes_update_mode_6(screen, curline); break;      /* Mode 6 - Supports offset per tile and hires */
989      case 7: snes_update_mode_7(screen, curline); break;      /* Mode 7 - Supports direct colour */
1212      case 0: snes_update_mode_0(curline); break;      /* Mode 0 */
1213      case 1: snes_update_mode_1(curline); break;      /* Mode 1 */
1214      case 2: snes_update_mode_2(curline); break;      /* Mode 2 - Supports offset per tile */
1215      case 3: snes_update_mode_3(curline); break;      /* Mode 3 - Supports direct colour */
1216      case 4: snes_update_mode_4(curline); break;      /* Mode 4 - Supports offset per tile and direct colour */
1217      case 5: snes_update_mode_5(curline); break;      /* Mode 5 - Supports hires */
1218      case 6: snes_update_mode_6(curline); break;      /* Mode 6 - Supports offset per tile and hires */
1219      case 7: snes_update_mode_7(curline); break;      /* Mode 7 - Supports direct colour */
9901220   }
9911221}
9921222
r7501r7502
10021232 * XOR:  ...###..###...     ###...##...###
10031233 * XNOR: ###...##...###     ...###..###...
10041234 *********************************************/
1005static void snes_update_windowmasks(void)
1235
1236static void snes_update_windowmasks( void )
10061237{
10071238   UINT16 ii, jj;
10081239   INT8 w1, w2;
r7501r7502
10731304 *
10741305 * Update the offsets with the latest changes.
10751306 *********************************************/
1076static void snes_update_offsets(void)
1307
1308static void snes_update_offsets( void )
10771309{
10781310   int ii;
10791311   for (ii = 0; ii < 4; ii++)
r7501r7502
10871319 *
10881320 * Redraw the current line.
10891321 *********************************************/
1322
10901323static void snes_refresh_scanline( running_machine *machine, bitmap_t *bitmap, UINT16 curline )
10911324{
10921325   UINT16 ii;
r7501r7502
11331366         scanlines[SNES_MAINSCREEN].buffer[ii] = snes_cgram[0];
11341367      }
11351368
1136      /* Draw SNES_SUBSCREEN */
1137      snes_draw_screen(SNES_SUBSCREEN, curline);
1369      /* Draw screens */
1370      snes_draw_screens(curline);
11381371
1139      /* Draw SNES_MAINSCREEN */
1140      snes_draw_screen(SNES_MAINSCREEN, curline);
1141
11421372#ifdef SNES_LAYER_DEBUG
11431373      if (snes_dbg_video(machine, bitmap, curline))
11441374      {
r7501r7502
11561386      /* Phew! Draw the line to screen */
11571387      fade = snes_ppu.screen_brightness;
11581388
1159      for (x = 0; x < SNES_SCR_WIDTH * 2; x += 2)
1389      for (x = 0; x < SNES_SCR_WIDTH * 2; x++)
11601390      {
1161         if (snes_ppu.mode != 5 && snes_ppu.mode != 6)
1162         {
1163            int r, g, b;
1164            c = scanline->buffer[x];
1391         int r, g, b, hires;
1392         UINT16 temp_col;
1393         hires = (snes_ppu.mode != 5 && snes_ppu.mode != 6) ? 0 : 1;
1394         c = scanline->buffer[x];
1395         temp_col = scanline->buffer[x];
11651396
1166            /* perform color math if the layer wants it (except if it's an object > 192) */
1167            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1168               snes_draw_blend_lores(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1397         /* perform color math if the layer wants it (except if it's an object > 192) */
1398         if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1399            snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
11691400
1170            r = ((c & 0x1f) * fade) >> 4;
1171            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1172            b = (((c & 0x7c00) >> 10) * fade) >> 4;
1401         r = ((c & 0x1f) * fade) >> 4;
1402         g = (((c & 0x3e0) >> 5) * fade) >> 4;
1403         b = (((c & 0x7c00) >> 10) * fade) >> 4;
11731404
1174            *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1405         *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1406
1407         if (!hires)
11751408            *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1176
1177            c = scanline->buffer[x + 1];
1178
1179            /* perform color math if the layer wants it (except if it's an object > 192) */
1180            if (!scanlines[SNES_MAINSCREEN].blend_exception[x + 1] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x + 1]].color_math)
1181               snes_draw_blend_lores(x + 1, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1182
1183            r = ((c & 0x1f) * fade) >> 4;
1184            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1185            b = (((c & 0x7c00) >> 10) * fade) >> 4;
1186
1187            *BITMAP_ADDR32(bitmap, curline, (x + 1) * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1188            *BITMAP_ADDR32(bitmap, curline, (x + 1) * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1189
1190         }
11911409         else
11921410         {
1193            int r, g, b;
1194            UINT16 temp_col;
1195            c = scanline->buffer[x];
1196            temp_col = scanline->buffer[x];
1197
1198            /* perform color math if the layer wants it (except if it's an object > 192) */
1199            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1200               snes_draw_blend_hires(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1201
1202            r = ((c & 0x1f) * fade) >> 4;
1203            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1204            b = (((c & 0x7c00) >> 10) * fade) >> 4;
1205
1206            *BITMAP_ADDR32(bitmap, curline, x) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1207
12081411            c = scanlines[SNES_SUBSCREEN].buffer[x];
12091412            scanlines[SNES_SUBSCREEN].buffer[x] = temp_col;
12101413
1211            /* perform color math only if it's been done on the previous pixel */
1212            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1213               snes_draw_blend_hires(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1414            if (!scanlines[SNES_SUBSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1415               snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
12141416
12151417            r = ((c & 0x1f) * fade) >> 4;
12161418            g = (((c & 0x3e0) >> 5) * fade) >> 4;
12171419            b = (((c & 0x7c00) >> 10) * fade) >> 4;
12181420
1219            *BITMAP_ADDR32(bitmap, curline, x + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1421            *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
12201422         }
12211423      }
12221424   }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team