Added x/y boundary checking to ST-V bitmaps [Angelo Salese]

This commit is contained in:
Angelo Salese 2010-05-22 17:08:24 +00:00
parent 248a75eeef
commit 45654f782a

View File

@ -2861,6 +2861,8 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
int tw = 0;
/*Transparency code 1=opaque,0=transparent*/
int t_pen;
int screen_x,screen_y;
if (!stv2_current_tilemap.enabled) return;
/* size for n0 / n1 */
@ -2909,6 +2911,9 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
stv2_current_tilemap.bitmap_palette_number+=stv2_current_tilemap.colour_ram_address_offset;
stv2_current_tilemap.bitmap_palette_number&=7;//safety check
screen_x = video_screen_get_visible_area(machine->primary_screen)->max_x;
screen_y = video_screen_get_visible_area(machine->primary_screen)->max_y;
switch(stv2_current_tilemap.colour_depth)
{
/*Palette Format*/
@ -2923,6 +2928,8 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
t_pen = (((gfxdata[0] & 0x0f) >> 0) != 0) ? (1) : (0);
if(stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE) t_pen = 1;
if(t_pen)
{
if (((xcnt + 1) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
*BITMAP_ADDR16(bitmap, ycnt, xcnt+1) = machine->pens[((gfxdata[0] & 0x0f) >> 0) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
@ -2930,12 +2937,15 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
*BITMAP_ADDR16(bitmap, ycnt, xcnt+1) = alpha_blend_r16(*BITMAP_ADDR16(bitmap, ycnt, xcnt+1), machine->pens[((gfxdata[0] & 0x0f) >> 0) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
}
}
}
tw = stv_vdp2_window_process(xcnt,ycnt);
if(tw == 0)
{
t_pen = (((gfxdata[0] & 0xf0) >> 4) != 0) ? (1) : (0);
if(stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE) t_pen = 1;
if(t_pen)
{
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = machine->pens[((gfxdata[0] & 0xf0) >> 4) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
@ -2943,6 +2953,7 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = alpha_blend_r16(*BITMAP_ADDR16(bitmap, ycnt, xcnt), machine->pens[((gfxdata[0] & 0xf0) >> 4) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
}
}
}
gfxdata++;
if ( gfxdata >= gfxdatahigh ) gfxdata = gfxdatalow;
}
@ -2968,6 +2979,8 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
t_pen = ((gfxdata[xs] & 0xff) != 0) ? (1) : (0);
if(stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE) t_pen = 1;
if(t_pen)
{
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = machine->pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
@ -2975,6 +2988,7 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = alpha_blend_r16(*BITMAP_ADDR16(bitmap, ycnt, xcnt), machine->pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
}
}
}
if ( (gfxdata + xs) >= gfxdatahigh )
{
//gfx_wraparound = (ycnt << 16) | xcnt;
@ -3011,6 +3025,8 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
t_pen = ((gfxdata[xs] & 0xff) != 0) ? 1 : 0;
if(stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE) t_pen = 1;
if(t_pen)
{
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = machine->pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
@ -3018,6 +3034,7 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = alpha_blend_r16(*BITMAP_ADDR16(bitmap, ycnt, xcnt), machine->pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
}
}
}
if ( (gfxdata + xs) >= gfxdatahigh ) gfxdata = gfxdatalow;
@ -3036,6 +3053,8 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
t_pen = ((((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff)) != 0) ? (1) : (0);
if(stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE) t_pen = 1;
if(t_pen)
{
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = machine->pens[((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff) | pal_color_offset];
@ -3043,6 +3062,7 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
*BITMAP_ADDR16(bitmap, ycnt, xcnt) = alpha_blend_r16(*BITMAP_ADDR16(bitmap, ycnt, xcnt), machine->pens[((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff) | pal_color_offset], stv2_current_tilemap.alpha);
}
}
}
gfxdata+=2;
if ( gfxdata >= gfxdatahigh ) gfxdata = gfxdatalow;
@ -3080,12 +3100,15 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
stv_vdp2_compute_color_offset_RGB555(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
tw = stv_vdp2_window_process(xcnt,ycnt);
if(tw == 0)
{
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
destline[xcnt] = b | g << 5 | r << 10;
else
destline[xcnt] = alpha_blend_r16( destline[xcnt], b | g << 5 | r << 10, stv2_current_tilemap.alpha );
}
}
if ( (gfxdata + 2*xs) >= gfxdatahigh ) gfxdata = gfxdatalow;
}
@ -3122,6 +3145,8 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
if(tw == 0)
{
if(t_pen)
{
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
{
if ( stv2_current_tilemap.colour_calculation_enabled == 1 )
destline[xcnt] = alpha_blend_r16( destline[xcnt], b | g << 5 | r << 10, stv2_current_tilemap.alpha );
@ -3129,6 +3154,7 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
destline[xcnt] = b | g << 5 | r << 10;
}
}
}
if ( (gfxdata + 2*xs) >= gfxdatahigh ) gfxdata = gfxdatalow;
}
@ -3167,6 +3193,7 @@ static void stv_vdp2_draw_basic_bitmap(running_machine *machine, bitmap_t *bitma
if(tw == 0)
{
if(t_pen)
if (((xcnt + 0) < screen_x) && (ycnt < screen_y))
destline[xcnt] = b | g << 5 | r << 10;
}
gfxdata+=4;
@ -3979,11 +4006,11 @@ static void stv_vdp2_check_tilemap(running_machine *machine, bitmap_t *bitmap, c
/*elandore doesn't like current cliprect code,will be worked on...*/
if ( window_applied && stv2_current_tilemap.colour_depth != 0)
stv2_current_tilemap.window_control = 0;
stv_vdp2_draw_basic_bitmap(machine, bitmap, &mycliprect);
}
else
{
stv_vdp2_draw_basic_tilemap(machine, bitmap, &mycliprect);
if((stv2_current_tilemap.window_control & 6) != 0 && VDP2_ERR(1))
@ -5450,22 +5477,6 @@ VIDEO_START( stv_vdp2 )
/*TODO: frame_period should be different for every kind of resolution (needs tests on actual boards)*/
/* & height / width not yet understood (docs-wise MUST be bigger than normal visible area)*/
static TIMER_CALLBACK( dyn_res_change )
{
int vblank_period,hblank_period;
rectangle visarea = *video_screen_get_visible_area(machine->primary_screen);
visarea.min_x = 0;
visarea.max_x = horz_res-1;
visarea.min_y = 0;
visarea.max_y = vert_res-1;
vblank_period = get_vblank_duration(machine);
hblank_period = get_hblank_duration(machine);
// popmessage("%d",vblank_period);
// hblank_period = get_hblank_duration(machine->primary_screen);
video_screen_configure(machine->primary_screen, (horz_res+hblank_period), (vert_res+vblank_period), &visarea, video_screen_get_frame_period(machine->primary_screen).attoseconds );
}
static void stv_vdp2_dynamic_res_change(running_machine *machine)
{
static UINT8 old_vres = 0,old_hres = 0;
@ -5501,7 +5512,19 @@ static void stv_vdp2_dynamic_res_change(running_machine *machine)
// vert_res*=2;
if(old_vres != vert_res || old_hres != horz_res)
{
timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), NULL, 0, dyn_res_change);
int vblank_period,hblank_period;
rectangle visarea = *video_screen_get_visible_area(machine->primary_screen);
visarea.min_x = 0;
visarea.max_x = horz_res-1;
visarea.min_y = 0;
visarea.max_y = vert_res-1;
vblank_period = get_vblank_duration(machine);
hblank_period = get_hblank_duration(machine);
// popmessage("%d",vblank_period);
// hblank_period = get_hblank_duration(machine->primary_screen);
video_screen_configure(machine->primary_screen, (horz_res+hblank_period), (vert_res+vblank_period), &visarea, video_screen_get_frame_period(machine->primary_screen).attoseconds );
old_vres = vert_res;
old_hres = horz_res;
}