namcos2_sprite.cpp : Updates

Simplfiy / Correct sprite gfx select behavior, Reduce unnecessary lines, Fix spacings, Use shorter / correct type values
namcos2.cpp : Simplify gfxdecodes
This commit is contained in:
cam900 2019-05-11 14:46:57 +09:00
parent 42221910aa
commit b1b2b37296
3 changed files with 466 additions and 478 deletions

File diff suppressed because it is too large Load Diff

View File

@ -41,35 +41,35 @@ void namcos2_sprite_device::device_start()
void namcos2_sprite_device::zdrawgfxzoom( void namcos2_sprite_device::zdrawgfxzoom(
screen_device &screen, screen_device &screen,
bitmap_ind16 &dest_bmp,const rectangle &clip,gfx_element *gfx, bitmap_ind16 &dest_bmp,const rectangle &clip,gfx_element *gfx,
uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy, u32 code,u32 color,bool flipx,bool flipy,int sx,int sy,
int scalex, int scaley, int zpos ) int scalex, int scaley, int zpos)
{ {
if (!scalex || !scaley) return; if (!scalex || !scaley) return;
if (dest_bmp.bpp() == 16) if (dest_bmp.bpp() == 16)
{ {
if( gfx ) if (gfx)
{ {
device_palette_interface &palette = m_gfxdecode->palette(); device_palette_interface &palette = gfx->palette();
int shadow_offset = (palette.shadows_enabled())?palette.entries():0; const int shadow_offset = (palette.shadows_enabled()) ? palette.entries() : 0;
const pen_t *pal = &palette.pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors())); const pen_t *pal = &palette.pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
const uint8_t *source_base = gfx->get_data(code % gfx->elements()); const u8 *source_base = gfx->get_data(code % gfx->elements());
int sprite_screen_height = (scaley*gfx->height()+0x8000)>>16; const int sprite_screen_height = (scaley * gfx->height() + 0x8000) >> 16;
int sprite_screen_width = (scalex*gfx->width()+0x8000)>>16; const int sprite_screen_width = (scalex * gfx->width() + 0x8000) >> 16;
if (sprite_screen_width && sprite_screen_height) if (sprite_screen_width && sprite_screen_height)
{ {
/* compute sprite increment per screen pixel */ /* compute sprite increment per screen pixel */
int dx = (gfx->width()<<16)/sprite_screen_width; int dx = (gfx->width() << 16) / sprite_screen_width;
int dy = (gfx->height()<<16)/sprite_screen_height; int dy = (gfx->height() << 16) / sprite_screen_height;
int ex = sx+sprite_screen_width; int ex = sx + sprite_screen_width;
int ey = sy+sprite_screen_height; int ey = sy + sprite_screen_height;
int x_index_base; int x_index_base;
int y_index; int y_index;
if( flipx ) if (flipx)
{ {
x_index_base = (sprite_screen_width-1)*dx; x_index_base = (sprite_screen_width - 1) * dx;
dx = -dx; dx = -dx;
} }
else else
@ -77,9 +77,9 @@ void namcos2_sprite_device::zdrawgfxzoom(
x_index_base = 0; x_index_base = 0;
} }
if( flipy ) if (flipy)
{ {
y_index = (sprite_screen_height-1)*dy; y_index = (sprite_screen_height - 1) * dy;
dy = -dy; dy = -dy;
} }
else else
@ -87,58 +87,57 @@ void namcos2_sprite_device::zdrawgfxzoom(
y_index = 0; y_index = 0;
} }
if( sx < clip.min_x) if (sx < clip.min_x)
{ /* clip left */ { /* clip left */
int pixels = clip.min_x-sx; int pixels = clip.min_x - sx;
sx += pixels; sx += pixels;
x_index_base += pixels*dx; x_index_base += pixels * dx;
} }
if( sy < clip.min_y ) if (sy < clip.min_y)
{ /* clip top */ { /* clip top */
int pixels = clip.min_y-sy; int pixels = clip.min_y - sy;
sy += pixels; sy += pixels;
y_index += pixels*dy; y_index += pixels * dy;
} }
if( ex > clip.max_x+1 ) if (ex > clip.max_x + 1)
{ /* clip right */ { /* clip right */
int pixels = ex-clip.max_x-1; int pixels = ex - clip.max_x - 1;
ex -= pixels; ex -= pixels;
} }
if( ey > clip.max_y+1 ) if (ey > clip.max_y + 1)
{ /* clip bottom */ { /* clip bottom */
int pixels = ey-clip.max_y-1; int pixels = ey - clip.max_y - 1;
ey -= pixels; ey -= pixels;
} }
if( ex>sx ) if (ex > sx)
{ /* skip if inner loop doesn't draw anything */ { /* skip if inner loop doesn't draw anything */
int y;
bitmap_ind8 &priority_bitmap = screen.priority(); bitmap_ind8 &priority_bitmap = screen.priority();
if( priority_bitmap.valid() ) if (priority_bitmap.valid())
{ {
for( y=sy; y<ey; y++ ) for (int y = sy; y < ey; y++)
{ {
const uint8_t *source = source_base + (y_index>>16) * gfx->rowbytes(); const u8 *source = source_base + (y_index>>16) * gfx->rowbytes();
uint16_t *dest = &dest_bmp.pix16(y); u16 *dest = &dest_bmp.pix16(y);
uint8_t *pri = &priority_bitmap.pix8(y); u8 *pri = &priority_bitmap.pix8(y);
int x, x_index = x_index_base; int x_index = x_index_base;
/* this code was previously shared with the c355 where this was needed /* this code was previously shared with the c355 where this was needed
if( m_palxor ) if (m_palxor)
{ {
for( x=sx; x<ex; x++ ) for (int x = sx; x < ex; x++)
{ {
int c = source[x_index>>16]; const u8 c = source[x_index >> 16];
if( c != 0xff ) if (c != 0xff)
{ {
if( pri[x]<=zpos ) if (pri[x] <= zpos)
{ {
switch( c ) switch(c)
{ {
case 0: case 0:
dest[x] = 0x4000|(dest[x]&0x1fff); dest[x] = 0x4000 | (dest[x] & 0x1fff);
break; break;
case 1: case 1:
dest[x] = 0x6000|(dest[x]&0x1fff); dest[x] = 0x6000 | (dest[x] & 0x1fff);
break; break;
default: default:
dest[x] = pal[c]; dest[x] = pal[c];
@ -154,14 +153,14 @@ void namcos2_sprite_device::zdrawgfxzoom(
else else
*/ */
{ {
for( x=sx; x<ex; x++ ) for (int x = sx; x < ex; x++)
{ {
int c = source[x_index>>16]; const u8 c = source[x_index >> 16];
if( c != 0xff ) if (c != 0xff)
{ {
if( pri[x]<=zpos ) if (pri[x] <= zpos)
{ {
if( color == 0xf && c==0xfe && shadow_offset ) if (color == 0xf && c==0xfe && shadow_offset)
{ {
dest[x] |= shadow_offset; dest[x] |= shadow_offset;
} }
@ -187,21 +186,20 @@ void namcos2_sprite_device::zdrawgfxzoom(
void namcos2_sprite_device::zdrawgfxzoom( void namcos2_sprite_device::zdrawgfxzoom(
screen_device &screen, screen_device &screen,
bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx, bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy, u32 code,u32 color,bool flipx,bool flipy,int sx,int sy,
int scalex, int scaley, int zpos ) int scalex, int scaley, int zpos)
{ {
/* nop */ /* nop */
} }
void namcos2_sprite_device::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int pri, int control ) void namcos2_sprite_device::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int pri, int control)
{ {
int offset = (control & 0x000f) * (128*4); int offset = (control & 0x000f) * (128 * 4);
int loop; if (pri == 0)
if( pri==0 )
{ {
screen.priority().fill(0, cliprect ); screen.priority().fill(0, cliprect);
} }
for( loop=0; loop < 128; loop++ ) for (int loop = 0; loop < 128; loop++)
{ {
/**************************************** /****************************************
* word#0 * word#0
@ -211,8 +209,7 @@ void namcos2_sprite_device::draw_sprites(screen_device &screen, bitmap_ind16 &bi
* *
* word#1 * word#1
* Sprite Quadrant D00-D01 * Sprite Quadrant D00-D01
* Sprite Number D02-D12 * Sprite Number D02-D13
* Sprite ROM Bank select D13
* Sprite flip X D14 * Sprite flip X D14
* Sprite flip Y D15 * Sprite flip Y D15
* *
@ -224,35 +221,34 @@ void namcos2_sprite_device::draw_sprites(screen_device &screen, bitmap_ind16 &bi
* Sprite colour index D04-D07 * Sprite colour index D04-D07
* Sprite Size X D10-D15 * Sprite Size X D10-D15
*/ */
int word3 = m_spriteram[offset+(loop*4)+3]; const u16 word3 = m_spriteram[offset + (loop * 4) + 3];
if( (word3&0xf)==pri ) if ((word3 & 0xf) == pri)
{ {
int word0 = m_spriteram[offset+(loop*4)+0]; const u16 word0 = m_spriteram[offset + (loop * 4) + 0];
int word1 = m_spriteram[offset+(loop*4)+1]; const u16 word1 = m_spriteram[offset + (loop * 4) + 1];
int offset4 = m_spriteram[offset+(loop*4)+2]; const u16 offset4 = m_spriteram[offset + (loop * 4) + 2];
int sizey=((word0>>10)&0x3f)+1; const int sizey = ((word0 >> 10) & 0x003f) + 1;
int sizex=(word3>>10)&0x3f; int sizex = (word3 >> 10) & 0x003f;
if((word0&0x0200)==0) sizex>>=1; if ((word0 & 0x0200) == 0) sizex >>= 1;
if((sizey-1) && sizex ) if ((sizey - 1) && sizex)
{ {
int color = (word3>>4)&0x000f; const u32 color = (word3 >> 4) & 0x000f;
int sprn = (word1>>2)&0x7ff; const u32 sprn = (word1 >> 2) & 0x0fff;
int rgn = (word1&0x2000)?1:0; const int ypos = (0x1ff - (word0 & 0x01ff)) - 0x50 + 0x02;
int ypos = (0x1ff-(word0&0x01ff))-0x50+0x02; const int xpos = (offset4 & 0x03ff) - 0x50 + 0x07;
int xpos = (offset4&0x03ff)-0x50+0x07; const bool flipy = word1 & 0x8000;
int flipy = word1&0x8000; const bool flipx = word1 & 0x4000;
int flipx = word1&0x4000; const int scalex = (sizex << 16) / ((word0 & 0x0200) ? 0x20 : 0x10);
int scalex = (sizex<<16)/((word0&0x0200)?0x20:0x10); const int scaley = (sizey << 16) / ((word0 & 0x0200) ? 0x20 : 0x10);
int scaley = (sizey<<16)/((word0&0x0200)?0x20:0x10); if (scalex && scaley)
if(scalex && scaley)
{ {
gfx_element *gfx = m_gfxdecode->gfx(rgn); gfx_element *gfx = m_gfxdecode->gfx(0);
if( (word0&0x0200)==0 ) if ((word0 & 0x0200) == 0)
gfx->set_source_clip((word1&0x0001) ? 16 : 0, 16, (word1&0x0002) ? 16 : 0, 16); gfx->set_source_clip((word1 & 0x0001) ? 16 : 0, 16, (word1 & 0x0002) ? 16 : 0, 16);
else else
gfx->set_source_clip(0, 32, 0, 32); gfx->set_source_clip(0, 32, 0, 32);
@ -266,14 +262,14 @@ void namcos2_sprite_device::draw_sprites(screen_device &screen, bitmap_ind16 &bi
flipx,flipy, flipx,flipy,
xpos,ypos, xpos,ypos,
scalex,scaley, scalex,scaley,
loop ); loop);
} }
} }
} }
} }
} /* namcos2_draw_sprites */ } /* draw_sprites */
void namcos2_sprite_device::draw_sprites_metalhawk(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int pri ) void namcos2_sprite_device::draw_sprites_metalhawk(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int pri)
{ {
/** /**
* word#0 * word#0
@ -282,8 +278,7 @@ void namcos2_sprite_device::draw_sprites_metalhawk(screen_device &screen, bitmap
* -------xxxxxxxxx screeny * -------xxxxxxxxx screeny
* *
* word#1 * word#1
* --x------------- bank * --xxxxxxxxxxxxxx tile
* ----xxxxxxxxxxxx tile
* *
* word#2 (unused) * word#2 (unused)
* *
@ -305,62 +300,52 @@ void namcos2_sprite_device::draw_sprites_metalhawk(screen_device &screen, bitmap
* --------xxxx---- color * --------xxxx---- color
* x--------------- unknown * x--------------- unknown
*/ */
const uint16_t *pSource = m_spriteram; const u16 *pSource = m_spriteram;
int loop; if (pri == 0)
if( pri==0 )
{ {
screen.priority().fill(0, cliprect ); screen.priority().fill(0, cliprect);
} }
for( loop=0; loop < 128; loop++ ) for (int loop=0; loop < 128; loop++)
{ {
int ypos = pSource[0]; const u16 ypos = pSource[0];
int tile = pSource[1]; const u16 tile = pSource[1];
int xpos = pSource[3]; const u16 xpos = pSource[3];
int flags = pSource[6]; const u16 flags = pSource[6];
int attrs = pSource[7]; const u16 attrs = pSource[7];
int sizey = ((ypos>>10)&0x3f)+1; const int sizey = ((ypos >> 10) & 0x003f) + 1;
int sizex = (xpos>>10)&0x3f; const int sizex = (xpos >> 10) & 0x003f;
int sprn = (tile>>2)&0x7ff; const u32 sprn = (tile >> 2) & 0x0fff;
if( tile&0x2000 ) if ((sizey - 1) && sizex && (attrs & 0xf) == pri)
{ {
sprn&=0x3ff; const bool bBigSprite = flags & 0x0008;
} const u32 color = (attrs >> 4) & 0x000f;
else int sx = (xpos & 0x03ff) - 0x50 + 0x07;
{ int sy = (0x1ff - (ypos & 0x01ff)) - 0x50 + 0x02;
sprn|=0x400; const bool flipx = flags & 0x0002;
} const bool flipy = flags & 0x0004;
const int scalex = (sizex << 16) / (0x20);//(sizex << 16) / (bBigSprite ? 0x20 : 0x10); correct formula?
if( (sizey-1) && sizex && (attrs&0xf)==pri ) const int scaley = (sizey << 16) / (bBigSprite ? 0x20 : 0x10);
{
int bBigSprite = (flags&8);
int color = (attrs>>4)&0xf;
int sx = (xpos&0x03ff)-0x50+0x07;
int sy = (0x1ff-(ypos&0x01ff))-0x50+0x02;
int flipx = flags&2;
int flipy = flags&4;
int scalex = (sizex<<16)/(0x20);//(sizex<<16)/(bBigSprite?0x20:0x10); correct formula?
int scaley = (sizey<<16)/(bBigSprite?0x20:0x10);
/* swap xy */ /* swap xy */
int rgn = (flags&0x01); const int rgn = (flags & 0x0001);
gfx_element *gfx = m_gfxdecode->gfx(rgn); gfx_element *gfx = m_gfxdecode->gfx(rgn);
if( bBigSprite ) if (bBigSprite)
{ {
if( sizex < 0x20 ) if (sizex < 0x20)
{ {
sx -= (0x20-sizex)/0x8; sx -= (0x20 - sizex) / 0x8;
} }
if( sizey < 0x20 ) if (sizey < 0x20)
{ {
sy += (0x20-sizey)/0xC; sy += (0x20 - sizey) / 0xC;
} }
gfx->set_source_clip(0, 32, 0, 32); gfx->set_source_clip(0, 32, 0, 32);
} }
else else
gfx->set_source_clip((tile&0x0001) ? 16 : 0, 16, (tile&0x0002) ? 16 : 0, 16); gfx->set_source_clip((tile & 0x0001) ? 16 : 0, 16, (tile & 0x0002) ? 16 : 0, 16);
zdrawgfxzoom( zdrawgfxzoom(
screen, screen,
@ -371,8 +356,8 @@ void namcos2_sprite_device::draw_sprites_metalhawk(screen_device &screen, bitmap
flipx,flipy, flipx,flipy,
sx,sy, sx,sy,
scalex, scaley, scalex, scaley,
loop ); loop);
} }
pSource += 8; pSource += 8;
} }
} /* namcos2_draw_sprites_metalhawk */ } /* draw_sprites_metalhawk */

View File

@ -27,16 +27,15 @@ protected:
private: private:
// general // general
void zdrawgfxzoom(screen_device &screen, bitmap_ind16 &dest_bmp, const rectangle &clip, gfx_element *gfx, uint32_t code, uint32_t color, int flipx, int flipy, int sx, int sy, int scalex, int scaley, int zpos); void zdrawgfxzoom(screen_device &screen, bitmap_ind16 &dest_bmp, const rectangle &clip, gfx_element *gfx, u32 code, u32 color, bool flipx, bool flipy, int sx, int sy, int scalex, int scaley, int zpos);
void zdrawgfxzoom(screen_device &screen, bitmap_rgb32 &dest_bmp, const rectangle &clip, gfx_element *gfx, uint32_t code, uint32_t color, int flipx, int flipy, int sx, int sy, int scalex, int scaley, int zpos); void zdrawgfxzoom(screen_device &screen, bitmap_rgb32 &dest_bmp, const rectangle &clip, gfx_element *gfx, u32 code, u32 color, bool flipx, bool flipy, int sx, int sy, int scalex, int scaley, int zpos);
required_device<gfxdecode_device> m_gfxdecode; required_device<gfxdecode_device> m_gfxdecode;
required_shared_ptr<uint16_t> m_spriteram; required_shared_ptr<u16> m_spriteram;
}; };
// device type definition // device type definition
DECLARE_DEVICE_TYPE(NAMCOS2_SPRITE, namcos2_sprite_device) DECLARE_DEVICE_TYPE(NAMCOS2_SPRITE, namcos2_sprite_device)
#endif // MAME_VIDEO_NAMCOS2_SPRITE_H #endif // MAME_VIDEO_NAMCOS2_SPRITE_H