prepare SunPlus rendering code for sharing between SPG2xx and GPL16250 (nw) (#6780)

This commit is contained in:
David Haywood 2020-06-02 19:10:17 +01:00 committed by GitHub
parent bdf4b325bd
commit 4f7c1a03ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 695 additions and 602 deletions

View File

@ -2902,6 +2902,8 @@ if (MACHINES["SPG2XX"]~=null) then
MAME_DIR .. "src/devices/machine/generalplus_gpl16250soc.h",
MAME_DIR .. "src/devices/machine/generalplus_gpl16250soc_video.cpp",
MAME_DIR .. "src/devices/machine/generalplus_gpl16250soc_video.h",
MAME_DIR .. "src/devices/machine/spg_renderer.cpp",
MAME_DIR .. "src/devices/machine/spg_renderer.h",
}
end

View File

@ -133,7 +133,8 @@ gcm394_base_video_device::gcm394_base_video_device(const machine_config &mconfig
// m_pal_sprites(0x100),
// m_pal_back(0x000),
m_alt_extrasprite_hack(0),
m_alt_tile_addressing(0)
m_alt_tile_addressing(0),
m_renderer(*this, "renderer")
{
}
@ -1801,6 +1802,7 @@ void gcm394_base_video_device::device_add_mconfig(machine_config &config)
PALETTE(config, m_palette).set_format(palette_device::xRGB_555, 256*0x10);
GFXDECODE(config, m_gfxdecode, m_palette, gfx);
SPG_RENDERER(config, m_renderer, 0);
}

View File

@ -11,6 +11,7 @@
#pragma once
#include "spg_renderer.h"
#include "cpu/unsp/unsp.h"
#include "screen.h"
#include "emupal.h"
@ -261,6 +262,7 @@ protected:
int m_alt_extrasprite_hack;
int m_alt_tile_addressing;
required_device<spg_renderer_device> m_renderer;
};
class gcm394_video_device : public gcm394_base_video_device

View File

@ -37,7 +37,8 @@ spg2xx_video_device::spg2xx_video_device(const machine_config &mconfig, device_t
m_hcompram(*this, "hcompram"),
m_paletteram(*this, "paletteram"),
m_spriteram(*this, "spriteram"),
m_video_irq_cb(*this)
m_video_irq_cb(*this),
m_renderer(*this, "renderer")
{
}
@ -48,17 +49,6 @@ spg24x_video_device::spg24x_video_device(const machine_config &mconfig, const ch
void spg2xx_video_device::device_start()
{
for (uint8_t i = 0; i < 32; i++)
{
m_rgb5_to_rgb8[i] = (i << 3) | (i >> 2);
}
for (uint16_t i = 0; i < 0x8000; i++)
{
m_rgb555_to_rgb888[i] = (m_rgb5_to_rgb8[(i >> 10) & 0x1f] << 16) |
(m_rgb5_to_rgb8[(i >> 5) & 0x1f] << 8) |
(m_rgb5_to_rgb8[(i >> 0) & 0x1f] << 0);
}
m_guny_in.resolve_safe(0);
m_gunx_in.resolve_safe(0);
@ -67,12 +57,7 @@ void spg2xx_video_device::device_start()
save_item(NAME(m_video_regs));
save_item(NAME(m_ycmp_table));
m_sprlimit_read_cb.resolve_safe(0);
m_video_irq_cb.resolve();
}
@ -82,547 +67,18 @@ void spg2xx_video_device::device_reset()
m_video_regs[0x36] = 0xffff;
m_video_regs[0x37] = 0xffff;
m_video_regs[0x3c] = 0x0020;
m_video_regs[0x42] = 0x0001;
for (int i = 0; i < 480; i++)
{
m_ycmp_table[i] = 0xffffffff;
}
//m_video_regs[0x3c] = 0x0020;
//m_video_regs[0x42] = 0x0001;
}
/*************************
* Video Hardware *
*************************/
void spg2xx_video_device::draw_linemap(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* regs)
{
if ((scanline < 0) || (scanline >= 240))
return;
address_space &space = m_cpu->space(AS_PROGRAM);
uint32_t tilemap = regs[4];
uint32_t palette_map = regs[5];
//printf("draw bitmap bases %04x %04x\n", tilemap, palette_map);
//uint32_t xscroll = regs[0];
uint32_t yscroll = regs[1];
int realline = (scanline + yscroll) & 0xff;
uint16_t tile = space.read_word(tilemap + realline);
uint16_t palette = 0;
//if (!tile)
// continue;
palette = space.read_word(palette_map + realline / 2);
if (scanline & 1)
palette >>= 8;
else
palette &= 0x00ff;
//const int linewidth = 320 / 2;
int sourcebase = tile | (palette << 16);
uint32_t ctrl = regs[3];
if (ctrl & 0x80) // HiColor mode (rad_digi)
{
for (int i = 0; i < 320; i++)
{
const uint16_t data = space.read_word(sourcebase + i);
if (!(data & 0x8000))
{
dst[i] = m_rgb555_to_rgb888[data & 0x7fff];
}
}
}
else
{
for (int i = 0; i < 320 / 2; i++)
{
uint8_t palette_entry;
uint16_t color;
const uint16_t data = space.read_word(sourcebase + i);
palette_entry = (data & 0x00ff);
color = m_paletteram[palette_entry];
if (!(color & 0x8000))
{
dst[(i * 2) + 0] = m_rgb555_to_rgb888[color & 0x7fff];
}
palette_entry = (data & 0xff00) >> 8;
color = m_paletteram[palette_entry];
if (!(color & 0x8000))
{
dst[(i * 2) + 1] = m_rgb555_to_rgb888[color & 0x7fff];
}
}
}
}
bool spg2xx_video_device::get_tile_info(uint32_t tilemap_rambase, uint32_t palettemap_rambase, uint32_t x0, uint32_t y0, uint32_t tile_count_x, uint32_t ctrl, uint32_t attr, uint16_t& tile, bool& blend, bool& flip_x, bool& flip_y, uint32_t& palette_offset)
{
address_space &space = m_cpu->space(AS_PROGRAM);
uint32_t tile_address = x0 + (tile_count_x * y0);
tile = (ctrl & 0x0004) ? space.read_word(tilemap_rambase) : space.read_word(tilemap_rambase + tile_address);
if (!tile)
return false;
uint32_t tileattr = attr;
uint32_t tilectrl = ctrl;
if ((ctrl & 2) == 0)
{ // -(1) bld(1) flip(2) pal(4)
uint16_t palette = (ctrl & 0x0004) ? space.read_word(palettemap_rambase) : space.read_word(palettemap_rambase + tile_address / 2);
if (x0 & 1)
palette >>= 8;
else
palette &= 0x00ff;
tileattr &= ~0x000c;
tileattr |= (palette >> 2) & 0x000c; // flip
tileattr &= ~0x0f00;
tileattr |= (palette << 8) & 0x0f00; // palette
tilectrl &= ~0x0100;
tilectrl |= (palette << 2) & 0x0100; // blend
}
blend = (tileattr & 0x4000 || tilectrl & 0x0100);
flip_x = (tileattr & 0x0004);
flip_y= (tileattr & 0x0008);
palette_offset = (tileattr & 0x0f00) >> 4;
return true;
}
// 3 is good
// this builds up a line table for the vcmp effect, this is not correct when step is used
void spg2xx_video_device::update_vcmp_table()
{
int currentline = 0;
int step = m_video_regs[0x1e] & 0xff;
if (step & 0x80)
step = step - 0x100;
int current_inc_value = (m_video_regs[0x1c]<<4);
int counter = 0;
for (int i = 0; i < 480; i++)
{
if (i < m_video_regs[0x1d])
{
m_ycmp_table[i] = 0xffffffff;
}
else
{
if ((currentline >= 0) && (currentline < 240))
{
m_ycmp_table[i] = currentline;
}
counter += current_inc_value;
while (counter >= (0x20<<4))
{
currentline++;
current_inc_value += step;
counter -= (0x20<<4);
}
}
}
}
// Perform a lerp between a and b
inline uint8_t spg2xx_video_device::mix_channel(uint8_t bottom, uint8_t top)
{
uint8_t alpha = (m_video_regs[0x2a] & 3) << 6;
return ((256 - alpha) * bottom + alpha * top) >> 8;
}
template<spg2xx_video_device::blend_enable_t Blend, spg2xx_video_device::flipx_t FlipX>
void spg2xx_video_device::draw_tilestrip(const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint16_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile)
{
address_space &space = m_cpu->space(AS_PROGRAM);
const uint32_t yflipmask = flip_y ? tile_h - 1 : 0;
uint32_t m = tilegfxdata_addr + words_per_tile * tile + bits_per_row * (tile_scanline ^ yflipmask);
uint32_t bits = 0;
uint32_t nbits = 0;
for (int32_t x = FlipX ? (tile_w - 1) : 0; FlipX ? x >= 0 : x < tile_w; FlipX ? x-- : x++)
{
int realdrawpos = (drawx + x) & 0x1ff;
bits <<= nc_bpp;
if (nbits < nc_bpp)
{
uint16_t b = space.read_word(m++ & 0x3fffff);
b = (b << 8) | (b >> 8);
bits |= b << (nc_bpp - nbits);
nbits += 16;
}
nbits -= nc_bpp;
uint32_t pal = palette_offset + (bits >> 16);
bits &= 0xffff;
if (realdrawpos >= 0 && realdrawpos < 320)
{
uint16_t rgb = m_paletteram[pal];
if (!(rgb & 0x8000))
{
if (Blend)
{
dst[realdrawpos] = (mix_channel((uint8_t)(dst[realdrawpos] >> 16), m_rgb5_to_rgb8[(rgb >> 10) & 0x1f]) << 16) |
(mix_channel((uint8_t)(dst[realdrawpos] >> 8), m_rgb5_to_rgb8[(rgb >> 5) & 0x1f]) << 8) |
(mix_channel((uint8_t)(dst[realdrawpos] >> 0), m_rgb5_to_rgb8[rgb & 0x1f]));
}
else
{
dst[realdrawpos] = m_rgb555_to_rgb888[rgb];
}
}
}
}
}
void spg2xx_video_device::draw_page(const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t *regs)
{
const uint32_t attr = regs[2];
const uint32_t ctrl = regs[3];
if (!(ctrl & 0x0008))
{
return;
}
if (((attr & 0x3000) >> 12) != priority)
{
return;
}
if (ctrl & 0x0001) // Bitmap / Linemap mode! (basically screen width tile mode)
{
draw_linemap(cliprect, dst, scanline, priority, tilegfxdata_addr, regs);
return;
}
uint32_t logical_scanline = scanline;
if (ctrl & 0x0040) // 'vertical compression feature' (later models only?)
{
if (m_video_regs[0x1e] != 0x0000)
popmessage("vertical compression mode with non-0 step amount %04x offset %04x step %04x\n", m_video_regs[0x1c], m_video_regs[0x1d], m_video_regs[0x1e]);
logical_scanline = m_ycmp_table[scanline];
if (logical_scanline == 0xffffffff)
return;
//logical_scanline >>= 5;
}
const uint32_t xscroll = regs[0];
const uint32_t yscroll = regs[1];
const uint32_t tilemap_rambase = regs[4];
const uint32_t palettemap_rambase = regs[5];
const int tile_width = (attr & 0x0030) >> 4;
const uint32_t tile_h = 8 << ((attr & 0x00c0) >> 6);
const uint32_t tile_w = 8 << (tile_width);
const uint32_t tile_count_x = 512 / tile_w; // all tilemaps are 512 pixels wide
const uint32_t bitmap_y = (logical_scanline + yscroll) & 0xff; // all tilemaps are 256 pixels high
const uint32_t y0 = bitmap_y / tile_h;
const uint32_t tile_scanline = bitmap_y % tile_h;
const uint8_t bpp = attr & 0x0003;
const uint32_t nc_bpp = ((bpp)+1) << 1;
const uint32_t bits_per_row = nc_bpp * tile_w / 16;
const uint32_t words_per_tile = bits_per_row * tile_h;
const bool row_scroll = (ctrl & 0x0010);
int realxscroll = xscroll;
if (row_scroll)
{
// Tennis in My Wireless Sports confirms the need to add the scroll value here rather than rowscroll being screen-aligned
realxscroll += (int16_t)m_scrollram[(logical_scanline+yscroll) & 0xff];
}
for (uint32_t x0 = 0; x0 < (320+tile_w)/tile_w; x0++)
{
bool blend, flip_x, flip_y;
uint16_t tile;
uint32_t palette_offset;
if (!get_tile_info(tilemap_rambase, palettemap_rambase, (x0 + (realxscroll >> (tile_width+3))) & (tile_count_x-1) , y0, tile_count_x, ctrl, attr, tile, blend, flip_x, flip_y, palette_offset))
continue;
palette_offset >>= nc_bpp;
palette_offset <<= nc_bpp;
int drawx = (x0 * tile_w);
drawx = drawx - (realxscroll & (tile_w-1));
if (blend)
{
if (flip_x)
{
draw_tilestrip<BlendOn, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOn, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
else
{
if (flip_x)
{
draw_tilestrip<BlendOff, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOff, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
}
}
void spg2xx_video_device::draw_sprite(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t base_addr)
{
uint32_t tilegfxdata_addr = 0x40 * m_video_regs[0x22];
uint16_t tile = m_spriteram[base_addr + 0];
int16_t x = m_spriteram[base_addr + 1];
int16_t y = m_spriteram[base_addr + 2];
uint16_t attr = m_spriteram[base_addr + 3];
if (!tile)
{
return;
}
if (((attr & 0x3000) >> 12) != priority)
{
return;
}
const uint32_t tile_h = 8 << ((attr & 0x00c0) >> 6);
const uint32_t tile_w = 8 << ((attr & 0x0030) >> 4);
if (!(m_video_regs[0x42] & 0x0002))
{
x = (160 + x) - tile_w / 2;
y = (120 - y) - (tile_h / 2) + 8;
}
x &= 0x01ff;
y &= 0x01ff;
int firstline = y;
int lastline = y + (tile_h - 1);
lastline &= 0x1ff;
bool blend = (attr & 0x4000);
bool flip_x = (attr & 0x0004);
const uint8_t bpp = attr & 0x0003;
const uint32_t nc_bpp = ((bpp)+1) << 1;
const uint32_t bits_per_row = nc_bpp * tile_w / 16;
const uint32_t words_per_tile = bits_per_row * tile_h;
bool flip_y = (attr & 0x0008);
uint32_t palette_offset = (attr & 0x0f00) >> 4;
// the Circuit Racing game in PDC100 needs this or some graphics have bad colours at the edges when turning as it leaves stray lower bits set
palette_offset >>= nc_bpp;
palette_offset <<= nc_bpp;
if (firstline < lastline)
{
int scanx = scanline - firstline;
if ((scanx >= 0) && (scanline <= lastline))
{
if (blend)
{
if (flip_x)
{
draw_tilestrip<BlendOn, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOn, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
else
{
if (flip_x)
{
draw_tilestrip<BlendOff, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOff, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
}
}
else
{
// clipped from top
int tempfirstline = firstline - 0x200;
int templastline = lastline;
int scanx = scanline - tempfirstline;
if ((scanx >= 0) && (scanline <= templastline))
{
if (blend)
{
if (flip_x)
{
draw_tilestrip<BlendOn, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOn, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
else
{
if (flip_x)
{
draw_tilestrip<BlendOff, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOff, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
}
// clipped against the bottom
tempfirstline = firstline;
templastline = lastline + 0x200;
scanx = scanline - tempfirstline;
if ((scanx >= 0) && (scanline <= templastline))
{
if (blend)
{
if (flip_x)
{
draw_tilestrip<BlendOn, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOn, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
else
{
if (flip_x)
{
draw_tilestrip<BlendOff, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
else
{
draw_tilestrip<BlendOff, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile);
}
}
}
}
}
void spg2xx_video_device::draw_sprites(const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority)
{
if (!(m_video_regs[0x42] & 0x0001))
{
return;
}
for (uint32_t n = 0; n < m_sprlimit_read_cb(); n++)
{
draw_sprite(cliprect, dst, scanline, priority, 4 * n);
}
}
void spg2xx_video_device::apply_saturation_and_fade(bitmap_rgb32& bitmap, const rectangle& cliprect, int scanline)
{
static const float s_u8_to_float = 1.0f / 255.0f;
static const float s_gray_r = 0.299f;
static const float s_gray_g = 0.587f;
static const float s_gray_b = 0.114f;
const float sat_adjust = (0xff - (m_video_regs[0x3c] & 0x00ff)) / (float)(0xff - 0x20);
const uint16_t fade_offset = m_video_regs[0x30];
uint32_t* src = &bitmap.pix32(scanline, cliprect.min_x);
for (int x = cliprect.min_x; x <= cliprect.max_x; x++)
{
if ((m_video_regs[0x3c] & 0x00ff) != 0x0020) // apply saturation
{
const uint32_t src_rgb = *src;
const float src_r = (uint8_t)(src_rgb >> 16) * s_u8_to_float;
const float src_g = (uint8_t)(src_rgb >> 8) * s_u8_to_float;
const float src_b = (uint8_t)(src_rgb >> 0) * s_u8_to_float;
const float luma = src_r * s_gray_r + src_g * s_gray_g + src_b * s_gray_b;
const float adjusted_r = luma + (src_r - luma) * sat_adjust;
const float adjusted_g = luma + (src_g - luma) * sat_adjust;
const float adjusted_b = luma + (src_b - luma) * sat_adjust;
const int integer_r = (int)floor(adjusted_r * 255.0f);
const int integer_g = (int)floor(adjusted_g * 255.0f);
const int integer_b = (int)floor(adjusted_b * 255.0f);
*src = (integer_r > 255 ? 0xff0000 : (integer_r < 0 ? 0 : ((uint8_t)integer_r << 16))) |
(integer_g > 255 ? 0x00ff00 : (integer_g < 0 ? 0 : ((uint8_t)integer_g << 8))) |
(integer_b > 255 ? 0x0000ff : (integer_b < 0 ? 0 : (uint8_t)integer_b));
}
if (fade_offset != 0) // apply fade
{
const uint32_t src_rgb = *src;
const uint8_t src_r = (src_rgb >> 16) & 0xff;
const uint8_t src_g = (src_rgb >> 8) & 0xff;
const uint8_t src_b = (src_rgb >> 0) & 0xff;
const uint8_t r = src_r - fade_offset;
const uint8_t g = src_g - fade_offset;
const uint8_t b = src_b - fade_offset;
*src = (r > src_r ? 0 : (r << 16)) |
(g > src_g ? 0 : (g << 8)) |
(b > src_b ? 0 : (b << 0));
}
src++;
}
}
uint32_t spg2xx_video_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
address_space &mem = m_cpu->space(AS_PROGRAM);
if (0)
{
uint16_t attr1 = m_video_regs[0x12];
@ -647,8 +103,10 @@ uint32_t spg2xx_video_device::screen_update(screen_device &screen, bitmap_rgb32
const uint32_t page1_addr = 0x40 * m_video_regs[0x20];
const uint32_t page2_addr = 0x40 * m_video_regs[0x21];
uint16_t *page1_regs = m_video_regs + 0x10;
uint16_t *page2_regs = m_video_regs + 0x16;
uint16_t *page1_scroll = m_video_regs + 0x10;
uint16_t *page2_scroll = m_video_regs + 0x16;
uint16_t *page1_regs = m_video_regs + 0x12;
uint16_t *page2_regs = m_video_regs + 0x18;
bitmap.fill(0, cliprect);
@ -658,17 +116,18 @@ uint32_t spg2xx_video_device::screen_update(screen_device &screen, bitmap_rgb32
for (int i = 0; i < 4; i++)
{
draw_page(cliprect, dst, scanline, i, page1_addr, page1_regs);
draw_page(cliprect, dst, scanline, i, page2_addr, page2_regs);
draw_sprites(cliprect, dst, scanline, i);
m_renderer->draw_page(cliprect, dst, scanline, i, page1_addr, page1_scroll, page1_regs, mem, m_paletteram, m_scrollram);
m_renderer->draw_page(cliprect, dst, scanline, i, page2_addr, page2_scroll, page2_regs, mem, m_paletteram, m_scrollram);
m_renderer->draw_sprites(cliprect, dst, scanline, i, mem, m_paletteram, m_spriteram, m_sprlimit_read_cb());
}
apply_saturation_and_fade(bitmap, cliprect, scanline);
m_renderer->apply_saturation_and_fade(bitmap, cliprect, scanline);
}
return 0;
}
void spg2xx_video_device::do_sprite_dma(uint32_t len)
{
address_space &mem = m_cpu->space(AS_PROGRAM);
@ -697,18 +156,46 @@ READ16_MEMBER(spg2xx_video_device::video_r)
switch (offset)
{
case 0x10: // Page 1 X scroll
LOGMASKED(LOG_PPU_WRITES, "video_r: Page 1 X Scroll\n");
LOGMASKED(LOG_PPU_READS, "video_r: Page 1 X Scroll\n");
return m_video_regs[offset];
case 0x11: // Page 1 Y scroll
LOGMASKED(LOG_PPU_WRITES, "video_r: Page 1 Y Scroll\n");
LOGMASKED(LOG_PPU_READS, "video_r: Page 1 Y Scroll\n");
return m_video_regs[offset];
case 0x1c: // vertical compression, amount, 0x20 = no scale? (not on spg288?)
LOGMASKED(LOG_PPU_READS, "video_r: Ycmp_Value\n");
return m_renderer->get_video_reg_1c();
case 0x1d: // (not on spg288?)
LOGMASKED(LOG_PPU_READS, "video_r: Ycmp_Y_Offset\n");
return m_renderer->get_video_reg_1d();
case 0x1e: // (not on spg288?)
LOGMASKED(LOG_PPU_READS, "video_r: Ycmp_Step\n");
return m_renderer->get_video_reg_1e();
case 0x22: // Sprite Segment Address
LOGMASKED(LOG_PPU_READS, "video_r: Sprite Segment Address\n");
return m_renderer->get_video_reg_22();
case 0x2a: // Blend Level Control
LOGMASKED(LOG_PPU_READS, "video_r: Blend Level Control\n");
return m_renderer->get_video_reg_2a();
case 0x30: // Fade Effect Control
LOGMASKED(LOG_PPU_READS, "video_r: Fade Effect Control\n");
return m_renderer->get_video_reg_30();
break;
case 0x38: // Current Line
LOGMASKED(LOG_VLINES, "video_r: Current Line: %04x\n", m_screen->vpos());
return m_screen->vpos();
case 0x3c: // TV Control 1
LOGMASKED(LOG_PPU_READS, "video_r: TV Control 1\n");
return m_renderer->get_video_reg_3c();
case 0x3e: // Light Pen Y Position
LOGMASKED(LOG_PPU_READS, "video_r: Light Pen Y / Lightgun Y\n");
return m_guny_in();
@ -717,6 +204,10 @@ READ16_MEMBER(spg2xx_video_device::video_r)
LOGMASKED(LOG_PPU_READS, "video_r: Light Pen X / Lightgun X\n");
return m_gunx_in();
case 0x42: // Sprite Control
LOGMASKED(LOG_PPU_READS, "video_w: Sprite Control\n");
return m_renderer->get_video_reg_42();
case 0x62: // Video IRQ Enable
LOGMASKED(LOG_IRQS, "video_r: Video IRQ Enable: %04x\n", VIDEO_IRQ_ENABLE);
return VIDEO_IRQ_ENABLE;
@ -815,19 +306,19 @@ WRITE16_MEMBER(spg2xx_video_device::video_w)
case 0x1c: // vertical compression, amount, 0x20 = no scale? (not on spg288?)
LOGMASKED(LOG_PPU_WRITES, "video_w: Ycmp_Value = %04x\n", data);
m_video_regs[offset] = data;
update_vcmp_table();
m_renderer->set_video_reg_1c(data);
break;
case 0x1d: // (not on spg288?)
LOGMASKED(LOG_PPU_WRITES, "video_w: Ycmp_Y_Offset = %04x\n", data);
m_video_regs[offset] = data;
update_vcmp_table();
m_renderer->set_video_reg_1d(data);
break;
case 0x1e: // (not on spg288?)
LOGMASKED(LOG_PPU_WRITES, "video_w: Ycmp_Step = %04x\n", data);
m_video_regs[offset] = data;
update_vcmp_table();
m_renderer->set_video_reg_1e(data);
break;
case 0x20: // Page 1 Segment Address
@ -843,16 +334,19 @@ WRITE16_MEMBER(spg2xx_video_device::video_w)
case 0x22: // Sprite Segment Address
LOGMASKED(LOG_PPU_WRITES, "video_w: Sprite Segment Address = %04x\n", data);
m_video_regs[offset] = data;
m_renderer->set_video_reg_22(data);
break;
case 0x2a: // Blend Level Control
LOGMASKED(LOG_PPU_WRITES, "video_w: Blend Level Control = %04x\n", data & 0x0003);
m_video_regs[offset] = data & 0x0003;
m_renderer->set_video_reg_2a(data);
break;
case 0x30: // Fade Effect Control
LOGMASKED(LOG_PPU_WRITES, "video_w: Fade Effect Control = %04x\n", data & 0x00ff);
m_video_regs[offset] = data & 0x00ff;
m_renderer->set_video_reg_30(data);
break;
case 0x36: // IRQ pos V
@ -873,6 +367,7 @@ WRITE16_MEMBER(spg2xx_video_device::video_w)
case 0x3c: // TV Control 1
LOGMASKED(LOG_PPU_WRITES, "video_w: TV Control 1 = %04x (Hue:%02x, Saturation:%02x)\n", data, data >> 8, data & 0x00ff);
m_video_regs[offset] = data;
m_renderer->set_video_reg_3c(data);
break;
case 0x3d: // TV Control 2
@ -893,8 +388,9 @@ WRITE16_MEMBER(spg2xx_video_device::video_w)
break;
case 0x42: // Sprite Control
LOGMASKED(LOG_PPU_WRITES, "video_w: Sprite Control = %04x (TopLeft:%d, Enable:%d)\n", data & 0x0003, BIT(data, 1), BIT(data, 0));
m_video_regs[offset] = data & 0x0003;
LOGMASKED(LOG_PPU_WRITES, "video_w: Sprite Control = %04x (TopLeft:%d, Enable:%d)\n", data, BIT(data, 1), BIT(data, 0));
m_video_regs[offset] = data;
m_renderer->set_video_reg_42(data);
break;
case 0x62: // Video IRQ Enable
@ -987,3 +483,9 @@ void spg2xx_video_device::device_timer(emu_timer &timer, device_timer_id id, int
}
}
}
void spg2xx_video_device::device_add_mconfig(machine_config &config)
{
SPG_RENDERER(config, m_renderer, 0);
}

View File

@ -11,6 +11,7 @@
#pragma once
#include "spg_renderer.h"
#include "cpu/unsp/unsp.h"
#include "screen.h"
@ -34,6 +35,7 @@ public:
auto write_video_irq_callback() { return m_video_irq_cb.bind(); };
protected:
virtual void device_add_mconfig(machine_config &config) override;
devcb_read16 m_guny_in;
devcb_read16 m_gunx_in;
@ -48,44 +50,6 @@ protected:
void do_sprite_dma(uint32_t len);
enum blend_enable_t : const bool
{
BlendOff = false,
BlendOn = true
};
enum rowscroll_enable_t : const bool
{
RowScrollOff = false,
RowScrollOn = true
};
enum flipx_t : const bool
{
FlipXOff = false,
FlipXOn = true
};
void apply_saturation_and_fade(bitmap_rgb32& bitmap, const rectangle& cliprect, int scanline);
void draw_page(const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t *regs);
void draw_sprites(const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority);
inline void draw_sprite(const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t base_addr);
inline void draw_linemap(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* regs);
inline bool get_tile_info(uint32_t tilemap_rambase, uint32_t palettemap_rambase, uint32_t x0, uint32_t y0, uint32_t tile_count_x, uint32_t ctrl, uint32_t attr, uint16_t& tile, bool& blend, bool& flip_x, bool& flip_y, uint32_t& palette_offset);
template<spg2xx_video_device::blend_enable_t Blend, spg2xx_video_device::flipx_t FlipX>
inline void draw_tilestrip(const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint16_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile);
uint8_t mix_channel(uint8_t a, uint8_t b);
uint8_t m_rgb5_to_rgb8[32];
uint32_t m_rgb555_to_rgb888[0x8000];
uint32_t m_ycmp_table[480];
void update_vcmp_table();
uint16_t m_video_regs[0x100];
devcb_read16 m_sprlimit_read_cb;
@ -100,6 +64,8 @@ protected:
required_shared_ptr<uint16_t> m_spriteram;
devcb_write_line m_video_irq_cb;
required_device<spg_renderer_device> m_renderer;
};
class spg24x_video_device : public spg2xx_video_device

View File

@ -0,0 +1,526 @@
// license:BSD-3-Clause
// copyright-holders:David Haywood, Ryan Holtz
#include "emu.h"
#include "spg_renderer.h"
DEFINE_DEVICE_TYPE(SPG_RENDERER, spg_renderer_device, "spg_renderer", "SunPlus / GeneralPlus video rendering")
spg_renderer_device::spg_renderer_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, type, tag, owner, clock)
{
}
spg_renderer_device::spg_renderer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
spg_renderer_device(mconfig, SPG_RENDERER, tag, owner, clock)
{
}
void spg_renderer_device::device_start()
{
for (uint8_t i = 0; i < 32; i++)
{
m_rgb5_to_rgb8[i] = (i << 3) | (i >> 2);
}
for (uint16_t i = 0; i < 0x8000; i++)
{
m_rgb555_to_rgb888[i] = (m_rgb5_to_rgb8[(i >> 10) & 0x1f] << 16) |
(m_rgb5_to_rgb8[(i >> 5) & 0x1f] << 8) |
(m_rgb5_to_rgb8[(i >> 0) & 0x1f] << 0);
}
save_item(NAME(m_video_regs_1c));
save_item(NAME(m_video_regs_1d));
save_item(NAME(m_video_regs_1e));
save_item(NAME(m_video_regs_22));
save_item(NAME(m_video_regs_2a));
save_item(NAME(m_video_regs_30));
save_item(NAME(m_video_regs_3c));
save_item(NAME(m_video_regs_42));
save_item(NAME(m_ycmp_table));
}
void spg_renderer_device::device_reset()
{
m_video_regs_1c = 0x0000;
m_video_regs_1d = 0x0000;
m_video_regs_1e = 0x0000;
m_video_regs_22 = 0x0000;
m_video_regs_2a = 0x0000;
m_video_regs_30 = 0x0000;
m_video_regs_3c = 0x0020;
m_video_regs_42 = 0x0001;
for (int i = 0; i < 480; i++)
{
m_ycmp_table[i] = 0xffffffff;
}
}
// Perform a lerp between a and b
inline uint8_t spg_renderer_device::mix_channel(uint8_t bottom, uint8_t top)
{
uint8_t alpha = (m_video_regs_2a & 3) << 6;
return ((256 - alpha) * bottom + alpha * top) >> 8;
}
template<spg_renderer_device::blend_enable_t Blend, spg_renderer_device::flipx_t FlipX>
void spg_renderer_device::draw_tilestrip(const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint16_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile, address_space &spc, uint16_t* paletteram)
{
const uint32_t yflipmask = flip_y ? tile_h - 1 : 0;
uint32_t m = tilegfxdata_addr + words_per_tile * tile + bits_per_row * (tile_scanline ^ yflipmask);
uint32_t bits = 0;
uint32_t nbits = 0;
for (int32_t x = FlipX ? (tile_w - 1) : 0; FlipX ? x >= 0 : x < tile_w; FlipX ? x-- : x++)
{
int realdrawpos = (drawx + x) & 0x1ff;
bits <<= nc_bpp;
if (nbits < nc_bpp)
{
uint16_t b = spc.read_word(m++ & 0x3fffff);
b = (b << 8) | (b >> 8);
bits |= b << (nc_bpp - nbits);
nbits += 16;
}
nbits -= nc_bpp;
uint32_t pal = palette_offset + (bits >> 16);
bits &= 0xffff;
if (realdrawpos >= 0 && realdrawpos < 320)
{
uint16_t rgb = paletteram[pal];
if (!(rgb & 0x8000))
{
if (Blend)
{
dst[realdrawpos] = (mix_channel((uint8_t)(dst[realdrawpos] >> 16), m_rgb5_to_rgb8[(rgb >> 10) & 0x1f]) << 16) |
(mix_channel((uint8_t)(dst[realdrawpos] >> 8), m_rgb5_to_rgb8[(rgb >> 5) & 0x1f]) << 8) |
(mix_channel((uint8_t)(dst[realdrawpos] >> 0), m_rgb5_to_rgb8[rgb & 0x1f]));
}
else
{
dst[realdrawpos] = m_rgb555_to_rgb888[rgb];
}
}
}
}
}
void spg_renderer_device::draw_linemap(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* scrollregs, uint16_t* tilemapregs, address_space &spc, uint16_t* paletteram)
{
if ((scanline < 0) || (scanline >= 240))
return;
uint32_t tilemap = tilemapregs[2];
uint32_t palette_map = tilemapregs[3];
//printf("draw bitmap bases %04x %04x\n", tilemap, palette_map);
//uint32_t xscroll = scrollregs[0];
uint32_t yscroll = scrollregs[1];
int realline = (scanline + yscroll) & 0xff;
uint16_t tile = spc.read_word(tilemap + realline);
uint16_t palette = 0;
//if (!tile)
// continue;
palette = spc.read_word(palette_map + realline / 2);
if (scanline & 1)
palette >>= 8;
else
palette &= 0x00ff;
//const int linewidth = 320 / 2;
int sourcebase = tile | (palette << 16);
uint32_t ctrl = tilemapregs[1];
if (ctrl & 0x80) // HiColor mode (rad_digi)
{
for (int i = 0; i < 320; i++)
{
const uint16_t data = spc.read_word(sourcebase + i);
if (!(data & 0x8000))
{
dst[i] = m_rgb555_to_rgb888[data & 0x7fff];
}
}
}
else
{
for (int i = 0; i < 320 / 2; i++)
{
uint8_t palette_entry;
uint16_t color;
const uint16_t data = spc.read_word(sourcebase + i);
palette_entry = (data & 0x00ff);
color = paletteram[palette_entry];
if (!(color & 0x8000))
{
dst[(i * 2) + 0] = m_rgb555_to_rgb888[color & 0x7fff];
}
palette_entry = (data & 0xff00) >> 8;
color = paletteram[palette_entry];
if (!(color & 0x8000))
{
dst[(i * 2) + 1] = m_rgb555_to_rgb888[color & 0x7fff];
}
}
}
}
bool spg_renderer_device::get_tile_info(uint32_t tilemap_rambase, uint32_t palettemap_rambase, uint32_t x0, uint32_t y0, uint32_t tile_count_x, uint32_t ctrl, uint32_t attr, uint16_t& tile, spg_renderer_device::blend_enable_t& blend, spg_renderer_device::flipx_t& flip_x, bool& flip_y, uint32_t& palette_offset, address_space &spc)
{
uint32_t tile_address = x0 + (tile_count_x * y0);
tile = (ctrl & 0x0004) ? spc.read_word(tilemap_rambase) : spc.read_word(tilemap_rambase + tile_address);
if (!tile)
return false;
uint32_t tileattr = attr;
uint32_t tilectrl = ctrl;
if ((ctrl & 2) == 0)
{ // -(1) bld(1) flip(2) pal(4)
uint16_t palette = (ctrl & 0x0004) ? spc.read_word(palettemap_rambase) : spc.read_word(palettemap_rambase + tile_address / 2);
if (x0 & 1)
palette >>= 8;
else
palette &= 0x00ff;
tileattr &= ~0x000c;
tileattr |= (palette >> 2) & 0x000c; // flip
tileattr &= ~0x0f00;
tileattr |= (palette << 8) & 0x0f00; // palette
tilectrl &= ~0x0100;
tilectrl |= (palette << 2) & 0x0100; // blend
}
blend = ((tileattr & 0x4000 || tilectrl & 0x0100)) ? BlendOn : BlendOff;
flip_x = (tileattr & 0x0004) ? FlipXOn : FlipXOff;
flip_y= (tileattr & 0x0008);
palette_offset = (tileattr & 0x0f00) >> 4;
return true;
}
// this builds up a line table for the vcmp effect, this is not correct when step is used
void spg_renderer_device::update_vcmp_table()
{
int currentline = 0;
int step = m_video_regs_1e & 0xff;
if (step & 0x80)
step = step - 0x100;
int current_inc_value = (m_video_regs_1c<<4);
int counter = 0;
for (int i = 0; i < 480; i++)
{
if (i < m_video_regs_1d)
{
m_ycmp_table[i] = 0xffffffff;
}
else
{
if ((currentline >= 0) && (currentline < 240))
{
m_ycmp_table[i] = currentline;
}
counter += current_inc_value;
while (counter >= (0x20<<4))
{
currentline++;
current_inc_value += step;
counter -= (0x20<<4);
}
}
}
}
void spg_renderer_device::draw_tilestrip(spg_renderer_device::blend_enable_t blend, spg_renderer_device::flipx_t flip_x, const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint16_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile, address_space& spc, uint16_t* paletteram)
{
if (blend)
{
if (flip_x)
{
draw_tilestrip<BlendOn, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
else
{
draw_tilestrip<BlendOn, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
}
else
{
if (flip_x)
{
draw_tilestrip<BlendOff, FlipXOn>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
else
{
draw_tilestrip<BlendOff, FlipXOff>(cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
}
}
void spg_renderer_device::draw_page(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* scrollregs, uint16_t* tilemapregs, address_space& spc, uint16_t* paletteram, uint16_t* scrollram)
{
const uint32_t attr = tilemapregs[0];
const uint32_t ctrl = tilemapregs[1];
if (!(ctrl & 0x0008))
{
return;
}
if (((attr & 0x3000) >> 12) != priority)
{
return;
}
if (ctrl & 0x0001) // Bitmap / Linemap mode! (basically screen width tile mode)
{
draw_linemap(cliprect, dst, scanline, priority, tilegfxdata_addr, scrollregs, tilemapregs, spc, paletteram);
return;
}
uint32_t logical_scanline = scanline;
if (ctrl & 0x0040) // 'vertical compression feature' (later models only?)
{
if (m_video_regs_1e != 0x0000)
popmessage("vertical compression mode with non-0 step amount %04x offset %04x step %04x\n", m_video_regs_1c, m_video_regs_1d, m_video_regs_1e);
logical_scanline = m_ycmp_table[scanline];
if (logical_scanline == 0xffffffff)
return;
}
const uint32_t xscroll = scrollregs[0];
const uint32_t yscroll = scrollregs[1];
const uint32_t tilemap_rambase = tilemapregs[2];
const uint32_t palettemap_rambase = tilemapregs[3];
const int tile_width = (attr & 0x0030) >> 4;
const uint32_t tile_h = 8 << ((attr & 0x00c0) >> 6);
const uint32_t tile_w = 8 << (tile_width);
const uint32_t tile_count_x = 512 / tile_w; // all tilemaps are 512 pixels wide
const uint32_t bitmap_y = (logical_scanline + yscroll) & 0xff; // all tilemaps are 256 pixels high
const uint32_t y0 = bitmap_y / tile_h;
const uint32_t tile_scanline = bitmap_y % tile_h;
const uint8_t bpp = attr & 0x0003;
const uint32_t nc_bpp = ((bpp)+1) << 1;
const uint32_t bits_per_row = nc_bpp * tile_w / 16;
const uint32_t words_per_tile = bits_per_row * tile_h;
const bool row_scroll = (ctrl & 0x0010);
int realxscroll = xscroll;
if (row_scroll)
{
// Tennis in My Wireless Sports confirms the need to add the scroll value here rather than rowscroll being screen-aligned
realxscroll += (int16_t)scrollram[(logical_scanline+yscroll) & 0xff];
}
const int upperscrollbits = (realxscroll >> (tile_width + 3));
const int endpos = (320 + tile_w) / tile_w;
for (uint32_t x0 = 0; x0 < endpos; x0++)
{
spg_renderer_device::blend_enable_t blend;
spg_renderer_device::flipx_t flip_x;
bool flip_y;
uint16_t tile;
uint32_t palette_offset;
if (!get_tile_info(tilemap_rambase, palettemap_rambase, (x0 + upperscrollbits) & (tile_count_x-1) , y0, tile_count_x, ctrl, attr, tile, blend, flip_x, flip_y, palette_offset, spc))
continue;
palette_offset >>= nc_bpp;
palette_offset <<= nc_bpp;
const int drawx = (x0 * tile_w) - (realxscroll & (tile_w-1));
draw_tilestrip(blend,flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
}
void spg_renderer_device::draw_sprite(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t base_addr, address_space &spc, uint16_t* paletteram, uint16_t* spriteram)
{
uint32_t tilegfxdata_addr = 0x40 * m_video_regs_22;
uint16_t tile = spriteram[base_addr + 0];
int16_t x = spriteram[base_addr + 1];
int16_t y = spriteram[base_addr + 2];
uint16_t attr = spriteram[base_addr + 3];
if (!tile)
{
return;
}
if (((attr & 0x3000) >> 12) != priority)
{
return;
}
const uint32_t tile_h = 8 << ((attr & 0x00c0) >> 6);
const uint32_t tile_w = 8 << ((attr & 0x0030) >> 4);
if (!(m_video_regs_42 & 0x0002))
{
x = (160 + x) - tile_w / 2;
y = (120 - y) - (tile_h / 2) + 8;
}
x &= 0x01ff;
y &= 0x01ff;
int firstline = y;
int lastline = y + (tile_h - 1);
lastline &= 0x1ff;
const spg_renderer_device::blend_enable_t blend = (attr & 0x4000) ? BlendOn : BlendOff;
const spg_renderer_device::flipx_t flip_x = (attr & 0x0004) ? FlipXOn : FlipXOff;
const uint8_t bpp = attr & 0x0003;
const uint32_t nc_bpp = ((bpp)+1) << 1;
const uint32_t bits_per_row = nc_bpp * tile_w / 16;
const uint32_t words_per_tile = bits_per_row * tile_h;
bool flip_y = (attr & 0x0008);
uint32_t palette_offset = (attr & 0x0f00) >> 4;
// the Circuit Racing game in PDC100 needs this or some graphics have bad colours at the edges when turning as it leaves stray lower bits set
palette_offset >>= nc_bpp;
palette_offset <<= nc_bpp;
if (firstline < lastline)
{
int scanx = scanline - firstline;
if ((scanx >= 0) && (scanline <= lastline))
{
draw_tilestrip(blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
}
else
{
// clipped from top
int tempfirstline = firstline - 0x200;
int templastline = lastline;
int scanx = scanline - tempfirstline;
if ((scanx >= 0) && (scanline <= templastline))
{
draw_tilestrip(blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
// clipped against the bottom
tempfirstline = firstline;
templastline = lastline + 0x200;
scanx = scanline - tempfirstline;
if ((scanx >= 0) && (scanline <= templastline))
{
draw_tilestrip(blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram);
}
}
}
void spg_renderer_device::draw_sprites(const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority, address_space &spc, uint16_t* paletteram, uint16_t* spriteram, int sprlimit)
{
if (!(m_video_regs_42 & 0x0001))
{
return;
}
for (uint32_t n = 0; n < sprlimit; n++)
{
draw_sprite(cliprect, dst, scanline, priority, 4 * n, spc, paletteram, spriteram);
}
}
void spg_renderer_device::apply_saturation_and_fade(bitmap_rgb32& bitmap, const rectangle& cliprect, int scanline)
{
static const float s_u8_to_float = 1.0f / 255.0f;
static const float s_gray_r = 0.299f;
static const float s_gray_g = 0.587f;
static const float s_gray_b = 0.114f;
const float sat_adjust = (0xff - (m_video_regs_3c & 0x00ff)) / (float)(0xff - 0x20);
const uint16_t fade_offset = m_video_regs_30;
uint32_t* src = &bitmap.pix32(scanline, cliprect.min_x);
for (int x = cliprect.min_x; x <= cliprect.max_x; x++)
{
if ((m_video_regs_3c & 0x00ff) != 0x0020) // apply saturation
{
const uint32_t src_rgb = *src;
const float src_r = (uint8_t)(src_rgb >> 16) * s_u8_to_float;
const float src_g = (uint8_t)(src_rgb >> 8) * s_u8_to_float;
const float src_b = (uint8_t)(src_rgb >> 0) * s_u8_to_float;
const float luma = src_r * s_gray_r + src_g * s_gray_g + src_b * s_gray_b;
const float adjusted_r = luma + (src_r - luma) * sat_adjust;
const float adjusted_g = luma + (src_g - luma) * sat_adjust;
const float adjusted_b = luma + (src_b - luma) * sat_adjust;
const int integer_r = (int)floor(adjusted_r * 255.0f);
const int integer_g = (int)floor(adjusted_g * 255.0f);
const int integer_b = (int)floor(adjusted_b * 255.0f);
*src = (integer_r > 255 ? 0xff0000 : (integer_r < 0 ? 0 : ((uint8_t)integer_r << 16))) |
(integer_g > 255 ? 0x00ff00 : (integer_g < 0 ? 0 : ((uint8_t)integer_g << 8))) |
(integer_b > 255 ? 0x0000ff : (integer_b < 0 ? 0 : (uint8_t)integer_b));
}
if (fade_offset != 0) // apply fade
{
const uint32_t src_rgb = *src;
const uint8_t src_r = (src_rgb >> 16) & 0xff;
const uint8_t src_g = (src_rgb >> 8) & 0xff;
const uint8_t src_b = (src_rgb >> 0) & 0xff;
const uint8_t r = src_r - fade_offset;
const uint8_t g = src_g - fade_offset;
const uint8_t b = src_b - fade_offset;
*src = (r > src_r ? 0 : (r << 16)) |
(g > src_g ? 0 : (g << 8)) |
(b > src_b ? 0 : (b << 0));
}
src++;
}
}

View File

@ -0,0 +1,93 @@
// license:BSD-3-Clause
// copyright-holders:David Haywood, Ryan Holtz
#ifndef MAME_MACHINE_SPG_RENDERER_H
#define MAME_MACHINE_SPG_RENDERER_H
#pragma once
#include "screen.h"
class spg_renderer_device : public device_t
{
public:
spg_renderer_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
spg_renderer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
void draw_sprites(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, address_space& spc, uint16_t* paletteram, uint16_t* spriteram, int sprlimit);
void draw_page(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* scrollregs, uint16_t* tilemapregs, address_space& spc, uint16_t* paletteram, uint16_t* scrollram);
void apply_saturation_and_fade(bitmap_rgb32& bitmap, const rectangle& cliprect, int scanline);
void set_video_reg_1c(uint16_t val) { m_video_regs_1c = val; update_vcmp_table(); }
void set_video_reg_1d(uint16_t val) { m_video_regs_1d = val; update_vcmp_table(); }
void set_video_reg_1e(uint16_t val) { m_video_regs_1e = val; update_vcmp_table(); }
void set_video_reg_22(uint16_t val) { m_video_regs_22 = val; }
void set_video_reg_2a(uint16_t val) { m_video_regs_2a = val; }
void set_video_reg_30(uint16_t val) { m_video_regs_30 = val; }
void set_video_reg_3c(uint16_t val) { m_video_regs_3c = val; }
void set_video_reg_42(uint16_t val) { m_video_regs_42 = val; }
uint16_t get_video_reg_1c(void) { return m_video_regs_1c; }
uint16_t get_video_reg_1d(void) { return m_video_regs_1d; }
uint16_t get_video_reg_1e(void) { return m_video_regs_1e; }
uint16_t get_video_reg_22(void) { return m_video_regs_22; }
uint16_t get_video_reg_2a(void) { return m_video_regs_2a; }
uint16_t get_video_reg_30(void) { return m_video_regs_30; }
uint16_t get_video_reg_3c(void) { return m_video_regs_3c; }
uint16_t get_video_reg_42(void) { return m_video_regs_42; }
protected:
virtual void device_start() override;
virtual void device_reset() override;
enum blend_enable_t : const bool
{
BlendOff = false,
BlendOn = true
};
enum flipx_t : const bool
{
FlipXOff = false,
FlipXOn = true
};
template<spg_renderer_device::blend_enable_t Blend, spg_renderer_device::flipx_t FlipX>
inline void draw_tilestrip(const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint16_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile, address_space &spc, uint16_t* palette);
inline void draw_tilestrip(spg_renderer_device::blend_enable_t blend, spg_renderer_device::flipx_t flip_x, const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint16_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile, address_space& spc, uint16_t* paletteram);
void draw_sprite(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t base_addr, address_space& spc, uint16_t* paletteram, uint16_t* spriteram);
inline bool get_tile_info(uint32_t tilemap_rambase, uint32_t palettemap_rambase, uint32_t x0, uint32_t y0, uint32_t tile_count_x, uint32_t ctrl, uint32_t attr, uint16_t& tile, spg_renderer_device::blend_enable_t& blend, spg_renderer_device::flipx_t& flip_x, bool& flip_y, uint32_t& palette_offset, address_space& spc);
inline void draw_linemap(const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* scrollregs, uint16_t* tilemapregs, address_space& spc, uint16_t* paletteram);
uint8_t mix_channel(uint8_t a, uint8_t b);
uint8_t m_rgb5_to_rgb8[32];
uint32_t m_rgb555_to_rgb888[0x8000];
private:
void update_vcmp_table();
uint16_t m_video_regs_1c;
uint16_t m_video_regs_1d;
uint16_t m_video_regs_1e;
uint16_t m_video_regs_2a;
uint16_t m_video_regs_22;
uint16_t m_video_regs_42;
uint16_t m_video_regs_30;
uint16_t m_video_regs_3c;
uint32_t m_ycmp_table[480];
};
DECLARE_DEVICE_TYPE(SPG_RENDERER, spg_renderer_device)
#endif // MAME_MACHINE_SPG_RENDERER_H