Subversion Repositories Kolibri OS

Rev

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