I/O operations

To use the functions described in this page, the file <hal.h> should be included.

Output to the screen

JSLK currently only supports outputting to the screen in text mode, through a 24x80 map. A line is not considered because of the menu bar. The console is started by the kernel entrypoint, in x86 this is done through the startConsole() function defined in vga.c.

kprintf()
cprintf()
kputc()
consolePutChar()
clear_console()

int kprintf(string c, ...)

Used to print a formatted string to the console.

Arguments

string c: The string to be printed. Use special characters in string to interpolate values.

Optional arguments: The values to be interpolated (in the order specified in the string).

Special characters

%i: Decimal number.

%s: String.

%h: Hexadecimal number.

Return value

Returns 0 if successful.

int cprintf(string c, uint8_t color, ...)

Used to print a formatted rich-text string to the console.

Arguments

string c: The string to be printed. Use special characters in string to interpolate values.

uint8_t color: The color of the text to be printed. A color value can be obtained through the getColor() function.

Optional arguments: The values to be interpolated (in the order specified in the string).

Special characters

%i: Decimal number.

%s: String.

%h: Hexadecimal number.

Return value

Returns 0 if successful.

void kputc(char c)

Used to print a character to the console.

Arguments

char c: The character to be printed.

Return value

This function has no return value.

void consolePutChar(char c, uint8_t color, size_t x, size_t y);

Used to print a character to the console on the specified position.

Arguments

char c: The character to be printed.

uint8_t color: The color of the text to be printed. A color value can be obtained through the getColor() function.

size_t x: The x position of the character coordinate.

size_t y: The y position of the character coordinate.

Return value

This function has no return value.

void clear_console()

Used to clear the console.

Arguments

This function takes no arguments.

Return value

This function has no return value.

setConsoleColor()
getColor()
setMenubarText()
debugPrint()

void setConsoleColor(uint8_t color)

Used to change the console color. clear_console() must be called to apply changes to the whole console.

Arguments

uint8_t color: The color of the text to be printed. A color value can be obtained through the getColor() function.

Return value

This function has no return value.

uint8_t getColor(vga_color text, vga_color background)

Used to get a console compatible color.

Special Types

vga_color: One of the sixteen possible VGA colors.

vga.h
// ...
enum vga_color_t
{
vga_black = 0,
vga_blue = 1,
vga_green = 2,
vga_cyan = 3,
vga_red = 4,
vga_magenta = 5,
vga_brown = 6,
vga_light_grey = 7,
vga_grey = 8,
vga_light_blue = 9,
vga_light_green = 10,
vga_light_cyan = 11,
vga_light_red = 12,
vga_light_magenta = 13,
vga_light_brown = 14,
vga_white = 15,
};
// ...

Arguments

vga_color text: Text color in the console (foreground).

vga_color background: Console's background color.

Optional arguments: The values to be interpolated (in the order specified in the string).

Return value

Returns a console compatible color value in a uint8_t.

Sample usage

sample.c
uint8_t color = getColor(vga_grey, vga_black); // Get a color value to use later
setConsoleColor(color); // Example of how you could use the obtained value

void setMenubarText(string text)

Used to change the text in the menu bar.

Arguments

string text: The string to be displayed in the menu bar.

Return value

This function has no return value.

void debugPrint(string msg)

Used to print a string to the console only if the KERNEL_DEBUG flag was set during build.

Arguments

string msg: The string to be printed.

Return value

This function has no return value.

Input from the keyboard

Although there is a keyboard driver provided, there is currently no way of interfacing with it without the need to write auxiliary code. Currently, all input from the keyboard is printed to the screen, and there is one function that will indicate if the enter key was pressed (read_key()), although it was just written for testing purposes and will be removed in the future. If you are in need to use the keyboard, feel free to write your own interface until one is added in a future release.

File I/O

The VFS

I/O with other hardware

The following functions can be used to interface with ports.

outb()
inb()
inw()

void outb(uint16_t port, uint8_t value)

Used to send a byte to a specific port.

Arguments

uint16_t port: The port to send the byte to.

uint8_t value: The value to be sent.

Return value

This function has no return value.

uint8_t inb(uint16_t port)

Used to read a byte from a specific port.

Arguments

uint16_t port: The port to read from.

Return value

The byte read is returned as a uint8_t.

uint16_t inw(uint16_t port)

Used to read a word from a specific port.

Arguments

uint16_t port: The port to read from.

Return value

The word read is returned as a uint16_t.