summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/tanbus/ravdu.cpp
blob: 80664797081a1f2115e3282b918ab374b5ccf369 (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    Ralph Allen Colour VDU Card

    http://www.microtan.ukpc.net/6809/Video.pdf

    TODO:
    - use MC6845 screen_update to implement cursor, requires interlace
    - verify whether INHRAM and BE lines are used

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


#include "emu.h"
#include "ravdu.h"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(TANBUS_RAVDU, tanbus_ravdu_device, "tanbus_ravdu", "Ralph Allen Colour VDU Card")


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

void tanbus_ravdu_device::device_add_mconfig(machine_config &config)
{
	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
	m_screen->set_refresh_hz(50);
	m_screen->set_vblank_time(ATTOSECONDS_IN_USEC(2500));
	m_screen->set_size(1536, 624);
	m_screen->set_visarea(0, 972 - 1, 0, 500 - 1);
	//m_screen->set_screen_update("mc6845", FUNC(mc6845_device::screen_update)); // TODO: implement interlace in mc6845
	m_screen->set_screen_update("saa5055", FUNC(saa5055_device::screen_update));

	MC6845(config, m_crtc, DERIVED_CLOCK(1, 4));
	m_crtc->set_screen(nullptr);
	m_crtc->set_show_border_area(false);
	m_crtc->set_char_width(12);
	m_crtc->out_vsync_callback().set(FUNC(tanbus_ravdu_device::vsync_changed));
	m_crtc->set_update_row_callback(FUNC(tanbus_ravdu_device::crtc_update_row));

	SAA5055(config, m_trom, DERIVED_CLOCK(1, 1));
	m_trom->d_cb().set(FUNC(tanbus_ravdu_device::videoram_r));
	m_trom->set_screen_size(81, 25, 81);
}


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

//-------------------------------------------------
//  tanbus_ravdu_device - constructor
//-------------------------------------------------

tanbus_ravdu_device::tanbus_ravdu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, TANBUS_RAVDU, tag, owner, clock)
	, device_tanbus_interface(mconfig, *this)
	, m_screen(*this, "screen")
	, m_crtc(*this, "mc6845")
	, m_trom(*this, "saa5055")
{
}


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

void tanbus_ravdu_device::device_start()
{
	set_clock(m_tanbus->clock());
	m_videoram = std::make_unique<uint8_t[]>(0x800);
	memset(m_videoram.get(), 0xff, sizeof(uint8_t) * 0x800);

	save_pointer(NAME(m_videoram), 0x800);
}

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

void tanbus_ravdu_device::device_reset()
{
}

//-------------------------------------------------
//  read - card read
//-------------------------------------------------

uint8_t tanbus_ravdu_device::read(offs_t offset, int inhrom, int inhram, int be)
{
	uint8_t data = 0xff;

	if ((offset & 0xf800) == 0xe000)
	{
		data = m_videoram[offset & 0x7ff];
	}

	switch (offset)
	{
	case 0xe7fe:
		data = m_crtc->status_r();
		break;
	case 0xe7ff:
		data = m_crtc->register_r();
		break;
	}

	return data;
}

//-------------------------------------------------
//  write - card write
//-------------------------------------------------

void tanbus_ravdu_device::write(offs_t offset, uint8_t data, int inhrom, int inhram, int be)
{
	if ((offset & 0xf800) == 0xe000)
	{
		m_videoram[offset & 0x7ff] = data;
	}

	switch (offset)
	{
	case 0xe7fe:
		m_crtc->address_w(data);
		break;
	case 0xe7ff:
		m_crtc->register_w(data);
		break;
	}
}

//-------------------------------------------------
//  set_inhibit_lines
//-------------------------------------------------

void tanbus_ravdu_device::set_inhibit_lines(offs_t offset, int &inhram, int &inhrom)
{
	if ((offset & 0xf800) == 0xe000)
	{
		inhram = 1;
	}
};

//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

uint8_t tanbus_ravdu_device::videoram_r(offs_t offset)
{
	return m_videoram[offset & 0x7ff];
}

MC6845_UPDATE_ROW(tanbus_ravdu_device::crtc_update_row)
{
	uint32_t *p = &bitmap.pix32(y);

	m_trom->lose_w(1);
	m_trom->lose_w(0);

	for (int column = 0; column < x_count; column++)
	{
		m_trom->write(m_videoram[(ma + column) & 0x7ff]);

		m_trom->f1_w(1);
		m_trom->f1_w(0);

		for (int bit = 0; bit < 12; bit++)
		{
			m_trom->tr6_w(1);
			m_trom->tr6_w(0);

			int col = m_trom->get_rgb() ^ ((column == cursor_x) ? 7 : 0);

			int r = BIT(col, 0) * 0xff;
			int g = BIT(col, 1) * 0xff;
			int b = BIT(col, 2) * 0xff;

			*p++ = rgb_t(r, g, b);
		}
	}
}

WRITE_LINE_MEMBER(tanbus_ravdu_device::vsync_changed)
{
	m_trom->dew_w(state);
}