prog.c 959 B

1234567891011121314151617181920212223242526272829303132
  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. /* Pad binary past 1KB so it uses cluster 8+ (reproduces LBA 0x27 read failure on real HW). */
  8. static const char prog_padding[3072] __attribute__((used)) = { 0 };
  9. void _start(void)
  10. {
  11. (void)prog_padding; /* keep in binary */
  12. unsigned int cols, rows, cx, cy;
  13. const char *msg = "omg!";
  14. cols = api->get_cols();
  15. rows = api->get_rows();
  16. /* Center "omg!" (4 chars): x = (cols*8)/2 - (4*8)/2, y = (rows*10)/2 - 5 */
  17. cx = (cols * CHAR_WIDTH) / 2 - (4 * CHAR_WIDTH) / 2;
  18. cy = (rows * ROW_HEIGHT) / 2 - ROW_HEIGHT / 2;
  19. api->draw_string_xy(cx, cy, msg, 255, 255, 255, 0);
  20. while (api->poll_key() != IO_KEY_ESC)
  21. ;
  22. return;
  23. }