Example SCDSI.DLL Usage Code

From StoneHome

Contents

Using the DLL

Tee hee. This code may be shitty, but it'll at least give you an idea how to use the Nintendo DS Interface Simulator DLL. The easiest way to put one of these things together is to use one of the application wizards in MSVS. I used the CDHtmlDialog MFC application because I'm ultra-lazy. Deal with it. Chances are it's easiest to just grab the MSVC7 Project (53k). That said, here are the salient few behaviors.

Code Examples

Here are how to store the function pointers, how to assign the appropriate addresses to the function pointers once they're loaded, and how to use the function pointers once they're established. Those three things are the primary obstacles for novices, but if you need more, grab the example project above. No, I will not provide examples for other IDEs. I'm lazy. It's a DLL. Read your IDE's DLL documentation. Sorry.

Storing the Functions

typedef
void
(CALLBACK* fp_void_void)(
void
);  
typedef
void
* (CALLBACK* fp_vptr_void)(
void
);  
typedef
char
* (CALLBACK* fp_cptr_void)(
void
);

 

 
typedef
void
(CALLBACK* fp_void_vptr)(
void
*);  
typedef
void
(CALLBACK* fp_void_uint)(
unsigned
int
);

 

 
typedef
unsigned
char
(CALLBACK* fp_byte_void)(
void
);

   fp_void_void ShowInterface;  fp_void_void HideInterface;  fp_vptr_void GetHiScreenBuffer;  fp_vptr_void GetLoScreenBuffer;  fp_cptr_void GetVersionString;  fp_vptr_void GetInterfaceState;  fp_vptr_void GetKeyState;  fp_byte_void GetTouchX;  fp_byte_void GetTouchY;  fp_void_vptr SetVClockHandler;  fp_void_uint EnableVClock;

 fp_void_void UpdateDllVideo;

Acquiring the Functions

std::string dllError;  
bool
CScDsiTestApp::AttemptLoadDll() {

 

 
bool
success =
false
;

 

  hInterfaceDll = LoadLibrary(
"DsInterfaceDll"
);

 

 
if
(hInterfaceDll != NULL) {   HideInterface = (fp_void_void)GetProcAddress(hInterfaceDll,
"HideInterface"
);  
if
(HideInterface) {   ShowInterface = (fp_void_void)GetProcAddress(hInterfaceDll,
"ShowInterface"
);  
if
(ShowInterface) {   GetHiScreenBuffer = (fp_vptr_void)GetProcAddress(hInterfaceDll,
"GetHiScreenBuffer"
);  
if
(GetHiScreenBuffer) {   GetLoScreenBuffer = (fp_vptr_void)GetProcAddress(hInterfaceDll,
"GetLoScreenBuffer"
);  
if
(GetLoScreenBuffer) {   GetVersionString = (fp_cptr_void)GetProcAddress(hInterfaceDll,
"GetVersionString"
);  
if
(GetVersionString) {   GetInterfaceState = (fp_vptr_void)GetProcAddress(hInterfaceDll,
"GetInterfaceState"
);  
if
(GetInterfaceState) {   GetKeyState = (fp_vptr_void)GetProcAddress(hInterfaceDll,
"GetKeyState"
);  
if
(GetKeyState) {   GetTouchX = (fp_byte_void)GetProcAddress(hInterfaceDll,
"GetTouchX"
);  
if
(GetTouchX) {   GetTouchY = (fp_byte_void)GetProcAddress(hInterfaceDll,
"GetTouchY"
);  
if
(GetTouchY) {   SetVClockHandler = (fp_void_vptr)GetProcAddress(hInterfaceDll,
"SetVClockHandler"
);  
if
(SetVClockHandler) {  
/* Yay for stupid deep nesting */
EnableVClock = (fp_void_uint)GetProcAddress(hInterfaceDll,
"EnableVClock"
);  
/* you know you wish you wrote this */
if
(EnableVClock) {   UpdateDllVideo = (fp_void_void)GetProcAddress(hInterfaceDll,
"UpdateDllVideo"
);  
if
(UpdateDllVideo) {   success =
true
;  
/* I'm gonna pretend it's about the */
}
else
dllError =
"Can't load UpdateDllVideo()."
;  
/* probably 6 or so cycles I save doing */
}
else
dllError =
"Can't load EnableVClock()."
;  
/* it this way, but that's a lie */
}
else
dllError =
"Can't load SetVClockHandler()."
;   }
else
dllError =
"Can't load GetTouchY()."
;   }
else
dllError =
"Can't load GetTouchX()."
;   }
else
dllError =
"Can't load GetKeyState()."
;   }
else
dllError =
"Can't load GetInterfaceState()."
;   }
else
dllError =
"Can't load GetVersionString()."
;   }
else
dllError =
"Can't load GetLoScreenBuffer()."
;   }
else
dllError =
"Can't load GetHiScreenBuffer()."
;   }
else
dllError =
"Can't load ShowInterface()."
;   }
else
dllError =
"Can't load HideInterface()."
;   }
else
dllError =
"Can't load the DLL."
;  
// I just like the pretty triangle
// so suck it, fool
return
success;

 

 
// Bad as mayonnaise.
 }

Using the Functions

All you actually need to do is call as UpdateDllVideo() below. I just cast the pointers returned from GetHiScreenBuffer() and GetLoScreenBuffer() because I'm a control freak. Don't mind me.

void
CScDsiTestApp::BlueScreen() {

 

 
unsigned
int
* screenPtrH = (
unsigned
int
*)GetHiScreenBuffer();  
unsigned
int
* screenPtrL = (
unsigned
int
*)GetLoScreenBuffer();

 

 
for
(
int
i=0; i<256*192; ++i) {

  screenPtrH[i] = screenPtrL[i] = MakeColor(0,0,31);   }     UpdateDllVideo();  

 }