run_api.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* API passed to loaded program at PROGRAM_API_ADDR. Used by run command and by programs run via run (e.g. prog, space). */
  2. #ifndef RUN_API_H
  3. #define RUN_API_H
  4. /* Sits just below the program load area, inside the low 1 MB the frame
  5. * allocator reserves; keep in sync with run.c and user.ld. */
  6. #define PROGRAM_API_ADDR 0x7FF00
  7. #define IO_KEY_ESC 0x1B
  8. #define IO_KEY_SPACE 0x20
  9. #define IO_KEY_LEFT 0x100
  10. #define IO_KEY_RIGHT 0x101
  11. /* Function pointer types for the program API. */
  12. typedef void (*prog_draw_string_xy_t)(unsigned int x0, unsigned int y0,
  13. const char *str, unsigned int r_fg, unsigned int g_fg, unsigned int b_fg,
  14. int transparent_bg);
  15. typedef unsigned int (*prog_get_cols_t)(void);
  16. typedef unsigned int (*prog_get_rows_t)(void);
  17. typedef int (*prog_poll_key_t)(void);
  18. typedef int (*prog_poll_key_with_hw_t)(void);
  19. typedef unsigned int (*prog_get_fb_width_t)(void);
  20. typedef unsigned int (*prog_get_fb_height_t)(void);
  21. typedef void (*prog_clear_rgb_t)(unsigned int r, unsigned int g, unsigned int b);
  22. typedef void (*prog_put_pixel_rgb_t)(unsigned int x, unsigned int y,
  23. unsigned int r, unsigned int g, unsigned int b);
  24. typedef unsigned int (*prog_get_ticks_ms_t)(void);
  25. struct prog_api {
  26. prog_draw_string_xy_t draw_string_xy;
  27. prog_get_cols_t get_cols;
  28. prog_get_rows_t get_rows;
  29. prog_poll_key_t poll_key;
  30. prog_poll_key_with_hw_t poll_key_with_hw;
  31. prog_get_fb_width_t get_fb_width;
  32. prog_get_fb_height_t get_fb_height;
  33. prog_clear_rgb_t clear_rgb;
  34. prog_put_pixel_rgb_t put_pixel_rgb;
  35. prog_get_ticks_ms_t get_ticks_ms;
  36. };
  37. #endif