Author Topic: FBA SDL fixes  (Read 7221 times)

Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
FBA SDL fixes
« on: March 15, 2015, 06:11:52 AM »
Hello.


Btw, I'm supporting a port of FBA for GCW-Zero/Dingoo a320: https://github.com/dmitrysmagin/fba-sdl

FBA SDL build is broken long ago, so here are the fixes: https://www.sendspace.com/file/w63h4v
Unpack the archive over fba_src_029735 contents and type 'make -f makefile sdl'

Changes:
- makefile.sdl is fixed to work with win/linux
- sound is fixed (no more stuttering)
- wrong colors for OpenGL mode are fixed
- ATTENTION: Reverted back autofire, since it's not working right with FBASDL.

Besides, do you use any versioning system to control sources?

Regards,
Dmitry

Online dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: FBA SDL fixes
« Reply #1 on: March 15, 2015, 12:15:30 PM »
Hi,
Nice job on the fixes, my idea is to integrate your fixes into our codebase, but my only concern is the shared sources such as intf/interface.h, intf/input/inp_interface.*, instead of cutting out the stuff for qt, and win32 autofire, how about put #ifndef "SOME_SDL_DEFINE" around the code unused by your project, this way we retain compatibility and features with the other targets.  Also, with burner/image & state.cpp win32 defines changed from BUILD_WIN32 to WIN32 and _WIN32 - we should keep things standardized, perhaps?

best regards.
- dink


Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
Re: FBA SDL fixes
« Reply #2 on: March 15, 2015, 12:52:48 PM »
Hello,
you are right concerning autofire, I'll post changes later with #ifdef'ed portions for SDL. Also, makefile.sdl is improved as well.

As for WIN32 and _WIN32 in state.cpp and image.cpp, it would be better to use #ifdef BUILD_WIN32 for more consistency. Reason: SDL build could be built both on windows and linux and those portions of code refer to windows exclusively.

Besides, it would be better to use #include <SDL/SDL.h> everywhere to avoid path problems on all platforms. (BTW Qt build has its own SDL.h which simply includes real SDL/SDL.h)

regards,
Dmitry

PS: I'd recommend using git for code versioning, this makes submitting patches and tracking changes much easier. Right now FBA code has both unix and windows style end of strings, trailing spaces and tab/spaces mixture.

Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
Re: FBA SDL fixes
« Reply #3 on: March 15, 2015, 02:00:35 PM »
Ok, here's attached a new fix. Unpack over FBA 0.2.97.35 sources

- makefile.sdl is fully linux-friendly
- Input with autofire is unified with FBA 0.2.97.35
   it works on linux at least, i'll check with mingw/windows tomorrow

Some small fixes for non-sdl files:
Code: [Select]
burner/image.cpp:
-#ifdef WIN3
+#ifdef BUILD_WIN32

burner/state.cpp:
-#ifdef _WIN32
+#ifdef BUILD_WIN32

intf/video/scalers/superscale.asm:
  GLOBAL _superscale_line
  GLOBAL _superscale_line_75
+ GLOBAL superscale_line
+ GLOBAL superscale_line_75
...
 _superscale_line:
+superscale_line:
...
 _superscale_line_75:    ;do a 75% reduction on the final pixel colour
+superscale_line_75:    ;do a 75% reduction on the final pixel colour

intf/video/vid_softfx.h:
- #include <SDL.h>
+ #include <SDL/SDL.h>

And I'd recommend this fix as well (vital for mingw):
burn/burnint.h:
 #include <assert.h>
+#include <stdint.h>

Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
Re: FBA SDL fixes
« Reply #4 on: March 16, 2015, 11:06:15 AM »
Fixed keys autorepeat for SDL on all platforms.
The fix is rather trivial:
Code: [Select]
diff --git a/src/intf/input/sdl/inp_sdl.cpp b/src/intf/input/sdl/inp_sdl.cpp
index c65040c..de49c87 100644
--- a/src/intf/input/sdl/inp_sdl.cpp
+++ b/src/intf/input/sdl/inp_sdl.cpp
@@ -24,7 +24,8 @@ static int SDLinpJoystickInit(int i)
 static int SDLinpKeyboardInit()
 {
  for (int i = 0; i < 512; i++) {
- FBKtoSDL[SDLtoFBK[i]] = i;
+ if (SDLtoFBK[i] > 0)
+ FBKtoSDL[SDLtoFBK[i]] = i;
  }
 
  return 0;

Updated archive attached.

Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
Re: FBA SDL fixes
« Reply #5 on: March 17, 2015, 11:12:15 AM »
Again new fix:

- Fixed games with vertical and flipped screens for OpenGL (crashed previously or being shown upside-down)
- Fix formatting in intf/video/sdl/vid_sdlopengl.cpp

The patch is trivial again (OpenGL does all the proper rotations and such):
Code: [Select]
diff --git a/src/intf/video/sdl/vid_sdlopengl.cpp b/src/intf/video/sdl/vid_sdlopengl.cpp
index 82ea7a9..dcf54a7 100644
--- a/src/intf/video/sdl/vid_sdlopengl.cpp
+++ b/src/intf/video/sdl/vid_sdlopengl.cpp
@@ -29,6 +29,7 @@ static int nSize;
 static int nUseBlitter;
 
 static int nRotateGame = 0;
+static bool bFlipped = false;
 
 static int PrimClear()
 {
@@ -145,7 +146,7 @@ void init_gl()
  glRotatef(0.0, 0.0, 0.0, 1.0);
  glOrtho(0, nGamesWidth, nGamesHeight, 0, -1, 1);
  } else {
- glRotatef(90.0, 0.0, 0.0, 1.0);
+ glRotatef((bFlipped ? -90.0 : 90.0), 0.0, 0.0, 1.0);
  glOrtho(0, nGamesHeight, nGamesWidth, 0, -1, 5);
  }
 
@@ -222,19 +223,14 @@ static int Init()
  BurnDrvGetVisibleSize(&nGamesWidth, &nGamesHeight);
 
  if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) {
- if (nVidRotationAdjust & 1) {
- int n = nGamesWidth;
- nGamesWidth = nGamesHeight;
- nGamesHeight = n;
- nRotateGame |= (nVidRotationAdjust & 2);
- } else {
- nRotateGame |= 1;
- }
+ printf("Vertical\n");
+ nRotateGame = 1;
  }
 
  if (BurnDrvGetFlags() & BDF_ORIENTATION_FLIPPED) {
- nRotateGame ^= 2;
- }
+ printf("Flipped\n");
+ bFlipped = true;
+ }
  }
 
  if (!nRotateGame) {
@@ -291,31 +287,24 @@ static int Frame(bool bRedraw) // bRedraw = 0
  return 0;
 }
 
-typedef unsigned char byte;
-
-void SurfToTex()
+static void SurfToTex()
 {
- unsigned char *Surf = (unsigned char *)gamescreen;
- int nPitch = nVidImagePitch;
-
- //printf("nvidImagePitch %d\n",nVidImagePitch);
-
- unsigned char *VidSurf = (unsigned char *)texture;
  int nVidPitch = nTextureWidth * nVidImageBPP;
 
- unsigned char *pd, *ps;
+ unsigned char *ps = (unsigned char *)gamescreen;
+ unsigned char *pd = (unsigned char *)texture;
 
- int nHeight = nGamesHeight;
- pd = VidSurf; ps = Surf;
- for (int y = 0; y < nHeight; y++, pd += nVidPitch, ps += nPitch) {
- memcpy(pd, ps, nPitch);
+ for (int y = nGamesHeight; y--;) {
+ memcpy(pd, ps, nVidImagePitch);
+ pd += nVidPitch;
+ ps += nVidImagePitch;
  }
 
- glTexImage2D(GL_TEXTURE_2D, 0,3, nTextureWidth, nTextureHeight, 0,
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, nTextureWidth, nTextureHeight, 0,
       GL_RGB, texture_type, texture);
 }
 
-void TexToQuad()
+static void TexToQuad()
 {
  glBegin(GL_QUADS);
  glTexCoord2f(0, 0);

kev

  • Guest
Re: FBA SDL fixes
« Reply #6 on: March 17, 2015, 02:37:54 PM »
Nice work. Been meaning to get to this for a while so glad someone has beaten me to it.

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: FBA SDL fixes
« Reply #7 on: March 17, 2015, 06:23:18 PM »
Thanks for the fixes. I have committed them.
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 Romhack

  • Expert
  • *****
  • Posts: 92
  • Karma: +49/-0
Re: FBA SDL fixes
« Reply #8 on: March 17, 2015, 07:50:06 PM »
Thanks for the fixes. I have committed them.
Hey Barry, what do you think about one make system to rule them all? (CMake).

Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
Re: FBA SDL fixes
« Reply #9 on: March 18, 2015, 11:19:40 AM »
Thanks for the fixes. I have committed them.
Thank you.

Sorry, but here's another vital fix:
- Fixed crashing on exit when using OpenGL
- Fixed column of black pixels at the edge of window

In fact it's a memory corruption bug which lead to unpredicted memory errors. It also showed a column of black pixels at the left or right of the window. With these fixes OpenGL renderer is now quite usable.

Code: [Select]
diff --git a/src/intf/video/sdl/vid_sdlopengl.cpp b/src/intf/video/sdl/vid_sdlopengl.cpp
index 09ea80e..91e5f12 100644
--- a/src/intf/video/sdl/vid_sdlopengl.cpp
+++ b/src/intf/video/sdl/vid_sdlopengl.cpp
@@ -89,7 +90,7 @@ static int BlitFXInit()
  gamescreen = (unsigned char *)malloc(nMemLen);
  if (gamescreen) {
  memset(gamescreen, 0, nMemLen);
- pVidImage = gamescreen + nVidImagePitch;
+ pVidImage = gamescreen;
  return 0;
  } else {
  pVidImage = NULL;

Please, update.

Regards,
Dmitry
« Last Edit: March 19, 2015, 08:13:59 AM by dmitry_smagin »

Offline dmitry_smagin

  • New Member
  • *
  • Posts: 9
  • Karma: +5/-0
Re: FBA SDL fixes
« Reply #10 on: March 20, 2015, 12:31:13 PM »
Hi again. :)
Here's another memory corruption fix for OpenGL renderer.

In fact, there was some confusion with width/height of video buffer with rotated games. This lead to rare memory corruptions. Now nVidImageWidth, nVidImageHeight and nVidImageDepth contain the buffer as Burn core renders it (normal or rotated) and OpenGL does rotation in hardware.

Also, I'd like to point that some games like sfiii2 or all neogeo titles don't respect nBurnPitch (nVidImagePitch) value and render everything as if nBurnPitch == nVidImageWidth. If they did, one single buffer for OpenGL texture could be used, not two as now.

Regards,
Dmitry

Online dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: FBA SDL fixes
« Reply #11 on: March 20, 2015, 12:40:56 PM »
Thanks Dmitry!