SCI Specifications: Chapter 5 (cont.) - Kernel functions

From SCI Wiki
Revision as of 16:23, 5 August 2013 by Andrew Branscom (talk | contribs) (1 revision)
Jump to navigationJump to search

Kernel functions

Thanks to Lars Skovlund, Francois Boyer and Jeremy Tartaglia for additional information!

In SCI0, calls to the SCI kernel are initiated by using the callk opcode. callk has the opcode 0x42 or 0x43; 0x42 takes one 16 bit little endian and one 8 bit paramter, 0x43 takes two 8 bit parameters. The first parameter is the number of the kernel function to be called, the second number undetermined (as of yet).

Opcode summary:

op 0x42: callk W kfunct, B kparams (4 bytes) op 0x43: callk B kfunct, B kparams (3 bytes)

The number of parameters passed to the kernel function are determined by kparam. A total number of (kparams+2) bytes are removed from the local stack and passed on to the kernel function. The first two of those bytes are apparently always created by pushing the number of following bytes. For example, if Load(view, 10) is called, then we've got two word parameters, "view" (0x0080) and "10" (0x000a). So the callk function would have kparams set to 4; this value would be pushed to the stack first, followed by the two parameters. So the stack would look like this (left means lower address, byte ordering little endian):

02 00 80 00 0a 00

before calling Load().

Return values are returned into the accumulator, unless stated otherwise. If return type is stated as (void), then the accumulator is not modified.

Parameter types

SCI0 uses only little endian 16 bit integer values for parameters. However, this document distinguishes between different uses of those integers by defining the following variable types:

(word): 16 bit signed little endian integer
(HeapPtr): As (word); interpreted as a pointer to a heap address
(DblList): As (HeapPtr); interpreted as offset of a doubly linked list
(Node): As (HeapPtr); interpreted as offset of a list node
(&FarPtr): As (HeapPtr); interpreted as the 32 bit pointer stored at the referenced heap address
(Point): A sequence of two (word)s to describe a point on the screen, with the y coordinate being the first in the sequence.
(Rect): A sequence of four (word)s describing a rectangle. If you read "(Rect) foo", think "(word) foo_ymin, (word) foo_xmin, (word) foo_ymax, (word) foo_xmax" instead.
(String): If greater than or equal to 1000, this is the heap address of a text string. If less than 1000, it is the number of a text resource, and immediately followed by another word that contains the number of the string inside the text resource.

Parameters in brackets (like "[foo]") are optional.

Most functions exit gracefully if either a NULL HeapPtr or DblList is provided.

SCI0 Kernel functions

Kernel function 0x00: Load(word, word)

kfunct 0x00: Load (word ResType, word ResNr);

(word) ResType: The resource type number | 0x80 (as in the patch files)
(word) ResNr: The resource number

Returns: (&FarPtr) : A HeapPtr pointing to an actual pointer on the heap.

Loads a resource. The returned HeapPtr points to a special point on the heap where a pointer (32 bits) to the memory location of the specified resource is located. If the resource type equals sci_memory, the resource number is interpreted as a memory size instead; the specified number of bytes is allocated dynamically, and a handle returned.

Kernel function 0x01: UnLoad(word, word)

kfunct 0x01: UnLoad (word ResType, word ResNr);

(word) ResType: The resource type number | 0x80 (word) ResNr: The resource number

Returns: (void)

This function unloads a resource identified by its ResType and ResNr, NOT by the HeapPtr it has been loaded to, except for sci_memory resources, where the parameters are the memory resource type and the handle.

Kernel function 0x02:ScriptID(word, word)

kfunct 0x02: ScriptID (word ScriptNr, word DispatchNr);

(word) ScriptNr: Number of the script to reference (word) DispatchNr: Number of the Dispatch entry inside the script to reference

Returns: (HeapPtr) : The address pointed to by the specified element of the dispatch/exports table (script block type #7)

This function returns the address pointed to by an element of a script's dispatch table.

Kernel function 0x03: DisposeScript(word ScriptNumber)

kfunct 0x03: DisposeScript (word ScriptNumber);

(word) ScriptNumber

Returns: (void)

Disposes a script. Unloads it, removes its entries from the class table, and frees the associated heap memory.

Kernel function 0x04: Clone(HeapPtr)

kfunct 0x04:Clone (HeapPtr object);

(HeapPtr) object: The object to clone

Returns: (HeapPtr) The address of the clone

This function clones a Class or Object by copying it as a whole and mofifying the -info- selector so that it contains 1. Objects with -info- set to 0x8000 (Classes) are stripped of their selector name area, and both Objects and Classes are stripped of the function selector area.

Kernel function 0x05: DisposeClone(HeapPtr)

kfunct 0x05: DisposeClone (HeapPtr clone);

(HeapPtr) clone: The clone to dispose

Returns: (void)

Frees all memory associated with a cloned object (as produced by Clone()).

Kernel function 0x06: IsObject(HeapPtr)

kfunct 0x06: IsObject (HeapPtr suspected_object);

(HeapPtr) suspected_object: The address of something that is suspected to be an object.

Returns: (int) 1 if there is an object at the specified address, 0 if not.

This function checks whether the supplied heap pointer is valid and returns 0 if not, then proceeds to testing whether an object is at the indexed heap position. If it is, 1 is returned, 0 otherwise.

Kernel function 0x07: RespondsTo(?)

Kernel function 0x08: DrawPic(word[, word, word, word])

kfunct 0x08: DrawPic (word PicNr[, word Animation, word Flags, word DefaultPalette]);

(word) PicNr: The resource number of the picture to draw
(word) Animation: One of the following animation modes:

-1: Display instantly
 0: horizontally open from center
 1: vertically open from center
 2: open from right
 3: open from left
 4: open from bottom
 5: open from top
 6: open from edges to center
 7: open from center to edges
 8: open random checkboard
 9: horizontally close to center, reopen from center
10: vertically close to center, reopen from center
11: close to right, reopen from right
12: close to left, reopen from left
13: close to bottom, reopen from bottom
14: close to top, reopen from top
15: close from center to edges, reopen from edges to center
16: close from edges to center, reopen from center to edges
17: close random checkboard, reopen

The animation is executed when kAnimate() (see the Section called Kernel function 0x0b: Animate([DblList], [word]) is invoked. If not specified, it is assumed to be the same animation as last time. (word) Flags:

Bit 0: Clear screen before drawing
Bit 1-f: unknown, probably unused

If not specified, it defaults to 1.

Note: Some interpreter versions older than 0.000.502 interpret this parameter inversely, and have 0 as a default.
(word) DefaultPalette: The default palette number to use for drawing

Returns: (void)

The second parameter does not appear to affect anything. In QfG1, it appears to be set to 0x64 constantly. DefaultPalette is used to differentiate between day and night in QfG1. Palette 1 is used for "night" pictures, Palette 0 for "day" pictures there. The picture is drawn to the background image (which is used for restauration of everything with the exception of the mouse pointer). To bring it to the foreground, Animate() must be used.

Kernel function 0x09: Show()

kfunct 0x09: Show ();

Returns: (void)

Sets the PicNotValid flag to 2.

Kernel function 0x0a: PicNotValid([word])

kfunct 0x0a: PicNotValid ([(word) NewPicNotValid]);

[(word) NewPicNotValid]: The new value of the "PicNotValid" flag.

Returns: (word) : The previous value of the "PicNotValid" flag

This sets the PicNotValid flag that determines whether or not the current background picture should be considered "valid" by the other kernel functions.

Kernel function 0x0b: Animate([DblList], [word])

kfunct 0x0b: Animate ([DblList ViewList], [word cycle]);

[(DblList) ViewList]: List of views that are to be drawn on top of the background picture
(word) <unknown>

Returns: (void)

This function draws a background picture plus some views to the foreground. If the background picture had not been drawn previously, it is animated with the animation style set during kDrawPic (see the Section called Kernel function 0x08: DrawPic(word[, word, word, word]) ). Drawing the views is a rather complex issue. Refer to the Section called Views and animation in SCI in Chapter 6 for its description.

Kernel function 0x0c: SetNowSeen(DblList)

?? kfunct 0x0c: SetNowSeen (DblList ViewList);

(DblList) ViewList: List of affected views

Returns: (void)

Kernel function 0x0d: NumLoops(HeapPtr)

kfunct 0x0d: NumLoops (HeapPtr object);

(HeapPtr) object: The object which the view selector should be taken from

Returns: (word) The number of loops in the view

This function looks up the view selector in the specified object, loads the view resource associated with it, and checks for the number of animation loops in the view.

Kernel function 0x0e: NumCels(HeapPtr)

kfunct 0x0e: NumCels (HeapPtr object);

HeapPtr object: The object which the selectors should be taken from

Returns: (word) The number of cels in the loop

This function looks up one specific loop in a specific view (both are taken from selectors with the same name from the object pointed to by the parameter) and returns the number of cels (animation frames) in it.

Kernel function 0x0f: CelWide(word view, word loop, word cel)

kfunct 0x0f: CelWide (word view, word loop, word cel);

(HeapPtr) view: The view we're searching in loop: The loop the cel is contained in cel: The cel we're interested in

Returns: (word) The width of the cel identified by the tuple (view, loop, cel).

Kernel function 0x0f: CelWide(word view, word loop, word cel)

kfunct 0x10: CelHigh (word view, word loop, word cel);

(HeapPtr) view: The view we're searching in loop: The loop the cel is contained in cel: The cel we're interested in

Returns: (word) The height of the cel identified by the tuple (view, loop, cel).

Kernel function 0x11: DrawCel(word, word, word, Point, word)

kfunct 0x11: DrawCel (word view, word loop, word cel, Point pos, word priority);

(word) view: Number of the view resource to display
(word) loop: Number of the loop in the view resource to display
(word) cel: Number of the cel inside the loop to display
(Point) pos: Position the cel should be drawn to
(word) priority: Priority to draw the cel with

Returns: (void)

Explicitly draws a cel, specified by the complete tuple (view, loop, cel), to a specified position. Invalid loop/cel values are assumed to be 0.

Kernel function 0x12: AddToPic(DblList)

kfunct 0x12: AddToPic (DblList picviews);

(DblList) picviews: A doubly linked list of PicViews, i.e. objects that are drawn statically onto the background picture

Returns: (void)

This function stores the list of PicViews for later use by the Animate() syscall. See the Section called Kernel function 0x0b: Animate([DblList], [word]) for more details.

Kernel function 0x13: NewWindow(Rect, HeapPtr, word, word, word, word)

kfunct NewWindow (Rect Boundaries, HeapPtr Title, word Flags, word Priority, word FGColor, word BGColor);

(Rect) Boundaries: The bounding rectangle of the window
(HeapPtr) Title: A pointer to the window title
(word) Flags:

bit 0 - transparency
bit 1 - window does not have a frame
bit 2 - the window has a title (starting 10 pixels above the minimum y position specified as the first element of Boundaries)
bit 3-6 - unused
bit 7 - don't draw anything

(word) Priority: The priority at which the window should be drawn, or -1 to force on-top drawing
(word) FGColor: The foreground color for the window
(word) BGColor: The background color

Returns: (HeapPtr) : The position of the window structure on the heap

This function creates a window (see also the Section called Windows, Dialogs and Controls in Chapter 3), sets this window as the active port, draws the window (if neccessary), and returns with the window's heap address.

Kernel function 0x14: GetPort()

kfunct 0x14: GetPort ();
Returns: (HeapPtr) : A pointer to a record with the internal representation of the currently active port.
Returns a heap pointer to a port structure.

Kernel function 0x15: SetPort()

kfunct 0x15: SetPort (HeapPtr NewPort);

(HeapPtr) NewPort: The new port to set

Returns: (void)
This selects the new port which many kernel functions will draw to.
If 0 is passed, the window manager port is selected. The picture window is not accessible using this call. Only other kernel calls like KDrawPic may activate the picture window - and they always save the old port and restore it before they return.

Kernel function 0x16: DisposeWindow(HeapPtr Window)

kfunct 0x16: DisposeWindow (HeapPtr Window);

(HeapPtr) Window: The heap address of the window to destroy

Returns: (void)
Destroys a window and frees the associated heap structure.

Kernel function 0x17: DrawControl(HeapPtr)

kfunct 0x17: DrawControl (HeapPtr Control);

(HeapPtr) Control: The heap address of the Control to draw

Returns: (void)

This function draws a Control (see the Section called Windows, Dialogs and Controls in Chapter 3 for details). Please note that the correct port must be selected beforehand.

Kernel function 0x18: HiliteControl(HeapPtr)

kfunct 0x18: HiliteControl (HeapPtr Control);

(HeapPtr) Control: The control to highlight

Returns: (void)

This function is used to highlight a control by drawing it with an inverted color scheme. It requires the correct port to be set beforehand. See the Section called Windows, Dialogs and Controls in Chapter 3 for details on the windowing/Control system.

Kernel function 0x19: EditControl(HeapPtr)

kfunct 0x19: EditControl (HeapPtr Control, HeapPtr Event);

(HeapPtr) Control: A heap pointer to the Control to edit
(HeapPtr) Event: The event to interpret

Returns: (void)

This function will apply the event provided to edit a type 3 (Edit window) Control (see the Section called Windows, Dialogs and Controls in Chapter 3 for a description of the control system). Normal keypresses are added to the area pointed to by Control::text, unless the total string length would be greater than Control::max. Cursor keys, backspace and a few other keys may be used to manipulate the control. In FreeSCI, some of the libreadline control keys can be used to edit and move the cursor as well. If it is called to edit a Control which is not of type 3, it returns without error. Please note that the correct port (usually the window which the Control was drawn in) must be selected beforehand.

Kernel function 0x1a: TextSize(HeapPtr, HeapPtr, word[, word])

kfunct 0x1a: TextSize (HeapPtr dest, HeapPtr src, word font[, word maxwidth]);

(HeapPtr) dest: The destination to write the rectangle to
(HeapPtr) src: A pointer to the string to analyze
(word) font: The number of the font resource to use for this check
(word) maxwidth: The maximum width to allow for the text (defaults to 192)

Returns: (void)

This function calculates the width and height the specified text will require to be displayed with the specified font and the specified maximum width. The result will be written to the (you guessed it) specified destination on the heap. The result is a rectangle structure: The first four bytes equal to zero, the next word is the height, and the last word is the width.

Kernel function 0x1b: Display(String, word...)

kfunct 0x1b: Display (String text, word commands...);

(String) text: The text to work with
(word) commands...: A sequence of commands with parameters:

100: 2 params, (X,Y) coord of where to write on the port.
101: 1 param, -1, 0 or 1 (align right (-1), left (0) or center (1)
102: 1 param, set the text color.
103: 1 param, set the background color (-1 to draw text with transparent background)
104: 1 param, set the "gray text" flag (1 to draw disabled items)
105: 1 param, (resource number) set the font
106: 1 param, set the width of the text (the text wraps to fit in that width)
107: no param, set the "save under" flag, to save a copy of the pixels before writing the text (the handle to the saved pixels is returned)
108: 1 param, (handle to stored pixels) restore under. With this command, the text and all other parameters are ignored.

Returns: (void) or (&FarPtr) (see above)

This function executes the specified commands, then draws the supplied text to the active port (unless command 108 was executed).

Kernel function 0x1c: GetEvent(word, HeapPtr)

kfunct 0x1c: GetEvent ( word Flags, HeapPtr Event);

(word) Flags: A bitfield:

bit 0 - 14: Bit mask for the events to be returned.
bit 15: Disable joystick polling

(HeapPtr) Event: An Object on the stack which the results are written to.

Returns: (word): 0 if a null event was created, 1 otherwise.

This function fills an Event object with data from the event queue. The results are written to the "type", "message" and "modifiers" selectors. See the Section called Event handling in SCI in Chapter 6 for details.

Kernel function 0x1d: GlobalToLocal(HeapPtr Event)

kfunct 0x1d: GlobalToLocal ( HeapPtr Event);

(HeapPtr) Event: pointer to the Event object to convert

Returns: (void)

This function converts a screen-relative event to a port-relative one, using the currently active port.

Kernel function 0x1e: LocalToGlobal(HeapPtr Event)

kfunct 0x1e: LocalToGlobal ( HeapPtr Event);

(HeapPtr) Event: pointer to the Event object to convert

Returns: (void)

This function converts a port-relative event to a screen-relative one, using the currently active port.

Kernel function 0x1f: MapKeyToDir(HeapPtr Event)

kfunct 0x1f: MapKeyToDir ( HeapPtr Event);

(HeapPtr) Event: pointer to the Event object to convert

Returns: (HeapPtr): A pointer to the converted object

This function converts a keyboard event to a movement event, if possible. Otherwise, the function returns without error. See the Section called Event handling in SCI in Chapter 6 for details.

Kernel function 0x20: DrawMenuBar(word)

kfunct 0x20: DrawMenuBar (word mode);

(word) mode: 1 to draw, 0 to clear

Returns: (void)

Either draws or clears (overdraws with black) the menu bar.

Kernel function 0x21: MenuSelect(HeapPtr[, word])

kfunct 0x21: MenuSelect (HeapPtr event[, word flag]);

(HeapPtr) event: The event to interpret
(word) flag: (unknown)

Returns: (word) The menu index of a selected option, -1 if no menu option was selected, or 0 if the event passed through all of the menu system's filters.

This function interprets the event passed to it by running several checks. First, it tries to determine whether the menu system was activated by pressing the ESC key or clicking on the menu bar. In this case, the interpreter takes over and waits for the player to select a menu option. It then returns the menu option selected (menu number, starting at 1, in the upper 8 bits, item number, starting at 1 as well, in the lower part) or -1 if no active menu item was selected. In any case, the event is claimed. If the menu system was not activated by the event, it checks the event against the key commands or Said Blocks associated with each menu entry. If there is a match, the menu coordinate tuple is returned and the event is claimed, otherwise, 0 is returned.

Kernel function 0x22: AddMenu(HeapPtr, HeapPtr)

kfunct 0x22: AddMenu (HeapPtr title, HeapPtr content);

(HeapPtr) title: The menu title
(HeapPtr) content: The menu options

Returns: (void)

This function adds a menu to the menu bar. The menu title is passed in the first parameter, the second parameter contains a heap pointer to the menu entries. They are contained in one single string; the following special characters/character combinations are used:

'`': Right justify the following text
':': Menu item separator
"--!": Seperation line: This menu item is just a separator
'#': Function key. This is replaced by an F for displaying
'^': Control key. This is replaced by \001 (CTRL) for displaying

Kernel function 0x23: DrawStatus(HeapPtr)

kfunct 0x23: DrawStatus (HeapPtr text);

(HeapPtr) text: The text to draw

Returns: (void)

Draws the specified text to the title bar

Kernel function 0x24: Parse(HeapPtr, HeapPtr)

kfunct 0x24: Parse (HeapPtr event, HeapPtr input);

(HeapPtr) event: The event to generate
(HeapPtr) input: The input line to parse

Returns: (word) 1 on success, 0 otherwise

This function parses the input line and generates a parse event (type 0x80). See the Section called The Parser in Chapter 6 and the Section called Event handling in SCI in Chapter 6 for details.

Kernel function 0x25: Said(HeapPtr)

kfunct 0x:25: Said (HeapPtr said_block);

(HeapPtr) said_block: Pointer to a Said block

Returns: (word) 1 if the line last parsed meets the criteria of the supplied said_block, 0 otherwise.

This function is only invoked after Parse() was called, and works on output generated by this function. See the Section called The Parser in Chapter 6 and the Section called Event handling in SCI in Chapter 6 for details.

Kernel function 0x26: SetSynonyms(DblList)

kfunct 0x26: SetSynonyms (HeapPtr list);

(DblList) list: List of script objects to examine

Returns: (void)

This function sets the synonyms used by the parser. Synonyms are used to replace specified word groups with other word groups. The list contains a collection of script objects; all synonyms defined by the corresponding script (which can be identified by evaluating the 'number' selector of the script object) are added to the list of active synonyms.

Kernel function 0x27: HaveMouse()

kfunct 0x27: HaveMouse ();

Returns: (word) 1 if a mouse is available, 0 if not.

This function simply returns a flag containing the availability of a pointing device.

Kernel function 0x28: SetCursor(word, word[, Point])

kfunct 0x28: SetCursor (word resource, word visible[, Point coordinates]);

(word) resource: The cursor resource to use for drawing the mouse pointer
(word) visible: 1 if the mouse pointer should be visible, 0 if not
(Point) coordinates: The coordinates (relative to the wm-port) to move the mouse pointer to

Returns: (void)

This function can change the appearance and position of the mouse pointer. If no position is provided, the position remains unchanged.

Kernel function 0x29: FOpen(String, word)

kfunct 0x29: FOpen (String fname, word mode);

(String) fname: The file name
(word) mode: The mode to open the file with

Returns: (word) a file handle on success, 0 on error

Tries to open or create a file in the CWD with the specified file name. The following modes are valid:

0: open or fail: Try to open file, abort if not possible
1: open or create: Try to open file, create it if it doesn't exist
2: create: Create the file, destroying any content it might have had

Kernel function 0x2a: FPuts(word, String)

kfunct 0x2a: FPuts (word filehandle, String data);

(word) filehandle: Handle of the file to write to
(String) data: The string to write to the file

Returns: (void)

Writes a zero-terminated string to a file

Kernel function 0x2b: FGets(String, word, word)

kfunct 0x2b: FGets (String dest, word maxsize, word handle);

(String) dest: Pointer to the destination buffer
(word) maxsize: Maximum number of bytes to read
(word) handle: Handle of the file to read from

Returns: (word) The number of bytes actually read

Kernel function 0x2c: FClose(word)

kfunct 0x2c: FClose (word filehandle);

(word) filehandle: Handle of the file to close

Returns: (void)

Closes a previously opened file.

Kernel function 0x2d: SaveGame(String, word, String, String)

kfunct 0x2d: SaveGame (String game_id, word save_nr, String save_description, String version);

(String) game_id: The game object's ID string (e.g. "SQ3")
(word) save_nr: "slot" the game is to be saved to
(String) save_description: String description of the game
(String) version: Stringified game version number

Returns: (word) 1 on success, 0 if an error occured while saving

This function saves the game state (heap, windows, call stack, view list, sound state etc.) to the savegame with the numeric id save_nr and the description save_description. game_id and version are stored alongside, for verification when the game state is restored.

Kernel function 0x2e: RestoreGame(String, word, String)

kfunct 0x2e: RestoreGame (String game_id, word save_nr, String version);

(String) game_id: The game object's ID string
(word) save_nr: Number of the save game to restore
(String) version: The game object's version number

Returns: (void)

This function restores a previously saved game. It should only return if restoring failed.

Kernel function 0x2f: RestartGame()

kfunct 0x2f: RestartGame ();

Returns: never

If this function is invoked, the following things happen:

The restarting flag is set
The menu bar structure is destroyed
All sounds are stopped
All scripts are removed from the script table
The heap status is reset, but the heap is not cleared

After this is done, the engine restarts at a certain point (see the Section called Interpreter initialization and the main execution loop), re-initializes the stack, and executes the replay method of the game object.

Kernel function 0x30: GameIsRestarting()

kfunct 0x30: GameIsRestarting ();

Returns: (word) 1 if the game is restarting, 0 if not

Kernel function 0x31: DoSound(word, ...])

kfunct 0x31: DoSound (word action, ...);

(word) action: The sound command subfunction number

Returns: (see below)

'action' may be one of the following:

0x0: INIT
0x1: PLAY
0x2: NOP
0x3: DISPOSE
0x4: SET_SOUND
0x5: STOP
0x6: SUSPEND
0x7: RESUME
0x8: VOLUME
0x9: UPDATE
0xa: FADE
0xb: CHECK_DRIVER
0xc: ALL_STOP

See individual descriptions below for more information.

Kernel function 0x31: DoSound(INIT, Object)

kfunct 0x31: DoSound (word 0, Object sound_obj);

(word) 0: subfunction identifier
(Object) sound_obj: The sound object affected

Returns: (void)

Initializes the specified sound object. This will set the 'status' selector of the object to 1 ('initialized'), and load the sound indicated by the 'number' selector into the sound driver.

Kernel function 0x31: DoSound(PLAY, Object)

kfunct 0x31: DoSound (word 1, Object sound_obj);

(word) 1: The subfunction identifier
(Object) sound_obj: The sound object affected

Returns: (void)

Starts to play the song represented by the specified sound object. This will also set the 'status' selector of the object to 2 ('playing').

Kernel function 0x31: DoSound(NOP)

kfunct 0x31: DoSound (word 2);

(word) 2: The sound command subfunction number

Returns: (void)

No action appears to be associated with this subfunction call.

Kernel function 0x31: DoSound(DISPOSE, Object)

kfunct 0x31: DoSound (word 3, Object sound_obj);

(word) 3: The sound command subfunction number
(Object) sound_obj: The sound object affected

Returns: (void)

Removes the song indexed by a sound object from the sound server song list

Kernel function 0x31: DoSound(SET_SOUND, word)

kfunct 0x31: DoSound (word 4, word state);

(word) 4: The sound command subfunction number
(word) state: 1 if sound should be active, 0 if it should be turned off

Returns: (word) 1 if currently active, 0 if currently muted.

This function completely mutes or un-mutes the sound subsystem. If called with no parameters, it returns the current status.

Kernel function 0x31: DoSound(STOP, Object)

kfunct 0x31: DoSound (word 5, Object sound_obj);

(word) 5: The sound command subfunction number
(Object) sound_obj: The sound object affected

Returns: (void)

Stops playing the song represented by the specified sound object. This will set the object's 'state' selector to 0 ('stopped').

Kernel function 0x31: DoSound(SUSPEND, Object)

kfunct 0x31: DoSound (word 6, Object sound_obj);

(word) 6: The sound command subfunction number
(Object) sound_obj: The sound object affected

Returns: (void)

Suspends the song associated with the specified sound object. Its state is buffered, so that it can be resumed later on. The sound object's 'state' selector is set to 3 ('suspended').

Kernel function 0x31: DoSound(RESUME, Object)

kfunct 0x31: DoSound (word 7, Object sound_obj);

(word) 7: The sound command subfunction number
(Object) sound_obj: The sound object affected

Returns: (void)

Resumes a previously suspended song. The 'state' selector is set to 2 ('playing').

Kernel function 0x31: DoSound(VOLUME[, word])

kfunct 0x31: DoSound (word 8[, word volume]);

(word) 8: The sound command subfunction number
(word) volume: An optional volume parameter

Returns: (word) The currently set sound volume (0 to 0xf)

This subfunction retrieves and returns the current sound volume. If a second parameter is supplied the volume will be set to the value of this parameter.

Kernel function 0x31: DoSound(UPDATE, Object])

kfunct 0x31: DoSound (word 9, Object sound_obj);

(word) 9: The sound command subfunction number
(Object) sound_obj: The sound object affected

Returns: (void)

Notifies the sound server that a sound object was modified. The song priority and number of loops (stored in the 'priority' and 'loop' selectors, respectively) are re-evaulated by the sound system.

Kernel function 0x31: DoSound(FADE, Object])

kfunct 0x31: DoSound (word 0xa, Object sound_obj);

(word) 0xa: The sound command subfunction number
(Object) sound_obj: The sound object affected

Returns: (void)

Fades the specified song. Fading takes approximately two seconds. The song status is set to 'stopped' (0) afterwards.

Kernel function 0x31: DoSound(CHECK_DRIVER)

kfunct 0x31: DoSound (word 0xb);

(word) 0xb: The sound command subfunction number

Returns: (word) 1 if the sound driver was installed successfully, 0 if not

Kernel function 0x31: DoSound(ALL_STOP)

kfunct 0x31: DoSound (word 0xc);

(word) 0xc: The sound command subfunction number

Returns: (void)

Stops all music and sound effects.

Kernel function 0x32: NewList()

kfunct 0x32: NewList ();

Returns: (DblList) The address of a new node list on the heap

This function allocates and initializes a node list containing no elements.

Kernel function 0x33: DisposeList(DblList)

kfunct 0x33: DisposeList (NodeList list);

(NodeList) list: The list to dispose

Returns: (void)

Frees all memory associated to a list

Kernel function 0x34: NewNode(word, word)

kfunct 0x34: NewNode (word value, word key);

(word) value: The node value
(word) key: The node key (used for searching the list)

Returns: (Node) A new node

This function allocates a new node and initializes it with the key and value passed as parameters.

Kernel function 0x35: FirstNode(DblList)

kfunct 0x35: FirstNode (DblList list);

(DblList) list: The list to examine

Returns: (Node) The first node of the list, or 0 if the list is empty

Kernel function 0x36: LastNode(DblList)

kfunct 0x36: LastNode (DblList list);

(DblList) list: The list to examine

Returns: (Node) The last node of the list, or 0 if the list is empty

Kernel function 0x37: EmptyList(DblList)

kfunct 0x37: EmptyList (DblList list);

(DblList) list: The list to check

Returns: (int) 1 if list is an empty list, 0 if it isn't.

Kernel function 0x38: NextNode(Node)

kfunct 0x38: NextNode (Node node);

(Node) node: The node whose succcessor is to be found

Returns: (Node) The node following the supplied node, or 0 if none is available

Kernel function 0x39: PrevNode(Node)

kfunct 0x39: PrevNode (Node node);

(Node) node: The node whose predecessor is to be determined

Returns: (Node) The supplied node's predecessor, or 0 if the node has no predecessor

Kernel function 0x3a: NodeValue(Node)

kfunct 0x3a: NodeValue (Node node);

(Node) node: The node whose value is to be determined

Returns: (word) The value associated with the specified node

Kernel function 0x3b: AddAfter(DblList, Node, Node)

kfunct 0x3b: AddAfter (DblList list, Node ref_node, Node new_node);

(DblList) list: The list to insert into
(Node) ref_node: The node in list to insert after
(Node) new_node: The node to insert

Returns: (void)

This function inserts new_node into list as the immediate successor of ref_node.

Kernel function 0x3c: AddToFront(DblList, Node)

kfunct 0x3c: AddToFront (DblList list, Node node);

(DblList) list: The list the node is to be added to
(Node) node: The node to add

Returns: (void)

This function adds a node to the beginning of a doubly linked list.

Kernel function 0x3d: AddToEnd(DblList, Node)

kfunct 0x3d: AddToEnd (DblList list, Node node);

(DblList) list: The list to add the node to
(Node) node: The node to add to the list

Returns: (void)

This function adds the specified node to the end of the specified list.

Kernel function 0x3e: FindKey(DblList, word)

kfunct 0x3e: FindKey (DblList list, word key);

(DblList) list: The list in which the key is to be sought
(word) key: The key to seek

Returns: (Node) The node containing the key, or 0 if no node contains it

This function searches for a specific key in the nodes of a doubly linked list.

Kernel function 0x3f: DeleteKey(DblList, word)

kfunct 0x3f: (DblList list, word key);

(DblList) list: The list to examine
(word) key: The key to find

Returns: (void)

This function searches in the supplied list for the specified key and removes the node containing it, if any can be found.

Kernel function 0x40: Random(word, word)

kfunct 0x40: Random (word min, word max);

(word) min: The minimum result
(word) max: The maximum result

Returns: (word) A random number between min and max (inclusive)

Kernel function 0x41: Abs(word)

kfunct 0x41: Abs (word value);

(word) value: The value to absolutize

Returns: (word) The absolute value of the specified parameter

This function interprets the supplied value as a signed value and returns its absolute value.

Kernel function 0x42: Sqrt(word)

kfunct 0x42: Sqrt (word value);

(word) value: The value to draw the square root out of

Returns: (word) The square root of the supplied value

Kernel function 0x43: GetAngle(Point, Point)

kfunct 0x43: GetAngle (Point origin, Point destination);

(Point) origin: The point to look from
(Point) destination: The point to look to

Returns: (word) A positive angle between the two points, relative to the screen coordinate axis.

This function returns approximately the following value: -(180.0/PI * atan2(destination.y - origin.y, destination.x - origin.x)) + 180; Where atan2(double, double) is the libm function.

Kernel function 0x44: GetDistance(Point, Point)

kfunct 0x44: GetDistance (Point foo, Point bar);

(Point) foo: A point in two-dimensional integer space
(Point) bar: Another two-dimensional integer point

Returns: (int) The euklidian distance between the points foo and bar

Kernel function 0x45: Wait(word)

kfunct 0x45: Wait (word ticks);

(word) ticks: The number of game ticks (60 Hz beats) to wait

Returns: (word) The time passed in between the finish of the last Wait() syscall

Kernel function 0x46: GetTime([word])

kfunct 0x46: GetTime (word mode);

(wrod) mode: If this parameter is supplied, the time of day is returned.

Returns: (word) Either the time of day in seconds, or the elapsed number of ticks since the interpreter started.

This function is somewhat strange, because it determines its behaviour not by the value of a parameter passed, but by its presence instead. Please note that the time of day in this case does not distinguish between am and pm.

Kernel function 0x47: StrEnd(HeapPtr)

kfunct 0x47: StrEnd (HeapPtr string);

(HeapPtr) string: The string whose terminator should be found

Returns: (HeapPtr) The address of the null terminator of the indexed string

Kernel function 0x48: StrCat(HeapPtr, HeapPtr)

kfunct 0x48: StrCat (HeapPtr dest, HeapPtr source);

(HeapPtr) dest: The string whose end is appended to
(HeapPtr) source: The string to append

Returns: (HeapPtr) dest

This function concatenates two strings on the heap.

Kernel function 0x49: StrCmp(HeapPtr, HeapPtr[, word])

kfunct 0x49: StrCmp (HeapPtr foo, HeapPtr bar[, word length]);

(HeapPtr) foo: The one string to compare
(HeapPtr) bar: The other string to compare
(int) width: The maximum number of characters to compare

Returns: (word) -1 if foo is less than bar, 0 if both are equal, 1 if foo is greater than bar

This function simply encapsulates the libc strcmp(char *, char *) and strncmp(char *, char *, int) functions.

Kernel function 0x4a: StrLen(HeapPtr)

kfunct 0x4a: StrLen (HeapPtr string);

(HeapPtr) string: The string whose length should be calculated

Returns: (word) The length of the specified string.

Kernel function 0x4b: StrCpy(HeapPtr, HeapPtr[, word])

kfunct 0x4b: StrCpy (HeapPtr dest, HeapPtr src[, word length]);

(HeapPtr) dest: The destination to copy the string to
(HeapPtr) src: The source from which the string is to be copied
(word) length: The maximum length of the string to copy

Returns: (HeapPtr) dest

Copies a string, plus the trailing \0 terminator. The length of the string may be reduced with the optional length parameter. This function simply encapsulates the libc strcpy(char *, char *) and strncpy(char *, char *, int) fucntions.

Kernel function 0x4c: Format(HeapPtr, String,...)

kfunct 0x4c: Format (HeapPtr dest, String format, parameters...);

(HeapPtr) dest: The heap destination to write to
(String) format: The format to use
(misc) parameters: The values and strings to insert

Returns: (HeapPtr) dest

This syscall acts as a frontend to the libc sprintf(char *, char *) function.

Kernel function 0x4d: GetFarText(word, word, HeapPtr)

kfunct 0x4d: GetFarText (word resnr, word stringnr, HeapPtr dest);

(word) resnr: Number of the text resource to retreive the text from
(word) stringnr: Number of the string inside the resource to retreive
(HeapPtr) dest: The destination to write the text to

Returns: (HeapPtr) dest

Retreives a string from a text resource and puts it on the heap.

Kernel function 0x4e: ReadNumber(HeapPtr)

kfunct 0x4e: ReadNumber (HeapPtr src);

(HeapPtr) src: The address of the string to interpret as a number

Returns: (word) The numeric value of the supplied string

This function acts as a frontend to the libc atoi(char *)function, with one exception: Numbers beginning with a '$' are interpreted as hexadecimal numbers.

Kernel function 0x4f: BaseSetter(HeapPtr)

kfunct 0x4f: BaseSetter (HeapPtr view_obj);

(HeapPtr) view_obj: The view object whose base is to be set

Returns: (void)

This method is used to set the bounding rectangle of a view. The bounding rectangle is specified by the set {brLeft, brRight, brTop, brBottom} of selectors, which indicate the window-relative boundary points of the object's bounding rectangle. The rectangle defined here is used for colission detection, among other things.

The algorithm employed by FreeSCI to determine these values appears to be either identical or very close to the original algorithm; it depends several of the object's selectors (x, y, z, ystep, view) the width and height of the view indicated by its (view, loop, cel) selectors, and that view's horizontal and vertical pixel offset modifyers (xmod, ymod). The algorithm works as follows:

        brLeft := x - xmod - width / 2
	brRight := brLeft + width
	brBottom := y - z - ymod + 1
	brTop := brBottom - ystep

Kernel function 0x50: DirLoop(HeapPtr, word)

kfunct 0x50: DirLoop (HeapPtr object, word angle);

(HeapPtr) object: The object whose loop selector is to be set (word) angle: The angle which is to be used as a base to choose the loop angle

Returns: (void)
This function sets the loop selector of the specified object to a value implied by the 'angle' parameter, according to the following table:

angle loop value
angle < 45 || angle >= 314 3
angle >= 45 && angle < 135 0
angle >= 135 && angle < 225 2
angle >= 225 && angle < 314 1

Kernel function 0x51: CanBeHere(HeapPtr [, DblList])

kfunct 0x51: CanBeHere (HeapPtr obj [, DblList clip_list]);

(HeapPtr) obj: The object to test
(DblList) clip_list: An optional list of objects to test obj against

Returns: (int) 1 if obj can be where it is, 0 if not.

This function first retreives obj's signal and illegalBits selectors, plus its brRect (boundary rectangle, consisting of brTop, brBottom, brLeft and brRight). If either of the DONT_RESTORE or IGNORE_ACTOR flags is set, the function returns 1, otherwise it proceeds with verifying that

illegalBits bitwise-AND the disjunction of all elements of { 2n | ∃ a pixel with the color value n inside the control map zone delimited by obj's brRect} equals 0
¬∃pic,pic∈clip_list. (pic::signal & (DONT_RESTORE | IGNORE_ACTOR)) = 0 ∧ pic::brRect ∩ obj::brRect ≠ ∅

If both conditions are met, 1 is returned. Otherwise, 0 is returned.

Kernel function 0x52: OnControl(word, Point | Rect)

kfunct 0x52: OnControl (word map, Point|Rect area);

(word) map: The map to check (bit 0: visual, bit 1: priority, bit 2: special)
(Point) or (Rect) Area: The point or rectangle that is to be scanned

Returns: (word) The resulting bitfield

This function scans the indicated point or area on the specified map, and sets the bit corresponding to each color value found correspondingly. For example, if scanning map 4 (special) would touch two areas, one with color value 1 and one with color value 10, the resulting return value would be 0x0402 (binary 0000010000000010). See also the Section called Pictures and movement control in Chapter 3.

Kernel function 0x53: InitBresen(HeapPtr [, word])

kfunct 0x53: InitBresen HeapPtr mover, word step_factor);

(HeapPtr) mover: The mover object to initialize
(word) step_factor: A factor to multiply the step size with (defaults to 1)

Returns: (void)

Initializes a mover object for bresenham movement from the object's client's coordinates to the coordinates specified by its own pair of (x,y) selectors. To do this, it retreives the mover's client, and calculates the result values according to the algorithm for determining the initial values for iterative line drawing according to the Bresenham line algorithm:

        client := mover::client
        δx := mover::x - client::x
        δy := mover::y - client::y

        vxmax := client::xStep * step_factor
        vymax := client::yStep * step_factor

        numstepsx := |δx / vxmax|
        numstepsy := |δy / vymax|

        IF numstepsx > numstepsy THEN
                numsteps := numstepsx
                mover::b_xAxis := 1
                δ0 := δx
                δ1 := δy
                s := client::yStep
        ELSE
                numsteps := numstepsy
                mover::b_xAxis := 0
                δ1 := δx
                δ0 := δy
                s := client::xStep
        FI

        mover::dx := δx / numsteps
        mover::dy := δy / numsteps

        mover::b_di := - |δ0|
        mover::b_i1 := 2 * (|δ1| - |s * numsteps|) * |δ0|
        mover::b_incr := δ1 / |δ1|
        mover::b_i2 := mover::b_d1 * 2

Kernel function 0x54: DoBresen()

kfunct 0x55: DoBresen ();

Returns: (void)

Executes the Bresenham algorithm on the values calculated by InitBresen, and counts down the number of steps. It then invokes CanBeHere() on the resulting coordinates, and sets the new coordinates if it actually Can Be There.

Kernel function 0x55: DoAvoider(HeapPtr)

kfunct 0x55: DoAvoider (HeapPtr avoider);

Returns: (word) New direction

This function is a no-op in later SCI games, but is implemented in some or all pre-0.000.576 interpreters.

Kernel function 0x56: SetJump(?)

Kernel function 0x57: SetDebug()

kfunct 0x57: SetDebug ();

Returns: (void)

This function forces the interpreter to enter debug mode. It is equivalent to pressing LShift-RShift-PadMinus.

Kernel function 0x58: InspectObj(?)

Kernel function 0x59: ShowSends(?)

Kernel function 0x5a: ShowObjs(?)

Kernel function 0x5b: ShowFree(?)

Kernel function 0x5c: MemoryInfo(word)

kfunct 0x5c: word mode (word mode);

(word) mode: 0 to 4 (see below)

Returns: (word) The amount of free memory on the heap, in bytes

This function returns the total amount of free memory on the heap if mode == 0. If mode equals 1, the total size of the largest chunk of heap memory is returned. In mode 2, the size of the largest available hunk memory block is returned, and mode 3 returns the total amount of free hunk memory, shiftet to the right by 4 bits.

Mode 4 was apparently introduced in SCI01 and reports the amount of free memory provided by DOS in paragraphs.

Kernel function 0x5d: StackUsage(?)

Kernel function 0x5e: Profiler(?)

Kernel function 0x5f: GetMenu(?)

Kernel function 0x60: SetMenu(?)

Kernel function 0x61: GetSaveFiles(String, String, HeapPtr*)

kfunct 0x61: GetSaveFiles (String game_id, String strspace, HeapPtr *ptrs);

(String) game_id: The game ID as a string
(String) strspace: The string which the result should be stored in
(HeapPtr *) ptrs: The array of pointers which the string pointers are to be stored in

Returns: (word) The number of savegames for the specified game_id.

Returns an array of strings describing the existing save games for game_id. The strings are put into strspace one by one, and heap pointers to each of them are put into the ptrs array. The number of saved games is returned in the accumulator.

Kernel function 0x62: GetCWD(HeapPtr)

kfunct 0x62: GetCWD (HeapPtr address);

(HeapPtr) address: The address to write to

Returns: (HeapPtr) The supplied address

This function retreives the current working directory (CWD) and stores its string representation at the location pointed to by the supplied parameter.

Note: FreeSCI returns a sub-directory of the user's home directory, if applicable, instead of the cwd.

Kernel function 0x63: CheckFreeSpace(String)

kfunct 0x63: CheckFreeSpace (String path);

(String) path: The path to examine

Returns: (word) 1 if saving is possible, 0 otherwise

Returns TRUE if there would be enough space left on the specified path to save the current game (but doesn't actually save).

Kernel function 0x64: ValidPath(?)

Kernel function 0x65: CoordPri(?)

Kernel function 0x66: StrAt (String, word[, char])

kfunct 0x66: StrAt (String src, word offset[, char replacement]);

(String) src: The string to read from
(word) offset: The offset inside the string
(char) replacement: An optional replacement value for the indexed character

Returns: (char) The character requested

This function retreives a single character from a string. Optionally, if replacement is set, the source character will be replaced with the specified replacement.

Kernel function 0x67: DeviceInfo(word, String[, String])

kfunct 0x67: DeviceInfo (word sub_function, String string1[, String string2]);

(word) sub_function: A numeric value from 0 to 3, inclusive. See below.
(String) string1: See below.
(String) string2: See below.

Returns: See below

Depending on the value of sub_function, this system call executes one of four defined actions:

0: GET_DEVICE
1: GET_CURRENT_DEVICE
2: PATHS_EQUAL
3: IS_FLOPPY


See the specific function definitions below for more information.

Kernel function 0x67: DeviceInfo(GET_DEVICE, String, String)

kfunct 0x67: DeviceInfo (word GET_DEVICE, String input, String output);

(word) GET_DEVICE: Constant sub-function identifier (0)
(String) input: A path whose device identifier should be extracted
(String) output: The destination of the device identifier

Returns: (HeapPtr) Points to the terminating zero character of output

GET_DEVICE returns the drive/device on which "input" resides in output (and a pointer to the terminating NULL in the accumulator).

Kernel function 0x67: DeviceInfo(GET_CURRENT_DEVICE, String output)

kfunct 0x67: DeviceInfo (word GET_CURRENT_DEVICE, String output);

(word) GET_CURRENT_DEVICE: Constant sub-function identifier (1)
(String) output: The destination which the CWD device identifier should be written to.

Returns: (HeapPtr) Points to the terminating null character of output

GET_CURRENT_DEVICE returns the drive/device that contains the current working directory (and a pointer to the terminating NULL in the accumulator)

Kernel function 0x67: DeviceInfo(PATHS_EQUAL, String path1, String path2)

kfunct 0x67: DeviceInfo (word PATHS_EQUAL, String path1, String path2);

(word) PATHS_EQUAL: Constant sub-function identifier (2)
(String) path1: First path to compare
(String) path2: Second path to compare

Returns: (word) 1 if path1 and path2 point to the same physical location, 0 otherwise.

PATHS_EQUAL returns TRUE if the two supplied paths point to the same place.

Kernel function 0x67: DeviceInfo(IS_FLOPPY, String path)

kfunct 0x67: DeviceInfo (word IS_FLOPPY, String path);

(word) IS_FLOPPY: Constant sub-function identifier (3)
(String) path:

Returns: (word) 1 if path is on a floppy disk, 0 otherwise

PATHS_EQUAL returns TRUE if the two supplied paths point to the same place.

Kernel function 0x68: GetSaveDir()

kfunct 0x68: GetSaveDir ();

Returns: (String)

This function returns the heap position allocated to store the string representation of the save game directory. This heap space is allocated automatically during startup.

Kernel function 0x69: CheckSaveGame(String, word[, String])

kfunct 0x69: CheckSaveGame (String game_id, word game_nr[, String version]);

(String) game_id: The savegame ID string
(word) game_nr: The savegame number
(String) version: An optional game version string

Returns: (word) 1 if the savegame is loadable, 0 otherwise

Returns TRUE if the specified save game is valid and loadable (i.e., not for another game/interpreter/version).

Kernel function 0x6a: ShakeScreen(word[, word])

kfunct 0x6a: ShakeScreen ( word times [, word direction] );

(word) times: Number of times to shake the screen
(word) direction: See below

Returns: (void)

If direction is not specified, it defaults to 1. It is a bitmask and defined as follows:

bit 0: Shake 10 pixels downwards
bit 1: Shake to the right
bit 2: Unknown, but used

Kernel function 0x6b: FlushResources(?)

Kernel function 0x6c: SinMult(?)

Kernel function 0x6d: CosMult(?)

Kernel function 0x6e: SinDiv(?)

Kernel function 0x6f: CosDiv(?)

Kernel function 0x70: Graph(?)

Kernel function 0x71: Joystick(word, word)

kfunct 0x71: Joystick (word subfunction, word param);

(word) subfunction: Always 0x0c
(word) param: Parameter for the subfunction, purpose unknown.

Returns: (void)

 

< Previous: Chapter 5 - The SCI Virtual MachineNext: Chapter 6 - SCI in action >