
We write “Hello world!” For KolibriOS in C
Many people ask: “Is it possible to write a C program under KolibriOS?”
Answer: “Yes, it is possible!” , And below I will tell you how to do it.

To write a program, we need:
There are two types of programs in KolibriOS: window and console. A program with a GUI is written using the system functions and the BoxLib library . The console program is written using the console.obj library . The work with libraries will be described in the following articles; Today we will write a window application based on system functions.
The window application consists of the main () function , which has a special message handler:
In our program, we will only process keyboard events and button clicks. Their processing takes place in a while loop using switch - case.
Let's analyze these events:
2 - a key is pressed on the keyboard;
3 - the button is pressed, the button defined earlier (in this example, this is only the cross of closing the program, which is the button created with the window);
You can read more about the event system on our Wiki or in the documentation that comes with the OS (Docpack program on the desktop).
For the convenience of development, we will issue the commands that are responsible for the appearance of the window into a separate draw_window () function .
Now it's time to figure out how to draw a window.
Drawing a window starts with the _ksys_window_redraw (1) function , and ends with _ksys_window_redraw (2) . To draw a window, you need to use the _ksys_draw_window function (window coordinate by x, window coordinate by y, width, height, color, window type, window title color, whether the window is not movable, window frame color);
Window types:
0 - type I - window of fixed sizes (without skin)
1 - only determine the area of the window, do not draw anything
2 - type II - window of resizable (without skin)
3 - window with skin (resizable)
4 - window with fixed-size skin
Finally, to draw text, you need to use: _ksys_write_text (x coordinate, y coordinate, font type, line, line length);
You can write the program directly in Hummingbird. Open Tinypad , and write this code:
If you wrote the code not in Hummingbird, dump it on a USB flash drive along with the compiler . For example, I save the file as hello.c .
For people who can’t install Hummingbirds, you can connect a USB flash drive to a virtual machine:

To compile, open the directory where the compiler is in the console ( Shell ) and enter this command.
If everything is done correctly, we will see our program in the same directory. Now it can be started.
And we get the following picture:

For those who do not like to read a lot, a video tutorial on the topic:
I repeat that you can discuss ktcc (and programs for it) on our forum .
Answer: “Yes, it is possible!” , And below I will tell you how to do it.

To write a program, we need:
- A computer or virtual machine with KolibriOS (if you do not have KolibriOS installed, you can download it from our website ). Let me remind you that KolibriOS requires at least 8MB RAM and a Pentium-compatible CPU to work.
- A flash drive (if you are not writing the code in Hummingbird itself).
- Compiler TCC ( T iny C C ompiler). Assembly for Hummingbird ( mini_c_dev ) can be downloaded on our forum . A discussion topic about ktcc (Kolibri TCC) is here: board.kolibrios.org/viewtopic.php?f=45&t=565
Bit of theory
There are two types of programs in KolibriOS: window and console. A program with a GUI is written using the system functions and the BoxLib library . The console program is written using the console.obj library . The work with libraries will be described in the following articles; Today we will write a window application based on system functions.
The window application consists of the main () function , which has a special message handler:
while (!0) {
switch (_ksys_wait_for_event(10)) {
case 2:
return 0;
case 3:
if (_ksys_get_button_id() == 1)
return 0;
break;
default:
//Здесь задаются команды, с помощью которых можно нарисовать окно.
break;
}
}
}
In our program, we will only process keyboard events and button clicks. Their processing takes place in a while loop using switch - case.
Let's analyze these events:
2 - a key is pressed on the keyboard;
3 - the button is pressed, the button defined earlier (in this example, this is only the cross of closing the program, which is the button created with the window);
You can read more about the event system on our Wiki or in the documentation that comes with the OS (Docpack program on the desktop).
For the convenience of development, we will issue the commands that are responsible for the appearance of the window into a separate draw_window () function .
Now it's time to figure out how to draw a window.
Drawing a window starts with the _ksys_window_redraw (1) function , and ends with _ksys_window_redraw (2) . To draw a window, you need to use the _ksys_draw_window function (window coordinate by x, window coordinate by y, width, height, color, window type, window title color, whether the window is not movable, window frame color);
Window types:
0 - type I - window of fixed sizes (without skin)
1 - only determine the area of the window, do not draw anything
2 - type II - window of resizable (without skin)
3 - window with skin (resizable)
4 - window with fixed-size skin
Finally, to draw text, you need to use: _ksys_write_text (x coordinate, y coordinate, font type, line, line length);
Now you can proceed to the code itself
You can write the program directly in Hummingbird. Open Tinypad , and write this code:
#include
#include
#include
#define FONT0 0
#define FONT1 0x10000000
char header[] = {"Hello World!"};
#define BT_NORMAL 0
#define BT_DEL 0x80000000
#define BT_HIDE 0x40000000
#define BT_NOFRAME 0x20000000
void draw_window () {
_ksys_window_redraw(1);
_ksys_draw_window(100, 100, 300, 120, 0xaabbcc, 4, 0x5080d0, 0, 0x5080d0);
_ksys_write_text(50,30,FONT0, header, strlen(header));
_ksys_window_redraw(2);
}
int main (int argc, char **argv) {
while (!0) {
switch (_ksys_wait_for_event(10)) {
case 2:
return 0;
case 3:
if (_ksys_get_button_id() == 1)
return 0;
break;
default:
draw_window();
break;
}
}
}
Now is the time to compile!
If you wrote the code not in Hummingbird, dump it on a USB flash drive along with the compiler . For example, I save the file as hello.c .
For people who can’t install Hummingbirds, you can connect a USB flash drive to a virtual machine:

To compile, open the directory where the compiler is in the console ( Shell ) and enter this command.
ktcc.kex <имя_исходного_файла> libck.a –o <имя_готовой_программы>
If everything is done correctly, we will see our program in the same directory. Now it can be started.
And we get the following picture:

For those who do not like to read a lot, a video tutorial on the topic:
I repeat that you can discuss ktcc (and programs for it) on our forum .
Only registered users can participate in the survey. Please come in.
Does Habr need an article about using C cross-compilers for KolibriOS?
- 79.9% Yes 283
- 20% No 71