Apps: fixed 3 programs for using a long path in parameters
[kolibrios.git] / programs / other / tte / console_obj.h
blob29d99ad0cfa355ab9e83a242822ea8dcfc11e436
1 // Console.obj loading for kos32-gcc
2 // Writed by rgimad and maxcodehack
4 #include <string.h>
5 #include <stdlib.h>
7 #ifndef CONSOLE_OBJ_H
8 #define CONSOLE_OBJ_H
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 #ifndef NULL
15 #define NULL 0
16 #endif
18 #ifndef cdecl
19 #define cdecl __attribute__ ((cdecl))
20 #endif
22 #ifndef stdcall
23 #define stdcall __attribute__ ((stdcall))
24 #endif
26 typedef unsigned int dword;
27 typedef unsigned short word;
29 const char* imports[] = {
30 "START", "version", "con_init", "con_write_asciiz", "con_write_string",
31 "con_printf", "con_exit", "con_get_flags", "con_set_flags", "con_kbhit",
32 "con_getch", "con_getch2", "con_gets", "con_gets2", "con_get_font_height",
33 "con_get_cursor_height", "con_set_cursor_height", "con_cls",
34 "con_get_cursor_pos", "con_set_cursor_pos", "con_set_title",
35 (char*)0
38 dword *version;
40 typedef int (stdcall * con_gets2_callback)(int keycode, char** pstr, int* pn,
41 int* ppos);
43 void stdcall (*con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title) = 0;
44 void stdcall (*con_exit)(int bCloseWindow) = 0;
45 void stdcall (*con_set_title)(const char* title) = 0;
46 void stdcall (*con_write_asciiz)(const char* str) = 0;
47 void stdcall (*con_write_string)(const char* str, dword length) = 0;
48 int cdecl (*con_printf)(const char* format, ...) = 0;
49 dword stdcall (*con_get_flags)(void) = 0;
50 dword stdcall (*con_set_flags)(dword new_flags) = 0;
51 int stdcall (*con_get_font_height)(void) = 0;
52 int stdcall (*con_get_cursor_height)(void) = 0;
53 int stdcall (*con_set_cursor_height)(int new_height) = 0;
54 int stdcall (*con_getch)(void) = 0;
55 word stdcall (*con_getch2)(void) = 0;
56 int stdcall (*con_kbhit)(void) = 0;
57 char* stdcall (*con_gets)(char* str, int n) = 0;
58 char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n) = 0;
59 void stdcall (*con_cls)() = 0;
60 void stdcall (*con_get_cursor_pos)(int* px, int* py) = 0;
61 void stdcall (*con_set_cursor_pos)(int x, int y) = 0;
63 const char lib_path[] = "/sys/lib/console.obj";
65 void* load_library(const char *name)
67 void *table;
68 __asm__ __volatile__(
69 "int $0x40"
70 :"=a"(table)
71 :"a"(68), "b"(19), "c"(name));
72 return table;
75 void *load_library_procedure(void *exports, const char *name)
77 if (exports == NULL) { return 0; }
78 while (*(dword*)exports != 0)
80 char *str1 = (char*)(*(dword*)exports);
81 if (strcmp(str1, name) == 0)
83 void *ptr = (void*)*(dword*)(exports + 4);
84 return ptr;
86 exports += 8;
88 return 0;
91 void output_debug_string(const char *s)
93 unsigned int i = 0;
94 while(*(s + i))
96 asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s + i)));
97 i++;
101 void load_console()
103 void *lib = load_library(lib_path);
105 if (!lib)
107 output_debug_string("Console.obj loading error\r\n");
108 exit(1);
111 dword (*start_lib)(dword) = (dword(*)(dword))load_library_procedure(lib, imports[0]);
113 version = (dword*)load_library_procedure(lib, imports[1]);
115 con_init = (void stdcall(*)(dword,dword,dword,dword,const char*))load_library_procedure(lib, imports[2]);
116 con_write_asciiz = (void stdcall(*)(const char*))load_library_procedure(lib, imports[3]);
117 con_write_string = (void stdcall(*)(const char*,dword))load_library_procedure(lib, imports[4]);
118 con_printf = (int cdecl(*)(const char*,...))load_library_procedure(lib, imports[5]);
119 con_exit = (void stdcall(*)(int))load_library_procedure(lib, imports[6]);
120 con_get_flags = (dword stdcall(*)(void))load_library_procedure(lib, imports[7]);
121 con_set_flags = (dword stdcall(*)(dword))load_library_procedure(lib, imports[8]);
122 con_kbhit = (int stdcall(*)(void))load_library_procedure(lib, imports[9]);
123 con_getch = (int stdcall(*)(void))load_library_procedure(lib, imports[10]);
124 con_getch2 = (word stdcall(*)(void))load_library_procedure(lib, imports[11]);
125 con_gets = (char* stdcall(*)(char*,int))load_library_procedure(lib, imports[12]);
126 con_gets2 = (char* stdcall(*)(con_gets2_callback,char*,int))load_library_procedure(lib, imports[13]);
127 con_get_font_height = (int stdcall(*)(void))load_library_procedure(lib, imports[14]);
128 con_get_cursor_height = (int stdcall(*)(void))load_library_procedure(lib, imports[15]);
129 con_set_cursor_height = (int stdcall(*)(int))load_library_procedure(lib, imports[16]);
130 con_cls = (void stdcall(*)(void))load_library_procedure(lib, imports[17]);
131 con_get_cursor_pos = (void stdcall(*)(int*,int*))load_library_procedure(lib, imports[18]);
132 con_set_cursor_pos = (void stdcall(*)(int,int))load_library_procedure(lib, imports[19]);
133 con_set_title = (void stdcall(*)(const char*))load_library_procedure(lib, imports[20]);
137 #ifdef __cplusplus
139 #endif
141 #endif