summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/drivers/bigfghtr.c
blob: 854f60c479a8b79b3edafa410ea489939876f3c5 (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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/**********************************************************************
Tatakae! Big Fighter (c)1989 Nichibutsu

 based on armedf.c

 TODO:
 - scroll
 - controls
 - dips

    $80600($80000 ?? ) - $80fff  = shared ram with 8751 MCU

    controls :

    02E3E8: move.w  $8c000.l, $8064a.l
    02E3F2: move.w  $8c002.l, $8064c.l
    02E3FC: move.b  #$1, $80640.l
    02E404: move.w  $400000.l, D0
    02E40A: tst.b   $80640.l
    02E410: bne     2e3fc
    02E412: move.w  $80642.l, $8064e.l
    02E41C: move.w  $80644.l, $80650.l
    02E426: move.w  $80646.l, $80652.l - input 1 (80646)
    02E430: move.w  $80648.l, $80654.l
    02E43A: rts


------------------------------------------------------------------------
Tatakae! Big Fighter
Nichibutsu, 1989

This is a horizontal shoot'em-up similar to R-Type.

It appears this PCB is re-used? Sticker says PCB number is 1706 and (C) 1989
On the PCB under the sticker is written 1605 and (C) 1988


PCB Layout
----------


1605A-1 (1706-1)
-------------------------------------------------------------------
|                     2018                                        |
|              6.15F  2018                                        |
|  PROM.13H    5.13F                                              |
|                                                                 |
|                                                                 |
|                            5814                                 |
|                            5814                                 |
|                                                                 |
|                     5814                                        |
|                     5814                                        |
|                                           7.11C                 |
|                                                                 |
|                     6264   6264                                 |
|                     6264   6264                                 |
|                   ----------------                              |
|                   |1706-3        |                              |
|                   |              |                  PAL         |
|                   | PAL  8751    |                              |
|                   |          PAL |                              |
|                   |              |                              |
|                   |              |                  PAL         |
|                   | 2.IC4  4.IC5 |                              |
|                   | 1.IC2  3.IC3 |                              |
| DSW2              |              |                              |
| DSW1              |    68000     |    16MHz         PAL         |
|                   ----------------                              |
-------------------------------------------------------------------


1605B (1706-2)
-------------------------------------------------------------------
|                                                                 |
| 8.17K  Z80A                2018                                 |
|                            2018                                 |
| YM3812  2018               2018                                 |
| Y3014B                                                          |
|                                                                 |
|                                                                 |
|                                                                 |
|                                                                 |
|                                                                 |
|                                                                 |
|                                                                 |
|                                  2018                           |
|                          10.9D   2018                           |
|                           9.8D                          12.8A   |
|                           PAL                           11.6A   |
|                                                                 |
|                                                                 |
|                                                                 |
|                                                                 |
| 2018  2018                                                      |
| 2018  2018                                                      |
|                                                                 |
|               24MHz                                             |
|                                                                 |
-------------------------------------------------------------------


Notes:
      Horizontal Sync: 15.08kHz
        Vertical Sync: 60Hz
            68K Clock: 7.998MHz
            Z80 Clock: ? (unstable, probably 6MHz or less)


**********************************************************************/
#include "emu.h"
#include "cpu/z80/z80.h"
#include "cpu/m68000/m68000.h"
#include "deprecat.h"
#include "sound/dac.h"
#include "sound/okim6295.h"
#include "sound/3812intf.h"


class bigfghtr_state : public driver_device
{
public:
	bigfghtr_state(running_machine &machine, const driver_device_config_base &config)
		: driver_device(machine, config) { }

	/* video-related */
	UINT16 *      text_videoram;
	UINT16 *      bg_videoram;
	UINT16 *      fg_videoram;
	UINT16 *      sharedram;
//  UINT16 *      spriteram;    // currently this uses generic buffer_spriteram_w
//  UINT16 *      paletteram;   // currently this uses generic palette handling

	/* video-related */
	tilemap_t       *bg_tilemap, *fg_tilemap, *tx_tilemap;
	UINT16        fg_scrollx, fg_scrolly;
	UINT16        vreg;
	UINT16        scroll_x, scroll_y;

	/* misc */
	int           read_latch;
	UINT8		  mcu_input_snippet;
	UINT8		  mcu_jsr_snippet;
};


static TILE_GET_INFO( get_fg_tile_info )
{
	bigfghtr_state *state = machine->driver_data<bigfghtr_state>();
	int data = state->fg_videoram[tile_index];
	SET_TILE_INFO(
			1,
			(data & 0x7ff),
			data >> 11,
			0);
}


static TILE_GET_INFO( get_bg_tile_info )
{
	bigfghtr_state *state = machine->driver_data<bigfghtr_state>();
	int data = state->bg_videoram[tile_index];
	SET_TILE_INFO(
			2,
			(data & 0x3ff),
			data >> 11,
			0);
}

static TILE_GET_INFO( get_tx_tile_info )
{
	bigfghtr_state *state = machine->driver_data<bigfghtr_state>();
	int tile_number = state->text_videoram[tile_index] & 0xff;
	int attributes;

	attributes = state->text_videoram[tile_index + 0x800] & 0xff;

	SET_TILE_INFO(
			0,
			tile_number + 256 * (attributes & 0x3),
			attributes >> 4,
			0);
}

static VIDEO_START( bigfghtr )
{
	bigfghtr_state *state = machine->driver_data<bigfghtr_state>();

	state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_cols, 16, 16, 64, 32);
	state->fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_cols, 16, 16, 64, 32);
	state->tx_tilemap = tilemap_create(machine, get_tx_tile_info, tilemap_scan_cols, 8, 8, 64, 32);

	tilemap_set_transparent_pen(state->fg_tilemap, 0xf);
	tilemap_set_transparent_pen(state->tx_tilemap, 0xf);
}

static WRITE16_HANDLER(text_videoram_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	COMBINE_DATA(&state->text_videoram[offset]);
	tilemap_mark_tile_dirty(state->tx_tilemap, offset & 0x7ff);
}

static WRITE16_HANDLER( fg_videoram_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	COMBINE_DATA(&state->fg_videoram[offset]);
	tilemap_mark_tile_dirty(state->fg_tilemap, offset);
}

static WRITE16_HANDLER( bg_videoram_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	COMBINE_DATA(&state->bg_videoram[offset]);
	tilemap_mark_tile_dirty(state->bg_tilemap, offset);
}

static WRITE16_HANDLER( fg_scrollx_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();
	COMBINE_DATA(&state->fg_scrollx);
}

static WRITE16_HANDLER( fg_scrolly_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();
	COMBINE_DATA(&state->fg_scrolly);
}

static WRITE16_HANDLER( bg_scrollx_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	COMBINE_DATA(&state->scroll_x);
	tilemap_set_scrollx(state->bg_tilemap, 0, state->scroll_x);
}

static WRITE16_HANDLER( bg_scrolly_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	COMBINE_DATA(&state->scroll_y);
	tilemap_set_scrolly(state->bg_tilemap, 0, state->scroll_y);
}

static void draw_sprites( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int priority )
{
	UINT16 *buffered_spriteram = machine->generic.buffered_spriteram.u16;
	int offs;
	for (offs = 0; offs < machine->generic.spriteram_size / 2; offs += 4)
	{
		int code = buffered_spriteram[offs + 1]; /* ??YX?TTTTTTTTTTT */
		int flipx = code & 0x2000;
		int flipy = code & 0x1000;
		int color = (buffered_spriteram[offs + 2] >> 8) & 0x1f;
		int sx = buffered_spriteram[offs + 3];
		int sy = 240 - (buffered_spriteram[offs + 0] & 0x1ff);

		if (((buffered_spriteram[offs + 0] & 0x3000) >> 12) == priority)
		{
			drawgfx_transpen(bitmap,cliprect,machine->gfx[3],
				code & 0xfff,
				color,
				flipx,flipy,
				sx,sy,15);
		}
	}
}


static VIDEO_UPDATE( bigfghtr )
{
	bigfghtr_state *state = screen->machine->driver_data<bigfghtr_state>();
	int sprite_enable = state->vreg & 0x200;

	tilemap_set_enable(state->bg_tilemap, state->vreg & 0x800);
	tilemap_set_enable(state->fg_tilemap, state->vreg & 0x400);
	tilemap_set_enable(state->tx_tilemap, state->vreg & 0x100);

	tilemap_set_scrollx(state->fg_tilemap, 0, state->fg_scrollx);
	tilemap_set_scrolly(state->fg_tilemap, 0, state->fg_scrolly);

	if (state->vreg & 0x0800)
		tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0);
	else
		bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine));

	if(sprite_enable)
		draw_sprites(screen->machine, bitmap, cliprect, 2);

	tilemap_draw(bitmap, cliprect, state->fg_tilemap, 0, 0);

	if(sprite_enable)
		draw_sprites(screen->machine, bitmap, cliprect, 1);

	tilemap_draw(bitmap, cliprect, state->tx_tilemap, 0, 0);

	if (sprite_enable)
		draw_sprites(screen->machine, bitmap, cliprect, 0);

	return 0;
}



static VIDEO_EOF( bigfghtr )
{
	address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
	buffer_spriteram16_w(space, 0, 0, 0xffff);
}


static WRITE16_HANDLER( sound_command_w )
{
	if (ACCESSING_BITS_0_7)
		soundlatch_w(space, 0, ((data & 0x7f) << 1) | 1);
}

static WRITE16_HANDLER( io_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	COMBINE_DATA(&state->vreg);
	flip_screen_set(space->machine, state->vreg & 0x1000);
}


static WRITE16_HANDLER( sharedram_w )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();
	COMBINE_DATA(&state->sharedram[offset]);

	switch(offset)
	{
		case 0x40/2:
			state->mcu_input_snippet = (data == 0x100);
			state->mcu_jsr_snippet = (data == 0x300);
			break;
	}
}

static READ16_HANDLER(sharedram_r)
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	if(state->mcu_input_snippet)
	{
		switch(offset+0x600/2)
		{
			case 0x640/2:
				if(state->read_latch)
				{
					state->read_latch = 0;
					return mame_rand(space->machine); // TODO
				}
				break;

			case 0x642/2:
				return (input_port_read(space->machine, "DSW0") & 0xffff) ^ 0xffff;

			case 0x644/2:
				return (input_port_read(space->machine, "DSW1") & 0xffff) ^ 0xffff;

			case 0x646/2:
				return (input_port_read(space->machine, "P1") & 0xffff) ^ 0xffff;

			case 0x648/2:
				return (input_port_read(space->machine, "P2") & 0xffff) ^ 0xffff;
		}
	}

	if(state->mcu_jsr_snippet)
	{
		switch(offset+0x600/2)
		{
			case 0x640/2:
				if(state->read_latch)
				{
					state->read_latch = 0;
					return mame_rand(space->machine); // TODO
				}
				break;
			case 0x642/2:
				return (input_port_read(space->machine, "DSW0") & 0xffff) ^ 0xffff;

			case 0x644/2:
				return (input_port_read(space->machine, "DSW1") & 0xffff) ^ 0xffff;

			case 0x646/2:
				return (input_port_read(space->machine, "P1") & 0xffff) ^ 0xffff;

			case 0x648/2:
				return (input_port_read(space->machine, "P2") & 0xffff) ^ 0xffff;

			/*
            protection controls where the program code should jump to.

            example snippet:
            00DB2A: 41FA FE86                  lea     (-$17a,PC), A0; ($d9b2) ;base program vector
            00DB2E: 4DF9 0008 0E2A             lea     $80e2a.l, A6 ;base RAM vector, used by the i8751 to send the value, this value is added to the above A0
            00DB34: 3039 0008 0E62             move.w  $80e62.l, D0 ;number of snippets to execute
            00DB3A: 6100 00F0                  bsr     $dc2c
            */

			/* bp daee, A0 = 0xdd02, A6 = 0x808ca, D0 = 0x80902 */
			//case 0x902/2:
			//  return 0x0001;
			//case (0x90a+0x24)/2:
			//  return 0x0001;
			//case (0x902+8)/2:
			//  return 0x0004; // 0xf86a

			/* bp db02, A0 = 0xdc2e, A6 = 0x80912, D0 = 0x8094a */
			//case 0x94a/2:
			//  return 1;
			//case (0x94a+8)/2:
			//  return 0x00dc; // 0xd62e

			/* bp db16, A0 = 0xda86, A6 = 0x80c22, D0 = 0x80c5a */
			//case 0xc5a/2:
			//  return 1;
			//case (0xc5a+8)/2:
			//  return 0x0288; // 0x345f4

			/* bp db2a, A0 = 0xd9b2, A6 = 0x80e2a, D0 = 0x80e62 */

			/* bp db3e, A0 = 0xd8da, A6 = 0x81132, D0 = 0x8116a */

			/* bp db52, A0 = 0xd806, A6 = 0x8133a, D0 = 0x81372 */

			/* bp db66, A0 = 0xd7aa, A6 = 0x81742, D0 = 0x8177a */

			/* bp db7a, A0 = 0xd746, A6 = 0x81b4a, D0 = 0x81b82 */

			/* bp db8e, A0 = 0xd672, A6 = 0x81f52, D0 = 0x81f8a */

			/* bp dba4, A0 = 0xd5ae, A6 = 0x8205a, D0 = 0x82092 */

			/* bp dbba, A0 = 0xd5be, A6 = 0x82862, D0 = 0x8289a */

			/* bp dbd0, A0 = 0xd512, A6 = 0x8296a, D0 = 0x829a2 */

			/* bp dbe6, A0 = 0xd466, A6 = 0x82d72, D0 = 0x82daa */

			/* bp dbfc, A0 = 0xd43e, A6 = 0x8357a, D0 = 0x835b2 */

			/* following is separated from the others, dunno why ... */
			/* bp dc14, A0 = 0xd3aa, A6 = 0x835a2, D0 = 0x835b2 */


			/*case 0x
            case 0x94a/2:
                return 0x0002*4;
            case (0x90a+2*0x40)/2:
            case (0x90a+3*0x40)/2:
                return 0x0003*4;
            case (0x90a+4*0x40)/2:
                return 0x000c*4; // 0x13d74
            case (0x90a+5*0x40)/2:
                return 0x000d*4; // 0x130f6
            case (0x90a+6*0x40)/2:
                return 0x000e*4; // 0x1817e
            case (0x90a+7*0x40)/2:
                return 0x0010*4; // 0x15924
            //case (0x90a+0x25)/2:
            //  return 2;*/
		}
	}

	return state->sharedram[offset];
}

static READ16_HANDLER( latch_r )
{
	bigfghtr_state *state = space->machine->driver_data<bigfghtr_state>();

	state->read_latch = 1;
	return 0;
}

static ADDRESS_MAP_START( mainmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_ROM
	AM_RANGE(0x080000, 0x0805ff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram)
	AM_RANGE(0x080600, 0x083fff) AM_READWRITE(sharedram_r, sharedram_w) AM_BASE_MEMBER(bigfghtr_state, sharedram)
	AM_RANGE(0x084000, 0x085fff) AM_RAM //??
	AM_RANGE(0x086000, 0x086fff) AM_RAM_WRITE(bg_videoram_w) AM_BASE_MEMBER(bigfghtr_state, bg_videoram)
	AM_RANGE(0x087000, 0x087fff) AM_RAM_WRITE(fg_videoram_w) AM_BASE_MEMBER(bigfghtr_state, fg_videoram)
	AM_RANGE(0x088000, 0x089fff) AM_RAM_WRITE(text_videoram_w) AM_BASE_MEMBER(bigfghtr_state, text_videoram)
	AM_RANGE(0x08a000, 0x08afff) AM_RAM_WRITE(paletteram16_xxxxRRRRGGGGBBBB_word_w) AM_BASE_GENERIC(paletteram)
	AM_RANGE(0x08b000, 0x08bfff) AM_RAM //??
	AM_RANGE(0x08c000, 0x08c001) AM_READ_PORT("P1")
	AM_RANGE(0x08c002, 0x08c003) AM_READ_PORT("P2")
	AM_RANGE(0x08c004, 0x08c005) AM_READ_PORT("DSW0")
	AM_RANGE(0x08c006, 0x08c007) AM_READ_PORT("DSW1")

	AM_RANGE(0x08d000, 0x08d001) AM_WRITE(io_w) 				//807b0

	AM_RANGE(0x08d002, 0x08d003) AM_WRITE(bg_scrollx_w) //8069a
	AM_RANGE(0x08d004, 0x08d005) AM_WRITE(bg_scrolly_w) //80696
	AM_RANGE(0x08d006, 0x08d007) AM_WRITE(fg_scrollx_w) //80692
	AM_RANGE(0x08d008, 0x08d009) AM_WRITE(fg_scrolly_w) //8068e

	AM_RANGE(0x08d00a, 0x08d00b) AM_WRITE(sound_command_w)
	AM_RANGE(0x400000, 0x400001) AM_READ(latch_r)
ADDRESS_MAP_END

static ADDRESS_MAP_START( soundmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0xf7ff) AM_ROM
	AM_RANGE(0xf800, 0xffff) AM_RAM
ADDRESS_MAP_END

static READ8_HANDLER( soundlatch_clear_r )
{
	soundlatch_clear_w(space, 0, 0);
	return 0;
}

static ADDRESS_MAP_START( soundport, ADDRESS_SPACE_IO, 8 )
	ADDRESS_MAP_GLOBAL_MASK(0xff)
	AM_RANGE(0x0, 0x1) AM_DEVWRITE("ymsnd", ym3812_w)
	AM_RANGE(0x2, 0x2) AM_DEVWRITE("dac1", dac_signed_w)
	AM_RANGE(0x3, 0x3) AM_DEVWRITE("dac2", dac_signed_w)
	AM_RANGE(0x4, 0x4) AM_READ(soundlatch_clear_r)
	AM_RANGE(0x6, 0x6) AM_READ(soundlatch_r)
ADDRESS_MAP_END



static INPUT_PORTS_START( bigfghtr )
	PORT_START("P1")
	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_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_COIN1 )
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_COIN2 )
	PORT_BIT( 0xf000, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_SERVICE1 )
	PORT_SERVICE_NO_TOGGLE( 0x0200, IP_ACTIVE_LOW )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_TILT )
	PORT_BIT( 0xf800, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("DSW0")
	PORT_DIPNAME( 0x03, 0x03, DEF_STR( Lives ) )
	PORT_DIPSETTING(    0x03, "3" )
	PORT_DIPSETTING(    0x02, "4" )
	PORT_DIPSETTING(    0x01, "5" )
	PORT_DIPSETTING(    0x00, "6" )
	PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Bonus_Life ) )
	PORT_DIPSETTING(    0x0c, "20k then every 60k" )
	PORT_DIPSETTING(    0x04, "20k then every 80k" )
	PORT_DIPSETTING(    0x08, "40k then every 60k" )
	PORT_DIPSETTING(    0x00, "40k then every 80k" )
	PORT_DIPNAME( 0x10, 0x10, DEF_STR( Demo_Sounds ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x10, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x00, DEF_STR( Cabinet ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
	PORT_DIPSETTING(    0x20, DEF_STR( Cocktail ) )
	PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Difficulty ) )
	PORT_DIPSETTING(    0xc0, DEF_STR( Easy ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Normal ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Hard ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Hardest ) )

	PORT_START("DSW1")
	PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_A ) )
	PORT_DIPSETTING(    0x01, DEF_STR( 2C_1C ) )
	PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )
	PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
	PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_B ) )
	PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
	PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
	PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) )
	PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
	PORT_DIPNAME( 0x30, 0x00, DEF_STR( Allow_Continue ) )
	PORT_DIPSETTING(    0x30, DEF_STR( No ) )
	PORT_DIPSETTING(    0x20, "3 Times" )
	PORT_DIPSETTING(    0x10, "5 Times" )
	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Flip_Screen ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
INPUT_PORTS_END


static const gfx_layout char_layout =
{
	8,8,
	RGN_FRAC(1,1),
	4,
	{ 0, 1, 2, 3 },
	{ 4, 0, 12, 8, 20, 16, 28, 24},
	{ 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
	32*8
};

static const gfx_layout tile_layout =
{
	16,16,
	RGN_FRAC(1,1),
	4,
	{ 0, 1, 2, 3 },
	{ 4, 0, 12, 8, 20, 16, 28, 24,
			32+4, 32+0, 32+12, 32+8, 32+20, 32+16, 32+28, 32+24 },
	{ 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
			8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
	128*8
};

static const gfx_layout sprite_layout =
{
	16,16,
	RGN_FRAC(1,2),
	4,
	{ 0, 1, 2, 3 },
	{ 4, 0, RGN_FRAC(1,2)+4, RGN_FRAC(1,2)+0, 12, 8, RGN_FRAC(1,2)+12, RGN_FRAC(1,2)+8,
			20, 16, RGN_FRAC(1,2)+20, RGN_FRAC(1,2)+16, 28, 24, RGN_FRAC(1,2)+28, RGN_FRAC(1,2)+24 },
	{ 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
			8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 },
	64*8
};

static GFXDECODE_START( bigfghtr )
	GFXDECODE_ENTRY( "gfx1", 0, char_layout,		 0*16,	32 )
	GFXDECODE_ENTRY( "gfx2", 0, tile_layout,		64*16,	32 )
	GFXDECODE_ENTRY( "gfx3", 0, tile_layout,		96*16,	32 )
	GFXDECODE_ENTRY( "gfx4", 0, sprite_layout,	32*16,	32 )
GFXDECODE_END



static MACHINE_START( bigfghtr )
{
	bigfghtr_state *state = machine->driver_data<bigfghtr_state>();

	state_save_register_global(machine, state->fg_scrollx);
	state_save_register_global(machine, state->fg_scrolly);
	state_save_register_global(machine, state->scroll_x);
	state_save_register_global(machine, state->scroll_y);
	state_save_register_global(machine, state->vreg);
	state_save_register_global(machine, state->read_latch);
}

static MACHINE_RESET( bigfghtr )
{
	bigfghtr_state *state = machine->driver_data<bigfghtr_state>();

	state->fg_scrollx = 0;
	state->fg_scrolly = 0;
	state->scroll_x = 0;
	state->scroll_y = 0;
	state->vreg = 0;
	state->read_latch = 0;
}


static MACHINE_CONFIG_START( bigfghtr, bigfghtr_state )

	MCFG_CPU_ADD("maincpu", M68000, 8000000) /* 8 MHz?? */
	MCFG_CPU_PROGRAM_MAP(mainmem)

	MCFG_CPU_VBLANK_INT("screen", irq1_line_hold)

	MCFG_CPU_ADD("audiocpu", Z80, 3072000)	/* 3.072 MHz???? */
	MCFG_CPU_PROGRAM_MAP(soundmem)
	MCFG_CPU_IO_MAP(soundport)
	MCFG_CPU_VBLANK_INT_HACK(irq0_line_hold,128)

	MCFG_MACHINE_START(bigfghtr)
	MCFG_MACHINE_RESET(bigfghtr	)

	/* video hardware */
	MCFG_VIDEO_ATTRIBUTES(VIDEO_BUFFERS_SPRITERAM)

	MCFG_SCREEN_ADD("screen", RASTER)
	MCFG_SCREEN_REFRESH_RATE(57)
	MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
	MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
	MCFG_SCREEN_SIZE(64*8, 32*8)
	MCFG_SCREEN_VISIBLE_AREA(12*8, (64-12)*8-1, 1*8, 31*8-1 )
	MCFG_GFXDECODE(bigfghtr)
	MCFG_PALETTE_LENGTH(2048)

	MCFG_VIDEO_EOF(bigfghtr)
	MCFG_VIDEO_START(bigfghtr)
	MCFG_VIDEO_UPDATE(bigfghtr)

	/* sound hardware */
	MCFG_SPEAKER_STANDARD_MONO("mono")

	MCFG_SOUND_ADD("ymsnd", YM3812, 4000000)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)

	MCFG_SOUND_ADD("dac1", DAC, 0)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)

	MCFG_SOUND_ADD("dac2", DAC, 0)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
MACHINE_CONFIG_END


ROM_START( skyrobo )
	ROM_REGION( 0x80000, "maincpu", 0 )
	ROM_LOAD16_BYTE( "3", 0x00000, 0x20000, CRC(02d8ba9f) SHA1(7622cc17561e5d1c069341b5f412f732f901d4a8) ) /* Rom location IC3 */
	ROM_LOAD16_BYTE( "1", 0x00001, 0x20000, CRC(fcfd9e2e) SHA1(c69b34653f04af8d488e323bc2db89656f76c332) ) /* Rom location IC2 */
	ROM_LOAD16_BYTE( "4", 0x40000, 0x20000, CRC(37ced4b7) SHA1(9ded66f795d3c0886f48e52de632e6edb8c57e84) ) /* Rom location IC5 */
	ROM_LOAD16_BYTE( "2", 0x40001, 0x20000, CRC(88d52f8e) SHA1(33b0d2b3cd38a13d8580694e7c50c059914eebe2) ) /* Rom location IC4 */

	ROM_REGION( 0x10000, "audiocpu", 0 )	/* Z80 code (sound) */
	ROM_LOAD( "8.17k", 0x00000, 0x10000, CRC(0aeab61e) SHA1(165e0ad58542b65383fef714578da21f62df7b74) )

	ROM_REGION( 0x10000, "mcu", 0 )	/* Intel C8751 read protected MCU */
	ROM_LOAD( "i8751.mcu", 0x00000, 0x1000, NO_DUMP )

	ROM_REGION( 0x08000, "gfx1", 0 )
	ROM_LOAD( "7", 0x00000, 0x08000, CRC(f556ef28) SHA1(2acb83cdf23356091056f2cfbbc2b9828ee25b6f) ) /* Rom location 11C */

	ROM_REGION( 0x30000, "gfx2", 0 )
	ROM_LOAD( "5.13f", 0x00000, 0x20000, CRC(d440a29f) SHA1(9e6ea7c9903e5e3e8e10ac7680c6120e1aa27250) )
	ROM_LOAD( "6.15f", 0x20000, 0x10000, CRC(27469a76) SHA1(ebf2c60e1f70a589680c05adf10771ac2097b9d0) )

	ROM_REGION( 0x20000, "gfx3", 0 )
	ROM_LOAD( "12.8a", 0x00000, 0x10000, CRC(a5694ea9) SHA1(ea94174495b3a65b3797932074a94df3b55fa0a2) )
	ROM_LOAD( "11.6a", 0x10000, 0x10000, CRC(10b74e2c) SHA1(e3ec68726e7f277dc2043424f2e4d863eb01b3dc) )

	ROM_REGION( 0x40000, "gfx4", 0 )
	ROM_LOAD( "9.8d",  0x00000, 0x20000, CRC(fe67800e) SHA1(0d3c4c3cb185270260fa691a97cddf082d6a056e) )
	ROM_LOAD( "10.9d", 0x20000, 0x20000, CRC(dcb828c4) SHA1(607bc86580a6fe6e15e91131532b0eecd8b7a0cb) )

	ROM_REGION( 0x0100, "proms", 0 )
	ROM_LOAD( "tf.13h", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* Prom is a N82S129AN type */
ROM_END

ROM_START( bigfghtr )
	ROM_REGION( 0x80000, "maincpu", 0 )
	ROM_LOAD16_BYTE( "3.ic3", 0x00000, 0x20000, CRC(e1e1f291) SHA1(dbbd707be6250d9ffcba3fee265869b72f790e26) )
	ROM_LOAD16_BYTE( "1.ic2", 0x00001, 0x20000, CRC(1100d991) SHA1(3c79398804b3a26b3df0c5734b270c37e1ba6a60) )
	ROM_LOAD16_BYTE( "4.ic5", 0x40000, 0x20000, CRC(2464a83b) SHA1(00f5ac81bc33148daafeab757647b63894e0e0ca) )
	ROM_LOAD16_BYTE( "2.ic4", 0x40001, 0x20000, CRC(b47bbcd5) SHA1(811bd4bc8fb662abf4734ab51e24c863d5cc3df3) )

	ROM_REGION( 0x10000, "audiocpu", 0 )	/* Z80 code (sound) */
	ROM_LOAD( "8.17k", 0x00000, 0x10000, CRC(0aeab61e) SHA1(165e0ad58542b65383fef714578da21f62df7b74) )

	ROM_REGION( 0x10000, "mcu", 0 )	/* Intel C8751 read protected MCU */
	ROM_LOAD( "i8751.mcu", 0x00000, 0x1000, NO_DUMP )

	ROM_REGION( 0x08000, "gfx1", 0 )
	ROM_LOAD( "7.11c", 0x00000, 0x08000, CRC(1809e79f) SHA1(730547771f803857acb552a84a8bc21bd3bda33f) )

	ROM_REGION( 0x30000, "gfx2", 0 )
	ROM_LOAD( "5.13f", 0x00000, 0x20000, CRC(d440a29f) SHA1(9e6ea7c9903e5e3e8e10ac7680c6120e1aa27250) )
	ROM_LOAD( "6.15f", 0x20000, 0x10000, CRC(27469a76) SHA1(ebf2c60e1f70a589680c05adf10771ac2097b9d0) )

	ROM_REGION( 0x20000, "gfx3", 0 )
	ROM_LOAD( "12.8a", 0x00000, 0x10000, CRC(a5694ea9) SHA1(ea94174495b3a65b3797932074a94df3b55fa0a2) )
	ROM_LOAD( "11.6a", 0x10000, 0x10000, CRC(10b74e2c) SHA1(e3ec68726e7f277dc2043424f2e4d863eb01b3dc) )

	ROM_REGION( 0x40000, "gfx4", 0 )
	ROM_LOAD( "9.8d",  0x00000, 0x20000, CRC(fe67800e) SHA1(0d3c4c3cb185270260fa691a97cddf082d6a056e) )
	ROM_LOAD( "10.9d", 0x20000, 0x20000, CRC(dcb828c4) SHA1(607bc86580a6fe6e15e91131532b0eecd8b7a0cb) )

	ROM_REGION( 0x0100, "proms", 0 )
	ROM_LOAD( "tf.13h", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* Prom is a N82S129AN type */
ROM_END

GAME( 1989, skyrobo,        0, bigfghtr, bigfghtr, 0,  ROT0, "Nichibutsu", "Sky Robo", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_SUPPORTS_SAVE )
GAME( 1989, bigfghtr, skyrobo, bigfghtr, bigfghtr, 0,  ROT0, "Nichibutsu", "Tatakae! Big Fighter (Japan)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_SUPPORTS_SAVE )