From f9204e5b6fae8843a45013e63fa91c0a72b8d4d2 Mon Sep 17 00:00:00 2001
From: acqn <acqn163@outlook.com>
Date: Thu, 16 Apr 2020 18:38:49 +0800
Subject: [PATCH] Fixed g_addlocal codegen with long types.

---
 src/cc65/codegen.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c
index a611f4f6a..35af5281e 100644
--- a/src/cc65/codegen.c
+++ b/src/cc65/codegen.c
@@ -1541,16 +1541,17 @@ void g_addlocal (unsigned flags, int offs)
 /* Add a local variable to ax */
 {
     unsigned L;
+    int NewOff;
 
     /* Correct the offset and check it */
-    offs -= StackPtr;
-    CheckLocalOffs (offs);
+    NewOff = offs - StackPtr;
+    CheckLocalOffs (NewOff);
 
     switch (flags & CF_TYPEMASK) {
 
         case CF_CHAR:
             L = GetLocalLabel();
-            AddCodeLine ("ldy #$%02X", offs & 0xFF);
+            AddCodeLine ("ldy #$%02X", NewOff & 0xFF);
             AddCodeLine ("clc");
             AddCodeLine ("adc (sp),y");
             AddCodeLine ("bcc %s", LocalLabelName (L));
@@ -1559,7 +1560,7 @@ void g_addlocal (unsigned flags, int offs)
             break;
 
         case CF_INT:
-            AddCodeLine ("ldy #$%02X", offs & 0xFF);
+            AddCodeLine ("ldy #$%02X", NewOff & 0xFF);
             AddCodeLine ("clc");
             AddCodeLine ("adc (sp),y");
             AddCodeLine ("pha");