Skip to content

Commit

Permalink
kaneko/kaneko_spr.cpp, kaneko/kaneko_tmap.cpp: Use generic gfx layout…
Browse files Browse the repository at this point in the history
…, Reduce unnecessary finder

kaneko/kaneko_spr.cpp: Fix typename for boolean flags
  • Loading branch information
cam900 committed Nov 17, 2024
1 parent 0ad4341 commit 9706220
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 88 deletions.
101 changes: 48 additions & 53 deletions src/mame/kaneko/kaneko_spr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ kaneko16_sprite_device::kaneko16_sprite_device(
: device_t(mconfig, type, tag, owner, clock)
, device_gfx_interface(mconfig, *this, nullptr)
, device_video_interface(mconfig, *this)
, m_gfx_region(*this, DEVICE_SELF)
, m_colbase(0)
{
m_keep_sprites = 0; // default disabled for games not using it


m_sprite_xoffs = 0;
m_sprite_yoffs = 0;

Expand Down Expand Up @@ -81,54 +79,51 @@ void kaneko16_sprite_device::device_start()
}


GFXDECODE_MEMBER(kaneko_vu002_sprite_device::gfxinfo)
GFXDECODE_DEVICE(DEVICE_SELF, 0, gfx_8x8x4_row_2x2_group_packed_msb, 0, 0x40)
GFXDECODE_END


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);
decode_gfx(gfxinfo);
gfx(0)->set_colorbase(m_colbase);
kaneko16_sprite_device::device_start();
set_gfx(0, std::make_unique<gfx_element>(&palette(), layout_16x16x4, m_gfx_region->base(), 0, 0x40, m_colbase));
}


/*
16x16x8 made of 4 8x8x8 blocks arrenged like: 01
23
*/
static gfx_layout layout_16x16x8 =
{
16,16,
RGN_FRAC(1,1),
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
};

GFXDECODE_MEMBER(kaneko_kc002_sprite_device::gfxinfo)
GFXDECODE_DEVICE(DEVICE_SELF, 0, layout_16x16x8, 0, 0x40)
GFXDECODE_END


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);
decode_gfx(gfxinfo);
gfx(0)->set_colorbase(m_colbase);
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()
{
m_sprite_flipx = 0;
m_sprite_flipy = 0;
m_sprite_flipx = false;
m_sprite_flipy = false;
}

/***************************************************************************
Expand Down Expand Up @@ -189,15 +184,15 @@ void kaneko_kc002_sprite_device::get_sprite_attributes(struct tempsprite_t *s, u
{
s->color = (attr & 0x003f);
s->priority = (attr & 0x00c0) >> 6;
s->flipy = (attr & 0x0100);
s->flipx = (attr & 0x0200);
s->flipy = BIT(attr, 8);
s->flipx = BIT(attr, 9);
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->flipy = BIT(attr, 0);
s->flipx = BIT(attr, 1);
s->color = (attr & 0x00fc) >> 2;
s->priority = (attr & 0x0300) >> 8;
}
Expand Down Expand Up @@ -232,9 +227,9 @@ int kaneko16_sprite_device::parse_sprite_type012(int i, struct tempsprite_t *s,
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 (BIT(attr, 13) ? USE_LATCHED_XY : 0) |
(BIT(attr, 14) ? USE_LATCHED_COLOR : 0) |
(BIT(attr, 15) ? USE_LATCHED_CODE : 0) ;
}

// custom function to draw a single sprite. needed to keep correct sprites - sprites and sprites - tilemaps priorities
Expand Down Expand Up @@ -352,8 +347,8 @@ void kaneko16_sprite_device::draw_sprites(const rectangle &cliprect, u16* sprite
int priority = 0;
int xoffs = 0;
int yoffs = 0;
int flipx = 0;
int flipy = 0;
bool flipx = false;
bool flipy = false;

while (1)
{
Expand All @@ -374,7 +369,7 @@ void kaneko16_sprite_device::draw_sprites(const rectangle &cliprect, u16* sprite
s->xoffs = xoffs;
s->yoffs = yoffs;

if (m_sprite_fliptype==0)
if (m_sprite_fliptype == 0)
{
s->flipx = flipx;
s->flipy = flipy;
Expand All @@ -387,15 +382,15 @@ void kaneko16_sprite_device::draw_sprites(const rectangle &cliprect, u16* sprite
xoffs = s->xoffs;
yoffs = s->yoffs;

if (m_sprite_fliptype==0)
if (m_sprite_fliptype == 0)
{
flipx = s->flipx;
flipy = s->flipy;
}
}

// 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)
if (m_sprite_fliptype == 1)
{
flipx = s->flipx;
flipy = s->flipy;
Expand Down Expand Up @@ -529,11 +524,11 @@ void kaneko16_sprite_device::regs_w(offs_t offset, u16 data, u16 mem_mask)
case 0:
if (ACCESSING_BITS_0_7)
{
m_sprite_flipx = new_data & 2;
m_sprite_flipy = new_data & 1;
m_sprite_flipx = BIT(new_data, 1);
m_sprite_flipy = BIT(new_data, 0);

if (get_sprite_type() == 0)
m_keep_sprites = ~new_data & 4;
m_keep_sprites = BIT(~new_data, 2);
}

break;
Expand Down Expand Up @@ -610,8 +605,8 @@ void kaneko16_sprite_device::bootleg_draw_sprites(bitmap_ind16 &bitmap, const re
{
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;
const bool flipx = BIT(spriteram16[offs], 1);
const bool flipy = BIT(spriteram16[offs], 0);

if ((spriteram16[offs] & 0x6000) == 0x6000) /* Link bits */
{
Expand Down
11 changes: 8 additions & 3 deletions src/mame/kaneko/kaneko_spr.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ class kaneko16_sprite_device : public device_t, public device_gfx_interface, pub
// them in a different order
virtual void get_sprite_attributes(struct tempsprite_t *s, u16 attr) =0;

required_memory_region m_gfx_region;
u16 m_colbase;

private:
// registers
u16 m_sprite_flipx;
u16 m_sprite_flipy;
bool m_sprite_flipx;
bool m_sprite_flipy;
std::unique_ptr<u16[]> m_sprites_regs;

std::unique_ptr<struct tempsprite_t[]> m_first_sprite;
Expand Down Expand Up @@ -128,6 +127,9 @@ class kaneko_vu002_sprite_device : public kaneko16_sprite_device

protected:
virtual void device_start() override ATTR_COLD;

private:
DECLARE_GFXDECODE_MEMBER(gfxinfo);
};

DECLARE_DEVICE_TYPE(KANEKO_VU002_SPRITE, kaneko_vu002_sprite_device)
Expand All @@ -147,6 +149,9 @@ class kaneko_kc002_sprite_device : public kaneko16_sprite_device

protected:
virtual void device_start() override ATTR_COLD;

private:
DECLARE_GFXDECODE_MEMBER(gfxinfo);
};

DECLARE_DEVICE_TYPE(KANEKO_KC002_SPRITE, kaneko_kc002_sprite_device)
Expand Down
51 changes: 21 additions & 30 deletions src/mame/kaneko/kaneko_tmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ kaneko_view2_tilemap_device::kaneko_view2_tilemap_device(const machine_config &m
, device_gfx_interface(mconfig, *this, nullptr)
, m_vram(*this, "vram_%u", 0U)
, m_vscroll(*this, "scroll_%u", 0U)
, m_gfxrom(*this, DEVICE_SELF)
, m_colbase(0)
, m_dx(0)
, m_dy(0)
Expand All @@ -133,27 +132,19 @@ TILE_GET_INFO_MEMBER(kaneko_view2_tilemap_device::get_tile_info)
tileinfo.category = (attr >> 8) & 7;
}

GFXDECODE_MEMBER(kaneko_view2_tilemap_device::gfxinfo)
GFXDECODE_DEVICE(DEVICE_SELF, 0, gfx_8x8x4_row_2x2_group_packed_lsb, 0, 0x40)
GFXDECODE_END


void kaneko_view2_tilemap_device::device_start()
{
/* 16x16x4 tiles (made of four 8x8 tiles) */
gfx_layout layout =
{
16,16,
0,
4,
{ STEP4(0,1) },
{ 4, 0, 12, 8, 20, 16, 28, 24, 8*32+4, 8*32+0, 8*32+12, 8*32+8, 8*32+20, 8*32+16, 8*32+28, 8*32+24 },
{ STEP8(0,32), STEP8(16*32,32) },
16*16*4
};
layout.total = m_gfxrom->bytes() / ((16*16*4) / 8);
decode_gfx(gfxinfo);
gfx(0)->set_colorbase(m_colbase);

m_view2_cb.resolve();
m_regs = make_unique_clear<u16[]>(0x20/2);

set_gfx(0, std::make_unique<gfx_element>(&palette(), layout, m_gfxrom->base(), 0, 0x40, m_colbase));

m_tmap[0] = &machine().tilemap().create(
*this,
tilemap_get_info_delegate(*this, FUNC(kaneko_view2_tilemap_device::get_tile_info<0>)),
Expand Down Expand Up @@ -185,10 +176,10 @@ void kaneko_view2_tilemap_device::device_reset()
}


void kaneko_view2_tilemap_device::vram_w(int _N_, offs_t offset, u16 data, u16 mem_mask)
void kaneko_view2_tilemap_device::vram_w(int i, offs_t offset, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_vram[_N_][offset]);
m_tmap[_N_]->mark_tile_dirty(offset/2);
COMBINE_DATA(&m_vram[i][offset]);
m_tmap[i]->mark_tile_dirty(offset/2);
}

void kaneko_view2_tilemap_device::prepare(bitmap_ind16 &bitmap, const rectangle &cliprect) { prepare_common(bitmap, cliprect); }
Expand All @@ -200,23 +191,23 @@ void kaneko_view2_tilemap_device::prepare_common(BitmapClass &bitmap, const rect
const u16 layers_flip_0 = m_regs[4];

/* Enable layers */
m_tmap[0]->enable(~layers_flip_0 & 0x1000);
m_tmap[1]->enable(~layers_flip_0 & 0x0010);
m_tmap[0]->enable(BIT(~layers_flip_0, 12));
m_tmap[1]->enable(BIT(~layers_flip_0, 4));

/* Flip layers */
if (!m_invert_flip)
{
m_tmap[0]->set_flip(((layers_flip_0 & 0x0100) ? TILEMAP_FLIPY : 0) |
((layers_flip_0 & 0x0200) ? TILEMAP_FLIPX : 0));
m_tmap[1]->set_flip(((layers_flip_0 & 0x0100) ? TILEMAP_FLIPY : 0) |
((layers_flip_0 & 0x0200) ? TILEMAP_FLIPX : 0));
m_tmap[0]->set_flip((BIT(layers_flip_0, 8) ? TILEMAP_FLIPY : 0) |
(BIT(layers_flip_0, 9) ? TILEMAP_FLIPX : 0));
m_tmap[1]->set_flip((BIT(layers_flip_0, 8) ? TILEMAP_FLIPY : 0) |
(BIT(layers_flip_0, 9) ? TILEMAP_FLIPX : 0));
}
else
{
m_tmap[0]->set_flip(((layers_flip_0 & 0x0100) ? 0 : TILEMAP_FLIPY) |
((layers_flip_0 & 0x0200) ? 0 : TILEMAP_FLIPX));
m_tmap[1]->set_flip(((layers_flip_0 & 0x0100) ? 0 : TILEMAP_FLIPY) |
((layers_flip_0 & 0x0200) ? 0 : TILEMAP_FLIPX));
m_tmap[0]->set_flip((BIT(layers_flip_0, 8) ? 0 : TILEMAP_FLIPY) |
(BIT(layers_flip_0, 9) ? 0 : TILEMAP_FLIPX));
m_tmap[1]->set_flip((BIT(layers_flip_0, 8) ? 0 : TILEMAP_FLIPY) |
(BIT(layers_flip_0, 9) ? 0 : TILEMAP_FLIPX));
}

/* Scroll layers */
Expand All @@ -230,9 +221,9 @@ void kaneko_view2_tilemap_device::prepare_common(BitmapClass &bitmap, const rect

for (int i = 0; i < 0x200; i++)
{
u16 scroll = (layers_flip_0 & 0x0800) ? m_vscroll[0][i] : 0;
u16 scroll = BIT(layers_flip_0, 11) ? m_vscroll[0][i] : 0;
m_tmap[0]->set_scrollx(i,(layer0_scrollx + scroll) >> 6 );
scroll = (layers_flip_0 & 0x0008) ? m_vscroll[1][i] : 0;
scroll = BIT(layers_flip_0, 3) ? m_vscroll[1][i] : 0;
m_tmap[1]->set_scrollx(i,(layer1_scrollx + scroll) >> 6 );
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/mame/kaneko/kaneko_tmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class kaneko_view2_tilemap_device : public device_t, public device_gfx_interface

template <typename... T> void set_tile_callback(T &&... args) { m_view2_cb.set(std::forward<T>(args)...); }

void vram_w(int _N_, offs_t offset, u16 data, u16 mem_mask = u16(~0));
void vram_w(int i, offs_t offset, u16 data, u16 mem_mask = u16(~0));

// call to do the rendering etc.
template<class BitmapClass>
Expand Down Expand Up @@ -76,11 +76,12 @@ class kaneko_view2_tilemap_device : public device_t, public device_gfx_interface

private:
template<unsigned Layer> TILE_GET_INFO_MEMBER(get_tile_info);
DECLARE_GFXDECODE_MEMBER(gfxinfo);

required_shared_ptr_array<u16, 2> m_vram;
required_shared_ptr_array<u16, 2> m_vscroll;

// set when creating device
required_memory_region m_gfxrom;
u16 m_colbase;
int m_dx, m_dy, m_xdim, m_ydim;
int m_invert_flip;
Expand Down

0 comments on commit 9706220

Please sign in to comment.