andreasjhkarlsson / gbdk-n

gbdk libraries updated for newer versions of sdcc
174 stars 25 forks source link

Fix INT8 that was unsigned instead of signed #13

Closed flozz closed 5 years ago

flozz commented 5 years ago

Since 2016, the char type is unsigned by default in SDCC. From the SDCC ChageLog:

2016-02-01 Philipp Klaus Krause <pkk AT spth.de>

    * src/SDCCglobl.h,
      src/SDCCmain.c,
      src/SDCCsymt.c,
      src/SDCCval.c,
      doc/sdccman.lyx:
      Make char unsigned by default.

As the INT8 type is based on char, this make it unsigned...

This PR fixes the issue. There is also an other possible fix: using the --fsigned-char option of the compiler.

Here a small code that reproduce the issue:

#include <stdio.h>
#include <gb/gb.h>

void main(void) {
    INT8 x = 10;
    INT8 dx = -1;
    printf("INT8 x = 10;\n");
    printf("INT8 dx = -1;\n\n");
    printf("x + dx = %i\n", x + dx);
}

Result before the fix:

capture d ecran de 2019-02-25 14-01-19

And after the patch:

capture d ecran de 2019-02-25 14-01-34

andreasjhkarlsson commented 5 years ago

Nice find! Thanks a lot!