⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atarisy2.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************

  vidhrdw.c

  Functions to emulate the video hardware of the machine.

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

#include "driver.h"
#include "machine/atarigen.h"
#include "vidhrdw/generic.h"

#define XCHARS 64
#define YCHARS 48

#define XDIM (XCHARS*8)
#define YDIM (YCHARS*8)


extern int slapstic_tweak (int offset);


struct atarisys2_mo_data
{
	int *redraw_list, *redraw;
	int xhold;
};



/*************************************
 *
 *		Globals we own
 *
 *************************************/

unsigned char *atarisys2_slapstic_base;



/*************************************
 *
 *		Statics
 *
 *************************************/

static unsigned char *playfieldram;
static unsigned char *alpharam;

static int playfieldram_size = 0x4000;

static int alpharam_size = 0x1800;

static int videobank;

static unsigned char *playfielddirty;

static struct osd_bitmap *playfieldbitmap;

static int *pf_bank, *mo_bank;



/*************************************
 *
 *		Prototypes from other modules
 *
 *************************************/

void atarisys2_vh_stop (void);

#if 0
static void atarisys2_dump_video_ram (void);
#endif


/*************************************
 *
 *		Video system start
 *
 *************************************/

int atarisys2_vh_start(void)
{
	static struct atarigen_modesc atarisys2_modesc =
	{
		256,                 /* maximum number of MO's */
		8,                   /* number of bytes per MO entry */
		2,                   /* number of bytes between MO words */
		3,                   /* ignore an entry if this word == 0xffff */
		3, 3, 0xff,          /* link = (data[linkword] >> linkshift) & linkmask */
		0                    /* render in reverse link order */
	};

	/* allocate banked memory */
	alpharam = calloc (0x8000, 1);
	if (!alpharam)
	{
		atarisys2_vh_stop ();
		return 1;
	}
	spriteram = alpharam + alpharam_size;
	playfieldram = alpharam + 0x4000;

	/* reset the videoram banking */
	videoram = alpharam;
	videobank = 0;

	/* allocate dirty buffers */
	if (!playfielddirty)
		playfielddirty = malloc (playfieldram_size / 2);
	if (!playfielddirty)
	{
		atarisys2_vh_stop ();
		return 1;
	}

	/* allocate bitmaps */
	if (!playfieldbitmap)
		playfieldbitmap = osd_new_bitmap (128*8, 64*8, Machine->scrbitmap->depth);
	if (!playfieldbitmap)
	{
		atarisys2_vh_stop ();
		return 1;
	}

	/*
	 * if we are palette reducing, do the simple thing by marking everything used except for
	 * the transparent sprite and alpha colors; this should give some leeway for machines
	 * that can't give up all 256 colors
	 */
	if (palette_used_colors)
	{
		int i;
		memset (palette_used_colors, PALETTE_COLOR_USED, Machine->drv->total_colors * sizeof(unsigned char));
		for (i = 0; i < 4; i++)
			palette_used_colors[0 + i * 16] = PALETTE_COLOR_TRANSPARENT;
		for (i = 0; i < 8; i++)
			palette_used_colors[64 + i * 4] = PALETTE_COLOR_TRANSPARENT;
	}

	/* initialize the displaylist system */
	return atarigen_init_display_list (&atarisys2_modesc);
}


int paperboy_vh_start (void)
{
	/* playfield bit mapping */
	static int pf_offs[16] =
	{
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x0800, 0x0800,  /* PFROMSEL1 */
		0x0000, 0x0400,  /* PFROMSEL2 */
		0x0800, 0x0800,  /* PFROMSEL3 */
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x0800, 0x0800,  /* PFROMSEL1 */
		0x0000, 0x0400,  /* PFROMSEL2 */
		0x0800, 0x0800   /* PFROMSEL3 */
	};

	/* motion object bit mapping */
	static int mo_offs[32] =
	{
		0x0000, 0x0200, 0x0400, 0x0600,  /* 000 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 001 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 010 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 011 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 100 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 101 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 110 */
		0x0000, 0x0200, 0x0400, 0x0600   /* 111 */
	};

	pf_bank = pf_offs;
	mo_bank = mo_offs;
	return atarisys2_vh_start ();
}


int apb_vh_start (void)
{
	/* playfield bit mapping */
	static int pf_offs[16] =
	{
		0x0800, 0x0c00,  /* PFROMSEL0 */
		0x1800, 0x1c00,  /* PFROMSEL1 */
		0x2800, 0x2c00,  /* PFROMSEL2 */
		0x3800, 0x3c00,  /* PFROMSEL3 */
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x1000, 0x1400,  /* PFROMSEL1 */
		0x2000, 0x2400,  /* PFROMSEL2 */
		0x3000, 0x3400   /* PFROMSEL3 */
	};

	/* motion object bit mapping */
	static int mo_offs[32] =
	{
		0x0200, 0x0600, 0x0a00, 0x0e00,  /* 000 */
		0x0000, 0x0400, 0x0800, 0x0c00,  /* 001 */
		0x1200, 0x1600, 0x1a00, 0x1e00,  /* 010 */
		0x1000, 0x1400, 0x1800, 0x1c00,  /* 011 */
		0x0200, 0x0600, 0x0a00, 0x0e00,  /* 100 */
		0x0000, 0x0400, 0x0800, 0x0c00,  /* 101 */
		0x1200, 0x1600, 0x1a00, 0x1e00,  /* 110 */
		0x1000, 0x1400, 0x1800, 0x1c00   /* 111 */
	};

	pf_bank = pf_offs;
	mo_bank = mo_offs;
	return atarisys2_vh_start ();
}


int a720_vh_start (void)
{
	/* playfield bit mapping */
	static int pf_offs[16] =
	{
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x0800, 0x0c00,  /* PFROMSEL1 */
		0x1000, 0x1400,  /* PFROMSEL2 */
		0x1800, 0x1c00,  /* PFROMSEL3 */
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x0800, 0x0c00,  /* PFROMSEL1 */
		0x1000, 0x1400,  /* PFROMSEL2 */
		0x1800, 0x1c00   /* PFROMSEL3 */
	};

	/* motion object bit mapping */
	static int mo_offs[32] =
	{
		0x0200, 0x0600, 0x0a00, 0x0e00,  /* 000 */
		0x0000, 0x0400, 0x0800, 0x0c00,  /* 001 */
		0x1200, 0x1600, 0x1a00, 0x1e00,  /* 010 */
		0x1000, 0x1400, 0x1800, 0x1c00,  /* 011 */
		0x0200, 0x0600, 0x0a00, 0x0e00,  /* 100 */
		0x0000, 0x0400, 0x0800, 0x0c00,  /* 101 */
		0x1200, 0x1600, 0x1a00, 0x1e00,  /* 110 */
		0x1000, 0x1400, 0x1800, 0x1c00   /* 111 */
	};

	pf_bank = pf_offs;
	mo_bank = mo_offs;
	return atarisys2_vh_start ();
}


int ssprint_vh_start (void)
{
	/* playfield bit mapping */
	static int pf_offs[16] =
	{
		0x0800, 0x0c00,  /* PFROMSEL0 */
		0x1800, 0x1c00,  /* PFROMSEL1 */
		0x2800, 0x2c00,  /* PFROMSEL2 */
		0x3800, 0x3c00,  /* PFROMSEL3 */
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x1000, 0x1400,  /* PFROMSEL1 */
		0x2000, 0x2400,  /* PFROMSEL2 */
		0x3000, 0x3400   /* PFROMSEL3 */
	};

	/* motion object bit mapping */
	static int mo_offs[32] =
	{
		0x0000, 0x0200, 0x0400, 0x0600,  /* 000 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 001 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 010 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 011 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 100 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 101 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 110 */
		0x0000, 0x0200, 0x0400, 0x0600   /* 111 */
	};

	pf_bank = pf_offs;
	mo_bank = mo_offs;
	return atarisys2_vh_start ();
}


int csprint_vh_start (void)
{
	/* playfield bit mapping */
	static int pf_offs[16] =
	{
		0x0800, 0x0c00,  /* PFROMSEL0 */
		0x1800, 0x1c00,  /* PFROMSEL1 */
		0x2800, 0x2c00,  /* PFROMSEL2 */
		0x3800, 0x3c00,  /* PFROMSEL3 */
		0x0000, 0x0400,  /* PFROMSEL0 */
		0x1000, 0x1400,  /* PFROMSEL1 */
		0x2000, 0x2400,  /* PFROMSEL2 */
		0x3000, 0x3400   /* PFROMSEL3 */
	};

	/* motion object bit mapping */
	static int mo_offs[32] =
	{
		0x0000, 0x0200, 0x0400, 0x0600,  /* 000 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 001 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 010 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 011 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 100 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 101 */
		0x0000, 0x0200, 0x0400, 0x0600,  /* 110 */
		0x0000, 0x0200, 0x0400, 0x0600   /* 111 */
	};

	pf_bank = pf_offs;
	mo_bank = mo_offs;
	return atarisys2_vh_start ();
}



/*************************************
 *
 *		Video system shutdown
 *
 *************************************/

void atarisys2_vh_stop(void)
{
	/* free memory */
	if (alpharam)
		free (alpharam);
	alpharam = playfieldram = spriteram = 0;

	/* free bitmaps */
	if (playfieldbitmap)
		osd_free_bitmap (playfieldbitmap);
	playfieldbitmap = 0;

	/* free dirty buffers */
	if (playfielddirty)
		free (playfielddirty);
	playfielddirty = 0;
}



/*************************************
 *
 *		Scroll/playfield bank w
 *
 *************************************/

void atarisys2_vscroll_w (int offset, int data)
{
	int oldword = READ_WORD (&atarigen_vscroll[offset]);
	int newword = COMBINE_WORD (oldword, data);
	WRITE_WORD (&atarigen_vscroll[offset], newword);

	/* if we changed the bank, we need to rerender the playfield */
	if (offset == 0 && (oldword & 15) != (newword & 15))
		memset (playfielddirty, 1, playfieldram_size / 2);
}


void atarisys2_hscroll_w (int offset, int data)
{
	int oldword = READ_WORD (&atarigen_hscroll[offset]);
	int newword = COMBINE_WORD (oldword, data);
	WRITE_WORD (&atarigen_hscroll[offset], newword);

	/* if we changed the bank, we need to rerender the playfield */
	if (offset == 0 && (oldword & 15) != (newword & 15))
		memset (playfielddirty, 1, playfieldram_size / 2);
}



/*************************************
 *
 *		Palette RAM read/write handlers
 *
 *************************************/

void atarisys2_paletteram_w (int offset, int data)
{
	static const int intensity_table[16] =
	{
		#define ZB 115
		#define Z3 78
		#define Z2 37
		#define Z1 17
		#define Z0 9
		0, ZB+Z0, ZB+Z1, ZB+Z1+Z0, ZB+Z2, ZB+Z2+Z0, ZB+Z2+Z1, ZB+Z2+Z1+Z0,
		ZB+Z3, ZB+Z3+Z0, ZB+Z3+Z1, ZB+Z3+Z1+Z0,ZB+ Z3+Z2, ZB+Z3+Z2+Z0, ZB+Z3+Z2+Z1, ZB+Z3+Z2+Z1+Z0
	};
	static const int color_table[16] =
		{ 0x0, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xe, 0xf, 0xf };

	int inten, red, green, blue;

	int oldword = READ_WORD (&paletteram[offset]);
	int newword = COMBINE_WORD (oldword, data);
	int indx = offset / 2;

	WRITE_WORD (&paletteram[offset], newword);

	inten = intensity_table[newword & 15];
	red = (color_table[(newword >> 12) & 15] * inten) >> 4;
	green = (color_table[(newword >> 8) & 15] * inten) >> 4;
	blue = (color_table[(newword >> 4) & 15] * inten) >> 4;
	palette_change_color (indx, red, green, blue);
}



/*************************************
 *
 *		Video RAM bank read/write handlers
 *
 *************************************/

int atarisys2_slapstic_r (int offset)
{
	slapstic_tweak (offset / 2);

	/* an extra tweak for the next opcode fetch */
	videobank = slapstic_tweak (0x1234);
	videoram = alpharam + videobank * 0x2000;

	return READ_WORD (&atarisys2_slapstic_base[offset]);
}


void atarisys2_slapstic_w (int offset, int data)
{
	slapstic_tweak (offset / 2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -