From 91a79e47145e22e6ced3910e62f017c3012483ee Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 14 Aug 2003 13:08:46 +0000 Subject: [PATCH] Fixed a bug git-svn-id: svn://svn.cc65.org/cc65/trunk@2312 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codegen.c | 48 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 06fe224c7..5eb1825e3 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -585,39 +585,49 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) /* Don't loop for up to two bytes */ if (Bytes == 1) { - ldyconst (StackOffs); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta regbank%+d", RegOffs); + ldyconst (StackOffs); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta regbank%+d", RegOffs); } else if (Bytes == 2) { - ldyconst (StackOffs); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta regbank%+d", RegOffs); - AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta regbank%+d", RegOffs+1); + 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); } else { - /* More than two bytes - loop */ - unsigned Label = GetLocalLabel (); - ldyconst (StackOffs+Bytes-1); - ldxconst (Bytes); - g_defcodelabel (Label); + /* More bytes - loop */ + unsigned Label = GetLocalLabel (); + ldyconst (StackOffs); + g_defcodelabel (Label); AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta regbank%+d,x", RegOffs-1); - AddCodeLine ("dey"); - AddCodeLine ("dex"); + AddCodeLine ("sta regbank%+d,y", RegOffs - StackOffs); + AddCodeLine ("iny"); + AddCodeLine ("cpy #$%02X", StackOffs + Bytes); AddCodeLine ("bne %s", LocalLabelName (Label)); - } } /*****************************************************************************/ -/* Fetching memory cells */ +/* Fetching memory cells */ /*****************************************************************************/ -- 2.39.5