summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/video/abc80.c
blob: be7ede0f0cd9f3466fa213c939fcad44e7f8447d (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*****************************************************************************
 *
 * video/abc80.c
 *
 ****************************************************************************/

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



//-------------------------------------------------
//  gfx_layout charlayout
//-------------------------------------------------

static const gfx_layout charlayout =
{
	6, 10,
	128,
	1,
	{ 0 },
	{ 0, 1, 2, 3, 4, 5 },
	{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8 },
	10*8
};


//-------------------------------------------------
//  GFXDECODE( abc80 )
//-------------------------------------------------

static GFXDECODE_START( abc80 )
	GFXDECODE_ENTRY( "chargen", 0,	   charlayout, 0, 2 ) // normal characters
	GFXDECODE_ENTRY( "chargen", 0x500, charlayout, 0, 2 ) // graphics characters
GFXDECODE_END


//-------------------------------------------------
//  update_screen -
//-------------------------------------------------

void abc80_state::update_screen(bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	int c = 0;
	int r = 0;
	int mode = 0;

	for (int y = 0; y < 312; y++)
	{
		UINT8 vsync_data = m_vsync_prom[y];
		UINT8 l = m_line_prom[y];
		int dv = (vsync_data & ABC80_K2_DV) ? 1 : 0;

		if (!(vsync_data & ABC80_K2_FRAME_RESET))
		{
			// reset F2
			r = 0;
		}

		for (int sx = 0; sx < 64; sx++)
		{
			UINT8 hsync_data = m_hsync_prom[sx];
			int dh = (hsync_data & ABC80_K5_DH) ? 1 : 0;
			UINT8 data = 0;

			if (hsync_data & ABC80_K5_LINE_END)
			{
				// reset F4
				c = 0;

				// reset J5
				mode = 0;
			}

			/*

                Video RAM Addressing Scheme

                A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
                R2 R1 R0 xx xx xx xx C2 C1 C0

                A6 A5 A4 A3 = 00 C5 C4 C3 + R4 R3 R4 R3

            */

			int a = (c >> 3) & 0x07;
			int b = ((r >> 1) & 0x0c) | ((r >> 3) & 0x03);
			int s = (a + b) & 0x0f;
			UINT16 videoram_addr = ((r & 0x07) << 7) | (s << 3) | (c & 0x07);
			UINT8 videoram_data = m_latch;
			UINT8 attr_addr = ((dh & dv) << 7) | (videoram_data & 0x7f);
			UINT8 attr_data = m_attr_prom[attr_addr];

			int blank = (attr_data & ABC80_J3_BLANK) ? 1 : 0;
			int j = (attr_data & ABC80_J3_TEXT) ? 1 : 0;
			int k = (attr_data & ABC80_J3_GRAPHICS) ? 1 : 0;
			int versal = (attr_data & ABC80_J3_VERSAL) ? 1 : 0;
			int cursor = (videoram_data & ABC80_CHAR_CURSOR) ? 1 : 0;

			if (!j && k) mode = 0;
			if (j && !k) mode = 1;
			if (j && k) mode = !mode;

			if (mode & versal)
			{
				// graphics mode
				int r0 = 1, r1 = 1, r2 = 1;

				if (l < 3) r0 = 0; else if (l < 7) r1 = 0; else r2 = 0;

				int c0 = BIT(videoram_data, 0) | r0;
				int c1 = BIT(videoram_data, 1) | r0;
				int c2 = BIT(videoram_data, 2) | r1;
				int c3 = BIT(videoram_data, 3) | r1;
				int c4 = BIT(videoram_data, 4) | r2;
				int c5 = BIT(videoram_data, 6) | r2;

				if (!(c0 & c2 & c4)) data |= 0xe0;
				if (!(c1 & c3 & c5)) data |= 0x1c;
			}
			else
			{
				// text mode
				UINT16 chargen_addr = ((videoram_data & 0x7f) * 10) + l;

				data = m_char_rom[chargen_addr];
			}

			// shift out pixels
			for (int bit = 0; bit < 6; bit++)
			{
				int color = BIT(data, 7);
				int x = (sx * 6) + bit;

				color ^= (cursor & m_blink);
				color &= blank;

				bitmap.pix32(y, x) = RGB_MONOCHROME_WHITE[color];

				data <<= 1;
			}

			m_latch = m_video_ram[videoram_addr];

			if (hsync_data & ABC80_K5_ROW_START)
			{
				// clock F4
				c++;
			}
		}

		if (vsync_data & ABC80_K2_FRAME_END)
		{
			// clock F2
			r++;
		}
	}
}


//-------------------------------------------------
//  VIDEO_START( abc80 )
//-------------------------------------------------

void abc80_state::video_start()
{
	screen_device *screen = machine().device<screen_device>(SCREEN_TAG);

	// start timers
	m_pio_timer = timer_alloc(TIMER_ID_PIO);
	m_pio_timer->adjust(screen->time_until_pos(0, 0), 0, screen->scan_period());

	m_blink_timer = timer_alloc(TIMER_ID_BLINK);
	m_blink_timer->adjust(attotime::from_hz(XTAL_11_9808MHz/2/6/64/312/16), 0, attotime::from_hz(XTAL_11_9808MHz/2/6/64/312/16));

	m_vsync_on_timer = timer_alloc(TIMER_ID_VSYNC_ON);
	m_vsync_on_timer->adjust(screen->time_until_pos(0, 0), 0, screen->frame_period());

	m_vsync_off_timer = timer_alloc(TIMER_ID_VSYNC_OFF);
	m_vsync_on_timer->adjust(screen->time_until_pos(16, 0), 0, screen->frame_period());

	// allocate memory
	m_video_ram = auto_alloc_array(machine(), UINT8, 0x400);

	// find memory regions
	m_char_rom = memregion("chargen")->base();
	m_hsync_prom = memregion("hsync")->base();
	m_vsync_prom = memregion("vsync")->base();
	m_line_prom = memregion("line")->base();
	m_attr_prom = memregion("attr")->base();

	// register for state saving
	save_item(NAME(m_blink));
	save_item(NAME(m_latch));
}


//-------------------------------------------------
//  SCREEN_UPDATE_IND16( abc80 )
//-------------------------------------------------

UINT32 abc80_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	update_screen(bitmap, cliprect);

	return 0;
}


//-------------------------------------------------
//  MACHINE_CONFIG_FRAGMENT( abc80_video )
//-------------------------------------------------

MACHINE_CONFIG_FRAGMENT( abc80_video )
	MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
	MCFG_SCREEN_UPDATE_DRIVER(abc80_state, screen_update)

	MCFG_GFXDECODE(abc80)

	MCFG_SCREEN_RAW_PARAMS(XTAL_11_9808MHz/2, ABC80_HTOTAL, ABC80_HBEND, ABC80_HBSTART, ABC80_VTOTAL, ABC80_VBEND, ABC80_VBSTART)
MACHINE_CONFIG_END