#172842 - Ruben - Mon Mar 08, 2010 8:51 am
Hi all!
I just figured out how to read data from DS-Slot ROM [which I believe only works with emulators as I think flash software can only patch official stuff] so...
Setting up a framework
This step is quite important as it will define how you will setup your file reading routines.
Do you need directories? How long are the filenames allowed to be? Will they get exclusive rights/permissions?
Those are some questions you need to ask yourself.
For me, these are my answers:
-I do not need directories, merely names
-Filenames should only be 32-64 at most
-No exclusive permissions
Making a pseudo filesystem
Now that you have your answers, you will need to make a program that adds files to your NDS binary. Something simple would be similar to this..
-Pad NDS file to 200h bytes
-Find magic key for allocation table
-Setup parameters in said allocation table [things like filename, filesize [padded to 200h bytes], permissions, etc]
-Append files to NDS file, making sure to PAD EVERY FILE to 200h bytes
My program is rather simple, and can be found here: link
Accessing your filesystem
Now that you have your files appended to the binary [there to no be loaded into RAM automatically] and have your FAT set up, you now need a way to read from ROM to get the right data.
The first part is rather simple: You look through your FAT until you find the file you're after and load its parameters needed for loading.
Now the tricky part is using the registers correctly [this took me AGES to figure out].
The first thing to do is enable the NDS-slot. To do this, you merely ORR the right bit into AUXSPICNT
Now that the DS-slot is enabled you have to tell it what to do. This is done by issuing a read command like so..
B7aaaaaaaa000000 <- Read command [from gbaTek]
The B7 is the 'read' command. aaaaaaaa is the address/offset from which we want to read [aligned by 200h]. So the first thing to do is write the command to the register.
Notice that the offset is MSB first.
Now that the command has been sent, we have to enable the transfer. This is done by writing to ROMCTRL:
Now the DS will read from ROM and give you the right data. How do we read it? Simple.
We wait until the block word is ready [bit 23, ROMCTRL] and read a word from 0x04100010. This is done until we've read the full 200h block.
If your file is bigger than 200h then you will need to do this more than once until all the 200h blocks are done.
My source can be found here: link
Final notes
Well, this article may have been a bit confusing but hopefully the source code will help you figure out the parts that make no sense ;D
I'd like to thank DekuTree for putting up with me for ages about this and whoever it was that made gbaTek for its specs. ^-^'
Lastly, the dsfsLoad function can be used and/or distributed freely. No credit required though it would be nice. Also, it only takes a single argument which is the filename; it mallocs the length of the file and returns its address.
Until later!
I just figured out how to read data from DS-Slot ROM [which I believe only works with emulators as I think flash software can only patch official stuff] so...
Setting up a framework
This step is quite important as it will define how you will setup your file reading routines.
Do you need directories? How long are the filenames allowed to be? Will they get exclusive rights/permissions?
Those are some questions you need to ask yourself.
For me, these are my answers:
-I do not need directories, merely names
-Filenames should only be 32-64 at most
-No exclusive permissions
Making a pseudo filesystem
Now that you have your answers, you will need to make a program that adds files to your NDS binary. Something simple would be similar to this..
-Pad NDS file to 200h bytes
-Find magic key for allocation table
-Setup parameters in said allocation table [things like filename, filesize [padded to 200h bytes], permissions, etc]
-Append files to NDS file, making sure to PAD EVERY FILE to 200h bytes
My program is rather simple, and can be found here: link
Accessing your filesystem
Now that you have your files appended to the binary [there to no be loaded into RAM automatically] and have your FAT set up, you now need a way to read from ROM to get the right data.
The first part is rather simple: You look through your FAT until you find the file you're after and load its parameters needed for loading.
Now the tricky part is using the registers correctly [this took me AGES to figure out].
The first thing to do is enable the NDS-slot. To do this, you merely ORR the right bit into AUXSPICNT
Code: |
REG_AUXSPICNT |= 0x8000; //alternatively, you can write 0x80
//to the top byte |
Now that the DS-slot is enabled you have to tell it what to do. This is done by issuing a read command like so..
B7aaaaaaaa000000 <- Read command [from gbaTek]
The B7 is the 'read' command. aaaaaaaa is the address/offset from which we want to read [aligned by 200h]. So the first thing to do is write the command to the register.
Code: |
REG_DSCARD_CMD[0] = 0xB7,
REG_DSCARD_CMD[1] = offset>>24, REG_DSCARD_CMD[2] = offset>>16, REG_DSCARD_CMD[3] = offset>> 8, REG_DSCARD_CMD[4] = offset, REG_DSCARD_CMD[5] = 0, REG_DSCARD_CMD[6] = 0, REG_DSCARD_CMD[7] = 0; |
Notice that the offset is MSB first.
Now that the command has been sent, we have to enable the transfer. This is done by writing to ROMCTRL:
Code: |
REG_ROMCTRL = START + BIT(29) + SIZE(1); //A1000000h |
Now the DS will read from ROM and give you the right data. How do we read it? Simple.
We wait until the block word is ready [bit 23, ROMCTRL] and read a word from 0x04100010. This is done until we've read the full 200h block.
If your file is bigger than 200h then you will need to do this more than once until all the 200h blocks are done.
My source can be found here: link
Final notes
Well, this article may have been a bit confusing but hopefully the source code will help you figure out the parts that make no sense ;D
I'd like to thank DekuTree for putting up with me for ages about this and whoever it was that made gbaTek for its specs. ^-^'
Lastly, the dsfsLoad function can be used and/or distributed freely. No credit required though it would be nice. Also, it only takes a single argument which is the filename; it mallocs the length of the file and returns its address.
Until later!