summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a800/rom.cpp
blob: a32edcc35c6508f1a6084eb9a883b9e50f3d9332 (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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/***********************************************************************************************************

 A800/A5200/XEGS ROM cart emulation

 Basic carts work the same (in addition of being mostly compatible) for all these systems
 and thus we deal with them in a single file

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


#include "emu.h"
#include "rom.h"


//-------------------------------------------------
//  constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(A800_ROM,           a800_rom_device,           "a800_rom",      "Atari 800 ROM Carts")
DEFINE_DEVICE_TYPE(A800_ROM_BBSB,      a800_rom_bbsb_device,      "a800_bbsb",     "Atari 800 ROM Carts BBSB")
DEFINE_DEVICE_TYPE(A800_ROM_WILLIAMS,  a800_rom_williams_device,  "a800_williams", "Atari 800 64K ROM Carts Williams")
DEFINE_DEVICE_TYPE(A800_ROM_EXPRESS,   a800_rom_express_device,   "a800_express",  "Atari 800 64K ROM Carts Express/Diamond")
DEFINE_DEVICE_TYPE(A800_ROM_TURBO,     a800_rom_turbo_device,     "a800_turbo",    "Atari 800 64K ROM Carts Turbosoft")
DEFINE_DEVICE_TYPE(A800_ROM_TELELINK2, a800_rom_telelink2_device, "a800_tlink2",   "Atari 800 64K ROM Cart Telelink II")
DEFINE_DEVICE_TYPE(A800_ROM_MICROCALC, a800_rom_microcalc_device, "a800_sitsa",    "Atari 800 64K ROM Carts SITSA MicroCalc")
DEFINE_DEVICE_TYPE(A800_ROM_CORINA,    a800_rom_corina_device,    "a800_corina",   "Atari 800 ROM Carts Corina 1MB Flash ROM")
DEFINE_DEVICE_TYPE(A800_ROM_CORINA_SRAM, a800_rom_corina_sram_device,    "a800_corina_sram",   "Atari 800 ROM Carts Corina 512KB Flash ROM + 512KB RAM")
DEFINE_DEVICE_TYPE(XEGS_ROM,           xegs_rom_device,           "a800_xegs",     "Atari XEGS 64K ROM Carts")
DEFINE_DEVICE_TYPE(A5200_ROM_2CHIPS,   a5200_rom_2chips_device,   "a5200_16k2c",   "Atari 5200 ROM Cart 16K in 2 Chips")
DEFINE_DEVICE_TYPE(A5200_ROM_BBSB,     a5200_rom_bbsb_device,     "a5200_bbsb",    "Atari 5200 ROM Cart BBSB")


a800_rom_device::a800_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_a800_cart_interface( mconfig, *this )
{
}

a800_rom_device::a800_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM, tag, owner, clock)
{
}


a800_rom_bbsb_device::a800_rom_bbsb_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM_BBSB, tag, owner, clock)
{
}



xegs_rom_device::xegs_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, XEGS_ROM, tag, owner, clock)
	, m_bank(0)
{
}


a800_rom_williams_device::a800_rom_williams_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM_WILLIAMS, tag, owner, clock)
	, m_bank(0)
{
}


a800_rom_express_device::a800_rom_express_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM_EXPRESS, tag, owner, clock)
	, m_bank(0)
{
}


a800_rom_turbo_device::a800_rom_turbo_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM_TURBO, tag, owner, clock)
	, m_bank(0)
{
}


a800_rom_telelink2_device::a800_rom_telelink2_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM_TELELINK2, tag, owner, clock)
{
}


a800_rom_microcalc_device::a800_rom_microcalc_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A800_ROM_MICROCALC, tag, owner, clock)
	, m_bank(0)
{
}

a800_rom_corina_device::a800_rom_corina_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a800_rom_device(mconfig, type, tag, owner, clock)
	, m_rom_bank(0)
	, m_view_select(0)
{
}

a800_rom_corina_device::a800_rom_corina_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a800_rom_device(mconfig, A800_ROM_CORINA, tag, owner, clock)
{
}

a800_rom_corina_sram_device::a800_rom_corina_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a800_rom_corina_device(mconfig, A800_ROM_CORINA_SRAM, tag, owner, clock)
{
}

a5200_rom_2chips_device::a5200_rom_2chips_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A5200_ROM_2CHIPS, tag, owner, clock)
{
}


a5200_rom_bbsb_device::a5200_rom_bbsb_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: a800_rom_device(mconfig, A5200_ROM_BBSB, tag, owner, clock)
{
}




void a800_rom_device::device_start()
{
}

void a800_rom_device::device_reset()
{
}


void a800_rom_bbsb_device::device_start()
{
	save_item(NAME(m_banks));
}

void a800_rom_bbsb_device::device_reset()
{
	m_banks[0] = 0;
	m_banks[1] = 0;
}


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

void xegs_rom_device::device_reset()
{
	m_bank = 0;
}


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

void a800_rom_williams_device::device_reset()
{
	m_bank = 0;
}


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

void a800_rom_express_device::device_reset()
{
	m_bank = 0;
}


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

void a800_rom_turbo_device::device_reset()
{
	m_bank = 0;
}


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

void a800_rom_microcalc_device::device_reset()
{
	m_bank = 0;
}


void a800_rom_corina_device::device_start()
{
	save_item(NAME(m_rom_bank));
	save_item(NAME(m_view_select));
}

void a800_rom_corina_device::device_reset()
{
	m_rom_bank = 0;
	m_view_select = 0;
}


void a5200_rom_bbsb_device::device_start()
{
	save_item(NAME(m_banks));
}

void a5200_rom_bbsb_device::device_reset()
{
	m_banks[0] = 0;
	m_banks[1] = 0;
}



/*-------------------------------------------------
 mapper specific handlers
 -------------------------------------------------*/

/*-------------------------------------------------

 Carts with no bankswitch (8K, 16K)

 The cart accessors are mapped in the correct
 range at driver start

 -------------------------------------------------*/

uint8_t a800_rom_device::read_80xx(offs_t offset)
{
	return m_rom[offset & (m_rom_size - 1)];
}



/*-------------------------------------------------

 Bounty Bob Strikes Back! cart (40K)

 Area 0xa000-0xbfff always point to last 8K bank
 Areas 0x8000-0x8fff and 0x9000-0x9fff are
 separate banks of 4K mapped either in the first
 16K chunk or in the second 16K chunk
 Bankswitch is controlled by data written in
 0x8000-0x8fff and 0x9000-0x9fff respectively

 -------------------------------------------------*/

uint8_t a800_rom_bbsb_device::read_80xx(offs_t offset)
{
	if ((offset & 0x2000) == 0 && !machine().side_effects_disabled())
	{
		uint16_t addr = offset & 0xfff;

		if (addr >= 0xff6 && addr <= 0xff9)
			m_banks[BIT(offset, 12)] = (addr - 0xff6);
	}

	if (offset < 0x1000)
		return m_rom[(offset & 0xfff) + (m_banks[0] * 0x1000) + 0];
	else if (offset < 0x2000)
		return m_rom[(offset & 0xfff) + (m_banks[1] * 0x1000) + 0x4000];
	else
		return m_rom[(offset & 0x1fff) + 0x8000];
}

void a800_rom_bbsb_device::write_80xx(offs_t offset, uint8_t data)
{
	uint16_t addr = offset & 0xfff;
	if (addr >= 0xff6 && addr <= 0xff9)
		m_banks[BIT(offset, 12)] = (addr - 0xff6);
}

/*-------------------------------------------------

 XEGS carts (32K, 64K or 128K)

 Bankswitch is controlled by data written in
 0xd500-0xd5ff

 -------------------------------------------------*/

uint8_t xegs_rom_device::read_80xx(offs_t offset)
{
	if (offset < 0x2000)
		return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
	else
		return m_rom[(offset & 0x1fff) + (m_bank_mask * 0x2000)];   // always last 8K bank

}

void xegs_rom_device::write_d5xx(offs_t offset, uint8_t data)
{
	m_bank = data & m_bank_mask;
}


/*-------------------------------------------------

 Williams 64K

 The rom is accessed in 8K chunks at 0xa000-0xbfff
 Bankswitch is controlled by writing to 7 diff
 offsets (their location varies with the cart type):
 offs 0 points to bank 0, offs 1 points to bank 1,
 and so on... the rom can be disabled by writing to
 the offsets 0x8-0xf of the same range as the bankswitch

 -------------------------------------------------*/

uint8_t a800_rom_williams_device::read_80xx(offs_t offset)
{
	return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
}

void a800_rom_williams_device::write_d5xx(offs_t offset, uint8_t data)
{
	m_bank = (offset & 0x07);
}

/*-------------------------------------------------

 Express 64K / Diamond 64K carts

 The rom is accessed in 8K chunks at 0xa000-0xbfff
 Bankswitch is the same as above, but writes trigger
 banks in reverse order: offs 7 points to bank 0, offs 6
 points to bank 1, and so on... the rom can be disabled
 by writing to the offsets 0x8-0xf of the same range
 as the bankswitch

 -------------------------------------------------*/

uint8_t a800_rom_express_device::read_80xx(offs_t offset)
{
	return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
}

void a800_rom_express_device::write_d5xx(offs_t offset, uint8_t data)
{
	m_bank = (offset ^ 0x07) & 0x0f;
}


/*-------------------------------------------------

 Turbosoft 64K / 128K


 -------------------------------------------------*/

uint8_t a800_rom_turbo_device::read_80xx(offs_t offset)
{
	return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
}

void a800_rom_turbo_device::write_d5xx(offs_t offset, uint8_t data)
{
	m_bank = offset & m_bank_mask;
}


/*-------------------------------------------------

 Telelink II


 -------------------------------------------------*/

uint8_t a800_rom_telelink2_device::read_80xx(offs_t offset)
{
	if (offset >= 0x2000)
		return m_rom[offset & 0x1fff];
	if (offset >= 0x1000 && offset < 0x1100)
		return m_nvram[offset & 0xff];

	return 0xff;
}

void a800_rom_telelink2_device::write_80xx(offs_t offset, uint8_t data)
{
	m_nvram[offset & 0xff] = data | 0xf0;   // low 4bits only
}

uint8_t a800_rom_telelink2_device::read_d5xx(offs_t offset)
{
	// this should affect NVRAM enable / save
	return 0xff;
}

void a800_rom_telelink2_device::write_d5xx(offs_t offset, uint8_t data)
{
	// this should affect NVRAM enable / save
}



/*-------------------------------------------------

 SITSA Microcalc


 -------------------------------------------------*/

uint8_t a800_rom_microcalc_device::read_80xx(offs_t offset)
{
	return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
}

void a800_rom_microcalc_device::write_d5xx(offs_t offset, uint8_t data)
{
	m_bank = data;
}

/*-------------------------------------------------

 Corina

 Comes in two configs:
 - 1MB Flash ROM (yakungfu)
 - 512KB Flash ROM + 512KB SRAM (bombjake)

 Both contains 8KB NVRAM
 -------------------------------------------------*/

uint8_t a800_rom_corina_device::read_view_1(offs_t offset)
{
	return m_rom[(offset & 0x3fff) + (m_rom_bank * 0x4000) + 0x80000];
}

void a800_rom_corina_device::write_view_1(offs_t offset, u8 data)
{
}

uint8_t a800_rom_corina_sram_device::read_view_1(offs_t offset)
{
	return m_ram[(offset & 0x3fff) + (m_rom_bank * 0x4000)];
}

void a800_rom_corina_sram_device::write_view_1(offs_t offset, u8 data)
{
	m_ram[(offset & 0x3fff) + (m_rom_bank * 0x4000)] = data;
}

uint8_t a800_rom_corina_device::read_80xx(offs_t offset)
{
	switch( m_view_select )
	{
		case 0:
			return m_rom[(offset & 0x3fff) + (m_rom_bank * 0x4000)];
		case 1:
			return read_view_1(offset);
		case 2:
			return m_nvram[offset & 0x1fff];
	}

	logerror("view select R=3 [%04x]\n", offset);
	return 0xff;
}

void a800_rom_corina_device::write_80xx(offs_t offset, uint8_t data)
{
	switch( m_view_select )
	{
		case 1:
			write_view_1(offset, data);
			return;
		case 2:
			m_nvram[offset & 0x1fff] = data;
			return;
	}
	// view 0: flash ROM commands?
	// TODO: identify
	logerror("view select W=%d [%04x, %02x] -> %02x\n", m_view_select, offset, m_rom_bank, data);
}

/*
 * 0--- ---- enable Corina window
 * 1--- ---- disable Corina and select main unit 8000-bfff window instead
 * -xx- ---- view select
 * -00- ---- first half of ROM
 * -01- ---- second half of ROM or RAM (^ depending on PCB config)
 * -10- ---- NVRAM
 * -11- ---- <reserved>
 * ---x xxxx ROM/RAM lower bank value,
 *           ignored if view select is not in ROM/RAM mode
 *           or Corina window is disabled
 */
void a800_rom_corina_device::write_d5xx(offs_t offset, uint8_t data)
{
	m_rom_bank = data & 0x1f;
	m_view_select = (data & 0x60) >> 5;
	// TODO: bit 7, currently handled in a400_state
}



// Atari 5200


/*-------------------------------------------------

 Carts with no bankswitch (4K, 8K, 16K, 32K)

 Same as base carts above

 -------------------------------------------------*/

/*-------------------------------------------------

 Carts with 2x8K (16K) with A13 line not connected

 Range 0x4000-0x7fff contains two copies of the low
 8K, range 0x8000-0xbfff contains two copies of the
 high 8K

 -------------------------------------------------*/

uint8_t a5200_rom_2chips_device::read_80xx(offs_t offset)
{
	if (offset < 0x4000)
		return m_rom[offset & 0x1fff];
	else
		return m_rom[(offset & 0x1fff) + 0x2000];
}


/*-------------------------------------------------

 Bounty Bob Strikes Back! cart (40K)

 Similar to the A800 version, but:
 Area 0x8000-0xbfff always point to last 8K bank
 (repeated twice)
 Areas 0x4000-0x4fff and 0x5000-0x5fff are
 separate banks of 4K mapped either in the first
 16K chunk or in the second 16K chunk
 Bankswitch is controlled by data written in
 0x4000-0x4fff and 0x5000-0x5fff respectively

 -------------------------------------------------*/

uint8_t a5200_rom_bbsb_device::read_80xx(offs_t offset)
{
	if ((offset & 0xe000) == 0 && !machine().side_effects_disabled())
	{
		uint16_t addr = offset & 0xfff;
		if (addr >= 0xff6 && addr <= 0xff9)
			m_banks[BIT(offset, 12)] = (addr - 0xff6);
	}

	if (offset < 0x1000)
		return m_rom[(offset & 0xfff) + (m_banks[0] * 0x1000) + 0x2000];
	else if (offset < 0x2000)
		return m_rom[(offset & 0xfff) + (m_banks[1] * 0x1000) + 0x6000];
	else if (offset >= 0x4000)
		return m_rom[(offset & 0x1fff) + 0x0000];
	else
		return 0;
}

void a5200_rom_bbsb_device::write_80xx(offs_t offset, uint8_t data)
{
	uint16_t addr = offset & 0xfff;
	if (addr >= 0xff6 && addr <= 0xff9)
		m_banks[BIT(offset, 12)] = (addr - 0xff6);
}