1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood
3 /********************************************************************
4 
5     Ashita no Joe (Success Joe) [Wave]
6     video hardware emulation
7 
8 *********************************************************************/
9 
10 #include "emu.h"
11 #include "includes/ashnojoe.h"
12 
13 
TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_highest)14 TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_highest)
15 {
16 	int code = m_tileram[0][tile_index];
17 
18 	tileinfo.set(2,
19 			code & 0xfff,
20 			((code >> 12) & 0x0f),
21 			0);
22 }
23 
TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_midlow)24 TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_midlow)
25 {
26 	int code = m_tileram[1][tile_index * 2];
27 	int attr = m_tileram[1][tile_index * 2 + 1];
28 
29 	tileinfo.set(4,
30 			(code & 0x7fff),
31 			((attr >> 8) & 0x1f) + 0x40,
32 			0);
33 }
34 
TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_high)35 TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_high)
36 {
37 	int code = m_tileram[2][tile_index];
38 
39 	tileinfo.set(0,
40 			code & 0xfff,
41 			((code >> 12) & 0x0f) + 0x10,
42 			0);
43 }
44 
TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_low)45 TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_low)
46 {
47 	int code = m_tileram[3][tile_index];
48 
49 	tileinfo.set(1,
50 			code & 0xfff,
51 			((code >> 12) & 0x0f) + 0x60,
52 			0);
53 }
54 
TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_midhigh)55 TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_midhigh)
56 {
57 	int code = m_tileram[4][tile_index * 2];
58 	int attr = m_tileram[4][tile_index * 2 + 1];
59 
60 	tileinfo.set(4,
61 			(code & 0x7fff),
62 			((attr >> 8) & 0x1f) + 0x20,
63 			0);
64 }
65 
TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_lowest)66 TILE_GET_INFO_MEMBER(ashnojoe_state::get_tile_info_lowest)
67 {
68 	const int buffer = (m_tilemap_reg[0] & 0x02) >> 1;
69 	int code = m_tileram[5 + buffer][tile_index * 2];
70 	int attr = m_tileram[5 + buffer][tile_index * 2 + 1];
71 
72 	tileinfo.set(3,
73 			(code & 0x1fff),
74 			((attr >> 8) & 0x1f) + 0x70,
75 			0);
76 }
77 
78 
tilemaps_xscroll_w(offs_t offset,u16 data)79 void ashnojoe_state::tilemaps_xscroll_w(offs_t offset, u16 data)
80 {
81 	switch (offset)
82 	{
83 	case 0:
84 		m_tilemap[2]->set_scrollx(0, data);
85 		break;
86 	case 1:
87 		m_tilemap[4]->set_scrollx(0, data);
88 		break;
89 	case 2:
90 		m_tilemap[1]->set_scrollx(0, data);
91 		break;
92 	case 3:
93 		m_tilemap[3]->set_scrollx(0, data);
94 		break;
95 	case 4:
96 		m_tilemap[5]->set_scrollx(0, data);
97 		break;
98 	}
99 }
100 
tilemaps_yscroll_w(offs_t offset,u16 data)101 void ashnojoe_state::tilemaps_yscroll_w(offs_t offset, u16 data)
102 {
103 	switch (offset)
104 	{
105 	case 0:
106 		m_tilemap[2]->set_scrolly(0, data);
107 		break;
108 	case 1:
109 		m_tilemap[4]->set_scrolly(0, data);
110 		break;
111 	case 2:
112 		m_tilemap[1]->set_scrolly(0, data);
113 		break;
114 	case 3:
115 		m_tilemap[3]->set_scrolly(0, data);
116 		break;
117 	case 4:
118 		m_tilemap[5]->set_scrolly(0, data);
119 		break;
120 	}
121 }
122 
tilemap_regs_w(offs_t offset,u16 data,u16 mem_mask)123 void ashnojoe_state::tilemap_regs_w(offs_t offset, u16 data, u16 mem_mask)
124 {
125 	const u16 old = m_tilemap_reg[offset];
126 	data = COMBINE_DATA(&m_tilemap_reg[offset]);
127 	if (old != data)
128 	{
129 		if (offset == 0)
130 		{
131 			if ((old ^ data) & 0x02)
132 				m_tilemap[5]->mark_all_dirty();
133 		}
134 	}
135 }
136 
video_start()137 void ashnojoe_state::video_start()
138 {
139 	m_tilemap[0] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(ashnojoe_state::get_tile_info_highest)), TILEMAP_SCAN_ROWS,  8,  8, 64, 32);
140 	m_tilemap[1] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(ashnojoe_state::get_tile_info_midlow)),  TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
141 	m_tilemap[2] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(ashnojoe_state::get_tile_info_high)),    TILEMAP_SCAN_ROWS,  8,  8, 64, 64);
142 	m_tilemap[3] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(ashnojoe_state::get_tile_info_low)),     TILEMAP_SCAN_ROWS,  8,  8, 64, 64);
143 	m_tilemap[4] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(ashnojoe_state::get_tile_info_midhigh)), TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
144 	m_tilemap[5] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(ashnojoe_state::get_tile_info_lowest)),  TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
145 
146 	m_tilemap[0]->set_transparent_pen(15);
147 	m_tilemap[1]->set_transparent_pen(15);
148 	m_tilemap[2]->set_transparent_pen(15);
149 	m_tilemap[3]->set_transparent_pen(15);
150 	m_tilemap[4]->set_transparent_pen(15);
151 }
152 
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)153 u32 ashnojoe_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
154 {
155 	//m_tilemap_reg[0] & 0x10 // ?? on coin insertion
156 
157 	flip_screen_set(m_tilemap_reg[0] & 1);
158 
159 	m_tilemap[5]->draw(screen, bitmap, cliprect, 0, 0);
160 	m_tilemap[3]->draw(screen, bitmap, cliprect, 0, 0);
161 	m_tilemap[1]->draw(screen, bitmap, cliprect, 0, 0);
162 	m_tilemap[4]->draw(screen, bitmap, cliprect, 0, 0);
163 	m_tilemap[2]->draw(screen, bitmap, cliprect, 0, 0);
164 	m_tilemap[0]->draw(screen, bitmap, cliprect, 0, 0);
165 
166 	return 0;
167 }
168