From: cuz Date: Thu, 11 Oct 2001 07:01:16 +0000 (+0000) Subject: Track sreg in OptDecouple X-Git-Tag: V2.12.0~2572 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4fb253cef0c9bc6ebc27b5b8f48d532c0947f8e4;p=cc65 Track sreg in OptDecouple git-svn-id: svn://svn.cc65.org/cc65/trunk@1019 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index 288a069b7..7d9dddcb6 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -952,14 +952,17 @@ static unsigned OptPtrLoad6 (CodeSeg* S) static unsigned OptDecouple (CodeSeg* S) /* Decouple operations, that is, do the following replacements: * - * dex -> ldx - * inx -> ldx - * dey -> ldy - * iny -> ldy - * tax -> ldx - * txa -> lda - * tay -> ldy - * tya -> lda + * dex -> ldx #imm + * inx -> ldx #imm + * dey -> ldy #imm + * iny -> ldy #imm + * tax -> ldx #imm + * txa -> lda #imm + * tay -> ldy #imm + * tya -> lda #imm + * lda sreg -> lda #imm + * ldx sreg -> ldx #imm + * ldy sreg -> ldy #imm * * Provided that the register values are known of course. */ @@ -1013,6 +1016,42 @@ static unsigned OptDecouple (CodeSeg* S) } break; + case OP65_LDA: + if (E->AM == AM65_ZP) { + if ((E->Use & REG_SREG_LO) != 0 && E->RI->In.SRegLo >= 0) { + xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.SRegLo); + X = NewCodeEntry (OP65_LDA, AM65_IMM, Buf, 0, E->LI); + } else if ((E->Use & REG_SREG_HI) != 0 && E->RI->In.SRegHi >= 0) { + xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.SRegHi); + X = NewCodeEntry (OP65_LDA, AM65_IMM, Buf, 0, E->LI); + } + } + break; + + case OP65_LDX: + if (E->AM == AM65_ZP) { + if ((E->Use & REG_SREG_LO) != 0 && E->RI->In.SRegLo >= 0) { + xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.SRegLo); + X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, E->LI); + } else if ((E->Use & REG_SREG_HI) != 0 && E->RI->In.SRegHi >= 0) { + xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.SRegHi); + X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, E->LI); + } + } + break; + + case OP65_LDY: + if (E->AM == AM65_ZP) { + if ((E->Use & REG_SREG_LO) != 0 && E->RI->In.SRegLo >= 0) { + xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.SRegLo); + X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI); + } else if ((E->Use & REG_SREG_HI) != 0 && E->RI->In.SRegHi >= 0) { + xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.SRegHi); + X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI); + } + } + break; + case OP65_TAX: if (E->RI->In.RegA >= 0) { xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegA);