WonderWitch/Process

From WSdev Wiki
Jump to navigationJump to search

Memory layout

Process memory is stored in SRAM banks 3 (process 0 - typically used by FreyaOS), 2 (process 1) and 1 (process 2). The entire bank is available to the process.

Process control block

The process control block contains information about the running process. It is stored in the first 96 bytes of data.

Process control block structure
Offset Length Contents
0 4 Compiler ID, zero-terminated string; see below
4 2 TODO
6 2 TODO
8 2 TODO
10 2 TODO
12 4 Far pointer to IlibIL library
16 4 Far pointer to ProcIL library
20 4 TODO
24 64 Current working directory of the process
88 2 Near pointer to an array of near pointers to arguments (argv)
90 4 Far pointer to the process's resource data
94 2 Near pointer to the beginning of the process's free heap area.

Compiler IDs

Known compiler IDs
ID Compiler Source
LCC LSI C WonderWitch SDK
TCC Turbo C/C++ WonderWitch SDK
DMC Digital Mars C WonderWitch SDK (newer versions)
GCC gcc-ia16 Wonderful Toolchain
TCC Visual C++ WonBe

Launching procedure

Launching a process is split into two stages: loading and running.

Load

The load routine begins at offset 0 into the application. It performs the following activities:

  • SRAM initialization: copying static data from ROM to SRAM and zeroing SRAM memory,
  • copying the compiler ID to the PCB,
  • heap initialization: setting the argv and heap pointers to the location of the first free byte in SRAM,
  • returning in AX a near pointer to the start function (see "Run").

Run

The start function is of the form void main(int argc, char* argv);. It typically performs the following activities before jumping to C code:

  • configuring the stack pointer (SP) and data segment (DS),
  • resetting the display (disabling screen/sprite layers, clearing window and sprite configuration, resetting scroll),
  • initializing screen/sprite VRAM locations according to user needs (one/two screens, 256/512 free tiles),
  • initializing the default display settings (configuring text mode, enabling screen layers).

After running C code, INT $10 is triggered to exit the process.