Rev 8930 | Rev 9716 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8930 | Rev 9354 | ||
---|---|---|---|
1 | #include <_ansi.h> |
1 | #include <_ansi.h> |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include "io.h" |
4 | #include "io.h" |
5 | #include |
5 | #include |
6 | 6 | ||
7 | 7 | ||
8 | void load_libconsole(); |
8 | void load_libconsole(); |
9 | void __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t); |
9 | void __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t); |
10 | void __stdcall con_exit(char bCloseWindow); |
10 | void __stdcall con_exit(char bCloseWindow); |
11 | unsigned __stdcall con_get_flags(void); |
11 | unsigned __stdcall con_get_flags(void); |
12 | unsigned __stdcall con_set_flags(unsigned new_flags); |
12 | unsigned __stdcall con_set_flags(unsigned new_flags); |
13 | void __stdcall con_cls(void); |
13 | void __stdcall con_cls(void); |
14 | void __stdcall con_write_string(const char* string, unsigned length); |
14 | void __stdcall con_write_string(const char* string, unsigned length); |
15 | short __stdcall con_getch2(void); |
15 | short __stdcall con_getch2(void); |
16 | char* __stdcall con_gets(char*, unsigned); |
16 | char* __stdcall con_gets(char*, unsigned); |
- | 17 | ||
- | 18 | extern void __stdcall (*con_set_title_ptr)(char*); |
|
17 | 19 | ||
18 | int __gui_mode; |
20 | int __gui_mode; |
19 | 21 | ||
20 | void con_init_opt(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t){ |
22 | void con_init_opt(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t){ |
21 | con_init(w_w, w_h, s_w, s_h, t); |
23 | con_init(w_w, w_h, s_w, s_h, t); |
22 | } |
24 | } |
23 | 25 | ||
24 | static int console_read(const char *path, void *buff, |
26 | static int console_read(const char *path, void *buff, |
25 | size_t offset, size_t count, size_t *done) |
27 | size_t offset, size_t count, size_t *done) |
26 | { |
28 | { |
27 | char *p = buff; |
29 | char *p = buff; |
28 | /*int cnt = 0; |
30 | /*int cnt = 0; |
29 | short c; |
31 | short c; |
30 | char ch;*/ |
32 | char ch;*/ |
31 | con_gets(p, count+1); |
33 | con_gets(p, count+1); |
32 | *done = strlen(p); |
34 | *done = strlen(p); |
33 | 35 | ||
34 | // __asm__ volatile("int3"); |
36 | // __asm__ volatile("int3"); |
35 | /* |
37 | /* |
36 | do |
38 | do |
37 | { |
39 | { |
38 | c = con_getch2(); |
40 | c = con_getch2(); |
39 | printf("%d\n",(char)c); |
41 | printf("%d\n",(char)c); |
40 | ch = (char)c; |
42 | ch = (char)c; |
41 | if(ch != 0) |
43 | if(ch != 0) |
42 | { |
44 | { |
43 | p[cnt] = ch != 0x0D ? ch : 0x0A; |
45 | p[cnt] = ch != 0x0D ? ch : 0x0A; |
44 | con_write_string(p+cnt, 1); |
46 | con_write_string(p+cnt, 1); |
45 | cnt++; |
47 | cnt++; |
46 | } |
48 | } |
47 | }while(ch != 0x0D); |
49 | }while(ch != 0x0D); |
48 | *done = cnt; |
50 | *done = cnt; |
49 | */ |
51 | */ |
50 | return 0; |
52 | return 0; |
51 | } |
53 | } |
52 | 54 | ||
53 | static int console_write(const char *path, const void *buff, |
55 | static int console_write(const char *path, const void *buff, |
54 | size_t offset, size_t count, size_t *writes) |
56 | size_t offset, size_t count, size_t *writes) |
55 | { |
57 | { |
56 | con_write_string(buff, count); |
58 | con_write_string(buff, count); |
57 | 59 | ||
58 | *writes = count; |
60 | *writes = count; |
59 | return 0; |
61 | return 0; |
60 | }; |
62 | }; |
61 | 63 | ||
62 | void __init_conio() |
64 | void __init_conio() |
63 | { |
65 | { |
64 | __io_handle *ioh; |
66 | __io_handle *ioh; |
65 | 67 | ||
66 | load_libconsole(); |
68 | load_libconsole(); |
67 | con_init(80, 25, 80, 500, "Console application"); |
69 | con_init(80, 25, 80, 500, "Console application"); |
68 | 70 | ||
69 | ioh = &__io_tab[STDIN_FILENO]; |
71 | ioh = &__io_tab[STDIN_FILENO]; |
70 | ioh->mode = _READ|_ISTTY; |
72 | ioh->mode = _READ|_ISTTY; |
71 | ioh->read = &console_read; |
73 | ioh->read = &console_read; |
72 | 74 | ||
73 | ioh = &__io_tab[STDOUT_FILENO]; |
75 | ioh = &__io_tab[STDOUT_FILENO]; |
74 | ioh->mode = _WRITE|_ISTTY; |
76 | ioh->mode = _WRITE|_ISTTY; |
75 | ioh->write = &console_write; |
77 | ioh->write = &console_write; |
76 | }; |
78 | }; |
77 | 79 | ||
78 | void __fini_conio() |
80 | void __fini_conio() |
79 | { |
81 | { |
80 | con_exit(0); |
82 | con_exit(0); |
81 | } |
83 | } |
82 | - | ||
- | 84 | ||
83 | 85 | void con_set_title(char *title) |
|
- | 86 | { |
|
84 | 87 | con_set_title_ptr(title); |
|
- | 88 | } |