summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/speedspn.cpp
blob: 22d019891452bc9ad69995a7049c16cd2602d5cd (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
// license:BSD-3-Clause
// copyright-holders:David Haywood, Farfetch'd
/* Speed Spin video, see driver file for notes */

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


TILE_GET_INFO_MEMBER(speedspn_state::get_tile_info)
{
	int code = m_vidram[tile_index*2+1] | (m_vidram[tile_index*2] << 8);
	int attr = m_attram[tile_index^0x400];

	SET_TILE_INFO_MEMBER(0,code,attr & 0x3f,(attr & 0x80) ? TILE_FLIPX : 0);
}

void speedspn_state::video_start()
{
	m_display_disable = false;
	m_bank_vidram = 0;
	m_vidram.resize(0x1000 * 2);
	memset(&m_vidram[0], 0, 0x1000*2);
	m_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(speedspn_state::get_tile_info)), TILEMAP_SCAN_COLS, 8, 8, 64, 32);

	save_item(NAME(m_display_disable));
	save_item(NAME(m_bank_vidram));
	save_item(NAME(m_vidram));
}

WRITE8_MEMBER(speedspn_state::vidram_w)
{
	m_vidram[offset + m_bank_vidram] = data;

	if (m_bank_vidram == 0)
		m_tilemap->mark_tile_dirty(offset/2);
}

WRITE8_MEMBER(speedspn_state::attram_w)
{
	m_attram[offset] = data;

	m_tilemap->mark_tile_dirty(offset^0x400);
}

READ8_MEMBER(speedspn_state::vidram_r)
{
	return m_vidram[offset + m_bank_vidram];
}

WRITE8_MEMBER(speedspn_state::vidram_bank_w)
{
//  logerror("VidRam Bank: %04x\n", data);
	m_bank_vidram = data & 1;
	m_bank_vidram *= 0x1000;
}

WRITE8_MEMBER(speedspn_state::display_disable_w)
{
//  logerror("Global display: %u\n", data);
	m_display_disable = data & 1;
}


void speedspn_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect )
{
	gfx_element *gfx = m_gfxdecode->gfx(1);
	uint8_t *source = &m_vidram[0x1000];
	uint8_t *finish = source + 0x1000;

	while( source<finish )
	{
		int xpos = source[0];
		int tileno = source[1];
		int attr = source[2];
		int ypos = source[3];
		int color;

		if (!attr && xpos) break; // end of sprite list marker?

		if (attr&0x10) xpos +=0x100;

		xpos = 0x1f8-xpos;
		tileno += ((attr & 0xe0) >> 5) * 0x100;
		color = attr & 0x0f;

		gfx->transpen(bitmap,cliprect,
				tileno,
				color,
				0,0,
				xpos,ypos,15);

		source +=4;
	}
}


uint32_t speedspn_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_display_disable)
	{
		bitmap.fill(m_palette->black_pen(), cliprect);
		return 0;
	}

#if 0
	{
		FILE* f;
		f = fopen("vidram.bin","wb");
		fwrite(m_vidram, 1, 0x1000 * 2, f);
		fclose(f);
	}
#endif
	m_tilemap->set_scrollx(0, 0x100); // verify
	m_tilemap->draw(screen, bitmap, cliprect, 0,0);
	draw_sprites(bitmap,cliprect);
	return 0;
}