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

	driver.c

	NEOGEO CDZ driver (based on M.A.M.E.'s neogeo driver)

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

#ifndef NEOCDZ_DRIVER_H
#define NEOCDZ_DRIVER_H

#define RASTER_LINES		264
#define FIRST_VISIBLE_LINE	16
#define	LAST_VISIBLE_LINE	239

#define PATCH_NONE		0
#define PATCH_SSRPG		(1 << 0)
#define PATCH_AOF2		(1 << 1)
#define PATCH_ADKWORLD	(1 << 2)
#define PATCH_CRSWORD2	(1 << 3)
#define PATCH_RBFF2		(1 << 4)

#define GAME_NAME(name)  	(!strcmp(name, game_name))
#define NGH_NUMBER(value)	(neogeo_ngh_number == value)

#define	EXMEM_OBJ		0x00
#define	EXMEM_PCMA		0x01
#define	EXMEM_Z80		0x04
#define	EXMEM_FIX		0x05
#define	EXMEM_UNKNOWN	0xff

#define	PRG_TYPE		0x00
#define FIX_TYPE		0x01
#define SPR_TYPE		0x02
#define Z80_TYPE		0x03
#define PCM_TYPE		0x04
#define PAT_TYPE		0x05
#define PAL_TYPE		0x06
#define OBJ_TYPE		0x07
#define AXX_TYPE		0x08
#define BACKUP_RAM		0x09
#define UNKNOWN_TYPE	0x0f

#define UPLOAD_IMMIDIATE	0x00
#define UPLOAD_PATTERN		0x01
#define UPLOAD_MEMORY		0x02
#define UPLOAD_FILE			0x03

#define upload_get_type()		m68k_read_memory_8(0x108000 + 0x7eda)
#define upload_get_bank()		m68k_read_memory_8(0x108000 + 0x7edb)
#define upload_get_dst()		m68k_read_memory_32(0x108000 + 0x7ef4)
#define upload_get_src()		m68k_read_memory_32(0x108000 + 0x7ef8)
#define upload_get_length()		m68k_read_memory_32(0x108000 + 0x7efc)

#define with_image()			m68k_read_memory_8(0x108000 + 0x7ddc)
#define spr_disable_w(data)		m68k_write_memory_8(0xff0111, data)
#define fix_disable_w(data)		m68k_write_memory_8(0xff0115, data)
#define video_enable_w(data)	m68k_write_memory_8(0xff0119, data)

#define INTERRUPT_GEN(name)		void name(int param)

enum
{
	NORMAL = 0,
	RASTER,
	CHECK_RASTERCOUNTER,
	AOF2
};

typedef struct game_t
{
	const char name[12];
	const u16  ngh_number;
	const u16  type;
} GAMES;


extern const GAMES games[100];
extern const char *game_name;
extern const char default_name[16];
extern int game_index;
extern int neogeo_ngh_number;
extern int driver_type;
extern u32 neogeo_frame_counter;
extern int neogeo_skip_this_frame;
extern struct rectangle visible_area;
extern int watchdog_counter;

void neogeo_driver_init(void);
void neogeo_driver_reset(void);
void neogeo_check_game(void);

INTERRUPT_GEN( neogeo_interrupt );
INTERRUPT_GEN( neogeo_interrupt_aof2 );
INTERRUPT_GEN( neogeo_raster_interrupt );
INTERRUPT_GEN( neogeo_raster_busy_interrupt );

READ16_HANDLER( neogeo_z80_r );
WRITE16_HANDLER( neogeo_z80_w );

WRITE16_HANDLER( neogeo_syscontrol2_16_w );

READ16_HANDLER( neogeo_video_16_r );
WRITE16_HANDLER( neogeo_video_16_w );

WRITE16_HANDLER( neogeo_paletteram16_w );

READ16_HANDLER( neogeo_externalmem_16_r );
WRITE16_HANDLER( neogeo_externalmem_16_w );

READ16_HANDLER( neogeo_hardcontrol_16_r );
WRITE16_HANDLER( neogeo_hardcontrol_16_w );

u32 neogeo_z80_port_r(u32 port);
void neogeo_z80_port_w(u32 port, u32 value);

void neogeo_sound_irq(int irq);

#ifdef SAVE_STATE
void state_save_driver(u8 *state_buf);
void state_load_driver(u8 *state_buf);
#endif

#endif /* NEOCDZ_DRIVER_H */
