Rev 647 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6412 | siemargl | 1 | #include |
647 | andrew_pro | 2 | #include |
3 | #include |
||
4 | #include |
||
5 | |||
6 | char* dllname="/sys/lib/console.obj"; |
||
7 | int console_init_status; |
||
8 | |||
9 | char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL}; |
||
10 | char* caption = "Console test - colors"; |
||
11 | |||
12 | dword* dll_ver; |
||
13 | void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); |
||
14 | void stdcall (* con_write_asciiz)(const char* string); |
||
15 | void cdecl (* con_printf)(const char* format,...); |
||
16 | void stdcall (* con_exit)(dword bCloseWindow); |
||
17 | |||
18 | struct import{ |
||
19 | char *name; |
||
20 | void *data; |
||
21 | }; |
||
22 | |||
23 | void printf_link(struct import *exp, char** imports){ |
||
24 | |||
25 | dll_ver = (dword*) |
||
26 | _ksys_cofflib_getproc(exp, imports[1]); |
||
27 | con_init = (void stdcall (*)(dword , dword, dword, dword, const char*)) |
||
28 | _ksys_cofflib_getproc(exp, imports[2]); |
||
29 | con_printf = (void cdecl (*)(const char*,...)) |
||
30 | _ksys_cofflib_getproc(exp, imports[4]); |
||
31 | con_exit = (void stdcall (*)(dword)) |
||
32 | _ksys_cofflib_getproc(exp, imports[5]); |
||
33 | } |
||
34 | |||
35 | int init_console(void) |
||
36 | { |
||
37 | struct import * hDll; |
||
38 | |||
39 | if((hDll = (struct import *)_ksys_cofflib_load(dllname)) == 0){ |
||
40 | debug_out_str("can't load lib\n"); |
||
41 | return 1; |
||
42 | } |
||
43 | printf_link(hDll, imports); |
||
44 | debug_out_str("dll loaded\n"); |
||
45 | |||
46 | con_init(-1, -1, -1, -1, caption); |
||
47 | return(0); |
||
48 | } |
||
49 | |||
50 | int printf(const char *format,...) |
||
51 | { |
||
52 | int i; |
||
53 | int printed_simbols; |
||
54 | va_list arg; |
||
55 | char simbol[]={"%s"}; |
||
56 | char *s; |
||
57 | |||
58 | va_start(arg,format); |
||
59 | |||
60 | if (console_init_status==0) |
||
61 | { |
||
62 | i=init_console(); |
||
63 | console_init_status=1; |
||
64 | } |
||
65 | |||
66 | if (i==0) |
||
67 | { |
||
68 | s=malloc(4096); |
||
69 | printed_simbols=format_print(s,4096,format,arg); |
||
70 | con_printf(simbol,s); |
||
71 | free(s); |
||
72 | } |
||
73 | return(printed_simbols); |
||
74 | } |
||
75 |