summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/tc0100scn.h
blob: a0399a2a031c7c9ee2e3cbdfb18548dba641dd36 (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
144
145
146
147
148
149
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
#ifndef MAME_VIDEO_TC0100SCN_H
#define MAME_VIDEO_TC0100SCN_H

#pragma once

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

	// configuration
	void set_gfxdecode_tag(const char *tag);
	void set_palette_tag(const char *tag);
	void set_gfx_region(int gfxregion) { m_gfxnum = gfxregion; }
	void set_tx_region(int txregion) { m_txnum = txregion; }
	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);

	/* Function to set bg tilemask < 0xffff */
	void set_bg_tilemask(int mask);

	/* Function to for Mjnquest to select gfx bank */
	DECLARE_WRITE16_MEMBER(gfxbank_w);

	DECLARE_READ16_MEMBER(word_r);
	DECLARE_WRITE16_MEMBER(word_w);
	DECLARE_READ16_MEMBER(ctrl_word_r);
	DECLARE_WRITE16_MEMBER(ctrl_word_w);

	/* Functions for use with 68020 (Under Fire) */
	DECLARE_READ32_MEMBER(long_r);
	DECLARE_WRITE32_MEMBER(long_w);
	DECLARE_READ32_MEMBER(ctrl_long_r);
	DECLARE_WRITE32_MEMBER(ctrl_long_w);

	void tilemap_update();
	int tilemap_draw(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int flags, uint32_t priority);

	/* 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();

	void postload();

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

private:
	// internal state
	uint16_t       m_ctrl[8];

	std::unique_ptr<uint16_t[]>    m_ram;
	uint16_t *     m_bg_ram;
	uint16_t *     m_fg_ram;
	uint16_t *     m_tx_ram;
	uint16_t *     m_char_ram;
	uint16_t *     m_bgscroll_ram;
	uint16_t *     m_fgscroll_ram;
	uint16_t *     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];

	int          m_bg_tilemask;
	int32_t        m_gfxbank;
	int32_t        m_bg0_colbank, m_bg1_colbank, m_tx_colbank;
	int          m_dblwidth;

	int          m_gfxnum;
	int          m_txnum;
	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;

	required_device<gfxdecode_device> m_gfxdecode;
	required_device<palette_device> m_palette;

	TILE_GET_INFO_MEMBER(get_bg_tile_info);
	TILE_GET_INFO_MEMBER(get_fg_tile_info);
	TILE_GET_INFO_MEMBER(get_tx_tile_info);

	void common_get_tile_info(tile_data &tileinfo, int tile_index, uint16_t *ram, int colbank);

	void tilemap_draw_fg(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, tilemap_t* tmap, int flags, uint32_t priority);
	void set_layer_ptrs();
	void dirty_tilemaps();
	void restore_scroll();
};

DECLARE_DEVICE_TYPE(TC0100SCN, tc0100scn_device)


#define MCFG_TC0100SCN_GFX_REGION(_region) \
	downcast<tc0100scn_device &>(*device).set_gfx_region(_region);

#define MCFG_TC0100SCN_TX_REGION(_region) \
	downcast<tc0100scn_device &>(*device).set_tx_region(_region);

#define MCFG_TC0100SCN_OFFSETS(_xoffs, _yoffs) \
	downcast<tc0100scn_device &>(*device).set_offsets(_xoffs, _yoffs);

#define MCFG_TC0100SCN_OFFSETS_FLIP(_xoffs, _yoffs) \
	downcast<tc0100scn_device &>(*device).set_offsets_flip(_xoffs, _yoffs);

#define MCFG_TC0100SCN_OFFSETS_FLIPTX(_xoffs, _yoffs) \
	downcast<tc0100scn_device &>(*device).set_offsets_fliptx(_xoffs, _yoffs);

#define MCFG_TC0100SCN_MULTISCR_XOFFS(_xoffs) \
	downcast<tc0100scn_device &>(*device).set_multiscr_xoffs(_xoffs);

#define MCFG_TC0100SCN_MULTISCR_HACK(_hack) \
	downcast<tc0100scn_device &>(*device).set_multiscr_hack(_hack);

#define MCFG_TC0100SCN_GFXDECODE(_gfxtag) \
	downcast<tc0100scn_device &>(*device).set_gfxdecode_tag("^" _gfxtag);

#define MCFG_TC0100SCN_PALETTE(_palette_tag) \
	downcast<tc0100scn_device &>(*device).set_palette_tag("^" _palette_tag);

#endif // MAME_VIDEO_TC0100SCN_H