Subversion Repositories Kolibri OS

Rev

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