samyk / opensesame

OpenSesame attacks wireless garages and can open most fixed-code garages and gates in seconds using a Mattel toy
https://samy.pl/opensesame/
GNU General Public License v2.0
846 stars 175 forks source link

SDCC version > 3.6.0 error 91: extern definition for 'putchar' mismatches with declaration #11

Open ghost opened 3 years ago

ghost commented 3 years ago

When you want to compile the source without error, with a version of SDCC > 3.6.0, you need to change the putchar() function prototype to fit SDCC, bacause it was changed. I tested it on SDCC v4.0 (Linux Fedora 33).

In display.h

#ifndef LOCAL
//void putchar(char c);
int putchar(int c);
#endif

and in display.c

/* sdcc provides printf if we provide this */
//void putchar(char c)
int putchar(int c)
{
 ....
 return(c);
}
samyk commented 3 years ago

Thanks - do you know the exact version it needs to be adjusted or have a link with further info on the version with the change? Adjusting that fails to compile on sdcc 3.4.0 so would like some ifdefs to support both.

ghost commented 3 years ago

The change of putchar() prototype was made in version 3.7.0

SDCC 3.7.0 Feature List:

It was a fix of an issue from 2016-06-16 (SDCC changelog):

samyk commented 3 years ago

Cool, it will now check version of sdcc to decide what to do. Hopefully that resolves it!

Ivan275g4 commented 3 years ago

I'm not sure that actually fixed it at least not for me under Windows/Linux with SDCC 4.0.0 I will start by saying I don't know wtf I'm doing but.... Shouldn't

if (SDCC_VERSION_HI == 3 && SDCC_VERSION_LO >= 7) || (SDCC_VERSION_HI >= 4) be

if (SDCC_VERSION_MAGOR == 3 && SDCC_VERSION_MINOR >= 7) || (__SDCC_VERSION_MAJOR >= 4)

also both in display C and H, the declaration and use of putchar() needs to be fixed for >3.7. With the code above the Int/Int that is expected turns to int/char with the current code. Adding PUTCHAR_TYPE2 fixes that. But I'm not a fan of that name.

display.h

// sdcc 3.7.0+ uses int putchar
#if (__SDCC_VERSION_MAGOR == 3 && __SDCC_VERSION_MINOR >= 7) || (__SDCC_VERSION_MAJOR >= 4)
  #define PUTCHAR_INT
  #define PUTCHAR_TYPE int
  #define PUTCHAR_TYPE2 int
#else
  #define PUTCHAR_TYPE void
  #define PUTCHAR_TYPE2 char
#endif

display.h

#ifndef LOCAL
    PUTCHAR_TYPE putchar(PUTCHAR_TYPE2 c);
#endif

display.c

/* sdcc provides printf if we provide this */
PUTCHAR_TYPE putchar(PUTCHAR_TYPE2 c)
{
#ifdef SIMULATOR
    while (!TI); /*  wait end of last transmission */
    TI = 0;
    SBUF = c; /*  transmit to serial */
#else
    u8 i;
    c &= 0x7f;
    if (c >= FONT_OFFSET)
    {
        for (i = 0; i < FONT_WIDTH; i++)
            txData(font[c - FONT_OFFSET][i] ^ (reverseTxt ? 0xff : 0));
        txData(reverseTxt ? 0xff : 0x00);
    }
#endif
#ifdef PUTCHAR_INT
  return c;
#endif
}