📄 punchout.c
字号:
/***************************************************************************
vidhrdw.c
Functions to emulate the video hardware of the machine.
***************************************************************************/
#include "driver.h"
#include "vidhrdw/generic.h"
#define TOP_MONITOR_ROWS 30
#define BOTTOM_MONITOR_ROWS 30
#define BIGSPRITE_WIDTH 128
#define BIGSPRITE_HEIGHT 256
#define ARMWREST_BIGSPRITE_WIDTH 256
#define ARMWREST_BIGSPRITE_HEIGHT 128
unsigned char *punchout_videoram2;
int punchout_videoram2_size;
unsigned char *punchout_bigsprite1ram;
int punchout_bigsprite1ram_size;
unsigned char *punchout_bigsprite2ram;
int punchout_bigsprite2ram_size;
unsigned char *punchout_scroll;
unsigned char *punchout_bigsprite1;
unsigned char *punchout_bigsprite2;
unsigned char *punchout_palettebank;
static unsigned char *dirtybuffer2,*bs1dirtybuffer,*bs2dirtybuffer;
static struct osd_bitmap *bs1tmpbitmap,*bs2tmpbitmap;
static int top_palette_bank,bottom_palette_bank;
static struct rectangle topvisiblearea =
{
0*8, 32*8-1,
0*8, (TOP_MONITOR_ROWS-2)*8-1
};
static struct rectangle bottomvisiblearea =
{
0*8, 32*8-1,
(TOP_MONITOR_ROWS+2)*8, (TOP_MONITOR_ROWS+BOTTOM_MONITOR_ROWS)*8-1
};
static struct rectangle backgroundvisiblearea =
{
0*8, 64*8-1,
(TOP_MONITOR_ROWS+2)*8, (TOP_MONITOR_ROWS+BOTTOM_MONITOR_ROWS)*8-1
};
/***************************************************************************
Convert the color PROMs into a more useable format.
Punch Out has a six 512x4 palette PROMs (one per gun; three for the top
monitor chars, three for everything else).
I don't know the exact values of the resistors between the RAM and the
RGB output. I assumed these values (the same as Commando)
bit 3 -- 220 ohm resistor -- inverter -- RED/GREEN/BLUE
-- 470 ohm resistor -- inverter -- RED/GREEN/BLUE
-- 1 kohm resistor -- inverter -- RED/GREEN/BLUE
bit 0 -- 2.2kohm resistor -- inverter -- RED/GREEN/BLUE
***************************************************************************/
void punchout_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
int i;
#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
#define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + (offs)])
for (i = 0;i < 1024;i++)
{
int bit0,bit1,bit2,bit3;
bit0 = (color_prom[0] >> 0) & 0x01;
bit1 = (color_prom[0] >> 1) & 0x01;
bit2 = (color_prom[0] >> 2) & 0x01;
bit3 = (color_prom[0] >> 3) & 0x01;
*(palette++) = 255 - (0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3);
bit0 = (color_prom[1024] >> 0) & 0x01;
bit1 = (color_prom[1024] >> 1) & 0x01;
bit2 = (color_prom[1024] >> 2) & 0x01;
bit3 = (color_prom[1024] >> 3) & 0x01;
*(palette++) = 255 - (0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3);
bit0 = (color_prom[2*1024] >> 0) & 0x01;
bit1 = (color_prom[2*1024] >> 1) & 0x01;
bit2 = (color_prom[2*1024] >> 2) & 0x01;
bit3 = (color_prom[2*1024] >> 3) & 0x01;
*(palette++) = 255 - (0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3);
color_prom++;
}
/* reserve the last color for the transparent pen (none of the game colors can have */
/* these RGB components) */
*(palette++) = 1;
*(palette++) = 1;
*(palette++) = 1;
/* top monitor chars - palette order is inverted */
for (i = 0;i < TOTAL_COLORS(0);i++)
COLOR(0,i ^ 3) = i;
/* bottom monitor chars */
for (i = 0;i < TOTAL_COLORS(1);i++)
COLOR(1,i) = i + 512;
/* big sprite #1 - palette order is inverted */
for (i = 0;i < TOTAL_COLORS(2);i++)
{
if (i % 8 == 0) COLOR(2,i ^ 7) = 1024; /* transparent */
else COLOR(2,i ^ 7) = i + 512;
}
/* big sprite #2 */
for (i = 0;i < TOTAL_COLORS(3);i++)
{
if (i % 4 == 0) COLOR(3,i) = 1024; /* transparent */
else COLOR(3,i) = i + 512;
}
}
void armwrest_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
int i;
#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
#define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + (offs)])
for (i = 0;i < 1024;i++)
{
int bit0,bit1,bit2,bit3;
bit0 = (color_prom[0] >> 0) & 0x01;
bit1 = (color_prom[0] >> 1) & 0x01;
bit2 = (color_prom[0] >> 2) & 0x01;
bit3 = (color_prom[0] >> 3) & 0x01;
*(palette++) = 255 - (0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3);
bit0 = (color_prom[1024] >> 0) & 0x01;
bit1 = (color_prom[1024] >> 1) & 0x01;
bit2 = (color_prom[1024] >> 2) & 0x01;
bit3 = (color_prom[1024] >> 3) & 0x01;
*(palette++) = 255 - (0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3);
bit0 = (color_prom[2*1024] >> 0) & 0x01;
bit1 = (color_prom[2*1024] >> 1) & 0x01;
bit2 = (color_prom[2*1024] >> 2) & 0x01;
bit3 = (color_prom[2*1024] >> 3) & 0x01;
*(palette++) = 255 - (0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3);
color_prom++;
}
/* reserve the last color for the transparent pen (none of the game colors can have */
/* these RGB components) */
*(palette++) = 1;
*(palette++) = 1;
*(palette++) = 1;
/* top monitor / bottom monitor backround chars */
for (i = 0;i < TOTAL_COLORS(0);i++)
COLOR(0,i) = i;
/* bottom monitor foreground chars */
for (i = 0;i < TOTAL_COLORS(1);i++)
COLOR(1,i) = i + 512;
/* big sprite #1 */
for (i = 0;i < TOTAL_COLORS(2);i++)
{
if (i % 8 == 7) COLOR(2,i) = 1024; /* transparent */
else COLOR(2,i) = i + 512;
}
/* big sprite #2 - palette order is inverted */
for (i = 0;i < TOTAL_COLORS(3);i++)
{
if (i % 4 == 3) COLOR(3,i ^ 3) = 1024; /* transparent */
else COLOR(3,i ^ 3) = i + 512;
}
}
/***************************************************************************
Start the video hardware emulation.
***************************************************************************/
int punchout_vh_start(void)
{
if ((dirtybuffer = malloc(videoram_size)) == 0)
return 1;
memset(dirtybuffer,1,videoram_size);
if ((dirtybuffer2 = malloc(punchout_videoram2_size)) == 0)
{
free(dirtybuffer);
return 1;
}
memset(dirtybuffer2,1,punchout_videoram2_size);
if ((tmpbitmap = osd_create_bitmap(512,480)) == 0)
{
free(dirtybuffer);
free(dirtybuffer2);
return 1;
}
if ((bs1dirtybuffer = malloc(punchout_bigsprite1ram_size)) == 0)
{
osd_free_bitmap(tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
return 1;
}
memset(bs1dirtybuffer,1,punchout_bigsprite1ram_size);
if ((bs1tmpbitmap = osd_create_bitmap(BIGSPRITE_WIDTH,BIGSPRITE_HEIGHT)) == 0)
{
osd_free_bitmap(tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
return 1;
}
if ((bs2dirtybuffer = malloc(punchout_bigsprite2ram_size)) == 0)
{
osd_free_bitmap(tmpbitmap);
osd_free_bitmap(bs1tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
return 1;
}
memset(bs2dirtybuffer,1,punchout_bigsprite2ram_size);
if ((bs2tmpbitmap = osd_create_bitmap(BIGSPRITE_WIDTH,BIGSPRITE_HEIGHT)) == 0)
{
osd_free_bitmap(tmpbitmap);
osd_free_bitmap(bs1tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
free(bs2dirtybuffer);
return 1;
}
return 0;
}
int armwrest_vh_start(void)
{
if ((dirtybuffer = malloc(videoram_size)) == 0)
return 1;
memset(dirtybuffer,1,videoram_size);
if ((dirtybuffer2 = malloc(punchout_videoram2_size)) == 0)
{
free(dirtybuffer);
return 1;
}
memset(dirtybuffer2,1,punchout_videoram2_size);
if ((tmpbitmap = osd_create_bitmap(512,480)) == 0)
{
free(dirtybuffer);
free(dirtybuffer2);
return 1;
}
if ((bs1dirtybuffer = malloc(punchout_bigsprite1ram_size)) == 0)
{
osd_free_bitmap(tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
return 1;
}
memset(bs1dirtybuffer,1,punchout_bigsprite1ram_size);
if ((bs1tmpbitmap = osd_create_bitmap(ARMWREST_BIGSPRITE_WIDTH,ARMWREST_BIGSPRITE_HEIGHT)) == 0)
{
osd_free_bitmap(tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
return 1;
}
if ((bs2dirtybuffer = malloc(punchout_bigsprite2ram_size)) == 0)
{
osd_free_bitmap(tmpbitmap);
osd_free_bitmap(bs1tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
return 1;
}
memset(bs2dirtybuffer,1,punchout_bigsprite2ram_size);
if ((bs2tmpbitmap = osd_create_bitmap(BIGSPRITE_WIDTH,BIGSPRITE_HEIGHT)) == 0)
{
osd_free_bitmap(tmpbitmap);
osd_free_bitmap(bs1tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
free(bs2dirtybuffer);
return 1;
}
return 0;
}
/***************************************************************************
Stop the video hardware emulation.
***************************************************************************/
void punchout_vh_stop(void)
{
free(dirtybuffer);
free(dirtybuffer2);
free(bs1dirtybuffer);
free(bs2dirtybuffer);
osd_free_bitmap(tmpbitmap);
osd_free_bitmap(bs1tmpbitmap);
osd_free_bitmap(bs2tmpbitmap);
}
void punchout_videoram2_w(int offset,int data)
{
if (punchout_videoram2[offset] != data)
{
dirtybuffer2[offset] = 1;
punchout_videoram2[offset] = data;
}
}
void punchout_bigsprite1ram_w(int offset,int data)
{
if (punchout_bigsprite1ram[offset] != data)
{
bs1dirtybuffer[offset] = 1;
punchout_bigsprite1ram[offset] = data;
}
}
void punchout_bigsprite2ram_w(int offset,int data)
{
if (punchout_bigsprite2ram[offset] != data)
{
bs2dirtybuffer[offset] = 1;
punchout_bigsprite2ram[offset] = data;
}
}
void punchout_palettebank_w(int offset,int data)
{
*punchout_palettebank = data;
if (top_palette_bank != ((data >> 1) & 0x01))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -