mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Fix load of longs and improve zero page info
git-svn-id: svn://svn.cc65.org/cc65/trunk@739 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
a687912ea3
commit
caf73cf15f
@ -558,65 +558,74 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void g_getimmed (unsigned flags, unsigned long val, unsigned offs)
|
void g_getimmed (unsigned Flags, unsigned long Val, unsigned Offs)
|
||||||
/* Load a constant into the primary register */
|
/* Load a constant into the primary register */
|
||||||
{
|
{
|
||||||
if ((flags & CF_CONST) != 0) {
|
unsigned char B1, B2, B3, B4;
|
||||||
|
unsigned Done;
|
||||||
|
|
||||||
|
|
||||||
|
if ((Flags & CF_CONST) != 0) {
|
||||||
|
|
||||||
/* Numeric constant */
|
/* Numeric constant */
|
||||||
switch (flags & CF_TYPE) {
|
switch (Flags & CF_TYPE) {
|
||||||
|
|
||||||
case CF_CHAR:
|
case CF_CHAR:
|
||||||
if ((flags & CF_FORCECHAR) != 0) {
|
if ((Flags & CF_FORCECHAR) != 0) {
|
||||||
ldaconst (val);
|
ldaconst (Val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
case CF_INT:
|
case CF_INT:
|
||||||
ldxconst ((val >> 8) & 0xFF);
|
ldxconst ((Val >> 8) & 0xFF);
|
||||||
ldaconst (val & 0xFF);
|
ldaconst (Val & 0xFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_LONG:
|
case CF_LONG:
|
||||||
if (val < 0x100) {
|
/* Split the value into 4 bytes */
|
||||||
AddCodeLine ("ldx #$00");
|
B1 = (unsigned char) (Val >> 0);
|
||||||
AddCodeLine ("stx sreg+1");
|
B2 = (unsigned char) (Val >> 8);
|
||||||
AddCodeLine ("stx sreg");
|
B3 = (unsigned char) (Val >> 16);
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) val);
|
B4 = (unsigned char) (Val >> 24);
|
||||||
} else if ((val & 0xFFFF00FF) == 0) {
|
|
||||||
AddCodeLine ("lda #$00");
|
/* Remember which bytes are done */
|
||||||
AddCodeLine ("sta sreg+1");
|
Done = 0;
|
||||||
AddCodeLine ("sta sreg");
|
|
||||||
AddCodeLine ("ldx #$%02X", (unsigned char) (val >> 8));
|
/* Load the value */
|
||||||
} else if ((val & 0xFFFF0000) == 0 && CodeSizeFactor > 140) {
|
AddCodeLine ("ldx #$%02X", B2);
|
||||||
AddCodeLine ("lda #$00");
|
Done |= 0x02;
|
||||||
AddCodeLine ("sta sreg+1");
|
if (B2 == B3) {
|
||||||
AddCodeLine ("sta sreg");
|
AddCodeLine ("stx sreg");
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) val);
|
Done |= 0x04;
|
||||||
AddCodeLine ("ldx #$%02X", (unsigned char) (val >> 8));
|
}
|
||||||
} else if ((val & 0xFFFFFF00) == 0xFFFFFF00) {
|
if (B2 == B4) {
|
||||||
AddCodeLine ("ldx #$FF");
|
AddCodeLine ("stx sreg+1");
|
||||||
AddCodeLine ("stx sreg+1");
|
Done |= 0x08;
|
||||||
AddCodeLine ("stx sreg");
|
}
|
||||||
if ((val & 0xFF) == 0xFF) {
|
if ((Done & 0x04) == 0 && B1 != B3) {
|
||||||
AddCodeLine ("txa");
|
AddCodeLine ("lda #$%02X", B3);
|
||||||
} else {
|
AddCodeLine ("sta sreg");
|
||||||
AddCodeLine ("lda #$%02X", (unsigned char) val);
|
Done |= 0x04;
|
||||||
}
|
}
|
||||||
} else if ((val & 0xFFFF00FF) == 0xFFFF00FF) {
|
if ((Done & 0x08) == 0 && B1 != B4) {
|
||||||
AddCodeLine ("lda #$FF");
|
AddCodeLine ("lda #$%02X", B4);
|
||||||
AddCodeLine ("sta sreg+1");
|
AddCodeLine ("sta sreg+1");
|
||||||
AddCodeLine ("sta sreg");
|
Done |= 0x08;
|
||||||
AddCodeLine ("ldx #$%02X", (unsigned char) (val >> 8));
|
}
|
||||||
} else {
|
AddCodeLine ("lda #$%02X", B1);
|
||||||
/* Call a subroutine that will load following value */
|
Done |= 0x01;
|
||||||
AddCodeLine ("jsr ldeax");
|
if ((Done & 0x04) == 0) {
|
||||||
AddCodeLine (".dword $%08lX", val & 0xFFFFFFFF);
|
CHECK (B1 == B3);
|
||||||
}
|
AddCodeLine ("sta sreg");
|
||||||
|
}
|
||||||
|
if ((Done & 0x08) == 0) {
|
||||||
|
CHECK (B1 == B4);
|
||||||
|
AddCodeLine ("sta sreg+1");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
typeerror (flags);
|
typeerror (Flags);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -624,7 +633,7 @@ void g_getimmed (unsigned flags, unsigned long val, unsigned offs)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Some sort of label */
|
/* Some sort of label */
|
||||||
const char* Label = GetLabelName (flags, val, offs);
|
const char* Label = GetLabelName (Flags, Val, Offs);
|
||||||
|
|
||||||
/* Load the address into the primary */
|
/* Load the address into the primary */
|
||||||
AddCodeLine ("lda #<(%s)", Label);
|
AddCodeLine ("lda #<(%s)", Label);
|
||||||
@ -709,14 +718,9 @@ void g_getlocal (unsigned flags, int offs)
|
|||||||
AddCodeLine ("lda (sp),y");
|
AddCodeLine ("lda (sp),y");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (offs == 0) {
|
ldyconst (offs);
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
AddCodeLine ("lda (sp,x)");
|
AddCodeLine ("lda (sp),y");
|
||||||
} else {
|
|
||||||
ldyconst (offs);
|
|
||||||
AddCodeLine ("ldx #$00");
|
|
||||||
AddCodeLine ("lda (sp),y");
|
|
||||||
}
|
|
||||||
if ((flags & CF_UNSIGNED) == 0) {
|
if ((flags & CF_UNSIGNED) == 0) {
|
||||||
unsigned L = GetLocalLabel();
|
unsigned L = GetLocalLabel();
|
||||||
AddCodeLine ("bpl %s", LocalLabelName (L));
|
AddCodeLine ("bpl %s", LocalLabelName (L));
|
||||||
@ -792,11 +796,12 @@ void g_getind (unsigned flags, unsigned offs)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flags & CF_UNSIGNED) {
|
if (flags & CF_UNSIGNED) {
|
||||||
if (CodeSizeFactor > 250) {
|
if (CodeSizeFactor > 330) {
|
||||||
AddCodeLine ("sta ptr1");
|
AddCodeLine ("sta ptr1");
|
||||||
AddCodeLine ("stx ptr1+1");
|
AddCodeLine ("stx ptr1+1");
|
||||||
|
AddCodeLine ("ldy #$00");
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
AddCodeLine ("lda (ptr1,x)");
|
AddCodeLine ("lda (ptr1),y");
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("jsr ldaui");
|
AddCodeLine ("jsr ldaui");
|
||||||
}
|
}
|
||||||
@ -1697,32 +1702,18 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
|
|||||||
|
|
||||||
case CF_CHAR:
|
case CF_CHAR:
|
||||||
if (flags & CF_FORCECHAR) {
|
if (flags & CF_FORCECHAR) {
|
||||||
if (offs == 0) {
|
ldyconst (offs);
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
if (flags & CF_CONST) {
|
if (flags & CF_CONST) {
|
||||||
AddCodeLine ("clc");
|
AddCodeLine ("clc");
|
||||||
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
|
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
|
||||||
AddCodeLine ("adc (sp,x)");
|
AddCodeLine ("adc (sp),y");
|
||||||
AddCodeLine ("sta (sp,x)");
|
AddCodeLine ("sta (sp),y");
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("clc");
|
AddCodeLine ("clc");
|
||||||
AddCodeLine ("adc (sp,x)");
|
AddCodeLine ("adc (sp),y");
|
||||||
AddCodeLine ("sta (sp,x)");
|
AddCodeLine ("sta (sp),y");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ldyconst (offs);
|
|
||||||
AddCodeLine ("ldx #$00");
|
|
||||||
if (flags & CF_CONST) {
|
|
||||||
AddCodeLine ("clc");
|
|
||||||
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
|
|
||||||
AddCodeLine ("adc (sp),y");
|
|
||||||
AddCodeLine ("sta (sp),y");
|
|
||||||
} else {
|
|
||||||
AddCodeLine ("clc");
|
|
||||||
AddCodeLine ("adc (sp),y");
|
|
||||||
AddCodeLine ("sta (sp),y");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((flags & CF_UNSIGNED) == 0) {
|
if ((flags & CF_UNSIGNED) == 0) {
|
||||||
unsigned L = GetLocalLabel();
|
unsigned L = GetLocalLabel();
|
||||||
AddCodeLine ("bpl %s", LocalLabelName (L));
|
AddCodeLine ("bpl %s", LocalLabelName (L));
|
||||||
@ -1779,20 +1770,12 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
|
|||||||
case CF_CHAR:
|
case CF_CHAR:
|
||||||
AddCodeLine ("sta ptr1");
|
AddCodeLine ("sta ptr1");
|
||||||
AddCodeLine ("stx ptr1+1");
|
AddCodeLine ("stx ptr1+1");
|
||||||
if (offs == 0) {
|
AddCodeLine ("ldy #$%02X", offs);
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
|
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
|
||||||
AddCodeLine ("clc");
|
AddCodeLine ("clc");
|
||||||
AddCodeLine ("adc (ptr1,x)");
|
AddCodeLine ("adc (ptr1),y");
|
||||||
AddCodeLine ("sta (ptr1,x)");
|
AddCodeLine ("sta (ptr1),y");
|
||||||
} else {
|
|
||||||
AddCodeLine ("ldy #$%02X", offs);
|
|
||||||
AddCodeLine ("ldx #$00");
|
|
||||||
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
|
|
||||||
AddCodeLine ("clc");
|
|
||||||
AddCodeLine ("adc (ptr1),y");
|
|
||||||
AddCodeLine ("sta (ptr1),y");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_INT:
|
case CF_INT:
|
||||||
@ -2016,20 +1999,12 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
|
|||||||
case CF_CHAR:
|
case CF_CHAR:
|
||||||
AddCodeLine ("sta ptr1");
|
AddCodeLine ("sta ptr1");
|
||||||
AddCodeLine ("stx ptr1+1");
|
AddCodeLine ("stx ptr1+1");
|
||||||
if (offs == 0) {
|
AddCodeLine ("ldy #$%02X", offs);
|
||||||
AddCodeLine ("ldx #$00");
|
AddCodeLine ("ldx #$00");
|
||||||
AddCodeLine ("lda (ptr1,x)");
|
AddCodeLine ("lda (ptr1),y");
|
||||||
AddCodeLine ("sec");
|
AddCodeLine ("sec");
|
||||||
AddCodeLine ("sbc #$%02X", (unsigned char)val);
|
AddCodeLine ("sbc #$%02X", (unsigned char)val);
|
||||||
AddCodeLine ("sta (ptr1,x)");
|
AddCodeLine ("sta (ptr1),y");
|
||||||
} else {
|
|
||||||
AddCodeLine ("ldy #$%02X", offs);
|
|
||||||
AddCodeLine ("ldx #$00");
|
|
||||||
AddCodeLine ("lda (ptr1),y");
|
|
||||||
AddCodeLine ("sec");
|
|
||||||
AddCodeLine ("sbc #$%02X", (unsigned char)val);
|
|
||||||
AddCodeLine ("sta (ptr1),y");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_INT:
|
case CF_INT:
|
||||||
|
@ -82,45 +82,55 @@ static const FuncInfo FuncInfoTable[] = {
|
|||||||
{ "decax3", REG_AX, REG_AX },
|
{ "decax3", REG_AX, REG_AX },
|
||||||
{ "decax4", REG_AX, REG_AX },
|
{ "decax4", REG_AX, REG_AX },
|
||||||
{ "decax5", REG_AX, REG_AX },
|
{ "decax5", REG_AX, REG_AX },
|
||||||
{ "decax6", REG_AX, REG_AX },
|
{ "decax6", REG_AX, REG_AX },
|
||||||
{ "decax7", REG_AX, REG_AX },
|
{ "decax7", REG_AX, REG_AX },
|
||||||
{ "decax8", REG_AX, REG_AX },
|
{ "decax8", REG_AX, REG_AX },
|
||||||
{ "decaxy", REG_AXY, REG_AX },
|
{ "decaxy", REG_AXY, REG_AX },
|
||||||
{ "decsp2", REG_NONE, REG_A },
|
{ "decsp2", REG_NONE, REG_A },
|
||||||
{ "decsp3", REG_NONE, REG_A },
|
{ "decsp3", REG_NONE, REG_A },
|
||||||
{ "decsp4", REG_NONE, REG_A },
|
{ "decsp4", REG_NONE, REG_A },
|
||||||
{ "decsp5", REG_NONE, REG_A },
|
{ "decsp5", REG_NONE, REG_A },
|
||||||
{ "decsp6", REG_NONE, REG_A },
|
{ "decsp6", REG_NONE, REG_A },
|
||||||
{ "decsp7", REG_NONE, REG_A },
|
{ "decsp7", REG_NONE, REG_A },
|
||||||
{ "decsp8", REG_NONE, REG_A },
|
{ "decsp8", REG_NONE, REG_A },
|
||||||
{ "incsp1", REG_NONE, REG_NONE },
|
{ "incsp1", REG_NONE, REG_NONE },
|
||||||
{ "incsp2", REG_NONE, REG_Y },
|
{ "incsp2", REG_NONE, REG_Y },
|
||||||
{ "incsp3", REG_NONE, REG_Y },
|
{ "incsp3", REG_NONE, REG_Y },
|
||||||
{ "incsp4", REG_NONE, REG_Y },
|
{ "incsp4", REG_NONE, REG_Y },
|
||||||
{ "incsp5", REG_NONE, REG_Y },
|
{ "incsp5", REG_NONE, REG_Y },
|
||||||
{ "incsp6", REG_NONE, REG_Y },
|
{ "incsp6", REG_NONE, REG_Y },
|
||||||
{ "incsp7", REG_NONE, REG_Y },
|
{ "incsp7", REG_NONE, REG_Y },
|
||||||
{ "incsp8", REG_NONE, REG_Y },
|
{ "incsp8", REG_NONE, REG_Y },
|
||||||
{ "ldax0sp", REG_Y, REG_AX },
|
{ "ldax0sp", REG_Y, REG_AX },
|
||||||
{ "ldaxysp", REG_Y, REG_AX },
|
{ "ldaxysp", REG_Y, REG_AX },
|
||||||
{ "pusha", REG_A, REG_Y },
|
{ "pusha", REG_A, REG_Y },
|
||||||
{ "pusha0", REG_A, REG_XY },
|
{ "pusha0", REG_A, REG_XY },
|
||||||
{ "pushax", REG_AX, REG_Y },
|
{ "pushax", REG_AX, REG_Y },
|
||||||
{ "pushw0sp", REG_NONE, REG_AXY },
|
{ "pushw0sp", REG_NONE, REG_AXY },
|
||||||
{ "pushwysp", REG_Y, REG_AXY },
|
{ "pushwysp", REG_Y, REG_AXY },
|
||||||
{ "tosicmp", REG_AX, REG_AXY },
|
{ "tosicmp", REG_AX, REG_AXY },
|
||||||
};
|
};
|
||||||
#define FuncInfoCount (sizeof(FuncInfoTable) / sizeof(FuncInfoTable[0]))
|
#define FuncInfoCount (sizeof(FuncInfoTable) / sizeof(FuncInfoTable[0]))
|
||||||
|
|
||||||
/* Table with names of zero page locations used by the compiler */
|
/* Table with names of zero page locations used by the compiler */
|
||||||
static const char* ZPNameTable[] = {
|
typedef struct ZPInfo ZPInfo;
|
||||||
"ptr1", "regbank", "regsave", "sp", "sreg", "tmp1"
|
struct ZPInfo {
|
||||||
|
unsigned char Len; /* Length of the following string */
|
||||||
|
char Name[11]; /* Name of zero page symbol */
|
||||||
};
|
};
|
||||||
#define ZPNameCount (sizeof(ZPNameTable) / sizeof(ZPNameTable[0]))
|
static const ZPInfo ZPInfoTable[] = {
|
||||||
|
{ 4, "ptr1" },
|
||||||
|
{ 7, "regbank" },
|
||||||
|
{ 7, "regsave" },
|
||||||
|
{ 2, "sp" },
|
||||||
|
{ 4, "sreg" },
|
||||||
|
{ 4, "tmp1" },
|
||||||
|
};
|
||||||
|
#define ZPInfoCount (sizeof(ZPInfoTable) / sizeof(ZPInfoTable[0]))
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Code */
|
/* Code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@ -207,10 +217,12 @@ int IsZPName (const char* Name)
|
|||||||
/* Return true if the given name is a zero page symbol */
|
/* Return true if the given name is a zero page symbol */
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
|
const ZPInfo* Info;
|
||||||
|
|
||||||
/* Because of the low number of symbols, we do a linear search here */
|
/* Because of the low number of symbols, we do a linear search here */
|
||||||
for (I = 0; I < ZPNameCount; ++I) {
|
for (I = 0, Info = ZPInfoTable; I < ZPInfoCount; ++I, ++Info) {
|
||||||
if (strcmp (Name, ZPNameTable[I]) == 0) {
|
if (strncmp (Name, Info->Name, Info->Len) == 0 &&
|
||||||
|
(Name[Info->Len] == '\0' || Name[Info->Len] == '+')) {
|
||||||
/* Found */
|
/* Found */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user