Formatting System
Text Formatting, Colors, and Structured Output
Overview
The Formatting System handles text formatting, colors, alignment, and structured output. It uses kernel I/O primitives to display formatted text on the VGA screen.
VGA Color Attributes
VGA colors use the format 0xBF where B = background and F = foreground:
| Value | Constant | Color |
|---|---|---|
0x00 |
COLOR_BLACK |
Black |
0x01 |
COLOR_BLUE |
Blue |
0x02 |
COLOR_GREEN |
Green |
0x03 |
COLOR_CYAN |
Cyan |
0x04 |
COLOR_RED |
Red |
0x05 |
COLOR_MAGENTA |
Magenta |
0x06 |
COLOR_BROWN |
Brown |
0x07 |
COLOR_LIGHT_GRAY |
Light Gray |
0x08 |
COLOR_DARK_GRAY |
Dark Gray |
0x09 |
COLOR_LIGHT_BLUE |
Light Blue |
0x0A |
COLOR_LIGHT_GREEN |
Light Green |
0x0B |
COLOR_LIGHT_CYAN |
Light Cyan |
0x0C |
COLOR_LIGHT_RED |
Light Red |
0x0D |
COLOR_LIGHT_MAGENTA |
Light Magenta |
0x0E |
COLOR_YELLOW |
Yellow |
0x0F |
COLOR_WHITE |
White |
Default Colors
| Constant | Value | Usage |
|---|---|---|
COLOR_DEFAULT |
0x0F |
White on black (default text) |
COLOR_PROMPT |
0x0F |
White on black (shell prompt) |
COLOR_ERROR |
0x0C |
Light red on black (error messages) |
COLOR_SUCCESS |
0x0A |
Light green on black (success messages) |
COLOR_INFO |
0x0B |
Light cyan on black (info messages) |
COLOR_WARNING |
0x0E |
Yellow on black (warning messages) |
COLOR_COMMAND |
0x0E |
Yellow on black (command names) |
VGA Screen Constants
| Constant | Value | Description |
|---|---|---|
VGA_WIDTH |
80 |
Characters per line |
VGA_HEIGHT |
25 |
Lines per screen |
VGA_BUFFER |
0xb8000 |
VGA text buffer address |
VGA_BYTES_PER_LINE |
160 |
80 chars * 2 bytes (char + attribute) |
API Reference
format_set_color
Sets the current color for subsequent output.
; Set color
mov al, COLOR_LIGHT_GREEN
call format_set_color
format_print_colored
Prints a string with a specific color.
; Print colored string
mov rsi, message_string
mov rcx, message_length
mov al, COLOR_ERROR
call format_print_colored
format_scroll_screen
Scrolls the VGA screen up by one line.
; Scroll screen
call format_scroll_screen
format_clear_screen
Clears the entire VGA screen.
; Clear screen
call format_clear_screen
File Locations
- 64-bit Implementation:
system/shell/formatting_64.asm
Related Documentation
- Shell System - Uses formatting for output
- I/O System - Low-level I/O operations
- Memory Layout - VGA buffer address