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.