summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a2bus/a2ultraterm.cpp
blob: 7b6caa40624355bfe4d50d6fb33dce95031710f4 (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*********************************************************************

    a2ultraterm.c

    Implementation of the Videx UltraTerm 80/132/160-column card

    Notes:

    C0nX: C0n0 is 6845 register address,
          C0n1 is 6845 register data.
          C0n2 is control 1: b7 = 0 to read RAM at cc00, 1 for ROM (writes always to RAM)
                             b6 = 0 for Apple II video, 1 for 6845
                             b5 = 0 for 17.430 MHz 6845 clock, 1 for 28.7595 MHz 6845 clock
                             b4 = 0 for 512 byte RAM block addressing (VideoTerm emulation), 1 for 256-byte RAM page addressing
                             b3-b0 = page select
          C0n3 is control 2: b7 = 0 for attributes software controllable, 1 for DIP switches control attributes
                             b5 = 0 for normal video if bit 7 set, 1 for inverse if bit 7 set
                             b4 = 0 for lowlight if bit 7 set, 1 for highlight if bit 7 set
                             b2 = 0 for high-density character set, 1 for low-density character set
                             b1 = same as b5
                             b0 = same as b4

    C800-CBFF: ROM page 1
    CC00-CFEF: VRAM window or ROM page 2

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

#include "emu.h"
#include "a2ultraterm.h"
#include "screen.h"


/***************************************************************************
    PARAMETERS
***************************************************************************/

//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

DEFINE_DEVICE_TYPE(A2BUS_ULTRATERM,    a2bus_ultraterm_device,    "a2ulttrm", "Videx UltraTerm (original)")
DEFINE_DEVICE_TYPE(A2BUS_ULTRATERMENH, a2bus_ultratermenh_device, "a2ultrme", "Videx UltraTerm (enhanced //e)")

#define ULTRATERM_ROM_REGION  "uterm_rom"
#define ULTRATERM_GFX_REGION  "uterm_gfx"
#define ULTRATERM_SCREEN_NAME "uterm_screen"
#define ULTRATERM_MC6845_NAME "mc6845_uterm"

#define CLOCK_LOW   17430000
#define CLOCK_HIGH  28759500

#define CT1_MEMSEL  (0x80)  // 0 for read RAM at cc00, 1 for read ROM
#define CT1_VIDSEL  (0x40)  // 0 for Apple video passthrough, 1 for 6845 video
#define CT1_CLKSEL  (0x20)  // 0 for Videoterm clock, 1 for faster clock
#define CT1_VTEMU   (0x10)  // Videoterm emulation mode if 0
#define CT1_PAGEMASK (0x0f)

#define CT2_USEDIPS (0x80)  // 0 to use the rest of ctrl2's bits, 1 to use DIPs
#define CT2_INVBIT7H (0x20)
#define CT2_HLBIT7H (0x10)
#define CT2_HIDENSITY (0x04)
#define CT2_INVBIT7L (0x02)
#define CT2_HLBIT7L (0x01)


static const rgb_t ultraterm_palette[4] =
{
	rgb_t(0x00,0x00,0x00),
	rgb_t(0x55,0x55,0x55),
	rgb_t(0xaa,0xaa,0xaa),
	rgb_t(0xff,0xff,0xff)
};


ROM_START( a2ultraterm )
	ROM_REGION(0x1000, ULTRATERM_ROM_REGION, 0)
	ROM_LOAD( "frm_b537.bin", 0x000000, 0x001000, CRC(1e85a93e) SHA1(b4acd1775c08ae43996ab4edf6d8e28f4736346b) )

	ROM_REGION(0x1000, ULTRATERM_GFX_REGION, 0)
	ROM_LOAD( "chs_7859.bin", 0x000000, 0x001000, CRC(ebe8f333) SHA1(3517fa9e7a39573f1cb159b3161d6939dec199ba) )

	ROM_REGION(0x400, "pal", 0)
	ROM_LOAD( "ult_2a313.jed", 0x000000, 0x000305, CRC(dcd51dea) SHA1(0ad0c5e802e48495da27f7bd26ee3ab1c92d74dd) )
ROM_END

ROM_START( a2ultratermenh )
	ROM_REGION(0x1000, ULTRATERM_ROM_REGION, 0)
	ROM_LOAD( "frm_b5c9.bin", 0x000000, 0x001000, CRC(b71e05e0) SHA1(092e3eda4644d4f465809864a7f023ac7d1d1542) )

	ROM_REGION(0x1000, ULTRATERM_GFX_REGION, 0)
	ROM_LOAD( "chs_5604.bin", 0x000000, 0x001000, CRC(3fb4e90a) SHA1(94ff75199232a9b613585c22f88470f73fb7dd09) )

	ROM_REGION(0x400, "pal", 0)
	ROM_LOAD( "ult_251c.jed", 0x000000, 0x000305, CRC(12fabb0d) SHA1(d4a36837cb98bb65f7ddef7455eb5a7f8e648a82) )
ROM_END

/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void a2bus_videx160_device::device_add_mconfig(machine_config &config)
{
	screen_device &screen(SCREEN(config, ULTRATERM_SCREEN_NAME, SCREEN_TYPE_RASTER));
	screen.set_raw(CLOCK_LOW, 882, 0, 720, 370, 0, 350);
	screen.set_screen_update(ULTRATERM_MC6845_NAME, FUNC(mc6845_device::screen_update));

	MC6845(config, m_crtc, CLOCK_LOW/9);
	m_crtc->set_screen(ULTRATERM_SCREEN_NAME);
	m_crtc->set_show_border_area(false);
	m_crtc->set_char_width(8);
	m_crtc->set_update_row_callback(FUNC(a2bus_videx160_device::crtc_update_row));
	m_crtc->out_vsync_callback().set(FUNC(a2bus_videx160_device::vsync_changed));
}

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

const tiny_rom_entry *a2bus_ultraterm_device::device_rom_region() const
{
	return ROM_NAME( a2ultraterm );
}

const tiny_rom_entry *a2bus_ultratermenh_device::device_rom_region() const
{
	return ROM_NAME( a2ultratermenh );
}

//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

a2bus_videx160_device::a2bus_videx160_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, type, tag, owner, clock),
	device_a2bus_card_interface(mconfig, *this), m_rom(nullptr), m_chrrom(nullptr), m_framecnt(0), m_ctrl1(0), m_ctrl2(0),
	m_crtc(*this, ULTRATERM_MC6845_NAME), m_rambank(0)
{
}

a2bus_ultraterm_device::a2bus_ultraterm_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	a2bus_videx160_device(mconfig, A2BUS_ULTRATERM, tag, owner, clock)
{
}

a2bus_ultratermenh_device::a2bus_ultratermenh_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	a2bus_videx160_device(mconfig, A2BUS_ULTRATERMENH, tag, owner, clock)
{
}

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

void a2bus_videx160_device::device_start()
{
	m_rom = machine().root_device().memregion(this->subtag(ULTRATERM_ROM_REGION).c_str())->base();

	m_chrrom = machine().root_device().memregion(this->subtag(ULTRATERM_GFX_REGION).c_str())->base();

	memset(m_ram, 0, 256*16);

	save_item(NAME(m_ram));
	save_item(NAME(m_framecnt));
	save_item(NAME(m_rambank));
	save_item(NAME(m_ctrl1));
	save_item(NAME(m_ctrl2));
}

void a2bus_videx160_device::device_reset()
{
	m_rambank = 0;
	m_framecnt = 0;
}


/*-------------------------------------------------
    read_c0nx - called for reads from this card's c0nx space
-------------------------------------------------*/

uint8_t a2bus_videx160_device::read_c0nx(uint8_t offset)
{
//    printf("%s Read c0n%x\n", machine().describe_context().c_str(), offset);

	if (!(m_ctrl1 & CT1_VTEMU))
	{
		m_rambank = ((offset>>2) & 3) * 512;
	}

	switch (offset)
	{
		case 1:
			return m_crtc->register_r();   // status_r?

		case 2:
			return m_ctrl1;

		case 3:
			return m_ctrl2;
	}

	return 0xff;
}


/*-------------------------------------------------
    write_c0nx - called for writes to this card's c0nx space
-------------------------------------------------*/

void a2bus_videx160_device::write_c0nx(uint8_t offset, uint8_t data)
{
//    printf("%s Write %02x to c0n%x\n", machine().describe_context().c_str(), data, offset);

	switch (offset)
	{
		case 0:
			m_crtc->address_w(data);
			break;

		case 1:
			m_crtc->register_w(data);
			break;

		case 2:
			m_ctrl1 = data;
//          printf("%02x to ctrl1\n", data);

			// if disabling Videoterm emulation, change RAM banking
			if (data & CT1_VTEMU)
			{
				m_rambank = (data & CT1_PAGEMASK) * 256;
			}
			break;

		case 3:
			m_ctrl2 = data;
//          printf("%02x to ctrl2\n", data);
			break;
	}

	if (!(m_ctrl1 & CT1_VTEMU))
	{
		m_rambank = ((offset >> 2) & 3) * 512;
	}
}

/*-------------------------------------------------
    read_cnxx - called for reads from this card's cnxx space
-------------------------------------------------*/

uint8_t a2bus_videx160_device::read_cnxx(uint8_t offset)
{
	return m_rom[offset+(slotno() * 0x100)];
}

/*-------------------------------------------------
    write_cnxx - called for writes to this card's cnxx space
    the firmware writes here to switch in our $C800 a lot
-------------------------------------------------*/
void a2bus_videx160_device::write_cnxx(uint8_t offset, uint8_t data)
{
}

/*-------------------------------------------------
    read_c800 - called for reads from this card's c800 space
-------------------------------------------------*/

uint8_t a2bus_videx160_device::read_c800(uint16_t offset)
{
	// ROM at c800-cbff
	// bankswitched RAM at cc00-cdff
	if (offset < 0x400)
	{
//        printf("Read VRAM at %x = %02x\n", offset+m_rambank, m_ram[offset + m_rambank]);
		return m_rom[offset + 0x800];
	}
	else
	{
		if (m_ctrl1 & CT1_MEMSEL)   // read ROM?
		{
			return m_rom[offset + 0x800];
		}

		return m_ram[(offset - 0x400) + m_rambank];
	}
}

/*-------------------------------------------------
    write_c800 - called for writes to this card's c800 space
-------------------------------------------------*/
void a2bus_videx160_device::write_c800(uint16_t offset, uint8_t data)
{
	if (offset >= 0x400)
	{
//        printf("%02x to VRAM at %x\n", data, offset-0x400+m_rambank);
		m_ram[(offset-0x400) + m_rambank] = data;
	}
}

MC6845_UPDATE_ROW( a2bus_videx160_device::crtc_update_row )
{
	uint32_t  *p = &bitmap.pix32(y);
	uint16_t  chr_base = ra;
	int i;

	for ( i = 0; i < x_count; i++ )
	{
		uint16_t offset = ( ma + i );
		uint8_t chr = m_ram[ offset ];
		uint8_t data = m_chrrom[ chr_base + (chr * 16) ];
		uint8_t fg = 2;
		uint8_t bg = 0;
		uint8_t tmp;

		// apply attributes
		if (!(m_ctrl2 & CT2_USEDIPS))
		{
			// this set and bit 7 in char, highlight
			if ((m_ctrl2 & CT2_HLBIT7H) && (chr & 0x80))
			{
				fg = 3;
				bg = 0;
			}

			// this set and NOT bit 7 in char, highlight
			if ((m_ctrl2 & CT2_HLBIT7L) && (!(chr & 0x80)))
			{
				fg = 3;
				bg = 0;
			}

			// this clear and bit 7 in char, lowlight
			if (!(m_ctrl2 & CT2_HLBIT7H) && (chr & 0x80))
			{
				fg = 1;
				bg = 0;
			}

			// this clear and NOT bit 7 in char, lowlight
			if (!(m_ctrl2 & CT2_HLBIT7L) && (!(chr & 0x80)))
			{
				fg = 1;
				bg = 0;
			}

			// invert last so invert + hilight/invert + lowlight are possible
			// invert if char bit 7 is set
			if ((m_ctrl2 & CT2_INVBIT7H) && (chr & 0x80))
			{
				tmp = fg;
				fg = bg;
				bg = tmp;
			}

			// invert if char bit 7 is clear
			if ((m_ctrl2 & CT2_INVBIT7L) && (!(chr & 0x80)))
			{
				tmp = fg;
				fg = bg;
				bg = tmp;
			}
		}

		if ( i == cursor_x )
		{
			if ( m_framecnt & 0x08 )
			{
				data = 0xFF;
			}
		}

		*p = ultraterm_palette[( data & 0x80 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x40 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x20 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x10 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x08 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x04 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x02 ) ? fg : bg]; p++;
		*p = ultraterm_palette[( data & 0x01 ) ? fg : bg]; p++;
	}
}

WRITE_LINE_MEMBER( a2bus_videx160_device::vsync_changed )
{
	if ( state )
	{
		m_framecnt++;
	}
}