]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codegen.c
remove TABs
[cc65] / src / cc65 / codegen.c
index 4a3eb17c30f73b7decc7836844bb4a20d33dca2b..a611f4f6a809ec0789c5c975bfc7876104e10b8e 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 codegen.c                                */
+/*                                 codegen.c                                 */
 /*                                                                           */
-/*                            6502 code generator                           */
+/*                            6502 code generator                            */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
@@ -40,6 +40,7 @@
 /* common */
 #include "check.h"
 #include "cpu.h"
+#include "inttypes.h"
 #include "strbuf.h"
 #include "xmalloc.h"
 #include "xsprintf.h"
@@ -55,6 +56,7 @@
 #include "global.h"
 #include "segments.h"
 #include "stackptr.h"
+#include "stdfunc.h"
 #include "textseg.h"
 #include "util.h"
 #include "codegen.h"
@@ -62,7 +64,7 @@
 
 
 /*****************************************************************************/
-/*                                  Helpers                                 */
+/*                                  Helpers                                  */
 /*****************************************************************************/
 
 
@@ -91,7 +93,7 @@ static void CheckLocalOffs (unsigned Offs)
 
 
 
-static const char* GetLabelName (unsigned Flags, unsigned long Label, long Offs)
+static const char* GetLabelName (unsigned Flags, uintptr_t Label, long Offs)
 {
     static char Buf [256];              /* Label name */
 
@@ -103,22 +105,22 @@ static const char* GetLabelName (unsigned Flags, unsigned long Label, long Offs)
             if (Offs) {
                 xsprintf (Buf, sizeof (Buf), "%s%+ld", LocalLabelName (Label), Offs);
             } else {
-                       xsprintf (Buf, sizeof (Buf), "%s", LocalLabelName (Label));
+                xsprintf (Buf, sizeof (Buf), "%s", LocalLabelName (Label));
             }
             break;
 
         case CF_EXTERNAL:
             /* External label */
             if (Offs) {
-               xsprintf (Buf, sizeof (Buf), "_%s%+ld", (char*) Label, Offs);
+                xsprintf (Buf, sizeof (Buf), "_%s%+ld", (char*) Label, Offs);
             } else {
-               xsprintf (Buf, sizeof (Buf), "_%s", (char*) Label);
+                xsprintf (Buf, sizeof (Buf), "_%s", (char*) Label);
             }
             break;
 
         case CF_ABSOLUTE:
             /* Absolute address */
-            xsprintf (Buf, sizeof (Buf), "$%04X", (int)((Label+Offs) & 0xFFFF));
+            xsprintf (Buf, sizeof (Buf), "$%04X", (unsigned)((Label+Offs) & 0xFFFF));
             break;
 
         case CF_REGVAR:
@@ -137,7 +139,7 @@ static const char* GetLabelName (unsigned Flags, unsigned long Label, long Offs)
 
 
 /*****************************************************************************/
-/*                           Pre- and postamble                             */
+/*                            Pre- and postamble                             */
 /*****************************************************************************/
 
 
@@ -152,7 +154,7 @@ void g_preamble (void)
 
     /* Insert some object file options */
     AddTextLine ("\t.fopt\t\tcompiler,\"cc65 v %s\"",
-                GetVersionAsString ());
+                 GetVersionAsString ());
 
     /* If we're producing code for some other CPU, switch the command set */
     switch (CPU) {
@@ -192,8 +194,8 @@ void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime)
 {
     if (DebugInfo) {
         /* We have to place this into the global text segment, so it will
-         * appear before all .dbg line statements.
-         */
+        ** appear before all .dbg line statements.
+        */
         TS_AddLine (GS->Text, "\t.dbg\t\tfile, \"%s\", %lu, %lu", Name, Size, MTime);
     }
 }
@@ -201,7 +203,7 @@ void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime)
 
 
 /*****************************************************************************/
-/*                             Segment support                              */
+/*                              Segment support                              */
 /*****************************************************************************/
 
 
@@ -249,7 +251,7 @@ void g_segname (segment_t Seg)
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -298,15 +300,15 @@ int push (unsigned flags)
 
 static unsigned MakeByteOffs (unsigned Flags, unsigned Offs)
 /* The value in Offs is an offset to an address in a/x. Make sure, an object
- * of the type given in Flags can be loaded or stored into this address by
- * adding part of the offset to the address in ax, so that the remaining
- * offset fits into an index register. Return the remaining offset.
- */
+** of the type given in Flags can be loaded or stored into this address by
+** adding part of the offset to the address in ax, so that the remaining
+** offset fits into an index register. Return the remaining offset.
+*/
 {
     /* If the offset is too large for a byte register, add the high byte
-     * of the offset to the primary. Beware: We need a special correction
-     * if the offset in the low byte will overflow in the operation.
-     */
+    ** of the offset to the primary. Beware: We need a special correction
+    ** if the offset in the low byte will overflow in the operation.
+    */
     unsigned O = Offs & ~0xFFU;
     if ((Offs & 0xFF) > 256 - sizeofarg (Flags)) {
         /* We need to add the low byte also */
@@ -326,7 +328,7 @@ static unsigned MakeByteOffs (unsigned Flags, unsigned Offs)
 
 
 /*****************************************************************************/
-/*                     Functions handling local labels                      */
+/*                      Functions handling local labels                      */
 /*****************************************************************************/
 
 
@@ -351,8 +353,8 @@ void g_aliasdatalabel (unsigned label, unsigned baselabel, long offs)
 /* Define label as a local alias for baselabel+offs */
 {
     /* We need an intermediate buffer here since LocalLabelName uses a
-     * static buffer which changes with each call.
-     */
+    ** static buffer which changes with each call.
+    */
     StrBuf L = AUTO_STRBUF_INITIALIZER;
     SB_AppendStr (&L, LocalLabelName (label));
     SB_Terminate (&L);
@@ -366,7 +368,7 @@ void g_aliasdatalabel (unsigned label, unsigned baselabel, long offs)
 
 
 /*****************************************************************************/
-/*                    Functions handling global labels                      */
+/*                     Functions handling global labels                      */
 /*****************************************************************************/
 
 
@@ -421,16 +423,16 @@ void g_importmainargs (void)
 
 
 /*****************************************************************************/
-/*                          Function entry and exit                         */
+/*                          Function entry and exit                          */
 /*****************************************************************************/
 
 
 
 /* Remember the argument size of a function. The variable is set by g_enter
- * and used by g_leave. If the functions gets its argument size by the caller
- * (variable param list or function without prototype), g_enter will set the
- * value to -1.
- */
+** and used by g_leave. If the function gets its argument size by the caller
+** (variable param list or function without prototype), g_enter will set the
+** value to -1.
+*/
 static int funcargs;
 
 
@@ -485,7 +487,7 @@ void g_leave (void)
 
 
 /*****************************************************************************/
-/*                                   Register variables                             */
+/*                            Register variables                             */
 /*****************************************************************************/
 
 
@@ -602,9 +604,9 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
     } else if (StackOffs <= RegOffs) {
 
         /* More bytes, but the relation between the register offset in the
-         * register bank and the stack offset allows us to generate short
-         * code that uses just one index register.
-         */
+        ** register bank and the stack offset allows us to generate short
+        ** code that uses just one index register.
+        */
         unsigned Label = GetLocalLabel ();
         AddCodeLine ("ldy #$%02X", StackOffs);
         g_defcodelabel (Label);
@@ -616,9 +618,9 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
 
     } else {
 
-        /* Ok, this is the generic code. We need to save X because the
-         * caller will only save A.
-         */
+        /* OK, this is the generic code. We need to save X because the
+        ** caller will only save A.
+        */
         unsigned Label = GetLocalLabel ();
         AddCodeLine ("stx tmp1");
         AddCodeLine ("ldy #$%02X", (unsigned char) (StackOffs + Bytes - 1));
@@ -637,7 +639,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
 
 
 /*****************************************************************************/
-/*                           Fetching memory cells                          */
+/*                           Fetching memory cells                           */
 /*****************************************************************************/
 
 
@@ -686,7 +688,7 @@ void g_getimmed (unsigned Flags, unsigned long Val, long Offs)
                     AddCodeLine ("stx sreg+1");
                     Done |= 0x08;
                 }
-               if ((Done & 0x04) == 0 && B1 != B3) {
+                if ((Done & 0x04) == 0 && B1 != B3) {
                     AddCodeLine ("lda #$%02X", B3);
                     AddCodeLine ("sta sreg");
                     Done |= 0x04;
@@ -728,7 +730,7 @@ void g_getimmed (unsigned Flags, unsigned long Val, long Offs)
 
 
 
-void g_getstatic (unsigned flags, unsigned long label, long offs)
+void g_getstatic (unsigned flags, uintptr_t label, long offs)
 /* Fetch an static memory cell into the primary register */
 {
     /* Create the correct label name */
@@ -739,17 +741,17 @@ void g_getstatic (unsigned flags, unsigned long label, long offs)
 
         case CF_CHAR:
             if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
-                AddCodeLine ("lda %s", lbuf);  /* load A from the label */
+                AddCodeLine ("lda %s", lbuf);   /* load A from the label */
             } else {
                 AddCodeLine ("ldx #$00");
-               AddCodeLine ("lda %s", lbuf);   /* load A from the label */
-               if (!(flags & CF_UNSIGNED)) {
-                   /* Must sign extend */
+                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");
+                    AddCodeLine ("bpl %s", LocalLabelName (L));
+                    AddCodeLine ("dex");
                     g_defcodelabel (L);
-               }
+                }
             }
             break;
 
@@ -764,13 +766,13 @@ void g_getstatic (unsigned flags, unsigned long label, long offs)
 
         case CF_LONG:
             if (flags & CF_TEST) {
-               AddCodeLine ("lda %s+3", lbuf);
+                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+3", lbuf);
+                AddCodeLine ("sta sreg+1");
                 AddCodeLine ("lda %s+2", lbuf);
                 AddCodeLine ("sta sreg");
                 AddCodeLine ("ldx %s+1", lbuf);
@@ -801,12 +803,12 @@ void g_getlocal (unsigned Flags, int Offs)
                 AddCodeLine ("ldy #$%02X", Offs);
                 AddCodeLine ("ldx #$00");
                 AddCodeLine ("lda (sp),y");
-               if ((Flags & CF_UNSIGNED) == 0) {
+                if ((Flags & CF_UNSIGNED) == 0) {
                     unsigned L = GetLocalLabel();
-                   AddCodeLine ("bpl %s", LocalLabelName (L));
-                   AddCodeLine ("dex");
+                    AddCodeLine ("bpl %s", LocalLabelName (L));
+                    AddCodeLine ("dex");
                     g_defcodelabel (L);
-               }
+                }
             }
             break;
 
@@ -814,7 +816,7 @@ void g_getlocal (unsigned Flags, int Offs)
             CheckLocalOffs (Offs + 1);
             AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+1));
             if (Flags & CF_TEST) {
-               AddCodeLine ("lda (sp),y");
+                AddCodeLine ("lda (sp),y");
                 AddCodeLine ("dey");
                 AddCodeLine ("ora (sp),y");
             } else {
@@ -827,7 +829,7 @@ void g_getlocal (unsigned Flags, int Offs)
             AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+3));
             AddCodeLine ("jsr ldeaxysp");
             if (Flags & CF_TEST) {
-               g_test (Flags);
+                g_test (Flags);
             }
             break;
 
@@ -840,13 +842,13 @@ void g_getlocal (unsigned Flags, int Offs)
 
 void g_getind (unsigned Flags, unsigned Offs)
 /* Fetch the specified object type indirect through the primary register
- * into the primary register
- */
+** into the primary register
+*/
 {
     /* If the offset is greater than 255, add the part that is > 255 to
-     * the primary. This way we get an easy addition and use the low byte
-     * as the offset
-     */
+    ** the primary. This way we get an easy addition and use the low byte
+    ** as the offset
+    */
     Offs = MakeByteOffs (Flags, Offs);
 
     /* Handle the indirect fetch */
@@ -958,8 +960,8 @@ void g_leasp (int Offs)
 
 void g_leavariadic (int Offs)
 /* Fetch the address of a parameter in a variadic function into the primary
- * register
- */
+** register
+*/
 {
     unsigned ArgSizeOffs;
 
@@ -967,8 +969,8 @@ void g_leavariadic (int Offs)
     Offs -= StackPtr;
 
     /* 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.
-     */
+    ** entry and check if this offset is reachable with a byte offset.
+    */
     CHECK (StackPtr <= 0);
     ArgSizeOffs = -StackPtr;
     CheckLocalOffs (ArgSizeOffs);
@@ -1002,12 +1004,12 @@ void g_leavariadic (int Offs)
 
 
 /*****************************************************************************/
-/*                            Store into memory                             */
+/*                             Store into memory                             */
 /*****************************************************************************/
 
 
 
-void g_putstatic (unsigned flags, unsigned long label, long offs)
+void g_putstatic (unsigned flags, uintptr_t label, long offs)
 /* Store the primary register into the specified static memory cell */
 {
     /* Create the correct label name */
@@ -1051,7 +1053,7 @@ void g_putlocal (unsigned Flags, int Offs, long Val)
 
         case CF_CHAR:
             if (Flags & CF_CONST) {
-               AddCodeLine ("lda #$%02X", (unsigned char) Val);
+                AddCodeLine ("lda #$%02X", (unsigned char) Val);
             }
             AddCodeLine ("ldy #$%02X", Offs);
             AddCodeLine ("sta (sp),y");
@@ -1090,7 +1092,7 @@ void g_putlocal (unsigned Flags, int Offs, long Val)
 
         case CF_LONG:
             if (Flags & CF_CONST) {
-               g_getimmed (Flags, Val, 0);
+                g_getimmed (Flags, Val, 0);
             }
             AddCodeLine ("ldy #$%02X", Offs);
             AddCodeLine ("jsr steaxysp");
@@ -1106,14 +1108,14 @@ void g_putlocal (unsigned Flags, int Offs, long Val)
 
 void g_putind (unsigned Flags, unsigned Offs)
 /* Store the specified object type in the primary register at the address
- * on the top of the stack
- */
+** on the top of the stack
+*/
 {
     /* We can handle offsets below $100 directly, larger offsets must be added
-     * to the address. Since a/x is in use, best code is achieved by adding
-     * just the high byte. Be sure to check if the low byte will overflow while
-     * while storing.
-     */
+    ** to the address. Since a/x is in use, best code is achieved by adding
+    ** just the high byte. Be sure to check if the low byte will overflow while
+    ** while storing.
+    */
     if ((Offs & 0xFF) > 256 - sizeofarg (Flags | CF_FORCECHAR)) {
 
         /* Overflow - we need to add the low byte also */
@@ -1175,7 +1177,7 @@ void g_putind (unsigned Flags, unsigned Offs)
 
 
 /*****************************************************************************/
-/*                    type conversion and similiar stuff                    */
+/*                    type conversion and similiar stuff                     */
 /*****************************************************************************/
 
 
@@ -1226,26 +1228,34 @@ void g_tosint (unsigned flags)
 
 
 
-void g_regint (unsigned Flags)
-/* Make sure, the value in the primary register an int. Convert if necessary */
+static void g_regchar (unsigned Flags)
+/* Make sure, the value in the primary register is in the range of char. Truncate if necessary */
 {
     unsigned L;
 
+    AddCodeLine ("ldx #$00");
+
+    if ((Flags & CF_UNSIGNED) == 0) {
+        /* Sign extend */
+        L = GetLocalLabel();
+        AddCodeLine ("cmp #$80");
+        AddCodeLine ("bcc %s", LocalLabelName (L));
+        AddCodeLine ("dex");
+        g_defcodelabel (L);
+    }
+}
+
+
+
+void g_regint (unsigned Flags)
+/* Make sure, the value in the primary register an int. Convert if necessary */
+{
     switch (Flags & CF_TYPEMASK) {
 
         case CF_CHAR:
             if (Flags & CF_FORCECHAR) {
                 /* Conversion is from char */
-                if (Flags & CF_UNSIGNED) {
-                    AddCodeLine ("ldx #$00");
-                } else {
-                    L = GetLocalLabel();
-                    AddCodeLine ("ldx #$00");
-                    AddCodeLine ("cmp #$80");
-                    AddCodeLine ("bcc %s", LocalLabelName (L));
-                    AddCodeLine ("dex");
-                    g_defcodelabel (L);
-                }
+                g_regchar (Flags);
             }
             /* FALLTHROUGH */
 
@@ -1263,8 +1273,6 @@ void g_regint (unsigned Flags)
 void g_reglong (unsigned Flags)
 /* Make sure, the value in the primary register a long. Convert if necessary */
 {
-    unsigned L;
-
     switch (Flags & CF_TYPEMASK) {
 
         case CF_CHAR:
@@ -1280,12 +1288,7 @@ void g_reglong (unsigned Flags)
                     }
                 } else {
                     if (IS_Get (&CodeSizeFactor) >= 366) {
-                        L = GetLocalLabel();
-                        AddCodeLine ("ldx #$00");
-                        AddCodeLine ("cmp #$80");
-                        AddCodeLine ("bcc %s", LocalLabelName (L));
-                        AddCodeLine ("dex");
-                        g_defcodelabel (L);
+                        g_regchar (Flags);
                         AddCodeLine ("stx sreg");
                         AddCodeLine ("stx sreg+1");
                     } else {
@@ -1297,15 +1300,15 @@ void g_reglong (unsigned Flags)
 
         case CF_INT:
             if (Flags & CF_UNSIGNED) {
-               if (IS_Get (&CodeSizeFactor) >= 200) {
+                if (IS_Get (&CodeSizeFactor) >= 200) {
                     AddCodeLine ("ldy #$00");
-                   AddCodeLine ("sty sreg");
-                   AddCodeLine ("sty sreg+1");
-               } else {
-                           AddCodeLine ("jsr axulong");
-               }
+                    AddCodeLine ("sty sreg");
+                    AddCodeLine ("sty sreg+1");
+                } else {
+                    AddCodeLine ("jsr axulong");
+                }
             } else {
-               AddCodeLine ("jsr axlong");
+                AddCodeLine ("jsr axlong");
             }
             break;
 
@@ -1321,9 +1324,9 @@ void g_reglong (unsigned Flags)
 
 unsigned g_typeadjust (unsigned lhs, unsigned rhs)
 /* Adjust the integer operands before doing a binary operation. lhs is a flags
- * value, that corresponds to the value on TOS, rhs corresponds to the value
- * in (e)ax. The return value is the the flags value for the resulting type.
- */
+** value, that corresponds to the value on TOS, rhs corresponds to the value
+** in (e)ax. The return value is the the flags value for the resulting type.
+*/
 {
     unsigned ltype, rtype;
     unsigned result;
@@ -1352,11 +1355,11 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs)
     }
 
     /* Determine the result type for the operation:
-     *  - The result is const if both operands are const.
-     *  - The result is unsigned if one of the operands is unsigned.
-     *  - The result is long if one of the operands is long.
-     *  - Otherwise the result is int sized.
-     */
+    **  - The result is const if both operands are const.
+    **  - The result is unsigned if one of the operands is unsigned.
+    **  - The result is long if one of the operands is long.
+    **  - Otherwise the result is int sized.
+    */
     result = (lhs & CF_CONST) & (rhs & CF_CONST);
     result |= (lhs & CF_UNSIGNED) | (rhs & CF_UNSIGNED);
     if (rtype == CF_LONG || ltype == CF_LONG) {
@@ -1371,38 +1374,45 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs)
 
 unsigned g_typecast (unsigned lhs, unsigned rhs)
 /* Cast the value in the primary register to the operand size that is flagged
- * by the lhs value. Return the result value.
- */
+** by the lhs value. Return the result value.
+*/
 {
-    unsigned ltype, rtype;
-
-    /* Get the type spec from the flags */
-    ltype = lhs & CF_TYPEMASK;
-    rtype = rhs & CF_TYPEMASK;
-
     /* Check if a conversion is needed */
     if ((rhs & CF_CONST) == 0) {
-        if (ltype == CF_LONG && rtype != CF_LONG) {
-            /* We must promote the primary register to long */
-            g_reglong (rhs);
-        } else if (ltype == CF_INT && rtype != CF_INT) {
-            /* We must promote the primary register to int */
-            g_regint (rhs);
+        switch (lhs & CF_TYPEMASK) {
+
+            case CF_LONG:
+                /* We must promote the primary register to long */
+                g_reglong (rhs);
+                break;
+
+            case CF_INT:
+                /* We must promote the primary register to int */
+                g_regint (rhs);
+                break;
+
+            case CF_CHAR:
+                /* We must truncate the primary register to char */
+                g_regchar (lhs);
+                break;
+
+            default:
+                typeerror (lhs);
         }
     }
 
     /* Do not need any other action. If the left type is int, and the primary
-     * register is long, it will be automagically truncated. If the right hand
-     * side is const, it is not located in the primary register and handled by
-     * the expression parser code.
-     */
+    ** register is long, it will be automagically truncated. If the right hand
+    ** side is const, it is not located in the primary register and handled by
+    ** the expression parser code.
+    */
 
     /* Result is const if the right hand side was const */
     lhs |= (rhs & CF_CONST);
 
     /* The resulting type is that of the left hand side (that's why you called
-     * this function :-)
-     */
+    ** this function :-)
+    */
     return lhs;
 }
 
@@ -1410,10 +1420,10 @@ unsigned g_typecast (unsigned lhs, unsigned rhs)
 
 void g_scale (unsigned flags, long val)
 /* Scale the value in the primary register by the given value. If val is positive,
- * scale up, is val is negative, scale down. This function is used to scale
- * the operands or results of pointer arithmetic by the size of the type, the
- * pointer points to.
- */
+** scale up, is val is negative, scale down. This function is used to scale
+** the operands or results of pointer arithmetic by the size of the type, the
+** pointer points to.
+*/
 {
     int p2;
 
@@ -1430,28 +1440,28 @@ void g_scale (unsigned flags, long val)
 
                 case CF_CHAR:
                     if (flags & CF_FORCECHAR) {
-                       while (p2--) {
-                           AddCodeLine ("asl a");
-                       }
-                       break;
-                   }
-                   /* FALLTHROUGH */
-
-               case CF_INT:
+                        while (p2--) {
+                            AddCodeLine ("asl a");
+                        }
+                        break;
+                    }
+                    /* FALLTHROUGH */
+
+                case CF_INT:
                     if (flags & CF_UNSIGNED) {
                         AddCodeLine ("jsr shlax%d", p2);
                     } else {
                         AddCodeLine ("jsr aslax%d", p2);
                     }
-                   break;
+                    break;
 
-               case CF_LONG:
-                   if (flags & CF_UNSIGNED) {
-                       AddCodeLine ("jsr shleax%d", p2);
-                   } else {
-                       AddCodeLine ("jsr asleax%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);
@@ -1478,11 +1488,11 @@ void g_scale (unsigned flags, long val)
                     if (flags & CF_FORCECHAR) {
                         if (flags & CF_UNSIGNED) {
                             while (p2--) {
-                               AddCodeLine ("lsr a");
+                                AddCodeLine ("lsr a");
                             }
                             break;
                         } else if (p2 <= 2) {
-                           AddCodeLine ("cmp #$80");
+                            AddCodeLine ("cmp #$80");
                             AddCodeLine ("ror a");
                             break;
                         }
@@ -1499,9 +1509,9 @@ void g_scale (unsigned flags, long val)
 
                 case CF_LONG:
                     if (flags & CF_UNSIGNED) {
-                       AddCodeLine ("jsr lsreax%d", p2);
+                        AddCodeLine ("jsr lsreax%d", p2);
                     } else {
-                               AddCodeLine ("jsr asreax%d", p2);
+                        AddCodeLine ("jsr asreax%d", p2);
                     }
                     break;
 
@@ -1522,7 +1532,7 @@ void g_scale (unsigned flags, long val)
 
 
 /*****************************************************************************/
-/*             Adds and subs of variables fix a fixed address               */
+/*              Adds and subs of variables fix a fixed address               */
 /*****************************************************************************/
 
 
@@ -1575,7 +1585,7 @@ void g_addlocal (unsigned flags, int offs)
 
 
 
-void g_addstatic (unsigned flags, unsigned long label, long offs)
+void g_addstatic (unsigned flags, uintptr_t label, long offs)
 /* Add a static variable to ax */
 {
     unsigned L;
@@ -1620,13 +1630,13 @@ void g_addstatic (unsigned flags, unsigned long label, long offs)
 
 
 /*****************************************************************************/
-/*                          Special op= functions                           */
+/*                           Special op= functions                           */
 /*****************************************************************************/
 
 
 
-void g_addeqstatic (unsigned flags, unsigned long label, long offs,
-                   unsigned long val)
+void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
+                    unsigned long val)
 /* Emit += for a static variable */
 {
     /* Create the correct label name */
@@ -1637,25 +1647,25 @@ void g_addeqstatic (unsigned flags, unsigned long label, long offs,
 
         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) {
+                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 ("bpl %s", LocalLabelName (L));
                     AddCodeLine ("dex");
                     g_defcodelabel (L);
                 }
@@ -1671,25 +1681,25 @@ void g_addeqstatic (unsigned flags, unsigned long label, long offs,
                     AddCodeLine ("bne %s", LocalLabelName (L));
                     AddCodeLine ("inc %s+1", lbuf);
                     g_defcodelabel (L);
-                    AddCodeLine ("lda %s", lbuf);              /* Hmmm... */
+                    AddCodeLine ("lda %s", lbuf);               /* Hmmm... */
                     AddCodeLine ("ldx %s+1", lbuf);
                 } else {
-                           AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+                    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);
+                        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);
+                        AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8));
+                        AddCodeLine ("adc %s+1", lbuf);
+                        AddCodeLine ("sta %s+1", lbuf);
+                        AddCodeLine ("tax");
+                        AddCodeLine ("lda %s", lbuf);
                     }
                 }
             } else {
@@ -1698,9 +1708,9 @@ void g_addeqstatic (unsigned flags, unsigned long label, long offs,
                 AddCodeLine ("sta %s", lbuf);
                 AddCodeLine ("txa");
                 AddCodeLine ("adc %s+1", lbuf);
-               AddCodeLine ("sta %s+1", lbuf);
-               AddCodeLine ("tax");
-               AddCodeLine ("lda %s", lbuf);
+                AddCodeLine ("sta %s+1", lbuf);
+                AddCodeLine ("tax");
+                AddCodeLine ("lda %s", lbuf);
             }
             break;
 
@@ -1714,7 +1724,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, long offs,
                         AddCodeLine ("jsr laddeq1");
                     } else {
                         AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
-                       AddCodeLine ("jsr laddeqa");
+                        AddCodeLine ("jsr laddeqa");
                     }
                 } else {
                     g_getstatic (flags, label, offs);
@@ -1760,13 +1770,13 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val)
                     AddCodeLine ("adc (sp),y");
                     AddCodeLine ("sta (sp),y");
                 }
-               if ((flags & CF_UNSIGNED) == 0) {
+                if ((flags & CF_UNSIGNED) == 0) {
                     unsigned L = GetLocalLabel();
-                   AddCodeLine ("bpl %s", LocalLabelName (L));
-                   AddCodeLine ("dex");
+                    AddCodeLine ("bpl %s", LocalLabelName (L));
+                    AddCodeLine ("dex");
                     g_defcodelabel (L);
-               }
-               break;
+                }
+                break;
             }
             /* FALLTHROUGH */
 
@@ -1790,13 +1800,13 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val)
                     AddCodeLine ("jsr addeqysp");
                 }
             } else {
-               AddCodeLine ("jsr addeqysp");
+                AddCodeLine ("jsr addeqysp");
             }
             break;
 
         case CF_LONG:
             if (flags & CF_CONST) {
-               g_getimmed (flags, val, 0);
+                g_getimmed (flags, val, 0);
             }
             AddCodeLine ("ldy #$%02X", Offs);
             AddCodeLine ("jsr laddeqysp");
@@ -1813,9 +1823,9 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
 /* Emit += for the location with address in ax */
 {
     /* If the offset is too large for a byte register, add the high byte
-     * of the offset to the primary. Beware: We need a special correction
-     * if the offset in the low byte will overflow in the operation.
-     */
+    ** of the offset to the primary. Beware: We need a special correction
+    ** if the offset in the low byte will overflow in the operation.
+    */
     offs = MakeByteOffs (flags, offs);
 
     /* Check the size and determine operation */
@@ -1834,11 +1844,11 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
 
         case CF_INT:
         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 */
+            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:
@@ -1848,7 +1858,7 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
 
 
 
-void g_subeqstatic (unsigned flags, unsigned long label, long offs,
+void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
                     unsigned long val)
 /* Emit -= for a static variable */
 {
@@ -1861,41 +1871,41 @@ void g_subeqstatic (unsigned flags, unsigned long label, long offs,
         case CF_CHAR:
             if (flags & CF_FORCECHAR) {
                 AddCodeLine ("ldx #$00");
-               if (flags & CF_CONST) {
+                if (flags & CF_CONST) {
                     if (val == 1) {
                         AddCodeLine ("dec %s", lbuf);
                         AddCodeLine ("lda %s", lbuf);
                     } else {
-                       AddCodeLine ("lda %s", lbuf);
-                               AddCodeLine ("sec");
-                       AddCodeLine ("sbc #$%02X", (int)(val & 0xFF));
-                       AddCodeLine ("sta %s", lbuf);
+                        AddCodeLine ("lda %s", lbuf);
+                        AddCodeLine ("sec");
+                        AddCodeLine ("sbc #$%02X", (int)(val & 0xFF));
+                        AddCodeLine ("sta %s", lbuf);
                     }
-               } else {
+                } else {
                     AddCodeLine ("eor #$FF");
                     AddCodeLine ("sec");
-                           AddCodeLine ("adc %s", lbuf);
+                    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;
+                }
+                break;
             }
             /* FALLTHROUGH */
 
         case CF_INT:
             if (flags & CF_CONST) {
-                       AddCodeLine ("lda %s", lbuf);
+                AddCodeLine ("lda %s", lbuf);
                 AddCodeLine ("sec");
-               AddCodeLine ("sbc #$%02X", (unsigned char)val);
-               AddCodeLine ("sta %s", lbuf);
-               if (val < 0x100) {
-                   unsigned L = GetLocalLabel ();
-                   AddCodeLine ("bcs %s", LocalLabelName (L));
+                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);
@@ -1909,11 +1919,11 @@ void g_subeqstatic (unsigned flags, unsigned long label, long offs,
             } else {
                 AddCodeLine ("eor #$FF");
                 AddCodeLine ("sec");
-                       AddCodeLine ("adc %s", lbuf);
+                AddCodeLine ("adc %s", lbuf);
                 AddCodeLine ("sta %s", lbuf);
                 AddCodeLine ("txa");
                 AddCodeLine ("eor #$FF");
-                       AddCodeLine ("adc %s+1", lbuf);
+                AddCodeLine ("adc %s+1", lbuf);
                 AddCodeLine ("sta %s+1", lbuf);
                 AddCodeLine ("tax");
                 AddCodeLine ("lda %s", lbuf);
@@ -1969,22 +1979,22 @@ void g_subeqlocal (unsigned flags, int Offs, unsigned long val)
                 } else {
                     AddCodeLine ("eor #$FF");
                     AddCodeLine ("sec");
-                   AddCodeLine ("adc (sp),y");
+                    AddCodeLine ("adc (sp),y");
                 }
-               AddCodeLine ("sta (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;
+                    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);
+                g_getimmed (flags, val, 0);
             }
             AddCodeLine ("ldy #$%02X", Offs);
             AddCodeLine ("jsr subeqysp");
@@ -1992,7 +2002,7 @@ void g_subeqlocal (unsigned flags, int Offs, unsigned long val)
 
         case CF_LONG:
             if (flags & CF_CONST) {
-               g_getimmed (flags, val, 0);
+                g_getimmed (flags, val, 0);
             }
             AddCodeLine ("ldy #$%02X", Offs);
             AddCodeLine ("jsr lsubeqysp");
@@ -2009,9 +2019,9 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
 /* Emit -= for the location with address in ax */
 {
     /* If the offset is too large for a byte register, add the high byte
-     * of the offset to the primary. Beware: We need a special correction
-     * if the offset in the low byte will overflow in the operation.
-     */
+    ** of the offset to the primary. Beware: We need a special correction
+    ** if the offset in the low byte will overflow in the operation.
+    */
     offs = MakeByteOffs (flags, offs);
 
     /* Check the size and determine operation */
@@ -2030,11 +2040,11 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
 
         case CF_INT:
         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 */
+            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:
@@ -2045,7 +2055,7 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
 
 
 /*****************************************************************************/
-/*                 Add a variable address to the value in ax                */
+/*                 Add a variable address to the value in ax                 */
 /*****************************************************************************/
 
 
@@ -2084,7 +2094,7 @@ void g_addaddr_local (unsigned flags attribute ((unused)), int offs)
 
 
 
-void g_addaddr_static (unsigned flags, unsigned long label, long offs)
+void g_addaddr_static (unsigned flags, uintptr_t label, long offs)
 /* Add the address of a static variable to ax */
 {
     /* Create the correct label name */
@@ -2103,7 +2113,7 @@ void g_addaddr_static (unsigned flags, unsigned long label, long offs)
 
 
 /*****************************************************************************/
-/*                                                                          */
+/*                                                                           */
 /*****************************************************************************/
 
 
@@ -2116,7 +2126,7 @@ void g_save (unsigned flags)
 
         case CF_CHAR:
             if (flags & CF_FORCECHAR) {
-               AddCodeLine ("pha");
+                AddCodeLine ("pha");
                 break;
             }
             /* FALLTHROUGH */
@@ -2145,8 +2155,8 @@ void g_restore (unsigned flags)
 
         case CF_CHAR:
             if (flags & CF_FORCECHAR) {
-                       AddCodeLine ("pla");
-               break;
+                AddCodeLine ("pla");
+                break;
             }
             /* FALLTHROUGH */
 
@@ -2168,8 +2178,8 @@ void g_restore (unsigned flags)
 
 void g_cmp (unsigned flags, unsigned long val)
 /* Immidiate compare. The primary register will not be changed, Z flag
- * will be set.
- */
+** will be set.
+*/
 {
     unsigned L;
 
@@ -2178,8 +2188,8 @@ void g_cmp (unsigned flags, unsigned long val)
 
         case CF_CHAR:
             if (flags & CF_FORCECHAR) {
-                       AddCodeLine ("cmp #$%02X", (unsigned char)val);
-                       break;
+                AddCodeLine ("cmp #$%02X", (unsigned char)val);
+                break;
             }
             /* FALLTHROUGH */
 
@@ -2202,13 +2212,13 @@ void g_cmp (unsigned flags, unsigned long val)
 
 
 
-static void oper (unsigned Flags, unsigned long Val, const char** Subs)
+static void oper (unsigned Flags, unsigned long Val, const char* const* Subs)
 /* Encode a binary operation. subs is a pointer to four strings:
- *      0      --> Operate on ints
- *      1      --> Operate on unsigneds
- *      2      --> Operate on longs
- *      3      --> Operate on unsigned longs
- */
+**      0       --> Operate on ints
+**      1       --> Operate on unsigneds
+**      2       --> Operate on longs
+**      3       --> Operate on unsigned longs
+*/
 {
     /* Determine the offset into the array */
     if (Flags & CF_UNSIGNED) {
@@ -2252,9 +2262,9 @@ void g_test (unsigned flags)
 
         case CF_LONG:
             if (flags & CF_UNSIGNED) {
-               AddCodeLine ("jsr utsteax");
+                AddCodeLine ("jsr utsteax");
             } else {
-               AddCodeLine ("jsr tsteax");
+                AddCodeLine ("jsr tsteax");
             }
             break;
 
@@ -2308,7 +2318,7 @@ void g_push (unsigned flags, unsigned long val)
                 break;
 
             case CF_LONG:
-               AddCodeLine ("jsr pusheax");
+                AddCodeLine ("jsr pusheax");
                 break;
 
             default:
@@ -2326,8 +2336,8 @@ void g_push (unsigned flags, unsigned long val)
 
 void g_swap (unsigned flags)
 /* Swap the primary register and the top of the stack. flags give the type
- * of *both* values (must have same size).
- */
+** of *both* values (must have same size).
+*/
 {
     switch (flags & CF_TYPEMASK) {
 
@@ -2415,14 +2425,27 @@ void g_falsejump (unsigned flags attribute ((unused)), unsigned label)
 }
 
 
+void g_lateadjustSP (unsigned label)
+/* Adjust stack based on non-immediate data */
+{
+    AddCodeLine ("pha");
+    AddCodeLine ("lda %s", LocalLabelName (label));
+    AddCodeLine ("clc");
+    AddCodeLine ("adc sp");
+    AddCodeLine ("sta sp");
+    AddCodeLine ("lda %s+1", LocalLabelName (label));
+    AddCodeLine ("adc sp+1");
+    AddCodeLine ("sta sp+1");
+    AddCodeLine ("pla");
+}
 
 void g_drop (unsigned Space)
 /* Drop space allocated on the stack */
 {
     if (Space > 255) {
         /* Inline the code since calling addysp repeatedly is quite some
-         * overhead.
-         */
+        ** overhead.
+        */
         AddCodeLine ("pha");
         AddCodeLine ("lda #$%02X", (unsigned char) Space);
         AddCodeLine ("clc");
@@ -2450,8 +2473,8 @@ void g_space (int Space)
         g_drop (-Space);
     } else if (Space > 255) {
         /* Inline the code since calling subysp repeatedly is quite some
-         * overhead.
-         */
+        ** overhead.
+        */
         AddCodeLine ("pha");
         AddCodeLine ("lda sp");
         AddCodeLine ("sec");
@@ -2490,12 +2513,12 @@ void g_stackcheck (void)
 void g_add (unsigned flags, unsigned long val)
 /* Primary = TOS + Primary */
 {
-    static const char* ops[12] = {
+    static const char* const ops[4] = {
         "tosaddax", "tosaddax", "tosaddeax", "tosaddeax"
     };
 
     if (flags & CF_CONST) {
-        flags &= ~CF_FORCECHAR;        /* Handle chars as ints */
+        flags &= ~CF_FORCECHAR; /* Handle chars as ints */
         g_push (flags & ~CF_CONST, 0);
     }
     oper (flags, val, ops);
@@ -2506,12 +2529,12 @@ void g_add (unsigned flags, unsigned long val)
 void g_sub (unsigned flags, unsigned long val)
 /* Primary = TOS - Primary */
 {
-    static const char* ops[12] = {
-        "tossubax", "tossubax", "tossubeax", "tossubeax",
+    static const char* const ops[4] = {
+        "tossubax", "tossubax", "tossubeax", "tossubeax"
     };
 
     if (flags & CF_CONST) {
-        flags &= ~CF_FORCECHAR;        /* Handle chars as ints */
+        flags &= ~CF_FORCECHAR; /* Handle chars as ints */
         g_push (flags & ~CF_CONST, 0);
     }
     oper (flags, val, ops);
@@ -2522,8 +2545,8 @@ void g_sub (unsigned flags, unsigned long val)
 void g_rsub (unsigned flags, unsigned long val)
 /* Primary = Primary - TOS */
 {
-    static const char* ops[12] = {
-        "tosrsubax", "tosrsubax", "tosrsubeax", "tosrsubeax",
+    static const char* const ops[4] = {
+        "tosrsubax", "tosrsubax", "tosrsubeax", "tosrsubeax"
     };
     oper (flags, val, ops);
 }
@@ -2533,8 +2556,8 @@ void g_rsub (unsigned flags, unsigned long val)
 void g_mul (unsigned flags, unsigned long val)
 /* Primary = TOS * Primary */
 {
-    static const char* ops[12] = {
-        "tosmulax", "tosumulax", "tosmuleax", "tosumuleax",
+    static const char* const ops[4] = {
+        "tosmulax", "tosumulax", "tosmuleax", "tosumuleax"
     };
 
     int p2;
@@ -2547,8 +2570,8 @@ void g_mul (unsigned flags, unsigned long val)
     }
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -2558,37 +2581,37 @@ void g_mul (unsigned flags, unsigned long val)
                     /* 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");
+                        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");
-                           return;
-
-                       case 10:
-                           AddCodeLine ("sta tmp1");
-                           AddCodeLine ("asl a");
-                           AddCodeLine ("asl a");
-                           AddCodeLine ("clc");
-                           AddCodeLine ("adc tmp1");
-                           AddCodeLine ("asl a");
-                           return;
+                            AddCodeLine ("clc");
+                            AddCodeLine ("adc tmp1");
+                            AddCodeLine ("asl a");
+                            return;
                     }
                 }
                 /* FALLTHROUGH */
@@ -2624,9 +2647,9 @@ void g_mul (unsigned flags, unsigned long val)
         }
 
         /* 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 */
+        ** into the normal, non-optimized stuff.
+        */
+        flags &= ~CF_FORCECHAR; /* Handle chars as ints */
         g_push (flags & ~CF_CONST, 0);
 
     }
@@ -2640,8 +2663,8 @@ void g_mul (unsigned flags, unsigned long val)
 void g_div (unsigned flags, unsigned long val)
 /* Primary = TOS / Primary */
 {
-    static const char* ops[12] = {
-        "tosdivax", "tosudivax", "tosdiveax", "tosudiveax",
+    static const char* const ops[4] = {
+        "tosdivax", "tosudivax", "tosdiveax", "tosudiveax"
     };
 
     /* Do strength reduction if the value is constant and a power of two */
@@ -2653,7 +2676,7 @@ void g_div (unsigned flags, unsigned long val)
         /* Generate a division */
         if (flags & CF_CONST) {
             /* lhs is not on stack */
-            flags &= ~CF_FORCECHAR;    /* Handle chars as ints */
+            flags &= ~CF_FORCECHAR;     /* Handle chars as ints */
             g_push (flags & ~CF_CONST, 0);
         }
         oper (flags, val, ops);
@@ -2665,8 +2688,8 @@ void g_div (unsigned flags, unsigned long val)
 void g_mod (unsigned flags, unsigned long val)
 /* Primary = TOS % Primary */
 {
-    static const char* ops[12] = {
-        "tosmodax", "tosumodax", "tosmodeax", "tosumodeax",
+    static const char* const ops[4] = {
+        "tosmodax", "tosumodax", "tosmodeax", "tosumodeax"
     };
     int p2;
 
@@ -2678,7 +2701,7 @@ void g_mod (unsigned flags, unsigned long val)
         /* Do it the hard way... */
         if (flags & CF_CONST) {
             /* lhs is not on stack */
-            flags &= ~CF_FORCECHAR;    /* Handle chars as ints */
+            flags &= ~CF_FORCECHAR;     /* Handle chars as ints */
             g_push (flags & ~CF_CONST, 0);
         }
         oper (flags, val, ops);
@@ -2690,13 +2713,13 @@ void g_mod (unsigned flags, unsigned long val)
 void g_or (unsigned flags, unsigned long val)
 /* Primary = TOS | Primary */
 {
-    static const char* ops[12] = {
-        "tosorax", "tosorax", "tosoreax", "tosoreax",
+    static const char* const ops[4] = {
+        "tosorax", "tosorax", "tosoreax", "tosoreax"
     };
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -2704,7 +2727,7 @@ void g_or (unsigned flags, unsigned long val)
             case CF_CHAR:
                 if (flags & CF_FORCECHAR) {
                     if ((val & 0xFF) != 0) {
-                               AddCodeLine ("ora #$%02X", (unsigned char)val);
+                        AddCodeLine ("ora #$%02X", (unsigned char)val);
                     }
                     return;
                 }
@@ -2744,9 +2767,9 @@ void g_or (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -2760,14 +2783,14 @@ void g_or (unsigned flags, unsigned long val)
 void g_xor (unsigned flags, unsigned long val)
 /* Primary = TOS ^ Primary */
 {
-    static const char* ops[12] = {
-        "tosxorax", "tosxorax", "tosxoreax", "tosxoreax",
+    static const char* const ops[4] = {
+        "tosxorax", "tosxorax", "tosxoreax", "tosxoreax"
     };
 
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -2775,7 +2798,7 @@ void g_xor (unsigned flags, unsigned long val)
             case CF_CHAR:
                 if (flags & CF_FORCECHAR) {
                     if ((val & 0xFF) != 0) {
-                               AddCodeLine ("eor #$%02X", (unsigned char)val);
+                        AddCodeLine ("eor #$%02X", (unsigned char)val);
                     }
                     return;
                 }
@@ -2784,14 +2807,14 @@ void g_xor (unsigned flags, unsigned long val)
             case CF_INT:
                 if (val <= 0xFF) {
                     if (val != 0) {
-                       AddCodeLine ("eor #$%02X", (unsigned char)val);
+                        AddCodeLine ("eor #$%02X", (unsigned char)val);
                     }
-                       } else if (val != 0) {
+                } else if (val != 0) {
                     if ((val & 0xFF) != 0) {
                         AddCodeLine ("eor #$%02X", (unsigned char)val);
                     }
                     AddCodeLine ("pha");
-                   AddCodeLine ("txa");
+                    AddCodeLine ("txa");
                     AddCodeLine ("eor #$%02X", (unsigned char)(val >> 8));
                     AddCodeLine ("tax");
                     AddCodeLine ("pla");
@@ -2801,7 +2824,7 @@ void g_xor (unsigned flags, unsigned long val)
             case CF_LONG:
                 if (val <= 0xFF) {
                     if (val != 0) {
-                               AddCodeLine ("eor #$%02X", (unsigned char)val);
+                        AddCodeLine ("eor #$%02X", (unsigned char)val);
                     }
                     return;
                 }
@@ -2812,9 +2835,9 @@ void g_xor (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -2828,13 +2851,13 @@ void g_xor (unsigned flags, unsigned long val)
 void g_and (unsigned Flags, unsigned long Val)
 /* Primary = TOS & Primary */
 {
-    static const char* ops[12] = {
-        "tosandax", "tosandax", "tosandeax", "tosandeax",
+    static const char* const ops[4] = {
+        "tosandax", "tosandax", "tosandeax", "tosandeax"
     };
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (Flags & CF_CONST) {
 
         switch (Flags & CF_TYPEMASK) {
@@ -2846,37 +2869,37 @@ void g_and (unsigned Flags, unsigned long Val)
                     } else if ((Val & 0xFF) != 0xFF) {
                         AddCodeLine ("and #$%02X", (unsigned char)Val);
                     }
-                           return;
-                       }
-                       /* FALLTHROUGH */
+                    return;
+                }
+                /* FALLTHROUGH */
             case CF_INT:
-                       if ((Val & 0xFFFF) != 0xFFFF) {
-                           if (Val <= 0xFF) {
+                if ((Val & 0xFFFF) != 0xFFFF) {
+                    if (Val <= 0xFF) {
                         AddCodeLine ("ldx #$00");
-                               if (Val == 0) {
+                        if (Val == 0) {
                             AddCodeLine ("lda #$00");
-                               } else if (Val != 0xFF) {
-                                   AddCodeLine ("and #$%02X", (unsigned char)Val);
-                               }
-                           } else if ((Val & 0xFFFF) == 0xFF00) {
+                        } else if (Val != 0xFF) {
+                            AddCodeLine ("and #$%02X", (unsigned char)Val);
+                        }
+                    } else if ((Val & 0xFFFF) == 0xFF00) {
                         AddCodeLine ("lda #$00");
                     } 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");
-                       AddCodeLine ("lda #$00");
+                        AddCodeLine ("and #$%02X", (unsigned char)Val);
+                    } else if ((Val & 0x00FF) == 0x0000) {
+                        AddCodeLine ("txa");
+                        AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
+                        AddCodeLine ("tax");
+                        AddCodeLine ("lda #$00");
                     } else {
-                       AddCodeLine ("tay");
-                       AddCodeLine ("txa");
-                       AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
-                       AddCodeLine ("tax");
-                       AddCodeLine ("tya");
-                       if ((Val & 0x00FF) == 0x0000) {
+                        AddCodeLine ("tay");
+                        AddCodeLine ("txa");
+                        AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
+                        AddCodeLine ("tax");
+                        AddCodeLine ("tya");
+                        if ((Val & 0x00FF) == 0x0000) {
                             AddCodeLine ("lda #$00");
-                       } else if ((Val & 0x00FF) != 0x00FF) {
-                                   AddCodeLine ("and #$%02X", (unsigned char)Val);
+                        } else if ((Val & 0x00FF) != 0x00FF) {
+                            AddCodeLine ("and #$%02X", (unsigned char)Val);
                         }
                     }
                 }
@@ -2886,9 +2909,9 @@ void g_and (unsigned Flags, unsigned long Val)
                 if (Val <= 0xFF) {
                     AddCodeLine ("ldx #$00");
                     AddCodeLine ("stx sreg+1");
-                   AddCodeLine ("stx sreg");
+                    AddCodeLine ("stx sreg");
                     if ((Val & 0xFF) != 0xFF) {
-                        AddCodeLine ("and #$%02X", (unsigned char)Val);
+                         AddCodeLine ("and #$%02X", (unsigned char)Val);
                     }
                     return;
                 } else if (Val == 0xFF00) {
@@ -2904,9 +2927,9 @@ void g_and (unsigned Flags, unsigned long Val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         Flags &= ~CF_FORCECHAR;
         g_push (Flags & ~CF_CONST, 0);
     }
@@ -2920,13 +2943,13 @@ void g_and (unsigned Flags, unsigned long Val)
 void g_asr (unsigned flags, unsigned long val)
 /* Primary = TOS >> Primary */
 {
-    static const char* ops[12] = {
-        "tosasrax", "tosshrax", "tosasreax", "tosshreax",
+    static const char* const ops[4] = {
+        "tosasrax", "tosshrax", "tosasreax", "tosshreax"
     };
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -2934,36 +2957,36 @@ void g_asr (unsigned flags, unsigned long val)
             case CF_CHAR:
             case CF_INT:
                 val &= 0x0F;
-                       if (val >= 8) {
+                if (val >= 8) {
                     if (flags & CF_UNSIGNED) {
                         AddCodeLine ("txa");
                         AddCodeLine ("ldx #$00");
                     } else {
-                               unsigned L = GetLocalLabel();
+                        unsigned L = GetLocalLabel();
                         AddCodeLine ("cpx #$80");   /* Sign bit into carry */
                         AddCodeLine ("txa");
                         AddCodeLine ("ldx #$00");
                         AddCodeLine ("bcc %s", LocalLabelName (L));
                         AddCodeLine ("dex");        /* Make $FF */
-                               g_defcodelabel (L);
+                        g_defcodelabel (L);
                     }
                     val -= 8;
                 }
                 if (val >= 4) {
                     if (flags & CF_UNSIGNED) {
-                               AddCodeLine ("jsr shrax4");
+                        AddCodeLine ("jsr shrax4");
                     } else {
-                               AddCodeLine ("jsr asrax4");
+                        AddCodeLine ("jsr asrax4");
                     }
                     val -= 4;
                 }
                 if (val > 0) {
                     if (flags & CF_UNSIGNED) {
-                               AddCodeLine ("jsr shrax%ld", val);
+                        AddCodeLine ("jsr shrax%ld", val);
                     } else {
-                               AddCodeLine ("jsr asrax%ld", val);
+                        AddCodeLine ("jsr asrax%ld", val);
                     }
-                       }
+                }
                 return;
 
             case CF_LONG:
@@ -2985,10 +3008,10 @@ void g_asr (unsigned flags, unsigned long val)
                     AddCodeLine ("ldy #$00");
                     AddCodeLine ("ldx sreg+1");
                     if ((flags & CF_UNSIGNED) == 0) {
-                               unsigned L = GetLocalLabel();
+                        unsigned L = GetLocalLabel();
                         AddCodeLine ("bpl %s", LocalLabelName (L));
                         AddCodeLine ("dey");
-                               g_defcodelabel (L);
+                        g_defcodelabel (L);
                     }
                     AddCodeLine ("lda sreg");
                     AddCodeLine ("sty sreg+1");
@@ -3001,12 +3024,12 @@ void g_asr (unsigned flags, unsigned long val)
                     AddCodeLine ("ldy sreg+1");
                     AddCodeLine ("sty sreg");
                     if ((flags & CF_UNSIGNED) == 0) {
-                               unsigned L = GetLocalLabel();
+                        unsigned L = GetLocalLabel();
                         AddCodeLine ("cpy #$80");
                         AddCodeLine ("ldy #$00");
                         AddCodeLine ("bcc %s", LocalLabelName (L));
                         AddCodeLine ("dey");
-                               g_defcodelabel (L);
+                        g_defcodelabel (L);
                     } else {
                         AddCodeLine ("ldy #$00");
                     }
@@ -3015,17 +3038,17 @@ void g_asr (unsigned flags, unsigned long val)
                 }
                 if (val >= 4) {
                     if (flags & CF_UNSIGNED) {
-                               AddCodeLine ("jsr shreax4");
+                        AddCodeLine ("jsr shreax4");
                     } else {
-                               AddCodeLine ("jsr asreax4");
+                        AddCodeLine ("jsr asreax4");
                     }
                     val -= 4;
                 }
                 if (val > 0) {
                     if (flags & CF_UNSIGNED) {
-                               AddCodeLine ("jsr shreax%ld", val);
+                        AddCodeLine ("jsr shreax%ld", val);
                     } else {
-                               AddCodeLine ("jsr asreax%ld", val);
+                        AddCodeLine ("jsr asreax%ld", val);
                     }
                 }
                 return;
@@ -3035,9 +3058,9 @@ void g_asr (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3051,14 +3074,14 @@ void g_asr (unsigned flags, unsigned long val)
 void g_asl (unsigned flags, unsigned long val)
 /* Primary = TOS << Primary */
 {
-    static const char* ops[12] = {
-        "tosaslax", "tosshlax", "tosasleax", "tosshleax",
+    static const char* const ops[4] = {
+        "tosaslax", "tosshlax", "tosasleax", "tosshleax"
     };
 
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -3114,17 +3137,17 @@ void g_asl (unsigned flags, unsigned long val)
                 }
                 if (val > 4) {
                     if (flags & CF_UNSIGNED) {
-                               AddCodeLine ("jsr shleax4");
+                        AddCodeLine ("jsr shleax4");
                     } else {
-                               AddCodeLine ("jsr asleax4");
+                        AddCodeLine ("jsr asleax4");
                     }
                     val -= 4;
                 }
                 if (val > 0) {
                     if (flags & CF_UNSIGNED) {
-                               AddCodeLine ("jsr shleax%ld", val);
+                        AddCodeLine ("jsr shleax%ld", val);
                     } else {
-                               AddCodeLine ("jsr asleax%ld", val);
+                        AddCodeLine ("jsr asleax%ld", val);
                     }
                 }
                 return;
@@ -3134,9 +3157,9 @@ void g_asl (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3243,9 +3266,9 @@ void g_inc (unsigned flags, unsigned long val)
             if (flags & CF_FORCECHAR) {
                 if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val <= 2) {
                     while (val--) {
-                               AddCodeLine ("ina");
+                        AddCodeLine ("ina");
                     }
-               } else {
+                } else {
                     AddCodeLine ("clc");
                     AddCodeLine ("adc #$%02X", (unsigned char)val);
                 }
@@ -3274,21 +3297,21 @@ void g_inc (unsigned flags, unsigned long val)
                 /* 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);
+                        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");
+                        AddCodeLine ("inx");
                     }
                     if (val >= 0x200) {
-                               AddCodeLine ("inx");
+                        AddCodeLine ("inx");
                     }
                     if (val >= 0x300) {
-                               AddCodeLine ("inx");
+                        AddCodeLine ("inx");
                     }
                 } else if ((val & 0xFF) != 0) {
                     AddCodeLine ("clc");
@@ -3342,11 +3365,11 @@ void g_dec (unsigned flags, unsigned long val)
             if (flags & CF_FORCECHAR) {
                 if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val <= 2) {
                     while (val--) {
-                       AddCodeLine ("dea");
+                        AddCodeLine ("dea");
                     }
                 } else {
                     AddCodeLine ("sec");
-                   AddCodeLine ("sbc #$%02X", (unsigned char)val);
+                    AddCodeLine ("sbc #$%02X", (unsigned char)val);
                 }
                 break;
             }
@@ -3368,22 +3391,22 @@ void g_dec (unsigned flags, unsigned long val)
                 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");
+                        AddCodeLine ("sec");
+                        AddCodeLine ("sbc #$%02X", (unsigned char) val);
+                        AddCodeLine ("bcs %s", LocalLabelName (L));
+                        AddCodeLine ("dex");
                         g_defcodelabel (L);
                     }
                     if (val >= 0x100) {
-                               AddCodeLine ("dex");
+                        AddCodeLine ("dex");
                     }
                     if (val >= 0x200) {
-                               AddCodeLine ("dex");
+                        AddCodeLine ("dex");
                     }
                 } else {
                     if ((val & 0xFF) != 0) {
                         AddCodeLine ("sec");
-                       AddCodeLine ("sbc #$%02X", (unsigned char) val);
+                        AddCodeLine ("sbc #$%02X", (unsigned char) val);
                         AddCodeLine ("pha");
                         AddCodeLine ("txa");
                         AddCodeLine ("sbc #$%02X", (unsigned char) (val >> 8));
@@ -3419,25 +3442,25 @@ void g_dec (unsigned flags, unsigned long val)
 
 
 /*
- * Following are the conditional operators. They compare the TOS against
- * the primary and put a literal 1 in the primary if the condition is
- * true, otherwise they clear the primary register
- */
+** Following are the conditional operators. They compare the TOS against
+** the primary and put a literal 1 in the primary if the condition is
+** true, otherwise they clear the primary register
+*/
 
 
 
 void g_eq (unsigned flags, unsigned long val)
 /* Test for equal */
 {
-    static const char* ops[12] = {
-        "toseqax", "toseqax", "toseqeax", "toseqeax",
+    static const char* const ops[4] = {
+        "toseqax", "toseqax", "toseqeax", "toseqeax"
     };
 
     unsigned L;
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -3453,7 +3476,7 @@ void g_eq (unsigned flags, unsigned long val)
             case CF_INT:
                 L = GetLocalLabel();
                 AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
-                       AddCodeLine ("bne %s", LocalLabelName (L));
+                AddCodeLine ("bne %s", LocalLabelName (L));
                 AddCodeLine ("cmp #$%02X", (unsigned char)val);
                 g_defcodelabel (L);
                 AddCodeLine ("jsr booleq");
@@ -3467,9 +3490,9 @@ void g_eq (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3483,15 +3506,15 @@ void g_eq (unsigned flags, unsigned long val)
 void g_ne (unsigned flags, unsigned long val)
 /* Test for not equal */
 {
-    static const char* ops[12] = {
-        "tosneax", "tosneax", "tosneeax", "tosneeax",
+    static const char* const ops[4] = {
+        "tosneax", "tosneax", "tosneeax", "tosneeax"
     };
 
     unsigned L;
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         switch (flags & CF_TYPEMASK) {
@@ -3521,9 +3544,9 @@ void g_ne (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3537,21 +3560,21 @@ void g_ne (unsigned flags, unsigned long val)
 void g_lt (unsigned flags, unsigned long val)
 /* Test for less than */
 {
-    static const char* ops[12] = {
-        "tosltax", "tosultax", "toslteax", "tosulteax",
+    static const char* const ops[4] = {
+        "tosltax", "tosultax", "toslteax", "tosulteax"
     };
 
     unsigned Label;
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         /* Because the handling of the overflow flag is too complex for
-         * inlining, we can handle only unsigned compares, and signed
-         * compares against zero here.
-         */
+        ** inlining, we can handle only unsigned compares, and signed
+        ** compares against zero here.
+        */
         if (flags & CF_UNSIGNED) {
 
             /* Give a warning in some special cases */
@@ -3683,9 +3706,9 @@ void g_lt (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3699,14 +3722,14 @@ void g_lt (unsigned flags, unsigned long val)
 void g_le (unsigned flags, unsigned long val)
 /* Test for less than or equal to */
 {
-    static const char* ops[12] = {
-        "tosleax", "tosuleax", "tosleeax", "tosuleeax",
+    static const char* const ops[4] = {
+        "tosleax", "tosuleax", "tosleeax", "tosuleeax"
     };
 
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         /* Look at the type */
@@ -3716,28 +3739,28 @@ void g_le (unsigned flags, unsigned long val)
                 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.
-                            */
+                        if (val < 0xFF) {
+                            /* Use < instead of <= because the former gives
+                            ** better code on the 6502 than the latter.
+                            */
                             g_lt (flags, val+1);
-                       } else {
+                        } 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.
-                            */
+                        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 {
+                        } else {
                             /* Always true */
                             Warning ("Condition is always true");
                             AddCodeLine ("jsr return1");
-                       }
+                        }
                     }
                     return;
                 }
@@ -3747,10 +3770,10 @@ void g_le (unsigned flags, unsigned long val)
                 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);
+                        /* 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");
@@ -3759,7 +3782,7 @@ void g_le (unsigned flags, unsigned long val)
                 } else {
                     /* Signed compare */
                     if ((long) val < 0x7FFF) {
-                               g_lt (flags, val+1);
+                        g_lt (flags, val+1);
                     } else {
                         /* Always true */
                         Warning ("Condition is always true");
@@ -3772,10 +3795,10 @@ void g_le (unsigned flags, unsigned long val)
                 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);
+                        /* 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");
@@ -3784,7 +3807,7 @@ void g_le (unsigned flags, unsigned long val)
                 } else {
                     /* Signed compare */
                     if ((long) val < 0x7FFFFFFF) {
-                               g_lt (flags, val+1);
+                        g_lt (flags, val+1);
                     } else {
                         /* Always true */
                         Warning ("Condition is always true");
@@ -3798,9 +3821,9 @@ void g_le (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3814,14 +3837,14 @@ void g_le (unsigned flags, unsigned long val)
 void g_gt (unsigned flags, unsigned long val)
 /* Test for greater than */
 {
-    static const char* ops[12] = {
-        "tosgtax", "tosugtax", "tosgteax", "tosugteax",
+    static const char* const ops[4] = {
+        "tosgtax", "tosugtax", "tosgteax", "tosugteax"
     };
 
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         /* Look at the type */
@@ -3830,27 +3853,27 @@ void g_gt (unsigned flags, unsigned long val)
             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.
-                            */
+                        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.
-                            */
+                        } 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 {
+                        } 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.
-                            */
+                        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 */
@@ -3865,23 +3888,23 @@ void g_gt (unsigned flags, unsigned long val)
             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.
-                        */
+                    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 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 {
+                    }
+                } else {
                     /* Signed compare */
                     if ((long) val < 0x7FFF) {
                         g_ge (flags, val+1);
@@ -3889,30 +3912,30 @@ void g_gt (unsigned flags, unsigned long val)
                         /* 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.
-                        */
+                    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 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 {
+                    }
+                } else {
                     /* Signed compare */
                     if ((long) val < 0x7FFFFFFF) {
                         g_ge (flags, val+1);
@@ -3920,18 +3943,18 @@ void g_gt (unsigned flags, unsigned long val)
                         /* Never true */
                         Warning ("Condition is never true");
                         AddCodeLine ("jsr return0");
-                   }
+                    }
                 }
                 return;
 
             default:
-               typeerror (flags);
+                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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -3945,22 +3968,22 @@ void g_gt (unsigned flags, unsigned long val)
 void g_ge (unsigned flags, unsigned long val)
 /* Test for greater than or equal to */
 {
-    static const char* ops[12] = {
-        "tosgeax", "tosugeax", "tosgeeax", "tosugeeax",
+    static const char* const ops[4] = {
+        "tosgeax", "tosugeax", "tosgeeax", "tosugeeax"
     };
 
     unsigned Label;
 
 
     /* If the right hand side is const, the lhs is not on stack but still
-     * in the primary register.
-     */
+    ** in the primary register.
+    */
     if (flags & CF_CONST) {
 
         /* Because the handling of the overflow flag is too complex for
-         * inlining, we can handle only unsigned compares, and signed
-         * compares against zero here.
-         */
+        ** inlining, we can handle only unsigned compares, and signed
+        ** compares against zero here.
+        */
         if (flags & CF_UNSIGNED) {
 
             /* Give a warning in some special cases */
@@ -4087,9 +4110,9 @@ void g_ge (unsigned flags, unsigned long val)
         }
 
         /* 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
-         * always work with ints.
-         */
+        ** into the normal, non-optimized stuff. Note: The standard stuff will
+        ** always work with ints.
+        */
         flags &= ~CF_FORCECHAR;
         g_push (flags & ~CF_CONST, 0);
     }
@@ -4101,7 +4124,7 @@ void g_ge (unsigned flags, unsigned long val)
 
 
 /*****************************************************************************/
-/*                         Allocating static storage                        */
+/*                         Allocating static storage                         */
 /*****************************************************************************/
 
 
@@ -4123,7 +4146,7 @@ void g_defdata (unsigned flags, unsigned long val, long offs)
         switch (flags & CF_TYPEMASK) {
 
             case CF_CHAR:
-               AddDataLine ("\t.byte\t$%02lX", val & 0xFF);
+                AddDataLine ("\t.byte\t$%02lX", val & 0xFF);
                 break;
 
             case CF_INT:
@@ -4233,7 +4256,7 @@ void g_initauto (unsigned Label, unsigned Size)
         AddCodeLine ("lda %s,y", GetLabelName (CF_STATIC, Label, 0));
         AddCodeLine ("sta (sp),y");
         AddCodeLine ("iny");
-        AddCodeLine ("cpy #$%02X", (unsigned char) Size);
+        AddCmpCodeIfSizeNot256 ("cpy #$%02X", Size);
         AddCodeLine ("bne %s", LocalLabelName (CodeLabel));
     }
 }
@@ -4258,16 +4281,16 @@ void g_initstatic (unsigned InitLabel, unsigned VarLabel, unsigned Size)
         AddCodeLine ("lda %s,y", GetLabelName (CF_STATIC, InitLabel, 0));
         AddCodeLine ("sta %s,y", GetLabelName (CF_STATIC, VarLabel, 0));
         AddCodeLine ("iny");
-        AddCodeLine ("cpy #$%02X", (unsigned char) Size);
+        AddCmpCodeIfSizeNot256 ("cpy #$%02X", Size);
         AddCodeLine ("bne %s", LocalLabelName (CodeLabel));
     } else {
-        /* Use the easy way here: memcpy */
+        /* Use the easy way here: memcpy() */
         g_getimmed (CF_STATIC, VarLabel, 0);
         AddCodeLine ("jsr pushax");
         g_getimmed (CF_STATIC, InitLabel, 0);
         AddCodeLine ("jsr pushax");
         g_getimmed (CF_INT | CF_UNSIGNED | CF_CONST, Size, 0);
-        AddCodeLine ("jsr %s", GetLabelName (CF_EXTERNAL, (unsigned long) "memcpy", 0));
+        AddCodeLine ("jsr %s", GetLabelName (CF_EXTERNAL, (uintptr_t) "memcpy", 0));
     }
 }
 
@@ -4331,11 +4354,11 @@ void g_switch (Collection* Nodes, unsigned DefaultLabel, unsigned Depth)
 
             /* Determine the next label */
             if (I == CollCount (Nodes) - 1) {
-               /* Last node means not found */
+                /* Last node means not found */
                 g_truejump (0, DefaultLabel);
             } else {
-               /* Jump to the next check */
-               NextLabel = GetLocalLabel ();
+                /* Jump to the next check */
+                NextLabel = GetLocalLabel ();
                 g_truejump (0, NextLabel);
             }
 
@@ -4352,7 +4375,7 @@ void g_switch (Collection* Nodes, unsigned DefaultLabel, unsigned Depth)
 
 
 /*****************************************************************************/
-/*                       User supplied assembler code                       */
+/*                       User supplied assembler code                        */
 /*****************************************************************************/
 
 
@@ -4362,6 +4385,3 @@ void g_asmcode (struct StrBuf* B)
 {
     AddCodeLine ("%.*s", (int) SB_GetLen (B), SB_GetConstBuf (B));
 }
-
-
-