]> Shamusworld >> Repos - rmac/blobdiff - direct.c
Introducing .align directive, thanks to Bastian Schick for most of the implementation...
[rmac] / direct.c
index 585764aa151aad87bc054d3385e329aca9e81083..65a119d3211e5063fb9a58d05b957dd86f17a54f 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -90,6 +90,7 @@ int d_prgflags(void);
 int d_opt(void);
 int d_dsp(void);
 int d_objproc(void);
+int d_align(void);
 void SetLargestAlignment(int);
 
 // Directive handler table
@@ -163,6 +164,7 @@ int (*dirtab[])() = {
        d_opt,                          // 66 .opt
        d_objproc,                      // 67 .objproc
        (void *)d_dsm,                  // 68 .dsm
+       d_align                         // 69 .align
 };
 
 
@@ -842,6 +844,48 @@ int d_qphrase(void)
 }
 
 
+//
+// Adjust location to <alignment> bytes
+//
+int d_align(void)
+{
+       unsigned bytesToSkip;
+       uint64_t eval;
+
+       if (abs_expr(&eval) != OK)
+               return 0;
+
+       if (eval < 2)
+       {
+               return error("Invalid .align value specified");
+       }
+
+       if (dsp56001)
+       {
+               bytesToSkip = eval - sloc % eval;
+               D_ZEROFILL(bytesToSkip*3);
+               return 0;
+       }
+
+       bytesToSkip = eval - (rgpu || rdsp ? orgaddr : sloc) % eval;
+       if ( bytesToSkip != eval )
+       {
+               if ((scattr & SBSS) == 0)
+               {
+                       D_ZEROFILL(bytesToSkip);
+               }
+               else
+               {
+                       sloc += bytesToSkip;
+
+                       if (orgactive)
+                               orgaddr += bytesToSkip;
+               }
+       }
+       return 0;
+}
+
+
 //
 // Do auto-even.  This must be called ONLY if 'sloc' is odd.
 //