Subversion Repositories Kolibri OS

Rev

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