Subversion Repositories Kolibri OS

Rev

Rev 9558 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <sys/ksys.h>
  2. #include <conio.h>
  3. #include "stdio.h"
  4.  
  5. static char* __con_caption = "Console application";
  6. static char* __con_dllname = "/sys/lib/console.obj";
  7.  
  8. int __con_is_load = 0;
  9.  
  10. void  __stdcall (*__con_init_hidden)(int wnd_width, unsigned wnd_height, int scr_width, int scr_height, const char* title);
  11. void  __stdcall (*con_exit)(int);
  12. void  __stdcall (*con_set_title)(const char* title);
  13. void  __stdcall (*con_write_asciiz)(const char* str);
  14. void  __stdcall (*con_write_string)(const char* str, dword length);
  15. int   __cdecl   (*con_printf)(const char* format, ...);
  16. dword __stdcall (*con_get_flags)(void);
  17. dword __stdcall (*con_set_flags)(dword new_flags);
  18. int   __stdcall (*con_get_font_height)(void);
  19. int   __stdcall (*con_get_cursor_height)(void);
  20. int   __stdcall (*con_set_cursor_height)(int new_height);
  21. int   __stdcall (*con_getch)(void);
  22. word  __stdcall (*con_getch2)(void);
  23. int   __stdcall (*con_kbhit)(void);
  24. char* __stdcall (*con_gets)(char* str, int n);
  25. char* __stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n);
  26. void  __stdcall (*con_cls)();
  27. void  __stdcall (*con_get_cursor_pos)(int* px, int* py);
  28. void  __stdcall (*con_set_cursor_pos)(int x, int y);
  29.  
  30. static void __con_lib_link(ksys_dll_t *exp)
  31. {
  32.     __con_init_hidden = _ksys_dlsym(exp, "con_init");
  33.     con_exit          = _ksys_dlsym(exp, "con_exit");
  34.     con_set_title     = _ksys_dlsym(exp, "con_set_title");
  35.     con_write_asciiz  = _ksys_dlsym(exp, "con_write_asciiz");
  36.     con_write_string  = _ksys_dlsym(exp, "con_write_string");
  37.     con_printf        = _ksys_dlsym(exp, "con_printf");
  38.     con_get_flags     = _ksys_dlsym(exp, "con_get_flags");
  39.     con_set_flags     = _ksys_dlsym(exp, "con_set_flags");
  40.     con_get_font_height = _ksys_dlsym(exp, "con_get_font_height");
  41.     con_get_cursor_height = _ksys_dlsym(exp, "con_get_cursor_height");
  42.     con_set_cursor_height = _ksys_dlsym(exp, "con_set_cursor_height");
  43.     con_getch           = _ksys_dlsym(exp, "con_getch");
  44.     con_getch2          = _ksys_dlsym(exp, "con_getch2");
  45.     con_kbhit           = _ksys_dlsym(exp, "con_kbhit");
  46.     con_gets            = _ksys_dlsym(exp, "con_gets");
  47.     con_gets2           = _ksys_dlsym(exp, "con_gets2");
  48.     con_cls             = _ksys_dlsym(exp, "con_cls");
  49.     con_get_cursor_pos  = _ksys_dlsym(exp, "con_get_cursor_pos");
  50.     con_set_cursor_pos  = _ksys_dlsym(exp, "con_set_cursor_pos");
  51. }
  52.  
  53. int con_init_opt(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title)
  54. {  
  55.     if(!__con_is_load){
  56.         ksys_dll_t *__con_lib;
  57.         __con_lib = _ksys_dlopen(__con_dllname);
  58.         if(__con_lib==NULL){
  59.             _ksys_debug_puts("Error! Can't load console.obj lib\n");
  60.             return 1;
  61.         }
  62.         __con_lib_link(__con_lib);
  63.         __con_init_hidden(wnd_width, wnd_height, scr_width, scr_height, title);
  64.         __con_is_load= 1;
  65.         return 0;
  66.     }
  67.     return 1;
  68. }
  69.  
  70.  
  71. int con_init(void)
  72. {
  73.     return con_init_opt(-1, -1, -1, -1, __con_caption);
  74. }
  75.  
  76.