Author Topic: FBA libsnes implementation  (Read 13937 times)

Offline Themaister

  • Newbies
  • *
  • Posts: 10
  • Karma: +1/-0
FBA libsnes implementation
« on: January 26, 2012, 05:17:01 PM »
So, we're quite late on this, but hey. SVN made development very painful for us, sadly. :(

There are some standing issues:
- Pre-generated files. Atm, Squarepusher has a script that generates the generated cores. How is this handled by upstream? It should probably be generated on-the-fly in the Makefile.
- Currently, we're using the old archive.cpp and Fex to load archives. It still works, but as I understand it, there is some built-in mechanism now to do this? If so, how?

Our current implementation is here: https://github.com/twinaphex/fba-next-slim/tree/master/libsnes
- Makefile.libsnes
- libsnes/

It's some snapshot from a couple of weeks ago, but API shouldn't have changed. It didn't seem to have changed much when the port was rebased anyways.

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: FBA libsnes implementation
« Reply #1 on: January 27, 2012, 04:57:56 PM »
So, we're quite late on this, but hey. SVN made development very painful for us, sadly. :(

There are some standing issues:
- Pre-generated files. Atm, Squarepusher has a script that generates the generated cores. How is this handled by upstream? It should probably be generated on-the-fly in the Makefile.
- Currently, we're using the old archive.cpp and Fex to load archives. It still works, but as I understand it, there is some built-in mechanism now to do this? If so, how?

Our current implementation is here: https://github.com/twinaphex/fba-next-slim/tree/master/libsnes
- Makefile.libsnes
- libsnes/

It's some snapshot from a couple of weeks ago, but API shouldn't have changed. It didn't seem to have changed much when the port was rebased anyways.

Thanks - I've added the files to the repo.

Pre-generated files - the current targets generated files go in src/dep/generated. I imagine adding rules to makefile.libsnes for these would be preferable.

FB Alpha has always been able to load files from archives using zlib, and unzip.c from the minizip project, along with win32 specific code in burner/win32/bzip.cpp. If you want blarg's file extractor adding to the repo let me know and I'll find somewhere to add it. :)
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 Themaister

  • Newbies
  • *
  • Posts: 10
  • Karma: +1/-0
Re: FBA libsnes implementation
« Reply #2 on: January 28, 2012, 09:15:48 AM »
Alright. Both issues are now sorted out.
Dropped Fex and archive.cpp. zipfn.cpp worked fine.

Apparently there were lots of changes to source tree layout the last 3 weeks, so fixed that up against rev. 300.

Also added generate_files.sh script to libsnes/. Should just be run prior to build. Easier than working out complicated build rules.

Updated files are here, and again, libsnes/ and makefile.libsnes.
https://github.com/twinaphex/fba-next-slim/tree/master/src-0.2.97.21

There is one needed patch to be applied to burn/burn.cpp.
Code: [Select]
diff --git a/src-0.2.97.21/src/burn/burn.cpp b/src-0.2.97.21/src/burn/burn.cpp
index 6e519a1..e6bd674 100644
--- a/src-0.2.97.21/src/burn/burn.cpp
+++ b/src-0.2.97.21/src/burn/burn.cpp
@@ -173,15 +173,15 @@ extern "C" TCHAR* BurnDrvGetText(UINT32 i)
 
 #else
 
-       static INT8 szShortNameA[32];
-       static INT8 szDateA[32];
-       static INT8 szFullNameA[256];
-       static INT8 szCommentA[256];
-       static INT8 szManufacturerA[256];
-       static INT8 szSystemA[256];
-       static INT8 szParentA[32];
-       static INT8 szBoardROMA[32];
-       static INT8 szSampleNameA[32];
+       static char szShortNameA[32];
+       static char szDateA[32];
+       static char szFullNameA[256];
+       static char szCommentA[256];
+       static char szManufacturerA[256];
+       static char szSystemA[256];
+       static char szParentA[32];
+       static char szBoardROMA[32];
+       static char szSampleNameA[32];
 
 #endif
 
@@ -410,6 +410,7 @@ extern "C" char* BurnDrvGetTextA(UINT32 i)
        }
 }
 
+#ifndef __LIBSNES__
 void BurnLocalisationSetName(char *szName, TCHAR *szLongName)
 {
        for (UINT32 i = 0; i < nBurnDrvCount; i++) {
@@ -419,6 +420,7 @@ void BurnLocalisationSetName(char *szName, TCHAR *szLongName)
                }
        }
 }
+#endif
 
 // Get the zip names for the driver
 extern "C" INT32 BurnDrvGetZipName(char** pszName, UINT32 i)

BurnLocalisationSetName is wrong as it takes TCHAR* and assumes it's a wchar_t*, which breaks for non-unicode. It might have to be fixed up properly, but ifdeffing was the easiest way out, as it seems to only be used for Win32.
« Last Edit: January 28, 2012, 09:18:53 AM by Themaister »

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: FBA libsnes implementation
« Reply #3 on: January 28, 2012, 04:13:27 PM »
Alright. Both issues are now sorted out.
Dropped Fex and archive.cpp. zipfn.cpp worked fine.

Apparently there were lots of changes to source tree layout the last 3 weeks, so fixed that up against rev. 300.

Also added generate_files.sh script to libsnes/. Should just be run prior to build. Easier than working out complicated build rules.

Updated files are here, and again, libsnes/ and makefile.libsnes.
https://github.com/twinaphex/fba-next-slim/tree/master/src-0.2.97.21

There is one needed patch to be applied to burn/burn.cpp.
Code: [Select]
diff --git a/src-0.2.97.21/src/burn/burn.cpp b/src-0.2.97.21/src/burn/burn.cpp
index 6e519a1..e6bd674 100644
--- a/src-0.2.97.21/src/burn/burn.cpp
+++ b/src-0.2.97.21/src/burn/burn.cpp
@@ -173,15 +173,15 @@ extern "C" TCHAR* BurnDrvGetText(UINT32 i)
 
 #else
 
-       static INT8 szShortNameA[32];
-       static INT8 szDateA[32];
-       static INT8 szFullNameA[256];
-       static INT8 szCommentA[256];
-       static INT8 szManufacturerA[256];
-       static INT8 szSystemA[256];
-       static INT8 szParentA[32];
-       static INT8 szBoardROMA[32];
-       static INT8 szSampleNameA[32];
+       static char szShortNameA[32];
+       static char szDateA[32];
+       static char szFullNameA[256];
+       static char szCommentA[256];
+       static char szManufacturerA[256];
+       static char szSystemA[256];
+       static char szParentA[32];
+       static char szBoardROMA[32];
+       static char szSampleNameA[32];
 
 #endif
 
@@ -410,6 +410,7 @@ extern "C" char* BurnDrvGetTextA(UINT32 i)
        }
 }
 
+#ifndef __LIBSNES__
 void BurnLocalisationSetName(char *szName, TCHAR *szLongName)
 {
        for (UINT32 i = 0; i < nBurnDrvCount; i++) {
@@ -419,6 +420,7 @@ void BurnLocalisationSetName(char *szName, TCHAR *szLongName)
                }
        }
 }
+#endif
 
 // Get the zip names for the driver
 extern "C" INT32 BurnDrvGetZipName(char** pszName, UINT32 i)

BurnLocalisationSetName is wrong as it takes TCHAR* and assumes it's a wchar_t*, which breaks for non-unicode. It might have to be fixed up properly, but ifdeffing was the easiest way out, as it seems to only be used for Win32.

Thanks, all added to the repo.

I hid BurnLocalisationSetName  behind a _UNICODE define as it is effectively a Unicode only function, it's main use being to localise the game titles to other languages, particuarly Asian languages.
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 Twinaphex

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +8/-0
Re: FBA libsnes implementation
« Reply #4 on: April 01, 2012, 07:52:29 AM »
Some problems I stumbled across while making FBA libsnes for Xbox 360 -

MSVC only supports C89 - and 'inline' isn't supported. I have to compile certain files as C (such as ym2413.c). Unfortunately, they make certain assumptions - such as 'inline' being available which isn't the case for Xbox 360 at least (when compiling C code).

In ym2413.c

Code: [Select]
#define MAME_INLINE static inline

What I do instead is make a preprocessor define where I redefine MAME_INLINE, such as:

MAME_INLINE="_inline static".

To allow this to work, there needs to be an ifndef wrapped around that define.

So change in ym2413.c - this:

Code: [Select]
#define MAME_INLINE static inline

to:

Code: [Select]
#ifndef MAME_INLINE
#define MAME_INLINE static inline
#endif

There is a similar issue going on with the SH2 CPU core (cpu/sh2/sh2.cpp):

Code: [Select]
#define SH2_INLINE

I define SH2_INLINE as a preprocessor switch because compiling without inlining these functions gives me horrendous performance on PS3. So if we could include a guard against defining this as well, such as:

Code: [Select]
#ifndef SH2_INLINE
#define SH2_INLINE
#endif

There are similar issues in src/burn/state.h -

Code: [Select]
inline static void ScanVar(void* pv, INT32 nSize, char* szName)

Include something like this just after the #ifdef __cplusplus define:

Code: [Select]
#if !defined(__cplusplus) && defined(_XBOX)
#define C_INLINE _inline
#else
#define C_INLINE inline
#endif

and then use it like this in the rest of the header wherever inline is being used:

Code: [Select]
C_INLINE static void ScanVar(void* pv, INT32 nSize, char* szName)

That should take care of my issues.
« Last Edit: April 01, 2012, 07:58:37 AM by Twinaphex »

Offline Twinaphex

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +8/-0
Re: FBA libsnes implementation
« Reply #5 on: April 01, 2012, 08:26:01 AM »
If this could be appllied to SVN - it created plenty of lockup problems whenever I wanted to change between ROMs on FBA libsnes PS3/360 -

https://github.com/twinaphex/fba-libsnes/commit/73fc5f64bb2b53b2b419199f158453bc29dd62f5

If you guys prefer diff patches instead of just linking to my own fork then I'll try to do that instead - hopefully this will suffice though.

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: FBA libsnes implementation
« Reply #6 on: April 01, 2012, 08:29:37 AM »
If this could be appllied to SVN - it created plenty of lockup problems whenever I wanted to change between ROMs on FBA libsnes PS3/360 -

https://github.com/twinaphex/fba-libsnes/commit/73fc5f64bb2b53b2b419199f158453bc29dd62f5

If you guys prefer diff patches instead of just linking to my own fork then I'll try to do that instead - hopefully this will suffice though.
Small changes should be fine from a git, big ones will definitely need a diff. :)


Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: FBA libsnes implementation
« Reply #7 on: April 01, 2012, 11:36:37 AM »
There are similar issues in src/burn/state.h -

Code: [Select]
inline static void ScanVar(void* pv, INT32 nSize, char* szName)

Include something like this just after the #ifdef __cplusplus define:

Code: [Select]
#if !defined(__cplusplus) && defined(_XBOX)
#define C_INLINE _inline
#else
#define C_INLINE inline
#endif

and then use it like this in the rest of the header wherever inline is being used:

Code: [Select]
C_INLINE static void ScanVar(void* pv, INT32 nSize, char* szName)

That should take care of my issues.

I've applied all the other fixes, but I'll take a look at this one some more soon. :)
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 Twinaphex

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +8/-0
Re: FBA libsnes implementation
« Reply #8 on: April 01, 2012, 12:22:38 PM »
Yes, we're currently still struggling with EEPROM saving/loading. It seems to save the nv file now correctly -but savestates only work per emulator session. If I close FBA and then start FBA again and try to load the savefile, the savestate won't work even though the .nv file is there and has apparently been loaded.

Seems like there's some additional run-time dependent volatile information that is currently different between emulator sessions, though I struggle to see why this is.

Offline Twinaphex

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +8/-0
Re: FBA libsnes implementation
« Reply #9 on: April 01, 2012, 12:34:46 PM »
OK - I'll do a checkout of the current SVN trunk, apply all the changes needed to get the libsnes port up to the state where it will also work on Wii/PS3/360, and then give you a diff. Saves you having to go through a bunch of commits on git.

EDIT: OK, invited Treble Winner and iq_132 to a private fork - the changes I committed are r496 and r497.
« Last Edit: April 01, 2012, 01:26:58 PM by Twinaphex »

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: FBA libsnes implementation
« Reply #10 on: April 01, 2012, 03:02:14 PM »
OK - I'll do a checkout of the current SVN trunk, apply all the changes needed to get the libsnes port up to the state where it will also work on Wii/PS3/360, and then give you a diff. Saves you having to go through a bunch of commits on git.

EDIT: OK, invited Treble Winner and iq_132 to a private fork - the changes I committed are r496 and r497.

Ok, committed 496 and 497. I didn't commit the d_suprnova.cpp change as sek.h shouldn't be required in there. If you have a problem that requires sek.h please let me know what it is and I'll see if there is a better solution.
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 Twinaphex

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +8/-0
Re: FBA libsnes implementation
« Reply #11 on: April 01, 2012, 03:40:56 PM »
Ok, committed 496 and 497. I didn't commit the d_suprnova.cpp change as sek.h shouldn't be required in there. If you have a problem that requires sek.h please let me know what it is and I'll see if there is a better solution.

Yes, it complains to me that SM_ROM and SM_RAM have not been defined if I do not include sek.h in d_suprnova.cpp.

I looked at the recent commits - thanks. I'm still missing the .vcxproj and .vcxproj.filters file in the libsnes 360 solution directory though. Perhaps those could be added as well.
« Last Edit: April 01, 2012, 03:42:52 PM by Twinaphex »

Offline lantus

  • Expert
  • *****
  • Posts: 162
  • Karma: +32/-0
Re: FBA libsnes implementation
« Reply #12 on: April 01, 2012, 03:55:23 PM »
ive fixed this one. The thing is d_supernova.cpp isnt a part of FBA makefile so i havent commited it. I believe its an unfinished driver by iq_132

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: FBA libsnes implementation
« Reply #13 on: April 01, 2012, 04:10:15 PM »
Nope, I never committed mine. I don't remember who wrote the skeleton that's in the source.


Offline BisonSAS

  • Expert
  • *****
  • Posts: 210
  • Karma: +27/-0
  • [NGBRT]
    • NeoGeo BR Team
Re: FBA libsnes implementation
« Reply #14 on: April 01, 2012, 04:45:23 PM »
Nope, I never committed mine. I don't remember who wrote the skeleton that's in the source.
The skeleton is made by OopsWare