* This is from the manual of AGDS (Adventure Game Development Toolkit) which contains a good deal of information about the AGI interpreter and its data formats. Translated from Russian by Vassili Bykov, email@example.com
One of the most complex resources. It contains interpreter commands and messages. In essence, it is the LOGIC resource that determines the plot of the game. It describes all possible interactions between the objects and the use of the resources, according to the game script.
Let us consider the interpreter commands in detail.
Commands that operate on variables:
[The allowed range of variable values is not specified anywhere explicitly, however implicitly it seems to be 8 bit (0..255). --VB]
The value of the variable Var(n) is incremented by one, i.e. Var(n) = Var(n)+1. If the value is already 255, it is left unchanged.
The value of the variable Var(n) is decremented by one, i.e. Var(n) = Var(n)-1. If the value is 0, it is left unchanged.
Variable Var(n) is assigned the value m, i.e. Var(n) = m
Variable Var(n) is assigned the value of Var(m), i.e. Var(n) = Var(m).
The value of variable Var(n) is incremented by m, i.e. Var(n) = Var(n) + m.
The value of variable Var(n) is incremented by the value of Var(m), i.e. Var(n) = Var(n) + m.
[Now what happens in the above two commands on 8-bit overflow: does the result wrap over 0 or stays 255? I.e. is 250 + 10 == 4 or 250 + 10 == 255? --VB]
The value of Var(n) is decremented by M, i.e. Var(n) = Var(n) - m
The value of Var(n) is decremented by Var(m), i.e. Var(n) = Var(n) - Var(m).
[Again, what happens when the result must be negative: is 1 - 2 == 255 or 1 - 2 == 0? --VB]
Variable Var(i) where i is the value of Var(n) is assigned a value m, i.e. Var(Var(n)) = m.
Variable Var(i) where i is the value of Var(n) is assigned the value of Var(m), i.e. Var(Var(n)) = Var(m).
Variable Var(n) is assigned the value of Var(i) where i is the value of Var(m), i.e. Var(n) = Var(Var(m)).
Variable Var(n) is multiplied by m, i.e. Var(n) = Var(n) * m.
Variable Var(n) is multiplied by the value of Var(m), i.e. Var(n) = Var(n) * Var(m).
[What happens on overflow? --VB]
Variable Var(n) is divided by m, i.e. Var(n) = Var(n) / m.
Variable Var(n) is divided by the value of Var(m), i.e. Var(n) = Var(n) / Var(m).
[What happens on division by 0? --VB]
random(n, m, k)
Variable Var(k) is assigned a random value in the range between n and m.
Now let us consider the commands changing flag values. Remember that a flag can only have a value 0 or 1.
flag(n) is set to 1.
flag(i), where i is the value of var (n), is set to 1. i.e. flag(var(n)) = 1.
flag(n) is set to 0.
flag(i), where i is the value of var (n), is set to 0, i.e. flag(var(n)) = 0.
flag(n) toggles its value.
flag(i), where i is the value of var (n), i.e. flag(var(n)), toggles is value.
Commands in this chapter load (into the interpreter's memory) and unload (discard, thus freeing interpreter's memory) LOGIC, PICTURE, VIEW, and SOUND resources. Always remember that the internal memory of the interpreter is 64K. This restriction is rarely a problem, but do not forget about it.
When the internal memory is full, the program has to be broken into parts which are loaded and unloaded as the story unfolds in the given room, or PICTURE, VIEW, and SOUND resources have to be manipulated using the commands below.
Remember that when a resource is unloaded, all resources loaded after it ARE ALSO AUTOMATICALLY UNLOADED!
Load into memory the LOGIC resource number n, i.e. Logic(n)
Load into memory the LOGIC resource number i, where i is the value of Var(n), i.e. Logic(Var(n))
Loads into memory the PICTURE resource number i, where i is the value of Var(n), i.e. Picture(Var(n))
[This may be a mistake in the original: I would expect this command to be `load_pic_v', while `load_pic n' would load resource number n. --VB]
[load_pic_v may be a more appropriate name for it, but the name above is what they gave it. There is no equivalent command that takes a number rather than a variable. --LE]
Loads into memory the VIEW resource number n, i.e. View(n).
Loads into memory the VIEW resource number i, where i is the value of Var(n), i.e. View(Var(n))
Loads into memory the SOUND resource number n, i.e. Sound(n).
[Note that there is no load_sound_v listed. I wonder if this is a mistake or there really is no way to load a sound with indirection (unlikely, I think) --VB]
[There really is no way of loading a sound with indirection. The command doesn't exist. --LE]
Unloads PICTURE resource number i where i is the value of Var(n).
Unload VIEW resource number n, i.e. View(n)
Unloads VIEW resource number i where i the value of Var(n), i.e. View(Var(n)).
[And what about discard_logic, discard_logic_v, discard_sound, and discard_sound_v? --VB]
[There must be some other way that those commands are removed from memory, because the commands you mention above don't exist. --LE]
new.room command is one of the most powerful commands of the interpreter.
It is used to change algorithms of the object behaviour, props, etc. Automatic change of EGO coordinates imitates moving into a room adjacent to the edge of the initial one. [Sounds awkward but that's what it says. --VB]
The format of the command:
These commands do the following:
Subroutine call commands:
LOGIC resource number n (or number i where i the value of Var(n)) is executed as a subroutine. If the logic with the given ID is not loaded in memory, it is temporarily loaded and discarded after returning from the call (this takes extra time). call command does not change any variables or flags.
This command returns control to the interpreter if it is executed in Logic(0), or to the command following the call command which called the current logic.
This command unconditionally transfers control to a command starting with a symbol combination <label> within the same logic.
Normally, when a logic is called using call command, execution begins at the first instruction. set_scan_start command sets the entry point at the command following it, while reset_scan_start returns entry point to the beginning.
Interpreter controls movement of objects around the screen automatically checking the following conditions:
- If an object priority is 0 it cannot cross an unconditional barrier (pixels with priority 0).
- If an object priority is 15 and a command ignore_block has not been given to it, it cannot cross a conditional barrier (pixels with priority 1) and leave the block set using the `block' command.
- If an object has not been given `ignore.horizon' command, it cannot move above the horizon set using the set_horizon command.
- An object should follow the conditions set using object.on.water and object.on.land commands (see below).
Object number 0 is called EGO. It is different from others in that the player may move it around using the keyboard.
Object number n is included in the list of object controlled by the interpreter.
OBJECTS NOT INCLUDED IN THAT LIST ARE CONSIDERED INEXISTENT!
All objects are removed from the control list and are considered inexistent.
Object n is associated with a VIEW resource number m (or pointed to by Var(m)), which may be an image of the object.
Chooses a loop m (or Var(m)) in the VIEW resource associated with the object n.
Turns off automatic choice of loop number for the object number n.
Turns on automatic choice of loop number depending on the direction of motion of the object n.
1 8 | 2 \ | / \ | / 7 ------------- 3 0 - object stands still / | \ / | \ 6 | 4 5
Automatic choice of the loop is done according to the table:
- for objects with fewer than 4 but more than 1 loops:
* - means the current loop number is retained
- for objects with more than 4 loops:
Selects a cel m in the current loop of the object m.
The number of the last cel of the current loop of the object n is stored in Var(m).
The number of the current cel of the object n is stored in Var(m).
The number of the current loop of the object n is stored in Var(m).
The number of the current VIEW resource associated with the object n is stored in Var(m).
Set priority of the view of the object n to m (or Var(m)).
Turns on the automatic priority choice for the object n. The priority is set depending on the vertical coordinate of the object.
This way, as an object moves down it approaches the viewer.
The value of the current priority of the object n is stored in Var(m).
position(n, x, y)
position.v(n, x, y)
Coordinates of the object n, not yet displayed on the screen, are set to x and y (or Var(x) and Var(y)).
Object n is shown on the screen. The image uses the values of the loop and the cel in the VIEW resource associated with the object n (see set_view), as well as the priority and coordinates of the object. If a command start_cycling is also issued, an infinite "movie" for the object n is shown until stopped (for example, with stop_cycling).
Object n is erased from the screen.
get.posn(n, x, y)
Coordinates of the object n are stored in Var(x) and Var(y). Coordinates of the object are coordinates of the base point (bottom left corner) of cels of the VIEW resource associated
Interpreter automatically shows a "movie" (a loop in the VIEW resource) associated with the object, starting at the specified cel. The following commands control this process.
Enables automatic change of cels in a chosen (using set_loop) loop of a VIEW resource associated with the object n (using set_view).
Disables automatic change of cels in a chosen (using set_loop_ loop of a VIEW resource associated with the object n (using set_view).
Cels of the loop associated with the object n follow in a normal order:
0, 1, 2, .., k-1, 0, 1, 2..
Cels of the loop associated with the object n follow in a reverse order:
k-1, k-2, ..., 1, 0, k-1, k-2, ..1, 0, ..
Plays the loop associated with the object n once, from the current cel to the last. When finished, Flag(m) is set to 1.
Plays the loop associated with the object n once in a reverse order, from the current cel to the first. When finished, Flag(m) is set to 1.
Var(m) sets the time in interpreter cycles between cel changes for the object n. When Var(m) = 1 cels are changed every cycle.
The following commands can be given to the object included in the interpreter control list with animate_obj:
Set the horizon to y = n.
Object n moves regardless of the horizon position.
Object n cannot move above the horizon.
block(x1, y1, x2, y2)
Sets a rectangular area (block).
(x1, y1) ------------------ | | | | | | ------------------ (x2, y2)
Cancels previously set block.
Object n moves ignoring conditional barriers (pixels with priority 1) and a block set with a block command.
Object n may not cross conditional barriers or leave the block.
Object n moves regardless of positions of other objects.
Object n treats other objects as obstacles.
The player is allowed to control EGO (object number 0) using the keyboard or the joystick.
The player is not allowed to control object 0 (EGO).
Motion of object n is stopped. If n = 0, program_control is automatically executed.
Motion of object n is started. If n = 0 (EGO), player_control automatically executed.
Var(n) determines the number of pixels the object n moves each step.
Var(n) determines the speed of object n motion: delay in the interpreter cycles between consecutive steps. If Var(m) = 1, step occurs on every cycle.
move.obj(n, x, y, s, m)
move.obj.v(n, x, y, s, m
Object n is told to move to the point x,y (or Var(x), Var(y)) by s pixels every step. When the destination is reached, Flag(m) is set to 1. If n = 0 (EGO), program_control is executed automatically.
follow.ego(n, s, m)
Object n is told to chase object 0 (EGO) by s pixels every step. When EGO's and the object's coordinates become equal, Flag(m) is set to 1.
Object n randomly changes the direction of its motion (wanders). If n = 0 (EGO), program_control is issued automatically.
Special object motion mode is canceled. The object continues to move in the direction it was moving in at the time the command was issued.
Object n is told to move in the direction Var(m)
1 8 | 2 \ | / \ | / 7 ------------- 3 0 - stop / | \ / | \ 6 | 4 5
Direction of object n motion is stored in Var(m).
Object n is allowed to be only in the area where its base line is completely on pixels with priority 3 (water surface).
Object n is not allowed to touch pixels of water surface (priority 3).
Motion restrictions previously set on the object n with commands object_on_water or object_on_land are cancelled.
reposition(n, dx, dy)
Object n jumps from its current location into the location with coordinates x + Var(dx), y + Var(dy).
[Shouldn't there be reposition and reposition.v? --VB]
[There should be, but they don't exist. --LE]
reposition.to(n, x, y)
reposition.to.v(n, x, y)
Similar to the preceding command, but the object is moved to the point x, y (Var(x),Var(y)).
Object n is removed from the list of objects updated by the interpreter on each step. The object stays on the screen unchanged.
Object n is redrawn on each interpreter step.
Object n is redrawn immediately, without waiting for the end of the interpreter cycle.
distance(n, m, d)
If both objects n and m are on the screen, then
Var(d) = ABS(x(n) - x(m)) + ABS(y(n) - y(m)),
otherwise Var(d) = 255.
OBJECT resources, stored in a separate file OBJECT, are most often used to represent inventory items. An item is a structure which consists of a one-byte field called room and a string of text, the item name.
If the room field of an item is 255, the item belongs to the player. Otherwise the item is considered to be in the room with the corresponding ID number.
Let us consider item management commands.
Stores 255 in room field of an object n, which means the player owns it.
Stores 0 in the room field of object n.
Stores the value m (or Var(m)) in the room field of the object n.
Stores the value of the room field of object Var(n) in Var(m).
The screen is switched to text mode; the top line displays "You are carrying:", then the names of the object with room field equal to 255 are listed. If there are no such objects, the word "nothing" is displayed.
If Flag(13) = 1 (allow item selection), a highlight appears which allows the player to select an item name. When Enter is pressed, the selected object number is stored in Var(25). When Esc is pressed, 255 is stored in Var(25).
The following commands operate on PICTURE resources (3D props), prepared using PM editor and loaded in the interpreter memory using load_pic:
A PICTURE resource number i, where i is the value of Var(n) is executed. As the result, the background picture is created in the internal buffer of the interpreter. Before execution, the buffer is cleared, i.e. all pixels are set to colour 15 and priority 4.
Just like the above, only the internal buffer is not cleared before drawing. Picture(Var(n)) is drawn over the existing picture.
add.to.pic(a, b, c, d, e, f, g)
add.to.pic.v(a, b, c, d, e, f, g)
A picture of a VIEW resource is added to the background as its component. Typically, this is used to add small complicated details which would require too many PICTURE resource commands to draw.
a ( Var(a) ) - number of the VIEW resource;
b ( Var(b) ) - loop number;
c ( Var(c) ) - cel number;
d ( Var(d) ) - x coordinate;
e ( Var(e) ) - y coordinate;
f ( Var(f) ) - priority;
g ( Var(g) ) - margin.
If margin is 0, 1, 2, or 3, the base of the cel is surrounded with a rectangle of the corresponding priority. If margin > 4, this extra margin is not shown.
Shows internal buffer on the screen.
Please use the following sequence of commands when loading PICTURE resources
in the interpreter memory:
Any other order may crash the interpreter without any diagnostic messages.
Starts playback of the SOUND resource number n. When finished, Flag(m) is set to 1.
Stops the playback.
Prevents the user from entering anything using the keyboard.
Allows the user to enter text using the keyboard.
Opens a text window in the centre of the screen, where a message number n (or Var(n)) from the messages field of the current LOGIC resource is displayed. Output mode is determined by Flag(15) (see flag description)
The message is a NULL-terminated string of text. In addition to letters, digits, and other symbols, the string may contain:
- Newline character (0Ah);
- Format element:
For v format, you can add a vertical line and a number of characters the output should take. In this case leading zeros are not suppressed in the output.
Example: %v34 | 2
When you write your messages, remember that the interpreter wraps
the text between the lines as needed when the message is displayed.
display(R<ow>, C<olumn>, N<umber>)
display.v(R<ow>, C<olumn>, N<umber>)
Prints a message number N (Var(N)) in the row R (Var(R)), starting with the column C (Var(C)). No window is created, so it is up to the programmer to erase the output when it is no longer needed.
print.at(n, x, y, l)
print.at.v(n, x, y, l)
Analogous to print but the programmer can specify the window location. x, y, and l are constants specifying coordinates of the top left corner of the window and its width in character cells of a 40x25 screen.
Prints interpreter version in the centre of the screen.
The screen switches to the text mode 40x25.
The screen returns to the graphics mode. The picture on the screen is restored.
First byte of the message n is user as a text mode cursor.
Sets foreground and background colours for display, get_num, and get_string commands.
clear.lines(n, m, C<olor>)
Clears text lines from n to m using colour C.
clear.text.rect(x1, y1, x2, y2, C<olor>)
Clears a rectangular area with top left corner coordinates (x1,y1) and bottom right coordinates (x2,y2) using colour C.
Shows the status line containing the current score and sound status (on/off).
Removes the status line.
Stores message number m in the string variable n.
Word number m of the user input is stored in String(n).
get.string(n, m, x, y, l)
User input is stored in String(n). m is the number of the message used as the prompt, x, y, l are input position and maximum string length.
Parses String(n) as if it were entered by the player.
Enters a number from the keyboard into Var(m). Message n is used as the prompt.
Set interpreter's special key.
c - code (decimal number from 0 to 255);
s - if the key is a regular, or Ctrl+key pair,
the ASCII code (for example, 0009h - TAB);
- if the key is functional or Alt+key pair,
the corresponding scan-code in the high byte of s.
For example, the scan code of F1 is 3b00h, Alt+Z - 2c00h, etc.
Message n is scanned by the interpreter and compared with its internal identifier. On mismatch, the program exits. For AGDS interpreter the identifier is 'TQ'.
Sets the size of script table in bytes. Script table stores codes of some interpreter commands. It is needed to the interpreter can correctly reload resources when restore_game is executed.
trace.info(n, m, l)
Sets the built-in debugger parameters
n - number of LOGIC resource with command names.
m, l - first line and height of the debugger window.
Turns on the debugger. In general, the debugger is turned on with Scroll Lock key when the command name table is loaded even if this command does not occur in the program.
This is a debugging command. It writes a log message in a file:
Room <current room> Input line <current input line>
followed by the message number n.
Creating your program, you can offer the player a choice using a system of menus. These may be short one-line questions (menu header) with several answers (menu elements), or a prompt to change some of the system parameters, for example, object movement speed. Let us consider these commands.
Message n is used as the header of the menu elements which follow.
Message n is used as a menu element, where c is this element's code (a number between 0 and 255).
Ends menu creation.
Enables or disables a menu item with the code c.
|-------- heading v ------------------------------- | Fill | ------------------------------- Menu --->| Save | Element |------------| | Restore | |------------| |XXXXXXXXXXXX|<---- menu element disabled |------------| using disable.item | Quit | --------------
If Flag(14) = 1, a menu system is shown on the screen, allowing the user to choose an item. Whether an item with the code c has been chosen can be tested using a command 'controller c', where c is the code assigned to the menu item.
Apparently, to build a program you need commands that change the execution order of instructions. To check for various conditions, test commands are used.
The result of test command can be either TRUE or FALSE.
True if Var(n) = m.
true if Var(n) = Var(m).
True if Var(n) < m.
True if Var(n) < Var(m).
True if Var(n) > m.
True if Var(n) > Var(m).
True if Flag(n) = 1 (set).
True if Flag(Var(n)) = 1 (set).
True if the room field of item n is 255, i.e. the item belongs to the player.
True if room field of the object n is Var(m).
posn(n, x1, y1, x2, y2)
True if the coordinates of the base point of the cel which is the current image of object n satisfies the equation
x1 <= x <= x2, y1 <= y <= y2.
obj.in.box(n, x1, y1, x2, y2)
True if the base of the object n is completely within the rectangle specified using its top left (x1,y1) and bottom right (x2,y2) corners.
(x1, y1) ------------------ | | | | | | ------------------ (x2, y2)
center.position(n, x1, y1, x2, y2)
True of the center of the base line of the object n is inside the rectangle specified as its top left and bottom right corners.
right.position(n, x1, y1, x2, y2)
True of the right side of the base line of the object n is inside the rectangle specified as its top left and bottom right corners.
True if the user has pressed any key on the keyboard. Used to create cycles to wait until any key is pressed.
True if string(s1) = string(s2).
said(n, W(i)) , where i = 1, ..., n
True if the player has entered a phrase that completely matches W(1),...W(n), where n is the number of W(i) which are codes of the vocabulary words.
Here is how the input is matched. After the player types a message and presses Enter, the input line is processed by the interpreter.
If the search is unsuccessful, Var(9) is assigned the number of
the word in the message that failed to match and the processing
ends. If all the words have been assigned some codes:
If the sequence of code produced by the interpreter is
The test is performed as follows:
If Flag(2) = 0 or Flag(4) = 1, return FALSE.
Compare parameters W(i) and codes V(i) as follows:
Otherwise W(i) should be equal to V(i).
If all elements match, Flag(4) (`said' accepted the user input) is set to
1 and the command returns TRUE. Otherwise, FALSE is returned.
True if the event with code n has occurred:
The interpreter allows to work with logical expressions using a logical command. Its general format is the following:
if_ logical expression ; is the result true? else_ LABEL ; no: go to LABEL ; yes: execute commands ................ ; between else_ ; and LABEL LABEL: .................. ..................
Logical expressions are allowed only within a logical command and are sequences of tests and operations between if_ and else_ tokens. An expression is true if all its elements are true.
The following operations are allowed, listed in the order of decreasing priority:
If a logical expression is true, the commands following the expression are executed; if false, the program branches to the instruction labeled LABEL.
Here are a few examples of the use of logical commands and calculating logical expressions.
assignn 35, 10 ; v35 = 10 set 24 ; f24 -> 1 if_ ; if equaln 35, 10 ; v35 = 10 and (conjunction by default) isset 24 ; f24 set to 1 ? else_ A ; no: go to A ; yes: sound 25, 52 ; play sound 25, when finished f52 -> 1 return ; return control A: sound 30, 52 ; play sound 30, when finished f52 -> 1 ............
Here the test commands are by default combined with AND operation, and the
result is TRUE. Therefore, sound 25 will play and control will return to
the interpreter (if we are in Logic(0), or to the command following the
subroutine call (call or call_v) in the caller logic.
assignn 35, 40 ; v35 = 10 set 24 ; f24 -> 1 if_ ; if equaln 35, 40 ; v35 = 10 and (conjunction by default) not_ ; not isset 24 ; set (equals to 1) f24 ? else_ A ; no: go to A ; yes: sound 25, 52 ; play sound 25, when finished f52 -> 1 return ; return control A: sound 30, 52 ; play sound 30, when finished f52 -> 1 ............
Let us consider how this fragment works. The result of "test equaln 35, 40" is TRUE, sequence "not_ isset 24" (negation first) is FALSE and the result of conjunction is FALSE, which will play sound 30.
assignn 25, 10 ; v35 = 10 set 24 ; f24 -> 1 reset 25 ; f25 -> 0 if_ ; if isset 24 ; f24 set to 1 and (conjunction by default or_ ; open disjunctive bracket greatern 25, 11 ; if v25 > 11 not_ ; and not isset 25 ; set (equals 1) f25 or_ ; close disjunctive bracket ; is TRUE ? else_ A ; no: go to A ; yes: sound 25, 52 ; play sound 25, when finished f52 -> 1 return ; return control A: sound 30, 52 ; play sound 30, when finished f52 -> 1 ............
In the result of this fragment execution, sound 25 will play because "greatern 25, 11" is FALSE, "not_ isset 25" is TRUE, disjunction of these is TRUE and (default) conjunction of them is - TRUE.
If, after reading this section, not everything is clear, see the source code of the educational program "Thunderstorm" and analyze them yourself.
configure.screen(a, b, c)
Sets position of lines on the screen:
a = 1 (minimum line number for print);
b - user input line;
c - status line.
Prints a message for the object Var (n):
Obj <number> x: <coordinate> y: <coordinate> pri: <priority>
stepsize: <step size>.
Displays a report of the interpreter memory status.
Shows priorities of the screen pixels. Priority n is shown as color number n (see color setting commands in I.188.8.131.52).
In the centre at the bottom of the screen a cel 0 of loop 0 of the VIEW resource n is shown. In the centre of the screen, a message associated with the VIEW resource is printed.
[That's what they say but I suspect they mean OBJECT n, not VIEW resource. --VB]
[Actually, in this case the argument does refer to the VIEW resource. This is because the VIEW in question isn't meant to be a controlled object but instead is simply the picture and textual description of the an inventory item. --LE]
The screen shakes n times.
The last line entered by the user is displayed in the input line.
Input line is cleared.
If there is a text window on the screen, it is removed.
Enables and disables get_string and get_num commands if prevent_input has been issued.
Restarts the game from the very beginning.
These command save and restore the current state of the game into disk files.
Stops the interpreter until any key is pressed.
Exits the interpreter.
If n = 1, quits immediately
If n = 0, asks "Press ENTER to quit.", "Press ESC to continue."
Switch RGB monitor into the graphics mode.
Usually the crossing by an object of various areas and lines is tracked by the base point (bottom right corner) of its cel. After this command, top left corner is used as such
You can help keep The Sierra Help Pages and its affiliates alive by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.Thank you.
The Sierra Help Pages | Sierra Game Help | Walkthroughs | Hints, Tips & Spoilers | Utilities | Links | SHP Forums | Search
© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.