Debian Codegraph @

terps/level9/Glk/glk_readme.txt

raw
1 Level 9 Interpreter, Glk Notes
2 ------------------------------
3
4
5 Introduction
6 ------------
7
8 This is a port of the Level 9 interpreter to Glk. The complete interface
9 lives in the single file
10
11 glk.c
12
13 The main test and development system for the port is Linux, with Xglk as the
14 Glk library.
15
16
17 Acknowledgements
18 ----------------
19
20 Thanks to Alan Staniforth for considerable help with getting the some of the
21 source for the base interpreter together, and for his hints on how to cover
22 the porting requirements, and to David Kinder for a complete reality check on
23 the port progress, and also for the Level 9 interpreter.
24
25 Thanks also to Ben Hines <[email protected]> for the Mac code, which, if
26 I have transcribed it correctly from earlier work with AGiliTy, should permit
27 this port to run on Mac platforms with Glk.
28
29
30 Running Games
31 -------------
32
33 The interpreter understands game files that use the "Spectrum snapshot" format.
34 A file in this format usually has the extension ".sna" or ".SNA".
35
36 Give the name of the game file to run at the system prompt. For example
37
38 glklevel9 colossal.sna
39
40 If the game has an external line drawing graphics file, make sure that the file
41 lives in the same directory as the game file, and has the same base name with
42 the extension ".pic", or is named "picture.dat". The Glk interpreter will
43 find this file automatically, if it exists, and use it to create game pictures.
44 Line drawn graphics are not always held in an external graphics file; a game
45 may l hold its graphics internally, in which case no addtional files are
46 required.
47
48 If the game has external bitmap pictures, these will normally appear as
49 multiple files with ".pic", ".squ", ".picN", or ".title" extensions. As with
50 line drawn graphics, ensure that these files are in the same directory as the
51 main game file, so that the Glk interpreter can find them.
52
53 If there are no graphics files, the interpreter will run in text only mode. It
54 will also do this if it cannot open the graphics files, or if the files do not
55 seem to contain usable game graphics.
56
57 There are a few command line options that you can also add, to vary the way
58 that the game looks:
59
60 -np Don't display game pictures initially
61 -ni Don't intercept 'quit', 'restart', 'save', and 'restore'
62 -ne Don't add an extra prompt on line input
63 -nl Don't attempt to detect infinite loops in games
64 -na Don't expand single-letter abbreviations
65 -nc Don't attempt to interpret selected commands locally
66
67 See below for further information about what these options mean.
68
69
70 Compiling
71 ---------
72
73 To compile Glk Level 9 for Linux, first unpack the source files. You might
74 need to use the -a argument to unzip in order to convert text files for your
75 system.
76
77 Edit Makefile.glk so that it has the right path to the Glk library you wish to
78 build with. If you want to build the IFP plugin, also edit the parts of
79 Makefile.glk that have paths to IFP components.
80
81 To build standalone binary version of Glk Level 9, use
82
83 make -f Makefile.glk glklevel9
84
85 To build the IFP plugin, use
86
87 make -f Makefile.glk level9-5.2.so
88
89 To clean up and delete everything in the case of a build error, use
90
91 make -f Makefile.glk clean
92
93
94 Intercepting Game Commands
95 --------------------------
96
97 Some Level 9 games are written for cassette tape based microprocessor systems,
98 and the way in which they save, restore, and restart games generally reflects
99 this. Additionally, there's often no straightforward way to quit from a game.
100
101 To try to make things a bit more convenient for a player, Glk Level 9 traps the
102 following command words in its interface:
103
104 quit, restart, save, restore, and load (synonym for restore)
105
106 When it sees one of these entered on an input line, it tries to handle the
107 command itself. In the case of "quit" and "restart", it will confirm that you
108 want to end the current game.
109
110 In the case of "save" and "restore", Glk Level 9 will try to handle saving or
111 loading game state to or from system files using the Level 9 interpreter
112 internal routines, rather than the ones built into the game itself. This
113 bypasses the inconvenient "Lenslok" check built into some games, and also works
114 round a couple of possible Level 9 interpreter bugs.
115
116 If you prefix a command with a single quote, Glk Level 9 will not try to handle
117 the command itself, but will remove the quote, and pass the remaining string
118 to the game without change.
119
120 You can turn off command interception with the command line option '-ni'.
121
122
123 Extra Prompting
124 ---------------
125
126 Early Level 9 games generally output a prompt something like
127
128 What now?
129
130 However, it's not always printed when the game is expecting line input. Simply
131 leaning on the Return key will scroll the game with no prompting, and the
132 Adrian Mole games offer no prompt at all when not in menu modes.
133
134 Some later Level 9 games begin with the "What now?" (or "What gnow?"), then
135 switch to issuing a "> " prompt later on.
136
137 To try to make it a little clearer to see what's going on, the Glk Level 9 will
138 add it's own "> " prompt when the game is expecting line input, but only when
139 it determines that the game has not already issued its own prompt.
140
141 You can turn this off with the '-ne' option.
142
143
144 Displaying Pictures
145 -------------------
146
147 Level 9 games may contain graphics, and while not essential to the game, they
148 can enhance the experience of playing.
149
150 Unfortunately, Glk does not provide a method to directly display an image
151 bitmap, so Glk Level 9 needs to adopt some tricks to get a picture to display.
152 The end result is that, on Linux Xglk at least, it can take several seconds to
153 render a complete picture.
154
155 To reduce the problems caused by a game pausing for several seconds for a
156 picture, Glk Level 9 does its picture rendering using a background "thread".
157 This draws in the complete picture over a series of smaller image updates,
158 while at the same time still allowing game play. To speed up picture
159 rendering, Glk Level 9 also goes to considerable effort to try to minimize the
160 amount of Glk graphics operations it uses.
161
162 If you move to a location with a new picture before the current one has been
163 fully rendered, Glk Level 9 will simply start working on the newer picture.
164
165 Most Level 9 games accept the "graphics" and "text" commands, which turn
166 pictures on and off respectively. It is also possible to turn off pictures
167 directly in Glk, for games that don't support these two commands.
168
169 You can use the "-np" option to turn off pictures. Glk Level 9 also will not
170 show pictures if the Glk library does not support both graphics and timers, if
171 there are no graphics files, built in graphics, or bitmaps, or if the
172 interpreter cannot open graphics files successfully. See below for further
173 notes about displaying pictures.
174
175
176 Game Infinite Loop Checking
177 ---------------------------
178
179 Some Level 9 games can enter an infinite loop if they have nothing better to
180 do. For example, at then end of Adrian Mole, you have the option to play the
181 last part again. If you decline, the game will spin in a tight loop which
182 does nothing.
183
184 Because it's hard to break into this loop without killing the interpreter
185 completely, Glk Level 9 notes how much work the interpreter is doing over time.
186 If it notices that the interpreter has neither printed anything nor asked for
187 input for five seconds or so, it assumes that the game is in an infinite loop,
188 and offers you the chance to stop the game.
189
190 In the unlikely event that this check triggers with a game that is not in an
191 infinite loop, you can turn off the option with "-nl".
192
193
194 Status Line
195 -----------
196
197 Level 9 games do not print a status line, so Glk Level 9 will use the status
198 window, a separate window above the main window created by Glk libraries that
199 support separate windows, to display the game's name and version details.
200
201 For other Glk libraries, Glk Level 9 will print the game's name in "[...]"
202 brackets above the standard game output following each turn, but only when the
203 game name has changed since the last turn (that is, in multi-file games).
204
205
206 Expanding Abbreviations
207 -----------------------
208
209 Many IF games systems allow a player to use single character abbreviations for
210 selected common commands, for example, 'x' for 'examine', 'l' for look, and so
211 on. Not all Level 9 games offer this feature, however.
212
213 To try to help the player, Glk Level 9 will automatically expand a selection
214 of single character commands, before passing the expanded string to the game as
215 input. It expands a command only if the first word of the command is a single
216 letter, and one of the following:
217
218 'c' -> "close" 'g' -> "again" 'i' -> "inventory"
219 'k' -> "attack" 'l' -> "look" 'p' -> "open"
220 'q' -> "quit" 'r' -> "drop" 't' -> "take"
221 'x' -> "examine" 'y' -> "yes" 'z' -> "wait"
222
223 If you want to suppress abbreviation expansion, you can prefix your input with
224 a single quote character (like putting literal strings into a spreadsheet).
225 If you do this, Glk Level 9 will strip the quote, then pass the rest of the
226 string to the main interpreter without any more changes. So for example,
227
228 'x something
229
230 will pass the string "x something" back to the game, whereas
231
232 x something
233
234 will pass "examine something" back to the game.
235
236 You can turn off abbreviation expansions with the command line option '-na'.
237
238
239 Interpreting Commands Locally
240 -----------------------------
241
242 Glk Level 9 will handle special commands if they are prefixed with the string
243 'glk'. It understands the following special commands:
244
245 help Prints help on Glk special commands
246 summary Prints all current Glk settings
247 version Prints the Glk library and Glk port version numbers
248 license Prints the Glk port license
249
250 script on Starts recording the game text output sent to the
251 main game window
252 script off Turns off game text recording
253 inputlog on Starts recording input lines typed by the player
254 inputlog off Stops recording input lines
255 readlog on Reads an input log file as if it had been typed by
256 a player; reading stops automatically at the end of
257 the file
258 abbreviations on Turn abbreviation expansion on
259 abbreviations off Turn abbreviation expansion off
260 graphics on Turn on Glk graphics
261 graphics off Turn off Glk graphics (see below)
262 loopchecks on Turn game infinite loop checking on
263 loopchecks off Turn game infinite loop checking off
264 locals on Turn local interception of 'quit', 'restart',
265 'save' and 'restore' on
266 locals off Turn local interception of 'quit', etc. off
267 prompts on Turn extra "> " prompting on
268 prompts off Turn extra "> " prompting off
269 commands off Turn of Glk special commands; once off, there is no
270 way to turn them back on
271
272 You can abbreviate these commands, as long as the abbreviation you use is
273 unambiguous.
274
275 If for some reason you need to pass the string "glk" to the interpreter, you
276 can, as with abbreviations above, prefix it with a single quote character.
277
278 You can turn off local command handling with the command line option '-nc'.
279
280 If all of abbreviation expansion, local command handling, and game command
281 interceptions are turned off, there is no need to use single quotes to suppress
282 special interpreter features.
283
284
285 Multi-file Games
286 ----------------
287
288 Some Level 9 games come in multiple files, for example
289
290 gamedat1.sna
291 gamedat2.sna
292 ...
293
294 and so on. Once a game part is finished, the Level 9 interpreter queries the
295 Glk interface for the next file. When this happens, both for disk and for
296 tape based games, the interface will try to generate the appropriate file name
297 for the next game part, by incrementing the last digit found in the file's
298 name. The interpreter will then look in the same directory for the new file
299 name.
300
301 If this method fails, then you will need to run the separate game parts
302 manually. Alternatively, rename the files so that they match this pattern.
303
304
305 Keyboard Polling
306 ----------------
307
308 Some Level 9 games use the standard home microprocessor system method of
309 waiting for a keypress, using a tight spin loop that samples the keyboard until
310 a key is detected. The Adrian Mole games use this keyboard sampling both for
311 scroll pausing, and for their main menu selections, with something like:
312
313 for each line in the output paragraph
314 print the line
315 while (os_readchar() shows a key is pressed)
316 ;
317 endwhile
318 endfor
319 selection = return value from os_readchar()
320 while (selection shows no key is pressed)
321 selection = return value from os_readchar()
322 handle selection...
323
324 This means that os_readchar() _must_ be implemented according to the notes in
325 Level 9's porting.txt. That is, it must poll the keyboard for key presses,
326 and return the key code if a key is pressed, or zero if no key is currently
327 pressed.
328
329 If os_readchar() waits for a key press on each call, Adrian Mole games will
330 wait for a key press after each output line, which is not what we want. On the
331 other hand, if it doesn't wait for a key press at the menu selection point, the
332 interpreter will consume all the available system CPU time, which is also very
333 undesirable on a multi-tasking operating system.
334
335 To solve this, Glk Level 9 uses two different techniques, and which it chooses
336 depends on whether the Glk library it is linked with has timers.
337
338 If the Glk library has timers, then on each call to os_readchar(), Glk Level 9
339 starts a timeout for a short period, then waits for either a key press event,
340 or a timeout. If it receives a key press, it returns the code, otherwise it
341 returns zero. This lets games run correctly. Continually cycling through the
342 Glk timeout is fast enough to be acceptable to a player, but the timeout
343 provides good protection against spinning wildly in a tight loop.
344
345 If the Glk library does not have timers, then the interface will return zero
346 for some large number of consecutive calls, then wait until a character is
347 entered. Since the initial number is large, this allows the game to progress,
348 generally, to the point where it needs a key press to continue at all. The
349 only thing that might show slightly odd behaviour is the DEMO mode of Adrian
350 Mole games.
351
352 Also, this type of character polling cannot be used with reading input logs.
353 So the Glk "readlog" command does not function with Adrian Mole games.
354
355 To pretend that no key was pressed, when the interface is in fact waiting for
356 a key press, you can type Control-U. The Glk interface will return this to
357 the game as a zero.
358
359 Games that rarely, or never, use line input, but continually poll for input
360 using os_readchar(), are difficult to stop. To help with this, Glk Level 9
361 offers Control-C as as way to quit the game, with a confirmation as for "quit"
362 above. Note that Control-C will only work when the game is using os_readchar()
363 (that is, most of the time for Adrian Mole games, and occasionally, if ever,
364 in other games). For normal line input, use "quit" as described above.
365
366 Control-C is turned off by the command line option "-nc".
367
368
369 A Few Last Words on Graphics
370 ----------------------------
371
372 When turning graphics on and off with Glk commands, you should pay special
373 attention to whether graphics are turned on or off in the game. In order for
374 graphics to be displayed, they must be turned on both in the game AND in Glk.
375 Turning off graphics in Glk is a little more permanent than turning them off
376 in a game; in fact, some games don't seem to allow you to turn off graphics
377 within the game at all.
378
379 Why a secondary Glk way to turn off pictures? Well, Level 9 games don't always
380 behave the same way with the "graphics" and "text" commands, so a control
381 inside Glk Level 9 itself gives a more consistent way to turn graphics on and
382 off. The command
383
384 glk graphics
385
386 with no on/off argument, prints out a brief information about the current state
387 of a game's graphics. In practice, it's probably best to stick to just one
388 method of turning graphics on and off -- either the game's own way, or the
389 'glk graphics' command if the former is not available.
390
391 Glk Level 9 does not display all of the line drawn graphics correctly in a
392 handful of games. Games known to not display all graphics fully correctly are
393 "Erik the Viking" (Spectrum, v2), "Return to Eden" (Spectrum48, v3), and
394 "Price of Magik" (Spectrum48, v3).
395
396
397 --
398
399 Simon Baldwin, [email protected]