Subversion Repositories Kolibri OS

Rev

Rev 5369 | 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. oskey_t get_key(void)
  198. {
  199.     oskey_t val;
  200.     __asm__ __volatile__(
  201.     "int $0x40"
  202.     :"=a"(val)
  203.     :"a"(2));
  204.     return val;
  205. }
  206.  
  207. static inline
  208. uint32_t get_os_button()
  209. {
  210.     uint32_t val;
  211.     __asm__ __volatile__(
  212.     "int $0x40"
  213.     :"=a"(val)
  214.     :"a"(17));
  215.     return val>>8;
  216. };
  217.  
  218. static inline uint32_t get_service(char *name)
  219. {
  220.     uint32_t retval = 0;
  221.     __asm__ __volatile__(
  222.     "int $0x40"
  223.     :"=a"(retval)
  224.     :"a"(68),"b"(16),"c"(name)
  225.     :"memory");
  226.  
  227.     return retval;
  228. };
  229.  
  230. static inline int call_service(ioctl_t *io)
  231. {
  232.     int retval;
  233.  
  234.     __asm__ __volatile__(
  235.     "int $0x40"
  236.     :"=a"(retval)
  237.     :"a"(68),"b"(17),"c"(io)
  238.     :"memory","cc");
  239.  
  240.     return retval;
  241. };
  242.  
  243.  
  244. static inline
  245. void draw_line(int xs, int ys, int xe, int ye, color_t color)
  246. {
  247.     __asm__ __volatile__(
  248.     "int $0x40"
  249.     ::"a"(38), "d"(color),
  250.       "b"((xs << 16) | xe),
  251.       "c"((ys << 16) | ye));
  252. }
  253.  
  254.  
  255.  
  256. static inline
  257. void draw_bar(int x, int y, int w, int h, color_t color)
  258. {
  259.     __asm__ __volatile__(
  260.     "int $0x40"
  261.     ::"a"(13), "d"(color),
  262.       "b"((x << 16) | w),
  263.       "c"((y << 16) | h));
  264. }
  265.  
  266. static inline
  267. void draw_bitmap(void *bitmap, int x, int y, int w, int h)
  268. {
  269.     __asm__ __volatile__(
  270.     "int $0x40"
  271.     ::"a"(7), "b"(bitmap),
  272.       "c"((w << 16) | h),
  273.       "d"((x << 16) | y));
  274. }
  275.  
  276. static inline
  277. void draw_text_sys(const char *text, int x, int y, int len, color_t color)
  278. {
  279.     __asm__ __volatile__(
  280.     "int $0x40"
  281.     ::"a"(4),"d"(text),
  282.       "b"((x << 16) | y),
  283.       "S"(len),"c"(color)
  284.      :"memory");
  285. }
  286.  
  287. static inline void yield(void)
  288. {
  289.     __asm__ __volatile__(
  290.     "int $0x40"
  291.     ::"a"(68), "b"(1));
  292. };
  293.  
  294. static inline void delay(uint32_t time)
  295. {
  296.     __asm__ __volatile__(
  297.     "int $0x40"
  298.     ::"a"(5), "b"(time)
  299.     :"memory");
  300. };
  301.  
  302. static inline
  303. void *user_alloc(size_t size)
  304. {
  305.     void  *val;
  306.     __asm__ __volatile__(
  307.     "int $0x40"
  308.     :"=a"(val)
  309.     :"a"(68),"b"(12),"c"(size));
  310.     return val;
  311. }
  312. static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
  313.  
  314. static inline
  315. int user_free(void *mem)
  316. {
  317.     int  val;
  318.     __asm__ __volatile__(
  319.     "int $0x40"
  320.     :"=a"(val)
  321.     :"a"(68),"b"(13),"c"(mem));
  322.     return val;
  323. }
  324. static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
  325.  
  326. static inline
  327. int *user_unmap(void *base, size_t offset, size_t size)
  328. {
  329.     int  *val;
  330.     __asm__ __volatile__(
  331.     "int $0x40"
  332.     :"=a"(val)
  333.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  334.     return val;
  335. };
  336. static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
  337.  
  338. typedef union
  339. {
  340.     struct
  341.     {
  342.         void   *data;
  343.         size_t  size;
  344.     };
  345.     unsigned long long raw;
  346. }ufile_t;
  347.  
  348.  
  349. static inline ufile_t load_file(const char *path)
  350. {
  351.     ufile_t uf;
  352.  
  353.     __asm__ __volatile__ (
  354.     "int $0x40"
  355.     :"=A"(uf.raw)
  356.     :"a" (68), "b"(27),"c"(path));
  357.  
  358.     return uf;
  359. };
  360. static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
  361.  
  362. static inline int GetScreenSize()
  363. {
  364.     int retval;
  365.  
  366.     __asm__ __volatile__(
  367.     "int $0x40"
  368.     :"=a"(retval)
  369.     :"a"(61), "b"(1));
  370.     return retval;
  371. }
  372.  
  373. static inline
  374. uint32_t  load_cursor(void *path, uint32_t flags)
  375. {
  376.     uint32_t  val;
  377.     __asm__ __volatile__(
  378.     "int $0x40"
  379.     :"=a"(val)
  380.     :"a"(37), "b"(4), "c"(path), "d"(flags));
  381.     return val;
  382. }
  383. static inline
  384. uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
  385.  
  386. static inline
  387. uint32_t  set_cursor(uint32_t  cursor)
  388. {
  389.     uint32_t  old;
  390.     __asm__ __volatile__(
  391.     "int $0x40"
  392.     :"=a"(old)
  393.     :"a"(37), "b"(5), "c"(cursor));
  394.     return old;
  395. };
  396. static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));
  397.  
  398. static inline
  399. int destroy_cursor(uint32_t cursor)
  400. {
  401.     int ret;
  402.     __asm__ __volatile__(
  403.     "int $0x40"
  404.     :"=a"(ret)
  405.     :"a"(37), "b"(6), "c"(cursor)
  406.     :"memory");
  407.     return ret;
  408. };
  409. static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
  410.  
  411. static inline void get_proc_info(char *info)
  412. {
  413.     __asm__ __volatile__(
  414.     "int $0x40"
  415.     :
  416.     :"a"(9), "b"(info), "c"(-1));
  417. };
  418. static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
  419.  
  420. static inline
  421. void* user_realloc(void *mem, size_t size)
  422. {
  423.     void *val;
  424.     __asm__ __volatile__(
  425.     "int $0x40"
  426.     :"=a"(val)
  427.     :"a"(68),"b"(20),"c"(size),"d"(mem)
  428.     :"memory");
  429.  
  430.     return val;
  431. };
  432. static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
  433.  
  434. void *get_resource(void *data, uint32_t id);
  435.  
  436. struct blit_call
  437. {
  438.     int dstx;
  439.     int dsty;
  440.     int w;
  441.     int h;
  442.  
  443.     int srcx;
  444.     int srcy;
  445.     int srcw;
  446.     int srch;
  447.  
  448.     void *bitmap;
  449.     int   stride;
  450. };
  451.  
  452. static inline void Blit(void *bitmap, int dst_x, int dst_y,
  453.                         int src_x, int src_y, int w, int h,
  454.                         int src_w, int src_h, int stride)
  455. {
  456.     volatile struct blit_call bc;
  457.  
  458.     bc.dstx = dst_x;
  459.     bc.dsty = dst_y;
  460.     bc.w    = w;
  461.     bc.h    = h;
  462.     bc.srcx = src_x;
  463.     bc.srcy = src_y;
  464.     bc.srcw = src_w;
  465.     bc.srch = src_h;
  466.     bc.stride = stride;
  467.     bc.bitmap = bitmap;
  468.  
  469.     __asm__ __volatile__(
  470.     "int $0x40"
  471.     ::"a"(73),"b"(0),"c"(&bc.dstx));
  472. };
  473.  
  474. void* load_library(const char *name);
  475.  
  476. void* get_proc_address(void *handle, const char *proc_name);
  477.  
  478. void enumerate_libraries(int (*callback)(void *handle, const char* name,
  479.                                          uint32_t base, uint32_t size, void *user_data),
  480.                          void *user_data);
  481.  
  482. #ifdef __cplusplus
  483. }
  484. #endif
  485.  
  486.  
  487. #endif
  488.  
  489.  
  490.  
  491.  
  492.  
  493.