From befac9b2424114fef7ab40c8032852a042ea4878 Mon Sep 17 00:00:00 2001 From: pavelyakov Date: Fri, 27 Nov 2015 09:20:48 +0000 Subject: [PATCH] source code library git-svn-id: svn://kolibrios.org@5936 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/libraries/libs_v2/array.bat | 1 + programs/develop/libraries/libs_v2/array.c | 244 +++++ programs/develop/libraries/libs_v2/build.bat | 10 + programs/develop/libraries/libs_v2/coff.h | 45 + programs/develop/libraries/libs_v2/fs.bat | 1 + programs/develop/libraries/libs_v2/fs.c | 897 ++++++++++++++++++ .../develop/libraries/libs_v2/include/all.h | 18 + .../develop/libraries/libs_v2/include/array.h | 24 + .../libraries/libs_v2/include/boolean.c | 3 + .../libraries/libs_v2/include/console.c | 117 +++ .../develop/libraries/libs_v2/include/ctype.c | 39 + .../develop/libraries/libs_v2/include/font.h | 13 + .../develop/libraries/libs_v2/include/fs.c | 394 ++++++++ .../develop/libraries/libs_v2/include/fs.h | 23 + .../libraries/libs_v2/include/kolibri.c | 525 ++++++++++ .../develop/libraries/libs_v2/include/lexer.h | 1 + .../libraries/libs_v2/include/library.h | 51 + .../develop/libraries/libs_v2/include/math.c | 76 ++ .../libraries/libs_v2/include/stdlib.c | 49 + .../libraries/libs_v2/include/string.c | 197 ++++ .../develop/libraries/libs_v2/library.bat | 1 + programs/develop/libraries/libs_v2/library.c | 151 +++ 22 files changed, 2880 insertions(+) create mode 100644 programs/develop/libraries/libs_v2/array.bat create mode 100644 programs/develop/libraries/libs_v2/array.c create mode 100644 programs/develop/libraries/libs_v2/build.bat create mode 100644 programs/develop/libraries/libs_v2/coff.h create mode 100644 programs/develop/libraries/libs_v2/fs.bat create mode 100644 programs/develop/libraries/libs_v2/fs.c create mode 100644 programs/develop/libraries/libs_v2/include/all.h create mode 100644 programs/develop/libraries/libs_v2/include/array.h create mode 100644 programs/develop/libraries/libs_v2/include/boolean.c create mode 100644 programs/develop/libraries/libs_v2/include/console.c create mode 100644 programs/develop/libraries/libs_v2/include/ctype.c create mode 100644 programs/develop/libraries/libs_v2/include/font.h create mode 100644 programs/develop/libraries/libs_v2/include/fs.c create mode 100644 programs/develop/libraries/libs_v2/include/fs.h create mode 100644 programs/develop/libraries/libs_v2/include/kolibri.c create mode 100644 programs/develop/libraries/libs_v2/include/lexer.h create mode 100644 programs/develop/libraries/libs_v2/include/library.h create mode 100644 programs/develop/libraries/libs_v2/include/math.c create mode 100644 programs/develop/libraries/libs_v2/include/stdlib.c create mode 100644 programs/develop/libraries/libs_v2/include/string.c create mode 100644 programs/develop/libraries/libs_v2/library.bat create mode 100644 programs/develop/libraries/libs_v2/library.c diff --git a/programs/develop/libraries/libs_v2/array.bat b/programs/develop/libraries/libs_v2/array.bat new file mode 100644 index 0000000000..4870fdc26b --- /dev/null +++ b/programs/develop/libraries/libs_v2/array.bat @@ -0,0 +1 @@ +build.bat %~n0 \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/array.c b/programs/develop/libraries/libs_v2/array.c new file mode 100644 index 0000000000..5ab4394fea --- /dev/null +++ b/programs/develop/libraries/libs_v2/array.c @@ -0,0 +1,244 @@ +/* + 2015 + Author: Pavel Yakovlev. +*/ + +#define LIB_NAME "array" + +#include "coff.h" + +#include +#include + +typedef struct +{ + dword key; + dword value; +} array; + +char *ARRAY_KEY_STRING = (char *)0; +char *ARRAY_VALUE_STRING = (char *)0; +array *ARRAY_ADRESS = (dword)0; + +dword hash_binary(char *data,dword size) +{ + byte h1,h2,h3,h4; + if(!size) return 0; + h1 = *data; + if(size==1) return h1<<24; + h2 = *++data; + if(size==2) return (h1<<24)|(h2<<16); + h3 = *++data; + if(size==3) return (h1<<24)|(h2<<16)|(h3<<8); + h4 = *++data; + if(size==4) return (h1<<24)|(h2<<16)|(h3<<8)|(h4); + + size-=4; + + while(size--) + { + h1^=*data;h2^=*data;h3^=*data;h4^=*data; + ++data; + } + + return (h1<<24)|(h2<<16)|(h3<<8)|(h4); +} +dword hash_string(char *data) +{ + byte h1,h2,h3,h4; + if(!*data) return 0; + h1 = *data; + if(!*++data) return h1<<24; + h2 = *data; + if(!*++data) return (h1<<24)|(h2<<16); + h3 = *data; + if(!*++data) return (h1<<24)|(h2<<16)|(h3<<8); + h4 = *data; + if(!*++data) return (h1<<24)|(h2<<16)|(h3<<8)|(h4); + + while(*data) + { + h1^=*data;h2^=*data;h3^=*data;h4^=*data; + ++data; + } + + return (h1<<24)|(h2<<16)|(h3<<8)|(h4); +} + +dword hash_integer(dword dec) +{ + dword tmp = dec; + tmp <<= 16; + tmp ^= 0xFFFFFFFF; + dec &= tmp; + dec ^= dec>>5; + dec += dec<<3; + dec ^= dec>>13; + tmp = dec<<9; + tmp ^= 0xFFFFFFFF; + dec += tmp; + dec ^= dec>>17; + return dec; +} + +dword buffer = 0xFF; +dword ARRAY_COUNT = 0; +dword tmp,tmp1; + +array *key_string_set(dword *ary,char *key,void *data) +{ + //dword *ptr = (dword *)ary; + array *m; + if(!*ary) + { + *ary = (dword)malloc(sizeof(array)*(buffer+1)); + m = (array *)*ary; + m[0].value = buffer; + } + + else + { + m = (array *)*ary; + if(m[0].value<=m[0].key) + { + m[0].value += buffer; + *ary = (dword)realloc((void*)*ary,sizeof(array)*(m[0].value+1)); + } + } + + ++m[0].key; + + dword tmp = hash_string(key)%buffer; + tmp+=(m[0].value/buffer)*buffer; + ++tmp; + + while(m[tmp].key) + { + if(!strcmp(key,(char*)m[tmp].key))break; + ++tmp; + } + m[tmp].key = (dword)key; + m[tmp].value = (dword)data; + return m; +} + +array *key_binary_set(dword *ary,void *key,void *data,dword size) +{ + + array *m; + if(!*ary) + { + *ary = (dword)malloc(sizeof(array)*(buffer+1)); + m = (array *)*ary; + m[0].value = buffer+1; + } + else + { + m = (array *)*ary; + } + + ++m[0].key; + + dword tmp = hash_string(key)%buffer; + ++tmp; + while(m[tmp].key) + { + if(!strncmp((char*)key,(char*)m[tmp].key,size))break; + ++tmp; + } + m[tmp].key = (dword)key; + m[tmp].value = (dword)data; + return m; +} + +array *key_integer_set(dword *ary,dword key,void *data) +{ + + + if(!*ary) + { + //(dword)m[0].value = (dword)buffer; + *ary = (dword)malloc(sizeof(array)*(buffer+1)); + } + + array *m = (array *)*ary; + + dword tmp = hash_integer(key)%buffer; + + while(m[tmp].key) + { + if(key==m[tmp].key)break; + ++tmp; + } + m[tmp].key = (dword)key; + m[tmp].value = (dword)data; + return m; +} + + +void *key_string_get(dword *ary,char *key) +{ + if(!*ary)return 0; + + array *m = (array *)*ary; + + dword tmp = hash_string(key)%buffer; + tmp+=(m[0].value/buffer)*buffer; + ++tmp; + while(m[tmp].key) + { + if(!strcmp(key,(char*)m[tmp].key))break; + ++tmp; + } + return (void *)m[tmp].value; +} + +void *key_binary_get(dword *ary,char *key,dword size) +{ + if(!*ary)return 0; + + array *m = (array *)*ary; + + dword tmp = hash_string(key)%buffer; + + while(m[tmp].key) + { + if(!strncmp(key,(char*)m[tmp].key,size))break; + ++tmp; + } + return (void *)m[tmp].value; +} + +void *key_integer_get(dword *ary,dword key) +{ + if(!*ary)return 0; + + array *m = (array *)*ary; + + dword tmp = hash_integer(key)%buffer; + + while(m[tmp].key) + { + if(key==m[tmp].key)break; + ++tmp; + } + return (void *)m[tmp].value; +} + + +EXPORT_ + export(buffer) + + export(hash_string) + export(hash_binary) + export(hash_integer) + + export(key_string_set) + export(key_binary_set) + export(key_integer_set) + + export(key_string_get) + export(key_binary_get) + export(key_integer_get) + +_EXPORT \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/build.bat b/programs/develop/libraries/libs_v2/build.bat new file mode 100644 index 0000000000..d50c9bf1cd --- /dev/null +++ b/programs/develop/libraries/libs_v2/build.bat @@ -0,0 +1,10 @@ +set FILE_NAME=%1 +set DIR_LIB=C:\Programs\KlbrInWin\LIB + +del "%FILE_NAME%.obj" +gcc -w --target=alpha-coff -nostdlib -I"./include" --prefix=/opt/cross-gcc -c -o "%FILE_NAME%.obj" "%FILE_NAME%.c" +kpack %FILE_NAME%.obj +@echo off +copy "%FILE_NAME%.obj" "%DIR_LIB%\%FILE_NAME%.obj">Nul + +pause \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/coff.h b/programs/develop/libraries/libs_v2/coff.h new file mode 100644 index 0000000000..b05294897f --- /dev/null +++ b/programs/develop/libraries/libs_v2/coff.h @@ -0,0 +1,45 @@ +/* + 2015 + Author: Pavel Yakovlev. +*/ + +typedef struct +{ + void *name; + void *function; +} export_t; + +typedef unsigned long long qword; +typedef unsigned int dword; +typedef unsigned char byte; +typedef unsigned short word; + +#define NULL ((void*)0) + +#define quotess(name) #name + +#ifdef NO_LIBIMPORT_FUNC + #define EXPORT_ export_t EXPORTS[]={ +#else + #define EXPORT_ export_t EXPORTS[]={{"lib_pointer_library",&lib_pointer_library}, +#endif + + +#define export(name) {LIB_NAME "." quotess(name),&name}, +#define _EXPORT { NULL, NULL }}; + +#ifndef NO_LIBIMPORT_FUNC +static struct LIBDLL_STRUCT +{ + int (*load)(char *path); + dword (*get)(char *name); +}; + +static inline struct LIBDLL_STRUCT library; + +static void lib_pointer_library(dword adr1,dword adr2) +{ + library.load = adr1; + library.get = adr2; +} +#endif \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/fs.bat b/programs/develop/libraries/libs_v2/fs.bat new file mode 100644 index 0000000000..4870fdc26b --- /dev/null +++ b/programs/develop/libraries/libs_v2/fs.bat @@ -0,0 +1 @@ +build.bat %~n0 \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/fs.c b/programs/develop/libraries/libs_v2/fs.c new file mode 100644 index 0000000000..14de6997df --- /dev/null +++ b/programs/develop/libraries/libs_v2/fs.c @@ -0,0 +1,897 @@ +/* + 2015 + Author: Pavel Yakovlev. +*/ + +#define LIB_NAME "fs" + +#include "coff.h" +#include +#include + + +//char _PATH_[4096]; +char *_PATH_; +dword *_ADR_ = 32; +char *FS_SELF_PATH; +char *FS_SELF_DIR=0; + +char TMP1[4096] = {0}; +char TMP2[4096] = {0}; + +static void*(* _stdcall pointer_callback_copy)(void); +static void*(* _stdcall pointer_callback_move)(void); +static void*(* _stdcall pointer_callback_remove)(void); + +#pragma pack(push,1) +typedef struct +{ +unsigned p00; +unsigned p04; +unsigned p08; +unsigned p12; +unsigned p16; +char p20; +char *p21; +} FS_struct70; +#pragma pack(pop) + +#pragma pack(push,1) +typedef struct +{ +unsigned p00; +char p04; +char p05[3]; +unsigned p08; +unsigned p12; +unsigned p16; +unsigned p20; +unsigned p24; +unsigned p28; +//unsigned p32[2]; +long long p32; +unsigned p40; +} FS_struct_BDVK; +#pragma pack(pop) + +#define FS_COPY_BUFFER_SET 0x100000 +static inline char BUF_COPY[FS_COPY_BUFFER_SET] = {0}; + +static inline char *string_error_code(char code) +{ + if(!code)return "Successfully!"; + if(code==1)return "Not defined basis and / or hard disk partition (sub-functions 7, 8 function 21)!"; + if(code==2)return "Function is not supported for this file system!"; + if(code==3)return "Unknown file system!"; + if(code==4)return "Reserved, never returned to the current implementation!"; + if(code==5)return "File not found!"; + if(code==6)return "The file is ended!"; + if(code==7)return "Pointer out the application memory!"; + if(code==8)return "Disk is full!"; + if(code==9)return "FAT table is destroyed!"; + if(code==10)return "Access is denied!"; + if(code==11)return "Device error!"; + return "An unexpected error!"; +} + +static inline dword sprintf(char *mstr,const char *fmt,...) +{ + + dword *arg = &fmt; + char *tmp = 0; + char *pos = mstr; + --pos; + --fmt; + while(*++fmt) + { + char s = *fmt; + if(s=='%') + { + s = *++fmt; + if(s=='s') + { + tmp = *++arg; + while(*tmp)*++pos = *tmp++; + } + else + { + *++pos='%'; + --fmt; + } + } + else *++pos=s; + } + *++pos = 0; + return pos-mstr; +} + +static inline int FS_file_70(FS_struct70 *k) +{ + asm volatile ("int $0x40"::"a"(70), "b"(k)); +} + +FS_struct_BDVK ret_struct; +static inline char get_bdvk(char *path) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 5; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = (unsigned)&ret_struct; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + return FS_file_70(&file_read_struct); + //return (FS_struct_BDVK*)&ret_struct; +} + +static inline char set_bdvk(char *path,FS_struct_BDVK *bdvk) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 6; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = bdvk; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + return FS_file_70(&file_read_struct); +} + +static inline long long file_size(char *path) +{ + FS_struct_BDVK *data = get_bdvk(path); + return data->p32; +} + +static inline byte file_isdir(char *path) +{ + FS_struct_BDVK *data = get_bdvk(path); + if(data->p00&0b10000)return 1; + return 0; +} + +static inline byte file_ismetka(char *path) +{ + FS_struct_BDVK *data = get_bdvk(path); + if(data->p00&0b1000)return 1; + return 0; +} + +static inline byte file_isfile() +{ + //FS_struct_BDVK *data = get_bdvk(path); + if(ret_struct.p00&0b11000)return 0; + return 1; +} + +static inline int file_run(char *path,char *arg) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 7; + file_read_struct.p04 = 0; + file_read_struct.p08 = arg; + file_read_struct.p12 = 0; + file_read_struct.p16 = 0; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + return FS_file_70(&file_read_struct); + +} + +static inline int file_read_binary(char *path,unsigned pos,unsigned size,void *adr) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 0; + file_read_struct.p04 = pos; + file_read_struct.p08 = 0; + file_read_struct.p12 = size; + file_read_struct.p16 = (unsigned)adr; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error read file (%s) file: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_delete(char *path) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 8; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = 0; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error delete file: %s. Info: %s'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_mkdir(char *path) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 9; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = 0; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error make dir: %s. Info: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_write(char *path,void *ukaz,dword size) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 2; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = size; + file_read_struct.p16 = ukaz; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error write file: %s. Info: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_rewrite(char *path,dword pos1,dword pos2,void *ukaz,dword size) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 3; + file_read_struct.p04 = pos1; + file_read_struct.p08 = pos2; + file_read_struct.p12 = size; + file_read_struct.p16 = ukaz; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error rewrite file (%s) file: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + + +static inline char file_copy(char *path1,char *path2) +{ + long long size = file_size(path1); + if(!size)file_write(path2,&BUF_COPY,0); + long long cel = size; + cel /= FS_COPY_BUFFER_SET; + dword ost = size-cel*FS_COPY_BUFFER_SET; + long long i = 0; + char err=0; + if(cel) + { + if(file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR; + if(file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR; + ++i; + } + else + { + if(file_read_binary(path1,0,ost,&BUF_COPY))goto ERROR; + if(file_write(path2,&BUF_COPY,ost))goto ERROR; + return 1; + } + while(i0)--quantity_dir; + asm volatile(""::"c"(quantity_dir),"d"(quantity_file)); + return (dword)size; +} + +/* +char set_attributes_loop(char *path,dword strucs) +{ + if(get_bdvk(path))return 0; + dword tmp = (ret_struct.p00^strucs)&0b111; + ret_struct.p00=(tmp^ret_struct.p00)^0xFFFFFFFF; + if(ret_struct.p00&0b10000) + { + dword tmp_buf = _get_dir_info(path); + if(!COUNT_FILE) goto END; + + char *new_path_file = malloc(4096); + int tmp_count = COUNT_FILE; + int i = 0; + char *position = tmp_buf+72; + while(i= 97) && (c <= 122) ) + return c-32 ; + +if ( (c >= 160) && (c <= 175) ) + return c-32 ; + +if ( (c >= 224) && (c <= 239) ) + return c-80 ; + +if ( (c == 241) || (c == 243) || (c == 245) || (c == 247) ) + return c-1; + +return c; +} + +static inline int tolower(int c) +{ + +if ( (c >= 65) && (c <= 90) ) + return c+32 ; + +if ( (c >= 128) && (c <= 143) ) + return c+32 ; + +if ( (c >= 144) && (c <= 159) ) + return c+80 ; + +if ( (c == 240) || (c == 242) || (c == 244) || (c == 246) ) + return c+1; + +return c; +} + diff --git a/programs/develop/libraries/libs_v2/include/font.h b/programs/develop/libraries/libs_v2/include/font.h new file mode 100644 index 0000000000..f6a92217b4 --- /dev/null +++ b/programs/develop/libraries/libs_v2/include/font.h @@ -0,0 +1,13 @@ + +:typedef struct +{ + char (*load)(char *path); +} _FONT_; +_FONT_ font; + +static inline font_lib_init(void) +{ + if(font.load)return; + library.load("/sys/lib/font.obj"); + font.load = library.get("font.load"); +} \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/include/fs.c b/programs/develop/libraries/libs_v2/include/fs.c new file mode 100644 index 0000000000..36e3deb74a --- /dev/null +++ b/programs/develop/libraries/libs_v2/include/fs.c @@ -0,0 +1,394 @@ +#ifndef FS_C_INCLUDE +#define FS_C_INCLUDE + +#include "stdlib.c" + +#pragma pack(push,1) +typedef struct +{ +unsigned p00; +unsigned p04; +unsigned p08; +unsigned p12; +unsigned p16; +char p20; +char *p21; +} FS_struct70; +#pragma pack(pop) + +#pragma pack(push,1) +typedef struct +{ +unsigned p00; +char p04; +char p05[3]; +unsigned p08; +unsigned p12; +unsigned p16; +unsigned p20; +unsigned p24; +unsigned p28; +//unsigned p32[2]; +long long p32; +unsigned p40; +} FS_struct_BDVK; +#pragma pack(pop) + +#define FS_COPY_BUFFER_SET 0x100000 +static inline char BUF_COPY[FS_COPY_BUFFER_SET] = {0}; + +static inline char *string_error_code(char code) +{ + if(!code)return "Successfully!"; + if(code==1)return "Not defined basis and / or hard disk partition (sub-functions 7, 8 function 21)!"; + if(code==2)return "Function is not supported for this file system!"; + if(code==3)return "Unknown file system!"; + if(code==4)return "Reserved, never returned to the current implementation!"; + if(code==5)return "File not found!"; + if(code==6)return "The file is ended!"; + if(code==7)return "Pointer out the application memory!"; + if(code==8)return "Disk is full!"; + if(code==9)return "FAT table is destroyed!"; + if(code==10)return "Access is denied!"; + if(code==11)return "Device error!"; + return "An unexpected error!"; +} + +static inline dword sprintf(char *mstr,const char *fmt,...) +{ + + dword *arg = &fmt; + char *tmp = 0; + char *pos = mstr; + --pos; + --fmt; + while(*++fmt) + { + char s = *fmt; + if(s=='%') + { + s = *++fmt; + if(s=='s') + { + tmp = *++arg; + while(*tmp)*++pos = *tmp++; + } + else + { + *++pos='%'; + --fmt; + } + } + else *++pos=s; + } + *++pos = 0; + return pos-mstr; +} + +static inline int FS_file_70(FS_struct70 *k) +{ + asm volatile ("int $0x40"::"a"(70), "b"(k)); +} + +FS_struct_BDVK ret_struct; +static inline FS_struct_BDVK* get_bdvk(char *path) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 5; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = (unsigned)&ret_struct; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + FS_file_70(&file_read_struct); + return (FS_struct_BDVK*)&ret_struct; +} + +static inline long long file_size(char *path) +{ + FS_struct_BDVK *data = get_bdvk(path); + return data->p32; +} + +static inline byte file_isdir(char *path) +{ + FS_struct_BDVK *data = get_bdvk(path); + if(data->p00&0b10000)return 1; + return 0; +} + +static inline byte file_ismetka(char *path) +{ + FS_struct_BDVK *data = get_bdvk(path); + if(data->p00&0b1000)return 1; + return 0; +} + +static inline byte file_isfile() +{ + //FS_struct_BDVK *data = get_bdvk(path); + if(ret_struct.p00&0b11000)return 0; + return 1; +} + +static inline int file_run(char *path,char *arg) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 7; + file_read_struct.p04 = 0; + file_read_struct.p08 = arg; + file_read_struct.p12 = 0; + file_read_struct.p16 = 0; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + return FS_file_70(&file_read_struct); + +} + +static inline int file_read_binary(char *path,unsigned pos,unsigned size,void *adr) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 0; + file_read_struct.p04 = pos; + file_read_struct.p08 = 0; + file_read_struct.p12 = size; + file_read_struct.p16 = (unsigned)adr; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error read file (%s) file: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_delete(char *path) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 8; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = 0; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error delete file: %s. Info: %s'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_mkdir(char *path) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 9; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = 0; + file_read_struct.p16 = 0; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error make dir: %s. Info: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_write(char *path,void *ukaz,dword size) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 2; + file_read_struct.p04 = 0; + file_read_struct.p08 = 0; + file_read_struct.p12 = size; + file_read_struct.p16 = ukaz; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error write file: %s. Info: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + +static inline int file_rewrite(char *path,dword pos1,dword pos2,void *ukaz,dword size) +{ + FS_struct70 file_read_struct; + file_read_struct.p00 = 3; + file_read_struct.p04 = pos1; + file_read_struct.p08 = pos2; + file_read_struct.p12 = size; + file_read_struct.p16 = ukaz; + file_read_struct.p20 = 0; + file_read_struct.p21 = path; + char c = FS_file_70(&file_read_struct); + if(c) + { + sprintf(&BUF_COPY,"'Error rewrite file (%s) file: %s.'E",string_error_code(c),path); + file_run("/sys/@notify",&BUF_COPY); + } + return c; +} + + +static inline char file_copy(char *path1,char *path2) +{ + long long size = file_size(path1); + if(!size)file_write(path2,&BUF_COPY,0); + long long cel = size; + cel /= FS_COPY_BUFFER_SET; + dword ost = size-cel*FS_COPY_BUFFER_SET; + long long i = 0; + char err=0; + if(cel) + { + if(file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR; + if(file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR; + ++i; + } + else + { + if(file_read_binary(path1,0,ost,&BUF_COPY))goto ERROR; + if(file_write(path2,&BUF_COPY,ost))goto ERROR; + return 1; + } + while(i 1 ) + board_puti(n / 10); + + c = n % 10 + '0'; + asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c)); + +} + + +static inline int file_70(struct70 *k) +{ + asm volatile ("int $0x40"::"a"(70), "b"(k)); +} + + +static inline struct_import* cofflib_load(char *name) +{ + asm volatile ("int $0x40"::"a"(68), "b"(19), "c"(name)); +} + + +static inline void* cofflib_procload (struct_import *imp, char *name) +{ + int i; + for (i=0;;i++) + if ( NULL == ((imp+i) -> name)) + break; + else + if ( 0 == strcmp(name, (imp+i)->name) ) + return (imp+i)->data; + return NULL; +} + + +static inline unsigned cofflib_procnum (struct_import *imp) +{ + unsigned i, n; + + for (i=n=0;;i++) + if ( NULL == ((imp+i) -> name)) + break; + else + n++; + + return n; +} + + +static inline void cofflib_procname (struct_import *imp, char *name, unsigned n) +{ + unsigned i; + *name = 0; + + for (i=0;;i++) + if ( NULL == ((imp+i) -> name)) + break; + else + if ( i == n ) + { + strcpy(name, ((imp+i)->name)); + break; + } + +} + + +static inline unsigned system_cpufreq() +{ + asm volatile ("int $0x40"::"a"(18), "b"(5)); +} + + +static inline unsigned system_mem() +{ + asm volatile ("int $0x40"::"a"(18), "b"(17)); +} + + +static inline unsigned system_memfree() +{ + asm volatile ("int $0x40"::"a"(18), "b"(16)); +} + + +static inline unsigned system_time_get() +{ + asm volatile ("int $0x40"::"a"(3)); +} + + +static inline unsigned system_date_get() +{ + asm volatile ("int $0x40"::"a"(29)); +} + + +static inline unsigned system_end(unsigned param) +{ + asm volatile ("int $0x40"::"a"(18), "b"(9), "c"(param)); +} + +static inline unsigned win_min() +{ + asm volatile ("int $0x40"::"a"(18), "b"(10)); +} + + +static inline void path_file2dir(char *dir, char *fname) +{ + unsigned i; + strcpy (dir, fname); + for ( i = strlen(dir);; --i) + if ( '/' == dir[i]) + { + dir[i] = '\0'; + return; + } +} + + +static inline void path_full(char *full, char *fname) +{ + char temp[256]; + + switch (*fname) + { + + case '/': + strncpy(temp, fname+1, 2); + temp[2]=0; + if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) ) + strcpy (full, fname); + break; + + case '.': + break; + + default: + break; + + }; +} + + + +static inline void __attribute__((__always_inline__)) screen_wait_rr() +{ + asm volatile ("int $0x40"::"a"(18), "b"(14)); +} + + + +static inline void screen_get_size(unsigned *w, unsigned *h) +{ + unsigned size; + asm volatile ("int $0x40":"=a"(size):"a"(14)); + *h = size&0xFFFF; + *w = size>>16; +} + + +static inline unsigned skin_height() +{ + asm volatile ("int $0x40"::"a"(48), "b"(4)); +} + + +static inline unsigned thread_start(unsigned start, unsigned stack) +{ + asm volatile ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack)); +} + + +static inline unsigned time_tick() +{ + asm volatile ("int $0x40"::"a"(26), "b"(9)); +} + + +static inline unsigned sound_speaker(char data[]) +{ + asm volatile ("movl %0, %%esi"::"a"(data)); + asm volatile ("int $0x40"::"a"(55), "b"(55)); +} + + +static inline unsigned process_info(signed slot, char buf1k[]) +{ + asm volatile ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot)); +} + + +static inline int process_kill_pid(unsigned process) +{ + asm volatile ("int $0x40"::"a"(18), "b"(18), "c"(process)); +} + +static inline int kill_process(unsigned process) +{ + asm volatile ("int $0x40"::"a"(18), "b"(2), "c"(process)); +} + +static inline void get_kernel_ver(char buff16b[]) +{ + asm volatile ("int $0x40"::"a"(18), "b"(13), "c"(buff16b)); +} + +static inline long GetFreeRam(void) +{ + asm ("int $0x40"::"a"(18), "b"(16)); +} + +static inline long WaitBlanking(void) +{ + asm ("int $0x40"::"a"(18), "b"(14)); +} + +static inline int buffer_open(char name[], int mode, int size, char **buf) +{ + int error; + asm volatile ("int $0x40":"=a"(*buf), "=d"(error):"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)); + return error; +} + +static inline void buffer_close(char name[]) +{ + asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name)); +} + +static inline int clip_num() +{ + asm volatile ("int $0x40"::"a"(54), "b"(0)); +} + +static inline char* clip_get(int n) +{ + asm volatile ("int $0x40"::"a"(54), "b"(1), "c"(n)); +} + +static inline int clip_set(int n, char buffer[]) +{ + asm volatile ("int $0x40"::"a"(54), "b"(2), "c"(n), "d"(buffer)); +} + + +#endif \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/include/lexer.h b/programs/develop/libraries/libs_v2/include/lexer.h new file mode 100644 index 0000000000..d3f5a12faa --- /dev/null +++ b/programs/develop/libraries/libs_v2/include/lexer.h @@ -0,0 +1 @@ + diff --git a/programs/develop/libraries/libs_v2/include/library.h b/programs/develop/libraries/libs_v2/include/library.h new file mode 100644 index 0000000000..92ff9b44a4 --- /dev/null +++ b/programs/develop/libraries/libs_v2/include/library.h @@ -0,0 +1,51 @@ +#ifndef LIBRARY_H +#define LIBRARY_H + +#pragma pack(push,1) + typedef struct + { + char *name; + void *data; + } struct_import_lib_init; +#pragma pack(pop) + +typedef struct +{ + int (*load)(char *path); + unsigned int (*get)(char *name); +} OBJECT_LIBRARY; + +static char init_load_obj = 0; + +static int (* _stdcall _ptr_load_dll_)(char *path); +static unsigned int (* _stdcall _ptr_get_dll_)(char *path); + +static inline int _OBJECT__LOAD_(char *path) +{ + struct_import_lib_init *imp; + if(!init_load_obj) + { + asm("int $0x40":"=a"(imp):"a"(68), "b"(19), "c"("/sys/lib/library.obj")); + _ptr_load_dll_ = imp[0].data; + _ptr_get_dll_ = imp[1].data; + init_load_obj = 1; + } + return _ptr_load_dll_(path); +} + +static inline unsigned int _OBJECT__GET_(char *name) +{ + return _ptr_get_dll_(name); +} + +static inline OBJECT_LIBRARY library = {&_OBJECT__LOAD_,&_OBJECT__GET_}; + +/* + Example: + void*(* stdcall name_func)(...); + library.load("/sys/lib/... .obj"); + name_func = library.get("name_function"); + name_func(...); +*/ + +#endif \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/include/math.c b/programs/develop/libraries/libs_v2/include/math.c new file mode 100644 index 0000000000..0e2c141f86 --- /dev/null +++ b/programs/develop/libraries/libs_v2/include/math.c @@ -0,0 +1,76 @@ +//IO library +#ifndef INCLUDE_MATH_C +#define INCLUDE_MATH_C + +static inline signed math_round(float x) +{ + x+=0.6; + return x; +} +static inline signed math_ceil(float x) +{ + long z = (long)x; + if(z> 16); +} + + +static inline void* malloc(unsigned s) +{ + asm ("int $0x40"::"a"(68), "b"(12), "c"(s) ); +} + + +static inline void free(void *p) +{ + asm ("int $0x40"::"a"(68), "b"(13), "c"(p) ); +} + +static inline void *realloc(void *data, long size) +{ + void *r = malloc(size); + byte *p = (byte *)r; + byte *pd = (byte *)data; + while(size--) *p++=*pd++; + free(data); + return r; +} + + +#endif \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/include/string.c b/programs/develop/libraries/libs_v2/include/string.c new file mode 100644 index 0000000000..1d9714e43d --- /dev/null +++ b/programs/develop/libraries/libs_v2/include/string.c @@ -0,0 +1,197 @@ + +#ifndef NULL +#define NULL ((void*)0) +#endif + +static inline void* memset(void *mem, int c, unsigned size) +{ +unsigned i; + +for ( i = 0; i < size; i++ ) + *((char *)mem+i) = (char) c; + +return NULL; +} + + +static inline void* memcpy(void *dst, const void *src, unsigned size) +{ + +unsigned i; + +for ( i = 0; i < size; i++) + *(char *)(dst+i) = *(char *)(src+i); + +return NULL; +} + + +static inline int memcmp(const void* buf1, const void* buf2, int count) +{ +int i; +for (i=0;i*(unsigned char*)buf2) + return 1; + } +return 0; +} + +static inline char *strcat(char strDest[], char strSource[]) +{ + int i, j; + i = j = 0; + while (strDest[i] != '\0') i++; + while ((strDest[i++] = strSource[j++]) != '\0'); + return strDest; +} + + +static inline int strcmp(char* string1,char* string2) +{ + +while (1) +{ +if (*string1<*string2) + return -1; +if (*string1>*string2) + return 1; + +if (*string1=='\0') + return 0; + +string1++; +string2++; +} + +} + +static inline char *strcpy(char strDest[], const char strSource[]) +{ + unsigned i; + i = 0; + while ((strDest[i] = strSource[i]) != '\0') i++; + return strDest; +} + + +char* strncpy(char *strDest, const char *strSource, unsigned n) +{ + unsigned i; + + if (! n ) + return strDest; + + i = 0; + while ((strDest[i] = strSource[i]) != '\0') + if ( (n-1) == i ) + break; + else + i++; + + return strDest; +} + + +static inline int strlen(const char* string) +{ + int i; + + i=0; + while (*string++) i++; + return i; +} + + + +static inline char* strchr(const char* string, int c) +{ + while (*string) + { + if (*string==c) + return (char*)string; + string++; + } + return (char*)0; +} + + +static inline char* strrchr(const char* string, int c) +{ + char* last_found; + while (*string) + { + if (*string==c) + { + last_found = (char*)string; + } + string++; + } + return last_found; +} + + + +static inline void _itoa(int i, char *s) +{ + int a, b, c, d; + a = (i - i%1000)/1000; + b = (i - i%100)/100 - a*10; + c = (i - i%10)/10 - a*100 - b*10; + d = i%10; + s[0] = a + '0'; + s[1] = b + '0'; + s[2] = c + '0'; + s[3] = d + '0'; + s[4] = 0; +} + + + /* reverse: переворачиваем строку s на месте */ +static inline void reverse(char s[]) + { + int i, j; + char c; + + for (i = 0, j = strlen(s)-1; i 0); + if (sign < 0) + s[i++] = '-'; + s[i] = '\0'; + reverse(s); + } + + + +static inline int atoi ( char *s ) +{ + int i, n; + + n = 0; + for ( i = 0; s[i]!= '\0'; ++i) + if ((s[i]<'0') || (s[i]>'9')) + return 0; + else + n = 10 * n + s[i] - '0'; + + return n; +} diff --git a/programs/develop/libraries/libs_v2/library.bat b/programs/develop/libraries/libs_v2/library.bat new file mode 100644 index 0000000000..9593ef1ad2 --- /dev/null +++ b/programs/develop/libraries/libs_v2/library.bat @@ -0,0 +1 @@ +build.bat library \ No newline at end of file diff --git a/programs/develop/libraries/libs_v2/library.c b/programs/develop/libraries/libs_v2/library.c new file mode 100644 index 0000000000..a2c7332439 --- /dev/null +++ b/programs/develop/libraries/libs_v2/library.c @@ -0,0 +1,151 @@ +/* + 2015 + Author: Pavel Yakovlev. +*/ + +#define LIB_NAME "library" +#define NO_LIBIMPORT_FUNC + +#include "coff.h" + +#include +#include + +struct_import *array_list_func; +dword ADR_FUNC_LIST=0; +dword ADR_LIB_LIST=0; + +dword init_list_function_adr(); + +typedef struct +{ + dword key; + dword value; +} array; + +void strtolower(char *text) +{ + --text; + while(*++text)if((*text>='A')&&(*text<='Z'))*text+='a'-'A'; +} + +static array*(* _stdcall array_set_key_string)(array *ary,char *key,void *data); +static void*(* _stdcall array_get_key_string)(array *ary,char *key); + +static char*(* _stdcall get_full_path)(char *path); +byte init_check_fs = 0; +byte init_fs() +{ + if(init_check_fs)return 1; + char *name = "/sys/lib/fs.obj"; + array_list_func = cofflib_load(name); + if (!array_list_func) exit(); + + get_full_path = (void *)cofflib_procload (array_list_func, "fs.get_full_path"); + if (!get_full_path) exit(); + + init_check_fs = 1; + + array_set_key_string(&ADR_LIB_LIST,name,array_list_func); + return init_list_function_adr(); +} + +byte init_check_array = 0; +byte init_array() +{ + if(init_check_array)return 1; + + char *name = "/sys/lib/array.obj"; + array_list_func = cofflib_load(name); + if (!array_list_func) exit(); + + array_set_key_string = (void *)cofflib_procload (array_list_func, "array.key_string_set"); + if (!array_set_key_string) exit(); + + array_get_key_string = (void *)cofflib_procload (array_list_func, "array.key_string_get"); + if (!array_get_key_string) exit(); + + init_check_array = 1; + + array_set_key_string(&ADR_LIB_LIST,name,array_list_func); + init_list_function_adr(); + return init_fs(); +} + +int load_dll2(dword dllname,struct_import* import_table, byte need_init) +{ + struct_import* import_table1 = cofflib_load(dllname); + if(import_table1)return -1; + + dword i=0,ii=0; + dword name = import_table1[i].name; + dword name1 = import_table[ii].name; + while(name) + { + if(!strcmp(name,name1)) + { + import_table[ii].data=import_table1[i].data; + name1 = import_table[++ii].name; + } + name = import_table1[++i].name; + } + if(need_init) dll_init(import_table1[0].data); + return 0; +} + +static void (* lib_init_eval)(dword,dword,dword,dword); + +void dll_init(dword data) +{ + lib_init_eval = data; + lib_init_eval(&malloc,&free,&realloc,&load_dll2); +} + +byte first_load = 0; + +dword load(char *name) +{ + init_array(); + name = get_full_path(name); + strtolower(name); + if(array_get_key_string(&ADR_LIB_LIST,name))return 1; + array_list_func = cofflib_load(name); + if(!array_list_func) return 0; + array_set_key_string(&ADR_LIB_LIST,name,array_list_func); + return init_list_function_adr(); +} + +dword get(char *name) +{ + return (dword)array_get_key_string(&ADR_FUNC_LIST,name); +} + +static void (* _stdcall eval_set_pointer)(dword,dword); + +dword init_list_function_adr() +{ + dword i=0,data; + char *name = 0; + LOOP: + name = array_list_func[i].name; + if(!name) return 1; + data = array_list_func[i++].data; + if(!strcmp("lib_init",name)) + { + dll_init(data); + goto LOOP; + } + if(!strcmp("lib_pointer_library",name)) + { + eval_set_pointer = data; + eval_set_pointer(&load,&get); + goto LOOP; + } + array_set_key_string(&ADR_FUNC_LIST,name,data); + goto LOOP; +} + +EXPORT_ + export(load) + export(get) +_EXPORT \ No newline at end of file