EOY minor update.
[rmac] / 6502.c
diff --git a/6502.c b/6502.c
index 55c604808283f56c12b5d45373300b70029e9cb1..55eab740115446b4f1b3ad63437be70403bab82e 100644 (file)
--- a/6502.c
+++ b/6502.c
@@ -1,7 +1,7 @@
 //
 // RMAC - Reboot's Macro Assembler for all Atari computers
 // 6502.C - 6502 Assembler
-// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
@@ -344,6 +344,7 @@ void m6502cg(int op)
                {
                        // (foo,x)
                        tok++;
+#if 0
                        p = string[tok[1]];
 
                        // Sleazo tolower() -----------------vvvvvvvvvvv
@@ -351,17 +352,27 @@ void m6502cg(int op)
                                goto badmode;
 
                        tok += 2;
-
                        if (*tok++ != ')')
                                goto badmode;
 
                        amode = A65_INDX;
+#else
+                       if (tok[0] == KW_X)
+                               amode = A65_INDX;
+
+                       if ((tok[1] != ')') || (tok[2] != EOL))
+                               goto badmode;
+
+                       tok += 2;
+#endif
                }
                else
                        goto badmode;
 
                break;
 
+       // I'm guessing that the form of this is @<expr>(X) or @<expr>(Y), which
+       // I've *never* seen before.  :-/
        case '@':
                tok++;
 
@@ -371,6 +382,7 @@ void m6502cg(int op)
                if (*tok == '(')
                {
                        tok++;
+#if 0
                        p = string[tok[1]];
 
                        if (*tok != SYMBOL || p[1] != EOS || tok[2] != ')' || tok[3] != EOL)
@@ -386,6 +398,19 @@ void m6502cg(int op)
                                goto badmode;
 
                        tok += 3;               // Past SYMBOL <string> ')' EOL
+#else
+                       if ((tok[1] != ')') || (tok[2] != EOL))
+                               goto badmode;
+
+                       if (tok[0] == KW_X)
+                               amode = A65_INDX;
+                       else if (tok[0] == KW_Y)
+                               amode = A65_INDY;
+                       else
+                               goto badmode;
+
+                       tok += 2;
+#endif
                        zpreq = 1;              // Request zeropage optimization
                }
                else if (*tok == EOL)
@@ -620,46 +645,39 @@ badmode:
        if (sloc > 0x10000L)
                fatal("6502 code pointer > 64K");
 
-//Now why use this instead of at_eol()?
-       if (*tok != EOL)
-               error(extra_stuff);
+       ErrorIfNotAtEOL();
 }
 
 
 //
 // Generate 6502 object output file.
+// ggn: Converted to COM/EXE/XEX output format
 //
-// ggn: converted into a com/exe/xex output format
 void m6502obj(int ofd)
 {
-       uint16_t exeheader[3];
-       int headsize = 6;
-       uint16_t * headpoint = exeheader;
+       uint8_t header[4];
 
        CHUNK * ch = sect[M6502].scode;
 
-       // If no 6502 code was generated, forget it
+       // If no 6502 code was generated, bail out
        if ((ch == NULL) || (ch->challoc == 0))
                return;
 
-       exeheader[0] = 0xFFFF;          // Mandatory for first segment
        register uint8_t * p = ch->chptr;
 
+       // Write out mandatory $FFFF header
+       header[0] = header[1] = 0xFF;
+       uint32_t unused = write(ofd, header, 2);
+
        for(uint16_t * l=&orgmap[0][0]; l<currentorg; l+=2)
        {
-/*
-Why are we assuming endianness here? This is retarded
-*/
-               exeheader[1] = l[0];
-               exeheader[2] = l[1] - 1;
-
-               // Write header
-               size_t unused = write(ofd, headpoint, headsize);
-               unused = write(ofd, p + l[0], l[1] - l[0]);
+               SETLE16(header, 0, l[0]);
+               SETLE16(header, 2, l[1] - 1);
 
-               // Skip the $FFFF after first segment, it's not mandatory
-               headpoint = &exeheader[1];
-               headsize = 4;
+               // Write header for segment
+               unused = write(ofd, header, 4);
+               // Write the segment data
+               unused = write(ofd, p + l[0], l[1] - l[0]);
        }
 }