Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Hello,
I'm really new to the GB Dev scene and C is far from my primary language, so I'm a little confused on some of the outputs I'm getting from printf.
With this code:
#include <stdio.h>
int main () {
printf("%d\n", 5);
printf("%d\n", -5);
return 1;
}
I am getting an output on the GB emulator screen of:
-50683
-50437
This is just a tiny file I came up with to test the print function since I was getting similar values from the printing in my main game file.
Any information to help with this, or tips on how to put out debug information, would be appreciated.
Offline
Never mind, I figured it out via some other posts in the forums.
I was basically trying to print out a standard into which doesn't play well with the SDCC (or GBDK, still not 100% on that part), but by bringing in the GB library and using INT16s instead of ints, I was able to solve the issue.
My code has been changed to:
#include <gb/gb.h>
#include <stdio.h>
int main () {
INT16 x = 4;
printf("%u\n", x);
printf("%u\n", (INT16)5);
return 1;
}
The output from that is:
4
5
Offline
I got the exact same problem - thanks to Zalo for pointing out that printf needs value to be casted as UINT16 in order to display them!
Offline