sverx / devkitSMS

development kit and libraries for SEGA Master System / SEGA Game Gear / SEGA SG-1000 / SEGA SC-3000 homebrew programming using C language (and the SDCC compiler)
223 stars 34 forks source link

32bits variables #21

Closed Alirio926 closed 3 years ago

Alirio926 commented 3 years ago

It's not a problem, but is there a way to make calculations with 32-bit variables?

tried:

unsigned long ab = 0x10001; char buffer[24]; sprintf(buffer, "%d", sizeof(ab)); draw_text(buffer, 9, 2); sprintf(buffer, "%d", ab); draw_text(buffer, 9, 3);

But this print: 4 and 1, so unsignd long is 32 bits but why cannot show?

drawText method.

void draw_text(unsigned char text, unsigned char x, unsigned char y) { //const unsigned int pnt = devkitSMS_fonttiles1bpp; unsigned char idx = 0; while ('\0' != text[idx]) { signed char tile = text[idx];// -TEXT_ROOT; SMS_setNextTileatXY(x++, y); SMS_setTile(SMS_TextRenderer_offset + tile); idx++; } }

sverx commented 3 years ago

I suspect the problem might be in sprintf(buffer, "%d", ab);

unsigned long are surely supported by the compiler (SDCC) but I never used their sprintf implementation, it might not work as expected

Alirio926 commented 3 years ago

You're right, I changed the parameter to %lu and it worked, Thanks!!!