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

Minesweeper driver, originally for Dotrikun hardware

Driver by Robert - 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 (^^)

Robert's notes:
- Backup nvram added


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

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

static UINT8 color = 1;	// red


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

    Palette Setting.

*******************************************************************/
WRITE8_HANDLER( mineswp_color_w )	/* doesnt appear to be used */
{
	color = data;

	video_screen_update_partial(0, video_screen_get_vpos(0));
}


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 + 0, x + 0) = pen;
			*BITMAP_ADDR32(bitmap, y + 0, x + 1) = pen;
			*BITMAP_ADDR32(bitmap, y + 1, x + 0) = pen;
			*BITMAP_ADDR32(bitmap, y + 1, x + 1) = pen;

			x = x + 2;
			data = data << 1;
		}
	}

	return 0;
}


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_FLAGS( AMEF_ABITS(8) )
	AM_RANGE(0x00, 0x00) AM_READ(input_port_0_r)
//	AM_RANGE(0x00, 0x00) AM_WRITE(mineswp_color_w)		/* not used? */
	AM_RANGE(0x20, 0x20) AM_WRITENOP		// sound?
ADDRESS_MAP_END


INPUT_PORTS_START( mineswp )
	PORT_START
	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


static MACHINE_DRIVER_START( mineswp )

	/* basic machine hardware */
	MDRV_CPU_ADD(Z80, 4000000)		 /* 4 MHz */
	MDRV_CPU_PROGRAM_MAP(mineswp_map,0)
	MDRV_CPU_IO_MAP(mineswp_io,0)
	MDRV_CPU_VBLANK_INT(irq0_line_hold,1)

	MDRV_SCREEN_REFRESH_RATE(60)
	MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)

	/* video hardware */
	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
	MDRV_VIDEO_UPDATE(mineswp)

	MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
	MDRV_SCREEN_SIZE(256, 256)
	MDRV_SCREEN_VISIBLE_AREA(0, 256-1, 0, 192-1)
	MDRV_NVRAM_HANDLER(generic_1fill)

	/* sound hardware */
MACHINE_DRIVER_END


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

  Game driver(s)

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

ROM_START( mineswp )
	ROM_REGION( 0x10000, REGION_CPU1, 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]", GAME_NO_SOUND )

