* fixed GCC 4.4.0 mingw compilation:
[fw/sdcc] / as / z80 / z80adr.c
index d47b8eba4c105f1b820d7e088c7a50753d85e5b9..cc273c2c0edbf21123c39df08ccc58691b6c5c32 100644 (file)
@@ -1,13 +1,20 @@
-/* z80adr.c */
+/* z80adr.c
 
-/*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- */
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 /*
  * Extensions: P. Felber
  *
  * This addr(esp) routine performs the following addressing decoding:
  *
- *     address         mode            flag            addr            base
- *     #n              S_IMMED         0               n               NULL
- *     label           s_type          ----            s_addr          s_area
- *     [REG]           S_IND+icode     0               0               NULL
- *     [label]         S_INDM          ----            s_addr          s_area
- *     offset[REG]     S_IND+icode     ----            offset          ----
+ *      address         mode            flag            addr            base
+ *      #n              S_IMMED         0               n               NULL
+ *      label           s_type          ----            s_addr          s_area
+ *      [REG]           S_IND+icode     0               0               NULL
+ *      [label]         S_INDM          ----            s_addr          s_area
+ *      offset[REG]     S_IND+icode     ----            offset          ----
  */
 int
 addr(esp)
 register struct expr *esp;
 {
-       register int c, mode = 0, indx;
+        register int c, mode = 0, indx;
 
-       if ((c = getnb()) == '#') {
-               expr(esp, 0);
-               esp->e_mode = S_IMMED;
-       } else
-       if (c == LFIND) {
-               if ((indx = admode(R8)) != 0) {
-                       mode = S_INDB;
-               } else
-               if ((indx = admode(R16)) != 0) {
-                       mode = S_INDR;
-               } else  
-               if ((indx = admode(R8X)) != 0) {
-                       mode = S_R8X;
-                       aerr();
-               } else
-               if ((indx = admode(R16X)) != 0) {
-                       mode = S_R16X;
-                       aerr();
-               } else {
-                       expr(esp, 0);
-                       esp->e_mode = S_INDM;
-               }
-               if (indx) {
-                       esp->e_mode = (mode + indx)&0xFF;
-                       esp->e_base.e_ap = NULL;
-               }
-               if ((c = getnb()) != RTIND)
-                       qerr();
-       } else {
-               unget(c);
-               if ((indx = admode(R8)) != 0) {
-                       mode = S_R8;
-               } else
-               if ((indx = admode(R16)) != 0) {
-                       mode = S_R16;
-               } else  
-               if ((indx = admode(R8X)) != 0) {
-                       mode = S_R8X;
-               } else
-               if ((indx = admode(R16X)) != 0) {
-                       mode = S_R16X;
-               } else {
-                       expr(esp, 0);
-                       esp->e_mode = S_USER;
-               }
-               if (indx) {
-                       esp->e_addr = indx&0xFF;
-                       esp->e_mode = mode;
-                       esp->e_base.e_ap = NULL;
-               }
-               if ((c = getnb()) == LFIND) {
+        if ((c = getnb()) == '#') {
+                expr(esp, 0);
+                esp->e_mode = S_IMMED;
+        } else
+        if (c == LFIND) {
+                if ((indx = admode(R8)) != 0) {
+                        mode = S_INDB;
+                } else
+                if ((indx = admode(R16)) != 0) {
+                        mode = S_INDR;
+                } else
+                if ((indx = admode(R8X)) != 0) {
+                        mode = S_R8X;
+                        aerr();
+                } else
+                if ((indx = admode(R16X)) != 0) {
+                        mode = S_R16X;
+                        aerr();
+                } else {
+                        expr(esp, 0);
+                        esp->e_mode = S_INDM;
+                }
+                if (indx) {
+                        esp->e_mode = (mode + indx)&0xFF;
+                        esp->e_base.e_ap = NULL;
+                }
+                if ((c = getnb()) != RTIND)
+                        qerr();
+        } else {
+                unget(c);
+                if ((indx = admode(R8)) != 0) {
+                        mode = S_R8;
+                } else
+                if ((indx = admode(R16)) != 0) {
+                        mode = S_R16;
+                } else
+                if ((indx = admode(R8X)) != 0) {
+                        mode = S_R8X;
+                } else
+                if ((indx = admode(R16X)) != 0) {
+                        mode = S_R16X;
+                } else {
+                        expr(esp, 0);
+                        esp->e_mode = S_USER;
+                }
+                if (indx) {
+                        esp->e_addr = indx&0xFF;
+                        esp->e_mode = mode;
+                        esp->e_base.e_ap = NULL;
+                }
+                if ((c = getnb()) == LFIND) {
 #ifndef GAMEBOY
-                       if ((indx=admode(R16))!=0
-                               && ((indx&0xFF)==IX || (indx&0xFF)==IY)) {
+                        if ((indx=admode(R16))!=0
+                                && ((indx&0xFF)==IX || (indx&0xFF)==IY)) {
 #else /* GAMEBOY */
-                       if ((indx=admode(R16))!=0) {
+                        if ((indx=admode(R16))!=0) {
 #endif /* GAMEBOY */
-                               esp->e_mode = S_INDR + (indx&0xFF);
-                       } else {
-                               aerr();
-                       }
-                       if ((c = getnb()) != RTIND)
-                               qerr();
-               } else {
-                       unget(c);
-               }
-       }
-       return (esp->e_mode);
+                                esp->e_mode = S_INDR + (indx&0xFF);
+                        } else {
+                                aerr();
+                        }
+                        if ((c = getnb()) != RTIND)
+                                qerr();
+                } else {
+                        unget(c);
+                }
+        }
+        return (esp->e_mode);
 }
 
 /*
@@ -118,22 +125,22 @@ int
 admode(sp)
 register struct adsym *sp;
 {
-       register char *ptr;
-       register int i;
-       register char *ips;
+        register char *ptr;
+        register int i;
+        register const char *ips;
 
-       ips = ip;
-       unget(getnb());
+        ips = ip;
+        unget(getnb());
 
-       i = 0;
-       while ( *(ptr = (char *) &sp[i]) ) {
-               if (srch(ptr)) {
-                       return(sp[i].a_val);
-               }
-               i++;
-       }
-       ip = ips;
-       return(0);
+        i = 0;
+        while ( *(ptr = (char *) &sp[i]) ) {
+                if (srch(ptr)) {
+                        return(sp[i].a_val);
+                }
+                i++;
+        }
+        ip = ips;
+        return(0);
 }
 
 /*
@@ -143,39 +150,39 @@ int
 srch(str)
 register char *str;
 {
-       register char *ptr;
-       ptr = ip;
+        register const char *ptr;
+        ptr = ip;
 
-#if    CASE_SENSITIVE
-       while (*ptr && *str) {
-               if (*ptr != *str)
-                       break;
-               ptr++;
-               str++;
-       }
-       if (*ptr == *str) {
-               ip = ptr;
-               return(1);
-       }
+#if     CASE_SENSITIVE
+        while (*ptr && *str) {
+                if (*ptr != *str)
+                        break;
+                ptr++;
+                str++;
+        }
+        if (*ptr == *str) {
+                ip = ptr;
+                return(1);
+        }
 #else
-       while (*ptr && *str) {
-               if (ccase[(unsigned char)(*ptr)] != ccase[(unsigned char)(*str)])
-                       break;
-               ptr++;
-               str++;
-       }
-       if (ccase[(unsigned char)(*ptr)] == ccase[(unsigned char)(*str)]) {
-               ip = ptr;
-               return(1);
-       }
+        while (*ptr && *str) {
+                if (ccase[(unsigned char)(*ptr)] != ccase[(unsigned char)(*str)])
+                        break;
+                ptr++;
+                str++;
+        }
+        if (ccase[(unsigned char)(*ptr)] == ccase[(unsigned char)(*str)]) {
+                ip = ptr;
+                return(1);
+        }
 #endif
 
-       if (!*str)
-               if (any(*ptr," \t\n,);")) {
-                       ip = ptr;
-                       return(1);
-               }
-       return(0);
+        if (!*str)
+                if (any(*ptr," \t\n,);")) {
+                        ip = ptr;
+                        return(1);
+                }
+        return(0);
 }
 
 /*
@@ -185,72 +192,101 @@ int
 any(c,str)
 char    c, *str;
 {
-       while (*str)
-               if(*str++ == c)
-                       return(1);
-       return(0);
+        while (*str)
+                if(*str++ == c)
+                        return(1);
+        return(0);
 }
 
 /*
  * Registers
  */
 
-struct adsym   R8[] = {
-    { "b",     B|0400 },
-    { "c",     C|0400 },
-    { "d",     D|0400 },
-    { "e",     E|0400 },
-    { "h",     H|0400 },
-    { "l",     L|0400 },
-    { "a",     A|0400 },
-    { "",      000 }
+struct  adsym   R8[] = {
+    { "b",      B|0400 },
+    { "c",      C|0400 },
+    { "d",      D|0400 },
+    { "e",      E|0400 },
+    { "h",      H|0400 },
+    { "l",      L|0400 },
+    { "a",      A|0400 },
+    { "B",      B|0400 },
+    { "C",      C|0400 },
+    { "D",      D|0400 },
+    { "E",      E|0400 },
+    { "H",      H|0400 },
+    { "L",      L|0400 },
+    { "A",      A|0400 },
+    { "",       000 }
 };
 
-struct adsym   R8X[] = {
-    { "i",     I|0400 },
-    { "r",     R|0400 },
-    { "",      000 }
+struct  adsym   R8X[] = {
+    { "i",      I|0400 },
+    { "r",      R|0400 },
+    { "I",      I|0400 },
+    { "R",      R|0400 },
+    { "",       000 }
 };
 
-struct adsym   R16[] = {
-    { "bc",    BC|0400 },
-    { "de",    DE|0400 },
-    { "hl",    HL|0400 },
-    { "sp",    SP|0400 },
+struct  adsym   R16[] = {
+    { "bc",     BC|0400 },
+    { "de",     DE|0400 },
+    { "hl",     HL|0400 },
+    { "sp",     SP|0400 },
+    { "BC",     BC|0400 },
+    { "DE",     DE|0400 },
+    { "HL",     HL|0400 },
+    { "SP",     SP|0400 },
 #ifndef GAMEBOY
-    { "ix",    IX|0400 },
-    { "iy",    IY|0400 },
+    { "ix",     IX|0400 },
+    { "iy",     IY|0400 },
+    { "IX",     IX|0400 },
+    { "IY",     IY|0400 },
 #else /* GAMEBOY */
-    { "hl-",   HLD|0400 },
-    { "hl+",   HLI|0400 },
-    { "hld",   HLD|0400 },
-    { "hli",   HLI|0400 },
+    { "hl-",    HLD|0400 },
+    { "hl+",    HLI|0400 },
+    { "hld",    HLD|0400 },
+    { "hli",    HLI|0400 },
+    { "HL-",    HLD|0400 },
+    { "HL+",    HLI|0400 },
+    { "HLD",    HLD|0400 },
+    { "HLI",    HLI|0400 },
 #endif /* GAMEBOY */
-    { "",      000 }
+    { "",       000 }
 };
 
-struct adsym   R16X[] = {
-    { "af",    AF|0400 },
+struct  adsym   R16X[] = {
+    { "af",     AF|0400 },
+    { "AF",     AF|0400 },
 #ifndef GAMEBOY
-    { "af'",   AF|0400 },
+    { "af'",    AF|0400 },
+    { "AF'",    AF|0400 },
 #endif /* GAMEBOY */
-    { "",      000 }
+    { "",       000 }
 };
 
 /*
  * Conditional definitions
  */
 
-struct adsym   CND[] = {
-    { "NZ",    NZ|0400 },
-    { "Z",     Z |0400 },
-    { "NC",    NC|0400 },
-    { "C",     CS|0400 },
+struct  adsym   CND[] = {
+    { "NZ",     NZ|0400 },
+    { "Z",      Z |0400 },
+    { "NC",     NC|0400 },
+    { "C",      CS|0400 },
+    { "nz",     NZ|0400 },
+    { "z",      Z |0400 },
+    { "nc",     NC|0400 },
+    { "c",      CS|0400 },
 #ifndef GAMEBOY
-    { "PO",    PO|0400 },
-    { "PE",    PE|0400 },
-    { "P",     P |0400 },
-    { "M",     M |0400 },
+    { "PO",     PO|0400 },
+    { "PE",     PE|0400 },
+    { "P",      P |0400 },
+    { "M",      M |0400 },
+    { "po",     PO|0400 },
+    { "pe",     PE|0400 },
+    { "p",      P |0400 },
+    { "m",      M |0400 },
 #endif /* GAMEBOY */
-    { "",      000 }
+    { "",       000 }
 };