]> Shamusworld >> Repos - rmac/blobdiff - sect.c
Code cleanup, version bump for last commit. :-)
[rmac] / sect.c
diff --git a/sect.c b/sect.c
index b58d441709681244e395a0bb2683d607cf4e00f1..7a88a5610693f2271e5154f75aab471d0b0bf887 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -7,6 +7,7 @@
 //
 
 #include "sect.h"
+#include "6502.h"
 #include "direct.h"
 #include "error.h"
 #include "expr.h"
@@ -85,7 +86,7 @@ void InitSection(void)
        MakeSection(TEXT, SUSED | TEXT       );         // TEXT
        MakeSection(DATA, SUSED | DATA       );         // DATA
        MakeSection(BSS,  SUSED | BSS  | SBSS);         // BSS
-//     MakeSection(M6502, SUSED | TEXT       );                // 6502 code section
+       MakeSection(M6502, SUSED | TEXT      );         // 6502 code section
 
        // Switch to TEXT for starters
        SwitchSection(TEXT);
@@ -115,6 +116,8 @@ void SwitchSection(int sno)
        cursect = sno;
        SECT * p = &sect[sno];
 
+    m6502 = (sno == M6502);    /* set 6502-mode */
+
        // Copy section vars
        scattr = p->scattr;
        sloc = p->sloc;
@@ -409,6 +412,12 @@ int ResolveFixups(int sno)
        if (cch == NULL)
                return 0;
 
+       /*
+        *  Wire the 6502 segment's size to its allocated size (64K)
+        */
+       if (sno == M6502)
+               cch->ch_size = cch->challoc;
+
        do
        {
                fup.cp = ch->chptr;                                     // fup -> start of chunk
@@ -583,6 +592,25 @@ int ResolveFixups(int sno)
 
                                *locp = (uint8_t)eval;
                                break;
+                       // Fixup high/low byte off word for 6502
+                       case FU_BYTEH:
+                               if (!(eattr & DEFINED))
+                               {
+                                       error("external byte reference");
+                                       continue;
+                               }
+
+                               *locp = (uint8_t)((eval >> 8) & 0xFF);
+                               break;
+                       case FU_BYTEL:
+                               if (!(eattr & DEFINED))
+                               {
+                                       error("external byte reference");
+                                       continue;
+                               }
+
+                               *locp = (uint8_t)(eval & 0xFF);
+                               break;
                        // Fixup WORD forward references;
                        // the word could be unaligned in the section buffer, so we have to
                        // be careful.
@@ -713,7 +741,12 @@ int ResolveFixups(int sno)
                                        }
                                }
 
-                               SETBE16(locp, 0, eval);
+                               // 6502 words are little endian, so handle that here
+                               if (sno == M6502)
+                                       SETLE16(locp, 0, eval)
+                               else
+                                   SETBE16(locp, 0, eval)
+
                                break;
                        // Fixup LONG forward references;
                        // the long could be unaligned in the section buffer, so be careful
@@ -793,6 +826,8 @@ int ResolveAllFixups(void)
        ResolveFixups(TEXT);
        DEBUG printf("Resolving DATA sections...\n");
        ResolveFixups(DATA);
+       DEBUG printf("Resolving 6502 sections...\n");
+       ResolveFixups(M6502);           /* fixup 6502 section (if any) */
 
        return 0;
 }