diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h b/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h index 2f2681eed..286d0eab9 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h @@ -43,4 +43,6 @@ extern int _FUNC(rand)(void); extern void _FUNC(__assert_fail)(const char *expr, const char *file, int line, const char *func); extern void _FUNC(qsort)(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *)); +extern double _FUNC(atof)(const char *ascii); + #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h index c6e3c32aa..4b844b398 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h @@ -11,10 +11,10 @@ * All wrappers must start with the "_ksys_" prefix. * I consider it mandatory to place the wrappers in the correct order in the official documentation. * Enjoy writing your code :) -*/ -// Warning! The end of the file is the old definitions of function/structure names. -// They are for compatibility... Better not to use them. */ + * Warning! The end of the file is the old definitions of function/structure names. + * They are for compatibility... Better not to use them. +*/ #ifndef _KSYS_H_ #define _KSYS_H_ @@ -686,6 +686,8 @@ void _ksys_kill_by_pid(uint32_t PID) ); } +/*===================== Function 18, subfunction 21 ====================*/ +/*=====Get the slot number of the process / thread by identifier.. =====*/ static inline int _ksys_get_thread_slot(int PID){ @@ -962,12 +964,13 @@ uint32_t _ksys_get_skin_height(){ /*==================== Function 51 - create thread. ====================*/ static inline -int _ksys_start_thread(void* thread_entry, void* stack_top){ +int _ksys_create_thread(void* thread_entry, void* stack_top){ int val; asm_inline( "int $0x40" :"=a"(val) :"a"(51), "b"(1), "c"(thread_entry), "d"(stack_top) + :"memory" ); return val; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile index 5b65aa5ab..2130a39e8 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile +++ b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile @@ -21,6 +21,7 @@ clayer/libimg.kex \ clayer/dialog.kex \ clayer/msgbox.kex \ clayer/boxlib.kex \ +thread_work.kex LIBS= -ltcc -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c b/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c new file mode 100644 index 000000000..12d962f35 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c @@ -0,0 +1,69 @@ +/* + * An example of using threads to create a copy of a window. + * Built on top of the /programs/develop/examples/thread/trunk/thread.asm example. + * + * Created by turbocat (Maxim Logaev) 2021. +*/ + +#include +#include +#include + +#define TH_STACK_SIZE 1024 + +enum BUTTONS{ + BTN_QUIT = 1, + BTN_CREATE_TH = 2, +}; + +ksys_colors_table_t sys_colors; + +extern int main(); + +void redraw_window(void){ + ksys_pos_t mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS); + _ksys_start_draw(); + _ksys_create_window(mouse_pos.x, mouse_pos.y, 140, 60, "Threads", sys_colors.work_area, 0x14); + _ksys_define_button(10, 30, 120, 20, BTN_CREATE_TH, sys_colors.work_button); + _ksys_draw_text("Create thread!", 15, 34, 0, 0x90000000 | sys_colors.work_button_text); + _ksys_end_draw(); +} + +void create_thread(void){ + unsigned tid; // New thread ID + void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack + if(!th_stack){ + _ksys_debug_puts("Memory allocation error for thread!"); + return; + } + tid = _ksys_create_thread(main, th_stack+TH_STACK_SIZE); // Create new thread with entry "main" + if(tid==-1){ + _ksys_debug_puts("Unable to create a new thread!"); + return; + } + debug_printf("New thread created (TID=%u)\n", tid); +} + +int main(){ + _ksys_get_system_colors(&sys_colors); + int gui_event; + redraw_window(); + + while(1){ + gui_event = _ksys_get_event(); + switch(gui_event){ + case KSYS_EVENT_REDRAW: + redraw_window(); + break; + case KSYS_EVENT_BUTTON: + switch (_ksys_get_button()){ + case BTN_CREATE_TH: + create_thread(); + break; + case BTN_QUIT: + _ksys_exit(); + } + break; + } + } +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libc.c b/programs/develop/ktcc/trunk/libc.obj/source/libc.c index 23ffc9d4c..86b2bb1c8 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libc.c @@ -100,6 +100,7 @@ #include "stdlib/rand.c" #include "stdlib/qsort.c" #include "stdlib/assert.c" +#include "stdlib/atof.c" #include "math/acosh.c" #include "math/asinh.c" diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c new file mode 100644 index 000000000..f9f7f98a9 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c @@ -0,0 +1,8 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double +atof(const char *ascii) +{ + return strtod(ascii, 0); +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt b/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt index 9b3505dde..e5baef06b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt +++ b/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt @@ -46,6 +46,7 @@ abs atoi atol atoll +atof calloc div exit