Main
Links
Games
Main
Download
Documentation
Development
Bug list

Kernel functions

Note

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 0x08: DrawPic(word[, word, word, word])

(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 0x11: DrawCel(word, word, word, Point, word)

(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 0x13: NewWindow(Rect, HeapPtr, word, word, word, word)

(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 0x17: DrawControl(HeapPtr)

(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 0x19: EditControl(HeapPtr)

(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 0x1b: Display(String, word...)

(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 0x22: AddMenu(HeapPtr, HeapPtr)

(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 0x28: SetCursor(word, word[, Point])

(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)

(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 0x2b: FGets(String, word, word)

(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 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 0x31: DoSound(word, ...])

(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 0x4d: GetFarText(word, word, HeapPtr)

(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 0x51: CanBeHere(HeapPtr [, DblList])

(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 0x6a: ShakeScreen(word[, word])

(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 0x71: Joystick(word, word)

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

Returns: (void)