small cleanup: put draw_sprites in its own function instead of inside screen_update

This commit is contained in:
Michaël Banaan Ananas 2014-05-22 16:19:39 +00:00
parent e5cb963716
commit dd65152b67
3 changed files with 119 additions and 156 deletions

View File

@ -20,19 +20,24 @@
#include "includes/finalizr.h"
TIMER_DEVICE_CALLBACK_MEMBER(finalizr_state::finalizr_scanline)
{
int scanline = param;
if(scanline == 240 && m_irq_enable) // vblank irq
if (scanline == 240 && m_irq_enable) // vblank irq
m_maincpu->set_input_line(M6809_IRQ_LINE, HOLD_LINE);
else if(((scanline % 32) == 0) && m_nmi_enable) // timer irq
else if (((scanline % 32) == 0) && m_nmi_enable) // timer irq
m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
}
WRITE8_MEMBER(finalizr_state::finalizr_videoctrl_w)
{
m_charbank = data & 3;
m_spriterambank = data & 8;
/* other bits unknown */
}
WRITE8_MEMBER(finalizr_state::finalizr_coin_w)
{
coin_counter_w(machine(), 0, data & 0x01);
@ -257,11 +262,10 @@ static MACHINE_CONFIG_START( finalizr, finalizr_state )
MCFG_CPU_PROGRAM_MAP(main_map)
MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", finalizr_state, finalizr_scanline, "screen", 0, 1)
MCFG_CPU_ADD("audiocpu", I8039,XTAL_18_432MHz/2) /* 9.216MHz clkin ?? */
MCFG_CPU_ADD("audiocpu", I8039,XTAL_18_432MHz/2) /* 9.216MHz clkin ?? */
MCFG_CPU_PROGRAM_MAP(sound_map)
MCFG_CPU_IO_MAP(sound_io_map)
/* video hardware */
MCFG_SCREEN_ADD("screen", RASTER)
MCFG_SCREEN_REFRESH_RATE(60)

View File

@ -1,6 +1,6 @@
/***************************************************************************
Finalizer
Konami Finalizer
***************************************************************************/
@ -9,17 +9,24 @@ class finalizr_state : public driver_device
public:
finalizr_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag),
m_maincpu(*this, "maincpu"),
m_audiocpu(*this, "audiocpu"),
m_gfxdecode(*this, "gfxdecode"),
m_palette(*this, "palette"),
m_scroll(*this, "scroll"),
m_colorram(*this, "colorram"),
m_videoram(*this, "videoram"),
m_colorram2(*this, "colorram2"),
m_videoram2(*this, "videoram2"),
m_spriteram(*this, "spriteram"),
m_spriteram_2(*this, "spriteram_2"),
m_maincpu(*this, "maincpu"),
m_audiocpu(*this, "audiocpu"),
m_gfxdecode(*this, "gfxdecode"),
m_palette(*this, "palette") { }
m_spriteram_2(*this, "spriteram_2")
{ }
/* devices */
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
/* memory pointers */
required_shared_ptr<UINT8> m_scroll;
@ -31,17 +38,16 @@ public:
required_shared_ptr<UINT8> m_spriteram_2;
/* video-related */
tilemap_t *m_fg_tilemap;
tilemap_t *m_bg_tilemap;
int m_spriterambank;
int m_charbank;
tilemap_t *m_fg_tilemap;
tilemap_t *m_bg_tilemap;
int m_spriterambank;
int m_charbank;
/* misc */
int m_T1_line;
UINT8 m_nmi_enable;
UINT8 m_irq_enable;
int m_T1_line;
UINT8 m_nmi_enable;
UINT8 m_irq_enable;
/* devices */
DECLARE_WRITE8_MEMBER(finalizr_coin_w);
DECLARE_WRITE8_MEMBER(finalizr_flipscreen_w);
DECLARE_WRITE8_MEMBER(finalizr_i8039_irq_w);
@ -56,10 +62,7 @@ public:
virtual void machine_reset();
virtual void video_start();
DECLARE_PALETTE_INIT(finalizr);
void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
UINT32 screen_update_finalizr(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
TIMER_DEVICE_CALLBACK_MEMBER(finalizr_scanline);
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
};

View File

@ -1,6 +1,6 @@
/***************************************************************************
video.c
Konami Finalizer
Functions to emulate the video hardware of the machine.
@ -119,150 +119,106 @@ void finalizr_state::video_start()
WRITE8_MEMBER(finalizr_state::finalizr_videoctrl_w)
{
m_charbank = data & 3;
m_spriterambank = data & 8;
/* other bits unknown */
}
/**************************************************************************/
void finalizr_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
gfx_element *gfx1 = m_gfxdecode->gfx(1);
gfx_element *gfx2 = m_gfxdecode->gfx(2);
UINT8 *sr = m_spriterambank ? m_spriteram_2 : m_spriteram;
for (int offs = 0; offs <= m_spriteram.bytes() - 5; offs += 5)
{
int sx, sy, flipx, flipy, code, color, size;
sx = 32 + 1 + sr[offs + 3] - ((sr[offs + 4] & 0x01) << 8);
sy = sr[offs + 2];
flipx = sr[offs + 4] & 0x20;
flipy = sr[offs + 4] & 0x40;
code = sr[offs] + ((sr[offs + 1] & 0x0f) << 8);
color = ((sr[offs + 1] & 0xf0) >> 4);
// (sr[offs + 4] & 0x02) is used, meaning unknown
size = sr[offs + 4] & 0x1c;
if (size >= 0x10)
{
// 32x32
if (flip_screen())
{
sx = 256 - sx;
sy = 224 - sy;
flipx = !flipx;
flipy = !flipy;
}
gfx1->transpen(bitmap, cliprect, code + 0, color, flipx, flipy, flipx ? sx + 16 : sx, flipy ? sy + 16 : sy, 0);
gfx1->transpen(bitmap, cliprect, code + 1, color, flipx, flipy, flipx ? sx : sx + 16, flipy ? sy + 16 : sy, 0);
gfx1->transpen(bitmap, cliprect, code + 2, color, flipx, flipy, flipx ? sx + 16: sx , flipy ? sy : sy + 16, 0);
gfx1->transpen(bitmap, cliprect, code + 3, color, flipx, flipy, flipx ? sx : sx + 16, flipy ? sy : sy + 16, 0);
}
else
{
if (flip_screen())
{
sx = ((size & 0x08) ? 280: 272) - sx;
sy = ((size & 0x04) ? 248: 240) - sy;
flipx = !flipx;
flipy = !flipy;
}
if (size == 0x00)
{
// 16x16
gfx1->transpen(bitmap, cliprect, code, color, flipx, flipy, sx, sy, 0);
}
else
{
code = ((code & 0x3ff) << 2) | ((code & 0xc00) >> 10);
if (size == 0x04)
{
// 16x8
gfx2->transpen(bitmap, cliprect, code &~1, color, flipx, flipy, flipx ? sx + 8 : sx, sy, 0);
gfx2->transpen(bitmap, cliprect, code | 1, color, flipx, flipy, flipx ? sx : sx + 8, sy, 0);
}
else if (size == 0x08)
{
// 8x16
gfx2->transpen(bitmap, cliprect, code &~2, color, flipx, flipy, sx, flipy ? sy + 8 : sy, 0);
gfx2->transpen(bitmap, cliprect, code | 2, color, flipx, flipy, sx, flipy ? sy : sy + 8, 0);
}
else if (size == 0x0c)
{
// 8x8
gfx2->transpen(bitmap, cliprect, code, color, flipx, flipy, sx, sy, 0);
}
}
}
}
}
UINT32 finalizr_state::screen_update_finalizr(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int offs;
m_bg_tilemap->mark_all_dirty();
m_fg_tilemap->mark_all_dirty();
m_bg_tilemap->set_scrollx(0, *m_scroll - 32);
m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
/* Draw the sprites. */
{
gfx_element *gfx1 = m_gfxdecode->gfx(1);
gfx_element *gfx2 = m_gfxdecode->gfx(2);
draw_sprites(bitmap, cliprect);
UINT8 *sr = m_spriterambank ? m_spriteram_2 : m_spriteram;
// draw top status region
const rectangle &visarea = screen.visible_area();
rectangle clip = cliprect;
clip.min_x = visarea.min_x;
clip.max_x = visarea.min_x + 31;
m_fg_tilemap->set_scrolldx(0,-32);
m_fg_tilemap->draw(screen, bitmap, clip, 0, 0);
for (offs = 0; offs <= m_spriteram.bytes() - 5; offs += 5)
{
int sx, sy, flipx, flipy, code, color, size;
sx = 32 + 1 + sr[offs + 3] - ((sr[offs + 4] & 0x01) << 8);
sy = sr[offs + 2];
flipx = sr[offs + 4] & 0x20;
flipy = sr[offs + 4] & 0x40;
code = sr[offs] + ((sr[offs + 1] & 0x0f) << 8);
color = ((sr[offs + 1] & 0xf0)>>4);
// (sr[offs + 4] & 0x02) is used, meaning unknown
size = sr[offs + 4] & 0x1c;
if (size >= 0x10) /* 32x32 */
{
if (flip_screen())
{
sx = 256 - sx;
sy = 224 - sy;
flipx = !flipx;
flipy = !flipy;
}
gfx1->transpen(bitmap,cliprect,
code,
color,
flipx,flipy,
flipx?sx+16:sx,flipy?sy+16:sy,0);
gfx1->transpen(bitmap,cliprect,
code + 1,
color,
flipx,flipy,
flipx?sx:sx+16,flipy?sy+16:sy,0);
gfx1->transpen(bitmap,cliprect,
code + 2,
color,
flipx,flipy,
flipx?sx+16:sx,flipy?sy:sy+16,0);
gfx1->transpen(bitmap,cliprect,
code + 3,
color,
flipx,flipy,
flipx?sx:sx+16,flipy?sy:sy+16,0);
}
else
{
if (flip_screen())
{
sx = ((size & 0x08) ? 280:272) - sx;
sy = ((size & 0x04) ? 248:240) - sy;
flipx = !flipx;
flipy = !flipy;
}
if (size == 0x00) /* 16x16 */
{
gfx1->transpen(bitmap,cliprect,
code,
color,
flipx,flipy,
sx,sy,0);
}
else
{
code = ((code & 0x3ff) << 2) | ((code & 0xc00) >> 10);
if (size == 0x04) /* 16x8 */
{
gfx2->transpen(bitmap,cliprect,
code & ~1,
color,
flipx,flipy,
flipx?sx+8:sx,sy,0);
gfx2->transpen(bitmap,cliprect,
code | 1,
color,
flipx,flipy,
flipx?sx:sx+8,sy,0);
}
else if (size == 0x08) /* 8x16 */
{
gfx2->transpen(bitmap,cliprect,
code & ~2,
color,
flipx,flipy,
sx,flipy?sy+8:sy,0);
gfx2->transpen(bitmap,cliprect,
code | 2,
color,
flipx,flipy,
sx,flipy?sy:sy+8,0);
}
else if (size == 0x0c) /* 8x8 */
{
gfx2->transpen(bitmap,cliprect,
code,
color,
flipx,flipy,
sx,sy,0);
}
}
}
}
}
{
const rectangle &visarea = screen.visible_area();
rectangle clip = cliprect;
/* draw top status region */
clip.min_x = visarea.min_x;
clip.max_x = visarea.min_x + 31;
m_fg_tilemap->set_scrolldx(0,-32);
m_fg_tilemap->draw(screen, bitmap, clip, 0, 0);
}
return 0;
}