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

    Electron 68000 Expansion

    This is a homebrew 68000 second processor for the Electron from around 1990.

    Commands:
    *FX29 - sends a short stub to the 68000 which tells it to:
            (a) start the 68000 OS in ROM now.
            (b) start the 68000 OS on every reset from now on, until the next
                CTRL+BREAK or power cycle.
    *FX28 - tells sideways bank 12 to make itself the current language ROM on the
            6502, and the language entry point tells the 68000 to start the BASIC
            interpreter in ROM, but the 68000 OS has to be currently running.

    BREAK will restart the current language ROM, so will restart 68000 BASIC.
    CTRL+BREAK will go back to 6502 BASIC as the language ROM.

    Usage notes:
    - to enter 68000 BASIC do *FX29, then *FX28, then BREAK.
    - to start the word processor, do CALL&407000 from the 68000 BASIC prompt.
    - to use the assembler, type your assembly code in as a BASIC program, with
      instruction mnemonics in lower case. Set D% to where in RAM you want the
      object code stored and P% to 2, then CALL&401C8C.

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


#include "emu.h"
#include "mc68k.h"
#include "machine/6522via.h"
#include "machine/6850acia.h"
#include "machine/clock.h"
#include "machine/input_merger.h"


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

DEFINE_DEVICE_TYPE(ELECTRON_MC68K, electron_mc68k_device, "electron_mc68k", "Electron 68000 Expansion")



//-------------------------------------------------
//  ADDRESS_MAP( mem_map )
//-------------------------------------------------

void electron_mc68k_device::mem_map(address_map &map)
{
	map(0x000000, 0x00ffff).ram();
	map(0x400000, 0x40ffff).rom().region("main_rom", 0);
	map(0x800000, 0x800fff).rom().region("boot_rom", 0);
	map(0xff8000, 0xff801f).rw("via", FUNC(via6522_device::read), FUNC(via6522_device::write)).umask16(0xff00);
	map(0xff8020, 0xff803f).rw(m_pia[0], FUNC(pia6821_device::read), FUNC(pia6821_device::write)).umask16(0xff00);
	map(0xff8040, 0xff805f).rw("acia", FUNC(acia6850_device::read), FUNC(acia6850_device::write)).umask16(0xff00);
}

//-------------------------------------------------
//  ROM( mc68k )
//-------------------------------------------------

ROM_START( mc68k )
	ROM_REGION(0x8000, "exp_rom", 0)
	ROM_LOAD("elk68k_lower.bin", 0x0000, 0x4000, CRC(6e18f9fb) SHA1(31d228e4b6be18c51dd6a0c42c9e6e1e507decc6))
	ROM_LOAD("elk68k_upper.bin", 0x4000, 0x4000, CRC(0c960571) SHA1(cf3a060fee7ac23128d9e4657790d218681e6e61))

	ROM_REGION16_BE(0x1000, "boot_rom", ROMREGION_ERASE00)
	ROM_LOAD("68kboot.bin", 0x0000, 0x0100, CRC(5855ef60) SHA1(76165ee0f34a24fd2a908987fd5f05e23ea75677))

	ROM_REGION16_BE(0x10000, "main_rom", ROMREGION_ERASE00)
	ROM_LOAD("68kmain.bin", 0x0000, 0x10000, CRC(4d7a9e4f) SHA1(90afb5910995511ae943ad62ea2967eff85e8ef7))
ROM_END


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

void electron_mc68k_device::device_add_mconfig(machine_config &config)
{
	M68000(config, m_maincpu, 10_MHz_XTAL);
	m_maincpu->set_addrmap(AS_PROGRAM, &electron_mc68k_device::mem_map);
	m_maincpu->disable_interrupt_mixer();

	INPUT_MERGER_ANY_HIGH(config, "irq_ipl0").output_handler().set_inputline(m_maincpu, M68K_IRQ_IPL0);
	INPUT_MERGER_ANY_HIGH(config, "irq_ipl1").output_handler().set_inputline(m_maincpu, M68K_IRQ_IPL1);
	INPUT_MERGER_ANY_HIGH(config, "irq_exp").output_handler().set(DEVICE_SELF_OWNER, FUNC(electron_expansion_slot_device::irq_w));

	RAM(config, m_ram).set_default_size("256K").set_extra_options("64K,128K,192K");

	PIA6821(config, m_pia[0], 0);
	m_pia[0]->writepb_handler().set(m_pia[1], FUNC(pia6821_device::set_a_input));
	m_pia[0]->ca2_handler().set(m_pia[1], FUNC(pia6821_device::cb1_w));
	m_pia[0]->cb2_handler().set(m_pia[1], FUNC(pia6821_device::ca1_w));
	m_pia[0]->irqa_handler().set("irq_ipl0", FUNC(input_merger_device::in_w<0>));
	m_pia[0]->irqb_handler().set("irq_ipl0", FUNC(input_merger_device::in_w<1>));

	PIA6821(config, m_pia[1], 0);
	m_pia[1]->writepb_handler().set(m_pia[0], FUNC(pia6821_device::set_a_input));
	m_pia[1]->ca2_handler().set(m_pia[0], FUNC(pia6821_device::cb1_w));
	m_pia[1]->cb2_handler().set(m_pia[0], FUNC(pia6821_device::ca1_w));
	m_pia[1]->irqa_handler().set("irq_exp", FUNC(input_merger_device::in_w<0>));
	m_pia[1]->irqb_handler().set("irq_exp", FUNC(input_merger_device::in_w<1>));

	via6522_device &via(MOS6522(config, "via", 10_MHz_XTAL / 10));
	via.irq_handler().set("irq_ipl1", FUNC(input_merger_device::in_w<0>));

	acia6850_device &acia(ACIA6850(config, "acia", 0));
	acia.irq_handler().set("irq_ipl1", FUNC(input_merger_device::in_w<1>));

	clock_device &acia_clock(CLOCK(config, "acia_clock", 3.6864_MHz_XTAL / 12));
	acia_clock.signal_handler().set("acia", FUNC(acia6850_device::write_txc));
	acia_clock.signal_handler().append("acia", FUNC(acia6850_device::write_rxc));
}

const tiny_rom_entry *electron_mc68k_device::device_rom_region() const
{
	return ROM_NAME( mc68k );
}

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

//-------------------------------------------------
//  electron_mc68k_device - constructor
//-------------------------------------------------

electron_mc68k_device::electron_mc68k_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, ELECTRON_MC68K, tag, owner, clock)
	, device_electron_expansion_interface(mconfig, *this)
	, m_maincpu(*this, "maincpu")
	, m_ram(*this, RAM_TAG)
	, m_pia(*this, "pia%u", 0U)
	, m_boot_rom(*this, "boot_rom")
	, m_exp_rom(*this, "exp_rom")
	, m_romsel(0)
{
}

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

void electron_mc68k_device::device_start()
{
	save_item(NAME(m_romsel));
}

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

void electron_mc68k_device::device_reset()
{
	address_space &program = m_maincpu->space(AS_PROGRAM);

	// address map during booting
	program.install_rom(0x0000, 0x0fff, m_boot_rom->base());

	m_rom_shadow_tap = program.install_read_tap(0x800000, 0xffffff, "rom_shadow_r", [this](offs_t offset, u16 &data, u16 mem_mask)
	{
		if (!machine().side_effects_disabled())
		{
			// delete this tap
			m_rom_shadow_tap->remove();

			// address map after booting
			m_maincpu->space(AS_PROGRAM).install_ram(0x000000, m_ram->mask(), m_ram->pointer());
		}

		// return the original data
		return data;
	});
}

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

u8 electron_mc68k_device::expbus_r(offs_t offset)
{
	u8 data = 0xff;

	switch (offset >> 12)
	{
	case 0x8: case 0x9: case 0xa: case 0xb:
		switch (m_romsel)
		{
		 case 12:
			data = m_exp_rom->base()[0x0000 | (offset & 0x3fff)];
			break;
		case 13:
			data = m_exp_rom->base()[0x4000 | (offset & 0x3fff)];
			break;
		}
		break;

	case 0xf:
		switch (offset >> 8)
		{
		case 0xfd:
			switch (offset & 0xf8)
			{
			case 0x80:
				data = m_pia[1]->read_alt(offset);
				break;
			}
			break;
		}
	}

	return data;
}

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

void electron_mc68k_device::expbus_w(offs_t offset, u8 data)
{
	switch (offset >> 8)
	{
	case 0xfd:
		switch (offset & 0xf8)
		{
		case 0x80:
			m_pia[1]->write_alt(offset, data);
			break;
		}
		break;

	case 0xfe:
		if (offset == 0xfe05)
		{
			m_romsel = data & 0x0f;
		}
		break;
	}
}