prog.c 752 B

12345678910111213141516171819202122232425262728
  1. /* Example user program: draws "omg!" centered, runs until ESC. Uses kernel API at PROGRAM_API_ADDR. */
  2. #include "prog_api.h"
  3. /* Character cell size used by fbtext (8px wide, 10px row height). */
  4. #define CHAR_WIDTH 8
  5. #define ROW_HEIGHT 10
  6. static const struct prog_api *const api = (const struct prog_api *)PROGRAM_API_ADDR;
  7. void _start(void)
  8. {
  9. unsigned int cols, rows, cx, cy;
  10. const char *msg = "omg!";
  11. cols = api->get_cols();
  12. rows = api->get_rows();
  13. /* Center "omg!" (4 chars): x = (cols*8)/2 - (4*8)/2, y = (rows*10)/2 - 5 */
  14. cx = (cols * CHAR_WIDTH) / 2 - (4 * CHAR_WIDTH) / 2;
  15. cy = (rows * ROW_HEIGHT) / 2 - ROW_HEIGHT / 2;
  16. api->draw_string_xy(cx, cy, msg, 255, 255, 255, 0);
  17. while (api->poll_key() != IO_KEY_ESC)
  18. ;
  19. return;
  20. }