Subversion Repositories Kolibri OS

Rev

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

  1. #include <conio.h>
  2. #include <kolibrisys.h>
  3.  
  4. char* con_caption = "Console app";
  5. extern int __argc;
  6. extern char** __argv;
  7. extern char* __path;
  8. dword   *con_dll_ver;
  9. int   __console_initdll_status;
  10.  
  11. char* con_dllname="/sys/lib/console.obj";
  12.  
  13. struct import{
  14.         char *name;
  15.         void *data;
  16. };
  17.  
  18. void stdcall (*con_init)(dword wnd_width, dword wnd_height,
  19.         dword scr_width, dword scr_height, const char* title);
  20. void stdcall (*con_exit)(int bCloseWindow);
  21. void stdcall (*con_set_title)(const char* title);
  22. void stdcall (*con_write_asciiz)(const char* str);
  23. void stdcall (*con_write_string)(const char* str, dword length);
  24. int cdecl (*con_printf)(const char* format, ...);
  25. dword stdcall (*con_get_flags)(void);
  26. dword stdcall (*con_set_flags)(dword new_flags);
  27. int stdcall (*con_get_font_height)(void);
  28. int stdcall (*con_get_cursor_height)(void);
  29. int stdcall (*con_set_cursor_height)(int new_height);
  30. int stdcall (*con_getch)(void);
  31. word stdcall (*con_getch2)(void);
  32. int stdcall (*con_kbhit)(void);
  33. char* stdcall (*con_gets)(char* str, int n);
  34. char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n);
  35. void stdcall (*con_cls)();
  36. void stdcall (*con_get_cursor_pos)(int* px, int* py);
  37. void stdcall (*con_set_cursor_pos)(int x, int y);
  38.  
  39.  
  40. // don't change order in this! linked by index
  41. char* con_imports[] = {
  42.         "START", "version", "con_init", "con_write_asciiz", "con_write_string",
  43.         "con_printf", "con_exit", "con_get_flags", "con_set_flags", "con_kbhit",
  44.         "con_getch", "con_getch2", "con_gets", "con_gets2", "con_get_font_height",
  45.         "con_get_cursor_height", "con_set_cursor_height",  "con_cls",
  46.         "con_get_cursor_pos", "con_set_cursor_pos", "con_set_title",
  47.         (char*)0
  48. };
  49.  
  50. void con_lib_link(struct import *exp, char** imports){
  51.  
  52.         con_dll_ver             = _ksys_cofflib_getproc(exp, imports[1]);
  53.         con_init                        = _ksys_cofflib_getproc(exp, imports[2]);
  54.         con_write_asciiz        = _ksys_cofflib_getproc(exp, imports[3]);
  55.         con_write_string        = _ksys_cofflib_getproc(exp, imports[4]);
  56.         con_printf                      = _ksys_cofflib_getproc(exp, imports[5]);
  57.         con_exit                        = _ksys_cofflib_getproc(exp, imports[6]);
  58.         con_get_flags           = _ksys_cofflib_getproc(exp, imports[7]);
  59.         con_set_flags           = _ksys_cofflib_getproc(exp, imports[8]);
  60.         con_kbhit                       = _ksys_cofflib_getproc(exp, imports[9]);
  61.         con_getch                       = _ksys_cofflib_getproc(exp, imports[10]);
  62.         con_getch2                      = _ksys_cofflib_getproc(exp, imports[11]);
  63.         con_gets                        = _ksys_cofflib_getproc(exp, imports[12]);
  64.         con_gets2                       = _ksys_cofflib_getproc(exp, imports[13]);
  65.         con_get_font_height     = _ksys_cofflib_getproc(exp, imports[14]);
  66.         con_get_cursor_height=_ksys_cofflib_getproc(exp, imports[15]);
  67.         con_set_cursor_height=_ksys_cofflib_getproc(exp, imports[16]);
  68.         con_cls                         = _ksys_cofflib_getproc(exp, imports[17]);
  69.         con_get_cursor_pos      = _ksys_cofflib_getproc(exp, imports[18]);
  70.                 con_set_cursor_pos      = _ksys_cofflib_getproc(exp, imports[19]);
  71.                 con_set_title           = _ksys_cofflib_getproc(exp, imports[20]);
  72. }
  73.  
  74.  
  75. int con_init_console_dll(void)
  76. {
  77.     return con_init_console_dll_param(-1, -1, -1, -1, con_caption);
  78. }
  79.  
  80.  
  81. int con_init_console_dll_param(dword wnd_width, dword wnd_height,
  82.         dword scr_width, dword scr_height, const char* title)
  83. /*      work as con_init_console_dll, but call con_init with params
  84. */
  85. {
  86.         struct import * hDll;
  87.  
  88.         if (__console_initdll_status == 1) return 0;
  89.    
  90.         if((hDll = (struct import *)_ksys_cofflib_load(con_dllname)) == 0){
  91.                 debug_out_str("can't load lib\n");
  92.                 return 1;
  93.         }
  94.         con_lib_link(hDll, con_imports);
  95.  
  96.         con_init(wnd_width, wnd_height, scr_width, scr_height, title);
  97.  
  98.         __console_initdll_status = 1;
  99.  
  100.         return 0;
  101. }
  102.  
  103.