1 // Console.obj loading for kos32-gcc
2 // Writed by rgimad and maxcodehack
19 #define cdecl __attribute__ ((cdecl))
23 #define stdcall __attribute__ ((stdcall))
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",
40 typedef int (stdcall * con_gets2_callback
)(int keycode
, char** pstr
, int* pn
,
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
)
71 :"a"(68), "b"(19), "c"(name
));
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);
91 void output_debug_string(const char *s
)
96 asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s
+ i
)));
103 void *lib
= load_library(lib_path
);
107 output_debug_string("Console.obj loading error\r\n");
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]);