Subversion Repositories Kolibri OS

Rev

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