Subversion Repositories Kolibri OS

Rev

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

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