summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/strnskil.cpp
blob: 5913cfd537b88fca498a9ac1acf6cc6dceb5a070 (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
// license:BSD-3-Clause
// copyright-holders:Uki
/******************************************************************************

Strength & Skill (c) 1984 Sun Electronics

Video hardware driver by Uki

    19/Jun/2001 -

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

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


PALETTE_INIT_MEMBER(strnskil_state, strnskil)
{
	const uint8_t *color_prom = memregion("proms")->base();
	int i;

	/* create a lookup table for the palette */
	for (i = 0; i < 0x100; i++)
	{
		int r = pal4bit(color_prom[i + 0x000]);
		int g = pal4bit(color_prom[i + 0x100]);
		int b = pal4bit(color_prom[i + 0x200]);

		palette.set_indirect_color(i, rgb_t(r, g, b));
	}

	/* color_prom now points to the beginning of the lookup table */
	color_prom += 0x300;

	/* sprites lookup table */
	for (i = 0; i < 0x400; i++)
	{
		uint8_t ctabentry = color_prom[i];
		palette.set_pen_indirect(i, ctabentry);
	}
}


WRITE8_MEMBER(strnskil_state::strnskil_videoram_w)
{
	m_videoram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset / 2);
}

WRITE8_MEMBER(strnskil_state::strnskil_scrl_ctrl_w)
{
	m_scrl_ctrl = data >> 5;

	if (flip_screen() != (data & 0x08))
	{
		flip_screen_set(data & 0x08);
		machine().tilemap().mark_all_dirty();
	}
}

TILE_GET_INFO_MEMBER(strnskil_state::get_bg_tile_info)
{
	int attr = m_videoram[tile_index * 2];
	int code = m_videoram[(tile_index * 2) + 1] + ((attr & 0x60) << 3);
	int color = (attr & 0x1f) | ((attr & 0x80) >> 2);

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

void strnskil_state::video_start()
{
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(strnskil_state::get_bg_tile_info),this), TILEMAP_SCAN_COLS,
			8, 8, 32, 32);

	m_bg_tilemap->set_scroll_rows(32);
}

void strnskil_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int offs;

	for (offs = 0x60; offs < 0x100; offs += 4)
	{
		int code = m_spriteram[offs + 1];
		int color = m_spriteram[offs + 2] & 0x3f;
		int flipx = flip_screen_x();
		int flipy = flip_screen_y();

		int sx = m_spriteram[offs + 3];
		int sy = m_spriteram[offs];
		int px, py;

		if (flip_screen())
		{
			px = 240 - sx + 0; /* +2 or +0 ? */
			py = sy;
		}
		else
		{
			px = sx - 2;
			py = 240 - sy;
		}

		sx = sx & 0xff;

		if (sx > 248)
			sx = sx - 256;


		m_gfxdecode->gfx(1)->transmask(bitmap,cliprect,
			code, color,
			flipx, flipy,
			px, py,
			m_palette->transpen_mask(*m_gfxdecode->gfx(1), color, 0));
	}
}

uint32_t strnskil_state::screen_update_strnskil(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	const uint8_t *usr1 = memregion("user1")->base();

	for (int row = 0; row < 32; row++)
	{
		if (m_scrl_ctrl != 0x07)
		{
			switch (usr1[m_scrl_ctrl * 32 + row])
			{
			case 2:
				m_bg_tilemap->set_scrollx(row, -~m_xscroll[1]);
				break;
			case 4:
				m_bg_tilemap->set_scrollx(row, -~m_xscroll[0]);
				break;
			}
		}
	}

	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	draw_sprites(bitmap, cliprect);
	return 0;
}