diff --git a/doc/cc65.sgml b/doc/cc65.sgml index ae80b11b0..56a87ae72 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -1390,7 +1390,12 @@ parameter with the operator will be used + to determine the number from the bank attribute defined in the linker config, + see . Note that + this currently implies that only the least significant 8 bits of the bank attribute + can be used. The address of a wrapped function is passed in Other MEMORY area attributes

+Other MEMORY area attributes

There are some other attributes not covered above. Before starting the reference section, I will discuss the remaining things here. @@ -822,7 +822,6 @@ that has a segment reference (for example a symbol). The result of this function is the value of the bank attribute for the run memory area of the segment. - Other SEGMENT attributes

Segments may be aligned to some memory boundary. Specify "WrappedCallData); - SB_AppendStr (&S, tmp); + if (Func->WrappedCallData == WRAPPED_CALL_USE_BANK) { + /* 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 b69cfa850..e065c7602 100644 --- a/src/cc65/funcdesc.h +++ b/src/cc65/funcdesc.h @@ -58,7 +58,7 @@ /* Bits that must be ignored when comparing funcs */ #define FD_IGNORE (FD_INCOMPLETE_PARAM | FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER) - +#define WRAPPED_CALL_USE_BANK 0x0100U /* WrappedCall uses .bank() */ /* Function descriptor */ typedef struct FuncDesc FuncDesc; @@ -71,7 +71,7 @@ struct FuncDesc { struct SymEntry* LastParam; /* Pointer to last parameter */ struct FuncDesc* FuncDef; /* Descriptor used in definition */ struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */ - unsigned char WrappedCallData; /* The WrappedCall's user data */ + unsigned int WrappedCallData; /* The WrappedCall's user data */ }; diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index f0f7ed36f..e4bb4cdeb 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -531,16 +531,19 @@ static void WrappedCallPragma (StrBuf* B) /* Skip the following comma */ if (!GetComma (B)) { /* Error already flagged by GetComma */ + Error ("Value or the word 'bank' required for wrapped-call identifier"); + goto ExitPoint; + } + + /* Next must be either a numeric value, or "bank" */ + if (HasStr (B, "bank")) { + Val = WRAPPED_CALL_USE_BANK; + } else if (!GetNumber (B, &Val)) { Error ("Value required for wrapped-call identifier"); goto ExitPoint; } - if (!GetNumber (B, &Val)) { - Error ("Value required for wrapped-call identifier"); - goto ExitPoint; - } - - if (Val < 0 || Val > 255) { + if (!(Val == WRAPPED_CALL_USE_BANK) && (Val < 0 || Val > 255)) { Error ("Identifier must be between 0-255"); goto ExitPoint; } @@ -552,7 +555,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 int) Val); 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..ecf2c3a53 100644 --- a/src/cc65/wrappedcall.c +++ b/src/cc65/wrappedcall.c @@ -64,7 +64,7 @@ static IntPtrStack WrappedCalls; -void PushWrappedCall (void *Ptr, unsigned char Val) +void PushWrappedCall (void *Ptr, unsigned int Val) /* Push the current WrappedCall */ { if (IPS_IsFull (&WrappedCalls)) { @@ -88,7 +88,7 @@ void PopWrappedCall (void) -void GetWrappedCall (void **Ptr, unsigned char *Val) +void GetWrappedCall (void **Ptr, unsigned int *Val) /* Get the current WrappedCall */ { if (IPS_GetCount (&WrappedCalls) < 1) { @@ -97,6 +97,6 @@ void GetWrappedCall (void **Ptr, unsigned char *Val) } else { long Temp; IPS_Get (&WrappedCalls, &Temp, Ptr); - *Val = (unsigned char) Temp; + *Val = (unsigned int) Temp; } } diff --git a/src/cc65/wrappedcall.h b/src/cc65/wrappedcall.h index 3517c2465..9a1bb51bf 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 int Val); /* Push the current WrappedCall */ void PopWrappedCall (void); /* Pop the current WrappedCall */ -void GetWrappedCall (void **Ptr, unsigned char *Val); +void GetWrappedCall (void **Ptr, unsigned int *Val); /* Get the current WrappedCall, if any */