Skip to content

Commit

Permalink
Fix enhanced definition video quality on Wii.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Apr 10, 2019
1 parent 15795a3 commit 941d687
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions libogc/video.c
Expand Up @@ -2774,7 +2774,8 @@ static const struct _timing {
static u32 vdacFlagRegion;
static u32 i2cIdentFirst = 0;
static u32 i2cIdentFlag = 1;
static u32 oldTvStatus = 0x03e7;
static u32 oldViMode = 0x03e7;
static u32 oldTvMode = 0x03e7;
static u32 oldDtvStatus = 0x03e7;
static vu32* const _i2cReg = (u32*)0xCD800000;
#endif
Expand Down Expand Up @@ -3544,6 +3545,11 @@ static void __VIWriteI2CRegisterBuf(u8 reg, int size, u8 *data)
udelay(2);
}

static void __VISetOverSampling(u8 enable)
{
__VIWriteI2CRegister8(0x65, enable);
}

static void __VISetVolume(u8 left, u8 right)
{
__VIWriteI2CRegister16(0x71, (left<<8)|right);
Expand Down Expand Up @@ -3581,18 +3587,21 @@ static void __VISetupEncoder(void)
0x00
};

u8 dtv, tv;
u8 dtv, tvmode, vimode;

tv = VIDEO_GetCurrentTvMode();
vimode = VIDEO_GetCurrentViMode();
tvmode = VIDEO_GetCurrentTvMode();
dtv = VIDEO_HaveComponentCable();
oldDtvStatus = dtv;

// SetRevolutionModeSimple

memset(macrobuf, 0, 0x1a);

__VIWriteI2CRegister8(0x6a, 1);
__VIWriteI2CRegister8(0x65, 1);

if(vimode&VI_CLOCK_54MHZ) __VISetOverSampling(3);
else __VISetOverSampling(1);

__VISetYUVSEL(dtv);
__VIWriteI2CRegister8(0x00, 0);
__VISetVolume(0x8e, 0x8e);
Expand All @@ -3613,10 +3622,8 @@ static void __VISetupEncoder(void)

__VIWriteI2CRegister8(0x04, 1);

if(tv==VI_EURGB60) __VISetFilterEURGB60(1);
if(tvmode==VI_EURGB60) __VISetFilterEURGB60(1);
else __VISetFilterEURGB60(0);
oldTvStatus = tv;

}
#endif

Expand Down Expand Up @@ -3730,7 +3737,7 @@ static inline void __VIGetCurrentPosition(s32 *px,s32 *py)
static void __VIRetraceHandler(u32 nIrq,frame_context *pCtx)
{
#if defined(HW_RVL)
u8 dtv, tv;
u8 dtv, tvmode, vimode;
#endif
u32 ret = 0;
u32 intr;
Expand Down Expand Up @@ -3779,16 +3786,24 @@ static void __VIRetraceHandler(u32 nIrq,frame_context *pCtx)
}
}
#if defined(HW_RVL)
tv = VIDEO_GetCurrentTvMode();
vimode = VIDEO_GetCurrentViMode();
tvmode = VIDEO_GetCurrentTvMode();
dtv = VIDEO_HaveComponentCable();
if(dtv!=oldDtvStatus || tv!=oldTvStatus) __VISetYUVSEL(dtv);

if(vimode!=oldViMode) {
if(vimode&VI_CLOCK_54MHZ) __VISetOverSampling(3);
else __VISetOverSampling(1);
}
oldViMode = vimode;

if(dtv!=oldDtvStatus || tvmode!=oldTvMode) __VISetYUVSEL(dtv);
oldDtvStatus = dtv;

if(tv!=oldTvStatus) {
if(tv==VI_EURGB60) __VISetFilterEURGB60(1);
if(tvmode!=oldTvMode) {
if(tvmode==VI_EURGB60) __VISetFilterEURGB60(1);
else __VISetFilterEURGB60(0);
}
oldTvStatus = tv;
oldTvMode = tvmode;
#endif
if(postRetraceCB)
postRetraceCB(retraceCount);
Expand Down

5 comments on commit 941d687

@homebrewGT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What an amazing discovery! D:
Cheers! I hope we get an update for Nintendon't (?)

@saradk
Copy link

@saradk saradk commented on 941d687 Apr 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOW! Brilliant work!

@gingerbeardman
Copy link

@gingerbeardman gingerbeardman commented on 941d687 Jun 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some photos of my 640x480p LCD displaying Mario Kart Wii both with and without the 480p fix. This is great because the 1:1 pixel output allows you to see the differences at a sub-pixel resolution.

Places to look for differences

  1. e of Channel
  2. inside the a of Back
  3. glasses frame on my Mii
  4. Ms of Main Menu

Conclusion

  • fixed: graphics are pixel aligned horizontally
  • original: graphics are not pixel aligned horizontally

cropped photo album
https://imgur.com/a/Ef02mmz

full size photo album
https://imgur.com/a/R0k3igo

fixed: single pixel wide glasses frame
IMG_6337

original: double pixel wide glasses frame
IMG_6341

fixed: m starts on pixel boundary
IMG_6338

original: m starts half way through a pixel
IMG_6342

Extrems original (before/after) checkerboard image (click to view 1:1):
https://user-images.githubusercontent.com/49612/58824671-8a67f180-8634-11e9-976f-3dc0372e653f.png

@philou-felin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gingerbeardman, what was your monitor? I can't reproduce that on my 640x480 LCD TV.

@NintendoManiac64
Copy link

@NintendoManiac64 NintendoManiac64 commented on 941d687 Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, the hex-edit needed to manually apply Extrems' 480p fix to any Wii homebrew boot.dol seems to be:
38 80 00 01 38 60 00 65 4B FF
becomes:
38 80 00 03 38 60 00 65 4B FF

The only change being that the 01 becomes 03...unless, by some freak chance, GCMM v1.4f, Savegame Manager GX R127 (non-vWii), and Not64 build 2015-02-05 all just happen to use this exact same line of hex?

Please sign in to comment.