// license:BSD-3-Clause
// copyright-holders:David Haywood
#ifndef MAME_VIDEO_K054156_K054157_K056832_H
#define MAME_VIDEO_K054156_K054157_K056832_H
#pragma once
#include "video/k055555.h" // still needs k055555_get_palette_index
typedef device_delegate<void (int layer, int *code, int *color, int *flags)> k056832_cb_delegate;
#define K056832_CB_MEMBER(_name) void _name(int layer, int *code, int *color, int *flags)
#define MCFG_K056832_CB(_class, _method) \
downcast<k056832_device &>(*device).set_k056832_callback(k056832_cb_delegate(&_class::_method, #_class "::" #_method, this));
#define MCFG_K056832_CONFIG(_gfx_reg, _bpp, _big, _djmain_hack) \
downcast<k056832_device &>(*device).set_config(_gfx_reg, _bpp, _big, _djmain_hack);
#define K056832_PAGE_COUNT 16
/* bit depths for the 56832 */
#define K056832_BPP_4 0
#define K056832_BPP_5 1
#define K056832_BPP_6 2
#define K056832_BPP_8 3
#define K056832_BPP_4dj 4
#define K056832_BPP_4PIRATESH 5
#define K056832_BPP_8LE 6
#define K056832_BPP_8TASMAN 7
#define K056832_DRAW_FLAG_MIRROR 0x00800000
#define K056382_DRAW_FLAG_FORCE_XYSCROLL 0x00800000
class k055555_device;
class k056832_device : public device_t, public device_gfx_interface
{
public:
template <typename T> k056832_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&mixer_tag)
: k056832_device(mconfig, tag, owner, clock)
{
m_k055555.set_tag(std::forward<T>(mixer_tag));
}
k056832_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
void set_k056832_callback(k056832_cb_delegate callback) { m_k056832_cb = callback; }
void set_config(const char *gfx_reg, int bpp, int big, int djmain_hack)
{
m_rombase.set_tag(gfx_reg);
m_bpp = bpp;
m_big = big;
m_djmain_hack = djmain_hack;
}
void SetExtLinescroll(); /* Lethal Enforcers */
DECLARE_READ16_MEMBER( ram_word_r );
DECLARE_WRITE16_MEMBER( ram_word_w );
DECLARE_READ16_MEMBER( ram_half_word_r );
DECLARE_WRITE16_MEMBER( ram_half_word_w );
DECLARE_READ16_MEMBER( k_5bpp_rom_word_r );
DECLARE_READ32_MEMBER( k_5bpp_rom_long_r );
DECLARE_READ32_MEMBER( k_6bpp_rom_long_r );
DECLARE_READ16_MEMBER( rom_word_r );
DECLARE_READ8_MEMBER( konmedal_rom_r );
DECLARE_READ16_MEMBER( piratesh_rom_r );
DECLARE_READ16_MEMBER( mw_rom_word_r );
DECLARE_READ16_MEMBER( bishi_rom_word_r );
DECLARE_READ16_MEMBER( old_rom_word_r );
DECLARE_READ16_MEMBER( rom_word_8000_r );
DECLARE_WRITE16_MEMBER( word_w ); // "VRAM" registers
DECLARE_WRITE16_MEMBER( b_word_w );
DECLARE_READ8_MEMBER( ram_code_lo_r );
DECLARE_READ8_MEMBER( ram_code_hi_r );
DECLARE_READ8_MEMBER( ram_attr_lo_r );
DECLARE_READ8_MEMBER( ram_attr_hi_r );
DECLARE_WRITE8_MEMBER( ram_code_lo_w );
DECLARE_WRITE8_MEMBER( ram_code_hi_w );
DECLARE_WRITE8_MEMBER( ram_attr_lo_w );
DECLARE_WRITE8_MEMBER( ram_attr_hi_w );
DECLARE_WRITE8_MEMBER( write );
DECLARE_WRITE8_MEMBER( b_w );
void mark_plane_dirty(int num);
void mark_all_tilemaps_dirty();
void tilemap_draw(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int num, uint32_t flags, uint32_t priority);
void tilemap_draw(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int num, uint32_t flags, uint32_t priority);
void tilemap_draw_dj(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int layer, uint32_t flags, uint32_t priority);
void set_layer_association(int status);
int get_layer_association();
void set_layer_offs(int layer, int offsx, int offsy);
void set_lsram_page(int logical_page, int physical_page, int physical_offset);
void linemap_enable(int enable);
int is_irq_enabled(int irqline);
void read_avac(int *mode, int *data);
int read_register(int regnum);
int get_current_rambank();
int get_lookup(int bits); /* Asterix */
void set_tile_bank(int bank); /* Asterix */
int get_gfx_num() const { return m_gfx_num; }
DECLARE_READ32_MEMBER( ram_long_r );
DECLARE_READ32_MEMBER( rom_long_r );
DECLARE_WRITE32_MEMBER( ram_long_w );
DECLARE_READ32_MEMBER( unpaged_ram_long_r );
DECLARE_WRITE32_MEMBER( unpaged_ram_long_w );
DECLARE_WRITE32_MEMBER( long_w );
DECLARE_WRITE32_MEMBER( b_long_w );
DECLARE_READ16_MEMBER( word_r ); // VACSET
DECLARE_READ16_MEMBER( b_word_r ); // VSCCS (board dependent)
DECLARE_READ32_MEMBER( long_r ); // VACSET
protected:
// device-level overrides
virtual void device_start() override;
private:
// internal state
tilemap_t *m_tilemap[K056832_PAGE_COUNT];
bitmap_ind16 *m_pixmap[K056832_PAGE_COUNT];
std::vector<uint16_t> m_videoram;
uint16_t m_regs[0x20]; // 157/832 regs group 1
uint16_t m_regsb[4]; // 157/832 regs group 2, board dependent
required_region_ptr<uint8_t> m_rombase; // pointer to tile gfx data
int m_num_gfx_banks; // depends on size of graphics ROMs
int m_cur_gfx_banks; // cached info for K056832_regs[0x1a]
k056832_cb_delegate m_k056832_cb;
int m_gfx_num;
int m_bpp;
int m_big;
int m_djmain_hack;
// ROM readback involves reading 2 halves of a word
// from the same location in a row. Reading the
// RAM window resets this state so you get the first half.
int m_rom_half;
// locally cached values
int m_layer_assoc_with_page[K056832_PAGE_COUNT];
int m_layer_offs[8][2];
int m_lsram_page[8][2];
int32_t m_x[8]; // 0..3 left
int32_t m_y[8]; // 0..3 top
int32_t m_w[8]; // 0..3 width -> 1..4 pages
int32_t m_h[8]; // 0..3 height -> 1..4 pages
int32_t m_dx[8]; // scroll
int32_t m_dy[8]; // scroll
uint32_t m_line_dirty[K056832_PAGE_COUNT][8];
uint8_t m_all_lines_dirty[K056832_PAGE_COUNT];
uint8_t m_page_tile_mode[K056832_PAGE_COUNT];
int m_last_colorbase[K056832_PAGE_COUNT];
uint8_t m_layer_tile_mode[8];
int m_default_layer_association;
int m_layer_association;
int m_active_layer;
int m_selected_page;
int m_selected_page_x4096;
int m_linemap_enabled;
int m_use_ext_linescroll;
int m_uses_tile_banks, m_cur_tile_bank;
optional_device<k055555_device> m_k055555; /* used to choose colorbase */
void get_tile_info( tile_data &tileinfo, int tile_index, int pageIndex );
TILE_GET_INFO_MEMBER(get_tile_info0);
TILE_GET_INFO_MEMBER(get_tile_info1);
TILE_GET_INFO_MEMBER(get_tile_info2);
TILE_GET_INFO_MEMBER(get_tile_info3);
TILE_GET_INFO_MEMBER(get_tile_info4);
TILE_GET_INFO_MEMBER(get_tile_info5);
TILE_GET_INFO_MEMBER(get_tile_info6);
TILE_GET_INFO_MEMBER(get_tile_info7);
TILE_GET_INFO_MEMBER(get_tile_info8);
TILE_GET_INFO_MEMBER(get_tile_info9);
TILE_GET_INFO_MEMBER(get_tile_infoa);
TILE_GET_INFO_MEMBER(get_tile_infob);
TILE_GET_INFO_MEMBER(get_tile_infoc);
TILE_GET_INFO_MEMBER(get_tile_infod);
TILE_GET_INFO_MEMBER(get_tile_infoe);
TILE_GET_INFO_MEMBER(get_tile_infof);
void mark_page_dirty(int page);
void update_page_layout();
void change_rambank();
void change_rombank();
void postload();
int rom_read_b(int offset, int blksize, int blksize2, int zerosec);
template<class _BitmapClass>
int update_linemap(screen_device &screen, _BitmapClass &bitmap, int page, int flags);
template<class _BitmapClass>
void tilemap_draw_common(screen_device &screen, _BitmapClass &bitmap, const rectangle &cliprect, int layer, uint32_t flags, uint32_t priority);
void create_gfx();
void create_tilemaps();
void finalize_init();
public:
void m_tilemap_draw(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int num, uint32_t flags, uint32_t priority);
private:
int altK056832_update_linemap(screen_device &screen, bitmap_rgb32 &bitmap, int page, int flags);
};
DECLARE_DEVICE_TYPE(K056832, k056832_device)
#define MCFG_K056832_PALETTE(_palette_tag) \
MCFG_GFX_PALETTE(_palette_tag)
#endif // MAME_VIDEO_K054156_K054157_K056832_H