Mmuhack For Homebrew


JyCet

Member
Joined
Feb 23, 2004
Messages
469
Age
118
Location
France
Website
Visit site
Ok I'm starting another thread about the famous Squidge's mmuhack module :D

Normaly if it's good for emulators it should be good for homebrew ? But why no homebrew use it ?

I'm using HW paeryn SDL lib with lot of HW surface in all my gp2x program, I'm successfuly loaded mmuhack module (i think) ... but after that what can I do ? I havent seen atm any speed up but I suppose I've missed something to take all advantage of magic mmuhack :p

Here the code (it's directly a copy/past in mmuhack module readme)
CODE

...
...
...

int mmuhack(void)
{
int mmufd;
system("/sbin/rmmod mmuhack");
system("/sbin/insmod mmuhack.o");
mmufd = open("/dev/mmuhack", 2);
if(mmufd < 0) return 0;

close(mmufd);
return 1;
}

int mmuunhack(void)
{
system("/sbin/rmmod mmuhack");
return 1;
}

...
...
...

int main(int argc,char **argv){

int ret;
ret = mmuhack();
if (!ret){
printf("mmuhack failed!\n");
}else printf("mmuhack OK!\n");

...
...
...
SDL_Quit();

mmuunhack();

chdir("/usr/gp2x");
execl("gp2xmenu", "gp2xmenu", NULL);
return 0;
}



Did all sdl hw surface takes automatically advantage of mmuhack ?

I hope this thread help me and all gp2x homebrew coder ;)
The mmuhack module used is here:
http://www.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,46,1690

Thanks for any help B)
 
Ok, i've applied Optimus recommandation

QUOTE
optimus:

Just a notice for testers: The improvement only showed up if I called the function mmuhack after all the SDL inits in my code. And it even fucked up an OGG player I was using if the player was initialized before the mmuhack. But now, in the write order everything works fine and the GP2X power is mine!!! Ahh,. finally :p


So i've moved mmuhack(); call after SDL init and now I can see the difference!
the FPS boost from 7FPS to 20FPS with one alpha picture upper no alpha picture !!!
Really impressive :D

Now I need to add flush_uppermem_cache(screen_surface->pixels, screen_surface->pixels + 320*240, 0); somewhere to correct lines artifacts.

First problem, i've added #include "flush_uppermem_cache.h" and changed my makefile:
CODE
PROG_NAME = drill2x

OBJS = drill.o CBmps.o Cffont.o CTime.o CInput.o frame_skip.o drill_audio.o flush_uppermem_cache.o
CROSS_COMPILE = C:/devkitPro/devkitGP2X/bin/arm-linux-
SDL_BASE = C:/devkitPro/devkitGP2X/bin/arm-linux-
LDFLAGS = -static

CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AS = $(CROSS_COMPILE)as
STRIP = $(CROSS_COMPILE)strip
CLEANUP = rm -f $(ALL_TARGETS) *.o *~

CFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -funroll-loops
CXXFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror -funroll-loops

LIBS = `$(SDL_BASE)sdl-config --libs` -lmikmod

TARGET = $(PROG_NAME).gpe
SDLTEST_OBJS = $(OBJS)

all : $(TARGET)

$(TARGET) : $(SDLTEST_OBJS)
$(CXX) $(LDFLAGS) -o $(TARGET) $(SDLTEST_OBJS) $(LIBS)
$(STRIP) $(TARGET)
$(CLEANUP)



but i've an unknow error for my little brain:
CODE
...
c:\devkitpro\devkitgp2x\bin\..\lib\gcc\arm-linux\4.0.2\..\..\..\..\arm-linux\bin\ld.exe: ERROR: flush_uppermem_cache.o uses hardware FP, whereas drill2x.gpe uses software FP
c:\devkitpro\devkitgp2x\bin\..\lib\gcc\arm-linux\4.0.2\..\..\..\..\arm-linux\bin\ld.exe: failed to merge target specific data of file flush_uppermem_cache.o
make: *** [drill2x.gpe] Error 1
>Exit code: 2


I suppose something is wrong in my makefile but i really dont know what and where :(
 
I am using mmuhack on a game I am working on, its only to get a FPS increase on the menus as I was also alpha blending a large sprite as a menu background. The increase was significant, it was ~20 FPS before and then around double that after if I remember right, and it only involves a few minutes work adding the code.

Regarding the error, delete the flush_uppermem_cache.o file and run make again, it should compile. Your makefile is using hardware floating point and the flush_uppermem_cache.o is built using software floating point, deleting it should fix it. If not PM me your email address and ill send you mine.
 
I've compiled Notaz example and overwrite my flush_uppermem_cache.o by the notaz example result, and the compilation finish correctly.

So my conclusion is I need some specifique flags for AS part of my makefile!

and finally flush_uppermem_cache(screen_surface->pixels, screen_surface->pixels + 320*240, 0); resolve lot of lines artifacts for me ;)

I'm searching solution in my makefile
:ph34r:
 
JyCet said:
So my conclusion is I need some specifique flags for AS part of my makefile!
True. You can add this
CODE

ASFLAGS = -mfloat-abi=soft


or you can add a rule which forces compiling .s files with gcc (which itself will pass the file to as with correct flags):
CODE

.s.o:
$(CC) -c -o $@ $^


or you can rename flush_uppermem_cache.s to flush_uppermem_cache.S and make should use gcc for compiling.
 
Last edited by a moderator:
notaz said:
True. You can add this
CODE

ASFLAGS = -mfloat-abi=soft


Notaz you're my master :D
I've tested your first solution and it work perfectly !

here the finale makefile:
CODE
PROG_NAME = drill2x

OBJS = drill.o CBmps.o Cffont.o CTime.o CInput.o frame_skip.o drill_audio.o flush_uppermem_cache.o
CROSS_COMPILE = C:/devkitPro/devkitGP2X/bin/arm-linux-
SDL_BASE = C:/devkitPro/devkitGP2X/bin/arm-linux-
LDFLAGS = -static

CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AS = $(CROSS_COMPILE)as
STRIP = $(CROSS_COMPILE)strip
CLEANUP = rm -f $(ALL_TARGETS) *.o *~

CFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -funroll-loops
CXXFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror -funroll-loops
ASFLAGS = -mfloat-abi=soft

LIBS = `$(SDL_BASE)sdl-config --libs` -lmikmod

TARGET = $(PROG_NAME).gpe
SDLTEST_OBJS = $(OBJS)

all : $(TARGET)

$(TARGET) : $(SDLTEST_OBJS)
$(CXX) $(LDFLAGS) -o $(TARGET) $(SDLTEST_OBJS) $(LIBS)
$(STRIP) $(TARGET)
$(CLEANUP)



I hope this quick thread will help some other coders because squidgehack boost the speed NOT ONLY for emulator :D
 
Last edited by a moderator:
May I ask why you delete all object code after a successful build? That causes you to rebuild everything every time, rather than just the changed files...
 
Squidge said:
May I ask why you delete all object code after a successful build? That causes you to rebuild everything every time, rather than just the changed files...
Maybe he doesn't want to run into trouble after changing some header files. The are no header dependencies in the Makefile.
 
Last edited by a moderator:
Good point. I usually make a mental note of that or some very crude (=non recursive) dep checker. If something doesn't work right, the first thing I do is a full rebuild. Saves a lot of time when just playing with a certain piece of code trying to optimise/tweak or whatever.
 
The full compilation of my program doesnt take more than 10s ;)

For me the next chalenge is use mikmod lib with the 940 core
 
PokeParadox said:
ok I have a simple question about this... how do I use the .s file in the MMUhack pack?

Is it possible to inline the code into a function? (I'm just guessing it's assembly...)
add flush_uppermem_cache.o in your makefile
add #include "flush_uppermem_cache.h" in your code
use flush_uppermem_cache(screen_surface->pixels, screen_surface->pixels + 320*240, 0); before your video flip
and dont forget to put mmuhack.o near your gpe
:)
 
Last edited by a moderator:
That didn't really answer how to use the .s ...
BUT I do appreciate the response! And also I hung around the dev channel for a while and StarG managed to point out that you compile flush_uppermem_cache.s .

Sooo... for those that use Code::Blocks:
just add the flush_uppermem_cache.s file into your project file list. right-click it and check the boxes "compile" and "link"

job done.
 
PokeParadox said:
That didn't really answer how to use the .s ...
BUT I do appreciate the response! And also I hung around the dev channel for a while and StarG managed to point out that you compile flush_uppermem_cache.s .

Sooo... for those that use Code::Blocks:
just add the flush_uppermem_cache.s file into your project file list. right-click it and check the boxes "compile" and "link"

job done.
I cant answer really to your question because there's no really complexity, if you want to fix the artifact you need to use flush_uppermem_cache(screen_surface->pixels, screen_surface->pixels + 320*240, 0); and for that you just need to add flush_uppermem_cache.s in your program.
After that it depend of which compilator you use ... ;)
The upper code and makefile is one possibilty and example which work for me with devkitgp2x under windows os.
Sorry if I havent help you ;)
 
Last edited by a moderator:
Yeah it's ok, I was just saying that I didn't know how to use the .s file because I've never had to use .s files before.
But now I know I can just add them to a project and compile them the problem is sorted, so thanks anyway! :)
 
Back
Top