Nitrofs

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
  
 
The previous solutions to appending filesystems to .nds files were kinda suxy.
 
The previous solutions to appending filesystems to .nds files were kinda suxy.
==How to use==
+
==How to use and examples==
==Examples==
+
You place all the stuff you want to have on the filesystem into a directory. For this example we have a directory named "MyNitroFS".
Firstly, you'll need this includes:
+
This directory, its subdirectories, and all contents are then converted into nitro filesystem format and appended onto your executable using ndstool's -d option. Like So:
 +
ndstool -c myhomebrew.nds -d MyNitroFS
 +
 
 +
Thats it, now all the stuffs in MyNitroFS dir is elegantly appended into one nice pretty file. No need to ask the end user to copy over alot of seperate files and clutter up their flashcard. :D
 +
 
 +
Okay from a coding standpoint.. Firstly, you'll need this includes:
 
<source lang="c">
 
<source lang="c">
 
#include <nds.h>
 
#include <nds.h>
Line 34: Line 39:
 
You may want to add some error checking and reporting in case the filename or filepath passed to nitroFSInit are incorrect, the card does not support DLDI, or are not using the correct build for emulators not supporting DLDI (which are most of em'). This can be done somewhat like this:
 
You may want to add some error checking and reporting in case the filename or filepath passed to nitroFSInit are incorrect, the card does not support DLDI, or are not using the correct build for emulators not supporting DLDI (which are most of em'). This can be done somewhat like this:
 
<source lang="c">
 
<source lang="c">
int fd;
+
int fd;
bool imfat; //indicate fat driver loaded properly
+
bool imfat; //indicate fat driver loaded properly
printf("initalizing fat\n");
+
printf("initalizing fat\n");
if(fatInitDefault()) {
+
if(fatInitDefault()) {
imfat=true;
+
imfat=true;
printf("Success...\n");
+
printf("Success...\n");
} else {
+
} else {
imfat=false;
+
imfat=false;
printf("Failed... (normal for some emulators. Dont worry, yet :p)\n");
+
printf("Failed... (normal for some emulators. Dont worry, yet :p)\n");
}
+
}
printf("initalizing nitrofs\n");
+
printf("initalizing nitrofs\n");
if(nitroFSInit("myndsfile.nds")) {
+
if(nitroFSInit("myndsfile.nds")) {
fd=open("nitro:/myreadonlynitrofsfile.txt",O_RDONLY);
+
fd=open("nitro:/myreadonlynitrofsfile.txt",O_RDONLY);
if(fd) {
+
if(fd) {
len=read(fd,sample,st.st_size);
+
len=read(fd,sample,st.st_size);
close(fd);
+
close(fd);
}
+
} else {
+
printf("read only file open failed\n");
+
 
}
 
}
 
} else {
 
} else {
printf("Failed...\n");
+
printf("read only file open failed\n");
if(imfat) { //error if fat was initialized...
+
printf("Cannot open %s please check filename and path are correct.\n",FILENAME);
+
} else { //error if fat/dldi failed
+
printf("FAT/DLDI error, please to ensure your card supports DLDI.\n\nIf using emulators  that do not support fat/dldi (such as no$gba) be sure you are using a nds.gba or .sc.nds build.\n");
+
}
+
 
}
 
}
 +
} else {
 +
printf("Failed...\n");
 +
if(imfat) { //error if fat was initialized...
 +
printf("Cannot open %s please check filename and path are correct.\n",FILENAME);
 +
} else { //error if fat/dldi failed
 +
printf("FAT/DLDI error, please to ensure your card supports DLDI.\n\nIf using emulators  that do not support fat/dldi (such as no$gba) be sure you are using a nds.gba or .sc.nds build.\n");
 +
}
 +
}
 
</source>
 
</source>
  
 
==Releases==
 
==Releases==
 +
The archive contains three source files:
 +
nitrofs.c - The nitro filesystem source.
 +
nitrofs.h - The nitro filesystem header. This should only be included into the file where you have your nitroFSInit() call.
 +
main.c    - A working example
 +
 +
 
[http://blea.ch/wiki/images/b/b6/Nitrotstprojectv0.1.tar.bz2 Nitrotstprojectv0.1.tar.bz2]
 
[http://blea.ch/wiki/images/b/b6/Nitrotstprojectv0.1.tar.bz2 Nitrotstprojectv0.1.tar.bz2]
 +
  
 
----
 
----
 
[[Category:NDS]]
 
[[Category:NDS]]
 
[[Category:Drivers]]
 
[[Category:Drivers]]

Revision as of 22:38, 17 February 2008

Nitrofs Filesystem Driver

Why is this needed?

The nitrofs driver allows accessing of files from a read-only nitro-filesystem that is appended to the end of an .nds file.

The previous solutions to appending filesystems to .nds files were kinda suxy.

How to use and examples

You place all the stuff you want to have on the filesystem into a directory. For this example we have a directory named "MyNitroFS". This directory, its subdirectories, and all contents are then converted into nitro filesystem format and appended onto your executable using ndstool's -d option. Like So:

ndstool -c myhomebrew.nds -d MyNitroFS

Thats it, now all the stuffs in MyNitroFS dir is elegantly appended into one nice pretty file. No need to ask the end user to copy over alot of seperate files and clutter up their flashcard. :D

Okay from a coding standpoint.. Firstly, you'll need this includes:

#include <nds.h>
#include <stdio.h>
#include "nitrofs.h"
#include <fat.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

Then you will need to initialize the FAT driver, and the nitrofs driver:

fatInitDefault();
nitroFSInit("myndsfile.nds"); //See * Notes Below
  • Replace this with the name of your .nds file. You could try using argv[0] here (which points to the current file) but as of this writing it is not supported on all cards.

Lastly open a file as you would in any other OS specifying nitro: as the drive:

fd=open("nitro:/Th04_01.raw",O_RDONLY);
read(fd, myBuffer, mybufferSize);
close(fd);

(Author's Note: Really dislike that they did not use Unix style nodes for drives and devices such as '/dev/device' or '/media/drive'. Instead opting for DOS 'drive:' style.. buy jaja.. it works :D )

You may want to add some error checking and reporting in case the filename or filepath passed to nitroFSInit are incorrect, the card does not support DLDI, or are not using the correct build for emulators not supporting DLDI (which are most of em'). This can be done somewhat like this:

int fd;
bool imfat;	//indicate fat driver loaded properly
printf("initalizing fat\n");
if(fatInitDefault()) {
	imfat=true;
	printf("Success...\n");
} else {
	imfat=false;
	printf("Failed... (normal for some emulators. Dont worry, yet :p)\n");
}
printf("initalizing nitrofs\n");
if(nitroFSInit("myndsfile.nds")) {
	fd=open("nitro:/myreadonlynitrofsfile.txt",O_RDONLY);
	if(fd) {
		len=read(fd,sample,st.st_size);
		close(fd);
		}
	} else {
		printf("read only file open failed\n");
	}
} else {
	printf("Failed...\n");
	if(imfat) { //error if fat was initialized...
		printf("Cannot open %s please check filename and path are correct.\n",FILENAME);
	} else { //error if fat/dldi failed
		printf("FAT/DLDI error, please to ensure your card supports DLDI.\n\nIf using emulators  that do not support fat/dldi (such as no$gba) be sure you are using a nds.gba or .sc.nds build.\n");
	}
}

Releases

The archive contains three source files: nitrofs.c - The nitro filesystem source. nitrofs.h - The nitro filesystem header. This should only be included into the file where you have your nitroFSInit() call. main.c - A working example


Nitrotstprojectv0.1.tar.bz2



Personal tools
irssi scripts
eggdrop scripts