Commits

wahrhaft committed 43bec73

Use core logging function

Comments (0)

Files changed (12)

     if (ConfigOpenSection("Video-General", &video_general_section) != M64ERR_SUCCESS ||
         ConfigOpenSection("Video-Glide64", &video_glide64_section) != M64ERR_SUCCESS)
     {
-        printf("Could not open configuration\n", M64MSG_ERROR);
+        WriteLog(M64MSG_ERROR, "Could not open configuration");
         return FALSE;
     }
     ConfigSetDefaultBool(video_general_section, "Fullscreen", false, "Use fullscreen mode if True, or windowed mode if False");
 
 int Config_ReadInt(const char *itemname, int def_value, BOOL create)
 {
-    printf("Getting value %s\n", itemname);
+    WriteLog(M64MSG_VERBOSE, "Getting value %s", itemname);
     ConfigSetDefaultInt(video_glide64_section, itemname, def_value, itemname);
     return ConfigGetParamInt(video_glide64_section, itemname);
 }
 extern std::ofstream loga;
 #define LOG(x) loga.open("log.txt",ios::app); loga << x; loga.flush(); loga.close();
 #else
-#define LOG(x)
+#define LOG(x) WriteLog(M64MSG_VERBOSE, x);
 #endif
 
 
     }
    
     //strncat (path, "Glide64.ini", PATH_MAX - strlen(path));
-    printf("opening %s\n", path);
+    WriteLog(M64MSG_INFO, "opening %s\n", path);
     // Open the file
     ini = fopen (path, "rb");
     if (ini == NULL)
     {
-        printf("Could not find Glide64.ini!\n");
+        WriteLog(M64MSG_ERROR, "Could not find Glide64.ini!");
         return FALSE;
         /*
         ini = fopen (path, "w+b");
 
 #include <string.h>
 #include <stdlib.h>
-#include "messagebox.h"
+
 #ifndef _WIN32
 #include <sys/time.h>
 #endif
 std::ofstream rdp_err;
 #endif
 
-int messagebox( const char *title, int flags, const char *fmt, ... )
-{
-    //TODO: remove this function
-    return 0;
-}
-
 GFX_INFO gfx;
 /* definitions of pointers to Core config functions */
 ptr_ConfigOpenSection      ConfigOpenSection = NULL;
     }
     
     //tbuf_size *= 2;
-    printf("tbuf_size %gMb\n", tbuf_size/1024.0f/1024);
+    WriteLog(M64MSG_INFO, "tbuf_size %gMb\n", tbuf_size/1024.0f/1024);
     rdp.texbufs[0].tmu = GR_TMU0;
     rdp.texbufs[0].begin = grTexMinAddress(GR_TMU0);
     rdp.texbufs[0].end = rdp.texbufs[0].begin+tbuf_size;
 
   if (settings.fb_hires)
   {
-    printf("fb_hires\n");
+      WriteLog(M64MSG_INFO, "fb_hires\n");
     GRWINOPENEXT grSstWinOpenExt = (GRWINOPENEXT)grGetProcAddress("grSstWinOpenExt");
     if (grSstWinOpenExt)
       gfx_context = grSstWinOpenExt ((FxU32)NULL,
 
   if (!gfx_context)
   {
-    messagebox("Error", MB_OK|MB_ICONEXCLAMATION, "Error setting display mode");
+    WriteLog(M64MSG_ERROR, "Error setting display mode");
     grSstWinClose (gfx_context);
     grGlideShutdown ();
     return FALSE;
   
   // get the # of TMUs available
   grGet (GR_NUM_TMU, 4, (FxI32 *) &num_tmu);
-  printf("num_tmu %d\n", num_tmu);
+  WriteLog(M64MSG_INFO, "num_tmu %d\n", num_tmu);
   // get maximal texture size
   grGet (GR_MAX_TEXTURE_SIZE, 4, (FxI32 *) &max_tex_size);
   //num_tmu = 1;
   // Is mirroring allowed?
   const char *extensions = grGetString (GR_EXTENSION);
   
-  printf("bebefore\n");
   if (strstr (extensions, "TEXMIRROR"))
     sup_mirroring = 1;
   else
   else
     sup_32bit_tex = FALSE;
   
-  printf("bebefore2\n");
   if (settings.fb_hires)
   {
     const char * extstr = strstr(extensions, "TEXTUREBUFFER");
     grTextureBufferExt = 0;
 
   grFramebufferCopyExt = (GRFRAMEBUFFERCOPYEXT) grGetProcAddress("grFramebufferCopyExt");
-  printf("before\n");
   grStippleModeExt = (GRSTIPPLE) grStippleMode;
   grStipplePatternExt = (GRSTIPPLE) grStipplePattern; 
-  printf("after\n");
   if (grStipplePatternExt)
     grStipplePatternExt(settings.stipple_pattern);
 
           line[x*3+2] = 0x40;
         }
       }
-      printf("[Glide64] Cannot save screenshot in windowed mode!\n");
+      WriteLog(M64MSG_WARNING, "[Glide64] Cannot save screenshot in windowed mode?\n");
       return;
     }
     
 EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle CoreLibHandle, void *Context,
                                    void (*DebugCallback)(void *, int, const char *))
 {
+    l_DebugCallback = DebugCallback;
+    l_DebugCallContext = Context;
     ConfigOpenSection = (ptr_ConfigOpenSection) osal_dynlib_getproc(CoreLibHandle, "ConfigOpenSection");
     ConfigSetParameter = (ptr_ConfigSetParameter) osal_dynlib_getproc(CoreLibHandle, "ConfigSetParameter");
     ConfigGetParameter = (ptr_ConfigGetParameter) osal_dynlib_getproc(CoreLibHandle, "ConfigGetParameter");
         !ConfigGetParamInt   || !ConfigGetParamFloat   || !ConfigGetParamBool   || !ConfigGetParamString ||
         !ConfigGetSharedDataFilepath || !ConfigGetUserConfigPath || !ConfigGetUserDataPath || !ConfigGetUserCachePath)
     {
-        printf("Couldn't connect to Core configuration functions");
+        WriteLog(M64MSG_ERROR, "Couldn't connect to Core configuration functions");
         return M64ERR_INCOMPATIBLE;
     }
 
         !CoreVideo_SetCaption || !CoreVideo_ToggleFullScreen || !CoreVideo_GL_GetProcAddress ||
         !CoreVideo_GL_SetAttribute || !CoreVideo_GL_SwapBuffers)
     {
-        printf("Couldn't connect to Core configuration functions");
+        WriteLog(M64MSG_ERROR, "Couldn't connect to Core video functions");
         return M64ERR_INCOMPATIBLE;
     }
 
-    SetConfigDir(ConfigGetSharedDataFilepath("Glide64.ini"));
-
-    CoreVideo_Init();
-    return M64ERR_SUCCESS;
+    const char *configDir = ConfigGetSharedDataFilepath("Glide64.ini");
+    if (configDir)
+    {
+        SetConfigDir(configDir);
+        CoreVideo_Init();
+        return M64ERR_SUCCESS;
+    }
+    else
+    {
+        WriteLog(M64MSG_ERROR, "Couldn't find Glide64.ini");
+        return M64ERR_FILES;
+    }
 }
 
 EXPORT m64p_error CALL PluginShutdown(void)
   ClearCache ();
 }
 
+#if 0
 /******************************************************************
 Function: DllAbout
 Purpose:  This function is optional function that is provided
           "Thanks to EmuXHaven for hosting my site:\nhttp://glide64.emuxhaven.net/\n\n"
           "Official development channel: #Glide64 on EFnet\nNO ROM REQUESTS / NO BETA REQUESTS");
 }
+#endif
 
 /******************************************************************
 Function: DllTest
 *******************************************************************/ 
 EXPORT void CALL MoveScreen (int xpos, int ypos)
 {
-  LOG ("MoveScreen (" << xpos << ", " << ypos << ")\n");
+  LOG ("MoveScreen");
 }
 
 /******************************************************************
   ReadSpecialSettings (name);
 
 
-  printf("fb_clear %d fb_smart %d\n", settings.fb_depth_clear, settings.fb_smart);
+  WriteLog(M64MSG_INFO, "fb_clear %d fb_smart %d\n", settings.fb_depth_clear, settings.fb_smart);
 
   
   rdp_reset ();
     grSstSelect (0);
   }
   const char *extensions = grGetString (GR_EXTENSION);
-  printf("extensions '%s'\n", extensions);
+  WriteLog(M64MSG_INFO, "extensions '%s'\n", extensions);
   if (!fullscreen)
   {
     grGlideShutdown ();

src/TexBuffer.cpp

   }
   //not found. keep recently accessed bank, clear second one
   if (!rdp.texbufs[rdp.cur_tex_buf^1].clear_allowed) { //can't clear => can't allocate
-    printf("Can't allocate texture buffer\n");
+    WriteLog(M64MSG_WARNING, "Can't allocate texture buffer\n");
     return 0;
   }
   rdp.cur_tex_buf ^= 1;
 #include "m64p_vidext.h"
 #include <stdio.h>
 
-#define LOG(...)
-
 void WriteLog(m64p_msg_level level, const char *msg, ...);
 
 //The Glide API originally used an integer to pick an enumerated resolution.
 #include "CRC.h"
 #include "rdp.h"
 
-#include "messagebox.h"
 #ifndef _WIN32
 #include <sys/time.h>
 #endif // _WIN32
     INI_FindSection ("UCODE");
     FRDP("ucode = %s\n", str);
     int uc = INI_ReadInt (str, -2, 0);
-    printf("ucode = %d\n", uc);
+    WriteLog(M64MSG_INFO, "ucode = %d\n", uc);
     if (uc == -2 && ucode_error_report)
     {
         Config_Open();
         settings.ucode = Config_ReadInt ("ucode", 0);
         
         ReleaseGfx ();
-        sprintf (out_buf, "Error: uCode crc not found in INI, using currently selected uCode\n\n%08lx", (unsigned long)uc_crc);
-        messagebox("Error", MB_OK|MB_ICONEXCLAMATION, out_buf);
+        WriteLog(M64MSG_ERROR, "Error: uCode crc not found in INI, using currently selected uCode\n\n%08lx", (unsigned long)uc_crc);
         
         ucode_error_report = FALSE; // don't report any more ucode errors from this game
     }
         settings.ucode = Config_ReadInt ("ucode", 0);
         
         ReleaseGfx ();
-        sprintf (out_buf, "Error: Unsupported uCode!\n\ncrc: %08lx", (unsigned long)uc_crc);
-        messagebox("Error", MB_OK|MB_ICONEXCLAMATION, out_buf);
+        WriteLog(M64MSG_ERROR, "Error: Unsupported uCode!\n\ncrc: %08lx", (unsigned long)uc_crc);
         
         ucode_error_report = FALSE; // don't report any more ucode errors from this game
     }
       {
         RDP ("Framebuffer copy failed.\n");
       }
-    printf("erf\n");
+
       } else {
-    printf("youhou\n");
+
     if (grLfbLock (GR_LFB_READ_ONLY,
                buffer,
                GR_LFBWRITEMODE_888,
     } catch (...) {
         
         if (fullscreen) ReleaseGfx ();
-        if (messagebox("Glide64 Exception", MB_YESNO|MB_ICONEXCLAMATION, "The GFX plugin caused an exception and has been disabled.\nWould you like to turn it back on and attempt to continue?") == 2)
-            exception = TRUE;
+        WriteLog(M64MSG_ERROR, "The GFX plugin caused an exception and has been disabled.");
+        exception = TRUE;
     }
 #endif
     
 *******************************************************************/ 
 EXPORT void CALL FBRead(DWORD addr)
 {
-  printf("FBRead\n");
     LOG ("FBRead ()\n");
     
   if (cpu_fb_ignore)
     } catch (...) {
         
         if (fullscreen) ReleaseGfx ();
-        if (messagebox("Glide64 Exception", MB_YESNO|MB_ICONEXCLAMATION, "The GFX plugin caused an exception and has been disabled.\nWould you like to turn it back on and attempt to continue?") == 2)
-            exception = TRUE;
+        WriteLog(M64MSG_ERROR, "The GFX plugin caused an exception and has been disabled.");
+        exception = TRUE;
     }
 #endif
     
 
 
   
-  printf("ProcessRPDList %x %x %x\n",
+  WriteLog(M64MSG_VERBOSE, "ProcessRPDList %x %x %x\n",
          *gfx.DPC_START_REG,
          *gfx.DPC_END_REG,
          *gfx.DPC_CURRENT_REG);

src/wrapper/combiner.cpp

                FxBool invert
                )
 {
-    LOG("grAlphaCombine(%d,%d,%d,%d,%d)\r\n", function, factor, local, other, invert);
+    WriteLog(M64MSG_VERBOSE, "grAlphaCombine(%d,%d,%d,%d,%d)\r\n", function, factor, local, other, invert);
     if(glsl_support)
     {
         static int last_function = 0;

src/wrapper/geometry.cpp

 FX_ENTRY void FX_CALL 
 grCoordinateSpace( GrCoordinateSpaceMode_t mode )
 {
-    LOG("grCoordinateSpace(%d)\r\n", mode);
+    WriteLog(M64MSG_VERBOSE, "grCoordinateSpace(%d)\r\n", mode);
     switch(mode)
     {
     case GR_WINDOW_COORDS:
 FX_ENTRY void FX_CALL
 grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode)
 {
-    LOG("grVertexLayout(%d,%d,%d)\r\n", param, offset, mode);
+    WriteLog(M64MSG_VERBOSE, "grVertexLayout(%d,%d,%d)\r\n", param, offset, mode);
     switch(param)
     {
     case GR_PARAM_XY:
 FX_ENTRY void FX_CALL 
 grCullMode( GrCullMode_t mode )
 {
-    LOG("grCullMode(%d)\r\n", mode);
+    WriteLog(M64MSG_VERBOSE, "grCullMode(%d)\r\n", mode);
   static int oldmode = -1, oldinv = -1;
     culling_mode = mode;
   if (inverted_culling == oldinv && oldmode == mode)
 FX_ENTRY void FX_CALL
 grDepthBufferMode( GrDepthBufferMode_t mode )
 {
-    LOG("grDepthBufferMode(%d)\r\n", mode);
+    WriteLog(M64MSG_VERBOSE, "grDepthBufferMode(%d)\r\n", mode);
     switch(mode)
     {
     case GR_DEPTHBUFFER_DISABLE:
 FX_ENTRY void FX_CALL 
 grDepthBufferFunction( GrCmpFnc_t function )
 {
-    LOG("grDepthBufferFunction(%d)\r\n", function);
+    WriteLog(M64MSG_VERBOSE, "grDepthBufferFunction(%d)\r\n", function);
     switch(function)
     {
     case GR_CMP_GEQUAL:
 FX_ENTRY void FX_CALL 
 grDepthMask( FxBool mask )
 {
-    LOG("grDepthMask(%d)\r\n", mask);
+    WriteLog(M64MSG_VERBOSE, "grDepthMask(%d)\r\n", mask);
     glDepthMask(mask);
 }
 
       bestz = z;
       biasFactor = f;
     }
-    printf("f %g z %g\n", f, z);
+    WriteLog(M64MSG_VERBOSE, "f %g z %g\n", f, z);
   }
-  printf(" --> bias factor %g\n", biasFactor);
+  WriteLog(M64MSG_INFO, " --> bias factor %g\n", biasFactor);
   glPopAttrib();
 
 //   SDL_GL_SwapBuffers();
 FX_ENTRY void FX_CALL 
 grDepthBiasLevel( FxI32 level )
 {
-    LOG("grDepthBiasLevel(%d)\r\n", level);
+    WriteLog(M64MSG_VERBOSE, "grDepthBiasLevel(%d)\r\n", level);
   //depth_bias = level;
     if (level)
     {
     float *c_s1 = (float*)c + st1_off/sizeof(float);
     float *c_t1 = (float*)c + st1_off/sizeof(float) + 1;
     float *c_fog = (float*)c + fog_ext_off/sizeof(float);
-    LOG("grDrawTriangle()\r\n");
+    WriteLog(M64MSG_VERBOSE, "grDrawTriangle()\r\n");
 
     //if(*a_fog == 0.0f) *a_fog = 1.0f;
     //if(*b_fog == 0.0f) *b_fog = 1.0f;
     float *s1 = (float*)pt + st1_off/sizeof(float);
     float *t1 = (float*)pt + st1_off/sizeof(float) + 1;
     float *fog = (float*)pt + fog_ext_off/sizeof(float);
-    LOG("grDrawPoint()\r\n");
+    WriteLog(M64MSG_VERBOSE, "grDrawPoint()\r\n");
 
   reloadTexture();
 
     float *b_s1 = (float*)b + st1_off/sizeof(float);
     float *b_t1 = (float*)b + st1_off/sizeof(float) + 1;
     float *b_fog = (float*)b + fog_ext_off/sizeof(float);
-    LOG("grDrawLine()\r\n");
+    WriteLog(M64MSG_VERBOSE, "grDrawLine()\r\n");
 
     //if(*a_fog == 0.0f) *a_fog = 1.0f;
     //if(*b_fog == 0.0f) *b_fog = 1.0f;
     float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
     unsigned char *pargb;
         void **pointers = (void**)pointers2;
-    LOG("grDrawVertexArray(%d,%d)\r\n", mode, Count);
+    WriteLog(M64MSG_VERBOSE, "grDrawVertexArray(%d,%d)\r\n", mode, Count);
 
   reloadTexture();
 
     unsigned int i;
     float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
     unsigned char *pargb;
-    LOG("grDrawVertexArrayContiguous(%d,%d,%d)\r\n", mode, Count, stride);
+    WriteLog(M64MSG_VERBOSE, "grDrawVertexArrayContiguous(%d,%d,%d)\r\n", mode, Count, stride);
 
   // ZIGGY apparently, grDrawVertexArrayContiguous is only used to overwrite the
   // whole screen, so we treat it as a grClearBuffer, no need to reload the texture

src/wrapper/main.cpp

 
 #define INIT_ENTRY_POINT(type, funcname) \
   funcname = (type) CoreVideo_GL_GetProcAddress(#funcname); \
-  if (funcname == NULL) { LOG(M64MSG_WARNING, \
+  if (funcname == NULL) { WriteLog(M64MSG_WARNING, \
     "Couldn't get address of OpenGL function: '%s'", #funcname); funcname = (type) EmptyFunc; }
 
 static void InitGLPrototypes()
       }
       glCopyTexSubImage2D(target, level, 0, 0, x, y, width, height);
     } else {
-      printf("copyteximage %dx%d fmt %x old %dx%d oldfmt %x\n", width, height, internalFormat, w, h, fmt);
+      WriteLog(M64MSG_VERBOSE, "copyteximage %dx%d fmt %x old %dx%d oldfmt %x\n", width, height, internalFormat, w, h, fmt);
 //       glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, internalFormat, GL_UNSIGNED_BYTE, 0);
 //       glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
 //       printf("--> %dx%d newfmt %x\n", width, height, fmt);
     static int first_message = 100;
     if (first_message)
     {
-        unsigned char buf[1000];
+        char buf[1000];
         
         va_list ap;
     
         vsprintf((char*)buf, (char*)text, ap);
         va_end(ap);
 
-       printf("Glide3x warning : %s\n", buf);
+        WriteLog(M64MSG_WARNING, buf);
         first_message--;
     }
 }
 FX_ENTRY void FX_CALL
 grSstOrigin(GrOriginLocation_t  origin)
 {
-    LOG("grSstOrigin(%d)\r\n", origin);
+    WriteLog(M64MSG_VERBOSE, "grSstOrigin(%d)\r\n", origin);
     if (origin != GR_ORIGIN_UPPER_LEFT)
         display_warning("grSstOrigin : %x", origin);
 }
 FX_ENTRY void FX_CALL 
 grClipWindow( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy )
 {
-    LOG("grClipWindow(%d,%d,%d,%d)\r\n", minx, miny, maxx, maxy);
+    WriteLog(M64MSG_VERBOSE, "grClipWindow(%d,%d,%d,%d)\r\n", minx, miny, maxx, maxy);
 
   if (use_fbo && render_to_texture) {
     glScissor(minx, miny, maxx - minx, maxy - miny);
 FX_ENTRY void FX_CALL
 grColorMask( FxBool rgb, FxBool a )
 {
-    LOG("grColorMask(%d, %d)\r\n", rgb, a);
+    WriteLog(M64MSG_VERBOSE, "grColorMask(%d, %d)\r\n", rgb, a);
     glColorMask(rgb, rgb, rgb, a);
 }
 
 grGlideInit( void )
 {
     OPEN_LOG();
-    LOG("grGlideInit()\r\n");
+    WriteLog(M64MSG_VERBOSE, "grGlideInit()\r\n");
 }
 
 FX_ENTRY void FX_CALL 
 grSstSelect( int which_sst )
 {
-    LOG("grSstSelect(%d)\r\n", which_sst);
+    WriteLog(M64MSG_VERBOSE, "grSstSelect(%d)\r\n", which_sst);
 }
 
 BOOL isExtensionSupported(const char *extension)
           int                  nColBuffers,
           int                  nAuxBuffers)
 {
-    LOG("grSstWinOpenExt(%d, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers);
+    WriteLog(M64MSG_VERBOSE, "grSstWinOpenExt(%d, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers);
     return grSstWinOpen(hWnd, screen_resolution, refresh_rate, color_format, 
                         origin_location, nColBuffers, nAuxBuffers);
 }
   color_texture = free_texture++;
   depth_texture = free_texture++;
   
-    LOG("grSstWinOpen(%d, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers);
+    WriteLog(M64MSG_VERBOSE, "grSstWinOpen(%d, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers);
 
     PackedScreenResolution packedResolution;
     packedResolution.resolution = screen_resolution;
         CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, 16) != M64ERR_SUCCESS ||
         CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, 16)  != M64ERR_SUCCESS)
     {
-        printf("Could not set video attributes.");
+        WriteLog(M64MSG_ERROR, "Could not set video attributes.");
         return 0;
     }
 
     if (CoreVideo_SetVideoMode(width, height, 0, screen_mode) != M64ERR_SUCCESS)
     {
-        printf("Could not set video mode.");
+        WriteLog(M64MSG_ERROR, "Could not set video mode.");
         return 0;
     }
 
   if (!getDisableAuxbuf())
     glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &nbAuxBuffers);
   if (nbAuxBuffers > 0)
-    printf("Congratulations, you have %d auxiliary buffers, we'll use them wisely !\n", nbAuxBuffers);
+    WriteLog(M64MSG_INFO, "Congratulations, you have %d auxiliary buffers, we'll use them wisely !\n", nbAuxBuffers);
 
 #ifdef VOODOO1
     nbTextureUnits = 2;
     if (isExtensionSupported("GL_EXT_packed_pixels") == FALSE)
         packed_pixels_support = 0;
     else {
-      printf("packed pixels extension used\n");
+      WriteLog(M64MSG_INFO, "packed pixels extension used\n");
         packed_pixels_support = 1;
     }
 
     if (isExtensionSupported("GL_ARB_texture_non_power_of_two") == FALSE)
         npot_support = 0;
     else {
-      printf("NPOT extension used\n");
+      WriteLog(M64MSG_INFO, "NPOT extension used\n");
         npot_support = 1;
     }
 
 
   use_fbo = getEnableFBO();
 
-  printf("use_fbo %d\n", use_fbo);
+  WriteLog(M64MSG_INFO, "use_fbo %d\n", use_fbo);
 
     if (isExtensionSupported("GL_ARB_shading_language_100") &&
         isExtensionSupported("GL_ARB_shader_objects") &&
 FX_ENTRY void FX_CALL
 grGlideShutdown( void )
 {
-    LOG("grGlideShutdown\r\n");
+    WriteLog(M64MSG_VERBOSE, "grGlideShutdown\r\n");
     CLOSE_LOG();
 }
 
 grSstWinClose( GrContext_t context )
 {
   int i, clear_texbuff = use_fbo;
-    LOG("grSstWinClose(%d)\r\n", context);
+    WriteLog(M64MSG_VERBOSE, "grSstWinClose(%d)\r\n", context);
 
 //   void remove_all_tex();
 //   remove_all_tex();
     static int fbs_init = 0;
   
     //printf("grTextureBufferExt(%d, %d, %d, %d, %d, %d, %d)\r\n", tmu, startAddress, lodmin, lodmax, aspect, fmt, evenOdd);
-    LOG("grTextureBufferExt(%d, %d, %d, %d %d, %d, %d)\r\n", tmu, startAddress, lodmin, lodmax, aspect, fmt, evenOdd);
+    WriteLog(M64MSG_VERBOSE, "grTextureBufferExt(%d, %d, %d, %d %d, %d, %d)\r\n", tmu, startAddress, lodmin, lodmax, aspect, fmt, evenOdd);
     if (lodmin != lodmax) display_warning("grTextureBufferExt : loading more than one LOD");
   if (!use_fbo) {
 
                                         GrTextureFormat_t format,
                                         FxU32      odd_even_mask )
 {
-    LOG("grTextureAuxBufferExt(%d, %d, %d, %d %d, %d, %d)\r\n", tmu, startAddress, thisLOD, largeLOD, aspectRatio, format, odd_even_mask);
+    WriteLog(M64MSG_VERBOSE, "grTextureAuxBufferExt(%d, %d, %d, %d %d, %d, %d)\r\n", tmu, startAddress, thisLOD, largeLOD, aspectRatio, format, odd_even_mask);
     //display_warning("grTextureAuxBufferExt");
 }
 
 FX_ENTRY GrProc FX_CALL
 grGetProcAddress( const char *procName )
 {
-    LOG("grGetProcAddress(%s)\r\n", procName);
+    WriteLog(M64MSG_VERBOSE, "grGetProcAddress(%s)\r\n", procName);
     if(!strcmp(procName, "grSstWinOpenExt"))
         return (GrProc)grSstWinOpenExt;
     if(!strcmp(procName, "grTextureBufferExt"))
 FX_ENTRY FxU32 FX_CALL 
 grGet( FxU32 pname, FxU32 plength, FxI32 *params )
 {
-    LOG("grGet(%d,%d)\r\n", pname, plength);
+    WriteLog(M64MSG_VERBOSE, "grGet(%d,%d)\r\n", pname, plength);
     switch(pname)
     {
     case GR_MAX_TEXTURE_SIZE:
 FX_ENTRY const char * FX_CALL 
 grGetString( FxU32 pname )
 {
-    LOG("grGetString(%d)\r\n", pname);
+    WriteLog(M64MSG_VERBOSE, "grGetString(%d)\r\n", pname);
     switch(pname)
     {
     case GR_EXTENSION:
   if (use_fbo || !render_to_texture || buffer_cleared)
     return;
 
-  LOG("reload texture %dx%d\n", width, height);
-  printf("reload texture %dx%d\n", width, height);
+  WriteLog(M64MSG_VERBOSE, "reload texture %dx%d\n", width, height);
   
   buffer_cleared = TRUE;
 
 void updateTexture()
 {
   if (!use_fbo && render_to_texture == 2) {
-    LOG("update texture %x\n", pBufferAddress);
+    WriteLog(M64MSG_VERBOSE, "update texture %x\n", pBufferAddress);
     //printf("update texture %x\n", pBufferAddress);
 
     // nothing changed, don't update the texture
     if (!buffer_cleared) {
-      LOG("update cancelled\n", pBufferAddress);
+      WriteLog(M64MSG_VERBOSE, "update cancelled\n", pBufferAddress);
       return;
     }
     
     }
     
     if (from == GR_FBCOPY_BUFFER_BACK && to == GR_FBCOPY_BUFFER_FRONT) {
-      printf("save depth buffer %d\n", render_to_texture);
+      WriteLog(M64MSG_VERBOSE, "save depth buffer %d\n", render_to_texture);
       // save the depth image in a texture
       //glDisable(GL_ALPHA_TEST);
       glReadBuffer(current_buffer);
       return;
     }
     if (from == GR_FBCOPY_BUFFER_FRONT && to == GR_FBCOPY_BUFFER_BACK) {
-      printf("writing to depth buffer %d\n", render_to_texture);
+      WriteLog(M64MSG_VERBOSE, "writing to depth buffer %d\n", render_to_texture);
       
       glPushAttrib(GL_ALL_ATTRIB_BITS);
       glDisable(GL_ALPHA_TEST);
 FX_ENTRY void FX_CALL
 grRenderBuffer( GrBuffer_t buffer )
 {
-    LOG("grRenderBuffer(%d)\r\n", buffer);
+    WriteLog(M64MSG_VERBOSE, "grRenderBuffer(%d)\r\n", buffer);
     //printf("grRenderBuffer(%d)\n", buffer);
 
     switch(buffer)
 FX_ENTRY void FX_CALL
 grAuxBufferExt( GrBuffer_t buffer )
 {
-    LOG("grAuxBufferExt(%d)\r\n", buffer);
+    WriteLog(M64MSG_VERBOSE, "grAuxBufferExt(%d)\r\n", buffer);
     //display_warning("grAuxBufferExt");
 
   if (glsl_support && buffer == GR_BUFFER_AUXBUFFER) {
 FX_ENTRY void FX_CALL
 grBufferClear( GrColor_t color, GrAlpha_t alpha, FxU32 depth )
 {
-    LOG("grBufferClear(%d,%d,%d)\r\n", color, alpha, depth);
+    WriteLog(M64MSG_VERBOSE, "grBufferClear(%d,%d,%d)\r\n", color, alpha, depth);
     switch(lfb_color_fmt)
     {
     case GR_COLORFORMAT_ARGB:
   if(renderCallback)
     (*renderCallback)();
   int i;
-    LOG("grBufferSwap(%d)\r\n", swap_interval);
+    WriteLog(M64MSG_VERBOSE, "grBufferSwap(%d)\r\n", swap_interval);
   //printf("swap\n");
   if (render_to_texture) {
     display_warning("swap while render_to_texture\n");
            GrOriginLocation_t origin, FxBool pixelPipeline, 
            GrLfbInfo_t *info )
 {
-    LOG("grLfbLock(%d,%d,%d,%d,%d)\r\n", type, buffer, writeMode, origin, pixelPipeline);
+    WriteLog(M64MSG_VERBOSE, "grLfbLock(%d,%d,%d,%d,%d)\r\n", type, buffer, writeMode, origin, pixelPipeline);
     if (type == GR_LFB_WRITE_ONLY)
     {
         display_warning("grLfbLock : write only");
 FX_ENTRY FxBool FX_CALL
 grLfbUnlock( GrLock_t type, GrBuffer_t buffer )
 {
-    LOG("grLfbUnlock(%d,%d)\r\n", type, buffer);
+    WriteLog(M64MSG_VERBOSE, "grLfbUnlock(%d,%d)\r\n", type, buffer);
     if (type == GR_LFB_WRITE_ONLY)
     {
         display_warning("grLfbUnlock : write only");
     unsigned int i,j;
     unsigned short *frameBuffer = (unsigned short*)dst_data;
     unsigned short *depthBuffer = (unsigned short*)dst_data;
-    LOG("grLfbReadRegion(%d,%d,%d,%d,%d,%d)\r\n", src_buffer, src_x, src_y, src_width, src_height, dst_stride);
+    WriteLog(M64MSG_VERBOSE, "grLfbReadRegion(%d,%d,%d,%d,%d,%d)\r\n", src_buffer, src_x, src_y, src_width, src_height, dst_stride);
 
     switch(src_buffer)
     {
     unsigned short *frameBuffer = (unsigned short*)src_data;
     int texture_number;
     unsigned int tex_width = 1, tex_height = 1;
-    LOG("grLfbWriteRegion(%d,%d,%d,%d,%d,%d,%d,%d)\r\n",dst_buffer, dst_x, dst_y, src_format, src_width, src_height, pixelPipeline, src_stride);
+    WriteLog(M64MSG_VERBOSE, "grLfbWriteRegion(%d,%d,%d,%d,%d,%d,%d,%d)\r\n",dst_buffer, dst_x, dst_y, src_format, src_width, src_height, pixelPipeline, src_stride);
 
   glPushAttrib(GL_ALL_ATTRIB_BITS);
   

src/wrapper/main.h

 #ifndef MAIN_H
 #define MAIN_H
 
+#include "../m64p.h"
+
 #ifdef WIN32
     #include <SDL_opengl.h>
     extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
 #else // LOGGING
 #define OPEN_LOG()
 #define CLOSE_LOG()
-#define LOG(...)
+//#define LOG(...)
 #endif // LOGGING
 
 #endif

src/wrapper/textures.cpp

 FX_ENTRY FxU32 FX_CALL 
 grTexMinAddress( GrChipID_t tmu )
 {
-    LOG("grTexMinAddress(%d)\r\n", tmu);
+    WriteLog(M64MSG_VERBOSE, "grTexMinAddress(%d)\r\n", tmu);
     return tmu*TMU_SIZE;
 }
 
 FX_ENTRY FxU32 FX_CALL 
 grTexMaxAddress( GrChipID_t tmu )
 {
-    LOG("grTexMaxAddress(%d)\r\n", tmu);
+    WriteLog(M64MSG_VERBOSE, "grTexMaxAddress(%d)\r\n", tmu);
     return tmu*TMU_SIZE + TMU_SIZE - 1;
 }
 
                                  GrTexInfo *info   )
 {
     int width, height;
-    LOG("grTextureMemRequired(%d)\r\n", evenOdd);
+    WriteLog(M64MSG_VERBOSE, "grTextureMemRequired(%d)\r\n", evenOdd);
     if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexTextureMemRequired : loading more than one LOD");
 
     if (info->aspectRatioLog2 < 0)
                      GrAspectRatio_t aspect, GrTextureFormat_t fmt)
 {
     int width, height;
-    LOG("grTexCalcMemRequired(%d, %d, %d, %d)\r\n", lodmin, lodmax, aspect, fmt);
+    WriteLog(M64MSG_VERBOSE, "grTexCalcMemRequired(%d, %d, %d, %d)\r\n", lodmin, lodmax, aspect, fmt);
     if (lodmax != lodmin) display_warning("grTexCalcMemRequired : loading more than one LOD");
 
     if (aspect < 0)
     int glformat = GL_RGBA8;
     int gltexfmt, glpixfmt, glpackfmt;
     gltexfmt = glpixfmt = glpackfmt = 0;
-    LOG("grTexDownloadMipMap(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
+    WriteLog(M64MSG_VERBOSE, "grTexDownloadMipMap(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
     if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexDownloadMipMap : loading more than one LOD");
 
     if (info->aspectRatioLog2 < 0)
              FxU32      evenOdd,
              GrTexInfo  *info )
 {
-    LOG("grTexSource(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
+    WriteLog(M64MSG_VERBOSE, "grTexSource(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
     //if ((startAddress+1) == pBufferAddress && render_to_texture) updateTexture();
     //if ((startAddress+1) == pBufferAddress) display_warning("texsource");
     
                    float detail_max
                    )
 {
-    LOG("grTexDetailControl(%d,%d,%d,%d)\r\n", tmu, lod_bias, detail_scale, detail_max);
+    WriteLog(M64MSG_VERBOSE, "grTexDetailControl(%d,%d,%d,%d)\r\n", tmu, lod_bias, detail_scale, detail_max);
     if (lod_bias != 31 && detail_scale != 7)
     {
         if (!lod_bias && !detail_scale && !detail_max) return;
 FX_ENTRY void FX_CALL 
 grTexLodBiasValue(GrChipID_t tmu, float bias )
 {
-    LOG("grTexLodBiasValue(%d,%f)\r\n", tmu, bias);
+    WriteLog(M64MSG_VERBOSE, "grTexLodBiasValue(%d,%f)\r\n", tmu, bias);
     /*if (bias != 0 && bias != 1.0f)
         display_warning("grTexLodBiasValue : %f", bias);*/
 }
                 GrTextureFilterMode_t magfilter_mode
                 )
 {
-    LOG("grTexFilterMode(%d,%d,%d)\r\n", tmu, minfilter_mode, magfilter_mode);
+    WriteLog(M64MSG_VERBOSE, "grTexFilterMode(%d,%d,%d)\r\n", tmu, minfilter_mode, magfilter_mode);
     if (tmu == GR_TMU1 || nbTextureUnits <= 2)
     {
         if (tmu == GR_TMU1 && nbTextureUnits <= 2) return;
                GrTextureClampMode_t t_clampmode
                )
 {
-    LOG("grTexClampMode(%d, %d, %d)\r\n", tmu, s_clampmode, t_clampmode);
+    WriteLog(M64MSG_VERBOSE, "grTexClampMode(%d, %d, %d)\r\n", tmu, s_clampmode, t_clampmode);
     if (tmu == GR_TMU1 || nbTextureUnits <= 2)
     {
         if (tmu == GR_TMU1 && nbTextureUnits <= 2) return;