summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/electron/mode7.cpp
blob: 103c861c4ae50f81f1d8256b408d8f26a4448715 (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    JAFA Mode 7 Display Unit

    TODO:
      The SAA5050 output is currently being sent to a separate screen, it
      should be output to the same screen as the Electron.
      The Electron video output is 640x312 whereas the SAA5050 output is
      480x500 (doubled vertically to account for interlace). Only one
      output is ever active at any time, which is selected by the MA13
      line from the HD6845.

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


#include "emu.h"
#include "mode7.h"


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

DEFINE_DEVICE_TYPE(ELECTRON_MODE7, electron_mode7_device, "electron_mode7", "JAFA Mode 7 Display Unit")


//-------------------------------------------------
//  ROM( mode7 )
//-------------------------------------------------

ROM_START( mode7 )
	ROM_REGION(0x2000, "exp_rom", 0)
	ROM_SYSTEM_BIOS(0, "191", "Mode 7 OS v1.91")
	ROMX_LOAD("mode7_1.91.rom", 0x0000, 0x2000, CRC(1863bfe6) SHA1(a18c12c8e4bcd5284aac5b0f0a33dc040176084a), ROM_BIOS(0))
	ROM_SYSTEM_BIOS(1, "15", "Mode 7 OS v1.5")
	ROMX_LOAD("mode7_1.5.rom", 0x0000, 0x2000, CRC(eeea69ee) SHA1(3689a6ca8693fa9a6e53a02cf34d613303cb34d7), ROM_BIOS(1))
ROM_END

//-------------------------------------------------
//  INPUT_PORTS( mode7 )
//-------------------------------------------------

static INPUT_PORTS_START( mode7 )
	PORT_START("BUTTON")
	PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("Mode 7 Break") PORT_CODE(KEYCODE_HOME) PORT_CHANGED_MEMBER(DEVICE_SELF, electron_mode7_device, break_button, 0)
INPUT_PORTS_END

//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor electron_mode7_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( mode7 );
}

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

void electron_mode7_device::device_add_mconfig(machine_config &config)
{
	/* video hardware */
	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
	m_screen->set_raw(16_MHz_XTAL, 768, 0, 480, 622, 0, 500);
	m_screen->set_screen_update("hd6845", FUNC(hd6845s_device::screen_update));

	HD6845S(config, m_hd6845, DERIVED_CLOCK(1, 8)); // FIXME: double clock until interlace is implemented
	m_hd6845->set_screen("screen");
	m_hd6845->set_show_border_area(false);
	m_hd6845->set_char_width(12);
	m_hd6845->set_update_row_callback(FUNC(electron_mode7_device::crtc_update_row));
	m_hd6845->out_vsync_callback().set(FUNC(electron_mode7_device::vsync_changed));

	SAA5050(config, m_trom, 6_MHz_XTAL);

	/* pass-through */
	ELECTRON_EXPANSION_SLOT(config, m_exp, DERIVED_CLOCK(1, 1), electron_expansion_devices, nullptr);
	m_exp->irq_handler().set(DEVICE_SELF_OWNER, FUNC(electron_expansion_slot_device::irq_w));
	m_exp->nmi_handler().set(DEVICE_SELF_OWNER, FUNC(electron_expansion_slot_device::nmi_w));
}

const tiny_rom_entry *electron_mode7_device::device_rom_region() const
{
	return ROM_NAME( mode7 );
}

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

//-------------------------------------------------
//  electron_mode7_device - constructor
//-------------------------------------------------

electron_mode7_device::electron_mode7_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, ELECTRON_MODE7, tag, owner, clock)
	, device_electron_expansion_interface(mconfig, *this)
	, m_screen(*this, "screen")
	, m_hd6845(*this, "hd6845")
	, m_trom(*this, "saa5050")
	, m_exp(*this, "exp")
	, m_exp_rom(*this, "exp_rom")
	, m_romsel(0)
{
}

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

void electron_mode7_device::device_start()
{
	m_videoram = make_unique_clear<uint8_t[]>(0x800);

	/* register for save states */
	save_pointer(NAME(m_videoram), 0x800);
	save_item(NAME(m_romsel));
}

//-------------------------------------------------
//  expbus_r - expansion data read
//-------------------------------------------------

uint8_t electron_mode7_device::expbus_r(offs_t offset)
{
	uint8_t data = 0xff;

	if (offset >= 0x7c00 && offset < 0x8000)
	{
		data = m_videoram[offset & 0x3ff];
	}
	else if (offset >= 0x8000 && offset < 0xc000)
	{
		if (m_romsel == 15)
		{
			data = m_exp_rom->base()[offset & 0x1fff];
		}
	}
	else
	{
		switch (offset)
		{
		case 0xfc1e:
			data = m_hd6845->status_r();
			break;
		case 0xfc1f:
			data = m_hd6845->register_r();
			break;
		}
	}

	data &= m_exp->expbus_r(offset);

	return data;
}

//-------------------------------------------------
//  expbus_w - expansion data write
//-------------------------------------------------

void electron_mode7_device::expbus_w(offs_t offset, uint8_t data)
{
	if (offset >= 0x7c00 && offset < 0x8000)
	{
		m_videoram[offset & 0x3ff] = data & 0x7f;
	}
	else
	{
		switch (offset)
		{
		case 0xfc1c:
			m_hd6845->address_w(data);
			break;
		case 0xfc1d:
			m_hd6845->register_w(data);
			break;

		case 0xfe05:
			if ((data & 0xf0) != 0xf0)
				m_romsel = data & 0x0f;
			break;
		}
	}

	m_exp->expbus_w(offset, data);
}


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

MC6845_UPDATE_ROW(electron_mode7_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) & 0x3ff]);

		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(electron_mode7_device::vsync_changed)
{
	m_trom->dew_w(state);
}


INPUT_CHANGED_MEMBER(electron_mode7_device::break_button)
{
	m_slot->nmi_w(!newval);
}