Commits

Anonymous committed 7e126e1

THIS BREAKS EVERYTHING. Must find out why.

Comments (0)

Files changed (1)

 #include "FBtoScreen.h"
 #include "CRC.h"
 
-#warning SwapBlock32/64 DISABLED!
-//extern "C" void SwapBlock32 ();
-//extern "C" void SwapBlock64 ();
 
 #if defined(WIN32) || defined(NO_ASM)
   #define BYTESWAP1(s1) s1 = ((s1 & 0xff) << 24) | ((s1 & 0xff00) << 8) | ((s1 & 0xff0000) >> 8) | ((s1 & 0xff000000) >> 24);
   #define BYTESWAP2(s1,s2) s1 = ((s1 & 0xff) << 24) | ((s1 & 0xff00) << 8) | ((s1 & 0xff0000) >> 8) | ((s1 & 0xff000000) >> 24); \
   s2 = ((s2 & 0xff) << 24) | ((s2 & 0xff00) << 8) | ((s2 & 0xff0000) >> 8) | ((s2 & 0xff000000) >> 24);
-
 #else
   #define BYTESWAP1(s1) asm volatile (" bswap %0; " : "+r" (s1) : :);
   #define BYTESWAP2(s1,s2) asm volatile (" bswap %0; bswap %1; " : "+r" (s1), "+r" (s2) : :);
 #endif
 
-#warning NOT SUPPORTING SCREENSHOTS
+
+//extern "C" void SwapBlock32 ();
+//extern "C" void SwapBlock64 ();
+
 /*
 const int NumOfFormats = 3;
 SCREEN_SHOT_FORMAT ScreenShotFormats[NumOfFormats] = { {wxT("BMP"), wxT("bmp"), wxBITMAP_TYPE_BMP}, {wxT("PNG"), wxT("png"), wxBITMAP_TYPE_PNG}, {wxT("JPEG"), wxT("jpeg"), wxBITMAP_TYPE_JPEG} };
   {
     uc_crc += ((wxUint32*)microcode)[i];
   }
-  
+
   FRDP_E ("crc: %08lx\n", uc_crc);
 
 #ifdef LOG_UCODE
 
   FRDP("ucode = %08lx\n", uc_crc);
 
-//  #warning REPAIR INI HANDLING HERE!!
-
   char str[9];
   sprintf (str, "%08lx", (unsigned long)uc_crc);
-  
+
+
   INI_Open ();
   INI_FindSection ("UCODE");
   FRDP("ucode = %s\n", str);
   int uc = INI_ReadInt (str, -2, 0);
   WriteLog(M64MSG_INFO, "ucode = %d\n", uc);
+
   if (uc == -2 && ucode_error_report)
   {
     Config_Open();
     settings.ucode = Config_ReadInt ("ucode", "Force microcode", 0, FALSE, FALSE);
+
     ReleaseGfx ();
     WriteLog(M64MSG_ERROR, "Error: uCode crc not found in INI, using currently selected uCode\n\n%08lx", (unsigned long)uc_crc);
 
   }
 }
 
+/*
+class SoftLocker
+{
+public:
+  // lock the mutex in the ctor
+  SoftLocker(wxMutex* mutex)
+    : _isOk(false), _mutex(mutex)
+  { _isOk = ( _mutex->TryLock() == wxMUTEX_NO_ERROR ); }
+
+  // returns true if mutex was successfully locked in ctor
+  bool IsOk() const
+  { return _isOk; }
+
+  // unlock the mutex in dtor
+  ~SoftLocker()
+  { if ( IsOk() ) _mutex->Unlock(); }
+
+private:
+  bool     _isOk;
+  wxMutex* _mutex;
+};
+*/
+
 /******************************************************************
 Function: ProcessDList
 Purpose:  This function is called when there is a Dlist to be
 #endif
 
 
-// #warning ProcessDList is broken!
 EXPORT void CALL ProcessDList(void)
 {
-  LOG("CALL ProcessDList ()\n");
-  
+  {
+    if (!fullscreen)
+      drawNoFullscreenMessage();
+    // Set an interrupt to allow the game to continue
+    *gfx.MI_INTR_REG |= 0x20;
+    gfx.CheckInterrupts();
+    return;
+  }
+
   no_dlist = FALSE;
   update_screen_count = 0;
   ChangeSize ();
   wxUint32 dlist_start = *(wxUint32*)(gfx.DMEM+0xFF0);
   wxUint32 dlist_length = *(wxUint32*)(gfx.DMEM+0xFF4);
   FRDP("--- NEW DLIST --- crc: %08lx, ucode: %d, fbuf: %08lx, fbuf_width: %d, dlist start: %08lx, dlist_length: %d, x_scale: %f, y_scale: %f\n", uc_crc, settings.ucode, *gfx.VI_ORIGIN_REG, *gfx.VI_WIDTH_REG, dlist_start, dlist_length, (*gfx.VI_X_SCALE_REG & 0xFFF)/1024.0f, (*gfx.VI_Y_SCALE_REG & 0xFFF)/1024.0f);
-//  FRDP_E("--- NEW DLIST --- crc: %08lx, ucode: %d, fbuf: %08lx\n", uc_crc, settings.ucode, *gfx.VI_ORIGIN_REG);
+  FRDP_E("--- NEW DLIST --- crc: %08lx, ucode: %d, fbuf: %08lx\n", uc_crc, settings.ucode, *gfx.VI_ORIGIN_REG);
 
   if (cpu_fb_write == TRUE)
     DrawPartFrameBufferToScreen();
         rdp.pc[rdp.pc_i] = (a+8) & BMASK;
 
 #ifdef PERFORMANCE
-            QueryPerformanceCounter ((LARGE_INTEGER*)&perf_cur);
+        perf_cur = wxDateTime::UNow();
 #endif
         // Process this instruction
         gfx_instruction[settings.ucode][rdp.cmd0>>24] ();
         }
 
 #ifdef PERFORMANCE
-            QueryPerformanceCounter ((LARGE_INTEGER*)&perf_next);
-            __int64 t = perf_next-perf_cur;
-            sprintf (out_buf, "perf %08lx: %016I64d\n", a-8, t);
-            rdp_log << out_buf;
+        perf_next = wxDateTime::UNow();
+        sprintf (out_buf, "perf %08lx: %016I64d\n", a-8, (perf_next-perf_cur).Format(_T("%l")).mb_str());
+        rdp_log << out_buf;
 #endif
 
       } while (!rdp.halt);
       }
 #endif
     }
-        if (fullscreen) ReleaseGfx ();
-        WriteLog(M64MSG_ERROR, "The GFX plugin caused an exception and has been disabled.");
-        exception = TRUE;
+    WriteLog(M64MSG_ERROR, "The GFX plugin caused an exception and has been disabled.");
+    exception = TRUE;
+    return;
   }
 #endif
 
   LRDP("ProcessDList end\n");
 }
 
-#ifdef __cplusplus
-}
-#endif
-
-
 // undef - undefined instruction, always ignore
 static void undef()
 {
 #endif
 }
 
+#ifdef __cplusplus
+}
+#endif
+
+
 // spnoop - no operation, always ignore
 static void spnoop()
 {
     int rem = SrcOffs & 3;
     if (rem == 0)
     {
-        int *pSrc = (int *) ((wxUIntPtr) gfx.RDRAM + SrcOffs);
+        int *pSrc = (int *) ((uintptr_t) gfx.RDRAM + SrcOffs);
         for (unsigned int x = 0; x < cnt; x++)
         {
             int s1 = *pSrc++;
     else
     {
         // set source pointer to 4-byte aligned RDRAM location before the start
-        int *pSrc = (int *) ((wxUIntPtr) gfx.RDRAM + (SrcOffs & 0xfffffffc));
+        int *pSrc = (int *) ((uintptr_t) gfx.RDRAM + (SrcOffs & 0xfffffffc));
         // do the first partial 32-bit word
         int s0 = *pSrc++;
         BYTESWAP1(s0)
     }
 }
 
-
-#warning extern disabled, MAY NOT WORK!
-//extern "C" void asmLoadBlock(int src, int dst, int off, int dxt, int cnt, int swp);
-//void LoadBlock32b(wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 lr_s, wxUint32 dxt);
 static void rdp_loadblock()
 {
   if (rdp.skip_drawing)
 
   //angrylion's advice to use ul_s in texture image offset and cnt calculations.
   //Helps to fix Vigilante 8 jpeg backgrounds and logos
-  wxUint32 off = rdp.timg.addr + (ul_s << rdp.tiles[tile].size >> 1);
-//  wxUIntPtr dst = wxPtrToUInt(rdp.tmem)+(rdp.tiles[tile].t_mem<<3);
-
-  int * pDst = (int *) ((wxUIntPtr)rdp.tmem+(rdp.tiles[tile].t_mem<<3));
-
+  wxUint32 offs = rdp.timg.addr + (ul_s << rdp.tiles[tile].size >> 1);
+  wxUIntPtr dst = wxPtrToUInt(rdp.tmem)+(rdp.tiles[tile].t_mem<<3);
+  int * pDst = (int *) ((uintptr_t)rdp.tmem+(rdp.tiles[tile].t_mem<<3));
   wxUint32 cnt = lr_s-ul_s+1;
   if (rdp.tiles[tile].size == 3)
     cnt <<= 1;
 
-
-
-  #warning SwapMethod isn't used!
   // wxUIntPtr SwapMethod = wxPtrToUInt(reinterpret_cast<void*>(SwapBlock32));
 
   if (rdp.timg.size == 3)
     LoadBlock32b(tile, ul_s, ul_t, lr_s, dxt);
   else
   {
-    CopyswapBlock(pDst, cnt, off);
+    // Load the block from RDRAM and byteswap it as it loads
+    CopyswapBlock(pDst, cnt, offs);
 
     // now do 32-bit or 64-bit word swapping on every other row of data
-    wxInt32 dxt_accum = 0;
+    int dxt_accum = 0;
     while (cnt > 0)
     {
         // skip over unswapped blocks
-      do
-      {
-        pDst += 2;
-        if (--cnt == 0)
-          break;
-        dxt_accum += _dxt;
-      } while (!(dxt_accum & 0x80000000));
+        do
+        {
+            pDst += 2;
+            if (--cnt == 0)
+                break;
+            dxt_accum += _dxt;
+        } while (!(dxt_accum & 0x80000000));
         // count number of blocks to swap
-      if (cnt == 0) break;
-      int swapcnt = 0;
-      do
-      {
-        swapcnt++;
-        if (--cnt == 0)
-          break;
-        dxt_accum += _dxt;
-      } while (dxt_accum & 0x80000000);
+        if (cnt == 0) break;
+        int swapcnt = 0;
+        do
+        {
+            swapcnt++;
+            if (--cnt == 0)
+                break;
+            dxt_accum += _dxt;
+        } while (dxt_accum & 0x80000000);
         // do 32-bit or 64-bit swap operation on this block
-      WordswapBlock(pDst, swapcnt, rdp.tiles[tile].size);
-      pDst += swapcnt * 2;
+        WordswapBlock(pDst, swapcnt, rdp.tiles[tile].size);
+        pDst += swapcnt * 2;
     }
   }
-
-  //  asmLoadBlock(wxPtrToUInt(gfx.RDRAM), dst, off, _dxt, cnt, SwapMethod);
-
+  
   rdp.timg.addr += cnt << 3;
   rdp.tiles[tile].lr_t = ul_t + ((dxt*cnt)>>11);
 
     setTBufTex(rdp.tiles[tile].t_mem, cnt);
 }
 
-#warning extern asm func disabled!
-// extern "C" void asmLoadTile(int src, int dst, int width, int height, int line, int off, int end, int swap);
-//void LoadTile32b (wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 width, wxUint32 height);
+void LoadTile32b (wxUint32 tile, wxUint32 ul_s, wxUint32 ul_t, wxUint32 width, wxUint32 height);
 static void rdp_loadtile()
 {
   if (rdp.skip_drawing)
     if (height == 0)
       return;
 
-    #warning SwapMethod isn't used!
-    // wxUIntPtr SwapMethod = wxPtrToUInt(reinterpret_cast<void*>(SwapBlock32));
-
-    #warning Following code MAY NOT WORK AT ALL!
-    // wxUIntPtr dst = wxPtrToUInt(rdp.tmem) + (rdp.tiles[tile].t_mem<<3);
-    // wxUIntPtr end = wxPtrToUInt(rdp.tmem) + 4096 - (wid_64<<3);
-    
-    int * pDst = (int *) ((wxUIntPtr)rdp.tmem+(rdp.tiles[tile].t_mem<<3));
-    int * pEnd = (int *) ((wxUIntPtr)rdp.tmem+4096 - (wid_64<<3));
-
+    int * pDst = (int *) ((uintptr_t)rdp.tmem+(rdp.tiles[tile].t_mem<<3));
+    int * pEnd = (int *) ((uintptr_t)rdp.tmem+4096 - (wid_64<<3));
     for (unsigned int y = 0; y < height; y++)
     {
         if (pDst > pEnd) break;
         pDst += wid_64 * 2;
         offs += line_n;
     }
-    
-    
-    
-    //asmLoadTile(wxPtrToUInt(gfx.RDRAM), dst, wid_64, height, line_n, offs, end, SwapMethod);
   }
   FRDP("loadtile: tile: %d, ul_s: %d, ul_t: %d, lr_s: %d, lr_t: %d\n", tile,
     ul_s, ul_t, lr_s, lr_t);
   rdp.update |= UPDATE_COMBINE | UPDATE_ALPHA_COMPARE;
 }
 
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-
 /******************************************************************
 Function: FrameBufferRead
 Purpose:  This function is called to notify the dll that the
 output:   none
 *******************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 EXPORT void CALL FBRead(wxUint32 addr)
 {
-  LOG ("CALL FBRead ()\n");
+  LOG ("FBRead ()\n");
 
   if (cpu_fb_ignore)
     return;
   }
 }
 
+#if 0
 /******************************************************************
 Function: FrameBufferWriteList
 Purpose:  This function is called to notify the dll that the
 size = size of the plist, max = 1024
 output:   none
 *******************************************************************/
-/*EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, wxUint32 size)
+EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, wxUint32 size)
 {
   LOG ("FBWList ()\n");
   FRDP("FBWList. size: %d\n", size);
 }
-*/
+#endif
 
 /******************************************************************
 Function: FrameBufferWrite
 *******************************************************************/
 EXPORT void CALL FBWrite(wxUint32 addr, wxUint32 size)
 {
-  LOG ("CALL FBWrite ()\n");
+  LOG ("FBWrite ()\n");
   if (cpu_fb_ignore)
     return;
   if (cpu_fb_read_called)
   cpu_fb_write_called = TRUE;
   wxUint32 a = segoffset(addr);
   FRDP("FBWrite. addr: %08lx\n", a);
-  // ZIGGY : added a test on ci_width, otherwise we crash on zero division below
-  if (!rdp.ci_width || a < rdp.cimg || a > rdp.ci_end)
+  if (a < rdp.cimg || a > rdp.ci_end)
     return;
   cpu_fb_write = TRUE;
   wxUint32 shift_l = (a-rdp.cimg) >> 1;
 Plugin can return up to 6 frame buffer info
 ************************************************************************/
 ///*
-/*
-// already defined in API
+#if 0
 typedef struct
 {
   wxUint32 addr;
   wxUint32 width;
   wxUint32 height;
 } FrameBufferInfo;
-*/
+#endif
 EXPORT void CALL FBGetFrameBufferInfo(void *p)
 {
-  LOG ("CALL FBGetFrameBufferInfo ()\n");
+  LOG ("FBGetFrameBufferInfo ()\n");
   FrameBufferInfo * pinfo = (FrameBufferInfo *)p;
   memset(pinfo,0,sizeof(FrameBufferInfo)*6);
   if (!(settings.frame_buffer&fb_get_info))
   }
   //*/
 }
-//*/
+
 #ifdef __cplusplus
 }
 #endif
 
+
+//*/
 #include "ucodeFB.h"
+
 void DetectFrameBufferUsage ()
 {
   LRDP("DetectFrameBufferUsage\n");
     // Go to the next instruction
     rdp.pc[rdp.pc_i] = (a+8) & BMASK;
 
-    if ((uintptr_t)(reinterpret_cast<void*>(gfx_instruction_lite[settings.ucode][rdp.cmd0>>24])))
+    if (wxPtrToUInt(reinterpret_cast<void*>(gfx_instruction_lite[settings.ucode][rdp.cmd0>>24])))
       gfx_instruction_lite[settings.ucode][rdp.cmd0>>24] ();
 
     // check DL counter
   LRDP("DetectFrameBufferUsage End\n");
 }
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
 /*******************************************
  *          ProcessRDPList                 *
  *******************************************
   }
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 static void rdp_triangle(int shade, int texture, int zbuffer)
 {
   lle_triangle(rdp.cmd0, rdp.cmd1, shade, texture, zbuffer, rdp_cmd_data + rdp_cmd_cur);
   LRDP("rdphalf_cont - IGNORED\n");
 }
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
 /******************************************************************
 Function: ProcessRDPList
 Purpose:  This function is called when there is a Dlist to be
 input:    none
 output:   none
 *******************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 void CALL ProcessRDPList(void)
 {
-  LOG ("CALL ProcessRDPList ()\n");
-  LRDP("CALL ProcessRDPList ()\n");
+  LOG ("ProcessRDPList ()\n");
+  LRDP("ProcessRDPList ()\n");
 
   {
     if (!fullscreen)
   dp_start = dp_end;
 
   dp_status &= ~0x0002;
-
   //}
 }
 
 #ifdef __cplusplus
 }
 #endif
+