Permalink
Browse files

endianess fixes in imgreader plugin, working region patcher

  • Loading branch information...
gligli committed Dec 5, 2011
1 parent 751a032 commit b195cce6154ace97b2d0f6ee1270c4109ef95511
Showing with 39 additions and 19 deletions.
  1. +11 −0 nullDC/stdclass.cpp
  2. +1 −0 nullDC/stdclass.h
  3. +3 −1 plugins/ImgReader/ImgReader.cpp
  4. +24 −18 plugins/ImgReader/common.cpp
View
@@ -395,4 +395,15 @@ int msgboxf(char* text,unsigned int type,...)
/*gli else
return MessageBox(NULL,temp,VER_SHORTNAME,type | MB_TASKMODAL);*/
return 0;
+}
+
+void bswap_block(void * addr,int size)
+{
+ verify(!(size&3));
+ verify(!((u32)addr&3));
+
+ u32 * p= (u32*) addr;
+
+ for(int i=0;i<size/4;++i)
+ p[i]=__builtin_bswap32(p[i]);
}
View
@@ -266,6 +266,7 @@ class VArray2
void * ExeptionHandler(int pir,void * srr0,void * dar,int write);
int msgboxf(wchar* text,unsigned int type,...);
+void bswap_block(void * addr,int size);
#define MBX_OK 0x00000000L
#define MBX_OKCANCEL 0x00000001L
@@ -55,7 +55,9 @@ void irLoadSettings()
// strcpy(irsettings.DefaultImage,"sda:/dcisos/sonic/Sonic Adventure International v1.003 (1999)(Sega)(NTSC)(JP)(M5)[!].gdi");
// strcpy(irsettings.DefaultImage,"sda:/dcisos/ct/Crazy Taxi v1.004 (1999)(Sega)(NTSC)(US)[!][10S 51035].gdi");
// strcpy(irsettings.DefaultImage,"sda:/dcisos/powerstone/Power Stone v1.001 (1999)(Capcom)(NTSC)(US)[!].gdi");
-// irsettings.PatchRegion=true;
+// strcpy(irsettings.DefaultImage,"sda:/dcisos/pj/Project Justice v1.001 (2001)(Capcom)(NTSC)(US)[!].gdi");
+// strcpy(irsettings.DefaultImage,"sda:/dcisos/ikaruga/Ikaruga v1.002 (2002)(ESP)(NTSC)(JP)[!].gdi");
+ irsettings.PatchRegion=true;
}
void irSaveSettings()
{
@@ -55,6 +55,8 @@ void PatchRegion_0(u8* sector,int size)
//patch meta info
u8* p_area_symbol=&usersect[0x30];
memcpy(p_area_symbol,"JUE ",8);
+
+ bswap_block(p_area_symbol,8);
}
void PatchRegion_6(u8* sector,int size)
{
@@ -73,6 +75,10 @@ void PatchRegion_6(u8* sector,int size)
memcpy(&p_area_text[4],"For JAPAN,TAIWAN,PHILIPINES.",28);
memcpy(&p_area_text[4 + 32],"For USA and CANADA. ",28);
memcpy(&p_area_text[4 + 32 + 32],"For EUROPE. ",28);
+
+ bswap_block(&p_area_text[4],28);
+ bswap_block(&p_area_text[4 + 32],28);
+ bswap_block(&p_area_text[4 + 32 + 32],28);
}
bool ConvertSector(u8* in_buff , u8* out_buff , int from , int to,int sector)
{
@@ -216,20 +222,20 @@ void TermDrive()
u32 CreateTrackInfo(u32 ctrl,u32 addr,u32 fad)
{
u8 p[4];
- p[0]=(ctrl<<4)|(addr<<0);
- p[1]=fad>>16;
- p[2]=fad>>8;
- p[3]=fad>>0;
+ p[3]=(ctrl<<4)|(addr<<0);
+ p[2]=fad>>16;
+ p[1]=fad>>8;
+ p[0]=fad>>0;
return *(u32*)p;
}
u32 CreateTrackInfo_se(u32 ctrl,u32 addr,u32 tracknum)
{
u8 p[4];
- p[0]=(ctrl<<4)|(addr<<0);
- p[1]=tracknum;
- p[2]=0;
- p[3]=0;
+ p[3]=(ctrl<<4)|(addr<<0);
+ p[2]=tracknum;
+ p[1]=0;
+ p[0]=0;
return *(u32*)p;
}
@@ -292,22 +298,22 @@ void GetDriveSessionInfo(u8* to,u8 session)
{
if (!disc)
return;
- to[0]=2;//status , will get overwrited anyway
- to[1]=0;//0's
+ to[3]=2;//status , will get overwrited anyway
+ to[2]=0;//0's
if (session==0)
{
- to[2]=disc->sessions.size();//count of sessions
- to[3]=disc->EndFAD>>16;//fad is sessions end
- to[4]=disc->EndFAD>>8;
- to[5]=disc->EndFAD>>0;
+ to[1]=disc->sessions.size();//count of sessions
+ to[0]=disc->EndFAD>>16;//fad is sessions end
+ to[7]=disc->EndFAD>>8;
+ to[6]=disc->EndFAD>>0;
}
else
{
- to[2]=disc->sessions[session-1].FirstTrack;//start track of this session
- to[3]=disc->sessions[session-1].StartFAD>>16;//fad is session start
- to[4]=disc->sessions[session-1].StartFAD>>8;
- to[5]=disc->sessions[session-1].StartFAD>>0;
+ to[1]=disc->sessions[session-1].FirstTrack;//start track of this session
+ to[0]=disc->sessions[session-1].StartFAD>>16;//fad is session start
+ to[7]=disc->sessions[session-1].StartFAD>>8;
+ to[6]=disc->sessions[session-1].StartFAD>>0;
}
}

0 comments on commit b195cce

Please sign in to comment.