📄 travrusa.c
字号:
/***************************************************************************
vidhrdw.c
Traverse USA
L Taylor
J Clegg
Functions to emulate the video hardware of the machine.
***************************************************************************/
#include "driver.h"
#include "vidhrdw/generic.h"
unsigned char *travrusa_scroll_x_low;
unsigned char *travrusa_scroll_x_high;
unsigned char *travrusa_scroll_y_low;
unsigned char *travrusa_sprite_priority; /* JB 970912 */
static int flipscreen;
static struct rectangle spritevisiblearea =
{
1*8, 31*8-1,
0*8, 24*8-1
};
static struct rectangle spritevisibleareaflip =
{
1*8, 31*8-1,
8*8, 32*8-1
};
/***************************************************************************
Convert the color PROMs into a more useable format.
Traverse USA has one 256x8 character palette PROM (some versions have two
256x4), one 32x8 sprite palette PROM, and one 256x4 sprite color lookup
table PROM.
I don't know for sure how the palette PROMs are connected to the RGB
output, but it's probably something like this; note that RED and BLUE
are swapped wrt the usual configuration.
bit 7 -- 220 ohm resistor -- RED
-- 470 ohm resistor -- RED
-- 220 ohm resistor -- GREEN
-- 470 ohm resistor -- GREEN
-- 1 kohm resistor -- GREEN
-- 220 ohm resistor -- BLUE
-- 470 ohm resistor -- BLUE
bit 0 -- 1 kohm resistor -- BLUE
***************************************************************************/
void travrusa_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])
/* character palette */
for (i = 0;i < 128;i++)
{
int bit0,bit1,bit2;
/* red component */
bit0 = 0;
bit1 = (*color_prom >> 6) & 0x01;
bit2 = (*color_prom >> 7) & 0x01;
*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
/* green component */
bit0 = (*color_prom >> 3) & 0x01;
bit1 = (*color_prom >> 4) & 0x01;
bit2 = (*color_prom >> 5) & 0x01;
*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
/* blue component */
bit0 = (*color_prom >> 0) & 0x01;
bit1 = (*color_prom >> 1) & 0x01;
bit2 = (*color_prom >> 2) & 0x01;
*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
color_prom++;
}
/* skip bottom half - not used */
color_prom += 128;
/* sprite palette */
for (i = 0;i < 32;i++)
{
int bit0,bit1,bit2;
/* red component */
bit0 = 0;
bit1 = (*color_prom >> 6) & 0x01;
bit2 = (*color_prom >> 7) & 0x01;
*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
/* green component */
bit0 = (*color_prom >> 3) & 0x01;
bit1 = (*color_prom >> 4) & 0x01;
bit2 = (*color_prom >> 5) & 0x01;
*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
/* blue component */
bit0 = (*color_prom >> 0) & 0x01;
bit1 = (*color_prom >> 1) & 0x01;
bit2 = (*color_prom >> 2) & 0x01;
*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
color_prom++;
}
/* color_prom now points to the beginning of the lookup table */
/* character lookup table */
for (i = 0;i < TOTAL_COLORS(0);i++)
COLOR(0,i) = i;
/* sprite lookup table */
for (i = 0;i < TOTAL_COLORS(1);i++)
COLOR(1,i) = *(color_prom++) + 128;
}
/***************************************************************************
Start the video hardware emulation.
***************************************************************************/
int travrusa_vh_start(void)
{
if ((dirtybuffer = malloc(videoram_size)) == 0)
return 1;
memset(dirtybuffer,1,videoram_size);
if ((tmpbitmap = osd_create_bitmap(Machine->drv->screen_width*2,Machine->drv->screen_height)) == 0)
{
free(dirtybuffer);
return 1;
}
return 0;
}
/***************************************************************************
Stop the video hardware emulation.
***************************************************************************/
void travrusa_vh_stop(void)
{
free(dirtybuffer);
osd_free_bitmap(tmpbitmap);
}
void travrusa_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 travrusa_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
int offs;
/* for every character in the Video RAM, check if it has been modified */
/* since last time and update it accordingly. */
for (offs = videoram_size-2;offs >= 0;offs-=2)
{
if (dirtybuffer[offs] || dirtybuffer[offs+1])
{
int sx,sy,flipx,flipy;
dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
sx = (offs/2) % 64;
sy = (offs/2) / 64;
flipx = videoram[offs+1] & 0x20;
flipy = videoram[offs+1] & 0x10;
if (flipscreen)
{
sx = 63 - sx;
sy = 31 - sy;
flipx = !flipx;
flipy = !flipy;
}
drawgfx(tmpbitmap,Machine->gfx[0],
videoram[offs] + 4 * (videoram[offs+1] & 0xc0),
videoram[offs+1] & 0x0f,
flipx,flipy,
8*sx,8*sy,
0,TRANSPARENCY_NONE,0);
}
}
/* copy the temporary bitmap to the screen */
{
int scroll[32];
if (flipscreen)
{
for (offs = 0;offs < 24;offs++)
scroll[31-offs] = 256 + (*travrusa_scroll_x_high * 0x100 + *travrusa_scroll_x_low);
for (offs = 24;offs < 32;offs++)
scroll[31-offs] = 256;
}
else
{
for (offs = 0;offs < 24;offs++)
scroll[offs] = -(*travrusa_scroll_x_high * 0x100 + *travrusa_scroll_x_low);
for (offs = 24;offs < 32;offs++)
scroll[offs] = 0;
}
copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
}
/* copy the sprites */
for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
{
int sx,sy,flipx,flipy;
sx = spriteram[offs + 3];
sy = 240 - spriteram[offs];
flipx = spriteram[offs + 1] & 0x40;
flipy = spriteram[offs + 1] & 0x80;
if (flipscreen)
{
sx = 240 - sx;
sy = 240 - sy;
flipx = !flipx;
flipy = !flipy;
}
drawgfx(bitmap,Machine->gfx[1],
spriteram[offs + 2],
spriteram[offs + 1] & 0x0f,
flipx,flipy,
sx,sy,
flipscreen ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -