summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/bbc/rom/pal.cpp
blob: 65987025941ebe689e10969a7c9748b5b9ae01e9 (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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/***************************************************************************

    BBC Micro PALPROM carrier boards

  Computer Concepts PALPROM carrier boards (PAL16R4):
    These were the first to provide a 32K ROM banked into a 16K slot using
    a PAL to perform the switching upon reads from pre-programmed zones. In
    addition to being able to provide larger ROM based applications such
    as Inter-Word and Inter-Base, it also served as copy protection since
    the carrier board and PAL would have to be reproduced to support the
    ROM.
    Other publishers such as Beebug and PMS also used the carrier boards
    and PAL provided by Computer Concepts.

  Watford Electronics PALPROM carrier boards (PAL16L8):
    The PALPROM device provides a means of running 32K software within the
    space allocated to a 16K sideways ROM whilst providing a good degree of
    software protection.
    Within a PALPROM, a 32K EPROM is divided into 4 banks of 8K. These are
    arranged in a 3 plus 1 arrangement. Bank 0, which occupies &8000 to
    &9FFF is permanently enabled, whilst banks 1 to 3, which occupy the
    region &A000 to &BFFF, are swapped in one at a time. This swapping is
    made by performing an access to a special switching zone, of which there
    are 8 in total. Accessing a switching zone, which is 32 bytes in length
    and aligned to start on a 32 byte boundary, selects a pre-specified bank
    (1 to 3)

  P.R.E.S. PALPROM carrier boards:
    This was based on the Computer Concepts carrier board.

  Instant Mini Office 2:
    Not a PALPROM carrier board but a larger ROM carrier containing 4x32K
    and TTL circuits to enable and page each ROM into 16K banks.

  Acornsoft Trilogy Emulator (PAL20R4)
    An unreleased product that combines the View family of ROMs into a
    single banked 64K ROM, using a PAL to perform 16K bank switches upon
    reads from the last 4 bytes of ROM space &BFFC to &BFFF. Only known
    example loaned by Stuart Swales.

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

#include "emu.h"
#include "pal.h"


namespace {

// ======================> bbc_pal_device

class bbc_pal_device : public device_t, public device_bbc_rom_interface
{
protected:
	bbc_pal_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_bbc_rom_interface(mconfig, *this)
		, m_bank(0)
	{
	}

	// device_t overrides
	virtual void device_start() override ATTR_COLD;

	// device_bbc_rom_interface overrides
	virtual uint32_t get_rom_size() override { return 0x4000; }

	uint8_t m_bank;
};


// ======================> bbc_cciword_device

class bbc_cciword_device : public bbc_pal_device
{
public:
	bbc_cciword_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_CCIWORD, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Inter-Word
			switch (offset & 0x3fe0)
			{
			case 0x0060:
			case 0x3fc0: m_bank = 0; break;
			case 0x0040:
			case 0x3fa0:
			case 0x3fe0: m_bank = 1; break;
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 14)];
	}
};


// ======================> bbc_ccibase_device

class bbc_ccibase_device : public bbc_pal_device
{
public:
	bbc_ccibase_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_CCIBASE, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Inter-Base
			switch (offset & 0x3fe0)
			{
			case 0x3f80: m_bank = 0; break;
			case 0x3fa0: m_bank = 1; break;
			case 0x3fc0: m_bank = 2; break;
			case 0x3fe0: m_bank = 3; break;
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 14)];
	}
};


// ======================> bbc_ccispell_device

class bbc_ccispell_device : public bbc_pal_device
{
public:
	bbc_ccispell_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_CCISPELL, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for SpellMaster
			if (offset == 0x3fe0)
			{
				m_bank = 0;
			}
			else if (m_bank == 0)
			{
				switch (offset & 0x3fe0)
				{
				case 0x3fc0: m_bank = 1; break;
				case 0x3fa0: m_bank = 2; break;
				case 0x3f80: m_bank = 3; break;
				case 0x3f60: m_bank = 4; break;
				case 0x3f40: m_bank = 5; break;
				case 0x3f20: m_bank = 6; break;
				case 0x3f00: m_bank = 7; break;
				}
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 14)];
	}
};


// ======================> bbc_palqst_device

class bbc_palqst_device : public bbc_pal_device
{
public:
	bbc_palqst_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_PALQST, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Quest Paint and ConQuest
			switch (offset & 0x3fe0)
			{
			case 0x0820: m_bank = 2; break;
			case 0x11e0: m_bank = 1; break;
			case 0x12c0: m_bank = 3; break;
			case 0x1340: m_bank = 0; break;
			}
		}

		if (offset & 0x2000)
		{
			return get_rom_base()[(offset & 0x1fff) | (m_bank << 13)];
		}
		else
		{
			return get_rom_base()[offset & 0x1fff];
		}
	}
};


// ======================> bbc_palwap_device

class bbc_palwap_device : public bbc_pal_device
{
public:
	bbc_palwap_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_PALWAP, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Wapping Editor
			switch (offset & 0x3fe0)
			{
			case 0x1f00: m_bank = 0; break;
			case 0x1f20: m_bank = 1; break;
			case 0x1f40: m_bank = 2; break;
			case 0x1f60: m_bank = 3; break;
			case 0x1f80: m_bank = 4; break;
			case 0x1fa0: m_bank = 5; break;
			case 0x1fc0: m_bank = 6; break;
			case 0x1fe0: m_bank = 7; break;
			}
		}

		if (offset & 0x2000)
		{
			return get_rom_base()[(offset & 0x1fff) | (m_bank << 13)];
		}
		else
		{
			return get_rom_base()[offset & 0x1fff];
		}
	}
};


// ======================> bbc_palted_device

class bbc_palted_device : public bbc_pal_device
{
public:
	bbc_palted_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_PALTED, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for TED
			switch (offset & 0x3fe0)
			{
			case 0x1f80: m_bank = 0; break;
			case 0x1fa0: m_bank = 1; break;
			case 0x1fc0: m_bank = 2; break;
			case 0x1fe0: m_bank = 3; break;
			}
		}

		if (offset & 0x2000)
		{
			return get_rom_base()[(offset & 0x1fff) | (m_bank << 13)];
		}
		else
		{
			return get_rom_base()[offset & 0x1fff];
		}
	}
};


// ======================> bbc_palabep_device

class bbc_palabep_device : public bbc_pal_device
{
public:
	bbc_palabep_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_PALABEP, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Advanced BASIC Editor Plus
			switch (offset & 0x3ffc)
			{
			case 0x3ff8: m_bank = 0; break;
			case 0x3ffc: m_bank = 1; break;
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 14)];
	}
};


// ======================> bbc_palabe_device

class bbc_palabe_device : public bbc_pal_device
{
public:
	bbc_palabe_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_PALABE, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Advanced BASIC Editor
			switch (offset & 0x3ffc)
			{
			case 0x3ff8: m_bank = 1; break;
			case 0x3ffc: m_bank = 0; break;
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 14)];
	}
};


// ======================> bbc_palmo2_device

class bbc_palmo2_device : public bbc_pal_device
{
public:
	bbc_palmo2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_PALMO2, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Instant Mini Office 2
			switch (offset & 0x3ff0)
			{
			case 0x2000: m_bank = offset & 0x0f; break;
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 13)];
	}
};


// ======================> bbc_trilogy_device

class bbc_trilogy_device : public bbc_pal_device
{
public:
	bbc_trilogy_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: bbc_pal_device(mconfig, BBC_TRILOGY, tag, owner, clock)
	{
	}

protected:
	// device_bbc_rom_interface overrides
	virtual uint8_t read(offs_t offset) override
	{
		if (!machine().side_effects_disabled())
		{
			// switching zones for Acornsoft Trilogy Emulator
			switch (offset & 0x3ff8)
			{
			case 0x3ff8: m_bank = offset & 0x03; break;
			}
		}

		return get_rom_base()[(offset & 0x3fff) | (m_bank << 14)];
	}
};


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

void bbc_pal_device::device_start()
{
	save_item(NAME(m_bank));
}

} // anonymous namespace


DEFINE_DEVICE_TYPE_PRIVATE(BBC_CCIWORD, device_bbc_rom_interface, bbc_cciword_device, "bbc_cciword", "Computer Concepts 32K ROM Carrier (Inter-Word)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_CCIBASE, device_bbc_rom_interface, bbc_ccibase_device, "bbc_ccibase", "Computer Concepts 64K ROM Carrier (Inter-Base)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_CCISPELL, device_bbc_rom_interface, bbc_ccispell_device, "bbc_ccispell", "Computer Concepts 128K ROM Carrier (SpellMaster)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_PALQST, device_bbc_rom_interface, bbc_palqst_device, "bbc_palqst", "Watford Electronics ROM Carrier (Quest Paint)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_PALWAP, device_bbc_rom_interface, bbc_palwap_device, "bbc_palwap", "Watford Electronics ROM Carrier (Wapping Editor)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_PALTED, device_bbc_rom_interface, bbc_palted_device, "bbc_palted", "Watford Electronics ROM Carrier (TED)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_PALABEP, device_bbc_rom_interface, bbc_palabep_device, "bbc_palabep", "P.R.E.S. 32K ROM Carrier (ABE+)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_PALABE, device_bbc_rom_interface, bbc_palabe_device, "bbc_palabe", "P.R.E.S. 32K ROM Carrier (ABE)")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_PALMO2, device_bbc_rom_interface, bbc_palmo2_device, "bbc_palmo2", "Instant Mini Office 2 ROM Carrier")
DEFINE_DEVICE_TYPE_PRIVATE(BBC_TRILOGY, device_bbc_rom_interface, bbc_trilogy_device, "bbc_trilogy", "Acornsoft Trilogy Emulator")