Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6428 → Rev 6429

/programs/develop/ktcc/trunk/libc/include/conio.h
0,0 → 1,197
/*
 
This is adapded thunk for console.obj sys library
.h is equal to svn:\programs\develop\libraries\console\console_en.txt
 
Adapted for tcc by Siemargl, 2016
 
*/
#ifndef __conio_h
#define __conio_h
 
#define cdecl __attribute__ ((cdecl))
#define stdcall __attribute__ ((stdcall))
 
/*
console.obj exports the following functions
*/
typedef unsigned long dword; /* 32-bit unsigned integer */
typedef unsigned short word; /* 16-bit unsigned integer */
 
extern void stdcall (*con_init)(dword wnd_width, dword wnd_height,
dword scr_width, dword scr_height, const char* title);
/* Console initialization. Must be called only once.
wnd_width, wnd_height - width and height (in units of characters) of the visible
region;
scr_width, scr_height - width and height (in units of characters) of console;
Any of these four parameters can be set to -1 (=0xFFFFFFFF)
to use the library's default values;
title - console window's caption. */
 
extern void stdcall (*con_exit)(int bCloseWindow);
/* You should call this funstion at the end of the program.
If bCloseWindow is zero, the string "[Finished]" will be added to the caption of
the window and the console window will remain on the screen until the user
closes it. */
 
extern void stdcall (*con_set_title)(const char* title);
/* Set new window caption. */
 
extern void stdcall (*con_write_asciiz)(const char* str);
/* Display ASCIIZ-string to the console at the current position, shifting
the current position. */
 
extern void stdcall (*con_write_string)(const char* str, dword length);
/* Similar to con_write_asciiz, but length of the string must be given as a
separate parameter */
 
extern int cdecl (*con_printf)(const char* format, ...);
/* Standard "printf" function from ANSI C. */
 
extern dword stdcall (*con_get_flags)(void);
/* Get output flags. */
 
extern dword stdcall (*con_set_flags)(dword new_flags);
/* Set output flags. This function returns previous values. */
 
/* Flags (bitmask): */
/* text color */
#define CON_COLOR_BLUE 0x01
#define CON_COLOR_GREEN 0x02
#define CON_COLOR_RED 0x04
#define CON_COLOR_BRIGHT 0x08
/* background color */
#define CON_BGR_BLUE 0x10
#define CON_BGR_GREEN 0x20
#define CON_BGR_RED 0x40
#define CON_BGR_BRIGHT 0x80
/* output controls */
#define CON_IGNORE_SPECIALS 0x100
/* if this flag is cleared, function interprets special characters:
10 ('\n') - next line
13 ('\r') - carriage return
8 ('\b') - backspace
9 ('\t') - tab
27 ('\033' = '\x1B') - the beginning of Esc-sequences;
otherwise, these characters will be displayed like ordinary characters. */
/* Supported Esc-sequences:
Esc[<number1>;<number2>;<number3>m - choice of character attributes:
You can specify one, two or three codes in any order;
0 = normal mode (white on black)
1 = bright selection
5 = bright background
7 = inverse mode (black on white)
30 = black characters
31 = red characters
32 = green characters
33 = brown characters
34 = blue characters
35 = purple characters
36 = turqoise characters
37 = white characters
40 = black background
41 = red background
42 = green background
43 = brown background
44 = blue background
45 = purple background
46 = turqoise background
47 = white background
The following sequences appeared in version 5 of library:
Esc[2J - clear screen, move cursor to upper left corner
Esc[<number1>;<number2>H = Esc[<number1>;<number2>f -
move cursor to <number1>,<number2>
Esc[<number>A - move cursor to <number> lines up
Esc[<number>B - move cursor to <number> lines down
Esc[<number>C - move cursor to <number> positions right
Esc[<number>D - move cursor to <number> positions left
*/
/* signal "console closed"; appeared in version 6;
ignored by con_set_flags */
#define CON_WINDOW_CLOSED 0x200
/* The default value for flags = 7. (grey text on black background) */
 
extern int stdcall (*con_get_font_height)(void);
/* Get the height of the font. */
 
extern int stdcall (*con_get_cursor_height)(void);
/* Get the height of the cursor. */
 
extern int stdcall (*con_set_cursor_height)(int new_height);
/* Set the height of the cursor. This function returns previous value.
An attempt to set the value out of the correct interval (from 0 to
font_height-1) is ignored.
Cursor with zero height isn't displayed.
Default value: - 15% from font height. */
 
extern int stdcall (*con_getch)(void);
/* Get one character from the keyboard.
 
For normal characters function returns ASCII-code. For extended
characters (eg, Fx, and arrows), first function call returns 0
and second call returns the extended code (similar to the DOS-function
input). Starting from version 7, after closing the console window,
this function returns 0. */
 
extern word stdcall (*con_getch2)(void);
/* Reads a character from the keyboard. Low byte contains the ASCII-code
(0 for extended characters), high byte - advanced code (like in BIOS
input functions). Starting from version 7, after closing the console
window, this function returns 0. */
 
extern int stdcall (*con_kbhit)(void);
/* Returns 1 if a key was pressed, 0 otherwise. To read pressed keys use
con_getch and con_getch2. Starting from version 6, after closing
the console window, this function returns 1. */
 
extern char* stdcall (*con_gets)(char* str, int n);
/* Reads a string from the keyboard. Reading is interrupted when got
"new line" character, or after reading the (n-1) characters (depending on
what comes first). In the first case the newline is also recorded in the
str. The acquired line is complemented by a null character.
Starting from version 6, the function returns a pointer to the entered
line if reading was successful, and NULL if the console window was closed. */
 
typedef int (stdcall * con_gets2_callback)(int keycode, char** pstr, int* pn,
int* ppos);
 
extern char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n);
/* Con_gets completely analogous, except that when the user
press unrecognized key, it calls the specified callback-procedure
(which may, for example, handle up / down for history and tab to enter
autocompletion). You should pass to the procedure: key code and three pointers
- to the string, to the maximum length and to the current position.
function may change the contents of string and may change the string
itself (for example, to reallocate memory for increase the limit),
maximum length, and position of the line - pointers are passed for it.
Return value: 0 = line wasn't changed 1 = line changed, you should
remove old string and display new, 2 = line changed, it is necessary
to display it; 3 = immediately exit the function.
Starting from version 6, the function returns a pointer to the entered
line with the successful reading, and NULL if the console window was closed. */
 
extern void stdcall (*con_cls)();
/* Clear screen and set cursor at upper left corner. */
 
 
extern void stdcall (*con_get_cursor_pos)(int* px, int* py);
/* Wrote current (x) coordinate of cursor to *px, and (y) to *py. */
 
extern void stdcall (*con_set_cursor_pos)(int x, int y);
/* Set the cursor position to the specified coordinates. If any of the
parameters beyond the relevant range (from 0 to 1 scr_width-
for x, from 0 to 1 for scr_height-y, scr_width scr_height and were asked if
call con_init), then the corresponding coordinate of the cursor does not change.
*/
 
extern int __console_initdll_status;
/* == 1 if dll loaded */
 
extern dword *con_dll_ver;
 
extern int con_init_console_dll(void);
/* load library and link function symbols. returns 1 if error
called automatic in printf, otherwise, see __console_initdll_status
*/
 
#endif
/programs/develop/ktcc/trunk/libc/include/kos32sys1.h
0,0 → 1,723
#ifndef __KOS_32_SYS_H__
#define __KOS_32_SYS_H__
 
// file header taken from newlib
// added many sys functions, compatible with tcc
 
//#include <newlib.h>
//#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned long long uint64_t;
 
#ifdef __cplusplus
extern "C" {
#endif
 
//#ifdef CONFIG_DEBUF
// #define DBG(format,...) printf(format,##__VA_ARGS__)
//#else
// #define DBG(format,...)
//#endif
 
#define TYPE_3_BORDER_WIDTH 5
#define WIN_STATE_MINIMIZED 0x02
#define WIN_STATE_ROLLED 0x04
 
typedef unsigned int color_t;
 
typedef union
{
uint32_t val;
struct
{
short x;
short y;
}xy;
} __attribute__((packed)) pos_t ;
 
typedef union
{
uint32_t val;
struct
{
uint8_t state;
uint8_t code;
uint16_t ctrl_key;
}in;
}__attribute__((packed)) oskey_t ;
 
typedef struct
{
unsigned handle;
unsigned io_code;
void *input;
int inp_size;
void *output;
int out_size;
}ioctl_t;
 
static inline void begin_draw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
 
static inline
void end_draw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
 
static inline
void sys_create_window(int x, int y, int w, int h, const char *name,
color_t workcolor, uint32_t style)
{
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | ((w-1) & 0xFFFF)),
"c"((y << 16) | ((h-1) & 0xFFFF)),
"d"((style << 24) | (workcolor & 0xFFFFFF)),
"D"(name),
"S"(0) : "memory");
};
 
static inline
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(8),
"b"(x_w),
"c"(y_h),
"d"(id),
"S"(color));
};
 
static inline
void draw_line(int xs, int ys, int xe, int ye, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(38), "d"(color),
"b"((xs << 16) | xe),
"c"((ys << 16) | ye));
}
 
static inline
void draw_bar(int x, int y, int w, int h, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(13), "d"(color),
"b"((x << 16) | w),
"c"((y << 16) | h));
}
 
static inline
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
 
static inline
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color)
:"memory");
}
 
static inline
uint32_t get_skin_height(void)
{
uint32_t height;
 
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(height)
:"a"(48),"b"(4));
return height;
};
 
/*
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
color_t workcolor, uint32_t style)
__attribute__ ((alias ("sys_create_window")));
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
__attribute__ ((alias ("draw_line")));
static inline void DrawBar(int x, int y, int w, int h, color_t color)
__attribute__ ((alias ("draw_bar")));
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
__attribute__ ((alias ("draw_bitmap")));
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
*/
 
#define POS_SCREEN 0
#define POS_WINDOW 1
 
static inline
pos_t get_mouse_pos(int origin)
{
pos_t val;
 
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=a"(val)
:"a"(37),"b"(origin));
return val;
}
 
static inline
uint32_t get_mouse_buttons(void)
{
uint32_t val;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(2));
return val;
};
 
static inline
uint32_t get_mouse_wheels(void)
{
uint32_t val;
 
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(val)
:"a"(37),"b"(7));
return val;
};
 
static inline uint32_t load_cursor(void *path, uint32_t flags)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37), "b"(4), "c"(path), "d"(flags));
return val;
}
 
static inline uint32_t set_cursor(uint32_t cursor)
{
uint32_t old;
__asm__ __volatile__(
"int $0x40"
:"=a"(old)
:"a"(37), "b"(5), "c"(cursor));
return old;
};
 
static inline int destroy_cursor(uint32_t cursor)
{
int ret;
__asm__ __volatile__(
"int $0x40"
:"=a"(ret)
:"a"(37), "b"(6), "c"(cursor)
:"memory");
return ret;
};
 
/*
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
 
static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor")));
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
*/
 
static inline
uint32_t wait_for_event(uint32_t time)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(23), "b"(time));
return val;
};
 
static inline uint32_t check_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
 
static inline uint32_t get_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(10));
return val;
};
//static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
 
static inline
uint32_t get_tick_count(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(26),"b"(9));
return val;
};
 
static inline
uint64_t get_ns_count(void)
{
uint64_t val;
__asm__ __volatile__(
"int $0x40"
:"=A"(val)
:"a"(26), "b"(10));
return val;
};
 
static inline
oskey_t get_key(void)
{
oskey_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(2));
return val;
}
 
static inline
uint32_t get_os_button()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(17));
return val>>8;
};
 
static inline uint32_t get_service(char *name)
{
uint32_t retval = 0;
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(68),"b"(16),"c"(name)
:"memory");
 
return retval;
};
 
static inline int call_service(ioctl_t *io)
{
int retval;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(68),"b"(17),"c"(io)
:"memory","cc");
 
return retval;
};
 
 
static inline void yield(void)
{
__asm__ __volatile__(
"int $0x40"
::"a"(68), "b"(1));
};
 
static inline void delay(uint32_t time)
{
__asm__ __volatile__(
"int $0x40"
::"a"(5), "b"(time)
:"memory");
};
 
static inline
void *user_alloc(size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(12),"c"(size));
return val;
}
 
static inline
int user_free(void *mem)
{
int val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(13),"c"(mem));
return val;
}
 
static inline
void* user_realloc(void *mem, size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(20),"c"(size),"d"(mem)
:"memory");
 
return val;
};
 
static inline
int *user_unmap(void *base, size_t offset, size_t size)
{
int *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
return val;
};
 
/*
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
*/
 
typedef union
{
struct
{
void *data;
size_t size;
} x;
unsigned long long raw;
}ufile_t;
 
static inline ufile_t load_file(const char *path)
{
ufile_t uf;
 
__asm__ __volatile__ (
"int $0x40"
:"=A"(uf.raw)
:"a" (68), "b"(27),"c"(path));
 
return uf;
};
//static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
 
static inline int GetScreenSize()
{
int retval;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(61), "b"(1));
return retval;
}
 
 
static inline void get_proc_info(char *info)
{
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1)
:"memory");
};
//static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
 
 
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
 
int srcx;
int srcy;
int srcw;
int srch;
 
void *bitmap;
int stride;
};
 
static inline void Blit(void *bitmap, int dst_x, int dst_y,
int src_x, int src_y, int w, int h,
int src_w, int src_h, int stride)
{
volatile struct blit_call bc;
 
bc.dstx = dst_x;
bc.dsty = dst_y;
bc.w = w;
bc.h = h;
bc.srcx = src_x;
bc.srcy = src_y;
bc.srcw = src_w;
bc.srch = src_h;
bc.stride = stride;
bc.bitmap = bitmap;
 
__asm__ __volatile__(
"int $0x40"
::"a"(73),"b"(0),"c"(&bc.dstx));
};
 
int create_thread(int (*proc)(void *param), void *param, int stack_size);
 
void* load_library(const char *name);
 
void* get_proc_address(void *handle, const char *proc_name);
 
void enumerate_libraries(int (*callback)(void *handle, const char* name,
uint32_t base, uint32_t size, void *user_data),
void *user_data);
 
 
// May be next section need to be added in newlibc
 
enum KOLIBRI_GUI_EVENTS {
KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */
KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */
KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */
KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */
KOLIBRI_EVENT_DESKTOP = 5, /* Desktop redraw finished */
KOLIBRI_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */
KOLIBRI_EVENT_IPC = 7, /* Interprocess communication notify */
KOLIBRI_EVENT_NETWORK = 8, /* Network event */
KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */
KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
};
 
 
// copied from /programs/system/shell/system/kolibri.c
// fn's returned -1 as syserror, 1 as error, 0 as OK
static inline
int kol_clip_num()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(0));
return val;
}
 
static inline
char* kol_clip_get(int n)
// returned buffer must be freed by user_free()
{
register char* val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(1), "c"(n));
return val;
}
 
static inline
int kol_clip_set(int n, char buffer[])
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(2), "c"(n), "d"(buffer));
return val;
}
 
static inline
int kol_clip_pop()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(3));
return val;
}
 
static inline
int kol_clip_unlock()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(4));
return val;
}
 
struct kolibri_system_colors {
color_t frame_area;
color_t grab_bar;
color_t grab_bar_button;
color_t grab_button_text;
color_t grab_text;
color_t work_area;
color_t work_button;
color_t work_button_text;
color_t work_text;
color_t work_graph;
};
 
static inline void get_system_colors(struct kolibri_system_colors *color_table)
{
__asm__ volatile ("int $0x40"
:
:"a"(48),"b"(3),"c"(color_table),"d"(40)
);
 
/* color_table should point to the system color table */
}
 
static inline void debug_board_write_byte(const char ch){
__asm__ __volatile__(
"int $0x40"
:
:"a"(63), "b"(1), "c"(ch));
}
 
 
static inline void draw_number_sys(int32_t number, int x, int y, int len, color_t color){
register uint32_t fmt;
fmt = len << 16 | 0x80000000; // no leading zeros + width
// fmt = len << 16 | 0x00000000; // leading zeros + width
__asm__ __volatile__(
"int $0x40"
:
:"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
}
 
static inline
uint32_t get_mouse_eventstate(void)
{
uint32_t val;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(3));
return val;
};
 
static inline
uint32_t set_event_mask(uint32_t mask)
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(40), "b"(mask));
return val;
}
 
typedef void (*thread_proc)(void*);
 
static inline
int start_thread(thread_proc proc, char* stack_top)
{
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(51), "b"(1), "c"(proc), "d"(stack_top));
return val;
}
 
static inline
void kos_exit()
{
asm volatile ("int $0x40"::"a"(-1));
}
 
static inline void focus_window(int slot){
asm volatile ("int $0x40"::"a"(18), "b"(3), "c"(slot));
}
 
static inline int get_thread_slot(int tid){
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(18), "b"(21), "c"(tid));
return val;
}
 
static inline void set_current_folder(char* dir){
asm volatile ("int $0x40"::"a"(30), "b"(1), "c"(dir));
}
 
static inline int get_current_folder(char* buf, int bufsize){
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize));
return val;
}
 
/*
static inline char *getcwd(char *buf, size_t size)
{
int rc = get_current_folder(buf, size);
if (rc > size)
{
errno = ERANGE;
return 0;
}
else
return buf;
}
*/
// end section
 
 
 
//added nonstatic inline because incomfortabre stepping in in debugger
void __attribute__ ((noinline)) debug_board_write_str(const char* str);
void __attribute__ ((noinline)) debug_board_printf(const char *format,...);
 
/* copy body to only one project file
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
while(*str)
debug_board_write_byte(*str++);
}
 
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
{
va_list ap;
char log_board[300];
 
va_start (ap, format);
vsnprintf(log_board, sizeof log_board, format, ap);
va_end(ap);
debug_board_write_str(log_board);
}
*/
 
#ifdef __cplusplus
}
#endif
 
 
#endif
 
 
 
 
 
/programs/develop/ktcc/trunk/libc/include/stdio.h
63,6 → 63,9
 
#define getc(a) fgetc(a)
char * fgets ( char * str, int num, FILE * stream );
int putchar ( int character );
int putchar (int ch);
int getchar (void);
int puts (const char * str);
char * gets (char * str);
 
#endif
/programs/develop/ktcc/trunk/libc/include/tcclib.h
0,0 → 1,80
/* Simple libc header for TCC
*
* Add any function you want from the libc there. This file is here
* only for your convenience so that you do not need to put the whole
* glibc include files on your floppy disk
*/
#ifndef _TCCLIB_H
#define _TCCLIB_H
 
#include <stddef.h>
#include <stdarg.h>
 
/* stdlib.h */
void *calloc(size_t nmemb, size_t size);
void *malloc(size_t size);
void free(void *ptr);
void *realloc(void *ptr, size_t size);
int atoi(const char *nptr);
long int strtol(const char *nptr, char **endptr, int base);
unsigned long int strtoul(const char *nptr, char **endptr, int base);
void exit(int);
 
/* stdio.h */
typedef struct __FILE FILE;
#define EOF (-1)
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
int fclose(FILE *stream);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int getc(FILE *stream);
int getchar(void);
char *gets(char *s);
int ungetc(int c, FILE *stream);
int fflush(FILE *stream);
int putchar (int c);
 
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
int asprintf(char **strp, const char *format, ...);
int dprintf(int fd, const char *format, ...);
int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int vasprintf(char **strp, const char *format, va_list ap);
int vdprintf(int fd, const char *format, va_list ap);
 
void perror(const char *s);
 
/* string.h */
char *strcat(char *dest, const char *src);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strcpy(char *dest, const char *src);
void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
char *strdup(const char *s);
size_t strlen(const char *s);
 
/* dlfcn.h */
#define RTLD_LAZY 0x001
#define RTLD_NOW 0x002
#define RTLD_GLOBAL 0x100
 
void *dlopen(const char *filename, int flag);
const char *dlerror(void);
void *dlsym(void *handle, char *symbol);
int dlclose(void *handle);
 
#endif /* _TCCLIB_H */
/programs/develop/ktcc/trunk/libc/stdio/conio.c
0,0 → 1,92
#include <conio.h>
#include <kolibrisys.h>
 
char* con_caption = "Console app";
extern int __argc;
extern char** __argv;
extern char* __path;
dword *con_dll_ver;
int __console_initdll_status;
 
char* con_dllname="/sys/lib/console.obj";
 
struct import{
char *name;
void *data;
};
 
void stdcall (*con_init)(dword wnd_width, dword wnd_height,
dword scr_width, dword scr_height, const char* title);
void stdcall (*con_exit)(int bCloseWindow);
void stdcall (*con_set_title)(const char* title);
void stdcall (*con_write_asciiz)(const char* str);
void stdcall (*con_write_string)(const char* str, dword length);
int cdecl (*con_printf)(const char* format, ...);
dword stdcall (*con_get_flags)(void);
dword stdcall (*con_set_flags)(dword new_flags);
int stdcall (*con_get_font_height)(void);
int stdcall (*con_get_cursor_height)(void);
int stdcall (*con_set_cursor_height)(int new_height);
int stdcall (*con_getch)(void);
word stdcall (*con_getch2)(void);
int stdcall (*con_kbhit)(void);
char* stdcall (*con_gets)(char* str, int n);
char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n);
void stdcall (*con_cls)();
void stdcall (*con_get_cursor_pos)(int* px, int* py);
void stdcall (*con_set_cursor_pos)(int x, int y);
 
 
// don't change order in this! linked by index
char* con_imports[] = {
"START", "version", "con_init", "con_write_asciiz", "con_write_string",
"con_printf", "con_exit", "con_get_flags", "con_set_flags", "con_kbhit",
"con_getch", "con_getch2", "con_gets", "con_gets2", "con_get_font_height",
"con_get_cursor_height", "con_set_cursor_height", "con_cls",
"con_get_cursor_pos", "con_set_cursor_pos",
(char*)0
};
 
void con_lib_link(struct import *exp, char** imports){
 
con_dll_ver = _ksys_cofflib_getproc(exp, imports[1]);
con_init = _ksys_cofflib_getproc(exp, imports[2]);
con_write_asciiz = _ksys_cofflib_getproc(exp, imports[3]);
con_write_string = _ksys_cofflib_getproc(exp, imports[4]);
con_printf = _ksys_cofflib_getproc(exp, imports[5]);
con_exit = _ksys_cofflib_getproc(exp, imports[6]);
con_get_flags = _ksys_cofflib_getproc(exp, imports[7]);
con_set_flags = _ksys_cofflib_getproc(exp, imports[8]);
con_kbhit = _ksys_cofflib_getproc(exp, imports[9]);
con_getch = _ksys_cofflib_getproc(exp, imports[10]);
con_getch2 = _ksys_cofflib_getproc(exp, imports[11]);
con_gets = _ksys_cofflib_getproc(exp, imports[12]);
con_gets2 = _ksys_cofflib_getproc(exp, imports[13]);
con_get_font_height = _ksys_cofflib_getproc(exp, imports[14]);
con_get_cursor_height=_ksys_cofflib_getproc(exp, imports[15]);
con_set_cursor_height=_ksys_cofflib_getproc(exp, imports[16]);
con_cls = _ksys_cofflib_getproc(exp, imports[17]);
con_get_cursor_pos = _ksys_cofflib_getproc(exp, imports[18]);
con_set_cursor_pos = _ksys_cofflib_getproc(exp, imports[19]);
}
 
 
int con_init_console_dll(void)
{
struct import * hDll;
 
if (__console_initdll_status == 1) return 0;
if((hDll = (struct import *)_ksys_cofflib_load(con_dllname)) == 0){
debug_out_str("can't load lib\n");
return 1;
}
con_lib_link(hDll, con_imports);
 
con_init(-1, -1, -1, -1, con_caption); //__argv[0] && __path dont work
 
__console_initdll_status = 1;
 
return(0);
}
 
/programs/develop/ktcc/trunk/libc/stdio/getchar.c
0,0 → 1,6
#include<conio.h>
 
int getchar ( void )
{
return con_getch();
}
/programs/develop/ktcc/trunk/libc/stdio/gets.c
0,0 → 1,8
#include <conio.h>
 
char * gets ( char * str )
{
con_init_console_dll();
 
return con_gets(str, 80); // small, to reduce overflow risk
}
/programs/develop/ktcc/trunk/libc/stdio/printf.c
1,78 → 1,23
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <kolibrisys.h>
#include <conio.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 app";
extern int __argc;
extern char** __argv;
extern char* __path;
 
 
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); //__argv[0] && __path dont work
return(0);
}
 
int printf(const char *format,...)
{
int i = 0;
int printed_simbols;
int printed_simbols = 0;
va_list arg;
char simbol[]={"%s"};
char *s;
 
va_start(arg,format);
 
if (console_init_status==0)
{
i=init_console();
console_init_status=1;
}
i=con_init_console_dll();
 
if (i==0)
{
s=malloc(4096);
printed_simbols=format_print(s,4096,format,arg);
con_printf(simbol,s);
con_write_string(s, printed_simbols);
free(s);
}
return(printed_simbols);
/programs/develop/ktcc/trunk/libc/stdio/putchar.c
1,7 → 1,14
#include <stdio.h>
#include <conio.h>
 
int putchar ( int ch )
{
printf("%c", ch);
char s[2];
 
con_init_console_dll();
s[0] = (char)ch;
s[1] = '\0';
 
con_write_asciiz(s);
return ch;
}
/programs/develop/ktcc/trunk/libc/stdio/puts.c
0,0 → 1,11
#include <conio.h>
 
int puts ( const char * str )
{
con_init_console_dll();
con_write_asciiz(str);
con_write_asciiz("\n");
 
return 1;
}