Subversion Repositories Kolibri OS

Rev

Rev 7624 | Rev 8436 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include "kolibri.h"
  2. #include "string.h"
  3.  
  4.  
  5. extern char KOL_PATH[256];
  6. extern char KOL_PARAM[256];
  7. extern char KOL_DIR[256];
  8.  
  9.  
  10. void kol_exit()
  11. {
  12. asm volatile ("int $0x40"::"a"(-1));
  13. }
  14.  
  15.  
  16. void kol_sleep(unsigned d)
  17. {
  18. asm volatile ("int $0x40"::"a"(5), "b"(d));
  19. }
  20.  
  21.  
  22. // define a window
  23. // x, y - position; w, h - size; cs - color and style; c - caption; b - boder
  24. void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned cs, unsigned b, char *t)
  25. {
  26. asm volatile ("int $0x40"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(cs), "D"(t), "S"(b) );
  27. }
  28.  
  29.  
  30. void kol_wnd_move(unsigned x, unsigned y)
  31. {
  32. asm volatile ("int $0x40"::"a"(67), "b"(x), "c"(y), "d"(-1), "S"(-1));
  33. }
  34.  
  35.  
  36. void kol_event_mask(unsigned e)
  37. {
  38. asm volatile ("int $0x40"::"a"(40), "b"(e));
  39. }
  40.  
  41.  
  42. unsigned kol_event_wait()
  43. {
  44. asm volatile ("int $0x40"::"a"(10));
  45. }
  46.  
  47.  
  48. unsigned kol_event_wait_time(unsigned time)
  49. {
  50. asm volatile ("int $0x40"::"a"(23), "b"(time));
  51. }
  52.  
  53.  
  54. unsigned kol_event_check()
  55. {
  56. asm volatile ("int $0x40"::"a"(11));
  57. }
  58.  
  59.  
  60. inline void __attribute__((__always_inline__)) kol_paint_start()
  61. {
  62. asm volatile ("int $0x40"::"a"(12), "b"(1));
  63. }
  64.  
  65.  
  66. inline void __attribute__((__always_inline__)) kol_paint_end()
  67. {
  68. asm volatile ("int $0x40"::"a"(12), "b"(2));
  69. }
  70.  
  71.  
  72. void kol_paint_pixel(unsigned x, unsigned y, unsigned c)
  73. {
  74. asm volatile ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c));
  75. }
  76.  
  77.  
  78. void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
  79. {
  80. asm volatile ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
  81. }
  82.  
  83.  
  84. void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c)
  85. {
  86. asm volatile ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c));
  87. }
  88.  
  89.  
  90. void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c)
  91. {
  92. asm volatile ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s));
  93. }
  94.  
  95.  
  96. void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
  97. {
  98. asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
  99. }
  100.  
  101.  
  102. void kol_paint_image_24(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
  103. {
  104. asm volatile ("int $0x40"::"a"(65), "b"(d), "c"(w*65536+h), "d"(x*65536+y), "S"(32));
  105. }
  106.  
  107.  
  108. unsigned kol_key_get()
  109. {
  110. asm volatile ("int $0x40"::"a"(2));
  111. }
  112.  
  113.  
  114. unsigned kol_key_control()
  115. {
  116. asm volatile ("int $0x40"::"a"(66), "b"(3));
  117. }
  118.  
  119.  
  120. void kol_key_lang_set(unsigned lang)
  121. {
  122. asm volatile ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang));
  123. }
  124.  
  125.  
  126. unsigned kol_key_lang_get()
  127. {
  128. asm volatile ("int $0x40"::"a"(26), "b"(2), "c"(9));
  129. }
  130.  
  131.  
  132. void kol_key_mode_set(unsigned mode)
  133. {
  134. asm volatile ("int $0x40"::"a"(66), "b"(1), "c"(mode));
  135. }
  136.  
  137.  
  138. unsigned kol_key_mode_get()
  139. {
  140. asm volatile ("int $0x40"::"a"(66), "b"(2));
  141. }
  142.  
  143.  
  144. unsigned kol_btn_get()
  145. {
  146. asm volatile ("int $0x40"::"a"(17));
  147. }
  148.  
  149.  
  150. void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c)
  151. {
  152. asm volatile ("int $0x40"::"a"(8), "b"(x*65536+w), "c"(y*65536+h), "d"(d), "S"(c));
  153. }
  154.  
  155.  
  156. void kol_btn_type(unsigned t)
  157. {
  158. asm volatile ("int $0x40"::"a"(48), "b"(1), "c"(t));
  159. }
  160.  
  161.  
  162. void kol_wnd_caption(char *s)
  163. {
  164. asm volatile ("int $0x40"::"a"(71), "b"(1), "c"(s));
  165. }
  166.  
  167.  
  168. unsigned kol_mouse_pos()
  169. {
  170. asm volatile ("int $0x40"::"a"(37), "b"(0));
  171. }
  172.  
  173.  
  174. unsigned kol_mouse_posw()
  175. {
  176. asm volatile ("int $0x40"::"a"(37), "b"(1));
  177. }
  178.  
  179.  
  180. unsigned kol_mouse_btn()
  181. {
  182. asm volatile ("int $0x40"::"a"(37), "b"(2));
  183. }
  184.  
  185.  
  186. void kol_board_putc(char c)
  187. {
  188. asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
  189. }
  190.  
  191.  
  192. void kol_board_puts(char *s)
  193. {
  194. unsigned i;
  195. i = 0;
  196. while (*(s+i))
  197.         {
  198.         asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
  199.         i++;
  200.         }
  201. }
  202.  
  203.  
  204. void kol_board_puti(int n)
  205. {
  206. char c;
  207.  
  208. if ( n > 1 )
  209.         kol_board_puti(n / 10);
  210.  
  211. c = n % 10 + '0';
  212. asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
  213.  
  214. }
  215.  
  216.  
  217. int kol_file_70(kol_struct70 *k)
  218. {
  219. asm volatile ("int $0x40"::"a"(70), "b"(k));
  220. }
  221.  
  222.  
  223. kol_struct_import* kol_cofflib_load(char *name)
  224. {
  225. asm volatile ("int $0x40"::"a"(68), "b"(19), "c"(name));
  226. }
  227.  
  228.  
  229. void* kol_cofflib_procload (kol_struct_import *imp, char *name)
  230. {
  231. int i;
  232. for (i=0;;i++)
  233.         if ( NULL == ((imp+i) -> name))
  234.                 break;
  235.         else
  236.                 if ( 0 == strcmp(name, (imp+i)->name) )
  237.                         return (imp+i)->data;
  238. return NULL;
  239. }
  240.  
  241.  
  242. unsigned kol_cofflib_procnum (kol_struct_import *imp)
  243. {
  244. unsigned i, n;
  245.  
  246. for (i=n=0;;i++)
  247.         if ( NULL == ((imp+i) -> name))
  248.                 break;
  249.         else
  250.                 n++;
  251.  
  252. return n;
  253. }
  254.  
  255.  
  256. void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
  257. {
  258. unsigned i;
  259. *name = 0;
  260.  
  261. for (i=0;;i++)
  262.         if ( NULL == ((imp+i) -> name))
  263.                 break;
  264.         else
  265.                 if ( i == n )
  266.                         {
  267.                         strcpy(name, ((imp+i)->name));
  268.                         break;
  269.                         }
  270.  
  271. }
  272.  
  273.  
  274. unsigned kol_system_cpufreq()
  275. {
  276. asm volatile ("int $0x40"::"a"(18), "b"(5));
  277. }
  278.  
  279.  
  280. unsigned kol_system_mem()
  281. {
  282. asm volatile ("int $0x40"::"a"(18), "b"(17));
  283. }
  284.  
  285.  
  286. unsigned kol_system_memfree()
  287. {
  288. asm volatile ("int $0x40"::"a"(18), "b"(16));
  289. }
  290.  
  291.  
  292. unsigned kol_system_time_get()
  293. {
  294. asm volatile ("int $0x40"::"a"(3));
  295. }
  296.  
  297.  
  298. unsigned kol_system_date_get()
  299. {
  300. asm volatile ("int $0x40"::"a"(29));
  301. }
  302.  
  303.  
  304. unsigned kol_system_end(unsigned param)
  305. {
  306. asm volatile ("int $0x40"::"a"(18), "b"(9), "c"(param));
  307. }
  308.  
  309.  
  310. void kol_path_file2dir(char *dir, char *fname)
  311. {
  312. unsigned i;
  313. strcpy (dir, fname);
  314. for ( i = strlen(dir);; --i)
  315.         if ( '/' == dir[i])
  316.                 {
  317.                 dir[i] = '\0';
  318.                 return;
  319.                 }
  320. }
  321.  
  322.  
  323. void kol_path_full(char *full, char *fname)
  324. {
  325. char temp[256];
  326.  
  327. switch (*fname)
  328.         {
  329.  
  330.         case '/':
  331.                 strncpy(temp, fname+1, 2);
  332.                 temp[2]=0;
  333.                 if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) )
  334.                         strcpy (full, fname);
  335.                 break;
  336.  
  337.         case '.':
  338.                 break;
  339.  
  340.         default:
  341.                 break;
  342.  
  343.         };
  344.  
  345. }
  346.  
  347.  
  348.  
  349. inline void __attribute__((__always_inline__)) kol_screen_wait_rr()
  350. {
  351. asm volatile ("int $0x40"::"a"(18), "b"(14));
  352. }
  353.  
  354.  
  355.  
  356. void kol_screen_get_size(unsigned *w, unsigned *h)
  357. {
  358. unsigned size;
  359. asm volatile ("int $0x40":"=a"(size):"a"(14));
  360. *w = size / 65536;
  361. *h = size % 65536;
  362. }
  363.  
  364.  
  365.  
  366. unsigned kol_skin_height()
  367. {
  368. asm volatile ("int $0x40"::"a"(48), "b"(4));
  369. }
  370.  
  371.  
  372. unsigned kol_thread_start(unsigned start, unsigned stack)
  373. {
  374. asm volatile ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack));
  375. }
  376.  
  377.  
  378. unsigned kol_time_tick()
  379. {
  380. asm volatile ("int $0x40"::"a"(26), "b"(9));
  381. }
  382.  
  383.  
  384. unsigned kol_sound_speaker(char data[])
  385. {
  386. asm volatile ("movl %0, %%esi"::"a"(data));
  387. asm volatile ("int $0x40"::"a"(55), "b"(55));
  388. }
  389.  
  390.  
  391. unsigned kol_process_info(unsigned slot, char buf1k[])
  392. {
  393. asm volatile ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot));
  394. }
  395.  
  396.  
  397. int kol_process_kill_pid(unsigned process)
  398. {
  399. asm volatile ("int $0x40"::"a"(18), "b"(18), "c"(process));
  400. }
  401.  
  402. int kol_kill_process(unsigned process)
  403. {
  404. asm volatile ("int $0x40"::"a"(18), "b"(2), "c"(process));
  405. }
  406.  
  407. void kol_get_kernel_ver(char buff16b[])
  408. {
  409. asm volatile ("int $0x40"::"a"(18), "b"(13), "c"(buff16b));
  410. }
  411.  
  412. int kol_buffer_open(char name[], int mode, int size, char **buf)
  413. {
  414. int error;
  415. asm volatile ("int $0x40":"=a"(*buf), "=d"(error):"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode));
  416. return error;
  417. }
  418.  
  419. void kol_buffer_close(char name[])
  420. {
  421. asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name));
  422. }
  423.  
  424. int kol_clip_num()
  425. {
  426. asm volatile ("int $0x40"::"a"(54), "b"(0));
  427. }
  428.  
  429. char* kol_clip_get(int n)
  430. {
  431. asm volatile ("int $0x40"::"a"(54), "b"(1), "c"(n));
  432. }
  433.  
  434. int kol_clip_set(int n, char buffer[])
  435. {
  436. asm volatile ("int $0x40"::"a"(54), "b"(2), "c"(n), "d"(buffer));
  437. }
  438.  
  439. int kos_random(int num)
  440. {
  441.         srand(kol_time_tick());
  442.         return rand() % num;
  443. }
  444.  
  445. int kos_get_mouse_wheels(void)
  446. {
  447.     int val;
  448.     asm ("int $0x40":"=a"(val):"a"(37),"b"(7));
  449.     return val;
  450. };
  451.  
  452.  
  453. struct blit_call
  454. {
  455.    int dstx;      
  456.    int dsty;
  457.    int w;
  458.    int h;
  459.  
  460.    int srcx;
  461.    int srcy;
  462.    int srcw;
  463.    int srch;
  464.  
  465.    unsigned char *d;
  466.    int   stride;
  467. };
  468.  
  469. void kos_blit(int dstx, int dsty, int w, int h, int srcx,
  470.         int srcy,int srcw, int srch, int stride, char *d)
  471. {
  472.         struct blit_call image;
  473.         image.dstx=dstx;
  474.         image.dsty=dsty;
  475.         image.w=w;
  476.         image.h=h;
  477.         image.srcx=srcx;
  478.         image.srcy=srcy;
  479.         image.srcw=srcw;
  480.         image.srch=srch;
  481.         image.stride=stride;
  482.         image.d=d;
  483.         asm ("int $0x40"::"a"(73),"b"(0),"c"(&image));
  484. }
  485.  
  486.