At the start of your main header file, paste this block of code:
- Code: Select all
#if UNDER_CE
int __cdecl PrintF(const char *fmt, ...);
typedef struct
{
int version;
void *pIOInst;
int (__stdcall *p_input_available) (void *pInst);
char * (__stdcall *p_get_string) (void *pInst, char *s, int nmaxlen);
void (__stdcall *p_put_string) (void *pInst, const char *s);
int (__cdecl *p_print) (void *pInst, const char *fmt, ...);
int (__cdecl *p_vprint) (void *pInst, const char *fmt, va_list args);
unsigned int (__stdcall *p_available_memory) (void *pInst);
void * (__stdcall *p_allocate_memory) (void *pInst, int nsize);
void (__stdcall *p_free_memory) (void *pInst, void *pmem);
int argc;
char **argv;
}
TEngineIO;
extern TEngineIO *EngineIO;
#define malloc(n_) (EngineIO->p_allocate_memory(EngineIO->pIOInst,n_))
#define free(p_) (EngineIO->p_free_memory(EngineIO->pIOInst,p_))
#define printf PrintF
#define puts(s_) PrintF("%s\n",s_)
// replace this with the name of your "input-available" function
#define InputAvailable() (EngineIO->p_input_available(EngineIO->pIOInst))
#endif
At the end of your main source file, paste this block of code:
- Code: Select all
#if UNDER_CE
TEngineIO *EngineIO;
int __cdecl PrintF(const char *fmt, ...)
{
int n;
va_list args;
va_start (args, fmt);
n = EngineIO->p_vprint (EngineIO->pIOInst, fmt, args);
va_end (args);
return n;
}
BOOL WINAPI DllMain (HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
return TRUE;
}
__declspec(dllexport) void __stdcall Run (TEngineIO *pEngineIO)
{
EngineIO = pEngineIO;
main (EngineIO->argc, EngineIO->argv);
}
#endif
That's it! Yes, its that easy. Your winboard engine is now ready to run in ThinkerBoard.
I am hoping other authors of xboard-compatible engines would consider porting their engines. As can be seen, it takes very little effort - especially in the ThinkerBoard environment - it does not force you to reorganize your existing code.
If anyone needs help doing so, please let me know.
Thanks!