Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef KOLIBRI_INCLUDE
  2. #define KOLIBRI_INCLUDE
  3.  
  4. #define NULL ((void*)0)
  5.  
  6. #define SHM_OPEN                0
  7. #define SHM_OPEN_ALWAYS 0x04
  8. #define SHM_CREATE              0x08
  9. #define SHM_READ                0x00
  10. #define SHM_WRITE               0x01
  11.  
  12. #define E_NOTFOUND      5
  13. #define E_ACCESS        10
  14. #define E_NOMEM         30
  15. #define E_PARAM         33
  16.  
  17. #define evReDraw  1
  18. #define evKey     2
  19. #define evButton  3
  20. #define evDesktop 5
  21. #define evMouse   6
  22. #define evIPC     7
  23. #define evNetwork 8
  24. #define evDebug   9
  25.  
  26. #pragma pack(push,1)
  27. typedef struct
  28. {
  29. unsigned        p00;
  30. unsigned        p04;
  31. unsigned        p08;
  32. unsigned        p12;
  33. unsigned        p16;
  34. char            p20;
  35. char            *p21;
  36. } struct70;
  37. #pragma pack(pop)
  38.  
  39.  
  40. #pragma pack(push,1)
  41. typedef struct
  42. {
  43. unsigned        p00;
  44. char            p04;
  45. char            p05[3];
  46. unsigned        p08;
  47. unsigned        p12;
  48. unsigned        p16;
  49. unsigned        p20;
  50. unsigned        p24;
  51. unsigned        p28;
  52. unsigned        p32[2];
  53. unsigned        p40;
  54. } struct_BDVK;
  55. #pragma pack(pop)
  56.  
  57.  
  58. #pragma pack(push,1)
  59. typedef struct
  60. {
  61. char    *name;
  62. void    *data;
  63. } struct_import;
  64. #pragma pack(pop)
  65.  
  66. #include "string.c"
  67.  
  68.  
  69. extern char PATH[256];
  70. extern char PARAM[256];
  71. extern char DIR[256];
  72.  
  73.  
  74. static inline void exit()
  75. {
  76.         asm volatile ("int $0x40"::"a"(-1));
  77. }
  78.  
  79. static inline dword get_pixel(unsigned x,unsigned y,unsigned size)
  80. {
  81.         asm volatile ("int $0x40"::"a"(35), "b"((y*size+x)));
  82. }
  83.  
  84. static inline void sleep(unsigned d)
  85. {
  86.         asm volatile ("int $0x40"::"a"(5), "b"(d));
  87. }
  88.  
  89. static inline void GetRGB(unsigned x,unsigned y, unsigned w, unsigned h,unsigned d)
  90. {
  91.         asm volatile ("int $0x40"::"a"(36), "b"(d), "c"((w<<16)|h), "d"((x<<16)|y));
  92. }
  93.  
  94. // define a window
  95. // x, y - position; w, h - size; cs - color and style; c - caption; b - boder
  96. static inline void wnd_define(unsigned x, unsigned y, unsigned w, unsigned h)
  97. {
  98.         asm volatile ("int $0x40"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(0x43000000));
  99. }
  100.  
  101.  
  102. static inline void wnd_move(unsigned x, unsigned y)
  103. {
  104.         asm volatile ("int $0x40"::"a"(67), "b"(x), "c"(y), "d"(-1), "S"(-1));
  105. }
  106.  
  107.  
  108. static inline void event_mask(unsigned e)
  109. {
  110.         asm volatile ("int $0x40"::"a"(40), "b"(e));
  111. }
  112.  
  113.  
  114. static inline unsigned event_wait()
  115. {
  116.         asm volatile ("int $0x40"::"a"(10));
  117. }
  118.  
  119.  
  120. static inline unsigned event_wait_time(unsigned time)
  121. {
  122.         asm volatile ("int $0x40"::"a"(23), "b"(time));
  123. }
  124.  
  125.  
  126. static inline unsigned event_check()
  127. {
  128.         asm volatile ("int $0x40"::"a"(11));
  129. }
  130.  
  131.  
  132. static inline void __attribute__((__always_inline__)) paint_start()
  133. {
  134.         asm volatile ("int $0x40"::"a"(12), "b"(1));
  135. }
  136.  
  137.  
  138. static inline void __attribute__((__always_inline__)) paint_end()
  139. {
  140.         asm volatile ("int $0x40"::"a"(12), "b"(2));
  141. }
  142.  
  143.  
  144. static inline void paint_pixel(unsigned x, unsigned y, unsigned c)
  145. {
  146.         asm volatile ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c));
  147. }
  148.  
  149.  
  150. static inline void paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
  151. {
  152.         asm volatile ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
  153. }
  154.  
  155.  
  156. static inline void paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c)
  157. {
  158.         asm volatile ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c));
  159. }
  160.  
  161.  
  162. static inline void paint_string(unsigned x, unsigned y, char *s, unsigned c)
  163. {
  164.         asm volatile ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s));
  165. }
  166.  
  167.  
  168. static inline void paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
  169. {
  170.         asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
  171. }
  172.  
  173.  
  174. static inline void paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette)
  175. {
  176.         asm volatile ("int $0x40"::"a"(65), "b"(d), "c"(w*65536+h), "d"(x*65536+y), "D"(palette), "S"(8));
  177. }
  178.  
  179.  
  180. static inline unsigned key_get()
  181. {
  182.         asm volatile ("int $0x40"::"a"(2));
  183. }
  184.  
  185.  
  186. static inline unsigned key_control()
  187. {
  188.         asm volatile ("int $0x40"::"a"(66), "b"(3));
  189. }
  190.  
  191.  
  192. static inline void key_lang_set(unsigned lang)
  193. {
  194.         asm volatile ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang));
  195. }
  196.  
  197.  
  198. static inline unsigned key_lang_get()
  199. {
  200.         asm volatile ("int $0x40"::"a"(26), "b"(2), "c"(9));
  201. }
  202.  
  203.  
  204. static inline void key_mode_set(unsigned mode)
  205. {
  206.         asm volatile ("int $0x40"::"a"(66), "b"(1), "c"(mode));
  207. }
  208.  
  209.  
  210. static inline unsigned key_mode_get()
  211. {
  212.         asm volatile ("int $0x40"::"a"(66), "b"(2));
  213. }
  214.  
  215.  
  216. static inline unsigned btn_get()
  217. {
  218.         asm volatile ("int $0x40"::"a"(17));
  219. }
  220.  
  221.  
  222. static inline void btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c)
  223. {
  224.         asm volatile ("int $0x40"::"a"(8), "b"(x*65536+w), "c"(y*65536+h), "d"(d), "S"(c));
  225. }
  226.  
  227.  
  228. static inline void btn_type(unsigned t)
  229. {
  230.         asm volatile ("int $0x40"::"a"(48), "b"(1), "c"(t));
  231. }
  232.  
  233.  
  234. static inline void wnd_caption(char *s)
  235. {
  236.         asm volatile ("int $0x40"::"a"(71), "b"(1), "c"(s));
  237. }
  238.  
  239.  
  240. static inline unsigned mouse_pos()
  241. {
  242.         asm volatile ("int $0x40"::"a"(37), "b"(0));
  243. }
  244.  
  245.  
  246. static inline unsigned mouse_posw()
  247. {
  248.         asm volatile ("int $0x40"::"a"(37), "b"(1));
  249. }
  250.  
  251.  
  252. static inline unsigned mouse_btn()
  253. {
  254.         asm volatile ("int $0x40"::"a"(37), "b"(2));
  255. }
  256.  
  257.  
  258. static inline void board_putc(char c)
  259. {
  260.         asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
  261. }
  262.  
  263.  
  264. static inline void board_puts(char *s)
  265. {
  266.         unsigned i;
  267.         i = 0;
  268.         while (*(s+i))
  269.         {
  270.                 asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
  271.         i++;
  272.         }
  273. }
  274.  
  275.  
  276. static inline void board_puti(int n)
  277. {
  278.         char c;
  279.  
  280.         if ( n > 1 )
  281.                 board_puti(n / 10);
  282.  
  283.         c = n % 10 + '0';
  284.         asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
  285.  
  286. }
  287.  
  288.  
  289. static inline int file_70(struct70 *k)
  290. {
  291.         asm volatile ("int $0x40"::"a"(70), "b"(k));
  292. }
  293.  
  294.  
  295. static inline struct_import* cofflib_load(char *name)
  296. {
  297.         asm volatile ("int $0x40"::"a"(68), "b"(19), "c"(name));
  298. }
  299.  
  300.  
  301. static inline void* cofflib_procload (struct_import *imp, char *name)
  302. {
  303.         int i;
  304.         for (i=0;;i++)
  305.         if ( NULL == ((imp+i) -> name))
  306.                 break;
  307.         else
  308.                 if ( 0 == strcmp(name, (imp+i)->name) )
  309.                         return (imp+i)->data;
  310.         return NULL;
  311. }
  312.  
  313.  
  314. static inline unsigned cofflib_procnum (struct_import *imp)
  315. {
  316.         unsigned i, n;
  317.  
  318.         for (i=n=0;;i++)
  319.                 if ( NULL == ((imp+i) -> name))
  320.                         break;
  321.                 else
  322.                         n++;
  323.  
  324.         return n;
  325. }
  326.  
  327.  
  328. static inline void cofflib_procname (struct_import *imp, char *name, unsigned n)
  329. {
  330.         unsigned i;
  331.         *name = 0;
  332.  
  333.         for (i=0;;i++)
  334.                 if ( NULL == ((imp+i) -> name))
  335.                         break;
  336.                 else
  337.                         if ( i == n )
  338.                                 {
  339.                                         strcpy(name, ((imp+i)->name));
  340.                                         break;
  341.                                 }
  342.  
  343. }
  344.  
  345.  
  346. static inline unsigned system_cpufreq()
  347. {
  348.         asm volatile ("int $0x40"::"a"(18), "b"(5));
  349. }
  350.  
  351.  
  352. static inline unsigned system_mem()
  353. {
  354.         asm volatile ("int $0x40"::"a"(18), "b"(17));
  355. }
  356.  
  357.  
  358. static inline unsigned system_memfree()
  359. {
  360.         asm volatile ("int $0x40"::"a"(18), "b"(16));
  361. }
  362.  
  363.  
  364. static inline unsigned system_time_get()
  365. {
  366.         asm volatile ("int $0x40"::"a"(3));
  367. }
  368.  
  369.  
  370. static inline unsigned system_date_get()
  371. {
  372.         asm volatile ("int $0x40"::"a"(29));
  373. }
  374.  
  375.  
  376. static inline unsigned system_end(unsigned param)
  377. {
  378.         asm volatile ("int $0x40"::"a"(18), "b"(9), "c"(param));
  379. }
  380.  
  381. static inline unsigned win_min()
  382. {
  383.         asm volatile ("int $0x40"::"a"(18), "b"(10));
  384. }
  385.  
  386.  
  387. static inline void path_file2dir(char *dir, char *fname)
  388. {
  389.         unsigned i;
  390.         strcpy (dir, fname);
  391.         for ( i = strlen(dir);; --i)
  392.                 if ( '/' == dir[i])
  393.                 {
  394.                         dir[i] = '\0';
  395.                         return;
  396.                 }
  397. }
  398.  
  399.  
  400. static inline void path_full(char *full, char *fname)
  401. {
  402.         char temp[256];
  403.  
  404.         switch (*fname)
  405.                 {
  406.  
  407.                 case '/':
  408.                         strncpy(temp, fname+1, 2);
  409.                         temp[2]=0;
  410.                         if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) )
  411.                                 strcpy (full, fname);
  412.                         break;
  413.  
  414.                 case '.':
  415.                         break;
  416.  
  417.                 default:
  418.                         break;
  419.  
  420.                 };
  421. }
  422.  
  423.  
  424.  
  425. static inline void __attribute__((__always_inline__)) screen_wait_rr()
  426. {
  427.         asm volatile ("int $0x40"::"a"(18), "b"(14));
  428. }
  429.  
  430.  
  431.  
  432. static inline void screen_get_size(unsigned *w, unsigned *h)
  433. {
  434.         unsigned size;
  435.         asm volatile ("int $0x40":"=a"(size):"a"(14));
  436.         *h = size&0xFFFF;
  437.         *w = size>>16;
  438. }
  439.  
  440.  
  441. static inline unsigned skin_height()
  442. {
  443.         asm volatile ("int $0x40"::"a"(48), "b"(4));
  444. }
  445.  
  446.  
  447. static inline unsigned thread_start(unsigned start, unsigned stack)
  448. {
  449.         asm volatile ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack));
  450. }
  451.  
  452.  
  453. static inline unsigned time_tick()
  454. {
  455.         asm volatile ("int $0x40"::"a"(26), "b"(9));
  456. }
  457.  
  458.  
  459. static inline unsigned sound_speaker(char data[])
  460. {
  461.         asm volatile ("movl %0, %%esi"::"a"(data));
  462.         asm volatile ("int $0x40"::"a"(55), "b"(55));
  463. }
  464.  
  465.  
  466. static inline unsigned process_info(signed slot, char buf1k[])
  467. {
  468.         asm volatile ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot));
  469. }
  470.  
  471.  
  472. static inline int process_kill_pid(unsigned process)
  473. {
  474.         asm volatile ("int $0x40"::"a"(18), "b"(18), "c"(process));
  475. }
  476.  
  477. static inline int kill_process(unsigned process)
  478. {
  479.         asm volatile ("int $0x40"::"a"(18), "b"(2), "c"(process));
  480. }
  481.  
  482. static inline void get_kernel_ver(char buff16b[])
  483. {
  484.         asm volatile ("int $0x40"::"a"(18), "b"(13), "c"(buff16b));
  485. }
  486.  
  487. static inline long GetFreeRam(void)
  488. {
  489.         asm ("int $0x40"::"a"(18), "b"(16));
  490. }
  491.  
  492. static inline long WaitBlanking(void)
  493. {
  494.         asm ("int $0x40"::"a"(18), "b"(14));
  495. }
  496.  
  497. static inline int buffer_open(char name[], int mode, int size, char **buf)
  498. {
  499.         int error;
  500.         asm volatile ("int $0x40":"=a"(*buf), "=d"(error):"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode));
  501.         return error;
  502. }
  503.  
  504. static inline void buffer_close(char name[])
  505. {
  506.         asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name));
  507. }
  508.  
  509. static inline int clip_num()
  510. {
  511.         asm volatile ("int $0x40"::"a"(54), "b"(0));
  512. }
  513.  
  514. static inline char* clip_get(int n)
  515. {
  516.         asm volatile ("int $0x40"::"a"(54), "b"(1), "c"(n));
  517. }
  518.  
  519. static inline int clip_set(int n, char buffer[])
  520. {
  521.         asm volatile ("int $0x40"::"a"(54), "b"(2), "c"(n), "d"(buffer));
  522. }
  523.  
  524.  
  525. #endif