diff --git a/programs/emulator/kwine/bin/kwine b/programs/emulator/kwine/bin/kwine index 00afa7c990..a421544464 100644 Binary files a/programs/emulator/kwine/bin/kwine and b/programs/emulator/kwine/bin/kwine differ diff --git a/programs/emulator/kwine/bin/lib/msvcrt.dll b/programs/emulator/kwine/bin/lib/msvcrt.dll index 3d296d7f5a..8dd66d361f 100644 Binary files a/programs/emulator/kwine/bin/lib/msvcrt.dll and b/programs/emulator/kwine/bin/lib/msvcrt.dll differ diff --git a/programs/emulator/kwine/bin/samples.zip b/programs/emulator/kwine/bin/samples.zip index 5fab40f550..2d7bf9f994 100644 Binary files a/programs/emulator/kwine/bin/samples.zip and b/programs/emulator/kwine/bin/samples.zip differ diff --git a/programs/emulator/kwine/kwine.asm b/programs/emulator/kwine/kwine.asm index 0f3d665cac..e85ed39be2 100644 --- a/programs/emulator/kwine/kwine.asm +++ b/programs/emulator/kwine/kwine.asm @@ -117,7 +117,7 @@ lib dd 0 func dd 0 func_name dd 0 ; ------------------------------------------------------------- ; -sz_pe_load db "PELoad",0 +sz_pe_load db "KWINE",0 ; ------------------------------------------------------------- ; con_init dd 0 con_write_asciiz dd 0 diff --git a/programs/emulator/kwine/lib/conio.c b/programs/emulator/kwine/lib/conio.c index fbf60d2d56..a0b417fa71 100644 --- a/programs/emulator/kwine/lib/conio.c +++ b/programs/emulator/kwine/lib/conio.c @@ -42,12 +42,12 @@ void *load_library(char *name) { void *getprocaddress(void *exports, char *name) { if (exports == NULL) { return 0; } - while (*(uint32_t*)exports != NULL) + while (*(uint32_t*)exports != 0) { char *str1 = (char*)(*(uint32_t*)exports); if (strcmp(str1, name) == 0) { - void *ptr = *(uint32_t*)(exports + 4); + void *ptr = (void*)*(uint32_t*)(exports + 4); // important for debug /*debug_board_write_string(name); @@ -146,13 +146,13 @@ int con_init_console_dll(void) // -------------------------------------------------------------------- -int cdecl _getch() +int _getch() { con_init_console_dll(); return con_getch(); } -int cdecl _kbhit() +int _kbhit() { con_init_console_dll(); return con_kbhit(); diff --git a/programs/emulator/kwine/lib/conio.h b/programs/emulator/kwine/lib/conio.h new file mode 100644 index 0000000000..68fd648873 --- /dev/null +++ b/programs/emulator/kwine/lib/conio.h @@ -0,0 +1,11 @@ +#ifndef _CONIO_H +#define _CONIO_H + +int _getch(); +int _kbhit(); + +int con_init_console_dll(void); +int con_init_console_dll_param(uint32_t wnd_width, uint32_t wnd_height, uint32_t scr_width, uint32_t scr_height, const char* title); +void con_lib_link(void *exp, char** imports); + +#endif \ No newline at end of file diff --git a/programs/emulator/kwine/lib/msvcrt.dll.c b/programs/emulator/kwine/lib/msvcrt.dll.c index 55d6405c50..8eef7c93d0 100644 --- a/programs/emulator/kwine/lib/msvcrt.dll.c +++ b/programs/emulator/kwine/lib/msvcrt.dll.c @@ -6,15 +6,19 @@ #include #include "msvcrt.dll.h" +#include "string.h" +#include "conio.h" +#include "stdio.h" +#include "stdlib.h" +#include "time.h" + #include "string.c" -//#include "dlfcn.c" #include "conio.c" #include "stdio.c" #include "stdlib.c" - -#include "time.h" #include "time.c" +// note: by default all function in c are cdecl :D typedef struct { @@ -30,13 +34,23 @@ const char sz__kbhit[] = "_kbhit"; const char sz_printf[] = "printf"; const char sz_puts[] = "puts"; const char sz_gets[] = "gets"; +const char sz_putchar[] = "putchar"; //string const char sz_strlen[] = "strlen"; const char sz_strcmp[] = "strcmp"; const char sz_strcat[] = "strcat"; +const char sz_strchr[] = "strchr"; +const char sz_strrchr[] = "strrchr"; +const char sz_strcpy[] = "strcpy"; +const char sz_strncpy[] = "strncpy"; +const char sz_memset[] = "memset"; +const char sz_memcpy[] = "memcpy"; +const char sz_memcmp[] = "memcmp"; // stdlib +const char sz_srand[] = "srand"; +const char sz_rand[] = "rand"; const char sz_malloc[] = "malloc"; const char sz_free[] = "free"; const char sz_realloc[] = "realloc"; @@ -44,6 +58,9 @@ const char sz_realloc[] = "realloc"; // time const char sz_time[] = "time"; +const char sz_mktime[] = "mktime"; +const char sz_localtime[] = "localtime"; +const char sz_difftime[] = "difftime"; //uint32_t EXPORTS[] __asm__("EXPORTS") = @@ -55,16 +72,30 @@ export_t EXPORTS[] = {sz_printf, (void*)printf}, {sz_puts, (void*)puts}, {sz_gets, (void*)gets}, + {sz_putchar, (void*)putchar}, {sz_strlen, (void*)strlen}, {sz_strcmp, (void*)strcmp}, {sz_strcat, (void*)strcat}, + {sz_strchr, (void*)strchr}, + {sz_strrchr, (void*)strrchr}, + {sz_strcpy, (void*)strcpy}, + {sz_strncpy, (void*)strncpy}, + {sz_memset, (void*)memset}, + {sz_memcpy, (void*)memcpy}, + {sz_memcmp, (void*)memcmp}, + {sz_srand, (void*)srand}, + {sz_rand, (void*)rand}, {sz_malloc, (void*)malloc}, {sz_free, (void*)free}, {sz_realloc, (void*)realloc}, {sz_time, (void*)time}, + {sz_mktime, (void*)mktime}, + {sz_localtime, (void*)localtime}, + {sz_difftime, (void*)difftime}, + {NULL, NULL}, }; diff --git a/programs/emulator/kwine/lib/stdio.c b/programs/emulator/kwine/lib/stdio.c index c0ce829d52..882e332255 100644 --- a/programs/emulator/kwine/lib/stdio.c +++ b/programs/emulator/kwine/lib/stdio.c @@ -10,13 +10,13 @@ int putchar(int ch) return ch; } -void cdecl puts(const char *str) +void puts(const char *str) { con_init_console_dll(); con_write_asciiz(str); } -char* cdecl gets(char* str) +char* gets(char* str) { con_init_console_dll(); return con_gets(str, 256); diff --git a/programs/emulator/kwine/lib/stdio.h b/programs/emulator/kwine/lib/stdio.h new file mode 100644 index 0000000000..aacf30a940 --- /dev/null +++ b/programs/emulator/kwine/lib/stdio.h @@ -0,0 +1,14 @@ +#ifndef _STDIO_H +#define _STDIO_H + +int putchar(int ch); +void puts(const char *str); +char* gets(char* str); +void putuint(int i); +void putint(int i); +void puthex(uint32_t i); +void print(char *format, va_list args); +void printf(char *text, ... ); + + +#endif \ No newline at end of file diff --git a/programs/emulator/kwine/lib/stdlib.c b/programs/emulator/kwine/lib/stdlib.c index f86e1ce356..a2d77119da 100644 --- a/programs/emulator/kwine/lib/stdlib.c +++ b/programs/emulator/kwine/lib/stdlib.c @@ -1,4 +1,18 @@ + +unsigned long int __rnd_next = 1; + +int rand(void) // RAND_MAX assumed to be 32767 +{ + __rnd_next = __rnd_next * 1103515245 + 12345; + return (unsigned int)(__rnd_next/65536) % 32768; +} + +void srand(unsigned int seed) +{ + __rnd_next = seed; +} + void *malloc(size_t size) { void *val; diff --git a/programs/emulator/kwine/lib/stdlib.h b/programs/emulator/kwine/lib/stdlib.h new file mode 100644 index 0000000000..3f08447a1b --- /dev/null +++ b/programs/emulator/kwine/lib/stdlib.h @@ -0,0 +1,12 @@ +#ifndef _STDLIB_H +#define _STDLIB_H + +int rand(void); +void srand(unsigned int seed); + +void *malloc(size_t size); +int free(void *mem); +void* realloc(void *mem, size_t size); + + +#endif \ No newline at end of file diff --git a/programs/emulator/kwine/lib/string.h b/programs/emulator/kwine/lib/string.h new file mode 100644 index 0000000000..fc2f8cc8e1 --- /dev/null +++ b/programs/emulator/kwine/lib/string.h @@ -0,0 +1,23 @@ +#ifndef _STRING_H +#define _STRING_H + +void* memset(void *mem, int c, unsigned size); +void* memcpy(void *dst, const void *src, unsigned size); +int memcmp(const void* buf1, const void* buf2, int count); + +char *strcat(char strDest[], char strSource[]); +int strcmp(const char* s1, const char* s2); +char *strcpy(char strDest[], const char strSource[]); +char* strncpy(char *strDest, const char *strSource, unsigned n); +int strlen(const char* string); +char* strchr(const char* string, int c); +char* strrchr(const char* string, int c); + +void _itoa(int i, char *s); +void reverse(char s[]); +void itoa(int n, char s[]); +int atoi ( char *s ); + + + +#endif \ No newline at end of file