| 1 |
==================================================================== |
| 2 |
AGILITY: THE (MOSTLY) UNIVERSAL AGT INTERPRETER Version 1.1.2 |
| 3 |
MAGX: MAKE AGX, AGT-COMPATIBLE COMPILER Version 0.6.5 (beta) |
| 4 |
==================================================================== |
| 5 |
|
| 6 |
This file contains notes on compiling and porting AGiliTy and Magx. See |
| 7 |
'readme.agility' or 'readme.magx' for an introduction to the program. |
| 8 |
The two programs are separate packages, but they have a fairly large |
| 9 |
base of common code, so I've decided to merge their porting notes. |
| 10 |
|
| 11 |
This software may be freely redistributed under the terms of the GNU |
| 12 |
General Public License, version 2. Since this is free software, there |
| 13 |
is NO WARRANTY of any kind. |
| 14 |
|
| 15 |
The original author, Robert Masenten, has not been heard from in years, |
| 16 |
but David Kinder has done some work on updating AGiliTy to fix bugs. Any |
| 17 |
bugs you find can be reported at David's GitHub page for AGiliTy: |
| 18 |
https://github.com/DavidKinder/Windows-AGiliTy/ |
| 19 |
|
| 20 |
|
| 21 |
----------- |
| 22 |
CONTENTS |
| 23 |
----------- |
| 24 |
This document has the following sections: |
| 25 |
|
| 26 |
1.0 LIST OF MAJOR CHANGES... |
| 27 |
1.1 ...TO AGILITY SINCE VERSION 0.8.4 |
| 28 |
1.2 ...TO MAGX SINCE VERSION 0.4 |
| 29 |
2.0 SOURCE FILES |
| 30 |
2.1 COMMON SOURCE FILES |
| 31 |
2.2 AGILITY-SPECIFIC SOURCE FILES |
| 32 |
2.3 MAGX-SPECIFIC SOURCE FILES |
| 33 |
3.0 COMPILING |
| 34 |
3.1 AGILITY PACKAGE |
| 35 |
3.2 MAGX PACKAGE |
| 36 |
4.0 PORTING NOTES FOR BOTH SYSTEMS |
| 37 |
4.1 CONFIG.H: PLATFORM SPECIFIC #DEFINES |
| 38 |
4.2 VARIABLES AND FUNCTIONS DEFINED BY THE INTERPRETER |
| 39 |
4.3 FILENAME.C: OVERVIEW |
| 40 |
4.4 FILENAME.C: DATA TYPES |
| 41 |
4.5 FILENAME.C: FUNCTIONS |
| 42 |
5.0 FURTHER NOTES ON PORTING AGILITY |
| 43 |
5.1 OS_*.C: THE PLATFORM-SPECIFIC INTERFACE |
| 44 |
5.2 VARIABLES AND FUNCTIONS DEFINED BY THE INTERPRETER |
| 45 |
5.3 OTHER FUNCTIONS THAT CAN OPTIONALLY BE SPECIFIED |
| 46 |
5.4 GRAPHICS, FONT, AND SOUND FUNCTIONS |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
------------------------------- |
| 51 |
1.0 LIST OF MAJOR CHANGES... |
| 52 |
------------------------------- |
| 53 |
|
| 54 |
Theses are lists of the changes most likely to be relevant to |
| 55 |
porters; all of the changes are more extensivly documented in the body |
| 56 |
of this file and in the file 'changes.txt'. |
| 57 |
|
| 58 |
|
| 59 |
---------------------------------------- |
| 60 |
1.1 ...TO AGILITY SINCE VERSION 0.8.4 |
| 61 |
---------------------------------------- |
| 62 |
--os_linux.c has been renamed os_termcap.c; os_curses.c has become |
| 63 |
the main Linux display module. |
| 64 |
--replay_fast flag has been added; this should be checked by |
| 65 |
agt_delay() and agt_newline(). |
| 66 |
--Filename handling has been completely overhauled. All file I/O now |
| 67 |
goes through the new file "filename.c". This has the following effects |
| 68 |
on porters: |
| 69 |
1) filename.c needs to be compiled and linked with everything. |
| 70 |
2) agt_globalfile() and get_user_file() now have return-type |
| 71 |
'genfile'. (genfile is typedef'd to FILE* by default, so this |
| 72 |
shouldn't break anything.) |
| 73 |
3) 'scriptfile' is now of type genfile. See comment 2. |
| 74 |
4) start_interface() now takes an argument of type 'fc_type' |
| 75 |
instead of 'char*', as does set_default_filenames() |
| 76 |
If you are using the default filename.c, then you can get |
| 77 |
the old value by looking at "fc->gamename". |
| 78 |
5) If you're replacing main(), the call to run_game() now requires |
| 79 |
a file context instead of a game name. (See notes on main()). |
| 80 |
See section 4.5 for more information. |
| 81 |
--Added fixed font formatting code as well as FIXED_FONT |
| 82 |
configuration option. |
| 83 |
--Platform dependent information has been broken off into a seperate |
| 84 |
include file, config.h, which is #included in agility.h |
| 85 |
--Changed source code filenames to improve readability: |
| 86 |
agtread.h-->agility.h; uagt.h-->interp.h; |
| 87 |
agtdata.c-->gamedata.c; agtdbg.c-->disassemble.c; |
| 88 |
agttest.c-->agtout.c; rmem.c-->util.c |
| 89 |
--Converted bool to rbool to avoid conflicts with other libraries and |
| 90 |
systems. |
| 91 |
--Documentation of agt_textcolor() fixed. |
| 92 |
|
| 93 |
|
| 94 |
----------------------------------- |
| 95 |
1.2 ...TO MAGX SINCE VERSION 0.4 |
| 96 |
----------------------------------- |
| 97 |
--New source file, objcomp.c, split off of compile.c. |
| 98 |
--Platform dependent information has been broken off into a seperate |
| 99 |
include file, config.h, which is #included in agility.h. |
| 100 |
--Changed source code filenames to improve readability: |
| 101 |
agtread.h-->agility.h; agtdata.c-->gamedata.c; rmem.c-->util.c |
| 102 |
--Converted to using filename.c for file operations. See porting.txt |
| 103 |
for details. |
| 104 |
--Converted bool to rbool to avoid conflicts with other libraries and |
| 105 |
systems and eliminated occurances of 'class'. |
| 106 |
|
| 107 |
|
| 108 |
------------------- |
| 109 |
2.0 SOURCE FILES |
| 110 |
------------------- |
| 111 |
This lists the source files that should be in this package. |
| 112 |
|
| 113 |
|
| 114 |
-------------------------- |
| 115 |
2.1 COMMON SOURCE FILES |
| 116 |
-------------------------- |
| 117 |
config.g -- Platform specific #defines. |
| 118 |
agility.h -- The header for all of the above files. |
| 119 |
|
| 120 |
filename.c -- Functions for finding and opening files; this may |
| 121 |
need to be edited or replaced on some platforms. |
| 122 |
|
| 123 |
agxfile.c -- Routines to read and write AGX game files. |
| 124 |
auxfile.c -- Routines to read in various additional AGT files. |
| 125 |
gamedata.c -- Static data structures and dictionary management routines |
| 126 |
util.c -- Miscellaneous utilities including string functions, wrappers |
| 127 |
for dynamic allocation routines, and file I/O. |
| 128 |
agilstub.c -- This contains the basic output function used by the |
| 129 |
utility programs; not part of the interpreter. |
| 130 |
|
| 131 |
|
| 132 |
------------------------------------ |
| 133 |
2.2 AGILITY-SPECIFIC SOURCE FILES |
| 134 |
------------------------------------ |
| 135 |
interp.h -- Header for the interpreter files; contains things used by the |
| 136 |
interpreter but not by agtread.c. |
| 137 |
exec.h -- Header for the verb execution files (exec.c, runverb.c, |
| 138 |
metacommand.c, and debugcmd.c). |
| 139 |
|
| 140 |
os_none.c, os_termcap.c, os_dos.c, os_curses.c -- |
| 141 |
platform specific functions, including the lowest level terminal |
| 142 |
I/O routines. os_none.c provides a minimal interface that uses |
| 143 |
only ANSI C library functions; it is intended mainly as a template. |
| 144 |
os_termcap.c and os_curses.c are two alternative unix backends; |
| 145 |
they were developed under Linux but should work under most |
| 146 |
*nix variants. (Please e-mail me about any portability problems.) |
| 147 |
|
| 148 |
agtread.c -- Routines for reading AGT game files. |
| 149 |
agil.c -- Initialization and the main program loop for the interpreter. |
| 150 |
parser.c-- The parser and the menu system. |
| 151 |
exec.c-- The top-level function for running player commands, |
| 152 |
end-of-turn routines and miscellaneous utilities used during turn |
| 153 |
execution. |
| 154 |
metacommand.c-- Metacommand execution core. |
| 155 |
token.c-- Decoding and execution of the actual metacommand tokens. |
| 156 |
runverb.c-- Routines for executing verbs and the main routine |
| 157 |
for executing player commands. |
| 158 |
object.c -- Functions for manipulating the rooms, nouns, and creatures |
| 159 |
debugcmd.c-- Routines for executing the debugging verbs. |
| 160 |
interface.c -- The user interface for the interpreter and other semi-platform |
| 161 |
dependent things including main() |
| 162 |
disassemble.c -- Routines to print out the metacommand execution trace. |
| 163 |
(Basically a disassembler for metacommands) |
| 164 |
savegame.c -- Functions for saving and restoring the game state; used by |
| 165 |
RESTART and UNDO as well as SAVE and RESTORE. |
| 166 |
agtout.c -- Dumps out 'disassembled' AGT game files (originally written |
| 167 |
as a test for agtread.c) |
| 168 |
agt2agx.c -- Converts from AGT to AGX format. |
| 169 |
|
| 170 |
|
| 171 |
--------------------------------- |
| 172 |
2.3 MAGX-SPECIFIC SOURCE FILES |
| 173 |
--------------------------------- |
| 174 |
comp.h -- Header for all compiler-specific files. |
| 175 |
|
| 176 |
compstub.c -- Interface routines, main(), error reporting routine, |
| 177 |
and stubs for routines not used by the compiler. |
| 178 |
compile.c -- Core routines for compiling file. |
| 179 |
objcomp.c -- Routines to compile rooms, nouns, and creatures. |
| 180 |
command.c -- Routines to compile metacommands. |
| 181 |
symbol.c -- Routines to manipulate labels and check ranges. |
| 182 |
preproc.c -- Code for the Magx preprocessor. |
| 183 |
opdump.c -- Program to print out the list of meta-command tokens. |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
---------------- |
| 188 |
3.0 COMPILING |
| 189 |
---------------- |
| 190 |
For all of the following, you should define your platform either from |
| 191 |
the compiler or by adding a line to the top of config.h (e.g. #define |
| 192 |
LINUX). Currently LINUX, SUN, HPUX, NEXT, AMIGA, MSDOS, and PLAIN are |
| 193 |
supported, although some may require an appropriate os_<whatever>.c |
| 194 |
file to compile AGiliTY. (For example, AMIGA requires David Kinder's |
| 195 |
os_amiga.c file which is not included). For Magx, only LINUX and |
| 196 |
MSDOS have actually been tested. |
| 197 |
|
| 198 |
The following sections list the files that need to be compiled and |
| 199 |
linked to make each of the possible programs. |
| 200 |
|
| 201 |
|
| 202 |
---------------------- |
| 203 |
3.1 AGILITY PACKAGE |
| 204 |
---------------------- |
| 205 |
AGTOut (AGT file dumper) |
| 206 |
util.c, filename.c, gamedata.c, auxfile.c, agxfile.c, |
| 207 |
agilstub.c, agtread.c, disassemble.c, agtout.c |
| 208 |
|
| 209 |
AGT2AGX (AGT to AGX conversion utility) |
| 210 |
util.c, filename.c, gamedata.c, auxfile.c, agxfile.c, |
| 211 |
agilstub.c, agtread.c, agt2agx.c |
| 212 |
|
| 213 |
AGiliTy (AGT/AGX interpreter) |
| 214 |
util.c, filename.c, gamedata.c, auxfile.c, agxfile.c, |
| 215 |
agtread.c, disassemble.c, agil.c, parser.c, object.c, |
| 216 |
exec.c, runverb.c, metacommand.c, token.c, debugcmd.c, |
| 217 |
savegame.c, interface.c, os_<whatever>.c |
| 218 |
(Filling in <whatever> according to your platform.) |
| 219 |
|
| 220 |
os_curses.c uses curses.c; it has been written and tested on Linux |
| 221 |
with ncurses, but should work on other *nix platforms. Use of ncurses |
| 222 |
is recommended. Please e-mail me about any portability problems. |
| 223 |
|
| 224 |
os_termcap.c is termcap-based and in principal should work on any |
| 225 |
UNIX platform with termcap, although I recommend instead using |
| 226 |
os_curses. os_termcap.c has compiled and run successfully on both my |
| 227 |
Linux box and a Sun workstation, but usually requires minor tweaks |
| 228 |
between platforms, given the variation in terminal ioctrls between |
| 229 |
platforms. |
| 230 |
|
| 231 |
os_none.c is intended mainly as a template for use by those trying |
| 232 |
to port AGiliTy to a new platform. It should work on any platform |
| 233 |
supporting ANSI C and a command line at the expense of having a status |
| 234 |
line. (See PORTING below for details) |
| 235 |
|
| 236 |
os_dos.c was written to work with Borland C; I have no idea how it |
| 237 |
will work under other libraries or with other compilers. This should |
| 238 |
be compiled under the Huge memory model. |
| 239 |
|
| 240 |
|
| 241 |
------------------- |
| 242 |
3.2 MAGX PACKAGE |
| 243 |
------------------- |
| 244 |
OpDump (Prints list of metacommands and their argument types) |
| 245 |
util.c, filename.c, gamedata.c, agilstub.c, opdump.c |
| 246 |
|
| 247 |
Magx (AGT compiler) |
| 248 |
util.c, filename.c, gamedata.c, auxfile.c, agxfile.c, |
| 249 |
compile.c, command.c, symbol.c, preproc.c |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
------------------------------------- |
| 255 |
4.0 PORTING NOTES FOR BOTH SYSTEMS |
| 256 |
------------------------------------- |
| 257 |
The source code makes the following assumptions: |
| 258 |
--ANSI C: it uses enums, typedefs, ANSI-style prototypes, etc. |
| 259 |
--Text is encoded as ASCII. |
| 260 |
--long ints are at least 32 bits. |
| 261 |
--Negative numbers are represented in two's-complement. |
| 262 |
|
| 263 |
|
| 264 |
AGILITY |
| 265 |
In an ideal world, you should only need to change "config.h", |
| 266 |
"os_<whatever>.c", and possibly "filename.c". Then you could upgrade |
| 267 |
your port to a new version of AGiliTy by just replacing the default |
| 268 |
versions of these files with your own. (Any changes to the interface |
| 269 |
defined by these three files will be listed in the "Changes" section |
| 270 |
of this file.) |
| 271 |
|
| 272 |
In the real world, you may also need to tweak the memory allocation |
| 273 |
routines in util.c, the higher level output routines defined in |
| 274 |
interface.c, or the main() routines for any of the secondary programs. |
| 275 |
If you need to change more than this, please send me a note so I can |
| 276 |
try to fix whatever problem you ran into. |
| 277 |
|
| 278 |
|
| 279 |
MAGX |
| 280 |
It should compile and work "out of the box" on any system with a |
| 281 |
command line that obeys the above assumptions and for which config.h |
| 282 |
and filename.c have been set up correctly. |
| 283 |
|
| 284 |
All of the user interface routines (message output, argument |
| 285 |
parsing, main(), etc.) are in compstub.c, so this is the only file |
| 286 |
that should need to be edited to (e.g.) put a GUI front-end on the |
| 287 |
compiler. |
| 288 |
|
| 289 |
|
| 290 |
--------------------------------- |
| 291 |
4.1 PLATFORM SPECIFIC #DEFINES |
| 292 |
--------------------------------- |
| 293 |
To begin with, you need to determine the appropriate settings for the |
| 294 |
various platform-specific #define statements in config.h. Many of |
| 295 |
these #define's are only needed for one system or the other. |
| 296 |
The following symbols can be defined: |
| 297 |
|
| 298 |
PORTSTR: The string describing this particular port. |
| 299 |
e.g. #define PORTSTR "OrfDOS Port by R.J. Wright" |
| 300 |
|
| 301 |
NEED_STR_CMP, NEED_STRN_CMP: These should be defined if your C library |
| 302 |
doesn't have strcasecmp() and strncasecmp(), respectively. |
| 303 |
These are case insensitive string compare operations. |
| 304 |
|
| 305 |
HAVE_STRDUP: Set this if strdup() is defined by your C library. |
| 306 |
|
| 307 |
fix_ascii: Set this equal to 1 if your platform doesn't support IBM's |
| 308 |
extended ASCII character set (unless you want to write os_*.c |
| 309 |
to deal with the extended character set). [AGiliTy only] |
| 310 |
|
| 311 |
FAST_FIXSIGN: This speeds the program up but assumes 16-bit shorts and |
| 312 |
32-bit longs. |
| 313 |
|
| 314 |
MAXSTRUCT: The largest size a single data structure can be. It |
| 315 |
defaults to 1 MB. This should be at least as large as CBUF_SIZE, |
| 316 |
BUFF_SIZE, and DESCR_BUFFSIZE; it should also be at least 32K. |
| 317 |
|
| 318 |
BUFF_SIZE: Sets the maximum size of the file buffer used to read in |
| 319 |
the game files at the beginning. The buffer is allocated |
| 320 |
dynamically and will not be made larger than the size of the file |
| 321 |
regardless of the setting of this variable. It will also not be |
| 322 |
set smaller than an individual record size (which depends on the |
| 323 |
file). So you can choose to have minimal buffering by setting this |
| 324 |
to 0 or choose to buffer the whole file by making this |
| 325 |
sufficiently large (The Linux port uses 1MB, for example). |
| 326 |
The larger this is the faster files will load but the more |
| 327 |
memory will be used in the meantime. The default is 32K. |
| 328 |
|
| 329 |
CBUF_SIZE: This is the buffer size used when loading in Master's edition |
| 330 |
'.DA6' (code) files, measured in 2-byte units. (So the actual size |
| 331 |
is twice CBUF_SIZE). Nothing above 20,000 makes sense. [AGiliTy |
| 332 |
only] |
| 333 |
|
| 334 |
DESCR_BUFFSIZE: The maximum size of the description text block before |
| 335 |
the interpreter will read it from disk rather than storing it in |
| 336 |
memory during play; it defaults to 0 (i.e. always use the disk). |
| 337 |
It should not be any larger than MAXSTRUCT. At the moment this |
| 338 |
only affects AGX games; games in the 'D$$' format will always |
| 339 |
use the disk. |
| 340 |
Setting this option will speed up text output during play |
| 341 |
at the expense of a longer loading time (and more memory used). |
| 342 |
(See also the buff_maxmem variable, below). |
| 343 |
In practice, game description blocks range from around 50K to |
| 344 |
around 440K (for Shades of Gray), with most around 100K. |
| 345 |
[AGiliTy only] |
| 346 |
|
| 347 |
DOHASH: Define this to use hash tables for dictionary searches. |
| 348 |
This speeds up loading and compiling dramatically at a small |
| 349 |
increase in memory usage. |
| 350 |
|
| 351 |
UNIX_IO: If you have Unix-like low level file I/O functions. |
| 352 |
(MS-DOS, for example, does). This speeds up the reading |
| 353 |
of the large game data files on some platforms. If you set this, |
| 354 |
you will also need to set values for FILE_PERM, READFLAG, and |
| 355 |
WRITEFLAG; see the top of util.c. |
| 356 |
|
| 357 |
OPEN_AS_TEXT This causes text files to be opened as text files. |
| 358 |
Normally they are opened as binary files and end-of-line |
| 359 |
translation is done by hand, but if you have an operating |
| 360 |
system for which this doesn't work you might need to define this. |
| 361 |
If you define this, the variable open_as_binary can be set to |
| 362 |
cause text files to be opened as binary files, anyhow. |
| 363 |
(Which can be useful when trying to compile a file uploaded |
| 364 |
from another system.) |
| 365 |
|
| 366 |
REPLACE_MENU: Define this if you replace the function agt_menu() which |
| 367 |
creates menus for the player when a game is in menu mode. See 5.3. |
| 368 |
[AGiliTy only] |
| 369 |
|
| 370 |
REPLACE_MAIN: Define this if you replace main(). See 5.3. [AGiliTy only] |
| 371 |
|
| 372 |
REPLACE_GETFILE: Define this if you replace the function get_user_file(), |
| 373 |
say to allow the user to pick files from a menu. See 5.3 for |
| 374 |
details. [AGiliTy only] |
| 375 |
|
| 376 |
REPLACE_FC: Indicates you want to redefine the fc_type type. |
| 377 |
See the section 4.3 on the filename interface. |
| 378 |
|
| 379 |
pTTL, pINS, pVOC, pHNT, pCFG, pAGX [Both systems] |
| 380 |
DA1, DA2, DA3, DA4, DA5, DA6, DSS, pOPT [AGiliTy only] |
| 381 |
pAGT, pDAT, pMSG, pCMD, pSTD [Magx only] |
| 382 |
These should be defined to be the extensions to the various files |
| 383 |
that make up an AGT game. By default they will be ".da1", ".da2", |
| 384 |
".da3", ".da4", ".da5", ".da6", ".d$$", ".ttl", ".ins", ".voc", |
| 385 |
".opt", ".hnt", ".cfg", ".agx", ".agt", ".dat". "msg", ".cmd", and |
| 386 |
".std" which are the extensions under MS-DOS. |
| 387 |
(Although not all of them are used by both programs, don't delete |
| 388 |
the unused defaults as that will keep filename.c from compiling.) |
| 389 |
If you are replacing filename.c, you don't need to define these. |
| 390 |
|
| 391 |
pSAV,pSCR,pLOG: These are the default extension for save, script, and |
| 392 |
log files respectivly (by default they are ".sav", ".scr", and ".log"). |
| 393 |
These are only used if REPLACE_GETFILE is not defined. [AGiliTy only] |
| 394 |
|
| 395 |
AGTpSTD: This should be the file name of the generic error message |
| 396 |
file, which the compiler looks for if the game doesn't have its |
| 397 |
own. (By default, this will be "agt.std".) You don't need to |
| 398 |
define this if you are replacing filename.c. [Magx Only] |
| 399 |
|
| 400 |
PREFIX_EXT Put file name extensions before the base file name rather |
| 401 |
than after. You don't need to worry about this if you are |
| 402 |
replacing filename.c. |
| 403 |
|
| 404 |
PATH_SEP Define to be a string containing characters that could |
| 405 |
separate the directory path from the filename. If not defined, |
| 406 |
then AGiliTy will assume there are none and will not try |
| 407 |
to extract the path from filenames. |
| 408 |
You don't need to worry about this if you are replacing |
| 409 |
filename.c. |
| 410 |
|
| 411 |
pathtest(s) This is a macro (although you could rewrite it as a function) |
| 412 |
that should check whether the given string is an absolute |
| 413 |
path (e.g. in Unix, paths starting with a slash.) |
| 414 |
If this is left undefined, then _all_ paths will be |
| 415 |
treated as absolute. You don't need to define this if you are |
| 416 |
replacing filename.c. |
| 417 |
|
| 418 |
(There are also a handful of symbols specific to particular |
| 419 |
os_<platform>.c files; see the relevant files for details). |
| 420 |
|
| 421 |
|
| 422 |
--------------------------------------------------------- |
| 423 |
4.2 FUNCTIONS DEFINED BY THE INTERPRETER |
| 424 |
--------------------------------------------------------- |
| 425 |
These are defined in util.c; you are welcome to use them |
| 426 |
(and in unusual circumstances you might need to change them). |
| 427 |
|
| 428 |
void *rmalloc(long size) |
| 429 |
void *rrealloc(void *ptr,long size) |
| 430 |
void r_free(void *ptr) |
| 431 |
rfree(ptr) |
| 432 |
char *rstrdup(const char *s) |
| 433 |
These are interpreter's own internal memory allocation routines; |
| 434 |
these are wrappers around the usual functions that catch out-of-memory |
| 435 |
conditions (and exit the program if neccessary). Note that <size> is |
| 436 |
of type <long>, not <size_t>. |
| 437 |
<rfree()> is a macro that calls <r_free()> and then sets <ptr> to NULL. |
| 438 |
<rstrdup> creates a duplicate copy of a string s, using |
| 439 |
malloc. |
| 440 |
|
| 441 |
|
| 442 |
--------------------------- |
| 443 |
4.3 FILENAME.C: OVERVIEW |
| 444 |
--------------------------- |
| 445 |
You may not meed to change filename.c at all; the default interface |
| 446 |
is fairly flexible and should work on most systems. In particular, if |
| 447 |
your system has the following properties, then the original filename.c |
| 448 |
should be adequate (and you can skip ahead to chapter 5): |
| 449 |
|
| 450 |
i) Files are labeled by filenames. In particular, the file name |
| 451 |
(including extension) and path are enough to find the file |
| 452 |
uniquely. |
| 453 |
ii) File names can be split into a path (which says where the file |
| 454 |
is) and a filename, and the separator symbol(s) can't occur in |
| 455 |
the filename itself. |
| 456 |
iii) The file "type" of the AGT files is indicated by an extension |
| 457 |
(or prefix) to the filename. |
| 458 |
iv) The ANSI file functions are all supported. |
| 459 |
|
| 460 |
If one or more of these conditions is broken (or if you want to do |
| 461 |
something unusual, like read files straight out of ZIP archives), then |
| 462 |
you will need to either edit or replace filename.c. All code for |
| 463 |
dealing with filenames and file I/O goes through this file; by |
| 464 |
changing it, you can radically alter the way AGiliTy and Magx find and |
| 465 |
access files. |
| 466 |
|
| 467 |
If you make major changes to the filename system, you will |
| 468 |
probably also need to replace get_user_file() and |
| 469 |
set_default_filenames(); these are logically part of the filename |
| 470 |
interface, but have been put in interface.c since they shouldn't be |
| 471 |
linked into Magx or the various secondary programs. |
| 472 |
|
| 473 |
|
| 474 |
----------------------------- |
| 475 |
4.4 FILENAME.C: DATA TYPES |
| 476 |
----------------------------- |
| 477 |
There are a handful of definitions and typedefs in config.h; they |
| 478 |
are listed here with their default settings. You can change any of |
| 479 |
these (except for the filetype enum) and it won't break anything |
| 480 |
outside of filename.c, get_user_file(), and the various |
| 481 |
os_<whatever>.c files. |
| 482 |
|
| 483 |
typdef FILE* genfile; |
| 484 |
The basic file object. |
| 485 |
|
| 486 |
#define BAD_TEXTFILE NULL |
| 487 |
#define BAD_BINFILE NULL |
| 488 |
These define the value of genfile that means "this doesn't point to |
| 489 |
a file." |
| 490 |
|
| 491 |
typedef char *file_id_type |
| 492 |
Created by writeopen() for use by by binremove(). In the default |
| 493 |
filename.c, this is just the filename. It must be a pointer type. |
| 494 |
|
| 495 |
typedef file_context_rec *fc_type; |
| 496 |
This is in agility.h, but it can be redefined by #defining |
| 497 |
"REPLACE_FC" in config.h. Nothing in the core system depends on the |
| 498 |
internal structure of fc_type. (The only reason file_context_rec is in |
| 499 |
agility.h at all is so that os_<whatever>.c can use it.) This |
| 500 |
specifies a "file context", basically a glorified (and generalized) |
| 501 |
file name. |
| 502 |
The file context should contain whatever information is required |
| 503 |
to allow the various routines in filename.c to find the neccessary |
| 504 |
files. |
| 505 |
Although the default filename.c version is based around file names, |
| 506 |
this isn't required (at least if you're willing to replace filename.c, |
| 507 |
main(), and get_user_file()). |
| 508 |
|
| 509 |
|
| 510 |
typedef enum { |
| 511 |
fNONE no extension |
| 512 |
fDA1 the info(DA1) file |
| 513 |
fDA2 the room(DA2) file |
| 514 |
fDA3 the noun(DA3) file |
| 515 |
fDA4 the creature(DA4) file |
| 516 |
fDA5 the metacommand(DA5) file |
| 517 |
fDA6 the metacommand code(DA6) file |
| 518 |
fDSS the string(DSS) file |
| 519 |
fHNT the pophint file (not used yet) |
| 520 |
fOPT the options file |
| 521 |
fTTL the title file. |
| 522 |
fSAV a save file |
| 523 |
fSCR a script file |
| 524 |
fLOG a log file |
| 525 |
fAGX the AGX data file |
| 526 |
fINS the instruction file |
| 527 |
fVOC the vocabulary file (used for menuing) |
| 528 |
fCFG the game-specific configuration file |
| 529 |
fAGT,fDAT,fMSG,fCMD,fSTD AGT source files |
| 530 |
fAGT_STD The standard error message file |
| 531 |
} filetype; |
| 532 |
These are all of the various file types that the file system can |
| 533 |
be asked for. |
| 534 |
|
| 535 |
|
| 536 |
---------------------------- |
| 537 |
4.4 FILENAME.C: FUNCTIONS |
| 538 |
---------------------------- |
| 539 |
The following are all of the routines that must be defined by |
| 540 |
filename.c. Several of these are macros by default (these are all |
| 541 |
defined at the end of config.h). |
| 542 |
|
| 543 |
fc_type init_file_context(const char *name, filetype ft); |
| 544 |
This creates a file context based on the given name and |
| 545 |
on the file class 'ft'. The file class here doesn't refer to |
| 546 |
a particular file type but rather to how the context will be used; |
| 547 |
the following values of are used by AGiliTy (this is specific to |
| 548 |
init_file_context; elsewhere the filetype denotes actual types of |
| 549 |
files, not the broader classes here): |
| 550 |
fDA1: "name" is the name of a game; the context will be used to |
| 551 |
load the game data files. |
| 552 |
(AGX, DA1, DA2, ... DSS, CFG, TTL, VOC,... etc.). |
| 553 |
fNONE: As in fDA1, but gamepath hasn't been set yet, so |
| 554 |
don't integrate path information until fix_file_context() is |
| 555 |
called. |
| 556 |
fSAV: "name" will be used to access a save file. |
| 557 |
fSCR: "name" will be used to access a script file. |
| 558 |
fLOG: "name" will be used to access a log file. |
| 559 |
fAGX: "name" is name of an AGX file that is about to be written |
| 560 |
to (agt2agx and Magx only). |
| 561 |
fAGT: The context will be used to read source code. (Magx only) |
| 562 |
This is called from main() and get_user_file() so if you replace |
| 563 |
both of these (and the corresponding sections of agt2agx and |
| 564 |
agtout), then you don't need to implement this function. |
| 565 |
(Although you still need some way to create a file context to |
| 566 |
pass to run_game() and the SAVE/RESTORE/LOG/SCRIPT routines.) |
| 567 |
|
| 568 |
void fix_file_context(fc_type fc, filetype ft); |
| 569 |
Similar to creat_file_context, this is called after path information |
| 570 |
has been read in. It should adjust the file context to take advantage |
| 571 |
of that information. (On a port that doesn't support gamepath, this |
| 572 |
doesn't do anything.) |
| 573 |
|
| 574 |
fc_type convert_file_context(fc_type fc,filetype ft,const char *name) |
| 575 |
This creates a new file context based on fc and name, but possibly |
| 576 |
altered in some ways, depending on the file type. |
| 577 |
If name is NULL, then this routine should copy fc, making appropriate |
| 578 |
changes. If name is not NULL, then the routine should build a file |
| 579 |
context based on name, but possibly with information from fc. |
| 580 |
This is used for two purposes: |
| 581 |
i) To create save/script/log file contexts from a game name context. |
| 582 |
(in which case name will be NULL). |
| 583 |
E.g. converting "mygame.agx" to "mygame.sav" |
| 584 |
ii) To create contexts for new files in the same location as |
| 585 |
the context fc refers to. (For example, font files, include files, |
| 586 |
etc.-- which may not have the game name in their filename.) |
| 587 |
e.g. converting "/usr/local/spelunker/spelunk.agx" |
| 588 |
to "/usr/local/spelunker/cavepic.pcx" |
| 589 |
|
| 590 |
void release_file_context(fc_type *pfc); |
| 591 |
Free the file context pointed to by pfc. |
| 592 |
|
| 593 |
char *formal_name(fc_type fc, filetype ft); |
| 594 |
Return a user-readable string refering to the file associated with |
| 595 |
the given file context and type. This string will be used for |
| 596 |
reporting errors and other messages. The string should have been |
| 597 |
allocated with rmalloc. |
| 598 |
|
| 599 |
genfile badfile(filetype ft); |
| 600 |
Return the bad file marker for files of type ft. |
| 601 |
In the default filname.c, this always returns NULL. |
| 602 |
|
| 603 |
rbool fileexist(fc_type fc, filetype ft) |
| 604 |
Returns true if the file referred to by fc and ft exists. |
| 605 |
|
| 606 |
genfile readopen(fc_type fc, filetype ft, char **errstr); |
| 607 |
Open the file associated with the given file context and type for |
| 608 |
reading. If there is an error, *errstr should be set to point to |
| 609 |
an rmalloc'd error message; otherwise it should be set to NULL. |
| 610 |
|
| 611 |
genfile writeopen(fc_type fc, filetype ft, |
| 612 |
file_id_type *pfileid, char **errstr); |
| 613 |
Open the file associated with the given context and type for |
| 614 |
writing. Set *pfileid to whatever information is needed |
| 615 |
for binremove() to work; *set errstr as in readopen. |
| 616 |
|
| 617 |
rbool filevalid(genfile f, filetype ft); |
| 618 |
Return true if f refers to a valid file (as opposed to being NULL, |
| 619 |
say). ft contains the filetype of the given file, which can be |
| 620 |
useful if genfile is a union of several different datatypes. |
| 621 |
|
| 622 |
void readclose(genfile f); |
| 623 |
Close a file that was opened using readopen. |
| 624 |
|
| 625 |
void writeclose(genfile f, file_id_type fileid); |
| 626 |
Close a file that was opened using writeopen and (if neccessary) |
| 627 |
free any data pointed to by fileid. |
| 628 |
|
| 629 |
void binremove(genfile f, file_id_type fileid); |
| 630 |
Remove a file opened by writeopen. |
| 631 |
|
| 632 |
void binseek(genfile f, long offset); |
| 633 |
Seek to the location <offset> in the given file. |
| 634 |
|
| 635 |
rbool binread(genfile f, void *buff, long recsize, long recnum, |
| 636 |
char **errstr); |
| 637 |
Read a block of <recnum> records each of size <recsize> from the |
| 638 |
given file into the buffer <buff>. *errstr should be set as for |
| 639 |
binopen(). Return true on success, false on failure. |
| 640 |
Hitting the end-of-file counts as an error. |
| 641 |
|
| 642 |
rbool binwrite(genfile f, void *buff, long recsize, long recnum, |
| 643 |
rbool ferr); |
| 644 |
Write a block of <recnum> records each of size <recsize> from |
| 645 |
buffer <buff> into the given file. In the event of an error, |
| 646 |
abort the program if 'ferr' is true; otherwise just return 0. |
| 647 |
Return true on success, false on failure. |
| 648 |
|
| 649 |
long binsize(genfile f); |
| 650 |
Return the size of an open binary file. |
| 651 |
|
| 652 |
rbool textrewind(genfile f); |
| 653 |
Rewind the given text file to the beginning. |
| 654 |
|
| 655 |
int textgetc(genfile f); |
| 656 |
Wrapper around fgetc(f). |
| 657 |
|
| 658 |
void textungetc(genfile f, char c); |
| 659 |
Wrapper around ungetc(c,f). |
| 660 |
(Note the reversal of the order of arguments, done for internal |
| 661 |
consistency: all filename.c functions that require a file have it |
| 662 |
as their first argument.) |
| 663 |
|
| 664 |
int texteof(genfile f); |
| 665 |
Indicate if the given text file is at the end-of-file. |
| 666 |
|
| 667 |
void textgets(genfile f, char *buff, long leng); |
| 668 |
Wrapper around fgets(buff,leng,f). |
| 669 |
|
| 670 |
void textputs(genfile f, const char *s); |
| 671 |
Wrapper around fputs(buff,f). |
| 672 |
|
| 673 |
|
| 674 |
The default version of filename.c exports one additional function, |
| 675 |
which is only used by os_dos.c, os_termcap.c, and os_curses.c |
| 676 |
(although you are free to use it in your os_<whatever>.c file, too) |
| 677 |
and so doesn't need to be defined if you're writing both your own |
| 678 |
filename.c and os_<whatever>.c: |
| 679 |
|
| 680 |
char *assemble_filename(const char *path, const char *root, |
| 681 |
const char *ext); |
| 682 |
Concacate path, root, and ext and return the resulting |
| 683 |
rmalloc'd string. |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
---------------------------------------- |
| 689 |
5.0 FURTHER NOTES ON PORTING AGILITY |
| 690 |
---------------------------------------- |
| 691 |
The rest of this file discusses the details of writing a new port of |
| 692 |
AGiliTy. If you have any sort of command line, you may want to start |
| 693 |
by getting os_none.c to work (it uses only ANSI functions) and then |
| 694 |
work from there. |
| 695 |
|
| 696 |
Keep in mind that the current Linux and DOS ports have had a lot of |
| 697 |
bells and whistles added; the interface doesn't need to be as |
| 698 |
complicated as they have become. (The original os_dos.c was under 400 |
| 699 |
lines.) |
| 700 |
|
| 701 |
|
| 702 |
--------------------------------------------- |
| 703 |
5.1 OS_*.C: THE PLATFORM-SPECIFIC INTERFACE |
| 704 |
--------------------------------------------- |
| 705 |
To port AGiliTy to another platform, you also need to create the |
| 706 |
platform specific os_*.c file, which handles the platform |
| 707 |
specific tasks of the interpreter. |
| 708 |
|
| 709 |
A few notes: |
| 710 |
It is the responsibility of os_*.c to call for the updating |
| 711 |
of the status line by calling the function print_statline(void) |
| 712 |
periodically (it puts together the status line and then prints it out |
| 713 |
by calling agt_statline() ). At the very least, it should be called |
| 714 |
anytime the player is asked for input and should probably also be |
| 715 |
called before delay(). |
| 716 |
|
| 717 |
Output should be in a fixed-pitch font, ideally 80 columns |
| 718 |
wide. Some AGT games depend on both of these to format text vertically |
| 719 |
(e.g. both Shades of Gray and Cosmoserve). |
| 720 |
|
| 721 |
os_*.c must contain the definitions of the following |
| 722 |
functions (some of them can be empty functions, of course, and many of |
| 723 |
them only require a few lines of code; os_none.c is both a template |
| 724 |
and an example of a minimal os_*.c). |
| 725 |
|
| 726 |
void agt_delay(int n) |
| 727 |
Wait n seconds. (If fast_replay is true, don't wait at all.) |
| 728 |
|
| 729 |
int agt_rand(int a,int b) |
| 730 |
Return a random number from a to b, inclusive. |
| 731 |
If stable_random is set, the random number generator should have been |
| 732 |
initialized in a consistent way so the same numbers will be generated |
| 733 |
each time the program is run. |
| 734 |
|
| 735 |
void init_interface(int argc,char *argv) |
| 736 |
void start_interface(fc_type fc) |
| 737 |
These should initialize the interface. init_interface() is called at |
| 738 |
the very beginning of the program, before the game or any |
| 739 |
configuration files have been read. It is passed the the command line |
| 740 |
arguments. If you replace main() then you don't need to define |
| 741 |
init_interface() but you need to provide similar functionality from |
| 742 |
within your new main(). |
| 743 |
start_interface() is called after the game has been read in and |
| 744 |
needs to finish the initialization. You may assume only agt_newline(), |
| 745 |
agt_puts(), and agt_option() will be called before start_interface(), |
| 746 |
to print out diagnostic information. |
| 747 |
In addition they need to set screen_width, screen_height, |
| 748 |
status_width, and curr_x.(See below for what all of these are). They |
| 749 |
also needs to set script_on=center_on=par_fill_on=0, after which the |
| 750 |
interface can safely ignore the last two of the variables. It _is_ the |
| 751 |
responsibility of the os_* code to echo everything to the script file |
| 752 |
if script_on is 1. |
| 753 |
These are two functions so that start_interface() can use |
| 754 |
information from the game file (perhaps parsed by agt_option). If you |
| 755 |
aren't doing this, you can just put all of the initialization in |
| 756 |
init_interface() and leave start_interface() empty. |
| 757 |
|
| 758 |
void close_interface(void): |
| 759 |
This should do any cleanup necessary. |
| 760 |
|
| 761 |
char *agt_input(int in_type) |
| 762 |
This should read a line of input from the player and return it in a |
| 763 |
malloc'd buffer. (The routine calling agt_input is responsible for |
| 764 |
freeing this buffer). |
| 765 |
in_type specifies the type of input being asked for: |
| 766 |
0: a normal command |
| 767 |
1: a number |
| 768 |
2: the answer to a question |
| 769 |
3: a string (e.g. asking for the player's name) |
| 770 |
4: a filename |
| 771 |
5: 'RESTART, RESTORE, UNDO, or QUIT?' |
| 772 |
|
| 773 |
char agt_getkey(rbool echo_char) |
| 774 |
Get a single key-press from the keyboard. Echo it to the screen if |
| 775 |
echo_char==1. |
| 776 |
|
| 777 |
void agt_puts(const char *s) |
| 778 |
Output the string s. You may assume that s contains no newline |
| 779 |
characters and that the string itself will not wrap (at least as long |
| 780 |
as screen_width and curr_x have been correctly maintained). curr_x |
| 781 |
should be incremented by the length of s. (It *is* possible for |
| 782 |
characters to be output all the way to the rightmost column, which |
| 783 |
could cause the *cursor* to wrap) |
| 784 |
|
| 785 |
void agt_newline(void) |
| 786 |
Generate a newline, scrolling the screen up if necessary. |
| 787 |
|
| 788 |
void agt_clrscr(void) |
| 789 |
Clear the screen and position the cursor in the upper left-hand |
| 790 |
corner. |
| 791 |
|
| 792 |
void agt_statline(const char *s) |
| 793 |
Display the string s on the status line. This should be printed |
| 794 |
in a fixed-pitch font. |
| 795 |
|
| 796 |
void agt_textcolor(int c) |
| 797 |
This really handles *all* of the details of text appearance, not |
| 798 |
just color. |
| 799 |
0-6,9 are colors; see os_none.c for details. |
| 800 |
7= Normal: turn off all blinking, bold, color, etc. and restore |
| 801 |
the text to its default appearance. |
| 802 |
8= Turn on blinking. (Which can only be turned off by c=7) |
| 803 |
10= Turn on fixed-pitch font. |
| 804 |
11= Turn off fixed-pitch font. |
| 805 |
-1= Turn on emphasized text("Bold"). |
| 806 |
-2= Turn off emphasized text. |
| 807 |
None of these are toggles-- if any occur twice in a row, the second |
| 808 |
should just be ignored. |
| 809 |
If you are interested in implementing a proportional font interpreter, |
| 810 |
you should also look at the description of font_status in 5.2. |
| 811 |
|
| 812 |
|
| 813 |
void agt_tone(int hz,int ms) |
| 814 |
Create a tone at a frequency of hz hertz for ms milliseconds. |
| 815 |
This routine should check the sound_on variable; if it is 0, then the |
| 816 |
routine shouldn't do anything. |
| 817 |
|
| 818 |
|
| 819 |
void agt_makebox(int width,int height,unsigned long flags); |
| 820 |
This creates a text box of the given width and height. (These only |
| 821 |
include the text inside and do *not* include any border). The text |
| 822 |
will be output by using agt_puts() and agt_qnewline(). |
| 823 |
Flags can have the following bits set: |
| 824 |
TB_TTL, if the title is being printed (the box should be |
| 825 |
vertically centered in this case). |
| 826 |
TB_BORDER, Print a border around the box. |
| 827 |
TB_NOCENT, don't center the box horizontally; print it left justified |
| 828 |
Other bits are reserved for future use. |
| 829 |
The actual text of the box will be printed out using the regular |
| 830 |
agt_puts() function interspersed with calls to the box-specific |
| 831 |
agt_qnewline() (the 'q' stands for 'Quote'). |
| 832 |
You may assume that _exactly_ *width* characters of text will be |
| 833 |
printed out on each line (but possibly in multiple agt_puts() |
| 834 |
statements). agt_qnewline() will be called between lines, but will |
| 835 |
not be called after the last line (agt_endbox() will be called, |
| 836 |
instead). You may also assume that exactly *height* lines will be |
| 837 |
printed out. |
| 838 |
On the other hand, it is legal for agt_textcolor() to be called |
| 839 |
during the output of text in a box (which is one reason why there may be |
| 840 |
multiple agt_puts() commands per line). |
| 841 |
Text boxes should also be printed out in a fixed-pitch font. |
| 842 |
|
| 843 |
void agt_qnewline(void); |
| 844 |
This is used instead of agt_newline() when text inside a box is |
| 845 |
being printed out. See agt_makebox() for details. |
| 846 |
|
| 847 |
void agt_endbox(void); |
| 848 |
This is used at the end of a box. See agt_makebox() for details. |
| 849 |
It should leave the cursor in the left-most column on the line below |
| 850 |
the box. |
| 851 |
|
| 852 |
genfile agt_globalfile(int fid); /* When fid=0, return global config file */ |
| 853 |
When fid=0, this should return an open file descripter to the global |
| 854 |
configuration file for the interpreter. |
| 855 |
For example, in MS-DOS, this will be the file AGIL.CFG in the same |
| 856 |
directory as the interpreter; in Linux it is the file '$HOME/.agilrc'. |
| 857 |
For other values of fid, return NULL. |
| 858 |
|
| 859 |
rbool agt_option(int optnum,char *optstr[],rbool setflag); |
| 860 |
As the interpreter parses the configuration files, it will pass any |
| 861 |
options it doesn't understand to this function; this can be used to |
| 862 |
support platform-specific configuration options. |
| 863 |
The line will have been parsed into whitespace-separated words. |
| 864 |
*optnum*=number of words, *optstr[]* is the array contain pointers to all |
| 865 |
of them. optstr[0] will be the first word on the line (and hence the |
| 866 |
option name). |
| 867 |
*setflag* will be 1 unless the option name was prefixed by 'NO_' |
| 868 |
(inverting its meaning) in which case it will be 0 (and the 'NO_' |
| 869 |
prefix will have been stripped off). |
| 870 |
Return 1 if agt_option() recognized the option, 0 otherwise |
| 871 |
(which will cause a warning to be printed). |
| 872 |
|
| 873 |
|
| 874 |
--------------------------------------------------------- |
| 875 |
5.2 VARIABLES AND FUNCTIONS DEFINED BY THE INTERPRETER |
| 876 |
--------------------------------------------------------- |
| 877 |
|
| 878 |
The following variables are defined elsewhere, but need to be set and |
| 879 |
updated by the routines in os_*.c as they are used for |
| 880 |
line-break information and to format the status line: |
| 881 |
|
| 882 |
int screen_width: the width of the screen |
| 883 |
|
| 884 |
int status_width: the width of the status line (on most systems this |
| 885 |
will be the same as screen_width). |
| 886 |
|
| 887 |
int curr_x: The current x position (starting at 0). |
| 888 |
|
| 889 |
int screen_height: The height of the screen. |
| 890 |
Currently the only routine that uses this is the title printing |
| 891 |
routine. |
| 892 |
|
| 893 |
rbool script_on: This should be set to zero by init_interface() and |
| 894 |
does not need to be changed by the interface code after that. |
| 895 |
If it is 1 then all input and output should be echoed to the file |
| 896 |
associated with scriptfile. |
| 897 |
|
| 898 |
genfile scriptfile: The file script output should go to. This is set |
| 899 |
by interface.c. |
| 900 |
|
| 901 |
|
| 902 |
rbool sound_on: This is set to 1 initially; if it is 0, then agt_tone() |
| 903 |
shouldn't do anything. os_* may change this. |
| 904 |
|
| 905 |
char **gamepath: This is a pointer to a NULL-terminated array of |
| 906 |
pointers to strings, each of with gives a possible path for the game |
| 907 |
files. This is set to NULL initially, but you can set this to |
| 908 |
a list of game file search paths if you want. It needs to be set |
| 909 |
by init_interface() or agt_option() to have any effect. |
| 910 |
If this is not NULL, the directories is lists will be searched |
| 911 |
in order, *before* the current directory is checked. If you want |
| 912 |
the current directory to be searched first, make sure that |
| 913 |
gamepath[0] is the empty string "". |
| 914 |
|
| 915 |
rbool DEBUG_AGT_CMD: By default, this is set by main() according |
| 916 |
to command line options but you can change it if you want. |
| 917 |
It can also be set by the player using the AGILDEBUG command. |
| 918 |
This determines whether metacommand debugging information is |
| 919 |
printed out. |
| 920 |
|
| 921 |
rbool DEBUG_OUT: This should be set by init_interface(). If it is 0, |
| 922 |
metacommand debugging output will go to the screen (using |
| 923 |
agt_puts() and agt_newline()). If it is 1, debugging output will |
| 924 |
be sent to debugfile and the interface code should also echo |
| 925 |
everything to debugfile. Whether there is any debugging output |
| 926 |
in the first place is determined by DEBUG_AGT_CMD. |
| 927 |
|
| 928 |
FILE *debugfile: This is the file where metacommand debugging output |
| 929 |
will be sent if DEBUG_OUT is true. It should be set by init_interface(). |
| 930 |
|
| 931 |
(The Linux port, e.g., always sets debugfile to stderr and checks to |
| 932 |
see if stderr and stdout refer to the same underlying file; if they |
| 933 |
do it sets DEBUG_OUT to 0; if they are different, then it sets |
| 934 |
DEBUG_OUT to 1. Thus if stderr is redirected by the user, then |
| 935 |
a complete debugging log file will be written without cluttering |
| 936 |
the screen. If it is not redirected then debugging output will be |
| 937 |
sent to the screen through agt_puts().) |
| 938 |
|
| 939 |
|
| 940 |
stable_random: When this is set, the random number generator should |
| 941 |
behave consistantly so as to give the same set of values each time the |
| 942 |
interpreter is run. |
| 943 |
|
| 944 |
BATCH_MODE: We are running the game with a fixed script and so |
| 945 |
output can be supressed. |
| 946 |
|
| 947 |
menu_mode: If true, menu input will be used instead of the usual |
| 948 |
command line. This variable is managed automatically by the |
| 949 |
interpreter, but you can change it if you want. |
| 950 |
|
| 951 |
|
| 952 |
compass_rose: This is an unsigned short with a bit set for each |
| 953 |
direction the player can go; a fancy port of the interpreter could |
| 954 |
use this to print something out below the status line (or even draw |
| 955 |
an honest compass rose). There are 12 bits used; starting with the least |
| 956 |
significant bit they represent N, S, E, W, NE, NW, SE, SW, U, D, IN, |
| 957 |
and OUT. |
| 958 |
|
| 959 |
descr_maxmem: This is set to DESCR_BUFFSIZE at the beginning of the |
| 960 |
program, but you could change it based on the amount of memory |
| 961 |
available at runtime. It must be set before the game file is |
| 962 |
read in from memory (after init_interface() but before |
| 963 |
start_interface()). |
| 964 |
It sets the upper limit on the size of the description block |
| 965 |
before the interpreter will just leave it on disk rather than trying |
| 966 |
to load it into memory at once. |
| 967 |
|
| 968 |
font_status: This is set by the interpreter; it tells whether a |
| 969 |
proportional font can be use, or whether the interface must |
| 970 |
use a fixed pitch font. There are three possible values: |
| 971 |
0 -- The interpreter doesn't know whether proportional fonts |
| 972 |
are allowed or not; it's up to the interface (or the user) |
| 973 |
to make this decision. This is the setting for original AGT |
| 974 |
games and early Magx games. |
| 975 |
1 -- Fixed font needs to be on by default. |
| 976 |
2 -- Fixed font doesn't need to be on by default. |
| 977 |
See also agt_textcolor(). |
| 978 |
|
| 979 |
rbool fast_replay Set by the interpreter, this is true if the |
| 980 |
user is doing a fast replay from a log file. In this case, |
| 981 |
delays should be supressed and text scrolling should not be |
| 982 |
stopped each screen to wait for the user. |
| 983 |
|
| 984 |
The following functions are defined by the interpreter but can be |
| 985 |
used by os_*.c |
| 986 |
|
| 987 |
|
| 988 |
void agt_save(void) |
| 989 |
void agt_restore(void) |
| 990 |
void agt_quit(void) |
| 991 |
These save, restore, and quit the game, respectivly. They can be called |
| 992 |
asyncronously (although the quit or restore won't actually occur until |
| 993 |
the end of the current turn). These are intended mainly for use in |
| 994 |
event-driven GUIs. |
| 995 |
(These haven't been tested extensively) |
| 996 |
|
| 997 |
|
| 998 |
void agt_newgame(fc_type fc) |
| 999 |
This loads a new game, replacing the current one; like the function |
| 1000 |
above, it doesn't take effect until the end of the current turn. |
| 1001 |
During the start of a new game, start_interface() (but not |
| 1002 |
init_interface) will be called again. This is intended mainly for use |
| 1003 |
in event-driven GUIs. |
| 1004 |
(This hasn't been tested at all) |
| 1005 |
|
| 1006 |
|
| 1007 |
------------------------------------------------------- |
| 1008 |
5.3 OTHER FUNCTIONS THAT CAN OPTIONALLY BE SPECIFIED |
| 1009 |
------------------------------------------------------- |
| 1010 |
The following functions may also, optionally, be defined in |
| 1011 |
os_*.c, but you must insert appropriate #define statements |
| 1012 |
into config.h to prevent the default versions from being created |
| 1013 |
(see above). The default versions of all of these functions are in |
| 1014 |
interface.c. |
| 1015 |
|
| 1016 |
genfile get_user_file(int ft) /* 0=script, 1=save, 2=restore, |
| 1017 |
3=log(read) 4=log(write) */ |
| 1018 |
This gets a file name from the user, opens it, and returns the |
| 1019 |
appropriate data structure. If you redefine this then define |
| 1020 |
REPLACE_GET_FILE in config.h. You might want to redefine |
| 1021 |
this to allow the user to pick files from a menu, for example. |
| 1022 |
ft tells what sort of file the user is being asked for: 0=script, |
| 1023 |
1=save, 2=restore, 3=log file(read), 4=log file(write). |
| 1024 |
This is logically part of the filename system; see 4.5. |
| 1025 |
|
| 1026 |
void set_default_filenames(fc_type fc) |
| 1027 |
This is part of get_user_file and will also be left undefined |
| 1028 |
if REPLACE_GET_FILE is defined in config.h. |
| 1029 |
|
| 1030 |
int agt_menu(char *header,int size,int width,menuentry *menu); |
| 1031 |
This prints out a menu and gets a choice from the user. This is used |
| 1032 |
by a few games to get menu-driven input. You should define |
| 1033 |
REPLACE_MENU if you want to redefine this. |
| 1034 |
*header* is the header for the menu; e.g. 'PUT TUBA IN ?' |
| 1035 |
*size* is the number of entries in the menu |
| 1036 |
*width* is the width (in characters) of the widest one. |
| 1037 |
*menu[]* is the array of menu entries; menu entires are strings of |
| 1038 |
length MENU_WIDTH (currently 50). |
| 1039 |
(In interp.h: typedef char menuentry[MENU_WIDTH]; ) |
| 1040 |
Return the index corresponding to the menu entry chosen or -1 if |
| 1041 |
something strange happened (e.g. the player turned off menuing by |
| 1042 |
using special keys) |
| 1043 |
|
| 1044 |
|
| 1045 |
main() |
| 1046 |
By putting #define REPLACE_MAIN in config.h, you will prevent |
| 1047 |
main() from being defined in interface.c so that os_*.c can |
| 1048 |
define its own main function (on some platforms, this may be called |
| 1049 |
something other than 'main()'). |
| 1050 |
The main function needs to do the following: |
| 1051 |
--Call set_default_options() to make sure that all of the options are |
| 1052 |
initialized to the correct defaults. |
| 1053 |
--Set the various options, either from the command line or by other means |
| 1054 |
--Get the file name of the agt game being played (from the command line or |
| 1055 |
by other means). |
| 1056 |
--Do basic initialization of the interface (enough so that writestr() |
| 1057 |
and writeln() will work for diagnostic messages) |
| 1058 |
See the comments on init_interface() above. |
| 1059 |
--Call run_game( fc_type fc ), where fc is the file context of the |
| 1060 |
game file(s). If you're using the default filename.c, you can |
| 1061 |
get this context by calling init_file_context(gamename,fNONE). |
| 1062 |
--Terminate |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
------------------------------------------ |
| 1068 |
5.4 GRAPHICS, FONT, AND SOUND FUNCTIONS |
| 1069 |
------------------------------------------ |
| 1070 |
Master's Edition games included support for graphics and sound, |
| 1071 |
although only a very few games were made that made any use of these |
| 1072 |
features. The DOS and Linux ports support fonts and graphics; I don't |
| 1073 |
know of any ports that support sound, but the core interpreter |
| 1074 |
implements the necessary hooks. |
| 1075 |
|
| 1076 |
If you actually want to implement these, you'll want to track down |
| 1077 |
the documentation for the Master's Edition which discusses the file |
| 1078 |
naming conventions and file formats used for these. (You will also |
| 1079 |
want to get your hands on the game HURRY! HURRY! which demonstrates |
| 1080 |
all of these.) |
| 1081 |
|
| 1082 |
Stub versions of these functions are currently defined at the |
| 1083 |
beginning of interface.c; you'll need to comment out those functions |
| 1084 |
that you are replacing. |
| 1085 |
|
| 1086 |
|
| 1087 |
void fontcmd(int cmd,int font) |
| 1088 |
0=Load font, the name is fontlist[font] |
| 1089 |
1=Restore original (startup) font |
| 1090 |
2=Set game's initial font (<gamename>.FNT) |
| 1091 |
This sets the font used for all output text. Under DOS, the fonts |
| 1092 |
are stored in a file name <name>.FNT. The data seems to be stored |
| 1093 |
simply as a collection of binary bitmaps, 8x8 pixels, with eight bytes |
| 1094 |
for each of the 256 characters in the font set (giving one byte per |
| 1095 |
row). There doesn't seem to be any sort of header or other |
| 1096 |
information. |
| 1097 |
|
| 1098 |
|
| 1099 |
void pictcmd(int cmd,int pict) |
| 1100 |
1=Show global picture, name is pictlist[pict] |
| 1101 |
2=Show room picture, name is pixlist[pict] |
| 1102 |
3=Show title picture (usually <gamename>.pcx) |
| 1103 |
Display the picture requested on the screen until the user presses |
| 1104 |
a key. Pictures are stored in the PCX file format, but with nonstandard |
| 1105 |
filename extensions which indicate the PC video mode the image was |
| 1106 |
supposed to be viewed in. |
| 1107 |
Animations are stored in the FLI format. |
| 1108 |
|
| 1109 |
|
| 1110 |
int musiccmd(int cmd,int song) |
| 1111 |
1=play song, name is in songlist[song] |
| 1112 |
2=play song repeatedly, name is in songlist[song] |
| 1113 |
3=end repeat |
| 1114 |
4=end song |
| 1115 |
5=suspend song |
| 1116 |
6=resume song |
| 1117 |
7=clean-up sound system (called just before interpreter exits) |
| 1118 |
8=turn sound on |
| 1119 |
9=turn sound off |
| 1120 |
-1=Is a song playing? (0=false, 1=true) |
| 1121 |
-2=Is the sound on? (0=false, 1=true) |
| 1122 |
Songs are stored in the MUC file format: |
| 1123 |
The file format includes no header, but is a collection of |
| 1124 |
six-byte records. Each record consists of three unsigned 16-bit |
| 1125 |
numbers (stored little-endian like all numbers under AGT: the least |
| 1126 |
significant byte comes first): the frequency (in Hertz); the length of |
| 1127 |
time of the tone (in milliseconds); and a delay between tones (also in |
| 1128 |
milliseconds). |
| 1129 |
At least in theory, songs may also be stored in the VOC, MID, or CMF |
| 1130 |
formats. |
| 1131 |
|
| 1132 |
|
| 1133 |
|