Skip to content

Commit b32a533

Browse files
author
DavidKinder
committed
New version number, and fixes for glkop.c from Glulxe
1 parent c836145 commit b32a533

File tree

8 files changed

+69
-8
lines changed

8 files changed

+69
-8
lines changed

‎README.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ also to Eliuk Blau for tracking down bugs in the memory management opcodes.
192192

193193
* Version History
194194

195+
1.2.9 2011-08-28 Fixed a bug in glkop.c dispatching, to do with optional
196+
array arguments, following a similar fix in Glulxe.
197+
Glk array and string operations are now checked for memory
198+
overflows (though not for ROM writing), following a similar
199+
fix in Glulxe.
200+
195201
1.2.8 2010-08-25 Fixed a problem with 'undo' when compiled as 64 bit,
196202
contributed by Ben Cressey.
197203
Fixed a sign problem for the @fceil opcode, following a

‎git.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extern void startProgram (size_t cacheSize, enum IOMode ioMode);
124124
extern int git_init_dispatch();
125125
extern glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist);
126126
extern strid_t git_find_stream_by_id(glui32 id);
127+
extern glui32 git_find_id_for_stream(strid_t str);
127128

128129
// git_search.c
129130

‎glkop.c‎

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
277277
directly -- instead of bothering with the whole prototype
278278
mess. */
279279

280+
case 0x0047: /* stream_set_current */
281+
if (numargs != 1)
282+
goto WrongArgNum;
283+
glk_stream_set_current(git_find_stream_by_id(arglist[0]));
284+
break;
285+
case 0x0048: /* stream_get_current */
286+
if (numargs != 0)
287+
goto WrongArgNum;
288+
retval = git_find_id_for_stream(glk_stream_get_current());
289+
break;
280290
case 0x0080: /* put_char */
281291
if (numargs != 1)
282292
goto WrongArgNum;
@@ -297,6 +307,16 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
297307
goto WrongArgNum;
298308
retval = glk_char_to_upper(arglist[0] & 0xFF);
299309
break;
310+
case 0x0128: /* put_char_uni */
311+
if (numargs != 1)
312+
goto WrongArgNum;
313+
glk_put_char_uni(arglist[0]);
314+
break;
315+
case 0x012B: /* put_char_stream_uni */
316+
if (numargs != 2)
317+
goto WrongArgNum;
318+
glk_put_char_stream_uni(git_find_stream_by_id(arglist[0]), arglist[1]);
319+
break;
300320

301321
WrongArgNum:
302322
fatalError("Wrong number of arguments to Glk function.");
@@ -306,7 +326,7 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
306326
/* Go through the full dispatcher prototype foo. */
307327
char *proto, *cx;
308328
dispatch_splot_t splot;
309-
int argnum;
329+
int argnum, argnum2;
310330

311331
/* Grab the string. */
312332
proto = gidispatch_prototype(funcnum);
@@ -335,9 +355,11 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
335355
gidispatch_call(funcnum, argnum, splot.garglist);
336356

337357
/* Phase 3. */
338-
argnum = 0;
358+
argnum2 = 0;
339359
cx = proto;
340-
unparse_glk_args(&splot, &cx, 0, &argnum, 0, 0);
360+
unparse_glk_args(&splot, &cx, 0, &argnum2, 0, 0);
361+
if (argnum != argnum2)
362+
fatalError("Argument counts did not match.");
341363

342364
break;
343365
}
@@ -560,6 +582,12 @@ static void parse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
560582

561583
switch (typeclass) {
562584
case 'C':
585+
/* This test checks for a giant array length, and cuts it down to
586+
something reasonable. Future releases of this interpreter may
587+
treat this case as a fatal error. */
588+
if (varglist[ix+1] > gEndMem || varglist[ix]+varglist[ix+1] > gEndMem)
589+
varglist[ix+1] = gEndMem - varglist[ix];
590+
563591
garglist[gargnum].array = (void*) AddressOfArray(varglist[ix]);
564592
gargnum++;
565593
ix++;
@@ -568,6 +596,10 @@ static void parse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
568596
cx++;
569597
break;
570598
case 'I':
599+
/* See comment above. */
600+
if (varglist[ix+1] > gEndMem/4 || varglist[ix+1] > (gEndMem-varglist[ix])/4)
601+
varglist[ix+1] = (gEndMem - varglist[ix]) / 4;
602+
571603
garglist[gargnum].array = CaptureIArray(varglist[ix], varglist[ix+1], passin);
572604
gargnum++;
573605
ix++;
@@ -679,6 +711,8 @@ static void parse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
679711
}
680712
else {
681713
cx++;
714+
if (isarray)
715+
ix++;
682716
}
683717
}
684718
}
@@ -885,6 +919,8 @@ static void unparse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
885919
}
886920
else {
887921
cx++;
922+
if (isarray)
923+
ix++;
888924
}
889925
}
890926
}
@@ -916,6 +952,21 @@ strid_t git_find_stream_by_id(glui32 objid)
916952
return classes_get(1, objid);
917953
}
918954

955+
/* find_id_for_stream():
956+
The converse of find_stream_by_id().
957+
This is only needed in this file, so it's static.
958+
*/
959+
glui32 git_find_id_for_stream(strid_t str)
960+
{
961+
gidispatch_rock_t objrock;
962+
963+
if (!str)
964+
return 0;
965+
966+
objrock = gidispatch_get_objrock(str, 1);
967+
return ((classref_t *)objrock.ptr)->id;
968+
}
969+
919970
/* Build a hash table to hold a set of Glk objects. */
920971
static classtable_t *new_classtable(glui32 firstid)
921972
{

‎help/glk.htm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h1>Glk</h1>
88
The <a href="http://www.ifarchive.org/if-archive/programming/glk/glk-spec-070.txt">Glk specification</a>
99
was written by Andrew Plotkin as an attempt to define a standard input and output interface for general
1010
use in IF related projects. Windows Git uses my (David Kinder) implementation of Glk, called Windows
11-
Glk. Windows Glk is a complete implementation of all the features described in version 0.7.2 of the Glk
11+
Glk. Windows Glk is a complete implementation of all the features described in version 0.7.3 of the Glk
1212
specification.
1313
<p>
1414
The complete Windows Glk package, including developer information, can be downloaded from the IF Archive's

‎help/glulx.htm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h1>Glulx</h1>
1010
the Inform compiler could compile to, without the limitations of its original output format, Infocom's
1111
Z-Machine.
1212
<p>
13-
Windows Git is based on Iain Merrick's Git 1.2.8, which is a complete implementation of version 3.1.2
13+
Windows Git is based on Iain Merrick's Git 1.2.9, which is a complete implementation of version 3.1.2
1414
of the Glulx specification.
1515
<p>
1616
More information on Glulx is available from the Glulx web page:

‎help/overview.htm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<link rel="stylesheet" type="text/css" href="Git.css">
55
</head>
66
<body>
7-
<h1>Windows Git 1.2.8<br><font size="-1">(Windows Glk 1.43)</font></h1>
7+
<h1>Windows Git 1.2.9<br><font size="-1">(Windows Glk 1.43)</font></h1>
88
Windows Git is an interpreter for <a href="glulx.htm">Glulx</a> games. Windows Git
99
consists of a core interpreter called Git, and an input/output library, called Windows
1010
Glk. Together these two components form the Windows Git package, which has been created

‎help/revision.htm‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
<body>
77
<h1>Revision History</h1>
88

9-
<b>Git 1.2.8 (Windows Glk 1.43)</b>
9+
<b>Git 1.2.9 (Windows Glk 1.43)</b>
1010
<ul>
11+
<li>Updated to support Glk 0.7.3, which includes more control when playing sounds.
1112
<li>[More] prompts now function even if the game has exited, allowing any
1213
long amount of final text to be read.
1314
<li>Fixed a bug with file streams when reading and writing to the same file.
15+
<li>Updated to Git 1.2.9, which fixes bugs related to Glk call dispatching,
16+
following similar fixes in Glulxe.
1417
</ul>
1518

1619
<b>Git 1.2.8 (Windows Glk 1.42)</b>

‎version.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Automatically generated file -- do not edit!
22
#define GIT_MAJOR 1
33
#define GIT_MINOR 2
4-
#define GIT_PATCH 8
4+
#define GIT_PATCH 9

0 commit comments

Comments
 (0)