Reverted the direct sprite blitting as it causes problems when sprites are behind translucent backgrounds.

Added a new param to the sprite rendering funcs, meant for proper sprite blending.
This commit is contained in:
luigi__ 2009-01-17 15:08:55 +00:00
parent fd69a0e0aa
commit e271c6c4eb
3 changed files with 360 additions and 411 deletions

View File

@ -266,7 +266,7 @@ void GPU_Reset(GPU *g, u8 l)
g->spriteRender = sprite1D;
g->bgPrio[4] = 4;
g->bgPrio[4] = 0xFF;
if(g->core == GPU_SUB)
{
@ -597,7 +597,6 @@ static BOOL setFinalBGColorSpecialNone (GPU *gpu, u32 passing, u8 bgnum, u8 *dst
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
return 1;
}
@ -633,13 +632,11 @@ static BOOL setFinalBGColorSpecialBlend (GPU *gpu, u32 passing, u8 bgnum, u8 *ds
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
return 1;
@ -666,13 +663,11 @@ static BOOL setFinalBGColorSpecialIncrease (GPU *gpu, u32 passing, u8 bgnum, u8
T2WriteWord(dst, passing, color) ;
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
return 1;
@ -698,13 +693,11 @@ static BOOL setFinalBGColorSpecialDecrease (GPU *gpu, u32 passing, u8 bgnum, u8
}
T2WriteWord(dst, passing, color) ;
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
return 1;
@ -720,7 +713,6 @@ static BOOL setFinalBGColorSpecialNoneWnd (GPU *gpu, u32 passing, u8 bgnum, u8 *
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
@ -728,7 +720,6 @@ static BOOL setFinalBGColorSpecialNoneWnd (GPU *gpu, u32 passing, u8 bgnum, u8 *
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
}
@ -772,7 +763,6 @@ static BOOL setFinalBGColorSpecialBlendWnd (GPU *gpu, u32 passing, u8 bgnum, u8
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
@ -780,7 +770,6 @@ static BOOL setFinalBGColorSpecialBlendWnd (GPU *gpu, u32 passing, u8 bgnum, u8
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
}
@ -812,7 +801,6 @@ static BOOL setFinalBGColorSpecialIncreaseWnd (GPU *gpu, u32 passing, u8 bgnum,
T2WriteWord(dst, passing, color) ;
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
@ -820,7 +808,6 @@ static BOOL setFinalBGColorSpecialIncreaseWnd (GPU *gpu, u32 passing, u8 bgnum,
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
}
@ -851,7 +838,6 @@ static BOOL setFinalBGColorSpecialDecreaseWnd (GPU *gpu, u32 passing, u8 bgnum,
}
T2WriteWord(dst, passing, color) ;
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
else
{
@ -859,7 +845,6 @@ static BOOL setFinalBGColorSpecialDecreaseWnd (GPU *gpu, u32 passing, u8 bgnum,
{
T2WriteWord(dst, passing, color);
gpu->bgPixels[x] = bgnum;
gpu->bgPxPrio[x] = gpu->bgPrio[bgnum];
}
}
@ -874,7 +859,6 @@ static BOOL setFinal3DColorSpecialNone(GPU *gpu, u32 passing, u8 *dst, u16 color
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
return 1;
}
@ -916,13 +900,11 @@ static BOOL setFinal3DColorSpecialBlend(GPU *gpu, u32 passing, u8 *dst, u16 colo
T2WriteWord(dst, passing, (final | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
else
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
return 1;
@ -939,13 +921,11 @@ static BOOL setFinal3DColorSpecialIncrease(GPU *gpu, u32 passing, u8 *dst, u16 c
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
else
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
return 1;
@ -962,13 +942,11 @@ static BOOL setFinal3DColorSpecialDecrease(GPU *gpu, u32 passing, u8 *dst, u16 c
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
else
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
return 1;
@ -984,7 +962,6 @@ static BOOL setFinal3DColorSpecialNoneWnd(GPU *gpu, u32 passing, u8 *dst, u16 co
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
return windowDraw;
@ -1034,13 +1011,11 @@ static BOOL setFinal3DColorSpecialBlendWnd(GPU *gpu, u32 passing, u8 *dst, u16 c
T2WriteWord(dst, passing, (final | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
else
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
}
@ -1064,13 +1039,11 @@ static BOOL setFinal3DColorSpecialIncreaseWnd(GPU *gpu, u32 passing, u8 *dst, u1
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
else
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
}
@ -1094,13 +1067,11 @@ static BOOL setFinal3DColorSpecialDecreaseWnd(GPU *gpu, u32 passing, u8 *dst, u1
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
else
{
T2WriteWord(dst, passing, (color | 0x8000));
gpu->bgPixels[x] = 0;
gpu->bgPxPrio[x] = gpu->bgPrio[0];
}
}
@ -1567,14 +1538,12 @@ INLINE void render_sprite_BMP (GPU * gpu, u16 l, u8 * dst, u16 * src, u8 * prioT
color = LE_TO_LOCAL_16(src[x]);
// alpha bit = invisible
/*if ((color&0x8000)&&(prio<=prioTab[sprX]))
if ((color&0x8000)&&(prio<=prioTab[sprX]))
{
/* if we don't draw, do not set prio, or else *-/
/* if we don't draw, do not set prio, or else */
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX))
prioTab[sprX] = prio;
}*/
if ((color&0x8000) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX);
}
}
}
@ -1591,14 +1560,12 @@ INLINE void render_sprite_256 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
color = LE_TO_LOCAL_16(pal[palette_entry]);
// palette entry = 0 means backdrop
/*if ((palette_entry>0)&&(prio<=prioTab[sprX]))
if ((palette_entry>0)&&(prio<=prioTab[sprX]))
{
/* if we don't draw, do not set prio, or else *-/
/* if we don't draw, do not set prio, or else */
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX))
prioTab[sprX] = prio;
}*/
if ((palette_entry>0) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX);
}
}
}
@ -1618,14 +1585,12 @@ INLINE void render_sprite_16 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
color = LE_TO_LOCAL_16(pal[palette_entry]);
// palette entry = 0 means backdrop
/*if ((palette_entry>0)&&(prio<=prioTab[sprX]))
if ((palette_entry>0)&&(prio<=prioTab[sprX]))
{
/* if we don't draw, do not set prio, or else *-/
/* if we don't draw, do not set prio, or else */
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX ))
prioTab[sprX] = prio;
}*/
if ((palette_entry>0) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, color, sprX);
}
}
}
@ -1705,7 +1670,7 @@ INLINE BOOL compute_sprite_vars(_OAM_ * spriteInfo, u16 l,
/*****************************************************************************/
// SPRITE RENDERING
/*****************************************************************************/
void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
void sprite1D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
{
struct _DISPCNT * dispCnt = &(gpu->dispx_st)->dispx_DISPCNT.bits;
_OAM_ * spriteInfo = (_OAM_ *)(gpu->oam + (nbShow-1));// + 127;
@ -1829,13 +1794,11 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
offset = (auxX&0x7) + ((auxX&0xFFF8)<<3) + ((auxY>>3)*sprSize.x*8) + ((auxY&0x7)*8);
colour = src[offset];
/* if (colour && (prioTab[sprX]>=prio))
if (colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, T1ReadWord(pal, colour<<1), sprX ))
prioTab[sprX] = prio;
}*/
if ((colour) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, T1ReadWord(pal, colour<<1), sprX);
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
@ -1866,13 +1829,11 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
offset = (auxX) + (auxY<<5);
colour = T1ReadWord (src, offset<<1);
/*if((colour&0x8000) && (prioTab[sprX]>=prio))
if((colour&0x8000) && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, colour, sprX))
prioTab[sprX] = prio;
}*/
if ((colour&0x8000) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, colour, sprX);
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
@ -1905,13 +1866,11 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
if (auxX&1) colour >>= 4;
else colour &= 0xF;
/* if(colour && (prioTab[sprX]>=prio))
if(colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, T1ReadWord(pal, colour<<1), sprX ))
prioTab[sprX] = prio;
}*/
if ((colour) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, T1ReadWord(pal, colour<<1), sprX);
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
@ -1998,7 +1957,7 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
#endif
}
void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
void sprite2D(GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab)
{
struct _DISPCNT * dispCnt = &(gpu->dispx_st)->dispx_DISPCNT.bits;
_OAM_ * spriteInfo = (_OAM_*)(gpu->oam + (nbShow-1));// + 127;
@ -2121,13 +2080,11 @@ void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
offset = (auxX&0x7) + ((auxX&0xFFF8)<<3) + ((auxY>>3)<<10) + ((auxY&0x7)*8);
colour = src[offset];
/* if (colour && (prioTab[sprX]>=prio))
if (colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, T1ReadWord(pal, colour<<1), sprX ))
prioTab[sprX] = prio;
}*/
if ((colour) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, T1ReadWord(pal, colour<<1), sprX);
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
@ -2158,13 +2115,11 @@ void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
offset = auxX + (auxY<<8);
colour = T1ReadWord(src, offset<<1);
/* if((colour&0x8000) && (prioTab[sprX]>=prio))
if((colour&0x8000) && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1, 4, dst, colour, sprX ))
prioTab[sprX] = prio;
}*/
if ((colour&0x8000) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, colour, sprX);
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
@ -2196,13 +2151,11 @@ void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
if (auxX&1) colour >>= 4;
else colour &= 0xF;
/* if(colour && (prioTab[sprX]>=prio))
if(colour && (prioTab[sprX]>=prio))
{
if (gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, T1ReadWord (pal, colour<<1), sprX))
prioTab[sprX] = prio;
}*/
if ((colour) && (prio <= gpu->bgPxPrio[sprX]))
gpu->setFinalColorSpr(gpu, sprX << 1,4,dst, T1ReadWord(pal, colour<<1), sprX);
}
}
// Add the rotation/scale coeficients, here the rotation/scaling
@ -2487,8 +2440,6 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
/* reset them to backdrop */
memset(gpu->bgPixels, 5, 256);
memset(gpu->bgPxPrio, 0xFF, 256);
if (!gpu->LayersEnable[0] && !gpu->LayersEnable[1] &&
!gpu->LayersEnable[2] && !gpu->LayersEnable[3] &&
!gpu->LayersEnable[4]) return;
@ -2503,10 +2454,10 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
}
// for all the pixels in the line
/*if (gpu->LayersEnable[4])
if (gpu->LayersEnable[4])
{
for(int i = 0; i< 256; ++i) T2WriteWord(spr, i << 1, c);
gpu->spriteRender(gpu, l, spr, sprPrio);
gpu->spriteRender(gpu, l, dst, spr, sprPrio);
for(int i = 0; i<256; i++)
{
@ -2518,7 +2469,7 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
item->PixelsX[item->nbPixelsX]=i;
item->nbPixelsX++;
}
}*/
}
if (!gpu->LayersEnable[0] && !gpu->LayersEnable[1] && !gpu->LayersEnable[2] && !gpu->LayersEnable[3])
@ -2569,18 +2520,15 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l)
}
}
// render sprite Pixels
/* if (gpu->LayersEnable[4])
if (gpu->LayersEnable[4])
{
for (int i=0; i < item->nbPixelsX; i++)
{
i16=item->PixelsX[i];
T2WriteWord(dst, i16 << 1, T2ReadWord(spr, i16 << 1));
}
}*/
}
}
if(gpu->LayersEnable[4])
gpu->spriteRender(gpu, l, dst, sprPrio);
}
// TODO: capture emulated not fully

View File

@ -664,13 +664,12 @@ struct _GPU
u32 MasterBrightFactor;
u8 bgPixels[256];
u8 bgPxPrio[256];
u8 currLine;
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 * dst, u8 * prioTab);
void (*spriteRender) (GPU * gpu, u16 l, u8 * buf_under, u8 * dst, u8 * prioTab);
};
/*
// normally should have same addresses
@ -702,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 * dst, u8 * prioTab);
void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab);
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);
extern const short sizeTab[4][4][2];
extern const size sprSizeTab[4][4];

View File

@ -1,242 +1,244 @@
/* Copyright (C) 2006 yopyop
yopyop156@ifrance.com
yopyop156.ifrance.com
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "oamView.h"
#include <commctrl.h>
#include "debug.h"
#include "resource.h"
#include "../MMU.h"
#include "../GPU.h"
#include "../NDSSystem.h"
typedef struct
{
u32 autoup_secs;
bool autoup;
s16 num;
OAM *oam;
GPU *gpu;
} oamview_struct;
oamview_struct *OAMView = NULL;
//extern NDSSystem nds;
const char dimm[4][4][8] =
{
{"8 x 8", "16 x 8", "8 x 16", "- x -"},
{"16 x 16", "32 x 8", "8 x 32", "- x -"},
{"32 x 32", "32 x 16", "16 x 32", "- x -"},
{"64 x 64", "64 x 32", "32 x 64", "- x -"},
};
LRESULT OAMViewBox_OnPaint(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
//HWND hwnd = GetDlgItem(win->hwnd, IDC_OAM_BOX);
HDC hdc;
PAINTSTRUCT ps;
// TCHAR text[80];
RECT rect;
int lg;
int ht;
HDC mem_dc;
HBITMAP mem_bmp;
GetClientRect(hwnd, &rect);
lg = rect.right - rect.left;
ht = rect.bottom - rect.top;
hdc = BeginPaint(hwnd, &ps);
mem_dc = CreateCompatibleDC(hdc);
mem_bmp = CreateCompatibleBitmap(hdc, lg, ht);
SelectObject(mem_dc, mem_bmp);
FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
BitBlt(hdc, 0, 0, lg, ht, mem_dc, 0, 0, SRCCOPY);
DeleteDC(mem_dc);
DeleteObject(mem_bmp);
EndPaint(hwnd, &ps);
return 0;
}
LRESULT OamView_OnPaint(HWND hwnd, oamview_struct *win, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
OAM * oam = &win->oam[win->num];
char text[80];
u16 bitmap[256*192];
u8 prio[256*192];
BITMAPV4HEADER bmi;
u16 i;
s16 x;
//CreateBitmapIndirect(&bmi);
memset(&bmi, 0, sizeof(bmi));
bmi.bV4Size = sizeof(bmi);
bmi.bV4Planes = 1;
bmi.bV4BitCount = 16;
bmi.bV4V4Compression = BI_RGB|BI_BITFIELDS;
bmi.bV4RedMask = 0x001F;
bmi.bV4GreenMask = 0x03E0;
bmi.bV4BlueMask = 0x7C00;
bmi.bV4Width = 256;
bmi.bV4Height = -192;
for(i = 0; i < 256*192; ++i)
{
bitmap[i] = 0x7F0F;
prio[i] = 4;
}
hdc = BeginPaint(hwnd, &ps);
sprintf(text, "OAM : %d", win->num);
SetWindowText(GetDlgItem(hwnd, IDC_OAMNUM), text);
switch(oam->attr0&(3<<10))
{
case 0 :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "Normal");
break;
case (1<<10) :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "Smi-transp");
break;
case (2<<10) :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "OBJ Window");
break;
case (3<<10) :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "Bitmap");
}
sprintf(text, "0x%08X", oam->attr0/*oam->attr2&0x3FF*/);
SetWindowText(GetDlgItem(hwnd, IDC_TILE), text);
sprintf(text, "0x%08X", oam->attr1/*oam->attr2&0x3FF*/);
SetWindowText(GetDlgItem(hwnd, IDC_PAL), text);
//SetWindowText(GetDlgItem(hwnd, IDC_PAL), (oam->attr0&(1<<13))?"256 couleurs": "16 couleurs");
sprintf(text, "%d 0x%08X", (oam->attr2>>10)&3, oam->attr2);
SetWindowText(GetDlgItem(hwnd, IDC_PRIO), text);
x = oam->attr1&0x1FF;
x = ((s16)(x<<7)>>7);
sprintf(text, "%d x %d", x, oam->attr0&0xFF);
SetWindowText(GetDlgItem(hwnd, IDC_COOR), text);
SetWindowText(GetDlgItem(hwnd, IDC_DIM), dimm[oam->attr1>>14][oam->attr0>>14]);
SetWindowText(GetDlgItem(hwnd, IDC_ROT), oam->attr0&(1<<8)?"ON" : "OFF");
SetWindowText(GetDlgItem(hwnd, IDC_MOS), oam->attr0&(1<<12)?"ON" : "OFF");
if(oam->attr0&(1<<8))
{
sprintf(text, "Rot param : %d", (oam->attr1>>9)&0x1F);
SetWindowText(GetDlgItem(hwnd, IDC_PROP0), text);
SetWindowText(GetDlgItem(hwnd, IDC_PROP1), (oam->attr0&(1<<9))?"Double size": "");
}
else
{
if(oam->attr0&(1<<9))
sprintf(text, "INVISIBLE");
else
sprintf(text, "%s %s", oam->attr0&(1<<12)?"H FLIP":"", oam->attr0&(1<<13)?"V FLIP":"");
SetWindowText(GetDlgItem(hwnd, IDC_PROP0), text);
SetWindowText(GetDlgItem(hwnd, IDC_PROP1), "");
}
for(i = 0; i < 192; ++i)
{
win->gpu->spriteRender(win->gpu, i, (u8*)(bitmap + i*256), prio + i*256);
}
SetDIBitsToDevice(hdc, 180, 4, 256, 192, 0, 0, 0, 192, bitmap, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
EndPaint(hwnd, &ps);
return 0;
}
LRESULT CALLBACK ViewOAMBoxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_NCCREATE:
return 1;
case WM_NCDESTROY:
return 1;
case WM_PAINT:
OAMViewBox_OnPaint(hwnd, wParam, lParam);
return 1;
case WM_ERASEBKGND:
return 1;
default:
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
BOOL CALLBACK ViewOAMProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//bail out early if the dialog isnt initialized
if(!OAMView && message != WM_INITDIALOG)
return false;
switch (message)
{
case WM_INITDIALOG :
{
OAMView = new oamview_struct;
memset(OAMView, 0, sizeof(oamview_struct));
OAMView->oam = (OAM *)(ARM9Mem.ARM9_OAM);
OAMView->gpu = MainScreen.gpu;
OAMView->autoup_secs = 5;
SendMessage(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN),
UDM_SETRANGE, 0, MAKELONG(99, 1));
SendMessage(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN),
UDM_SETPOS32, 0, OAMView->autoup_secs);
HWND combo = GetDlgItem(hwnd, IDC_SCR_SELECT);
SendMessage(combo, CB_ADDSTRING, 0,(LPARAM)"Main screen sprite");
SendMessage(combo, CB_ADDSTRING, 0,(LPARAM)"Sub screen sprite");
SendMessage(combo, CB_SETCURSEL, 0, 0);
}
return 1;
case WM_CLOSE :
/* Copyright (C) 2006 yopyop
yopyop156@ifrance.com
yopyop156.ifrance.com
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "oamView.h"
#include <commctrl.h>
#include "debug.h"
#include "resource.h"
#include "../MMU.h"
#include "../GPU.h"
#include "../NDSSystem.h"
typedef struct
{
u32 autoup_secs;
bool autoup;
s16 num;
OAM *oam;
GPU *gpu;
} oamview_struct;
oamview_struct *OAMView = NULL;
//extern NDSSystem nds;
const char dimm[4][4][8] =
{
{"8 x 8", "16 x 8", "8 x 16", "- x -"},
{"16 x 16", "32 x 8", "8 x 32", "- x -"},
{"32 x 32", "32 x 16", "16 x 32", "- x -"},
{"64 x 64", "64 x 32", "32 x 64", "- x -"},
};
LRESULT OAMViewBox_OnPaint(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
//HWND hwnd = GetDlgItem(win->hwnd, IDC_OAM_BOX);
HDC hdc;
PAINTSTRUCT ps;
// TCHAR text[80];
RECT rect;
int lg;
int ht;
HDC mem_dc;
HBITMAP mem_bmp;
GetClientRect(hwnd, &rect);
lg = rect.right - rect.left;
ht = rect.bottom - rect.top;
hdc = BeginPaint(hwnd, &ps);
mem_dc = CreateCompatibleDC(hdc);
mem_bmp = CreateCompatibleBitmap(hdc, lg, ht);
SelectObject(mem_dc, mem_bmp);
FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
BitBlt(hdc, 0, 0, lg, ht, mem_dc, 0, 0, SRCCOPY);
DeleteDC(mem_dc);
DeleteObject(mem_bmp);
EndPaint(hwnd, &ps);
return 0;
}
LRESULT OamView_OnPaint(HWND hwnd, oamview_struct *win, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
OAM * oam = &win->oam[win->num];
char text[80];
u16 bitmap[256*192];
u16 bitmap_under[256*192];
u8 prio[256*192];
BITMAPV4HEADER bmi;
u16 i;
s16 x;
//CreateBitmapIndirect(&bmi);
memset(&bmi, 0, sizeof(bmi));
bmi.bV4Size = sizeof(bmi);
bmi.bV4Planes = 1;
bmi.bV4BitCount = 16;
bmi.bV4V4Compression = BI_RGB|BI_BITFIELDS;
bmi.bV4RedMask = 0x001F;
bmi.bV4GreenMask = 0x03E0;
bmi.bV4BlueMask = 0x7C00;
bmi.bV4Width = 256;
bmi.bV4Height = -192;
for(i = 0; i < 256*192; ++i)
{
bitmap[i] = 0x7F0F;
bitmap_under[i] = 0x7F0F;
prio[i] = 4;
}
hdc = BeginPaint(hwnd, &ps);
sprintf(text, "OAM : %d", win->num);
SetWindowText(GetDlgItem(hwnd, IDC_OAMNUM), text);
switch(oam->attr0&(3<<10))
{
case 0 :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "Normal");
break;
case (1<<10) :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "Smi-transp");
break;
case (2<<10) :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "OBJ Window");
break;
case (3<<10) :
SetWindowText(GetDlgItem(hwnd, IDC_MODE), "Bitmap");
}
sprintf(text, "0x%08X", oam->attr0/*oam->attr2&0x3FF*/);
SetWindowText(GetDlgItem(hwnd, IDC_TILE), text);
sprintf(text, "0x%08X", oam->attr1/*oam->attr2&0x3FF*/);
SetWindowText(GetDlgItem(hwnd, IDC_PAL), text);
//SetWindowText(GetDlgItem(hwnd, IDC_PAL), (oam->attr0&(1<<13))?"256 couleurs": "16 couleurs");
sprintf(text, "%d 0x%08X", (oam->attr2>>10)&3, oam->attr2);
SetWindowText(GetDlgItem(hwnd, IDC_PRIO), text);
x = oam->attr1&0x1FF;
x = ((s16)(x<<7)>>7);
sprintf(text, "%d x %d", x, oam->attr0&0xFF);
SetWindowText(GetDlgItem(hwnd, IDC_COOR), text);
SetWindowText(GetDlgItem(hwnd, IDC_DIM), dimm[oam->attr1>>14][oam->attr0>>14]);
SetWindowText(GetDlgItem(hwnd, IDC_ROT), oam->attr0&(1<<8)?"ON" : "OFF");
SetWindowText(GetDlgItem(hwnd, IDC_MOS), oam->attr0&(1<<12)?"ON" : "OFF");
if(oam->attr0&(1<<8))
{
sprintf(text, "Rot param : %d", (oam->attr1>>9)&0x1F);
SetWindowText(GetDlgItem(hwnd, IDC_PROP0), text);
SetWindowText(GetDlgItem(hwnd, IDC_PROP1), (oam->attr0&(1<<9))?"Double size": "");
}
else
{
if(oam->attr0&(1<<9))
sprintf(text, "INVISIBLE");
else
sprintf(text, "%s %s", oam->attr0&(1<<12)?"H FLIP":"", oam->attr0&(1<<13)?"V FLIP":"");
SetWindowText(GetDlgItem(hwnd, IDC_PROP0), text);
SetWindowText(GetDlgItem(hwnd, IDC_PROP1), "");
}
for(i = 0; i < 192; ++i)
{
win->gpu->spriteRender(win->gpu, i, (u8*)(bitmap_under + i*256), (u8*)(bitmap + i*256), prio + i*256);
}
SetDIBitsToDevice(hdc, 180, 4, 256, 192, 0, 0, 0, 192, bitmap, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
EndPaint(hwnd, &ps);
return 0;
}
LRESULT CALLBACK ViewOAMBoxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_NCCREATE:
return 1;
case WM_NCDESTROY:
return 1;
case WM_PAINT:
OAMViewBox_OnPaint(hwnd, wParam, lParam);
return 1;
case WM_ERASEBKGND:
return 1;
default:
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
BOOL CALLBACK ViewOAMProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//bail out early if the dialog isnt initialized
if(!OAMView && message != WM_INITDIALOG)
return false;
switch (message)
{
case WM_INITDIALOG :
{
OAMView = new oamview_struct;
memset(OAMView, 0, sizeof(oamview_struct));
OAMView->oam = (OAM *)(ARM9Mem.ARM9_OAM);
OAMView->gpu = MainScreen.gpu;
OAMView->autoup_secs = 5;
SendMessage(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN),
UDM_SETRANGE, 0, MAKELONG(99, 1));
SendMessage(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN),
UDM_SETPOS32, 0, OAMView->autoup_secs);
HWND combo = GetDlgItem(hwnd, IDC_SCR_SELECT);
SendMessage(combo, CB_ADDSTRING, 0,(LPARAM)"Main screen sprite");
SendMessage(combo, CB_ADDSTRING, 0,(LPARAM)"Sub screen sprite");
SendMessage(combo, CB_SETCURSEL, 0, 0);
}
return 1;
case WM_CLOSE :
{
if(OAMView->autoup)
{
KillTimer(hwnd, IDT_VIEW_OAM);
OAMView->autoup = false;
if(OAMView->autoup)
{
KillTimer(hwnd, IDT_VIEW_OAM);
OAMView->autoup = false;
}
if (OAMView!=NULL)
@ -247,94 +249,94 @@ BOOL CALLBACK ViewOAMProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
//INFO("Close OAM viewer dialog\n");
PostQuitMessage(0);
return 0;
}
case WM_PAINT:
OamView_OnPaint(hwnd, OAMView, wParam, lParam);
return 1;
case WM_TIMER:
SendMessage(hwnd, WM_COMMAND, IDC_REFRESH, 0);
return 1;
case WM_HSCROLL :
switch LOWORD(wParam)
{
case SB_LINERIGHT :
++(OAMView->num);
if(OAMView->num>127)
OAMView->num = 127;
break;
case SB_LINELEFT :
--(OAMView->num);
if(OAMView->num<0)
OAMView->num = 0;
break;
}
InvalidateRect(hwnd, NULL, FALSE);
return 1;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDC_FERMER :
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 1;
case IDC_AUTO_UPDATE :
if(OAMView->autoup)
{
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SECS), false);
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN), false);
KillTimer(hwnd, IDT_VIEW_OAM);
OAMView->autoup = FALSE;
return 1;
}
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SECS), true);
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN), true);
OAMView->autoup = TRUE;
SetTimer(hwnd, IDT_VIEW_OAM, OAMView->autoup_secs*1000, (TIMERPROC) NULL);
return 1;
case IDC_AUTO_UPDATE_SECS:
{
int t = GetDlgItemInt(hwnd, IDC_AUTO_UPDATE_SECS, FALSE, TRUE);
}
case WM_PAINT:
OamView_OnPaint(hwnd, OAMView, wParam, lParam);
return 1;
case WM_TIMER:
SendMessage(hwnd, WM_COMMAND, IDC_REFRESH, 0);
return 1;
case WM_HSCROLL :
switch LOWORD(wParam)
{
case SB_LINERIGHT :
++(OAMView->num);
if(OAMView->num>127)
OAMView->num = 127;
break;
case SB_LINELEFT :
--(OAMView->num);
if(OAMView->num<0)
OAMView->num = 0;
break;
}
InvalidateRect(hwnd, NULL, FALSE);
return 1;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDC_FERMER :
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 1;
case IDC_AUTO_UPDATE :
if(OAMView->autoup)
{
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SECS), false);
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN), false);
KillTimer(hwnd, IDT_VIEW_OAM);
OAMView->autoup = FALSE;
return 1;
}
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SECS), true);
EnableWindow(GetDlgItem(hwnd, IDC_AUTO_UPDATE_SPIN), true);
OAMView->autoup = TRUE;
SetTimer(hwnd, IDT_VIEW_OAM, OAMView->autoup_secs*1000, (TIMERPROC) NULL);
return 1;
case IDC_AUTO_UPDATE_SECS:
{
int t = GetDlgItemInt(hwnd, IDC_AUTO_UPDATE_SECS, FALSE, TRUE);
if (!OAMView)
{
SendMessage(hwnd, WM_INITDIALOG, 0, 0);
}
if (t != OAMView->autoup_secs)
{
OAMView->autoup_secs = t;
if (OAMView->autoup)
SetTimer(hwnd, IDT_VIEW_OAM,
OAMView->autoup_secs*1000, (TIMERPROC) NULL);
}
}
return 1;
case IDC_REFRESH:
InvalidateRect(hwnd, NULL, FALSE);
return 1;
case IDC_SCR_SELECT :
switch(HIWORD(wParam))
{
case CBN_CLOSEUP :
{
u32 sel = SendMessage(GetDlgItem(hwnd, IDC_SCR_SELECT), CB_GETCURSEL, 0, 0);
switch(sel)
{
case 0 :
OAMView->oam = (OAM *)ARM9Mem.ARM9_OAM;
OAMView->num = 0;
OAMView->gpu = MainScreen.gpu;
break;
case 1 :
OAMView->oam = (OAM *)(ARM9Mem.ARM9_OAM+0x400);
OAMView->num = 0;
OAMView->gpu = SubScreen.gpu;
break;
}
}
InvalidateRect(hwnd, NULL, FALSE);
return 1;
}
return 1;
}
return 0;
}
return FALSE;
}
}
if (t != OAMView->autoup_secs)
{
OAMView->autoup_secs = t;
if (OAMView->autoup)
SetTimer(hwnd, IDT_VIEW_OAM,
OAMView->autoup_secs*1000, (TIMERPROC) NULL);
}
}
return 1;
case IDC_REFRESH:
InvalidateRect(hwnd, NULL, FALSE);
return 1;
case IDC_SCR_SELECT :
switch(HIWORD(wParam))
{
case CBN_CLOSEUP :
{
u32 sel = SendMessage(GetDlgItem(hwnd, IDC_SCR_SELECT), CB_GETCURSEL, 0, 0);
switch(sel)
{
case 0 :
OAMView->oam = (OAM *)ARM9Mem.ARM9_OAM;
OAMView->num = 0;
OAMView->gpu = MainScreen.gpu;
break;
case 1 :
OAMView->oam = (OAM *)(ARM9Mem.ARM9_OAM+0x400);
OAMView->num = 0;
OAMView->gpu = SubScreen.gpu;
break;
}
}
InvalidateRect(hwnd, NULL, FALSE);
return 1;
}
return 1;
}
return 0;
}
return FALSE;
}