Subversion Repositories Kolibri OS

Rev

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