Skip to content

Commit

Permalink
Standard 1.1 header support (Mantis 1199) from Andrew Plotkin
Browse files Browse the repository at this point in the history
  • Loading branch information
David Kinder committed Mar 8, 2014
1 parent 9d1d4c9 commit 29717b7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 16 deletions.
9 changes: 7 additions & 2 deletions ReleaseNotes.html
Expand Up @@ -96,7 +96,12 @@ <h3>Features added</h3>
more efficient implementation, using Glulx&rsquo;s unsigned comparison opcodes.
<li><p>The debugging output file, generated when the <tt><b>-k</b></tt> is used, has been changed to a
new, XML-based format.
<li><p>A new Glulx-only setting <tt>$GLULX_OBJECT_EXT_BYTES</tt> has been added, which specifies an
<li><p>Two new Z-code settings have been added to support the extra words in the header extension table
specified in section 11.1.7 of the <i>Z-Machine Standards Document</i> version 1.1. <tt>$ZCODE_HEADER_EXT_WORDS</tt>
specifies how many extra words to add (so for all three words defined in the 1.1 standard, this would
be set to 3). <tt>$ZCODE_HEADER_FLAGS_3</tt> specifies the value to put in the first of these three words,
which is the "flags3" field.
<li><p>A new Glulx setting <tt>$GLULX_OBJECT_EXT_BYTES</tt> has been added, which specifies an
amount of additional space to add to each object record. The default is 0.
</ul>
<h3>Bugs fixed</h3>
Expand Down Expand Up @@ -128,7 +133,7 @@ <h3>Bugs fixed</h3>
third argument to the statement will not change the global variable that the statement uses internally. [Mantis 1084]
<li><p>The 'Abbreviate' statement now works with words containing non-English characters. [Mantis 1130]
<li><p>Attempting to use <tt>@pop</tt> opcode for V5 or higher no longer results in a crash. [Mantis 1172]
<li><p>The Glulx-only setting <tt>$NUM_ATTR_BYTES</tt>, which determines the number of bytes in an object set aside
<li><p>The Glulx setting <tt>$NUM_ATTR_BYTES</tt>, which determines the number of bytes in an object set aside
for attribute flags, now works correctly. Note that this has required a change to the veneer routines that conflicts
with the definition of <tt>FUNC_2_CP__Tab()</tt> in the &lsquo;Accelerated Functions&rsquo; section of the Glulx 3.1.2
specification. If you change this setting, you should take great care if you also use the Glulx accelerated functions
Expand Down
3 changes: 2 additions & 1 deletion header.h
Expand Up @@ -2412,7 +2412,7 @@ extern int32 requested_glulx_version;

extern int error_format, store_the_text, asm_trace_setting,
double_space_setting, trace_fns_setting, character_set_setting,
character_set_unicode, header_ext_setting;
character_set_unicode;

extern char Debugging_Name[];
extern char Transcript_Name[];
Expand Down Expand Up @@ -2519,6 +2519,7 @@ extern int32 MAX_STATIC_STRINGS, MAX_ZCODE_SIZE, MAX_LINK_DATA_SIZE,
extern int32 MAX_OBJ_PROP_COUNT, MAX_OBJ_PROP_TABLE_SIZE;
extern int MAX_LOCAL_VARIABLES, MAX_GLOBAL_VARIABLES;
extern int DICT_WORD_SIZE, DICT_CHAR_SIZE, DICT_WORD_BYTES;
extern int ZCODE_HEADER_EXT_WORDS, ZCODE_HEADER_FLAGS_3;
extern int NUM_ATTR_BYTES, GLULX_OBJECT_EXT_BYTES;
extern int WARN_UNUSED_ROUTINES, OMIT_UNUSED_ROUTINES;

Expand Down
8 changes: 3 additions & 5 deletions inform.c
Expand Up @@ -256,7 +256,6 @@ int character_set_setting, /* set by -C0 through -C9 */
double_space_setting, /* set by -d: 0, 1 or 2 */
trace_fns_setting, /* set by -g: 0, 1 or 2 */
linker_trace_setting, /* set by -y: ditto for linker_... */
header_ext_setting, /* set by -W */
store_the_text; /* when set, record game text to a chunk
of memory (used by both -r & -k) */
static int r_e_c_s_set; /* has -S been explicitly set? */
Expand Down Expand Up @@ -314,7 +313,6 @@ static void reset_switch_settings(void)

character_set_setting = 1; /* Default is ISO Latin-1 */
character_set_unicode = FALSE;
header_ext_setting = 0;

compression_switch = TRUE;
glulx_mode = FALSE;
Expand Down Expand Up @@ -1411,10 +1409,10 @@ extern void switches(char *p, int cmode)
case 'H': compression_switch = state; break;
case 'U': define_USE_MODULES_switch = state; break;
case 'W': if ((p[i+1]>='0') && (p[i+1]<='9'))
{ s=2; header_ext_setting = p[i+1]-'0';
{ s=2; ZCODE_HEADER_EXT_WORDS = p[i+1]-'0';
if ((p[i+2]>='0') && (p[i+2]<='9'))
{ s=3; header_ext_setting *= 10;
header_ext_setting += p[i+2]-'0';
{ s=3; ZCODE_HEADER_EXT_WORDS *= 10;
ZCODE_HEADER_EXT_WORDS += p[i+2]-'0';
}
}
break;
Expand Down
29 changes: 29 additions & 0 deletions memory.c
Expand Up @@ -254,6 +254,8 @@ int MAX_GLOBAL_VARIABLES;
int DICT_WORD_SIZE; /* number of characters in a dict word */
int DICT_CHAR_SIZE; /* (glulx) 1 for one-byte chars, 4 for Unicode chars */
int DICT_WORD_BYTES; /* DICT_WORD_SIZE*DICT_CHAR_SIZE */
int ZCODE_HEADER_EXT_WORDS; /* (zcode 1.0) requested header extension size */
int ZCODE_HEADER_FLAGS_3; /* (zcode 1.1) value to place in Flags 3 word */
int NUM_ATTR_BYTES;
int GLULX_OBJECT_EXT_BYTES; /* (glulx) extra bytes for each object record */
int32 MAX_NUM_STATIC_STRINGS;
Expand Down Expand Up @@ -297,6 +299,10 @@ static void list_memory_sizes(void)
printf("| %25s = %-7d |\n","MAX_EXPRESSION_NODES",MAX_EXPRESSION_NODES);
printf("| %25s = %-7d |\n","MAX_GLOBAL_VARIABLES",MAX_GLOBAL_VARIABLES);
printf("| %25s = %-7d |\n","HASH_TAB_SIZE",HASH_TAB_SIZE);
if (!glulx_mode)
printf("| %25s = %-7d |\n","ZCODE_HEADER_EXT_WORDS",ZCODE_HEADER_EXT_WORDS);
if (!glulx_mode)
printf("| %25s = %-7d |\n","ZCODE_HEADER_FLAGS_3",ZCODE_HEADER_FLAGS_3);
printf("| %25s = %-7d |\n","MAX_INCLUSION_DEPTH",MAX_INCLUSION_DEPTH);
printf("| %25s = %-7d |\n","MAX_INDIV_PROP_TABLE_SIZE",
MAX_INDIV_PROP_TABLE_SIZE);
Expand Down Expand Up @@ -510,6 +516,11 @@ extern void set_memory_sizes(int size_flag)
DICT_WORD_SIZE_g = 9;
NUM_ATTR_BYTES_z = 6;
NUM_ATTR_BYTES_g = 7;
/* Backwards-compatible behavior: allow for a unicode table
whether we need one or not. The user can set this to zero if
there's no unicode table. */
ZCODE_HEADER_EXT_WORDS = 3;
ZCODE_HEADER_FLAGS_3 = 0;
GLULX_OBJECT_EXT_BYTES = 0;
MAX_UNICODE_CHARS = 64;
MEMORY_MAP_EXTENSION = 0;
Expand Down Expand Up @@ -622,6 +633,20 @@ static void explain_parameter(char *command)
plus three.\n");
return;
}
if (strcmp(command,"ZCODE_HEADER_EXT_WORDS")==0)
{ printf(
" ZCODE_HEADER_EXT_WORDS is the number of words in the Z-code header \n\
extension table (Z-Spec 1.0). The -W switch also sets this. It defaults \n\
to 3, but can be set higher. (It can be set lower if no Unicode \n\
translation table is created.)\n");
return;
}
if (strcmp(command,"ZCODE_HEADER_FLAGS_3")==0)
{ printf(
" ZCODE_HEADER_FLAGS_3 is the value to store in the Flags 3 word of the \n\
header extension table (Z-Spec 1.1).\n");
return;
}
if (strcmp(command,"GLULX_OBJECT_EXT_BYTES")==0)
{ printf(
" GLULX_OBJECT_EXT_BYTES is an amount of additional space to add to each \n\
Expand Down Expand Up @@ -892,6 +917,10 @@ extern void memory_command(char *command)
{ NUM_ATTR_BYTES=j, flag=1;
NUM_ATTR_BYTES_g=NUM_ATTR_BYTES_z=j;
}
if (strcmp(command,"ZCODE_HEADER_EXT_WORDS")==0)
ZCODE_HEADER_EXT_WORDS=j, flag=1;
if (strcmp(command,"ZCODE_HEADER_FLAGS_3")==0)
ZCODE_HEADER_FLAGS_3=j, flag=1;
if (strcmp(command,"GLULX_OBJECT_EXT_BYTES")==0)
GLULX_OBJECT_EXT_BYTES=j, flag=1;
if (strcmp(command,"MAX_STATIC_DATA")==0)
Expand Down
38 changes: 30 additions & 8 deletions tables.c
Expand Up @@ -145,7 +145,7 @@ static int32 rough_size_of_paged_memory_z(void)
+ 6*32; /* abbreviations table */

total += 8; /* header extension table */
if (header_ext_setting>3) total += (header_ext_setting-3)*2;
if (ZCODE_HEADER_EXT_WORDS>3) total += (ZCODE_HEADER_EXT_WORDS-3)*2;

if (alphabet_modified) total += 78; /* character set table */

Expand Down Expand Up @@ -290,8 +290,17 @@ static void construct_storyfile_z(void)
/* ------------------- Header extension table ------------------------- */

headerext_at = mark;
headerext_length = 3; /* Usually 3 words long */
if (header_ext_setting>3) headerext_length = header_ext_setting;
headerext_length = ZCODE_HEADER_EXT_WORDS;
if (zscii_defn_modified) {
/* Need at least 3 words for unicode table address */
if (headerext_length < 3)
headerext_length = 3;
}
if (ZCODE_HEADER_FLAGS_3) {
/* Need at least 4 words for the flags-3 field (ZSpec 1.1) */
if (headerext_length < 4)
headerext_length = 4;
}
p[mark++] = 0; p[mark++] = headerext_length;
for (i=0; i<headerext_length; i++)
{ p[mark++] = 0; p[mark++] = 0;
Expand Down Expand Up @@ -780,11 +789,24 @@ or less.");

/* ------------------------ Header Extension -------------------------- */

i = headerext_at + 2;
p[i++] = 0; p[i++] = 0; /* Mouse x-coordinate slot */
p[i++] = 0; p[i++] = 0; /* Mouse y-coordinate slot */
j = unicode_at;
p[i++] = j/256; p[i++] = j%256; /* Unicode translation table address */
/* The numbering in the spec is a little weird -- it's headerext_length
words *after* the initial length word. We follow the spec numbering
in this switch statement, so the count is 1-based. */
for (i=1; i<=headerext_length; i++) {
switch (i) {
case 3:
j = unicode_at; /* Unicode translation table address */
break;
case 4:
j = ZCODE_HEADER_FLAGS_3; /* Flags 3 word */
break;
default:
j = 0;
break;
}
p[headerext_at+2*i+0] = j / 256;
p[headerext_at+2*i+1] = j % 256;
}

/* ----------------- The Header: Extras for modules ------------------- */

Expand Down

0 comments on commit 29717b7

Please sign in to comment.