summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a7800/rom.cpp
blob: 362902dbe5175a6c675da95673275b42647e94f4 (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
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/***********************************************************************************************************

 A7800 ROM cart emulation

 For the moment we use separate devices for each combination of hardware
 - bankswitch or not
 - pokey or not
 - 9 banks or not
 etc...
 But we might merge many of these if they become too many

 TODO:
 - Are POKEY regs readable somewhere in SG 144K + POKEY homebrew? How do they detect
   the POKEY otherwise?!?

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


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


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

DEFINE_DEVICE_TYPE(A78_ROM,             a78_rom_device,             "a78_rom",      "Atari 7800 ROM Carts w/no Bankswitch")
DEFINE_DEVICE_TYPE(A78_ROM_SG,          a78_rom_sg_device,          "a78_rom_sg",   "Atari 7800 ROM Carts w/SuperGame Bankswitch")
DEFINE_DEVICE_TYPE(A78_ROM_POKEY,       a78_rom_pokey_device,       "a78_rom_pok",  "Atari 7800 ROM Carts w/no Bankswitch + POKEY")
DEFINE_DEVICE_TYPE(A78_ROM_SG_POKEY,    a78_rom_sg_pokey_device,    "a78_rom_sgp",  "Atari 7800 ROM Carts w/SuperGame Bankswitch + POKEY")
DEFINE_DEVICE_TYPE(A78_ROM_SG_RAM,      a78_rom_sg_ram_device,      "a78_rom_sgr",  "Atari 7800 ROM Carts w/SuperGame Bankswitch + RAM")
DEFINE_DEVICE_TYPE(A78_ROM_MRAM,        a78_rom_mram_device,        "a78_rom_mram", "Atari 7800 ROM Carts + Mirror RAM")
DEFINE_DEVICE_TYPE(A78_ROM_SG9,         a78_rom_sg9_device,         "a78_rom_sg9",  "Atari 7800 ROM Carts w/SuperGame 9Banks")
DEFINE_DEVICE_TYPE(A78_ROM_ABSOLUTE,    a78_rom_abs_device,         "a78_rom_abs",  "Atari 7800 ROM Carts w/Absolute Bankswitch")
DEFINE_DEVICE_TYPE(A78_ROM_ACTIVISION,  a78_rom_act_device,         "a78_rom_act",  "Atari 7800 ROM Carts w/Activision Bankswitch")

DEFINE_DEVICE_TYPE(A78_ROM_P450,        a78_rom_p450_device,        "a78_p450_t0",  "Atari 7800 ROM Carts w/POKEY @ 0x0450")
DEFINE_DEVICE_TYPE(A78_ROM_P450_POKEY,  a78_rom_p450_pokey_device,  "a78_p450_t1",  "Atari 7800 ROM Carts w/no Bankswitch + POKEY + POKEY @ 0x0450")
DEFINE_DEVICE_TYPE(A78_ROM_P450_SG_RAM, a78_rom_p450_sg_ram_device, "a78_p450_t6",  "Atari 7800 ROM Carts w/SuperGame Bankswitch + RAM + POKEY @ 0x0450")
DEFINE_DEVICE_TYPE(A78_ROM_P450_SG9,    a78_rom_p450_sg9_device,    "a78_p450_ta",  "Atari 7800 ROM Carts w/SuperGame 9Banks + POKEY @ 0x0450")


a78_rom_device::a78_rom_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_a78_cart_interface( mconfig, *this )
{
}

a78_rom_device::a78_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, A78_ROM, tag, owner, clock)
{
}

a78_rom_pokey_device::a78_rom_pokey_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, type, tag, owner, clock)
	, m_pokey(*this, "pokey")
{
}

a78_rom_pokey_device::a78_rom_pokey_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_pokey_device(mconfig, A78_ROM_POKEY, tag, owner, clock)
{
}


a78_rom_mram_device::a78_rom_mram_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, type, tag, owner, clock)
{
}

a78_rom_mram_device::a78_rom_mram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_mram_device(mconfig, A78_ROM_MRAM, tag, owner, clock)
{
}

a78_rom_sg_device::a78_rom_sg_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, type, tag, owner, clock)
	, m_bank(0)
{
}

a78_rom_sg_device::a78_rom_sg_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg_device(mconfig, A78_ROM_SG, tag, owner, clock)
{
}

a78_rom_sg_pokey_device::a78_rom_sg_pokey_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg_device(mconfig, A78_ROM_SG_POKEY, tag, owner, clock)
	, m_pokey(*this, "pokey")
{
}


a78_rom_sg_ram_device::a78_rom_sg_ram_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg_device(mconfig, type, tag, owner, clock)
{
}

a78_rom_sg_ram_device::a78_rom_sg_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg_ram_device(mconfig, A78_ROM_SG_RAM, tag, owner, clock)
{
}


a78_rom_sg9_device::a78_rom_sg9_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg_device(mconfig, type, tag, owner, clock)
{
}

a78_rom_sg9_device::a78_rom_sg9_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg9_device(mconfig, A78_ROM_SG9, tag, owner, clock)
{
}


a78_rom_abs_device::a78_rom_abs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, A78_ROM_ABSOLUTE, tag, owner, clock)
	, m_bank(0)
{
}


a78_rom_act_device::a78_rom_act_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, A78_ROM_ACTIVISION, tag, owner, clock)
	, m_bank(0)
{
}



a78_rom_p450_device::a78_rom_p450_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, A78_ROM_P450, tag, owner, clock)
	, m_pokey450(*this, "pokey450")
{
}

a78_rom_p450_pokey_device::a78_rom_p450_pokey_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_pokey_device(mconfig, A78_ROM_P450_POKEY, tag, owner, clock)
	, m_pokey450(*this, "pokey450")
{
}

a78_rom_p450_sg_ram_device::a78_rom_p450_sg_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg_ram_device(mconfig, A78_ROM_P450_SG_RAM, tag, owner, clock)
	, m_pokey450(*this, "pokey450")
{
}

a78_rom_p450_sg9_device::a78_rom_p450_sg9_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_sg9_device(mconfig, A78_ROM_P450_SG9, tag, owner, clock)
	, m_pokey450(*this, "pokey450")
{
}



void a78_rom_device::device_start()
{
}

void a78_rom_device::device_reset()
{
}

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

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

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

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

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

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


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

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

 Carts with no bankswitch (8K to 48K)

 GAMES: Asteroids, Centipede, Dig Dug and many more

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

READ8_MEMBER(a78_rom_device::read_40xx)
{
	if (offset + 0x4000 < m_base_rom)
		return 0xff;
	else
		return m_rom[offset + 0x4000 - m_base_rom];
}

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

 Carts with no bankswitch + POKEY chip
 The Pokey chips is accessed by writing at
 0x4000-0x7fff.

 GAMES: Ballblazer, Beef Drop (homebrew)

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

READ8_MEMBER(a78_rom_pokey_device::read_40xx)
{
	if (offset < 0x4000)
		return m_pokey->read(offset & 0x0f);

	if (offset + 0x4000 < m_base_rom)
		return 0xff;
	else
		return m_rom[offset + 0x4000 - m_base_rom];
}

WRITE8_MEMBER(a78_rom_pokey_device::write_40xx)
{
	if (offset < 0x4000)
		m_pokey->write(offset & 0x0f, data);
}

// TO DO: do we need a PAL variant?!?
void a78_rom_pokey_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "addon").front_center();

	POKEY(config, m_pokey, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "addon", 1.00);
}

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

 Carts with no bankswitch + mRAM chip
 The RAM chips are accessed by writing at
 0x4000-0x7fff.
 The A8 line of the RAM chip isn't used, to create
 mirrors of even pages at odd page locations.

 GAMES: Rescue on Fractalus (proto)

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


READ8_MEMBER(a78_rom_mram_device::read_40xx)
{
	if (offset < 0x4000)
		return m_ram[offset & 0xfeff];
	if (offset + 0x4000 < m_base_rom)
		return 0xff;
	else
		return m_rom[offset + 0x4000 - m_base_rom];
}

WRITE8_MEMBER(a78_rom_mram_device::write_40xx)
{
	if (offset < 0x4000)
		m_ram[offset&0xfeff] = data;
}


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

 Carts with SuperGame bankswitch:
 8 x 16K banks mappable in 0x8000-0xbfff
 bank 7 is always mapped in 0xc000-0xffff
 range 0x4000-0x7fff is not clear: some games
 expect bank 6 to be mapped there, others
 have open bus (we assume the former until
 a game requires more precise behavior or
 some test is run)
 Note that the code is written so that also
 homebrew games with larger ROMs work!

 GAMES: Crack'd, Fatal Run, Ikari Warriors...

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

READ8_MEMBER(a78_rom_sg_device::read_40xx)
{
	if (offset < 0x4000)
		return m_rom[(offset & 0x3fff) + ((m_bank_mask - 1) * 0x4000)]; // second to last bank (is this always ok?!?)
	else if (offset < 0x8000)
		return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
	else
		return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
}

WRITE8_MEMBER(a78_rom_sg_device::write_40xx)
{
	if (offset >= 0x4000 && offset < 0x8000)
		m_bank = data & m_bank_mask;
}


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

 Carts with SuperGame bankswitch + POKEY chip
 As above + Pokey chip access

 GAMES: Commando

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

READ8_MEMBER(a78_rom_sg_pokey_device::read_40xx)
{
	if (offset < 0x4000)
		return m_pokey->read(offset & 0x0f);
	else if (offset < 0x8000)
		return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
	else
		return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
}

WRITE8_MEMBER(a78_rom_sg_pokey_device::write_40xx)
{
	if (offset < 0x4000)
		m_pokey->write(offset & 0x0f, data);
	else if (offset < 0x8000)
		m_bank = data & m_bank_mask;
}

void a78_rom_sg_pokey_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "addon").front_center();

	POKEY(config, m_pokey, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "addon", 1.00);
}


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

 Carts with SuperGame bankswitch + 16K RAM
 FIXME: Some games contained only 8K of RAM, but
 for the moment we treat all as 16K of RAM even if
 from softlist we shall differentiate between them.

 GAMES: Impossible Mission, Jinks and some protos

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

READ8_MEMBER(a78_rom_sg_ram_device::read_40xx)
{
	if (offset < 0x4000)
		return m_ram[offset];
	else if (offset < 0x8000)
		return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
	else
		return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
}

WRITE8_MEMBER(a78_rom_sg_ram_device::write_40xx)
{
	if (offset < 0x4000)
		m_ram[offset] = data;
	else if (offset < 0x8000)
		m_bank = data & m_bank_mask;
}


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

 Carts with SuperGame bankswitch 9banks:
 9 x 16K banks mappable in 0x8000-0xbfff
 bank 7 is always mapped in 0xc000-0xffff

 GAMES: Alien Brigade & Crossbow + some homebrew
 like Donkey Kong XM demo, Bentley Bear's Crystal
 Quest

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

READ8_MEMBER(a78_rom_sg9_device::read_40xx)
{
	if (offset < 0x4000)
		return m_rom[(offset & 0x3fff)];
	else if (offset < 0x8000)
		return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
	else
		return m_rom[(offset & 0x3fff) + ((m_bank_mask + 1) * 0x4000)]; // last bank
}

WRITE8_MEMBER(a78_rom_sg9_device::write_40xx)
{
	if (offset >= 0x4000 && offset < 0x8000)
		m_bank = (data & m_bank_mask) + 1;
}

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

 Carts with Absolute bankswitch:
 64K games. Lower 32K are 2 banks of 16K to be mapped
 in 0x4000-0x7fff, depending on the value written
 at 0x8000. Higher 32K are fixed in 0x8000-0xffff

 GAMES: F-18 Hornet

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

READ8_MEMBER(a78_rom_abs_device::read_40xx)
{
	if (offset < 0x4000)
		return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
	else
	{
		offset -= 0x4000;
		return m_rom[offset + 0x8000];
	}
}

WRITE8_MEMBER(a78_rom_abs_device::write_40xx)
{
	if (offset == 0x4000)
	{
		if (data & 1)
			m_bank = 0;
		else if (data & 2)
			m_bank = 1;
	}
}

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

 Carts with Activision bankswitch:
 128K games. 8 x 16K banks (0-7) to be mapped at
 0xa000-0xdfff. Bank is selected depending on the
 address written in 0xff80-0xff87.
 The rest of the memory is as follows:
 0x4000-0x5fff second 8kb of bank 6
 0x6000-0x7fff first 8kb of bank 6
 0x8000-0x9fff second 8kb of bank 7
 0xe000-0xffff first 8kb of bank 7

 GAMES: Double Dragon, Rampage.

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

READ8_MEMBER(a78_rom_act_device::read_40xx)
{
	uint8_t data = 0xff;
	uint16_t addr = offset & 0x1fff;

	// offset goes from 0 to 0xc000
	switch (offset & 0xe000)
	{
		case 0x0000:
			data = m_rom[addr + 0x1a000];
			break;
		case 0x2000:
			data = m_rom[addr + 0x18000];
			break;
		case 0x4000:
			data = m_rom[addr + 0x1e000];
			break;
		case 0x6000:
			data = m_rom[addr + (m_bank * 0x4000)];
			break;
		case 0x8000:
			data = m_rom[addr + (m_bank * 0x4000) + 0x2000];
			break;
		case 0xa000:
			data = m_rom[addr + 0x1c000];
			break;
	}

	return data;
}

WRITE8_MEMBER(a78_rom_act_device::write_40xx)
{
	if (offset >= 0xbf80 && offset <= 0xbf8f)
		m_bank = offset & 7;
}


// Machine configs for PCB variants with a POKEY at $0450

void a78_rom_p450_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "pokey_450").front_center();

	POKEY(config, m_pokey450, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "pokey_450", 1.00);
}

void a78_rom_p450_pokey_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "addon").front_center();

	POKEY(config, m_pokey, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "addon", 1.00);

	POKEY(config, m_pokey450, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "addon", 1.00);
}


void a78_rom_p450_sg_ram_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "pokey_450").front_center();

	POKEY(config, m_pokey450, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "pokey_450", 1.00);
}

void a78_rom_p450_sg9_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "pokey_450").front_center();

	POKEY(config, m_pokey450, XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "pokey_450", 1.00);
}