cleaning MASTER_BRIGHT

reverted 31 to 63 for brightness formula (gfx had become blank instead of
colourful for some games)
This commit is contained in:
damdoum 2007-01-11 12:24:35 +00:00
parent b5ddb1ce2c
commit db5a7884fc
2 changed files with 158 additions and 127 deletions

View File

@ -129,7 +129,7 @@ void GPU_resortBGs(GPU *gpu)
BOOL LayersEnable[5];
u16 WinBG=0;
int i,q ;
struct _DISPCNT * cnt = &gpu->dispCnt.bitfield;
struct _DISPCNT * cnt = &gpu->dispCnt.bits;
if (cnt->Win0_Enable || cnt->Win1_Enable)
{
@ -154,14 +154,15 @@ void GPU_resortBGs(GPU *gpu)
/* selection sort*/
for (i=0;i<4;i++)
{
/* weighted priorities: first drawn/not drawm, then set priority bits, then the num */
/* the higher the value the lower the priority */
u8 curPrio = gpu->bgCnt[gpu->ordre[i]].bitfield.Priority*4 + (LayersEnable[gpu->ordre[i]]?16:0) + gpu->ordre[i] ;
/* weighted priorities: first drawn/not drawm, then set priority bits,
then the num the higher the value the lower the priority */
u8 curPrio = gpu->bgCnt[gpu->ordre[i]].bits.Priority*4 + (LayersEnable[gpu->ordre[i]]?16:0) + gpu->ordre[i] ;
for (q=i+1;q<4;q++)
{
u8 lookingPrio = gpu->bgCnt[gpu->ordre[q]].bitfield.Priority*4 + (LayersEnable[gpu->ordre[q]]?16:0) + gpu->ordre[q] ;
/* if the one we are looking for is of higher priority then the current selected, swap them */
/* note: higher value = lower priority */
u8 lookingPrio = gpu->bgCnt[gpu->ordre[q]].bits.Priority*4 + (LayersEnable[gpu->ordre[q]]?16:0) + gpu->ordre[q] ;
/* if the one we are looking for is of higher priority then the
current selected, swap them
note: higher value = lower priority */
if (lookingPrio > curPrio)
{
/* swap the order */
@ -187,9 +188,9 @@ void GPU_setVideoProp(GPU * gpu, u32 p)
{
BOOL LayersEnable[5];
u16 WinBG=0;
struct _DISPCNT * cnt = &gpu->dispCnt.bitfield;
struct _DISPCNT * cnt = &gpu->dispCnt.bits;
gpu->dispCnt.integer = p;
gpu->dispCnt.val = p;
// gpu->dispMode = DISPCNT_DISPLAY_MODE(p,gpu->lcd) ;
gpu->dispMode = cnt->DisplayMode & ((gpu->lcd)?1:3);
@ -250,7 +251,7 @@ void GPU_setVideoProp(GPU * gpu, u32 p)
log::ajouter("------------------");
for(u8 i = 0; i < gpu->nbBGActif; ++i)
{
sprintf(logbuf, "bg %d prio %d", gpu->ordre[i], gpu->bgCnt[gpu->ordre[i]].bitfield.Priority);
sprintf(logbuf, "bg %d prio %d", gpu->ordre[i], gpu->bgCnt[gpu->ordre[i]].bits.Priority);
log::ajouter(logbuf);
}
log::ajouter("_________________");
@ -262,20 +263,20 @@ void GPU_setVideoProp(GPU * gpu, u32 p)
void GPU_setBGProp(GPU * gpu, u16 num, u16 p)
{
u8 index = gpu->BGIndex[num];
struct _BGxCNT * cnt = &(gpu->bgCnt[num].bitfield), *cnt2;
struct _BGxCNT * cnt = &(gpu->bgCnt[num].bits), *cnt2;
int lastPriority = cnt->Priority, mode;
gpu->bgCnt[num].integer = p;
gpu->bgCnt[num].val = p;
GPU_resortBGs(gpu) ;
GPU_resortBGs(gpu) ; /* is allready done in GPU_setBGProb */
if(gpu->core == GPU_SUB) {
gpu->BG_tile_ram[num] = ((u8 *)ARM9Mem.ARM9_BBG);
gpu->BG_bmp_ram[num] = ((u8 *)ARM9Mem.ARM9_BBG);
gpu->BG_map_ram[num] = ARM9Mem.ARM9_BBG;
} else {
gpu->BG_tile_ram[num] = ((u8 *)ARM9Mem.ARM9_ABG) + gpu->dispCnt.bitfield.CharacBase_Block * ADDRESS_STEP_64kB ;
gpu->BG_tile_ram[num] = ((u8 *)ARM9Mem.ARM9_ABG) + gpu->dispCnt.bits.CharacBase_Block * ADDRESS_STEP_64kB ;
gpu->BG_bmp_ram[num] = ((u8 *)ARM9Mem.ARM9_ABG);
gpu->BG_map_ram[num] = ARM9Mem.ARM9_ABG + gpu->dispCnt.bitfield.ScreenBase_Block * ADDRESS_STEP_64kB;
gpu->BG_map_ram[num] = ARM9Mem.ARM9_ABG + gpu->dispCnt.bits.ScreenBase_Block * ADDRESS_STEP_64kB;
}
gpu->BG_tile_ram[num] += (cnt->CharacBase_Block * ADDRESS_STEP_16KB);
gpu->BG_bmp_ram[num] += (cnt->ScreenBase_Block * ADDRESS_STEP_16KB);
@ -300,7 +301,7 @@ void GPU_setBGProp(GPU * gpu, u16 num, u16 p)
return;
}*/
mode = mode2type[gpu->dispCnt.bitfield.BG_Mode][num];
mode = mode2type[gpu->dispCnt.bits.BG_Mode][num];
gpu->BGSize[num][0] = sizeTab[mode][cnt->ScreenSize][0];
gpu->BGSize[num][1] = sizeTab[mode][cnt->ScreenSize][1];
}
@ -330,9 +331,9 @@ void GPU_addBack(GPU * gpu, u8 num)
{
u8 i = 0;
s8 j;
u8 p = gpu->bgCnt[num].bitfield.Priority;
u8 p = gpu->bgCnt[num].bits.Priority;
for(; i<gpu->nbBGActif; ++i)
if ((gpu->bgCnt[gpu->ordre[i]].bitfield.Priority >=p)&&(gpu->ordre[i]>num)) break;
if ((gpu->bgCnt[gpu->ordre[i]].bits.Priority >=p)&&(gpu->ordre[i]>num)) break;
for(j = gpu->nbBGActif-1; j >= i; --j)
{
@ -453,10 +454,10 @@ void GPU_setWINDOW_XDIM_Component(GPU *gpu, u8 v, u8 num) /* write start/end se
{
if (num & 1)
{
gpu->WINDOW_XDIM[num >> 1].bitfield.start = v ;
gpu->WINDOW_XDIM[num >> 1].bits.start = v ;
} else
{
gpu->WINDOW_XDIM[num >> 1].bitfield.end = v ;
gpu->WINDOW_XDIM[num >> 1].bits.end = v ;
}
}
@ -469,10 +470,10 @@ void GPU_setWINDOW_YDIM_Component(GPU *gpu, u8 v, u8 num) /* write start/end se
{
if (num & 1)
{
gpu->WINDOW_YDIM[num >> 1].bitfield.start = v ;
gpu->WINDOW_YDIM[num >> 1].bits.start = v ;
} else
{
gpu->WINDOW_YDIM[num >> 1].bitfield.end = v ;
gpu->WINDOW_YDIM[num >> 1].bits.end = v ;
}
}
@ -514,97 +515,97 @@ void GPU_setWINDOW_OUTCNT_Component(GPU *gpu, u8 v,u8 num)
void GPU_setMASTER_BRIGHT (GPU *gpu, u16 v)
{
gpu->MASTER_BRIGHT = v;
gpu->masterBright.val = v;
}
INLINE BOOL renderline_checkWindowInside(GPU *gpu, u8 bgnum, u16 x, u16 y, BOOL *draw, BOOL *effect)
{
/* priority to check the window regions: win0,win1,winobj */
if (gpu->dispCnt.bitfield.Win0_Enable) /* highest priority */
if (gpu->dispCnt.bits.Win0_Enable) /* highest priority */
{
if (((gpu->WINDOW_XDIM[0].val) && (gpu->WINDOW_YDIM[0].val)) &&
((((x >= gpu->WINDOW_XDIM[0].bitfield.start) && (x < gpu->WINDOW_XDIM[0].bitfield.end)) /* || (gpu->WINDOW_XDIM[1].bitfield.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[0].bitfield.start) && (y < gpu->WINDOW_YDIM[0].bitfield.end)))
((((x >= gpu->WINDOW_XDIM[0].bits.start) && (x < gpu->WINDOW_XDIM[0].bits.end)) /* || (gpu->WINDOW_XDIM[1].bits.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[0].bits.start) && (y < gpu->WINDOW_YDIM[0].bits.end)))
{
switch (bgnum) {
case 0:
if (!gpu->WINDOW_INCNT.bitfield.WIN0_BG0_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN0_BG0_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 1:
if (!gpu->WINDOW_INCNT.bitfield.WIN0_BG1_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN0_BG1_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 2:
if (!gpu->WINDOW_INCNT.bitfield.WIN0_BG2_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN0_BG2_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 3:
if (!gpu->WINDOW_INCNT.bitfield.WIN0_BG3_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN0_BG3_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 4:
if (!gpu->WINDOW_INCNT.bitfield.WIN0_OBJ_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN0_OBJ_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
}
*effect = gpu->WINDOW_INCNT.bitfield.WIN0_Effect_Enable ;
*effect = gpu->WINDOW_INCNT.bits.WIN0_Effect_Enable ;
return TRUE ;
}
}
if (gpu->dispCnt.bitfield.Win1_Enable) /* mid priority */
if (gpu->dispCnt.bits.Win1_Enable) /* mid priority */
{
if (((gpu->WINDOW_XDIM[1].val) && (gpu->WINDOW_YDIM[1].val)) &&
((((x >= gpu->WINDOW_XDIM[1].bitfield.start) && (x < gpu->WINDOW_XDIM[1].bitfield.end)) /* || (gpu->WINDOW_XDIM[1].bitfield.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[1].bitfield.start) && (y < gpu->WINDOW_YDIM[1].bitfield.end)))
((((x >= gpu->WINDOW_XDIM[1].bits.start) && (x < gpu->WINDOW_XDIM[1].bits.end)) /* || (gpu->WINDOW_XDIM[1].bits.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[1].bits.start) && (y < gpu->WINDOW_YDIM[1].bits.end)))
{
switch (bgnum) {
case 0:
if (!gpu->WINDOW_INCNT.bitfield.WIN0_BG0_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN0_BG0_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 1:
if (!gpu->WINDOW_INCNT.bitfield.WIN1_BG1_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN1_BG1_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 2:
if (!gpu->WINDOW_INCNT.bitfield.WIN1_BG2_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN1_BG2_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 3:
if (!gpu->WINDOW_INCNT.bitfield.WIN1_BG3_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN1_BG3_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 4:
if (!gpu->WINDOW_INCNT.bitfield.WIN1_OBJ_Enable)
if (!gpu->WINDOW_INCNT.bits.WIN1_OBJ_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
}
*effect = gpu->WINDOW_INCNT.bitfield.WIN1_Effect_Enable ;
*effect = gpu->WINDOW_INCNT.bits.WIN1_Effect_Enable ;
return TRUE ;
}
}
if ((gpu->dispCnt.bitfield.WinOBJ_Enable) && (bgnum==4)) /* low priority, but only applies to OBJ */
if ((gpu->dispCnt.bits.WinOBJ_Enable) && (bgnum==4)) /* low priority, but only applies to OBJ */
{
}
/* we have no rule, so allow everything for now */
@ -616,95 +617,95 @@ INLINE BOOL renderline_checkWindowInside(GPU *gpu, u8 bgnum, u16 x, u16 y, BOOL
INLINE BOOL renderline_checkWindowOutside(GPU *gpu, u8 bgnum, u16 x, u16 y, BOOL *draw, BOOL *effect)
{
/* priority to check the window regions: win0,win1,winobj */
if (gpu->dispCnt.bitfield.Win0_Enable) /* highest priority */
if (gpu->dispCnt.bits.Win0_Enable) /* highest priority */
{
if (((gpu->WINDOW_XDIM[0].val) && (gpu->WINDOW_YDIM[0].val)) &&
((((x >= gpu->WINDOW_XDIM[0].bitfield.start) && (x < gpu->WINDOW_XDIM[0].bitfield.end)) /* || (gpu->WINDOW_XDIM[1].bitfield.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[0].bitfield.start) && (y < gpu->WINDOW_YDIM[0].bitfield.end)))
((((x >= gpu->WINDOW_XDIM[0].bits.start) && (x < gpu->WINDOW_XDIM[0].bits.end)) /* || (gpu->WINDOW_XDIM[1].bits.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[0].bits.start) && (y < gpu->WINDOW_YDIM[0].bits.end)))
{
} else
{
switch (bgnum) {
case 0:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN0_BG0_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN0_BG0_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 1:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN0_BG1_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN0_BG1_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 2:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN0_BG2_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN0_BG2_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 3:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN0_BG3_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN0_BG3_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 4:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN0_OBJ_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN0_OBJ_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
}
*effect = gpu->WINDOW_OUTCNT.bitfield.WIN0_Effect_Enable ;
*effect = gpu->WINDOW_OUTCNT.bits.WIN0_Effect_Enable ;
return TRUE ;
}
}
if (gpu->dispCnt.bitfield.Win1_Enable) /* mid priority */
if (gpu->dispCnt.bits.Win1_Enable) /* mid priority */
{
if (((gpu->WINDOW_XDIM[1].val) && (gpu->WINDOW_YDIM[1].val)) &&
((((x >= gpu->WINDOW_XDIM[1].bitfield.start) && (x < gpu->WINDOW_XDIM[1].bitfield.end)) /* || (gpu->WINDOW_XDIM[1].bitfield.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[1].bitfield.start) && (y < gpu->WINDOW_YDIM[1].bitfield.end)))
((((x >= gpu->WINDOW_XDIM[1].bits.start) && (x < gpu->WINDOW_XDIM[1].bits.end)) /* || (gpu->WINDOW_XDIM[1].bits.end==0)*/)
&&(y >= gpu->WINDOW_YDIM[1].bits.start) && (y < gpu->WINDOW_YDIM[1].bits.end)))
{
} else
{
switch (bgnum) {
case 0:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN0_BG0_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN0_BG0_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 1:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN1_BG1_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN1_BG1_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 2:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN1_BG2_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN1_BG2_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 3:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN1_BG3_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN1_BG3_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
case 4:
if (!gpu->WINDOW_OUTCNT.bitfield.WIN1_OBJ_Enable)
if (!gpu->WINDOW_OUTCNT.bits.WIN1_OBJ_Enable)
*draw = FALSE ; /* drawing explicit disabled for thios bg in this rectangle */
else
*draw = TRUE ;
break ;
}
*effect = gpu->WINDOW_OUTCNT.bitfield.WIN1_Effect_Enable ;
*effect = gpu->WINDOW_OUTCNT.bits.WIN1_Effect_Enable ;
return TRUE ;
}
}
if ((gpu->dispCnt.bitfield.WinOBJ_Enable) && (bgnum==4)) /* low priority, but only applies to OBJ */
if ((gpu->dispCnt.bits.WinOBJ_Enable) && (bgnum==4)) /* low priority, but only applies to OBJ */
{
}
/* we have no rule, so allow everything for now */
@ -803,7 +804,7 @@ INLINE void renderline_setFinalColor(GPU *gpu,u32 passing,u8 bgnum,u8 *dst,u16 c
/* render a text background to the combined pixelbuffer */
INLINE void renderline_textBG(GPU * gpu, u8 num, u8 * DST, u16 X, u16 Y, u16 LG)
{
struct _BGxCNT bgCnt = gpu->bgCnt[num].bitfield;
struct _BGxCNT bgCnt = gpu->bgCnt[num].bits;
u16 lg = gpu->BGSize[num][0];
u16 ht = gpu->BGSize[num][1];
u16 tmp = ((Y&(ht-1))>>3);
@ -954,7 +955,7 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u8 * DST, u16 X, u16 Y, u16 LG)
}
return;
}
if(!gpu->dispCnt.bitfield.ExBGxPalette_Enable) /* color: no extended palette */
if(!gpu->dispCnt.bits.ExBGxPalette_Enable) /* color: no extended palette */
{
yoff = ((Y&7)<<3);
pal = ARM9Mem.ARM9_VMEM + gpu->core * ADDRESS_STEP_1KB ;
@ -1047,7 +1048,7 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u8 * DST, u16 X, u16 Y, u16 LG)
INLINE void rotBG2(GPU * gpu, u8 num, u8 * DST, u16 H, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 PD, u16 LG)
{
struct _BGxCNT bgCnt = gpu->bgCnt[num].bitfield;
struct _BGxCNT bgCnt = gpu->bgCnt[num].bits;
s32 x = X + (s32)PB*(s32)H;
s32 y = Y + (s32)PD*(s32)H;
@ -1100,7 +1101,7 @@ INLINE void rotBG2(GPU * gpu, u8 num, u8 * DST, u16 H, s32 X, s32 Y, s16 PA, s16
INLINE void extRotBG2(GPU * gpu, u8 num, u8 * DST, u16 H, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 PD, s16 LG)
{
struct _BGxCNT bgCnt = gpu->bgCnt[num].bitfield;
struct _BGxCNT bgCnt = gpu->bgCnt[num].bits;
s32 x = X + (s32)PB*(s32)H;
s32 y = Y + (s32)PD*(s32)H;
@ -1354,7 +1355,7 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab)
u16 i;
src = gpu->sprMem + (spriteInfo->TileIndex<<block) + ((y>>3)*sprSize.x*8) + ((y&0x7)*8);
if (gpu->dispCnt.bitfield.ExOBJPalette_Enable)
if (gpu->dispCnt.bits.ExOBJPalette_Enable)
pal = ARM9Mem.ObjExtPal[gpu->core][0]+(spriteInfo->PaletteIndex*0x200);
else
pal = ARM9Mem.ARM9_VMEM + 0x200 + gpu->core *0x400;

View File

@ -39,6 +39,10 @@ extern "C" {
#define min(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef max
#define max(a,b) (((a)>(b))?(a):(b))
#endif
#define GPU_MAIN 0
#define GPU_SUB 1
@ -96,10 +100,10 @@ struct _DISPCNT
typedef union
{
struct _DISPCNT bitfield;
u32 integer;
struct _DISPCNT bits;
u32 val;
} DISPCNT;
#define BGxENABLED(cnt,num) ((num<8)? ((cnt.integer>>8) & num):0)
#define BGxENABLED(cnt,num) ((num<8)? ((cnt.val>>8) & num):0)
@ -119,7 +123,7 @@ struct _COLOR { // abgr x555
typedef union
{
struct _COLOR bitfield;
struct _COLOR bits;
u16 val;
} COLOR;
@ -136,16 +140,16 @@ struct _COLOR32 { // ARGB
typedef union
{
struct _COLOR32 bitfield;
struct _COLOR32 bits;
u32 val;
} COLOR32;
#define COLOR_16_32(w,i) \
/* doesnt matter who's 16bit who's 32bit */ \
i.bitfield.red = w.bitfield.red; \
i.bitfield.green = w.bitfield.green; \
i.bitfield.blue = w.bitfield.blue; \
i.bitfield.alpha = w.bitfield.alpha;
i.bits.red = w.bits.red; \
i.bits.green = w.bits.green; \
i.bits.blue = w.bits.blue; \
i.bits.alpha = w.bits.alpha;
@ -177,16 +181,34 @@ struct _BGxCNT
typedef union
{
struct _BGxCNT bitfield;
u16 integer;
struct _BGxCNT bits;
u16 val;
} BGxCNT;
#define BGCNT_PRIORITY(val) ((val) & 3)
#define BGCNT_CHARBASEBLOCK(val) (((val) >> 2) & 0x0F)
#define BGCNT_256COL(val) (((val) >> 7) & 0x1)
#define BGCNT_SCREENBASEBLOCK(val) (((val) >> 8) & 0x1F)
#define BGCNT_EXTPALSLOT(val) (((val) >> 13) & 0x1)
#define BGCNT_SCREENSIZE(val) (((val) >> 14) & 0x3)
/*
this structure is to represent global FX
applied to a pixel
Factor (5bits values 0-16, values >16 same as 16)
// damdoum : then the 4th bit use is questionnable ?
Lighten : New = Old + (63-Old) * Factor/16
Darken : New = Old - Old * Factor/16
*/
struct _MASTER_BRIGHT
{
/*0*/ unsigned Factor:4; // brightnessFactor = Factor | FactorEx << 4
/*4*/ unsigned FactorEx:1; //
/*5*/ unsigned :9;
/*14*/ unsigned Mode:2; // 0=off, 1=Lighten, 2=Darken, 3=?
};
typedef union
{
struct _MASTER_BRIGHT bits;
u16 val;
} MASTER_BRIGHT;
@ -255,7 +277,7 @@ typedef union windowdim_t
{
/* 0*/ unsigned end:8;
/* 8*/ unsigned start:8;
} bitfield ;
} bits ;
unsigned short val ;
} windowdim_t ;
@ -277,7 +299,7 @@ typedef union windowcnt_t
/*12*/ unsigned WIN1_OBJ_Enable:1;
/*13*/ unsigned WIN1_Effect_Enable:1;
/*14*/ unsigned :2;
} bitfield ;
} bits ;
struct
{
unsigned char low ;
@ -299,6 +321,7 @@ struct _GPU
{
DISPCNT dispCnt;
BGxCNT bgCnt[4];
MASTER_BRIGHT masterBright;
#define BGBmpBB BG_bmp_ram
#define BGChBB BG_tile_ram
@ -341,7 +364,6 @@ struct _GPU
u16 BLDALPHA ;
u16 BLDY ;
u16 MOSAIC ;
u16 MASTER_BRIGHT;
windowdim_t WINDOW_XDIM[2] ;
windowdim_t WINDOW_YDIM[2] ;
@ -450,7 +472,7 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
{
gpu->spriteRender(gpu, l, spr, sprPrio);
if(gpu->bgCnt[gpu->ordre[0]].bitfield.Priority !=3)
if(gpu->bgCnt[gpu->ordre[0]].bits.Priority !=3)
{
for(i16 = 0; i16 < 128; ++i16) {
T2WriteLong(dst, i16 << 2, T2ReadLong(spr, i16 << 2));
@ -460,8 +482,8 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
for(i8 = 0; i8 < gpu->nbBGActif; ++i8)
{
modeRender[gpu->dispCnt.bitfield.BG_Mode][gpu->ordre[i8]](gpu, gpu->ordre[i8], l, dst);
bgprio = gpu->bgCnt[gpu->ordre[i8]].bitfield.Priority;
modeRender[gpu->dispCnt.bits.BG_Mode][gpu->ordre[i8]](gpu, gpu->ordre[i8], l, dst);
bgprio = gpu->bgCnt[gpu->ordre[i8]].bits.Priority;
if (gpu->sprEnable)
{
for(i16 = 0; i16 < 256; ++i16)
@ -472,10 +494,10 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
// Apply final brightness adjust (MASTER_BRIGHT)
// Reference: http://nocash.emubase.de/gbatek.htm#dsvideo (Under MASTER_BRIGHTNESS)
/* Mightymax> it should be more effective if the windowmanager applies brightness when drawing */
/* it will most likly take acceleration, while we are stuck here with CPU power */
switch ((gpu->MASTER_BRIGHT>>14)&3)
switch (gpu->masterBright.bits.Mode)
{
// Disabled
case 0:
@ -484,14 +506,18 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
// Bright up
case 1:
{
unsigned int masterBrightFactor = gpu->MASTER_BRIGHT&31;
masterBrightFactor = masterBrightFactor > 16 ? 16 : masterBrightFactor;
unsigned int masterBrightFactor = 16;
// if (gpu->masterBright.bit.FactorEx)
gpu->masterBright.bits.Factor;
if (!masterBrightFactor) break ; /* when we wont do anything, we dont need to loop */
if (masterBrightFactor == 16)
{
/* the formular would create only white, as (r + (31-r)) = 31 */
/* white = enable all bits */
/* damdoum : well, i think the formula was with 63!
so (r + (63-r)) = 63 & 31 = 31 = still white*/
memset(dst,0xFF, 256*2 /* sizeof(COLOR) */) ;
} else
{
@ -501,13 +527,13 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
COLOR dstColor;
unsigned int r,g,b; // get components, 5bit each
dstColor.val = T1ReadWord(dst, i16 << 1);
r = dstColor.bitfield.red;
g = dstColor.bitfield.green;
b = dstColor.bitfield.blue;
// Bright up and clamp to 5bit
dstColor.bitfield.red = min(31,(r + ((31-r)*masterBrightFactor)/16));
dstColor.bitfield.green = min(31,(g + ((31-g)*masterBrightFactor)/16));
dstColor.bitfield.blue = min(31,(b + ((31-b)*masterBrightFactor)/16));
r = dstColor.bits.red;
g = dstColor.bits.green;
b = dstColor.bits.blue;
// Bright up and clamp to 5bit <-- automatic
dstColor.bits.red = r + ((63-r)*masterBrightFactor)/16;
dstColor.bits.green = g + ((63-g)*masterBrightFactor)/16;
dstColor.bits.blue = b + ((63-b)*masterBrightFactor)/16;
T2WriteWord (dst, i16 << 1, dstColor.val);
}
}
@ -523,9 +549,13 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
we use 31 as top, instead of 63. Testing it on a few games,
using 63 seems to give severe color wraping, and 31 works
nicely, so for now we'll just that, until proven wrong.
i have seen pics of pokemon ranger getting white with 31, with 63 it is nice.
it could be pb of alpha or blending or...
*/
unsigned int masterBrightFactor = gpu->MASTER_BRIGHT&31;
masterBrightFactor = masterBrightFactor > 16 ? 16 : masterBrightFactor;
unsigned int masterBrightFactor = 16;
// if (gpu->masterBright.bit.FactorEx)
gpu->masterBright.bits.Factor;
if (!masterBrightFactor) break ; /* when we wont do anything, we dont need to loop */
if (masterBrightFactor == 16)
@ -541,13 +571,13 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
COLOR dstColor;
unsigned int r,g,b; // get components, 5bit each
dstColor.val = T1ReadWord(dst, i16 << 1);
r = dstColor.bitfield.red;
g = dstColor.bitfield.green;
b = dstColor.bitfield.blue;
// Bright up and clamp to 5bit
dstColor.bitfield.red = min(31,(r - (r*masterBrightFactor)/16));
dstColor.bitfield.green = min(31,(g - (g*masterBrightFactor)/16));
dstColor.bitfield.blue = min(31,(b - (b*masterBrightFactor)/16));
r = dstColor.bits.red;
g = dstColor.bits.green;
b = dstColor.bits.blue;
// Bright up and clamp to 5bit <- automatic
dstColor.bits.red = r - (r*masterBrightFactor)/16;
dstColor.bits.green = g - (g*masterBrightFactor)/16;
dstColor.bits.blue = b - (b*masterBrightFactor)/16;
T2WriteWord (dst, i16 << 1, dstColor.val);
}
}