Update to commit d9e45a19b61c54bc804232fdc67485b84c7af8e9 dated May 21, 2020. These...
[inform.git] / src / tables.c
index 103f6f91e432566d96b63bf53f085c805113c9e5..df3cdfb10313679b342ada031e3b3e131a7b886e 100644 (file)
@@ -3,7 +3,7 @@
 /*               end of dynamic memory, gluing together all the required     */
 /*               tables.                                                     */
 /*                                                                           */
-/* Copyright (c) Graham Nelson 1993 - 2018                                   */
+/* Copyright (c) Graham Nelson 1993 - 2020                                   */
 /*                                                                           */
 /* This file is part of Inform.                                              */
 /*                                                                           */
@@ -32,7 +32,7 @@ uchar *zmachine_paged_memory;          /* Where we shall store the story file
                                           at the end of the compilation pass */
 
 /* In Glulx, zmachine_paged_memory contains all of RAM -- i.e. all but
-   the header, the code, and the static strings. */
+   the header, the code, the static arrays, and the static strings. */
 
 /* ------------------------------------------------------------------------- */
 /*   Offsets of various areas in the Z-machine: these are set to nominal     */
@@ -72,7 +72,8 @@ int32 code_offset,
       routine_flags_array_offset,
       global_names_offset,
       global_flags_array_offset,
-      array_flags_array_offset;
+      array_flags_array_offset,
+      static_arrays_offset;
 int32 arrays_offset,
       object_tree_offset,
       grammar_table_offset,
@@ -191,6 +192,8 @@ static int32 rough_size_of_paged_memory_z(void)
     total += (subtract_pointers(dictionary_top, dictionary))  /* dictionary */
              + ((module_switch)?30:0);                        /* module map */
 
+    total += static_array_area_size;                       /* static arrays */
+
     total += scale_factor*0x100            /* maximum null bytes before code */
             + 1000;             /* fudge factor (in case the above is wrong) */
 
@@ -201,7 +204,7 @@ static int32 rough_size_of_paged_memory_g(void)
 {
     /*  This function calculates a modest over-estimate of the amount of
         memory required to store the machine's paged memory area
-        (that is, everything up to the start of the code area).              */
+        (that is, everything past the start of RAM). */
 
     int32 total;
 
@@ -246,7 +249,8 @@ static void construct_storyfile_z(void)
     int32 globals_at=0, link_table_at=0, dictionary_at=0, actions_at=0, preactions_at=0,
           abbrevs_at=0, prop_defaults_at=0, object_tree_at=0, object_props_at=0,
           map_of_module=0, grammar_table_at=0, charset_at=0, headerext_at=0,
-          terminating_chars_at=0, unicode_at=0, id_names_length=0;
+          terminating_chars_at=0, unicode_at=0, id_names_length=0,
+          static_arrays_at=0;
     int skip_backpatching = FALSE;
     char *output_called = (module_switch)?"module":"story file";
 
@@ -609,6 +613,12 @@ table format requested (producing number 2 format instead)");
         mark += 30;
     }
 
+    /*  ------------------------ Static Arrays ----------------------------- */
+
+    static_arrays_at = mark;
+    for (i=0; i<static_array_area_size; i++)
+        p[mark++] = static_array_area[i];
+    
     /*  ----------------- A gap before the code area ----------------------- */
     /*  (so that it will start at an exact packed address and so that all    */
     /*  routine packed addresses are >= 256, hence long constants)           */
@@ -706,6 +716,7 @@ or less.");
     prop_values_offset = object_props_at;
     static_memory_offset = grammar_table_at;
     grammar_table_offset = grammar_table_at;
+    static_arrays_offset = static_arrays_at;
 
     if (extend_memory_map)
     {   extend_offset=256;
@@ -1142,6 +1153,11 @@ printf("        + - - - - - - - - - - +   %05lx\n",
                                           (long int) map_of_module);
 printf("        | map of module addrs |\n");
 }
+if (static_array_area_size)
+{
+printf("        +---------------------+   %05lx\n", (long int) static_arrays_at);
+printf("        |    static arrays    |\n");
+}
 printf("        +=====================+   %05lx\n", (long int) Write_Code_At);
 printf("Above   |       Z-code        |\n");
 printf("readable+---------------------+   %05lx\n",
@@ -1196,7 +1212,7 @@ static void construct_storyfile_g(void)
     int32 globals_at, dictionary_at, actions_at, preactions_at,
           abbrevs_at, prop_defaults_at, object_tree_at, object_props_at,
           grammar_table_at, charset_at, headerext_at,
-          unicode_at, arrays_at;
+        unicode_at, arrays_at, static_arrays_at;
     int32 threespaces, code_length;
     char *output_called = (module_switch)?"module":"story file";
 
@@ -1256,8 +1272,10 @@ static void construct_storyfile_g(void)
     Write_Strings_At = Write_Code_At + code_length;
     strings_length = compression_table_size + compression_string_size;
 
+    static_arrays_at = Write_Strings_At + strings_length;
+
     /* Now figure out where RAM starts. */
-    Write_RAM_At = Write_Strings_At + strings_length;
+    Write_RAM_At = static_arrays_at + static_array_area_size;
     /* The Write_RAM_At boundary must be a multiple of GPAGESIZE. */
     while (Write_RAM_At % GPAGESIZE)
       Write_RAM_At++;
@@ -1568,6 +1586,7 @@ table format requested (producing number 2 format instead)");
 
     code_offset = Write_Code_At;
     strings_offset = Write_Strings_At;
+    static_arrays_offset = static_arrays_at;
 
     /*  --------------------------- The Header ----------------------------- */
 
@@ -1739,9 +1758,10 @@ Out:   %s %s %d.%c%c%c%c%c%c (%ld%sK long):\n",
         write_debug_section("string decoding table", Write_Strings_At);
         write_debug_section("strings area",
                             Write_Strings_At + compression_table_size);
-        if (Write_Strings_At + strings_length < Write_RAM_At)
+        write_debug_section("static array space", static_arrays_at);
+        if (static_arrays_at + static_array_area_size < Write_RAM_At)
         {   write_debug_section
-                ("zero padding", Write_Strings_At + strings_length);
+                ("zero padding", static_arrays_at + static_array_area_size);
         }
         if (globals_at)
         {   compiler_error("Failed assumption that globals are at start of "
@@ -1784,6 +1804,12 @@ printf("        | string decode table |\n");
 printf("        + - - - - - - - - - - +   %06lx\n",
   (long int) Write_Strings_At + compression_table_size);
 printf("        |       strings       |\n");
+            if (static_array_area_size)
+            {
+printf("        +---------------------+   %06lx\n", 
+  (long int) (static_arrays_at));
+printf("        |    static arrays    |\n");
+            }
 printf("        +=====================+   %06lx\n", 
   (long int) (Write_RAM_At+globals_at));
 printf("Dynamic |  global variables   |\n");
@@ -1911,6 +1937,7 @@ extern void init_tables_vars(void)
       identifier_names_offset=0x800;
       class_numbers_offset = 0x800;
       arrays_offset = 0x0800; /* only used in Glulx, but might as well set */
+      static_arrays_offset = 0x0800;
     }
     else {
       code_offset = 0x12345;
@@ -1924,6 +1951,7 @@ extern void init_tables_vars(void)
       individuals_offset=0x12345;
       identifier_names_offset=0x12345;
       class_numbers_offset = 0x12345;
+      static_arrays_offset = 0x12345;
     }
 }