Subversion Repositories Kolibri OS

Rev

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

  1. #include <_ansi.h>
  2. #include <sys/unistd.h>
  3. #include "io.h"
  4.  
  5. void load_libconsole();
  6. void     __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t);
  7. void     __stdcall con_exit(char bCloseWindow);
  8. unsigned __stdcall con_get_flags(void);
  9. unsigned __stdcall con_set_flags(unsigned new_flags);
  10. void     __stdcall con_cls(void);
  11. void     __stdcall con_write_string(const char* string, unsigned length);
  12. short    __stdcall con_getch2(void);
  13.  
  14. int __gui_mode;
  15.  
  16. static int console_read(const char *path, void *buff,
  17.            size_t offset, size_t count, size_t *done)
  18. {
  19.     char *p = buff;
  20.     int   cnt = 0;
  21.     short c;
  22.     char  ch;
  23.  
  24. //   __asm__ volatile("int3");
  25.  
  26.     do
  27.     {
  28.         c = con_getch2();
  29.         ch = (char)c;
  30.         if(ch != 0)
  31.         {
  32.             p[cnt] = ch != 0x0D ? ch : 0x0A;
  33.             con_write_string(p+cnt, 1);
  34.             cnt++;
  35.         }
  36.     }while(ch != 0x0D);
  37.  
  38.     *done = cnt;
  39.     return 0;
  40. }
  41.  
  42.  
  43. static int console_write(const char *path, const void *buff,
  44.                  size_t offset, size_t count, size_t *writes)
  45. {
  46.     con_write_string(buff, count);
  47.  
  48.     *writes = count;
  49.     return 0;
  50. };
  51.  
  52. void __init_conio()
  53. {
  54.     __io_handle *ioh;
  55.  
  56.     load_libconsole();
  57.     con_init(80, 25, 80, 500, "Console application");
  58.  
  59.     ioh = &__io_tab[STDIN_FILENO];
  60.     ioh->mode  = _READ|_ISTTY;
  61.     ioh->read  = &console_read;
  62.  
  63.     ioh = &__io_tab[STDOUT_FILENO];
  64.     ioh->mode  = _WRITE|_ISTTY;
  65.     ioh->write = &console_write;
  66. };
  67.  
  68. void __fini_conio()
  69. {
  70.     con_exit(0);
  71. }
  72.  
  73.  
  74.  
  75.  
  76.