1 // license:BSD-3-Clause
2 // copyright-holders:Fabio Priuli,Acho A. Tang, R. Belmont
3 #ifndef MAME_VIDEO_K051316_H
4 #define MAME_VIDEO_K051316_H
5 
6 #pragma once
7 
8 #include "tilemap.h"
9 
10 
11 #define K051316_CB_MEMBER(_name)   void _name(int *code, int *color, int *flags)
12 
13 
14 class k051316_device : public device_t, public device_gfx_interface
15 {
16 public:
17 	using zoom_delegate = device_delegate<void (int *code, int *color, int *flags)>;
18 
19 	k051316_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
20 
21 	static const gfx_layout charlayout4;
22 	static const gfx_layout charlayout7;
23 	static const gfx_layout charlayout8;
24 	DECLARE_GFXDECODE_MEMBER(gfxinfo);
25 	DECLARE_GFXDECODE_MEMBER(gfxinfo7);
26 	DECLARE_GFXDECODE_MEMBER(gfxinfo8);
27 	DECLARE_GFXDECODE_MEMBER(gfxinfo4_ram);
28 
29 	// configuration
set_zoom_callback(T &&...args)30 	template <typename... T> void set_zoom_callback(T &&... args) { m_k051316_cb.set(std::forward<T>(args)...); }
set_wrap(int wrap)31 	void set_wrap(int wrap) { m_wrap = wrap; }
32 	void set_bpp(int bpp);
set_layermask(int mask)33 	void set_layermask(int mask) { m_layermask = mask; }
set_offsets(int x_offset,int y_offset)34 	void set_offsets(int x_offset, int y_offset)
35 	{
36 		m_dx = x_offset;
37 		m_dy = y_offset;
38 	}
39 
40 	/*
41 	The callback is passed:
42 	- code (range 00-FF, contents of the first tilemap RAM byte)
43 	- color (range 00-FF, contents of the first tilemap RAM byte). Note that bit 6
44 	  seems to be hardcoded as flip X.
45 	The callback must put:
46 	- in code the resulting tile number
47 	- in color the resulting color index
48 	- if necessary, put flags for the TileMap code in the tile_info
49 	  structure (e.g. TILE_FLIPX)
50 	*/
51 
52 	u8 read(offs_t offset);
53 	void write(offs_t offset, u8 data);
54 	u8 rom_r(offs_t offset);
55 	void ctrl_w(offs_t offset, u8 data);
56 	void zoom_draw(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect,int flags,uint32_t priority);
57 	void wraparound_enable(int status);
58 
mark_gfx_dirty(offs_t byteoffset)59 	void mark_gfx_dirty(offs_t byteoffset) { gfx(0)->mark_dirty(byteoffset * m_pixels_per_byte / (16 * 16)); }
mark_tmap_dirty()60 	void mark_tmap_dirty() { m_tmap->mark_all_dirty(); }
61 
62 protected:
63 	// device-level overrides
64 	virtual void device_start() override;
65 	virtual void device_reset() override;
66 
67 private:
68 	// internal state
69 	std::vector<uint8_t> m_ram;
70 	uint8_t m_ctrlram[16];
71 	tilemap_t *m_tmap;
72 
73 	optional_region_ptr<uint8_t> m_zoom_rom;
74 
75 	int m_dx, m_dy;
76 	int m_wrap;
77 	int m_pixels_per_byte;
78 	int m_layermask;
79 	zoom_delegate m_k051316_cb;
80 
81 	TILE_GET_INFO_MEMBER(get_tile_info);
82 };
83 
84 DECLARE_DEVICE_TYPE(K051316, k051316_device)
85 
86 #endif // MAME_VIDEO_K051316_H
87