- case CF_STATIC:
- /* Static memory cell */
- if (Offs) {
- xsprintf (Buf, sizeof (Buf), "%s%+ld", LocalLabelName (Label), Offs);
- } else {
- xsprintf (Buf, sizeof (Buf), "%s", LocalLabelName (Label));
- }
- break;
-
- case CF_EXTERNAL:
- /* External label */
- if (Offs) {
- xsprintf (Buf, sizeof (Buf), "_%s%+ld", (char*) Label, Offs);
- } else {
- xsprintf (Buf, sizeof (Buf), "_%s", (char*) Label);
- }
- break;
-
- case CF_ABSOLUTE:
- /* Absolute address */
- xsprintf (Buf, sizeof (Buf), "$%04X", (int)((Label+Offs) & 0xFFFF));
- break;
-
- case CF_REGVAR:
- /* Variable in register bank */
- xsprintf (Buf, sizeof (Buf), "regbank+%u", (unsigned)((Label+Offs) & 0xFFFF));
- break;
-
- default:
- Internal ("Invalid address flags: %04X", Flags);
+ case CF_STATIC:
+ /* Static memory cell */
+ if (Offs) {
+ xsprintf (Buf, sizeof (Buf), "%s%+ld", LocalLabelName (Label), Offs);
+ } else {
+ xsprintf (Buf, sizeof (Buf), "%s", LocalLabelName (Label));
+ }
+ break;
+
+ case CF_EXTERNAL:
+ /* External label */
+ if (Offs) {
+ xsprintf (Buf, sizeof (Buf), "_%s%+ld", (char*) Label, Offs);
+ } else {
+ xsprintf (Buf, sizeof (Buf), "_%s", (char*) Label);
+ }
+ break;
+
+ case CF_ABSOLUTE:
+ /* Absolute address */
+ xsprintf (Buf, sizeof (Buf), "$%04X", (int)((Label+Offs) & 0xFFFF));
+ break;
+
+ case CF_REGVAR:
+ /* Variable in register bank */
+ xsprintf (Buf, sizeof (Buf), "regbank+%u", (unsigned)((Label+Offs) & 0xFFFF));
+ break;
+
+ default:
+ Internal ("Invalid address flags: %04X", Flags);
- ldyconst (StackOffs);
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("sta regbank%+d", RegOffs);
- AddCodeLine ("iny");
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("sta regbank%+d", RegOffs+1);
-
- } else if (Bytes == 3 && CodeSizeFactor >= 133) {
-
- ldyconst (StackOffs);
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("sta regbank%+d", RegOffs);
- AddCodeLine ("iny");
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("sta regbank%+d", RegOffs+1);
- AddCodeLine ("iny");
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("sta regbank%+d", RegOffs+2);
+ ldyconst (StackOffs);
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta regbank%+d", RegOffs);
+ AddCodeLine ("iny");
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta regbank%+d", RegOffs+1);
+
+ } else if (Bytes == 3 && IS_Get (&CodeSizeFactor) >= 133) {
+
+ ldyconst (StackOffs);
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta regbank%+d", RegOffs);
+ AddCodeLine ("iny");
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta regbank%+d", RegOffs+1);
+ AddCodeLine ("iny");
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta regbank%+d", RegOffs+2);
- /* Numeric constant */
- switch (Flags & CF_TYPE) {
-
- case CF_CHAR:
- if ((Flags & CF_FORCECHAR) != 0) {
- ldaconst (Val);
- break;
- }
- /* FALL THROUGH */
- case CF_INT:
- ldxconst ((Val >> 8) & 0xFF);
- ldaconst (Val & 0xFF);
- break;
-
- case CF_LONG:
- /* Split the value into 4 bytes */
- B1 = (unsigned char) (Val >> 0);
- B2 = (unsigned char) (Val >> 8);
- B3 = (unsigned char) (Val >> 16);
- B4 = (unsigned char) (Val >> 24);
-
- /* Remember which bytes are done */
- Done = 0;
-
- /* Load the value */
- AddCodeLine ("ldx #$%02X", B2);
- Done |= 0x02;
- if (B2 == B3) {
- AddCodeLine ("stx sreg");
- Done |= 0x04;
- }
- if (B2 == B4) {
- AddCodeLine ("stx sreg+1");
- Done |= 0x08;
- }
- if ((Done & 0x04) == 0 && B1 != B3) {
- AddCodeLine ("lda #$%02X", B3);
- AddCodeLine ("sta sreg");
- Done |= 0x04;
- }
- if ((Done & 0x08) == 0 && B1 != B4) {
- AddCodeLine ("lda #$%02X", B4);
- AddCodeLine ("sta sreg+1");
- Done |= 0x08;
- }
- AddCodeLine ("lda #$%02X", B1);
- Done |= 0x01;
- if ((Done & 0x04) == 0) {
- CHECK (B1 == B3);
- AddCodeLine ("sta sreg");
- }
- if ((Done & 0x08) == 0) {
- CHECK (B1 == B4);
- AddCodeLine ("sta sreg+1");
- }
- break;
-
- default:
- typeerror (Flags);
- break;
-
- }
+ /* Numeric constant */
+ switch (Flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if ((Flags & CF_FORCECHAR) != 0) {
+ ldaconst (Val);
+ break;
+ }
+ /* FALL THROUGH */
+ case CF_INT:
+ ldxconst ((Val >> 8) & 0xFF);
+ ldaconst (Val & 0xFF);
+ break;
+
+ case CF_LONG:
+ /* Split the value into 4 bytes */
+ B1 = (unsigned char) (Val >> 0);
+ B2 = (unsigned char) (Val >> 8);
+ B3 = (unsigned char) (Val >> 16);
+ B4 = (unsigned char) (Val >> 24);
+
+ /* Remember which bytes are done */
+ Done = 0;
+
+ /* Load the value */
+ AddCodeLine ("ldx #$%02X", B2);
+ Done |= 0x02;
+ if (B2 == B3) {
+ AddCodeLine ("stx sreg");
+ Done |= 0x04;
+ }
+ if (B2 == B4) {
+ AddCodeLine ("stx sreg+1");
+ Done |= 0x08;
+ }
+ if ((Done & 0x04) == 0 && B1 != B3) {
+ AddCodeLine ("lda #$%02X", B3);
+ AddCodeLine ("sta sreg");
+ Done |= 0x04;
+ }
+ if ((Done & 0x08) == 0 && B1 != B4) {
+ AddCodeLine ("lda #$%02X", B4);
+ AddCodeLine ("sta sreg+1");
+ Done |= 0x08;
+ }
+ AddCodeLine ("lda #$%02X", B1);
+ Done |= 0x01;
+ if ((Done & 0x04) == 0) {
+ CHECK (B1 == B3);
+ AddCodeLine ("sta sreg");
+ }
+ if ((Done & 0x08) == 0) {
+ CHECK (B1 == B4);
+ AddCodeLine ("sta sreg+1");
+ }
+ break;
+
+ default:
+ typeerror (Flags);
+ break;
+
+ }
- case CF_CHAR:
- if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
- AddCodeLine ("lda %s", lbuf); /* load A from the label */
- } else {
- ldxconst (0);
- AddCodeLine ("lda %s", lbuf); /* load A from the label */
- if (!(flags & CF_UNSIGNED)) {
- /* Must sign extend */
- unsigned L = GetLocalLabel ();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- }
- break;
-
- case CF_INT:
- AddCodeLine ("lda %s", lbuf);
- if (flags & CF_TEST) {
- AddCodeLine ("ora %s+1", lbuf);
- } else {
- AddCodeLine ("ldx %s+1", lbuf);
- }
- break;
-
- case CF_LONG:
- if (flags & CF_TEST) {
- AddCodeLine ("lda %s+3", lbuf);
- AddCodeLine ("ora %s+2", lbuf);
- AddCodeLine ("ora %s+1", lbuf);
- AddCodeLine ("ora %s+0", lbuf);
- } else {
- AddCodeLine ("lda %s+3", lbuf);
- AddCodeLine ("sta sreg+1");
- AddCodeLine ("lda %s+2", lbuf);
- AddCodeLine ("sta sreg");
- AddCodeLine ("ldx %s+1", lbuf);
- AddCodeLine ("lda %s", lbuf);
- }
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
+ AddCodeLine ("lda %s", lbuf); /* load A from the label */
+ } else {
+ ldxconst (0);
+ AddCodeLine ("lda %s", lbuf); /* load A from the label */
+ if (!(flags & CF_UNSIGNED)) {
+ /* Must sign extend */
+ unsigned L = GetLocalLabel ();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ }
+ break;
+
+ case CF_INT:
+ AddCodeLine ("lda %s", lbuf);
+ if (flags & CF_TEST) {
+ AddCodeLine ("ora %s+1", lbuf);
+ } else {
+ AddCodeLine ("ldx %s+1", lbuf);
+ }
+ break;
+
+ case CF_LONG:
+ if (flags & CF_TEST) {
+ AddCodeLine ("lda %s+3", lbuf);
+ AddCodeLine ("ora %s+2", lbuf);
+ AddCodeLine ("ora %s+1", lbuf);
+ AddCodeLine ("ora %s+0", lbuf);
+ } else {
+ AddCodeLine ("lda %s+3", lbuf);
+ AddCodeLine ("sta sreg+1");
+ AddCodeLine ("lda %s+2", lbuf);
+ AddCodeLine ("sta sreg");
+ AddCodeLine ("ldx %s+1", lbuf);
+ AddCodeLine ("lda %s", lbuf);
+ }
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
- ldyconst (offs);
- AddCodeLine ("lda (sp),y");
- } else {
- ldyconst (offs);
- AddCodeLine ("ldx #$00");
- AddCodeLine ("lda (sp),y");
- if ((flags & CF_UNSIGNED) == 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- }
- break;
-
- case CF_INT:
- CheckLocalOffs (offs + 1);
- if (flags & CF_TEST) {
- ldyconst (offs + 1);
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("dey");
- AddCodeLine ("ora (sp),y");
- } else {
- ldyconst (offs+1);
- AddCodeLine ("jsr ldaxysp");
- }
- break;
-
- case CF_LONG:
- ldyconst (offs+3);
- AddCodeLine ("jsr ldeaxysp");
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
+ ldyconst (offs);
+ AddCodeLine ("lda (sp),y");
+ } else {
+ ldyconst (offs);
+ AddCodeLine ("ldx #$00");
+ AddCodeLine ("lda (sp),y");
+ if ((flags & CF_UNSIGNED) == 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ }
+ break;
+
+ case CF_INT:
+ CheckLocalOffs (offs + 1);
+ if (flags & CF_TEST) {
+ ldyconst (offs + 1);
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("dey");
+ AddCodeLine ("ora (sp),y");
+ } else {
+ ldyconst (offs+1);
+ AddCodeLine ("jsr ldaxysp");
+ }
+ break;
+
+ case CF_LONG:
+ ldyconst (offs+3);
+ AddCodeLine ("jsr ldeaxysp");
+ if (flags & CF_TEST) {
+ g_test (flags);
+ }
+ break;
+
+ default:
+ typeerror (flags);
- if (CodeSizeFactor < 300) {
- ldaconst (offs); /* Load A with offset value */
- AddCodeLine ("jsr leaasp"); /* Load effective address */
- } else {
- unsigned L = GetLocalLabel ();
- if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && 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);
- }
+ if (IS_Get (&CodeSizeFactor) < 300) {
+ ldaconst (offs); /* Load A with offset value */
+ AddCodeLine ("jsr leaasp"); /* Load effective address */
+ } else {
+ unsigned L = GetLocalLabel ();
+ if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && 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);
+ }
- case CF_CHAR:
- if (Flags & CF_CONST) {
- AddCodeLine ("lda #$%02X", (unsigned char) Val);
- }
- ldyconst (Offs);
- AddCodeLine ("sta (sp),y");
- break;
-
- case CF_INT:
- if (Flags & CF_CONST) {
- ldyconst (Offs+1);
- AddCodeLine ("lda #$%02X", (unsigned char) (Val >> 8));
- AddCodeLine ("sta (sp),y");
- if ((Flags & CF_NOKEEP) == 0) {
- /* Place high byte into X */
- AddCodeLine ("tax");
- }
- if ((Val & 0xFF) == Offs+1) {
- /* The value we need is already in Y */
- AddCodeLine ("tya");
- AddCodeLine ("dey");
- } else {
- AddCodeLine ("dey");
- AddCodeLine ("lda #$%02X", (unsigned char) Val);
- }
- AddCodeLine ("sta (sp),y");
- } else {
- if ((Flags & CF_NOKEEP) == 0 || CodeSizeFactor < 160) {
- ldyconst (Offs);
- AddCodeLine ("jsr staxysp");
- } else {
- ldyconst (Offs);
- AddCodeLine ("sta (sp),y");
- AddCodeLine ("iny");
- AddCodeLine ("txa");
- AddCodeLine ("sta (sp),y");
- }
- }
- break;
-
- case CF_LONG:
- if (Flags & CF_CONST) {
- g_getimmed (Flags, Val, 0);
- }
- ldyconst (Offs);
- AddCodeLine ("jsr steaxysp");
- break;
-
- default:
- typeerror (Flags);
+ case CF_CHAR:
+ if (Flags & CF_CONST) {
+ AddCodeLine ("lda #$%02X", (unsigned char) Val);
+ }
+ ldyconst (Offs);
+ AddCodeLine ("sta (sp),y");
+ break;
+
+ case CF_INT:
+ if (Flags & CF_CONST) {
+ ldyconst (Offs+1);
+ AddCodeLine ("lda #$%02X", (unsigned char) (Val >> 8));
+ AddCodeLine ("sta (sp),y");
+ if ((Flags & CF_NOKEEP) == 0) {
+ /* Place high byte into X */
+ AddCodeLine ("tax");
+ }
+ if ((Val & 0xFF) == Offs+1) {
+ /* The value we need is already in Y */
+ AddCodeLine ("tya");
+ AddCodeLine ("dey");
+ } else {
+ AddCodeLine ("dey");
+ AddCodeLine ("lda #$%02X", (unsigned char) Val);
+ }
+ AddCodeLine ("sta (sp),y");
+ } else {
+ if ((Flags & CF_NOKEEP) == 0 || IS_Get (&CodeSizeFactor) < 160) {
+ ldyconst (Offs);
+ AddCodeLine ("jsr staxysp");
+ } else {
+ ldyconst (Offs);
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("iny");
+ AddCodeLine ("txa");
+ AddCodeLine ("sta (sp),y");
+ }
+ }
+ break;
+
+ case CF_LONG:
+ if (Flags & CF_CONST) {
+ g_getimmed (Flags, Val, 0);
+ }
+ ldyconst (Offs);
+ AddCodeLine ("jsr steaxysp");
+ break;
+
+ default:
+ typeerror (Flags);
- /* Overflow - we need to add the low byte also */
- AddCodeLine ("ldy #$00");
- AddCodeLine ("clc");
- AddCodeLine ("pha");
- AddCodeLine ("lda #$%02X", Offs & 0xFF);
- AddCodeLine ("adc (sp),y");
- AddCodeLine ("sta (sp),y");
- AddCodeLine ("iny");
- AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF);
- AddCodeLine ("adc (sp),y");
- AddCodeLine ("sta (sp),y");
- AddCodeLine ("pla");
-
- /* Complete address is on stack, new offset is zero */
- Offs = 0;
+ /* Overflow - we need to add the low byte also */
+ AddCodeLine ("ldy #$00");
+ AddCodeLine ("clc");
+ AddCodeLine ("pha");
+ AddCodeLine ("lda #$%02X", Offs & 0xFF);
+ AddCodeLine ("adc (sp),y");
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("iny");
+ AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF);
+ AddCodeLine ("adc (sp),y");
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("pla");
+
+ /* Complete address is on stack, new offset is zero */
+ Offs = 0;
- /* Scale up */
- if ((p2 = powerof2 (val)) > 0 && p2 <= 4) {
-
- /* Factor is 2, 4, 8 and 16, use special function */
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- while (p2--) {
- AddCodeLine ("asl a");
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (CodeSizeFactor >= (p2+1)*130U) {
- AddCodeLine ("stx tmp1");
- while (p2--) {
- AddCodeLine ("asl a");
- AddCodeLine ("rol tmp1");
- }
- AddCodeLine ("ldx tmp1");
- } else {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shlax%d", p2);
- } else {
- AddCodeLine ("jsr aslax%d", p2);
- }
- }
- break;
-
- case CF_LONG:
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shleax%d", p2);
- } else {
- AddCodeLine ("jsr asleax%d", p2);
- }
- break;
-
- default:
- typeerror (flags);
-
- }
-
- } else if (val != 1) {
-
- /* Use a multiplication instead */
- g_mul (flags | CF_CONST, val);
-
- }
+ /* Scale up */
+ if ((p2 = PowerOf2 (val)) > 0 && p2 <= 4) {
+
+ /* Factor is 2, 4, 8 and 16, use special function */
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ while (p2--) {
+ AddCodeLine ("asl a");
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (IS_Get (&CodeSizeFactor) >= (p2+1)*130) {
+ AddCodeLine ("stx tmp1");
+ while (p2--) {
+ AddCodeLine ("asl a");
+ AddCodeLine ("rol tmp1");
+ }
+ AddCodeLine ("ldx tmp1");
+ } else {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shlax%d", p2);
+ } else {
+ AddCodeLine ("jsr aslax%d", p2);
+ }
+ }
+ break;
+
+ case CF_LONG:
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shleax%d", p2);
+ } else {
+ AddCodeLine ("jsr asleax%d", p2);
+ }
+ break;
+
+ default:
+ typeerror (flags);
+
+ }
+
+ } else if (val != 1) {
+
+ /* Use a multiplication instead */
+ g_mul (flags | CF_CONST, val);
+
+ }
- /* Scale down */
- val = -val;
- if ((p2 = powerof2 (val)) > 0 && p2 <= 4) {
-
- /* Factor is 2, 4, 8 and 16 use special function */
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- if (flags & CF_UNSIGNED) {
- while (p2--) {
- AddCodeLine ("lsr a");
- }
- break;
- } else if (p2 <= 2) {
- AddCodeLine ("cmp #$80");
- AddCodeLine ("ror a");
- break;
- }
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (flags & CF_UNSIGNED) {
- if (CodeSizeFactor >= (p2+1)*130U) {
- AddCodeLine ("stx tmp1");
- while (p2--) {
- AddCodeLine ("lsr tmp1");
- AddCodeLine ("ror a");
- }
- AddCodeLine ("ldx tmp1");
- } else {
- AddCodeLine ("jsr lsrax%d", p2);
- }
- } else {
- if (CodeSizeFactor >= (p2+1)*150U) {
- AddCodeLine ("stx tmp1");
- while (p2--) {
- AddCodeLine ("cpx #$80");
- AddCodeLine ("ror tmp1");
- AddCodeLine ("ror a");
- }
- AddCodeLine ("ldx tmp1");
- } else {
- AddCodeLine ("jsr asrax%d", p2);
- }
- }
- break;
-
- case CF_LONG:
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr lsreax%d", p2);
- } else {
- AddCodeLine ("jsr asreax%d", p2);
- }
- break;
-
- default:
- typeerror (flags);
-
- }
-
- } else if (val != 1) {
-
- /* Use a division instead */
- g_div (flags | CF_CONST, val);
-
- }
+ /* Scale down */
+ val = -val;
+ if ((p2 = PowerOf2 (val)) > 0 && p2 <= 4) {
+
+ /* Factor is 2, 4, 8 and 16 use special function */
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ if (flags & CF_UNSIGNED) {
+ while (p2--) {
+ AddCodeLine ("lsr a");
+ }
+ break;
+ } else if (p2 <= 2) {
+ AddCodeLine ("cmp #$80");
+ AddCodeLine ("ror a");
+ break;
+ }
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (flags & CF_UNSIGNED) {
+ if (IS_Get (&CodeSizeFactor) >= (p2+1)*130) {
+ AddCodeLine ("stx tmp1");
+ while (p2--) {
+ AddCodeLine ("lsr tmp1");
+ AddCodeLine ("ror a");
+ }
+ AddCodeLine ("ldx tmp1");
+ } else {
+ AddCodeLine ("jsr lsrax%d", p2);
+ }
+ } else {
+ if (IS_Get (&CodeSizeFactor) >= (p2+1)*150) {
+ AddCodeLine ("stx tmp1");
+ while (p2--) {
+ AddCodeLine ("cpx #$80");
+ AddCodeLine ("ror tmp1");
+ AddCodeLine ("ror a");
+ }
+ AddCodeLine ("ldx tmp1");
+ } else {
+ AddCodeLine ("jsr asrax%d", p2);
+ }
+ }
+ break;
+
+ case CF_LONG:
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr lsreax%d", p2);
+ } else {
+ AddCodeLine ("jsr asreax%d", p2);
+ }
+ break;
+
+ default:
+ typeerror (flags);
+
+ }
+
+ } else if (val != 1) {
+
+ /* Use a division instead */
+ g_div (flags | CF_CONST, val);
+
+ }
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- AddCodeLine ("ldx #$00");
- if (flags & CF_CONST) {
- if (val == 1) {
- AddCodeLine ("inc %s", lbuf);
- AddCodeLine ("lda %s", lbuf);
- } else {
- AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
- AddCodeLine ("clc");
- AddCodeLine ("adc %s", lbuf);
- AddCodeLine ("sta %s", lbuf);
- }
- } else {
- AddCodeLine ("clc");
- AddCodeLine ("adc %s", lbuf);
- AddCodeLine ("sta %s", lbuf);
- }
- if ((flags & CF_UNSIGNED) == 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (flags & CF_CONST) {
- if (val == 1) {
- unsigned L = GetLocalLabel ();
- AddCodeLine ("inc %s", lbuf);
- AddCodeLine ("bne %s", LocalLabelName (L));
- AddCodeLine ("inc %s+1", lbuf);
- g_defcodelabel (L);
- AddCodeLine ("lda %s", lbuf); /* Hmmm... */
- AddCodeLine ("ldx %s+1", lbuf);
- } else {
- AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
- AddCodeLine ("clc");
- AddCodeLine ("adc %s", lbuf);
- AddCodeLine ("sta %s", lbuf);
- if (val < 0x100) {
- unsigned L = GetLocalLabel ();
- AddCodeLine ("bcc %s", LocalLabelName (L));
- AddCodeLine ("inc %s+1", lbuf);
- g_defcodelabel (L);
- AddCodeLine ("ldx %s+1", lbuf);
- } else {
- AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8));
- AddCodeLine ("adc %s+1", lbuf);
- AddCodeLine ("sta %s+1", lbuf);
- AddCodeLine ("tax");
- AddCodeLine ("lda %s", lbuf);
- }
- }
- } else {
- AddCodeLine ("clc");
- AddCodeLine ("adc %s", lbuf);
- AddCodeLine ("sta %s", lbuf);
- AddCodeLine ("txa");
- AddCodeLine ("adc %s+1", lbuf);
- AddCodeLine ("sta %s+1", lbuf);
- AddCodeLine ("tax");
- AddCodeLine ("lda %s", lbuf);
- }
- break;
-
- case CF_LONG:
- if (flags & CF_CONST) {
- if (val < 0x100) {
- AddCodeLine ("ldy #<(%s)", lbuf);
- AddCodeLine ("sty ptr1");
- AddCodeLine ("ldy #>(%s)", lbuf);
- if (val == 1) {
- AddCodeLine ("jsr laddeq1");
- } else {
- AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
- AddCodeLine ("jsr laddeqa");
- }
- } else {
- g_getstatic (flags, label, offs);
- g_inc (flags, val);
- g_putstatic (flags, label, offs);
- }
- } else {
- AddCodeLine ("ldy #<(%s)", lbuf);
- AddCodeLine ("sty ptr1");
- AddCodeLine ("ldy #>(%s)", lbuf);
- AddCodeLine ("jsr laddeq");
- }
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ AddCodeLine ("ldx #$00");
+ if (flags & CF_CONST) {
+ if (val == 1) {
+ AddCodeLine ("inc %s", lbuf);
+ AddCodeLine ("lda %s", lbuf);
+ } else {
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("clc");
+ AddCodeLine ("adc %s", lbuf);
+ AddCodeLine ("sta %s", lbuf);
+ }
+ } else {
+ AddCodeLine ("clc");
+ AddCodeLine ("adc %s", lbuf);
+ AddCodeLine ("sta %s", lbuf);
+ }
+ if ((flags & CF_UNSIGNED) == 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (flags & CF_CONST) {
+ if (val == 1) {
+ unsigned L = GetLocalLabel ();
+ AddCodeLine ("inc %s", lbuf);
+ AddCodeLine ("bne %s", LocalLabelName (L));
+ AddCodeLine ("inc %s+1", lbuf);
+ g_defcodelabel (L);
+ AddCodeLine ("lda %s", lbuf); /* Hmmm... */
+ AddCodeLine ("ldx %s+1", lbuf);
+ } else {
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("clc");
+ AddCodeLine ("adc %s", lbuf);
+ AddCodeLine ("sta %s", lbuf);
+ if (val < 0x100) {
+ unsigned L = GetLocalLabel ();
+ AddCodeLine ("bcc %s", LocalLabelName (L));
+ AddCodeLine ("inc %s+1", lbuf);
+ g_defcodelabel (L);
+ AddCodeLine ("ldx %s+1", lbuf);
+ } else {
+ AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8));
+ AddCodeLine ("adc %s+1", lbuf);
+ AddCodeLine ("sta %s+1", lbuf);
+ AddCodeLine ("tax");
+ AddCodeLine ("lda %s", lbuf);
+ }
+ }
+ } else {
+ AddCodeLine ("clc");
+ AddCodeLine ("adc %s", lbuf);
+ AddCodeLine ("sta %s", lbuf);
+ AddCodeLine ("txa");
+ AddCodeLine ("adc %s+1", lbuf);
+ AddCodeLine ("sta %s+1", lbuf);
+ AddCodeLine ("tax");
+ AddCodeLine ("lda %s", lbuf);
+ }
+ break;
+
+ case CF_LONG:
+ if (flags & CF_CONST) {
+ if (val < 0x100) {
+ AddCodeLine ("ldy #<(%s)", lbuf);
+ AddCodeLine ("sty ptr1");
+ AddCodeLine ("ldy #>(%s)", lbuf);
+ if (val == 1) {
+ AddCodeLine ("jsr laddeq1");
+ } else {
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("jsr laddeqa");
+ }
+ } else {
+ g_getstatic (flags, label, offs);
+ g_inc (flags, val);
+ g_putstatic (flags, label, offs);
+ }
+ } else {
+ AddCodeLine ("ldy #<(%s)", lbuf);
+ AddCodeLine ("sty ptr1");
+ AddCodeLine ("ldy #>(%s)", lbuf);
+ AddCodeLine ("jsr laddeq");
+ }
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- 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) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- ldyconst (offs);
- if (flags & CF_CONST) {
- if (CodeSizeFactor >= 400) {
- AddCodeLine ("clc");
- AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
- AddCodeLine ("adc (sp),y");
- AddCodeLine ("sta (sp),y");
- AddCodeLine ("iny");
- AddCodeLine ("lda #$%02X", (int) ((val >> 8) & 0xFF));
- AddCodeLine ("adc (sp),y");
- AddCodeLine ("sta (sp),y");
- AddCodeLine ("tax");
- AddCodeLine ("dey");
- AddCodeLine ("lda (sp),y");
- } else {
- g_getimmed (flags, val, 0);
- AddCodeLine ("jsr addeqysp");
- }
- } else {
- AddCodeLine ("jsr addeqysp");
- }
- break;
-
- case CF_LONG:
- if (flags & CF_CONST) {
- g_getimmed (flags, val, 0);
- }
- ldyconst (offs);
- AddCodeLine ("jsr laddeqysp");
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ 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) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ ldyconst (offs);
+ if (flags & CF_CONST) {
+ if (IS_Get (&CodeSizeFactor) >= 400) {
+ AddCodeLine ("clc");
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("adc (sp),y");
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("iny");
+ AddCodeLine ("lda #$%02X", (int) ((val >> 8) & 0xFF));
+ AddCodeLine ("adc (sp),y");
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("tax");
+ AddCodeLine ("dey");
+ AddCodeLine ("lda (sp),y");
+ } else {
+ g_getimmed (flags, val, 0);
+ AddCodeLine ("jsr addeqysp");
+ }
+ } else {
+ AddCodeLine ("jsr addeqysp");
+ }
+ break;
+
+ case CF_LONG:
+ if (flags & CF_CONST) {
+ g_getimmed (flags, val, 0);
+ }
+ ldyconst (offs);
+ AddCodeLine ("jsr laddeqysp");
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- AddCodeLine ("sta ptr1");
- AddCodeLine ("stx ptr1+1");
- AddCodeLine ("ldy #$%02X", offs);
- AddCodeLine ("ldx #$00");
- AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
- AddCodeLine ("clc");
- AddCodeLine ("adc (ptr1),y");
- AddCodeLine ("sta (ptr1),y");
- break;
-
- case CF_INT:
- if (CodeSizeFactor >= 200) {
- /* Lots of code, use only if size is not important */
- AddCodeLine ("sta ptr1");
- AddCodeLine ("stx ptr1+1");
- AddCodeLine ("ldy #$%02X", offs);
- AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
- AddCodeLine ("clc");
- AddCodeLine ("adc (ptr1),y");
- AddCodeLine ("sta (ptr1),y");
- AddCodeLine ("pha");
- AddCodeLine ("iny");
- AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8));
- AddCodeLine ("adc (ptr1),y");
- AddCodeLine ("sta (ptr1),y");
- AddCodeLine ("tax");
- AddCodeLine ("pla");
- break;
- }
- /* FALL THROUGH */
-
- case CF_LONG:
- AddCodeLine ("jsr pushax"); /* Push the address */
- push (CF_PTR); /* Correct the internal sp */
- g_getind (flags, offs); /* Fetch the value */
- g_inc (flags, val); /* Increment value in primary */
- g_putind (flags, offs); /* Store the value back */
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ AddCodeLine ("sta ptr1");
+ AddCodeLine ("stx ptr1+1");
+ AddCodeLine ("ldy #$%02X", offs);
+ AddCodeLine ("ldx #$00");
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("clc");
+ AddCodeLine ("adc (ptr1),y");
+ AddCodeLine ("sta (ptr1),y");
+ break;
+
+ case CF_INT:
+ if (IS_Get (&CodeSizeFactor) >= 200) {
+ /* Lots of code, use only if size is not important */
+ AddCodeLine ("sta ptr1");
+ AddCodeLine ("stx ptr1+1");
+ AddCodeLine ("ldy #$%02X", offs);
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("clc");
+ AddCodeLine ("adc (ptr1),y");
+ AddCodeLine ("sta (ptr1),y");
+ AddCodeLine ("pha");
+ AddCodeLine ("iny");
+ AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8));
+ AddCodeLine ("adc (ptr1),y");
+ AddCodeLine ("sta (ptr1),y");
+ AddCodeLine ("tax");
+ AddCodeLine ("pla");
+ break;
+ }
+ /* FALL THROUGH */
+
+ case CF_LONG:
+ AddCodeLine ("jsr pushax"); /* Push the address */
+ push (CF_PTR); /* Correct the internal sp */
+ g_getind (flags, offs); /* Fetch the value */
+ g_inc (flags, val); /* Increment value in primary */
+ g_putind (flags, offs); /* Store the value back */
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- AddCodeLine ("ldx #$00");
- if (flags & CF_CONST) {
- if (val == 1) {
- AddCodeLine ("dec %s", lbuf);
- AddCodeLine ("lda %s", lbuf);
- } else {
- AddCodeLine ("sec");
- AddCodeLine ("lda %s", lbuf);
- AddCodeLine ("sbc #$%02X", (int)(val & 0xFF));
- AddCodeLine ("sta %s", lbuf);
- }
- } else {
- AddCodeLine ("eor #$FF");
- AddCodeLine ("sec");
- AddCodeLine ("adc %s", lbuf);
- AddCodeLine ("sta %s", lbuf);
- }
- if ((flags & CF_UNSIGNED) == 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- AddCodeLine ("sec");
- if (flags & CF_CONST) {
- AddCodeLine ("lda %s", lbuf);
- AddCodeLine ("sbc #$%02X", (unsigned char)val);
- AddCodeLine ("sta %s", lbuf);
- if (val < 0x100) {
- unsigned L = GetLocalLabel ();
- AddCodeLine ("bcs %s", LocalLabelName (L));
- AddCodeLine ("dec %s+1", lbuf);
- g_defcodelabel (L);
- AddCodeLine ("ldx %s+1", lbuf);
- } else {
- AddCodeLine ("lda %s+1", lbuf);
- AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8));
- AddCodeLine ("sta %s+1", lbuf);
- AddCodeLine ("tax");
- AddCodeLine ("lda %s", lbuf);
- }
- } else {
- AddCodeLine ("eor #$FF");
- AddCodeLine ("adc %s", lbuf);
- AddCodeLine ("sta %s", lbuf);
- AddCodeLine ("txa");
- AddCodeLine ("eor #$FF");
- AddCodeLine ("adc %s+1", lbuf);
- AddCodeLine ("sta %s+1", lbuf);
- AddCodeLine ("tax");
- AddCodeLine ("lda %s", lbuf);
- }
- break;
-
- case CF_LONG:
- if (flags & CF_CONST) {
- if (val < 0x100) {
- AddCodeLine ("ldy #<(%s)", lbuf);
- AddCodeLine ("sty ptr1");
- AddCodeLine ("ldy #>(%s)", lbuf);
- AddCodeLine ("lda #$%02X", (unsigned char)val);
- AddCodeLine ("jsr lsubeqa");
- } else {
- g_getstatic (flags, label, offs);
- g_dec (flags, val);
- g_putstatic (flags, label, offs);
- }
- } else {
- AddCodeLine ("ldy #<(%s)", lbuf);
- AddCodeLine ("sty ptr1");
- AddCodeLine ("ldy #>(%s)", lbuf);
- AddCodeLine ("jsr lsubeq");
- }
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ AddCodeLine ("ldx #$00");
+ if (flags & CF_CONST) {
+ if (val == 1) {
+ AddCodeLine ("dec %s", lbuf);
+ AddCodeLine ("lda %s", lbuf);
+ } else {
+ AddCodeLine ("sec");
+ AddCodeLine ("lda %s", lbuf);
+ AddCodeLine ("sbc #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("sta %s", lbuf);
+ }
+ } else {
+ AddCodeLine ("eor #$FF");
+ AddCodeLine ("sec");
+ AddCodeLine ("adc %s", lbuf);
+ AddCodeLine ("sta %s", lbuf);
+ }
+ if ((flags & CF_UNSIGNED) == 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ AddCodeLine ("sec");
+ if (flags & CF_CONST) {
+ AddCodeLine ("lda %s", lbuf);
+ AddCodeLine ("sbc #$%02X", (unsigned char)val);
+ AddCodeLine ("sta %s", lbuf);
+ if (val < 0x100) {
+ unsigned L = GetLocalLabel ();
+ AddCodeLine ("bcs %s", LocalLabelName (L));
+ AddCodeLine ("dec %s+1", lbuf);
+ g_defcodelabel (L);
+ AddCodeLine ("ldx %s+1", lbuf);
+ } else {
+ AddCodeLine ("lda %s+1", lbuf);
+ AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8));
+ AddCodeLine ("sta %s+1", lbuf);
+ AddCodeLine ("tax");
+ AddCodeLine ("lda %s", lbuf);
+ }
+ } else {
+ AddCodeLine ("eor #$FF");
+ AddCodeLine ("adc %s", lbuf);
+ AddCodeLine ("sta %s", lbuf);
+ AddCodeLine ("txa");
+ AddCodeLine ("eor #$FF");
+ AddCodeLine ("adc %s+1", lbuf);
+ AddCodeLine ("sta %s+1", lbuf);
+ AddCodeLine ("tax");
+ AddCodeLine ("lda %s", lbuf);
+ }
+ break;
+
+ case CF_LONG:
+ if (flags & CF_CONST) {
+ if (val < 0x100) {
+ AddCodeLine ("ldy #<(%s)", lbuf);
+ AddCodeLine ("sty ptr1");
+ AddCodeLine ("ldy #>(%s)", lbuf);
+ AddCodeLine ("lda #$%02X", (unsigned char)val);
+ AddCodeLine ("jsr lsubeqa");
+ } else {
+ g_getstatic (flags, label, offs);
+ g_dec (flags, val);
+ g_putstatic (flags, label, offs);
+ }
+ } else {
+ AddCodeLine ("ldy #<(%s)", lbuf);
+ AddCodeLine ("sty ptr1");
+ AddCodeLine ("ldy #>(%s)", lbuf);
+ AddCodeLine ("jsr lsubeq");
+ }
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- ldyconst (offs);
- AddCodeLine ("ldx #$00");
- AddCodeLine ("sec");
- if (flags & CF_CONST) {
- AddCodeLine ("lda (sp),y");
- AddCodeLine ("sbc #$%02X", (unsigned char)val);
- } else {
- AddCodeLine ("eor #$FF");
- AddCodeLine ("adc (sp),y");
- }
- AddCodeLine ("sta (sp),y");
- if ((flags & CF_UNSIGNED) == 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (flags & CF_CONST) {
- g_getimmed (flags, val, 0);
- }
- ldyconst (offs);
- AddCodeLine ("jsr subeqysp");
- break;
-
- case CF_LONG:
- if (flags & CF_CONST) {
- g_getimmed (flags, val, 0);
- }
- ldyconst (offs);
- AddCodeLine ("jsr lsubeqysp");
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ ldyconst (offs);
+ AddCodeLine ("ldx #$00");
+ AddCodeLine ("sec");
+ if (flags & CF_CONST) {
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sbc #$%02X", (unsigned char)val);
+ } else {
+ AddCodeLine ("eor #$FF");
+ AddCodeLine ("adc (sp),y");
+ }
+ AddCodeLine ("sta (sp),y");
+ if ((flags & CF_UNSIGNED) == 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (flags & CF_CONST) {
+ g_getimmed (flags, val, 0);
+ }
+ ldyconst (offs);
+ AddCodeLine ("jsr subeqysp");
+ break;
+
+ case CF_LONG:
+ if (flags & CF_CONST) {
+ g_getimmed (flags, val, 0);
+ }
+ ldyconst (offs);
+ AddCodeLine ("jsr lsubeqysp");
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- AddCodeLine ("sta ptr1");
- AddCodeLine ("stx ptr1+1");
- AddCodeLine ("ldy #$%02X", offs);
- AddCodeLine ("ldx #$00");
- AddCodeLine ("lda (ptr1),y");
- AddCodeLine ("sec");
- AddCodeLine ("sbc #$%02X", (unsigned char)val);
- AddCodeLine ("sta (ptr1),y");
- break;
-
- case CF_INT:
- if (CodeSizeFactor >= 200) {
- /* Lots of code, use only if size is not important */
- AddCodeLine ("sta ptr1");
- AddCodeLine ("stx ptr1+1");
- AddCodeLine ("ldy #$%02X", offs);
- AddCodeLine ("lda (ptr1),y");
- AddCodeLine ("sec");
- AddCodeLine ("sbc #$%02X", (unsigned char)val);
- AddCodeLine ("sta (ptr1),y");
- AddCodeLine ("pha");
- AddCodeLine ("iny");
- AddCodeLine ("lda (ptr1),y");
- AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8));
- AddCodeLine ("sta (ptr1),y");
- AddCodeLine ("tax");
- AddCodeLine ("pla");
- break;
- }
- /* FALL THROUGH */
-
- case CF_LONG:
- AddCodeLine ("jsr pushax"); /* Push the address */
- push (CF_PTR); /* Correct the internal sp */
- g_getind (flags, offs); /* Fetch the value */
- g_dec (flags, val); /* Increment value in primary */
- g_putind (flags, offs); /* Store the value back */
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ AddCodeLine ("sta ptr1");
+ AddCodeLine ("stx ptr1+1");
+ AddCodeLine ("ldy #$%02X", offs);
+ AddCodeLine ("ldx #$00");
+ AddCodeLine ("lda (ptr1),y");
+ AddCodeLine ("sec");
+ AddCodeLine ("sbc #$%02X", (unsigned char)val);
+ AddCodeLine ("sta (ptr1),y");
+ break;
+
+ case CF_INT:
+ if (IS_Get (&CodeSizeFactor) >= 200) {
+ /* Lots of code, use only if size is not important */
+ AddCodeLine ("sta ptr1");
+ AddCodeLine ("stx ptr1+1");
+ AddCodeLine ("ldy #$%02X", offs);
+ AddCodeLine ("lda (ptr1),y");
+ AddCodeLine ("sec");
+ AddCodeLine ("sbc #$%02X", (unsigned char)val);
+ AddCodeLine ("sta (ptr1),y");
+ AddCodeLine ("pha");
+ AddCodeLine ("iny");
+ AddCodeLine ("lda (ptr1),y");
+ AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8));
+ AddCodeLine ("sta (ptr1),y");
+ AddCodeLine ("tax");
+ AddCodeLine ("pla");
+ break;
+ }
+ /* FALL THROUGH */
+
+ case CF_LONG:
+ AddCodeLine ("jsr pushax"); /* Push the address */
+ push (CF_PTR); /* Correct the internal sp */
+ g_getind (flags, offs); /* Fetch the value */
+ g_dec (flags, val); /* Increment value in primary */
+ g_putind (flags, offs); /* Store the value back */
+ break;
+
+ default:
+ typeerror (flags);
- /* Constant value given */
- if (val == 0 && subs [offs+0]) {
- /* Special case: constant with value zero */
- AddCodeLine ("jsr %s", subs [offs+0]);
- } else if (val < 0x100 && subs [offs+1]) {
- /* Special case: constant with high byte zero */
- ldaconst (val); /* Load low byte */
- AddCodeLine ("jsr %s", subs [offs+1]);
- } else {
- /* Others: arbitrary constant value */
- g_getimmed (flags, val, 0); /* Load value */
- AddCodeLine ("jsr %s", subs [offs+2]);
- }
+ /* Constant value given */
+ if (val == 0 && subs [offs+0]) {
+ /* Special case: constant with value zero */
+ AddCodeLine ("jsr %s", subs [offs+0]);
+ } else if (val < 0x100 && subs [offs+1]) {
+ /* Special case: constant with high byte zero */
+ ldaconst (val); /* Load low byte */
+ AddCodeLine ("jsr %s", subs [offs+1]);
+ } else {
+ /* Others: arbitrary constant value */
+ g_getimmed (flags, val, 0); /* Load value */
+ AddCodeLine ("jsr %s", subs [offs+2]);
+ }
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- /* Handle some special cases */
- switch (val) {
-
- case 3:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
- AddCodeLine ("adc tmp1");
- return;
-
- case 5:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
- AddCodeLine ("adc tmp1");
- return;
-
- case 6:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
- AddCodeLine ("adc tmp1");
- AddCodeLine ("asl a");
- return;
-
- case 10:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
- AddCodeLine ("adc tmp1");
- AddCodeLine ("asl a");
- return;
- }
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- switch (val) {
- case 3:
- AddCodeLine ("jsr mulax3");
- return;
- case 5:
- AddCodeLine ("jsr mulax5");
- return;
- case 6:
- AddCodeLine ("jsr mulax6");
- return;
- case 7:
- AddCodeLine ("jsr mulax7");
- return;
- case 9:
- AddCodeLine ("jsr mulax9");
- return;
- case 10:
- AddCodeLine ("jsr mulax10");
- return;
- }
- break;
-
- case CF_LONG:
- break;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff.
- */
- flags &= ~CF_FORCECHAR; /* Handle chars as ints */
- g_push (flags & ~CF_CONST, 0);
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ /* Handle some special cases */
+ switch (val) {
+
+ case 3:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc tmp1");
+ return;
+
+ case 5:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc tmp1");
+ return;
+
+ case 6:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc tmp1");
+ AddCodeLine ("asl a");
+ return;
+
+ case 10:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc tmp1");
+ AddCodeLine ("asl a");
+ return;
+ }
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ switch (val) {
+ case 3:
+ AddCodeLine ("jsr mulax3");
+ return;
+ case 5:
+ AddCodeLine ("jsr mulax5");
+ return;
+ case 6:
+ AddCodeLine ("jsr mulax6");
+ return;
+ case 7:
+ AddCodeLine ("jsr mulax7");
+ return;
+ case 9:
+ AddCodeLine ("jsr mulax9");
+ return;
+ case 10:
+ AddCodeLine ("jsr mulax10");
+ return;
+ }
+ break;
+
+ case CF_LONG:
+ break;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff.
+ */
+ flags &= ~CF_FORCECHAR; /* Handle chars as ints */
+ g_push (flags & ~CF_CONST, 0);
- return;
- }
- /* FALLTHROUGH */
- case CF_INT:
- if ((Val & 0xFFFF) != 0xFFFF) {
- if (Val <= 0xFF) {
- ldxconst (0);
- if (Val == 0) {
- ldaconst (0);
- } else if (Val != 0xFF) {
- AddCodeLine ("and #$%02X", (unsigned char)Val);
- }
- } else if ((Val & 0xFF00) == 0xFF00) {
- AddCodeLine ("and #$%02X", (unsigned char)Val);
- } else if ((Val & 0x00FF) == 0x0000) {
- AddCodeLine ("txa");
- AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
- AddCodeLine ("tax");
- ldaconst (0);
- } else {
- AddCodeLine ("tay");
- AddCodeLine ("txa");
- AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
- AddCodeLine ("tax");
- AddCodeLine ("tya");
- if ((Val & 0x00FF) != 0x00FF) {
- AddCodeLine ("and #$%02X", (unsigned char)Val);
- }
- }
- }
- return;
-
- case CF_LONG:
- if (Val <= 0xFF) {
- ldxconst (0);
- AddCodeLine ("stx sreg+1");
- AddCodeLine ("stx sreg");
- if ((Val & 0xFF) != 0xFF) {
- AddCodeLine ("and #$%02X", (unsigned char)Val);
- }
- return;
- } else if (Val == 0xFF00) {
- ldaconst (0);
- AddCodeLine ("sta sreg+1");
- AddCodeLine ("sta sreg");
- return;
- }
- break;
-
- default:
- typeerror (Flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ return;
+ }
+ /* FALLTHROUGH */
+ case CF_INT:
+ if ((Val & 0xFFFF) != 0xFFFF) {
+ if (Val <= 0xFF) {
+ ldxconst (0);
+ if (Val == 0) {
+ ldaconst (0);
+ } else if (Val != 0xFF) {
+ AddCodeLine ("and #$%02X", (unsigned char)Val);
+ }
+ } else if ((Val & 0xFF00) == 0xFF00) {
+ AddCodeLine ("and #$%02X", (unsigned char)Val);
+ } else if ((Val & 0x00FF) == 0x0000) {
+ AddCodeLine ("txa");
+ AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
+ AddCodeLine ("tax");
+ ldaconst (0);
+ } else {
+ AddCodeLine ("tay");
+ AddCodeLine ("txa");
+ AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
+ AddCodeLine ("tax");
+ AddCodeLine ("tya");
+ if ((Val & 0x00FF) != 0x00FF) {
+ AddCodeLine ("and #$%02X", (unsigned char)Val);
+ }
+ }
+ }
+ return;
+
+ case CF_LONG:
+ if (Val <= 0xFF) {
+ ldxconst (0);
+ AddCodeLine ("stx sreg+1");
+ AddCodeLine ("stx sreg");
+ if ((Val & 0xFF) != 0xFF) {
+ AddCodeLine ("and #$%02X", (unsigned char)Val);
+ }
+ return;
+ } else if (Val == 0xFF00) {
+ ldaconst (0);
+ AddCodeLine ("sta sreg+1");
+ AddCodeLine ("sta sreg");
+ return;
+ }
+ break;
+
+ default:
+ typeerror (Flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- case CF_INT:
- if (val >= 8 && (flags & CF_UNSIGNED)) {
- AddCodeLine ("txa");
- ldxconst (0);
- val -= 8;
- }
- if (val == 0) {
- /* Done */
- return;
- } else if (val >= 1 && val <= 4) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shrax%ld", val);
- } else {
- AddCodeLine ("jsr asrax%ld", val);
- }
- return;
- }
- break;
-
- case CF_LONG:
- if (val == 0) {
- /* Nothing to do */
- return;
- } else if (val >= 1 && val <= 4) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shreax%ld", val);
- } else {
- AddCodeLine ("jsr asreax%ld", val);
- }
- return;
- } else if (val == 8 && (flags & CF_UNSIGNED)) {
- AddCodeLine ("txa");
- AddCodeLine ("ldx sreg");
- AddCodeLine ("ldy sreg+1");
- AddCodeLine ("sty sreg");
- AddCodeLine ("ldy #$00");
- AddCodeLine ("sty sreg+1");
- return;
- } else if (val == 16) {
- AddCodeLine ("ldy #$00");
- AddCodeLine ("ldx sreg+1");
- if ((flags & CF_UNSIGNED) == 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dey");
- g_defcodelabel (L);
- }
- AddCodeLine ("lda sreg");
- AddCodeLine ("sty sreg+1");
- AddCodeLine ("sty sreg");
- return;
- }
- break;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ case CF_INT:
+ if (val >= 8 && (flags & CF_UNSIGNED)) {
+ AddCodeLine ("txa");
+ ldxconst (0);
+ val -= 8;
+ }
+ if (val == 0) {
+ /* Done */
+ return;
+ } else if (val >= 1 && val <= 4) {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shrax%ld", val);
+ } else {
+ AddCodeLine ("jsr asrax%ld", val);
+ }
+ return;
+ }
+ break;
+
+ case CF_LONG:
+ if (val == 0) {
+ /* Nothing to do */
+ return;
+ } else if (val >= 1 && val <= 4) {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shreax%ld", val);
+ } else {
+ AddCodeLine ("jsr asreax%ld", val);
+ }
+ return;
+ } else if (val == 8 && (flags & CF_UNSIGNED)) {
+ AddCodeLine ("txa");
+ AddCodeLine ("ldx sreg");
+ AddCodeLine ("ldy sreg+1");
+ AddCodeLine ("sty sreg");
+ AddCodeLine ("ldy #$00");
+ AddCodeLine ("sty sreg+1");
+ return;
+ } else if (val == 16) {
+ AddCodeLine ("ldy #$00");
+ AddCodeLine ("ldx sreg+1");
+ if ((flags & CF_UNSIGNED) == 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dey");
+ g_defcodelabel (L);
+ }
+ AddCodeLine ("lda sreg");
+ AddCodeLine ("sty sreg+1");
+ AddCodeLine ("sty sreg");
+ return;
+ }
+ break;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- case CF_INT:
- if (val >= 8) {
- AddCodeLine ("tax");
- AddCodeLine ("lda #$00");
- val -= 8;
- }
- if (val == 0) {
- /* Done */
- return;
- } else if (val >= 1 && val <= 4) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shlax%ld", val);
- } else {
- AddCodeLine ("jsr aslax%ld", val);
- }
- return;
- }
- break;
-
- case CF_LONG:
- if (val == 0) {
- /* Nothing to do */
- return;
- } else if (val >= 1 && val <= 4) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shleax%ld", val);
- } else {
- AddCodeLine ("jsr asleax%ld", val);
- }
- return;
- } else if (val == 8) {
- AddCodeLine ("ldy sreg");
- AddCodeLine ("sty sreg+1");
- AddCodeLine ("stx sreg");
- AddCodeLine ("tax");
- AddCodeLine ("lda #$00");
- return;
- } else if (val == 16) {
- AddCodeLine ("stx sreg+1");
- AddCodeLine ("sta sreg");
- AddCodeLine ("lda #$00");
- AddCodeLine ("tax");
- return;
- }
- break;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ case CF_INT:
+ if (val >= 8) {
+ AddCodeLine ("tax");
+ AddCodeLine ("lda #$00");
+ val -= 8;
+ }
+ if (val == 0) {
+ /* Done */
+ return;
+ } else if (val >= 1 && val <= 4) {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shlax%ld", val);
+ } else {
+ AddCodeLine ("jsr aslax%ld", val);
+ }
+ return;
+ }
+ break;
+
+ case CF_LONG:
+ if (val == 0) {
+ /* Nothing to do */
+ return;
+ } else if (val >= 1 && val <= 4) {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shleax%ld", val);
+ } else {
+ AddCodeLine ("jsr asleax%ld", val);
+ }
+ return;
+ } else if (val == 8) {
+ AddCodeLine ("ldy sreg");
+ AddCodeLine ("sty sreg+1");
+ AddCodeLine ("stx sreg");
+ AddCodeLine ("tax");
+ AddCodeLine ("lda #$00");
+ return;
+ } else if (val == 16) {
+ AddCodeLine ("stx sreg+1");
+ AddCodeLine ("sta sreg");
+ AddCodeLine ("lda #$00");
+ AddCodeLine ("tax");
+ return;
+ }
+ break;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val <= 2) {
- while (val--) {
- AddCodeLine ("ina");
- }
- } else {
- AddCodeLine ("clc");
- AddCodeLine ("adc #$%02X", (unsigned char)val);
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val == 1) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("ina");
- AddCodeLine ("bne %s", LocalLabelName (L));
- AddCodeLine ("inx");
- g_defcodelabel (L);
- } else if (CodeSizeFactor < 200) {
- /* Use jsr calls */
- if (val <= 8) {
- AddCodeLine ("jsr incax%lu", val);
- } else if (val <= 255) {
- ldyconst (val);
- AddCodeLine ("jsr incaxy");
- } else {
- g_add (flags | CF_CONST, val);
- }
- } else {
- /* Inline the code */
- if (val <= 0x300) {
- if ((val & 0xFF) != 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("clc");
- AddCodeLine ("adc #$%02X", (unsigned char) val);
- AddCodeLine ("bcc %s", LocalLabelName (L));
- AddCodeLine ("inx");
- g_defcodelabel (L);
- }
- if (val >= 0x100) {
- AddCodeLine ("inx");
- }
- if (val >= 0x200) {
- AddCodeLine ("inx");
- }
- if (val >= 0x300) {
- AddCodeLine ("inx");
- }
- } else {
- AddCodeLine ("clc");
- if ((val & 0xFF) != 0) {
- AddCodeLine ("adc #$%02X", (unsigned char) val);
- }
- AddCodeLine ("pha");
- AddCodeLine ("txa");
- AddCodeLine ("adc #$%02X", (unsigned char) (val >> 8));
- AddCodeLine ("tax");
- AddCodeLine ("pla");
- }
- }
- break;
-
- case CF_LONG:
- if (val <= 255) {
- ldyconst (val);
- AddCodeLine ("jsr inceaxy");
- } else {
- g_add (flags | CF_CONST, val);
- }
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val <= 2) {
+ while (val--) {
+ AddCodeLine ("ina");
+ }
+ } else {
+ AddCodeLine ("clc");
+ AddCodeLine ("adc #$%02X", (unsigned char)val);
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val == 1) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("ina");
+ AddCodeLine ("bne %s", LocalLabelName (L));
+ AddCodeLine ("inx");
+ g_defcodelabel (L);
+ } else if (IS_Get (&CodeSizeFactor) < 200) {
+ /* Use jsr calls */
+ if (val <= 8) {
+ AddCodeLine ("jsr incax%lu", val);
+ } else if (val <= 255) {
+ ldyconst (val);
+ AddCodeLine ("jsr incaxy");
+ } else {
+ g_add (flags | CF_CONST, val);
+ }
+ } else {
+ /* Inline the code */
+ if (val <= 0x300) {
+ if ((val & 0xFF) != 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("clc");
+ AddCodeLine ("adc #$%02X", (unsigned char) val);
+ AddCodeLine ("bcc %s", LocalLabelName (L));
+ AddCodeLine ("inx");
+ g_defcodelabel (L);
+ }
+ if (val >= 0x100) {
+ AddCodeLine ("inx");
+ }
+ if (val >= 0x200) {
+ AddCodeLine ("inx");
+ }
+ if (val >= 0x300) {
+ AddCodeLine ("inx");
+ }
+ } else {
+ AddCodeLine ("clc");
+ if ((val & 0xFF) != 0) {
+ AddCodeLine ("adc #$%02X", (unsigned char) val);
+ }
+ AddCodeLine ("pha");
+ AddCodeLine ("txa");
+ AddCodeLine ("adc #$%02X", (unsigned char) (val >> 8));
+ AddCodeLine ("tax");
+ AddCodeLine ("pla");
+ }
+ }
+ break;
+
+ case CF_LONG:
+ if (val <= 255) {
+ ldyconst (val);
+ AddCodeLine ("jsr inceaxy");
+ } else {
+ g_add (flags | CF_CONST, val);
+ }
+ break;
+
+ default:
+ typeerror (flags);
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val <= 2) {
- while (val--) {
- AddCodeLine ("dea");
- }
- } else {
- AddCodeLine ("sec");
- AddCodeLine ("sbc #$%02X", (unsigned char)val);
- }
- break;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (CodeSizeFactor < 200) {
- /* Use subroutines */
- if (val <= 8) {
- AddCodeLine ("jsr decax%d", (int) val);
- } else if (val <= 255) {
- ldyconst (val);
- AddCodeLine ("jsr decaxy");
- } else {
- g_sub (flags | CF_CONST, val);
- }
- } else {
- /* Inline the code */
- if (val < 0x300) {
- if ((val & 0xFF) != 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("sec");
- AddCodeLine ("sbc #$%02X", (unsigned char) val);
- AddCodeLine ("bcs %s", LocalLabelName (L));
- AddCodeLine ("dex");
- g_defcodelabel (L);
- }
- if (val >= 0x100) {
- AddCodeLine ("dex");
- }
- if (val >= 0x200) {
- AddCodeLine ("dex");
- }
- } else {
- AddCodeLine ("sec");
- if ((val & 0xFF) != 0) {
- AddCodeLine ("sbc #$%02X", (unsigned char) val);
- }
- AddCodeLine ("pha");
- AddCodeLine ("txa");
- AddCodeLine ("sbc #$%02X", (unsigned char) (val >> 8));
- AddCodeLine ("tax");
- AddCodeLine ("pla");
- }
- }
- break;
-
- case CF_LONG:
- if (val <= 255) {
- ldyconst (val);
- AddCodeLine ("jsr deceaxy");
- } else {
- g_sub (flags | CF_CONST, val);
- }
- break;
-
- default:
- typeerror (flags);
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val <= 2) {
+ while (val--) {
+ AddCodeLine ("dea");
+ }
+ } else {
+ AddCodeLine ("sec");
+ AddCodeLine ("sbc #$%02X", (unsigned char)val);
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (IS_Get (&CodeSizeFactor) < 200) {
+ /* Use subroutines */
+ if (val <= 8) {
+ AddCodeLine ("jsr decax%d", (int) val);
+ } else if (val <= 255) {
+ ldyconst (val);
+ AddCodeLine ("jsr decaxy");
+ } else {
+ g_sub (flags | CF_CONST, val);
+ }
+ } else {
+ /* Inline the code */
+ if (val < 0x300) {
+ if ((val & 0xFF) != 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("sec");
+ AddCodeLine ("sbc #$%02X", (unsigned char) val);
+ AddCodeLine ("bcs %s", LocalLabelName (L));
+ AddCodeLine ("dex");
+ g_defcodelabel (L);
+ }
+ if (val >= 0x100) {
+ AddCodeLine ("dex");
+ }
+ if (val >= 0x200) {
+ AddCodeLine ("dex");
+ }
+ } else {
+ AddCodeLine ("sec");
+ if ((val & 0xFF) != 0) {
+ AddCodeLine ("sbc #$%02X", (unsigned char) val);
+ }
+ AddCodeLine ("pha");
+ AddCodeLine ("txa");
+ AddCodeLine ("sbc #$%02X", (unsigned char) (val >> 8));
+ AddCodeLine ("tax");
+ AddCodeLine ("pla");
+ }
+ }
+ break;
+
+ case CF_LONG:
+ if (val <= 255) {
+ ldyconst (val);
+ AddCodeLine ("jsr deceaxy");
+ } else {
+ g_sub (flags | CF_CONST, val);
+ }
+ break;
+
+ default:
+ typeerror (flags);
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- AddCodeLine ("cmp #$%02X", (unsigned char)val);
- AddCodeLine ("jsr booleq");
- return;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- L = GetLocalLabel();
- AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
- AddCodeLine ("bne %s", LocalLabelName (L));
- AddCodeLine ("cmp #$%02X", (unsigned char)val);
- g_defcodelabel (L);
- AddCodeLine ("jsr booleq");
- return;
-
- case CF_LONG:
- break;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ AddCodeLine ("cmp #$%02X", (unsigned char)val);
+ AddCodeLine ("jsr booleq");
+ return;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ L = GetLocalLabel();
+ AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
+ AddCodeLine ("bne %s", LocalLabelName (L));
+ AddCodeLine ("cmp #$%02X", (unsigned char)val);
+ g_defcodelabel (L);
+ AddCodeLine ("jsr booleq");
+ return;
+
+ case CF_LONG:
+ break;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- AddCodeLine ("cmp #$%02X", (unsigned char)val);
- AddCodeLine ("jsr boolne");
- return;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- L = GetLocalLabel();
- AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
- AddCodeLine ("bne %s", LocalLabelName (L));
- AddCodeLine ("cmp #$%02X", (unsigned char)val);
- g_defcodelabel (L);
- AddCodeLine ("jsr boolne");
- return;
-
- case CF_LONG:
- break;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ AddCodeLine ("cmp #$%02X", (unsigned char)val);
+ AddCodeLine ("jsr boolne");
+ return;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ L = GetLocalLabel();
+ AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
+ AddCodeLine ("bne %s", LocalLabelName (L));
+ AddCodeLine ("cmp #$%02X", (unsigned char)val);
+ g_defcodelabel (L);
+ AddCodeLine ("jsr boolne");
+ return;
+
+ case CF_LONG:
+ break;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will
- /* Look at the type */
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- if (flags & CF_UNSIGNED) {
- /* Unsigned compare */
- if (val < 0xFF) {
- /* Use < instead of <= because the former gives
- * better code on the 6502 than the latter.
- */
- g_lt (flags, val+1);
- } else {
- /* Always true */
- Warning ("Condition is always true");
- AddCodeLine ("jsr return1");
- }
- } else {
- /* Signed compare */
- if ((long) val < 0x7F) {
- /* Use < instead of <= because the former gives
- * better code on the 6502 than the latter.
- */
- g_lt (flags, val+1);
- } else {
- /* Always true */
- Warning ("Condition is always true");
- AddCodeLine ("jsr return1");
- }
- }
- return;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (flags & CF_UNSIGNED) {
- /* Unsigned compare */
- if (val < 0xFFFF) {
- /* Use < instead of <= because the former gives
- * better code on the 6502 than the latter.
- */
- g_lt (flags, val+1);
- } else {
- /* Always true */
- Warning ("Condition is always true");
- AddCodeLine ("jsr return1");
- }
- } else {
- /* Signed compare */
- if ((long) val < 0x7FFF) {
- g_lt (flags, val+1);
- } else {
- /* Always true */
- Warning ("Condition is always true");
- AddCodeLine ("jsr return1");
- }
- }
- return;
-
- case CF_LONG:
- if (flags & CF_UNSIGNED) {
- /* Unsigned compare */
- if (val < 0xFFFFFFFF) {
- /* Use < instead of <= because the former gives
- * better code on the 6502 than the latter.
- */
- g_lt (flags, val+1);
- } else {
- /* Always true */
- Warning ("Condition is always true");
- AddCodeLine ("jsr return1");
- }
- } else {
- /* Signed compare */
- if ((long) val < 0x7FFFFFFF) {
- g_lt (flags, val+1);
- } else {
- /* Always true */
- Warning ("Condition is always true");
- AddCodeLine ("jsr return1");
- }
- }
- return;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ /* Look at the type */
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ if (flags & CF_UNSIGNED) {
+ /* Unsigned compare */
+ if (val < 0xFF) {
+ /* Use < instead of <= because the former gives
+ * better code on the 6502 than the latter.
+ */
+ g_lt (flags, val+1);
+ } else {
+ /* Always true */
+ Warning ("Condition is always true");
+ AddCodeLine ("jsr return1");
+ }
+ } else {
+ /* Signed compare */
+ if ((long) val < 0x7F) {
+ /* Use < instead of <= because the former gives
+ * better code on the 6502 than the latter.
+ */
+ g_lt (flags, val+1);
+ } else {
+ /* Always true */
+ Warning ("Condition is always true");
+ AddCodeLine ("jsr return1");
+ }
+ }
+ return;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (flags & CF_UNSIGNED) {
+ /* Unsigned compare */
+ if (val < 0xFFFF) {
+ /* Use < instead of <= because the former gives
+ * better code on the 6502 than the latter.
+ */
+ g_lt (flags, val+1);
+ } else {
+ /* Always true */
+ Warning ("Condition is always true");
+ AddCodeLine ("jsr return1");
+ }
+ } else {
+ /* Signed compare */
+ if ((long) val < 0x7FFF) {
+ g_lt (flags, val+1);
+ } else {
+ /* Always true */
+ Warning ("Condition is always true");
+ AddCodeLine ("jsr return1");
+ }
+ }
+ return;
+
+ case CF_LONG:
+ if (flags & CF_UNSIGNED) {
+ /* Unsigned compare */
+ if (val < 0xFFFFFFFF) {
+ /* Use < instead of <= because the former gives
+ * better code on the 6502 than the latter.
+ */
+ g_lt (flags, val+1);
+ } else {
+ /* Always true */
+ Warning ("Condition is always true");
+ AddCodeLine ("jsr return1");
+ }
+ } else {
+ /* Signed compare */
+ if ((long) val < 0x7FFFFFFF) {
+ g_lt (flags, val+1);
+ } else {
+ /* Always true */
+ Warning ("Condition is always true");
+ AddCodeLine ("jsr return1");
+ }
+ }
+ return;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will
- /* Look at the type */
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- if (flags & CF_FORCECHAR) {
- if (flags & CF_UNSIGNED) {
- if (val == 0) {
- /* If we have a compare > 0, we will replace it by
- * != 0 here, since both are identical but the
- * latter is easier to optimize.
- */
- g_ne (flags, val);
- } else if (val < 0xFF) {
- /* Use >= instead of > because the former gives
- * better code on the 6502 than the latter.
- */
- g_ge (flags, val+1);
- } else {
- /* Never true */
- Warning ("Condition is never true");
- AddCodeLine ("jsr return0");
- }
- } else {
- if ((long) val < 0x7F) {
- /* Use >= instead of > because the former gives
- * better code on the 6502 than the latter.
- */
- g_ge (flags, val+1);
- } else {
- /* Never true */
- Warning ("Condition is never true");
- AddCodeLine ("jsr return0");
- }
- }
- return;
- }
- /* FALLTHROUGH */
-
- case CF_INT:
- if (flags & CF_UNSIGNED) {
- /* Unsigned compare */
- if (val == 0) {
- /* If we have a compare > 0, we will replace it by
- * != 0 here, since both are identical but the latter
- * is easier to optimize.
- */
- g_ne (flags, val);
- } else if (val < 0xFFFF) {
- /* Use >= instead of > because the former gives better
- * code on the 6502 than the latter.
- */
- g_ge (flags, val+1);
- } else {
- /* Never true */
- Warning ("Condition is never true");
- AddCodeLine ("jsr return0");
- }
- } else {
- /* Signed compare */
- if ((long) val < 0x7FFF) {
- g_ge (flags, val+1);
- } else {
- /* Never true */
- Warning ("Condition is never true");
- AddCodeLine ("jsr return0");
- }
- }
- return;
-
- case CF_LONG:
- if (flags & CF_UNSIGNED) {
- /* Unsigned compare */
- if (val == 0) {
- /* If we have a compare > 0, we will replace it by
- * != 0 here, since both are identical but the latter
- * is easier to optimize.
- */
- g_ne (flags, val);
- } else if (val < 0xFFFFFFFF) {
- /* Use >= instead of > because the former gives better
- * code on the 6502 than the latter.
- */
- g_ge (flags, val+1);
- } else {
- /* Never true */
- Warning ("Condition is never true");
- AddCodeLine ("jsr return0");
- }
- } else {
- /* Signed compare */
- if ((long) val < 0x7FFFFFFF) {
- g_ge (flags, val+1);
- } else {
- /* Never true */
- Warning ("Condition is never true");
- AddCodeLine ("jsr return0");
- }
- }
- return;
-
- default:
- typeerror (flags);
- }
-
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff. Note: The standard stuff will
+ /* Look at the type */
+ switch (flags & CF_TYPE) {
+
+ case CF_CHAR:
+ if (flags & CF_FORCECHAR) {
+ if (flags & CF_UNSIGNED) {
+ if (val == 0) {
+ /* If we have a compare > 0, we will replace it by
+ * != 0 here, since both are identical but the
+ * latter is easier to optimize.
+ */
+ g_ne (flags, val);
+ } else if (val < 0xFF) {
+ /* Use >= instead of > because the former gives
+ * better code on the 6502 than the latter.
+ */
+ g_ge (flags, val+1);
+ } else {
+ /* Never true */
+ Warning ("Condition is never true");
+ AddCodeLine ("jsr return0");
+ }
+ } else {
+ if ((long) val < 0x7F) {
+ /* Use >= instead of > because the former gives
+ * better code on the 6502 than the latter.
+ */
+ g_ge (flags, val+1);
+ } else {
+ /* Never true */
+ Warning ("Condition is never true");
+ AddCodeLine ("jsr return0");
+ }
+ }
+ return;
+ }
+ /* FALLTHROUGH */
+
+ case CF_INT:
+ if (flags & CF_UNSIGNED) {
+ /* Unsigned compare */
+ if (val == 0) {
+ /* If we have a compare > 0, we will replace it by
+ * != 0 here, since both are identical but the latter
+ * is easier to optimize.
+ */
+ g_ne (flags, val);
+ } else if (val < 0xFFFF) {
+ /* Use >= instead of > because the former gives better
+ * code on the 6502 than the latter.
+ */
+ g_ge (flags, val+1);
+ } else {
+ /* Never true */
+ Warning ("Condition is never true");
+ AddCodeLine ("jsr return0");
+ }
+ } else {
+ /* Signed compare */
+ if ((long) val < 0x7FFF) {
+ g_ge (flags, val+1);
+ } else {
+ /* Never true */
+ Warning ("Condition is never true");
+ AddCodeLine ("jsr return0");
+ }
+ }
+ return;
+
+ case CF_LONG:
+ if (flags & CF_UNSIGNED) {
+ /* Unsigned compare */
+ if (val == 0) {
+ /* If we have a compare > 0, we will replace it by
+ * != 0 here, since both are identical but the latter
+ * is easier to optimize.
+ */
+ g_ne (flags, val);
+ } else if (val < 0xFFFFFFFF) {
+ /* Use >= instead of > because the former gives better
+ * code on the 6502 than the latter.
+ */
+ g_ge (flags, val+1);
+ } else {
+ /* Never true */
+ Warning ("Condition is never true");
+ AddCodeLine ("jsr return0");
+ }
+ } else {
+ /* Signed compare */
+ if ((long) val < 0x7FFFFFFF) {
+ g_ge (flags, val+1);
+ } else {
+ /* Never true */
+ Warning ("Condition is never true");
+ AddCodeLine ("jsr return0");
+ }
+ }
+ return;
+
+ default:
+ typeerror (flags);
+ }
+
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff. Note: The standard stuff will