Author Topic: Some 64-bit fixes  (Read 6608 times)

Offline Themaister

  • Newbies
  • *
  • Posts: 10
  • Karma: +1/-0
Some 64-bit fixes
« on: October 29, 2011, 01:36:40 PM »
Me and a codev are working on multiplatform port of FBA core.
Our repo can be found here:  https://github.com/twinaphex/fba-next-slim

Our current setup is mostly Linux 64-bit, and we've stumbled on some 64-bit issues.

Here are some fixes:

Code: [Select]
diff --git a/src-0.2.97.13/burn/drivers/toaplan/toa_bcu2.cpp b/src-0.2.97.13/burn/drivers/toaplan/toa_bcu2.cpp
index 9706f11..85f8cb1 100644
--- a/src-0.2.97.13/burn/drivers/toaplan/toa_bcu2.cpp
+++ b/src-0.2.97.13/burn/drivers/toaplan/toa_bcu2.cpp
@@ -358,7 +358,7 @@ int ToaInitBCU2()
 
        nFCU2MaxSprite = (nFCU2ROMSize - 1) >> 5;
 
-       nSize = 0x10 * 0x101 * sizeof(int);
+       nSize = 0x10 * 0x101 * sizeof(unsigned short*);
        pFCU2SpriteQueueData = (unsigned short**)malloc(nSize);
        memset(pFCU2SpriteQueueData, 0, nSize);
 
diff --git a/src-0.2.97.13/burn/drivers/toaplan/toa_gp9001.cpp b/src-0.2.97.13/burn/drivers/toaplan/toa_gp9001.cpp
index 9c4c87c..86dacfc 100644
--- a/src-0.2.97.13/burn/drivers/toaplan/toa_gp9001.cpp
+++ b/src-0.2.97.13/burn/drivers/toaplan/toa_gp9001.cpp
@@ -491,7 +491,7 @@ int ToaInitGP9001(int n)
                pTileQueueData[i] = (unsigned int*)malloc(nSize);
                memset(pTileQueueData[i], 0, nSize);
 
-               nSize = 0x10 * 0x101 * sizeof(int);
+               nSize = 0x10 * 0x101 * sizeof(unsigned char*);
                pSpriteQueueData[i] = (unsigned char**)malloc(nSize);
                memset(pSpriteQueueData[i], 0, nSize);
 

Code: [Select]
diff --git a/src-0.2.97.13/burn/sound/msm6295.cpp b/src-0.2.97.13/burn/sound/msm6295.cpp
index d632672..8feea9a 100644
--- a/src-0.2.97.13/burn/sound/msm6295.cpp
+++ b/src-0.2.97.13/burn/sound/msm6295.cpp
@@ -73,13 +73,13 @@ int MSM6295Scan(int nChip, int /*nAction*/)
        SCAN_VAR(nMSM6295Status[nChip]);
 
        for (int i = 0; i < 4; i++) {
-               MSM6295SampleInfo[nChip][i] -= (unsigned int)MSM6295ROM;
+               MSM6295SampleInfo[nChip][i] -= (uintptr_t)MSM6295ROM;
                SCAN_VAR(MSM6295SampleInfo[nChip][i]);
-               MSM6295SampleInfo[nChip][i] += (unsigned int)MSM6295ROM;
+               MSM6295SampleInfo[nChip][i] += (uintptr_t)MSM6295ROM;
 
-               MSM6295SampleData[nChip][i] -= (unsigned int)MSM6295ROM;
+               MSM6295SampleData[nChip][i] -= (uintptr_t)MSM6295ROM;
                SCAN_VAR(MSM6295SampleData[nChip][i]);
-               MSM6295SampleData[nChip][i] += (unsigned int)MSM6295ROM;
+               MSM6295SampleData[nChip][i] += (uintptr_t)MSM6295ROM;
        }
 
        return 0;

Code: [Select]
--- a/src-0.2.97.13/cpu/m6502/codes.h
+++ b/src-0.2.97.13/cpu/m6502/codes.h
@@ -234,6 +234,6 @@ default:
       printf
       (
         "[M6502 %lX] Unrecognized instruction: $%02X at PC=$%04X\n",
-        (unsigned long)(R->User),Op6502(R->PC.W-1),(word)(R->PC.W-1)
+        (unsigned)(size_t)(R->User),Op6502(R->PC.W-1),(word)(R->PC.W-1)
       );
   break;

Code: [Select]
diff --git a/src-0.2.97.13/cpu/arm7_intf.cpp b/src-0.2.97.13/cpu/arm7_intf.cpp
index c1fdd9a..16f39dd 100644
--- a/src-0.2.97.13/cpu/arm7_intf.cpp
+++ b/src-0.2.97.13/cpu/arm7_intf.cpp
@@ -31,7 +31,7 @@ static unsigned int Arm7IdleLoop = ~0;
 void Arm7Init( int num ) // only one cpu supported
 {
        for (int i = 0; i < 3; i++) {
-               membase[i] = (unsigned char**)malloc(PAGE_COUNT * sizeof(int));
+               membase[i] = (unsigned char**)malloc(PAGE_COUNT * sizeof(unsigned char*));
        }
 
        CpuCheatRegister(0x000a, num);

/cpu/sek.{cpp,h} (rather long and boring):
http://pastebin.com/ScRci3ib

SH2: Similar:
http://pastebin.com/c6DqNbpt

Hopefully these fixes can be reviewed.
« Last Edit: October 29, 2011, 02:24:35 PM by Themaister »

kev

  • Guest
Re: Some 64-bit fixes
« Reply #1 on: October 30, 2011, 08:11:15 AM »
I can confirm that these changes are working on 32 and 64-bit visual studio builds.

Offline Themaister

  • Newbies
  • *
  • Posts: 10
  • Karma: +1/-0
Re: Some 64-bit fixes
« Reply #2 on: October 30, 2011, 01:58:52 PM »
Additional fix for YM chips.
Using unsigned int make calculations in INTERPOLATE macros overflow, which happened to work on 32-bit, but foo[0xffffffff] != foo[-1] on 64-bit.

Code: [Select]
Program received signal SIGSEGV, Segmentation fault.
0x00007fffe957ff9c in YM2610UpdateResample (pSoundBuf=0x7fffeac5fea0,
    nSegmentEnd=534) at ../../burn/sound/burn_ym2610.cpp:135
135 nSample = INTERPOLATE4PS_16BIT((nFractionalPosition >> 4) & 0x0FFF,

Code: [Select]
diff --git a/src-0.2.97.13/burn/sound/burn_ym2610.cpp b/src-0.2.97.13/burn/sound/burn_ym2610.cpp
index 4a93ca7..6bd97da 100644
--- a/src-0.2.97.13/burn/sound/burn_ym2610.cpp
+++ b/src-0.2.97.13/burn/sound/burn_ym2610.cpp
@@ -17,7 +17,7 @@ static int nYM2610Position;
 static int nAY8910Position;
 
 static unsigned int nSampleSize;
-static unsigned int nFractionalPosition;
+static int nFractionalPosition;
 
 static int bYM2610AddSignal;
 static int bYM2610MixSound;

Code: [Select]
diff --git a/src-0.2.97.13/burn/sound/burn_ym2203.cpp b/src-0.2.97.13/burn/sound/burn_ym2203.cpp
index fe05824..f4aa6be 100644
--- a/src-0.2.97.13/burn/sound/burn_ym2203.cpp
+++ b/src-0.2.97.13/burn/sound/burn_ym2203.cpp
@@ -17,7 +17,7 @@ static int nYM2203Position;
 static int nAY8910Position;
 
 static unsigned int nSampleSize;
-static unsigned int nFractionalPosition;
+static int nFractionalPosition;
 
 static int nNumChips = 0;

Alternative is to subtract the indices with -1L to force int in the evaluation.
« Last Edit: October 30, 2011, 02:20:42 PM by Themaister »

kev

  • Guest
Re: Some 64-bit fixes
« Reply #3 on: October 30, 2011, 02:25:36 PM »
Cool. That fixes some weird sound problems in 64-bit builds I noticed in the one neogeo rom I have.

Offline Themaister

  • Newbies
  • *
  • Posts: 10
  • Karma: +1/-0
Re: Some 64-bit fixes
« Reply #4 on: October 30, 2011, 04:10:21 PM »
Fixed parodius. Long type is bad, _VERY_ bad, mmkay? :p
Got clue from here: http://mametesters.org/view.php?id=2802

http://pastebin.com/KwnQG6Jy

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: Some 64-bit fixes
« Reply #5 on: October 30, 2011, 04:20:42 PM »
I think it's time to go down the arduous road of changing the burn and cpu folders to use UINT8, UINT16 and UINT32 exclusively....
Account of Barry Harris; the traitor.
Send me an e-mail at barry@fbalpha.com letting me know how big of a piece of sh** I am.

kev

  • Guest
Re: Some 64-bit fixes
« Reply #6 on: October 31, 2011, 02:36:10 PM »
I agree. Set up some kind of online repo, it will be quicker/easier for all of us to do the work. Might even be able to get the fba-next big endian stuff in normal fba as well.

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: Some 64-bit fixes
« Reply #7 on: November 03, 2011, 04:49:50 PM »
FB Alpha now compiles with MinGW64 (both 32 and 64-bit), so I've shook these issues and a few others out.

Thanks for pointing them out.
Account of Barry Harris; the traitor.
Send me an e-mail at barry@fbalpha.com letting me know how big of a piece of sh** I am.

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: Some 64-bit fixes
« Reply #8 on: November 14, 2011, 05:14:18 PM »
Finally done them all. :)
Account of Barry Harris; the traitor.
Send me an e-mail at barry@fbalpha.com letting me know how big of a piece of sh** I am.