Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprintf decimal formatting inconsistent with other emulators #26

Open
jackbonaguro opened this issue Aug 18, 2023 · 1 comment
Open

Comments

@jackbonaguro
Copy link

I wrote a small program using tonc that just displays the string resulting from sprintf(str, "should print \"-1\": %d\n", -1);. The resulting GBA file faithfully prints should print "-1": -1 on mGBA on mac, PizzaBoy on Android, and SkyEmu in browser; but for gba.js.org, it prints should print "-1": -4294967297.

-4294967297 is 0x100000001 in hex; I would expect 0xffffffff instead. If I change the format string from %d to %x, all emulators print 0xffffffff. To me this indicates that the affected code is in sprintf, but the bug is in the emulator as an identical sprintf version is compiled into the same .gba file that results in different behavior per emulator.

Screenshots:

SkyEmu (web.skyemu.app):
Screen Shot 2023-08-18 at 4 00 46 PM

GBA.JS.ORG:
Screen Shot 2023-08-18 at 4 00 01 PM

main.c:

#include <string.h>
#include <tonc.h>

void update_console() {
	tte_erase_screen();
	tte_write("#{P:1,1}");
	char str[48];
	sprintf(str, "should print \"-1\": %d\n", -1);
	tte_write(str);
}

int main() {
	REG_DISPCNT= DCNT_OBJ | DCNT_OBJ_1D;
	REG_DISPCNT = REG_DISPCNT | DCNT_MODE0 | DCNT_BG0 | DCNT_BG1;
	REG_BGCNT[1]= BG_CBB(1) | BG_SBB(31) | BG_4BPP | BG_REG_32x32;

	tte_init_se(1, (BG_CBB(1))|BG_SBB(31), 0, CLR_YELLOW, 14, NULL, NULL);

	/* Main Loop */
	while(1) {
		vid_vsync();
		update_console();
	}

	return 0;
}

Attached .zip file includes sources and built .gba file. Depends on a working devkitPro toolchain to build from source.

gba-test.zip

@ayvacs
Copy link
Owner

ayvacs commented Aug 29, 2023

yeah i got no clue sorry bro

@jackbonaguro jackbonaguro changed the title Internal representation of -1 inconsistent with other emulators Sprintf decimal formatting inconsistent with other emulators Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants