summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/tc0100scn.h
blob: 3e68339a6069c71b07570fd77c9e37121b1c0d84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
#ifndef MAME_VIDEO_TC0100SCN_H
#define MAME_VIDEO_TC0100SCN_H

#pragma once

#include "emupal.h"

enum {
	TC0100SCN_LAYOUT_DEFAULT = 0,
	TC0100SCN_LAYOUT_1BPP
};

enum {
	TC0620SCC_LAYOUT_DEFAULT = 0 // default TC0620SCC layout is 6bpp
};

typedef device_delegate<void (u32 *code, u16 *color)> tc0100scn_cb_delegate;
#define TC0100SCN_CB_MEMBER(_name)   void _name(u32 *code, u16 *color)

class tc0100scn_base_device : public device_t, public device_gfx_interface
{
public:
	// configuration
	void set_gfxlayout(int layout) { m_gfxlayout = layout; }
	void set_color_base(u16 base) { m_col_base = base; }
	template <typename... T> void set_tile_callback(T &&... args) { m_tc0100scn_cb = tc0100scn_cb_delegate(std::forward<T>(args)...); }
	void set_multiscr_xoffs(int xoffs) { m_multiscrn_xoffs = xoffs; }
	void set_multiscr_hack(int hack) { m_multiscrn_hack = hack; }
	void set_offsets(int x_offset, int y_offset)
	{
		m_x_offset = x_offset;
		m_y_offset = y_offset;
	}
	void set_offsets_flip(int x_offset, int y_offset)
	{
		m_flip_xoffs = x_offset;
		m_flip_yoffs = y_offset;
	}
	void set_offsets_fliptx(int x_offset, int y_offset)
	{
		m_flip_text_xoffs = x_offset;
		m_flip_text_yoffs = y_offset;
	}

	static constexpr unsigned SINGLE_VDU = 1024; // for set_multiscr_xoffs

	/* Function to set separate color banks for the three tilemapped layers.
	To change from the default (0,0,0) use after calling TC0100SCN_vh_start */
	void set_colbanks(int bg0, int bg1, int tx);

	u16 ram_r(offs_t offset);
	void ram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
	u16 ctrl_r(offs_t offset);
	void ctrl_w(offs_t offset, u16 data, u16 mem_mask = ~0);

	void tilemap_update();
	int tilemap_draw(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int flags, u8 priority, u8 pmask = 0xff);
	void tilemap_set_dirty();

	/* returns 0 or 1 depending on the lowest priority tilemap set in the internal
	register. Use this function to draw tilemaps in the correct order. */
	int bottomlayer();

protected:
	tc0100scn_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);

	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_post_load() override;

	int          m_gfxlayout;
private:
	// internal state
	tc0100scn_cb_delegate   m_tc0100scn_cb;

	u16          m_ctrl[8];

	std::unique_ptr<u16[]>    m_ram;
	u16 *        m_bgscroll_ram;
	u16 *        m_fgscroll_ram;
	u16 *        m_colscroll_ram;

	int          m_bgscrollx, m_bgscrolly, m_fgscrollx, m_fgscrolly;

	/* We keep two tilemaps for each of the 3 actual tilemaps: one at standard width, one double */
	tilemap_t    *m_tilemap[3][2];

	s32          m_bg_colbank[2], m_tx_colbank;
	int          m_dblwidth;
	bool         m_dirty;

	int          m_x_offset, m_y_offset;
	int          m_flip_xoffs, m_flip_yoffs;
	int          m_flip_text_xoffs, m_flip_text_yoffs;
	int          m_multiscrn_xoffs;
	int          m_multiscrn_hack;

	u16          m_col_base;

	template<unsigned Offset, unsigned Colbank> TILE_GET_INFO_MEMBER(get_bg_tile_info);
	template<unsigned Offset, unsigned Gfx> TILE_GET_INFO_MEMBER(get_tx_tile_info);

	void tilemap_draw_fg(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, tilemap_t* tmap, int flags, u8 priority, u8 pmask = 0xff);
	void set_layer_ptrs();
	void restore_scroll();
};

class tc0100scn_device : public tc0100scn_base_device
{
public:
	tc0100scn_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

protected:
	// device-level overrides
	virtual void device_start() override;

private:
	// decoding info
	DECLARE_GFXDECODE_MEMBER(gfxinfo_default);
	DECLARE_GFXDECODE_MEMBER(gfxinfo_1bpp);
};

class tc0620scc_device : public tc0100scn_base_device
{
public:
	tc0620scc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

protected:
	// device-level overrides
	virtual void device_start() override;

private:
	// decoding info
	DECLARE_GFXDECODE_MEMBER(gfxinfo_6bpp);
};

DECLARE_DEVICE_TYPE(TC0100SCN, tc0100scn_device)
DECLARE_DEVICE_TYPE(TC0620SCC, tc0620scc_device)

#endif // MAME_VIDEO_TC0100SCN_H