summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/namco_c355spr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mame/video/namco_c355spr.cpp')
-rw-r--r--src/mame/video/namco_c355spr.cpp237
1 files changed, 118 insertions, 119 deletions
diff --git a/src/mame/video/namco_c355spr.cpp b/src/mame/video/namco_c355spr.cpp
index 13519e184ec..6a773f34af7 100644
--- a/src/mame/video/namco_c355spr.cpp
+++ b/src/mame/video/namco_c355spr.cpp
@@ -15,17 +15,23 @@
#include "emu.h"
#include "namco_c355spr.h"
+#include <algorithm>
+
DEFINE_DEVICE_TYPE(NAMCO_C355SPR, namco_c355spr_device, "namco_c355spr", "Namco C355 (Sprites)")
namco_c355spr_device::namco_c355spr_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
device_t(mconfig, NAMCO_C355SPR, tag, owner, clock),
+ device_gfx_interface(mconfig, *this, nullptr),
device_video_interface(mconfig, *this),
- m_gfx_region(0),
m_palxor(0),
- m_scrolloffs{ 0, 0 },
m_buffer(0),
- m_gfxdecode(*this, finder_base::DUMMY_TAG)
+ m_gfx_region(*this, DEVICE_SELF),
+ m_colbase(0)
{
+ std::fill(std::begin(m_position), std::end(m_position), 0);
+ std::fill(std::begin(m_scrolloffs), std::end(m_scrolloffs), 0);
+ for (int i = 0; i < 2; i++)
+ m_spriteram[i] = nullptr;
}
@@ -34,35 +40,35 @@ namco_c355spr_device::namco_c355spr_device(const machine_config &mconfig, const
void namco_c355spr_device::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 )
+ u32 code,u32 color,bool flipx,bool flipy,int sx,int sy,
+ int scalex, int scaley, int zpos)
{
if (!scalex || !scaley) return;
if (dest_bmp.bpp() == 16)
{
if (gfx)
{
- device_palette_interface &palette = m_gfxdecode->palette();
- int shadow_offset = (palette.shadows_enabled())?palette.entries():0;
+ device_palette_interface &palette = gfx->palette();
+ int shadow_offset = (palette.shadows_enabled()) ? palette.entries() : 0;
const pen_t *pal = &palette.pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
- const uint8_t *source_base = gfx->get_data(code % gfx->elements());
- int sprite_screen_height = (scaley*gfx->height()+0x8000)>>16;
- int sprite_screen_width = (scalex*gfx->width()+0x8000)>>16;
+ const u8 *source_base = gfx->get_data(code % gfx->elements());
+ int sprite_screen_height = (scaley * gfx->height() + 0x8000) >> 16;
+ int sprite_screen_width = (scalex * 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 = (gfx->width() << 16) / sprite_screen_width;
+ int dy = (gfx->height() << 16) / sprite_screen_height;
- int ex = sx+sprite_screen_width;
- int ey = sy+sprite_screen_height;
+ int ex = sx + sprite_screen_width;
+ int ey = sy + sprite_screen_height;
int x_index_base;
int y_index;
if (flipx)
{
- x_index_base = (sprite_screen_width-1)*dx;
+ x_index_base = (sprite_screen_width - 1) * dx;
dx = -dx;
}
else
@@ -72,7 +78,7 @@ void namco_c355spr_device::zdrawgfxzoom(
if (flipy)
{
- y_index = (sprite_screen_height-1)*dy;
+ y_index = (sprite_screen_height - 1) * dy;
dy = -dy;
}
else
@@ -82,44 +88,43 @@ void namco_c355spr_device::zdrawgfxzoom(
if (sx < clip.min_x)
{ /* clip left */
- int pixels = clip.min_x-sx;
+ int pixels = clip.min_x - sx;
sx += pixels;
- x_index_base += pixels*dx;
+ x_index_base += pixels * dx;
}
if (sy < clip.min_y)
{ /* clip top */
- int pixels = clip.min_y-sy;
+ int pixels = clip.min_y - sy;
sy += pixels;
- y_index += pixels*dy;
+ y_index += pixels * dy;
}
- if (ex > clip.max_x+1)
+ if (ex > clip.max_x + 1)
{ /* clip right */
- int pixels = ex-clip.max_x-1;
+ int pixels = ex - clip.max_x - 1;
ex -= pixels;
}
- if (ey > clip.max_y+1)
+ if (ey > clip.max_y + 1)
{ /* clip bottom */
- int pixels = ey-clip.max_y-1;
+ int pixels = ey - clip.max_y - 1;
ey -= pixels;
}
- if (ex>sx)
+ if (ex > sx)
{ /* skip if inner loop doesn't draw anything */
- int y;
bitmap_ind8 &priority_bitmap = screen.priority();
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();
- uint16_t *dest = &dest_bmp.pix16(y);
- uint8_t *pri = &priority_bitmap.pix8(y);
- int x, x_index = x_index_base;
+ const u8 *source = source_base + (y_index>>16) * gfx->rowbytes();
+ u16 *dest = &dest_bmp.pix16(y);
+ u8 *pri = &priority_bitmap.pix8(y);
+ int x_index = x_index_base;
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 (pri[x] <= zpos)
@@ -127,10 +132,10 @@ void namco_c355spr_device::zdrawgfxzoom(
switch (c)
{
case 0:
- dest[x] = 0x4000|(dest[x]&0x1fff);
+ dest[x] = 0x4000|(dest[x] & 0x1fff);
break;
case 1:
- dest[x] = 0x6000|(dest[x]&0x1fff);
+ dest[x] = 0x6000|(dest[x] & 0x1fff);
break;
default:
dest[x] = pal[c];
@@ -145,12 +150,12 @@ void namco_c355spr_device::zdrawgfxzoom(
}
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 (pri[x] <= zpos )
+ if (pri[x] <= zpos)
{
if (color == 0xf && c == 0xfe && shadow_offset)
{
@@ -178,23 +183,36 @@ void namco_c355spr_device::zdrawgfxzoom(
void namco_c355spr_device::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 )
+ u32 code,u32 color,bool flipx,bool flipy,int sx,int sy,
+ int scalex, int scaley, int zpos)
{
/* nop */
}
void namco_c355spr_device::device_start()
{
+ gfx_layout obj_layout =
+ {
+ 16,16,
+ RGN_FRAC(1,1),
+ 8, /* bits per pixel */
+ { STEP8(0,1) },
+ { STEP16(0,8) },
+ { STEP16(0,8*16) },
+ 16*16*8
+ };
+ obj_layout.total = m_gfx_region->bytes() / (16*16*8 / 8);
+
std::fill(std::begin(m_position), std::end(m_position), 0x0000);
for (int i = 0; i < 2; i++)
{
m_spritelist[i] = std::make_unique<c355_sprite []>(0x100);
m_sprite_end[i] = m_spritelist[i].get();
- m_spriteram[i] = std::make_unique<uint16_t []>(0x20000/2);
+ m_spriteram[i] = std::make_unique<u16 []>(0x20000/2);
std::fill_n(m_spriteram[i].get(), 0x20000/2, 0);
save_pointer(NAME(m_spriteram[i]), 0x20000/2, i);
}
+ set_gfx(0, std::make_unique<gfx_element>(&palette(), obj_layout, m_gfx_region->base(), 0, 0x10, m_colbase));
save_item(NAME(m_position));
}
@@ -212,11 +230,11 @@ void namco_c355spr_device::device_stop()
/**************************************************************************************/
-WRITE16_MEMBER( namco_c355spr_device::position_w )
+void namco_c355spr_device::position_w(offs_t offset, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_position[offset]);
}
-READ16_MEMBER( namco_c355spr_device::position_r )
+u16 namco_c355spr_device::position_r(offs_t offset)
{
return m_position[offset];
}
@@ -233,66 +251,48 @@ READ16_MEMBER( namco_c355spr_device::position_r )
* 0x10000 sprite attr (page1)
* 0x14000 sprite list (page1)
*/
-void namco_c355spr_device::get_single_sprite(const uint16_t *pSource, c355_sprite *sprite_ptr)
+void namco_c355spr_device::get_single_sprite(const u16 *pSource, c355_sprite *sprite_ptr)
{
- uint16_t *spriteram16 = &m_spriteram[std::max(0, m_buffer - 1)][0];
- unsigned screen_height_remaining, screen_width_remaining;
- unsigned source_height_remaining, source_width_remaining;
- int hpos,vpos;
- uint16_t hsize,vsize;
- uint16_t palette;
- uint16_t linkno;
- uint16_t format;
- int tile_index;
- int num_cols,num_rows;
- int dx,dy;
- int row,col;
- int sx,sy,tile;
- int flipx,flipy;
- uint32_t zoomx, zoomy;
- int tile_screen_width;
- int tile_screen_height;
- const uint16_t *spriteformat16 = &spriteram16[0x4000/2];
- const uint16_t *spritetile16 = &spriteram16[0x8000/2];
- const uint16_t *pWinAttr;
+ u16 *spriteram16 = &m_spriteram[std::max(0, m_buffer - 1)][0];
+ const u16 *spriteformat16 = &spriteram16[0x4000 / 2];
+ const u16 *spritetile16 = &spriteram16[0x8000 / 2];
rectangle clip;
- int xscroll, yscroll;
/**
* ----xxxx-------- window select
* --------xxxx---- priority
* ------------xxxx palette select
*/
- palette = pSource[6];
- sprite_ptr->pri = ((palette>>4)&0xf);
+ const u16 palette = pSource[6];
+ sprite_ptr->pri = ((palette >> 4) & 0xf);
- linkno = pSource[0]; /* LINKNO */
+ const u16 linkno = pSource[0]; /* LINKNO */
sprite_ptr->offset = pSource[1]; /* OFFSET */
- hpos = pSource[2]; /* HPOS 0x000..0x7ff (signed) */
- vpos = pSource[3]; /* VPOS 0x000..0x7ff (signed) */
- hsize = pSource[4]; /* HSIZE max 0x3ff pixels */
- vsize = pSource[5]; /* VSIZE max 0x3ff pixels */
+ int hpos = pSource[2]; /* HPOS 0x000..0x7ff (signed) */
+ int vpos = pSource[3]; /* VPOS 0x000..0x7ff (signed) */
+ u16 hsize = pSource[4]; /* HSIZE max 0x3ff pixels */
+ u16 vsize = pSource[5]; /* VSIZE max 0x3ff pixels */
/* pSource[6] contains priority/palette */
/* pSource[7] is used in Lucky & Wild, possibly for sprite-road priority */
- if (linkno*4>=0x4000/2) /* avoid garbage memory reads */
+ if (linkno * 4 >= 0x4000 / 2) /* avoid garbage memory reads */
{
sprite_ptr->disable = true;
return;
}
- xscroll = (int16_t)m_position[1];
- yscroll = (int16_t)m_position[0];
+ int xscroll = (s16)m_position[1];
+ int yscroll = (s16)m_position[0];
-// xscroll &= 0x3ff; if (xscroll & 0x200 ) xscroll |= ~0x3ff;
- xscroll &= 0x1ff; if (xscroll & 0x100 ) xscroll |= ~0x1ff;
- yscroll &= 0x1ff; if (yscroll & 0x100 ) yscroll |= ~0x1ff;
+// xscroll &= 0x3ff; if (xscroll & 0x200) xscroll |= ~0x3ff;
+ xscroll &= 0x1ff; if (xscroll & 0x100) xscroll |= ~0x1ff;
+ yscroll &= 0x1ff; if (yscroll & 0x100) yscroll |= ~0x1ff;
if (screen().height() > 384)
{ /* Medium Resolution: System21 adjust */
- xscroll = (int16_t)m_position[1];
+ xscroll = (s16)m_position[1];
xscroll &= 0x3ff; if (xscroll & 0x200) xscroll |= ~0x3ff;
- if (yscroll<0)
+ if (yscroll < 0)
{ /* solvalou */
yscroll += 0x20;
}
@@ -306,29 +306,29 @@ void namco_c355spr_device::get_single_sprite(const uint16_t *pSource, c355_sprit
hpos -= xscroll;
vpos -= yscroll;
- pWinAttr = &spriteram16[0x2400/2+((palette>>8)&0xf)*4];
+ const u16 *pWinAttr = &spriteram16[0x2400 / 2 + ((palette >> 8) & 0xf) * 4];
clip.set(pWinAttr[0] - xscroll, pWinAttr[1] - xscroll, pWinAttr[2] - yscroll, pWinAttr[3] - yscroll);
sprite_ptr->clip = clip;
- hpos&=0x7ff; if (hpos&0x400 ) hpos |= ~0x7ff; /* sign extend */
- vpos&=0x7ff; if (vpos&0x400 ) vpos |= ~0x7ff; /* sign extend */
+ hpos &= 0x7ff; if (hpos & 0x400) hpos |= ~0x7ff; /* sign extend */
+ vpos &= 0x7ff; if (vpos & 0x400) vpos |= ~0x7ff; /* sign extend */
- tile_index = spriteformat16[linkno*4+0];
- format = spriteformat16[linkno*4+1];
- dx = spriteformat16[linkno*4+2];
- dy = spriteformat16[linkno*4+3];
- num_cols = (format>>4)&0xf;
- num_rows = (format)&0xf;
+ int tile_index = spriteformat16[linkno * 4 + 0];
+ const u16 format = spriteformat16[linkno * 4 + 1];
+ int dx = spriteformat16[linkno * 4 + 2];
+ int dy = spriteformat16[linkno * 4 + 3];
+ int num_cols = (format >> 4) & 0xf;
+ int num_rows = (format) & 0xf;
if (num_cols == 0) num_cols = 0x10;
- flipx = (hsize&0x8000)?1:0;
+ bool flipx = (hsize & 0x8000);
hsize &= 0x3ff;//0x1ff;
if (hsize == 0)
{
sprite_ptr->disable = true;
return;
}
- zoomx = (hsize<<16)/(num_cols*16);
- dx = (dx*zoomx+0x8000)>>16;
+ u32 zoomx = (hsize << 16) / (num_cols * 16);
+ dx = (dx * zoomx + 0x8000) >> 16;
if (flipx)
{
hpos += dx;
@@ -339,15 +339,15 @@ void namco_c355spr_device::get_single_sprite(const uint16_t *pSource, c355_sprit
}
if (num_rows == 0) num_rows = 0x10;
- flipy = (vsize&0x8000)?1:0;
+ bool flipy = (vsize & 0x8000);
vsize &= 0x3ff;
if (vsize == 0)
{
sprite_ptr->disable = true;
return;
}
- zoomy = (vsize<<16)/(num_rows*16);
- dy = (dy*zoomy+0x8000)>>16;
+ u32 zoomy = (vsize << 16) / (num_rows * 16);
+ dy = (dy * zoomy + 0x8000) >> 16;
if (flipy)
{
vpos += dy;
@@ -360,34 +360,34 @@ void namco_c355spr_device::get_single_sprite(const uint16_t *pSource, c355_sprit
sprite_ptr->flipx = flipx;
sprite_ptr->flipy = flipy;
sprite_ptr->size = num_rows * num_cols;
- sprite_ptr->color = (palette&0xf)^m_palxor;
+ sprite_ptr->color = (palette & 0xf) ^ m_palxor;
- source_height_remaining = num_rows*16;
- screen_height_remaining = vsize;
- sy = vpos;
+ u32 source_height_remaining = num_rows * 16;
+ u32 screen_height_remaining = vsize;
+ int sy = vpos;
int ind = 0;
- for (row = 0; row < num_rows; row++)
+ for (int row = 0; row < num_rows; row++)
{
- tile_screen_height = 16*screen_height_remaining/source_height_remaining;
- zoomy = (screen_height_remaining<<16)/source_height_remaining;
+ int tile_screen_height = 16 * screen_height_remaining / source_height_remaining;
+ zoomy = (screen_height_remaining << 16) / source_height_remaining;
if (flipy)
{
sy -= tile_screen_height;
}
- source_width_remaining = num_cols*16;
- screen_width_remaining = hsize;
- sx = hpos;
- for (col = 0; col < num_cols; col++)
+ u32 source_width_remaining = num_cols * 16;
+ u32 screen_width_remaining = hsize;
+ int sx = hpos;
+ for (int col = 0; col < num_cols; col++)
{
- tile_screen_width = 16*screen_width_remaining/source_width_remaining;
- zoomx = (screen_width_remaining<<16)/source_width_remaining;
+ int tile_screen_width = 16 * screen_width_remaining / source_width_remaining;
+ zoomx = (screen_width_remaining << 16) / source_width_remaining;
if (flipx)
{
sx -= tile_screen_width;
}
- tile = spritetile16[tile_index++];
+ const u16 tile = spritetile16[tile_index++];
sprite_ptr->tile[ind] = tile;
- if ((tile&0x8000)==0)
+ if ((tile & 0x8000) == 0)
{
sprite_ptr->x[ind] = sx;
sprite_ptr->y[ind] = sy;
@@ -417,17 +417,17 @@ int namco_c355spr_device::default_code2tile(int code)
return code;
}
-void namco_c355spr_device::get_list(int no, const uint16_t *pSpriteList16, const uint16_t *pSpriteTable)
+void namco_c355spr_device::get_list(int no, const u16 *pSpriteList16, const u16 *pSpriteTable)
{
/* draw the sprites */
c355_sprite *sprite_ptr = m_spritelist[no].get();
for (int i = 0; i < 256; i++)
{
sprite_ptr->disable = false;
- uint16_t which = pSpriteList16[i];
- get_single_sprite(&pSpriteTable[(which&0xff)*8], sprite_ptr);
+ const u16 which = pSpriteList16[i];
+ get_single_sprite(&pSpriteTable[(which & 0xff) * 8], sprite_ptr);
sprite_ptr++;
- if (which&0x100) break;
+ if (which & 0x100) break;
}
m_sprite_end[no] = sprite_ptr;
}
@@ -476,7 +476,7 @@ void namco_c355spr_device::draw_sprites(screen_device &screen, BitmapClass &bitm
screen,
bitmap,
clip,
- m_gfxdecode->gfx(m_gfx_region),
+ gfx(0),
m_code2tile(sprite_ptr->tile[ind]) + sprite_ptr->offset,
sprite_ptr->color,
sprite_ptr->flipx, sprite_ptr->flipy,
@@ -502,17 +502,17 @@ void namco_c355spr_device::draw(screen_device &screen, bitmap_rgb32 &bitmap, con
draw_sprites(screen, bitmap, cliprect, pri);
}
-WRITE16_MEMBER( namco_c355spr_device::spriteram_w )
+void namco_c355spr_device::spriteram_w(offs_t offset, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_spriteram[0][offset]);
}
-READ16_MEMBER( namco_c355spr_device::spriteram_r )
+u16 namco_c355spr_device::spriteram_r(offs_t offset)
{
return m_spriteram[0][offset];
}
-WRITE_LINE_MEMBER( namco_c355spr_device::vblank )
+WRITE_LINE_MEMBER(namco_c355spr_device::vblank)
{
if (state)
{
@@ -523,4 +523,3 @@ WRITE_LINE_MEMBER( namco_c355spr_device::vblank )
std::copy_n(m_spriteram[0].get(), 0x20000/2, m_spriteram[1].get());
}
}
-