summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/segaic16.h
blob: d3e2f18263ad48a023d0b7bb1f2364dcee6ec4ad (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    Sega 16-bit common hardware

***************************************************************************/
#ifndef MAME_VIDEO_SEGAIC16_H
#define MAME_VIDEO_SEGAIC16_H

#pragma once

typedef device_delegate<void (int, uint16_t*, uint16_t*, uint16_t*, uint16_t*)> segaic16_video_pagelatch_delegate;

#define MCFG_SEGAIC16_VIDEO_SET_PAGELATCH_CB( _class, _method) \
	downcast<segaic16_video_device &>(*device).set_pagelatch_cb(segaic16_video_pagelatch_delegate(&_class::_method, #_class "::" #_method, nullptr, (_class *)nullptr));


/*************************************
 *
 *  Type definitions
 *
 *************************************/



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/



class segaic16_video_device :   public device_t,
								public device_video_interface
{
public:
	/* tilemap systems */
	static constexpr unsigned MAX_TILEMAPS       = 1;

	static constexpr unsigned TILEMAP_HANGON     = 0;
	static constexpr unsigned TILEMAP_16A        = 1;
	static constexpr unsigned TILEMAP_16B        = 2;
	static constexpr unsigned TILEMAP_16B_ALT    = 3;

	static constexpr unsigned TILEMAP_FOREGROUND = 0;
	static constexpr unsigned TILEMAP_BACKGROUND = 1;
	static constexpr unsigned TILEMAP_TEXT       = 2;



	/* rotation systems */
	static constexpr unsigned MAX_ROTATE         = 1;

	static constexpr unsigned ROTATE_YBOARD      = 0;



	struct tilemap_callback_info
	{
		uint16_t *        rambase;                        /* base of RAM for this tilemap page */
		const uint8_t *   bank;                           /* pointer to bank array */
		uint16_t          banksize;                       /* size of banks */
	};


	struct tilemap_info
	{
		uint8_t           index;                          /* index of this structure */
		uint8_t           type;                           /* type of tilemap (see segaic16.h for details) */
		uint8_t           numpages;                       /* number of allocated pages */
		uint8_t           flip;                           /* screen flip? */
		uint8_t           rowscroll, colscroll;           /* are rowscroll/colscroll enabled (if external enables are used) */
		uint8_t           bank[8];                        /* indexes of the tile banks */
		uint16_t          banksize;                       /* number of tiles per bank */
		uint16_t          latched_xscroll[4];             /* latched X scroll values */
		uint16_t          latched_yscroll[4];             /* latched Y scroll values */
		uint16_t          latched_pageselect[4];          /* latched page select values */
		int32_t           xoffs;                          /* X scroll offset */
		tilemap_t *     tilemaps[16];                   /* up to 16 tilemap pages */
		tilemap_t *     textmap;                        /* a single text tilemap */
		struct tilemap_callback_info tmap_info[16];     /* callback info for 16 tilemap pages */
		struct tilemap_callback_info textmap_info;      /* callback info for a single textmap page */
		void            (*reset)(screen_device &screen, struct tilemap_info *info);/* reset callback */
		void            (*draw_layer)(screen_device &screen, struct tilemap_info *info, bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int flags, int priority);
		uint16_t *        textram;                        /* pointer to textram pointer */
		uint16_t *        tileram;                        /* pointer to tileram pointer */
		emu_timer *     latch_timer;                    /* timer for latching 16b tilemap scroll values */
	};


	struct rotate_info
	{
		uint8_t           index;                          /* index of this structure */
		uint8_t           type;                           /* type of rotate system (see segaic16.h for details) */
		uint16_t          colorbase;                      /* base color index */
		int32_t           ramsize;                        /* size of rotate RAM */
		uint16_t *        rotateram;                      /* pointer to rotateram pointer */
		std::unique_ptr<uint16_t[]>        buffer;                         /* buffered data */
	};


	segaic16_video_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// configuration
	void set_gfxdecode_tag(const char *tag) { m_gfxdecode.set_tag(tag); }
	void set_pagelatch_cb(segaic16_video_pagelatch_delegate newtilecb) { m_pagelatch_cb = newtilecb; }

	uint8_t m_display_enable;
	optional_shared_ptr<uint16_t> m_tileram;
	optional_shared_ptr<uint16_t> m_textram;
	optional_shared_ptr<uint16_t> m_rotateram;

	void tilemap_set_colscroll(int which, int enable);
	void tilemap_set_rowscroll(int which, int enable);
	void tilemap_set_flip(int which, int flip);
	void tilemap_set_bank(int which, int banknum, int offset);
	void tilemap_reset(screen_device &screen);
	void tilemap_draw(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int map, int priority, int priority_mark);
//  void tilemap_16b_draw_layer(screen_device &screen, struct tilemap_info *info, bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int flags, int priority);
//  void tilemap_16a_draw_layer(screen_device &screen, struct tilemap_info *info, bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int flags, int priority);
//  void draw_virtual_tilemap(screen_device &screen, struct tilemap_info *info, bitmap_ind16 &bitmap, const rectangle &cliprect, uint16_t pages, uint16_t xscroll, uint16_t yscroll, uint32_t flags, uint32_t priority);
//  void tilemap_16b_reset(screen_device &screen, struct tilemap_info *info);

	segaic16_video_pagelatch_delegate m_pagelatch_cb;
	void tilemap_16b_fill_latch(int i, uint16_t* latched_pageselect, uint16_t* latched_yscroll, uint16_t* latched_xscroll, uint16_t* textram);
	TIMER_CALLBACK_MEMBER( tilemap_16b_latch_values );

	struct rotate_info m_rotate[MAX_ROTATE];
	struct tilemap_info m_bg_tilemap[MAX_TILEMAPS];

	void set_display_enable(int enable);
	void tilemap_init(int which, int type, int colorbase, int xoffs, int numbanks);
	void rotate_init(int which, int type, int colorbase);

	DECLARE_READ16_MEMBER( tileram_r );
	DECLARE_READ16_MEMBER( textram_r );
	DECLARE_WRITE16_MEMBER( tileram_w );
	DECLARE_WRITE16_MEMBER( textram_w );

	void rotate_draw(int which, bitmap_ind16 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, bitmap_ind16 &srcbitmap);

	DECLARE_READ16_MEMBER( rotate_control_r );

	TILE_GET_INFO_MEMBER( tilemap_16b_tile_info );
	TILE_GET_INFO_MEMBER( tilemap_16b_text_info );
	TILE_GET_INFO_MEMBER( tilemap_16b_alt_tile_info );
	TILE_GET_INFO_MEMBER( tilemap_16b_alt_text_info );

	TILE_GET_INFO_MEMBER( tilemap_16a_tile_info );
	TILE_GET_INFO_MEMBER( tilemap_16a_text_info );

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

private:
	// internal state
	required_device<gfxdecode_device> m_gfxdecode;
};

DECLARE_DEVICE_TYPE(SEGAIC16VID, segaic16_video_device)

#define MCFG_SEGAIC16VID_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, SEGAIC16VID, 0)

#define MCFG_SEGAIC16VID_GFXDECODE(_gfxtag) \
	downcast<segaic16_video_device &>(*device).set_gfxdecode_tag(_gfxtag);

#endif // MAME_VIDEO_SEGAIC16_H