Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 646 → Rev 647

/programs/develop/ktcc/trunk/libc/build.bat
0,0 → 1,68
@echo off
echo ####################################################
echo # Melibc builder #
echo # usage: build [clean] #
echo ####################################################
rem #### CONFIG SECTION ####
set LIBNAME=libck.a
set INCLUDE=include
set CC=
set CFLAGS=-c -nostdinc -DGNUC -I"%cd%\%INCLUDE%"
set AR=
set ASM=
set dirs=stdio memory kolibrisys string stdlib
rem #### END OF CONFIG SECTION ####
 
set objs=
set target=%1
if not "%1"=="clean" set target=all
 
set INCLUDE="%cd%"
call :Target_%target%
 
if ERRORLEVEL 0 goto Exit_OK
 
echo Probably at runing has been created error
echo For help send a report...
pause
goto :eof
 
:Compile_C
%CC% %CFLAGS% %1 -o "%~dpn1.o"
if not %errorlevel%==0 goto Error_Failed
set objs=%objs% "%~dpn1.o"
goto :eof
 
:Compile_Asm
%ASM% %1 "%~dpn1.o"
if not %errorlevel%==0 goto Error_Failed
set objs=%objs% "%~dpn1.o"
goto :eof
 
:Target_clean
echo cleaning ...
for %%a in (%dirs%) do del /Q "%%a\*.o"
goto :Exit_OK
 
:Target_all
echo building all ...
for %%a in (%dirs%) do (
for %%f in ("%%a\*.asm") do call :Compile_Asm "%%f"
for %%f in ("%%a\*.c") do call :Compile_C "%%f"
)
%AR% -ru %LIBNAME% %objs%
if not %errorlevel%==0 goto Error_Failed
goto Exit_OK
 
:Error_Failed
echo error: execution failed
pause
exit 1
 
:Exit_OK
echo ####################################################
echo # All operations has been done... #
echo # For cleaning run this script with param " clean" #
echo ####################################################
pause
exit 0
/programs/develop/ktcc/trunk/libc/include/ctype.h
0,0 → 1,35
/*
** All character classification functions except isascii().
** Integer argument (c) must be in ASCII range (0-127) for
** dependable answers.
*/
 
#define ALNUM 1
#define ALPHA 2
#define CNTRL 4
#define DIGIT 8
#define GRAPH 16
#define LOWER 32
#define PRINT 64
#define PUNCT 128
#define BLANK 256
#define UPPER 512
#define XDIGIT 1024
 
extern char _is[128];
 
#define isalnum(c)(_is[c] & ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */
#define isalpha(c)(_is[c] & ALPHA ) /* 'a'-'z', 'A'-'Z' */
#define iscntrl(c)(_is[c] & CNTRL ) /* 0-31, 127 */
#define isdigit(c)(_is[c] & DIGIT ) /* '0'-'9' */
#define isgraph(c)(_is[c] & GRAPH ) /* '!'-'~' */
#define islower(c)(_is[c] & LOWER ) /* 'a'-'z' */
#define isprint(c)(_is[c] & PRINT ) /* ' '-'~' */
#define ispunct(c)(_is[c] & PUNCT ) /* !alnum && !cntrl && !space */
#define isspace(c)(_is[c] & BLANK ) /* HT, LF, VT, FF, CR, ' ' */
#define isupper(c)(_is[c] & UPPER ) /* 'A'-'Z' */
#define isxdigit(c)(_is[c] & XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */
 
#define isascii(c) (!((c)&(~0x7f)))
#define toascii(c) ((c)&0x7f)
 
/programs/develop/ktcc/trunk/libc/include/kolibrisys.h
0,0 → 1,195
#ifndef kolibrisys_h
#define kolibrisys_h
/*
#ifdef GNUC
#define stdcall __stdcall
#define cdecl __cdecl
#else
#define stdcall ((__stdcall))
#define cdecl ((__cdecl))
#endif
*/
//#ifdef GNUC
//#define stdcall __stdcall
//#else
#define cdecl __attribute__ ((cdecl))
#define stdcall __attribute__ ((stdcall))
//#endif
 
typedef unsigned int dword;
typedef unsigned char byte;
typedef unsigned short word;
 
typedef unsigned int fpos_t;
typedef unsigned int size_t;
 
typedef struct process_table_entry{
int cpu_usage; //+0
int window_pos_info; //+4
short int reserved1; //+8
char name[12]; //+10
int memstart; //+22
int memused; //+26
int pid; //+30
int winx_start; //+34
int winy_start; //+38
int winx_size; //+42
int winy_size; //+46
short int slot_info; //+50
short int reserved2; //+52
int clientx; //+54
int clienty; //+58
int clientwidth; //+62
int clientheight; //+66
unsigned char window_state;//+70
char reserved3[1024-71]; //+71
}__attribute__((packed));
 
//-----------------------------------------------------------------------------------
//------------------------KolibriOS system acces to files----------------------------
//-----------------------------------------------------------------------------------
extern dword stdcall _ksys_get_filesize(char *filename);
extern dword stdcall _ksys_readfile(char *filename,dword pos,dword blocksize,void *data);
extern dword stdcall _ksys_rewritefile(char *filename,dword blocksize,void *data);
extern dword stdcall _ksys_appendtofile(char *filename,dword pos,dword blocksize,void *data);
//-----------------------------------------------------------------------------------
 
//----------------------Run program---------------------------------------------------
extern void stdcall _ksys_run_program(char* filename,char* parameters);
//------------------------------------------------------------------------------------
 
//--------------------Debug output---------------------------------------------------
extern void stdcall _ksys_debug_out(int c);
extern void stdcall debug_out_str(char* str);
//-----------------------------------------------------------------------------------
 
//--------------------------Mouse state----------------------------------------------
extern int stdcall _ksys_GetMouseXY(void);
extern int stdcall _ksys_GetMouseButtonsState(void);
//-----------------------------------------------------------------------------------
 
//--------------------------get skin height------------------------------------------
extern int stdcall _ksys_get_skin_height(void);
//-----------------------------------------------------------------------------------
 
//----------------------------background---------------------------------------------
extern void stdcall _ksys_set_background_size(int xsize,int ysize);
extern void stdcall _ksys_write_background_mem(int pos,int color);
extern void stdcall _ksys_draw_background(void);
extern void stdcall _ksys_set_background_draw_type(int type);
extern void stdcall _ksys_background_blockmove(void* src,int bgr_pos, int count);
//-----------------------------------------------------------------------------------
 
//----------------------------functionf for draw window,lines.bar,etc.---------------
extern void stdcall _ksys_draw_window(int xcoord,int ycoord, int xsize,
int ysize,int workcolor,int type,
int captioncolor,int windowtype,int bordercolor);
extern void stdcall _ksys_window_redraw(int status);
extern int stdcall _ksys_putpixel(int x,int y,int color);
extern void stdcall _ksys_draw_bar(int x, int y, int xsize, int ysize, int color);
extern void stdcall _ksys_line(int x1,int y1,int x2,int y2,int color);
extern void stdcall _ksys_putimage(int x, int y, int xsize, int ysize, void* image);
//-----------------------------------------------------------------------------------
 
//--------------------------write text(system fonts 6x9)-----------------------------
extern void stdcall _ksys_write_text(int x,int y,int color,char* text,int len);
//-----------------------------------------------------------------------------------
 
//------------------ get screen size and bytes per pixel---------------------------
extern int stdcall _ksys_get_screen_size(int* x,int* y);
extern void stdcall _ksys_dga_get_resolution(int* xres, int* yres, int* bpp, int* bpscan);
//-----------------------------------------------------------------------------------
 
//-------------------------------craete thread---------------------------------------
extern void* stdcall _ksys_start_thread(void (* func_ptr)(void),int stack_size,int* pid);
//-----------------------------------------------------------------------------------
 
//------------------system button(Old function. Better use libGUI functions.)--------
extern void stdcall _ksys_make_button(int x, int y, int xsize, int ysize, int id, int color);
extern int stdcall _ksys_get_button_id(void); //get state of system button
//------------------------------------------------------------------------------------
 
//----------------------system clock(in 1/100 sec.) and date--------------------------
extern int stdcall _ksys_get_system_clock(void);
extern int stdcall _ksys_get_date(void);
//------------------------------------------------------------------------------------
 
//-------------------------system delay(in 1/100 sec.)-------------------------------
extern void stdcall _ksys_delay(int m);
//-----------------------------------------------------------------------------------
 
//------------------------system events----------------------------------------------
extern int stdcall _ksys_wait_for_event_infinite(void);
extern int stdcall _ksys_check_for_event(void);
extern int stdcall _ksys_wait_for_event(int time);
extern void stdcall _ksys_set_wanted_events(int ev);
//-----------------------------------------------------------------------------------
 
//----------------------------system exit program------------------------------------
extern void stdcall _ksys_exit(void);
//-----------------------------------------------------------------------------------
 
//-----------------------------system IPC send message-------------------------------
extern void stdcall _ksys_send_message(int pid, void* msg, int size);
//-----------------------------------------------------------------------------------
 
//---------------------------system work with IRQ from user mode---------------------
extern void stdcall _ksys_define_receive_area(void* area, int size);
extern int stdcall _ksys_get_irq_owner(int irq);
extern int stdcall _ksys_get_data_read_by_irq(int irq, int* size, void* data);
extern int stdcall _ksys_send_data_to_device(int port, unsigned char val);
extern int stdcall _ksys_receive_data_from_device(int port,unsigned char* data);
extern void stdcall _ksys_program_irq(void* intrtable, int irq);
extern void stdcall _ksys_reserve_irq(int irq);
extern void stdcall _ksys_free_irq(int irq);
//----------------------------------------------------------------------------------
 
//----------------------------system reserve diapason of ports----------------------
extern int stdcall _ksys_reserve_port_area(int start,int end);
extern int stdcall _ksys_free_port_area(int start,int end);
//----------------------------------------------------------------------------------
 
//-------------functions get key and set keyboard mode------------------------------
extern int stdcall _ksys_get_key(void);
extern void stdcall _ksys_set_keyboard_mode(int mode);
//----------------------------------------------------------------------------------
 
//--------------simple work with MPU401 sound device---------------------------------
extern void stdcall _ksys_midi_reset(void);
extern void stdcall _ksys_midi_send(int data);
//-----------------------------------------------------------------------------------
 
//--------------------------acces to PCI BUS from user mode---------------------------
extern int stdcall _ksys_get_pci_version(void);
extern int stdcall _ksys_get_last_pci_bus(void);
extern int stdcall _ksys_get_pci_access_mechanism(void);
extern int stdcall _ksys_pci_read_config_byte(int bus,int dev,int fn,int reg);
extern int stdcall _ksys_pci_read_config_word(int bus,int dev,int fn,int reg);
extern int stdcall _ksys_pci_read_config_dword(int bus,int dev,int fn,int reg);
extern int stdcall _ksys_pci_write_config_byte(int bus,int dev,int fn,int reg,int value);
extern int stdcall _ksys_pci_write_config_word(int bus,int dev,int fn,int reg,int value);
extern int stdcall _ksys_pci_write_config_value(int bus,int dev,int fn,int reg,int value);
//--------------------------------------------------------------------------------------
 
//------------------------Process information--------------------------------------
extern int stdcall _ksys_get_process_table(struct process_table_entry *proctab,int pid); //if pid=-1 than get info about him.
//---------------------------------------------------------------------------------
 
//-----------------Old functions for work with sound(Sound Blaster only).---------
extern void stdcall _ksys_sound_load_block(void* blockptr);
extern void stdcall _ksys_sound_play_block(void);
extern void stdcall _ksys_sound_set_channels(int channels);
extern void stdcall _ksys_sound_set_data_size(int size);
extern void stdcall _ksys_sound_set_frequency(int frequency);
//--------------------------------------------------------------------------------
 
//------------------------------system speaker(integrated speaker)----------------
extern void stdcall _ksys_sound_speaker_play(void* data);
//--------------------------------------------------------------------------------
 
//------------------function for work with Dinamic Link Librarys(DLL)--------------
extern dword* stdcall _ksys_cofflib_load(char* name);
extern char* stdcall _ksys_cofflib_getproc(void* exp,char* sz_name);
//---------------------------------------------------------------------------------
 
#endif
/programs/develop/ktcc/trunk/libc/include/math.h
0,0 → 1,179
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
 
extern int stdcall integer(float number);
 
extern double acos(double _x);
extern double asin(double _x);
extern double atan(double _x);
extern double atan2(double _y, double _x);
extern double ceil(double _x);
extern double cos(double _x);
extern double cosh(double _x);
extern double exp(double _x);
extern double fabs(double _x);
extern double floor(double _x);
extern double fmod(double _x, double _y);
extern double frexp(double _x, int *_pexp);
extern double ldexp(double _x, int _exp);
extern double log(double _y);
extern double log10(double _x);
extern double modf(double _x, double *_pint);
extern double pow(double _x, double _y);
extern double sin(double _x);
extern double sinh(double _x);
extern double sqrt(double _x);
extern double tan(double _x);
extern double tanh(double _x);
 
//#ifndef __STRICT_ANSI__
 
//#ifndef _POSIX_SOURCE
 
#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074
#define M_LOG10E 0.43429448190325182765
#define M_LN2 0.69314718055994530942
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.78539816339744830962
#define M_1_PI 0.31830988618379067154
#define M_2_PI 0.63661977236758134308
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440
#define PI M_PI
#define PI2 M_PI_2
 
extern double acosh(double);
extern double asinh(double);
extern double atanh(double);
extern double cbrt(double);
extern double exp10(double _x);
extern double exp2(double _x);
extern double expm1(double);
extern double hypot(double, double);
extern double log1p(double);
extern double log2(double _x);
extern long double modfl(long double _x, long double *_pint);
extern double pow10(double _x);
extern double pow2(double _x);
extern double powi(double, int);
extern void sincos(double *, double *, double);
 
/* These are in libm.a (Cygnus). You must link -lm to get these */
/* See libm/math.h for comments */
/*
#ifndef __cplusplus
struct exception {
int type;
const char *name;
double arg1;
double arg2;
double retval;
int err;
};
#endif
*/
 
extern double erf(double);
extern double erfc(double);
extern double gamma(double);
extern int isinf(double);
extern int isnan(double);
extern int finite(double);
extern double j0(double);
extern double j1(double);
extern double jn(int, double);
extern double lgamma(double);
extern double nan(void);
extern double y0(double);
extern double y1(double);
extern double yn(int, double);
extern double logb(double);
extern double nextafter(double, double);
extern double remainder(double, double);
extern double scalb(double, double);
//#ifndef __cplusplus
//extern int matherr(struct exception *);
//#endif
extern double significand(double);
extern double copysign(double, double);
extern int ilogb(double);
extern double rint(double);
extern double scalbn(double, int);
extern double drem(double, double);
extern double gamma_r(double, int *);
extern double lgamma_r(double, int *);
extern float acosf(float);
extern float asinf(float);
extern float atanf(float);
extern float atan2f(float, float);
extern float cosf(float);
extern float sinf(float);
extern float tanf(float);
extern float coshf(float);
extern float sinhf(float);
extern float tanhf(float);
extern float expf(float);
extern float frexpf(float, int *);
extern float ldexpf(float, int);
extern float logf(float);
extern float log10f(float);
extern float modff(float, float *);
extern float powf(float, float);
extern float sqrtf(float);
extern float ceilf(float);
extern float fabsf(float);
extern float floorf(float);
extern float fmodf(float, float);
extern float erff(float);
extern float erfcf(float);
extern float gammaf(float);
extern float hypotf(float, float);
extern int isinff(float);
extern int isnanf(float);
extern int finitef(float);
extern float j0f(float);
extern float j1f(float);
extern float jnf(int, float);
extern float lgammaf(float);
extern float nanf(void);
extern float y0f(float);
extern float y1f(float);
extern float ynf(int, float);
extern float acoshf(float);
extern float asinhf(float);
extern float atanhf(float);
extern float cbrtf(float);
extern float logbf(float);
extern float nextafterf(float, float);
extern float remainderf(float, float);
extern float scalbf(float, float);
extern float significandf(float);
extern float copysignf(float, float);
extern int ilogbf(float);
extern float rintf(float);
extern float scalbnf(float, int);
extern float dremf(float, float);
extern float expm1f(float);
extern float log1pf(float);
extern float gammaf_r(float, int *);
extern float lgammaf_r(float, int *);
 
//#endif /* !_POSIX_SOURCE */
//#endif /* !__STRICT_ANSI__ */
//#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
 
//#ifndef __dj_ENFORCE_FUNCTION_CALLS
//#endif /* !__dj_ENFORCE_FUNCTION_CALLS */
 
//#ifdef __cplusplus
//}
//#endif
 
//#endif /* _USE_LIBM_MATH_H */
 
//#endif /* !__dj_include_math_h_ */
/programs/develop/ktcc/trunk/libc/include/stdio.h
0,0 → 1,57
#ifndef stdio_h
#define stdio_h
 
#include "kolibrisys.h"
 
typedef char *va_list;
#define _roundsize(n) ( (sizeof(n) + 3) & ~3 )
#define va_start(ap,v) (ap = (va_list)&v+_roundsize(v))
#define va_arg(ap,t) ( *(t *)((ap += _roundsize(t)) - _roundsize(t)) )
#define va_end(ap) (ap = (va_list)0)
 
#define NULL ((void*)0)
//extern int stdcall format_print(char *dest, size_t maxlen, const char *fmt0, va_list argp);
 
typedef struct {
char* buffer;
dword buffersize;
dword filesize;
dword filepos;
char* filename;
int mode;
} FILE;
 
#define FILE_OPEN_READ 0
#define FILE_OPEN_WRITE 1
#define FILE_OPEN_APPEND 2
#define FILE_OPEN_TEXT 4
#define FILE_OPEN_PLUS 8
#define EOF -1
 
extern FILE* fopen(const char* filename, const char *mode);
extern void fclose(FILE* file);
extern int feof(FILE* file);
extern int fflush(FILE* file);
extern int fgetc(FILE* file);
extern int fgetpos(FILE* file,fpos_t* pos);
extern int fsetpos(FILE* file,const fpos_t* pos);
extern int fputc(int c,FILE* file);
extern int fread(void* buffer,int size,int count,FILE* file);
extern int fwrite(void *buffer,int size,int count,FILE* file);
extern long ftell(FILE* file);
#define SEEK_CUR 0
#define SEEK_END 1
#define SEEK_SET 2
extern int fseek(FILE* file,long offset,int origin);
extern void rewind(FILE* file);
extern int cdecl fprintf(FILE* file, const char* format,...);
extern int fscanf(FILE* file,const char* format,...);
extern int ungetc(int c,FILE* file);
 
extern int cdecl printf(const char *format,...);
 
extern int vsnprintf(char *dest, size_t size,const char *format,va_list ap);
extern int cdecl snprintf(char *dest, size_t size, const char *format,...);
extern int cdecl sprintf(char *dest,const char *format,...);
 
#endif
/programs/develop/ktcc/trunk/libc/include/stdlib.h
0,0 → 1,18
#ifndef stdlib_h
#define stdlib_h
#include "kolibrisys.h"
 
//#define isspace(c) ((c)==' ')
#define abs(i) (((i)<0)?(-(i)):(i))
 
extern int atoib(char *s,int b);
extern int atoi(char *s);
extern unsigned char tolower(unsigned char c);
extern unsigned char toupper(unsigned char c);
extern void itoab(int n,char* s,int b);
extern void itoa(int n,char* s);
 
extern void* stdcall malloc(dword size);
extern void stdcall free(void *pointer);
extern void* stdcall realloc(void* pointer,dword size);
#endif
/programs/develop/ktcc/trunk/libc/include/string.h
0,0 → 1,25
#ifndef string_h
#define string_h
extern void* memchr(const void*,int,int);
extern int memcmp(const void*,const void*,int);
extern void* memcpy(void*,const void*,int);
extern void* memmove(void*,const void*,int);
extern void* memset(void*,int,int);
extern char* strcat(char*,const char*);
extern char* strchr(const char*,int);
extern int strcmp(const char*,const char*);
extern int strcoll(const char*,const char*);
extern char* strcpy(char*,const char*);
extern int strcspn(const char*,const char*);
extern int strlen(const char*);
extern char* strncat(char*,const char*,int);
extern int strncmp(const char*,const char*,int);
extern char* strncpy(char*,const char*,int);
extern char* strpbrk(const char*,const char*);
extern char* strrchr(const char*,int);
extern int strspn(const char*,const char*);
extern char* strstr(const char*,const char*);
extern char* strtok(char*,const char*);
extern int strxfrm(char*,const char*,int);
extern char* strdup(const char*);
#endif
/programs/develop/ktcc/trunk/libc/kolibrisys/_ksys_files_acces.asm
0,0 → 1,119
format ELF
 
section '.text' executable
 
include 'proc32.inc'
public _ksys_get_filesize
public _ksys_readfile
public _ksys_rewritefile
public _ksys_appendtofile
 
align 4
proc _ksys_get_filesize stdcall, filename:dword
 
xor eax,eax
mov ebx,[filename]
mov [fileinfo.subproc],dword 5
mov [fileinfo.offset_l],eax
mov [fileinfo.offset_h],eax
mov [fileinfo.size],eax
mov [fileinfo.data],dword buffer_for_info
mov [fileinfo.letter],al
mov [fileinfo.filename],ebx
 
mov eax,70
mov ebx,fileinfo
int 0x40
 
test eax,eax
jnz error_for_file_size
 
mov eax,[buffer_for_info+32] ;file size
 
error_for_file_size:
 
ret
endp
 
 
align 4
proc _ksys_readfile stdcall,filename:dword,position:dword,sizeblock:dword,buffer:dword
 
xor eax,eax
mov ebx,[position]
mov ecx,[sizeblock]
mov edx,[buffer]
mov esi,[filename]
mov [fileinfo.subproc],eax
mov [fileinfo.offset_l],ebx
mov [fileinfo.offset_h],eax
mov [fileinfo.size],ecx
mov [fileinfo.data],edx
mov [fileinfo.letter],al
mov [fileinfo.filename],esi
 
mov eax,70
mov ebx,fileinfo
int 0x40
 
ret
endp
 
align 4
proc _ksys_rewritefile stdcall,filename:dword,sizeblock:dword,data_write:dword
 
xor eax,eax
mov ebx,[sizeblock]
mov ecx,[data_write]
mov edx,[filename]
mov [fileinfo.subproc],dword 2
mov [fileinfo.offset_l],eax
mov [fileinfo.offset_h],eax
mov [fileinfo.size],ebx
mov [fileinfo.data],ecx
mov [fileinfo.letter],al
mov [fileinfo.filename],edx
 
mov eax,70
mov ebx,fileinfo
int 0x40
 
ret
endp
 
align 4
proc _ksys_appendtofile stdcall,filename:dword,pos:dword,sizeblock:dword,data_append:dword
 
xor eax,eax
mov ebx,[pos]
mov ecx,[sizeblock]
mov edx,[data_append]
mov esi,[filename]
mov [fileinfo.subproc],dword 3
mov [fileinfo.offset_l],ebx
mov [fileinfo.offset_h],eax
mov [fileinfo.size],ecx
mov [fileinfo.data],edx
mov [fileinfo.letter],al
mov [fileinfo.filename],esi
 
mov eax,70
mov ebx,fileinfo
int 0x40
 
ret
endp
 
struc FILEIO
{
.subproc rd 1
.offset_l rd 1
.offset_h rd 1
.size rd 1
.data rd 1
.letter rb 1
.filename rd 1
}
 
fileinfo FILEIO
buffer_for_info rd 11
/programs/develop/ktcc/trunk/libc/kolibrisys/backgr.asm
0,0 → 1,54
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_set_background_size,8
;arg1 - xsize
;arg2 - ysize
push ebx
mov ecx,[esp+8]
mov edx,[esp+12]
mov eax,15
mov ebx,1
int 0x40
pop ebx
ret 8
public_stdcall _ksys_write_background_mem,8
;arg1 - pos
;arg2 - color
push ebx
mov eax,15
mov ebx,2
mov ecx,[esp+8]
mov edx,[esp+12]
int 0x40
pop ebx
ret 8
public_stdcall _ksys_draw_background,0
mov edx,ebx
mov eax,15
mov ebx,3
int 0x40
mov ebx,edx
ret
public_stdcall _ksys_set_background_draw_type,4
;arg1 - type
mov edx,ebx
mov eax,15
mov ebx,4
mov ecx,[esp+4]
int 0x40
mov ebx,edx
ret 4
public_stdcall _ksys_background_blockmove,12
;arg1 - source
;arg2 - position in dest
;arg3 - size
push ebx esi
mov eax,15
mov ebx,5
mov ecx,[esp+12]
mov edx,[esp+16]
mov esi,[esp+20]
int 0x40
pop esi ebx
ret 12
/programs/develop/ktcc/trunk/libc/kolibrisys/button.asm
0,0 → 1,35
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_make_button,24
;arg1 - x
;arg2 - y
;arg3 - xsize
;arg4 - ysize
;arg5 - id
;arg6 - color
push ebx esi
mov ebx,[esp+12]
shl ebx,16
mov bx,[esp+20]
mov ecx,[esp+16]
shl ecx,16
mov cx,[esp+24]
mov edx,[esp+28]
mov esi,[esp+32]
mov eax,8
int 0x40
pop esi ebx
ret 24
public_stdcall _ksys_get_button_id,0
mov eax,17
int 0x40
test al,al
jnz .no_button
shr eax,8
ret
.no_button:
xor eax,eax
dec eax
ret
/programs/develop/ktcc/trunk/libc/kolibrisys/clock.asm
0,0 → 1,15
format ELF
 
include "proc32.inc"
 
section '.text' executable
public _ksys_get_system_clock
 
align 4
proc _ksys_get_system_clock stdcall
 
mov eax,3
int 0x40
ret
 
endp
/programs/develop/ktcc/trunk/libc/kolibrisys/cofflib.asm
0,0 → 1,73
format ELF
include 'proc32.inc'
section '.text' executable
 
public _ksys_cofflib_load
public _ksys_cofflib_getproc
 
proc _ksys_cofflib_load stdcall, name:dword
 
mov eax, 68
mov ebx, 19
mov ecx, [name]
int 0x40
ret
endp
 
proc _ksys_cofflib_getproc stdcall, export:dword,name:dword
 
mov ebx,[export]
 
next_name_check:
 
mov ecx,[ebx]
test ecx,ecx
jz end_export
 
;cmp export string with name
mov esi,[name]
xor edi,edi
next_simbol_check:
 
xor eax,eax
mov al,[ecx]
test al,al
jz exit_check_simbol
 
xor edx,edx
mov dl,[esi]
cmp al,dl
je simbols_equvalent
add edi,1
jmp exit_check_simbol
simbols_equvalent:
 
;pushad
 
;mov cl,al
;mov ebx,1
;mov eax,63
;int 0x40
 
;popad
 
add ecx,1
add esi,1
jmp next_simbol_check
exit_check_simbol:
 
test edi,edi
jnz function_not_finded
mov eax,[ebx+4]
jmp end_export
function_not_finded:
 
add ebx,8
 
jmp next_name_check
 
end_export:
 
ret
endp
 
/programs/develop/ktcc/trunk/libc/kolibrisys/date.asm
0,0 → 1,7
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_get_date,0
mov eax,29
int 0x40
ret
/programs/develop/ktcc/trunk/libc/kolibrisys/debug_board.asm
0,0 → 1,56
format ELF
 
include "proc32.inc"
 
section '.text' executable
 
public _ksys_debug_out
public debug_out_str
 
align 4
proc _ksys_debug_out stdcall, c:dword
 
pushad
 
xor ecx,ecx
mov cl,byte[c]
mov ebx,1
mov eax,63
int 0x40
 
popad
 
ret
 
endp
 
align 4
proc debug_out_str stdcall, s:dword
 
pushad
mov eax,[s] ;eax=pointer to string
next_simbol_print:
 
xor ebx,ebx
mov bl,[eax]
test bl,bl
jz exit_print_str
 
cmp bl,10
jne no_new_line
mov ecx,13
stdcall _ksys_debug_out, ecx
no_new_line:
 
stdcall _ksys_debug_out, ebx
add eax,1
 
jmp next_simbol_print
 
exit_print_str:
 
popad
 
ret
endp
/programs/develop/ktcc/trunk/libc/kolibrisys/delay.asm
0,0 → 1,11
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_delay,4
;arg1 - time
mov edx,ebx
mov eax,5
mov ebx,[esp+4]
int 0x40
mov ebx,edx
ret 4
/programs/develop/ktcc/trunk/libc/kolibrisys/dga.asm
0,0 → 1,34
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_dga_get_resolution,16
;arg1 - *xres
;arg2 - *yres
;arg3 - *bpp
;arg4 - *bpscan
mov edx,ebx
mov eax,61
mov ebx,1
int 0x40
mov ebx,[esp+8]
mov [ebx],ax
mov word [ebx+2],0
shr eax,16
mov ebx,[esp+4]
mov [ebx],eax
mov eax,61
mov ebx,2
int 0x40
mov ebx,[esp+12]
mov [ebx],eax
mov eax,61
mov ebx,3
int 0x40
mov ebx,[esp+16]
mov [ebx],eax
mov ebx,edx
ret 16
/programs/develop/ktcc/trunk/libc/kolibrisys/draw_bar.asm
0,0 → 1,21
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_draw_bar,20
;arg1 - x
;arg2 - y
;arg3 - xsize
;arg4 - ysize
;arg5 - color
push ebx
mov eax,13
mov ebx,[esp+8]
shl ebx,16
mov bx,[esp+16]
mov ecx,[esp+12]
shl ecx,16
mov cx,[esp+20]
mov edx,[esp+24]
int 0x40
pop ebx
ret 20
/programs/develop/ktcc/trunk/libc/kolibrisys/draw_image.asm
0,0 → 1,21
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_putimage,20
;arg1 - x
;arg2 - y
;arg3 - xsize
;arg4 - ysize
;arg5 - image
push ebx
mov ebx,[esp+24]
mov ecx,[esp+16]
shl ecx,16
mov ecx,[esp+20]
mov ebx,[esp+8]
shl ebx,16
mov ebx,[esp+12]
mov eax,7
int 0x40
pop ebx
ret 20
/programs/develop/ktcc/trunk/libc/kolibrisys/draw_window.asm
0,0 → 1,34
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_draw_window,36
;arg1 - xcoord
;arg2 - ycoord
;arg3 - xsize
;arg4 - ysize
;arg5 - workcolor
;arg6 - type
;arg7 - captioncolor
;arg8 - windowtype
;arg9 - bordercolor
push ebp
mov ebp,esp
push ebx esi edi
mov ebx,[ebp+8]
shl ebx,16
mov bx,[ebp+16]
mov ecx,[ebp+12]
shl ecx,16
mov cx,[ebp+20]
mov edx,[ebp+28]
shl edx,24
add edx,[ebp+24]
mov esi,[ebp+36]
shl esi,24
add esi,[ebp+32]
mov edi,[ebp+40]
xor eax,eax
int 0x40
pop edi esi ebx
pop ebp
ret 36
/programs/develop/ktcc/trunk/libc/kolibrisys/event.asm
0,0 → 1,40
format ELF
 
section '.text' executable
 
public _ksys_wait_for_event_infinite
public _ksys_check_for_event
public _ksys_wait_for_event
public _ksys_set_wanted_events
 
_ksys_wait_for_event_infinite:
 
mov eax,10
int 0x40
 
ret
_ksys_check_for_event:
 
mov eax,11
int 0x40
 
ret
_ksys_wait_for_event:
 
;arg1 - time
mov eax,23
mov ebx,[esp+4]
int 0x40
 
ret 4
_ksys_set_wanted_events:
 
;arg1 - flags
mov eax,40
mov ebx,[esp+4]
int 0x40
 
ret 4
/programs/develop/ktcc/trunk/libc/kolibrisys/exit.asm
0,0 → 1,8
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_exit,0
xor eax,eax
dec eax
int 0x40
; ret
/programs/develop/ktcc/trunk/libc/kolibrisys/ipc.asm
0,0 → 1,28
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_send_message,12
;arg1 - pid
;arg2 - msg
;arg3 - size
push ebx esi
mov eax,60
mov ebx,2
mov ecx,[esp+12]
mov edx,[esp+16]
mov esi,[esp+20]
int 0x40
pop esi ebx
ret 12
public_stdcall _ksys_define_receive_area,8
;arg1 - area
;arg2 - size
push ebx
mov eax,60
mov ebx,1
mov ecx,[esp+8]
mov edx,[esp+12]
int 0x40
pop ebx
ret 8
/programs/develop/ktcc/trunk/libc/kolibrisys/irq.asm
0,0 → 1,119
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_get_irq_owner,4
;arg1 - irq
mov edx,ebx
mov eax,41
mov ebx,[esp+4]
int 0x40
mov ebx,edx
ret 4
public_stdcall _ksys_get_data_read_by_irq,12
;arg1 - irq
;arg2 - *size
;arg3 - data
mov edx,ebx
mov eax,42
mov ebx,[esp+4]
int 0x40
cmp ecx,2
jz .not_an_owner
push ecx
mov ecx,[esp+16]
test ecx,ecx
jz .ignore_data
mov [ecx],bl
.ignore_data:
mov ecx,[esp+12]
mov [ecx],eax
pop eax
mov ebx,edx
ret 12
.not_an_owner:
mov eax,2
mov ebx,edx
ret
public_stdcall _ksys_send_data_to_device,8
;arg1 - port
;arg2 - data
mov edx,ebx
mov eax,63
mov ebx,[esp+8]
mov ecx,[esp+4]
int 0x40
mov ebx,edx
ret 8
public_stdcall _ksys_receive_data_from_device,8
;arg1 - port
;arg2 - data
mov edx,ebx
mov eax,43
mov ecx,[esp+4]
add ecx,0x80000000
int 0x40
mov ecx,[esp+8]
mov [ecx],bl
mov ebx,edx
ret 8
public_stdcall _ksys_program_irq,8
;arg1 - intrtable
;arg2 - irq
mov edx,ebx
mov eax,44
mov ebx,[esp+4]
mov ecx,[esp+8]
int 0x40
mov ebx,edx
ret 8
public_stdcall _ksys_reserve_irq,4
;arg1 - irq
mov edx,ebx
mov eax,45
xor ebx,ebx
mov ecx,[esp+4]
int 0x40
mov ebx,edx
ret 4
public_stdcall _ksys_free_irq,4
;arg1 - irq
mov edx,ebx
mov eax,45
xor ebx,ebx
inc ebx
mov ecx,[esp+4]
int 0x40
mov ebx,edx
ret 4
public_stdcall _ksys_reserve_port_area,8
;arg1 - start
;arg2 - end
push ebx
mov eax,46
xor ebx,ebx
mov ecx,[esp+8]
mov edx,[esp+12]
int 0x40
pop ebx
ret 8
public_stdcall _ksys_free_port_area,8
;arg1 - start
;arg2 - end
push ebx
mov eax,46
xor ebx,ebx
inc ebx
mov ecx,[esp+8]
mov edx,[esp+12]
int 0x40
pop ebx
ret 8
/programs/develop/ktcc/trunk/libc/kolibrisys/keyboard.asm
0,0 → 1,29
format ELF
 
include "proc32.inc"
 
section '.text' executable
 
public _ksys_get_key
public _ksys_set_keyboard_mode
 
align 4
proc _ksys_get_key stdcall
 
mov eax,2
int 0x40
ret
 
endp
 
align 4
proc _ksys_set_keyboard_mode stdcall, mode:dword
 
mov edx,ebx
mov eax,66
xor ebx,ebx
inc ebx
mov ecx,[mode]
mov ebx,edx
ret
endp
/programs/develop/ktcc/trunk/libc/kolibrisys/line.asm
0,0 → 1,21
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_line,20
;arg1 - x1
;arg2 - y1
;arg3 - x2
;arg4 - y2
;arg5 - color
push ebx
mov ebx,[esp+8]
shl ebx,16
mov bx,[esp+16]
mov ecx,[esp+12]
shl ecx,16
mov cx,[esp+20]
mov edx,[esp+24]
mov eax,38
int 0x40
pop ebx
ret 20
/programs/develop/ktcc/trunk/libc/kolibrisys/midi.asm
0,0 → 1,21
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_midi_reset,0
mov edx,ebx
mov eax,20
xor ebx,ebx
inc ebx
int 0x40
mov ebx,edx
ret
public_stdcall _ksys_midi_send,4
;arg1 - data
mov edx,ebx
mov eax,20
mov ebx,2
xor ecx,ecx
mov cl,[esp+4]
mov ebx,edx
ret 4
/programs/develop/ktcc/trunk/libc/kolibrisys/mouse.asm
0,0 → 1,25
 
format ELF
 
section '.text' executable
 
public _ksys_GetMouseXY
public _ksys_GetMouseButtonsState
 
align 4
_ksys_GetMouseXY:
 
mov eax,37
mov ebx,1
int 0x40
 
ret
 
align 4
_ksys_GetMouseButtonsState:
 
mov eax,37
mov ebx,2
int 0x40
 
ret
/programs/develop/ktcc/trunk/libc/kolibrisys/pci.asm
0,0 → 1,138
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_get_pci_version,0
mov edx,ebx
mov eax,62
xor ebx,ebx
int 0x40
movzx eax,ax
mov ebx,edx
ret
public_stdcall _ksys_get_last_pci_bus,0
mov edx,ebx
mov eax,62
xor ebx,ebx
inc ebx
int 0x40
movzx eax,al
mov ebx,edx
ret
public_stdcall _ksys_get_pci_access_mechanism,0
mov edx,ebx
mov eax,62
mov ebx,2
int 0x40
movzx eax,al
mov ebx,edx
ret
public_stdcall _ksys_pci_read_config_byte,16
;arg1 - bus
;arg2 - dev
;arg3 - fn
;arg4 - reg
mov edx,ebx
mov eax,62
mov bl,4
mov bh,[esp+4]
mov ch,[esp+8]
shl ch,3
add ch,[esp+12]
mov cl,[esp+16]
int 0x40
mov ebx,edx
ret 16
public_stdcall _ksys_pci_read_config_word,16
;arg1 - bus
;arg2 - dev
;arg3 - fn
;arg4 - reg
mov edx,ebx
mov eax,62
mov bl,5
mov bh,[esp+4]
mov ch,[esp+8]
shl ch,3
add ch,[esp+12]
mov cl,[esp+16]
int 0x40
mov ebx,edx
ret 16
public_stdcall _ksys_pci_read_config_dword,16
;arg1 - bus
;arg2 - dev
;arg3 - fn
;arg4 - reg
mov edx,ebx
mov eax,62
mov bl,6
mov bh,[esp+4]
mov ch,[esp+8]
shl ch,3
add ch,[esp+12]
mov cl,[esp+16]
int 0x40
mov ebx,edx
ret 16
public_stdcall _ksys_pci_write_config_byte,20
;arg1 - bus
;arg2 - dev
;arg3 - fn
;arg4 - reg
;arg5 - value
push ebx
mov eax,62
mov bl,8
mov bh,[esp+8]
mov ch,[esp+12]
shl ch,3
mov ch,[esp+16]
mov cl,[esp+20]
movzx edx,byte [esp+24]
int 0x40
pop ebx
ret 20
public_stdcall _ksys_pci_write_config_word,20
;arg1 - bus
;arg2 - dev
;arg3 - fn
;arg4 - reg
;arg5 - value
push ebx
mov eax,62
mov bl,9
mov bh,[esp+8]
mov ch,[esp+12]
shl ch,3
mov ch,[esp+16]
mov cl,[esp+20]
movzx edx,word [esp+24]
int 0x40
pop ebx
ret 20
public_stdcall _ksys_pci_write_config_dword,20
;arg1 - bus
;arg2 - dev
;arg3 - fn
;arg4 - reg
;arg5 - value
push ebx
mov eax,62
mov bl,10
mov bh,[esp+8]
mov ch,[esp+12]
shl ch,3
mov ch,[esp+16]
mov cl,[esp+20]
mov edx,[esp+24]
int 0x40
pop ebx
ret 20
/programs/develop/ktcc/trunk/libc/kolibrisys/pixel.asm
0,0 → 1,16
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_putpixel,12
;arg1 - x
;arg2 - y
;arg3 - color
push ebx
xor eax,eax
mov ebx,[esp+8]
inc eax
mov ecx,[esp+12]
mov edx,[esp+16]
int 0x40
pop ebx
ret 12
/programs/develop/ktcc/trunk/libc/kolibrisys/process.asm
0,0 → 1,16
format ELF
;include "public_stdcall.inc"
 
public _ksys_get_process_table
 
section '.text' executable
 
_ksys_get_process_table:
;arg1 - pointer to information
;arg2 - pid
mov eax,9
mov ebx,[esp+4]
mov ecx,[esp+8]
int 0x40
 
ret 8
/programs/develop/ktcc/trunk/libc/kolibrisys/screen.asm
0,0 → 1,15
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_get_screen_size,8
;arg1 - x
;arg2 - y
mov eax,14
int 0x40
mov ecx,[esp+8]
mov [ecx],ax
mov word [ecx+2],0
shr eax,16
mov ecx,[esp+4]
mov [ecx],eax
ret 8
/programs/develop/ktcc/trunk/libc/kolibrisys/skin.asm
0,0 → 1,13
format ELF
 
section '.text' executable
 
public _ksys_get_skin_height
 
_ksys_get_skin_height:
 
mov eax,48
mov ebx,4
int 0x40
 
ret
/programs/develop/ktcc/trunk/libc/kolibrisys/sound.asm
0,0 → 1,65
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksy_sound_load_block,4
;arg1 - blockptr
mov edx,ebx
mov eax,55
xor ebx,ebx
mov ecx,[esp+4]
int 0x40
mov ebx,edx
ret 4
public_stdcall _ksy_sound_play_block,0
mov edx,ebx
mov eax,55
xor ebx,ebx
inc ebx
int 0x40
mov ebx,edx
ret
public_stdcall _ksy_sound_set_channels,4
;arg1 - channels
push ebx
mov eax,55
mov ebx,2
xor ecx,ecx
mov edx,[esp+8]
int 0x40
pop ebx
ret 4
public_stdcall _ksy_sound_set_data_size,4
;arg1 - data size
push ebx
mov eax,55
mov ebx,2
xor ecx,ecx
inc ecx
mov edx,[esp+8]
int 0x40
pop ebx
ret 4
public_stdcall _ksy_sound_set_frequency,4
;arg1 - frequency
push ebx
mov eax,55
mov ebx,2
mov ecx,2
mov edx,[esp+8]
int 0x40
pop ebx
ret 4
public_stdcall _ksy_sound_speaker_play,4
;arg1 - data
mov edx,ebx
mov eax,55
mov ebx,55
mov ecx,[esp+4]
int 0x40
mov ebx,edx
ret 4
/programs/develop/ktcc/trunk/libc/kolibrisys/thread.asm
0,0 → 1,33
format ELF
include "public_stdcall.inc"
section '.text' executable
extrn malloc
public_stdcall _ksys_start_thread,12
;arg1 - proc
;arg2 - stacksize
;arg3 - pid
push dword [esp+8]
call malloc
test eax,eax
jz .no_mem
push ebx
mov edx,eax
add edx,[esp+12]
mov [edx-4],dword 0
mov ecx,[esp+8]
mov ebx,1
mov eax,51
int 0x40
mov ebx,[esp+16]
test ebx,ebx
jz .no_val
mov [ebx],eax
.no_val:
mov eax,edx
sub eax,[esp+12]
pop ebx
ret 12
.no_mem:
mov ecx,[esp+12]
mov [ecx],eax
ret 12
/programs/develop/ktcc/trunk/libc/kolibrisys/window_redraw.asm
0,0 → 1,11
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_window_redraw,4
;arg1 - status
mov edx,ebx
mov eax,12
mov ebx,[esp+4]
int 0x40
mov ebx,edx
ret 4
/programs/develop/ktcc/trunk/libc/kolibrisys/write_text.asm
0,0 → 1,21
format ELF
section '.text' executable
public _ksys_write_text
 
_ksys_write_text:
;arg1 - x
;arg2 - y
;arg3 - color
;arg4 - text
;arg5 - len
 
mov eax,4
mov ebx,[esp+4]
shl ebx,16
mov bx,[esp+8]
mov ecx,[esp+12]
mov edx,[esp+16]
mov esi,[esp+20]
int 0x40
 
ret 20
/programs/develop/ktcc/trunk/libc/makefile
0,0 → 1,30
INCLUDE = include
LIBSFORBUILD = math
LIBNAME = libck.a
CC = gcc
CFLAGS = -I$(INCLUDE) -nostdinc -DGNUC -L./ -lm
DIRS := stdio kolibrisys string stdlib memory math
 
##############################################################
#files := $(foreach dir,$(DIRS),$(dir)/$(wildcard $(dir)/*))
asmfiles := $(foreach dir,$(DIRS),$(patsubst %.asm, %.o, $(wildcard $(dir)/*.asm)))
cfiles := $(foreach dir,$(DIRS),$(patsubst %.c, %.o, $(wildcard $(dir)/*.c)))
 
.PHONY: clean all
 
ifdef windir
doClean = del /F /Q $(subst /,\,$(cfiles)) $(subst /,\,$(asmfiles))
else
doClean = rm $(cfiles) $(asmfiles)
endif
 
all: $(cfiles) $(asmfiles)
ar -ru $(LIBNAME) $^
 
$(cfiles): $(INCLUDE)/*.h
 
$(asmfiles):
fasm $*.asm $*.o
 
clean:
$(doClean)
/programs/develop/ktcc/trunk/libc/memory/memalloc.asm
0,0 → 1,38
format ELF
 
;include "proc32.inc"
section '.text' executable
public malloc
public free
public realloc
 
align 4
malloc:
 
mov eax,68
mov ebx,12
mov ecx,[esp+4] ;size
int 0x40
 
ret 4
 
align 4
free:
 
mov eax,68
mov ebx,13
mov ecx,[esp+4]
int 0x40
 
ret 4
 
align 4
realloc:
 
mov ebx,20
mov eax,68
mov ecx,[esp+4]
mov edx,[esp+8]
int 0x40
 
ret 8
/programs/develop/ktcc/trunk/libc/stdio/fclose.c
0,0 → 1,9
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
void fclose(FILE* file)
{
free(file->buffer);
free(file);
}
/programs/develop/ktcc/trunk/libc/stdio/feof.c
0,0 → 1,5
#include <stdio.h>
int feof(FILE* file)
{
return file->filepos>=file->filesize;
}
/programs/develop/ktcc/trunk/libc/stdio/fflush.c
0,0 → 1,7
#include <stdio.h>
int fflush(FILE* file)
{
if ((file->mode & 3)==FILE_OPEN_READ)
return 0;
return(EOF);
}
/programs/develop/ktcc/trunk/libc/stdio/fgetc.c
0,0 → 1,22
#include <stdio.h>
int fgetc(FILE* file)
{
dword res;
 
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0)) return EOF;
 
if (file->filepos>=file->filesize)
{
return EOF;
}
else
{
res=_ksys_readfile(file->filename,file->filepos,1,file->buffer);
if (res==0)
{
file->filepos++;
return (int)file->buffer[0];
}
else return(res);
}
}
/programs/develop/ktcc/trunk/libc/stdio/fgetpos.c
0,0 → 1,6
#include <stdio.h>
int fgetpos(FILE* file,fpos_t* pos)
{
*pos=file->filepos;
return 0;
}
/programs/develop/ktcc/trunk/libc/stdio/fopen.c
0,0 → 1,138
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
extern char __argv;
extern char __path;
 
const char* getfullpath(const char *path){
 
int i,j,relpath_pos,localpath_size;
int filename_size;
char local_path;
char *programpath;
char *newpath;
 
i=0;
local_path=1; //enable local path
while((*(path+i)!='\0') || (*(path+i)!=0))
{
if (*(path+i)=='.')
{
if (*(path+i+1)=='/')
{ //detected relative path
relpath_pos=i+2;
local_path=0;
break;
}
}
if (*(path+i)=='/')
{ //disabple local path
local_path=0;
return(path);
}
i++;
}
filename_size=i;
 
programpath=&__path;
 
if (local_path==1)
{
i=0x400;
//find local path of program
while(*(programpath+i)!='/')
{
i--;
}
localpath_size=i;
newpath=malloc(0x400);
//copy local path to the new path
for(i=0;i<=localpath_size;i++)
{
*(newpath+i)=*(programpath+i);
}
//copy filename to the new path
for(i=0;i<filename_size;i++)
{
*(newpath+localpath_size+1+i)=*(path+i);
}
return(newpath);
}
 
//if we here than path is a relative
i=0x400;
//find local path of program
while(*(programpath+i)!='/')
{
i--;
}
localpath_size=i;
i=0;
//find file name size
while((*(path+relpath_pos+i)!='\0') || (*(path+relpath_pos+i)!=0))
{
i++;
}
filename_size=i;
newpath=malloc(0x400);
//copy local path to the new path
for(i=0;i<=localpath_size;i++)
{
*(newpath+i)=*(programpath+i);
}
//copy filename to the new path
for(i=0;i<filename_size;i++)
{
*(newpath+localpath_size+1+i)=*(path+relpath_pos+i);
}
return(newpath);
}
 
 
FILE* fopen(const char* filename, const char *mode)
{
FILE* res;
int imode;
imode=0;
if (*mode=='r')
{
imode=FILE_OPEN_READ;
mode++;
}else if (*mode=='w')
{
imode=FILE_OPEN_WRITE;
mode++;
}else if (*mode=='a')
{
imode=FILE_OPEN_APPEND;
mode++;
}else
return 0;
if (*mode=='t')
{
imode|=FILE_OPEN_TEXT;
mode++;
}else if (*mode=='b')
mode++;
if (*mode=='+')
{
imode|=FILE_OPEN_PLUS;
mode++;
}
if (*mode!=0)
return 0;
res=malloc(sizeof(FILE));
res->buffer=malloc(256);
res->buffersize=256;
res->filesize=0;
res->filepos=0;
res->mode=imode;
res->filename=getfullpath(filename);
 
if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
{
res->filesize=_ksys_get_filesize(res->filename);
}
return res;
}
/programs/develop/ktcc/trunk/libc/stdio/format_print.c
0,0 → 1,729
/*
function for format output to the string
*/
 
#include <kolibrisys.h>
#include <string.h>
#include <stdio.h>
//#include <ctype.h>
#include <math.h>
 
int formatted_double_to_string(long double number,int format1,int format2,char *s)
{
double n;
double nbefor;
double nafter;
double v,v2;
long intdigit;
long beforpointdigit;
long div;
int i;
int pos;
int size;
int fmt1;
int fmt2;
long mul;
char buf[200];
 
size=(int)s;
n=(double)number;
if (n<0) {*s='-';s++;n=-n;}
 
fmt1=format1;
fmt2=format2;
if (fmt2>18) {fmt2=18;} //maximum of size long long type
 
//clear array befor output
for(i=0;i<=200;i++) {buf[i]=0;}
 
if ((fmt1>=0) && (n<1))
{ //formatted output if 0<=n<1
mul=1;
for(i=0;i<fmt2;i++)
{n=n*10;mul=mul*10;}
 
n=n*10;
n=ceil(n);
intdigit=floor(n);
//intdigit=n;
intdigit=(intdigit/10);
 
pos=0;
mul=mul/10;
for(i=0;i<fmt2-1;i++)
{
div=intdigit/mul;
buf[pos]=(char)div;
pos++;
intdigit=intdigit-div*mul;
mul=mul/10;
if (mul==1) break;
}
buf[pos]=(char)intdigit;
*s='0';s++;
*s='.';s++;
for(i=0;i<format2;i++)
{
if ((buf[i]>=0) && (buf[i]<=9)) {*s='0'+buf[i];}
else {*s='0';}
s++;
}
}
else
{ //if n>=1
//v=floorf(n+0.00000000000001);
beforpointdigit=floor(n+0.00000000000001);
//beforpointdigit=n;
nbefor=beforpointdigit;
nafter=n-nbefor;
 
//print part of number befor point
mul=1;
for(i=0;i<200-2;i++)
{
mul=mul*10;
if ((beforpointdigit/mul)==0) {fmt1=i+1;break;}
}
 
pos=0;
mul=mul/10;
for(i=0;i<fmt1-1;i++)
{
div=beforpointdigit/mul;
buf[pos]=(char)div;
pos++;
beforpointdigit=beforpointdigit-div*mul;
mul=mul/10;
if (mul==1) break;
}
buf[pos]=(char)beforpointdigit;
 
for(i=0;i<fmt1;i++)
{
if ((buf[i]>=0) && (buf[i]<=9)) {*s='0'+buf[i];}
s++;
}
 
//print part of number after point
mul=1;
for(i=0;i<fmt2;i++)
{nafter=nafter*10;mul=mul*10;}
 
nafter=nafter*10;
nafter=ceil(nafter);
intdigit=floor(nafter);
//intdigit=nafter;
intdigit=intdigit/10;
 
pos=0;
mul=mul/10;
for(i=0;i<fmt2-1;i++)
{
div=intdigit/mul;
buf[pos]=(char)div;
pos++;
intdigit=intdigit-div*mul;
mul=mul/10;
if (mul==1) break;
}
buf[pos]=(char)intdigit;
*s='.';s++;
for(i=0;i<format2;i++)
{
if ((buf[i]>=0) && (buf[i]<=9)) {*s='0'+buf[i];}
else {*s='0';}
s++;
}
 
}
size=(int)s-size;
return(size);
}
 
int formatted_long_to_string(long long number,int fmt1,char *s)
{
int i;
int pos;
int fmt;
int size;
int difference_pos;
long digit;
long mul;
long div;
char buf[200];
 
//clear array befor output
for(i=0;i<200;i++) {buf[i]=0;}
digit=number;
 
size=(int)s;
if (digit<0) {*s='-';s++;digit=-digit;}
if (digit==0) {*s='0';s++;goto end;}
 
mul=1;
for(i=0;i<200-2;i++)
{
mul=mul*10;
if ((digit/mul)==0) {fmt=i+1;break;}
}
 
difference_pos=i+1;
 
pos=0;
mul=mul/10;
for(i=0;i<fmt-1;i++)
{
div=digit/mul;
buf[pos]=(char)div;
pos++;
digit=digit-div*mul;
mul=mul/10;
if (mul==1) break;
}
buf[pos]=(char)digit;
 
if (fmt1>=difference_pos) fmt=fmt1;
else
fmt=difference_pos;
 
for(i=0;i<fmt;i++)
{
if (i<difference_pos)
{
if ((buf[i]>=0) && (buf[i]<=9)) {*s='0'+buf[i];}
}
else
{
*s=' ';
}
s++;
}
end:
size=(int)s-size;
return(size);
}
 
int formatted_hex_to_string(long long number,int fmt1,char flag_register,char *s)
{
long n;
int i,pos;
int fmt;
long size;
int difference_pos;
char xdigs_lower[16]="0123456789abcdef";
char xdigs_upper[16]="0123456789ABCDEF";
char buf[200];
 
n=(long)number;
size=(int)s;
if (n<0) {*s='-';s++;n=-n;}
 
if (n==0) {*s='0';s++;goto end;}
for(i=0;i<200;i++) {buf[i]=0;}
 
i=0;
if (flag_register==0)
{
while (n>0)
{
buf[i]=xdigs_lower[n & 15];
n=n>>4;
i++;
}
}
else
{
while (n>0)
{
buf[i]=xdigs_upper[n & 15];
n=n>>4;
i++;
}
}
 
pos=i;
difference_pos=i;
 
for(i=pos-1;i>=0;i--)
{
*s=buf[i];
s++;
}
 
if (fmt1-difference_pos>0)
{
for(i=difference_pos+1;i<=fmt1;i++)
{
*s=' ';
s++;
}
}
end:size=(int)s-size;
return(size);
}
 
int formatted_octa_to_string(long long number,int fmt1,char flag_register,char *s)
{
long n;
int i,pos;
int fmt;
long size;
int difference_pos;
char xdigs_lower[16]="012345678";
char buf[200];
 
n=number;
size=(int)s;
if (n<0) {*s='-';s++;n=-n;}
 
if (n==0) {*s='0';s++;goto end;}
for(i=0;i<200;i++) {buf[i]=0;}
 
i=0;
if (flag_register==0)
{
while (n>0)
{
buf[i]=xdigs_lower[n & 7];
n=n>>3;
i++;
}
}
 
pos=i;
difference_pos=i;
 
for(i=pos-1;i>=0;i--)
{
*s=buf[i];
s++;
}
 
if (fmt1-difference_pos>0)
{
for(i=difference_pos+1;i<=fmt1;i++)
{
*s=' ';
s++;
}
}
end:size=(int)s-size;
return(size);
}
 
int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp)
{
int i,j,k;
int length;
int fmt1,fmt2,stepen;
size_t pos,posc;
long long intdigit;
long double doubledigit;
float floatdigit;
const char *fmt,*fmtc;
char *s;
char *str;
char buffmt1[30];
char buffmt2[30];
char buf[1024];
char format_flag;
char flag_point;
char flag_noformat;
char flag_long;
char flag_unsigned;
char flag_register;
char flag_plus;
 
fmt=fmt0;
s=dest;
pos=0;
while(pos<maxlen)
{
if (*fmt=='%')
{
 
if (*(fmt+1)=='%')
{
*s='%';
s++;
fmt=fmt+2;
pos++;
goto exit_check;
}
//checking to containg format in the string
fmtc=fmt;
posc=pos;
format_flag=0;
flag_long=0;
flag_unsigned=0;
flag_register=0;
flag_plus=0;
while((*fmtc!='\0') || (*fmtc!=0))
{
fmtc++;
posc++;
switch(*fmtc)
{
case 'c':
case 'C':
format_flag=1;
break;
case 'd':
case 'D':
case 'i':
case 'I':
format_flag=1;
break;
case 'e':
format_flag=1;
break;
case 'E':
format_flag=1;
flag_long=1;
break;
case 'f':
format_flag=1;
break;
case 'F':
format_flag=1;
flag_long=1;
break;
case 'g':
format_flag=1;
break;
case 'G':
format_flag=1;
flag_long=1;
break;
case 'l':
flag_long=1;
break;
case 'L':
flag_long=2;
break;
case 'o':
format_flag=1;
break;
case 's':
case 'S':
format_flag=1;
break;
case 'u':
case 'U':
format_flag=1;
flag_unsigned=1;
break;
case 'x':
format_flag=1;
break;
case 'X':
flag_register=1;
format_flag=1;
break;
case 'z':
case 'Z':
format_flag=1;
flag_unsigned=1;
break;
case '+':
flag_plus=1;
break;
 
default:;
}
if ((*fmtc=='%') || (*fmtc==' ')) break;
if (format_flag==1) break;
}
 
if (format_flag==0)
{
*s=*fmt;
fmt++;
s++;
pos++;
}
else
{
if ((posc-pos)==1)
{//simbols % and format simbol near tothere(for example %c )
fmt=fmtc+1;
switch(*fmtc)
{
case 'c':
case 'C':
if ((pos+1)<maxlen)
{
//*s=(int)va_arg(argp,char*);
*s=*((char *)argp);
argp=argp+4;
*s++;pos++;
}
break;
case 's':
case 'S':
str=va_arg(argp,char*);
length=strlen(str);
if ((pos+length)<maxlen)
{
memcpy(s,str,length);
s=s+length;pos=pos+length;
}
break;
case 'd':
case 'D':
case 'i':
case 'I':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
//intdigit=*((long*)argp);
//argp=argp+4;
if ((intdigit>0) && (flag_plus==1) && (pos+1<maxlen))
{
*s='+';
s++;
pos++;
}
length=formatted_long_to_string(intdigit,0,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'o':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
//intdigit=*((long int *)argp);
//argp=argp+4;
 
length=formatted_octa_to_string(intdigit,0,flag_register,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'u':
case 'U':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long int);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
 
if (flag_unsigned==1) {
if (intdigit<0) {intdigit=-intdigit;}
}
 
length=formatted_long_to_string(intdigit,0,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'x':
case 'X':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
//intdigit=*((long int *)argp);
//argp=argp+4;
 
length=formatted_hex_to_string(intdigit,0,flag_register,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'z':
case 'Z':
intdigit=va_arg(argp,size_t);
 
if (flag_unsigned==1) {
if (intdigit<0) {intdigit=-intdigit;}
}
 
length=formatted_long_to_string(intdigit,0,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
default:;
 
}
}
else
{
fmt++;
flag_point=0;
flag_noformat=0;
fmt1=0;
fmt2=0;
j=0;
k=0;
for(i=pos+1;i<posc;i++)
{
switch(*fmt)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (flag_point==0)
{
buffmt1[j]=*fmt-'0';
j++;
}
else
{
buffmt2[k]=*fmt-'0';
k++;
}
break;
case '.':
flag_point=1;
break;
case 'l':
case 'L':
break;
case '+':
break;
default:flag_noformat=1;
}
if (flag_noformat==1) break;
fmt++;
}
if (flag_noformat==0)
{
stepen=1;
for(i=j-1;i>=0;i--)
{
fmt1=fmt1+buffmt1[i]*stepen;
stepen=stepen*10;
}
stepen=1;
for(i=k-1;i>=0;i--)
{
fmt2=fmt2+buffmt2[i]*stepen;
stepen=stepen*10;
}
switch(*fmtc)
{
case 'f':
case 'F':
if (flag_long==0) {doubledigit=va_arg(argp,double);}
if (flag_long>=1) {doubledigit=va_arg(argp,long double);}
//doubledigit=*((double *)argp);
//sargp=argp+8;
length=formatted_double_to_string(doubledigit,fmt1,fmt2,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'd':
case 'D':
case 'i':
case 'I':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
 
if ((intdigit>0) && (flag_plus==1) && (pos+1<maxlen))
{
*s='+';
s++;
pos++;
}
length=formatted_long_to_string(intdigit,fmt1,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'o':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
length=formatted_octa_to_string(intdigit,fmt1,flag_register,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'u':
case 'U':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long int);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
 
if (flag_unsigned==1) {
if (intdigit<0) {intdigit=-intdigit;}
}
 
length=formatted_long_to_string(intdigit,fmt1,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'x':
case 'X':
if (flag_long==0) {intdigit=va_arg(argp,int);}
if (flag_long==1) {intdigit=va_arg(argp,long int);}
if (flag_long==2) {intdigit=va_arg(argp,long long);}
length=formatted_hex_to_string(intdigit,fmt1,flag_register,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
case 'z':
case 'Z':
intdigit=va_arg(argp,size_t);
 
if (flag_unsigned==1) {
if (intdigit<0) {intdigit=-intdigit;}
}
 
length=formatted_long_to_string(intdigit,fmt1,buf);
if ((pos+length)<maxlen)
{
memcpy(s,buf,length);
s=s+length;pos=pos+length;
}
break;
default:;
}
}
fmt=fmtc+1;
}
}
}
else
{
if (*fmt=='\0') {break;}
*s=*fmt;
fmt++;
s++;
pos++;
}
exit_check:;
}
return(pos);
}
/programs/develop/ktcc/trunk/libc/stdio/fprintf.c
0,0 → 1,21
#include <stdio.h>
 
int format_print(char *dest, size_t maxlen, const char *fmt,va_list argp);
 
int fprintf(FILE* file, const char* format, ...)
{
va_list arg;
char *buf;
int printed;
//int data[4];
va_start (arg, format);
buf=malloc(4096*2); //8kb max
//data[0]=(int)&arg-(int)&format;
 
printed=format_print(buf,8191, format,arg);
fwrite(buf,printed,1,file);
free(buf);
 
return(printed);
}
/programs/develop/ktcc/trunk/libc/stdio/fputc.c
0,0 → 1,35
#include <stdio.h>
int fputc(int c,FILE* file)
{
dword res;
 
if ((file->mode & 3)==FILE_OPEN_READ) return EOF;
 
file->buffer[0]=c;
if ((file->mode & 3)==FILE_OPEN_APPEND)
{
file->filepos=file->filesize;
file->filesize++;
res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
if (res!=0) return(res);
file->filepos++;
return(0);
}
if ((file->mode & 3)==FILE_OPEN_WRITE)
{
if (file->filepos==0)
{ //file not craeted
res=_ksys_rewritefile(file->filename,1,file->buffer);
if (res!=0) return(res);
file->filepos++;
return 0;
}
else
{ //file craeted and need append one byte
res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
if (res!=0) return(res);
file->filepos++;
return 0;
}
}
}
/programs/develop/ktcc/trunk/libc/stdio/fread.c
0,0 → 1,26
#include <stdio.h>
#include <kolibrisys.h>
 
int fread(void *buffer,int size,int count,FILE* file)
{
dword res;
dword fullsize;
 
if ((file->mode!=FILE_OPEN_READ) || (file->mode==FILE_OPEN_PLUS)) return 0;
 
fullsize=count*size;
if ((fullsize+file->filepos)>(file->filesize))
{
fullsize=file->filesize-file->filepos;
if (fullsize<=0) return(0);
}
 
res=_ksys_readfile(file->filename,file->filepos,fullsize,buffer);
if (res==0)
{
file->filepos=file->filepos+fullsize;
fullsize=fullsize/size;
return(fullsize);
}
else return 0;
}
/programs/develop/ktcc/trunk/libc/stdio/fscanf.c
0,0 → 1,188
#include <stdio.h>
void skipspaces(FILE* file)
{
int c;
while(1)
{
c=getc(file);
if (c!=' ' && c!='\r' && c!='\n')
{
ungetc(c,file);
return;
}
}
}
int fscanf(FILE* file,const char* format, ...)
{
int res;
void* arg;
int i;
int c;
int contflag;
int longflag;
int sign;
long long number;
long double rnumber;
char* str;
res=0;
arg=&format;
arg+=sizeof(const char*);
while (*format!='\0')
{
if (*format!='%')
{
c=fgetc(file);
if (c!=*format)
{
fungetc(c,file);
return -1;
}
format++;
continue;
}
contflag=1;
longflag=0;
while (*format && contflag)
{
switch(*format)
{
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
format++;
continue;
break;
case 'l':
if (longflag==0)
longflag=1;
else
longflag=2;
format++;
break;
case 'L':
longflag=2;
format++;
break;
case 'f':
case 'd':
case 'c':
case 's':
case '%':
contflag=0;
break;
default:
contflag=0;
}
}
if (contflag)
break;
switch(*format)
{
case '%':
c=fgetc(file);
if (c!='%')
{
ungetc(c,file);
return -1;
}
res--;
break;
case 'd':
number=0;
sign=1;
skipspaces(file);
c=fgetc(file);
if (c=='-')
{
sign=-1;
}else if (c!='+')
ungetc(c,file);
contflag=0;
while(1)
{
c=fgetc(file);
if (c>='0' && c<='9')
{
contflag++;
number=number*10+(c-'0');
}else
break;
}
ungetc(c,file);
if (!contflag)
return res;
if (longflag<=1)
{
*((int*)arg)=number;
arg+=sizeof(int);
}else
{
*((long long*)arg)=number;
arg+=sizeof(long long);
}
break;
case 'c':
c=fgetc(file);
if (c==EOF)
return res;
*((char*)arg)=c;
arg+=sizeof(char);
break;
case 's':
skipspaces(file);
contflag=0;
str=*((char**)arg);
arg+=sizeof(char*);
while(1)
{
c=fgetc(file);
if (c==EOF || c==' ' || c=='\n' || c=='\r')
{
ungetc(c,file);
break;
}
*str=c;
str++;
contflag++;
}
if (!contflag)
return res;
break;
case 'f':
skipspaces(file);
// TODO: read real numbers
rnumber=0;
switch (longflag)
{
case 0:
*((float*)arg)=rnumber;
arg+=sizeof(float);
break;
case 1:
*((double*)arg)=rnumber;
arg+=sizeof(double);
break;
case 2:
*((long double*)arg)=rnumber;
arg+=sizeof(long double);
break;
default:
return res;
}
break;
default:
break;
}
format++;
res++;
}
return res;
}
/programs/develop/ktcc/trunk/libc/stdio/fseek.c
0,0 → 1,11
#include <stdio.h>
int fseek(FILE* file,long offset,int origin)
{
if (origin==SEEK_CUR)
offset+=file->filepos;
else if (origin==SEEK_END)
offset+=file->filesize;
else if (origin!=SEEK_SET)
return EOF;
return fsetpos(file,offset);
}
/programs/develop/ktcc/trunk/libc/stdio/fsetpos.c
0,0 → 1,11
#include <stdio.h>
int fsetpos(FILE* file,const fpos_t * pos)
{
if (*pos>=0)
{
file->filepos=*pos;
return 0;
}
else
return EOF;
}
/programs/develop/ktcc/trunk/libc/stdio/ftell.c
0,0 → 1,5
#include <stdio.h>
long ftell(FILE* file)
{
return file->filepos;
}
/programs/develop/ktcc/trunk/libc/stdio/fwrite.c
0,0 → 1,58
#include <stdio.h>
#include <kolibrisys.h>
 
int fwrite(void *buffer,int size,int count,FILE* file)
{
dword res;
dword fullsize;
 
if (file->mode==FILE_OPEN_READ) return 0;
 
if (file->mode==FILE_OPEN_APPEND)
file->filepos=file->filesize;
fullsize=count*size;
if ((file->filesize)<(file->filepos+fullsize)) file->filesize=file->filepos+fullsize;
 
/*
if (file->mode==FILE_OPEN_APPEND)
{
file->filepos==file->filesize;
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
if (res==0)
{
file->filepos+=fullsize;
fullsize=fullsize/size;
return(fullsize);
}
else return(0);
}
*/
if ((file->mode==FILE_OPEN_WRITE) || (file->mode==FILE_OPEN_APPEND))
{
if (file->filepos==0)
{ //file mot craeted yet
res=_ksys_rewritefile(file->filename,fullsize,buffer);
if (res==0)
{
file->filepos+=fullsize;
fullsize=fullsize/count;
return(fullsize);
}
else return(0);
}
else
{
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
if (res==0)
{
file->filepos+=fullsize;
fullsize=fullsize/count;
return(fullsize);
}
else return(0);
}
}
else return(0);
}
/programs/develop/ktcc/trunk/libc/stdio/printf.c
0,0 → 1,75
 
#include <stdio.h>
#include <string.h>
#include <kolibrisys.h>
 
char* dllname="/sys/lib/console.obj";
int console_init_status;
 
char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL};
char* caption = "Console test - colors";
 
dword* dll_ver;
void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title);
void stdcall (* con_write_asciiz)(const char* string);
void cdecl (* con_printf)(const char* format,...);
void stdcall (* con_exit)(dword bCloseWindow);
 
struct import{
char *name;
void *data;
};
 
void printf_link(struct import *exp, char** imports){
 
dll_ver = (dword*)
_ksys_cofflib_getproc(exp, imports[1]);
con_init = (void stdcall (*)(dword , dword, dword, dword, const char*))
_ksys_cofflib_getproc(exp, imports[2]);
con_printf = (void cdecl (*)(const char*,...))
_ksys_cofflib_getproc(exp, imports[4]);
con_exit = (void stdcall (*)(dword))
_ksys_cofflib_getproc(exp, imports[5]);
}
 
int init_console(void)
{
struct import * hDll;
 
if((hDll = (struct import *)_ksys_cofflib_load(dllname)) == 0){
debug_out_str("can't load lib\n");
return 1;
}
printf_link(hDll, imports);
debug_out_str("dll loaded\n");
 
con_init(-1, -1, -1, -1, caption);
return(0);
}
 
int printf(const char *format,...)
{
int i;
int printed_simbols;
va_list arg;
char simbol[]={"%s"};
char *s;
 
va_start(arg,format);
 
if (console_init_status==0)
{
i=init_console();
console_init_status=1;
}
 
if (i==0)
{
s=malloc(4096);
printed_simbols=format_print(s,4096,format,arg);
con_printf(simbol,s);
free(s);
}
return(printed_simbols);
}
 
/programs/develop/ktcc/trunk/libc/stdio/rewind.c
0,0 → 1,5
#include <stdio.h>
void rewind(FILE* file)
{
file->filepos=0;
}
/programs/develop/ktcc/trunk/libc/stdio/snprintf.c
0,0 → 1,15
#include <kolibrisys.h>
#include <stdlib.h>
#include <stdio.h>
 
int format_print(char *dest, size_t maxlen, const char *fmt,va_list argp);
 
 
int snprintf(char *dest, size_t size,const char *format,...)
{
va_list arg;
va_start (arg, format);
return format_print(dest,size, format, arg);
}
 
 
/programs/develop/ktcc/trunk/libc/stdio/sprintf.c
0,0 → 1,15
#include <kolibrisys.h>
#include <stdlib.h>
#include <stdio.h>
 
int format_print(char *dest, size_t maxlen, const char *fmt,va_list argp);
 
 
int sprintf(char *dest,const char *format,...)
{
va_list arg;
va_start (arg, format);
return format_print(dest,4096, format, arg);
}
 
 
/programs/develop/ktcc/trunk/libc/stdio/vsnprintf.c
0,0 → 1,15
#include <kolibrisys.h>
#include <stdlib.h>
#include <stdio.h>
 
int format_print(char *dest, size_t maxlen, const char *fmt,
va_list argp);
 
 
int vsnprintf(char *dest, size_t size,const char *format,va_list ap)
{
 
return format_print(dest,size, format, ap);
}
 
 
/programs/develop/ktcc/trunk/libc/stdlib/atoi.c
0,0 → 1,21
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
 
 
/*
** atoi(s) - convert s to integer.
*/
int atoi(char *s)
{
int sign, n;
while(isspace(*s)) ++s;
sign = 1;
switch(*s) {
case '-': sign = -1;
case '+': ++s;
}
n = 0;
while(isdigit(*s)) n = 10 * n + *s++ - '0';
return (sign * n);
}
/programs/develop/ktcc/trunk/libc/stdlib/atoib.cpp
0,0 → 1,22
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
 
/*
** atoib(s,b) - Convert s to "unsigned" integer in base b.
** NOTE: This is a non-standard function.
*/
int atoib(char *s,int b)
{
int n, digit;
n = 0;
while(isspace(*s)) ++s;
while((digit = (127 & *s++)) >= '0') {
if(digit >= 'a') digit -= 87;
else if(digit >= 'A') digit -= 55;
else digit -= '0';
if(digit >= b) break;
n = b * n + digit;
}
return (n);
}
/programs/develop/ktcc/trunk/libc/stdlib/itoa.c
0,0 → 1,21
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
 
/*
** itoa(n,s) - Convert n to characters in s
*/
void itoa(int n,char* s)
{
int sign;
char *ptr;
ptr = s;
if ((sign = n) < 0) n = -n;
do {
*ptr++ = n % 10 + '0';
} while ((n = n / 10) > 0);
if (sign < 0) *ptr++ = '-';
*ptr = '\0';
reverse(s);
}
 
/programs/develop/ktcc/trunk/libc/stdlib/itoab.c
0,0 → 1,24
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
 
/*
** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b.
** NOTE: This is a non-standard function.
*/
void itoab(int n,char* s,int b)
{
char *ptr;
int lowbit;
ptr = s;
b >>= 1;
do {
lowbit = n & 1;
n = (n >> 1) & 32767;
*ptr = ((n % b) << 1) + lowbit;
if(*ptr < 10) *ptr += '0'; else *ptr += 55;
++ptr;
} while(n /= b);
*ptr = 0;
reverse (s);
}
/programs/develop/ktcc/trunk/libc/stdlib/tolower.c
0,0 → 1,8
/*
** return lower-case of c if upper-case, else c
*/
unsigned char tolower(unsigned char c)
{
if(c<='Z' && c>='A') return (c+32);
return (c);
}
/programs/develop/ktcc/trunk/libc/stdlib/toupper.c
0,0 → 1,8
/*
** return upper-case of c if it is lower-case, else c
*/
unsigned char toupper(unsigned char c)
{
if(c<='z' && c>='a') return (c-32);
return (c);
}
/programs/develop/ktcc/trunk/libc/string/memmove.asm
0,0 → 1,35
format ELF
 
section '.text' executable
include 'proc32.inc'
 
public memcpy
public memmove
 
proc memcpy stdcall, to:dword,from:dword,count:dword
 
mov ecx,[count]
test ecx,ecx
jz no_copy_block
mov esi,[from]
mov edi,[to]
rep movsb
no_copy_block:
 
ret
endp
 
proc memmove stdcall, to:dword,from:dword,count:dword
 
mov ecx,[count]
test ecx,ecx
jz no_copy_block_
mov esi,[from]
mov edi,[to]
rep movsb
no_copy_block_:
 
ret
endp
/programs/develop/ktcc/trunk/libc/string/is.c
0,0 → 1,19
#include "ctype.h"
int __is[128] = {
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004,
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
0x140, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459,
0x459, 0x459, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
0x0D0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253,
0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
0x253, 0x253, 0x253, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0,
0x0D0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073,
0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
0x073, 0x073, 0x073, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x004
};
/programs/develop/ktcc/trunk/libc/string/strlen.c
0,0 → 1,7
int strlen(const char* string)
{
int i;
i=0;
while (*string++) i++;
return i;
}
/programs/develop/ktcc/trunk/libc/string/strcat.c
0,0 → 1,8
char* strcat(char* strDest, const char* strSource)
{
char* res;
res=strDest;
while (*strDest++) ;
while (*strDest++ = *strSource++) ;
return res;
}
/programs/develop/ktcc/trunk/libc/string/strchr.c
0,0 → 1,10
char* strchr(const char* string, int c)
{
while (*string)
{
if (*string==c)
return (char*)string;
string++;
}
return (char*)0;
}
/programs/develop/ktcc/trunk/libc/string/strcpy.c
0,0 → 1,7
char* strcpy(char* strDest,char* strSource)
{
char* res;
res=strDest;
while(*strDest++ == strSource++) ;
return res;
}
/programs/develop/ktcc/trunk/libc/string/strncat.c
0,0 → 1,13
char* strncat(char* strDest,const char* strSource,int count)
{
char* res;
res=strDest;
while (*strDest++) ;
while(count-->0)
{
if(*strDest++ = *strSource++) continue;
return(res);
}
*strDest = 0;
return res;
}
/programs/develop/ktcc/trunk/libc/string/strncmp.c
0,0 → 1,12
int strncmp(const char* string1, const char* string2, int count)
{
while(count>0 && *string1==*string2)
{
if (*string1) return 0;
++string1;
++string2;
--count;
}
if(count) return (*string1 - *string2);
return 0;
}
/programs/develop/ktcc/trunk/libc/string/strncpy.c
0,0 → 1,14
char* strncpy(char* strDest,const char* strSource,int count)
{
char* res;
res=strDest;
while (count>0)
{
*strDest=*strSource;
if (*strSource!='\0')
strSource++;
strDest++;
count--;
}
return res;
}
/programs/develop/ktcc/trunk/libc/string/memchr.c
0,0 → 1,10
void* memchr(const void* buf,int c,int count)
{
int i;
for (i=0;i<count;i++)
if (*(char*)buf==c)
return (void*)buf;
else
buf++;
return (void*)0;
}
/programs/develop/ktcc/trunk/libc/string/memcmp.c
0,0 → 1,13
typedef unsigned char uc;
int memcmp(const void* buf1,const void* buf2,int count)
{
int i;
for (i=0;i<count;i++)
{
if (*(uc*)buf1<*(uc*)buf2)
return -1;
if (*(uc*)buf1>*(uc*)buf2)
return 1;
}
return 0;
}
/programs/develop/ktcc/trunk/libc/string/memset.asm
0,0 → 1,15
format ELF
section '.text' executable
public memset
memset:
push edi
mov edi,[esp+8]
mov eax,[esp+12]
mov ecx,[esp+16]
jecxz .no_set
cld
rep stosb
.no_set:
pop edi
ret
/programs/develop/ktcc/trunk/libc/string/strcmp.c
0,0 → 1,14
int strcmp(const char* string1, const char* string2)
{
while (1)
{
if (*string1<*string2)
return -1;
if (*string1>*string2)
return 1;
if (*string1=='\0')
return 0;
string1++;
string2++;
}
}
/programs/develop/ktcc/trunk/libc/string/strcoll.c
0,0 → 1,4
int strcoll(const char* string1,const char* string2)
{
return strcmp(string1,string2);
}
/programs/develop/ktcc/trunk/libc/string/strcspn.c
0,0 → 1,17
int strcspn(const char* string, const char* strCharSet)
{
const char* temp;
int i;
i=0;
while(1)
{
temp=strCharSet;
while (*temp!='\0')
{
if (*string==*temp)
return i;
temp++;
}
i++;string++;
}
}
/programs/develop/ktcc/trunk/libc/string/strdup.c
0,0 → 1,9
char* strdup(char* str)
{
char* res;
int len;
len=strlen(str)+1;
res=malloc(len);
memcpy(res,str,len);
return res;
}
/programs/develop/ktcc/trunk/libc/string/strerror.c
0,0 → 1,4
char* strerror(int err)
{
return (char*)0;
}
/programs/develop/ktcc/trunk/libc/string/strnbrk.c
0,0 → 1,16
char* strpbrk(const char* string, const char* strCharSet)
{
char* temp;
while (*string!='\0')
{
temp=strCharSet;
while (*temp!='\0')
{
if (*string==*temp)
return string;
temp++;
}
string++;
}
return (char*)0;
}
/programs/develop/ktcc/trunk/libc/string/strrchr.c
0,0 → 1,14
char* strrchr(const char* s,int c)
{
char* res;
res=(char*)0;
while (1)
{
if (*s==(char)c)
res=(char*)s;
if (*s=='\0')
break;
s++;
}
return res;
}
/programs/develop/ktcc/trunk/libc/string/strspn.c
0,0 → 1,20
int strspn(const char* string,const char* strCharSet)
{
int i;
const char* temp;
i=0;
while (*string!='\0')
{
temp=strCharSet;
while (temp!='\0')
{
if (*temp==*string)
break;
}
if (temp=='\0')
break;
*string++;
i++;
}
return i;
}
/programs/develop/ktcc/trunk/libc/string/strstr.c
0,0 → 1,13
extern int strncmp(char* s1,char* s2,int len);
char* strstr(const char* s, const char* find)
{
int len;
len=strlen(find);
while (1)
{
if (strncmp(s,find,len)==0) return s;
if (*s=='\0')
return (char*) 0;
s++;
}
}
/programs/develop/ktcc/trunk/libc/string/strtok.c
0,0 → 1,14
#include "string.h"
char* strtok(char* s,const char* delim)
{
char* res;
if (*s=='\0')
return (char*)0;
s+=strspn(s,delim);
if (*s=='\0')
return (char*)0;
res=s;
s+=strcspn(s,delim);
*s=='\0';
return res;
}
/programs/develop/ktcc/trunk/libc/string/strxfrm.c
0,0 → 1,4
int strxfrm(char* strDest, const char* strSource, int count)
{
return 0;
}
/programs/develop/ktcc/trunk/libc/string
Property changes:
Added: svn:ignore
+*.o
+*.s
/programs/develop/ktcc/trunk/libc/start/start.asm
0,0 → 1,135
format ELF
section '.text' executable
public start
extrn mf_init
extrn main
public argc as '__ARGS'
 
__DEBUG__ equ 1
__DEBUG_LEVEL__ equ 1
 
include 'DEBUG-FDO.INC'
 
virtual at 0
db 'MENUET01' ; 1. Magic number (8 bytes)
dd 0x01 ; 2. Version of executable file
dd 0x0 ; 3. Start address
dd 0x0 ; 4. Size of image
dd 0x100000 ; 5. Size of needed memory
dd 0x100000 ; 6. Pointer to stack
hparams dd 0x0 ; 7. Pointer to program arguments
hpath dd 0x0 ; 8. Pointer to program path
end virtual
start:
DEBUGF 1,'Start programm\n'
xor eax,eax
call mf_init
DEBUGF 1,' path "%s"\n params "%s"\n', path, params
; check for overflow
mov al, [path+buf_len-1]
or al, [params+buf_len-1]
jnz .crash
; check if path written by OS
mov eax, [hparams]
test eax, eax
jz .without_path
mov eax, path
.without_path:
mov esi, eax
call push_param
; retrieving parameters
mov esi, params
xor edx, edx ; dl - èä¸ò ïàðàìåòð(1) èëè ðàçäåëèòåëè(0)
; dh - ñèìâîë ñ êîòîðîãî íà÷àëñÿ ïàðàìåòð (1 êàâû÷êè, 0 îñòàëüíîå)
mov ecx, 1 ; cl = 1
; ch = 0 ïðîñòî íîëü
.parse:
lodsb
test al, al
jz .run
test dl, dl
jnz .findendparam
;{åñëè áûë ðàçäåëèòåëü
cmp al, ' '
jz .parse ;çàãðóæåí ïðîáåë, ãðóçèì ñëåäóþùèé ñèìâîë
mov dl, cl ;íà÷èíàåòñÿ ïàðàìåòð
cmp al, '"'
jz @f ;çàãðóæåíû êàâû÷êè
mov dh, ch ;ïàðàìåòð áåç êàâû÷åê
dec esi
call push_param
inc esi
jmp .parse
 
@@:
mov dh, cl ;ïàðàìåòð â êàâû÷åêàõ
call push_param ;åñëè íå ïðîáåë çíà÷èò íà÷èíàåòñÿ êàêîé òî ïàðàìåòð
jmp .parse ;åñëè áûë ðàçäåëèòåëü}
 
.findendparam:
test dh, dh
jz @f ; áåç êàâû÷åê
cmp al, '"'
jz .clear
jmp .parse
@@:
cmp al, ' '
jnz .parse
 
.clear:
lea ebx, [esi - 1]
mov [ebx], ch
mov dl, ch
jmp .parse
 
.run:
DEBUGF 1,'call main(%x, %x) with params:\n', [argc], argv
if __DEBUG__ = 1
mov ecx, [argc]
@@:
lea esi, [ecx * 4 + argv-4]
DEBUGF 1,'%d) "%s"\n', cx, [esi]
loop @b
end if
push argv
push [argc]
call main
.exit:
DEBUGF 1,'Exit from prog with code: %x\n', eax;
xor eax,eax
dec eax
int 0x40
dd -1
.crash:
DEBUGF 1,'E:buffer overflowed\n'
jmp .exit
;============================
push_param:
;============================
;parameters
; esi - pointer
;description
; procedure increase argc
; and add pointer to array argv
; procedure changes ebx
mov ebx, [argc]
cmp ebx, max_parameters
jae .dont_add
mov [argv+4*ebx], esi
inc [argc]
.dont_add:
ret
;==============================
public params as '__argv'
public path as '__path'
 
section '.bss'
buf_len = 0x400
max_parameters=0x20
argc rd 1
argv rd max_parameters
path rb buf_len
params rb buf_len
 
section '.data'
include_debug_strings ; ALWAYS present in data section
/programs/develop/ktcc/trunk/libc/start/debug-fdo.inc
0,0 → 1,422
;
; Formatted Debug Output (FDO)
; Copyright (c) 2005-2006, mike.dld
; Created: 2005-01-29, Changed: 2006-11-10
;
; For questions and bug reports, mail to mike.dld@gmail.com
;
; Available format specifiers are: %s, %d, %u, %x (with partial width support)
;
 
; to be defined:
; __DEBUG__ equ 1
; __DEBUG_LEVEL__ equ 5
 
macro debug_func name {
if used name
name@of@func equ name
}
 
macro debug_beginf {
align 4
name@of@func:
}
 
debug_endf fix end if
 
macro DEBUGS _sign,[_str] {
common
local tp
tp equ 0
match _arg:_num,_str \{
DEBUGS_N _sign,_num,_arg
tp equ 1
\}
match =0 _arg,tp _str \{
DEBUGS_N _sign,,_arg
\}
}
 
macro DEBUGS_N _sign,_num,[_str] {
common
pushf
pushad
local ..str,..label,is_str
is_str = 0
forward
if _str eqtype ''
is_str = 1
end if
common
if is_str = 1
jmp ..label
..str db _str,0
..label:
add esp,4*8+4
mov edx,..str
sub esp,4*8+4
else
mov edx,_str
end if
if ~_num eq
if _num eqtype eax
if _num in <eax,ebx,ecx,edx,edi,ebp,esp>
mov esi,_num
else if ~_num eq esi
movzx esi,_num
end if
else if _num eqtype 0
mov esi,_num
else
local tp
tp equ 0
match [_arg],_num \{
mov esi,dword[_arg]
tp equ 1
\}
match =0 =dword[_arg],tp _num \{
mov esi,dword[_arg]
tp equ 1
\}
match =0 =word[_arg],tp _num \{
movzx esi,word[_arg]
tp equ 1
\}
match =0 =byte[_arg],tp _num \{
movzx esi,byte[_arg]
tp equ 1
\}
match =0,tp \{
'Error: specified string width is incorrect'
\}
end if
else
mov esi,0x7FFFFFFF
end if
call fdo_debug_outstr
popad
popf
}
 
macro DEBUGD _sign,_dec {
local tp
tp equ 0
match _arg:_num,_dec \{
DEBUGD_N _sign,_num,_arg
tp equ 1
\}
match =0 _arg,tp _dec \{
DEBUGD_N _sign,,_arg
\}
}
 
macro DEBUGD_N _sign,_num,_dec {
pushf
pushad
if (~_num eq)
if (_dec eqtype eax | _dec eqtype 0)
'Error: precision allowed only for in-memory variables'
end if
if (~_num in <1,2,4>)
if _sign
'Error: 1, 2 and 4 are only allowed for precision in %d'
else
'Error: 1, 2 and 4 are only allowed for precision in %u'
end if
end if
end if
if _dec eqtype eax
if _dec in <ebx,ecx,edx,esi,edi,ebp,esp>
mov eax,_dec
else if ~_dec eq eax
if _sign = 1
movsx eax,_dec
else
movzx eax,_dec
end if
end if
else if _dec eqtype 0
mov eax,_dec
else
add esp,4*8+4
if _num eq
mov eax,dword _dec
else if _num = 1
if _sign = 1
movsx eax,byte _dec
else
movzx eax,byte _dec
end if
else if _num = 2
if _sign = 1
movsx eax,word _dec
else
movzx eax,word _dec
end if
else
mov eax,dword _dec
end if
sub esp,4*8+4
end if
mov cl,_sign
call fdo_debug_outdec
popad
popf
}
 
macro DEBUGH _sign,_hex {
local tp
tp equ 0
match _arg:_num,_hex \{
DEBUGH_N _sign,_num,_arg
tp equ 1
\}
match =0 _arg,tp _hex \{
DEBUGH_N _sign,,_arg
\}
}
 
macro DEBUGH_N _sign,_num,_hex {
pushf
pushad
if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>)
'Error: 1..8 are only allowed for precision in %x'
end if
if _hex eqtype eax
if _hex in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
if ~_hex eq eax
mov eax,_hex
end if
else if _hex in <ax,bx,cx,dx,si,di,bp,sp>
if ~_hex eq ax
movzx eax,_hex
end if
shl eax,16
if (_num eq)
mov edx,4
end if
else if _hex in <al,ah,bl,bh,cl,ch,dl,dh>
if ~_hex eq al
movzx eax,_hex
end if
shl eax,24
if (_num eq)
mov edx,2
end if
end if
else if _hex eqtype 0
mov eax,_hex
else
add esp,4*8+4
mov eax,dword _hex
sub esp,4*8+4
end if
if ~_num eq
mov edx,_num
else
mov edx,8
end if
call fdo_debug_outhex
popad
popf
}
 
;-----------------------------------------------------------------------------
 
debug_func fdo_debug_outchar
debug_beginf
pushad
mov cl,al
mov ebx,1
mov eax,63
int 0x40
popad
ret
debug_endf
 
debug_func fdo_debug_outstr
debug_beginf
mov eax,63
mov ebx,1
.l1: dec esi
js .l2
mov cl,[edx]
or cl,cl
jz .l2
int 0x40
inc edx
jmp .l1
.l2: ret
debug_endf
 
debug_func fdo_debug_outdec
debug_beginf
or cl,cl
jz @f
or eax,eax
jns @f
neg eax
push eax
mov al,'-'
call fdo_debug_outchar
pop eax
@@: push 10
pop ecx
push -'0'
.l1: xor edx,edx
div ecx
push edx
test eax,eax
jnz .l1
.l2: pop eax
add al,'0'
jz .l3
call fdo_debug_outchar
jmp .l2
.l3: ret
debug_endf
 
debug_func fdo_debug_outhex
__fdo_hexdigits db '0123456789ABCDEF'
debug_beginf
mov cl,dl
neg cl
add cl,8
shl cl,2
rol eax,cl
.l1: rol eax,4
push eax
and eax,0x0000000F
mov al,[__fdo_hexdigits+eax]
call fdo_debug_outchar
pop eax
dec edx
jnz .l1
ret
debug_endf
 
;-----------------------------------------------------------------------------
 
macro DEBUGF _level,_format,[_arg] {
common
if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__
local ..f1,f2,a1,a2,c1,c2,c3,..lbl
_debug_str_ equ __debug_str_ # a1
a1 = 0
c2 = 0
c3 = 0
f2 = 0
repeat ..lbl-..f1
virtual at 0
db _format,0,0
load c1 word from %-1
end virtual
if c1 = '%s'
virtual at 0
db _format,0,0
store word 0 at %-1
load c1 from f2-c2
end virtual
if c1 <> 0
DEBUGS 0,_debug_str_+f2-c2
end if
c2 = c2 + 1
f2 = %+1
DEBUGF_HELPER S,a1,0,_arg
else if c1 = '%x'
virtual at 0
db _format,0,0
store word 0 at %-1
load c1 from f2-c2
end virtual
if c1 <> 0
DEBUGS 0,_debug_str_+f2-c2
end if
c2 = c2 + 1
f2 = %+1
DEBUGF_HELPER H,a1,0,_arg
else if c1 = '%d' | c1 = '%u'
local c4
if c1 = '%d'
c4 = 1
else
c4 = 0
end if
virtual at 0
db _format,0,0
store word 0 at %-1
load c1 from f2-c2
end virtual
if c1 <> 0
DEBUGS 0,_debug_str_+f2-c2
end if
c2 = c2 + 1
f2 = %+1
DEBUGF_HELPER D,a1,c4,_arg
else if c1 = '\n'
c3 = c3 + 1
end if
end repeat
virtual at 0
db _format,0,0
load c1 from f2-c2
end virtual
if (c1<>0)&(f2<>..lbl-..f1-1)
DEBUGS 0,_debug_str_+f2-c2
end if
virtual at 0
..f1 db _format,0
..lbl:
__debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3
end virtual
end if
}
 
macro __include_debug_strings dummy,[_id,_fmt,_len] {
common
local c1,a1,a2
forward
if defined _len & ~_len eq
_id:
a1 = 0
a2 = 0
repeat _len
virtual at 0
db _fmt,0,0
load c1 word from %+a2-1
end virtual
if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u')
db 0
a2 = a2 + 1
else if (c1='\n')
dw $0A0D
a1 = a1 + 1
a2 = a2 + 1
else
db c1 and 0x0FF
end if
end repeat
db 0
end if
}
 
macro DEBUGF_HELPER _letter,_num,_sign,[_arg] {
common
local num
num = 0
forward
if num = _num
DEBUG#_letter _sign,_arg
end if
num = num+1
common
_num = _num+1
}
 
macro include_debug_strings {
if __DEBUG__ = 1
match dbg_str,__debug_strings \{
__include_debug_strings dbg_str
\}
end if
}
/programs/develop/ktcc/trunk/libc/start/macros.inc
0,0 → 1,337
; language for programs
lang fix en ; ru en fr ge fi
 
@^ fix macro comment {
^@ fix }
 
; strings
macro sz name,[data] { ; from MFAR [mike.dld]
common
if used name
name db data
.size = $-name
end if
}
 
macro lsz name,[lng,data] { ; from MFAR [mike.dld]
common
if used name
label name
forward
if lang eq lng
db data
end if
common
.size = $-name
end if
}
 
macro szc name,elsz,[data] { ; from MFAR [mike.dld]
common
local s,m
m = 0
if used name
label name
virtual at 0
db data
s = $
end virtual
d#elsz s
if m < s
m = s
end if
db data
.size = $-name
.maxl = m
end if
}
 
macro lszc name,elsz,[lng,data] { ; from MFAR [mike.dld]
common
local s,m
m = 0
if used name
label name
forward
if lang eq lng
virtual at 0
db data
s = $
end virtual
d#elsz s
if m < s
m = s
end if
db data
end if
common
.size = $-name
.maxl = m
end if
}
 
 
; easy system call macro
macro mpack dest, hsrc, lsrc
{
if (hsrc eqtype 0) & (lsrc eqtype 0)
mov dest, (hsrc) shl 16 + lsrc
else
if (hsrc eqtype 0) & (~lsrc eqtype 0)
mov dest, (hsrc) shl 16
add dest, lsrc
else
mov dest, hsrc
shl dest, 16
add dest, lsrc
end if
end if
}
 
macro __mov reg,a,b { ; mike.dld
if (~a eq)&(~b eq)
mpack reg,a,b
else if (~a eq)&(b eq)
mov reg,a
end if
}
 
macro mcall a,b,c,d,e,f { ; mike.dld
__mov eax,a
__mov ebx,b
__mov ecx,c
__mov edx,d
__mov esi,e
__mov edi,f
int 0x40
}
 
; -------------------------
macro header a,[b] {
common
use32
org 0
db 'MENUET',a
forward
if b eq
dd 0
else
dd b
end if }
macro section name,algn
{
local boundary
boundary = 16
if ~algn eq
boundary = algn
end if
align boundary
label name
}
macro func name {
if ~used name
display 'FUNC NOT USED: ',`name,13,10
else
align 4
name:
;pushad
;pushfd
;dps `name
;newline
;mcall 5,1
;popfd
;popad
}
macro endf { end if }
 
macro jif _op1,_cond,_op2,_label,_op
{
if _op eq
cmp _op1,_op2
else
_op _op1,_op2
end if
j#_cond _label
}
 
macro diff16 title,l1,l2
{
local s,d
s = l2-l1
display title,': 0x'
repeat 8
d = '0' + s shr ((8-%) shl 2) and $0F
if d > '9'
d = d + 'A'-'9'-1
end if
display d
end repeat
display 13,10
}
 
macro diff10 title,l1,l2
{
local s,d,z,m
s = l2-l1
z = 0
m = 1000000000
display title,': '
repeat 10
d = '0' + s / m
s = s - (s/m)*m
m = m / 10
if d <> '0'
z = 1
end if
if z <> 0
display d
end if
end repeat
display 13,10
}
 
; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
macro add arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
inc arg1
else
add arg1,arg2
end if
else
add arg1,arg2
end if
}
 
macro sub arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
dec arg1
else
sub arg1,arg2
end if
else
sub arg1,arg2
end if
}
 
macro mov arg1,arg2
{
if (arg1 in __regs) & (arg2 eqtype 0)
if (arg2) = 0
xor arg1,arg1
else if (arg2) = 1
xor arg1,arg1
inc arg1
else if (arg2) = -1
or arg1,-1
else if (arg2) > -128 & (arg2) < 128
push arg2
pop arg1
else
mov arg1,arg2
end if
else
mov arg1,arg2
end if
}
 
 
struc POINT _t,_dx,_dy {
.x _t _dx
.y _t _dy
}
 
; structure definition helper
macro struct name, [arg]
{
common
name@struct fix name
struc name arg {
}
 
macro struct_helper name
{
virtual at 0
name name
sizeof.#name = $ - name
name equ sizeof.#name
end virtual
}
 
ends fix } struct_helper name@struct
 
macro union [def]
{
common size@union = 0
origin@union = $
forward virtual
def
if $-origin@union > size@union
size@union = $-origin@union
end if
end virtual
common rb size@union
}
 
; structures used in MeOS
struc process_information
{
.cpu_usage dd ? ; +0
.window_stack_position dw ? ; +4
.window_stack_value dw ? ; +6
.not_used1 dw ? ; +8
.process_name rb 12 ; +10
.memory_start dd ? ; +22
.used_memory dd ? ; +26
.PID dd ? ; +30
.x_start dd ? ; +34
.y_start dd ? ; +38
.x_size dd ? ; +42
.y_size dd ? ; +46
.slot_state dw ? ; +50
rb (1024-52)
}
 
struc system_colors
{
.frame dd ?
.grab dd ?
.grab_button dd ?
.grab_button_text dd ?
.grab_text dd ?
.work dd ?
.work_button dd ?
.work_button_text dd ?
.work_text dd ?
.work_graph dd ?
}
 
 
; constants
 
; events
EV_IDLE = 0
EV_TIMER = 0
EV_REDRAW = 1
EV_KEY = 2
EV_BUTTON = 3
EV_EXIT = 4
EV_BACKGROUND = 5
EV_MOUSE = 6
EV_IPC = 7
EV_STACK = 8
 
; event mask bits for function 40
EVM_REDRAW = 1b
EVM_KEY = 10b
EVM_BUTTON = 100b
EVM_EXIT = 1000b
EVM_BACKGROUND = 10000b
EVM_MOUSE = 100000b
EVM_IPC = 1000000b
EVM_STACK = 10000000b
/programs/develop/ktcc/trunk/libc/start
Property changes:
Added: svn:ignore
+*.o
+*.s
/programs/develop/ktcc/trunk/libc/proc32.inc
0,0 → 1,268
 
; Macroinstructions for defining and calling procedures
 
macro stdcall proc,[arg] ; directly call STDCALL procedure
{ common
if ~ arg eq
reverse
pushd arg
common
end if
call proc }
 
macro invoke proc,[arg] ; indirectly call STDCALL procedure
{ common
if ~ arg eq
reverse
pushd arg
common
end if
call [proc] }
 
macro ccall proc,[arg] ; directly call CDECL procedure
{ common
size@ccall = 0
if ~ arg eq
reverse
pushd arg
size@ccall = size@ccall+4
common
end if
call proc
if size@ccall
add esp,size@ccall
end if }
 
macro cinvoke proc,[arg] ; indirectly call CDECL procedure
{ common
size@ccall = 0
if ~ arg eq
reverse
pushd arg
size@ccall = size@ccall+4
common
end if
call [proc]
if size@ccall
add esp,size@ccall
end if }
 
macro proc [args] ; define procedure
{ common
match name params, args>
\{ define@proc name,<params \} }
 
prologue@proc equ prologuedef
 
macro prologuedef procname,flag,parmbytes,localbytes,reglist
{ if parmbytes | localbytes
push ebp
mov ebp,esp
if localbytes
sub esp,localbytes
end if
end if
irps reg, reglist \{ push reg \} }
 
epilogue@proc equ epiloguedef
 
macro epiloguedef procname,flag,parmbytes,localbytes,reglist
{ irps reg, reglist \{ reverse pop reg \}
if parmbytes | localbytes
leave
end if
if (flag and 10000b) | (parmbytes=0)
retn
else
retn parmbytes
end if }
 
macro define@proc name,statement
{ local params,flag,regs,parmbytes,localbytes,current
if used name
name:
match =stdcall args, statement \{ params equ args
flag = 11b \}
match =stdcall, statement \{ params equ
flag = 11b \}
match =c args, statement \{ params equ args
flag = 10001b \}
match =c, statement \{ params equ
flag = 10001b \}
match =params, params \{ params equ statement
flag = 0 \}
virtual at ebp+8
match =uses reglist=,args, params \{ regs equ reglist
params equ args \}
match =regs =uses reglist, regs params \{ regs equ reglist
params equ \}
match =regs, regs \{ regs equ \}
match =,args, params \{ defargs@proc args \}
match =args@proc args, args@proc params \{ defargs@proc args \}
parmbytes = $ - (ebp+8)
end virtual
name # % = parmbytes/4
all@vars equ
current = 0
match prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,parmbytes,localbytes,reglist \}
macro locals
\{ virtual at ebp-localbytes+current
macro label . \\{ deflocal@proc .,:, \\}
struc db [val] \\{ \common deflocal@proc .,db,val \\}
struc dw [val] \\{ \common deflocal@proc .,dw,val \\}
struc dp [val] \\{ \common deflocal@proc .,dp,val \\}
struc dd [val] \\{ \common deflocal@proc .,dd,val \\}
struc dt [val] \\{ \common deflocal@proc .,dt,val \\}
struc dq [val] \\{ \common deflocal@proc .,dq,val \\}
struc rb cnt \\{ deflocal@proc .,rb cnt, \\}
struc rw cnt \\{ deflocal@proc .,rw cnt, \\}
struc rp cnt \\{ deflocal@proc .,rp cnt, \\}
struc rd cnt \\{ deflocal@proc .,rd cnt, \\}
struc rt cnt \\{ deflocal@proc .,rt cnt, \\}
struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \}
macro endl
\{ purge label
restruc db,dw,dp,dd,dt,dq
restruc rb,rw,rp,rd,rt,rq
restruc byte,word,dword,pword,tword,qword
current = $-(ebp-localbytes)
end virtual \}
macro ret operand
\{ match any, operand \\{ retn operand \\}
match , operand \\{ match epilogue:reglist, epilogue@proc:<regs>
\\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \}
macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2
end if \} }
 
macro defargs@proc [arg]
{ common
if ~ arg eq
forward
local ..arg,current@arg
match argname:type, arg
\{ current@arg equ argname
label ..arg type
argname equ ..arg
if dqword eq type
dd ?,?,?,?
else if tbyte eq type
dd ?,?,?
else if qword eq type | pword eq type
dd ?,?
else
dd ?
end if \}
match =current@arg,current@arg
\{ current@arg equ arg
arg equ ..arg
..arg dd ? \}
common
args@proc equ current@arg
forward
restore current@arg
common
end if }
 
macro deflocal@proc name,def,[val]
{ common
match vars, all@vars \{ all@vars equ all@vars, \}
all@vars equ all@vars name
forward
local ..var,..tmp
..var def val
match =?, val \{ ..tmp equ \}
match any =dup (=?), val \{ ..tmp equ \}
match tmp : value, ..tmp : val
\{ tmp: end virtual
initlocal@proc ..var,def value
virtual at tmp\}
common
match first rest, ..var, \{ name equ first \} }
 
macro initlocal@proc name,def
{ virtual at name
def
size@initlocal = $ - name
end virtual
position@initlocal = 0
while size@initlocal > position@initlocal
virtual at name
def
if size@initlocal - position@initlocal < 2
current@initlocal = 1
load byte@initlocal byte from name+position@initlocal
else if size@initlocal - position@initlocal < 4
current@initlocal = 2
load word@initlocal word from name+position@initlocal
else
current@initlocal = 4
load dword@initlocal dword from name+position@initlocal
end if
end virtual
if current@initlocal = 1
mov byte [name+position@initlocal],byte@initlocal
else if current@initlocal = 2
mov word [name+position@initlocal],word@initlocal
else
mov dword [name+position@initlocal],dword@initlocal
end if
position@initlocal = position@initlocal + current@initlocal
end while }
 
macro endp
{ purge ret,locals,endl
finish@proc
purge finish@proc
restore regs@proc
match all,args@proc \{ restore all \}
restore args@proc
match all,all@vars \{ restore all \} }
 
macro local [var]
{ common
locals
forward done@local equ
match varname[count]:vartype, var
\{ match =BYTE, vartype \\{ varname rb count
restore done@local \\}
match =WORD, vartype \\{ varname rw count
restore done@local \\}
match =DWORD, vartype \\{ varname rd count
restore done@local \\}
match =PWORD, vartype \\{ varname rp count
restore done@local \\}
match =QWORD, vartype \\{ varname rq count
restore done@local \\}
match =TBYTE, vartype \\{ varname rt count
restore done@local \\}
match =DQWORD, vartype \\{ label varname dqword
rq count+count
restore done@local \\}
match , done@local \\{ virtual
varname vartype
end virtual
rb count*sizeof.\#vartype
restore done@local \\} \}
match :varname:vartype, done@local:var
\{ match =BYTE, vartype \\{ varname db ?
restore done@local \\}
match =WORD, vartype \\{ varname dw ?
restore done@local \\}
match =DWORD, vartype \\{ varname dd ?
restore done@local \\}
match =PWORD, vartype \\{ varname dp ?
restore done@local \\}
match =QWORD, vartype \\{ varname dq ?
restore done@local \\}
match =TBYTE, vartype \\{ varname dt ?
restore done@local \\}
match =DQWORD, vartype \\{ label varname dqword
dq ?,?
restore done@local \\}
match , done@local \\{ varname vartype
restore done@local \\} \}
match ,done@local
\{ var
restore done@local \}
common
endl }
/programs/develop/ktcc/trunk/libc/public_stdcall.inc
0,0 → 1,7
macro public_stdcall name,size
{
public name
public name#@#size
name:
name#@#size:
}
/programs/develop/ktcc/trunk/libc/.
Property changes:
Added: svn:ignore
+*.a
+script.txt