summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/atarifb.c
blob: 6857ca8d35fa6074c47db7f8af963e2de2c7df9d (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
199
200
201
202
203
/*************************************************************************

    Atari Football hardware

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

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


/*************************************
 *
 *  Tilemap callbacks
 *
 *************************************/

static void get_tile_info_common( running_machine &machine, tile_data &tileinfo, tilemap_memory_index tile_index, UINT8 *alpha_videoram )
{
	int code = alpha_videoram[tile_index] & 0x3f;
	int flip = alpha_videoram[tile_index] & 0x40;
	int disable = alpha_videoram[tile_index] & 0x80;

	if (disable)
		code = 0;	/* I *know* this is a space */

	SET_TILE_INFO(0, code, 0, (flip ? TILE_FLIPX | TILE_FLIPY : 0));
}


TILE_GET_INFO_MEMBER(atarifb_state::alpha1_get_tile_info)
{
	get_tile_info_common(machine(), tileinfo, tile_index, m_alphap1_videoram);
}


TILE_GET_INFO_MEMBER(atarifb_state::alpha2_get_tile_info)
{
	get_tile_info_common(machine(), tileinfo, tile_index, m_alphap2_videoram);
}


TILE_GET_INFO_MEMBER(atarifb_state::field_get_tile_info)
{
	int code = m_field_videoram[tile_index] & 0x3f;
	int flipyx = m_field_videoram[tile_index] >> 6;

	SET_TILE_INFO_MEMBER(1, code, 0, TILE_FLIPYX(flipyx));
}




/*************************************
 *
 *  Video RAM writes
 *
 *************************************/

WRITE8_MEMBER(atarifb_state::atarifb_alpha1_videoram_w)
{

	m_alphap1_videoram[offset] = data;
	m_alpha1_tilemap->mark_tile_dirty(offset);
}


WRITE8_MEMBER(atarifb_state::atarifb_alpha2_videoram_w)
{

	m_alphap2_videoram[offset] = data;
	m_alpha2_tilemap->mark_tile_dirty(offset);
}


WRITE8_MEMBER(atarifb_state::atarifb_field_videoram_w)
{

	m_field_videoram[offset] = data;
	m_field_tilemap->mark_tile_dirty(offset);
}



/*************************************
 *
 *  Video system start
 *
 *************************************/

void atarifb_state::video_start()
{

	m_alpha1_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(atarifb_state::alpha1_get_tile_info),this), TILEMAP_SCAN_COLS, 8, 8, 3, 32);
	m_alpha2_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(atarifb_state::alpha2_get_tile_info),this), TILEMAP_SCAN_COLS, 8, 8, 3, 32);
	m_field_tilemap  = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(atarifb_state::field_get_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
}



static void draw_playfield_and_alpha( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int playfield_x_offset, int playfield_y_offset )
{
	atarifb_state *state = machine.driver_data<atarifb_state>();
	const rectangle bigfield_area(4 * 8, 34 * 8 - 1, 0 * 8, 32 * 8 - 1);

	int scroll_x[1];
	int scroll_y[1];

	scroll_x[0] = - *state->m_scroll_register + 32 + playfield_x_offset;
	scroll_y[0] = 8 + playfield_y_offset;

	copybitmap(bitmap, state->m_alpha1_tilemap->pixmap(), 0, 0, 35*8, 1*8, cliprect);
	copybitmap(bitmap, state->m_alpha2_tilemap->pixmap(), 0, 0,  0*8, 1*8, cliprect);
	copyscrollbitmap(bitmap, state->m_field_tilemap->pixmap(),  1, scroll_x, 1, scroll_y, bigfield_area);
}


static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int gfx, int is_soccer )
{
	atarifb_state *state = machine.driver_data<atarifb_state>();
	const rectangle bigfield_area(4 * 8, 34 * 8 - 1, 0 * 8, 32 * 8 - 1);

	int obj;

	for (obj = 0; obj < 16; obj++)
	{
		int charcode;
		int flipx, flipy;
		int sx, sy;
		int shade = 0;

		sy = 255 - state->m_spriteram[obj * 2 + 1];
		if (sy == 255)
			continue;

		charcode = state->m_spriteram[obj * 2] & 0x3f;
		flipx = (state->m_spriteram[obj * 2] & 0x40);
		flipy = (state->m_spriteram[obj * 2] & 0x80);
		sx = state->m_spriteram[obj * 2 + 0x20] + 8 * 3;

		/* Note on Atari Soccer: */
		/* There are 3 sets of 2 bits each, where the 2 bits represent */
		/* black, dk grey, grey and white. I think the 3 sets determine the */
		/* color of each bit in the sprite, but I haven't implemented it that way. */
		if (is_soccer)
		{
			shade = ((state->m_spriteram[obj * 2 + 1 + 0x20]) & 0x07);

			drawgfx_transpen(bitmap, bigfield_area, machine.gfx[gfx + 1],
				charcode, shade,
				flipx, flipy, sx, sy, 0);

			shade = ((state->m_spriteram[obj * 2 + 1 + 0x20]) & 0x08) >> 3;
		}

		drawgfx_transpen(bitmap, bigfield_area, machine.gfx[gfx],
				charcode, shade,
				flipx, flipy, sx, sy, 0);

		/* If this isn't soccer, handle the multiplexed sprites */
		if (!is_soccer)
		{
			/* The down markers are multiplexed by altering the y location during */
			/* mid-screen. We'll fake it by essentially doing the same thing here. */
			if ((charcode == 0x11) && (sy == 0x07))
			{
				sy = 0xf1; /* When multiplexed, it's 0x10...why? */
				drawgfx_transpen(bitmap, bigfield_area, machine.gfx[gfx],
					charcode, 0,
					flipx, flipy, sx, sy, 0);
			}
		}
	}
}


UINT32 atarifb_state::screen_update_atarifb(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	draw_playfield_and_alpha(screen.machine(), bitmap, cliprect, 0, 0);

	draw_sprites(screen.machine(), bitmap, cliprect, 1, 0);

	return 0;
}


UINT32 atarifb_state::screen_update_abaseb(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	draw_playfield_and_alpha(screen.machine(), bitmap, cliprect, -8, 0);

	draw_sprites(screen.machine(), bitmap, cliprect, 1, 0);

	return 0;
}


UINT32 atarifb_state::screen_update_soccer(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	draw_playfield_and_alpha(screen.machine(), bitmap, cliprect, 0, 8);

	draw_sprites(screen.machine(), bitmap, cliprect, 2, 1);

	return 0;
}