📄 kungfum.c
字号:
/***************************************************************************
vidhrdw.c
Functions to emulate the video hardware of the machine.
***************************************************************************/
#include "driver.h"
#include "vidhrdw/generic.h"
unsigned char *kungfum_scroll_low;
unsigned char *kungfum_scroll_high;
static int flipscreen;
static const unsigned char *sprite_height_prom;
static struct rectangle spritevisiblearea =
{
0*8, 32*8-1,
10*8, 32*8-1
};
static struct rectangle flipspritevisiblearea =
{
0*8, 32*8-1,
0*8, 22*8-1
};
/***************************************************************************
Convert the color PROMs into a more useable format.
Kung Fu Master has a six 256x4 palette PROMs (one per gun; three for
characters, three for sprites).
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 -- RED/GREEN/BLUE
-- 470 ohm resistor -- RED/GREEN/BLUE
-- 1 kohm resistor -- RED/GREEN/BLUE
bit 0 -- 2.2kohm resistor -- RED/GREEN/BLUE
***************************************************************************/
void kungfum_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
int i;
for (i = 0;i < Machine->drv->total_colors;i++)
{
int bit0,bit1,bit2,bit3;
/* red component */
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++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
/* green component */
bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
*(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
/* blue component */
bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
*(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
color_prom++;
}
color_prom += 2*Machine->drv->total_colors;
/* color_prom now points to the beginning of the sprite height table */
sprite_height_prom = color_prom; /* we'll need this at run time */
}
/***************************************************************************
Start the video hardware emulation.
***************************************************************************/
int kungfum_vh_start(void)
{
if ((dirtybuffer = malloc(videoram_size)) == 0)
return 1;
memset(dirtybuffer,1,videoram_size);
/* Kung Fu Master has a virtual screen twice as large as the visible screen */
if ((tmpbitmap = osd_create_bitmap(2 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
{
free(dirtybuffer);
return 1;
}
return 0;
}
/***************************************************************************
Stop the video hardware emulation.
***************************************************************************/
void kungfum_vh_stop(void)
{
free(dirtybuffer);
osd_free_bitmap(tmpbitmap);
}
void kungfum_flipscreen_w(int offset,int data)
{
/* screen flip is handled both by software and hardware */
data ^= ~readinputport(4) & 1;
if (flipscreen != (data & 1))
{
flipscreen = data & 1;
memset(dirtybuffer,1,videoram_size);
}
}
/***************************************************************************
Draw the game screen in the given osd_bitmap.
Do NOT call osd_update_display() from this function, it will be called by
the main emulation engine.
***************************************************************************/
void kungfum_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
int offs,i;
/* for every character in the Video RAM, check if it has been modified */
/* since last time and update it accordingly. */
for (offs = videoram_size - 1;offs >= 0;offs--)
{
if (dirtybuffer[offs])
{
int sx,sy,flipx,flipy;
dirtybuffer[offs] = 0;
sx = offs % 64;
sy = offs / 64;
flipx = colorram[offs] & 0x20;
flipy = 0;
if (flipscreen)
{
sx = 63 - sx;
sy = 31 - sy;
flipx = !flipx;
flipy = !flipy;
}
drawgfx(tmpbitmap,Machine->gfx[0],
videoram[offs] + 4 * (colorram[offs] & 0xc0),
colorram[offs] & 0x1f,
flipx,flipy,
8*sx,8*sy,
0,TRANSPARENCY_NONE,0);
}
}
/* copy the temporary bitmap to the screen */
{
int scroll[32];
if (flipscreen)
{
for (i = 31;i > 25;i--)
scroll[i] = -128;
for (i = 25;i >= 0;i--)
scroll[i] = (*kungfum_scroll_low + 256 * *kungfum_scroll_high) - 128;
}
else
{
for (i = 0;i < 6;i++)
scroll[i] = -128;
for (i = 6;i < 32;i++)
scroll[i] = -(*kungfum_scroll_low + 256 * *kungfum_scroll_high) - 128;
}
copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
}
/* Draw the sprites. */
for (offs = 0;offs < spriteram_size;offs += 8)
{
int incr,code,col,flipx,flipy,sx,sy;
code = spriteram[offs+4] + 256 * (spriteram[offs+5] & 0x03);
if (code != 0)
{
col = spriteram[offs+0] & 0x1f;
sx = 256 * (spriteram[offs+7] & 1) + spriteram[offs+6] - 128,
sy = 256+128-15 - (256 * (spriteram[offs+3] & 1) + spriteram[offs+2]),
flipx = spriteram[offs+5] & 0x40;
flipy = spriteram[offs+5] & 0x80;
i = sprite_height_prom[code / 32];
if (i == 1) /* double height */
{
code &= ~1;
sy -= 16;
}
else if (i == 2) /* quadruple height */
{
i = 3;
code &= ~3;
sy -= 3*16;
}
if (flipscreen)
{
sx = 240 - sx;
sy = 242 - i*16 - sy; /* sprites are slightly misplaced by the hardware */
flipx = !flipx;
flipy = !flipy;
}
if (flipy)
{
incr = -1;
code += i;
}
else incr = 1;
do
{
drawgfx(bitmap,Machine->gfx[1],
code + i * incr,col,
flipx,flipy,
sx,sy + 16 * i,
flipscreen ? &flipspritevisiblearea : &spritevisiblearea,TRANSPARENCY_PEN,0);
i--;
} while (i >= 0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -