summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/kaneko_spr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mame/video/kaneko_spr.cpp')
-rw-r--r--src/mame/video/kaneko_spr.cpp357
1 files changed, 188 insertions, 169 deletions
diff --git a/src/mame/video/kaneko_spr.cpp b/src/mame/video/kaneko_spr.cpp
index e656aeefc30..598c005f9cd 100644
--- a/src/mame/video/kaneko_spr.cpp
+++ b/src/mame/video/kaneko_spr.cpp
@@ -38,8 +38,10 @@ kaneko16_sprite_device::kaneko16_sprite_device(
device_t *owner,
u32 clock)
: device_t(mconfig, type, tag, owner, clock)
+ , device_gfx_interface(mconfig, *this, nullptr)
, device_video_interface(mconfig, *this)
- , m_gfxdecode(*this, finder_base::DUMMY_TAG)
+ , m_gfx_region(*this, DEVICE_SELF)
+ , m_colbase(0)
{
m_keep_sprites = 0; // default disabled for games not using it
@@ -77,6 +79,49 @@ void kaneko16_sprite_device::device_start()
}
+void kaneko_vu002_sprite_device::device_start()
+{
+ /*
+ 16x16x4 made of 4 8x8x4 blocks arrenged like: 01
+ 23
+ */
+ gfx_layout layout_16x16x4 =
+ {
+ 16,16,
+ 0,
+ 4,
+ { STEP4(0,1) },
+ { STEP8(8*8*4*0,4), STEP8(8*8*4*1,4) },
+ { STEP8(8*8*4*0,8*4), STEP8(8*8*4*2,8*4) },
+ 16*16*4
+ };
+ layout_16x16x4.total = m_gfx_region->bytes() / ((16*16*4) / 8);
+ kaneko16_sprite_device::device_start();
+ set_gfx(0, std::make_unique<gfx_element>(&palette(), layout_16x16x4, m_gfx_region->base(), 0, 0x40, m_colbase));
+}
+
+
+void kaneko_kc002_sprite_device::device_start()
+{
+ /*
+ 16x16x8 made of 4 8x8x8 blocks arrenged like: 01
+ 23
+ */
+ gfx_layout layout_16x16x8 =
+ {
+ 16,16,
+ 0,
+ 8,
+ { STEP8(0,1) },
+ { STEP8(0,8), STEP8(8*8*8*1,8) },
+ { STEP8(0,8*8), STEP8(8*8*8*2,8*8) },
+ 16*16*8
+ };
+ layout_16x16x8.total = m_gfx_region->bytes() / ((16*16*8) / 8);
+ kaneko16_sprite_device::device_start();
+ set_gfx(0, std::make_unique<gfx_element>(&palette(), layout_16x16x8, m_gfx_region->base(), 0, 0x40, m_colbase));
+}
+
void kaneko16_sprite_device::device_reset()
{
@@ -140,170 +185,155 @@ Offset: Format: Value:
void kaneko_kc002_sprite_device::get_sprite_attributes(struct tempsprite_t *s, u16 attr)
{
- s->color = (attr & 0x003f);
- s->priority = (attr & 0x00c0) >> 6;
- s->flipy = (attr & 0x0100);
- s->flipx = (attr & 0x0200);
- s->code += (s->y & 1) << 16; // bloodwar
+ s->color = (attr & 0x003f);
+ s->priority = (attr & 0x00c0) >> 6;
+ s->flipy = (attr & 0x0100);
+ s->flipx = (attr & 0x0200);
+ s->code += (s->y & 1) << 16; // bloodwar
}
void kaneko_vu002_sprite_device::get_sprite_attributes(struct tempsprite_t *s, u16 attr)
{
- s->flipy = (attr & 0x0001);
- s->flipx = (attr & 0x0002);
- s->color = (attr & 0x00fc) >> 2;
- s->priority = (attr & 0x0300) >> 8;
+ s->flipy = (attr & 0x0001);
+ s->flipx = (attr & 0x0002);
+ s->color = (attr & 0x00fc) >> 2;
+ s->priority = (attr & 0x0300) >> 8;
}
int kaneko16_sprite_device::parse_sprite_type012(int i, struct tempsprite_t *s, u16* spriteram16, int spriteram16_bytes)
{
- int attr, xoffs, offs;
+ const int offs = i * 8 / 2;
- offs = i * 8/2;
+ if (offs >= (spriteram16_bytes / 2)) return -1;
- if (offs >= (spriteram16_bytes/2)) return -1;
-
- attr = spriteram16[offs + 0];
- s->code = spriteram16[offs + 1];
- s->x = spriteram16[offs + 2];
- s->y = spriteram16[offs + 3];
+ const u16 attr = spriteram16[offs + 0];
+ s->code = spriteram16[offs + 1];
+ s->x = spriteram16[offs + 2];
+ s->y = spriteram16[offs + 3];
// this differs between each chip type
get_sprite_attributes(s, attr);
- xoffs = (attr & 0x1800) >> 11;
- s->yoffs = m_sprites_regs[0x10/2 + xoffs*2 + 1];
- s->xoffs = m_sprites_regs[0x10/2 + xoffs*2 + 0];
+ const u16 xoffs = (attr & 0x1800) >> 11;
+ s->yoffs = m_sprites_regs[0x10 / 2 + xoffs * 2 + 1];
+ s->xoffs = m_sprites_regs[0x10 / 2 + xoffs * 2 + 0];
if (m_sprite_flipy)
{
- s->yoffs -= m_sprites_regs[0x2/2];
- s->yoffs -= screen().visible_area().min_y<<6;
+ s->yoffs -= m_sprites_regs[0x2/2];
+ s->yoffs -= screen().visible_area().min_y << 6;
}
else
{
- s->yoffs -= m_sprites_regs[0x2/2];
- s->yoffs += screen().visible_area().min_y<<6;
+ s->yoffs -= m_sprites_regs[0x2/2];
+ s->yoffs += screen().visible_area().min_y << 6;
}
- return ( (attr & 0x2000) ? USE_LATCHED_XY : 0 ) |
- ( (attr & 0x4000) ? USE_LATCHED_COLOR : 0 ) |
- ( (attr & 0x8000) ? USE_LATCHED_CODE : 0 ) ;
+ return ((attr & 0x2000) ? USE_LATCHED_XY : 0) |
+ ((attr & 0x4000) ? USE_LATCHED_COLOR : 0) |
+ ((attr & 0x8000) ? USE_LATCHED_CODE : 0) ;
}
// custom function to draw a single sprite. needed to keep correct sprites - sprites and sprites - tilemaps priorities
-
-
template<class _BitmapClass>
void kaneko16_sprite_device::draw_sprites_custom(_BitmapClass &dest_bmp,const rectangle &clip,gfx_element *gfx,
- u32 code,u32 color,int flipx,int flipy,int sx,int sy,
+ u32 code,u32 color,bool flipx,bool flipy,int sx,int sy,
bitmap_ind8 &priority_bitmap, int priority)
{
- pen_t pen_base = gfx->colorbase() + gfx->granularity() * (color % gfx->colors());
+ const pen_t pen_base = gfx->colorbase() + gfx->granularity() * (color % gfx->colors());
const u8 *source_base = gfx->get_data(code % gfx->elements());
- int sprite_screen_height = ((1<<16)*gfx->height()+0x8000)>>16;
- int sprite_screen_width = ((1<<16)*gfx->width()+0x8000)>>16;
-
- if (sprite_screen_width && sprite_screen_height)
- {
- /* compute sprite increment per screen pixel */
- int dx = (gfx->width()<<16)/sprite_screen_width;
- int dy = (gfx->height()<<16)/sprite_screen_height;
+ int dx, dy;
- int ex = sx+sprite_screen_width;
- int ey = sy+sprite_screen_height;
+ int ex = sx+gfx->width();
+ int ey = sy+gfx->height();
- int x_index_base;
- int y_index;
+ int x_index_base;
+ int y_index;
- if( flipx )
- {
- x_index_base = (sprite_screen_width-1)*dx;
- dx = -dx;
- }
- else
- {
- x_index_base = 0;
- }
-
- if( flipy )
- {
- y_index = (sprite_screen_height-1)*dy;
- dy = -dy;
- }
- else
- {
- y_index = 0;
- }
+ if (flipx)
+ {
+ x_index_base = gfx->width() - 1;
+ dx = -1;
+ }
+ else
+ {
+ x_index_base = 0;
+ dx = 1;
+ }
- if( sx < clip.min_x)
- { /* clip left */
- int pixels = clip.min_x-sx;
- sx += pixels;
- x_index_base += pixels*dx;
- }
- if( sy < clip.min_y )
- { /* clip top */
- int pixels = clip.min_y-sy;
- sy += pixels;
- y_index += pixels*dy;
- }
- /* NS 980211 - fixed incorrect clipping */
- if( ex > clip.max_x+1 )
- { /* clip right */
- int pixels = ex-clip.max_x-1;
- ex -= pixels;
- }
- if( ey > clip.max_y+1 )
- { /* clip bottom */
- int pixels = ey-clip.max_y-1;
- ey -= pixels;
- }
+ if (flipy)
+ {
+ y_index = gfx->height() - 1;
+ dy = -1;
+ }
+ else
+ {
+ y_index = 0;
+ dy = 1;
+ }
- if (ex > sx)
- { /* skip if inner loop doesn't draw anything */
+ if (sx < clip.min_x)
+ { /* clip left */
+ int pixels = clip.min_x - sx;
+ sx += pixels;
+ x_index_base += pixels * dx;
+ }
+ if (sy < clip.min_y)
+ { /* clip top */
+ int pixels = clip.min_y - sy;
+ sy += pixels;
+ y_index += pixels * dy;
+ }
+ /* NS 980211 - fixed incorrect clipping */
+ if (ex > clip.max_x + 1)
+ { /* clip right */
+ int pixels = ex-clip.max_x - 1;
+ ex -= pixels;
+ }
+ if (ey > clip.max_y + 1)
+ { /* clip bottom */
+ int pixels = ey-clip.max_y - 1;
+ ey -= pixels;
+ }
- typename _BitmapClass::pixel_t *dest;
- int rgb;
- if (sizeof(*dest) == 2) rgb = 0;
- else rgb = 1;
+ if (ex > sx)
+ { /* skip if inner loop doesn't draw anything */
+ typename _BitmapClass::pixel_t *dest;
+ int rgb;
+ if (sizeof(*dest) == 2) rgb = 0;
+ else rgb = 1;
- const pen_t *pal = gfx->palette().pens();
+ const pen_t *pal = gfx->palette().pens();
+ for (int y = sy; y < ey; y++)
+ {
+ const u8 *source = source_base + y_index * gfx->rowbytes();
+ dest = &dest_bmp.pix(y);
+ u8 *pri = &priority_bitmap.pix8(y);
- for (int y = sy; y < ey; y++)
+ int x_index = x_index_base;
+ for (int x = sx; x < ex; x++)
{
- const u8 *source = source_base + (y_index >> 16) * gfx->rowbytes();
- dest = &dest_bmp.pix(y);
- u8 *pri = &priority_bitmap.pix8(y);
-
- int x_index = x_index_base;
- for (int x = sx; x < ex; x++)
+ const u8 c = source[x_index];
+ if (c != 0)
{
- int c = source[x_index >> 16];
- if (c != 0)
+ if (pri[x] < priority)
{
- if (pri[x] < priority)
- {
- if (!rgb) dest[x] = pen_base + c;
- else dest[x] = pal[pen_base + c];
- }
- pri[x] = 0xff; // mark it "already drawn"
+ if (!rgb) dest[x] = pen_base + c;
+ else dest[x] = pal[pen_base + c];
}
- x_index += dx;
+ pri[x] = 0xff; // mark it "already drawn"
}
-
- y_index += dy;
+ x_index += dx;
}
+ y_index += dy;
}
}
}
-
-
/* Build a list of sprites to display & draw them */
template<class _BitmapClass>
void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, u16* spriteram16, int spriteram16_bytes)
@@ -317,7 +347,7 @@ void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle
in a temp buffer, then draw the buffer's contents from last
to first. */
- int max = (screen().width() > 0x100) ? (0x200<<6) : (0x100<<6);
+ const int max = (screen().width() > 0x100) ? (0x200 << 6) : (0x100 << 6);
int i = 0;
struct tempsprite_t *s = m_first_sprite.get();
@@ -335,9 +365,7 @@ void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle
while (1)
{
- int flags;
-
- flags = parse_sprite_type012(i,s, spriteram16, spriteram16_bytes);
+ int flags = parse_sprite_type012(i,s, spriteram16, spriteram16_bytes);
if (flags == -1) // End of Sprites
break;
@@ -347,26 +375,25 @@ void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle
else
code = s->code; // .. or latch this value
-
if (flags & USE_LATCHED_COLOR)
{
- s->color = color;
- s->priority = priority;
- s->xoffs = xoffs;
- s->yoffs = yoffs;
+ s->color = color;
+ s->priority = priority;
+ s->xoffs = xoffs;
+ s->yoffs = yoffs;
if (m_sprite_fliptype==0)
{
- s->flipx = flipx;
- s->flipy = flipy;
+ s->flipx = flipx;
+ s->flipy = flipy;
}
}
else
{
- color = s->color;
- priority = s->priority;
- xoffs = s->xoffs;
- yoffs = s->yoffs;
+ color = s->color;
+ priority = s->priority;
+ xoffs = s->xoffs;
+ yoffs = s->yoffs;
if (m_sprite_fliptype==0)
{
@@ -378,8 +405,8 @@ void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle
// brap boys explicitly doesn't want the flip to be latched, maybe there is a different bit to enable that behavior?
if (m_sprite_fliptype==1)
{
- flipx = s->flipx;
- flipy = s->flipy;
+ flipx = s->flipx;
+ flipy = s->flipy;
}
if (flags & USE_LATCHED_XY)
@@ -388,22 +415,22 @@ void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle
s->y += y;
}
// Always latch the latest result
- x = s->x;
- y = s->y;
+ x = s->x;
+ y = s->y;
/* We can now buffer this sprite */
- s->x = s->xoffs + s->x;
- s->y = s->yoffs + s->y;
+ s->x = s->xoffs + s->x;
+ s->y = s->yoffs + s->y;
- s->x += m_sprite_xoffs;
- s->y += m_sprite_yoffs;
+ s->x += m_sprite_xoffs;
+ s->y += m_sprite_yoffs;
- if (m_sprite_flipx) { s->x = max - s->x - (16<<6); s->flipx = !s->flipx; }
- if (m_sprite_flipy) { s->y = max - s->y - (16<<6); s->flipy = !s->flipy; }
+ if (m_sprite_flipx) { s->x = max - s->x - (16 << 6); s->flipx = !s->flipx; }
+ if (m_sprite_flipy) { s->y = max - s->y - (16 << 6); s->flipy = !s->flipy; }
- s->x = ( (s->x & 0x7fc0) - (s->x & 0x8000) ) / 0x40;
- s->y = ( (s->y & 0x7fc0) - (s->y & 0x8000) ) / 0x40;
+ s->x = ((s->x & 0x7fc0) - (s->x & 0x8000)) / 0x40;
+ s->y = ((s->y & 0x7fc0) - (s->y & 0x8000)) / 0x40;
i++;
s++;
@@ -415,18 +442,18 @@ void kaneko16_sprite_device::draw_sprites(_BitmapClass &bitmap, const rectangle
for (s--; s >= m_first_sprite.get(); s--)
{
- int curr_pri = s->priority;
+ const int curr_pri = s->priority;
- u32 primask = m_priority.sprite[curr_pri];
+ const u32 primask = m_priority.sprite[curr_pri];
draw_sprites_custom(
- bitmap,cliprect,m_gfxdecode->gfx(0),
+ bitmap,cliprect,gfx(0),
s->code,
s->color,
s->flipx, s->flipy,
s->x, s->y,
priority_bitmap,
- primask );
+ primask);
}
}
@@ -507,10 +534,8 @@ u16 kaneko16_sprite_device::regs_r(offs_t offset)
void kaneko16_sprite_device::regs_w(offs_t offset, u16 data, u16 mem_mask)
{
- u16 new_data;
-
COMBINE_DATA(&m_sprites_regs[offset]);
- new_data = m_sprites_regs[offset];
+ const u16 new_data = m_sprites_regs[offset];
switch (offset)
{
@@ -520,7 +545,7 @@ void kaneko16_sprite_device::regs_w(offs_t offset, u16 data, u16 mem_mask)
m_sprite_flipx = new_data & 2;
m_sprite_flipy = new_data & 1;
- if(get_sprite_type() == 0)
+ if (get_sprite_type() == 0)
m_keep_sprites = ~new_data & 4;
}
@@ -538,25 +563,22 @@ void kaneko16_sprite_device::copybitmap(bitmap_ind16 &bitmap, const rectangle &c
void kaneko16_sprite_device::copybitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
- const pen_t *pal = m_gfxdecode->gfx(0)->palette().pens();
- u16* srcbitmap;
- u32* dstbitmap;
+ const pen_t *pal = gfx(0)->palette().pens();
for (int y = cliprect.min_y; y <= cliprect.max_y; y++)
{
- srcbitmap = &m_sprites_bitmap.pix16(y);
- dstbitmap = &bitmap.pix32(y);
+ u16* srcbitmap = &m_sprites_bitmap.pix16(y);
+ u32* dstbitmap = &bitmap.pix32(y);
for (int x = cliprect.min_x; x <= cliprect.max_x; x++)
{
- u16 pix = srcbitmap[x];
+ const u16 pix = srcbitmap[x];
if (pix) dstbitmap[x] = pal[pix];
}
}
}
-
void kaneko16_sprite_device::render_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, u16* spriteram16, int spriteram16_bytes) { render_sprites_common(bitmap, cliprect, priority_bitmap, spriteram16, spriteram16_bytes); }
void kaneko16_sprite_device::render_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, u16* spriteram16, int spriteram16_bytes) { render_sprites_common(bitmap, cliprect, priority_bitmap, spriteram16, spriteram16_bytes); }
@@ -566,7 +588,7 @@ void kaneko16_sprite_device::render_sprites_common(_BitmapClass &bitmap, const r
/* Sprites last (rendered with pdrawgfx, so they can slip
in between the layers) */
- if(m_keep_sprites)
+ if (m_keep_sprites)
{
/* keep sprites on screen - used by mgcrystl when you get the first gem and it shows instructions */
draw_sprites(m_sprites_bitmap, cliprect, priority_bitmap, spriteram16, spriteram16_bytes);
@@ -594,19 +616,16 @@ kaneko_kc002_sprite_device::kaneko_kc002_sprite_device(const machine_config &mco
void kaneko16_sprite_device::bootleg_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, u16* spriteram16, int spriteram16_bytes)
{
// u16 *spriteram16 = m_spriteram;
- int offs;
- int sx=0, sy=0;
+ int sx = 0, sy = 0;
- for (offs = 0;offs < spriteram16_bytes/2;offs += 4)
+ for (int offs = 0; offs < spriteram16_bytes / 2; offs += 4)
{
- int code,color,flipx,flipy;
-
- code = spriteram16[offs + 1] & 0x1fff;
- color = (spriteram16[offs] & 0x003c) >> 2;
- flipx = spriteram16[offs] & 0x0002;
- flipy = spriteram16[offs] & 0x0001;
+ const u32 code = spriteram16[offs + 1] & 0x1fff;
+ const u32 color = (spriteram16[offs] & 0x003c) >> 2;
+ const bool flipx = spriteram16[offs] & 0x0002;
+ const bool flipy = spriteram16[offs] & 0x0001;
- if((spriteram16[offs] & 0x6000) == 0x6000) /* Link bits */
+ if ((spriteram16[offs] & 0x6000) == 0x6000) /* Link bits */
{
sx += spriteram16[offs + 2] >> 6;
sy += spriteram16[offs + 3] >> 6;
@@ -617,10 +636,10 @@ void kaneko16_sprite_device::bootleg_draw_sprites(bitmap_ind16 &bitmap, const re
sy = spriteram16[offs + 3] >> 6;
}
- sx = (sx&0x1ff) - (sx&0x200);
- sy = (sy&0x1ff) - (sy&0x200);
+ sx = (sx & 0x1ff) - (sx & 0x200);
+ sy = (sy & 0x1ff) - (sy & 0x200);
- m_gfxdecode->gfx(0)->transpen(bitmap,cliprect,
+ gfx(0)->transpen(bitmap,cliprect,
code,
color,
flipx,flipy,