📄 nemesis.c
字号:
/***************************************************************************
vidhrdw.c
***************************************************************************/
#include "driver.h"
#include "vidhrdw/generic.h"
unsigned char *nemesis_videoram1;
unsigned char *nemesis_videoram2;
unsigned char *nemesis_characterram;
unsigned char *nemesis_characterram_gfx;
int nemesis_characterram_size;
unsigned char *nemesis_xscroll1,*nemesis_xscroll2,*nemesis_yscroll;
struct osd_bitmap *tmpbitmap2;
static unsigned char *video1_dirty; /* 0x800 chars - foreground */
static unsigned char *video2_dirty; /* 0x800 chars - background */
static unsigned char *char_dirty; /* 2048 chars */
static unsigned char *sprite_dirty; /* 512 sprites */
static unsigned char *sprite3216_dirty; /* 256 sprites */
static unsigned char *sprite816_dirty; /* 1024 sprites */
static unsigned char *sprite1632_dirty; /* 256 sprites */
static unsigned char *sprite3232_dirty; /* 128 sprites */
int nemesis_videoram1_r(int offset)
{
return READ_WORD(&nemesis_videoram1[offset]);
}
void nemesis_videoram1_w(int offset,int data)
{
COMBINE_WORD_MEM(&nemesis_videoram1[offset],data);
if (offset < 0x1000)
video1_dirty[offset / 2] = 1;
else
video2_dirty[(offset - 0x1000) / 2] = 1;
}
int nemesis_videoram2_r(int offset)
{
return READ_WORD(&nemesis_videoram2[offset]);
}
void nemesis_videoram2_w(int offset,int data)
{
COMBINE_WORD_MEM(&nemesis_videoram2[offset],data);
if (offset < 0x1000)
video1_dirty[offset / 2] = 1;
else
video2_dirty[(offset - 0x1000) / 2] = 1;
}
/* we have to straighten out the 16-bit word into bytes for gfxdecode() to work */
int nemesis_characterram_r(int offset)
{
int res;
res = READ_WORD(&nemesis_characterram_gfx[offset]);
#ifdef LSB_FIRST
res = ((res & 0x00ff) << 8) | ((res & 0xff00) >> 8);
#endif
return res;
}
void nemesis_characterram_w(int offset,int data)
{
int oldword = READ_WORD(&nemesis_characterram_gfx[offset]);
int newword;
COMBINE_WORD_MEM(&nemesis_characterram[offset],data); /* this is need so that twinbee can run code in the
character RAM */
#ifdef LSB_FIRST
data = ((data & 0x00ff00ff) << 8) | ((data & 0xff00ff00) >> 8);
#endif
newword = COMBINE_WORD(oldword,data);
if (oldword != newword)
{
WRITE_WORD(&nemesis_characterram_gfx[offset],newword);
char_dirty[offset / 32] = 1;
sprite_dirty[offset / 128] = 1;
sprite3216_dirty[offset / 256] = 1;
sprite1632_dirty[offset / 256] = 1;
sprite3232_dirty[offset / 512] = 1;
sprite816_dirty[offset / 64] = 1;
}
}
/* free the palette dirty array */
void nemesis_vh_stop(void)
{
osd_free_bitmap(tmpbitmap);
osd_free_bitmap(tmpbitmap2);
tmpbitmap=0;
free (char_dirty);
free (sprite_dirty);
free (sprite3216_dirty);
free (sprite1632_dirty);
free (sprite3232_dirty);
free (sprite816_dirty);
char_dirty = 0;
free (video1_dirty);
free (video2_dirty);
free (nemesis_characterram_gfx);
}
/* claim a palette dirty array */
int nemesis_vh_start(void)
{
if ((tmpbitmap = osd_new_bitmap(2 * Machine->drv->screen_width,Machine->drv->screen_height,Machine->scrbitmap->depth)) == 0)
{
nemesis_vh_stop();
return 1;
}
if ((tmpbitmap2 = osd_new_bitmap(2 * Machine->drv->screen_width,Machine->drv->screen_height,Machine->scrbitmap->depth)) == 0)
{
nemesis_vh_stop();
return 1;
}
char_dirty = malloc(2048);
if (!char_dirty) {
nemesis_vh_stop();
return 1;
}
memset(char_dirty,1,2048);
sprite_dirty = malloc(512);
if (!sprite_dirty) {
nemesis_vh_stop();
return 1;
}
memset(sprite_dirty,1,512);
sprite3216_dirty = malloc(256);
if (!sprite3216_dirty) {
nemesis_vh_stop();
return 1;
}
memset(sprite3216_dirty,1,256);
sprite1632_dirty = malloc(256);
if (!sprite1632_dirty) {
nemesis_vh_stop();
return 1;
}
memset(sprite1632_dirty,1,256);
sprite3232_dirty = malloc(128);
if (!sprite3232_dirty) {
nemesis_vh_stop();
return 1;
}
memset(sprite3232_dirty,1,128);
sprite816_dirty = malloc(1024);
if (!sprite816_dirty) {
nemesis_vh_stop();
return 1;
}
memset(sprite816_dirty,1,1024);
video1_dirty = malloc (0x800);
video2_dirty = malloc (0x800);
if (!video1_dirty || !video2_dirty)
{
nemesis_vh_stop();
return 1;
}
memset(video1_dirty,1,0x800);
memset(video2_dirty,1,0x800);
nemesis_characterram_gfx = malloc(nemesis_characterram_size);
if(!nemesis_characterram_gfx)
{
nemesis_vh_stop();
return 1;
}
memset(nemesis_characterram_gfx,0,nemesis_characterram_size);
return 0;
}
/* This is a bit slow, but it works. I'll speed it up later */
static void nemesis_drawgfx_zoomup(struct osd_bitmap *dest,const struct GfxElement *gfx,
unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
const struct rectangle *clip,int transparency,int transparent_color,int scale)
{
int ex,ey,y,start,dy;
const unsigned char *sd;
unsigned char *bm;
int col;
struct rectangle myclip;
int dda_x=0;
int dda_y=0;
int ex_count;
int ey_count;
int real_x;
const unsigned short *paldata; /* ASG 980209 */
int transmask;
if (!gfx) return;
code %= gfx->total_elements;
color %= gfx->total_colors;
transmask = 1 << transparent_color;
if ((gfx->pen_usage[code] & ~transmask) == 0)
/* character is totally transparent, no need to draw */
return;
if (Machine->orientation & ORIENTATION_SWAP_XY)
{
int temp;
temp = sx;
sx = sy;
sy = temp;
temp = flipx;
flipx = flipy;
flipy = temp;
if (clip)
{
/* clip and myclip might be the same, so we need a temporary storage */
temp = clip->min_x;
myclip.min_x = clip->min_y;
myclip.min_y = temp;
temp = clip->max_x;
myclip.max_x = clip->max_y;
myclip.max_y = temp;
clip = &myclip;
}
}
if (Machine->orientation & ORIENTATION_FLIP_X)
{
sx = dest->width - gfx->width - sx;
if (clip)
{
int temp;
/* clip and myclip might be the same, so we need a temporary storage */
temp = clip->min_x;
myclip.min_x = dest->width-1 - clip->max_x;
myclip.max_x = dest->width-1 - temp;
myclip.min_y = clip->min_y;
myclip.max_y = clip->max_y;
clip = &myclip;
}
}
if (Machine->orientation & ORIENTATION_FLIP_Y)
{
sy = dest->height - gfx->height - sy;
if (clip)
{
int temp;
myclip.min_x = clip->min_x;
myclip.max_x = clip->max_x;
/* clip and myclip might be the same, so we need a temporary storage */
temp = clip->min_y;
myclip.min_y = dest->height-1 - clip->max_y;
myclip.max_y = dest->height-1 - temp;
clip = &myclip;
}
}
/* check bounds */
/* Clipping currently done in code loop */
ex = sx + gfx->width-1;
ey = sy + gfx->height-1;
/* if (ex >= dest->width) ex = dest->width-1;
if (clip && ex > clip->max_x) ex = clip->max_x;
if (sx > ex) return;
if (ey >= dest->height) tey = dest->height-1;
if (clip && ey > clip->max_y) ey = clip->max_y;
if (sy > ey) return;
*/
/* start = code * gfx->height; */
if (flipy) /* Y flip */
{
start = code * gfx->height + gfx->height-1;
dy = -1;
}
else /* normal */
{
start = code * gfx->height;
dy = 1;
}
paldata = &gfx->colortable[gfx->color_granularity * color];
if (flipx) /* X flip */
{
y=sy;
dda_y=0x80;
ey_count=sy;
do
{
if(y>=clip->min_y && y<=clip->max_y)
{
bm = dest->line[y]+sx;
sd = (gfx->gfxdata->line[start] + gfx->width -1);
dda_x=0x80;
ex_count=sx;
col = *(sd);
real_x=sx;
do
{
if(real_x>clip->max_x) break;
if(real_x>=clip->min_x)
if (col != transparent_color) *bm = paldata[col];
bm++;
real_x++;
dda_x-=scale;
if(dda_x<=0)
{
dda_x+=0x80;
sd--;
ex_count++;
col = *(sd);
}
} while(ex_count <= ex);
}
y++;
dda_y-=scale;
if(dda_y<=0)
{
dda_y+=0x80;
start+=dy;
ey_count++;
}
} while(ey_count <= ey);
}
else /* normal */
{
y=sy;
dda_y=0x80;
ey_count=sy;
do
{
if(y>=clip->min_y && y<=clip->max_y)
{
bm = dest->line[y]+sx;
sd = (gfx->gfxdata->line[start]);
dda_x=0x80;
ex_count=sx;
col = *(sd);
real_x=sx;
do
{
if(real_x>clip->max_x) break;
if(real_x>=clip->min_x)
if (col != transparent_color) *bm = paldata[col];
bm++;
real_x++;
dda_x-=scale;
if(dda_x<=0)
{
dda_x+=0x80;
sd++;
ex_count++;
col = *(sd);
}
} while(ex_count <= ex);
}
y++;
dda_y-=scale;
if(dda_y<=0)
{
dda_y+=0x80;
start+=dy;
ey_count++;
}
} while(ey_count <= ey);
}
}
/* This is a bit slow, but it works. I'll speed it up later */
static void nemesis_drawgfx_zoomdown(struct osd_bitmap *dest,const struct GfxElement *gfx,
unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
const struct rectangle *clip,int transparency,int transparent_color,int scale)
{
int ex,ey,y,start,dy;
const unsigned char *sd;
unsigned char *bm;
int col;
struct rectangle myclip;
int dda_x=0;
int dda_y=0;
int ex_count;
int ey_count;
int real_x;
int ysize;
int xsize;
int transmask;
const unsigned short *paldata; /* ASG 980209 */
if (!gfx) return;
code %= gfx->total_elements;
color %= gfx->total_colors;
transmask = 1 << transparent_color;
if ((gfx->pen_usage[code] & ~transmask) == 0)
/* character is totally transparent, no need to draw */
return;
if (Machine->orientation & ORIENTATION_SWAP_XY)
{
int temp;
temp = sx;
sx = sy;
sy = temp;
temp = flipx;
flipx = flipy;
flipy = temp;
if (clip)
{
/* clip and myclip might be the same, so we need a temporary storage */
temp = clip->min_x;
myclip.min_x = clip->min_y;
myclip.min_y = temp;
temp = clip->max_x;
myclip.max_x = clip->max_y;
myclip.max_y = temp;
clip = &myclip;
}
}
if (Machine->orientation & ORIENTATION_FLIP_X)
{
sx = dest->width - gfx->width - sx;
if (clip)
{
int temp;
/* clip and myclip might be the same, so we need a temporary storage */
temp = clip->min_x;
myclip.min_x = dest->width-1 - clip->max_x;
myclip.max_x = dest->width-1 - temp;
myclip.min_y = clip->min_y;
myclip.max_y = clip->max_y;
clip = &myclip;
}
}
if (Machine->orientation & ORIENTATION_FLIP_Y)
{
sy = dest->height - gfx->height - sy;
if (clip)
{
int temp;
myclip.min_x = clip->min_x;
myclip.max_x = clip->max_x;
/* clip and myclip might be the same, so we need a temporary storage */
temp = clip->min_y;
myclip.min_y = dest->height-1 - clip->max_y;
myclip.max_y = dest->height-1 - temp;
clip = &myclip;
}
}
/* check bounds */
xsize=gfx->width;
ysize=gfx->height;
ex = sx + gfx->width-1;
if (ex >= dest->width) ex = dest->width-1;
if (clip && ex > clip->max_x) ex = clip->max_x;
if (sx > ex) return;
ey = sy + gfx->height-1;
if (ey >= dest->height) ey = dest->height-1;
if (clip && ey > clip->max_y) ey = clip->max_y;
if (sy > ey) return;
/* start = code * gfx->height; */
if (flipy) /* Y flip */
{
start = code * gfx->height + gfx->height-1;
dy = -1;
}
else /* normal */
{
start = code * gfx->height;
dy = 1;
}
paldata = &gfx->colortable[gfx->color_granularity * color];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -