Subversion Repositories Kolibri OS

Rev

Rev 5081 | 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) : "memory");
  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.      :"memory");
  280. }
  281.  
  282. static inline void yield(void)
  283. {
  284.     __asm__ __volatile__(
  285.     "int $0x40"
  286.     ::"a"(68), "b"(1));
  287. };
  288.  
  289. static inline void delay(uint32_t time)
  290. {
  291.     __asm__ __volatile__(
  292.     "int $0x40"
  293.     ::"a"(5), "b"(time)
  294.     :"memory");
  295. };
  296.  
  297. static inline
  298. void *user_alloc(size_t size)
  299. {
  300.     void  *val;
  301.     __asm__ __volatile__(
  302.     "int $0x40"
  303.     :"=a"(val)
  304.     :"a"(68),"b"(12),"c"(size));
  305.     return val;
  306. }
  307. static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
  308.  
  309. static inline
  310. int user_free(void *mem)
  311. {
  312.     int  val;
  313.     __asm__ __volatile__(
  314.     "int $0x40"
  315.     :"=a"(val)
  316.     :"a"(68),"b"(13),"c"(mem));
  317.     return val;
  318. }
  319. static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
  320.  
  321. static inline
  322. int *user_unmap(void *base, size_t offset, size_t size)
  323. {
  324.     int  *val;
  325.     __asm__ __volatile__(
  326.     "int $0x40"
  327.     :"=a"(val)
  328.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  329.     return val;
  330. };
  331. static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
  332.  
  333. typedef union
  334. {
  335.     struct
  336.     {
  337.         void   *data;
  338.         size_t  size;
  339.     };
  340.     unsigned long long raw;
  341. }ufile_t;
  342.  
  343.  
  344. static inline ufile_t load_file(const char *path)
  345. {
  346.     ufile_t uf;
  347.  
  348.     __asm__ __volatile__ (
  349.     "int $0x40"
  350.     :"=A"(uf.raw)
  351.     :"a" (68), "b"(27),"c"(path));
  352.  
  353.     return uf;
  354. };
  355. static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
  356.  
  357. static inline int GetScreenSize()
  358. {
  359.     int retval;
  360.  
  361.     __asm__ __volatile__(
  362.     "int $0x40"
  363.     :"=a"(retval)
  364.     :"a"(61), "b"(1));
  365.     return retval;
  366. }
  367.  
  368. static inline
  369. uint32_t  load_cursor(void *path, uint32_t flags)
  370. {
  371.     uint32_t  val;
  372.     __asm__ __volatile__(
  373.     "int $0x40"
  374.     :"=a"(val)
  375.     :"a"(37), "b"(4), "c"(path), "d"(flags));
  376.     return val;
  377. }
  378. static inline
  379. uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
  380.  
  381. static inline
  382. uint32_t  set_cursor(uint32_t  cursor)
  383. {
  384.     uint32_t  old;
  385.     __asm__ __volatile__(
  386.     "int $0x40"
  387.     :"=a"(old)
  388.     :"a"(37), "b"(5), "c"(cursor));
  389.     return old;
  390. };
  391. static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));
  392.  
  393. static inline
  394. int destroy_cursor(uint32_t cursor)
  395. {
  396.     int ret;
  397.     __asm__ __volatile__(
  398.     "int $0x40"
  399.     :"=a"(ret)
  400.     :"a"(37), "b"(6), "c"(cursor)
  401.     :"memory");
  402.     return ret;
  403. };
  404. static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
  405.  
  406. static inline void get_proc_info(char *info)
  407. {
  408.     __asm__ __volatile__(
  409.     "int $0x40"
  410.     :
  411.     :"a"(9), "b"(info), "c"(-1));
  412. };
  413. static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
  414.  
  415. static inline
  416. void* user_realloc(void *mem, size_t size)
  417. {
  418.     void *val;
  419.     __asm__ __volatile__(
  420.     "int $0x40"
  421.     :"=a"(val)
  422.     :"a"(68),"b"(20),"c"(size),"d"(mem)
  423.     :"memory");
  424.  
  425.     return val;
  426. };
  427. static inline void* UserRrealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
  428.  
  429. void *get_resource(void *data, uint32_t id);
  430.  
  431. struct blit_call
  432. {
  433.     int dstx;
  434.     int dsty;
  435.     int w;
  436.     int h;
  437.  
  438.     int srcx;
  439.     int srcy;
  440.     int srcw;
  441.     int srch;
  442.  
  443.     unsigned char *bitmap;
  444.     int   stride;
  445. };
  446.  
  447. static inline void Blit(void *bitmap, int dst_x, int dst_y,
  448.                         int src_x, int src_y, int w, int h,
  449.                         int src_w, int src_h, int stride)
  450. {
  451.     volatile struct blit_call bc;
  452.  
  453.     bc.dstx = dst_x;
  454.     bc.dsty = dst_y;
  455.     bc.w    = w;
  456.     bc.h    = h;
  457.     bc.srcx = src_x;
  458.     bc.srcy = src_y;
  459.     bc.srcw = src_w;
  460.     bc.srch = src_h;
  461.     bc.stride = stride;
  462.     bc.bitmap = bitmap;
  463.  
  464.     __asm__ __volatile__(
  465.     "int $0x40"
  466.     ::"a"(73),"b"(0),"c"(&bc.dstx));
  467. };
  468.  
  469. #endif
  470.  
  471.  
  472.  
  473.  
  474.  
  475.