summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/video/gf4500.c
blob: a8619ea7cc6c9352ff4d26bd4115ada05ad78094 (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
/*

    NVIDIA GoForce 4500

    (c) 2010 Tim Schuerewegen

*/

#include "emu.h"
#include "video/gf4500.h"

#define VERBOSE_LEVEL ( 0 )

INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ...)
{
	if (VERBOSE_LEVEL >= n_level)
	{
		va_list v;
		char buf[32768];
		va_start(v, s_fmt);
		vsprintf(buf, s_fmt, v);
		va_end(v);
		logerror("%s: %s", machine.describe_context(), buf);
	}
}

#define BIT(x,n) (((x)>>(n))&1)
#define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1))

#define GF4500_FRAMEBUF_OFFSET 0x20000


const device_type GF4500 = &device_creator<gf4500_device>;


gf4500_device::gf4500_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
				: device_t(mconfig, GF4500, "NVIDIA GoForce 4500", tag, owner, clock)
{
}


//-------------------------------------------------
//  device_config_complete - perform any
//  operations now that the configuration is
//  complete
//-------------------------------------------------

void gf4500_device::device_config_complete()
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void gf4500_device::device_start()
{
	m_data = auto_alloc_array_clear(machine(), UINT32, 0x140000/4);

	save_pointer(NAME(m_data), 0x140000/4);
	save_item(NAME(m_screen_x));
	save_item(NAME(m_screen_y));
	save_item(NAME(m_screen_x_max));
	save_item(NAME(m_screen_y_max));
	save_item(NAME(m_screen_x_min));
	save_item(NAME(m_screen_y_min));
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void gf4500_device::device_reset()
{
	m_screen_x = m_screen_y = 0;
	m_screen_x_max = m_screen_y_max = m_screen_x_min = m_screen_y_min = 0;
}	


void gf4500_device::vram_write16( UINT16 data )
{
	if ((m_screen_x < m_screen_x_max) && (m_screen_y < m_screen_y_max))
	{
		UINT16 *vram = (UINT16 *)((UINT8 *)m_data + GF4500_FRAMEBUF_OFFSET + (((m_screen_y_min + m_screen_y) * (320 + 1)) + (m_screen_x_min + m_screen_x)) * 2);
		*vram = data;
		m_screen_x++;
	}
}

static rgb_t gf4500_get_color_16( UINT16 data )
{
	UINT8 r, g, b;
	r = BITS(data, 15, 11) << 3;
	g = BITS(data, 10, 5) << 2;
	b = BITS(data, 4, 0) << 3;
	return MAKE_RGB(r, g, b);
}

UINT32 gf4500_device::screen_update(screen_device &device, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	UINT16 *vram = (UINT16 *)(m_data + GF4500_FRAMEBUF_OFFSET / 4);
	int x, y;
	for (y = 0; y < 240; y++)
	{
		UINT32 *scanline = &bitmap.pix32(y);
		for (x = 0; x < 320; x++)
		{
			*scanline++ = gf4500_get_color_16(*vram++);
		}
		vram += 1;
	}
	return 0;
}

READ32_MEMBER( gf4500_device::read )
{
	UINT32 data = m_data[offset];
	switch (offset)
	{
		case 0x4c / 4:
			data = 0x00145000;
			break;
	}
	if ((offset < (GF4500_FRAMEBUF_OFFSET / 4)) || (offset >= ((GF4500_FRAMEBUF_OFFSET + (321 * 240 * 2)) / 4)))
	{
		verboselog(machine(), 9, "(GFO) %08X -> %08X\n", 0x34000000 + (offset << 2), data);
	}
	return data;
}

WRITE32_MEMBER( gf4500_device::write )
{
	COMBINE_DATA(&m_data[offset]);
	if ((offset < (GF4500_FRAMEBUF_OFFSET / 4)) || (offset >= ((GF4500_FRAMEBUF_OFFSET + (321 * 240 * 2)) / 4)))
	{
		verboselog(machine(), 9, "(GFO) %08X <- %08X\n", 0x34000000 + (offset << 2), data);
	}
	switch (offset)
	{
		case 0x300 / 4 :
			m_screen_x = m_screen_y = 0;
			break;
		case 0x304 / 4 :
			m_screen_x_max = (data >>  0) & 0xFFFF;
			m_screen_y_max = (data >> 16) & 0xFFFF;
			if (m_screen_x_max & 1) m_screen_x_min++;
			//if (screen_y_max & 1) screen_y_min++;
			break;
		case 0x308 / 4 :
			m_screen_x_min = (data >>  0) & 0xFFFF;
			m_screen_y_min = (data >> 16) & 0xFFFF;
			if (m_screen_x_min & 1) m_screen_x_min--;
			//if (screen_y_min & 1) screen_y_min--;
			break;
	}
	if ((offset >= (0x200 / 4)) && (offset < (0x280 / 4)))
	{
// 'maincpu' (02996998): (GFO) 34000304 <- 00F00140
// 'maincpu' (029969A8): (GFO) 34000308 <- 00000000
// 'maincpu' (029969B4): (GFO) 34000324 <- 00000000
// 'maincpu' (029969C4): (GFO) 34000328 <- 40000282
// 'maincpu' (029969D4): (GFO) 34000300 <- 001022CC
//
// 'maincpu' (01DCC55C): (GFO) 34000024 -> 00000000
// 'maincpu' (02996A24): (GFO) 34000200 <- AE9FAE9F
//
// 'maincpu' (02996A24): (GFO) 3400027C <- AE9FAE9F
//
// 'maincpu' (01DCC55C): (GFO) 34000024 -> 00000000
// 'maincpu' (02996A24): (GFO) 34000200 <- AE9FAE9F
// ...
// 'maincpu' (02996A24): (GFO) 3400027C <- AE9FAE9F

		vram_write16((data >>  0) & 0xFFFF);
		vram_write16((data >> 16) & 0xFFFF);
		if (m_screen_x >= m_screen_x_max)
		{
			m_screen_x = 0;
			m_screen_y++;
		}
	}
}