Skip to content

Commit

Permalink
introduce sram flags (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: Extrems <[email protected]>
Co-authored-by: Dave Murphy <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2021
1 parent b2a0b7a commit bc4b778
Show file tree
Hide file tree
Showing 2 changed files with 245 additions and 24 deletions.
50 changes: 44 additions & 6 deletions gc/ogc/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@ distribution.
#define SYS_PROTECTWRITE 0x00000002 /*!< Write to protected region is permitted */
#define SYS_PROTECTRDWR (SYS_PROTECTREAD|SYS_PROTECTWRITE) /*!< Read and write operations on protected region is permitted */

/*!
* \sram language flags
*/

#define SYS_LANG_ENGLISH 0
#define SYS_LANG_GERMAN 1
#define SYS_LANG_FRENCH 2
#define SYS_LANG_SPANISH 3
#define SYS_LANG_ITALIAN 4
#define SYS_LANG_DUTCH 5

/*!
* \sram video flags
*/

#define SYS_VIDEO_NTSC 0
#define SYS_VIDEO_PAL 1
#define SYS_VIDEO_MPAL 2

/*!
* \sram audio flags
*/

#define SYS_SOUND_MONO 0
#define SYS_SOUND_STEREO 1

/*!
*@}
*/
Expand All @@ -102,7 +128,6 @@ distribution.
#define SYS_FONTSIZE_SJIS (3840 + 1179648)



/*!
* \addtogroup sys_mcastmacros OS memory casting macros
* @{
Expand Down Expand Up @@ -147,7 +172,7 @@ typedef u32 syswd_t;
* \param ead1 unknown attribute
* \param counter_bias bias value for the realtime clock
* \param display_offsetH pixel offset for the VI
* \param ntd unknown attribute
* \param ntd mostly unknown attribute
* \param lang language of system
* \param flags device and operations flag
*/
Expand Down Expand Up @@ -305,11 +330,24 @@ s32 SYS_RemoveAlarm(syswd_t thealarm);
*/
s32 SYS_CancelAlarm(syswd_t thealarm);


void SYS_SetWirelessID(u32 chan,u32 id);
u32 SYS_GetWirelessID(u32 chan);
void SYS_SetGBSMode(u16 mode);
u32 SYS_GetCounterBias(void);
void SYS_SetCounterBias(u32 bias);
s8 SYS_GetDisplayOffsetH(void);
void SYS_SetDisplayOffsetH(s8 offset);
u8 SYS_GetEuRGB60(void);
void SYS_SetEuRGB60(u8 enable);
u8 SYS_GetLanguage(void);
void SYS_SetLanguage(u8 lang);
u8 SYS_GetProgressiveScan(void);
void SYS_SetProgressiveScan(u8 enable);
u8 SYS_GetSoundMode(void);
void SYS_SetSoundMode(u8 mode);
u8 SYS_GetVideoMode(void);
void SYS_SetVideoMode(u8 mode);
u16 SYS_GetWirelessID(u32 chan);
void SYS_SetWirelessID(u32 chan,u16 id);
u16 SYS_GetGBSMode(void);
void SYS_SetGBSMode(u16 mode);
u32 SYS_GetFontEncoding(void);
u32 SYS_InitFont(sys_fontheader *font_data);
void SYS_GetFontTexture(s32 c,void **image,s32 *xpos,s32 *ypos,s32 *width);
Expand Down
219 changes: 201 additions & 18 deletions libogc/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,18 @@ distribution.
#endif
#define KERNEL_HEAP (1*1024*1024)

// SRAM bits
#define SRAM_VIDEO_MODE_BITS 0x03
#define SRAM_SOUND_MODE_BIT 0x04
#define SRAM_OOBE_DONE_BIT 0x08
#define SRAM_UNKNOWN1_BIT 0x10
#define SRAM_UNKNOWN2_BIT 0x20
#define SRAM_BOOTIPL_BIT 0x40
#define SRAM_PROGSCAN_BIT 0x80

// DSPCR bits
#define DSPCR_DSPRESET 0x0800 // Reset DSP
#define DSPCR_DSPDMA 0x0200 // ARAM dma in progress, if set
#define DSPCR_DSPDMA 0x0200 // ARAM dma in progress, if set
#define DSPCR_DSPINTMSK 0x0100 // * interrupt mask (RW)
#define DSPCR_DSPINT 0x0080 // * interrupt active (RWC)
#define DSPCR_ARINTMSK 0x0040
Expand Down Expand Up @@ -731,7 +740,7 @@ static u32 __unlocksram(u32 write,u32 loc)

if(write) {
if(!loc) {
if((sram->flags&0x03)>0x02) sram->flags = (sram->flags&~0x03);
if((sram->flags&SRAM_VIDEO_MODE_BITS) > 0x02) sram->flags &= ~SRAM_VIDEO_MODE_BITS;
__buildchecksum((u16*)sramcntrl.srambuf,&sram->checksum,&sram->checksum_inv);
}
if(loc<sramcntrl.offset) sramcntrl.offset = loc;
Expand Down Expand Up @@ -1125,7 +1134,7 @@ void SYS_ResetSystem(s32 reset,u32 reset_code,s32 force_menu)

if(reset==SYS_HOTRESET && force_menu==TRUE) {
sram = __SYS_LockSram();
sram->flags |= 0x40;
sram->flags |= SRAM_BOOTIPL_BIT;
__SYS_UnlockSram(TRUE);
while(!__SYS_SyncSram());
}
Expand Down Expand Up @@ -1662,42 +1671,201 @@ void SYS_DumpPMC(void)
printf("<%u load/stores / %u miss cycles / %u cycles / %u instructions>\n",mfpmc1(),mfpmc2(),mfpmc3(),mfpmc4());
}

void SYS_SetWirelessID(u32 chan,u32 id)
u32 SYS_GetCounterBias(void)
{
u32 bias;
syssram *sram;

sram = __SYS_LockSram();
bias = sram->counter_bias;
__SYS_UnlockSram(0);
return bias;
}

void SYS_SetCounterBias(u32 bias)
{
u32 write;
syssramex *sram;
syssram *sram;

write = 0;
sram = __SYS_LockSramEx();
if(sram->wirelessPad_id[chan]!=(u16)id) {
sram->wirelessPad_id[chan] = (u16)id;
sram = __SYS_LockSram();
if(sram->counter_bias!=bias) {
sram->counter_bias = bias;
write = 1;
}
__SYS_UnlockSramEx(write);
__SYS_UnlockSram(write);
}

s8 SYS_GetDisplayOffsetH(void)
{
s8 offset;
syssram *sram;

sram = __SYS_LockSram();
offset = sram->display_offsetH;
__SYS_UnlockSram(0);
return offset;
}

void SYS_SetDisplayOffsetH(s8 offset)
{
u32 write;
syssram *sram;

write = 0;
sram = __SYS_LockSram();
if(sram->display_offsetH!=offset) {
sram->display_offsetH = offset;
write = 1;
}
__SYS_UnlockSram(write);
}

u8 SYS_GetEuRGB60(void)
{
u8 enable;
syssram *sram;

sram = __SYS_LockSram();
enable = _SHIFTR(sram->ntd,6,1);
__SYS_UnlockSram(0);
return enable;
}

void SYS_SetEuRGB60(u8 enable)
{
u32 write;
syssram *sram;

write = 0;
sram = __SYS_LockSram();
if(_SHIFTR(sram->ntd,6,1)!=enable) {
sram->ntd = (sram->ntd&~0x40)|(_SHIFTL(enable,6,1));
write = 1;
}
__SYS_UnlockSram(write);
}

u8 SYS_GetLanguage(void)
{
u8 lang;
syssram *sram;

sram = __SYS_LockSram();
lang = sram->lang;
__SYS_UnlockSram(0);
return lang;
}

void SYS_SetLanguage(u8 lang)
{
u32 write;
syssram *sram;

write = 0;
sram = __SYS_LockSram();
if(sram->lang!=lang) {
sram->lang = lang;
write = 1;
}
__SYS_UnlockSram(write);
}

u8 SYS_GetProgressiveScan(void)
{
u8 enable;
syssram *sram;

sram = __SYS_LockSram();
enable = ( sram->flags & SRAM_PROGSCAN_BIT );
__SYS_UnlockSram(0);
return enable != 0;
}

u32 SYS_GetWirelessID(u32 chan)
void SYS_SetProgressiveScan(u8 enable)
{
u32 write;
syssram *sram;

write = 0;
sram = __SYS_LockSram();
if(_SHIFTR(sram->flags,7,1)!=enable) {
sram->flags = ( sram->flags & ~SRAM_PROGSCAN_BIT ) | ( _SHIFTL(enable,7,1) );
write = 1;
}
__SYS_UnlockSram(write);
}

u8 SYS_GetSoundMode(void)
{
u8 mode;
syssram *sram;

sram = __SYS_LockSram();
mode = ( sram->flags & SRAM_SOUND_MODE_BIT );
__SYS_UnlockSram(0);
return mode != 0;
}

void SYS_SetSoundMode(u8 mode)
{
u32 write;
syssram *sram;

write = 0;
sram = __SYS_LockSram();
if(_SHIFTR(sram->flags,2,1)!=mode) {
sram->flags = ( sram->flags & ~SRAM_SOUND_MODE_BIT )| ( _SHIFTL(mode,2,1) );
write = 1;
}
__SYS_UnlockSram(write);
}

u8 SYS_GetVideoMode(void)
{
u8 mode;
syssram *sram;

sram = __SYS_LockSram();
mode = ( sram->flags & SRAM_VIDEO_MODE_BITS );
__SYS_UnlockSram(0);
return mode;
}

void SYS_SetVideoMode(u8 mode)
{
u32 write;
syssram *sram;

write = 0;
sram = __SYS_LockSram();
if((sram->flags&SRAM_VIDEO_MODE_BITS)!=mode) {
sram->flags = ( sram->flags & ~SRAM_VIDEO_MODE_BITS )|(mode & SRAM_VIDEO_MODE_BITS);
write = 1;
}
__SYS_UnlockSram(write);
}

u16 SYS_GetWirelessID(u32 chan)
{
u16 id;
syssramex *sram;
syssramex *sramex;

id = 0;
sram = __SYS_LockSramEx();
id = sram->wirelessPad_id[chan];
sramex = __SYS_LockSramEx();
id = sramex->wirelessPad_id[chan];
__SYS_UnlockSramEx(0);
return id;
}

void SYS_SetGBSMode(u16 mode)
void SYS_SetWirelessID(u32 chan,u16 id)
{
u32 write;
syssramex *sramex;

write = 0;
sramex = __SYS_LockSramEx();
if(_SHIFTR(mode,10,5)>=20 || _SHIFTR(mode,6,2)==0x3 || (mode&0x3f)>=60) mode = 0;
if(sramex->gbs!=mode) {
sramex->gbs = mode;
if(sramex->wirelessPad_id[chan]!=id) {
sramex->wirelessPad_id[chan] = id;
write = 1;
}
__SYS_UnlockSramEx(write);
Expand All @@ -1714,6 +1882,21 @@ u16 SYS_GetGBSMode(void)
return mode;
}

void SYS_SetGBSMode(u16 mode)
{
u32 write;
syssramex *sramex;

write = 0;
sramex = __SYS_LockSramEx();
if(_SHIFTR(mode,10,5)>=20 || _SHIFTR(mode,6,2)==0x3 || (mode&0x3f)>=60) mode = 0;
if(sramex->gbs!=mode) {
sramex->gbs = mode;
write = 1;
}
__SYS_UnlockSramEx(write);
}

#if defined(HW_RVL)
u32 SYS_GetHollywoodRevision(void)
{
Expand Down

0 comments on commit bc4b778

Please sign in to comment.