]> Shamusworld >> Repos - rmac/blobdiff - 6502.c
Version bump for last commit. :-)
[rmac] / 6502.c
diff --git a/6502.c b/6502.c
index d478e3a4669c812463a2e94f5ed5885088fb633e..66f2080977e2a0d73a639252a43867c672da9ef9 100644 (file)
--- a/6502.c
+++ b/6502.c
@@ -21,8 +21,9 @@
 #include "sect.h"
 #include "token.h"
 
-#define DEF_KW
-#include "kwtab.h"
+#define DEF_REG65
+#define DECL_REG65
+#include "6502regs.h"
 
 #define        UPSEG_SIZE      0x10010L // size of 6502 code buffer, 64K+16bytes
 
@@ -238,6 +239,11 @@ int d_6502()
 {
        SaveSection();                  // Save curent section
        SwitchSection(M6502);   // Switch to 6502 section
+       regbase = reg65base;    // Update register DFA tables
+       regtab = reg65tab;
+       regcheck = reg65check;
+       regaccept = reg65accept;
+       used_architectures |= M6502;
 
        return 0;
 }
@@ -263,7 +269,7 @@ void m6502cg(int op)
                amode = A65_IMPL;
                break;
 
-       case KW_A:
+       case REG65_A:
                if (tok[1] != EOL)
                        goto badmode;
 
@@ -307,7 +313,7 @@ void m6502cg(int op)
                                tok++;
                                amode = A65_INDY;
 
-                               if (tok[0] != KW_Y)
+                               if (tok[0] != REG65_Y)
                                        goto badmode;
 
                                tok++;
@@ -315,7 +321,7 @@ void m6502cg(int op)
                        else
                                amode = A65_IND;
                }
-               else if ((tok[0] == ',') && (tok[1] == KW_X) && (tok[2] == ')'))
+               else if ((tok[0] == ',') && (tok[1] == REG65_X) && (tok[2] == ')'))
                {
                        // (foo,x)
                        tok += 3;
@@ -341,9 +347,9 @@ void m6502cg(int op)
                        if ((tok[1] != ')') || (tok[2] != EOL))
                                goto badmode;
 
-                       if (tok[0] == KW_X)
+                       if (tok[0] == REG65_X)
                                amode = A65_INDX;
-                       else if (tok[0] == KW_Y)
+                       else if (tok[0] == REG65_Y)
                                amode = A65_INDY;
                        else
                                goto badmode;
@@ -373,12 +379,12 @@ void m6502cg(int op)
                {
                        tok++;
 
-                       if (tok[0] == KW_X)
+                       if (tok[0] == REG65_X)
                        {
                                tok++;
                                amode = A65_ABSX;
                        }
-                       else if (tok[0] == KW_Y)
+                       else if (tok[0] == REG65_Y)
                        {
                                tok++;
                                amode = A65_ABSY;
@@ -418,6 +424,8 @@ badmode:
        DEBUG printf("inf[op][amode]=%d\n", (int)inf[op][amode]);
 #endif
 
+       GENLINENOSYM();
+
        switch (inf[op][amode])
        {
                case A65_IMPL:          // Just leave the instruction
@@ -562,3 +570,52 @@ void m6502obj(int ofd)
        }
 }
 
+
+// Write raw 6502 org'd code.
+// Super copypasta'd from above function
+void m6502raw(int ofd)
+{
+       CHUNK * ch = sect[M6502].scode;
+
+       // If no 6502 code was generated, bail out
+       if ((ch == NULL) || (ch->challoc == 0))
+               return;
+
+       register uint8_t *p = ch->chptr;
+
+       for(uint16_t * l=&orgmap[0][0]; l<currentorg; l+=2)
+       {
+               // Write the segment data
+               uint32_t unused = write(ofd, p + l[0], l[1] - l[0]);
+       }
+}
+
+
+//
+// Generate a C64 .PRG output file
+//
+void m6502c64(int ofd)
+{
+       uint8_t header[2];
+
+       CHUNK * ch = sect[M6502].scode;
+
+       // If no 6502 code was generated, bail out
+       if ((ch == NULL) || (ch->challoc == 0))
+               return;
+
+       if (currentorg != &orgmap[1][0])
+       {
+               // More than one 6502 section created, this is not allowed
+               error("when generating C64 .PRG files only one org section is allowed - aborting");
+               return;
+       }
+
+       SETLE16(header, 0, orgmap[0][0]);
+       register uint8_t * p = ch->chptr;
+
+       // Write header
+       uint32_t unused = write(ofd, header, 2);
+       // Write the data
+       unused = write(ofd, p + orgmap[0][0], orgmap[0][1] - orgmap[0][0]);
+}