Anonymous avatar Anonymous committed b19076b

more forward porting for old api

Comments (0)

Files changed (2)

 //****************************************************************
 
 #include "Gfx #1.3.h"
-#include "m64p.h"
 
 #include "Ext_TxFilter.h"
 #include "Ini.h"
 EXPORT void CALL ChangeWindow (void)
 {
   VLOG ("CALL ChangeWindow()\n");
+  #ifdef OLDAPI
+    if (evoodoo)
+  {
+    char strWrapperFullScreenResolutionExt[] = "grWrapperFullScreenResolutionExt";
+    if (!ev_fullscreen)
+    {
+      to_fullscreen = TRUE;
+#ifdef __WINDOWS__
+      if (gfx.hStatusBar)
+        ShowWindow( gfx.hStatusBar, SW_HIDE );
+      ShowCursor( FALSE );
+#endif
+      GRWRAPPERFULLSCREENRESOLUTIONEXT grWrapperFullScreenResolutionExt =
+        (GRWRAPPERFULLSCREENRESOLUTIONEXT)grGetProcAddress(strWrapperFullScreenResolutionExt);
+      if (grWrapperFullScreenResolutionExt) {
+        wxUint32 _width, _height = 0;
+        settings.res_data_org = settings.res_data;
+        settings.res_data = grWrapperFullScreenResolutionExt(&_width, &_height);
+        settings.scr_res_x = settings.res_x = _width;
+        settings.scr_res_y = settings.res_y = _height;
+      }
+    }
+    else
+    {
+      ReleaseGfx ();
+      GRWRAPPERFULLSCREENRESOLUTIONEXT grWrapperFullScreenResolutionExt =
+        (GRWRAPPERFULLSCREENRESOLUTIONEXT)grGetProcAddress(strWrapperFullScreenResolutionExt);
+      if (grWrapperFullScreenResolutionExt != NULL)
+      {
+        settings.res_data = settings.res_data_org;
+        settings.scr_res_x = settings.res_x = resolutions[settings.res_data][0];
+        settings.scr_res_y = settings.res_y = resolutions[settings.res_data][1];
+      }
+      InitGfx (TRUE);
+#ifdef __WINDOWS__
+      ShowCursor( TRUE );
+      if (gfx.hStatusBar)
+        ShowWindow( gfx.hStatusBar, SW_SHOW );
+      SetWindowLong (gfx.hWnd, GWL_WNDPROC, (long)oldWndProc);
+#endif
+    }
+  }
+  else
+  {
+    // Go to fullscreen at next dlist
+    // This is for compatibility with 1964, which reloads the plugin
+    //  when switching to fullscreen
+    if (!fullscreen)
+    {
+      to_fullscreen = TRUE;
+#ifdef __WINDOWS__
+      if (gfx.hStatusBar)
+        ShowWindow( gfx.hStatusBar, SW_HIDE );
+      ShowCursor( FALSE );
+#endif
+    }
+    else
+    {
+      ReleaseGfx ();
+#ifdef __WINDOWS__
+      ShowCursor( TRUE );
+      if (gfx.hStatusBar)
+        ShowWindow( gfx.hStatusBar, SW_SHOW );
+      // SetWindowLong fixes the following Windows XP Banshee issues:
+      // 1964 crash error when loading another rom.
+      // All N64 emu's minimize, restore crashes.
+      SetWindowLong (gfx.hWnd, GWL_WNDPROC, (long)oldWndProc);
+#endif
+    }
+  }
+#endif
 }
 
 /******************************************************************
 {
   VLOG ("CALL CloseDLL ()\n");
 
+  // re-set the old window proc
+#ifdef WINPROC_OVERRIDE
+  SetWindowLong (gfx.hWnd, GWL_WNDPROC, (long)oldWndProc);
+#endif
+
 #ifdef ALTTAB_FIX
   if (hhkLowLevelKybd)
   {
         output ((float)(settings.res_x - 68), y, 0, out_buf, 0);
       }
       //hotkeys
-      // #warning Hotkeys disabled!
       if (CheckKeyPressed(G64_VK_BACK, 0x0001))
       {
         hotkey_info.hk_filtering = 100;
       }
     
     }
-
-//    #warning screen capture disabled!
-    /*if (capture_screen)
+    #ifdef OLDAPI
+    if (capture_screen)
     {
       //char path[256];
       // Make the directory if it doesn't exist
         capture_screen = 0;
       }
     }
-*/
+    #endif
 
     // Capture the screen if debug capture is set
     if (_debugger.capture)
 }
 #endif
 
+#ifdef OLDAPI
 
+static wxConfigBase * wxOpenIni()
+{
+  wxConfigBase * ini = wxConfigBase::Get(false);
+  if (!ini)
+  {
+    if (iniName.IsEmpty())
+      iniName = pluginPath + wxT("/Glide64.ini");
+    if (wxFileExists(iniName))
+    {
+      wxFileInputStream is(iniName);
+      wxFileConfig * fcfg = new wxFileConfig(is, wxConvISO8859_1);
+      wxConfigBase::Set(fcfg);
+      ini = fcfg;
+    }
+  }
+  if (!ini)
+    ERRLOG("Can not find ini file! Plugin will not run properly."), _T("File not found"), wxOK|wxICON_EXCLAMATION);
+  return ini;
+}
 
 
+void WriteSettings (bool saveEmulationSettings)
+{
+  wxConfigBase * ini = wxOpenIni();
+  if (!ini || !ini->HasGroup(_T("/SETTINGS")))
+    return;
+  ini->SetPath(_T("/SETTINGS"));
 
+  ini->Write(_T("card_id"), settings.card_id);
+  ini->Write(_T("lang_id"), settings.lang_id);
+  ini->Write(_T("resolution"), (int)settings.res_data);
+  ini->Write(_T("ssformat"), settings.ssformat);
+  ini->Write(_T("vsync"), settings.vsync);
+  ini->Write(_T("show_fps"), settings.show_fps);
+  ini->Write(_T("clock"), settings.clock);
+  ini->Write(_T("clock_24_hr"), settings.clock_24_hr);
+  ini->Write(_T("advanced_options"), settings.advanced_options);
+  ini->Write(_T("texenh_options"), settings.texenh_options);
 
+  ini->Write(_T("wrpResolution"), settings.wrpResolution);
+  ini->Write(_T("wrpVRAM"), settings.wrpVRAM);
+  ini->Write(_T("wrpFBO"), settings.wrpFBO);
+  ini->Write(_T("wrpAnisotropic"), settings.wrpAnisotropic);
 
+#ifndef _ENDUSER_RELEASE_
+  ini->Write(_T("autodetect_ucode"), settings.autodetect_ucode);
+  ini->Write(_T("ucode"), (int)settings.ucode);
+  ini->Write(_T("wireframe"), settings.wireframe);
+  ini->Write(_T("wfmode"), settings.wfmode);
+  ini->Write(_T("logging"), settings.logging);
+  ini->Write(_T("log_clear"), settings.log_clear);
+  ini->Write(_T("run_in_window"), settings.run_in_window);
+  ini->Write(_T("elogging"), settings.elogging);
+  ini->Write(_T("filter_cache"), settings.filter_cache);
+  ini->Write(_T("unk_as_red"), settings.unk_as_red);
+  ini->Write(_T("log_unk"), settings.log_unk);
+  ini->Write(_T("unk_clear"), settings.unk_clear);
+#endif //_ENDUSER_RELEASE_
 
+#ifdef TEXTURE_FILTER
+  ini->Write(_T("ghq_fltr"), settings.ghq_fltr);
+  ini->Write(_T("ghq_cmpr"), settings.ghq_cmpr);
+  ini->Write(_T("ghq_enht"), settings.ghq_enht);
+  ini->Write(_T("ghq_hirs"), settings.ghq_hirs);
+  ini->Write(_T("ghq_enht_cmpr"), settings.ghq_enht_cmpr);
+  ini->Write(_T("ghq_enht_tile"), settings.ghq_enht_tile);
+  ini->Write(_T("ghq_enht_f16bpp"), settings.ghq_enht_f16bpp);
+  ini->Write(_T("ghq_enht_gz"), settings.ghq_enht_gz);
+  ini->Write(_T("ghq_enht_nobg"), settings.ghq_enht_nobg);
+  ini->Write(_T("ghq_hirs_cmpr"), settings.ghq_hirs_cmpr);
+  ini->Write(_T("ghq_hirs_tile"), settings.ghq_hirs_tile);
+  ini->Write(_T("ghq_hirs_f16bpp"), settings.ghq_hirs_f16bpp);
+  ini->Write(_T("ghq_hirs_gz"), settings.ghq_hirs_gz);
+  ini->Write(_T("ghq_hirs_altcrc"), settings.ghq_hirs_altcrc);
+  ini->Write(_T("ghq_cache_save"), settings.ghq_cache_save);
+  ini->Write(_T("ghq_cache_size"), settings.ghq_cache_size);
+  ini->Write(_T("ghq_hirs_let_texartists_fly"), settings.ghq_hirs_let_texartists_fly);
+  ini->Write(_T("ghq_hirs_dump"), settings.ghq_hirs_dump);
+#endif
 
+  if (saveEmulationSettings)
+  {
+    if (romopen)
+    {
+      wxString S = _T("/");
+      ini->SetPath(S+rdp.RomName);
+    }
+    else
+      ini->SetPath(_T("/DEFAULT"));
+    ini->Write(_T("filtering"), settings.filtering);
+    ini->Write(_T("fog"), settings.fog);
+    ini->Write(_T("buff_clear"), settings.buff_clear);
+    ini->Write(_T("swapmode"), settings.swapmode);
+    ini->Write(_T("lodmode"), settings.lodmode);
+    ini->Write(_T("aspect"), settings.aspectmode);
 
+    ini->Write(_T("fb_read_always"), settings.frame_buffer&fb_ref ? 1 : 0l);
+    ini->Write(_T("fb_smart"), settings.frame_buffer & fb_emulation ? 1 : 0l);
+    //    ini->Write("motionblur", settings.frame_buffer & fb_motionblur ? 1 : 0);
+    ini->Write(_T("fb_hires"), settings.frame_buffer & fb_hwfbe ? 1 : 0l);
+    ini->Write(_T("fb_get_info"), settings.frame_buffer & fb_get_info ? 1 : 0l);
+    ini->Write(_T("fb_render"), settings.frame_buffer & fb_depth_render ? 1 : 0l);
+    ini->Write(_T("detect_cpu_write"), settings.frame_buffer & fb_cpu_write_hack ? 1 : 0l);
+    if (settings.frame_buffer & fb_read_back_to_screen)
+      ini->Write(_T("read_back_to_screen"), 1);
+    else if (settings.frame_buffer & fb_read_back_to_screen2)
+      ini->Write(_T("read_back_to_screen"), 2);
+    else
+      ini->Write(_T("read_back_to_screen"), 0l);
+  }
 
+  wxFileOutputStream os(iniName);
+  ((wxFileConfig*)ini)->Save(os);
+}
 
 
+//
+// DllMain - called when the DLL is loaded, use this to get the DLL's instance
+//
+wxMutex *mutexProcessDList = NULL;
 
+class wxDLLApp : public wxApp
+{
+public:
+  virtual bool OnInit();
+};
 
+IMPLEMENT_APP_NO_MAIN(wxDLLApp)
 
+bool wxDLLApp::OnInit()
+{
+  if (mutexProcessDList == NULL)
+    mutexProcessDList = new wxMutex(wxMUTEX_DEFAULT);
+  wxImage::AddHandler(new wxPNGHandler);
+  wxImage::AddHandler(new wxJPEGHandler);
+  PluginPath();
+  return true;
+}
 
+#ifndef __WINDOWS__
+int __attribute__ ((constructor)) DllLoad(void);
+int __attribute__ ((destructor)) DllUnload(void);
+#endif
 
+// Called when the library is loaded and before dlopen() returns
+int DllLoad(void)
+{
+    int argc = 0;
+    char **argv = NULL;
+    wxEntryStart(argc, argv);
+    if (wxTheApp)
+      return wxTheApp->CallOnInit() ? TRUE : FALSE;
+    return 0;
+}
 
+// Called when the library is unloaded and before dlclose() returns
+int DllUnload(void)
+{
+    if ( wxTheApp )
+      wxTheApp->OnExit();
+    wxEntryCleanup();
+    return TRUE;
+}
 
+#ifdef __WINDOWS__
+extern "C" int WINAPI DllMain (HINSTANCE hinstDLL,
+                     wxUint32 fdwReason,
+                     LPVOID lpReserved)
+{
+  sprintf (out_buf, "DllMain (%08lx - %d)\n", hinstDLL, fdwReason);
+  LOG (out_buf);
 
+  if (fdwReason == DLL_PROCESS_ATTACH)
+  {
+    wxSetInstance(hinstDLL);
+    return DllLoad();
+  }
+  else if (fdwReason == DLL_PROCESS_DETACH)
+  {
+    if (GFXWindow != NULL)
+      GFXWindow->SetHWND(NULL);
+    return DllUnload();
+  }
+  return TRUE;
+}
 
+void CALL ReadScreen(void **dest, int *width, int *height)
+{
+  *width = settings.res_x;
+  *height = settings.res_y;
+  wxUint8 * buff = (wxUint8*)malloc(settings.res_x * settings.res_y * 3);
+  wxUint8 * line = buff;
+  *dest = (void*)buff;
 
+  if (!fullscreen)
+  {
+    for (wxUint32 y=0; y<settings.res_y; y++)
+    {
+      for (wxUint32 x=0; x<settings.res_x; x++)
+      {
+        line[x*3] = 0x20;
+        line[x*3+1] = 0x7f;
+        line[x*3+2] = 0x40;
+      }
+    }
+    LOG ("ReadScreen. not in the fullscreen!\n");
+    return;
+  }
 
+  GrLfbInfo_t info;
+  info.size = sizeof(GrLfbInfo_t);
+  if (grLfbLock (GR_LFB_READ_ONLY,
+    GR_BUFFER_FRONTBUFFER,
+    GR_LFBWRITEMODE_565,
+    GR_ORIGIN_UPPER_LEFT,
+    FXFALSE,
+    &info))
+  {
+    wxUint32 offset_src=info.strideInBytes*(settings.scr_res_y-1);
+
+    // Copy the screen
+    wxUint8 r, g, b;
+    if (info.writeMode == GR_LFBWRITEMODE_8888)
+    {
+      wxUint32 col;
+      for (wxUint32 y=0; y<settings.res_y; y++)
+      {
+        wxUint32 *ptr = (wxUint32*)((wxUint8*)info.lfbPtr + offset_src);
+        for (wxUint32 x=0; x<settings.res_x; x++)
+        {
+          col = *(ptr++);
+          r = (wxUint8)((col >> 16) & 0xFF);
+          g = (wxUint8)((col >> 8) & 0xFF);
+          b = (wxUint8)(col & 0xFF);
+          line[x*3] = b;
+          line[x*3+1] = g;
+          line[x*3+2] = r;
+        }
+        line += settings.res_x * 3;
+        offset_src -= info.strideInBytes;
+      }
+    }
+    else
+    {
+      wxUint16 col;
+      for (wxUint32 y=0; y<settings.res_y; y++)
+      {
+        wxUint16 *ptr = (wxUint16*)((wxUint8*)info.lfbPtr + offset_src);
+        for (wxUint32 x=0; x<settings.res_x; x++)
+        {
+          col = *(ptr++);
+          r = (wxUint8)((float)(col >> 11) / 31.0f * 255.0f);
+          g = (wxUint8)((float)((col >> 5) & 0x3F) / 63.0f * 255.0f);
+          b = (wxUint8)((float)(col & 0x1F) / 31.0f * 255.0f);
+          line[x*3] = b;
+          line[x*3+1] = g;
+          line[x*3+2] = r;
+        }
+        line += settings.res_x * 3;
+        offset_src -= info.strideInBytes;
+      }
+    }
+    // Unlock the frontbuffer
+    grLfbUnlock (GR_LFB_READ_ONLY, GR_BUFFER_FRONTBUFFER);
+  }
+  VLOG ("ReadScreen. Success.\n");
+}
+
+
+#endif
+
+
+
+#endif
 #ifndef M64P_H
 #define M64P_H
 
+#ifndef OLDAPI
+
 #include "m64p_types.h"
 #include "m64p_plugin.h"
 #include "m64p_config.h"
 #include "m64p_vidext.h"
+#include "winlnxdefs.h"
 #include <stdio.h>
 
 void WriteLog(m64p_msg_level level, const char *msg, ...);
 extern ptr_VidExt_GL_SetAttribute       CoreVideo_GL_SetAttribute;
 extern ptr_VidExt_GL_SwapBuffers        CoreVideo_GL_SwapBuffers;
 
+#else
+
+#include <wx/wx.h>
+#include <wx/fileconf.h>
+#include <wx/wfstream.h>
+
+
 #endif
+
+#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.