Gameboy Development Forum

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.

Ads

#1 2017-07-03 09:43:45

Binsou
New member
Registered: 2017-07-03
Posts: 3

Getting weird outputs from printf calls. Please help.

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

 

#2 2017-07-03 10:07:12

Binsou
New member
Registered: 2017-07-03
Posts: 3

Re: Getting weird outputs from printf calls. Please help.

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

 

#3 2017-07-03 19:34:48

drludos
Member
Registered: 2017-05-11
Posts: 52

Re: Getting weird outputs from printf calls. Please help.

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!


Download ROMs of my games: https://drludos.itch.io/
Support my work and get access to beta and prototypes: https://www.patreon.com/drludos

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson