Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <sys/ksys.h>
  2. #include "conio.h"
  3.  
  4. static char* __con_caption = "Console application";
  5. static char* __con_dllname = "/sys/lib/console.obj";
  6.  
  7. int __con_is_load = 0;
  8.  
  9. void stdcall (*__con_init_hidden)(int wnd_width, int wnd_height,int scr_width, int scr_height, const char* title);
  10. void stdcall (*__con_write_asciiz)(const char* str);
  11. void stdcall (*__con_write_string)(const char* str, unsigned length);
  12. int stdcall (*__con_getch)(void);
  13. short stdcall (*__con_getch2)(void);
  14. int stdcall (*__con_kbhit)(void);
  15. char* stdcall (*__con_gets)(char* str, int n);
  16. char* stdcall (*__con_gets2)(__con_gets2_callback callback, char* str, int n);
  17. void stdcall (*__con_exit)(int status);
  18. void stdcall (*__con_set_title)(const char* title);
  19.  
  20. static void __con_panic(char* func_name)
  21. {
  22.     _ksys_debug_puts("libc.obj: ");
  23.     _ksys_debug_puts(func_name);
  24.     _ksys_debug_puts(" = NULL\n");
  25.     _ksys_exit();
  26. }
  27.  
  28. static void __con_lib_link(ksys_coff_etable_t *exp)
  29. {
  30.     __con_init_hidden   = _ksys_get_coff_func(exp, "con_init", __con_panic);
  31.     __con_write_asciiz  = _ksys_get_coff_func(exp, "con_write_asciiz", __con_panic);
  32.     __con_write_string  = _ksys_get_coff_func(exp, "con_write_string", __con_panic);
  33.     __con_getch         = _ksys_get_coff_func(exp, "con_getch", __con_panic);
  34.     __con_getch2        = _ksys_get_coff_func(exp, "con_getch2", __con_panic);
  35.     __con_kbhit         = _ksys_get_coff_func(exp, "con_kbhit", __con_panic);
  36.     __con_gets          = _ksys_get_coff_func(exp, "con_gets", __con_panic);
  37.     __con_gets2         = _ksys_get_coff_func(exp, "con_gets2", __con_panic);
  38.     __con_exit          = _ksys_get_coff_func(exp, "con_exit", __con_panic);
  39.     __con_set_title     = _ksys_get_coff_func(exp, "con_set_title", __con_panic);
  40. }
  41.  
  42.  
  43. int __con_init(void)
  44. {
  45.     return __con_init_opt(-1, -1, -1, -1, __con_caption);
  46. }
  47.  
  48. void con_set_title(const char* title){
  49.     __con_init();
  50.     __con_set_title(title);
  51. }
  52.  
  53. int __con_init_opt(int wnd_width, int wnd_height,int scr_width, int scr_height, const char* title)
  54. {  
  55.     if(!__con_is_load){
  56.         ksys_coff_etable_t *__con_lib;
  57.         __con_lib = _ksys_load_coff(__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.