Previous 199869 Revisions Next

r21002 Tuesday 12th February, 2013 at 21:39:49 UTC by Angelo Salese
Part 1 of drawing window rewrite
[src/emu/video]stvvdp2.c
[src/mame/includes]stv.h

trunk/src/mame/includes/stv.h
r21001r21002
382382
383383   void refresh_palette_data( void );
384384   int stv_vdp2_window_process(int x,int y);
385   void stv_vdp2_get_window0_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y);
386   void stv_vdp2_get_window1_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y);
387   int get_window_pixel(UINT16 s_x,UINT16 e_x,UINT16 s_y,UINT16 e_y,int x, int y,UINT8 win_num);
385   void stv_vdp2_get_window0_coordinates(int *s_x, int *e_x, int *s_y, int *e_y);
386   void stv_vdp2_get_window1_coordinates(int *s_x, int *e_x, int *s_y, int *e_y);
387   int get_window_pixel(int s_x,int e_x,int s_y,int e_y,int x, int y,UINT8 win_num);
388388   int stv_vdp2_apply_window_on_layer(rectangle &cliprect);
389389
390390   void stv_vdp2_draw_basic_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect);
r21001r21002
400400   void stv_vdp2_drawgfx_rgb555( bitmap_rgb32 &dest_bmp, const rectangle &clip, UINT32 code, int flipx, int flipy, int sx, int sy, int transparency, int alpha);
401401   void stv_vdp2_drawgfx_rgb888( bitmap_rgb32 &dest_bmp, const rectangle &clip, UINT32 code, int flipx, int flipy, int sx, int sy, int transparency, int alpha);
402402
403   void stv_vdp2_drawgfx_alpha(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx, UINT32 code,UINT32 color, int flipx,int flipy,int offsx,int offsy, int transparent_color, int alpha);
404   void stv_vdp2_drawgfx_transpen(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx, UINT32 code,UINT32 color, int flipx,int flipy,int offsx,int offsy, int transparent_color);
405
406
403407   void stv_vdp2_draw_rotation_screen(bitmap_rgb32 &bitmap, const rectangle &cliprect, int iRP);
404408   void stv_vdp2_check_tilemap_with_linescroll(bitmap_rgb32 &bitmap, const rectangle &cliprect);
405409   void stv_vdp2_check_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect);
trunk/src/emu/video/stvvdp2.c
r21001r21002
30043004      }
30053005
30063006   }
3007}
30073008
3009void saturn_state::stv_vdp2_drawgfx_alpha(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
3010                     UINT32 code,UINT32 color, int flipx,int flipy,int offsx,int offsy,
3011                     int transparent_color, int alpha)
3012{
3013   const pen_t *pal = &gfx->machine().pens[gfx->colorbase() + gfx->granularity() * (color % gfx->colors())];
3014   const UINT8 *source_base = gfx->get_data(code % gfx->elements());
3015   int x_index_base, y_index, sx, sy, ex, ey;
3016   int xinc, yinc;
3017
3018   xinc = flipx ? -1 : 1;
3019   yinc = flipy ? -1 : 1;
3020
3021   x_index_base = flipx ? gfx->width()-1 : 0;
3022   y_index = flipy ? gfx->height()-1 : 0;
3023
3024   /* start coordinates */
3025   sx = offsx;
3026   sy = offsy;
3027
3028   /* end coordinates */
3029   ex = sx + gfx->width();
3030   ey = sy + gfx->height();
3031
3032   /* clip left */
3033   if (sx < clip.min_x)
3034   {
3035      int pixels = clip.min_x-sx;
3036      sx += pixels;
3037      x_index_base += xinc*pixels;
3038   }
3039
3040   /* clip top */
3041   if (sy < clip.min_y)
3042   {    int pixels = clip.min_y-sy;
3043      sy += pixels;
3044      y_index += yinc*pixels;
3045   }
3046
3047   /* clip right */
3048   if (ex > clip.max_x+1)
3049   {
3050      ex = clip.max_x+1;
3051   }
3052   /* clip bottom */
3053   if (ey > clip.max_y+1)
3054   {
3055      ey = clip.max_y+1;
3056   }
3057
3058   /* skip if inner loop doesn't draw anything */
3059   if (ex > sx)
3060   {
3061      int x, y;
3062
3063      {
3064         for (y = sy; y < ey; y++)
3065         {
3066            const UINT8 *source = source_base + y_index*gfx->rowbytes();
3067            UINT32 *dest = &dest_bmp.pix32(y);
3068            int x_index = x_index_base;
3069            for (x = sx; x < ex; x++)
3070            {
3071               int c = (source[x_index]);
3072               if (c != transparent_color)
3073                  dest[x] = alpha_blend_r32( dest[x], pal[c], alpha );;
3074
3075               x_index += xinc;
3076            }
3077            y_index += yinc;
3078         }
3079      }
3080   }
30083081}
30093082
3083void saturn_state::stv_vdp2_drawgfx_transpen(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
3084                     UINT32 code,UINT32 color, int flipx,int flipy,int offsx,int offsy,
3085                     int transparent_color)
3086{
3087   const pen_t *pal = &gfx->machine().pens[gfx->colorbase() + gfx->granularity() * (color % gfx->colors())];
3088   const UINT8 *source_base = gfx->get_data(code % gfx->elements());
3089   int x_index_base, y_index, sx, sy, ex, ey;
3090   int xinc, yinc;
3091
3092   xinc = flipx ? -1 : 1;
3093   yinc = flipy ? -1 : 1;
3094
3095   x_index_base = flipx ? gfx->width()-1 : 0;
3096   y_index = flipy ? gfx->height()-1 : 0;
3097
3098   /* start coordinates */
3099   sx = offsx;
3100   sy = offsy;
3101
3102   /* end coordinates */
3103   ex = sx + gfx->width();
3104   ey = sy + gfx->height();
3105
3106   /* clip left */
3107   if (sx < clip.min_x)
3108   {
3109      int pixels = clip.min_x-sx;
3110      sx += pixels;
3111      x_index_base += xinc*pixels;
3112   }
3113
3114   /* clip top */
3115   if (sy < clip.min_y)
3116   {    int pixels = clip.min_y-sy;
3117      sy += pixels;
3118      y_index += yinc*pixels;
3119   }
3120
3121   /* clip right */
3122   if (ex > clip.max_x+1)
3123   {
3124      ex = clip.max_x+1;
3125   }
3126   /* clip bottom */
3127   if (ey > clip.max_y+1)
3128   {
3129      ey = clip.max_y+1;
3130   }
3131
3132   /* skip if inner loop doesn't draw anything */
3133   if (ex > sx)
3134   {
3135      int x, y;
3136
3137      {
3138         for (y = sy; y < ey; y++)
3139         {
3140            const UINT8 *source = source_base + y_index*gfx->rowbytes();
3141            UINT32 *dest = &dest_bmp.pix32(y);
3142            int x_index = x_index_base;
3143            for (x = sx; x < ex; x++)
3144            {
3145               if(!stv_vdp2_window_process(x,y))
3146                  continue;
3147
3148               int c = (source[x_index]);
3149               if (c != transparent_color)
3150                  dest[x] = pal[c];
3151
3152               x_index += xinc;
3153            }
3154            y_index += yinc;
3155         }
3156      }
3157   }
3158}
3159
30103160void saturn_state::draw_4bpp_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
30113161{
30123162   int xsize, ysize, xsize_mask, ysize_mask;
r21001r21002
30363186   {
30373187      for(xdst=cliprect.min_x;xdst<=cliprect.max_x;xdst++)
30383188      {
3039         if(stv_vdp2_window_process(xdst,ydst))
3189         if(!stv_vdp2_window_process(xdst,ydst))
30403190            continue;
30413191
30423192         xsrc = (xdst + scrollx) & (xsize_mask-1);
r21001r21002
30933243   {
30943244      for(xdst=cliprect.min_x;xdst<=cliprect.max_x;xdst++)
30953245      {
3096         if(stv_vdp2_window_process(xdst,ydst))
3246         if(!stv_vdp2_window_process(xdst,ydst))
30973247            continue;
30983248
30993249         xf = stv2_current_tilemap.incx * xdst;
r21001r21002
31453295   {
31463296      for(xdst=cliprect.min_x;xdst<=cliprect.max_x;xdst++)
31473297      {
3148         if(stv_vdp2_window_process(xdst,ydst))
3298         if(!stv_vdp2_window_process(xdst,ydst))
31493299            continue;
31503300
31513301         xf = stv2_current_tilemap.incx * xdst;
r21001r21002
32023352   {
32033353      for(xdst=cliprect.min_x;xdst<=cliprect.max_x;xdst++)
32043354      {
3205         if(stv_vdp2_window_process(xdst,ydst))
3355         if(!stv_vdp2_window_process(xdst,ydst))
32063356            continue;
32073357
32083358         xsrc = (xdst + scrollx) & (xsize_mask-1);
r21001r21002
42074357               else if (stv2_current_tilemap.transparency == STV_TRANSPARENCY_ALPHA)
42084358               {
42094359                  /* alpha */
4210                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,0,stv2_current_tilemap.alpha);
4211                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,0,stv2_current_tilemap.alpha);
4212                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,0,stv2_current_tilemap.alpha);
4213                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,0,stv2_current_tilemap.alpha);
4360                  stv_vdp2_drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,0,stv2_current_tilemap.alpha);
4361                  stv_vdp2_drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,0,stv2_current_tilemap.alpha);
4362                  stv_vdp2_drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,0,stv2_current_tilemap.alpha);
4363                  stv_vdp2_drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,0,stv2_current_tilemap.alpha);
42144364               }
42154365               else
42164366               {
42174367                  /* normal */
4218                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4219                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4220                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4221                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4368                  stv_vdp2_drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4369                  stv_vdp2_drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4370                  stv_vdp2_drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4371                  stv_vdp2_drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
42224372               }
42234373            }
42244374            else
r21001r21002
42344384               else
42354385               {
42364386                  if (stv2_current_tilemap.transparency == STV_TRANSPARENCY_ALPHA)
4237                     drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,0,stv2_current_tilemap.alpha);
4387                     stv_vdp2_drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,0,stv2_current_tilemap.alpha);
42384388                  else
4239                     drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4389                     stv_vdp2_drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
42404390               }
42414391            }
42424392            drawxpos = olddrawxpos;
r21001r21002
44264576      }
44274577      else
44284578      {
4429         stv_vdp2_apply_window_on_layer(mycliprect);
4579         //stv_vdp2_apply_window_on_layer(mycliprect);
44304580         stv_vdp2_draw_basic_tilemap(bitmap, mycliprect);
44314581      }
44324582
r21001r21002
45184668
45194669   if (stv2_current_tilemap.bitmap_enable) // this layer is a bitmap
45204670   {
4521      /*elandore doesn't like current cliprect code,will be worked on...*/
4522      //if ( window_applied && stv2_current_tilemap.colour_depth != 4)
4523      //  stv2_current_tilemap.window_control = 0;
4524
45254671      stv_vdp2_draw_basic_bitmap(bitmap, mycliprect);
45264672   }
45274673   else
45284674   {
4529      stv_vdp2_apply_window_on_layer(mycliprect);
4675      //stv_vdp2_apply_window_on_layer(mycliprect);
45304676      stv_vdp2_draw_basic_tilemap(bitmap, mycliprect);
45314677   }
45324678
r21001r21002
62966442                  (0 = OR,1 = AND)
62976443******************************************************************************************/
62986444
6299void saturn_state::stv_vdp2_get_window0_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y)
6445void saturn_state::stv_vdp2_get_window0_coordinates(int *s_x, int *e_x, int *s_y, int *e_y)
63006446{
63016447   /*W0*/
63026448   switch(STV_VDP2_LSMD & 3)
r21001r21002
63416487   }
63426488}
63436489
6344void saturn_state::stv_vdp2_get_window1_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y)
6490void saturn_state::stv_vdp2_get_window1_coordinates(int *s_x, int *e_x, int *s_y, int *e_y)
63456491{
63466492   /*W1*/
63476493   switch(STV_VDP2_LSMD & 3)
r21001r21002
63876533
63886534}
63896535
6390int saturn_state::get_window_pixel(UINT16 s_x,UINT16 e_x,UINT16 s_y,UINT16 e_y,int x, int y,UINT8 win_num)
6536int saturn_state::get_window_pixel(int s_x,int e_x,int s_y,int e_y,int x, int y,UINT8 win_num)
63916537{
6538   int res;
6539
6540   res = 1;
63926541   if(stv2_current_tilemap.window_control & (2 << win_num))
63936542   {
6394      /*Outside Area*/
63956543      if(stv2_current_tilemap.window_control & (0x10 << win_num))
6396      {
6397         if(y < s_y || y > e_y)
6398            return 1;
6399         else
6400         {
6401            if(x < s_x || x > e_x)
6402               return 1;
6403            //else
6404            //  return 0;
6405         }
6406      }
6407      /*Inside Area*/
6544         res = (y >= s_y && y <= e_y && x >= s_x && x <= e_x);
64086545      else
6409      {
6410         if(y > s_y && y < e_y)
6411         {
6412            if(x > s_x && x < e_x)
6413               return 1;
6414         }
6415         //else
6416         //  return 0;
6417      }
6546         res = (y >= s_y && y <= e_y && x >= s_x && x <= e_x) ^ 1;
64186547   }
64196548
6420   return 0;
6549   return res;
64216550}
64226551
64236552int saturn_state::stv_vdp2_window_process(int x,int y)
64246553{
6425   UINT16 s_x=0,e_x=0,s_y=0,e_y=0;
6426   UINT8 w0_pix, w1_pix;
6554   int s_x=0,e_x=0,s_y=0,e_y=0;
6555   int w0_pix, w1_pix;
64276556
64286557   if ((stv2_current_tilemap.window_control & 6) == 0)
6429      return 0;
6558      return 1;
64306559
64316560   stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y);
64326561   w0_pix = get_window_pixel(s_x,e_x,s_y,e_y,x,y,0);
r21001r21002
64346563   stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y);
64356564   w1_pix = get_window_pixel(s_x,e_x,s_y,e_y,x,y,1);
64366565
6437   return stv2_current_tilemap.window_control & 1 ? (w0_pix & w1_pix) : (w0_pix | w1_pix);
6566   return stv2_current_tilemap.window_control & 1 ? (w0_pix | w1_pix) : (w0_pix & w1_pix);
64386567}
64396568
64406569int saturn_state::stv_vdp2_apply_window_on_layer(rectangle &cliprect)
64416570{
6442   UINT16 s_x=0,e_x=0,s_y=0,e_y=0;
6571   int s_x=0,e_x=0,s_y=0,e_y=0;
64436572
64446573   if ( stv2_current_tilemap.window_control == 0x12 )
64456574   {

Previous 199869 Revisions Next


© 1997-2024 The MAME Team