1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-07 15:25:31 +00:00

65C02 additions, saved a few bytes in the code generator

git-svn-id: svn://svn.cc65.org/cc65/trunk@80 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-06-14 16:58:52 +00:00
parent 409d12534b
commit 500233166a
2 changed files with 147 additions and 115 deletions

View File

@@ -790,8 +790,12 @@ void g_getlocal (unsigned flags, int offs)
case CF_CHAR:
if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
if (CPU == CPU_65C02 && offs == 0) {
AddCodeLine ("\tlda\t(sp)");
} else {
ldyconst (offs);
AddCodeLine ("\tlda\t(sp),y");
}
} else {
if (offs == 0) {
AddCodeLine ("\tldx\t#$00");
@@ -1004,8 +1008,12 @@ void g_putlocal (unsigned flags, int offs)
switch (flags & CF_TYPE) {
case CF_CHAR:
if (CPU == CPU_65C02 && offs == 0) {
AddCodeLine ("\tsta\t(sp)");
} else {
ldyconst (offs);
AddCodeLine ("\tsta\t(sp),y");
}
break;
case CF_INT:
@@ -3741,8 +3749,8 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs)
AddCodeLine ("\tiny");
AddCodeLine ("\tlda\t%s,y", lbuf);
AddCodeLine ("\tbne\tL%04X", label);
AddCodeLine ("\ttax");
AddCodeLine ("\ttya");
AddCodeLine ("\tldx\t#$00");
} else {
@@ -3759,8 +3767,8 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs)
AddCodeLine ("\tiny");
AddCodeLine ("\tlda\t(ptr1),y");
AddCodeLine ("\tbne\tL%04X", label);
AddCodeLine ("\ttax");
AddCodeLine ("\ttya");
AddCodeLine ("\tldx\t#$00");
}
}
}

View File

@@ -1103,7 +1103,7 @@ static unsigned RVUInt2 (Line* L,
do {
/* Handle jumps to local labels (continue there) */
if (LineMatch (L, "\tjmp\tL")) {
if (LineMatch (L, "\tjmp\tL") || LineMatch (L, "\tbra\tL")) {
/* Get the target of the jump */
L = GetTargetLine (L->Line+5);
}
@@ -1124,7 +1124,7 @@ static unsigned RVUInt2 (Line* L,
goto ExitPoint;
}
} while (LineMatch (L, "\tjmp\tL"));
} while (LineMatch (L, "\tjmp\tL") || LineMatch (L, "\tbra\tL"));
/* Special handling for branches */
if (LineMatchX (L, ShortBranches) >= 0 ||
@@ -3867,6 +3867,10 @@ static Line* OptOneBlock (Line* L)
} else if (LineFullMatch (L, "\tjsr\tpushax")) {
/* We know about this function */
Y = 1;
} else if (LineFullMatch (L, "\tjsr\tpushaysp")) {
/* We know about this function */
A = -1;
Y = 0;
} else if (LineFullMatch (L, "\tjsr\tpushc0")) {
/* We know about this function */
A = 0;
@@ -4196,6 +4200,26 @@ static void OptJumps (void)
}
L = NextCodeLine (L);
}
/* Special treatment for jumps on the 65C02 */
if (CPU == CPU_65C02) {
Line* L = FirstCode;
while (L) {
if (LineMatch (L, "\tjmp\tL")) {
Line* Target = GetTargetLine (L->Line+5);
unsigned Distance = GetJumpDistance (L, Target);
if (Distance < 123) { /* Safety */
L->Line [1] = 'b'; /* Make a short branch */
L->Line [2] = 'r';
L->Line [3] = 'a';
L->Size = 2; /* Set new size */
}
}
L = NextCodeLine (L);
}
}
}