summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/canyon.c
blob: c013e77bc6cbd9c91e72abc0eb81484ddbe12683 (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
/***************************************************************************

Atari Canyon Bomber video emulation

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

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


WRITE8_HANDLER( canyon_videoram_w )
{
	canyon_state *state = space->machine().driver_data<canyon_state>();
	state->m_videoram[offset] = data;
	tilemap_mark_tile_dirty(state->m_bg_tilemap, offset);
}


static TILE_GET_INFO( get_bg_tile_info )
{
	canyon_state *state = machine.driver_data<canyon_state>();
	UINT8 code = state->m_videoram[tile_index];

	SET_TILE_INFO(0, code & 0x3f, code >> 7, 0);
}


VIDEO_START( canyon )
{
	canyon_state *state = machine.driver_data<canyon_state>();

	state->m_bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
}


static void draw_sprites( running_machine &machine, bitmap_t *bitmap, const rectangle* cliprect )
{
	canyon_state *state = machine.driver_data<canyon_state>();
	int i;

	for (i = 0; i < 2; i++)
	{
		int x = state->m_videoram[0x3d0 + 2 * i + 0x1];
		int y = state->m_videoram[0x3d0 + 2 * i + 0x8];
		int c = state->m_videoram[0x3d0 + 2 * i + 0x9];

		drawgfx_transpen(bitmap, cliprect,
			machine.gfx[1],
			c >> 3,
			i,
			!(c & 0x80), 0,
			224 - x,
			240 - y, 0);
	}
}


static void draw_bombs( running_machine &machine, bitmap_t *bitmap, const rectangle* cliprect )
{
	canyon_state *state = machine.driver_data<canyon_state>();
	int i;

	for (i = 0; i < 2; i++)
	{
		int sx = 254 - state->m_videoram[0x3d0 + 2 * i + 0x5];
		int sy = 246 - state->m_videoram[0x3d0 + 2 * i + 0xc];

		rectangle rect;

		rect.min_x = sx;
		rect.min_y = sy;
		rect.max_x = sx + 1;
		rect.max_y = sy + 1;

		if (rect.min_x < cliprect->min_x) rect.min_x = cliprect->min_x;
		if (rect.min_y < cliprect->min_y) rect.min_y = cliprect->min_y;
		if (rect.max_x > cliprect->max_x) rect.max_x = cliprect->max_x;
		if (rect.max_y > cliprect->max_y) rect.max_y = cliprect->max_y;

		bitmap_fill(bitmap, &rect, 1 + 2 * i);
	}
}


SCREEN_UPDATE( canyon )
{
	canyon_state *state = screen->machine().driver_data<canyon_state>();

	tilemap_draw(bitmap, cliprect, state->m_bg_tilemap, 0, 0);

	draw_sprites(screen->machine(), bitmap, cliprect);

	draw_bombs(screen->machine(), bitmap, cliprect);

	/* watchdog is disabled during service mode */
	watchdog_enable(screen->machine(), !(input_port_read(screen->machine(), "IN2") & 0x10));

	return 0;
}