summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/drivers/segapico.c
blob: 607f1ef2a229c9649895b6c17fc835eaf3076771 (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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/****************************************** PICO emulation ****************************************/

/* todo, make this more independent of the Genesis emulation, it's really only the same CPU + VDP
   and doesn't need to be connected to the Genesis at all.

   sound is the 315-5641 / D77591, should be compatible with the 7759? but probably wants us to maintain
   an external buffer of at least 0x40 bytes and feed it on a timer in sync with the timer in the chip?

   currently no way to select (or display) the story book area of the games? (will require layout and
   external artwork)

*/


/*

Pico mainboard (PAL version)

+---+                              +-------------------------------------------------------------------------+
|   |                              |                                    +-+                                  |
|   |                              |                 +--+               |B|        +-+                       |
|   |                              |                 |A3|               +-+        | |                       |
|   +------------------------------+                 +--+                          |C|                     +-|
|                                                                                  | |                     | |
|    GCMK-C2X                                                                      +-+                     | --> PEN
|                                 +-----+     +--+                                                         +-|
|                                 |     |     |A3|            +--------+                                     |
|                                 | A1  |     +--+            |        |              +---------+            |
|          SEGA                   |     |                     |    A2  |              |HM53861J |            |
|     1994 837-10846              +-----+                     |        |              |         |            |
|      IAC MAIN PAL                                           +--------+              +---------+            |
|     MADE IN JAPAN                                                        +----+                            |
|           VA0          +----------+                                      |XTAL|                         +--+
|                        |   SEGA   |         +---------+                  |    |                         |  <-- VCC IN
|                        | 315-5640 |         |MC68HC000|                  |53.2|                         +--+
|                        | 9434 W51 |         |FN8-A    |  +----+          |00  |    +----------+            |
|                        |          |         |         |  |    |          +----+    |   SEGA   |            |
|                        |          |         |  2B89N  |  |    |                    | 315-5313A|            |
|                        |          |         |S0AH9425A|  | A4 |                    |   F1001  |         +--|
|                        +----------+         +---------+  |    |                    |          |         |  |
|                                                          |    |                    |9428 LAGG |         |  --> VIDEO OUT
|                                                          |    |                    |          |         |  |
|                                                          +----+                    +----------+         +--|
|                                                                                                            |
|                                                                     +----------------------------+         |
|                                                                     ||||||CARTRIDGE CONNECTOR|||||         |
|                                                                     +----------------------------+         |
|                                                                                                            |
+------------------------------------------------------------------------------------------------------------+

A1 = SEGA / 315-5641 / D77591 / 9442CA010
A2 = SEGA / 315-5769 U13 / 9451MD020
A3 = BA10324AF
A4 = MALAYSIA 9336 / 651632DFP-15 / 0000988S
B = 4K16 / HC00
C = MB3514 / 9325 M36


315-5640  - touchpad controller?
315-5313A - VDP
315-5641  - PCM chip


*/

/*
   Pico Implementation By ElBarto (Emmanuel Vadot, elbarto@megadrive.org)
   Still missing the PCM custom chip
   Some game will not boot due to this

 Pico Info from Notaz (http://notaz.gp2x.de/docs/picodoc.txt)

 addr   acc   description
-------+-----+------------
800001  byte  Version register.
              ?vv? ????, where v can be:
                00 - hardware is for Japan
                01 - European version
                10 - USA version
                11 - ?
800003  byte  Buttons, 0 for pressed, 1 for released:
                bit 0: UP (white)
                bit 1: DOWN (orange)
                bit 2: LEFT (blue)
                bit 3: RIGHT (green)
                bit 4: red button
                bit 5: unused?
                bit 6: unused?
                bit 7: pen button
800005  byte  Most significant byte of pen x coordinate.
800007  byte  Least significant byte of pen x coordinate.
800009  byte  Most significant byte of pen y coordinate.
80000b  byte  Least significant byte of pen y coordinate.
80000d  byte  Page register. One bit means one uncovered page sensor.
                00 - storyware closed
                01, 03, 07, 0f, 1f, 3f - pages 1-6
                either page 5 or page 6 is often unused.
800010  word  PCM data register.
        r/w   read returns free bytes left in PCM FIFO buffer
              writes write data to buffer.
800012  word  PCM control register.
        r/w   For writes, it has following possible meanings:
              ?p?? ???? ???? ?rrr
                p - set to enable playback?
                r - sample rate / PCM data type?
                  0: 8kHz 4bit ADPCM?
                  1-7: 16kHz variants?
              For reads, if bit 15 is cleared, it means PCM is 'busy' or
              something like that, as games sometimes wait for it to become 1.
800019  byte  Games write 'S'
80001b  byte  Games write 'E'
80001d  byte  Games write 'G'
80001f  byte  Games write 'A'

*/

#include "emu.h"
#include "includes/md_cons.h"
#include "sound/upd7759.h"


#define PICO_PENX   1
#define PICO_PENY   2

class pico_base_state : public md_cons_state
{
public:
	pico_base_state(const machine_config &mconfig, device_type type, const char *tag)
		: md_cons_state(mconfig, type, tag),
	m_upd7759(*this, "7759") { }

	optional_device<upd7759_device> m_upd7759;

	ioport_port *m_io_page;
	ioport_port *m_io_pad;
	ioport_port *m_io_penx;
	ioport_port *m_io_peny;

	UINT8 m_page_register;

	UINT16 pico_read_penpos(int pen);
	DECLARE_READ16_MEMBER(pico_68k_io_read);
	DECLARE_WRITE16_MEMBER(pico_68k_io_write);
	DECLARE_WRITE_LINE_MEMBER(sound_cause_irq);

	DECLARE_DRIVER_INIT(pico);
	DECLARE_DRIVER_INIT(picou);
	DECLARE_DRIVER_INIT(picoj);
};

class pico_state : public pico_base_state
{
public:
	pico_state(const machine_config &mconfig, device_type type, const char *tag)
	: pico_base_state(mconfig, type, tag),
	m_picocart(*this, "picoslot") { }

	required_device<pico_cart_slot_device> m_picocart;
	DECLARE_MACHINE_START(pico);
};



UINT16 pico_base_state::pico_read_penpos(int pen)
{
	UINT16 penpos = 0;

	switch (pen)
	{
		case PICO_PENX:
			penpos = m_io_penx->read_safe(0);
			penpos |= 0x6;
			penpos = penpos * 320 / 255;
			penpos += 0x3d;
			break;
		case PICO_PENY:
			penpos = m_io_peny->read_safe(0);
			penpos |= 0x6;
			penpos = penpos * 251 / 255;
			penpos += 0x1fc;
			break;
	}

	return penpos;
}

READ16_MEMBER(pico_base_state::pico_68k_io_read )
{
	UINT8 retdata = 0;

	switch (offset)
	{
		case 0: /* Version register ?XX?????? where XX is 00 for japan, 01 for europe and 10 for USA*/
			retdata = m_version_hi_nibble;
			break;
		case 1:
			retdata = m_io_pad->read_safe(0);
			break;

			/*
			Still notes from notaz for the pen :

			The pen can be used to 'draw' either on the drawing pad or on the storyware
			itself. Both storyware and drawing pad are mapped on single virtual plane, where
			coordinates range:

			x: 0x03c - 0x17c
			y: 0x1fc - 0x2f7 (drawing pad)
			  0x2f8 - 0x3f3 (storyware)
			*/
		case 2:
			retdata = pico_read_penpos(PICO_PENX) >> 8;
			break;
		case 3:
			retdata = pico_read_penpos(PICO_PENX) & 0x00ff;
			break;
		case 4:
			retdata = pico_read_penpos(PICO_PENY) >> 8;
			break;
		case 5:
			retdata = pico_read_penpos(PICO_PENY) & 0x00ff;
			break;
		case 6:
		/* Page register :
		   00 - storyware closed
		   01, 03, 07, 0f, 1f, 3f - pages 1-6
		   either page 5 or page 6 is often unused.
		*/
			{
				UINT8 tmp = m_io_page->read_safe(0);
				if (tmp == 2 && m_page_register != 0x3f)
				{
					m_page_register <<= 1;
					m_page_register |= 1;
				}
				if (tmp == 1 && m_page_register != 0x00)
					m_page_register >>= 1;
				retdata = m_page_register;
				break;
			}



		case 8: // toy story 2 checks this for 0x3f (is that 'empty'?)
			/* Returns free bytes left in the PCM FIFO buffer */
			retdata = 0x3f;
			break;
		case 9:
		/*
		   For reads, if bit 15 is cleared, it means PCM is 'busy' or
		   something like that, as games sometimes wait for it to become 1.
		*/
			return (m_upd7759->busy_r()^1) << 15;


		case 7:
		case 10:
		case 11:
		case 12:
		case 13:
		case 14:
		case 15:
			logerror("pico_68k_io_read %d\n", offset);

	}

	return retdata | retdata << 8;
}


WRITE_LINE_MEMBER(pico_base_state::sound_cause_irq)
{
//  printf("sound irq\n");
	/* upd7759 callback */
	m_maincpu->set_input_line(3, HOLD_LINE);
}

WRITE16_MEMBER(pico_base_state::pico_68k_io_write )
{
//  printf("pico_68k_io_write %04x %04x %04x\n", offset*2, data, mem_mask);

	switch (offset)
	{
		case 0x12/2: // guess
			m_upd7759->reset_w(0);
			m_upd7759->start_w(0);
			m_upd7759->reset_w(1);
			m_upd7759->start_w(1);

			if (mem_mask&0x00ff) m_upd7759->port_w(space,0,data&0xff);
			if (mem_mask&0xff00) m_upd7759->port_w(space,0,(data>>8)&0xff);

			break;
	}
}

static ADDRESS_MAP_START( pico_mem, AS_PROGRAM, 16, pico_base_state )
	AM_RANGE(0x000000, 0x3fffff) AM_ROM

	AM_RANGE(0x800000, 0x80001f) AM_READWRITE(pico_68k_io_read, pico_68k_io_write)

	AM_RANGE(0xc00000, 0xc0001f) AM_DEVREADWRITE("gen_vdp", sega315_5313_device, vdp_r, vdp_w)
	AM_RANGE(0xe00000, 0xe0ffff) AM_RAM AM_MIRROR(0x1f0000)
ADDRESS_MAP_END


static INPUT_PORTS_START( pico )
	PORT_START("PAD")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1)
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("Red Button")
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("Pen Button")

	PORT_START("PAGE")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("Increment Page")
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("Decrement Page")

	PORT_START("PENX")
	PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(10) PORT_MINMAX(0, 255) PORT_PLAYER(1) PORT_NAME("PEN X")

	PORT_START("PENY")
	PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(10) PORT_MINMAX(0,255 ) PORT_PLAYER(1) PORT_NAME("PEN Y")
INPUT_PORTS_END


static SLOT_INTERFACE_START(pico_cart)
	SLOT_INTERFACE_INTERNAL("rom",  MD_STD_ROM)
	SLOT_INTERFACE_INTERNAL("rom_sram",  MD_ROM_SRAM)   // not sure these are needed...
	SLOT_INTERFACE_INTERNAL("rom_sramsafe",  MD_ROM_SRAM)   // not sure these are needed...
SLOT_INTERFACE_END

MACHINE_START_MEMBER(pico_state,pico)
{
	m_io_page = ioport("PAGE");
	m_io_pad = ioport("PAD");
	m_io_penx = ioport("PENX");
	m_io_peny = ioport("PENY");

	m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7fffff, read16_delegate(FUNC(base_md_cart_slot_device::read),(base_md_cart_slot_device*)m_picocart), write16_delegate(FUNC(base_md_cart_slot_device::write),(base_md_cart_slot_device*)m_picocart));
	m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xa13000, 0xa130ff, read16_delegate(FUNC(base_md_cart_slot_device::read_a13),(base_md_cart_slot_device*)m_picocart), write16_delegate(FUNC(base_md_cart_slot_device::write_a13),(base_md_cart_slot_device*)m_picocart));
	m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xa15000, 0xa150ff, read16_delegate(FUNC(base_md_cart_slot_device::read_a15),(base_md_cart_slot_device*)m_picocart), write16_delegate(FUNC(base_md_cart_slot_device::write_a15),(base_md_cart_slot_device*)m_picocart));
	m_maincpu->space(AS_PROGRAM).install_write_handler(0xa14000, 0xa14003, write16_delegate(FUNC(base_md_cart_slot_device::write_tmss_bank),(base_md_cart_slot_device*)m_picocart));

	m_vdp->stop_timers();
}

static MACHINE_CONFIG_START( pico, pico_state )
	MCFG_FRAGMENT_ADD( md_ntsc )

	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_PROGRAM_MAP(pico_mem)

	MCFG_DEVICE_REMOVE("genesis_snd_z80")

	MCFG_MACHINE_START_OVERRIDE( pico_state, pico )
	MCFG_MACHINE_RESET_OVERRIDE( pico_base_state, ms_megadriv )

	MCFG_PICO_CARTRIDGE_ADD("picoslot", pico_cart, NULL)
	MCFG_SOFTWARE_LIST_ADD("cart_list","pico")

	MCFG_SOUND_ADD("7759", UPD7759, UPD7759_STANDARD_CLOCK)
	MCFG_UPD7759_DRQ_CALLBACK(WRITELINE(pico_state,sound_cause_irq))
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.48)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.48)
MACHINE_CONFIG_END

static MACHINE_CONFIG_START( picopal, pico_state )
	MCFG_FRAGMENT_ADD( md_pal )

	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_PROGRAM_MAP(pico_mem)

	MCFG_DEVICE_REMOVE("genesis_snd_z80")

	MCFG_MACHINE_START_OVERRIDE( pico_state, pico )
	MCFG_MACHINE_RESET_OVERRIDE( pico_base_state, ms_megadriv )

	MCFG_PICO_CARTRIDGE_ADD("picoslot", pico_cart, NULL)
	MCFG_SOFTWARE_LIST_ADD("cart_list","pico")

	MCFG_SOUND_ADD("7759", UPD7759, UPD7759_STANDARD_CLOCK)
	MCFG_UPD7759_DRQ_CALLBACK(WRITELINE(pico_state,sound_cause_irq))
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.48)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.48)
MACHINE_CONFIG_END



ROM_START( pico )
	ROM_REGION(MD_CPU_REGION_SIZE, "maincpu", ROMREGION_ERASEFF)
	ROM_REGION( 0x10000, "soundcpu", ROMREGION_ERASEFF)
ROM_END

ROM_START( picou )
	ROM_REGION(MD_CPU_REGION_SIZE, "maincpu", ROMREGION_ERASEFF)
	ROM_REGION( 0x10000, "soundcpu", ROMREGION_ERASEFF)
ROM_END

ROM_START( picoj )
	ROM_REGION(MD_CPU_REGION_SIZE, "maincpu", ROMREGION_ERASEFF)
	ROM_REGION( 0x10000, "soundcpu", ROMREGION_ERASEFF)
ROM_END


DRIVER_INIT_MEMBER(pico_base_state, pico)
{
	DRIVER_INIT_CALL(megadrie);
	DRIVER_INIT_CALL(mess_md_common);

	m_version_hi_nibble = 0x60; // Export PAL
}

DRIVER_INIT_MEMBER(pico_base_state, picou)
{
	DRIVER_INIT_CALL(megadriv);
	DRIVER_INIT_CALL(mess_md_common);

	m_version_hi_nibble = 0x40; // Export NTSC
}

DRIVER_INIT_MEMBER(pico_base_state, picoj)
{
	DRIVER_INIT_CALL(megadrij);
	DRIVER_INIT_CALL(mess_md_common);

	m_version_hi_nibble = 0x00; // JPN NTSC
}


CONS( 1994, pico,       0,         0,      picopal,         pico, pico_base_state,   pico,    "Sega",   "Pico (Europe, PAL)", GAME_NOT_WORKING)
CONS( 1994, picou,      pico,      0,      pico,            pico, pico_base_state,   picou,   "Sega",   "Pico (USA, NTSC)", GAME_NOT_WORKING)
CONS( 1993, picoj,      pico,      0,      pico,            pico, pico_base_state,   picoj,   "Sega",   "Pico (Japan, NTSC)", GAME_NOT_WORKING)

/*

This looks a lot like a Pico with extra sound hardware...
 YMZ263B is the basis of a Sound Blaster Clone
 YMF262-M is the OPL3

YAMAHA - MIXT BOOK PLAYER COPERA
MMG-1


            +-------------+
            |             |
            |------+      |
            |      |      |
 MIDI OUT <--      |      |
            |      |      |
            |------+      |
            |             |              +------------------------------------------------------------------------------------------------------+
            |------+      |              |                                    +--+                                                              |
            |      |      |              |                                    |YM|                                                              |
  MIDI IN <--      |      |              |                                    |7 |                                                              |
            |      |      |              |                                    |12|                             +---------+                      |
            |------+ +--+ |       +------+                                    |8B|                             | YAMAHA  |                      |
            |        |||| |       |                                           +--+                             | YMZ263B |                      |
            +---------||--+       |                              +--------+                                    |         |                      |
                      ||          |                              |YM7 128B|                                    +---------+    +---+             |
                      ||          |                              +--------+                                                   |YMF|             |
            +---------||----------+                                                                                           |262|             |
            |         ||                                                                                                      |-M |             |
            |         ||                                                                                                      +---+             |
            |         ||                                                                                                                        |
            |         ||                                                           SEGA                                                         |
            |------+  ||                                                 1993 837-9845 COPERA                                                   |
            |      |  ||                                                      MADE IN JAPAN                                                  +--|
            |      |  ||                                                           VA0                                                       |  --> PEN
  CONTROL <--      |  ||                                                                                                                     |  |
            |      |  ||                                                                                                                     +--|
            |      |  ||                                                                                                                        |
            |      |  ||                                                                                                                        |
            |------+  ||                                                                                         +----+                         |
            |         ||                                                                                         |XTAL|  +------------+         |
            |         ||                                                                                         |    |  | OKI JAPAN  |      +----+
            |         ||                                          +----------+                                   |53.6|  | M54C864-80 |      |    |
            |        ||||                                         |   SEGA   |                                   |93  |  +------------+      |    |
            |        +--+                                         | 315-5639 |                                   | Mhz|                      |    |
            |                                                     |       U11|                                   +----+  +-------------+     |  E |
            |                                                     |9341PD025 |                                           |             |     |  X |
            |--+                                                  +----------+                                           |     SEGA    |     |  T |
      MIC <--  |                                                                     +----+  +----+                      |  315-5313A  |     |  E |
            |  |                                                                     |TC51|  |TC51|                      |   FC1001    |     |  N |
            |--+                                                                     |832A|  |832A|                      |  9331 AASG  |     |  D |
            |                                                                        |FL-1|  |FL-1|                      |             |     |  E |
            |                                                                        |0   |  |0   |                      |             |     |  D |
            |                                                                        |    |  |    |                      |             |     |    |
            |--+                                                                     +----+  +----+                      +-------------+     |    |
          +--  |                                                                                                                             |  C |
          | |--+                                                                                                                             |  O |
S-AUDIO <-| |                              +-----------+           +-------+                                                                 |  N |
          | |--+                           |   SEGA    |           | SEGA  |          +-----------+                                          |  N |
          +--  |                           | 315-5640  |           |315-564|          |   3D4 UA  |                                          |  E |
            |--+                           | 9333 W26  |           |1      |          |HD68HC000CP|                                          |  C |
            |                              |           |           |D77591 |          |8          |                                          |  T |
            |--+                           |           |           +-------+          |           |                                          |  O |
  S-VIDEO <--  |                           |           |                              |           |                                          |  R |
            |--+                           |           |                              |           |                                          |    |
            |                              +-----------+                              |      JAPAN|                                          |    |
            |                                                                         +-----------+                                          |    |
            |--+                                                                                                                             |    |
       VCC --> |                                                                      +----------------------------------------------+       |    |
            |--+                                                                      |                  CARTRIDGE                   |       +----+
            |                                                                         |                  CONNECTOR                   |          |
            |                                                                         +----------------------------------------------+          |
            +-----------------------------------------------------------------------------------------------------------------------------------+

*/



class copera_state : public pico_base_state
{
public:
	copera_state(const machine_config &mconfig, device_type type, const char *tag)
	: pico_base_state(mconfig, type, tag),
	m_picocart(*this, "coperaslot") { }

	required_device<copera_cart_slot_device> m_picocart;
	DECLARE_MACHINE_START(copera);
};



static ADDRESS_MAP_START( copera_mem, AS_PROGRAM, 16, copera_state )
	AM_RANGE(0x000000, 0x3fffff) AM_ROM

	AM_RANGE(0x800000, 0x80001f) AM_READWRITE(pico_68k_io_read, pico_68k_io_write)

	AM_RANGE(0xc00000, 0xc0001f) AM_DEVREADWRITE("gen_vdp", sega315_5313_device, vdp_r, vdp_w)

	AM_RANGE(0xe00000, 0xe0ffff) AM_RAM AM_MIRROR(0x1f0000)
ADDRESS_MAP_END



static SLOT_INTERFACE_START(copera_cart)
	SLOT_INTERFACE_INTERNAL("rom",  MD_STD_ROM)
	SLOT_INTERFACE_INTERNAL("rom_sram",  MD_ROM_SRAM)   // not sure these are needed...
	SLOT_INTERFACE_INTERNAL("rom_sramsafe",  MD_ROM_SRAM)   // not sure these are needed...
SLOT_INTERFACE_END

MACHINE_START_MEMBER(copera_state,copera)
{
	m_io_page = ioport("PAGE");
	m_io_pad = ioport("PAD");
	m_io_penx = ioport("PENX");
	m_io_peny = ioport("PENY");

	m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7fffff, read16_delegate(FUNC(base_md_cart_slot_device::read),(base_md_cart_slot_device*)m_picocart), write16_delegate(FUNC(base_md_cart_slot_device::write),(base_md_cart_slot_device*)m_picocart));
	m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xa13000, 0xa130ff, read16_delegate(FUNC(base_md_cart_slot_device::read_a13),(base_md_cart_slot_device*)m_picocart), write16_delegate(FUNC(base_md_cart_slot_device::write_a13),(base_md_cart_slot_device*)m_picocart));
	m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xa15000, 0xa150ff, read16_delegate(FUNC(base_md_cart_slot_device::read_a15),(base_md_cart_slot_device*)m_picocart), write16_delegate(FUNC(base_md_cart_slot_device::write_a15),(base_md_cart_slot_device*)m_picocart));
	m_maincpu->space(AS_PROGRAM).install_write_handler(0xa14000, 0xa14003, write16_delegate(FUNC(base_md_cart_slot_device::write_tmss_bank),(base_md_cart_slot_device*)m_picocart));

	m_upd7759->reset_w(0);
	m_upd7759->start_w(0);
	m_upd7759->reset_w(1);
	m_upd7759->start_w(1);

}

static MACHINE_CONFIG_START( copera, copera_state )
	MCFG_FRAGMENT_ADD( md_ntsc )

	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_PROGRAM_MAP(copera_mem)

	MCFG_DEVICE_REMOVE("genesis_snd_z80")

	MCFG_MACHINE_START_OVERRIDE( copera_state, copera )
	MCFG_MACHINE_RESET_OVERRIDE( pico_base_state, ms_megadriv )

	MCFG_COPERA_CARTRIDGE_ADD("coperaslot", copera_cart, NULL)
	MCFG_SOFTWARE_LIST_ADD("cart_list","copera")

	MCFG_SOUND_ADD("7759", UPD7759, UPD7759_STANDARD_CLOCK)
	MCFG_UPD7759_DRQ_CALLBACK(WRITELINE(copera_state,sound_cause_irq))
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.48)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.48)
MACHINE_CONFIG_END



ROM_START( copera )
	ROM_REGION(MD_CPU_REGION_SIZE, "maincpu", ROMREGION_ERASEFF)
	ROM_REGION( 0x10000, "soundcpu", ROMREGION_ERASEFF)
ROM_END

CONS( 1993, copera,       0,         0,      copera,         pico, pico_base_state,   picoj,    "Yamaha / Sega",   "Yamaha Mixt Book Player Copera", GAME_NOT_WORKING)