diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 0868c2082..0b705a320 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1739,6 +1739,7 @@ static FuncDesc* ParseFuncDecl (void) SymEntry* Sym; SymEntry* WrappedCall; unsigned char WrappedCallData; + int WrappedCallUseBank; /* Create a new function descriptor */ FuncDesc* F = NewFuncDesc (); @@ -1791,10 +1792,11 @@ static FuncDesc* ParseFuncDecl (void) RememberFunctionLevel (F); /* Did we have a WrappedCall for this function? */ - GetWrappedCall((void **) &WrappedCall, &WrappedCallData); + GetWrappedCall((void **) &WrappedCall, &WrappedCallData, &WrappedCallUseBank); if (WrappedCall) { F->WrappedCall = WrappedCall; F->WrappedCallData = WrappedCallData; + F->WrappedCallUseBank = WrappedCallUseBank; } /* Return the function descriptor */ diff --git a/src/cc65/expr.c b/src/cc65/expr.c index bc277f13b..d2cd4ca5c 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -997,9 +997,16 @@ static void FunctionCall (ExprDesc* Expr) char tmp[64]; StrBuf S = AUTO_STRBUF_INITIALIZER; - /* Store the WrappedCall data in tmp4 */ - sprintf(tmp, "ldy #%u", Func->WrappedCallData); - SB_AppendStr (&S, tmp); + if (Func->WrappedCallUseBank) { + /* Store the bank attribute in tmp4 */ + SB_AppendStr (&S, "ldy #<.bank(_"); + SB_AppendStr (&S, (const char*) Expr->Name); + SB_AppendChar (&S, ')'); + } else { + /* Store the WrappedCall data in tmp4 */ + sprintf(tmp, "ldy #%u", Func->WrappedCallData); + SB_AppendStr (&S, tmp); + } g_asmcode (&S); SB_Clear(&S); diff --git a/src/cc65/funcdesc.h b/src/cc65/funcdesc.h index 423e7621f..5875723fb 100644 --- a/src/cc65/funcdesc.h +++ b/src/cc65/funcdesc.h @@ -72,6 +72,7 @@ struct FuncDesc { struct FuncDesc* FuncDef; /* Descriptor used in definition */ struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */ unsigned char WrappedCallData;/* The WrappedCall's user data */ + int WrappedCallUseBank;/* Flag: does WrappedCall use .bank() or literal value */ }; diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index f0f7ed36f..249e4f1b4 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -497,6 +497,7 @@ static void WrappedCallPragma (StrBuf* B) const char *Name; long Val; SymEntry *Entry; + int UseBank = 0; /* Check for the "push" or "pop" keywords */ switch (ParsePushPop (B)) { @@ -535,12 +536,15 @@ static void WrappedCallPragma (StrBuf* B) goto ExitPoint; } - if (!GetNumber (B, &Val)) { + /* Next must be either a numeric value, or "bank" */ + if (HasStr (B, "bank")) { + UseBank = 1; + } else if (!GetNumber (B, &Val)) { Error ("Value required for wrapped-call identifier"); goto ExitPoint; } - if (Val < 0 || Val > 255) { + if (!UseBank && (Val < 0 || Val > 255)) { Error ("Identifier must be between 0-255"); goto ExitPoint; } @@ -552,7 +556,7 @@ static void WrappedCallPragma (StrBuf* B) /* Check if the name is valid */ if (Entry && (Entry->Flags & SC_FUNC) == SC_FUNC) { - PushWrappedCall(Entry, (unsigned char) Val); + PushWrappedCall(Entry, (unsigned char) Val, UseBank); Entry->Flags |= SC_REF; GetFuncDesc (Entry->Type)->Flags |= FD_CALL_WRAPPER; diff --git a/src/cc65/wrappedcall.c b/src/cc65/wrappedcall.c index 18cb507ac..a67f9815d 100644 --- a/src/cc65/wrappedcall.c +++ b/src/cc65/wrappedcall.c @@ -64,13 +64,13 @@ static IntPtrStack WrappedCalls; -void PushWrappedCall (void *Ptr, unsigned char Val) +void PushWrappedCall (void *Ptr, unsigned char Val, int UseBank) /* Push the current WrappedCall */ { if (IPS_IsFull (&WrappedCalls)) { Error ("WrappedCall stack overflow"); } else { - IPS_Push (&WrappedCalls, Val, Ptr); + IPS_Push (&WrappedCalls, Val | (UseBank << 8), Ptr); } } @@ -88,7 +88,7 @@ void PopWrappedCall (void) -void GetWrappedCall (void **Ptr, unsigned char *Val) +void GetWrappedCall (void **Ptr, unsigned char *Val, int *UseBank) /* Get the current WrappedCall */ { if (IPS_GetCount (&WrappedCalls) < 1) { @@ -97,6 +97,7 @@ void GetWrappedCall (void **Ptr, unsigned char *Val) } else { long Temp; IPS_Get (&WrappedCalls, &Temp, Ptr); - *Val = (unsigned char) Temp; + *UseBank = (int) Temp >> 8; + *Val = (unsigned char) Temp & 0xff; } } diff --git a/src/cc65/wrappedcall.h b/src/cc65/wrappedcall.h index 3517c2465..ddf6dd2b9 100644 --- a/src/cc65/wrappedcall.h +++ b/src/cc65/wrappedcall.h @@ -50,13 +50,13 @@ -void PushWrappedCall (void *Ptr, unsigned char Val); +void PushWrappedCall (void *Ptr, unsigned char Val, int usebank); /* Push the current WrappedCall */ void PopWrappedCall (void); /* Pop the current WrappedCall */ -void GetWrappedCall (void **Ptr, unsigned char *Val); +void GetWrappedCall (void **Ptr, unsigned char *Val, int *usebank); /* Get the current WrappedCall, if any */