Rev 539 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 539 | Rev 647 | ||
---|---|---|---|
1 | // Console dynamic link library. Sample by Ghost |
1 | // Console dynamic link library. Sample by Ghost |
2 | 2 | ||
3 | #include "stdio.h" |
3 | #include |
4 | #include "string.h" |
4 | #include |
5 | #include "mesys.h" |
5 | #include |
6 | 6 | ||
7 | char* dllname="/sys/console.obj"; |
7 | char* dllname="/sys/lib/console.obj"; |
8 | int i; |
8 | int i; |
9 | 9 | ||
10 | char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL}; |
10 | char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL}; |
11 | char* caption = "Console test - colors"; |
11 | char* caption = "Console test - colors"; |
12 | 12 | ||
13 | dword (* dll_start)(dword res); |
13 | dword (* dll_start)(dword res); |
14 | dword* dll_ver; |
14 | dword* dll_ver; |
15 | void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); |
15 | void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); |
16 | void stdcall (* con_write_asciiz)(dword flags, const char* string); |
16 | void stdcall (* con_write_asciiz)(const char* string); |
17 | void cdecl (* con_printf)(dword flags, const char* format, ...); |
17 | void cdecl (* con_printf)(const char* format,...); |
18 | void stdcall (* con_exit)(dword bCloseWindow); |
18 | void stdcall (* con_exit)(dword bCloseWindow); |
19 | 19 | ||
20 | struct import{ |
20 | struct import{ |
21 | char *name; |
21 | char *name; |
22 | void *data; |
22 | void *data; |
23 | }; |
23 | }; |
24 | 24 | ||
25 | // â áèáëèîòåêå åñòü àíàëîãè÷íàÿ ôóíêöèÿ _msys_cofflib_getproc, íî ïîêà îíà ðàáîòàåò íå êîððåêòíî |
- | |
26 | void* __msys_cofflib_getproc(struct import *lib, char *name){ |
- | |
27 | int i; |
- | |
28 | for(i = 0; lib[i].name && strcmp(name, lib[i].name); i++); |
- | |
29 | if(lib[i].name)return lib[i].data; |
- | |
30 | else return NULL; |
- | |
31 | } |
- | |
32 | - | ||
33 | void link(struct import *exp, char** imports){ |
25 | void link(struct import *exp, char** imports){ |
34 | dll_start = (dword (*)(dword)) |
26 | dll_start = (dword (*)(dword)) |
35 | __msys_cofflib_getproc(exp, imports[0]); |
27 | _ksys_cofflib_getproc(exp, imports[0]); |
36 | dll_ver = (dword*) |
28 | dll_ver = (dword*) |
37 | __msys_cofflib_getproc(exp, imports[1]); |
29 | _ksys_cofflib_getproc(exp, imports[1]); |
38 | con_init = (void stdcall (*)(dword , dword, dword, dword, const char*)) |
30 | con_init = (void stdcall (*)(dword , dword, dword, dword, const char*)) |
39 | __msys_cofflib_getproc(exp, imports[2]); |
31 | _ksys_cofflib_getproc(exp, imports[2]); |
40 | con_write_asciiz = (void stdcall (*)(dword, const char*)) |
32 | con_write_asciiz = (void stdcall (*)(const char*)) |
41 | __msys_cofflib_getproc(exp, imports[3]); |
33 | _ksys_cofflib_getproc(exp, imports[3]); |
42 | con_printf = (void cdecl (*)(dword, const char*, ...)) |
34 | con_printf = (void cdecl (*)(const char*,...)) |
43 | __msys_cofflib_getproc(exp, imports[4]); |
35 | _ksys_cofflib_getproc(exp, imports[4]); |
44 | con_exit = (void stdcall (*)(dword)) |
36 | con_exit = (void stdcall (*)(dword)) |
45 | __msys_cofflib_getproc(exp, imports[5]); |
37 | _ksys_cofflib_getproc(exp, imports[5]); |
46 | } |
38 | } |
47 | 39 | ||
48 | int main(int argc, char **argv){ |
40 | int main(int argc, char **argv){ |
49 | struct import * hDll; |
41 | |
- | 42 | struct import * hDll; |
|
50 | 43 | int a,b,c,d; |
|
- | 44 | ||
51 | if((hDll = (struct import *)_msys_cofflib_load(dllname)) == 0){ |
45 | if((hDll = (struct import *)_ksys_cofflib_load(dllname)) == 0){ |
52 | debug_out_str("can't load lib\n\r"); |
46 | debug_out_str("can't load lib\n"); |
53 | return 1; |
47 | return 1; |
54 | } |
48 | } |
55 | link(hDll, imports); |
49 | link(hDll, imports); |
56 | debug_out_str("dll loaded\n\r"); |
50 | debug_out_str("dll loaded\n"); |
57 | 51 | ||
58 | if(dll_start(1) == 0){ |
52 | if(dll_start(1) == 0){ |
59 | debug_out_str("dll_start failed\n\r"); |
53 | debug_out_str("dll_start failed\n"); |
60 | return 1; |
54 | return 1; |
61 | } |
55 | } |
62 | 56 | ||
63 | con_init(-1, -1, -1, -1, caption); |
57 | con_init(-1, -1, -1, -1, caption); |
64 | for(i = 0; i < 256; i++){ |
58 | |
- | 59 | for(i = 0; i < 256; i++){ |
|
65 | con_printf(7, "Color 0x%02X: ", i); |
60 | con_printf("Color 0x%02X: ", i); |
66 | con_write_asciiz(i, "Text sample."); |
61 | con_write_asciiz("Text sample."); |
67 | 62 | ||
- | 63 | con_printf(" printf %s test %d\n", "small", i); |
|
- | 64 | ||
68 | con_printf(i, " printf %s test %d\n", "small", i); |
- | |
69 | } |
65 | } |
70 | 66 | ||
71 | con_exit(0); |
67 | con_exit(0); |
72 | debug_out_str("all right's ;)\n\r"); |
68 | debug_out_str("all right's ;)\n"); |
73 | }> |
69 | }> |
74 | 70 | ||
75 | 71 |