Added new function gfx_element_build_temporary() to safely build a temporary

gfx_element. Updated the drivers that did this to use the new function, fixing
random crashes.

Fixed a couple of other minor regressions with recent drawgfx changes.
This commit is contained in:
Aaron Giles 2009-01-14 05:16:23 +00:00
parent a9f31c6003
commit f449ec6100
7 changed files with 62 additions and 113 deletions

View File

@ -215,6 +215,42 @@ void gfx_element_free(gfx_element *gfx)
}
/*-------------------------------------------------
gfx_element_build_temporary - create a
temporary one-off gfx_element
-------------------------------------------------*/
void gfx_element_build_temporary(gfx_element *gfx, running_machine *machine, UINT8 *base, UINT32 width, UINT32 height, UINT32 rowbytes, UINT32 color_base, UINT32 color_granularity, UINT32 flags)
{
static UINT8 not_dirty = 0;
gfx->width = width;
gfx->height = height;
gfx->startx = 0;
gfx->starty = 0;
gfx->origwidth = width;
gfx->origheight = height;
gfx->flags = flags;
gfx->total_elements = 1;
gfx->color_base = color_base;
gfx->color_depth = color_granularity;
gfx->color_granularity = color_granularity;
gfx->total_colors = (machine->config->total_colors - color_base) / color_granularity;
gfx->pen_usage = NULL;
gfx->gfxdata = base;
gfx->line_modulo = rowbytes;
gfx->char_modulo = 0;
gfx->srcdata = base;
gfx->dirty = &not_dirty;
gfx->dirtyseq = 0;
gfx->machine = machine;
}
/*-------------------------------------------------
calc_penusage - calculate the pen usage for
@ -1893,8 +1929,8 @@ void copyscrollbitmap_trans(bitmap_t *dest, bitmap_t *src, UINT32 numrows, const
break;
/* compute the cliprect for this group */
subclip.min_x = col * colwidth;
subclip.max_x = (col + groupcols) * colwidth - 1;
subclip.min_x = col * colwidth + xscroll;
subclip.max_x = (col + groupcols) * colwidth - 1 + xscroll;
sect_rect(&subclip, cliprect);
/* iterate over all portions of the scroll that overlap the destination */
@ -1927,8 +1963,8 @@ void copyscrollbitmap_trans(bitmap_t *dest, bitmap_t *src, UINT32 numrows, const
break;
/* compute the cliprect for this group */
subclip.min_y = row * rowheight;
subclip.max_y = (row + grouprows) * rowheight - 1;
subclip.min_y = row * rowheight + yscroll;
subclip.max_y = (row + grouprows) * rowheight - 1 + yscroll;
sect_rect(&subclip, cliprect);
/* iterate over all portions of the scroll that overlap the destination */

View File

@ -178,6 +178,9 @@ void gfx_element_decode(const gfx_element *gfx, UINT32 code);
/* free a gfx_element */
void gfx_element_free(gfx_element *gfx);
/* create a temporary one-off gfx_element */
void gfx_element_build_temporary(gfx_element *gfx, running_machine *machine, UINT8 *base, UINT32 width, UINT32 height, UINT32 rowbytes, UINT32 color_base, UINT32 color_granularity, UINT32 flags);
/* ----- core graphics drawing ----- */

View File

@ -173,27 +173,13 @@ static void draw_sprite(running_machine *machine, bitmap_t *bitmap,const rectang
{
// prepare GfxElement on the fly
gfx_element gfx;
UINT8 dirty = 0;
gfx.machine = machine;
gfx.width = dimx;
gfx.height = dimy;
gfx.total_elements = 1;
gfx.color_depth = 32;
gfx.color_granularity = 32;
gfx.color_base = 0x100;
gfx.total_colors = 8;
gfx.pen_usage = NULL;
gfx.gfxdata = sprites_gfx + addr;
gfx.dirty = &dirty;
gfx.line_modulo = dimx;
gfx.char_modulo = 0; // doesn't matter
gfx.flags = 0;
// Bounds checking
if ( addr + dimx * dimy >= sprites_gfx_size )
return;
gfx_element_build_temporary(&gfx, machine, sprites_gfx + addr, dimx, dimy, dimx, 0x100, 32, 0);
drawgfx( bitmap,&gfx,
0, color,
flipx, flipy,

View File

@ -355,7 +355,6 @@ static void draw_sprites(running_machine *machine, UINT32 *sprites, const rectan
for(i = 0; i <= count*2; i += 2)
{
int x, width, flipx, y, height, flipy, code, color, pri;
UINT8 dirty = 0;
if(~sprites[i] & 0x80000000) continue;
@ -381,26 +380,13 @@ static void draw_sprites(running_machine *machine, UINT32 *sprites, const rectan
gfxdata = base_gfx + 64 * code;
/* prepare GfxElement on the fly */
gfx.machine = machine;
gfx.width = width;
gfx.height = height;
gfx.total_elements = 1;
gfx.color_depth = 256;
gfx.color_granularity = 256;
gfx.color_base = 0;
gfx.total_colors = 0x10;
gfx.pen_usage = NULL;
gfx.gfxdata = gfxdata;
gfx.line_modulo = width;
gfx.char_modulo = 0; /* doesn't matter */
gfx.flags = 0;
gfx.dirty = &dirty;
/* Bounds checking */
if ( (gfxdata + width * height - 1) >= gfx_max )
continue;
/* prepare GfxElement on the fly */
gfx_element_build_temporary(&gfx, machine, gfxdata, width, height, width, 0, 256, 0);
draw_single_sprite(sprites_bitmap,&gfx,0,color,flipx,flipy,x,y,cliprect,pri);
// wrap around x

View File

@ -418,6 +418,7 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta
for ( ; src >= end; src -= 8/2 )
{
int x,y, attr,code,color,flipx,flipy, zoom, curr_pri,width,height;
gfx_element gfx;
UINT8 *gfxdata;
/* Exponential zoom table extracted from daitoride */
@ -469,28 +470,12 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta
if (color == 0xf) /* 8bpp */
{
/* prepare GfxElement on the fly */
gfx_element gfx;
gfx.machine = machine;
gfx.width = width;
gfx.height = height;
gfx.total_elements = 1;
gfx.color_depth = 256;
gfx.color_granularity = 256;
gfx.color_base = 0;
gfx.total_colors = 0x20;
gfx.pen_usage = NULL;
gfx.gfxdata = gfxdata;
gfx.line_modulo = width;
gfx.char_modulo = 0; /* doesn't matter */
gfx.flags = 0;
gfx.dirty = &dirty;
gfx.machine = machine;
/* Bounds checking */
if ( (gfxdata + width * height - 1) >= gfx_max )
continue;
gfx_element_build_temporary(&gfx, machine, gfxdata, width, height, width, 0, 256, 0);
pdrawgfxzoom( bitmap,&gfx,
0,
color_start >> 4,
@ -502,28 +487,12 @@ static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const recta
}
else
{
/* prepare GfxElement on the fly */
gfx_element gfx;
gfx.machine = machine;
gfx.width = width;
gfx.height = height;
gfx.total_elements = 1;
gfx.color_depth = 16;
gfx.color_granularity = 16;
gfx.color_base = 0;
gfx.total_colors = 0x200;
gfx.pen_usage = NULL;
gfx.gfxdata = gfxdata;
gfx.line_modulo = width/2;
gfx.char_modulo = 0; /* doesn't matter */
gfx.flags = GFX_ELEMENT_PACKED;
gfx.dirty = &dirty;
gfx.machine = machine;
/* Bounds checking */
if ( (gfxdata + width/2 * height - 1) >= gfx_max )
continue;
gfx_element_build_temporary(&gfx, machine, gfxdata, width, height, width/2, 0, 16, GFX_ELEMENT_PACKED);
pdrawgfxzoom( bitmap,&gfx,
0,
(color ^ 0x0f) + color_start,

View File

@ -622,6 +622,8 @@ void metro_draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectan
for (i=0; i<0x20; i++)
{
gfx_element gfx;
if (!(metro_videoregs[0x02/2] & 0x8000))
{
src = spriteram16 + (sprites - 1) * (8/2);
@ -690,28 +692,12 @@ void metro_draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectan
if (support_8bpp && color == 0xf) /* 8bpp */
{
/* prepare GfxElement on the fly */
gfx_element gfx;
gfx.machine = machine;
gfx.width = width;
gfx.height = height;
gfx.total_elements = 1;
gfx.color_depth = 256;
gfx.color_granularity = 256;
gfx.color_base = 0;
gfx.total_colors = 0x20;
gfx.pen_usage = NULL;
gfx.gfxdata = gfxdata;
gfx.line_modulo = width;
gfx.char_modulo = 0; /* doesn't matter */
gfx.flags = 0;
gfx.dirty = &dirty;
gfx.machine = machine;
/* Bounds checking */
if ( (gfxdata + width * height - 1) >= gfx_max )
continue;
gfx_element_build_temporary(&gfx, machine, gfxdata, width, height, width, 0, 256, 0);
pdrawgfxzoom( bitmap,&gfx,
0,
color_start >> 4,
@ -723,28 +709,12 @@ void metro_draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectan
}
else
{
/* prepare GfxElement on the fly */
gfx_element gfx;
gfx.machine = machine;
gfx.width = width;
gfx.height = height;
gfx.total_elements = 1;
gfx.color_depth = 16;
gfx.color_granularity = 16;
gfx.color_base = 0;
gfx.total_colors = 0x200;
gfx.pen_usage = NULL;
gfx.gfxdata = gfxdata;
gfx.line_modulo = width/2;
gfx.char_modulo = 0; /* doesn't matter */
gfx.flags = GFX_ELEMENT_PACKED;
gfx.dirty = &dirty;
gfx.machine = machine;
/* Bounds checking */
if ( (gfxdata + width/2 * height - 1) >= gfx_max )
continue;
gfx_element_build_temporary(&gfx, machine, gfxdata, width, height, width/2, 0, 16, GFX_ELEMENT_PACKED);
pdrawgfxzoom( bitmap,&gfx,
0,
color + color_start,

View File

@ -209,7 +209,7 @@ static VIDEO_START( snk_4bpp_shadow )
/* prepare shadow draw table */
for(i = 0; i <= 13; i++) drawmode_table[i] = DRAWMODE_SOURCE;
drawmode_table[14] = (machine->config->video_attributes & VIDEO_HAS_SHADOWS) ? DRAWMODE_SHADOW : DRAWMODE_SOURCE;
drawmode_table[14] = DRAWMODE_SHADOW;
drawmode_table[15] = DRAWMODE_NONE;
/* all palette entries are not affected by shadow sprites... */
@ -358,9 +358,8 @@ VIDEO_START( gwar )
VIDEO_START( tdfever )
{
VIDEO_START_CALL(snk_4bpp_shadow);
VIDEO_START_CALL(gwar);
VIDEO_START_CALL(snk_4bpp_shadow);
}
/**************************************************************************************/