summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/video/z88.c
blob: 0cd28565e781d3ea3732b0213d7f6724901b616d (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
// license:?
// copyright-holders:Kevin Thacker,Sandro Ronco
/***************************************************************************

  z88.c

  Functions to emulate the video hardware of the Cambridge Z88

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

#include "includes/z88.h"


inline void z88_state::plot_pixel(bitmap_ind16 &bitmap, int x, int y, UINT16 color)
{
	if (x<Z88_SCREEN_WIDTH)
		bitmap.pix16(y, x) = color;
}

// convert absolute offset into correct address to get data from
inline UINT8* z88_state::convert_address(UINT32 offset)
{
	return (offset < 0x80000 ? m_bios : m_ram_base) + (offset & 0x7ffff);
}

/***************************************************************************
  Start the video hardware emulation.
***************************************************************************/

// Initialise the palette
void z88_state::palette_init()
{
	palette_set_color(machine(), 0, MAKE_RGB(138, 146, 148));
	palette_set_color(machine(), 1, MAKE_RGB(92,  83,  88));
	palette_set_color(machine(), 2, MAKE_RGB(122, 126, 129));
}

/* temp - change to gfxelement structure */

void z88_state::vh_render_8x8(bitmap_ind16 &bitmap, int x, int y, UINT16 pen0, UINT16 pen1, UINT8 *gfx)
{
	for (int h=0; h<8; h++)
	{
		UINT8 data = gfx[h];

		for (int b=0; b<8; b++)
		{
			plot_pixel(bitmap, x+b, y+h, (data & 0x80) ? pen1 : pen0);

			data = data<<1;
		}
	}
}

void z88_state::vh_render_6x8(bitmap_ind16 &bitmap, int x, int y, UINT16 pen0, UINT16 pen1, UINT8 *gfx)
{
	for (int h=0; h<8; h++)
	{
		UINT8 data = gfx[h]<<2;

		for (int b=0; b<6; b++)
		{
			plot_pixel(bitmap, x+1+b, y+h, (data & 0x80) ? pen1 : pen0);
			data = data<<1;
		}
	}
}

void z88_state::vh_render_line(bitmap_ind16 &bitmap, int x, int y, UINT16 pen)
{
	for (int i=0; i<8; i++)
		plot_pixel(bitmap, x + i, y + 7, pen);
}

void z88_state::lcd_update(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash)
{
	if (sbf == 0)
	{
		// LCD disabled
		bitmap.fill(0);
	}
	else
	{
		UINT8 *vram = convert_address(sbf<<11);

		for (int y=0; y<(Z88_SCREEN_HEIGHT>>3); y++)
		{
			int x = 0, c = 0;

			while (x < Z88_SCREEN_WIDTH)
			{
				UINT16 pen0, pen1;
				UINT8 *char_gfx;
				UINT8 byte0 = vram[(y * 0x100) + c];
				UINT8 byte1 = vram[(y * 0x100) + c + 1];

				// inverted graphics?
				if (byte1 & Z88_SCR_HW_REV)
				{
					pen0 = (byte1 & Z88_SCR_HW_GRY) ? 2 : 1;
					pen1 = 0;
				}
				else
				{
					pen0 = 0;
					pen1 = (byte1 & Z88_SCR_HW_GRY) ? 2 : 1;
				}

				if ((byte1 & Z88_SCR_HW_NULL) == Z88_SCR_HW_NULL)
				{
					// hidden
				}
				else if (!(byte1 & Z88_SCR_HW_HRS) || (((byte1 & Z88_SCR_HW_CURS) == Z88_SCR_HW_CURS)))
				{
					// low-res 6x8
					UINT16 ch = (byte0 | (byte1<<8)) & 0x1ff;

					if ((ch & 0x01c0) == 0x01c0)
					{
						ch &= 0x3f;

						char_gfx = convert_address(lores0<<9);
					}
					else
					{
						char_gfx = convert_address(lores1<<12);
					}

					char_gfx += (ch<<3);

					// cursor flash
					if (flash && (byte1 & Z88_SCR_HW_CURS) == Z88_SCR_HW_CURS)
						vh_render_6x8(bitmap, x,(y<<3), pen1, pen0, char_gfx);
					else
						vh_render_6x8(bitmap, x,(y<<3), pen0, pen1, char_gfx);

					// underline?
					if (byte1 & Z88_SCR_HW_UND)
						vh_render_line(bitmap, x, (y<<3), pen1);

					x += 6;
				}
				else if ((byte1 & Z88_SCR_HW_HRS) && !(byte1 & Z88_SCR_HW_REV))
				{
					// high-res 8x8
					UINT16 ch = (byte0 | (byte1<<8)) & 0x3ff;

					if (ch & 0x0100)
					{
						ch &= 0xff;
						char_gfx = convert_address(hires1<<11);
					}
					else
					{
						ch &= 0xff;
						char_gfx = convert_address(hires0<<13);
					}

					char_gfx += (ch<<3);

					// flash
					if ((byte1 & Z88_SCR_HW_FLS) && flash)
						pen0 = pen1 = 0;

					vh_render_8x8(bitmap, x,(y<<3), pen0, pen1, char_gfx);

					x += 8;
				}

				// every char takes 2 bytes
				c += 2;
			}
		}
	}
}