Subversion Repositories Kolibri OS

Rev

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
  244. void *user_alloc(size_t size)
  245. {
  246.     void  *val;
  247.     __asm__ __volatile__(
  248.     "int $0x40"
  249.     :"=a"(val)
  250.     :"a"(68),"b"(12),"c"(size));
  251.     return val;
  252. }
  253.  
  254. static inline
  255. int user_free(void *mem)
  256. {
  257.     int  val;
  258.     __asm__ __volatile__(
  259.     "int $0x40"
  260.     :"=a"(val)
  261.     :"a"(68),"b"(12),"c"(mem));
  262.     return val;
  263. }
  264.  
  265. static inline
  266. int *user_unmap(void *base, size_t offset, size_t size)
  267. {
  268.     void  *val;
  269.     __asm__ __volatile__(
  270.     "int $0x40"
  271.     :"=a"(val)
  272.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  273.     return val;
  274. }
  275.  
  276. static inline int GetScreenSize()
  277. {
  278.      int retval;
  279.  
  280.      __asm__ __volatile__(
  281.      "int $0x40"
  282.      :"=a"(retval)
  283.      :"a"(61), "b"(1));
  284.      return retval;
  285. }
  286.  
  287. static inline
  288. uint32_t  load_cursor(void *path, uint32_t flags)
  289. {
  290.     uint32_t  val;
  291.     __asm__ __volatile__(
  292.     "int $0x40"
  293.     :"=a"(val)
  294.     :"a"(37), "b"(4), "c"(path), "d"(flags));
  295.     return val;
  296. }
  297.  
  298. static inline
  299. uint32_t  set_cursor(uint32_t  cursor)
  300. {
  301.     uint32_t  old;
  302.     __asm__ __volatile__(
  303.     "int $0x40"
  304.     :"=a"(old)
  305.     :"a"(37), "b"(5), "c"(cursor));
  306.     return old;
  307. }
  308.  
  309. static inline
  310. int destroy_cursor(uint32_t cursor)
  311. {
  312.     int ret;
  313.     __asm__ __volatile__(
  314.     "int $0x40"
  315.     :"=a"(ret)
  316.     :"a"(37), "b"(6), "c"(cursor)
  317.     :"memory");
  318.     return ret;
  319. };
  320.  
  321. static inline void get_proc_info(char *info)
  322. {
  323.     __asm__ __volatile__(
  324.     "int $0x40"
  325.     :
  326.     :"a"(9), "b"(info), "c"(-1));
  327. }
  328.  
  329. static inline
  330. void* user_realloc(void *mem, size_t size)
  331. {
  332.     void *val;
  333.     __asm__ __volatile__(
  334.     "int $0x40"
  335.     :"=a"(val)
  336.     :"a"(68),"b"(20),"c"(size),"d"(mem)
  337.     :"memory");
  338.  
  339.     return val;
  340. }
  341.  
  342. void *load_file(const char *path, size_t *len);
  343.  
  344. void *get_resource(void *data, uint32_t id);
  345.  
  346. struct blit_call
  347. {
  348.     int dstx;
  349.     int dsty;
  350.     int w;
  351.     int h;
  352.  
  353.     int srcx;
  354.     int srcy;
  355.     int srcw;
  356.     int srch;
  357.  
  358.     unsigned char *bitmap;
  359.     int   stride;
  360. };
  361.  
  362. void Blit(void *bitmap, int dst_x, int dst_y,
  363.                         int src_x, int src_y, int w, int h,
  364.                         int src_w, int src_h, int stride);
  365.  
  366.                        
  367. #endif
  368.  
  369.  
  370.  
  371.  
  372.  
  373.