#4714 - cewlout - Mon Apr 07, 2003 9:45 pm
Hi dudes,
I am coding on the GBA with the freely available Devkit Advance.
To quick-test my code I use VisualBoy Advance (don't want to
use the flasher everytime).
But now to my actual question ;) - Is there a way to view values
of variables when I run the code in an emulator? I am desperately
searching for a method to make variables (variables' values) visible at run-time. A simple 'printf("%d",myvariable)' would be enough. How do you guys do this? And which tools/emus (if available freely) do you use for tracing or printing/viewing variables.. any suggestions?
thank you!
#4717 - tepples - Mon Apr 07, 2003 10:10 pm
cewlout wrote: |
Is there a way to view values of variables when I run the code in an emulator? |
If you're using a BG for the status bar, you can try making the status bar taller and printing the variables you want to display into that.
I guess you're wondering how to print a number. Use siprintf() (same as sprintf() but doesn't support floating point so it won't add the whole floating point library to your project) to make a string, then write that string to your status bar.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#4719 - DekuTree64 - Mon Apr 07, 2003 10:16 pm
The way I do it is just load in a bitmap font (you can use mine, which I uploaded to http://www.angelfire.com/wizard/deku/Font.bmp). Then just have a print function that takes an x, y, and BG screen idx. That font starts with a space, which in ascii is 32, so just subtract 32 from each character of your string, set tile x + (y << 5) of BGS(screenIdx) to that value, and increment x for the next character. Then you need an int to string conversion function, which is very easy to do in hex, and slightly harder in decimal. For hex, just check the upper 4 bits, set to '0' + val if less than 10, set to 'A' + val otherwise, strPos++, then val <<= 4 (so the next 4 bits are in the same position as the 4 you just did), and repeat 8 times total for a 32 number.
For decimal, it's basically the same thing, but since you don't want to print eevry digit possible unless the number is that big, you have to start at the end of the output string and work backwards. Just set str[strPos--] to val % 10, then divide val by 10, and repeat until val == 0. If you use the BIOS division, you can get the div and mod at the same timet o speed it up.
#4720 - regularkid - Mon Apr 07, 2003 10:24 pm
Yup. Just use the MappyVM emulator and add this function to your code:
(from the MappyVM SDK doc):
Code: |
void dprint(const char *sz) {
asm volatile("
mov r2, %0
ldr r0, =0xc0ded00d
mov r1, #0
and r0, r0, r0
" :
/* No output */ :
"r" (sz) :
"r0", "r1", "r2");
}
|
In my library I modified this function to take parameters similar to a printf function so that I could call this function like this:
Code: |
dprint("My variable = %d\n", myVar);
|
I can't remember the exact code for this since I'm at work and my library code is at home, but I remember you need to use the va_list functions (i'm sure you can find examples of this somewhere. If not, I can post code later tonight). This is EXTREMELY useful and is my main source of debugging help! Hope this helps.
_________________
- RegularKid
#4737 - Torlus - Tue Apr 08, 2003 10:08 am
There is a similar function with VisualBoyAdvance (i use it on Linux).
As far as i remember, you have to do is call "swi 0xFF" with r1 pointing to a C-style string.
I think you'll be able to find an example for calling it from C somewhere in the forum, as it has been discussed before.
Hope this helps.
#4740 - Drago - Tue Apr 08, 2003 11:19 am
Code: |
#include <stdio.h>
#include <stdarg.h>
//////////////////////////////////
// VisualBoy console output
//////////////////////////////////
static void conprint(const char *a_str)
{
asm volatile (
" \n\
mov r0, %0 \n\
swi 0xff \n\
"
:
// no output
:
"r" (a_str)
:
"r0"
);
}
//////////////////////////////////
// Format output
//////////////////////////////////
void dprint(const char *a_fmtstr, ...)
{
va_list argptr;
char buffer[256];
va_start(argptr, a_fmtstr);
vsprintf(buffer, a_fmtstr, argptr);
conprint(buffer);
va_end(argptr);
}
|
Note that the swi 0xff hangs the GBA, so you should disable the console output when testing on the hardware.
#4751 - TurboHz - Tue Apr 08, 2003 2:17 pm
// ARM code
void print(char *s)
{
asm volatile("mov r0, %0;"
"swi 0xff0000;"
: // no ouput
: "r" (s)
: "r0");
}
I found this output code in VBA FAQ... how would that translate to ARM asm??
Something about loading in r0 the starting address of a string of bytes (chars)?
How should the string be terminated? with a chr(13)?
Sorry if this seems obvious to anyone. (I'm not using C for GBA dev, just asm)
#4752 - cewlout - Tue Apr 08, 2003 3:44 pm
Thank you very much dudes, you helped me alot!
#4758 - tom - Tue Apr 08, 2003 4:55 pm
Drago wrote: |
Note that the swi 0xff hangs the GBA, so you should disable the console output when testing on the hardware. |
actually visualboy advance supports two methods to print text to the log window. one is swi 0xff, and the other one is similar to mappy'ss method. this method has the advantage that it doesn't crash the hardware. pretty useful, as you don't have to switch between release/debug builds during development.
i added the following code to the file vba.s that can be downloaded from the visualboy website Code: |
.align 2
.global vbalog_hardware_friendly
.thumb_func
.type vbalog_hardware_friendly,function
@ log a message to VBA's output console, don't crash real hardware
@ r0 = pointer to log message
vbalog_hardware_friendly:
mov r2,r0
ldr r0,=0xc0ded00d
mov r1,#0
and r0,r0
bx lr
|