gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Problem (?) with new libnds

#80844 - techno - Tue Apr 25, 2006 8:56 pm

Just wondering if anyone else has seen any issues when linking with the new libnds (r18) with multiple files where weird things will happen?

The main thing I have noticed is print statements either not outputting the correct thing or it seeming to stop at the print statements (I'm talking with Dualis, haven't done too much troubleshooting with hardware yet.).

I have an example that I can duplicate the issue with (it involves some additional files). I'd upload everything, but I'm at work at the moment, but all that is needed is chishm's latest fat driver and the latest examples from libnds.

Take the original "examples\nds\graphics\2d\hello_world\" project from the latest libnds and make a copy of it naming it something else.. (You could probably create a new file from scratch, this way is just easier.) In the main.cpp, 'replace' the following..

Quote:
iprintf(" Hello DS dev'rs\n");
iprintf(" www.devkitpro.org\n");
iprintf(" www.drunkencoders.com\n\n");

int clusCount;
u32 position;
u32 curPos;
int curSect;
int curByte;
int filesysBytePerSec;
int filesysBytePerClus;

position = 0x4a095;
curPos = 0x0;
curSect = 0x0;

filesysBytePerSec = 0x200;
curByte = 0x0;
filesysBytePerClus = 0x2000;

clusCount = (position - curPos + (curSect * filesysBytePerSec) + curByte) / filesysBytePerClus; // Fixed thanks to AgentQ

iprintf("test: 0: %lx\n", (position - curPos + (curSect * filesysBytePerSec) + curByte));
iprintf("test: 1: %lx\n", filesysBytePerClus);
iprintf("test: 2: %lx\n", (position - curPos + (curSect * filesysBytePerSec) + curByte) / filesysBytePerClus);
iprintf("test: 3: %lx\n", 0x4a095/0x2000);

iprintf("test: 0: %d\n", (position - curPos + (curSect * filesysBytePerSec) + curByte));
iprintf("test: 1: %d\n", filesysBytePerClus);
iprintf("test: 2: %d\n", (position - curPos + (curSect * filesysBytePerSec) + curByte) / filesysBytePerClus);
iprintf("test: 3: %d\n", 0x4a095/0x2000);

while(1) {}

return 0;


The printf's at the top and "return 0;" at the bottom are from the original file to give you an idea of where this is pasted into the file (pretty much replacing the while loop from the original.)

Nothing will be done with fat library files yet, so don't compile them into the project yet.

You can them save/make/run the prog.. On my machine (Dualis) I got this as my output:

Quote:
test: 0: 4a095
test: 1: 2000
test: 2: 25
test: 3: 25
test: 0: 303253
test: 1: 8192
test: 2: 37
test: 3: 37


Which is what I expected.

Now you can do a make clean and then add the files from chishm fat library to the project.. (all the *.h files in the \include folder and all the *.c files into the \source folder). The main.cpp shouldn't reference the other files in anyway, which is fine. When make is run on the project, it should compile ok, basically just increasing the filesize of the final nds. Now when I run this program in Dualis I get this...

Quote:
test: 0: 4a095
test: 1: 2000
test: 2: 25
test: 3: 25


The outpus are right, there's just stuff missing.. In my original program (which is a big mess, but that's another problem) I have other issues where it will even output the wrong values in some cases..

If I compile this program (or my original) against the r17 libnds, everything is fine.

Any ideas? I'm a beginner at this and wasn't sture if I was really screwing something up. Thanx..

P.S. I know that the code that I'm using above is from chishm's fat library, but this was where I first noticed the problem (after about a week of troubleshooting what was going on.) =)

#80919 - techno - Wed Apr 26, 2006 3:16 am

Ok I tried it with hardware and it seems to work, so it looks more like some kind of weird Dualis issue (I hope it's not my programming, it's only like 10 lines of code.. I can't be that bad.. ).

After looking into it more it looks it is only affecting Dualis 19.1 and later only when using the r18 libnds.

Will try to post to Dualis board when I'm authorized to, if anyone cares. =)

#80924 - tepples - Wed Apr 26, 2006 3:27 am

techno wrote:
Ok I tried it with hardware and it seems to work, so it looks more like some kind of weird Dualis issue (I hope it's not my programming, it's only like 10 lines of code.. I can't be that bad.. ).

Wintermute's habit of breaking emulators with each new libnds release makes it harder for me to justify spending time on DS development if it involves bringing a CF card into the edit-build-test cycle.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#80937 - wintermute - Wed Apr 26, 2006 5:33 am

It's not deliberate, honest, it just seems to happen with alarming regularity.

no$gba's nds emulation is getting there, I can run most of the current 2d example code with 2.2c even with r19 which unfortunately seems to have broken both Dualis and iDeaS quite badly.

FWIW I tried this particular "problematic" code with no$gba and it emulates correctly.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#80940 - tepples - Wed Apr 26, 2006 6:26 am

How hard would it be to make test cases for each of the DS emulator bugs that you happen upon, similar to Blargg's NES test case library?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#80949 - josath - Wed Apr 26, 2006 7:35 am

also remember to try http://desmume.sf.net/ ... I've actually had it work better than dualis on some apps, even if it is a tad slower

#81002 - Chris Holmes - Wed Apr 26, 2006 6:57 pm

Tepples,
Have you considered making a seperate NDS library that is designed to run under linux/windows? The OpenGL calls can just call the native platform opengl calls, etc etc.

If you aren't doing anything terribly complex, that seems like an awfully easy way to go, and then you at least have the advantage of all the dev and debugging tools available for the platform.

Chris

#81016 - tepples - Wed Apr 26, 2006 7:47 pm

If I were to make an API compatibility layer, how would I have it handle writes to registers? Or would I have to convert all register accesses to use the getSomething() and setSomething() idiom seen in e.g. Java? And even then, wouldn't I have to pretty much put an entire DS emulator (except for the CPU) in order to handle input, 2D video, and audio? This could get complicated.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#81029 - Chris Holmes - Wed Apr 26, 2006 8:28 pm

In the end, yes, you would basically have the equivalent of an emulator, but only if you went that far. On the other hand, you would also be able to actually step through code in a debugger.

It's a big task, but if you want just an opengl compatibility layer, that would actually be very easy to do. Audio and the custom video modes would be more of a task, but there's really nothing that the DS/GBA can do that can't be pretty easily emulated in OpenGL (or the emulators would be much harder to write).

Chris

#81032 - tepples - Wed Apr 26, 2006 8:43 pm

Chris Holmes wrote:
there's really nothing that the DS/GBA can do that can't be pretty easily emulated in OpenGL

Mode 7 and other raster effects mean you'd have to have a quad per scanline per layer. This is why most of the PC based GBA emulators render to a texture in software and then blit that texture to the screen.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.