Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include <newlib.h>
  3. #include <stdint.h>
  4. #include <stddef.h>
  5.  
  6. #ifdef CONFIG_DEBUF
  7.   #define DBG(format,...) printf(format,##__VA_ARGS__)
  8. #else
  9.   #define DBG(format,...)
  10. #endif
  11.  
  12. typedef  unsigned int color_t;
  13.  
  14. typedef union __attribute__((packed))
  15. {
  16.     uint32_t val;
  17.     struct
  18.     {
  19.         short  x;
  20.         short  y;
  21.     };
  22. }pos_t;
  23.  
  24. typedef union __attribute__((packed))
  25. {
  26.     uint32_t val;
  27.     struct
  28.     {
  29.         uint8_t   state;
  30.         uint8_t   code;
  31.         uint16_t  ctrl_key;
  32.     };
  33. }oskey_t;
  34.  
  35. static inline
  36. void BeginDraw(void)
  37. {
  38.     __asm__ __volatile__(
  39.     "int $0x40" ::"a"(12),"b"(1));
  40. };
  41.  
  42. static inline
  43. void EndDraw(void)
  44. {
  45.     __asm__ __volatile__(
  46.     "int $0x40" ::"a"(12),"b"(2));
  47. };
  48.  
  49. static inline void DrawWindow(int x, int y, int w, int h, char *name,
  50.                        color_t workcolor, uint32_t style)
  51. {
  52.  
  53.     __asm__ __volatile__(
  54.     "int $0x40"
  55.     ::"a"(0),
  56.       "b"((x << 16) | (w & 0xFFFF)),
  57.       "c"((y << 16) | (h & 0xFFFF)),
  58.       "d"((style << 24) | (workcolor & 0xFFFFFF)),
  59.       "D"(name));
  60. };
  61.  
  62. static inline
  63. pos_t get_mouse_pos(void)
  64. {
  65.     pos_t val;
  66.  
  67.     __asm__ __volatile__(
  68.     "int $0x40 \n\t"
  69.     "rol $16, %%eax"
  70.     :"=a"(val)
  71.     :"a"(37),"b"(1));
  72.     return val;
  73. }
  74.  
  75. static inline
  76. pos_t get_cursor_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"(0));
  85.     return val;
  86. }
  87.  
  88. static inline
  89. uint32_t get_mouse_buttons(void)
  90. {
  91.     uint32_t val;
  92.  
  93.     __asm__ __volatile__(
  94.     "int $0x40"
  95.     :"=a"(val)
  96.     :"a"(37),"b"(2));
  97.     return val;
  98. };
  99.  
  100. static inline
  101. uint32_t get_mouse_wheels(void)
  102. {
  103.     uint32_t val;
  104.  
  105.     __asm__ __volatile__(
  106.     "int $0x40 \n\t"
  107.     "rol $16, %%eax"
  108.     :"=a"(val)
  109.     :"a"(37),"b"(7));
  110.     return val;
  111. };
  112.  
  113. static inline
  114. uint32_t wait_for_event(uint32_t time)
  115. {
  116.     uint32_t val;
  117.     __asm__ __volatile__(
  118.     "int $0x40"
  119.     :"=a"(val)
  120.     :"a"(23), "b"(time));
  121.     return val;
  122. };
  123.  
  124. static inline uint32_t check_os_event()
  125. {
  126.     uint32_t val;
  127.     __asm__ __volatile__(
  128.     "int $0x40"
  129.     :"=a"(val)
  130.     :"a"(11));
  131.     return val;
  132. };
  133.  
  134. static inline
  135. uint32_t get_tick_count(void)
  136. {
  137.     uint32_t val;
  138.     __asm__ __volatile__(
  139.     "int $0x40"
  140.     :"=a"(val)
  141.     :"a"(26),"b"(9));
  142.     return val;
  143. };
  144.  
  145. static inline
  146. oskey_t get_key(void)
  147. {
  148.     oskey_t val;
  149.     __asm__ __volatile__(
  150.     "int $0x40"
  151.     :"=a"(val)
  152.     :"a"(2));
  153.     return val;
  154. }
  155.  
  156. static inline
  157. void draw_line(int xs, int ys, int xe, int ye, color_t color)
  158. {
  159.     __asm__ __volatile__(
  160.     "int $0x40"
  161.     ::"a"(38), "d"(color),
  162.       "b"((xs << 16) | xe),
  163.       "c"((ys << 16) | ye));
  164. }
  165.  
  166.  
  167.  
  168. static inline
  169. void draw_bar(int x, int y, int w, int h, color_t color)
  170. {
  171.     __asm__ __volatile__(
  172.     "int $0x40"
  173.     ::"a"(13), "d"(color),
  174.       "b"((x << 16) | w),
  175.       "c"((y << 16) | h));
  176. }
  177.  
  178. static inline
  179. void draw_bitmap(void *bitmap, int x, int y, int w, int h)
  180. {
  181.     __asm__ __volatile__(
  182.     "int $0x40"
  183.     ::"a"(7), "b"(bitmap),
  184.       "c"((w << 16) | h),
  185.       "d"((x << 16) | y));
  186. }
  187.  
  188. #if 0
  189. static inline
  190. void draw_text_sys(const char *text, int x, int y, int len, color_t color)
  191. {
  192.     __asm__ __volatile__(
  193.     "int $0x40"
  194.     ::"a"(4),"d"(text),
  195.       "b"((x << 16) | y),
  196.       "S"(len),"c"(color));
  197. }
  198. #endif
  199.  
  200. static inline
  201. void *user_alloc(size_t size)
  202. {
  203.     void  *val;
  204.     __asm__ __volatile__(
  205.     "int $0x40"
  206.     :"=a"(val)
  207.     :"a"(68),"b"(12),"c"(size));
  208.     return val;
  209. }
  210.  
  211. static inline
  212. int user_free(void *mem)
  213. {
  214.     int  val;
  215.     __asm__ __volatile__(
  216.     "int $0x40"
  217.     :"=a"(val)
  218.     :"a"(68),"b"(12),"c"(mem));
  219.     return val;
  220. }
  221.  
  222. static inline
  223. int *user_unmap(void *base, size_t offset, size_t size)
  224. {
  225.     void  *val;
  226.     __asm__ __volatile__(
  227.     "int $0x40"
  228.     :"=a"(val)
  229.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  230.     return val;
  231. }
  232.  
  233. /*
  234. extern inline
  235. void    exit(int status)  __attribute__((noreturn)) ;
  236.  
  237. extern inline
  238. void    exit(int status)
  239. {
  240.     __asm__ __volatile__(
  241.     "int $0x40"
  242.     ::"a"(-1));
  243.     for(;;);
  244. }
  245. */
  246.  
  247. static inline
  248. uint32_t  load_cursor(void *path, uint32_t flags)
  249. {
  250.     uint32_t  val;
  251.     __asm__ __volatile__(
  252.     "int $0x40"
  253.     :"=a"(val)
  254.     :"a"(37), "b"(4), "c"(path), "d"(flags));
  255.     return val;
  256. }
  257.  
  258. static inline
  259. uint32_t  set_cursor(uint32_t  cursor)
  260. {
  261.     uint32_t  old;
  262.     __asm__ __volatile__(
  263.     "int $0x40"
  264.     :"=a"(old)
  265.     :"a"(37), "b"(5), "c"(cursor));
  266.     return old;
  267. }
  268.  
  269. static inline
  270. int destroy_cursor(uint32_t cursor)
  271. {
  272.     int ret;
  273.     __asm__ __volatile__(
  274.     "int $0x40"
  275.     :"=a"(ret)
  276.     :"a"(37), "b"(6), "c"(cursor)
  277.     :"memory");
  278.     return ret;
  279. };
  280.  
  281.  
  282. static inline void get_proc_info(char *info)
  283. {
  284.     __asm__ __volatile__(
  285.     "int $0x40"
  286.     :
  287.     :"a"(9), "b"(info), "c"(-1));
  288. }
  289.  
  290. static inline
  291. void* user_realloc(void *mem, size_t size)
  292. {
  293.     void *val;
  294.     __asm__ __volatile__(
  295.     "int $0x40"
  296.     :"=a"(val)
  297.     :"a"(68),"b"(12),"c"(size),"d"(mem)
  298.     :"memory");
  299.  
  300.     return val;
  301. }
  302.  
  303. void *load_file(const char *path, size_t *len);
  304.  
  305. void *get_resource(void *data, uint32_t id);
  306.  
  307. struct blit_call
  308. {
  309.     int dstx;
  310.     int dsty;
  311.     int w;
  312.     int h;
  313.  
  314.     int srcx;
  315.     int srcy;
  316.     int srcw;
  317.     int srch;
  318.  
  319.     unsigned char *bitmap;
  320.     int   stride;
  321. };
  322.  
  323. void Blit(void *bitmap, int dst_x, int dst_y,
  324.                         int src_x, int src_y, int w, int h,
  325.                         int src_w, int src_h, int stride);
  326.  
  327.