jalblend.c: converted to be a device (nw)

This commit is contained in:
Ivan Vangelista 2015-03-02 18:27:30 +01:00
parent 202d316cdb
commit e166b8f2a4
8 changed files with 161 additions and 127 deletions

View File

@ -548,6 +548,8 @@ static MACHINE_CONFIG_START( argus, argus_state )
MCFG_GFXDECODE_ADD("gfxdecode", "palette", argus)
MCFG_PALETTE_ADD("palette", 896)
MCFG_DEVICE_ADD("blend", JALECO_BLEND, 0)
MCFG_VIDEO_START_OVERRIDE(argus_state,argus)
MCFG_VIDEO_RESET_OVERRIDE(argus_state,argus)
@ -592,6 +594,8 @@ static MACHINE_CONFIG_START( valtric, argus_state )
MCFG_GFXDECODE_ADD("gfxdecode", "palette", valtric)
MCFG_PALETTE_ADD("palette", 768)
MCFG_DEVICE_ADD("blend", JALECO_BLEND, 0)
MCFG_VIDEO_START_OVERRIDE(argus_state,valtric)
MCFG_VIDEO_RESET_OVERRIDE(argus_state,valtric)
@ -636,6 +640,8 @@ static MACHINE_CONFIG_START( butasan, argus_state )
MCFG_GFXDECODE_ADD("gfxdecode", "palette", butasan)
MCFG_PALETTE_ADD("palette", 768)
MCFG_DEVICE_ADD("blend", JALECO_BLEND, 0)
MCFG_VIDEO_START_OVERRIDE(argus_state,butasan)
MCFG_VIDEO_RESET_OVERRIDE(argus_state,butasan)

View File

@ -722,6 +722,8 @@ static MACHINE_CONFIG_START( psychic5, psychic5_state )
MCFG_GFXDECODE_ADD("gfxdecode", "palette", psychic5)
MCFG_PALETTE_ADD("palette", 768)
MCFG_DEVICE_ADD("blend", JALECO_BLEND, 0)
MCFG_VIDEO_START_OVERRIDE(psychic5_state,psychic5)
MCFG_VIDEO_RESET_OVERRIDE(psychic5_state,psychic5)

View File

@ -1,3 +1,5 @@
#include "video/jalblend.h"
class argus_state : public driver_device
{
public:
@ -8,6 +10,7 @@ public:
m_gfxdecode(*this, "gfxdecode"),
m_screen(*this, "screen"),
m_palette(*this, "palette"),
m_blend(*this, "blend"),
m_bg0_scrollx(*this, "bg0_scrollx"),
m_bg0_scrolly(*this, "bg0_scrolly"),
m_bg1_scrollx(*this, "bg1_scrollx"),
@ -23,6 +26,7 @@ public:
required_device<gfxdecode_device> m_gfxdecode;
required_device<screen_device> m_screen;
required_device<palette_device> m_palette;
required_device<jaleco_blend_device> m_blend;
optional_shared_ptr<UINT8> m_bg0_scrollx;
optional_shared_ptr<UINT8> m_bg0_scrolly;

View File

@ -1,4 +1,5 @@
#include "machine/bankdev.h"
#include "video/jalblend.h"
class psychic5_state : public driver_device
{
@ -10,6 +11,7 @@ public:
m_gfxdecode(*this, "gfxdecode"),
m_palette(*this, "palette"),
m_vrambank(*this, "vrambank"),
m_blend(*this, "blend"),
m_spriteram(*this, "spriteram"),
m_fg_videoram(*this, "fg_videoram"),
m_bg_videoram(*this, "bg_videoram"),
@ -25,6 +27,8 @@ public:
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
optional_device<address_map_bank_device> m_vrambank;
optional_device<jaleco_blend_device> m_blend;
required_shared_ptr<UINT8> m_spriteram;
required_shared_ptr<UINT8> m_fg_videoram;
required_shared_ptr<UINT8> m_bg_videoram;
@ -83,5 +87,5 @@ public:
void change_bg_palette(int color, int lo_offs, int hi_offs);
void set_background_palette_intensity();
void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect);
void draw_background(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
void draw_background(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); //only used by psychic5
};

View File

@ -114,7 +114,6 @@ BG0 palette intensity ( $C47F, $C4FF )
***************************************************************************/
#include "emu.h"
#include "video/jalblend.h"
#include "includes/argus.h"
@ -271,8 +270,6 @@ VIDEO_START_MEMBER(argus_state,argus)
/* dummy RAM for back ground */
m_dummy_bg0ram = auto_alloc_array(machine(), UINT8, 0x800);
jal_blend_init(machine(), 1);
save_item(NAME(m_bg_status));
save_item(NAME(m_flipscreen));
save_item(NAME(m_palette_intensity));
@ -301,8 +298,6 @@ VIDEO_START_MEMBER(argus_state,valtric)
m_screen->register_screen_bitmap(m_mosaicbitmap);
jal_blend_init(machine(), 1);
save_item(NAME(m_bg_status));
save_item(NAME(m_flipscreen));
save_item(NAME(m_palette_intensity));
@ -335,8 +330,6 @@ VIDEO_START_MEMBER(argus_state,butasan)
m_butasan_txram = &m_butasan_pagedram[1][0x000];
m_butasan_txbackram = &m_butasan_pagedram[1][0x800];
jal_blend_init(machine(), 1);
save_item(NAME(m_bg_status));
save_item(NAME(m_flipscreen));
save_item(NAME(m_palette_intensity));
@ -390,7 +383,7 @@ void argus_state::change_palette(int color, int lo_offs, int hi_offs)
{
UINT8 lo = m_paletteram[lo_offs];
UINT8 hi = m_paletteram[hi_offs];
jal_blend_set(color, hi & 0x0f);
m_blend->set(color, hi & 0x0f);
m_palette->set_pen_color(color, pal4bit(lo >> 4), pal4bit(lo), pal4bit(hi >> 4));
}
@ -426,7 +419,7 @@ void argus_state::change_bg_palette(int color, int lo_offs, int hi_offs)
rgb = rgb_t(r,g,b);
}
rgb = jal_blend_func(rgb,irgb,ix);
rgb = m_blend->func(rgb,irgb,ix);
m_palette->set_pen_color(color,rgb);
}
@ -832,7 +825,7 @@ void argus_state::argus_draw_sprites(bitmap_rgb32 &bitmap, const rectangle &clip
}
if (priority != pri)
jal_blend_drawgfx(m_palette,
m_blend->drawgfx(m_palette,
bitmap,cliprect,m_gfxdecode->gfx(0),
tile,
color,
@ -956,7 +949,7 @@ void argus_state::valtric_draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cl
flipy = !flipy;
}
jal_blend_drawgfx(m_palette,
m_blend->drawgfx(m_palette,
bitmap,cliprect,m_gfxdecode->gfx(0),
tile,
color,
@ -1004,7 +997,7 @@ void argus_state::butasan_draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cl
if ((offs >= 0x100 && offs <= 0x2ff) || (offs >= 0x400 && offs <= 0x57f))
{
jal_blend_drawgfx(m_palette,
m_blend->drawgfx(m_palette,
bitmap,cliprect,m_gfxdecode->gfx(0),
tile,
color,
@ -1018,7 +1011,7 @@ void argus_state::butasan_draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cl
{
td = (fx) ? (1 - i) : i;
jal_blend_drawgfx(m_palette,
m_blend->drawgfx(m_palette,
bitmap,cliprect,m_gfxdecode->gfx(0),
tile + td,
color,
@ -1038,7 +1031,7 @@ void argus_state::butasan_draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cl
else
td = (fx) ? (i * 2) + 1 - j : i * 2 + j;
jal_blend_drawgfx(m_palette,
m_blend->drawgfx(m_palette,
bitmap,cliprect,m_gfxdecode->gfx(0),
tile + td,
color,
@ -1059,7 +1052,7 @@ void argus_state::butasan_draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cl
else
td = (fx) ? (i * 4) + 3 - j : i * 4 + j;
jal_blend_drawgfx(m_palette,
m_blend->drawgfx(m_palette,
bitmap,cliprect,m_gfxdecode->gfx(0),
tile + td,
color,

View File

@ -14,33 +14,43 @@
#include "emu.h"
#include "jalblend.h"
/* each palette entry contains a fourth 'alpha' value */
static UINT8 *jal_blend_table;
/*****************************************************************************
DEVICE INTERFACE
*****************************************************************************/
static void jal_blend_reset(running_machine &machine)
const device_type JALECO_BLEND = &device_creator<jaleco_blend_device>;
jaleco_blend_device::jaleco_blend_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, JALECO_BLEND, "Jaleco Blending Device", tag, owner, clock, "jaleco_blend", __FILE__),
m_table(NULL)
{
memset(jal_blend_table, 0, 0xc00);
}
void jal_blend_init(running_machine &machine, int enable)
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void jaleco_blend_device::device_start()
{
if (enable)
{
jal_blend_table = auto_alloc_array_clear(machine, UINT8, 0xc00);
machine.add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(jal_blend_reset), &machine));
machine.save().save_pointer(NAME(jal_blend_table), 0xc00);
}
else
{
jal_blend_table = NULL;
}
m_table = auto_alloc_array_clear(machine(), UINT8, 0xc00);
save_pointer(NAME(m_table), 0xc00);
}
void jal_blend_set(int color, UINT8 val)
//-------------------------------------------------
// device_reset - device-specific startup
//-------------------------------------------------
void jaleco_blend_device::device_reset()
{
if (jal_blend_table) jal_blend_table[color] = val;
memset(m_table, 0, 0xc00);
}
void jaleco_blend_device::set(int color, UINT8 val)
{
m_table[color] = val;
}
/*
@ -56,7 +66,7 @@ void jal_blend_set(int color, UINT8 val)
*/
/* basically an add/subtract function with clamping */
rgb_t jal_blend_func(rgb_t dest, rgb_t addMe, UINT8 alpha)
rgb_t jaleco_blend_device::func(rgb_t dest, rgb_t addMe, UINT8 alpha)
{
int r, g, b;
int ir, ig, ib;
@ -86,100 +96,91 @@ rgb_t jal_blend_func(rgb_t dest, rgb_t addMe, UINT8 alpha)
}
template<class _BitmapClass>
void jal_blend_drawgfx_common(palette_device &palette,_BitmapClass &dest_bmp,const rectangle &clip,gfx_element *gfx,
void jaleco_blend_device::drawgfx_common(palette_device &palette,_BitmapClass &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color)
{
if (jal_blend_table == NULL)
{
gfx->transpen(dest_bmp,clip,code,color,flipx,flipy,offsx,offsy,transparent_color);
return;
/* Start drawing */
const pen_t *pal = &palette.pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
const UINT8 *alpha = &m_table[gfx->granularity() * (color % gfx->colors())];
const UINT8 *source_base = gfx->get_data(code % gfx->elements());
int x_index_base, y_index, sx, sy, ex, ey;
int xinc, yinc;
xinc = flipx ? -1 : 1;
yinc = flipy ? -1 : 1;
x_index_base = flipx ? gfx->width()-1 : 0;
y_index = flipy ? gfx->height()-1 : 0;
// start coordinates
sx = offsx;
sy = offsy;
// end coordinates
ex = sx + gfx->width();
ey = sy + gfx->height();
if (sx < clip.min_x)
{ // clip left
int pixels = clip.min_x-sx;
sx += pixels;
x_index_base += xinc*pixels;
}
if (sy < clip.min_y)
{ // clip top
int pixels = clip.min_y-sy;
sy += pixels;
y_index += yinc*pixels;
}
// NS 980211 - fixed incorrect clipping
if (ex > clip.max_x+1)
{ // clip right
ex = clip.max_x+1;
}
if (ey > clip.max_y+1)
{ // clip bottom
ey = clip.max_y+1;
}
/* Start drawing */
if (gfx)
{
const pen_t *pal = &palette.pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
const UINT8 *alpha = &jal_blend_table[gfx->granularity() * (color % gfx->colors())];
const UINT8 *source_base = gfx->get_data(code % gfx->elements());
int x_index_base, y_index, sx, sy, ex, ey;
int xinc, yinc;
if (ex > sx)
{ // skip if inner loop doesn't draw anything
int x, y;
xinc = flipx ? -1 : 1;
yinc = flipy ? -1 : 1;
x_index_base = flipx ? gfx->width()-1 : 0;
y_index = flipy ? gfx->height()-1 : 0;
// start coordinates
sx = offsx;
sy = offsy;
// end coordinates
ex = sx + gfx->width();
ey = sy + gfx->height();
if (sx < clip.min_x)
{ // clip left
int pixels = clip.min_x-sx;
sx += pixels;
x_index_base += xinc*pixels;
}
if (sy < clip.min_y)
{ // clip top
int pixels = clip.min_y-sy;
sy += pixels;
y_index += yinc*pixels;
}
// NS 980211 - fixed incorrect clipping
if (ex > clip.max_x+1)
{ // clip right
ex = clip.max_x+1;
}
if (ey > clip.max_y+1)
{ // clip bottom
ey = clip.max_y+1;
}
if (ex > sx)
{ // skip if inner loop doesn't draw anything
int x, y;
// taken from case 7: TRANSPARENCY_ALPHARANGE
for (y = sy; y < ey; y++)
// taken from case 7: TRANSPARENCY_ALPHARANGE
for (y = sy; y < ey; y++)
{
const UINT8 *source = source_base + y_index*gfx->rowbytes();
typename _BitmapClass::pixel_t *dest = &dest_bmp.pix(y);
int x_index = x_index_base;
for (x = sx; x < ex; x++)
{
const UINT8 *source = source_base + y_index*gfx->rowbytes();
typename _BitmapClass::pixel_t *dest = &dest_bmp.pix(y);
int x_index = x_index_base;
for (x = sx; x < ex; x++)
int c = source[x_index];
if (c != transparent_color)
{
int c = source[x_index];
if (c != transparent_color)
if (alpha[c] & 8)
{
if (alpha[c] & 8)
{
// Comp with clamp
dest[x] = jal_blend_func(dest[x], pal[c], alpha[c]);
}
else
{
// Skip the costly alpha step altogether
dest[x] = pal[c];
}
// Comp with clamp
dest[x] = jaleco_blend_device::func(dest[x], pal[c], alpha[c]);
}
else
{
// Skip the costly alpha step altogether
dest[x] = pal[c];
}
x_index += xinc;
}
y_index += yinc;
x_index += xinc;
}
y_index += yinc;
}
}
}
void jal_blend_drawgfx(palette_device &palette,bitmap_ind16 &dest_bmp,const rectangle &clip,gfx_element *gfx,
void jaleco_blend_device::drawgfx(palette_device &palette,bitmap_ind16 &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color)
{ jal_blend_drawgfx_common(palette,dest_bmp, clip, gfx, code, color, flipx, flipy, offsx, offsy, transparent_color); }
void jal_blend_drawgfx(palette_device &palette,bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
{ jaleco_blend_device::drawgfx_common(palette,dest_bmp, clip, gfx, code, color, flipx, flipy, offsx, offsy, transparent_color); }
void jaleco_blend_device::drawgfx(palette_device &palette,bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color)
{ jal_blend_drawgfx_common(palette,dest_bmp, clip, gfx, code, color, flipx, flipy, offsx, offsy, transparent_color); }
{ jaleco_blend_device::drawgfx_common(palette,dest_bmp, clip, gfx, code, color, flipx, flipy, offsx, offsy, transparent_color); }

View File

@ -1,10 +1,31 @@
void jal_blend_init(running_machine &machine, int enable);
void jal_blend_set(int color, UINT8 val);
class jaleco_blend_device : public device_t
{
public:
jaleco_blend_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~jaleco_blend_device() {}
void set(int color, UINT8 val);
rgb_t func(rgb_t dest, rgb_t addMe, UINT8 alpha);
void drawgfx(palette_device &palette,bitmap_ind16 &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color);
void drawgfx(palette_device &palette,bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color);
rgb_t jal_blend_func(rgb_t dest, rgb_t addMe, UINT8 alpha);
void jal_blend_drawgfx(palette_device &palette,bitmap_ind16 &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color);
void jal_blend_drawgfx(palette_device &palette,bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
protected:
// device-level overrides
virtual void device_start();
virtual void device_reset();
private:
/* each palette entry contains a fourth 'alpha' value */
UINT8 *m_table;
template<class _BitmapClass>
void drawgfx_common(palette_device &palette,_BitmapClass &dest_bmp,const rectangle &clip,gfx_element *gfx,
UINT32 code,UINT32 color,int flipx,int flipy,int offsx,int offsy,
int transparent_color);
};
extern const device_type JALECO_BLEND;

View File

@ -7,7 +7,6 @@
***************************************************************************/
#include "emu.h"
#include "video/jalblend.h"
#include "includes/psychic5.h"
@ -25,8 +24,10 @@ void psychic5_state::change_palette(int offset, UINT8* palram, int palbase)
UINT8 hi = palram[(offset) | 1];
int color = offset >> 1;
jal_blend_set(palbase + color, hi & 0x0f);
if (m_blend)
m_blend->set(palbase + color, hi & 0x0f);
m_palette->set_pen_color(palbase + color, pal4bit(lo >> 4), pal4bit(lo), pal4bit(hi >> 4));
}
@ -56,7 +57,7 @@ void psychic5_state::change_bg_palette(int color, int lo_offs, int hi_offs)
{
UINT8 val = (r + g + b) / 3; /* Grey */
/* Just leave plain grey */
m_palette->set_pen_color(color,jal_blend_func(rgb_t(val,val,val),irgb,ix));
m_palette->set_pen_color(color,m_blend->func(rgb_t(val,val,val),irgb,ix));
}
else
{
@ -64,7 +65,7 @@ void psychic5_state::change_bg_palette(int color, int lo_offs, int hi_offs)
if (!(m_title_screen & 1))
{
/* Leave the world as-is */
m_palette->set_pen_color(color,jal_blend_func(rgb_t(r,g,b),irgb,ix));
m_palette->set_pen_color(color,m_blend->func(rgb_t(r,g,b),irgb,ix));
}
}
}
@ -191,7 +192,6 @@ VIDEO_START_MEMBER(psychic5_state,psychic5)
m_bg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(psychic5_state::get_bg_tile_info),this), TILEMAP_SCAN_COLS, 16, 16, 64, 32);
m_fg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(psychic5_state::get_fg_tile_info),this), TILEMAP_SCAN_COLS, 8, 8, 32, 32);
m_fg_tilemap->set_transparent_pen(15);
jal_blend_init(machine(), 1);
save_item(NAME(m_title_screen));
@ -204,7 +204,6 @@ VIDEO_START_MEMBER(psychic5_state,bombsa)
m_bg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(psychic5_state::get_bg_tile_info),this), TILEMAP_SCAN_COLS, 16, 16, 128, 32);
m_fg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(psychic5_state::get_fg_tile_info),this), TILEMAP_SCAN_COLS, 8, 8, 32, 32);
m_fg_tilemap->set_transparent_pen(15);
jal_blend_init(machine(), 0);
save_item(NAME(m_bombsa_unknown));
}
@ -223,7 +222,11 @@ VIDEO_RESET_MEMBER(psychic5_state,psychic5)
Screen refresh
***************************************************************************/
#define DRAW_SPRITE(code, sx, sy) jal_blend_drawgfx(m_palette, bitmap, cliprect, m_gfxdecode->gfx(0), code, color, flipx, flipy, sx, sy, 15);
#define DRAW_SPRITE(code, sx, sy) \
if (m_blend) \
m_blend->drawgfx(m_palette, bitmap, cliprect, m_gfxdecode->gfx(0), code, color, flipx, flipy, sx, sy, 15); \
else \
m_gfxdecode->gfx(0)->transpen(bitmap, cliprect, code, color, flipx, flipy, sx, sy, 15);
void psychic5_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect)
{