• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Dolphin Site › Dolphin Patches (Archive) v
1 2 3 4 5 ... 7 Next »

General fault: using swap*() where big endian transforming is wanted
View New Posts | View Today's Posts

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
General fault: using swap*() where big endian transforming is wanted
02-05-2014, 03:13 AM
#1
Wiimm
Unregistered
 
I working to integrate WDF support. As template I use WbfsBlob.*. In the code review I found, that the swap functions swap16() and swap32() are used. But this works only on little endian systems. I know, that Dolphin will run only an little endian system until now, so it's only a cosmetic bug. However, it is wrong and using for example ntohl() or be32toh() is the correct solution.

And then I have looked into other source files and saw, that this mistake is done many times.

Here is a patch for WbfsBlob.cpp:
Code:
diff --git a/Source/Core/DiscIO/WbfsBlob.cpp b/Source/Core/DiscIO/WbfsBlob.cpp
index 7a4d8d9..568dc7a 100644
--- a/Source/Core/DiscIO/WbfsBlob.cpp
+++ b/Source/Core/DiscIO/WbfsBlob.cpp
@@ -5,6 +5,12 @@
#include "WbfsBlob.h"
#include "FileUtil.h"

+#ifdef _MSC_VER
+  #include <Winsock2.h>
+#else
+  #include <arpa/inet.h>
+#endif
+
namespace DiscIO
{
const u64 wii_sector_size = 0x8000;
@@ -78,7 +84,7 @@ bool WbfsFileReader::ReadHeader()

        // Read hd size info
        m_files[0]->file.ReadBytes(&hd_sector_count, 4);
-       hd_sector_count = Common::swap32(hd_sector_count);
+       hd_sector_count = ntohl(hd_sector_count);

        m_files[0]->file.ReadBytes(&hd_sector_shift, 1);
        hd_sector_size = 1ull << hd_sector_shift;
@@ -139,7 +145,7 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
        u64 base_cluster = offset >> wbfs_sector_shift;
        if(base_cluster < m_blocks_per_disc)
        {
-               u64 cluster_address = wbfs_sector_size * Common::swap16(m_wlba_table[base_cluster]);
+               u64 cluster_address = wbfs_sector_size * ntohs(m_wlba_table[base_cluster]);
                u64 cluster_offset = offset & (wbfs_sector_size - 1);
                u64 final_address = cluster_address + cluster_offset;
02-05-2014, 03:39 AM
#2
ExtremeDude2 Offline
Gotta post fast
*******
Posts: 9,306
Threads: 273
Joined: Dec 2010
I guess you should have posted here:

https://forums.dolphin-emu.org/Forum-code-patches
Check out my videos (dead)
[Image: sig-22354.png]
Website Find
02-05-2014, 08:31 AM
#3
mbc07 Offline
Wiki Caretaker
*******
Content Creators (Moderators)
Posts: 3,563
Threads: 47
Joined: Dec 2010
Moved to code patches.
Avell A70 MOB: Core i7-11800H, GeForce RTX 3060, 16 GB DDR4-3200, Windows 11 (Insider Preview)
ASRock Z97M OC Formula: Pentium G3258, GeForce GT 440, 16 GB DDR3-1600, Windows 10 (22H2)
Find
02-05-2014, 08:50 AM
#4
neobrain Offline
"Wow, I made my code 1000x faster! That means I can make it 2048x slower now!"
**********
Developers (Some Administrators and Super Moderators)
Posts: 3,208
Threads: 50
Joined: Jun 2009
Please create a fork of our project on github, apply your patch and create a pull request for it.

https://github.com/dolphin-emu/dolphin
My blog
Me on Twitter
My wishlist on Amazon.de
Find
02-05-2014, 09:34 AM
#5
delroth Offline
Making the world a better place through reverse engineered DSP firmwares
**********
Developers (Some Administrators and Super Moderators)
Posts: 1,354
Threads: 63
Joined: Aug 2011
Tbh I don't think it's worth it. Dolphin is so dependent on running on a little endian system that fixing it in one place is 1. useless; 2. borderline inconsistent.
Pierre "delroth" Bourdon - @delroth_ - Blog

<@neobrain> that looks sophisticated enough to not be a totally dumb thing to do
Website Find
02-05-2014, 11:02 PM
#6
lamedude Offline
Senior Member
****
Posts: 360
Threads: 7
Joined: Jan 2011
Wink 
Think of the PS360 and 68K Amiga/Mac ports!
Website Find
« Next Oldest | Next Newest »


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 1 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode