I've been trying to learn Text File I/O for about 35 minutes total, and this is my way of grabbing a few words, now obviously this will take a lot of space. I have 8 char variables, which I think are 4 bytes each, so that adds up to 32 bytes. I'm trying to be a GBA programmer which multiplies the size of the game by 8, so that would be 256 bytes just to output "This text will now be inside of example.txt"
Is there a better way of doing this?
It would also help if someone would tell me you can even use text files on GBA.
Pickzell wrote:I've been trying to learn Text File I/O for about 35 minutes total, and this is my way of grabbing a few words, now obviously this will take a lot of space. I have 8 char variables, which I think are 4 bytes each, so that adds up to 32 bytes. I'm trying to be a GBA programmer which multiplies the size of the game by 8, so that would be 256 bytes just to output "This text will now be inside of example.txt"
Is there a better way of doing this?
It would also help if someone would tell me you can even use text files on GBA.
I'm actually not yet familiar with file i/o, but I can tell you that the size of this should be even bigger than you expect. A char is actually 1 byte but these are char arrays so each would be at least 10 bytes (according to how you sized them), so about 80 bytes total. I'm not sure what you mean by a GBA game multiplies the size of it by 8.
avansc wrote:if you wanna know how many bytes a string has do this.
char *str = "bla bla bla";
int size = sizeof(char)*strlen(str); // you might have to add one. i always forget about the null terminating char.
sizeof(str)?
hurstshifter wrote:A char is actually 1 byte but these are char arrays so each would be at least 10 bytes (according to how you sized them), so about 80 bytes total.
This is correct.
I'm not sure what you mean by a GBA game multiplies the size of it by 8.
I would guess, judging from NDS games, that what he means is that games are in sizes that are powers of 2? 2 mb, 4 mb, 8 mb, 64 mb, 128 mb, 256 mb... Really what should be done here is to find the size of whatever you have and then round up to the nearest power of 2, padding the rest of the space with null characters.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
hurstshifter wrote: I'm not sure what you mean by a GBA game multiplies the size of it by 8.
When a game is put on a GBA cartridge the file size of the game is multiplied by 8, so a 1 MB game on PC would be an 8 MB game on GBA.
EG: A 256 MB cartridge would only actually hold 32 MBs.
I can't really describe it better. ):
And apparently you can use either C or C++ for GBA.
avansc wrote:if you wanna know how many bytes a string has do this.
char *str = "bla bla bla";
int size = sizeof(char)*strlen(str); // you might have to add one. i always forget about the null terminating char.
sizeof(str)?
That would just give the size of the pointer
yes thats correct. in this case it would be the same. but you never use sizeof on a variable, only on data types.
the reason you use sizeof(datatype) and not sizeof(number) is because that code is not considered portable. although most
architectures these days have the same data sizes there can be some differences.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
OK first of all: iostream would probably run like a cheetah carrying an elephant over quicksand on gba. Second: I believe all images and stuff are converted and simply part of the rom. This means that instead of reading from a file you would convert the picture into a source file containing info about it. For example, if you were making NDS homebrew using PAlib, you'd probably use PAgfx to convert your graphics. I believe that grit and gfx2gba are 2 programs you can use for the same purpose. I guess what I'm trying to say is that all file I/O on GBA or NDS would probably be using something similar libfat, to access either memory provided on the gba flash cart or (on DS) the microSD card. other than that you'd have all that stuff packed into your rom. And no, not all memory usage is multiplied by 8. To me it just seems that your rom would get padded with NOP's at the end of your rom until it is a power of 2 in size. And I think that for a beginner programmer like you it would be better to start with NDS development, because that allows a bit more wiggle room (it seems that the GBA has <1 MB of ram, while the DS has 4 MB. Also, the NDS has 2 processors, not just one). Both are very similar (NDS actually borrowed some of the GBA's input hardware), so it shouldn't be too difficult to transition from one to the other.
I seem to have rambled on, and I don't know how to end this, so I'll just post this how it is. enjoy
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Seriously, if you don't learn C IO, you are going to murder your poor GBA. You may be able to use C++, but the C++ standard libraries are pretty taxing even on a Dreamcast or PSP. You're going to rape a GBA (if those libraries even run).
hurstshifter wrote: I'm not sure what you mean by a GBA game multiplies the size of it by 8.
When a game is put on a GBA cartridge the file size of the game is multiplied by 8, so a 1 MB game on PC would be an 8 MB game on GBA.
EG: A 256 MB cartridge would only actually hold 32 MBs.
You're probably confusing megabit with megabyte, often the sizes of roms will be denoted using megabits.
If you have the size of a rom in megabytes and want it in megabits you multiply by 8.
So the cartridge is likely to have 256 megabit of storage and not 256 megabyte.
#include "stdio.h"
int main(int argc, char** argv){
// variables; one to handle the file, one to store the string
FILE* file;
char str[128];
// now we open the file in write-mode ("w") and print some text into it
file = fopen("example.txt", "w");
fprintf(file, "This text will now be inside of example.txt");
fclose(file);
// now we open it again in read-mode ("r") and use fgets to take a line of text out of the file into str
file = fopen("example.txt", "r");
fgets(str, 128, file);
fclose(file);
// now we print the contents of str, which should be what was in the file :)
printf("%s", str);
return 0;
}
Ryan Pridgeon C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal Music | Blog