Skip to content

Commit bc4b778

Browse files
DacoTacoExtremsWinterMute
authored
introduce sram flags (#90)
Co-authored-by: Extrems <metaradil@gmail.com> Co-authored-by: Dave Murphy <davem@devkitpro.org>
1 parent b2a0b7a commit bc4b778

2 files changed

Lines changed: 245 additions & 24 deletions

File tree

gc/ogc/system.h

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@ distribution.
9494
#define SYS_PROTECTWRITE 0x00000002 /*!< Write to protected region is permitted */
9595
#define SYS_PROTECTRDWR (SYS_PROTECTREAD|SYS_PROTECTWRITE) /*!< Read and write operations on protected region is permitted */
9696

97+
/*!
98+
* \sram language flags
99+
*/
100+
101+
#define SYS_LANG_ENGLISH 0
102+
#define SYS_LANG_GERMAN 1
103+
#define SYS_LANG_FRENCH 2
104+
#define SYS_LANG_SPANISH 3
105+
#define SYS_LANG_ITALIAN 4
106+
#define SYS_LANG_DUTCH 5
107+
108+
/*!
109+
* \sram video flags
110+
*/
111+
112+
#define SYS_VIDEO_NTSC 0
113+
#define SYS_VIDEO_PAL 1
114+
#define SYS_VIDEO_MPAL 2
115+
116+
/*!
117+
* \sram audio flags
118+
*/
119+
120+
#define SYS_SOUND_MONO 0
121+
#define SYS_SOUND_STEREO 1
122+
97123
/*!
98124
*@}
99125
*/
@@ -102,7 +128,6 @@ distribution.
102128
#define SYS_FONTSIZE_SJIS (3840 + 1179648)
103129

104130

105-
106131
/*!
107132
* \addtogroup sys_mcastmacros OS memory casting macros
108133
* @{
@@ -147,7 +172,7 @@ typedef u32 syswd_t;
147172
* \param ead1 unknown attribute
148173
* \param counter_bias bias value for the realtime clock
149174
* \param display_offsetH pixel offset for the VI
150-
* \param ntd unknown attribute
175+
* \param ntd mostly unknown attribute
151176
* \param lang language of system
152177
* \param flags device and operations flag
153178
*/
@@ -305,11 +330,24 @@ s32 SYS_RemoveAlarm(syswd_t thealarm);
305330
*/
306331
s32 SYS_CancelAlarm(syswd_t thealarm);
307332

308-
309-
void SYS_SetWirelessID(u32 chan,u32 id);
310-
u32 SYS_GetWirelessID(u32 chan);
311-
void SYS_SetGBSMode(u16 mode);
333+
u32 SYS_GetCounterBias(void);
334+
void SYS_SetCounterBias(u32 bias);
335+
s8 SYS_GetDisplayOffsetH(void);
336+
void SYS_SetDisplayOffsetH(s8 offset);
337+
u8 SYS_GetEuRGB60(void);
338+
void SYS_SetEuRGB60(u8 enable);
339+
u8 SYS_GetLanguage(void);
340+
void SYS_SetLanguage(u8 lang);
341+
u8 SYS_GetProgressiveScan(void);
342+
void SYS_SetProgressiveScan(u8 enable);
343+
u8 SYS_GetSoundMode(void);
344+
void SYS_SetSoundMode(u8 mode);
345+
u8 SYS_GetVideoMode(void);
346+
void SYS_SetVideoMode(u8 mode);
347+
u16 SYS_GetWirelessID(u32 chan);
348+
void SYS_SetWirelessID(u32 chan,u16 id);
312349
u16 SYS_GetGBSMode(void);
350+
void SYS_SetGBSMode(u16 mode);
313351
u32 SYS_GetFontEncoding(void);
314352
u32 SYS_InitFont(sys_fontheader *font_data);
315353
void SYS_GetFontTexture(s32 c,void **image,s32 *xpos,s32 *ypos,s32 *width);

libogc/system.c

Lines changed: 201 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,18 @@ distribution.
6464
#endif
6565
#define KERNEL_HEAP (1*1024*1024)
6666

67+
// SRAM bits
68+
#define SRAM_VIDEO_MODE_BITS 0x03
69+
#define SRAM_SOUND_MODE_BIT 0x04
70+
#define SRAM_OOBE_DONE_BIT 0x08
71+
#define SRAM_UNKNOWN1_BIT 0x10
72+
#define SRAM_UNKNOWN2_BIT 0x20
73+
#define SRAM_BOOTIPL_BIT 0x40
74+
#define SRAM_PROGSCAN_BIT 0x80
75+
6776
// DSPCR bits
6877
#define DSPCR_DSPRESET 0x0800 // Reset DSP
69-
#define DSPCR_DSPDMA 0x0200 // ARAM dma in progress, if set
78+
#define DSPCR_DSPDMA 0x0200 // ARAM dma in progress, if set
7079
#define DSPCR_DSPINTMSK 0x0100 // * interrupt mask (RW)
7180
#define DSPCR_DSPINT 0x0080 // * interrupt active (RWC)
7281
#define DSPCR_ARINTMSK 0x0040
@@ -731,7 +740,7 @@ static u32 __unlocksram(u32 write,u32 loc)
731740

732741
if(write) {
733742
if(!loc) {
734-
if((sram->flags&0x03)>0x02) sram->flags = (sram->flags&~0x03);
743+
if((sram->flags&SRAM_VIDEO_MODE_BITS) > 0x02) sram->flags &= ~SRAM_VIDEO_MODE_BITS;
735744
__buildchecksum((u16*)sramcntrl.srambuf,&sram->checksum,&sram->checksum_inv);
736745
}
737746
if(loc<sramcntrl.offset) sramcntrl.offset = loc;
@@ -1125,7 +1134,7 @@ void SYS_ResetSystem(s32 reset,u32 reset_code,s32 force_menu)
11251134

11261135
if(reset==SYS_HOTRESET && force_menu==TRUE) {
11271136
sram = __SYS_LockSram();
1128-
sram->flags |= 0x40;
1137+
sram->flags |= SRAM_BOOTIPL_BIT;
11291138
__SYS_UnlockSram(TRUE);
11301139
while(!__SYS_SyncSram());
11311140
}
@@ -1662,42 +1671,201 @@ void SYS_DumpPMC(void)
16621671
printf("<%u load/stores / %u miss cycles / %u cycles / %u instructions>\n",mfpmc1(),mfpmc2(),mfpmc3(),mfpmc4());
16631672
}
16641673

1665-
void SYS_SetWirelessID(u32 chan,u32 id)
1674+
u32 SYS_GetCounterBias(void)
1675+
{
1676+
u32 bias;
1677+
syssram *sram;
1678+
1679+
sram = __SYS_LockSram();
1680+
bias = sram->counter_bias;
1681+
__SYS_UnlockSram(0);
1682+
return bias;
1683+
}
1684+
1685+
void SYS_SetCounterBias(u32 bias)
16661686
{
16671687
u32 write;
1668-
syssramex *sram;
1688+
syssram *sram;
16691689

16701690
write = 0;
1671-
sram = __SYS_LockSramEx();
1672-
if(sram->wirelessPad_id[chan]!=(u16)id) {
1673-
sram->wirelessPad_id[chan] = (u16)id;
1691+
sram = __SYS_LockSram();
1692+
if(sram->counter_bias!=bias) {
1693+
sram->counter_bias = bias;
16741694
write = 1;
16751695
}
1676-
__SYS_UnlockSramEx(write);
1696+
__SYS_UnlockSram(write);
1697+
}
1698+
1699+
s8 SYS_GetDisplayOffsetH(void)
1700+
{
1701+
s8 offset;
1702+
syssram *sram;
1703+
1704+
sram = __SYS_LockSram();
1705+
offset = sram->display_offsetH;
1706+
__SYS_UnlockSram(0);
1707+
return offset;
1708+
}
1709+
1710+
void SYS_SetDisplayOffsetH(s8 offset)
1711+
{
1712+
u32 write;
1713+
syssram *sram;
1714+
1715+
write = 0;
1716+
sram = __SYS_LockSram();
1717+
if(sram->display_offsetH!=offset) {
1718+
sram->display_offsetH = offset;
1719+
write = 1;
1720+
}
1721+
__SYS_UnlockSram(write);
1722+
}
1723+
1724+
u8 SYS_GetEuRGB60(void)
1725+
{
1726+
u8 enable;
1727+
syssram *sram;
1728+
1729+
sram = __SYS_LockSram();
1730+
enable = _SHIFTR(sram->ntd,6,1);
1731+
__SYS_UnlockSram(0);
1732+
return enable;
1733+
}
1734+
1735+
void SYS_SetEuRGB60(u8 enable)
1736+
{
1737+
u32 write;
1738+
syssram *sram;
1739+
1740+
write = 0;
1741+
sram = __SYS_LockSram();
1742+
if(_SHIFTR(sram->ntd,6,1)!=enable) {
1743+
sram->ntd = (sram->ntd&~0x40)|(_SHIFTL(enable,6,1));
1744+
write = 1;
1745+
}
1746+
__SYS_UnlockSram(write);
1747+
}
1748+
1749+
u8 SYS_GetLanguage(void)
1750+
{
1751+
u8 lang;
1752+
syssram *sram;
1753+
1754+
sram = __SYS_LockSram();
1755+
lang = sram->lang;
1756+
__SYS_UnlockSram(0);
1757+
return lang;
1758+
}
1759+
1760+
void SYS_SetLanguage(u8 lang)
1761+
{
1762+
u32 write;
1763+
syssram *sram;
1764+
1765+
write = 0;
1766+
sram = __SYS_LockSram();
1767+
if(sram->lang!=lang) {
1768+
sram->lang = lang;
1769+
write = 1;
1770+
}
1771+
__SYS_UnlockSram(write);
1772+
}
1773+
1774+
u8 SYS_GetProgressiveScan(void)
1775+
{
1776+
u8 enable;
1777+
syssram *sram;
1778+
1779+
sram = __SYS_LockSram();
1780+
enable = ( sram->flags & SRAM_PROGSCAN_BIT );
1781+
__SYS_UnlockSram(0);
1782+
return enable != 0;
16771783
}
16781784

1679-
u32 SYS_GetWirelessID(u32 chan)
1785+
void SYS_SetProgressiveScan(u8 enable)
1786+
{
1787+
u32 write;
1788+
syssram *sram;
1789+
1790+
write = 0;
1791+
sram = __SYS_LockSram();
1792+
if(_SHIFTR(sram->flags,7,1)!=enable) {
1793+
sram->flags = ( sram->flags & ~SRAM_PROGSCAN_BIT ) | ( _SHIFTL(enable,7,1) );
1794+
write = 1;
1795+
}
1796+
__SYS_UnlockSram(write);
1797+
}
1798+
1799+
u8 SYS_GetSoundMode(void)
1800+
{
1801+
u8 mode;
1802+
syssram *sram;
1803+
1804+
sram = __SYS_LockSram();
1805+
mode = ( sram->flags & SRAM_SOUND_MODE_BIT );
1806+
__SYS_UnlockSram(0);
1807+
return mode != 0;
1808+
}
1809+
1810+
void SYS_SetSoundMode(u8 mode)
1811+
{
1812+
u32 write;
1813+
syssram *sram;
1814+
1815+
write = 0;
1816+
sram = __SYS_LockSram();
1817+
if(_SHIFTR(sram->flags,2,1)!=mode) {
1818+
sram->flags = ( sram->flags & ~SRAM_SOUND_MODE_BIT )| ( _SHIFTL(mode,2,1) );
1819+
write = 1;
1820+
}
1821+
__SYS_UnlockSram(write);
1822+
}
1823+
1824+
u8 SYS_GetVideoMode(void)
1825+
{
1826+
u8 mode;
1827+
syssram *sram;
1828+
1829+
sram = __SYS_LockSram();
1830+
mode = ( sram->flags & SRAM_VIDEO_MODE_BITS );
1831+
__SYS_UnlockSram(0);
1832+
return mode;
1833+
}
1834+
1835+
void SYS_SetVideoMode(u8 mode)
1836+
{
1837+
u32 write;
1838+
syssram *sram;
1839+
1840+
write = 0;
1841+
sram = __SYS_LockSram();
1842+
if((sram->flags&SRAM_VIDEO_MODE_BITS)!=mode) {
1843+
sram->flags = ( sram->flags & ~SRAM_VIDEO_MODE_BITS )|(mode & SRAM_VIDEO_MODE_BITS);
1844+
write = 1;
1845+
}
1846+
__SYS_UnlockSram(write);
1847+
}
1848+
1849+
u16 SYS_GetWirelessID(u32 chan)
16801850
{
16811851
u16 id;
1682-
syssramex *sram;
1852+
syssramex *sramex;
16831853

1684-
id = 0;
1685-
sram = __SYS_LockSramEx();
1686-
id = sram->wirelessPad_id[chan];
1854+
sramex = __SYS_LockSramEx();
1855+
id = sramex->wirelessPad_id[chan];
16871856
__SYS_UnlockSramEx(0);
16881857
return id;
16891858
}
16901859

1691-
void SYS_SetGBSMode(u16 mode)
1860+
void SYS_SetWirelessID(u32 chan,u16 id)
16921861
{
16931862
u32 write;
16941863
syssramex *sramex;
16951864

16961865
write = 0;
16971866
sramex = __SYS_LockSramEx();
1698-
if(_SHIFTR(mode,10,5)>=20 || _SHIFTR(mode,6,2)==0x3 || (mode&0x3f)>=60) mode = 0;
1699-
if(sramex->gbs!=mode) {
1700-
sramex->gbs = mode;
1867+
if(sramex->wirelessPad_id[chan]!=id) {
1868+
sramex->wirelessPad_id[chan] = id;
17011869
write = 1;
17021870
}
17031871
__SYS_UnlockSramEx(write);
@@ -1714,6 +1882,21 @@ u16 SYS_GetGBSMode(void)
17141882
return mode;
17151883
}
17161884

1885+
void SYS_SetGBSMode(u16 mode)
1886+
{
1887+
u32 write;
1888+
syssramex *sramex;
1889+
1890+
write = 0;
1891+
sramex = __SYS_LockSramEx();
1892+
if(_SHIFTR(mode,10,5)>=20 || _SHIFTR(mode,6,2)==0x3 || (mode&0x3f)>=60) mode = 0;
1893+
if(sramex->gbs!=mode) {
1894+
sramex->gbs = mode;
1895+
write = 1;
1896+
}
1897+
__SYS_UnlockSramEx(write);
1898+
}
1899+
17171900
#if defined(HW_RVL)
17181901
u32 SYS_GetHollywoodRevision(void)
17191902
{

0 commit comments

Comments
 (0)