mirror of
https://github.com/holub/mame
synced 2025-04-25 01:40:16 +03:00
konami/k037122.cpp: Implement device_palette_interface for palette. (#11792)
Also cleaned up code and reduced hard-coded constants.
This commit is contained in:
parent
ddccb2bcbd
commit
1b590b0399
@ -1310,11 +1310,8 @@ void hornet_state::hornet(machine_config &config)
|
||||
screen.set_raw(XTAL(64'000'000) / 4, 644, 41, 41 + 512, 428, 27, 27 + 384);
|
||||
screen.set_screen_update(FUNC(hornet_state::screen_update<0>));
|
||||
|
||||
PALETTE(config, "palette").set_entries(65536);
|
||||
|
||||
K037122(config, m_k037122[0], 0);
|
||||
m_k037122[0]->set_screen("screen");
|
||||
m_k037122[0]->set_palette("palette");
|
||||
|
||||
K056800(config, m_k056800, XTAL(16'934'400));
|
||||
m_k056800->int_callback().set_inputline(m_audiocpu, M68K_IRQ_2);
|
||||
@ -1386,11 +1383,9 @@ void hornet_state::sscope(machine_config &config)
|
||||
m_dsp[1]->set_addrmap(AS_DATA, &hornet_state::sharc1_map);
|
||||
|
||||
m_k037122[0]->set_screen("lscreen");
|
||||
m_k037122[0]->set_palette("palette");
|
||||
|
||||
K037122(config, m_k037122[1], 0); // unknown input clock
|
||||
m_k037122[1]->set_screen("rscreen");
|
||||
m_k037122[1]->set_palette("palette");
|
||||
|
||||
m_voodoo[0]->set_screen("lscreen");
|
||||
|
||||
|
@ -82,11 +82,11 @@ DEFINE_DEVICE_TYPE(K037122, k037122_device, "k037122", "K037122 2D Tilemap")
|
||||
k037122_device::k037122_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
|
||||
device_t(mconfig, K037122, tag, owner, clock),
|
||||
device_video_interface(mconfig, *this),
|
||||
device_gfx_interface(mconfig, *this, nullptr),
|
||||
device_gfx_interface(mconfig, *this, nullptr, DEVICE_SELF),
|
||||
device_palette_interface(mconfig, *this),
|
||||
m_tile_ram(nullptr),
|
||||
m_char_ram(nullptr),
|
||||
m_reg(nullptr),
|
||||
m_gfx_index(0)
|
||||
m_reg(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -96,9 +96,6 @@ k037122_device::k037122_device(const machine_config &mconfig, const char *tag, d
|
||||
|
||||
void k037122_device::device_start()
|
||||
{
|
||||
if (!palette().device().started())
|
||||
throw device_missing_dependencies();
|
||||
|
||||
static const gfx_layout k037122_char_layout =
|
||||
{
|
||||
8, 8,
|
||||
@ -120,7 +117,7 @@ void k037122_device::device_start()
|
||||
m_tilemap_128->set_transparent_pen(0);
|
||||
m_tilemap_256->set_transparent_pen(0);
|
||||
|
||||
set_gfx(m_gfx_index,std::make_unique<gfx_element>(&palette(), k037122_char_layout, (uint8_t*)m_char_ram.get(), 0, palette().entries() / 16, 0));
|
||||
set_gfx(0,std::make_unique<gfx_element>(this, k037122_char_layout, (uint8_t*)m_char_ram.get(), 0, entries() / 16, 0));
|
||||
|
||||
save_pointer(NAME(m_reg), 0x400 / 4);
|
||||
save_pointer(NAME(m_char_ram), 0x200000 / 4);
|
||||
@ -149,17 +146,17 @@ void k037122_device::device_reset()
|
||||
|
||||
TILE_GET_INFO_MEMBER(k037122_device::tile_info)
|
||||
{
|
||||
uint32_t val = m_tile_ram[tile_index + (m_tilemap_base / 4)];
|
||||
int color = (val >> 17) & 0x1f;
|
||||
int tile = val & 0x3fff;
|
||||
uint32_t const val = m_tile_ram[tile_index + (m_tilemap_base / 4)];
|
||||
uint32_t const color = (val >> 17) & 0x1f;
|
||||
uint32_t const tile = val & 0x3fff;
|
||||
int flags = 0;
|
||||
|
||||
if (val & 0x400000)
|
||||
if (BIT(val, 22))
|
||||
flags |= TILE_FLIPX;
|
||||
if (val & 0x800000)
|
||||
if (BIT(val, 23))
|
||||
flags |= TILE_FLIPY;
|
||||
|
||||
tileinfo.set(m_gfx_index, tile, color, flags);
|
||||
tileinfo.set(0, tile, color, flags);
|
||||
}
|
||||
|
||||
|
||||
@ -167,13 +164,13 @@ void k037122_device::tile_draw( screen_device &screen, bitmap_rgb32 &bitmap, con
|
||||
{
|
||||
const rectangle &visarea = screen.visible_area();
|
||||
|
||||
int16_t scrollx = m_reg[0x8] >> 16;
|
||||
int16_t const scrollx = m_reg[0x8] >> 16;
|
||||
int16_t scrolly = m_reg[0x8] & 0xffff;
|
||||
|
||||
int16_t incxx = m_reg[0xa] >> 16;
|
||||
int16_t incxy = m_reg[0xa] & 0xffff;
|
||||
int16_t incyx = m_reg[0x9] >> 16;
|
||||
int16_t incyy = m_reg[0x9] & 0xffff;
|
||||
int16_t const incxx = m_reg[0xa] >> 16;
|
||||
int16_t const incxy = m_reg[0xa] & 0xffff;
|
||||
int16_t const incyx = m_reg[0x9] >> 16;
|
||||
int16_t const incyy = m_reg[0x9] & 0xffff;
|
||||
|
||||
if (m_reg[0xc] & 0x10000)
|
||||
{
|
||||
@ -211,12 +208,12 @@ void k037122_device::sram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
|
||||
{
|
||||
COMBINE_DATA(m_tile_ram.get() + offset);
|
||||
|
||||
uint32_t address = offset * 4;
|
||||
uint32_t const address = offset * 4;
|
||||
|
||||
if (address >= m_palette_base && address < m_palette_base + 0x8000)
|
||||
{
|
||||
int color = (address - m_palette_base) / 4;
|
||||
palette().set_pen_color(color, pal5bit(data >> 6), pal6bit(data >> 0), pal5bit(data >> 11));
|
||||
uint32_t const color = (address - m_palette_base) / 4;
|
||||
set_pen_color(color, pal5bit(data >> 6), pal6bit(data >> 0), pal5bit(data >> 11));
|
||||
}
|
||||
|
||||
if (address >= m_tilemap_base && address < m_tilemap_base + 0x10000)
|
||||
@ -229,18 +226,18 @@ void k037122_device::sram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
|
||||
|
||||
uint32_t k037122_device::char_r(offs_t offset)
|
||||
{
|
||||
int bank = m_reg[0x30 / 4] & 0x7;
|
||||
uint32_t const bank = m_reg[0x30 / 4] & 0x7;
|
||||
|
||||
return m_char_ram[offset + (bank * (0x40000 / 4))];
|
||||
}
|
||||
|
||||
void k037122_device::char_w(offs_t offset, uint32_t data, uint32_t mem_mask)
|
||||
{
|
||||
int bank = m_reg[0x30 / 4] & 0x7;
|
||||
uint32_t addr = offset + (bank * (0x40000/4));
|
||||
uint32_t const bank = m_reg[0x30 / 4] & 0x7;
|
||||
uint32_t const addr = offset + (bank * (0x40000/4));
|
||||
|
||||
COMBINE_DATA(m_char_ram.get() + addr);
|
||||
gfx(m_gfx_index)->mark_dirty(addr / 32);
|
||||
gfx(0)->mark_dirty(addr / 32);
|
||||
}
|
||||
|
||||
uint32_t k037122_device::reg_r(offs_t offset)
|
||||
@ -259,20 +256,20 @@ void k037122_device::reg_w(offs_t offset, uint32_t data, uint32_t mem_mask)
|
||||
{
|
||||
if (offset == 0x34/4 && ACCESSING_BITS_0_15)
|
||||
{
|
||||
uint32_t palette_base = (data & 0x4) ? 0x18000 : 0x00000;
|
||||
uint32_t const palette_base = BIT(data, 2) ? 0x18000 : 0x00000;
|
||||
|
||||
// tilemap is at 0x00000 unless CLUT is there
|
||||
uint32_t tilemap_base = (data & 0x4) ? 0x00000 : 0x08000;
|
||||
uint32_t const tilemap_base = BIT(data, 2) ? 0x00000 : 0x08000;
|
||||
|
||||
if (palette_base != m_palette_base)
|
||||
{
|
||||
m_palette_base = palette_base;
|
||||
|
||||
// update all colors since palette moved
|
||||
for (auto p = 0; p < 8192; p++)
|
||||
for (auto p = 0; p < entries(); p++)
|
||||
{
|
||||
uint32_t color = m_tile_ram[(m_palette_base / 4) + p];
|
||||
palette().set_pen_color(p, pal5bit(color >> 6), pal6bit(color >> 0), pal5bit(color >> 11));
|
||||
uint32_t const color = m_tile_ram[(m_palette_base / 4) + p];
|
||||
set_pen_color(p, pal5bit(color >> 6), pal6bit(color >> 0), pal5bit(color >> 11));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,16 +8,14 @@
|
||||
|
||||
class k037122_device : public device_t,
|
||||
public device_video_interface,
|
||||
public device_gfx_interface
|
||||
public device_gfx_interface,
|
||||
public device_palette_interface
|
||||
{
|
||||
public:
|
||||
static constexpr feature_type imperfect_features() { return feature::GRAPHICS; } // unimplemented tilemap ROZ, scroll registers
|
||||
|
||||
k037122_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
|
||||
// configuration
|
||||
void set_gfx_index(int index) { m_gfx_index = index; }
|
||||
|
||||
void tile_draw( screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect );
|
||||
uint32_t sram_r(offs_t offset);
|
||||
void sram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
|
||||
@ -31,6 +29,9 @@ protected:
|
||||
virtual void device_start() override;
|
||||
virtual void device_reset() override;
|
||||
|
||||
// device_palette_interface impleemntations
|
||||
virtual uint32_t palette_entries() const noexcept override { return 8192; }
|
||||
|
||||
private:
|
||||
// internal state
|
||||
tilemap_t* m_tilemap_128 = nullptr;
|
||||
@ -43,8 +44,6 @@ private:
|
||||
std::unique_ptr<uint32_t[]> m_char_ram;
|
||||
std::unique_ptr<uint32_t[]> m_reg;
|
||||
|
||||
int m_gfx_index;
|
||||
|
||||
TILE_GET_INFO_MEMBER(tile_info);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user