diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 0d09f7f70..3aaee6f23 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -38,6 +38,8 @@ #include /* common */ +#include "addrsize.h" +#include "mmodel.h" #include "xmalloc.h" /* cc65 */ @@ -843,6 +845,13 @@ static FuncDesc* ParseFuncDecl (const DeclSpec* Spec) Sym = Sym->PrevSym; } + /* Add the default address size for the function */ + if (CodeAddrSize == ADDR_SIZE_FAR) { + F->Flags |= FD_FAR; + } else { + F->Flags |= FD_NEAR; + } + /* Leave the lexical level remembering the symbol tables */ RememberFunctionLevel (F); @@ -903,7 +912,10 @@ static void ApplyFunctionModifiers (type* T, unsigned Flags) Flags &= ~FD_FASTCALL; } - /* Add the flags */ + /* Remove the default function address size modifiers */ + F->Flags &= ~(FD_NEAR | FD_FAR); + + /* Add the new modifers */ F->Flags |= Flags; } diff --git a/src/cc65/main.c b/src/cc65/main.c index 78df3c22c..b720c5ce9 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -556,15 +556,23 @@ static void OptListOptSteps (const char* Opt attribute ((unused)), static void OptMemoryModel (const char* Opt, const char* Arg) /* Set the memory model */ { + mmodel_t M; + + /* Check the current memory model */ if (MemoryModel != MMODEL_UNKNOWN) { AbEnd ("Cannot use option `%s' twice", Opt); } - MemoryModel = FindMemoryModel (Arg); - if (MemoryModel == MMODEL_UNKNOWN) { + + /* Translate the memory model name and check it */ + M = FindMemoryModel (Arg); + if (M == MMODEL_UNKNOWN) { AbEnd ("Unknown memory model: %s", Arg); - } else if (MemoryModel == MMODEL_HUGE) { + } else if (M == MMODEL_HUGE) { AbEnd ("Unsupported memory model: %s", Arg); } + + /* Set the memory model */ + SetMemoryModel (M); }