#177027 - Dekota - Mon Nov 28, 2011 5:34 pm
Hi
Bit curious about how you properly write to ROM space.
I know there are 3 different ROM spaces with wait 0-2 and I know the memory locations. But how do I go about writing to these spaces.
I would presume its something to do with the make process.
Also would it be fine to write headers to the rom and load the data from them or would I have to make a binary file and work from that?
Last note does any one know where I can get a flash cart in the UK?
Thanks
#177028 - Dwedit - Mon Nov 28, 2011 7:20 pm
You won't be writing to the ROM space unless:
* You have a Supercard/M3 or some other cartridge with RAM there, and have unlocked the RAM.
* You have a Flash chip there, and have completed the sequence of unlocking and erasing a flash page. Then you can reprogram 1 bits into 0 bits. Flash pages are usually erased in units of 256kB, erasing sets a page to all 1s.
ROM area is also only writable in units of 16-bits, like VRAM. 32-bit writes will also work. 8-bit writes will double the byte across the 16-bit word.
The make process has nothing to do with anything.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#177029 - Dekota - Mon Nov 28, 2011 8:24 pm
sorry if these seem like stupid questions but I cant seem to get my head round where al my data is being stored
If I had say 500 or so sprites in the game how would I go about storing all the data.
at the moment I would have all the raw data in a couple of header files and then just load the data when its needed.
When I said ROM I think I should have said the GamePak Not the GBA's ROM.
thanks
#177030 - Miked0801 - Tue Nov 29, 2011 7:11 pm
For the development I did, you would compile your program into a single binary with both code and data put together in a way that is consistent and addressable, then you would burn/flash this file onto a ROM cartridge. Your program will now reside within ROM.
Another way is to flash your info directly into RAM via any number of cables and utilities. In this case, your code and data must all fit within RAM, along with anything you need to allocate.
#177031 - Dekota - Tue Nov 29, 2011 11:24 pm
So far I have the make file which converts all my headers and c files into .o files and then into the rom.
Just getting a little confused about where my data is being stored at the moment.
if there is any information or if such thing exists a tutorial on reading and writing to the gamepak It would be much appreciated.
I also have no problem converting a bmp into a bin file to be used but have no idea how to write it and read it from rom.
thanks
#177032 - Dwedit - Wed Nov 30, 2011 3:38 am
Here's what happens when you compile something...
Source code (.c) files get compiled into assembly code (.s files, but you don't see these), then they get turned into object code .o. Then a bunch of .o files get linked together into one binary, the .elf file. The .elf file contains lots of extra information that won't go on the cartridge ROM, such as symbol tables, and debugging information about how the binary code corresponds back to the source files. So it runs objcopy to extract only the binary data itself, and it makes the .GBA file. A .GBA file is the contents of the cartridge ROM.
Your code goes into the .text section, which is placed into the cartridge ROM area.
Your read-only data goes into the .rodata section, which is also placed into the cartridge ROM area.
Your writable global variables go into the .data (not zero-filled) and .bss (zero-filled) sections, which go into IWRAM (32k of fast RAM).
Your local variables inside your functions exist in the registers, and on the stack, which is also inside of IWRAM.
Memory you allocate with malloc and the C++ "new" operator goes into EWRAM, 256k of slower RAM than IWRAM, but 256k is much bigger than 32k.
There is boot code that runs before any of your code, it is found in the crt0.s file. It copies memory into the appropriate sections as needed, clears other memory, then calls main().
When you load graphics, you copy your data from ROM into VRAM as needed.
You generally never write back to cartridge ROM. On commercial GBA games, it's physically impossible. Instead, you write to save memory built into the cartridges.
Also, make sure all data is declared as "const", otherwise it makes a copy of it in RAM. If you are just loading it into video memory, you don't need the extra copy eating up your RAM. When you use binary conversion tools that generate .o files, that is usually enough to ensure it gets put in ROM.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#177045 - Dekota - Fri Dec 02, 2011 1:49 pm
so if in a header file I had
int Array[100][100] = {.....}
that would be placed in .rodata and when I read from the array I would be reading directly from rom?
#177050 - Dwedit - Fri Dec 02, 2011 5:15 pm
You didn't declare it as const, so it goes into the .data (read-write global variables) section. A copy goes into ROM, then at bootup, it is copied into IWRAM, but before that happens, you get a Link Error because 40k is too big for 32k of IWRAM.
If you DID declare it as const, it would be in the .rodata section, and you would be reading directly from ROM.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#177052 - sverx - Fri Dec 02, 2011 6:11 pm
All that copy ROM to RAM etc etc... doesn't apply to DS, right? Otherwise I guess I must be missing something very important...
_________________
libXM7 | NDS programming tutorial (Italiano) | Waimanu DS | A DS Homebrewer's Diary
#177054 - Dekota - Fri Dec 02, 2011 8:37 pm
Thank you Dwedit for explaining that has help out a lot.
was using large arrays to store map data and was starting to get a little worried about if it was being stored in IWRAM or on the rom.
#177055 - Dwedit - Fri Dec 02, 2011 8:57 pm
On the DS, your entire program is copied into RAM before any crt0 code is run. .rodata and .data both live in main memory, so they don't get moved or copied to anywhere else at bootup.
The only time you get extra copy operations is if the variables live in another memory section. For example, you might have a 4k large array declared in DTCM. At bootup, the memory is copied from main memory to DTCM. Then the space is reclaimed and cleared to zeroes before main is called.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#177068 - sverx - Mon Dec 05, 2011 11:43 am
Oh, good :)
BTW:
Dwedit wrote: |
The only time you get extra copy operations is if the variables live in another memory section. For example, you might have a 4k large array declared in DTCM. At bootup, the memory is copied from main memory to DTCM. Then the space is reclaimed and cleared to zeroes before main is called. |
I guess you mean an array which is initialized to some value, right? :)
_________________
libXM7 | NDS programming tutorial (Italiano) | Waimanu DS | A DS Homebrewer's Diary