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

Minesweeper driver, originally for Dotrikun hardware

Driver by Robbbert - April 2007

CPU   : Z-80 (4MHz)
SOUND : (none)

****************************************************************************

Notes from the Readme files

MINE SWEEPER for SEGA's Dottorikun PCB

Distributed by Arcade roms from Japan (j-rom)

This game is the Dottorikun port of the Windows' Mine Sweeper.
It has "Time Limit", "more Stage", etc...

Usage:

You must burn DT_MINEJ.BIN to 27128 and replace it to the ROM of
Dottorikun's board. I assume you can find this board easily...

Rules:

* The timer limit is 999
* If you hit a mine, many counts added to the timer
* There are no mines at the start point and the corner

Option:

This game supports BACKUP and SOUND. If you want to play
the sound correctly, you must modify the board. If not,
some noise appears on the screen.

* THIS MODIFY IS QUITE DIFFICULT, USE AT YOUR OWN RISK! *
*    AND DON'T ASK ABOUT THIS MODIFYING INFORMATION!    *

Backup Support:

* You have to install the RESET-IC (PST518, etc.)
* Check the power on/off
* Install the Lithium battery or super capacity condensor
* Connect the inverted RESET signal to RAM's 18pin (use 74HC04, etc.)
  (You must backup both RAM and HC04)

Sound Support:

You must get the sound board of Wing War (Guns'n Wings).
You can hear the sonic sound if you use this sound board!

* Cut IC17's 10pin from the board
* Use shielded cable, Connect CN2's 6pin on the sound board to the above pin
* And the shield connects GND and CN2's 5pin
* Connect IC17 10pin's board side to the GND
* This sound board has 2 set of STEREO, you have to mix them

Secrets:

* Push start when the power on : RAM CLEAR
* right+up lever and push 1 and 2 button : SOUND TEST

* left+up and push 1, 2, COIN, START when the checking Backup RAM is
  finished, you can see the Ending scene.

* Push 1 and 2 when the Ending scene is changed, you can see the
  secret picture (^^)

Robbbert's notes:
- Backup nvram added (April 2007)
- Made everything static (July 2008)
- Hooked port 20 to the colour generator (July 2008)

Colours:	White (normal play / attract mode)
		Yellow (new record time)
		Green (new record level - must be at least level 3)
		Purple (stepped on a bomb)
		Red (game over)

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

#include "driver.h"
#include "cpu/z80/z80.h"

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

    Palette Setting.

*******************************************************************/
static UINT8 color;

static WRITE8_HANDLER( mineswp_color_w )
{
	video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
	color = data;
}


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

    Video updating

*******************************************************************/
static VIDEO_UPDATE( mineswp )
{
	int offs;

	pen_t back_pen = MAKE_RGB(pal1bit(color >> 3), pal1bit(color >> 4), pal1bit(color >> 5));
	pen_t fore_pen = MAKE_RGB(pal1bit(color >> 0), pal1bit(color >> 1), pal1bit(color >> 2));

	for (offs = 0; offs < videoram_size; offs++)
	{
		int i;
		UINT8 data = videoram[offs];

		UINT8 x = offs << 4;
		UINT8 y = offs >> 4 << 1;

		for (i = 0; i < 8; i++)
		{
			pen_t pen = (data & 0x80) ? fore_pen : back_pen;

			/* I think the video hardware doubles pixels, screen would be too small otherwise */
			*BITMAP_ADDR32(bitmap, y, x) = pen;
			*BITMAP_ADDR32(bitmap, y + 1, x) = pen;
			x++;

			*BITMAP_ADDR32(bitmap, y, x) = pen;
			*BITMAP_ADDR32(bitmap, y + 1, x) = pen;
			x++;

			data = data << 1;
		}
	}

	return 0;
}


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

    Address maps

*******************************************************************/
static ADDRESS_MAP_START( mineswp_map, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x3fff) AM_ROM
	AM_RANGE(0x8000, 0x85ff) AM_RAM AM_BASE(&videoram) AM_SIZE(&videoram_size)
	AM_RANGE(0x8600, 0x86df) AM_RAM
	AM_RANGE(0x86e0, 0x86ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)
	AM_RANGE(0x8700, 0x87ff) AM_RAM
	AM_RANGE(0xfffc, 0xffff) AM_RAM
ADDRESS_MAP_END

static ADDRESS_MAP_START( mineswp_io, ADDRESS_SPACE_IO, 8 )
	ADDRESS_MAP_GLOBAL_MASK(0xff)
	AM_RANGE(0x00, 0x00) AM_READ_PORT("IN0")
	AM_RANGE(0x20, 0x20) AM_WRITE(mineswp_color_w)
ADDRESS_MAP_END


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

    Inputs

*******************************************************************/
static INPUT_PORTS_START( mineswp )
	PORT_START  ("IN0")
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 )
INPUT_PORTS_END


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

    Machine driver

*******************************************************************/
static MACHINE_DRIVER_START( mineswp )

	/* basic machine hardware */
	MDRV_CPU_ADD  ("main", Z80, XTAL_4MHz)
	MDRV_CPU_PROGRAM_MAP(mineswp_map,0)
	MDRV_CPU_IO_MAP(mineswp_io,0)
	MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
	MDRV_NVRAM_HANDLER(generic_1fill)

	/* video hardware */
	MDRV_SCREEN_ADD("main", RASTER)
	MDRV_SCREEN_REFRESH_RATE(60)
	MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
	MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
	MDRV_SCREEN_SIZE(256, 256)
	MDRV_SCREEN_VISIBLE_AREA(0, 256-1, 0, 192-1)
	MDRV_VIDEO_UPDATE(mineswp)

	/* sound hardware */
MACHINE_DRIVER_END


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

  Game driver(s)

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

ROM_START( mineswp )
	ROM_REGION( 0x10000, "main", 0 ) /* 64k for code */
	ROM_LOAD( "14479b.mpr", 0x0000, 0x4000, CRC(1cece483) SHA1(c425a09b640721c9a5b499cdb79848dc18ee66b9) )
ROM_END

GAME( 1998, mineswp,  0, mineswp, mineswp, 0, ROT0, "J-Rom", "Mine Sweeper (Dottori Kun hardware) [h]", 0 )

