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 > DS File Browser? How would I go about making one?

#135507 - calcprogrammer1 - Tue Jul 24, 2007 1:24 am

I've been trying to find a good GnM compatible file browser for the DS. I know the DSOrganize browser is great, but A: it's incompatible with GnM, and B: it doesn't work with both slot-1 and slot-2 devices at the same time, a feature I really want (have file on GBAMP, copy it to the GnM, run it from there, and also copy files from GnM to GBAMP). I've made a test app that reads from both slots, and it successfully prints the contents of the GnM to the top screen and the contents of GBAMP to bottom.

I want to add a simple Windows Explorer like GUI, where you double click on folders to go in them, hit an up folder button to go up, and if you click a file, have the option to copy or delete it. I'm not looking for any sort of viewing or playback, just a manager/browser.

I'm using PAlib for this, as I can get sprites to work easily in PAlib.

The first thing I want to do is know where to start. My first idea was that I need an array to store the root contents in, and then draw the sprites based on that. But, that'd require an array of strings, so I ask, Is it possible to make an array of strings (or multi-character variables) that I could store directory names in?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135521 - calcprogrammer1 - Tue Jul 24, 2007 4:38 am

Ok, so I'm using an array of a file struct. I'll load the names of all the files into the array, and use the array to draw, I can also sort the array with all the directories at the top.

Problem is, I don't know how to do pixel positioned text in PAlib. The only thing I can find is tile position text. I've seen talk of a PA_16cText() function but it doesn't seem to work at all for me.

Hmm...

Code:

typedef struct{
     char name[256];
     struct stat st;
} file;

file filelist[200];
char currentdir[256];

//.....further along in the program...//

void getFileList(){
     DIR_ITER* dir = diropen(currentdir);
     char filename[256];
     struct stat st;
     int i = 0
     while(dirnext(dir, filename, &st) == 0){
          filelist[i].name = filename; // GIVES ERROR ON THIS LINE
          filelist[i].st = st;
          i++;
     }
}

//..........in the Main loop...........//

     fatInitDefault(); //initializes libfat
     currentdir = '/'; //GIVES ERROR ON THIS LINE TOO


As you can see, it gives me two errors. These are:

Code:
...main.cpp(42): error: ISO C++ forbids assignment of arrays

and

...main.cpp(55): error: incompatible types in assignment of 'char' to 'char [256]'


How would I go about fixing this? Why can't I assign anything to an array?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135525 - DragonMinded - Tue Jul 24, 2007 5:10 am

Off topic: what do you mean DSOrganize is not compatible with GnM? I have one right here and it loads fine, writes fine, and boots fine...
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#135526 - calcprogrammer1 - Tue Jul 24, 2007 5:13 am

I'm using the GBAX version, it works perfectly with the bootme.nds method, but it locks at "initializing plugins and settings" when booting from the GnM menu.

And with the GnM's incompatible loader, it can't run anything else from the browser, so the only thing you can use on that microSD is DSO...and although I have two microSD's, the GnM's microSD port seems to wear out easily, so I don't want to switch them out a lot.

Is there a new version or something? I love the app, I use it all the time on my GBAMP, and if there's one that works with the GnM I'd download instantly. Probably still wouldn't browse two slots though.

EDIT:
I got it booting other stuff with the new boot.bin thing. It still won't boot from the menu though, so it's still using bootme.nds, which is slower than other methods. You said you were delaying the next version until after GBAX, but will that version boot from the GnM without bootme.nds method?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135529 - Lynx - Tue Jul 24, 2007 6:00 am

DragonMinded wrote:
Off topic: what do you mean DSOrganize is not compatible with GnM? I have one right here and it loads fine, writes fine, and boots fine...


The only versions I have been able to get to boot fine on my GnM is the ones from http://hbnds.biohazardteam.org/

And the current one even boots homebrew fine, which I couldn't get chishm's boot.bin to work for me either. So, unless there have been updates since a few days ago, biohazardteam are the only ones working for me.
_________________
NDS Homebrew Roms & Reviews

#135532 - DragonMinded - Tue Jul 24, 2007 7:30 am

Calcprogrammer1 if you had read the blog, you would know. I have posted a boot.bin that I have personally verified with GnM to work, as well as fixed the bootme.nds problem. Please read up a little next time. ;)
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#135560 - calcprogrammer1 - Tue Jul 24, 2007 4:36 pm

I have the boot.bin, it now boots other .nds files properly, but DSO still won't load when I select it from the GnM menu, so I still need bootme.nds. Is there a download that fixes this?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135585 - spinal_cord - Tue Jul 24, 2007 9:05 pm

PALib text used a tiled background. I doubt you'd be able to pixel located text. You might have to make your own text renderer in a bitmap layer.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#135594 - calcprogrammer1 - Tue Jul 24, 2007 10:22 pm

I read up on 16c text, that seems to do what I want, just didn't have it set up correctly.

My main problem now are the compile errors.

If I want a string called currentdir, and I want it to hold the path, how do I set it to '/' if I am using a char[256]?

I haven't done much in terms of strings on DS or GBA...I've always just used the 'string' type available on PC's using #include <string>, but I guess the DS doesn't support strings.

My other problem is trying to assign stuff (again, character type) to an array of structs.

For some reason,

filelist[i].name = filename (where filename is what has been read, and filelist[i].name is part of an array of type 'file' which contains a char[256] called 'name' and a struct stat st.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135600 - kusma - Tue Jul 24, 2007 10:34 pm

calcprogrammer1 wrote:
If I want a string called currentdir, and I want it to hold the path, how do I set it to '/' if I am using a char[256]?

There's many solutions, but strncpy() springs to mind.

Quote:

I haven't done much in terms of strings on DS or GBA...I've always just used the 'string' type available on PC's using #include <string>, but I guess the DS doesn't support strings.

It does.

Quote:

My other problem is trying to assign stuff (again, character type) to an array of structs.

For some reason,

filelist[i].name = filename (where filename is what has been read, and filelist[i].name is part of an array of type 'file' which contains a char[256] called 'name' and a struct stat st.

see answer above. strncpy() should do the trick.

#135603 - calcprogrammer1 - Tue Jul 24, 2007 11:26 pm

How do you declare a string?

I did:

string myString = "";

Compile said something along the lines of "error: 'string' does not name a valid type" or something...

Is it str, string, strn?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135604 - chuckstudios - Tue Jul 24, 2007 11:28 pm

You want a char array or a char pointer for strings.

Example:

char myString[256];

or

char* myString = malloc(256);

#135605 - calcprogrammer1 - Tue Jul 24, 2007 11:31 pm

I have the char myString[256] but assigning stuff to it gives an error, does the strncopy() assign stuff properly to char values?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135615 - kusma - Wed Jul 25, 2007 12:04 am

calcprogrammer1 wrote:
How do you declare a string?

I did:

string myString = "";

Compile said something along the lines of "error: 'string' does not name a valid type" or something...

Is it str, string, strn?


For C++ strings (STL) you do it like this:
Code:
#include <string>
std::string mystring = "test123";


for C-strings, you do it like this:
Code:
const char *mystring = "test123";

#135623 - calcprogrammer1 - Wed Jul 25, 2007 12:38 am

I finally got it to work using strncpy(), now I read the array correctly and print the contents onto the screen.

The problem I have now, is I know how to test if the entry is a directory, but how can I test the difference between a file and nothing?

I'm using
[code]
if(filelist[ypos].st.st_mode & S_IFDIR){
//---do a bunch of stuff---//
}else{
//---do a bunch of other stuff---//
}

but then it does other stuff (draws file icon) even if there's no file.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135631 - calcprogrammer1 - Wed Jul 25, 2007 3:41 am

Ok finally got the base code down, reading the list of files into an array, and processing it on screen. Here's a screenshot from NDeSmuME v0.4.0 (I tried Dualis, iDeaS, and NDeSmuME but only NDeSmuME supported FAT emulation):

[Images not permitted - Click here to view it]

Now I gotta figure out how to scroll the list and select a file.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135636 - calcprogrammer1 - Wed Jul 25, 2007 4:40 am

Hmm...it has a major problem here...

Code:

while(1){
     if((Pad.Newpress.Up) && (position > 0)){
          position = position - 1;
          clearScreen(); //deletes sprites, clears text
          updateScreen(position); //draws sprites and text, starting with 'position' in the array, and draws 12 lines (16x16 sprites)
     }
     if((Pad.Newpress.Down) && (position < numfiles)){ //numfiles is total files in array
           position = position + 1;
           clearScreen();
           updateScreen(position);
      }
}


That's my main loop. The problem is, when I push up or down, it doesn't increment by 1, it increments by 5. It did this in Desmume, but I tried it on my DS too, and it did the same thing. What is going on!?! I put a piece of code to display the value of Position on the top screen, and it jumps to like 5, then 10, then 14 (number of files in dir), then it went down to 9, 4, etc...

position is an int type, as is numfiles
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135638 - JeffMan - Wed Jul 25, 2007 5:12 am

Try holding down the up and down buttons longer; does it scroll the entire ways up/down? If so, and maybe even if not, your button detection might be off. Are there any alternatives to .Newpress for your compiler? I would use scanKeys() at the start of the loop and then check with (keysDown() & KEY_UP) with devKitPro, but it could be different for you.

#135639 - calcprogrammer1 - Wed Jul 25, 2007 5:14 am

Fixed that, PA_WaitForVBL() in the end of the loop fixed that.

Now I'm trying to add a background GIF...but I'm getting....

A MESS! It loads (although a palette error I'll try to work out later) with a big black streak across the image...as seen in this screenshot:

[Images not permitted - Click here to view it]

This seems to happen on my DS too, not just emulator...does the same thing in iDeaS even when no text is drawn (iDeaS won't show files).

Edit again:

Woah, just omitting the "PA_Init16cBg(0,2);" line seems to fix it perfectly!

Ok, it's 1:23 AM, I'm tired, mind doesn't think, code gets errors...must...sleep! I'll continue tomorrow (when my mind ain't dead).
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135743 - calcprogrammer1 - Wed Jul 25, 2007 11:57 pm

How do you copy a file in C? I want to use binary mode so I can copy any kinds of files, but I can't find any good tutorials on copying, all the examples are either just reading or just writing, or copying a text file.

I so far have:

Code:
void copyFiles(char source[256], char dest[256]){
     FILE * sourcefile;
     FILE * destfile;
     sourcefile = fopen(source,"rb");
     destfile = fopen(dest,"wb");
     
     long lSize;
     fseek(sourcefile,0,SEEK_END);
     lSize = ftell(sourcefile);
     rewind(sourcefile);


Do I need any kind of buffer or can I just go from source to dest? If so, how do you set up a buffer, and how do you allow it to copy files larger than the buffer?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135745 - simonjhall - Thu Jul 26, 2007 12:06 am

I'd copy a file like this:
Code:
void teh_copy(char *source, char *dest)
{
   FILE *in = fopen(source, "rb");
   FILE *out = fopen(dest, "wb");

   unsigned char buffer[4096];

   unsigned int file_size;
   fseek(in, 0, SEEK_END);
   file_size = ftell(in);
   rewind(in);

   while (file_size)
   {
        unsigned int to_copy = file_size > 4096 ? 4096 : file_size;
        fread(buffer, to_copy, 1, in);
        fwrite(buffer, to_copy, 1, out);

        file_size -= to_copy;
   }

   fclose(in);
   fclose(out);
}
...ta-da! A completely untested piece of code.
Insert error checking where required.

Works by passing in the source filename and the dest filename to copy to. Opens the files, figures out the file size. Makes a 4k buffer, moves data from one file to another in multiples of 4k - or whatever's left in the file if the remaining data is less than 4k.
_________________
Big thanks to everyone who donated for Quake2

#135747 - calcprogrammer1 - Thu Jul 26, 2007 12:14 am

I wrote something...but it's probably not gonna work.

I'll add that after I crash my DS running the monstrosity I've thrown together. Then I'll add bug fixes :)

I was right! it did crash my DS :)

I'm working on the code you wrote now.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135750 - calcprogrammer1 - Thu Jul 26, 2007 12:28 am

Wow! your code worked without editing!

Thanks :)
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.