AddCodeLine ("\tsta\tsreg+1");
AddCodeLine ("\tsta\tsreg");
AddCodeLine ("\tldx\t#$%02X", (unsigned char) (val >> 8));
- } else if ((val & 0xFFFF0000) == 0 && FavourSize == 0) {
+ } else if ((val & 0xFFFF0000) == 0 && CodeSizeFactor > 140) {
AddCodeLine ("\tlda\t#$00");
AddCodeLine ("\tsta\tsreg+1");
AddCodeLine ("\tsta\tsreg");
AddCodeLine ("\tdey");
AddCodeLine ("\tora\t(sp),y");
} else {
- if (FavourSize) {
+ if (CodeSizeFactor > 180) {
+ ldyconst (offs + 1);
+ AddCodeLine ("\tlda\t(sp),y");
+ AddCodeLine ("\ttax");
+ AddCodeLine ("\tdey");
+ AddCodeLine ("\tlda\t(sp),y");
+ } else {
if (offs) {
ldyconst (offs+1);
AddCodeLine ("\tjsr\tldaxysp");
} else {
AddCodeLine ("\tjsr\tldax0sp");
}
- } else {
- ldyconst (offs + 1);
- AddCodeLine ("\tlda\t(sp),y");
- AddCodeLine ("\ttax");
- AddCodeLine ("\tdey");
- AddCodeLine ("\tlda\t(sp),y");
}
}
break;
}
} else {
if (flags & CF_UNSIGNED) {
- if (FavourSize) {
- AddCodeLine ("\tjsr\tldaui");
- } else {
+ if (CodeSizeFactor > 250) {
AddCodeLine ("\tsta\tptr1");
AddCodeLine ("\tstx\tptr1+1");
AddCodeLine ("\tldx\t#$00");
AddCodeLine ("\tlda\t(ptr1,x)");
+ } else {
+ AddCodeLine ("\tjsr\tldaui");
}
} else {
AddCodeLine ("\tjsr\tldai");
AddCodeLine ("\tlda\tsp");
AddCodeLine ("\tldx\tsp+1");
} else {
- if (FavourSize) {
+ if (CodeSizeFactor < 300) {
ldaconst (offs); /* Load A with offset value */
AddCodeLine ("\tjsr\tleaasp"); /* Load effective address */
} else {
if (CPU == CPU_65C02 && offs == 1) {
AddCodeLine ("\tlda\tsp");
AddCodeLine ("\tldx\tsp+1");
- AddCodeLine ("\tina");
+ AddCodeLine ("\tina");
AddCodeLine ("\tbne\t*+3");
AddCodeLine ("\tinx");
AddCodeHint ("x:!"); /* Invalidate X */
AddCodeLine ("\tsta\t(sp),y");
}
} else {
- if ((Flags & CF_NOKEEP) == 0 || FavourSize) {
+ if ((Flags & CF_NOKEEP) == 0 || CodeSizeFactor < 160) {
if (Offs) {
ldyconst (Offs);
AddCodeLine ("\tjsr\tstaxysp");
case CF_CHAR:
case CF_INT:
if (flags & CF_UNSIGNED) {
- if (FavourSize) {
- AddCodeLine ("\tjsr\taxulong");
- } else {
+ if (CodeSizeFactor >= 200) {
ldyconst (0);
AddCodeLine ("\tsty\tsreg");
AddCodeLine ("\tsty\tsreg+1");
+ } else {
+ AddCodeLine ("\tjsr\taxulong");
}
} else {
AddCodeLine ("\tjsr\taxlong");
/* FALLTHROUGH */
case CF_INT:
- if (FavourSize || p2 >= 3) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("\tjsr\tshlax%d", p2);
- } else {
- AddCodeLine ("\tjsr\taslax%d", p2);
- }
- } else {
+ if (CodeSizeFactor >= (p2+1)*130U) {
AddCodeLine ("\tstx\ttmp1");
while (p2--) {
AddCodeLine ("\tasl\ta");
AddCodeLine ("\trol\ttmp1");
}
AddCodeLine ("\tldx\ttmp1");
+ } else {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("\tjsr\tshlax%d", p2);
+ } else {
+ AddCodeLine ("\tjsr\taslax%d", p2);
+ }
}
break;
case CF_INT:
if (flags & CF_UNSIGNED) {
- if (FavourSize || p2 >= 3) {
- AddCodeLine ("\tjsr\tlsrax%d", p2);
- } else {
+ if (CodeSizeFactor >= (p2+1)*130U) {
AddCodeLine ("\tstx\ttmp1");
while (p2--) {
AddCodeLine ("\tlsr\ttmp1");
AddCodeLine ("\tror\ta");
}
AddCodeLine ("\tldx\ttmp1");
+ } else {
+ AddCodeLine ("\tjsr\tlsrax%d", p2);
}
} else {
- if (FavourSize || p2 >= 3) {
- AddCodeLine ("\tjsr\tasrax%d", p2);
- } else {
+ if (CodeSizeFactor >= (p2+1)*150U) {
AddCodeLine ("\tstx\ttmp1");
while (p2--) {
AddCodeLine ("\tcpx\t#$80");
AddCodeLine ("\tror\ta");
}
AddCodeLine ("\tldx\ttmp1");
+ } else {
+ AddCodeLine ("\tjsr\tasrax%d", p2);
}
}
break;
break;
case CF_INT:
- if (!FavourSize) {
+ if (CodeSizeFactor >= 200) {
/* Lots of code, use only if size is not important */
AddCodeLine ("\tsta\tptr1");
AddCodeLine ("\tstx\tptr1+1");
break;
case CF_INT:
- if (!FavourSize) {
+ if (CodeSizeFactor >= 200) {
/* Lots of code, use only if size is not important */
AddCodeLine ("\tsta\tptr1");
AddCodeLine ("\tstx\tptr1+1");
if ((flags & CF_TYPE) == CF_CHAR && (flags & CF_FORCECHAR)) {
/* Handle as 8 bit value */
- if (FavourSize && val <= 2) {
- AddCodeLine ("\tjsr\tpushc%d", (int) val);
- } else {
+ if (CodeSizeFactor >= 165 || val > 2) {
ldaconst (val);
AddCodeLine ("\tjsr\tpusha");
+ } else {
+ AddCodeLine ("\tjsr\tpushc%d", (int) val);
}
} else {
AddCodeLine ("\tinx");
/* Tell the optimizer that the X register may be invalid */
AddCodeHint ("x:!");
- } else if (FavourSize) {
+ } else if (CodeSizeFactor < 200) {
/* Use jsr calls */
if (val <= 8) {
AddCodeLine ("\tjsr\tincax%lu", val);
if (val < 0x300) {
if ((val & 0xFF) != 0) {
AddCodeLine ("\tclc");
- AddCodeLine ("\tadc\t#$%02X", (unsigned char) val);
- AddCodeLine ("\tbcc\t*+3");
- AddCodeLine ("\tinx");
- /* Tell the optimizer that the X register may be invalid */
+ AddCodeLine ("\tadc\t#$%02X", (unsigned char) val);
+ AddCodeLine ("\tbcc\t*+3");
+ AddCodeLine ("\tinx");
+ /* Tell the optimizer that the X register may be invalid */
AddCodeHint ("x:!");
}
if (val >= 0x100) {
- AddCodeLine ("\tinx");
+ AddCodeLine ("\tinx");
}
if (val >= 0x200) {
- AddCodeLine ("\tinx");
+ AddCodeLine ("\tinx");
}
} else {
AddCodeLine ("\tclc");
if ((val & 0xFF) != 0) {
- AddCodeLine ("\tadc\t#$%02X", (unsigned char) val);
- /* Tell the optimizer that the X register may be invalid */
- AddCodeHint ("x:!");
+ AddCodeLine ("\tadc\t#$%02X", (unsigned char) val);
+ /* Tell the optimizer that the X register may be invalid */
+ AddCodeHint ("x:!");
}
AddCodeLine ("\tpha");
AddCodeLine ("\ttxa");
} else {
/* Address not constant but in primary */
- if (FavourSize) {
+ if (CodeSizeFactor < 400) {
/* This is too much code, so call strlen instead of inlining */
AddCodeLine ("\tjsr\t_strlen");
} else {
" --bss-name seg\tSet the name of the BSS segment\n"
" --check-stack\t\tGenerate stack overflow checks\n"
" --code-name seg\tSet the name of the CODE segment\n"
+ " --codesize x\tAccept larger code by factor x\n"
" --cpu type\t\tSet cpu type\n"
" --data-name seg\tSet the name of the DATA segment\n"
" --debug\t\tDebug mode\n"
+static void OptCodeSize (const char* Opt, const char* Arg)
+/* Handle the --codesize option */
+{
+ /* Numeric argument expected */
+ if (sscanf (Arg, "%u", &CodeSizeFactor) != 1 ||
+ CodeSizeFactor < 100 ||
+ CodeSizeFactor > 1000) {
+ AbEnd ("Argument for %s is invalid", Opt);
+ }
+}
+
+
+
static void OptCreateDep (const char* Opt, const char* Arg)
/* Handle the --create-dep option */
{
{
/* Program long options */
static const LongOpt OptTab[] = {
- { "--add-source", 0, OptAddSource },
- { "--ansi", 0, OptAnsi },
- { "--bss-name", 1, OptBssName },
+ { "--add-source", 0, OptAddSource },
+ { "--ansi", 0, OptAnsi },
+ { "--bss-name", 1, OptBssName },
{ "--check-stack", 0, OptCheckStack },
- { "--code-name", 1, OptCodeName },
- { "--create-dep", 0, OptCreateDep },
- { "--cpu", 1, OptCPU },
- { "--data-name", 1, OptDataName },
- { "--debug", 0, OptDebug },
- { "--debug-info", 0, OptDebugInfo },
- { "--help", 0, OptHelp },
+ { "--code-name", 1, OptCodeName },
+ { "--codesize", 1, OptCodeSize },
+ { "--create-dep", 0, OptCreateDep },
+ { "--cpu", 1, OptCPU },
+ { "--data-name", 1, OptDataName },
+ { "--debug", 0, OptDebug },
+ { "--debug-info", 0, OptDebugInfo },
+ { "--help", 0, OptHelp },
{ "--include-dir", 1, OptIncludeDir },
{ "--rodata-name", 1, OptRodataName },
{ "--signed-chars", 0, OptSignedChars },
{ "--static-locals", 0, OptStaticLocals },
- { "--target", 1, OptTarget },
- { "--verbose", 0, OptVerbose },
- { "--version", 0, OptVersion },
+ { "--target", 1, OptTarget },
+ { "--verbose", 0, OptVerbose },
+ { "--version", 0, OptVersion },
};
int I;
break;
case 'i':
FavourSize = 0;
+ CodeSizeFactor = 200;
break;
case 'r':
EnableRegVars = 1;