Skip to content

Commit

Permalink
Add VIDEO_GetVideoScanMode & fix the __ViInit loop (#144)
Browse files Browse the repository at this point in the history
* fixes: make compiler not remove the while loop by adding empty asm line

* video : add VIDEO_GetVideoScanMode
  • Loading branch information
DacoTaco authored Mar 13, 2023
1 parent a7e4bcd commit 46b47a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions gc/ogc/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ u32 VIDEO_HaveComponentCable(void);

GXRModeObj * VIDEO_GetPreferredMode(GXRModeObj *mode);

/*!
* \fn u32 VIDEO_GetVideoScanMode(void)
* \brief Get video scan mode. This function returns 0 when interlaced, 1 when non interlaced and 2 when progressive
*
* \return 0 when interlaced, 1 when non interlaced and 2 when progressive
*/
u32 VIDEO_GetVideoScanMode(void);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
24 changes: 23 additions & 1 deletion libogc/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,12 @@ static void __VIInit(u32 vimode)
//reset the interface
cnt = 0;
_viReg[1] = 0x02;
while(cnt<1000) cnt++;
while(cnt<1000)
{
__asm__ __volatile__ ("" ::: "memory");
cnt++;
}

_viReg[1] = 0x00;

// now begin to setup the interface
Expand Down Expand Up @@ -2958,3 +2963,20 @@ u32 VIDEO_HaveComponentCable(void)
{
return (_viReg[55]&0x01);
}

u32 VIDEO_GetVideoScanMode(void)
{
u32 level;
u32 mode;

_CPU_ISR_Disable(level);

// Check Clock Select Register for progressive clock
if (_viReg[54] & 1)
mode = VI_PROGRESSIVE;
else
mode = (_viReg[1] >> 2 & 1) ? VI_NON_INTERLACE : VI_INTERLACE;

_CPU_ISR_Restore(level);
return mode;
}

0 comments on commit 46b47a0

Please sign in to comment.