1 // license:BSD-3-Clause
2 // copyright-holders:Hau, Nicola Salmoria
3 /******************************************************************************
4
5 Ganbare Ginkun (Japan) (c)1995 TECMO
6 Final StarForce (US) (c)1992 TECMO
7 Riot (Japan) (c)1992 NMK
8
9 Based on sprite drivers from video/wc90.c by Ernesto Corvi (ernesto@imagina.com)
10
11 ******************************************************************************/
12
13 #include "emu.h"
14 #include "includes/tecmo16.h"
15
16
17 /******************************************************************************/
18
19
save_state()20 void tecmo16_state::save_state()
21 {
22 save_item(NAME(m_flipscreen));
23 save_item(NAME(m_scroll_x_w));
24 save_item(NAME(m_scroll_y_w));
25 save_item(NAME(m_scroll2_x_w));
26 save_item(NAME(m_scroll2_y_w));
27 save_item(NAME(m_scroll_char_x_w));
28 save_item(NAME(m_scroll_char_y_w));
29 }
30
TILE_GET_INFO_MEMBER(tecmo16_state::fg_get_tile_info)31 TILE_GET_INFO_MEMBER(tecmo16_state::fg_get_tile_info)
32 {
33 int tile = m_videoram[tile_index] & 0x1fff;
34 int color = m_colorram[tile_index] & 0x1f;
35
36 /* bit 4 controls blending */
37 //tileinfo.category = (m_colorram[tile_index] & 0x10) >> 4;
38
39 tileinfo.set(1,
40 tile,
41 color,
42 0);
43 }
44
TILE_GET_INFO_MEMBER(tecmo16_state::bg_get_tile_info)45 TILE_GET_INFO_MEMBER(tecmo16_state::bg_get_tile_info)
46 {
47 int tile = m_videoram2[tile_index] & 0x1fff;
48 int color = (m_colorram2[tile_index] & 0x0f);
49
50 tileinfo.set(1,
51 tile,
52 color,
53 0);
54 }
55
TILE_GET_INFO_MEMBER(tecmo16_state::tx_get_tile_info)56 TILE_GET_INFO_MEMBER(tecmo16_state::tx_get_tile_info)
57 {
58 int tile = m_charram[tile_index];
59 tileinfo.set(0,
60 tile & 0x0fff,
61 tile >> 12,
62 0);
63 }
64
65 /******************************************************************************/
66
video_start()67 void tecmo16_state::video_start()
68 {
69 /* set up tile layers */
70 m_screen->register_screen_bitmap(m_tile_bitmap_bg);
71 m_screen->register_screen_bitmap(m_tile_bitmap_fg);
72 m_screen->register_screen_bitmap(m_tile_bitmap_tx);
73
74 /* set up sprites */
75 m_screen->register_screen_bitmap(m_sprite_bitmap);
76
77 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::fg_get_tile_info)), TILEMAP_SCAN_ROWS, 16,16, 32,32);
78 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::bg_get_tile_info)), TILEMAP_SCAN_ROWS, 16,16, 32,32);
79 m_tx_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::tx_get_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64,32);
80
81 m_fg_tilemap->set_transparent_pen(0);
82 m_bg_tilemap->set_transparent_pen(0);
83 m_tx_tilemap->set_transparent_pen(0);
84
85 m_tx_tilemap->set_scrolly(0,-16);
86 m_flipscreen = 0;
87 m_game_is_riot = 0;
88
89 save_state();
90 }
91
VIDEO_START_MEMBER(tecmo16_state,ginkun)92 VIDEO_START_MEMBER(tecmo16_state,ginkun)
93 {
94 /* set up tile layers */
95 m_screen->register_screen_bitmap(m_tile_bitmap_bg);
96 m_screen->register_screen_bitmap(m_tile_bitmap_fg);
97 m_screen->register_screen_bitmap(m_tile_bitmap_tx);
98
99 /* set up sprites */
100 m_screen->register_screen_bitmap(m_sprite_bitmap);
101
102 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::fg_get_tile_info)), TILEMAP_SCAN_ROWS, 16,16, 64,32);
103 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::bg_get_tile_info)), TILEMAP_SCAN_ROWS, 16,16, 64,32);
104 m_tx_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::tx_get_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64,32);
105
106 m_fg_tilemap->set_transparent_pen(0);
107 m_bg_tilemap->set_transparent_pen(0);
108 m_tx_tilemap->set_transparent_pen(0);
109 m_flipscreen = 0;
110 m_game_is_riot = 0;
111
112 save_state();
113 }
114
VIDEO_START_MEMBER(tecmo16_state,riot)115 VIDEO_START_MEMBER(tecmo16_state,riot)
116 {
117 /* set up tile layers */
118 m_screen->register_screen_bitmap(m_tile_bitmap_bg);
119 m_screen->register_screen_bitmap(m_tile_bitmap_fg);
120 m_screen->register_screen_bitmap(m_tile_bitmap_tx);
121
122 /* set up sprites */
123 m_screen->register_screen_bitmap(m_sprite_bitmap);
124
125 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::fg_get_tile_info)), TILEMAP_SCAN_ROWS, 16,16, 64,32);
126 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::bg_get_tile_info)), TILEMAP_SCAN_ROWS, 16,16, 64,32);
127 m_tx_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tecmo16_state::tx_get_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64,32);
128
129 m_fg_tilemap->set_transparent_pen(0);
130 m_bg_tilemap->set_transparent_pen(0);
131 m_tx_tilemap->set_transparent_pen(0);
132 m_tx_tilemap->set_scrolldy(-16,-16);
133 m_flipscreen = 0;
134 m_game_is_riot = 1;
135
136 save_state();
137 }
138
139 /******************************************************************************/
140
videoram_w(offs_t offset,uint16_t data,uint16_t mem_mask)141 void tecmo16_state::videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
142 {
143 COMBINE_DATA(&m_videoram[offset]);
144 m_fg_tilemap->mark_tile_dirty(offset);
145 }
146
colorram_w(offs_t offset,uint16_t data,uint16_t mem_mask)147 void tecmo16_state::colorram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
148 {
149 COMBINE_DATA(&m_colorram[offset]);
150 m_fg_tilemap->mark_tile_dirty(offset);
151 }
152
videoram2_w(offs_t offset,uint16_t data,uint16_t mem_mask)153 void tecmo16_state::videoram2_w(offs_t offset, uint16_t data, uint16_t mem_mask)
154 {
155 COMBINE_DATA(&m_videoram2[offset]);
156 m_bg_tilemap->mark_tile_dirty(offset);
157 }
158
colorram2_w(offs_t offset,uint16_t data,uint16_t mem_mask)159 void tecmo16_state::colorram2_w(offs_t offset, uint16_t data, uint16_t mem_mask)
160 {
161 COMBINE_DATA(&m_colorram2[offset]);
162 m_bg_tilemap->mark_tile_dirty(offset);
163 }
164
165
charram_w(offs_t offset,uint16_t data,uint16_t mem_mask)166 void tecmo16_state::charram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
167 {
168 COMBINE_DATA(&m_charram[offset]);
169 m_tx_tilemap->mark_tile_dirty(offset);
170 }
171
flipscreen_w(uint16_t data)172 void tecmo16_state::flipscreen_w(uint16_t data)
173 {
174 m_flipscreen = data & 0x01;
175 flip_screen_set(m_flipscreen);
176 }
177
178 /******************************************************************************/
179
scroll_x_w(offs_t offset,uint16_t data,uint16_t mem_mask)180 void tecmo16_state::scroll_x_w(offs_t offset, uint16_t data, uint16_t mem_mask)
181 {
182 COMBINE_DATA(&m_scroll_x_w);
183 m_fg_tilemap->set_scrollx(0,m_scroll_x_w);
184 }
185
scroll_y_w(offs_t offset,uint16_t data,uint16_t mem_mask)186 void tecmo16_state::scroll_y_w(offs_t offset, uint16_t data, uint16_t mem_mask)
187 {
188 COMBINE_DATA(&m_scroll_y_w);
189 m_fg_tilemap->set_scrolly(0,m_scroll_y_w);
190 }
191
scroll2_x_w(offs_t offset,uint16_t data,uint16_t mem_mask)192 void tecmo16_state::scroll2_x_w(offs_t offset, uint16_t data, uint16_t mem_mask)
193 {
194 COMBINE_DATA(&m_scroll2_x_w);
195 m_bg_tilemap->set_scrollx(0,m_scroll2_x_w);
196 }
197
scroll2_y_w(offs_t offset,uint16_t data,uint16_t mem_mask)198 void tecmo16_state::scroll2_y_w(offs_t offset, uint16_t data, uint16_t mem_mask)
199 {
200 COMBINE_DATA(&m_scroll2_y_w);
201 m_bg_tilemap->set_scrolly(0,m_scroll2_y_w);
202 }
203
scroll_char_x_w(offs_t offset,uint16_t data,uint16_t mem_mask)204 void tecmo16_state::scroll_char_x_w(offs_t offset, uint16_t data, uint16_t mem_mask)
205 {
206 COMBINE_DATA(&m_scroll_char_x_w);
207 m_tx_tilemap->set_scrollx(0,m_scroll_char_x_w);
208 }
209
scroll_char_y_w(offs_t offset,uint16_t data,uint16_t mem_mask)210 void tecmo16_state::scroll_char_y_w(offs_t offset, uint16_t data, uint16_t mem_mask)
211 {
212 COMBINE_DATA(&m_scroll_char_y_w);
213 m_tx_tilemap->set_scrolly(0,m_scroll_char_y_w-16);
214 }
215
216 /******************************************************************************/
217
218
219 /******************************************************************************/
220
screen_update(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)221 uint32_t tecmo16_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
222 {
223 m_tile_bitmap_bg.fill(0, cliprect);
224 m_tile_bitmap_fg.fill(0, cliprect);
225 m_tile_bitmap_tx.fill(0, cliprect);
226 bitmap.fill(0, cliprect);
227
228 m_bg_tilemap->draw(screen, m_tile_bitmap_bg, cliprect, 0, 0);
229 m_fg_tilemap->draw(screen, m_tile_bitmap_fg, cliprect, 0, 0);
230 m_tx_tilemap->draw(screen, m_tile_bitmap_tx, cliprect, 0, 0);
231
232 m_mixer->mix_bitmaps(screen, bitmap, cliprect, *m_palette, &m_tile_bitmap_bg, &m_tile_bitmap_fg, &m_tile_bitmap_tx, &m_sprite_bitmap);
233
234 return 0;
235 }
236
WRITE_LINE_MEMBER(tecmo16_state::screen_vblank)237 WRITE_LINE_MEMBER(tecmo16_state::screen_vblank)
238 {
239 if (state)
240 {
241 const rectangle visarea = m_screen->visible_area();
242 // 2 frame sprite lags
243 m_sprite_bitmap.fill(0, visarea);
244 if (m_game_is_riot) m_sprgen->gaiden_draw_sprites(*m_screen, m_gfxdecode->gfx(2), visarea, m_spriteram->buffer(), 0, 0, flip_screen(), m_sprite_bitmap);
245 else m_sprgen->gaiden_draw_sprites(*m_screen, m_gfxdecode->gfx(2), visarea, m_spriteram->buffer(), 2, 0, flip_screen(), m_sprite_bitmap);
246
247 m_spriteram->copy();
248 }
249 }
250