Author Topic: Porting help thread  (Read 4907 times)

eule (OP)

  • * Former Staff
  • Posts: 889
Porting help thread
« on: July 28, 2010, 12:53:33 am »
Thought such a thread could be useful...  :D Feel free to add your own problems.

I?m currently trying to port a demo called "Yellow Rose of Texas" by Fit/Bandwagon
http://pouet.net/prod.php?which=10562
I use this sourcecode, not the one included in the 4k download (which contains ASM and OpenGL from what i can see).

It compiles fine, but i only get a black screen and then back to (freezed) gmenu. Tried setting the precalc flag, and the demo does precalc, but then the same. Changed the videomode in the main function from 32 to 16 bit, then lowered the sound quality to 22050 hz in main.c, still the same...

Soo, i guess i?m missing something. Maybe one of the brighter heads around could take a look at the makefile?  ;D I suspect though it?s fine...
Code: [Select]
TOOLCHAINDIR := /dingux
BINPATH    := $(TOOLCHAINDIR)/bin
LIBPATH    := $(TOOLCHAINDIR)/lib

INCLUDES := -I${TOOLCHAINDIR}/mipsel-linux-uclibc/include/SDL

ARCH := mipsel-linux-uclibc-
CC := ${BINPATH}/$(ARCH)gcc
CFLAGS  := -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
LDFLAGS := -O2 -Wall $(shell $(BINPATH)/sdl-config --libs)
COPT = -O2 -ffast-math -DBLKSIZE=1024 -DXS=320 -DYS=240
#COPT += -DPRECALC
OBJ = syna.o main.o osa.o biisi.o ml.o

yellow_rose: $(OBJ)
$(CC) -o [email protected] $(OBJ) `sdl-config --libs` -lm


%.o: %.c
$(CC) $(COPT) -c $<
      
clean:
rm *.o yellow_rose *~


Tried with swap and mouse on btw too... Interesting is, when mouse is started, gmenu no longer freezes.  ???
Thanks for any help/tips! Maybe someone knows these symptoms...  :D
« Last Edit: July 28, 2010, 01:00:20 am by eule »

zear

  • * Moderator
  • Posts: 2381
Re: Porting help thread
« Reply #1 on: July 28, 2010, 12:04:29 pm »
Try to debug it with gdb or strace (Download strace here).
What is the resolution of the video mode it tries to run with? The program will segfault if it's different than 320x240.

eule (OP)

  • * Former Staff
  • Posts: 889
Re: Porting help thread
« Reply #2 on: July 28, 2010, 01:34:32 pm »
The videomode is defined in the main.c:
Code: [Select]
s=SDL_SetVideoMode(XS,YS,16,flags);
And in the makefile with this:
Code: [Select]
-DXS=320 -DYS=240Guess that?s right?
Thanks for that strace idea, it?s bundled with the windows toolchain by SiENcE i use, but i always get an error "error while creating process yellow_rose"... Only works on the target system?
Now i tried your strace on the Dingoo and it works fine, i get this at the end, guess this is where the program crashes:
Code: [Select]
open("/etc/fb.modes", O_RDONLY)         = -1 ENOENT (No such file or directory)
ioctl(6, 0x4b46, 0x7f9e0214)            = 0
ioctl(6, 0x4b46, 0x7f9e0214)            = 0
etc.pp.

Further upwards are more of these errors:
Code: [Select]
open("/dev/vc/2", O_RDWR)               = -1 ENOENT (No such file or directory)
open("/dev/tty2", O_RDWR)               = 6
open("/dev/tty", O_RDWR)                = -1 ENXIO (No such device or address)

Interesting is this one, why does it try to open a file in usr/lib?
Code: [Select]
open("/usr/lib/libgcc_s.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libgcc_s.so.1", O_RDONLY)    = 5

So it seems the compiler "forgot" to add something to the binary, or better i forgot to tell him. Will try to work it out...

Incase you or someone else want to take a look, i attached the file (- 50,000 times the last line). But you don?t have to, i?ll get it somehow. I hope.  ;D

Edit: After thinking and thinking, i guess the problem is that those files are not on the Dingoo. Will try copying all wanted files and then see if it helps. Could compiling statically help? I don?t get it to work somehow, i set the LDFLAG --static-libs but the compiled file is the same size...

Sorry for all those newbie questions...  :-*

edit2: oh well, i have to specify the lib directories...  ::)
edit3: OK, got it to compile statically (now 983kb instead of 118) but it still does not run... probably missed some libs, strace only gives two missing directories now. Advance!  :D

But now i am lost, strace has still these errors:
Code: [Select]
open("/etc/fb.modes", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
...
open("/dev/vc/2", O_RDWR|O_LARGEFILE)   = -1 ENOENT (No such file or directory)
open("/dev/tty2", O_RDWR|O_LARGEFILE)   = 6
open("/dev/tty", O_RDWR|O_LARGEFILE)    = -1 ENXIO (No such device or address)
Googling tty leads to serial port, wtf? vc means virtual console... So the demo looks for those devices, but can?t find them and crashes?
« Last Edit: July 28, 2010, 04:35:27 pm by eule »

joyrider

  • Posts: 220
    • Willems Soft
Re: Porting help thread
« Reply #3 on: July 28, 2010, 09:21:13 pm »
strace might give more info then needed (like *it* might not need them files just looking for them although i'm not sure about that), never used it myselve, i'm a printf kinda guy :x

Just put a few printf's in key spots in the code and see to where it goes then narrow the printf spots down rebuild and retry at the end you can pinpoint the exact line where it happens or even sooner by going over the code between 2 printf's, takes a bit more time then strace of gdb or whatever but i only use those if i'm really stuck...

also porting is not just about recompiling and changing a few settings / variables, there comes more to it so you'd probably need to understand what's going on .... But hey you learn more by making mistakes and finding the problem / correcting it (yourselve)

eule (OP)

  • * Former Staff
  • Posts: 889
Re: Porting help thread
« Reply #4 on: July 28, 2010, 10:43:12 pm »
Thanks for that suggestion! Will surely try it, need to read a bit/lot about printf first though...
However, i?m pretty sure the demo crashes at this point (i read errors leading to crashes are mostly at the end of the logfile):
Code: [Select]
open("/dev/vc/2", O_RDWR|O_LARGEFILE)   = -1 ENOENT (No such file or directory)
open("/dev/tty2", O_RDWR|O_LARGEFILE)   = 6
open("/dev/tty", O_RDWR|O_LARGEFILE)    = -1 ENXIO (No such device or address)
ioctl(6, 0x4b44, 0x7fe249c0)            = 0
ioctl(6, 0x4b46, 0x7fe249c4)            = 0
ioctl(6, 0x4b46, 0x7fe249c4)            = 0
The last lines are repeated 60,000 times. O.o Not good i guess...

Oh well, just noticed that in the logfile of the statically compiled binary, after 60,000 same lines the program suddenly does something again, but segfaults later, twice.  :D Well, back to debugging, hope i find the error(s). Reading about printf first...

But you?re right, i guess i learn the most by making mistakes and correcting them. And my goal is to understand the code aswell, so far most is quite a mistery.  ;D Read and compiled some of the lazyfoo tutorials e.g..

The reason i chose this demo was that it was ported to so many platforms, just like Planet Hively, thought it?d be such a breeze too, well, i was wrong!  ::)

edit: just read a bit, you mean, i should throw some printf?s with different text/numbers into the code and look which print and which not? Clever! ;D
« Last Edit: July 28, 2010, 10:54:11 pm by eule »

joyrider

  • Posts: 220
    • Willems Soft
Re: Porting help thread
« Reply #5 on: July 28, 2010, 11:23:09 pm »
edit: just read a bit, you mean, i should throw some printf?s with different text/numbers into the code and look which print and which not? Clever! ;D

Exactly, works in most cases, but takes time... wouldn't really work with threads though although still possible :)

zeitpunk

  • Guest
Re: Porting help thread
« Reply #6 on: August 22, 2010, 08:49:12 am »
Yellow Rose is an OpenGL demo ... I doubt that this will work on Dingux - at least my rootfs does not include the GL library.

eule (OP)

  • * Former Staff
  • Posts: 889
Re: Porting help thread
« Reply #7 on: August 22, 2010, 01:54:53 pm »
Yeah, but there?s a software rendering version: http://ftp.kameli.net/pub/fit/yellow_rose/yellow_rose_sw3d.src.tar.gz
It compiles just fine, but seems to choke on a missing etc/fb.modes, just like Viagra and some other things i tried.  :'(
Haven?t yet tried joyrider?s suggestion very much though, the one time i tried lead to segfault. Epic programming noob here, you know... But i?ll try harder.  :)
« Last Edit: August 22, 2010, 01:57:49 pm by eule »

zeitpunk

  • Guest
Re: Porting help thread
« Reply #8 on: August 22, 2010, 06:33:58 pm »
Ah, ok, I didn't realize that there is a software rendering version, too, thanks for the hint!

I can get that version basically running on my Dingux - just had to disable the SDL_FULLSCREEN|SDL_DOUBLEBUF in main.c, change SDL_SetVideoMode to use 16 bpp instead of 32 bpp and change the rendering functions in ml.c to use 16 bpp instead of 32 bpp, too (i.e. change the pix variable from unsigned int to unsigned short and adapt the places where it is used).

However, the demo is unviewable slow on Dingux - most likely because it heavily uses floating point calculations and that does not perform well on the Dingoo. I maybe get 1 frame per second, so I guess this demo can not be properly ported to Dingux :-(

By the way, same for Viagra, that demo needs a faster / better CPU, too.

eule (OP)

  • * Former Staff
  • Posts: 889
Re: Porting help thread
« Reply #9 on: August 22, 2010, 07:01:09 pm »
I see, interesting! I did basically the same except that part:
Quote
(i.e. change the pix variable from unsigned int to unsigned short and adapt the places where it is used)
and i did not take SDL_FULLSCREEN out, is that necessary?
You could set the flag -DPRECALC, here?s the COPT line from the makefile i used:
Code: [Select]
COPT = -O2 -ffast-math -DXS=320 -DYS=240 -DPRECALCMaybe that?d help?

zeitpunk

  • Guest
Re: Porting help thread
« Reply #10 on: August 23, 2010, 06:47:34 pm »
PRECALC seems to fix the broken sound, but the graphic effects still remain incredibly slow :-(

eule (OP)

  • * Former Staff
  • Posts: 889
Re: Porting help thread
« Reply #11 on: August 23, 2010, 06:57:58 pm »
Hmm, too bad...  :'(
Any chance you could send me your changed source so i can study the changes, that way your work would not be totally useless, but give a noob a good lesson?  :D

joyrider

  • Posts: 220
    • Willems Soft
Re: Porting help thread
« Reply #12 on: August 23, 2010, 07:47:04 pm »
change the floating point operations to fixed point :) that will help a lot but might give artifacts due to lower precission

zeitpunk

  • Guest
Re: Porting help thread
« Reply #13 on: August 23, 2010, 08:36:05 pm »
Any chance you could send me your changed source so i can study the changes, that way your work would not be totally useless, but give a noob a good lesson?  :D

Sure, here's my patch:

Code: [Select]
diff -ruN yellow_rose_sw3d/main.c yellow_rose-dingux/main.c
--- yellow_rose_sw3d/main.c 2003-08-21 08:46:50.000000000 +0200
+++ yellow_rose-dingux/main.c 2010-08-23 21:29:08.000000000 +0200
@@ -28,7 +28,7 @@
 
 int main(int argc,char *argv[])
 {
-    int orig,flags=SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_SWSURFACE,n,prev,off;
+    int orig,flags=SDL_SWSURFACE,n,prev,off;
     SDL_Event e;
     SDL_AudioSpec w;
     SDL_Surface *s;
@@ -40,7 +40,10 @@
     if(argv[0][strlen(argv[0])-1]=='w')
             flags-=SDL_FULLSCREEN;
 
-    SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER);
+    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) != 0) {
+ printf("SDL_Init failed!\n");
+ exit(-1);
+    }
 
     w.freq=44100;
     w.format=AUDIO_S16SYS;
@@ -74,7 +77,12 @@
     counter=0;
 #endif
 
-    s=SDL_SetVideoMode(XS,YS,32,flags);
+    s=SDL_SetVideoMode(XS,YS,16,flags);
+
+    if (!s) {
+ printf("SDL_SetVideoMode failed!\n");
+ exit(-2);
+    }
 
     SDL_WM_SetCaption("Yellow Rose of Texas",0);
     SDL_ShowCursor(0);
diff -ruN yellow_rose_sw3d/Makefile yellow_rose-dingux/Makefile
--- yellow_rose_sw3d/Makefile 2003-08-21 08:52:47.000000000 +0200
+++ yellow_rose-dingux/Makefile 2010-08-22 23:49:39.000000000 +0200
@@ -1,15 +1,15 @@
-CC = gcc
-COPT = -O2 -ffast-math -DBLKSIZE=1024 -Wall -DXS=320 -DYS=240
-#COPT += -DPRECALC
+CC = mipsel-linux-uclibc-gcc
+COPT = -O3 -ffast-math -DBLKSIZE=1024 -Wall -DXS=320 -DYS=240
+COPT += -DPRECALC
 OBJ = syna.o main.o osa.o biisi.o ml.o
 
 yellow_rose: $(OBJ)
- $(CC) -o [email protected] $(OBJ) `sdl-config --libs` -lm
- strip [email protected]
+ $(CC) -o [email protected] $(OBJ) -msoft-float `sdl-config --libs` -lm
+ # mipsel-linux-uclibc-strip [email protected]
 
 %.o: %.c
  $(CC) $(COPT) -c $<
       
 clean:
- rm *.o yellow_rose *~
+ $(RM) *.o yellow_rose *~
 
diff -ruN yellow_rose_sw3d/ml.c yellow_rose-dingux/ml.c
--- yellow_rose_sw3d/ml.c 2003-08-21 08:50:17.000000000 +0200
+++ yellow_rose-dingux/ml.c 2010-08-23 21:28:35.000000000 +0200
@@ -7,7 +7,8 @@
 #define ZCLIP -0.01
 
 static float m[4*4],r[4*4],zbuf[XS*YS];
-static unsigned *pix,klear=0,light=0,nelem=0,mode=0,lw=1;
+static unsigned short *pix;
+static unsigned klear=0,light=0,nelem=0,mode=0,lw=1;
 static float color[3]={0,0,0},normal[3]={0,0,0},
              pts[4*2048],col[3*2048],nor[4*2048],
              amb[3]={0,0,0};
@@ -60,11 +61,11 @@
     if(r<0) r=0; if(g<0) g=0; if(b<0) b=0;
     if(r>1) r=1; if(g>1) g=1; if(b>1) b=1;
 
-    klear=r*255.0;
-    klear<<=8;
-    klear+=g*255.0;
-    klear<<=8;
-    klear+=b*255.0;
+    klear=r*0x1f;
+    klear<<=6;
+    klear+=g*0x3f;
+    klear<<=5;
+    klear+=b*0x1f;
 }
 
 void mlClear(int flag)
@@ -133,11 +134,11 @@
 
         if(!light)
         {
-            pcol=col[n*3]*255.0;
-            pcol<<=8;
-            pcol+=col[n*3+1]*255.0;
-            pcol<<=8;
-            pcol+=col[n*3+2]*255.0;
+            pcol=col[n*3]*0x1f;
+            pcol<<=6;
+            pcol+=col[n*3+1]*0x3f;
+            pcol<<=5;
+            pcol+=col[n*3+2]*0x1f;
         }
         else
         {
@@ -163,11 +164,11 @@
             if(c[1]>1) c[1]=1;
             if(c[2]>1) c[2]=1;
 
-            pcol=c[0]*255.0;
-            pcol<<=8;
-            pcol+=c[1]*255.0;
-            pcol<<=8;
-            pcol+=c[2]*255.0;
+            pcol=c[0]*0x1f;
+            pcol<<=6;
+            pcol+=c[1]*0x3f;
+            pcol<<=5;
+            pcol+=c[2]*0x1f;
         }
 
         if(mode==GL_LINES)

eule (OP)

  • * Former Staff
  • Posts: 889
Re: Porting help thread
« Reply #14 on: August 23, 2010, 08:38:45 pm »
Awesome, i?ll dive in it.  ;D