Rev 6074 | Rev 8777 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6074 | Rev 6536 | ||
---|---|---|---|
1 | #include <_ansi.h> |
1 | #include <_ansi.h> |
2 | #include |
2 | #include |
3 | #include "io.h" |
3 | #include "io.h" |
4 | 4 | ||
5 | void load_libconsole(); |
5 | void load_libconsole(); |
6 | void __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t); |
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); |
7 | void __stdcall con_exit(char bCloseWindow); |
8 | unsigned __stdcall con_get_flags(void); |
8 | unsigned __stdcall con_get_flags(void); |
9 | unsigned __stdcall con_set_flags(unsigned new_flags); |
9 | unsigned __stdcall con_set_flags(unsigned new_flags); |
10 | void __stdcall con_cls(void); |
10 | void __stdcall con_cls(void); |
11 | void __stdcall con_write_string(const char* string, unsigned length); |
11 | void __stdcall con_write_string(const char* string, unsigned length); |
- | 12 | short __stdcall con_getch2(void); |
|
12 | 13 | ||
13 | int __gui_mode; |
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 | ||
14 | 42 | ||
15 | static int console_write(const char *path, const void *buff, |
43 | static int console_write(const char *path, const void *buff, |
16 | size_t offset, size_t count, size_t *writes) |
44 | size_t offset, size_t count, size_t *writes) |
17 | { |
45 | { |
18 | con_write_string(buff, count); |
46 | con_write_string(buff, count); |
19 | 47 | ||
20 | *writes = count; |
48 | *writes = count; |
21 | return count; |
49 | return 0; |
22 | }; |
50 | }; |
23 | 51 | ||
24 | void __init_conio() |
52 | void __init_conio() |
25 | { |
53 | { |
26 | __io_handle *ioh; |
54 | __io_handle *ioh; |
27 | 55 | ||
28 | load_libconsole(); |
56 | load_libconsole(); |
29 | con_init(80, 25, 80, 500, "Console application"); |
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; |
|
30 | 62 | ||
31 | ioh = &__io_tab[STDOUT_FILENO]; |
63 | ioh = &__io_tab[STDOUT_FILENO]; |
32 | ioh->mode = _WRITE|_ISTTY; |
64 | ioh->mode = _WRITE|_ISTTY; |
33 | ioh->write = &console_write; |
65 | ioh->write = &console_write; |
34 | }; |
66 | }; |
35 | 67 | ||
36 | void __fini_conio() |
68 | void __fini_conio() |
37 | { |
69 | { |
38 | con_exit(0); |
70 | con_exit(0); |
39 | } |
71 | } |