]> git.sur5r.net Git - cc65/blobdiff - src/common/mmodel.c
Fixed LinuxDoc Tools issues in some verbatim blocks in the Atari document.
[cc65] / src / common / mmodel.c
index d3187ce00d279dbe3a775797dc06031ad7506cd3..05f2a4b27125204ac0a7e51afbd9bb38c2d9e314 100644 (file)
@@ -7,7 +7,7 @@
 /*                                                                           */
 /*                                                                           */
 /* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 #include <string.h>
 
 /* common */
+#include "addrsize.h"
 #include "mmodel.h"
 
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
@@ -56,10 +57,15 @@ static const char* MemoryModelNames[MMODEL_COUNT] = {
     "huge",
 };
 
+/* Address sizes for the segments */
+unsigned char CodeAddrSize = ADDR_SIZE_ABS;
+unsigned char DataAddrSize = ADDR_SIZE_ABS;
+unsigned char ZpAddrSize   = ADDR_SIZE_ZP;
+
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -71,9 +77,9 @@ mmodel_t FindMemoryModel (const char* Name)
 
     /* Check all CPU names */
     for (I = 0; I < MMODEL_COUNT; ++I) {
-       if (strcmp (MemoryModelNames[I], Name) == 0) {
-           return (mmodel_t)I;
-       }
+        if (strcmp (MemoryModelNames[I], Name) == 0) {
+            return (mmodel_t)I;
+        }
     }
 
     /* Not found */
@@ -82,3 +88,39 @@ mmodel_t FindMemoryModel (const char* Name)
 
 
 
+void SetMemoryModel (mmodel_t Model)
+/* Set the memory model updating the MemoryModel variables and the address
+** sizes for the segments.
+*/
+{
+    /* Remember the memory model */
+    MemoryModel = Model;
+
+    /* Set the address sizes for the segments */
+    switch (MemoryModel) {
+
+        case MMODEL_NEAR:
+            /* Code: near, data: near */
+            CodeAddrSize = ADDR_SIZE_ABS;
+            DataAddrSize = ADDR_SIZE_ABS;
+            break;
+
+        case MMODEL_FAR:
+            /* Code: far, data: near */
+            CodeAddrSize = ADDR_SIZE_FAR;
+            DataAddrSize = ADDR_SIZE_ABS;
+            break;
+
+        case MMODEL_HUGE:
+            /* Code: far, data: far */
+            CodeAddrSize = ADDR_SIZE_FAR;
+            DataAddrSize = ADDR_SIZE_FAR;
+            break;
+
+        default:
+            break;
+    }
+
+    /* Zeropage is always zeropage */
+    ZpAddrSize = ADDR_SIZE_ZP;
+}