Added palette to k053250 device, fixing xexex crash. Also modernized its coding conventions (dynamic_arrays, device_video_interface to attach screen, etc.) [Alex Jackson]

This commit is contained in:
Alex W. Jackson 2014-03-16 05:21:28 +00:00
parent cbb8715568
commit 55c4d53f0e
5 changed files with 65 additions and 57 deletions

View File

@ -1121,7 +1121,7 @@ static MACHINE_CONFIG_DERIVED( metamrph, mystwarr )
MCFG_DEVICE_REMOVE("k053252")
MCFG_K053252_ADD("k053252", 6000000, metamrph_k053252_intf) // 6 MHz?
MCFG_K053250_ADD("k053250_1", "screen", -7, 0)
MCFG_K053250_ADD("k053250_1", "palette", "screen", -7, 0)
/* video hardware */
MCFG_VIDEO_START_OVERRIDE(mystwarr_state,metamrph)

View File

@ -370,8 +370,8 @@ static MACHINE_CONFIG_START( overdriv, overdriv_state )
MCFG_K051316_GFXDECODE("gfxdecode")
MCFG_K051316_PALETTE("palette")
MCFG_K053251_ADD("k053251")
MCFG_K053250_ADD("k053250_1", "screen", 0, 0)
MCFG_K053250_ADD("k053250_2", "screen", 0, 0)
MCFG_K053250_ADD("k053250_1", "palette", "screen", 0, 0)
MCFG_K053250_ADD("k053250_2", "palette", "screen", 0, 0)
MCFG_K053252_ADD("k053252", 24000000/4, overdriv_k053252_intf)
/* sound hardware */

View File

@ -577,7 +577,7 @@ static MACHINE_CONFIG_START( xexex, xexex_state )
MCFG_K053246_ADD("k053246", xexex_k053246_intf)
MCFG_K053246_GFXDECODE("gfxdecode")
MCFG_K053246_PALETTE("palette")
MCFG_K053250_ADD("k053250", "screen", -5, -16)
MCFG_K053250_ADD("k053250", "palette", "screen", -5, -16)
MCFG_K053251_ADD("k053251")
MCFG_K053252_ADD("k053252", XTAL_32MHz/4, xexex_k053252_intf)
MCFG_K054338_ADD("k054338", xexex_k054338_intf)

View File

@ -3,21 +3,22 @@
const device_type K053250 = &device_creator<k053250_device>;
k053250_device::k053250_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, K053250, "K053250", tag, owner, clock, "k053250", __FILE__)
: device_t(mconfig, K053250, "K053250", tag, owner, clock, "k053250", __FILE__),
device_video_interface(mconfig, *this),
m_palette(*this)
{
}
void k053250_device::static_set_screen_tag(device_t &device, const char *screen_tag)
void k053250_device::static_set_palette_tag(device_t &device, const char *tag)
{
k053250_device &dev = downcast<k053250_device &>(device);
dev.screen_tag = screen_tag;
downcast<k053250_device &>(device).m_palette.set_tag(tag);
}
void k053250_device::static_set_offsets(device_t &device, int offx, int offy)
{
k053250_device &dev = downcast<k053250_device &>(device);
dev.offx = offx;
dev.offy = offy;
dev.m_offx = offx;
dev.m_offy = offy;
}
void k053250_device::unpack_nibbles()
@ -27,34 +28,35 @@ void k053250_device::unpack_nibbles()
const UINT8 *base = m_region->base();
int size = m_region->bytes();
unpacked = auto_alloc_array(machine(), UINT8, size*2);
for(int i=0; i<size; i++) {
unpacked[2*i] = base[i] >> 4;
unpacked[2*i+1] = base[i] & 15;
m_unpacked_rom.resize(size*2);
for(int i=0; i<size; i++)
{
m_unpacked_rom[2*i] = base[i] >> 4;
m_unpacked_rom[2*i+1] = base[i] & 0xf;
}
unpacked_size = 2*size;
}
void k053250_device::device_start()
{
screen = machine().device<screen_device>(screen_tag);
ram = auto_alloc_array_clear(machine(), UINT16, 0x6000/2);
buffer[0] = ram + 0x2000;
buffer[1] = ram + 0x2800;
m_ram.resize(0x6000/2);
m_buffer[0] = &m_ram[0x2000];
m_buffer[1] = &m_ram[0x2800];
unpack_nibbles();
save_pointer(NAME(ram), 0x6000/2);
save_item(NAME(regs));
save_item(NAME(page));
save_item(NAME(frame));
save_item(NAME(m_ram));
save_item(NAME(m_regs));
save_item(NAME(m_page));
save_item(NAME(m_frame));
}
void k053250_device::device_reset()
{
page = 0;
frame = -1;
memset(regs, 0, sizeof(regs));
m_page = 0;
m_frame = -1;
memset(m_regs, 0, sizeof(m_regs));
}
// utility function to render a clipped scanline vertically or horizontally
@ -230,10 +232,10 @@ void k053250_device::draw( bitmap_rgb32 &bitmap, const rectangle &cliprect, int
int color, offset, zoom, scroll, passes, i;
bool wrap500 = false;
UINT16 *line_ram = buffer[page]; // pointer to physical line RAM
int map_scrollx = short(regs[0] << 8 | regs[1]) - offx; // signed horizontal scroll value
int map_scrolly = short(regs[2] << 8 | regs[3]) - offy; // signed vertical scroll value
UINT8 ctrl = regs[4]; // register four is the main control register
UINT16 *line_ram = m_buffer[m_page]; // pointer to physical line RAM
int map_scrollx = short(m_regs[0] << 8 | m_regs[1]) - m_offx; // signed horizontal scroll value
int map_scrolly = short(m_regs[2] << 8 | m_regs[3]) - m_offy; // signed vertical scroll value
UINT8 ctrl = m_regs[4]; // register four is the main control register
// copy visible boundary values to more accessible locations
int dst_minx = cliprect.min_x;
@ -356,7 +358,7 @@ void k053250_device::draw( bitmap_rgb32 &bitmap, const rectangle &cliprect, int
linedata_offs += line_start * linedata_adv; // pre-advance line info offset for the clipped region
// load physical palette base
pal_base = screen->palette()->pens() + (colorbase << 4) % screen->palette()->entries();
pal_base = m_palette->pens() + (colorbase << 4) % m_palette->entries();
// walk the target bitmap within the visible area vertically or horizontally, one line at a time
for (line_pos=line_start; line_pos <= line_end; linedata_offs += linedata_adv, line_pos++)
@ -375,7 +377,7 @@ void k053250_device::draw( bitmap_rgb32 &bitmap, const rectangle &cliprect, int
// calculate physical pixel location
// each offset unit represents 256 pixels and should wrap at ROM boundary for safety
pix_ptr = unpacked + ((offset << 8) % unpacked_size);
pix_ptr = &m_unpacked_rom[((offset << 8) % m_unpacked_rom.count())];
// get scanline zoom factor
// For example, 0x20 doubles the length, 0x40 maintains a one-to-one length,
@ -425,19 +427,19 @@ void k053250_device::draw( bitmap_rgb32 &bitmap, const rectangle &cliprect, int
void k053250_device::dma(int limiter)
{
int current_frame = screen->frame_number();
int current_frame = m_screen->frame_number();
if (limiter && current_frame == frame)
if (limiter && current_frame == m_frame)
return; // make sure we only do DMA transfer once per frame
frame = current_frame;
memcpy(buffer[page], ram, 0x1000);
page ^= 1;
m_frame = current_frame;
memcpy(m_buffer[m_page], m_ram, 0x1000);
m_page ^= 1;
}
READ16_MEMBER(k053250_device::reg_r)
{
return regs[offset];
return m_regs[offset];
}
WRITE16_MEMBER(k053250_device::reg_w)
@ -445,24 +447,24 @@ WRITE16_MEMBER(k053250_device::reg_w)
if (ACCESSING_BITS_0_7)
{
// start LVC DMA transfer at the falling edge of control register's bit1
if (offset == 4 && !(data & 2) && (regs[4] & 2))
if (offset == 4 && !(data & 2) && (m_regs[4] & 2))
dma(1);
regs[offset] = data;
m_regs[offset] = data;
}
}
READ16_MEMBER(k053250_device::ram_r)
{
return ram[offset];
return m_ram[offset];
}
WRITE16_MEMBER(k053250_device::ram_w)
{
COMBINE_DATA(ram+offset);
COMBINE_DATA(&m_ram[offset]);
}
READ16_MEMBER(k053250_device::rom_r)
{
return m_region->base()[0x80000 * regs[6] + 0x800 * regs[7] + offset/2];
return m_region->base()[0x80000 * m_regs[6] + 0x800 * m_regs[7] + offset/2];
}

View File

@ -7,17 +7,19 @@
#include "emu.h"
#define MCFG_K053250_ADD(_tag, screen_tag, offx, offy) \
#define MCFG_K053250_ADD(_tag, _palette_tag, _screen_tag, offx, offy) \
MCFG_DEVICE_ADD(_tag, K053250, 0) \
k053250_device::static_set_screen_tag(*device, screen_tag); \
MCFG_VIDEO_SET_SCREEN(_screen_tag) \
k053250_device::static_set_palette_tag(*device, "^" _palette_tag); \
k053250_device::static_set_offsets(*device, offx, offy);
class k053250_device : public device_t
class k053250_device : public device_t,
public device_video_interface
{
public:
k053250_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
static void static_set_screen_tag(device_t &device, const char *screen_tag);
static void static_set_palette_tag(device_t &device, const char *tag);
static void static_set_offsets(device_t &device, int offx, int offy);
DECLARE_READ16_MEMBER(reg_r);
@ -29,21 +31,25 @@ public:
void draw( bitmap_rgb32 &bitmap, const rectangle &cliprect, int colorbase, int flags, bitmap_ind8 &priority_bitmap, int priority );
protected:
// device-level overrides
virtual void device_start();
virtual void device_reset();
private:
UINT8 regs[8];
UINT8 *unpacked;
UINT32 unpacked_size;
UINT16 *ram;
UINT16 *buffer[2];
UINT32 page;
INT32 frame;
int offx, offy;
const char *screen_tag;
screen_device *screen;
// configuration
int m_offx, m_offy;
// internal state
dynamic_buffer m_unpacked_rom;
dynamic_array<UINT16> m_ram;
UINT16 *m_buffer[2];
UINT8 m_regs[8];
UINT8 m_page;
INT32 m_frame;
required_device<palette_device> m_palette;
// internal helpers
void unpack_nibbles();
void dma(int limiter);
static void pdraw_scanline32(bitmap_rgb32 &bitmap, const pen_t *palette, UINT8 *source,