summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/ms1_tmap.h
blob: 75331ab4062331a943e02a2916bca28b19c74aa9 (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
// license:BSD-3-Clause
// copyright-holders:Luca Elia
/***************************************************************************

    ms1_tmap.h

    8x8/16x16 tilemap generator for Jaleco's Mega System 1 and driving
    and mahjong games from the same period.

***************************************************************************/
#ifndef MAME_VIDEO_MS1_TMAP_H
#define MAME_VIDEO_MS1_TMAP_H

#pragma once


//**************************************************************************
//  DEVICE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_MEGASYS1_TILEMAP_ADD(tag, palette_tag, colorbase) \
	MCFG_DEVICE_ADD(tag, MEGASYS1_TILEMAP, 0) \
	MCFG_GFX_PALETTE(palette_tag) \
	MCFG_MEGASYS1_TILEMAP_COLORBASE(colorbase)

#define MCFG_MEGASYS1_TILEMAP_8X8_SCROLL_FACTOR(scroll_factor) \
	downcast<megasys1_tilemap_device &>(*device).set_8x8_scroll_factor(scroll_factor);

#define MCFG_MEGASYS1_TILEMAP_16X16_SCROLL_FACTOR(scroll_factor) \
	downcast<megasys1_tilemap_device &>(*device).set_16x16_scroll_factor(scroll_factor);

#define MCFG_MEGASYS1_TILEMAP_BITS_PER_COLOR_CODE(bits) \
	downcast<megasys1_tilemap_device &>(*device).set_bits_per_color_code(bits);

#define MCFG_MEGASYS1_TILEMAP_COLORBASE(colorbase) \
	downcast<megasys1_tilemap_device &>(*device).set_colorbase(colorbase);

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> megasys1_tilemap_device

class megasys1_tilemap_device : public device_t, public device_gfx_interface
{
public:
	// construction/destruction
	megasys1_tilemap_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// configuration
	void set_8x8_scroll_factor(int scroll_factor);
	void set_16x16_scroll_factor(int scroll_factor);
	void set_bits_per_color_code(int bits);
	void set_colorbase(uint16_t colorbase);

	// memory handlers
	DECLARE_WRITE16_MEMBER(write);
	DECLARE_READ16_MEMBER(scroll_r);
	DECLARE_WRITE16_MEMBER(scroll_w);

	// drawing and layer control
	void draw(screen_device &screen, bitmap_ind16 &dest, const rectangle &cliprect, uint32_t flags, uint8_t priority = 0, uint8_t priority_mask = 0xff);
	void enable(bool enable);
	void set_flip(uint32_t attributes);

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

private:
	// shared memory finder
	required_shared_ptr<uint16_t> m_scrollram;

	// configuration
	int m_8x8_scroll_factor;
	int m_16x16_scroll_factor;
	int m_bits_per_color_code;
	uint16_t m_colorbase;

	// decoding info
	DECLARE_GFXDECODE_MEMBER(gfxinfo);

	// internal state
	uint16_t m_scrollx;
	uint16_t m_scrolly;
	uint16_t m_scroll_flag;
	tilemap_t *m_tmap;
	tilemap_t *m_tilemap[2][4];

	// helpers
	TILEMAP_MAPPER_MEMBER(scan_8x8);
	TILEMAP_MAPPER_MEMBER(scan_16x16);
	TILE_GET_INFO_MEMBER(get_scroll_tile_info_8x8);
	TILE_GET_INFO_MEMBER(get_scroll_tile_info_16x16);
};

// device type definition
DECLARE_DEVICE_TYPE(MEGASYS1_TILEMAP, megasys1_tilemap_device)

#endif  // MAME_VIDEO_MS1_TMAP_H