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

    Atari "Stella on Steroids" hardware

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

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



/*************************************
 *
 *  Video start/stop
 *
 *************************************/

void beathead_state::video_start()
{
	state_save_register_global(machine(), m_finescroll);
	state_save_register_global(machine(), m_vram_latch_offset);
	state_save_register_global(machine(), m_hsyncram_offset);
	state_save_register_global(machine(), m_hsyncram_start);
	state_save_register_global_array(machine(), m_hsyncram);
}



/*************************************
 *
 *  VRAM handling
 *
 *************************************/

WRITE32_MEMBER( beathead_state::vram_transparent_w )
{
	/* writes to this area appear to handle transparency */
	if (!(data & 0x000000ff)) mem_mask &= ~0x000000ff;
	if (!(data & 0x0000ff00)) mem_mask &= ~0x0000ff00;
	if (!(data & 0x00ff0000)) mem_mask &= ~0x00ff0000;
	if (!(data & 0xff000000)) mem_mask &= ~0xff000000;
	COMBINE_DATA(&m_videoram[offset]);
}


WRITE32_MEMBER( beathead_state::vram_bulk_w )
{
	/* it appears that writes to this area pass in a mask for 4 words in VRAM */
	/* allowing them to be filled from a preset latch */
	offset &= ~3;
	data = data & mem_mask & 0x0f0f0f0f;

	/* for now, just handle the bulk fill case; the others we'll catch later */
	if (data == 0x0f0f0f0f)
		m_videoram[offset+0] = m_videoram[offset+1] = m_videoram[offset+2] = m_videoram[offset+3] = *m_vram_bulk_latch;
	else
		logerror("Detected bulk VRAM write with mask %08x\n", data);
}


WRITE32_MEMBER( beathead_state::vram_latch_w )
{
	/* latch the address */
	m_vram_latch_offset = (4 * offset) & 0x7ffff;
}


WRITE32_MEMBER( beathead_state::vram_copy_w )
{
	/* copy from VRAM to VRAM, for 1024 bytes */
	offs_t dest_offset = (4 * offset) & 0x7ffff;
	memcpy(&m_videoram[dest_offset / 4], &m_videoram[m_vram_latch_offset / 4], 0x400);
}



/*************************************
 *
 *  Scroll offset handling
 *
 *************************************/

WRITE32_MEMBER( beathead_state::finescroll_w )
{
	UINT32 oldword = m_finescroll;
	UINT32 newword = COMBINE_DATA(&m_finescroll);

	/* if VBLANK is going off on a scanline other than the last, suspend time */
	if ((oldword & 8) && !(newword & 8) && space.machine().primary_screen->vpos() != 261)
	{
		logerror("Suspending time! (scanline = %d)\n", space.machine().primary_screen->vpos());
		cputag_set_input_line(space.machine(), "maincpu", INPUT_LINE_HALT, ASSERT_LINE);
	}
}



/*************************************
 *
 *  Palette handling
 *
 *************************************/

WRITE32_MEMBER( beathead_state::palette_w )
{
	int newword = COMBINE_DATA(&m_paletteram[offset]);
	int r = ((newword >> 9) & 0x3e) | ((newword >> 15) & 0x01);
	int g = ((newword >> 4) & 0x3e) | ((newword >> 15) & 0x01);
	int b = ((newword << 1) & 0x3e) | ((newword >> 15) & 0x01);
	palette_set_color_rgb(space.machine(), offset, pal6bit(r), pal6bit(g), pal6bit(b));
}



/*************************************
 *
 *  HSYNC RAM handling
 *
 *************************************/

READ32_MEMBER( beathead_state::hsync_ram_r )
{
	/* offset 0 is probably write-only */
	if (offset == 0)
		logerror("%08X:Unexpected HSYNC RAM read at offset 0\n", cpu_get_previouspc(&space.device()));

	/* offset 1 reads the data */
	else
		return m_hsyncram[m_hsyncram_offset];

	return 0;
}

WRITE32_MEMBER( beathead_state::hsync_ram_w )
{
	/* offset 0 selects the address, and can specify the start address */
	if (offset == 0)
	{
		COMBINE_DATA(&m_hsyncram_offset);
		if (m_hsyncram_offset & 0x800)
			m_hsyncram_start = m_hsyncram_offset & 0x7ff;
	}

	/* offset 1 writes the data */
	else
		COMBINE_DATA(&m_hsyncram[m_hsyncram_offset]);
}



/*************************************
 *
 *  Main screen refresher
 *
 *************************************/

bool beathead_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
{
	UINT8 *videoram = reinterpret_cast<UINT8 *>(m_videoram);
	int x, y;

	/* generate the final screen */
	for (y = cliprect.min_y; y <= cliprect.max_y; y++)
	{
		pen_t pen_base = (*m_palette_select & 0x7f) * 256;
		UINT16 scanline[336];

		/* blanking */
		if (m_finescroll & 8)
			for (x = cliprect.min_x; x <= cliprect.max_x; x++)
				scanline[x] = pen_base;

		/* non-blanking */
		else
		{
			offs_t scanline_offset = m_vram_latch_offset + (m_finescroll & 3);
			offs_t src = scanline_offset + cliprect.min_x;

			/* unswizzle the scanline first */
			for (x = cliprect.min_x; x <= cliprect.max_x; x++)
				scanline[x] = pen_base | videoram[BYTE4_XOR_LE(src++)];
		}

		/* then draw it */
		draw_scanline16(&bitmap, cliprect.min_x, y, cliprect.max_x - cliprect.min_x + 1, &scanline[cliprect.min_x], NULL);
	}
	return 0;
}