- Added support for MASTER_BRIGHT

- Changed a few things to get VisualC to compile GPU.c
This commit is contained in:
shashclp 2007-01-09 22:38:23 +00:00
parent 629f89e81b
commit 8157759485
3 changed files with 87 additions and 8 deletions

View File

@ -126,11 +126,12 @@ void GPU_DeInit(GPU * gpu)
/* Sets up LCD control variables for Display Engines A and B for quick reading */ /* Sets up LCD control variables for Display Engines A and B for quick reading */
void GPU_setVideoProp(GPU * gpu, u32 p) void GPU_setVideoProp(GPU * gpu, u32 p)
{ {
gpu->dispCnt.integer = p;
struct _DISPCNT * cnt = &gpu->dispCnt.bitfield; struct _DISPCNT * cnt = &gpu->dispCnt.bitfield;
// gpu->dispMode = DISPCNT_DISPLAY_MODE(p,gpu->lcd) ; gpu->dispCnt.integer = p;
gpu->dispMode = cnt->DisplayMode & ((gpu->lcd)?1:3);
// gpu->dispMode = DISPCNT_DISPLAY_MODE(p,gpu->lcd) ;
gpu->dispMode = cnt->DisplayMode & ((gpu->lcd)?1:3);
switch (gpu->dispMode) switch (gpu->dispMode)
{ {
@ -307,7 +308,7 @@ void GPU_setBGProp(GPU * gpu, u16 num, u16 p)
{ {
u8 index = gpu->BGIndex[num]; u8 index = gpu->BGIndex[num];
struct _BGxCNT * cnt = &(gpu->bgCnt[num].bitfield), *cnt2; struct _BGxCNT * cnt = &(gpu->bgCnt[num].bitfield), *cnt2;
int lastPriority = cnt->Priority; int lastPriority = cnt->Priority, mode;
gpu->bgCnt[num].integer = p; gpu->bgCnt[num].integer = p;
if((gpu->nbBGActif != 0) && (index != 0)) if((gpu->nbBGActif != 0) && (index != 0))
@ -384,10 +385,9 @@ void GPU_setBGProp(GPU * gpu, u16 num, u16 p)
return; return;
}*/ }*/
int mode = mode2type[gpu->dispCnt.bitfield.BG_Mode][num]; mode = mode2type[gpu->dispCnt.bitfield.BG_Mode][num];
gpu->BGSize[num][0] = sizeTab[mode][cnt->ScreenSize][0]; gpu->BGSize[num][0] = sizeTab[mode][cnt->ScreenSize][0];
gpu->BGSize[num][1] = sizeTab[mode][cnt->ScreenSize][1]; gpu->BGSize[num][1] = sizeTab[mode][cnt->ScreenSize][1];
} }
void GPU_remove(GPU * gpu, u8 num) void GPU_remove(GPU * gpu, u8 num)
@ -547,6 +547,11 @@ void GPU_setWINDOW_OUTCNT(GPU *gpu, u16 v)
gpu->WINDOW_OUTCNT.val = v ; gpu->WINDOW_OUTCNT.val = v ;
} }
void GPU_setMASTER_BRIGHT (GPU *gpu, u16 v)
{
gpu->MASTER_BRIGHT = v;
}
#ifndef min #ifndef min
#define min(a,b) (((a)<(b))?(a):(b)) #define min(a,b) (((a)<(b))?(a):(b))
#endif #endif

View File

@ -230,6 +230,7 @@ struct _GPU
u16 BLDALPHA ; u16 BLDALPHA ;
u16 BLDY ; u16 BLDY ;
u16 MOSAIC ; u16 MOSAIC ;
u16 MASTER_BRIGHT;
u16 WINDOW_XDIM[2] ; u16 WINDOW_XDIM[2] ;
u16 WINDOW_YDIM[2] ; u16 WINDOW_YDIM[2] ;
@ -359,6 +360,71 @@ static INLINE void GPU_ligne(Screen * screen, u16 l)
T2WriteWord(dst, i16 << 1, T2ReadWord(spr, i16 << 1)); T2WriteWord(dst, i16 << 1, T2ReadWord(spr, i16 << 1));
} }
} }
// Apply final brightness adjust (MASTER_BRIGHT)
// Reference: http://nocash.emubase.de/gbatek.htm#dsvideo (Under MASTER_BRIGHTNESS)
switch ((gpu->MASTER_BRIGHT>>14)&3)
{
// Disabled
case 0:
break;
// Bright up
case 1:
{
unsigned int masterBrightFactor = gpu->MASTER_BRIGHT&31;
masterBrightFactor = masterBrightFactor > 16 ? 16 : masterBrightFactor;
for(i16 = 0; i16 < 256; ++i16)
{
unsigned int dstColor = T1ReadWord(dst, i16 << 1);
unsigned int r = (dstColor>>10)&31, // Get the components, 5bit each
g = (dstColor>> 5)&31,
b = (dstColor )&31;
r = (r + (r*masterBrightFactor)/16)&31; // Bright up and clamp to 5bit
g = (g + (g*masterBrightFactor)/16)&31;
b = (b + (b*masterBrightFactor)/16)&31;
T2WriteWord (dst, i16 << 1, (r<<10) | (g<<5) | b);
}
break;
}
// Bright down
case 2:
{
unsigned int masterBrightFactor = gpu->MASTER_BRIGHT&31;
masterBrightFactor = masterBrightFactor > 16 ? 16 : masterBrightFactor;
for(i16 = 0; i16 < 256; ++i16)
{
unsigned int dstColor = T1ReadWord(dst, i16 << 1);
unsigned int r = (dstColor>>10)&31, // Get the components, 5bit each
g = (dstColor>> 5)&31,
b = (dstColor )&31;
/*
NOTE: gbatek (in the reference above) seems to expect 6bit values
per component, but as desmume works with 5bit per component,
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.
*/
r = (r + ((31-r)*masterBrightFactor)/16)&31; // Bright down and clamp to 5bit
g = (g + ((31-g)*masterBrightFactor)/16)&31;
b = (b + ((31-b)*masterBrightFactor)/16)&31;
T2WriteWord (dst, i16 << 1, (r<<10) | (g<<5) | b);
}
break;
}
// Reserved
case 3:
break;
}
} }
void GPU_setVideoProp(GPU *, u32 p); void GPU_setVideoProp(GPU *, u32 p);
@ -390,6 +456,8 @@ void GPU_setWINDOW_YDIM(GPU *gpu, u16 v, u8 num) ;
void GPU_setWINDOW_INCNT(GPU *gpu, u16 v) ; void GPU_setWINDOW_INCNT(GPU *gpu, u16 v) ;
void GPU_setWINDOW_INCNT(GPU *gpu, u16 v) ; void GPU_setWINDOW_INCNT(GPU *gpu, u16 v) ;
void GPU_setMASTER_BRIGHT (GPU *gpu, u16 v);
void GPU_remove(GPU *, u8 num); void GPU_remove(GPU *, u8 num);
void GPU_addBack(GPU *, u8 num); void GPU_addBack(GPU *, u8 num);

View File

@ -1190,6 +1190,12 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val)
case REG_DISPB_MOSAIC: case REG_DISPB_MOSAIC:
GPU_setMOSAIC(SubScreen.gpu,val) ; GPU_setMOSAIC(SubScreen.gpu,val) ;
break ; break ;
case REG_DISPA_MASTERBRIGHT:
GPU_setMASTER_BRIGHT (MainScreen.gpu, val);
break;
case REG_DISPB_MASTERBRIGHT:
GPU_setMASTER_BRIGHT (SubScreen.gpu, val);
break;
case REG_IME : case REG_IME :
MMU.reg_IME[proc] = val&1; MMU.reg_IME[proc] = val&1;
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x208, val); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x208, val);