Changed the sprite drawing functions to save sprite type & alpha.

I've figured out how to implement sprite blending, I'll do it soon.
This commit is contained in:
luigi__ 2009-01-18 00:39:24 +00:00
parent 4447955558
commit 45ee9f6bb5
3 changed files with 61 additions and 19 deletions

View File

@ -1529,8 +1529,8 @@ void extRotBG(GPU * gpu, u8 num, u8 * DST)
/* if i understand it correct, and it fixes some sprite problems in chameleon shot */
/* we have a 15 bit color, and should use the pal entry bits as alpha ?*/
/* http://nocash.emubase.de/gbatek.htm#dsvideoobjs */
INLINE void render_sprite_BMP (GPU * gpu, u16 l, u8 * dst, u16 * src, u8 * prioTab,
u8 prio, int lg, int sprX, int x, int xdir)
INLINE void render_sprite_BMP (GPU * gpu, u16 l, u8 * dst, u16 * src, u8 * dst_alpha, u8 * typeTab, u8 * prioTab,
u8 prio, int lg, int sprX, int x, int xdir, u8 alpha)
{
int i; u16 color;
for(i = 0; i < lg; i++, ++sprX, x+=xdir)
@ -1542,13 +1542,17 @@ INLINE void render_sprite_BMP (GPU * gpu, u16 l, u8 * dst, u16 * src, u8 * prioT
{
/* if we don't draw, do not set prio, or else */
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX))
{
dst_alpha[sprX] = alpha;
typeTab[sprX] = 3;
prioTab[sprX] = prio;
}
}
}
}
INLINE void render_sprite_256 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
u8 * prioTab, u8 prio, int lg, int sprX, int x, int xdir, u8 alpha)
u8 * dst_alpha, u8 * typeTab, u8 * prioTab, u8 prio, int lg, int sprX, int x, int xdir, u8 alpha)
{
int i;
u8 palette_entry;
@ -1564,13 +1568,17 @@ INLINE void render_sprite_256 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
{
/* if we don't draw, do not set prio, or else */
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX))
{
dst_alpha[sprX] = 16;
typeTab[sprX] = (alpha ? 1 : 0);
prioTab[sprX] = prio;
}
}
}
}
INLINE void render_sprite_16 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
u8 * prioTab, u8 prio, int lg, int sprX, int x, int xdir, u8 alpha)
u8 * dst_alpha, u8 * typeTab, u8 * prioTab, u8 prio, int lg, int sprX, int x, int xdir, u8 alpha)
{
int i;
u8 palette, palette_entry;
@ -1589,9 +1597,13 @@ INLINE void render_sprite_16 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
{
/* if we don't draw, do not set prio, or else */
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX ))
{
dst_alpha[sprX] = 16;
typeTab[sprX] = (alpha ? 1 : 0);
prioTab[sprX] = prio;
}
}
}
}
INLINE void render_sprite_Win (GPU * gpu, u16 l, u8 * src,
@ -1670,7 +1682,7 @@ INLINE BOOL compute_sprite_vars(_OAM_ * spriteInfo, u16 l,
/*****************************************************************************/
// SPRITE RENDERING
/*****************************************************************************/
void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab)
{
struct _DISPCNT * dispCnt = &(gpu->dispx_st)->dispx_DISPCNT.bits;
_OAM_ * spriteInfo = (_OAM_ *)(gpu->oam + (nbShow-1));// + 127;
@ -1797,9 +1809,13 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
if (colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, T1ReadWord(pal, colour<<1), sprX ))
{
dst_alpha[sprX] = 16;
typeTab[sprX] = spriteInfo->Mode;
prioTab[sprX] = prio;
}
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
// is performed
@ -1832,9 +1848,13 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
if((colour&0x8000) && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, colour, sprX))
{
dst_alpha[sprX] = spriteInfo->PaletteIndex;
typeTab[sprX] = spriteInfo->Mode;
prioTab[sprX] = prio;
}
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
// is performed
@ -1869,9 +1889,13 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
if(colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, T1ReadWord(pal, colour<<1), sprX ))
{
dst_alpha[sprX] = 16;
typeTab[sprX] = spriteInfo->Mode;
prioTab[sprX] = prio;
}
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
// is performed
@ -1918,7 +1942,7 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
}
CHECK_SPRITE(1);
render_sprite_BMP (gpu, l, dst, (u16*)src, prioTab, prio, lg, sprX, x, xdir);
render_sprite_BMP (gpu, l, dst, (u16*)src, dst_alpha, typeTab, prioTab, prio, lg, sprX, x, xdir, spriteInfo->PaletteIndex);
continue;
}
@ -1933,7 +1957,7 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
pal = (u16*)(ARM9Mem.ARM9_VMEM + 0x200 + gpu->core *0x400);
//sprwin test hack - to enable, only draw win and not sprite
render_sprite_256 (gpu, l, dst, src, pal, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
render_sprite_256 (gpu, l, dst, src, pal, dst_alpha, typeTab, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
//render_sprite_Win (gpu, l, src, spriteInfo->Depth, lg, sprX, x, xdir);
continue;
@ -1946,7 +1970,7 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
pal += (spriteInfo->PaletteIndex<<4);
//sprwin test hack - to enable, only draw win and not sprite
render_sprite_16 (gpu, l, dst, src, pal, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
render_sprite_16 (gpu, l, dst, src, pal, dst_alpha, typeTab, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
//render_sprite_Win (gpu, l, src, spriteInfo->Depth, lg, sprX, x, xdir);
}
}
@ -1957,7 +1981,7 @@ void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
#endif
}
void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab)
{
struct _DISPCNT * dispCnt = &(gpu->dispx_st)->dispx_DISPCNT.bits;
_OAM_ * spriteInfo = (_OAM_*)(gpu->oam + (nbShow-1));// + 127;
@ -2083,9 +2107,13 @@ void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
if (colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, T1ReadWord(pal, colour<<1), sprX ))
{
dst_alpha[sprX] = 16;
typeTab[sprX] = spriteInfo->Mode;
prioTab[sprX] = prio;
}
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
// is performed
@ -2118,9 +2146,13 @@ void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
if((colour&0x8000) && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, colour, sprX ))
{
dst_alpha[sprX] = spriteInfo->PaletteIndex;
typeTab[sprX] = spriteInfo->Mode;
prioTab[sprX] = prio;
}
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
// is performed
@ -2154,9 +2186,13 @@ void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
if(colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, T1ReadWord (pal, colour<<1), sprX))
{
dst_alpha[sprX] = 16;
typeTab[sprX] = spriteInfo->Mode;
prioTab[sprX] = prio;
}
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
// is performed
@ -2202,7 +2238,7 @@ void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
}
CHECK_SPRITE(2);
render_sprite_BMP (gpu, l, dst, (u16*)src, prioTab, prio, lg, sprX, x, xdir);
render_sprite_BMP (gpu, l, dst, (u16*)src, dst_alpha, typeTab, prioTab, prio, lg, sprX, x, xdir, spriteInfo->PaletteIndex);
continue;
}
@ -2218,7 +2254,7 @@ void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
pal = (u16*)(ARM9Mem.ARM9_VMEM + 0x200 + gpu->core *0x400);
render_sprite_256 (gpu, l, dst, src, pal,
prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
dst_alpha, typeTab, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
continue;
}
@ -2230,7 +2266,7 @@ void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
pal += (spriteInfo->PaletteIndex<<4);
render_sprite_16 (gpu, l, dst, src, pal,
prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
dst_alpha, typeTab, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1);
}
}
@ -2412,6 +2448,8 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
u8 * dst = (u8 *)(GPU_screen) + (screen->offset + l) * 512;
itemsForPriority_t * item;
u8 spr[512];
u8 sprAlpha[256];
u8 sprType[256];
u8 sprPrio[256];
u8 prio;
u16 i16;
@ -2445,6 +2483,8 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
!gpu->LayersEnable[4]) return;
// init background color & priorities
memset(sprAlpha, 0, 256);
memset(sprType, 0, 256);
memset(sprPrio,0xFF,256);
memset(sprWin,0,256);
@ -2457,7 +2497,7 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
if (gpu->LayersEnable[4])
{
for(int i = 0; i< 256; ++i) T2WriteWord(spr, i << 1, c);
gpu->spriteRender(gpu, l, dst, spr, sprPrio);
gpu->spriteRender(gpu, l, spr, sprAlpha, sprType, sprPrio);
for(int i = 0; i<256; i++)
{

View File

@ -669,7 +669,7 @@ struct _GPU
BOOL (*setFinalColorSpr)(GPU *gpu, u32 passing, u8 bgnum, u8 *dst, u16 color, u16 x);
BOOL (*setFinalColorBck)(GPU *gpu, u32 passing, u8 bgnum, u8 *dst, u16 color, u16 x);
BOOL (*setFinalColor3D) (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x);
void (*spriteRender) (GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab);
void (*spriteRender) (GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab);
};
/*
// normally should have same addresses
@ -701,8 +701,8 @@ void GPU_DeInit(GPU *);
void textBG(GPU * gpu, u8 num, u8 * DST); //Draw text based background
void rotBG(GPU * gpu, u8 num, u8 * DST);
void extRotBG(GPU * gpu, u8 num, u8 * DST);
void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab);
void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab);
void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab);
void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab);
extern const short sizeTab[4][4][2];
extern const size sprSizeTab[4][4];

View File

@ -89,7 +89,8 @@ LRESULT OamView_OnPaint(HWND hwnd, oamview_struct *win, WPARAM wParam, LPARAM lP
OAM * oam = &win->oam[win->num];
char text[80];
u16 bitmap[256*192];
u16 bitmap_under[256*192];
u8 bitmap_alpha[256*192];
u8 type[256*192];
u8 prio[256*192];
BITMAPV4HEADER bmi;
u16 i;
@ -110,7 +111,8 @@ LRESULT OamView_OnPaint(HWND hwnd, oamview_struct *win, WPARAM wParam, LPARAM lP
for(i = 0; i < 256*192; ++i)
{
bitmap[i] = 0x7F0F;
bitmap_under[i] = 0x7F0F;
bitmap_alpha[i] = 0;
type[i] = 0;
prio[i] = 4;
}
@ -177,7 +179,7 @@ LRESULT OamView_OnPaint(HWND hwnd, oamview_struct *win, WPARAM wParam, LPARAM lP
for(i = 0; i < 192; ++i)
{
win->gpu->spriteRender(win->gpu, i, (u8*)(bitmap_under + i*256), (u8*)(bitmap + i*256), prio + i*256);
win->gpu->spriteRender(win->gpu, i, (u8*)(bitmap + i*256), bitmap_alpha + i*256, type + i*256, prio + i*256);
}
SetDIBitsToDevice(hdc, 180, 4, 256, 192, 0, 0, 0, 192, bitmap, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);