#8443 - dchartier - Thu Jul 10, 2003 8:40 pm
I would like to allocate a static-size buffer into which I can write log messages, debugging info, etc. If possible, I would like to set the exact location of this buffer. My reason is that I would like to be able to check the contents of this buffer with any build without having to peruse map files to determine where the address-du-jour is.
As far as I can tell, a static array such as the following would not work because the linker could move the array elsewhere as my program evolves:
unsigned char debugBuf[BUF_SIZE];
I have the following questions:
1. Can I do what I described? If so, how?
2. Do I need to "inform" malloc of this buffer to ensure that it doesn't allocate memory within it?
3. Where is the best place to put the array? I figure that on-board WRAM would be best because access to the buffer is not very time-critical, and I'd like to save as much internal WRAM for my game as possible.
4. Should I worry about the stack overflowing into my buffer?
Thanks for your help!
#8462 - Quirky - Fri Jul 11, 2003 7:44 am
A silly question.. but why not use VBA's debugging output? If you use the SDL version, you can dump text to the console easily. And in the Windows version the output goes to the logging window. This buffer approach seems a bit too cumbersome to me.
Anyway, to do what you've described, I would place the array at a fixed address (something like u8 * debug = (u8*)0x0x2030000) then tell the linkscript that EWRAM is smaller than it really is - i.e. that it ends at the start of your array. That way malloc will still work as expected. You could do that by editting Jeff Frohwein's lnkscript file and setting __eheap_end = 0x2030000; That would give you a debug area of 0x10000 bytes (64kb).
If you never use malloc though, you can forget about the link script changes. Oh and don't worry about the stack if you place the array in ewram - the stack is handled in iwram.
#8463 - dchartier - Fri Jul 11, 2003 8:09 am
Quirky wrote: |
A silly question.. but why not use VBA's debugging output? If you use the SDL version, you can dump text to the console easily. And in the Windows version the output goes to the logging window. This buffer approach seems a bit too cumbersome to me.
Anyway, to do what you've described, I would place the array at a fixed address (something like u8 * debug = (u8*)0x0x2030000) then tell the linkscript that EWRAM is smaller than it really is - i.e. that it ends at the start of your array. That way malloc will still work as expected. You could do that by editting Jeff Frohwein's lnkscript file and setting __eheap_end = 0x2030000; That would give you a debug area of 0x10000 bytes (64kb).
If you never use malloc though, you can forget about the link script changes. Oh and don't worry about the stack if you place the array in ewram - the stack is handled in iwram. |
I want a buffer so that I can obtain debugging information regardless of the emulator I use. Thanks for the suggestions.
I wasn't aware that one of the emulators provided a console window for output; that would definitely make things simpler. Is VBA the "VisualBoyAdvance 1.5a" emulator at http://www.gbadev.org/tools.php?section=emulator? How can my program send strings to the console? Feel free to point me to the appropriate documentation.
Thanks!
#8603 - djei-dot - Wed Jul 16, 2003 12:03 pm
Didn't know that also... I browsed the vba site (vboy.emuhq.com) and found out a download for libvba - it's some kind of library that lets you write to the logging window.
#8608 - hnager - Wed Jul 16, 2003 12:47 pm
This is what I use (works in vba aswell as mappy):
inline void do_mappy_dprint(char* msg){
int loc = 0xc0ded00d;
asm volatile(
"mov r2, %0 \n"
"ldr r0, %1 \n"
"mov r1, #0 \n"
"and r0, r0, r0 \n"
:
: // No output
"r" (msg), "m" (loc) :
"r0", "r1", "r2");
}
usage:
do_mappy_dprint("TESTING1");
or you can pass in a char buffer.
#8611 - ampz - Wed Jul 16, 2003 3:15 pm
Or, you simply tell the linker not to use a part of the RAM, and then set up a pointer to that area.