What's new

Little patch

ZeLurker

New member
First thanks for mupen64, it seems to be the only n64 emulator working in linux and being open sourced !

Now I am having some troubles with this annoying freezing bug described in the big topic below (sound still works but everything except the sound is frozen).

So I made a few tests and discovered 2 thiings :
there is a gcc bug somewhere when you try to compile the glNintendo.so-0.3.1 plugin (the source of 0.4.1 does not seem to be available). Anyway the bug shows for example on the title screen of zelda : red rotating N, no textures and "Nintendo" unreadable. It happens with gcc-3.2.3 and gcc-3.3.1. The only work around I found was to use -O0 instead of -O3. I didn't take the time to find where the bug exactly is in the plugin source (usually you can find a workaround in these cases).

And secondly I found a buffer overflow in dma.c. It happens for example when you try to load "mortal kombat trilogy", it says the rom seems to be some kind of hack, you click yes to continue, and you get tons of segfaults after the title screen. Also this same bug makes the letters quite unreadable in zelda when you first enter your name.
It's around line 150 in memory/dma.c :
int offset = ((pi_register.pi_cart_addr_reg-0x10000000)&(taille_rom-1));
longueur = (pi_register.pi_wr_len_reg & 0xFFFFFF)+1;
i = (pi_register.pi_cart_addr_reg-0x10000000)&(taille_rom-1);
longueur = (i + longueur) > taille_rom ?
(taille_rom - i) : longueur;
longueur = (pi_register.pi_dram_addr_reg + longueur) > 0x7FFFFF ?
(0x7FFFFF - pi_register.pi_dram_addr_reg) : longueur;
for (i=0; i < longueur; i++)
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8]=
rom[(offset+i)^S8];

The bigest problem was with the line i = ....
It was anded with something much bigger than rdram, and the correction on longueur below was just not enough after this.

I still have this very annoying freezing bug, I don't have a clue about what's happening for now. You can save when it happens apparently, but it's useless because the cpu emulation seems dead.

Hope this dma thing helps, and thanks again for the emulator !
 
Last edited:

Hacktarux

Emulator Developer
Moderator
You were partially right... there's a problem here, but you can't use (taille_rom-1).. Roms that aren't power of 2 long wouldn't work with this... But i'll try to fix this. On a side not, mortal kombat trilogy perfectly works when you use a good dump...

For your information the freezing bug is caused by the sound plugin... if the buffer is too small, sound is bad, if it's too big, the game is running too fast while the buffer is filled.
What i would like to have is a sound plugin that is able to sync automatically the game with the sound but i'm having some difficulties to do that.
 

blight

New member
there is a gcc bug somewhere when you try to compile the glNintendo.so-0.3.1 plugin (the source of 0.4.1 does not seem to be available). Anyway the bug shows for example on the title screen of zelda : red rotating N, no textures and "Nintendo" unreadable. It happens with gcc-3.2.3 and gcc-3.3.1. The only work around I found was to use -O0 instead of -O3. I didn't take the time to find where the bug exactly is in the plugin source (usually you can find a workaround in these cases).
it's an "inofficial" source release - -O3 somehow breaks the plugin, i have noted that in the README (which i didn't pack into the source archive i guess ;))
but you can use -finline-functions, -funroll-loops and -fomit-frame-pointer ;)
or maybe try -O1?
 
OP
Z

ZeLurker

New member
Hacktarux said:
You were partially right... there's a problem here, but you can't use (taille_rom-1).. Roms that aren't power of 2 long wouldn't work with this... But i'll try to fix this. On a side not, mortal kombat trilogy perfectly works when you use a good dump...

I was almost sure the fix was not perfect, I just wanted to point at the problem so that people who knew the source better than me could find a better fix.
By the way, having the variable offset outside the loop is better than making the calculation for every step of the loop, but it's a detail.

Thanks for the info about the dump, I'll try to update it.

For your information the freezing bug is caused by the sound plugin... if the buffer is too small, sound is bad, if it's too big, the game is running too fast while the buffer is filled.
What i would like to have is a sound plugin that is able to sync automatically the game with the sound but i'm having some difficulties to do that.

Ok, since the source of the sound plugin seems quite short, it should not be too hard to do. The problem is that I will not have much time for that this week.
Maybe next week-end if nobody has done it before that !

Thanks for thie info !
 
OP
Z

ZeLurker

New member
blight said:
it's an "inofficial" source release - -O3 somehow breaks the plugin, i have noted that in the README (which i didn't pack into the source archive i guess ;))
but you can use -finline-functions, -funroll-loops and -fomit-frame-pointer ;)
or maybe try -O1?

After some quick tests, the gcc bug is with convert.c. Since it's a file full of asm anyway, the optimizations options should not be too important here. You can compile the whole plugin with all optimizations everywhere else, and keep -O0 for convert.o (tested, it works). Still a little slow though, but much better quality than the rice plugin for zelda...
 

Hacktarux

Emulator Developer
Moderator
ZeLurker said:
After some quick tests, the gcc bug is with convert.c. Since it's a file full of asm anyway, the optimizations options should not be too important here. You can compile the whole plugin with all optimizations everywhere else, and keep -O0 for convert.o (tested, it works). Still a little slow though, but much better quality than the rice plugin for zelda...

Do u have tried to declare asm blocks volatile ?
ex:
asm volatile("mov.... .... ");
 
OP
Z

ZeLurker

New member
Hacktarux said:
Do u have tried to declare asm blocks volatile ?
ex:
asm volatile("mov.... .... ");

Yeah good point, it works !
The fix was pretty easy here. So just replace __asm__( by __asm__ volatile( in convert.c and everything works.

By the way this plugin seems quite slower than the 0.4.1 beta version.

Is there a source of documentation somewhere about the n64 emulation ? I mean how this 3d chipset works, how you understand what there is in a rom and so on, or did you have to guess everything (quite crazy !) ?
 

blight

New member
there are 2 main processing chips in the N64 afaik, the CPU - a R4300 processor and the RCP (Reality Co-Processor) - a modified R4300 specifically for the N64 with vector instructions - the ucode is software running on the RCP/RDP (RDP = Reality Display Processor and RSP = Reality Sound or Signal Processor i think)
you have to understand it to write a plugin
 

Shin_Gouki

New member
wow the PJ64 RSP Interpreter Plugin source code, looks impressive O_O
at school we have now PC Soundcard DSP basics, maybe in a couple of weeks i´m able to understand more than just the c syntax ;)
wbr Shin Gouki
 

Doomulation

?????????????????????????
rofl
Then it's going to take at least a year before you start understanding anything out of that source code :p
I might as well say I don't understand anything, either :rolleyes:
 

Top