summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/quizdna.c
blob: fe48799e159be1925d91ec7d05b86f7c9671e870 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/******************************************************************************

Quiz DNA no Hanran (c) 1992 Face
Quiz Gakuen Paradise (c) 1991 NMK
Quiz Gekiretsu Scramble (Gakuen Paradise 2) (c) 1993 Face

Video hardware
    driver by Uki

******************************************************************************/

#include "emu.h"
#include "includes/quizdna.h"


TILE_GET_INFO_MEMBER(quizdna_state::get_bg_tile_info)
{
	int code = m_bg_ram[tile_index*2] + m_bg_ram[tile_index*2+1]*0x100 ;
	int col = m_bg_ram[tile_index*2+0x1000] & 0x7f;

	if (code>0x7fff)
		code &= 0x83ff;

	SET_TILE_INFO_MEMBER(1, code, col, 0);
}

TILE_GET_INFO_MEMBER(quizdna_state::get_fg_tile_info)
{
	int code,col,x,y;
	UINT8 *FG = memregion("user1")->base();

	x = tile_index & 0x1f;
	y = FG[(tile_index >> 5) & 0x1f] & 0x3f;
	code = y & 1;

	y >>= 1;

	col = m_fg_ram[x*2 + y*0x40 + 1];
	code += (m_fg_ram[x*2 + y*0x40] + (col & 0x1f) * 0x100) * 2;
	col >>= 5;
	col = (col & 3) | ((col & 4) << 1);

	SET_TILE_INFO_MEMBER(0, code, col, 0);
}


void quizdna_state::video_start()
{
	m_flipscreen = -1;
	m_video_enable = 0;
	m_bg_xscroll[0] = 0;
	m_bg_xscroll[1] = 0;

	m_bg_ram = auto_alloc_array(machine(), UINT8, 0x2000);
	m_fg_ram = auto_alloc_array(machine(), UINT8, 0x1000);

	m_bg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(quizdna_state::get_bg_tile_info),this),TILEMAP_SCAN_ROWS,8,8,64,32 );
	m_fg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(quizdna_state::get_fg_tile_info),this),TILEMAP_SCAN_ROWS,16,8,32,32 );

	m_fg_tilemap->set_transparent_pen(0 );

	save_pointer(NAME(m_bg_ram), 0x2000);
	save_pointer(NAME(m_fg_ram), 0x1000);
	save_item(NAME(m_bg_xscroll));
	save_item(NAME(m_flipscreen));
	save_item(NAME(m_video_enable));
}

WRITE8_MEMBER(quizdna_state::bg_ram_w)
{
	UINT8 *RAM = memregion("maincpu")->base();
	m_bg_ram[offset] = data;
	RAM[0x12000+offset] = data;

	m_bg_tilemap->mark_tile_dirty((offset & 0xfff) / 2 );
}

WRITE8_MEMBER(quizdna_state::fg_ram_w)
{
	int i;
	int offs = offset & 0xfff;
	UINT8 *RAM = memregion("maincpu")->base();

	RAM[0x10000+offs] = data;
	RAM[0x11000+offs] = data; /* mirror */
	m_fg_ram[offs] = data;

	for (i=0; i<32; i++)
		m_fg_tilemap->mark_tile_dirty(((offs/2) & 0x1f) + i*0x20 );
}

WRITE8_MEMBER(quizdna_state::bg_yscroll_w)
{
	m_bg_tilemap->set_scrolldy(255-data, 255-data+1 );
}

WRITE8_MEMBER(quizdna_state::bg_xscroll_w)
{
	int x;
	m_bg_xscroll[offset] = data;
	x = ~(m_bg_xscroll[0] + m_bg_xscroll[1]*0x100) & 0x1ff;

	m_bg_tilemap->set_scrolldx(x+64, x-64+10 );
}

WRITE8_MEMBER(quizdna_state::screen_ctrl_w)
{
	int tmp = (data & 0x10) >> 4;
	m_video_enable = data & 0x20;

	coin_counter_w(machine(), 0, data & 1);

	if (m_flipscreen == tmp)
		return;

	m_flipscreen = tmp;

	flip_screen_set(tmp);
	m_fg_tilemap->set_scrolldx(64, -64 +16);
}

WRITE8_MEMBER(quizdna_state::paletteram_xBGR_RRRR_GGGG_BBBB_w)
{
	int r,g,b,d0,d1;
	int offs = offset & ~1;

	m_generic_paletteram_8[offset] = data;

	d0 = m_generic_paletteram_8[offs];
	d1 = m_generic_paletteram_8[offs+1];

	r = ((d1 << 1) & 0x1e) | ((d1 >> 4) & 1);
	g = ((d0 >> 3) & 0x1e) | ((d1 >> 5) & 1);
	b = ((d0 << 1) & 0x1e) | ((d1 >> 6) & 1);

	m_palette->set_pen_color(offs/2,pal5bit(r),pal5bit(g),pal5bit(b));
}

void quizdna_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	for (int offs = 0; offs<m_spriteram.bytes(); offs+=8)
	{
		int x = m_spriteram[offs + 3]*0x100 + m_spriteram[offs + 2] + 64 - 8;
		int y = (m_spriteram[offs + 1] & 1)*0x100 + m_spriteram[offs + 0];
		int code = (m_spriteram[offs + 5] * 0x100 + m_spriteram[offs + 4]) & 0x3fff;
		int col =  m_spriteram[offs + 6];
		int fx = col & 0x80;
		int fy = col & 0x40;
		int ysize = (m_spriteram[offs + 1] & 0xc0) >> 6;
		int dy = 0x10;
		col &= 0x1f;

		if (m_flipscreen)
		{
			x -= 7;
			y += 1;
		}

		x &= 0x1ff;
		if (x>0x1f0)
			x -= 0x200;

		if (fy)
		{
			dy = -0x10;
			y += 0x10 * ysize;
		}

		if (code >= 0x2100)
			code &= 0x20ff;

		for (int i=0; i<ysize+1; i++)
		{
			y &= 0x1ff;

			m_gfxdecode->gfx(2)->transpen(bitmap,cliprect,
					code ^ i,
					col,
					fx,fy,
					x,y,0);

			y += dy;
		}
	}
}

UINT32 quizdna_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_video_enable)
	{
		m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
		draw_sprites(bitmap, cliprect);
		m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	}
	else
		bitmap.fill(m_palette->black_pen(), cliprect);
	return 0;
}