- if (FavourSize) {
- 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 ("\tbne\t*+3");
- AddCodeLine ("\tinx");
- AddCodeHint ("x:!"); /* Invalidate X */
- } else {
- ldaconst (offs);
- AddCodeLine ("\tclc");
- AddCodeLine ("\tldx\tsp+1");
- AddCodeLine ("\tadc\tsp");
- AddCodeLine ("\tbcc\t*+3");
- AddCodeLine ("\tinx");
- AddCodeHint ("x:!"); /* Invalidate X */
- }
- }
+ if (CodeSizeFactor < 300) {
+ ldaconst (offs); /* Load A with offset value */
+ AddCodeLine ("jsr leaasp"); /* Load effective address */
+ } else {
+ unsigned L = GetLocalLabel ();
+ if (CPU == CPU_65C02 && offs == 1) {
+ AddCodeLine ("lda sp");
+ AddCodeLine ("ldx sp+1");
+ AddCodeLine ("ina");
+ AddCodeLine ("bne %s", LocalLabelName (L));
+ AddCodeLine ("inx");
+ } else {
+ ldaconst (offs);
+ AddCodeLine ("clc");
+ AddCodeLine ("ldx sp+1");
+ AddCodeLine ("adc sp");
+ AddCodeLine ("bcc %s", LocalLabelName (L));
+ AddCodeLine ("inx");
+ }
+ g_defcodelabel (L);
+ }
+ }
+}
+
+
+
+void g_leavariadic (int Offs)
+/* Fetch the address of a parameter in a variadic function into the primary
+ * register
+ */
+{
+ unsigned ArgSizeOffs;
+
+ /* Calculate the offset relative to sp */
+ Offs -= oursp;
+
+ /* Get the offset of the parameter which is stored at sp+0 on function
+ * entry and check if this offset is reachable with a byte offset.
+ */
+ CHECK (oursp <= 0);
+ ArgSizeOffs = -oursp;
+ CheckLocalOffs (ArgSizeOffs);
+
+ /* Get the size of all parameters. */
+ if (ArgSizeOffs == 0 && CPU == CPU_65C02) {
+ AddCodeLine ("lda (sp)");
+ } else {
+ ldyconst (ArgSizeOffs);
+ AddCodeLine ("lda (sp),y");
+ }
+
+ /* Add the value of the stackpointer */
+ if (CodeSizeFactor > 250) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("ldx sp+1");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc sp");
+ AddCodeLine ("bcc %s", LocalLabelName (L));
+ AddCodeLine ("inx");
+ g_defcodelabel (L);
+ } else {
+ AddCodeLine ("jsr leaasp");
+ }
+
+ /* Add the offset to the primary */
+ if (Offs > 0) {
+ g_inc (CF_INT | CF_CONST, Offs);
+ } else if (Offs < 0) {
+ g_dec (CF_INT | CF_CONST, -Offs);