Subversion Repositories Kolibri OS

Rev

Rev 2427 | 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. static inline
  189. void draw_text(const char *text, int x, int y, int len, color_t color)
  190. {
  191.     __asm__ __volatile__(
  192.     "int $0x40"
  193.     ::"a"(4),"d"(text),
  194.       "b"((x << 16) | y),
  195.       "S"(len),"c"(color));
  196. }
  197.  
  198. static inline
  199. void *user_alloc(size_t size)
  200. {
  201.     void  *val;
  202.     __asm__ __volatile__(
  203.     "int $0x40"
  204.     :"=a"(val)
  205.     :"a"(68),"b"(12),"c"(size));
  206.     return val;
  207. }
  208.  
  209. static inline
  210. int user_free(void *mem)
  211. {
  212.     int  val;
  213.     __asm__ __volatile__(
  214.     "int $0x40"
  215.     :"=a"(val)
  216.     :"a"(68),"b"(12),"c"(mem));
  217.     return val;
  218. }
  219.  
  220. static inline
  221. int *user_unmap(void *base, size_t offset, size_t size)
  222. {
  223.     void  *val;
  224.     __asm__ __volatile__(
  225.     "int $0x40"
  226.     :"=a"(val)
  227.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  228.     return val;
  229. }
  230.  
  231. /*
  232. extern inline
  233. void    exit(int status)  __attribute__((noreturn)) ;
  234.  
  235. extern inline
  236. void    exit(int status)
  237. {
  238.     __asm__ __volatile__(
  239.     "int $0x40"
  240.     ::"a"(-1));
  241.     for(;;);
  242. }
  243. */
  244.  
  245. static inline
  246. uint32_t  load_cursor(void *path, uint32_t flags)
  247. {
  248.     uint32_t  val;
  249.     __asm__ __volatile__(
  250.     "int $0x40"
  251.     :"=a"(val)
  252.     :"a"(37), "b"(4), "c"(path), "d"(flags));
  253.     return val;
  254. }
  255.  
  256. static inline
  257. uint32_t  set_cursor(uint32_t  cursor)
  258. {
  259.     uint32_t  old;
  260.     __asm__ __volatile__(
  261.     "int $0x40"
  262.     :"=a"(old)
  263.     :"a"(37), "b"(5), "c"(cursor));
  264.     return old;
  265. }
  266.  
  267. static inline
  268. int destroy_cursor(uint32_t cursor)
  269. {
  270.     int ret;
  271.     __asm__ __volatile__(
  272.     "int $0x40"
  273.     :"=a"(ret)
  274.     :"a"(37), "b"(6), "c"(cursor)
  275.     :"memory");
  276.     return ret;
  277. };
  278.  
  279. static inline void get_proc_info(char *info)
  280. {
  281.     __asm__ __volatile__(
  282.     "int $0x40"
  283.     :
  284.     :"a"(9), "b"(info), "c"(-1));
  285. }
  286.  
  287. static inline
  288. void* user_realloc(void *mem, size_t size)
  289. {
  290.     void *val;
  291.     __asm__ __volatile__(
  292.     "int $0x40"
  293.     :"=a"(val)
  294.     :"a"(68),"b"(20),"c"(size),"d"(mem)
  295.     :"memory");
  296.  
  297.     return val;
  298. }
  299.  
  300. void *load_file(const char *path, size_t *len);
  301.  
  302. void *get_resource(void *data, uint32_t id);
  303.  
  304. struct blit_call
  305. {
  306.     int dstx;
  307.     int dsty;
  308.     int w;
  309.     int h;
  310.  
  311.     int srcx;
  312.     int srcy;
  313.     int srcw;
  314.     int srch;
  315.  
  316.     unsigned char *bitmap;
  317.     int   stride;
  318. };
  319.  
  320. void Blit(void *bitmap, int dst_x, int dst_y,
  321.                         int src_x, int src_y, int w, int h,
  322.                         int src_w, int src_h, int stride);
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.