diff --git a/programs/develop/ktcc/trunk/bin/lib/libshell.a b/programs/develop/ktcc/trunk/bin/lib/libshell.a new file mode 100644 index 0000000000..582aa71f6f Binary files /dev/null and b/programs/develop/ktcc/trunk/bin/lib/libshell.a differ diff --git a/programs/develop/ktcc/trunk/lib/libshell/Makefile b/programs/develop/ktcc/trunk/lib/libshell/Makefile new file mode 100644 index 0000000000..54d6dedbfc --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/Makefile @@ -0,0 +1,26 @@ +CC = kos32-tcc +AR = ar +CFLAGS = -c -I../../libc.obj/include + +LIB = libshell.a + +OBJS = \ + shell_exit.o \ + shell_puts.o \ + shell_get_pid.o \ + shell_ping.o \ + shell_getc.o \ + shell_cls.o \ + shell_init.o \ + shell_gets.o \ + shell_printf.o \ + shell_putc.o + +$(LIB): $(OBJS) + $(AR) -crs $@ $(OBJS) + +%.o : %.c Makefile + $(CC) $(CFLAGS) -o $@ $< + +clean: + rm -rf $(OBJS) $(LIB) \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/compile_flags.txt b/programs/develop/ktcc/trunk/lib/libshell/compile_flags.txt new file mode 100644 index 0000000000..8f44bce8ff --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/compile_flags.txt @@ -0,0 +1 @@ +-I../../libc.obj/include \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_cls.c b/programs/develop/ktcc/trunk/lib/libshell/shell_cls.c new file mode 100644 index 0000000000..e85af9b77c --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_cls.c @@ -0,0 +1,8 @@ +#include + +void shell_cls() +{ + __shell_init(); + *__shell_shm = SHELL_CLS; + __SHELL_WAIT(); +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_exit.c b/programs/develop/ktcc/trunk/lib/libshell/shell_exit.c new file mode 100644 index 0000000000..1c34e9f656 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_exit.c @@ -0,0 +1,11 @@ +#include +#include + +void shell_exit() +{ + if(__shell_is_init){ + *__shell_shm = SHELL_EXIT; + __SHELL_WAIT(); + _ksys_shm_close(__shell_shm_name); + } +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_get_pid.c b/programs/develop/ktcc/trunk/lib/libshell/shell_get_pid.c new file mode 100644 index 0000000000..d54cba03e6 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_get_pid.c @@ -0,0 +1,12 @@ +#include +#include + +unsigned shell_get_pid() +{ + unsigned pid; + __shell_init(); + *__shell_shm = SHELL_PID; + __SHELL_WAIT(); + memcpy(&pid, __shell_shm+1, sizeof(unsigned)); + return pid; +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_getc.c b/programs/develop/ktcc/trunk/lib/libshell/shell_getc.c new file mode 100644 index 0000000000..84c9efd1c9 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_getc.c @@ -0,0 +1,9 @@ +#include "shell_api.h" + +char shell_getc() +{ + __shell_init(); + *__shell_shm = SHELL_GETC; + __SHELL_WAIT(); + return *(__shell_shm+1); +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_gets.c b/programs/develop/ktcc/trunk/lib/libshell/shell_gets.c new file mode 100644 index 0000000000..41ff708fa3 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_gets.c @@ -0,0 +1,10 @@ +#include +#include + +void shell_gets(char *str, int n) +{ + __shell_init(); + *__shell_shm = SHELL_GETS; + __SHELL_WAIT(); + strncpy(str, __shell_shm+1, n); +} diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_init.c b/programs/develop/ktcc/trunk/lib/libshell/shell_init.c new file mode 100644 index 0000000000..c98ffe3d59 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_init.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +char app_name[13]; +char __shell_shm_name[32]; +char*__shell_shm=NULL; +int __shell_is_init=0; + +int __shell_shm_init() +{ + __shell_is_init=1; + ksys_thread_t *proc_info = (ksys_thread_t*)malloc(sizeof(ksys_thread_t)); + if(proc_info == NULL){ + return -1; + } + unsigned PID; + + _ksys_thread_info(proc_info, -1); + PID = proc_info->pid; + strncpy(app_name, proc_info->name, 12); + free(proc_info); + + itoa(PID, __shell_shm_name); + strcat(__shell_shm_name, "-SHELL"); + return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm); +} + +void __shell_init() +{ + if(!__shell_is_init){ + if(__shell_shm_init()){ + debug_printf("%s: shell problems detected!\n", app_name); + _ksys_exit(); + } + + if(!shell_ping()){ + debug_printf("%s: no shell found!\n", app_name); + _ksys_exit(); + } + } +} diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_ping.c b/programs/develop/ktcc/trunk/lib/libshell/shell_ping.c new file mode 100644 index 0000000000..87c1169fe8 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_ping.c @@ -0,0 +1,13 @@ +#include +#include + +int shell_ping() +{ + __shell_init(); + *__shell_shm = SHELL_PING; + _ksys_delay(10); + if(*__shell_shm==SHELL_OK){ + return 1; + } + return 0; +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_printf.c b/programs/develop/ktcc/trunk/lib/libshell/shell_printf.c new file mode 100644 index 0000000000..c61628e47f --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_printf.c @@ -0,0 +1,12 @@ +#include +#include + +void shell_printf(const char *format,...) +{ + va_list ap; + va_start (ap, format); + *__shell_shm=SHELL_PUTS; + vsnprintf(__shell_shm+1, SHELL_SHM_MAX, format, ap); + va_end(ap); + __SHELL_WAIT(); +} diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_putc.c b/programs/develop/ktcc/trunk/lib/libshell/shell_putc.c new file mode 100644 index 0000000000..fa4d7b9284 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_putc.c @@ -0,0 +1,9 @@ +#include + +void shell_putc(char c) +{ + __shell_init(); + *__shell_shm = SHELL_PUTC; + *(__shell_shm+1) = c; + __SHELL_WAIT(); +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/libshell/shell_puts.c b/programs/develop/ktcc/trunk/lib/libshell/shell_puts.c new file mode 100644 index 0000000000..58ddf8734c --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libshell/shell_puts.c @@ -0,0 +1,10 @@ +#include +#include + +void shell_puts(const char *str) +{ + __shell_init(); + *__shell_shm = SHELL_PUTS; + strcpy(__shell_shm+1, str); + __SHELL_WAIT(); +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h b/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h new file mode 100644 index 0000000000..3a68b2d4b6 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h @@ -0,0 +1,37 @@ +#ifndef _SHELL_API_H_ +#define _SHELL_API_H_ + +#include + +#define SHELL_OK 0 +#define SHELL_EXIT 1 +#define SHELL_PUTC 2 +#define SHELL_PUTS 3 +#define SHELL_GETC 4 +#define SHELL_GETS 5 +#define SHELL_CLS 6 +#define SHELL_PID 7 +#define SHELL_PING 8 + +#define SHELL_SHM_MAX 1024*16 + +extern char __shell_shm_name[32]; +extern char *__shell_shm; +extern int __shell_is_init; +extern void __shell_init(); + +#define __SHELL_WAIT() while (*__shell_shm) _ksys_delay(5) + +extern int shell_ping(); +extern unsigned shell_get_pid(); +extern void shell_exit(); + +extern char shell_getc(); +extern void shell_gets(char *str, int n); + +extern void shell_putc(char c); +extern void shell_puts(const char *str); +extern void shell_printf(const char *format,...); + +extern void shell_cls(); +#endif diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile index b0ad39d36e..2e72c0d2ac 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile +++ b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile @@ -1,4 +1,3 @@ - KTCC=kos32-tcc FASM= fasm KPACK = kpack @@ -22,9 +21,10 @@ clayer/dialog.kex \ clayer/msgbox.kex \ clayer/boxlib.kex \ thread_work.kex \ -sdltest.kex +sdltest.kex \ +shell_test.kex -LIBS= -lSDL -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj +LIBS= -lSDL -lshell -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj all: $(BIN) diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh index a452e4ff34..108d7dae5b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh @@ -18,3 +18,4 @@ cp /kolibrios/develop/tcc/samples/clayer/logo.png /tmp0/1/tcc_samples/logo.png /kolibrios/develop/tcc/tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -ltcc -lrasterworks -lc.obj /kolibrios/develop/tcc/tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc.obj /kolibrios/develop/tcc/tcc -I/kolibrios/develop/tcc/include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound -ltcc -lc.obj +/kolibrios/develop/tcc/tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell -ltcc -lc.obj diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c new file mode 100644 index 0000000000..c56a5869ba --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c @@ -0,0 +1,20 @@ + #include "../include/shell_api.h" + +char string[256]; + +int main(){ + shell_cls(); + shell_printf("SHELL PID=%d\n\r", shell_get_pid()); + + shell_puts("This is a test console application for Shell\n\r"); + shell_puts("Type a string (255 symbols max): "); + + shell_gets(string, 255); + shell_printf("You typed: %s\n\r", string); + + shell_puts("Press any key: "); + string[0] = shell_getc(); + shell_printf("\n\rYou pressed: %c", string[0]); + shell_exit(); + return 0; +} \ No newline at end of file