Subversion Repositories Kolibri OS

Rev

Rev 3900 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef __KOS_32_SYS_H__
  2. #define __KOS_32_SYS_H__
  3.  
  4.  
  5. #include <newlib.h>
  6. #include <stdint.h>
  7. #include <stddef.h>
  8.  
  9. #ifdef CONFIG_DEBUF
  10.   #define DBG(format,...) printf(format,##__VA_ARGS__)
  11. #else
  12.   #define DBG(format,...)
  13. #endif
  14.  
  15. typedef  unsigned int color_t;
  16.  
  17. typedef union __attribute__((packed))
  18. {
  19.     uint32_t val;
  20.     struct
  21.     {
  22.         short  x;
  23.         short  y;
  24.     };
  25. }pos_t;
  26.  
  27. typedef union __attribute__((packed))
  28. {
  29.     uint32_t val;
  30.     struct
  31.     {
  32.         uint8_t   state;
  33.         uint8_t   code;
  34.         uint16_t  ctrl_key;
  35.     };
  36. }oskey_t;
  37.  
  38. typedef struct
  39. {
  40.   unsigned      handle;
  41.   unsigned      io_code;
  42.   void          *input;
  43.   int           inp_size;
  44.   void          *output;
  45.   int           out_size;
  46. }ioctl_t;
  47.  
  48.  
  49. static inline
  50. void DefineButton(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
  51. {
  52.     __asm__ __volatile__(
  53.     "int $0x40"
  54.     ::"a"(8),
  55.       "b"(x_w),
  56.       "c"(y_h),
  57.       "d"(id),
  58.       "S"(color));
  59.  
  60.  
  61. };
  62.  
  63. static inline
  64. void BeginDraw(void)
  65. {
  66.     __asm__ __volatile__(
  67.     "int $0x40" ::"a"(12),"b"(1));
  68. };
  69.  
  70. static inline
  71. void EndDraw(void)
  72. {
  73.     __asm__ __volatile__(
  74.     "int $0x40" ::"a"(12),"b"(2));
  75. };
  76.  
  77. static inline void DrawWindow(int x, int y, int w, int h, char *name,
  78.                        color_t workcolor, uint32_t style)
  79. {
  80.  
  81.     __asm__ __volatile__(
  82.     "int $0x40"
  83.     ::"a"(0),
  84.       "b"((x << 16) | (w & 0xFFFF)),
  85.       "c"((y << 16) | (h & 0xFFFF)),
  86.       "d"((style << 24) | (workcolor & 0xFFFFFF)),
  87.       "D"(name));
  88. };
  89.  
  90. static inline
  91. pos_t get_mouse_pos(void)
  92. {
  93.     pos_t val;
  94.  
  95.     __asm__ __volatile__(
  96.     "int $0x40 \n\t"
  97.     "rol $16, %%eax"
  98.     :"=a"(val)
  99.     :"a"(37),"b"(1));
  100.     return val;
  101. }
  102.  
  103. static inline
  104. pos_t get_cursor_pos(void)
  105. {
  106.     pos_t val;
  107.  
  108.     __asm__ __volatile__(
  109.     "int $0x40 \n\t"
  110.     "rol $16, %%eax"
  111.     :"=a"(val)
  112.     :"a"(37),"b"(0));
  113.     return val;
  114. }
  115.  
  116. static inline
  117. uint32_t get_mouse_buttons(void)
  118. {
  119.     uint32_t val;
  120.  
  121.     __asm__ __volatile__(
  122.     "int $0x40"
  123.     :"=a"(val)
  124.     :"a"(37),"b"(2));
  125.     return val;
  126. };
  127.  
  128. static inline
  129. uint32_t get_mouse_wheels(void)
  130. {
  131.     uint32_t val;
  132.  
  133.     __asm__ __volatile__(
  134.     "int $0x40 \n\t"
  135.     "rol $16, %%eax"
  136.     :"=a"(val)
  137.     :"a"(37),"b"(7));
  138.     return val;
  139. };
  140.  
  141. static inline
  142. uint32_t wait_for_event(uint32_t time)
  143. {
  144.     uint32_t val;
  145.     __asm__ __volatile__(
  146.     "int $0x40"
  147.     :"=a"(val)
  148.     :"a"(23), "b"(time));
  149.     return val;
  150. };
  151.  
  152. static inline uint32_t check_os_event()
  153. {
  154.     uint32_t val;
  155.     __asm__ __volatile__(
  156.     "int $0x40"
  157.     :"=a"(val)
  158.     :"a"(11));
  159.     return val;
  160. };
  161.  
  162. static inline
  163. uint32_t get_tick_count(void)
  164. {
  165.     uint32_t val;
  166.     __asm__ __volatile__(
  167.     "int $0x40"
  168.     :"=a"(val)
  169.     :"a"(26),"b"(9));
  170.     return val;
  171. };
  172.  
  173. static inline
  174. oskey_t get_key(void)
  175. {
  176.     oskey_t val;
  177.     __asm__ __volatile__(
  178.     "int $0x40"
  179.     :"=a"(val)
  180.     :"a"(2));
  181.     return val;
  182. }
  183.  
  184. static inline
  185. uint32_t get_os_button()
  186. {
  187.     uint32_t val;
  188.     __asm__ __volatile__(
  189.     "int $0x40"
  190.     :"=a"(val)
  191.     :"a"(17));
  192.     return val>>8;
  193. };
  194.  
  195. static inline uint32_t get_service(char *name)
  196. {
  197.   uint32_t retval = 0;
  198.   asm volatile ("int $0x40"
  199.       :"=a"(retval)
  200.       :"a"(68),"b"(16),"c"(name)
  201.       :"memory");
  202.  
  203.   return retval;
  204. };
  205.  
  206. static inline int call_service(ioctl_t *io)
  207. {
  208.   int retval;
  209.  
  210.   asm volatile("int $0x40"
  211.       :"=a"(retval)
  212.       :"a"(68),"b"(17),"c"(io)
  213.       :"memory","cc");
  214.  
  215.   return retval;
  216. };
  217.  
  218.  
  219. static inline
  220. void draw_line(int xs, int ys, int xe, int ye, color_t color)
  221. {
  222.     __asm__ __volatile__(
  223.     "int $0x40"
  224.     ::"a"(38), "d"(color),
  225.       "b"((xs << 16) | xe),
  226.       "c"((ys << 16) | ye));
  227. }
  228.  
  229.  
  230.  
  231. static inline
  232. void draw_bar(int x, int y, int w, int h, color_t color)
  233. {
  234.     __asm__ __volatile__(
  235.     "int $0x40"
  236.     ::"a"(13), "d"(color),
  237.       "b"((x << 16) | w),
  238.       "c"((y << 16) | h));
  239. }
  240.  
  241. static inline
  242. void draw_bitmap(void *bitmap, int x, int y, int w, int h)
  243. {
  244.     __asm__ __volatile__(
  245.     "int $0x40"
  246.     ::"a"(7), "b"(bitmap),
  247.       "c"((w << 16) | h),
  248.       "d"((x << 16) | y));
  249. }
  250.  
  251. static inline
  252. void draw_text_sys(const char *text, int x, int y, int len, color_t color)
  253. {
  254.     __asm__ __volatile__(
  255.     "int $0x40"
  256.     ::"a"(4),"d"(text),
  257.       "b"((x << 16) | y),
  258.       "S"(len),"c"(color));
  259. }
  260.  
  261. static inline void yield(void)
  262. {
  263.     __asm__ __volatile__(
  264.     "int $0x40"
  265.     ::"a"(68), "b"(1));
  266. };
  267.  
  268. static inline void delay(uint32_t time)
  269. {
  270.     __asm__ __volatile__(
  271.     "int $0x40"
  272.     ::"a"(5), "b"(time)
  273.     :"memory");
  274. };
  275.  
  276. static inline
  277. void *user_alloc(size_t size)
  278. {
  279.     void  *val;
  280.     __asm__ __volatile__(
  281.     "int $0x40"
  282.     :"=a"(val)
  283.     :"a"(68),"b"(12),"c"(size));
  284.     return val;
  285. }
  286.  
  287. static inline
  288. int user_free(void *mem)
  289. {
  290.     int  val;
  291.     __asm__ __volatile__(
  292.     "int $0x40"
  293.     :"=a"(val)
  294.     :"a"(68),"b"(12),"c"(mem));
  295.     return val;
  296. }
  297.  
  298. static inline
  299. int *user_unmap(void *base, size_t offset, size_t size)
  300. {
  301.     void  *val;
  302.     __asm__ __volatile__(
  303.     "int $0x40"
  304.     :"=a"(val)
  305.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  306.     return val;
  307. }
  308.  
  309. typedef union
  310. {
  311.     struct
  312.     {
  313.         void   *data;
  314.         size_t  size;
  315.     };
  316.     unsigned long long raw;
  317. }ufile_t;
  318.  
  319.  
  320. static inline ufile_t load_file(const char *path)
  321. {
  322.      ufile_t uf;
  323.  
  324.      __asm__ __volatile__ (
  325.      "int $0x40"
  326.      :"=A"(uf.raw)
  327.      :"a" (68), "b"(27),"c"(path));
  328.  
  329.      return uf;
  330. };
  331.  
  332.  
  333. static inline int GetScreenSize()
  334. {
  335.      int retval;
  336.  
  337.      __asm__ __volatile__(
  338.      "int $0x40"
  339.      :"=a"(retval)
  340.      :"a"(61), "b"(1));
  341.      return retval;
  342. }
  343.  
  344. static inline
  345. uint32_t  load_cursor(void *path, uint32_t flags)
  346. {
  347.     uint32_t  val;
  348.     __asm__ __volatile__(
  349.     "int $0x40"
  350.     :"=a"(val)
  351.     :"a"(37), "b"(4), "c"(path), "d"(flags));
  352.     return val;
  353. }
  354.  
  355. static inline
  356. uint32_t  set_cursor(uint32_t  cursor)
  357. {
  358.     uint32_t  old;
  359.     __asm__ __volatile__(
  360.     "int $0x40"
  361.     :"=a"(old)
  362.     :"a"(37), "b"(5), "c"(cursor));
  363.     return old;
  364. }
  365.  
  366. static inline
  367. int destroy_cursor(uint32_t cursor)
  368. {
  369.     int ret;
  370.     __asm__ __volatile__(
  371.     "int $0x40"
  372.     :"=a"(ret)
  373.     :"a"(37), "b"(6), "c"(cursor)
  374.     :"memory");
  375.     return ret;
  376. };
  377.  
  378. static inline void get_proc_info(char *info)
  379. {
  380.     __asm__ __volatile__(
  381.     "int $0x40"
  382.     :
  383.     :"a"(9), "b"(info), "c"(-1));
  384. }
  385.  
  386. static inline
  387. void* user_realloc(void *mem, size_t size)
  388. {
  389.     void *val;
  390.     __asm__ __volatile__(
  391.     "int $0x40"
  392.     :"=a"(val)
  393.     :"a"(68),"b"(20),"c"(size),"d"(mem)
  394.     :"memory");
  395.  
  396.     return val;
  397. }
  398.  
  399.  
  400. void *get_resource(void *data, uint32_t id);
  401.  
  402. struct blit_call
  403. {
  404.     int dstx;
  405.     int dsty;
  406.     int w;
  407.     int h;
  408.  
  409.     int srcx;
  410.     int srcy;
  411.     int srcw;
  412.     int srch;
  413.  
  414.     unsigned char *bitmap;
  415.     int   stride;
  416. };
  417.  
  418. void Blit(void *bitmap, int dst_x, int dst_y,
  419.                         int src_x, int src_y, int w, int h,
  420.                         int src_w, int src_h, int stride);
  421.  
  422.  
  423. #endif
  424.  
  425.  
  426.  
  427.  
  428.  
  429.