Many people ask themselves: “Is it possible to write a C program under KolibriOS?” Answer: “Yes, you can!” , And below I will tell you how to do it.
To write the program, we need:
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 write code not in the Hummingbird itself).
In KolibriOS there are two types of programs: window and console. A GUI program is written using system functions and the BoxLib library. The console program is written using the console.obj library. Work with libraries will be discussed in the following articles; Today we will write a window application based on system functions.
A windowing application consists of a main () function, in which there is a special message handler: ')
In our program, we will handle only keyboard events and button presses. They are processed in a while loop using switch - case.
Let's sort these events: 2 - key is pressed on the keyboard; 3 - the button, the button defined earlier is pressed (in this example it is only a cross of the program’s close, which is the button created together with the window); More details about the event system can be found on our Wiki or in the documentation supplied with the OS (Docpack program on the desktop).
For ease of development, we will move the commands that are responsible for the appearance of the window into a separate function, draw_window () .
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 in x, window coordinate in y, width, height, color, window type, window title color, whether the window is not relocatable, window frame color);
Types of windows: 0 - type I - fixed-size window (no skin) 1 - only define the window area, draw nothing 2 - type II - resizable window (without skin) 3 - window with skin (resizable) 4 - window with a fixed size skin
And finally, to draw text, you need to use: _ksys_write_text (x coordinate, y coordinate, font type, string, string length);
Now you can proceed to the code itself
You can write the program directly in KolibriOS. Open Tinypad , and write this code:
If you did not write the code in Hummingbird, reset it to a USB flash drive along with the compiler . For example, I save the file as hello.c . For people who can not install Hummingbirds, you can connect a USB flash drive to a virtual machine:
To compile, open in the console ( Shell ) the directory where the compiler is located, and enter this command ktcc.kex <__> libck.a –o <__>
If everything is done correctly, we will see our program in the same directory. Now you can run it. And we get the following picture:
For those who do not like to read a lot, video tutorial on the topic:
I repeat that you can discuss ktcc (and programs for it) on our forum .