summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/capbowl.cpp
blob: f521da6ba035fcc1ff5e5d55c2ac6dab52866141 (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
// license:BSD-3-Clause
// copyright-holders:Zsolt Vasvari
/***************************************************************************

    Coors Light Bowling/Bowl-O-Rama hardware

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

#include "emu.h"
#include "cpu/m6809/m6809.h"
#include "includes/capbowl.h"


/*************************************
 *
 *  TMS34061 I/O
 *
 *************************************/

WRITE8_MEMBER(capbowl_state::tms34061_w)
{
	int func = (offset >> 8) & 3;
	int col = offset & 0xff;

	/* Column address (CA0-CA8) is hooked up the A0-A7, with A1 being inverted
	   during register access. CA8 is ignored */
	if (func == 0 || func == 2)
		col ^= 2;

	/* Row address (RA0-RA8) is not dependent on the offset */
	m_tms34061->write(space, col, *m_rowaddress, func, data);
}


READ8_MEMBER(capbowl_state::tms34061_r)
{
	int func = (offset >> 8) & 3;
	int col = offset & 0xff;

	/* Column address (CA0-CA8) is hooked up the A0-A7, with A1 being inverted
	   during register access. CA8 is ignored */
	if (func == 0 || func == 2)
		col ^= 2;

	/* Row address (RA0-RA8) is not dependent on the offset */
	return m_tms34061->read(space, col, *m_rowaddress, func);
}



/*************************************
 *
 *  Bowl-o-rama blitter
 *
 *************************************/

WRITE8_MEMBER(capbowl_state::bowlrama_blitter_w)
{
	switch (offset)
	{
		case 0x08:    /* Write address high byte (only 2 bits used) */
			m_blitter_addr = (m_blitter_addr & ~0xff0000) | (data << 16);
			break;

		case 0x17:    /* Write address mid byte (8 bits)   */
			m_blitter_addr = (m_blitter_addr & ~0x00ff00) | (data << 8);
			break;

		case 0x18:    /* Write Address low byte (8 bits)   */
			m_blitter_addr = (m_blitter_addr & ~0x0000ff) | (data << 0);
			break;

		default:
			logerror("PC=%04X Write to unsupported blitter address %02X Data=%02X\n", space.device().safe_pc(), offset, data);
			break;
	}
}


READ8_MEMBER(capbowl_state::bowlrama_blitter_r)
{
	uint8_t data = memregion("gfx1")->base()[m_blitter_addr];
	uint8_t result = 0;

	switch (offset)
	{
		/* Read Mask: Graphics data are 4bpp (2 pixels per byte).
		    This function returns 0's for new pixel data.
		    This allows data to be read as a mask, AND the mask with
		    the screen data, then OR new data read by read data command. */
		case 0:
			if (!(data & 0xf0))
				result |= 0xf0;     /* High nibble is transparent */
			if (!(data & 0x0f))
				result |= 0x0f;     /* Low nibble is transparent */
			break;

		/* Read data and increment address */
		case 4:
			result = data;
			m_blitter_addr = (m_blitter_addr + 1) & 0x3ffff;
			break;

		default:
			logerror("PC=%04X Read from unsupported blitter address %02X\n", space.device().safe_pc(), offset);
			break;
	}

	return result;
}



/*************************************
 *
 *  Main refresh
 *
 *************************************/

inline rgb_t capbowl_state::pen_for_pixel( uint8_t *src, uint8_t pix )
{
	return rgb_t(pal4bit(src[(pix << 1) + 0] >> 0),
					pal4bit(src[(pix << 1) + 1] >> 4),
					pal4bit(src[(pix << 1) + 1] >> 0));
}


uint32_t capbowl_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	/* first get the current display state */
	m_tms34061->get_display_state();

	/* if we're blanked, just fill with black */
	if (m_tms34061->m_display.blanked)
	{
		bitmap.erase(cliprect);
		return 0;
	}

	/* now regenerate the bitmap */
	for (int y = cliprect.min_y; y <= cliprect.max_y; y++)
	{
		uint8_t *src = &m_tms34061->m_display.vram[256 * y];
		uint32_t *dest = &bitmap.pix32(y);

		for (int x = cliprect.min_x & ~1; x <= cliprect.max_x; x += 2)
		{
			uint8_t pix = src[32 + (x / 2)];
			*dest++ = pen_for_pixel(src, pix >> 4);
			*dest++ = pen_for_pixel(src, pix & 0x0f);
		}
	}
	return 0;
}