Previous 199869 Revisions Next

r31934 Friday 5th September, 2014 at 22:26:12 UTC by hap
draw sprites front to back, this fixes some issues with shadow
[src/mame/includes]seibuspi.h
[src/mame/video]seibuspi.c

trunk/src/mame/includes/seibuspi.h
r31933r31934
121121   INTERRUPT_GEN_MEMBER(spi_interrupt);
122122
123123   void set_layer_offsets();
124   void drawgfx_blend(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy);
125   void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, int pri_mask);
124   void drawgfx_blend(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy, bitmap_ind8 &primap, int primask);
125   void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, bitmap_ind8 &primap, int priority);
126126   void set_rowscroll(tilemap_t *layer, int scroll, INT16* rows);
127127   void set_scroll(tilemap_t *layer, int scroll);
128   void combine_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect, tilemap_t *tile, int x, int y, int opaque, INT16 *rowscroll);
128   void combine_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect, tilemap_t *tile, int sx, int sy, int opaque, INT16 *rowscroll);
129129
130130   virtual void machine_start();
131131   virtual void video_start();
trunk/src/mame/video/seibuspi.c
r31933r31934
229229
230230/*****************************************************************************/
231231
232void seibuspi_state::drawgfx_blend(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy)
232void seibuspi_state::drawgfx_blend(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy, bitmap_ind8 &primap, int primask)
233233{
234   const pen_t *pens = &m_palette->pen(gfx->colorbase());
235   const UINT8 *dp;
236   int i, j;
237   int x1, x2;
238   int y1, y2;
239   int px, py;
240   int xd = 1, yd = 1;
241
242234   int width = gfx->width();
243235   int height = gfx->height();
244236
245   x1 = sx;
246   x2 = sx + width - 1;
247   y1 = sy;
248   y2 = sy + height - 1;
237   int x1 = sx;
238   int x2 = sx + width - 1;
239   int y1 = sy;
240   int y2 = sy + height - 1;
249241
250242   if (x1 > cliprect.max_x || x2 < cliprect.min_x)
251243   {
r31933r31934
256248      return;
257249   }
258250
259   px = 0;
260   py = 0;
251   int px = 0;
252   int py = 0;
253   int xd = 1;
254   int yd = 1;
261255
262256   if (flipx)
263257   {
r31933r31934
306300      y2 = cliprect.max_y;
307301   }
308302
309   dp = gfx->get_data(code);
303   const pen_t *pens = &m_palette->pen(gfx->colorbase());
304   const UINT8 *src = gfx->get_data(code);
310305
311306   // draw
312   for (j = y1; j <= y2; j++)
307   for (int y = y1; y <= y2; y++)
313308   {
314      UINT32 *p = &bitmap.pix32(j);
309      UINT32 *dest = &bitmap.pix32(y);
310      UINT8 *pri = &primap.pix8(y);
315311      UINT8 trans_pen = (1 << m_sprite_bpp) - 1;
316      int dp_i = (py * width) + px;
312      int src_i = (py * width) + px;
317313      py += yd;
318314
319      for (i = x1; i <= x2; i++)
315      for (int x = x1; x <= x2; x++)
320316      {
321         UINT8 pen = dp[dp_i];
322         if (pen != trans_pen)
317         UINT8 pen = src[src_i];
318         if (!(pri[x] & primask) && pen != trans_pen)
323319         {
320            pri[x] |= primask;
324321            int global_pen = pen + (color << m_sprite_bpp);
325322            if (m_alpha_enable && m_alpha_table[global_pen])
326            {
327               p[i] = alpha_blend_r32(p[i], pens[global_pen], 0x7f);
328            }
323               dest[x] = alpha_blend_r32(dest[x], pens[global_pen], 0x7f);
329324            else
330            {
331               p[i] = pens[global_pen];
332            }
325               dest[x] = pens[global_pen];
333326         }
334         dp_i += xd;
327         src_i += xd;
335328      }
336329   }
337330}
338331
339void seibuspi_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, int pri_mask)
332void seibuspi_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, bitmap_ind8 &primap, int priority)
340333{
341   INT16 xpos, ypos;
342   int tile_num, color;
343   int width, height;
344   int flip_x, flip_y;
345   int priority;
346   int x1, y1;
347334   gfx_element *gfx = m_gfxdecode->gfx(2);
348335   const int has_tile_high = (gfx->elements() > 0x10000) ? 1 : 0;
349336   const int colormask = (m_sprite_bpp == 6) ? 0x3f : 0x1f;
r31933r31934
362349   if (m_layer_enable & 0x10)
363350      return;
364351
365   for (int a = m_sprite_ram_size / 4 - 2; a >= 0; a -= 2)
352   for (int a = 0; a < (m_sprite_ram_size / 4); a += 2)
366353   {
367354      /*
368355          Word 0
r31933r31934
379366          -------- -------- ---x---- --------  tile_num high (only on RISE10/11 chip)
380367          -------- -------- ------xx xxxxxxxx  xpos
381368      */
382      tile_num = m_sprite_ram[a + 0] >> 16 & 0xffff;
369      int tile_num = m_sprite_ram[a + 0] >> 16 & 0xffff;
383370      if (tile_num == 0)
384371         continue;
385372
386373      if (has_tile_high)
387374         tile_num |= m_sprite_ram[a + 1] << 4 & 0x10000;
388375
389      priority = m_sprite_ram[a + 0] >> 6 & 0x3;
390      if (pri_mask != priority)
376      if (priority != (m_sprite_ram[a + 0] >> 6 & 0x3))
391377         continue;
378      int primask = 1 << priority;
392379
393      xpos = m_sprite_ram[a + 1] & 0x3ff;
380      INT16 xpos = m_sprite_ram[a + 1] & 0x3ff;
394381      if (xpos & 0x200)
395382         xpos |= 0xfc00;
396      ypos = m_sprite_ram[a + 1] >> 16 & 0x1ff;
383      INT16 ypos = m_sprite_ram[a + 1] >> 16 & 0x1ff;
397384      if (ypos & 0x100)
398385         ypos |= 0xfe00;
399      color = m_sprite_ram[a + 0] & colormask;
386      int color = m_sprite_ram[a + 0] & colormask;
400387
401      width = (m_sprite_ram[a + 0] >> 8 & 0x7) + 1;
402      height = (m_sprite_ram[a + 0] >> 12 & 0x7) + 1;
403      flip_x = m_sprite_ram[a + 0] >> 11 & 0x1;
404      flip_y = m_sprite_ram[a + 0] >> 15 & 0x1;
405      x1 = 0;
406      y1 = 0;
388      int width = (m_sprite_ram[a + 0] >> 8 & 0x7) + 1;
389      int height = (m_sprite_ram[a + 0] >> 12 & 0x7) + 1;
390      int flip_x = m_sprite_ram[a + 0] >> 11 & 0x1;
391      int flip_y = m_sprite_ram[a + 0] >> 15 & 0x1;
392      int x1 = 0;
393      int y1 = 0;
407394
408395      if (flip_x)
409396      {
r31933r31934
420407      {
421408         for (int y = y1; y < height; y++)
422409         {
423            drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y]);
410            drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y], primap, primask);
424411
425412            /* xpos seems to wrap-around to 0 at 512 */
426413            if ((xpos + (16 * x) + 16) >= 512)
427            {
428               drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos - 512 + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y]);
429            }
414               drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos - 512 + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y], primap, primask);
430415
431416            tile_num++;
432417         }
r31933r31934
434419   }
435420}
436421
437void seibuspi_state::combine_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect, tilemap_t *tile, int x, int y, int opaque, INT16 *rowscroll)
422void seibuspi_state::combine_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect, tilemap_t *tile, int sx, int sy, int opaque, INT16 *rowscroll)
438423{
439   UINT16 *s;
440   UINT32 *d;
441   UINT8 *t;
424   UINT16 *src;
425   UINT32 *dest;
426   UINT8 *flags;
442427   UINT32 xscroll_mask, yscroll_mask;
443428
444429   bitmap_ind16 &pen_bitmap = tile->pixmap();
r31933r31934
446431   xscroll_mask = pen_bitmap.width() - 1;
447432   yscroll_mask = pen_bitmap.height() - 1;
448433
449   for (int j = cliprect.min_y; j <= cliprect.max_y; j++)
434   for (int y = cliprect.min_y; y <= cliprect.max_y; y++)
450435   {
451      int rx = x;
436      int rx = sx;
452437      if (rowscroll)
453438      {
454         rx += rowscroll[(j+y) & yscroll_mask];
439         rx += rowscroll[(y + sy) & yscroll_mask];
455440      }
456441
457      d = &bitmap.pix32(j);
458      s = &pen_bitmap.pix16((j+y) & yscroll_mask);
459      t = &flags_bitmap.pix8((j+y) & yscroll_mask);
460      for (int i = cliprect.min_x+rx; i <= cliprect.max_x+rx; i++)
442      dest = &bitmap.pix32(y);
443      src = &pen_bitmap.pix16((y + sy) & yscroll_mask);
444      flags = &flags_bitmap.pix8((y + sy) & yscroll_mask);
445      for (int x = cliprect.min_x + rx; x <= cliprect.max_x + rx; x++)
461446      {
462         if (opaque || (t[i & xscroll_mask] & (TILEMAP_PIXEL_LAYER0 | TILEMAP_PIXEL_LAYER1)))
447         if (opaque || (flags[x & xscroll_mask] & (TILEMAP_PIXEL_LAYER0 | TILEMAP_PIXEL_LAYER1)))
463448         {
464            UINT16 pen = s[i & xscroll_mask];
449            UINT16 pen = src[x & xscroll_mask];
465450            if (m_alpha_enable && m_alpha_table[pen])
466            {
467               *d = alpha_blend_r32(*d, m_palette->pen(pen), 0x7f);
468            }
451               *dest = alpha_blend_r32(*dest, m_palette->pen(pen), 0x7f);
469452            else
470            {
471               *d = m_palette->pen(pen);
472            }
453               *dest = m_palette->pen(pen);
473454         }
474         ++d;
455         dest++;
475456      }
476457   }
477458}
r31933r31934
493474      fore_rowscroll = NULL;
494475   }
495476
477   screen.priority().fill(0, cliprect);
478
496479   if (m_layer_enable & 1)
497480      bitmap.fill(0, cliprect);
498
499   if (~m_layer_enable & 1)
481   else
500482      combine_tilemap(bitmap, cliprect, m_back_layer, m_scrollram[0] & 0xffff, (m_scrollram[0] >> 16) & 0xffff, 1, back_rowscroll);
501483
502   draw_sprites(bitmap, cliprect, 0);
484   draw_sprites(bitmap, cliprect, screen.priority(), 0);
503485
504486   // if fore layer is enabled, draw priority 0 sprites behind back layer
505487   if ((m_layer_enable & 0x15) == 0)
r31933r31934
507489
508490   // if fore layer is enabled, draw priority 1 sprites behind middle layer
509491   if (~m_layer_enable & 4)
510      draw_sprites(bitmap, cliprect, 1);
492      draw_sprites(bitmap, cliprect, screen.priority(), 1);
511493
512494   if (~m_layer_enable & 2)
513495      combine_tilemap(bitmap, cliprect, m_midl_layer, m_scrollram[1] & 0xffff, (m_scrollram[1] >> 16) & 0xffff, 0, midl_rowscroll);
514496
515497   // if fore layer is disabled, draw priority 1 sprites above middle layer
516498   if (m_layer_enable & 4)
517      draw_sprites(bitmap, cliprect, 1);
499      draw_sprites(bitmap, cliprect, screen.priority(), 1);
518500
519   draw_sprites(bitmap, cliprect, 2);
501   draw_sprites(bitmap, cliprect, screen.priority(), 2);
520502
521503   if (~m_layer_enable & 4)
522504      combine_tilemap(bitmap, cliprect, m_fore_layer, m_scrollram[2] & 0xffff, (m_scrollram[2] >> 16) & 0xffff, 0, fore_rowscroll);
523505
524   draw_sprites(bitmap, cliprect, 3);
506   draw_sprites(bitmap, cliprect, screen.priority(), 3);
525507
526508   if (~m_layer_enable & 8)
527509      combine_tilemap(bitmap, cliprect, m_text_layer, 0, 0, 0, NULL);
r31933r31934
531513
532514UINT32 seibuspi_state::screen_update_sys386f(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
533515{
516   screen.priority().fill(0, cliprect);
534517   bitmap.fill(0, cliprect);
535518
536   draw_sprites(bitmap, cliprect, 0);
537   draw_sprites(bitmap, cliprect, 1);
538   draw_sprites(bitmap, cliprect, 2);
539   draw_sprites(bitmap, cliprect, 3);
519   draw_sprites(bitmap, cliprect, screen.priority(), 0);
520   draw_sprites(bitmap, cliprect, screen.priority(), 1);
521   draw_sprites(bitmap, cliprect, screen.priority(), 2);
522   draw_sprites(bitmap, cliprect, screen.priority(), 3);
540523
541524   return 0;
542525}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team