Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.         some system function of KolibriOS
  3. */
  4.  
  5. #define KOLIBRIOS_SYS_EVENT_REDRAW                                                      1
  6. #define KOLIBRIOS_SYS_EVENT_KEYS                                                        2
  7. #define KOLIBRIOS_SYS_EVENT_BUTTON_PRESSED                                              3
  8. #define KOLIBRIOS_SYS_EVENT_REDRAW_BACKGROUND                                   5
  9. #define KOLIBRIOS_SYS_EVENT_MOUSE                                                       6
  10. #define KOLIBRIOS_SYS_EVENT_IPC                                                 7
  11. #define KOLIBRIOS_SYS_EVENT_NET                                                 8
  12. #define KOLIBRIOS_SYS_EVENT_DEBUG                                                       9
  13.  
  14. #define KOLIBRIOS_SYS_MOUSE_BUTTON_LEFT_DOWN                                    0x1
  15. #define KOLIBRIOS_SYS_MOUSE_BUTTON_RIGHT_DOWN                                   (0x1<<1)
  16. #define KOLIBRIOS_SYS_MOUSE_BUTTON_MIDDLE_DOWN                                  (0x1 <<2)
  17. #define KOLIBRIOS_SYS_MOUSE_BUTTON_4_DOWN                                               (0x1 <<3)
  18. #define KOLIBRIOS_SYS_MOUSE_BUTTON_5_DOWN                                               (0x1 <<4)
  19.  
  20. #define KOLIBRIOS_SYS_FILE_ACCESS_SUCCESSFULLY                                  0
  21. #define KOLIBRIOS_SYS_FILE_UNDEFINED_PARTITION_OR_HARDDRIVE_BASE                1
  22. #define KOLIBRIOS_SYS_FILE_FUNCTION_DONT_SUPPOROTE_FOR_CURRENT_FILE_SYSTEM      2
  23. #define KOLIBRIOS_SYS_FILE_UNKNOWN_FILE_SYSTEM                                  3
  24. #define KOLIBRIOS_SYS_FILE_NOT_FOUND                                            5
  25. #define KOLIBRIOS_SYS_FILE_FINISHED                                                     6
  26. #define KOLIBRIOS_SYS_FILE_POINTER_OUTOFMEMORY_APPLICATION                      7
  27. #define KOLIBRIOS_SYS_FILE_MEMORY_OF_DEVICE_FILLED                              8
  28. #define KOLIBRIOS_SYS_FILE_TABLE_DESTROYED                                              9
  29. #define KOLIBRIOS_SYS_FILE_ACCESS_DENITED                                               10
  30. #define KOLIBRIOS_SYS_FILE_DEVICE_ERROR                                         11
  31.  
  32. #pragma pack(push,1)
  33. struct KOLIBRIOS_FILEIO
  34. {
  35.         DWORD   number_subfunction;
  36.         DWORD   offset_in_file_low;
  37.         DWORD   offset_in_file_hight;
  38.         DWORD   size;
  39.         DWORD   *data;
  40.         BYTE    null;
  41.         char    *full_file_path;
  42. };
  43. #pragma pack(pop)
  44.  
  45. typedef struct KOLIBRIOS_FILEIO fileio_t;
  46.  
  47. #pragma pack(push,1)
  48. struct BLOCK_DATA_ENTRY_DIRECTORY
  49. {
  50.         DWORD   attributes;
  51.         DWORD   types_data_of_name;
  52.         DWORD   time_created_file;
  53.         DWORD   date_created_file;
  54.         DWORD   time_last_access;
  55.         DWORD   date_last_access;
  56.         DWORD   time_last_modification;
  57.         DWORD   date_last_modification;
  58.         DWORD   file_size_low;
  59.         DWORD   file_size_hight;
  60.         DWORD   *filename;
  61. };
  62. #pragma pack(pop)
  63.  
  64. typedef struct BLOCK_DATA_ENTRY_DIRECTORY bded_t;
  65.  
  66. #pragma pack(push,1)
  67. struct PROCESS_TABLE
  68. {
  69.         int cpu_usage;                  //+0
  70.         int window_pos_info;                    //+4
  71.         short int reserved1;                    //+8
  72.         char name[12];                  //+10
  73.         int memstart;                           //+22
  74.         int memused;                            //+26
  75.         int pid;                                //+30
  76.         int winx_start;                 //+34
  77.         int winy_start;                 //+38
  78.         int winx_size;                  //+42
  79.         int winy_size;                  //+46
  80.         short int slot_info;                    //+50
  81.         short int reserved2;                    //+52
  82.         int clientx;                            //+54
  83.         int clienty;                            //+58
  84.         int clientwidth;                        //+62
  85.         int clientheight;                       //+66
  86.         unsigned char window_state;             //+70
  87.         char reserved3[1024-71];                //+71
  88. };
  89. #pragma pack(pop)
  90.  
  91. typedef struct PROCESS_TABLE    process_table_t;
  92.  
  93. #pragma pack(push,1)
  94. struct IMPORT
  95. {
  96.         char *name;
  97.         void *data;
  98. };
  99. #pragma pack(pop)
  100.  
  101. typedef struct IMPORT   import_t;
  102.  
  103. static DWORD gui_get_file_size(char *filename,DWORD *buf_for_size);
  104. static DWORD gui_read_file(char *filename,DWORD *buf_pos_size,DWORD size_read,char *buf);
  105. static DWORD gui_create_rewrite_file(char *filename,DWORD *buf_pos_size,DWORD size_write,char *buf);
  106. static DWORD gui_append_to_file(char *filename,DWORD *buf_pos_size,DWORD size_write,char *buf);
  107. static void gui_debug_out_str(char *s);
  108. static void* gui_cofflib_getproc(import_t *lib, char *name);
  109.  
  110. #define alwinline       __attribute__((always_inline))
  111. //------------------------------------------------------------------------------------------
  112. //                                      draw window
  113. //------------------------------------------------------------------------------------------
  114. extern inline void __attribute__((always_inline)) gui_ksys_draw_window(DWORD x,DWORD y,DWORD sizex,DWORD sizey,DWORD flags)
  115. {
  116.         __asm__ __volatile__(
  117.         "xorl %%eax,%%eax\n\t"
  118.         "movl %0,%%ebx\n\t"
  119.         "movl %1,%%ecx\n\t"
  120.         "movl %4,%%edx\n\t"
  121.         "shll $16,%%ebx\n\t"
  122.         "shll $16,%%ecx\n\t"
  123.         "addl %2,%%ebx\n\t"
  124.         "addl %3,%%ecx\n\t"
  125.         "int $0x40"
  126.         :/*no output*/
  127.         :"g"(x),"g"(y),"g"(sizex),"g"(sizey),"g"(flags)
  128.         :"eax","ebx","ecx","edx");
  129. }
  130.  
  131. //------------------------------------------------------------------------------------------
  132. //              begin redraw window
  133. //------------------------------------------------------------------------------------------
  134. extern inline void  __attribute__((always_inline)) gui_ksys_begin_draw_window(void)
  135. {
  136.         __asm__ __volatile__(
  137.         "int $0x40"
  138.         :/*no output*/
  139.         :"a"(12),"b"(1));
  140. }
  141.  
  142. //------------------------------------------------------------------------------------------
  143. //              finish redraw window
  144. //------------------------------------------------------------------------------------------
  145. extern inline void __attribute__((always_inline)) gui_ksys_finish_draw_window(void)
  146. {
  147.         __asm__ __volatile__(
  148.         "int $0x40"
  149.         :/*no output*/
  150.         :"a"(12),"b"(2));
  151. }
  152.  
  153. //------------------------------------------------------------------------------------------
  154. //              set new position and new size of window
  155. //------------------------------------------------------------------------------------------
  156. extern inline void  alwinline gui_ksys_set_position_and_size_window(DWORD new_x,
  157.                         DWORD new_y,DWORD new_sizex,DWORD new_sizey)
  158. {
  159.         __asm__ __volatile__(
  160.         "int $0x40"
  161.         :/*no output*/
  162.         :"a"(67),"b"(new_x),"c"(new_y),"d"(new_sizex),"S"(new_sizey));
  163. }
  164.  
  165. //------------------------------------------------------------------------------------------
  166. //              set title of  window
  167. //------------------------------------------------------------------------------------------
  168. extern inline void  gui_ksys_set_title_window(char *title)
  169. {
  170.         __asm__ __volatile__(
  171.         "int $0x40"
  172.         :/*no output*/
  173.         :"a"(71),"b"(1),"c"(title));
  174. }
  175.  
  176. //------------------------------------------------------------------------------------------
  177. //              delete title of  window
  178. //------------------------------------------------------------------------------------------
  179. extern inline void  gui_ksys_delete_title_window(void)
  180. {
  181.         __asm__ __volatile__(
  182.         "int $0x40"
  183.         :/*no output*/
  184.         :"a"(71),"b"(1),"c"(0));
  185. }
  186.  
  187. //------------------------------------------------------------------------------------------
  188. //              get information about current process
  189. //------------------------------------------------------------------------------------------
  190. extern inline int  gui_ksys_get_current_process_information(void *mem)
  191. {
  192.         int     value;
  193.  
  194.         __asm__ __volatile__(
  195.         "int $0x40"
  196.         :"=a"(value)
  197.         :"a"(9),"b"(mem),"c"(-1));
  198.  
  199.         return(value);
  200. }
  201.  
  202. //------------------------------------------------------------------------------------------
  203. //              delete title of  window
  204. //------------------------------------------------------------------------------------------
  205. extern inline int __attribute__((always_inline)) gui_ksys_get_skin_height(void)
  206. {
  207.         int     value;
  208.  
  209.         __asm__ __volatile__(
  210.         "int $0x40"
  211.         :"=a"(value)
  212.         :"a"(48),"b"(4));
  213.  
  214.         return(value);
  215. }
  216.  
  217. //------------------------------------------------------------------------------------------
  218. //              get pressed key
  219. //------------------------------------------------------------------------------------------
  220. extern inline int  __attribute__((always_inline)) gui_ksys_get_key(void)
  221. {
  222.         int     value;
  223.  
  224.         __asm__ __volatile__(
  225.         "int $0x40"
  226.         :"=a"(value)
  227.         :"a"(2));
  228.  
  229.         return(value);
  230. }
  231.  
  232. //------------------------------------------------------------------------------------------
  233. //              set keyboard input mode
  234. //------------------------------------------------------------------------------------------
  235. extern inline void  gui_ksys_set_keyboard_input_mode(int mode)
  236. {
  237.         __asm__ __volatile__(
  238.         "int $0x40"
  239.         :/*no output*/
  240.         :"a"(66),"b"(1),"c"(mode));
  241.  
  242. }
  243.  
  244. //------------------------------------------------------------------------------------------
  245. //              get keyboard input mode
  246. //------------------------------------------------------------------------------------------
  247. extern inline int  gui_ksys_get_keyboard_input_mode(void)
  248. {
  249.         int     value;
  250.  
  251.         __asm__ __volatile__(
  252.         "int $0x40"
  253.         :"=a"(value)
  254.         :"a"(66),"b"(2));
  255.  
  256.         return(value);
  257. }
  258.  
  259. //------------------------------------------------------------------------------------------
  260. //              get state of menegers keys
  261. //------------------------------------------------------------------------------------------
  262. extern inline int  gui_ksys_get_state_menegers_keys(void)
  263. {
  264.         int     value;
  265.  
  266.         __asm__ __volatile__(
  267.         "int $0x40"
  268.         :"=a"(value)
  269.         :"a"(66),"b"(3));
  270.  
  271.         return(value);
  272. }
  273.  
  274. //------------------------------------------------------------------------------------------
  275. //              set events mask
  276. //------------------------------------------------------------------------------------------
  277. extern inline void  gui_ksys_set_events_mask(DWORD mask)
  278. {
  279.         __asm__ __volatile__(
  280.         "int $0x40"
  281.         :/*no output*/
  282.         :"a"(40),"b"(mask));
  283. }
  284.  
  285. //------------------------------------------------------------------------------------------
  286. //              wait event
  287. //------------------------------------------------------------------------------------------
  288. extern inline int  __attribute__((always_inline)) gui_ksys_wait_event(void)
  289. {
  290.         int     value;
  291.  
  292.         __asm__ __volatile__(
  293.         "int $0x40"
  294.         :"=a"(value)
  295.         :"a"(10));
  296.  
  297.         return(value);
  298. }
  299.  
  300. //------------------------------------------------------------------------------------------
  301. //              check for event
  302. //------------------------------------------------------------------------------------------
  303. extern inline int  gui_ksys_check_event(void)
  304. {
  305.         int     value;
  306.  
  307.         __asm__ __volatile__(
  308.         "int $0x40"
  309.         :"=a"(value)
  310.         :"a"(11));
  311.  
  312.         return(value);
  313. }
  314.  
  315. //------------------------------------------------------------------------------------------
  316. //              wait event while not timeout
  317. //------------------------------------------------------------------------------------------
  318. extern inline int  gui_ksys_wait_event_with_timeout(DWORD timeout)
  319. {
  320.         int     value;
  321.  
  322.         __asm__ __volatile__(
  323.         "int $0x40"
  324.         :"=a"(value)
  325.         :"a"(23),"b"(timeout));
  326.  
  327.         return(value);
  328. }
  329.  
  330. //------------------------------------------------------------------------------------------
  331. //              get code of pressed button
  332. //------------------------------------------------------------------------------------------
  333. extern inline int  gui_ksys_get_code_pressed_button(void)
  334. {
  335.         int     value;
  336.  
  337.         __asm__ __volatile__(
  338.         "int $0x40"
  339.         :"=a"(value)
  340.         :"a"(17));
  341.  
  342.         return(value);
  343. }
  344.  
  345. //------------------------------------------------------------------------------------------
  346. //              get window mouse coordinates
  347. //------------------------------------------------------------------------------------------
  348. extern inline int  gui_ksys_get_window_mouse_coordinates(void)
  349. {
  350.         int     value;
  351.  
  352.         __asm__ __volatile__(
  353.         "int $0x40"
  354.         :"=a"(value)
  355.         :"a"(37),"b"(1));
  356.  
  357.         return(value);
  358. }
  359.  
  360. //------------------------------------------------------------------------------------------
  361. //              get screen mouse coordinates
  362. //------------------------------------------------------------------------------------------
  363. extern inline int  gui_ksys_get_screen_mouse_coordinates(void)
  364. {
  365.         int     value;
  366.  
  367.         __asm__ __volatile__(
  368.         "int $0x40"
  369.         :"=a"(value)
  370.         :"a"(37),"b"(0));
  371.  
  372.         return(value);
  373. }
  374.  
  375. //------------------------------------------------------------------------------------------
  376. //              get mouse buttons state
  377. //------------------------------------------------------------------------------------------
  378. extern inline int  gui_ksys_get_mouse_buttons_state(void)
  379. {
  380.         int     value;
  381.  
  382.         __asm__ __volatile__(
  383.         "int $0x40"
  384.         :"=a"(value)
  385.         :"a"(37),"b"(2));
  386.  
  387.         return(value);
  388. }
  389.  
  390. //------------------------------------------------------------------------------------------
  391. //              get mouse ruler state
  392. //------------------------------------------------------------------------------------------
  393. extern inline int  gui_ksys_get_mouse_ruler_state(void)
  394. {
  395.         int     value;
  396.  
  397.         __asm__ __volatile__(
  398.         "int $0x40"
  399.         :"=a"(value)
  400.         :"a"(37),"b"(7));
  401.  
  402.         return(value);
  403. }
  404.  
  405. //------------------------------------------------------------------------------------------
  406. //              put pixel in window
  407. //------------------------------------------------------------------------------------------
  408. extern inline void  gui_ksys_put_pixel_window(int x,int y,DWORD color)
  409. {
  410.         __asm__ __volatile__(
  411.         "int $0x40"
  412.         :/*no output*/
  413.         :"a"(1),"b"(x),"c"(y),"d"(color));
  414. }
  415.  
  416. //------------------------------------------------------------------------------------------
  417. //              put image in window
  418. //------------------------------------------------------------------------------------------
  419. extern inline void  gui_ksys_put_image_window(char *p,int x,int y,int sizex,int sizey)
  420. {
  421.         __asm__ __volatile__(
  422.         "shll $16,%%ecx\n\t"
  423.         "shll $16,%%edx\n\t"
  424.         "addl %%esi,%%ecx\n\t"
  425.         "addl %%edi,%%edx\n\t"
  426.         "int $0x40"
  427.         :/*no output*/
  428.         :"a"(7),"b"(p),"c"(sizex),"d"(x),"S"(sizey),"D"(y));
  429. }
  430.  
  431. //------------------------------------------------------------------------------------------
  432. //              draw filled rectangle in window
  433. //------------------------------------------------------------------------------------------
  434. extern inline void  gui_ksys_draw_filled_rectangle_window(int x,int y,int sizex,int sizey,DWORD color)
  435. {
  436.         __asm__ __volatile__(
  437.         "shll $16,%%ebx\n\t"
  438.         "shll $16,%%ecx\n\t"
  439.         "addl %%esi,%%ebx\n\t"
  440.         "addl %%edi,%%ecx\n\t"
  441.         "int $0x40"
  442.         :/*no output*/
  443.         :"a"(13),"b"(x),"c"(y),"d"(color),"S"(sizex),"D"(sizey));
  444. }
  445.  
  446. //------------------------------------------------------------------------------------------
  447. //              get screen size
  448. //------------------------------------------------------------------------------------------
  449. extern inline DWORD  gui_ksys_get_screen_size(void)
  450. {
  451.         DWORD   value;
  452.  
  453.         __asm__ __volatile__(
  454.         "int $0x40"
  455.         :"=a"(value)
  456.         :"a"(14));
  457.  
  458.         return(value);
  459. }
  460.  
  461. //------------------------------------------------------------------------------------------
  462. //              get color of pixel in coordinates (x,y)
  463. //------------------------------------------------------------------------------------------
  464. extern inline DWORD  gui_ksys_get_color_pixel_window(DWORD coordinates)
  465. {
  466.         int     value;
  467.  
  468.         __asm__ __volatile__(
  469.         "int $0x40"
  470.         :"=a"(value)
  471.         :"a"(35),"b"(coordinates));
  472.  
  473.         return(value);
  474. }
  475.  
  476. //------------------------------------------------------------------------------------------
  477. //              get bits per pixel on the screen
  478. //------------------------------------------------------------------------------------------
  479. extern inline DWORD  gui_ksys_get_screen_bits_per_pixel(void)
  480. {
  481.         int     value;
  482.  
  483.         __asm__ __volatile__(
  484.         "int $0x40"
  485.         :"=a"(value)
  486.         :"a"(61),"b"(2));
  487.  
  488.         return(value);
  489. }
  490.  
  491. //------------------------------------------------------------------------------------------
  492. //              draw line in window
  493. //------------------------------------------------------------------------------------------
  494. extern inline void  gui_ksys_draw_line_window(int x1,int y1,int x2,int y2,DWORD color)
  495. {
  496.         __asm__ __volatile__(
  497.         "shll $16,%%ebx\n\t"
  498.         "shll $16,%%ecx\n\t"
  499.         "addl %%esi,%%ebx\n\t"
  500.         "addl %%edi,%%ecx\n\t"
  501.         "int $0x40"
  502.         :/*no output*/
  503.         :"a"(38),"b"(x1),"c"(y1),"d"(color),"S"(x2),"D"(y2));
  504. }
  505.  
  506. //------------------------------------------------------------------------------------------
  507. //              get standart colors table
  508. //------------------------------------------------------------------------------------------
  509. extern inline void  gui_ksys_get_standart_colors_table(char *buf)
  510. {
  511.         __asm__ __volatile__(
  512.         "int $0x40"
  513.         :/*no output*/
  514.         :"a"(48),"b"(3),"c"(buf),"d"(40));
  515. }
  516.  
  517. //------------------------------------------------------------------------------------------
  518. //              get time from start system to current in 1/100 sec.
  519. //------------------------------------------------------------------------------------------
  520. extern inline DWORD  gui_ksys_get_ticks(void)
  521. {
  522.         DWORD   value;
  523.  
  524.         __asm__ __volatile__(
  525.         "int $0x40"
  526.         :"=a"(value)
  527.         :"a"(26),"b"(9));
  528.  
  529.         return(value);
  530. }
  531.  
  532. //------------------------------------------------------------------------------------------
  533. //              initialize heap of memory
  534. //------------------------------------------------------------------------------------------
  535. extern inline DWORD  gui_ksys_init_user_heap(void)
  536. {
  537.         DWORD   value;
  538.  
  539.         __asm__ __volatile__(
  540.         "int $0x40"
  541.         :"=a"(value)
  542.         :"a"(68),"b"(11));
  543.  
  544.         return(value);
  545. }
  546.  
  547. //------------------------------------------------------------------------------------------
  548. //              alloctae size bytes of user memory
  549. //------------------------------------------------------------------------------------------
  550. extern inline void* gui_ksys_malloc(DWORD size)
  551. {
  552.   void *value;
  553.  
  554.   __asm__ __volatile__(
  555.       "int $0x40"
  556.         :"=a"(value)
  557.         :"a"(68),"b"(12),"c"(size)
  558.         :"memory");
  559.  
  560.   return(value);
  561. }
  562.  
  563. //------------------------------------------------------------------------------------------
  564. //              free pointer of memory
  565. //------------------------------------------------------------------------------------------
  566. extern inline void gui_ksys_free(void *mem)
  567. {
  568.      __asm__ __volatile__(
  569.         "int $0x40"
  570.         :
  571.         :"a"(68),"b"(13),"c"(mem)
  572.         :"memory");
  573. }
  574.  
  575. //------------------------------------------------------------------------------------------
  576. //              reallocate of memory
  577. //------------------------------------------------------------------------------------------
  578. extern inline void* gui_ksys_realloc(DWORD new_size,void *old_mem)
  579. {
  580.         void *new_mem;
  581.      __asm__ __volatile__(
  582.         "int $0x40"
  583.         :"=a"(new_mem)
  584.         :"a"(68),"b"(20),"c"(new_size),"d"(old_mem)
  585.         :"memory");
  586.  
  587.         return(new_mem);
  588. }
  589.  
  590.  
  591. //------------------------------------------------------------------------------------------
  592. //              load user mode DLL
  593. //------------------------------------------------------------------------------------------
  594. extern inline void* gui_ksys_load_dll(char *path)
  595. {
  596.         void    *dll_export;
  597.  
  598.      __asm__ __volatile__(
  599.         "int $0x40"
  600.         :"=a"(dll_export)
  601.         :"a"(68),"b"(19),"c"(path));
  602.  
  603.         return(dll_export);
  604. }
  605.  
  606. //------------------------------------------------------------------------------------------
  607. //              create thred
  608. //------------------------------------------------------------------------------------------
  609. extern inline void* gui_ksys_create_thread(DWORD *thread_eip,DWORD *thread_esp)
  610. {
  611.         void    *thread_TID;
  612.  
  613.      __asm__ __volatile__(
  614.         "int $0x40"
  615.         :"=a"(thread_TID)
  616.         :"a"(51),"b"(1),"c"(thread_eip),"d"(thread_esp)
  617.         :"memory");
  618.  
  619.         return(thread_TID);
  620. }
  621.  
  622. //------------------------------------------------------------------------------------------
  623. //              acces to files input output
  624. //------------------------------------------------------------------------------------------
  625. extern inline DWORD gui_ksys_files_io(fileio_t *f,DWORD value)
  626. {
  627.         DWORD   err_status;
  628.  
  629.      __asm__ __volatile__(
  630.         "int $0x40"
  631.         :"=a"(err_status),"=b"(value)
  632.         :"a"(70),"b"(f));
  633.  
  634.         return(err_status);
  635. }
  636.  
  637. //------------------------------------------------------------------------------------------
  638. //              debug board output
  639. //------------------------------------------------------------------------------------------
  640. extern inline void gui_ksys_debug_out(int c)
  641. {
  642.      __asm__ __volatile__(
  643.         "int $0x40"
  644.         :
  645.         :"a"(63),"b"(1),"c"(c));
  646. }
  647.  
  648. //------------------------------------------------------------------------------------------
  649. //              KolibriOS system exit program
  650. //------------------------------------------------------------------------------------------
  651. extern inline void gui_ksys_exit(int value)
  652. {
  653.      __asm__ __volatile__(
  654.         "int $0x40"
  655.         :
  656.         :"a"(-1),"b"(value));
  657. }
  658.  
  659.