The x16-PRos operating system provides a set of interrupt-driven APIs for developers to interact with the system. These APIs are organized into three categories, each accessible via a specific interrupt:
- INT 0x21: Output API for screen output and video mode initialization.
- INT 0x22: File System API for managing files on a FAT12 file system.
Each interrupt handler uses the AH register to specify the function code, with other registers used for input and
output parameters as described below. Unless specified, all functions preserve registers not used for output and set the
carry flag (CF) on error.
The Output API provides functions for displaying text on the screen in various colors and managing the video mode. It
uses interrupt 0x21 and is initialized by setting up the interrupt vector table (IVT) and configuring the VGA video
mode (640x480, 16 colors).
- Description: Initializes the output system by setting the VGA video mode to 640x480 with 16 colors.
- Input:
AH= 0x00
- Output: None
- Preserves: All registers
- Error Handling: No errors reported (no carry flag set)
- Notes: Uses BIOS interrupt
0x10withAX = 0x12to set the video mode. Called during kernel initialization.
- Description: Prints a null-terminated string to the screen in white.
- Input:
AH= 0x01SI= Pointer to null-terminated string
- Output: None
- Preserves: All registers except
SI(advanced to the end of the string) - Error Handling: No errors reported
- Notes: Uses BIOS interrupt
0x10withAH = 0x0EandBL = 0x0F(white color). Supports newline (0x0A) by inserting a carriage return (0x0D) and line feed.
- Description: Prints a null-terminated string to the screen in green.
- Input:
AH= 0x02SI= Pointer to null-terminated string
- Output: None
- Preserves: All registers except
SI(advanced to the end of the string) - Error Handling: No errors reported
- Notes: Similar to function 0x01, but uses
BL = 0x0A(green color).
- Description: Prints a null-terminated string to the screen in cyan.
- Input:
AH= 0x03SI= Pointer to null-terminated string
- Output: None
- Preserves: All registers except
SI(advanced to the end of the string) - Error Handling: No errors reported
- Notes: Uses
BL = 0x0B(cyan color).
- Description: Prints a null-terminated string to the screen in red.
- Input:
AH= 0x04SI= Pointer to null-terminated string
- Output: None
- Preserves: All registers except
SI(advanced to the end of the string) - Error Handling: No errors reported
- Notes: Uses
BL = 0x0C(red color).
- Description: Outputs a carriage return (
0x0D) and line feed (0x0A) to move the cursor to the next line. - Input:
AH= 0x05
- Output: None
- Preserves: All registers
- Error Handling: No errors reported
- Notes: Uses BIOS interrupt
0x10withAH = 0x0E.
- Description: Clears the screen by resetting the VGA video mode to 640x480 with 16 colors. The current theme is not reapplied — the screen is left in default VGA state (black background). Use this when the caller wants the raw VGA defaults (e.g. SETUP).
- Input:
AH= 0x06
- Output: None
- Preserves: All registers
- Error Handling: No errors reported
- Notes: Calls BIOS interrupt
0x10withAX = 0x12.
- Description: Sets the text color to be used by the
Print String with Current Colorfunction (0x08). - Input:
AH= 0x07BL= Color code (valid values: 0x00–0x0F, corresponding to VGA 16-color palette)
- Output: None
- Preserves: All registers
- Error Handling: No errors reported. Invalid color codes may result in undefined behavior.
- Notes:
- The color code in
BLcorresponds to the VGA 16-color palette (see Color Palette). - The color is stored globally and used by subsequent calls to function 0x08 until changed.
- The color code in
- Description: Prints a null-terminated string to the screen using the color previously set by function 0x07.
- Input:
AH= 0x08SI= Pointer to a null-terminated string
- Output: None
- Preserves: All registers except
SI(advanced to the end of the string) - Error Handling: No errors reported. Non-null-terminated strings may cause undefined behavior.
- Notes:
- Uses BIOS interrupt
INT 0x10withAH = 0x0Efor teletype output. - The color is determined by the value set by function 0x07 (stored in
current_color). - Handles newline characters (
0x0A) by outputting carriage return (0x0D) followed by line feed (0x0A).
- Uses BIOS interrupt
- Description: Returns the current system time with timezone offset applied.
- Input:
AH= 0x0A
- Output:
CH= Hours (0–23)CL= Minutes (0–59)DH= Seconds (0–59)
- Preserves: All registers except
CX,DX - Error Handling: No errors reported
- Notes: Reads the RTC via BIOS
INT 0x1Aand applies the timezone offset fromCONF.DIR/TIMEZONE.CFG. Values are returned in binary (not BCD).
- Description: Returns the current system date with timezone offset applied.
- Input:
AH= 0x0B
- Output:
CH= Century (e.g., 20)CL= Year (0–99, e.g., 26 for 2026)DH= Month (1–12)DL= Day (1–31)
- Preserves: All registers except
CX,DX - Error Handling: No errors reported
- Notes: Reads the RTC via BIOS
INT 0x1Aand applies the timezone offset fromCONF.DIR/TIMEZONE.CFG. Day boundaries are handled correctly (e.g., UTC+5 at 23:00 rolls the date forward). Values are returned in binary (not BCD).
- Description: Clears the screen and reapplies the user's current theme (background and foreground colors loaded from
CONF.DIR/THEME.CFG). Use this when the caller wants the screen to look consistent with the rest of the OS. - Input:
AH= 0x0C
- Output: None
- Preserves: All registers
- Error Handling: No errors reported
- Notes: Internally calls
set_video_modefollowed byload_and_apply_theme. If the theme file is missing or unreadable, the screen falls back to default VGA colors.
The following table lists the valid color codes for VGA mode 0x12 (16 colors):
| Code | Color Name | RGB (0–255) | HEX |
|---|---|---|---|
| 0x00 | Black | (0, 0, 0) | #000000 |
| 0x01 | Dark Blue | (0, 0, 170) | #0000AA |
| 0x02 | Dark Green | (0, 170, 0) | #00AA00 |
| 0x03 | Dark Cyan | (0, 170, 170) | #00AAAA |
| 0x04 | Dark Red | (170, 0, 0) | #AA0000 |
| 0x05 | Dark Magenta | (170, 0, 170) | #AA00AA |
| 0x06 | Brown | (170, 85, 0) | #AA5500 |
| 0x07 | Light Gray | (170, 170, 170) | #AAAAAA |
| 0x08 | Dark Gray | (85, 85, 85) | #555555 |
| 0x09 | Blue | (85, 85, 255) | #5555FF |
| 0x0A | Green | (85, 255, 85) | #55FF55 |
| 0x0B | Cyan | (85, 255, 255) | #55FFFF |
| 0x0C | Red | (255, 85, 85) | #FF5555 |
| 0x0D | Magenta | (255, 85, 255) | #FF55FF |
| 0x0E | Yellow | (255, 255, 85) | #FFFF55 |
| 0x0F | White | (255, 255, 255) | #FFFFFF |
The File System API provides functions for managing files on a FAT12 file system, typically on a 1.44 MB floppy disk. It
uses interrupt 0x22 and handles file operations such as listing, loading, writing, and deleting files. The API assumes
filenames are in 8.3 format (e.g., FILENAME.EXT) and converts them to uppercase internally.
- Description: Initializes the file system by resetting the floppy disk controller.
- Input:
AH= 0x00
- Output: None
- Preserves: All registers
- Error Handling: Sets carry flag (CF) on floppy reset failure
- Notes: Calls
fs_reset_floppyto reset the floppy drive using BIOS interrupt0x13withAH = 0x00.
- Description: Retrieves a comma-separated list of filenames from the root directory, along with the total size and file count.
- Input:
AH= 0x01AX= Pointer to buffer for storing the file list (comma-separated, null-terminated)
- Output:
BX= Low word of total file size (in bytes)CX= High word of total file size (32-bit size)DX= Number of files- Carry flag (CF) set on error
- Preserves: All registers except
BX,CX,DX - Error Handling: Sets CF on disk read errors
- Notes: Reads the root directory (sectors 19–32) and formats filenames in 8.3 format (e.g.,
FILENAME.EXT). Skips deleted entries, long filename entries, and directories.
- Description: Loads a file from the disk into memory at a specified address.
- Input:
AH= 0x02SI= Pointer to null-terminated filename (8.3 format)CX= Memory address to load the file
- Output:
BX= File size (in bytes)- Carry flag set on error (e.g., file not found, disk error)
- Preserves: All registers except
BX - Error Handling: Sets CF if the file is not found or disk read fails
- Notes: Converts the filename to uppercase and FAT12’s 11-character format. Reads the root directory and FAT to locate and load file sectors.
- Description: Writes data from a memory buffer to a file, creating it if it doesn’t exist.
- Input:
AH= 0x03SI= Pointer to null-terminated filename (8.3 format)BX= Pointer to data bufferCX= Size of data to write (in bytes)
- Output: Carry flag set on error
- Preserves: All registers
- Error Handling: Sets CF on invalid filename, disk full, or write errors
- Notes: Deletes the file if it exists before writing. Allocates clusters in the FAT and updates the root directory.
- Description: Checks if a file exists in the root directory.
- Input:
AH= 0x04SI= Pointer to null-terminated filename (8.3 format)
- Output: Carry flag cleared if file exists, set if not found
- Preserves: All registers
- Error Handling: Sets CF if the file is not found or the filename is invalid
- Notes: Converts the filename to uppercase and FAT12 format before searching the root directory.
- Description: Creates an empty file in the root directory.
- Input:
AH= 0x05SI= Pointer to null-terminated filename (8.3 format)
- Output: Carry flag set on error
- Preserves: All registers
- Error Handling: Sets CF if the filename is invalid, the file already exists, or the root directory is full
- Notes: Allocates a directory entry with zero size and no clusters.
- Description: Deletes a file by marking its directory entry as deleted and freeing its clusters.
- Input:
AH= 0x06SI= Pointer to null-terminated filename (8.3 format)
- Output: Carry flag set on error
- Preserves: All registers
- Error Handling: Sets CF if the file is not found or disk write fails
- Notes: Marks the directory entry with
0xE5and clears the corresponding FAT entries.
- Description: Renames a file by updating its directory entry.
- Input:
AH= 0x07SI= Pointer to null-terminated old filename (8.3 format)BX= Pointer to null-terminated new filename (8.3 format)
- Output: Carry flag set on error
- Preserves: All registers
- Error Handling: Sets CF if the old file is not found, the new filename is invalid, or disk write fails
- Notes: Both filenames are converted to uppercase and FAT12 format.
- Description: Retrieves the size of a file from its directory entry.
- Input:
AH= 0x08SI= Pointer to null-terminated filename (8.3 format)
- Output:
BX= File size (in bytes)- Carry flag set on error
- Preserves: All registers except
BX - Error Handling: Sets CF if the file is not found
- Notes: Reads the file size from the directory entry (offset 28).
- Description: Navigates into the specified directory. Supports nested subdirectories.
- Input:
AH= 0x09SI= Pointer to directory name in 8.3 format (e.g TEST.DIR; CONF.DIR; BIN.DIR)
- Output: CF set on error
- Notes: Changes into a single directory component relative to the current directory. To navigate a multi-level path (e.g.
CONF.DIR/SUB.DIR), call this function once per component. All filesystem operations (load, write, list, etc.) operate relative to the current directory.
- Description: Moves the current path up one level to the parent directory using the
..entry. - Input:
AH= 0x0A - Output: CF set if already at root
- Description: Creates a new directory entry in the current directory.
- Input:
AH= 0x0BSI= Pointer to directory name in 8.3 format (e.g TEST.DIR; CONF.DIR; BIN.DIR)
- Output: CF set on error
- Description: Deletes an empty directory from the current directory.
- Input:
AH= 0x0CSI= Pointer to directory name in 8.3 format (e.g TEST.DIR; CONF.DIR; BIN.DIR)
- Output: CF set on error
- Description: Determines if the specified name is a directory in the current directory.
- Input:
AH= 0x0DSI= Pointer to name in 8.3 format (e.g TEST.DIR; CONF.DIR; BIN.DIR)
- Output: CF set if it is a directory
- Description: Saves the current directory state (path, cluster, disk, drive) to internal kernel storage.
- Input:
AH= 0x0E - Output: None
- Description: Restores the directory state previously saved with function 0x0E.
- Input:
AH= 0x0F - Output: None
- Description: Loads a huge (> 32768bytes) file from the disk into memory at a specified address.
- Input:
AH= 0x10SI= Pointer to null-terminated filename (8.3 format)CX= load offset (position)DX= load segment address
- Output:
- Carry flag set on error (e.g., file not found, disk error)
- Error Handling: Sets CF if the file is not found or disk read fails
- Notes: Converts the filename to uppercase and FAT12’s 11-character format. Reads the root directory and FAT to locate and load file sectors.
- Description: Writes a large file from an arbitrary segment:offset in memory to the current directory. Supports files larger than 64 KB with automatic segment boundary wrapping. If a file with the same name exists, it is replaced.
- Input:
AH= 0x13SI= Pointer to null-terminated filename (8.3 format)CX= source data offsetDX= source data segmentBX= file size low word (bits 0-15)DI= file size high word (bits 16-31)
- Output:
- Carry flag set on error (e.g., disk full, write error)
- Error Handling: Sets CF on filename conversion failure, disk write error, or FAT exhaustion
- Notes: Writes data in batches of up to 128 clusters (64 KB) per pass. Automatically advances the source segment when the offset wraps past 0xFFFF. Creates the directory entry first, then allocates clusters, builds the FAT chain, and writes data sectors. The 32-bit file size is stored in the directory entry (bytes 28-31).
- Description: When called, saves the current drive letter into the AL register.
- Input:
AH= 0x14 - Output:
AL= current drive letter
- Environment: The x16-PRos API is designed for a 16-bit real-mode x86 environment, running on a 1.44 MB floppy disk with a FAT12 file system and VGA video mode (640x480, 16 colors).
- Filename Format: File system functions expect filenames in 8.3 format (e.g.,
FILENAME.EXT). Filenames are case-insensitive and converted to uppercase internally. - Error Handling: Most functions set the carry flag (CF) to indicate errors. Check the CF after calling file system functions to handle errors appropriately.
- Register Preservation: Functions preserve registers unless explicitly used for output, using
pusha/popaor temporary storage. - Interrupts: Ensure interrupts are enabled (
sti) before calling API functions, as they rely on BIOS interrupts (0x10,0x13,0x1A, etc.). - Memory Management: Buffers for file operations (e.g.,
fs_get_file_list,fs_load_file) must be large enough to hold the data. The kernel uses fixed buffers likedirlist(1024 bytes) andfile_buffer(32768 bytes). - Limitations:
- File sizes are limited to 16-bit values (65,535 bytes) in some functions.
- The root directory is limited to 224 entries (FAT12 limitation).
- String functions assume null-terminated strings and may have buffer size limits (e.g., 255 characters for keyboard input).
The x16-PRos operating system and its API are licensed under the MIT License. See the LICENSE.TXT for details.
Author: PRoX (https://github.com/PRoX2011) Version: 0.4, 0.5, 0.6, 0.7, 0.8, 0.9