Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 9866 → Rev 9865

/programs/develop/ktcc/trunk/lib/boxlib/boxlib.asm
0,0 → 1,230
; writed by maxcodehack
; adaptation of clayer for ktcc
format elf
use32 ; Tell compiler to use 32 bit instructions
; ELF section
section '.text' executable
 
 
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
 
 
public init_boxlib as 'kolibri_boxlib_init'
 
proc init_boxlib
local retval dd ?
mov [retval], eax
pusha
mcall 68, 11
test eax, eax
jnz @f
mov [retval], -1
jmp exit_init_boxlib
@@:
stdcall dll.Load, @IMPORT
test eax, eax
jz exit_init_boxlib
mov [retval], -1
exit_init_boxlib:
popa
mov eax, [retval]
ret
endp
 
;; Wrapper to handle edit_box_key function for editboxes.
;; Call this baby from C (refer kolibri_editbox.h for details)
public editbox_key_thunk as 'edit_box_key' ; renamed due to ambiguity
;; replaced by siemargl as inline ASM in C wrapper
editbox_key_thunk:
mov eax, [esp+8]
mov [oldebp], ebp ;Save ebp because GCC is crazy for it otherwise.
pop ebp ;Save return address in ebp. Stack top is param now.
;mov eax, dword [press_key]
call [edit_box_key] ; The pointer we passed should be on the stack already.
push ebp ;push the return address back to stack
mov ebp, [oldebp]
ret
oldebp dd ?
section '.data' writeable
 
@IMPORT:
library lib_boxlib, 'box_lib.obj'
 
import lib_boxlib, \
edit_box_draw, 'edit_box_draw' , \
edit_box_key, 'edit_box_key' , \
edit_box_mouse, 'edit_box_mouse', \
edit_box_set_text, 'edit_box_set_text' , \
init_checkbox2, 'init_checkbox2' , \
check_box_draw2, 'check_box_draw2' , \
check_box_mouse2, 'check_box_mouse2' , \
option_box_draw, 'option_box_draw' , \
option_box_mouse, 'option_box_mouse' , \
scrollbar_v_draw, 'scrollbar_v_draw' , \
scrollbar_v_mouse, 'scrollbar_v_mouse' , \
scrollbar_h_draw, 'scrollbar_h_draw' , \
scrollbar_h_mouse, 'scrollbar_h_mouse' , \
dynamic_button_draw, 'dbutton_draw' , \
dynamic_button_mouse, 'dbutton_mouse' , \
menu_bar_draw, 'menu_bar_draw' , \
menu_bar_mouse, 'menu_bar_mouse' , \
menu_bar_activate, 'menu_bar_activate' , \
fb_draw_panel, 'FileBrowser_draw' , \
fb_mouse, 'FileBrowser_mouse' , \
fb_key, 'FileBrowser_key' , \
tl_data_init, 'tl_data_init' , \
tl_data_clear, 'tl_data_clear' , \
tl_info_clear, 'tl_info_clear' , \
tl_key, 'tl_key' , \
tl_mouse, 'tl_mouse' , \
tl_draw, 'tl_draw' , \
tl_info_undo, 'tl_info_undo' , \
tl_info_redo, 'tl_info_redo' , \
tl_node_add, 'tl_node_add' , \
tl_node_set_data, 'tl_node_set_data' , \
tl_node_get_data, 'tl_node_get_data' , \
tl_node_delete, 'tl_node_delete' , \
tl_cur_beg, 'tl_cur_beg' , \
tl_cur_next, 'tl_cur_next' , \
tl_cur_perv, 'tl_cur_perv' , \
tl_node_close_open, 'tl_node_close_open' , \
tl_node_lev_inc, 'tl_node_lev_inc' , \
tl_node_lev_dec, 'tl_node_lev_dec' , \
tl_node_move_up, 'tl_node_move_up' , \
tl_node_move_down, 'tl_node_move_down' , \
tl_node_poi_get_info, 'tl_node_poi_get_info' , \
tl_node_poi_get_next_info, 'tl_node_poi_get_next_info' , \
tl_node_poi_get_data, 'tl_node_poi_get_data' , \
tl_save_mem, 'tl_save_mem' , \
tl_load_mem, 'tl_load_mem' , \
tl_get_mem_size, 'tl_get_mem_size' , \
path_show_prepare, 'PathShow_prepare' , \
path_show_draw, 'PathShow_draw' , \
ted_but_sumb_upper, 'ted_but_sumb_upper' , \
ted_but_sumb_lover, 'ted_but_sumb_lover' , \
ted_but_convert_by_table, 'ted_but_convert_by_table' , \
ted_can_save, 'ted_can_save' , \
ted_clear, 'ted_clear' , \
ted_delete, 'ted_delete' , \
ted_draw, 'ted_draw' , \
ted_init, 'ted_init' , \
ted_init_scroll_bars, 'ted_init_scroll_bars' , \
ted_init_syntax_file, 'ted_init_syntax_file' , \
ted_is_select, 'ted_is_select' , \
ted_key, 'ted_key' , \
ted_mouse, 'ted_mouse' , \
ted_open_file, 'ted_open_file' , \
ted_save_file, 'ted_save_file' , \
ted_text_add, 'ted_text_add' , \
ted_but_select_word, 'ted_but_select_word' , \
ted_but_cut, 'ted_but_cut' , \
ted_but_copy, 'ted_but_copy' , \
ted_but_paste, 'ted_but_paste' , \
ted_but_undo, 'ted_but_undo' , \
ted_but_redo, 'ted_but_redo' , \
ted_but_reverse, 'ted_but_reverse' , \
ted_but_find, 'ted_but_find' , \
ted_but_replace, 'ted_but_replace' , \
ted_text_colored, 'ted_text_colored' , \
ted_go_to_position, 'ted_go_to_position' , \
frame_draw, 'frame_draw' , \
progressbar_draw,'progressbar_draw' , \
progressbar_progress, 'progressbar_progress'
 
 
public edit_box_draw as 'edit_box_draw'
;public edit_box_key as 'edit_box_key'
 
public edit_box_mouse as 'edit_box_mouse'
public edit_box_set_text as 'edit_box_set_text'
 
public check_box_draw2 as 'check_box_draw2'
public check_box_mouse2 as 'check_box_mouse2'
public init_checkbox2 as 'init_checkbox2'
 
public progressbar_draw as 'progressbar_draw'
public progressbar_progress as 'progressbar_progress'
 
public frame_draw as 'frame_draw'
 
public scrollbar_v_draw as 'scrollbar_v_draw'
public scrollbar_v_mouse as 'scrollbar_v_mouse'
public scrollbar_h_draw as 'scrollbar_h_draw'
public scrollbar_h_mouse as 'scrollbar_h_mouse'
 
public option_box_draw as 'option_box_draw'
public option_box_mouse as 'option_box_mouse'
 
public menu_bar_draw as 'menu_bar_draw'
public menu_bar_mouse as 'menu_bar_mouse'
public menu_bar_activate as 'menu_bar_activate'
 
public dynamic_button_draw as 'dynamic_button_draw'
public dynamic_button_mouse as 'dynamic_button_mouse'
 
public path_show_prepare as 'path_show_prepare'
public path_show_draw as 'path_show_draw'
 
public fb_draw_panel as 'filebrowse_draw'
public fb_mouse as 'filebrowse_mouse'
public fb_key as 'filebrowse_key'
 
public ted_but_sumb_upper as 'ted_but_sumb_upper'
public ted_but_sumb_lover as 'ted_but_sumb_lover'
public ted_but_convert_by_table as 'ted_but_convert_by_table'
public ted_can_save as 'ted_can_save'
public ted_clear as 'ted_clear'
public ted_delete as 'ted_delete'
public ted_draw as 'ted_draw'
public ted_init as 'ted_init'
public ted_init_scroll_bars as 'ted_init_scroll_bars'
public ted_init_syntax_file as 'ted_init_syntax_file'
public ted_is_select as 'ted_is_select'
public ted_key as 'ted_key_asm'
public ted_mouse as 'ted_mouse'
public ted_open_file as 'ted_open_file_asm'
public ted_save_file as 'ted_save_file_asm'
public ted_text_add as '_ted_text_add'
public ted_but_select_word as 'ted_but_select_word'
public ted_but_cut as 'ted_but_cut'
public ted_but_copy as 'ted_but_copy'
public ted_but_paste as 'ted_but_paste'
public ted_but_undo as 'ted_but_undo'
public ted_but_redo as 'ted_but_redo'
public ted_but_reverse as 'ted_but_reverse'
public ted_but_find as 'ted_but_find'
public ted_but_replace as 'ted_but_replace'
public ted_text_colored as 'ted_text_colored_asm'
public ted_go_to_position as 'ted_go_to_position'
 
public tl_data_init as 'tl_data_init'
public tl_data_clear as 'tl_data_clear'
public tl_info_clear as 'tl_info_clear'
public tl_key as 'tl_key_asm'
public tl_mouse as 'tl_mouse'
public tl_draw as 'tl_draw'
public tl_info_undo as 'tl_info_undo'
public tl_info_redo as 'tl_info_redo'
public tl_node_add as 'tl_node_add'
public tl_node_set_data as 'tl_node_set_data'
public tl_node_get_data as 'tl_node_get_data'
public tl_node_delete as 'tl_node_delete'
public tl_cur_beg as 'tl_cur_beg'
public tl_cur_next as 'tl_cur_next'
public tl_cur_perv as 'tl_cur_perv'
public tl_node_close_open as 'tl_node_close_open'
public tl_node_lev_inc as 'tl_node_lev_inc'
public tl_node_lev_dec as 'tl_node_lev_dec'
public tl_node_move_up as 'tl_node_move_up'
public tl_node_move_down as 'tl_node_move_down'
public tl_node_poi_get_info as 'tl_node_poi_get_info'
public tl_node_poi_get_next_info as 'tl_node_poi_get_next_info'
public tl_node_poi_get_data as 'tl_node_poi_get_data'
public tl_save_mem as 'tl_save_mem_asm'
public tl_load_mem as 'tl_load_mem_asm'
public tl_get_mem_size as 'tl_get_mem_size_asm'
/programs/develop/ktcc/trunk/lib/boxlib/Makefile
0,0 → 1,10
all:
fasm boxlib.asm
ar -crs libbox.a boxlib.o
 
clean:
rm -f *.a
rm -f *.o
 
install:
mv libbox.a ../../bin/lib
/programs/develop/ktcc/trunk/lib/buf2d/Makefile
0,0 → 1,10
all:
fasm buf2d.asm buf2d.o
ar -csr libbuf2d.a buf2d.o
 
clean:
rm -f *.a
rm -f *.o
 
install:
mv *.a ../../bin/lib
/programs/develop/ktcc/trunk/lib/buf2d/buf2d.asm
0,0 → 1,90
format elf
use32 ; Tell compiler to use 32 bit instructions
 
section '.text' executable
 
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
;public lib_init as 'kolibri_buf2d_init'
;;; Returns 0 on success. -1 on failure.
public init_buf2d as 'kolibri_buf2d_init'
 
proc init_buf2d
pusha
mcall 68,11
stdcall dll.Load, @IMPORT
popa
ret
endp
 
section '.data' writeable
 
@IMPORT:
library lib_buf2d, 'buf2d.obj'
 
import lib_buf2d, \
libbuf2d_init, 'lib_init' , \
buf2d_create, 'buf2d_create' , \
buf2d_clear, 'buf2d_clear' , \
buf2d_draw, 'buf2d_draw' , \
buf2d_delete, 'buf2d_delete', \
buf2d_rotate, 'buf2d_rotate', \
buf2d_resize, 'buf2d_resize', \
buf2d_line, 'buf2d_line', \
buf2d_line_sm, 'buf2d_line_sm', \
buf2d_rect_by_size, 'buf2d_rect_by_size', \
buf2d_filled_rect_by_size, 'buf2d_filled_rect_by_size', \
buf2d_circle, 'buf2d_circle', \
buf2d_img_hdiv2, 'buf2d_img_hdiv2', \
buf2d_img_wdiv2, 'buf2d_img_wdiv2', \
buf2d_conv_24_to_8, 'buf2d_conv_24_to_8', \
buf2d_conv_24_to_32, 'buf2d_conv_24_to_32', \
buf2d_bit_blt, 'buf2d_bit_blt', \
buf2d_bit_blt_transp, 'buf2d_bit_blt_transp', \
buf2d_bit_blt_alpha, 'buf2d_bit_blt_alpha', \
buf2d_curve_bezier, 'buf2d_curve_bezier', \
buf2d_convert_text_matrix, 'buf2d_convert_text_matrix', \
buf2d_draw_text, 'buf2d_draw_text', \
buf2d_crop_color, 'buf2d_crop_color', \
buf2d_offset_h, 'buf2d_offset_h', \
buf2d_flood_fill, 'buf2d_flood_fill', \
buf2d_set_pixel, 'buf2d_set_pixel', \
buf2d_get_pixel, 'buf2d_get_pixel', \
buf2d_flip_h, 'buf2d_flip_h', \
buf2d_flip_v, 'buf2d_flip_v', \
buf2d_filter_dither, 'buf2d_filter_dither'
 
public libbuf2d_init as 'libimg_init'
public buf2d_create as 'buf2d_create_asm'
public buf2d_clear as 'buf2d_clear'
public buf2d_draw as 'buf2d_draw'
public buf2d_delete as 'buf2d_delete'
public buf2d_rotate as 'buf2d_rotate'
public buf2d_resize as 'buf2d_resize'
public buf2d_line as 'buf2d_line'
public buf2d_line_sm as 'buf2d_line_sm'
public buf2d_rect_by_size as 'buf2d_rect_by_size'
public buf2d_filled_rect_by_size as 'buf2d_filled_rect_by_size'
public buf2d_circle as 'buf2d_circle'
public buf2d_img_hdiv2 as 'buf2d_img_hdiv2'
public buf2d_img_wdiv2 as 'buf2d_img_wdiv2'
public buf2d_conv_24_to_8 as 'buf2d_conv_24_to_8'
public buf2d_conv_24_to_32 as 'buf2d_conv_24_to_32'
public buf2d_bit_blt as 'buf2d_bit_blt'
public buf2d_bit_blt_transp as 'buf2d_bit_blt_transp'
public buf2d_bit_blt_alpha as 'buf2d_bit_blt_alpha'
public buf2d_curve_bezier as 'buf2d_curve_bezier_asm'
public buf2d_convert_text_matrix as 'buf2d_convert_text_matrix'
public buf2d_draw_text as 'buf2d_draw_text'
public buf2d_crop_color as 'buf2d_crop_color'
public buf2d_offset_h as 'buf2d_offset_h'
public buf2d_flood_fill as 'buf2d_flood_fill'
public buf2d_set_pixel as 'buf2d_set_pixel'
public buf2d_get_pixel as 'buf2d_get_pixel'
public buf2d_flip_h as 'buf2d_flip_h'
public buf2d_flip_v as 'buf2d_flip_v'
public buf2d_filter_dither as 'buf2d_filter_dither'
/programs/develop/ktcc/trunk/lib/http/free.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ http_free
fun_str equ 'free'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/http/get.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ http_get
fun_str equ 'get'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/http/head.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ http_head
fun_str equ 'head'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/http/post.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ http_post
fun_str equ 'post'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/http/receive.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ http_receive
fun_str equ 'receive'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/http/send.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ http_send
fun_str equ 'send'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/http/Makefile
0,0 → 1,11
FASM = fasm
 
OBJS = get.o head.o __lib__.o post.o receive.o send.o free.o
 
%.o : %.asm
$(FASM) $<
 
all: $(OBJS)
ar -rsc libhttp.a *.o
mv -f libhttp.a ../../bin/lib
rm -f *.o
/programs/develop/ktcc/trunk/lib/http/__lib__.asm
0,0 → 1,9
format ELF
 
include '__lib__.inc'
 
section '.text'
 
public lib_name
 
lib_name db 0x55, 0xAA, lib_name_str, 0
/programs/develop/ktcc/trunk/lib/http/__lib__.inc
0,0 → 1,2
lib_name equ @http.obj
lib_name_str equ '/sys/lib/http.obj'
/programs/develop/ktcc/trunk/lib/inputbox/InputBox.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ InputBox
fun_str equ 'InputBox'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/inputbox/__lib__.asm
0,0 → 1,9
format ELF
 
include '__lib__.inc'
 
section '.text'
 
public lib_name
 
lib_name db 0x55, 0xAA, lib_name_str, 0
/programs/develop/ktcc/trunk/lib/inputbox/__lib__.inc
0,0 → 1,2
lib_name equ @inputbox.obj
lib_name_str equ '/sys/lib/inputbox.obj'
/programs/develop/ktcc/trunk/lib/inputbox/make.bat
0,0 → 1,5
fasm __lib__.asm
fasm InputBox.asm
kos32-ar -ru libinputbox.a *.o
del *.o
pause
/programs/develop/ktcc/trunk/lib/libimg/Makefile
0,0 → 1,9
all:
fasm loadlibimg.asm
ar -csr libimg.a loadlibimg.o
 
install:
mv libimg.a ../../bin/lib/libimg.a
 
clean:
rm -f *.o *.a
/programs/develop/ktcc/trunk/lib/libimg/loadlibimg.asm
0,0 → 1,88
format elf
use32 ; Tell compiler to use 32 bit instructions
 
; ELF section
section '.text' executable
 
 
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
 
public init_libimg as 'kolibri_libimg_init'
;;; Returns 0 on success. -1 on failure.
 
proc init_libimg
local retval dd ?
mov [retval], eax
pusha
mcall 68, 11
test eax, eax
jnz @f
mov [retval], -1
jmp exit_init_libimg
@@:
stdcall dll.Load, @IMPORT
test eax, eax
jz exit_init_libimg
mov [retval], -1
exit_init_libimg:
popa
mov eax, [retval]
ret
endp
 
; ELF section
section '.data' writeable
 
@IMPORT:
library lib_libimg, 'libimg.obj'
 
import lib_libimg, \
libimg_init, 'lib_init' , \
img_is_img, 'img_is_img' , \
img_info, 'img_info' , \
img_from_file, 'img_from_file', \
img_to_file, 'img_to_file', \
img_from_rgb, 'img_from_rgb', \
img_to_rgb, 'img_to_rgb', \
img_to_rgb2, 'img_to_rgb2', \
img_decode, 'img_decode', \
img_encode, 'img_encode', \
img_create, 'img_create', \
img_destroy, 'img_destroy', \
img_destroy_layer, 'img_destroy_layer', \
img_count, 'img_count', \
img_lock_bits, 'img_lock_bits', \
img_unlock_bits, 'img_unlock_bits', \
img_flip, 'img_flip', \
img_flip_layer, 'img_flip_layer', \
img_rotate, 'img_rotate', \
img_rotate_layer, 'img_rotate_layer', \
img_draw, 'img_draw', \
img_blend, 'img_blend', \
img_convert, 'img_convert', \
img_resize_data, 'img_resize_data', \
img_scale, 'img_scale'
public libimg_init as 'libimg_init'
public img_to_rgb as 'img_to_rgb'
public img_to_rgb2 as 'img_to_rgb2'
public img_decode as 'img_decode'
public img_encode as 'img_encode'
public img_create as 'img_create'
public img_destroy as 'img_destroy'
public img_destroy_layer as 'img_destroy_layer'
public img_count as 'img_count'
public img_flip as 'img_flip'
public img_flip_layer as 'img_flip_layer'
public img_rotate as 'img_rotate'
public img_rotate_layer as 'img_rotate_layer'
public img_draw as 'img_draw'
public img_blend as 'img_blend'
public img_convert as 'img_convert'
public img_resize_data as 'img_resize_data'
public img_scale as 'img_scale'
/programs/develop/ktcc/trunk/lib/libnetwork/Makefile
0,0 → 1,7
all:
fasm network.asm
ar -csr libnetwork.a network.o
clean:
rm -f *.o *.a
install:
cp libnetwork.a ../../bin/lib
/programs/develop/ktcc/trunk/lib/libnetwork/network.asm
0,0 → 1,50
format elf
use32 ; Tell compiler to use 32 bit instructions
; ELF section
section '.text' executable
 
 
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
 
 
public lib_init as 'networklib_init'
 
 
proc lib_init
local retval dd ?
mov [retval], eax
pusha
mcall 68, 11
test eax, eax
jnz @f
mov [retval], -1
jmp exit_init_networklib
@@:
stdcall dll.Load, @IMPORT
test eax, eax
jz exit_init_networklib
mov [retval], -1
exit_init_networklib:
popa
mov eax, [retval]
ret
endp
 
section '.data' writeable
@IMPORT:
library networklib, 'network.obj'
 
import networklib, \
inet_addr, 'inet_addr', \
inet_ntoa, 'inet_ntoa', \
getaddrinfo, 'getaddrinfo', \
freeaddrinfo, 'freeaddrinfo'
 
public inet_addr as 'inet_addr'
public inet_ntoa as 'inet_ntoa'
public getaddrinfo as 'getaddrinfo'
public freeaddrinfo as 'freeaddrinfo'
/programs/develop/ktcc/trunk/lib/librasterworks/charsFit.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ charsFit
fun_str equ 'charsFit'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/librasterworks/cntUTF-8.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ countUTF8Z
fun_str equ 'cntUTF-8'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/librasterworks/drawText.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ drawText
fun_str equ 'drawText'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/librasterworks/make.bat
0,0 → 1,7
fasm __lib__.asm
fasm mb_create.asm
fasm mb_reinit.asm
fasm mb_setfunctions.asm
kos32-ar -ru libmsgbox.a *.o
del *.o
pause
/programs/develop/ktcc/trunk/lib/librasterworks/strWidth.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ strWidth
fun_str equ 'strWidth'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/librasterworks/__lib__.asm
0,0 → 1,9
format ELF
 
include '__lib__.inc'
 
section '.text'
 
public lib_name
 
lib_name db 0x55, 0xAA, lib_name_str, 0
/programs/develop/ktcc/trunk/lib/librasterworks/__lib__.inc
0,0 → 1,2
lib_name equ @RASTERWORKS.OBJ
lib_name_str equ '/sys/lib/RASTERWORKS.OBJ'
/programs/develop/ktcc/trunk/lib/librasterworks/makefile
0,0 → 1,9
all:
fasm __lib__.asm
fasm charsFit.asm
fasm cntUTF-8.asm
fasm drawText.asm
fasm strWidth.asm
ar -crs librasterworks.a *.o
clean:
rm -f *.o
/programs/develop/ktcc/trunk/lib/msgbox/mb_create.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ msgbox_create
fun_str equ 'mb_create'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/msgbox/mb_reinit.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ msgbox_reinit
fun_str equ 'mb_reinit'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/msgbox/mb_setfunctions.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ msgbox_setfunctions
fun_str equ 'mb_setfunctions'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/msgbox/__lib__.asm
0,0 → 1,9
format ELF
 
include '__lib__.inc'
 
section '.text'
 
public lib_name
 
lib_name db 0x55, 0xAA, lib_name_str, 0
/programs/develop/ktcc/trunk/lib/msgbox/__lib__.inc
0,0 → 1,2
lib_name equ @msgbox.obj
lib_name_str equ '/sys/lib/msgbox.obj'
/programs/develop/ktcc/trunk/lib/msgbox/make.bat
0,0 → 1,7
fasm __lib__.asm
fasm mb_create.asm
fasm mb_reinit.asm
fasm mb_setfunctions.asm
kos32-ar -ru libmsgbox.a *.o
del *.o
pause
/programs/develop/ktcc/trunk/lib/msgbox/makefile
0,0 → 1,8
all:
fasm __lib__.asm
fasm mb_create.asm
fasm mb_reinit.asm
fasm mb_setfunctions.asm
kos32-ar -ru libmsgbox.a *.o
clean:
rm -f *.o
/programs/develop/ktcc/trunk/lib/proc_lib/Makefile
0,0 → 1,7
all:
fasm loadproclib.asm
ar -csr libdialog.a loadproclib.o
install:
mv libdialog.a ../../bin/lib
clean:
rm -f *.o *.a
/programs/develop/ktcc/trunk/lib/proc_lib/loadproclib.asm
0,0 → 1,39
 
format elf
use32 ; Tell compiler to use 32 bit instructions
 
section '.text' executable ; Keep this line before includes or GCC messes up call addresses
 
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
public init_proclib as 'kolibri_dialog_init'
;;; Returns 0 on success. -1 on failure.
 
proc init_proclib
pusha
mcall 68,11
stdcall dll.Load, @IMPORT
popa
ret
endp
 
section '.data' writeable
 
@IMPORT:
library lib_boxlib, 'proc_lib.obj'
 
import lib_boxlib, \
OpenDialog_init, 'OpenDialog_init' , \
OpenDialog_start, 'OpenDialog_start' , \
ColorDialog_init, 'ColorDialog_init' , \
ColorDialog_start, 'ColorDialog_start'
public OpenDialog_init as 'OpenDialog_init'
public OpenDialog_start as 'OpenDialog_start'
 
public ColorDialog_init as 'ColorDialog_init'
public ColorDialog_start as 'ColorDialog_start'
/programs/develop/ktcc/trunk/lib/sample/sample_symbol.asm
0,0 → 1,18
format ELF
 
include "__lib__.inc"
 
fun equ sample_symbol
fun_str equ 'sample_symbol'
 
section '.text'
 
fun_name db fun_str, 0
 
section '.data'
 
extrn lib_name
public fun
 
fun dd fun_name
lib dd lib_name
/programs/develop/ktcc/trunk/lib/sample/__lib__.asm
0,0 → 1,9
format ELF
 
include '__lib__.inc'
 
section '.text'
 
public lib_name
 
lib_name db 0x55, 0xAA, lib_name_str, 0
/programs/develop/ktcc/trunk/lib/sample/__lib__.inc
0,0 → 1,2
lib_name equ @sample.obj
lib_name_str equ '/sys/lib/sample.obj'
/programs/develop/ktcc/trunk/lib/sample/howto.txt
0,0 → 1,13
Create new library wrapper
 
1. Redefine lib_name and lib_name_str in __lib__.inc
2. Create file for each symbol, basing on sample_symbol.asm and for each:
2.1. Redefine fun to *your_symbol_name*
2.2. Redefine fun_name to '*your_symbol_name*' (with quotes, this is ASCII string, no trailing zero need)
3. Change make.bat as appropriate
 
ACHTUNG: lib_name need to be unique in project, this is why I started it with "@" and put "." into.
ACHTUNG: lib_name_str must be at least 5 symbols long, if is not, fix this adding padding to the path.
 
Now you can create header file and declare extern variables pointers-to-functions, and then link your app with -llibname (put .a file in lib folder).
For examples of such header files, look at include/kos/inputbox.h, include/kos/console.h and include/kos/http.h. IMO, first one is the simplest.
/programs/develop/ktcc/trunk/lib/sample/make.bat
0,0 → 1,5
fasm __lib__.asm
fasm sample_symbol.asm
kos32-ar -ru libsample.a *.o
del *.o
pause
/programs/develop/ktcc/trunk/libc/include/clayer/dialog.h
0,0 → 1,126
#ifndef KOLIBRI_DIALOG_H
#define KOLIBRI_DIALOG_H
 
#include <stdlib.h>
#define NOT_SUCCESS 0
#define SUCCESS 1
 
char sz_com_area_name[] = "FFFFFFFF_open_dialog";
char sz_dir_default_path[] = "/sys";
char sz_start_path[] = "/sys/File managers/opendial";
 
char cd_com_area_name[] = "FFFFFFFF_color_dialog";
char cd_start_path[] = "/sys/colrdial";
 
enum open_dialog_mode {
OPEN,
SAVE,
SELECT
};
 
typedef struct {
unsigned int size;
unsigned char end;
}od_filter __attribute__ ((__packed__));
 
typedef struct {
unsigned int mode;
char* procinfo;
char* com_area_name;
unsigned int com_area;
char* opendir_path;
char* dir_default_path;
char* start_path;
void (*draw_window)();
unsigned int status;
char* openfile_path;
char* filename_area;
od_filter* filter_area;
unsigned short x_size;
unsigned short x_start;
unsigned short y_size;
unsigned short y_start;
}open_dialog __attribute__ ((__packed__));
 
 
typedef struct{
unsigned int type;
char* procinfo;
char* com_area_name;
unsigned int com_area;
char* start_path;
void (*draw_window)(void);
unsigned int status;
unsigned short x_size;
unsigned short x_start;
unsigned short y_size;
unsigned short y_start;
unsigned int color_type;
unsigned int color;
}color_dialog __attribute__ ((__packed__));
 
void fake_on_redraw(void) {}
 
open_dialog* kolibri_new_open_dialog(unsigned int mode, unsigned short tlx, unsigned short tly, unsigned short x_size, unsigned short y_size)
{
open_dialog *new_opendialog = (open_dialog *)malloc(sizeof(open_dialog));
od_filter *new_od_filter = (od_filter *)malloc(sizeof(od_filter));
char *plugin_path = (char *)calloc(4096, sizeof(char));
char *openfile_path = (char *)calloc(4096, sizeof(char));
char *proc_info = (char *)calloc(1024, sizeof(char));
char *filename_area = (char *)calloc(256, sizeof(char));
 
new_od_filter -> size = 0;
new_od_filter -> end = 0;
 
new_opendialog -> mode = mode;
new_opendialog -> procinfo = proc_info;
new_opendialog -> com_area_name = sz_com_area_name;
new_opendialog -> com_area = 0;
new_opendialog -> opendir_path = plugin_path;
new_opendialog -> dir_default_path = sz_dir_default_path;
new_opendialog -> start_path = sz_start_path;
new_opendialog -> draw_window = &fake_on_redraw;
new_opendialog -> status = 0;
new_opendialog -> openfile_path = openfile_path;
new_opendialog -> filename_area = filename_area;
new_opendialog -> filter_area = new_od_filter;
new_opendialog -> x_size = x_size;
new_opendialog -> x_start = tlx;
new_opendialog -> y_size = y_size;
new_opendialog -> y_start = tly;
return new_opendialog;
}
 
void cd_fake_on_redraw(void) {}
 
color_dialog* kolibri_new_color_dialog(unsigned int type, unsigned short tlx, unsigned short tly, unsigned short x_size, unsigned short y_size)
{
color_dialog *new_colordialog = (color_dialog *)malloc(sizeof(color_dialog));
char *proc_info = (char *)calloc(1024, sizeof(char));
 
new_colordialog -> type = type;
new_colordialog -> procinfo = proc_info;
new_colordialog -> com_area_name = cd_com_area_name;
new_colordialog -> com_area = 0;
new_colordialog -> start_path = cd_start_path;
new_colordialog -> draw_window = &cd_fake_on_redraw;
new_colordialog -> status = 0;
new_colordialog -> x_size = x_size;
new_colordialog -> x_start = tlx;
new_colordialog -> y_size = y_size;
new_colordialog -> y_start = tly;
new_colordialog -> color_type = 0;
new_colordialog -> color = 0;
return new_colordialog;
}
 
extern void kolibri_dialog_init();
 
extern void (*OpenDialog_init __attribute__((__stdcall__)))(open_dialog *);
extern void (*OpenDialog_start __attribute__((__stdcall__)))(open_dialog *);
 
extern void (*ColorDialog_init __attribute__((__stdcall__)))(color_dialog *);
extern void (*ColorDialog_start __attribute__((__stdcall__)))(color_dialog *);
 
#endif
/programs/develop/ktcc/trunk/libc/include/clayer/boxlib.h
0,0 → 1,265
// writed by maxcodehack and superturbocat2001
// adaptation of clayer for ktcc
#ifndef KOLIBRI_BOXLIB_H
#define KOLIBRI_BOXLIB_H
 
typedef unsigned color_t;
 
extern int kolibri_boxlib_init(void);
 
/* flags meaning */
#define ed_figure_only 0b1000000000000000 // одни символы
#define ed_always_focus 0b100000000000000 // всегда с курсором (фокусом)
#define ed_focus 0b10 // фокус ввода приложения, мышится самостоятельно
#define ed_pass 0b1 // поле с паролем
#define ed_shift_on 0b1000 // если не установлен -значит впервые нажат shift,если был установлен, значит мы уже что - то делали удерживая //shift
#define ed_shift_on_off 0b1111111111110111
#define ed_shift 0b100 //включается при нажатии на shift т.е. если нажимаю
#define ed_shift_off 0b1111111111111011
#define ed_shift_bac 0b10000 //бит для очистки выделеного shift т.е. при установке говорит что есть выделение
#define ed_shift_bac_cl 0b1111111111101111 //очистка при удалении выделения
#define ed_shift_cl 0b1111111111100011
#define ed_shift_mcl 0b1111111111111011
#define ed_left_fl 0b100000
#define ed_right_fl 0b1111111111011111
#define ed_offset_fl 0b1000000
#define ed_offset_cl 0b1111111110111111
#define ed_insert 0b10000000
#define ed_insert_cl 0b1111111101111111
#define ed_mouse_on 0b100000000
#define ed_mous_adn_b 0b100011000
#define ed_mouse_off ~ed_mouse_on
#define ed_ctrl_on 0b1000000000
#define ed_ctrl_off ~ed_ctrl_on
#define ed_alt_on 0b10000000000
#define ed_alt_off ~ed_alt_on
#define ed_disabled 0b100000000000
 
// SCROLLBAR
typedef struct {
uint16_t xsize;
uint16_t xpos;
uint16_t ysize;
uint16_t ypos;
uint32_t btn_height;
uint32_t type; // type 1 - stylish frame, type 2 - ?, type 0 - ?
uint32_t max_area;
uint32_t cur_area;
uint32_t position;
uint32_t back_color;
uint32_t front_color;
uint32_t line_color;
uint32_t redraw;
uint16_t delta;
uint16_t delta2;
uint16_t r_size_x;
uint16_t r_start_x;
uint16_t r_size_y;
uint16_t r_start_y;
uint32_t m_pos;
uint32_t m_pos2;
uint32_t m_keys;
uint32_t run_size;
uint32_t position2;
uint32_t work_size;
uint32_t all_redraw; // need to be set =1 before each redraw
uint32_t ar_offset;
} __attribute__ ((__packed__)) scrollbar;
 
extern void (*scrollbar_h_draw __attribute__((__stdcall__)))(scrollbar*);
extern void (*scrollbar_h_mouse __attribute__((__stdcall__)))(scrollbar*);
extern void (*scrollbar_v_draw __attribute__((__stdcall__)))(scrollbar*);
extern void (*scrollbar_v_mouse __attribute__((__stdcall__)))(scrollbar*);
 
// CHECKBOX
typedef struct {
unsigned int left_s;
unsigned int top_s;
unsigned int ch_text_margin;
unsigned int color;
unsigned int border_color;
unsigned int text_color;
char *text;
unsigned int flags;
 
/* Users can use members above this */
unsigned int size_of_str;
}check_box;
 
extern void (*check_box_draw2 __attribute__((__stdcall__)))(check_box *);
extern void (*check_box_mouse2 __attribute__((__stdcall__)))(check_box *);
extern void (*init_checkbox2 __attribute__((__stdcall__)))(check_box *);
 
// DBUTTON
typedef struct {
uint32_t type;
uint32_t x_w;
uint32_t y_h;
uint32_t mouse_pos;
uint32_t mouse_keys;
uint32_t mouse_keys_old;
void* active_raw; //active bitmap
void* passive_raw; //passive bitmap
void* click_raw; //pressed bitmap
uint32_t resolution_raw; // bpp, as esi fn65
void* palette_raw; // palette, as edi fn65
uint32_t offset_raw; // width as ebp fn65
uint32_t select; // internal state: 0 - passive, 2 - pressed, 1 - clicked
uint32_t click; // clicked - 1, zero it after tested
} pict_button;
 
extern void (*dynamic_button_draw __attribute__((__stdcall__)))(pict_button *);
extern void (*dynamic_button_mouse __attribute__((__stdcall__)))(pict_button *);
 
// EDITBOX
 
#pragma pack(push,1)
typedef struct edit_box_t {
unsigned int width;
unsigned int left;
unsigned int top;
unsigned int color;
unsigned int shift_color; // selected text color
unsigned int focus_border_color;
unsigned int blur_border_color;
unsigned int text_color;
unsigned int max;
char *text;
void *mouse_variable; // must be pointer edit_box** to save focused editbox
unsigned int flags;
 
unsigned int size; // used symbols in buffer without trailing zero
unsigned int pos; // cursor position
/* The following struct members are not used by the users of API */
unsigned int offset;
unsigned int cl_curs_x;
unsigned int cl_curs_y;
unsigned int shift;
unsigned int shift_old;
unsigned int height;
unsigned int char_width;
}edit_box;
#pragma pack(pop)
 
extern void (*edit_box_draw __attribute__((__stdcall__)))(edit_box *);
extern void edit_box_key (edit_box *, unsigned int key_val)__attribute__((__stdcall__));
extern void (*edit_box_mouse __attribute__((__stdcall__)))(edit_box *);
extern void (*edit_box_set_text __attribute__((__stdcall__)))(edit_box *, char *);
 
// FRAME
typedef struct {
uint32_t type;
uint32_t x_w;
uint32_t y_h;
color_t ext_col;
color_t int_col;
uint32_t flags;
char *text_pointer;
uint32_t text_position;
uint32_t font_number;
uint32_t font_size_y;
color_t font_color;
color_t font_bg_color;
}frame;
 
extern void (*frame_draw)(frame *);
 
// MENUBAR
typedef struct
{
uint32_t type; // 1 åñëè íåò ïîäìåíþ, ïðîñòî ïóíêò
 
uint32_t x_w; // âåðõíèé ïóíêò
uint32_t y_h;
 
char* text_pointer;
char* pos_pointer;
char* text_end;
uint32_t mouse_pos;
uint32_t mouse_keys;
 
uint32_t x_w1; // ïîäìåíþ
uint32_t y_h1;
 
color_t bckg_col; // ôîí âåðõíåãî ïóêòà
color_t frnt_col; // ôîí âûáðàííîãî âåðõíåãî ïóíêòà
color_t menu_col; // ôîí âûïàäàþùåé ÷àñòè (ïîäïóêòû)
uint32_t select;
uint32_t out_select;
char* buf_adress;
char* procinfo;
uint32_t click;
uint32_t cursor;
uint32_t cursor_old;
uint32_t interval;
uint32_t cursor_max;
uint32_t extended_key;
color_t menu_sel_col; // öâåò ôîíà âûáðàííîãî ïîäïóíêòà
color_t bckg_text_col; // öâåò øðèôòà íåâûáðàííîãî ïóíêòà
color_t frnt_text_col; // öâåò øðèôòà âûáðàííîãî ïóíêòà
uint32_t mouse_keys_old;
uint32_t font_height;
uint32_t cursor_out;
uint32_t get_mouse_flag;
} menubar;
 
extern void (*menu_bar_draw)(menubar *);
extern void (*menu_bar_mouse)(menubar *);
extern void (*menu_bar_activate)(menubar *);
 
// OPTIONBOX
typedef struct option_box_t {
struct option_box_t **selected;
uint16_t posx;
uint16_t posy;
uint32_t text_margin; // = 4 ðàññòîÿíèå îò ïðÿìîóãîëüíèêà ÷åê áîêñà äî íàäïèñè
uint32_t size; // 12 ðàçìåð êâàäðàòà ÷åê áîêñà
color_t color;
color_t border_color; // individual border
color_t text_color;
char *text;
uint32_t text_len;
uint32_t flags;
} __attribute__ ((__packed__)) option_box;
 
extern void (*option_box_draw __attribute__((__stdcall__)))(option_box **);
extern void (*option_box_mouse __attribute__((__stdcall__)))(option_box **);
 
// PATHSHOW
typedef struct {
uint32_t type;
uint32_t x_y;
uint16_t font_size_x; // 6 - for font 0, 8 - for font 1
uint16_t area_size_x;
uint32_t font_number; // 0 - monospace, 1 - variable, as fn4 (2bit only 0-3)
uint32_t background_flag; // as fn4, if 0, bk_color unneeded
color_t font_color; // as fn4
color_t background_color; // as fn4
char* text_pointer; // 4096 ?
char* work_area_pointer; // 4096 ?
uint32_t temp_text_length;
} __attribute__ ((__packed__)) pathview;
 
extern void (*path_show_prepare __attribute__((__stdcall__)))(pathview *);
extern void (*path_show_draw __attribute__((__stdcall__)))(pathview *);
 
// PROGRESSBAR
typedef struct {
unsigned int value;
unsigned int left;
unsigned int top;
unsigned int width;
unsigned int height;
unsigned int style;
unsigned int min;
unsigned int max;
unsigned int back_color;
unsigned int progress_color;
unsigned int frame_color;
} progressbar;
 
extern void (*progressbar_draw __attribute__((__stdcall__)))(progressbar *);
extern void (*progressbar_progress __attribute__((__stdcall__)))(progressbar *);
 
 
#endif /* KOLIBRI_BOXLIB_H */
/programs/develop/ktcc/trunk/libc/include/clayer/http.h
0,0 → 1,153
/*
This is adapded thunk for http.obj sys library
.h is equal to svn:\\programs\develop\libraries\http\http_en.txt
 
Adapted for TCC's dynamic API by Magomed Kostoev, 2020
*/
 
#ifndef _HTTP_H_
#define _HTTP_H_
 
#define cdecl __attribute__ ((cdecl))
#define stdcall __attribute__ ((stdcall))
 
// Bitflags for http_msg.flags
// status
 
#define HTTP_FLAG_HTTP11 1 << 0
#define HTTP_FLAG_GOT_HEADER 1 << 1
#define HTTP_FLAG_GOT_ALL_DATA 1 << 2
#define HTTP_FLAG_CONTENT_LENGTH 1 << 3
#define HTTP_FLAG_CHUNKED 1 << 4
#define HTTP_FLAG_CONNECTED 1 << 5
 
// user options
#define HTTP_FLAG_KEEPALIVE 1 << 8
#define HTTP_FLAG_STREAM 1 << 9
#define HTTP_FLAG_REUSE_BUFFER 1 << 10
#define HTTP_FLAG_BLOCK 1 << 11
 
// error
#define HTTP_FLAG_INVALID_HEADER 1 << 16
#define HTTP_FLAG_NO_RAM 1 << 17
#define HTTP_FLAG_SOCKET_ERROR 1 << 18
#define HTTP_FLAG_TIMEOUT_ERROR 1 << 19
#define HTTP_FLAG_TRANSFER_FAILED 1 << 20
 
/*
User flags:
 
For the flag codes themselves, see http.inc file.
 
FLAG_KEEPALIVE will keep the connection open after first GET/POST/.. so you can send a second request on the same TCP session.
In this case, the session must be closed manually when done by using the exported disconnect() function.
 
FLAG_STREAM will force receive() to put the received content in a series of fixed size buffers, instead of everything in one big buffer.
This can be used for example to receive an internet radio stream,
but also to download larger files for which it does not make sense to put them completely in RAM first.
 
FLAG_REUSE_BUFFER is to be used in combination with FLAG_STREAM and will make receive() function re-use the same buffer.
This, for example, can be used when downloading a file straight to disk.
 
FLAG_BLOCK will make receive() function blocking. This is only to be used when receiving one file from a thread that has no other work.
If however, you want to receive multiple files, or do other things in the program mainloop, you should call the receive function periodically.
You may use system function 10 or 23 to wait for network event before calling one or more receive() functions.
*/
 
#pragma pack(push,1)
typedef struct http_msg_s {
unsigned socket; // socket on which the actual transfer happens
unsigned flags; // flags, reflects status of the transfer using bitflags
unsigned write_ptr; // internal use only (where to write new data in buffer)
unsigned buffer_length; // internal use only (number of available bytes in buffer)
unsigned chunk_ptr; // internal use only (where the next chunk begins)
unsigned timestamp; // internal use only (when last data was received)
unsigned status; // HTTP status
unsigned header_length; // length of HTTP header
void * content_ptr; // ptr to content
unsigned content_length; // total length of HTTP content
unsigned content_received; // number of currently received content bytes
char * http_header;
} http_msg;
#pragma pack(pop)
 
/*
url = pointer to ASCIIZ URL
identifier = identifier of previously opened connection (keep-alive), or 0 to open a new one.
flags = bit flags (see end of this document).
add_header = pointer to ASCIIZ additional header parameters, or null for none.
Every additional parameter must end with CR LF bytes, including the last line.
Initiates a HTTP connection, using 'GET' method.
Returns NULL on error, identifier otherwise.
*/
extern http_msg * stdcall (*http_get)(const char *url, http_msg *identifier, unsigned flags, const char *add_header);
 
/*
url = pointer to ASCIIZ URL
identifier = identifier of previously opened connection (keep-alive), or 0 to open a new one.
flags = bit flags (see end of this document).
add_header = pointer to ASCIIZ additional header parameters, or null for none.
Every additional parameter must end with CR LF bytes, including the last line.
Initiate a HTTP connection, using 'HEAD' method.
Returns NULL on error, identifier otherwise.
*/
extern http_msg * stdcall (*http_head)(const char *url, http_msg *identifier, unsigned flags, const char *add_header);
 
/*
url = pointer to ASCIIZ URL
identifier = identifier of previously opened connection (keep-alive), or 0 to open a new one.
flags = bit flags (see end of this document).
add_header = pointer to ASCIIZ additional header parameters, or null for none.
Every additional parameter must end with CR LF bytes, including the last line.
content-type = pointer to ASCIIZ string containing content type.
content-length = length of the content (in bytes).
Initiate a HTTP connection, using 'POST' method.
The content itself must be send to the socket (which you can find in the structure),
using system function 75, 6.
Returns 0 on error, identifier otherwise
*/
extern http_msg * stdcall (*http_post)(const char *url, http_msg *identifier, unsigned flags, const char *add_header,
const char *content_type, unsigned content_length);
 
/*
identifier = identifier which one of the previous functions returned
This procedure will handle all incoming data for a connection and place it in the buffer.
As long as the procedure expects more data, -1 is returned and the procedure must be called again.
When transfer is done, the procedure will return 0.
The receive procedure is non-blocking by default, but can be made to block by setting FLAG_BLOCK.
 
The HTTP header is placed together with some flags and other attributes in the http_msg structure.
This structure is defined in http.inc (and not copied here because it might still change.)
The identifier used by the functions is actually a pointer to this structure.
In the dword named .flags, the library will set various bit-flags indicating the status of the process.
(When a transfer is done, one should check these bit-flags to find out if the transfer was error-free.)
The HTTP header is placed at the end of this structure. The content is placed in another buffer.
The dword .status contains the status code received from the server (e.g. 200 for OK).
In header_length you'll find the length of the header as soon as it has been received.
In content_ptr you'll find a pointer to the actual content.
In content_length you'll find the length of the content.
In content_received, you'll find the number of content bytes already received.
*/
extern int stdcall (*http_receive)(http_msg *identifier);
 
/*
identifier = identifier which one of the previous functions returned
dataptr = pointer to the data you want to send
datalength = length of the data to send (in bytes)
This procedure can be used to send data to the server (POST)
Returns number of bytes sent, -1 on error
*/
extern int stdcall (*http_send)(http_msg *identifier, void *dataptr, unsigned datalength);
 
/*
Sometimes the http_receive function receives incomplete data. If you have the same problem then a macro can help you:
*/
 
extern int stdcall (*http_free)(http_msg *identifier);
/*
Free unused data
*/
 
#define http_long_receive(x) while(http_receive(x)){};
 
#endif // _HTTP_H_
/programs/develop/ktcc/trunk/libc/include/clayer/gb.h
0,0 → 1,19
 
#pragma pack(push, 1)
typedef struct
{
int w;
int h;
char *bmp;
char *alpha;
} GB_BMP;
#pragma pack(pop)
 
void gb_pixel_set(GB_BMP *b, int x, int y, unsigned c);
int gb_pixel_get(GB_BMP *b, int x, int y, unsigned *c);
void gb_line(GB_BMP *b, int x1, int y1, int x2, int y2, unsigned c);
void gb_rect(GB_BMP *b, int x, int y, int w, int h, unsigned c);
void gb_bar(GB_BMP *b, int x, int y, int w, int h, unsigned c);
void gb_circle(GB_BMP *b, int x, int y, int r, unsigned c);
void gb_image_set(GB_BMP *b_dest, int x_d, int y_d, GB_BMP *b_src, int x_s, int y_s, int w, int h);
void gb_image_set_t(GB_BMP *b_dest, int x_d, int y_d, GB_BMP *b_src, int x_s, int y_s, int w, int h, unsigned c);
/programs/develop/ktcc/trunk/libc/include/clayer/inputbox.h
0,0 → 1,17
/*
This is wrapper for Inputbox.obj sys library
https://board.kolibrios.org/viewtopic.php?f=24&t=3767&sid=fd2ca95b24eec430db0c61d977f5d8ba#p71585
 
Adapted for TCC's dynamic API by Magomed Kostoev, 2020
*/
 
#ifndef __KOS__INPUTBOX__H________
#define __KOS__INPUTBOX__H________
 
#define cdecl __attribute__ ((cdecl))
#define stdcall __attribute__ ((stdcall))
 
extern unsigned stdcall (*InputBox)(void* Buffer, char* Caption, char* Prompt, char* Default,
unsigned long Flags, unsigned long BufferSize, void* RedrawProc);
 
#endif // __KOS__INPUTBOX__H________
/programs/develop/ktcc/trunk/libc/include/clayer/libimg.h
0,0 → 1,126
/* Written by turbocat2001 (Logaev Maxim) */
 
#ifndef KOLIBRI_LIBIMG_H
#define KOLIBRI_LIBIMG_H
 
#include <stddef.h>
#include <stdbool.h>
 
extern int kolibri_libimg_init(void);
 
#define _stdcall __attribute__((__stdcall__))
 
//list of format id's
#define LIBIMG_FORMAT_BMP 1
#define LIBIMG_FORMAT_ICO 2
#define LIBIMG_FORMAT_CUR 3
#define LIBIMG_FORMAT_GIF 4
#define LIBIMG_FORMAT_PNG 5
#define LIBIMG_FORMAT_JPEG 6
#define LIBIMG_FORMAT_TGA 7
#define LIBIMG_FORMAT_PCX 8
#define LIBIMG_FORMAT_XCF 9
#define LIBIMG_FORMAT_TIFF 10
#define LIBIMG_FORMAT_PNM 11
#define LIBIMG_FORMAT_WBMP 12
#define LIBIMG_FORMAT_XBM 13
#define LIBIMG_FORMAT_Z80 14
 
#pragma pack(push, 1)
typedef struct{
uint32_t Checksum; // ((Width ROL 16) OR Height) XOR Data[0] ; ignored so far
uint32_t Width;
uint32_t Height;
uint32_t Next;
uint32_t Previous;
uint32_t Type; // one of Image.bppN
uint32_t* Data;
uint32_t Palette; // used iff Type eq Image.bpp1, Image.bpp2, Image.bpp4 or Image.bpp8i
uint32_t Extended;
uint32_t Flags; // bitfield
uint32_t Delay; // used iff Image.IsAnimated is set in Flags
} Image;
#pragma pack(pop)
 
#define IMAGE_BPP8i 1 // indexed
#define IMAGE_BPP24 2
#define IMAGE_BPP32 3
#define IMAGE_BPP15 4
#define IMAGE_BPP16 5
#define IMAGE_BPP1 6
#define IMAGE_BPP8g 7 // grayscale
#define IMAGE_BPP2i 8
#define IMAGE_BPP4i 9
#define IMAGE_BPP8a 10
 
// scale type
#define LIBIMG_SCALE_NONE 0
#define LIBIMG_SCALE_INTEGER 1
#define LIBIMG_SCALE_TILE 2
#define LIBIMG_SCALE_STRETCH 3
#define LIBIMG_SCALE_FIT_BOTH LIBIMG_SCALE_STRETCH
#define LIBIMG_SCALE_FIT_MIN 4
#define LIBIMG_SCALE_FIT_RECT LIBIMG_SCALE_FIT_MIN
#define LIBIMG_SCALE_FIT_WIDTH 5
#define LIBIMG_SCALE_FIT_HEIGHT 6
#define LIBIMG_SCALE_FIT_MAX 7
 
// interpolation algorithm
#define LIBIMG_INTER_NONE 0 // use it with LIBIMG_SCALE_INTEGER, LIBIMG_SCALE_TILE, etc
#define LIBIMG_INTER_BILINEAR 1
#define LIBIMG_INTER_BICUBIC 2
#define LIBIMG_INTER_LANCZOS 3
#define LIBIMG_INTER_DEFAULT LIBIMG_INTER_BILINEAR
 
//error codes
#define LIBIMG_ERROR_OUT_OF_MEMORY 1
#define LIBIMG_ERROR_FORMAT 2
#define LIBIMG_ERROR_CONDITIONS 3
#define LIBIMG_ERROR_BIT_DEPTH 4
#define LIBIMG_ERROR_ENCODER 5
#define LIBIMG_ERROR_SRC_TYPE 6
#define LIBIMG_ERROR_SCALE 7
#define LIBIMG_ERROR_INTER 8
#define LIBIMG_ERROR_NOT_INPLEMENTED 9
#define LIBIMG_ERROR_INVALID_INPUT 10
 
//encode flags (byte 0x02 of _common option)
#define LIBIMG_ENCODE_STRICT_SPECIFIC 0x01
#define LIBIMG_ENCODE_STRICT_BIT_DEPTH 0x02
#define LIBIMG_ENCODE_DELETE_ALPHA 0x08
#define LIBIMG_ENCODE_FLUSH_ALPHA 0x10
 
#define FLIP_VERTICAL 0x01
#define FLIP_HORIZONTAL 0x02
 
#define ROTATE_90_CW 0x01
#define ROTATE_180 0x02
#define ROTATE_270_CW 0x03
#define ROTATE_90_CCW ROTATE_270_CW
#define ROTATE_270_CCW ROTATE_90_CW
 
extern Image* (*img_decode _stdcall)(void* file_data, uint32_t size, uint32_t b_color);
extern Image* (*img_encode _stdcall)(Image* img, uint32_t length, uint32_t option);
extern Image* (*img_create _stdcall)(uint32_t width, uint32_t height, uint32_t type);
extern void (*img_to_rgb2 _stdcall)(Image* img, void *rgb_data);
extern Image* (*img_to_rgb _stdcall)(Image* img);
extern bool (*img_flip _stdcall)(Image* img, uint32_t flip);
extern bool (*img_flip_layer _stdcall)(Image *img, uint32_t flip);
extern bool (*img_rotate _stdcall)(Image *img, uint32_t rotate);
extern bool (*img_rotate_layer _stdcall)(Image* data, uint32_t rotate);
extern void (*img_draw _stdcall)(Image *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t xoff, uint32_t yoff);
extern int32_t (*img_count _stdcall)(Image *img);
extern bool (*img_destroy _stdcall)(Image *img);
extern bool (*img_destroy_layer _stdcall)(Image* img);
extern Image* (*img_blend _stdcall)(Image* dst, Image* src, uint32_t out_x, uint32_t out_y, uint32_t in_x, uint32_t in_y, uint32_t width, uint32_t height);
extern Image* (*img_convert _stdcall)(Image *src, Image *dst, uint32_t dst_type, uint32_t, uint32_t);
extern Image* (*img_resize_data _stdcall)(Image *src, uint32_t width, uint32_t height);
extern Image* (*img_scale _stdcall)(Image* src, uint32_t crop_x, uint32_t crop_y, uint32_t crop_width, uint32_t crop_height, Image* dst, uint32_t scale_type, uint32_t inter, uint32_t new_width, uint32_t new_height);
 
void img_fill_color(Image* img, uint32_t width, uint32_t height, uint32_t color){
for (uint32_t i = 0; i < width*height; i++) {
img->Data[i] = color;
}
}
 
#endif /* KOLIBRI_LIBIMG_H */
/programs/develop/ktcc/trunk/libc/include/clayer/buf2d.h
0,0 → 1,83
#ifndef KOLIBRI_BUF2D_H
#define KOLIBRI_BUF2D_H
 
#include <stdint.h>
/*ToDo
* voxel function
*/
 
extern int kolibri_buf2d_init(void);
 
typedef struct {
unsigned int *buf_pointer;
uint16_t left;
uint16_t top;
unsigned int width;
unsigned int height;
unsigned int bgcolor;
uint8_t color_bit;
} __attribute__ ((__packed__))buf2d_struct;
 
enum BUF2D_ALGORITM_FILTR {
SIERRA_LITE,
FLOYD_STEINBERG,
BURKERS,
HEAVYIRON_MOD,
ATKINSON
};
 
enum BUF2D_OPT_CROP {
BUF2D_OPT_CROP_TOP = 1,
BUF2D_OPT_CROP_LEFT = 2,
BUF2D_OPT_CROP_BOTTOM = 4,
BUF2D_OPT_CROP_RIGHT = 8
};
 
extern void (*buf2d_create_asm __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_curve_bezier_asm __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int);
 
buf2d_struct* buf2d_create(uint16_t tlx, uint16_t tly, unsigned int sizex, unsigned int sizey, unsigned int font_bgcolor, uint8_t color_bit)
{
buf2d_struct *new_buf2d_struct = (buf2d_struct *)malloc(sizeof(buf2d_struct));
new_buf2d_struct -> left = tlx;
new_buf2d_struct -> top = tly;
new_buf2d_struct -> width = sizex;
new_buf2d_struct -> height = sizey;
new_buf2d_struct -> bgcolor = font_bgcolor;
new_buf2d_struct -> color_bit = color_bit;
buf2d_create_asm(new_buf2d_struct);
return new_buf2d_struct;
}
 
void buf2d_curve_bezier(buf2d_struct *buf, unsigned int p0_x, unsigned int p0_y, unsigned int p1_x, unsigned int p1_y, unsigned int p2_x, unsigned int p2_y, unsigned int color)
{
buf2d_curve_bezier_asm(buf, (p0_x<<16)+p0_y, (p1_x<<16)+p1_y, (p2_x<<16)+p2_y, color);
}
 
extern void (*buf2d_draw __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_clear __attribute__((__stdcall__)))(buf2d_struct *, unsigned int);
extern void (*buf2d_delete __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_rotate __attribute__((__stdcall__)))(buf2d_struct *, unsigned int);
extern void (*buf2d_resize __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_line __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_line_sm __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_rect_by_size __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_filled_rect_by_size __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_circle __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_img_hdiv2 __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_img_wdiv2 __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_conv_24_to_8 __attribute__((__stdcall__)))(buf2d_struct *, unsigned int);
extern void (*buf2d_conv_24_to_32 __attribute__((__stdcall__)))(buf2d_struct *, unsigned int);
extern void (*buf2d_bit_blt_transp __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, buf2d_struct *);
extern void (*buf2d_bit_blt_alpha __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, buf2d_struct *);
extern void (*buf2d_convert_text_matrix __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_draw_text __attribute__((__stdcall__)))(buf2d_struct *, buf2d_struct *, const char *, unsigned int, unsigned int);
extern void (*buf2d_crop_color __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int);
extern void (*buf2d_offset_h __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_flood_fill __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int);
extern void (*buf2d_set_pixel __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int, unsigned int);
extern unsigned int (*buf2d_get_pixel __attribute__((__stdcall__)))(buf2d_struct *, unsigned int, unsigned int);
extern void (*buf2d_flip_h __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_flip_v __attribute__((__stdcall__)))(buf2d_struct *);
extern void (*buf2d_filter_dither __attribute__((__stdcall__)))(buf2d_struct *, unsigned int);
#endif /* KOLIBRI_BUF2D_H */
/programs/develop/ktcc/trunk/libc/include/clayer/msgbox.h
0,0 → 1,55
#ifndef KOLIBRI_MSGBOX_H
#define KOLIBRI_MSGBOX_H
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
 
 
typedef struct {
uint8_t retval; // 0 - win closed, 1 to n - button num, also default button on start
uint8_t reserv;
char texts[2048]; // must be enough ;-)
char msgbox_stack[1024];
uint32_t top_stack;
}__attribute__((packed)) msgbox;
 
typedef void (*msgbox_callback)(void);
 
extern void (*msgbox_create __attribute__((__stdcall__)))(msgbox *, void *thread); // clears callbacks, ! if fix lib, we can return eax as of Fn51
extern void (*msgbox_setfunctions __attribute__((__stdcall__)))(msgbox_callback*); // must be called immediately after create, zero-ended array
extern void (*msgbox_reinit __attribute__((__stdcall__)))(msgbox *) ; // recalc sizes when structure changes, called auto when MsgBoxCreate
 
static inline msgbox* kolibri_new_msgbox(char* title, char* text, int def_but, ...)
/// text can be multilined by code 13 = "\r"
/// def_but - highlighted and used on Enter (if zero - default is [X]), user may use Tabs or Arrows
/// last params are buttons text, max 8. last must set as NULL
{
va_list vl=0;
va_start(vl, def_but);
msgbox* box = calloc(sizeof(msgbox), 1);
box->retval = (uint8_t)def_but;
char *pc = box->texts;
strcpy(pc, title);
pc += strlen(title) + 1;
strcpy(pc, text);
pc += strlen(text) + 1;
char *but_text = va_arg(vl, char*);
while (but_text)
{
strcpy(pc, but_text);
pc += strlen(but_text) + 1;
but_text = va_arg(vl, char*);
}
 
va_end(vl);
return box;
}
 
static inline void kolibri_start_msgbox(msgbox* box, msgbox_callback cb[])
{
(*msgbox_create)(box, &box->top_stack);
if (cb) (*msgbox_setfunctions)(cb);
}
 
#endif
/programs/develop/ktcc/trunk/libc/include/clayer/rasterworks.h
0,0 → 1,11
#ifndef KOLIBRI_RASTERWORKS_H
#define KOLIBRI_RASTERWORKS_H
 
//extern int kolibri_rasterworks_init(void);
 
extern void (*drawText __attribute__((__stdcall__)))(void *canvas, int x, int y, const char *string, int charQuantity, int fontColor, int params);
extern int (*countUTF8Z __attribute__((__stdcall__)))(const char *string, int byteQuantity);
extern int (*charsFit __attribute__((__stdcall__)))(int areaWidth, int charHeight);
extern int (*strWidth __attribute__((__stdcall__)))(int charQuantity, int charHeight);
 
#endif /* KOLIBRI_RASTERWORKS_H */
/programs/develop/ktcc/trunk/libc/include/kos32sys1.h
0,0 → 1,815
#ifndef __KOS_32_SYS_H__
#define __KOS_32_SYS_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
 
#define TYPE_3_BORDER_WIDTH 5
#define WIN_STATE_MINIMIZED 0x02
#define WIN_STATE_ROLLED 0x04
#define POS_SCREEN 0
#define POS_WINDOW 1
 
#define IPC_NOBUFFER 1
#define IPC_LOCKED 2
#define IPC_OVERFLOW 3
#define IPC_NOPID 4
 
#define SHM_OPEN 0x00
#define SHM_OPEN_ALWAYS 0x04
#define SHM_CREATE 0x08
#define SHM_READ 0x00
#define SHM_WRITE 0x01
// for clipboard funtions
#define CLIP_UTF 0
#define CLIP_CP866 1
#define CLIP_CP1251 2
#define CLIP_TEXT 0
#define CLIP_IMAGE 1
#define CLIP_RAW 2
 
//Read/Write data as type (int char, etc.) at address "addr" with offset "offset". eg DATA(int, buff, 8);
#define DATA(type, addr, offset) *((type*)((uint8_t*)addr+offset))
#define X_W(X, W) ((X<<16)+W)
#define Y_H X_W
typedef struct {
uint8_t blue;
uint8_t green;
uint8_t red;
}RGB;
typedef unsigned int color_t;
 
typedef union __attribute__((packed)) pos_t
{
uint32_t val;
struct
{
short x;
short y;
};
} pos_t;
 
 
typedef union __attribute__((packed)) oskey_t
{
uint32_t val;
struct
{
uint8_t state;
uint8_t code;
uint16_t ctrl_key;
};
} oskey_t;
 
typedef struct
{
unsigned handle;
unsigned io_code;
void *input;
int inp_size;
void *output;
int out_size;
}ioctl_t;
 
typedef union
{
struct
{
void *data;
size_t size;
} x;
unsigned long long raw;
}ufile_t;
 
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;
};
 
 
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
 
int srcx;
int srcy;
int srcw;
int srch;
 
void *bitmap;
int stride;
};
 
struct ipc_message
{
uint32_t pid; // PID of sending thread
uint32_t datalen; // data bytes
char data[0]; // data begin
};
 
struct ipc_buffer
{
uint32_t lock; // nonzero is locked
uint32_t used; // used bytes in buffer
struct ipc_message data[0]; // data begin
};
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 sys_change_window(int new_x, int new_y, int new_w, int new_h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
);
}
 
 
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
void draw_text_sys_bg(const char *text, int x, int y, int len, color_t color, color_t bg)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color), "D"(bg)
:"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
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
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 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 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 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 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));
};
 
 
// newlib exclusive
#ifndef __TINYC__
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);
#endif
 
// 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;
}
 
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 void draw_number_sys_bg(int32_t number, int x, int y, int len, color_t color, color_t bg){
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), "D"(bg));
}
 
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
void ipc_set_area(void* buf, int bufsize){
asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize));
}
 
static inline
int ipc_send_message(int pid_reciever, void *data, int datalen) {
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen));
return val;
}
 
static inline
void* shm_open(char *shm_name, int msize, int flags, int *retsz){
register int val, cod;
asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags));
 
if(retsz) *retsz = cod; // errcode if NULL or memsize when open
return (void*)val;
}
 
static inline
void shm_close(char *shm_name){
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name));
}
 
static inline
int start_app(char *app_name, char *args){
struct file_op_t
{
uint32_t fn;
uint32_t flags;
char* args;
uint32_t res1, res2;
char zero;
char* app_name __attribute__((packed));
} file_op;
memset(&file_op, 0, sizeof(file_op));
file_op.fn = 7;
file_op.args = args;
file_op.app_name = app_name;
 
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
 
return val;
}
 
// TinyC don't support aliasing of static inline funcs, but support #define :)
#ifndef __TINYC__
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")));
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 GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
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")));
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
#else
#define BeginDraw begin_draw
#define EndDraw end_draw
#define DrawWindow sys_create_window
#define DefineButton define_button
#define DrawLine draw_line
#define DrawBar draw_bar
#define DrawBitmap draw_bitmap
#define GetSkinHeight get_skin_height
#define GetMousePos get_mouse_pos
#define GetMouseButtons get_mouse_buttons
#define GetMouseWheels get_mouse_wheels
#define LoadCursor load_cursor
#define SetCursor set_cursor
#define DestroyCursor destroy_cursor
#define GetOsEvent get_os_event
#define UserAlloc user_alloc
#define UserFree user_free
#define UserRealloc user_realloc
#define UserUnmap user_unmap
#define LoadFile load_file
#define GetProcInfo get_proc_info
#endif
 
#ifdef __cplusplus
}
#endif
 
 
#endif
 
 
 
 
 
/programs/develop/ktcc/trunk/libc/include/kolibrisys.h
0,0 → 1,197
#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 void* func_ptr;
typedef unsigned int dword;
typedef unsigned char byte;
typedef unsigned short word;
 
typedef unsigned int fpos_t;
typedef unsigned int size_t;
#pragma pack(push,1)
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
};
#pragma pack(pop)
 
//-----------------------------------------------------------------------------------
//------------------------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, int *preadbytes);
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_dword(int bus,int dev,int fn,int reg,int value);
//--------------------------------------------------------------------------------------
 
//------------------------Working with processes--------------------------------------
extern int stdcall _ksys_get_process_table(struct process_table_entry *proctab,int pid); //if pid=-1 than get info about him.
extern int stdcall _ksys_kill_process(int pid); // if it returns -1 then an error.
//---------------------------------------------------------------------------------
 
//-----------------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 func_ptr stdcall _ksys_cofflib_getproc(void* exp,char* sz_name);
//---------------------------------------------------------------------------------
 
#endif
/programs/develop/ktcc/trunk/libc/include/errno.h
0,0 → 1,42
#ifndef _ERRNO_H
#define _ERRNO_H
 
extern int errno;
/* errors codes from KOS, but minus */
# define E_SUCCESS (0)
# define E_UNSUPPORTED (-2)
# define E_UNKNOWNFS (-3)
# define E_NOTFOUND (-5)
# define E_EOF (-6)
# define E_INVALIDPTR (-7)
# define E_DISKFULL (-8)
# define E_FSYSERROR (-9)
# define E_ACCESS (-10)
# define E_HARDWARE (-11)
# define E_NOMEM (-12)
/* conversion errors */
# define ERANGE (-20)
# define EINVAL (-21)
/* program run and pipe errors */
# define E_NOMEM2 (-30)
# define E_FILEFMT (-31)
# define E_TOOMANY (-32)
# define E_PARAM (-33)
/* socket error codes*/
#define ENOBUFS 1
#define EINPROGRESS 2
#define EOPNOTSUPP 4
#define EWOULDBLOCK 6
#define ENOTCONN 9
#define EALREADY 10
#define EINVALUE 11
#define EMSGSIZE 12
#define ENOMEM 18
#define EADDRINUSE 20
#define ECONNREFUSED 61
#define ECONNRESET 52
#define EISCONN 56
#define ETIMEDOUT 60
#define ECONNABORTED 53
 
#endif
/programs/develop/ktcc/trunk/libc/include/net/socket.h
0,0 → 1,89
#ifndef __SOCKET_H
#define __SOCKET_H
 
#include <stddef.h>
#include <errno.h>
 
// Socket Types
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_RAW 3
// IP protocols
#define IPPROTO_IP 0
#define IPPROTO_ICMP 1
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_RAW 255
// IP options
#define IP_TTL 2
// Address families
#define AF_UNSPEC 0
#define AF_LOCAL 1
#define AF_INET 2
#define AF_INET4 2 // IPv4
#define AF_INET6 10 // IPv6
 
#define PF_UNSPEC AF_UNSPEC
#define PF_LOCAL AF_LOCAL
#define PF_INET4 AF_INET4
#define PF_INET6 AF_INET6
// internal definition
#define AI_SUPPORTED 0x40F
 
// for system function 76
#define API_ETH (0<<16)
#define API_IPv4 (1<<16)
#define API_ICMP (2<<16)
#define API_UDP (3<<16)
#define API_TCP (4<<16)
#define API_ARP (5<<16)
#define API_PPPOE (6<<16)
 
// Socket flags for user calls
#define MSG_NOFLAG 0
#define MSG_PEEK 0x02
#define MSG_DONTWAIT 0x40
// Socket levels
#define SOL_SOCKET 0xffff
 
//Socket options
#define SO_BINDTODEVICE (1<<9)
#define SO_NONBLOCK (1<<31)
#define PORT(X) (X<<8)
 
#pragma pack(push,1)
struct sockaddr{
unsigned short sin_family;
unsigned short sin_port;
unsigned int sin_addr;
unsigned long long sin_zero;
};
#pragma pack(pop)
 
#pragma pack(push,1)
typedef struct{
unsigned int level;
unsigned int optionname;
unsigned int optlenght;
unsigned char options;
}optstruct;
#pragma pack(pop)
 
int socket(int domain, int type, int protocol);
int close(int socket);
int bind(int socket, const struct sockaddr *addres, int addres_len);
int listen(int socket, int backlog);
int connect(int socket, const struct sockaddr* address, int socket_len);
int accept(int socket, const struct sockaddr* address, int address_len);
int send(int socket, const void *message, size_t msg_len, int flag);
int recv(int socket, void *buffer, size_t buff_len, int flag);
int setsockopt(int socket,const optstruct* opt);
int getsockopt(int socket, optstruct* opt);
int socketpair(int *sock1, int *sock2);
 
#endif
/programs/develop/ktcc/trunk/libc/include/net/network.h
0,0 → 1,54
#ifndef __NETWORK_H
#define __NETWORK_H
 
#include <net/socket.h>
 
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_OVERFLOW 14
 
// Flags for addrinfo
#define AI_PASSIVE 1
#define AI_CANONNAME 2
#define AI_NUMERICHOST 4
#define AI_NUMERICSERV 8
#define AI_ADDRCONFIG 0x400
 
#pragma pack(push, 1)
struct ARP_entry{
unsigned int IP;
unsigned char MAC[6];
unsigned short status;
unsigned short TTL;
};
#pragma pack(pop)
 
#pragma pack(push, 1)
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
int ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#pragma pack(pop)
 
extern int networklib_init ();
extern int (*inet_addr __attribute__ ((stdcall)))(const char* hostname);
extern char* (*inet_ntoa __attribute__ ((stdcall)))(int ip_addr);
extern int (*getaddrinfo __attribute__ ((stdcall)))(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res);
extern void (*freeaddrinfo __attribute__ ((stdcall)))(struct addrinfo* ai);
 
#endif
/programs/develop/ktcc/trunk/libc/include/stdio.h
0,0 → 1,105
#ifndef stdio_h
#define stdio_h
 
#include "kolibrisys.h"
#include <errno.h>
#include <stdarg.h>
/* use stdarg.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)
*/
#ifndef NULL
# define NULL ((void*)0)
#endif
 
typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit
typedef unsigned int size_t;
 
int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
 
typedef struct {
char* buffer;
dword buffersize;
dword filesize; // too small
int filepos; // too small, may be -1
char* filename;
int mode;
int ungetc_buf;
dword buffer_start; // 1st byte position
dword buffer_end; // points after last buffered data
} FILE;
 
#define stderr ((FILE*)3) /* works only for fprintf!!! */
 
#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)
#define BUFSIZ (4096)
#define FILENAME_MAX (0x400)
 
extern FILE* fopen(const char* filename, const char *mode);
extern int 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,...);
 
#define getc(a) fgetc(a)
#define putc(a, b) fputc(a, b)
char * fgets (char * str, int num, FILE * stream);
int putchar (int ch);
int getchar (void);
int puts (const char * str);
char * gets (char * str);
 
typedef int (*virtual_getc)(void *sp, const void *obj);
typedef void (*virtual_ungetc)(void *sp, int c, const void *obj);
int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc);
int vscanf ( const char * format, va_list arg );
int scanf ( const char * format, ...);
int vsscanf ( const char * s, const char * format, va_list arg );
int sscanf ( const char * s, const char * format, ...);
int vfscanf ( FILE * stream, const char * format, va_list arg );
int fputs ( const char * str, FILE * file );
void clearerr ( FILE * stream );
int ferror ( FILE * stream );
void perror ( const char * str );
int vprintf ( const char * format, va_list arg );
int vsprintf (char * s, const char * format, va_list arg );
int vfprintf ( FILE * stream, const char * format, va_list arg );
 
//debug
void debug_printf(const char *format,...);
 
int tiny_sprintf (char * s, const char * format, ... );
int tiny_snprintf (char * s, size_t n, const char * format, ... );
int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args );
// support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align
// always zero-ended
#endif
 
/programs/develop/ktcc/trunk/libc/include/math.h
0,0 → 1,55
/* Copyright (C) 1999 DJ Delorie, see http://www.delorie.com/copyright.html for details */
/* Copyright (C) 1998 DJ Delorie, see http://www.delorie.com/copyright.html for details */
/* Copyright (C) 1995 DJ Delorie, see http://www.delorie.com/copyright.html for details */
 
#ifndef _MATH_H
#define _MATH_H
 
extern double acos(double _x);
extern double asin(double _x);
extern double atan(double _x);
extern double atan2(double _y, double _x);
extern float ceilf(float);
extern double ceil(double _x);
extern double cos(double _x);
extern double cosh(double _x);
extern double exp(double _x);
extern double exp2(double _x);
extern double fabs(double _x);
extern float fabsf(float);
extern double floor(double _x);
extern float floorf(float);
extern double fmod(double _x, double _y);
extern double frexp(double _x, int *_pexp);
extern double ldexp(double _x, int _exp);
extern double remainder(double, double);
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 float sqrtf(float);
extern double tan(double _x);
extern double tanh(double _x);
extern double round(double x);
extern long double roundl (long double x);
 
#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
 
#endif
/programs/develop/ktcc/trunk/libc/include/tinygl/gl.h
0,0 → 1,838
/*
* The following constants come from Mesa
*/
#ifndef GL_H
#define GL_H
 
#define GL_VERSION_1_1 1
 
#ifdef __cplusplus
extern "C" {
#endif
 
enum {
/* Boolean values */
GL_FALSE = 0,
GL_TRUE = 1,
 
/* Data types */
GL_BYTE = 0x1400,
GL_UNSIGNED_BYTE = 0x1401,
GL_SHORT = 0x1402,
GL_UNSIGNED_SHORT = 0x1403,
GL_INT = 0x1404,
GL_UNSIGNED_INT = 0x1405,
GL_FLOAT = 0x1406,
GL_DOUBLE = 0x140A,
GL_2_BYTES = 0x1407,
GL_3_BYTES = 0x1408,
GL_4_BYTES = 0x1409,
 
/* Primitives */
GL_LINES = 0x0001,
GL_POINTS = 0x0000,
GL_LINE_STRIP = 0x0003,
GL_LINE_LOOP = 0x0002,
GL_TRIANGLES = 0x0004,
GL_TRIANGLE_STRIP = 0x0005,
GL_TRIANGLE_FAN = 0x0006,
GL_QUADS = 0x0007,
GL_QUAD_STRIP = 0x0008,
GL_POLYGON = 0x0009,
GL_EDGE_FLAG = 0x0B43,
 
/* Vertex Arrays */
GL_VERTEX_ARRAY = 0x8074,
GL_NORMAL_ARRAY = 0x8075,
GL_COLOR_ARRAY = 0x8076,
GL_INDEX_ARRAY = 0x8077,
GL_TEXTURE_COORD_ARRAY = 0x8078,
GL_EDGE_FLAG_ARRAY = 0x8079,
GL_VERTEX_ARRAY_SIZE = 0x807A,
GL_VERTEX_ARRAY_TYPE = 0x807B,
GL_VERTEX_ARRAY_STRIDE = 0x807C,
GL_VERTEX_ARRAY_COUNT = 0x807D,
GL_NORMAL_ARRAY_TYPE = 0x807E,
GL_NORMAL_ARRAY_STRIDE = 0x807F,
GL_NORMAL_ARRAY_COUNT = 0x8080,
GL_COLOR_ARRAY_SIZE = 0x8081,
GL_COLOR_ARRAY_TYPE = 0x8082,
GL_COLOR_ARRAY_STRIDE = 0x8083,
GL_COLOR_ARRAY_COUNT = 0x8084,
GL_INDEX_ARRAY_TYPE = 0x8085,
GL_INDEX_ARRAY_STRIDE = 0x8086,
GL_INDEX_ARRAY_COUNT = 0x8087,
GL_TEXTURE_COORD_ARRAY_SIZE = 0x8088,
GL_TEXTURE_COORD_ARRAY_TYPE = 0x8089,
GL_TEXTURE_COORD_ARRAY_STRIDE = 0x808A,
GL_TEXTURE_COORD_ARRAY_COUNT = 0x808B,
GL_EDGE_FLAG_ARRAY_STRIDE = 0x808C,
GL_EDGE_FLAG_ARRAY_COUNT = 0x808D,
GL_VERTEX_ARRAY_POINTER = 0x808E,
GL_NORMAL_ARRAY_POINTER = 0x808F,
GL_COLOR_ARRAY_POINTER = 0x8090,
GL_INDEX_ARRAY_POINTER = 0x8091,
GL_TEXTURE_COORD_ARRAY_POINTER = 0x8092,
GL_EDGE_FLAG_ARRAY_POINTER = 0x8093,
GL_V2F = 0x2A20,
GL_V3F = 0x2A21,
GL_C4UB_V2F = 0x2A22,
GL_C4UB_V3F = 0x2A23,
GL_C3F_V3F = 0x2A24,
GL_N3F_V3F = 0x2A25,
GL_C4F_N3F_V3F = 0x2A26,
GL_T2F_V3F = 0x2A27,
GL_T4F_V4F = 0x2A28,
GL_T2F_C4UB_V3F = 0x2A29,
GL_T2F_C3F_V3F = 0x2A2A,
GL_T2F_N3F_V3F = 0x2A2B,
GL_T2F_C4F_N3F_V3F = 0x2A2C,
GL_T4F_C4F_N3F_V4F = 0x2A2D,
 
/* Matrix Mode */
GL_MATRIX_MODE = 0x0BA0,
GL_MODELVIEW = 0x1700,
GL_PROJECTION = 0x1701,
GL_TEXTURE = 0x1702,
 
/* Points */
GL_POINT_SMOOTH = 0x0B10,
GL_POINT_SIZE = 0x0B11,
GL_POINT_SIZE_GRANULARITY = 0x0B13,
GL_POINT_SIZE_RANGE = 0x0B12,
 
/* Lines */
GL_LINE_SMOOTH = 0x0B20,
GL_LINE_STIPPLE = 0x0B24,
GL_LINE_STIPPLE_PATTERN = 0x0B25,
GL_LINE_STIPPLE_REPEAT = 0x0B26,
GL_LINE_WIDTH = 0x0B21,
GL_LINE_WIDTH_GRANULARITY = 0x0B23,
GL_LINE_WIDTH_RANGE = 0x0B22,
 
/* Polygons */
GL_POINT = 0x1B00,
GL_LINE = 0x1B01,
GL_FILL = 0x1B02,
GL_CCW = 0x0901,
GL_CW = 0x0900,
GL_FRONT = 0x0404,
GL_BACK = 0x0405,
GL_CULL_FACE = 0x0B44,
GL_CULL_FACE_MODE = 0x0B45,
GL_POLYGON_SMOOTH = 0x0B41,
GL_POLYGON_STIPPLE = 0x0B42,
GL_FRONT_FACE = 0x0B46,
GL_POLYGON_MODE = 0x0B40,
GL_POLYGON_OFFSET_FACTOR = 0x3038,
GL_POLYGON_OFFSET_UNITS = 0x2A00,
GL_POLYGON_OFFSET_POINT = 0x2A01,
GL_POLYGON_OFFSET_LINE = 0x2A02,
GL_POLYGON_OFFSET_FILL = 0x8037,
 
/* Display Lists */
GL_COMPILE = 0x1300,
GL_COMPILE_AND_EXECUTE = 0x1301,
GL_LIST_BASE = 0x0B32,
GL_LIST_INDEX = 0x0B33,
GL_LIST_MODE = 0x0B30,
 
/* Depth buffer */
GL_NEVER = 0x0200,
GL_LESS = 0x0201,
GL_GEQUAL = 0x0206,
GL_LEQUAL = 0x0203,
GL_GREATER = 0x0204,
GL_NOTEQUAL = 0x0205,
GL_EQUAL = 0x0202,
GL_ALWAYS = 0x0207,
GL_DEPTH_TEST = 0x0B71,
GL_DEPTH_BITS = 0x0D56,
GL_DEPTH_CLEAR_VALUE = 0x0B73,
GL_DEPTH_FUNC = 0x0B74,
GL_DEPTH_RANGE = 0x0B70,
GL_DEPTH_WRITEMASK = 0x0B72,
GL_DEPTH_COMPONENT = 0x1902,
 
/* Lighting */
GL_LIGHTING = 0x0B50,
GL_LIGHT0 = 0x4000,
GL_LIGHT1 = 0x4001,
GL_LIGHT2 = 0x4002,
GL_LIGHT3 = 0x4003,
GL_LIGHT4 = 0x4004,
GL_LIGHT5 = 0x4005,
GL_LIGHT6 = 0x4006,
GL_LIGHT7 = 0x4007,
GL_SPOT_EXPONENT = 0x1205,
GL_SPOT_CUTOFF = 0x1206,
GL_CONSTANT_ATTENUATION = 0x1207,
GL_LINEAR_ATTENUATION = 0x1208,
GL_QUADRATIC_ATTENUATION = 0x1209,
GL_AMBIENT = 0x1200,
GL_DIFFUSE = 0x1201,
GL_SPECULAR = 0x1202,
GL_SHININESS = 0x1601,
GL_EMISSION = 0x1600,
GL_POSITION = 0x1203,
GL_SPOT_DIRECTION = 0x1204,
GL_AMBIENT_AND_DIFFUSE = 0x1602,
GL_COLOR_INDEXES = 0x1603,
GL_LIGHT_MODEL_TWO_SIDE = 0x0B52,
GL_LIGHT_MODEL_LOCAL_VIEWER = 0x0B51,
GL_LIGHT_MODEL_AMBIENT = 0x0B53,
GL_FRONT_AND_BACK = 0x0408,
GL_SHADE_MODEL = 0x0B54,
GL_FLAT = 0x1D00,
GL_SMOOTH = 0x1D01,
GL_COLOR_MATERIAL = 0x0B57,
GL_COLOR_MATERIAL_FACE = 0x0B55,
GL_COLOR_MATERIAL_PARAMETER = 0x0B56,
GL_NORMALIZE = 0x0BA1,
 
/* User clipping planes */
GL_CLIP_PLANE0 = 0x3000,
GL_CLIP_PLANE1 = 0x3001,
GL_CLIP_PLANE2 = 0x3002,
GL_CLIP_PLANE3 = 0x3003,
GL_CLIP_PLANE4 = 0x3004,
GL_CLIP_PLANE5 = 0x3005,
 
/* Accumulation buffer */
GL_ACCUM_RED_BITS = 0x0D58,
GL_ACCUM_GREEN_BITS = 0x0D59,
GL_ACCUM_BLUE_BITS = 0x0D5A,
GL_ACCUM_ALPHA_BITS = 0x0D5B,
GL_ACCUM_CLEAR_VALUE = 0x0B80,
GL_ACCUM = 0x0100,
GL_ADD = 0x0104,
GL_LOAD = 0x0101,
GL_MULT = 0x0103,
GL_RETURN = 0x0102,
 
/* Alpha testing */
GL_ALPHA_TEST = 0x0BC0,
GL_ALPHA_TEST_REF = 0x0BC2,
GL_ALPHA_TEST_FUNC = 0x0BC1,
 
/* Blending */
GL_BLEND = 0x0BE2,
GL_BLEND_SRC = 0x0BE1,
GL_BLEND_DST = 0x0BE0,
GL_ZERO = 0,
GL_ONE = 1,
GL_SRC_COLOR = 0x0300,
GL_ONE_MINUS_SRC_COLOR = 0x0301,
GL_DST_COLOR = 0x0306,
GL_ONE_MINUS_DST_COLOR = 0x0307,
GL_SRC_ALPHA = 0x0302,
GL_ONE_MINUS_SRC_ALPHA = 0x0303,
GL_DST_ALPHA = 0x0304,
GL_ONE_MINUS_DST_ALPHA = 0x0305,
GL_SRC_ALPHA_SATURATE = 0x0308,
GL_CONSTANT_COLOR = 0x8001,
GL_ONE_MINUS_CONSTANT_COLOR = 0x8002,
GL_CONSTANT_ALPHA = 0x8003,
GL_ONE_MINUS_CONSTANT_ALPHA = 0x8004,
 
/* Render Mode */
GL_FEEDBACK = 0x1C01,
GL_RENDER = 0x1C00,
GL_SELECT = 0x1C02,
 
/* Feedback */
GL_2D = 0x0600,
GL_3D = 0x0601,
GL_3D_COLOR = 0x0602,
GL_3D_COLOR_TEXTURE = 0x0603,
GL_4D_COLOR_TEXTURE = 0x0604,
GL_POINT_TOKEN = 0x0701,
GL_LINE_TOKEN = 0x0702,
GL_LINE_RESET_TOKEN = 0x0707,
GL_POLYGON_TOKEN = 0x0703,
GL_BITMAP_TOKEN = 0x0704,
GL_DRAW_PIXEL_TOKEN = 0x0705,
GL_COPY_PIXEL_TOKEN = 0x0706,
GL_PASS_THROUGH_TOKEN = 0x0700,
 
/* Fog */
GL_FOG = 0x0B60,
GL_FOG_MODE = 0x0B65,
GL_FOG_DENSITY = 0x0B62,
GL_FOG_COLOR = 0x0B66,
GL_FOG_INDEX = 0x0B61,
GL_FOG_START = 0x0B63,
GL_FOG_END = 0x0B64,
GL_LINEAR = 0x2601,
GL_EXP = 0x0800,
GL_EXP2 = 0x0801,
 
/* Logic Ops */
GL_LOGIC_OP = 0x0BF1,
GL_LOGIC_OP_MODE = 0x0BF0,
GL_CLEAR = 0x1500,
GL_SET = 0x150F,
GL_COPY = 0x1503,
GL_COPY_INVERTED = 0x150C,
GL_NOOP = 0x1505,
GL_INVERT = 0x150A,
GL_AND = 0x1501,
GL_NAND = 0x150E,
GL_OR = 0x1507,
GL_NOR = 0x1508,
GL_XOR = 0x1506,
GL_EQUIV = 0x1509,
GL_AND_REVERSE = 0x1502,
GL_AND_INVERTED = 0x1504,
GL_OR_REVERSE = 0x150B,
GL_OR_INVERTED = 0x150D,
 
/* Stencil */
GL_STENCIL_TEST = 0x0B90,
GL_STENCIL_WRITEMASK = 0x0B98,
GL_STENCIL_BITS = 0x0D57,
GL_STENCIL_FUNC = 0x0B92,
GL_STENCIL_VALUE_MASK = 0x0B93,
GL_STENCIL_REF = 0x0B97,
GL_STENCIL_FAIL = 0x0B94,
GL_STENCIL_PASS_DEPTH_PASS = 0x0B96,
GL_STENCIL_PASS_DEPTH_FAIL = 0x0B95,
GL_STENCIL_CLEAR_VALUE = 0x0B91,
GL_STENCIL_INDEX = 0x1901,
GL_KEEP = 0x1E00,
GL_REPLACE = 0x1E01,
GL_INCR = 0x1E02,
GL_DECR = 0x1E03,
 
/* Buffers, Pixel Drawing/Reading */
GL_NONE = 0,
GL_LEFT = 0x0406,
GL_RIGHT = 0x0407,
/*GL_FRONT = 0x0404, */
/*GL_BACK = 0x0405, */
/*GL_FRONT_AND_BACK = 0x0408, */
GL_FRONT_LEFT = 0x0400,
GL_FRONT_RIGHT = 0x0401,
GL_BACK_LEFT = 0x0402,
GL_BACK_RIGHT = 0x0403,
GL_AUX0 = 0x0409,
GL_AUX1 = 0x040A,
GL_AUX2 = 0x040B,
GL_AUX3 = 0x040C,
GL_COLOR_INDEX = 0x1900,
GL_RED = 0x1903,
GL_GREEN = 0x1904,
GL_BLUE = 0x1905,
GL_ALPHA = 0x1906,
GL_LUMINANCE = 0x1909,
GL_LUMINANCE_ALPHA = 0x190A,
GL_ALPHA_BITS = 0x0D55,
GL_RED_BITS = 0x0D52,
GL_GREEN_BITS = 0x0D53,
GL_BLUE_BITS = 0x0D54,
GL_INDEX_BITS = 0x0D51,
GL_SUBPIXEL_BITS = 0x0D50,
GL_AUX_BUFFERS = 0x0C00,
GL_READ_BUFFER = 0x0C02,
GL_DRAW_BUFFER = 0x0C01,
GL_DOUBLEBUFFER = 0x0C32,
GL_STEREO = 0x0C33,
GL_BITMAP = 0x1A00,
GL_COLOR = 0x1800,
GL_DEPTH = 0x1801,
GL_STENCIL = 0x1802,
GL_DITHER = 0x0BD0,
GL_RGB = 0x1907,
GL_RGBA = 0x1908,
 
/* Implementation limits */
GL_MAX_LIST_NESTING = 0x0B31,
GL_MAX_ATTRIB_STACK_DEPTH = 0x0D35,
GL_MAX_MODELVIEW_STACK_DEPTH = 0x0D36,
GL_MAX_NAME_STACK_DEPTH = 0x0D37,
GL_MAX_PROJECTION_STACK_DEPTH = 0x0D38,
GL_MAX_TEXTURE_STACK_DEPTH = 0x0D39,
GL_MAX_EVAL_ORDER = 0x0D30,
GL_MAX_LIGHTS = 0x0D31,
GL_MAX_CLIP_PLANES = 0x0D32,
GL_MAX_TEXTURE_SIZE = 0x0D33,
GL_MAX_PIXEL_MAP_TABLE = 0x0D34,
GL_MAX_VIEWPORT_DIMS = 0x0D3A,
GL_MAX_CLIENT_ATTRIB_STACK_DEPTH= 0x0D3B,
 
/* Gets */
GL_ATTRIB_STACK_DEPTH = 0x0BB0,
GL_COLOR_CLEAR_VALUE = 0x0C22,
GL_COLOR_WRITEMASK = 0x0C23,
GL_CURRENT_INDEX = 0x0B01,
GL_CURRENT_COLOR = 0x0B00,
GL_CURRENT_NORMAL = 0x0B02,
GL_CURRENT_RASTER_COLOR = 0x0B04,
GL_CURRENT_RASTER_DISTANCE = 0x0B09,
GL_CURRENT_RASTER_INDEX = 0x0B05,
GL_CURRENT_RASTER_POSITION = 0x0B07,
GL_CURRENT_RASTER_TEXTURE_COORDS = 0x0B06,
GL_CURRENT_RASTER_POSITION_VALID = 0x0B08,
GL_CURRENT_TEXTURE_COORDS = 0x0B03,
GL_INDEX_CLEAR_VALUE = 0x0C20,
GL_INDEX_MODE = 0x0C30,
GL_INDEX_WRITEMASK = 0x0C21,
GL_MODELVIEW_MATRIX = 0x0BA6,
GL_MODELVIEW_STACK_DEPTH = 0x0BA3,
GL_NAME_STACK_DEPTH = 0x0D70,
GL_PROJECTION_MATRIX = 0x0BA7,
GL_PROJECTION_STACK_DEPTH = 0x0BA4,
GL_RENDER_MODE = 0x0C40,
GL_RGBA_MODE = 0x0C31,
GL_TEXTURE_MATRIX = 0x0BA8,
GL_TEXTURE_STACK_DEPTH = 0x0BA5,
GL_VIEWPORT = 0x0BA2,
 
 
/* Evaluators */
GL_AUTO_NORMAL = 0x0D80,
GL_MAP1_COLOR_4 = 0x0D90,
GL_MAP1_GRID_DOMAIN = 0x0DD0,
GL_MAP1_GRID_SEGMENTS = 0x0DD1,
GL_MAP1_INDEX = 0x0D91,
GL_MAP1_NORMAL = 0x0D92,
GL_MAP1_TEXTURE_COORD_1 = 0x0D93,
GL_MAP1_TEXTURE_COORD_2 = 0x0D94,
GL_MAP1_TEXTURE_COORD_3 = 0x0D95,
GL_MAP1_TEXTURE_COORD_4 = 0x0D96,
GL_MAP1_VERTEX_3 = 0x0D97,
GL_MAP1_VERTEX_4 = 0x0D98,
GL_MAP2_COLOR_4 = 0x0DB0,
GL_MAP2_GRID_DOMAIN = 0x0DD2,
GL_MAP2_GRID_SEGMENTS = 0x0DD3,
GL_MAP2_INDEX = 0x0DB1,
GL_MAP2_NORMAL = 0x0DB2,
GL_MAP2_TEXTURE_COORD_1 = 0x0DB3,
GL_MAP2_TEXTURE_COORD_2 = 0x0DB4,
GL_MAP2_TEXTURE_COORD_3 = 0x0DB5,
GL_MAP2_TEXTURE_COORD_4 = 0x0DB6,
GL_MAP2_VERTEX_3 = 0x0DB7,
GL_MAP2_VERTEX_4 = 0x0DB8,
GL_COEFF = 0x0A00,
GL_DOMAIN = 0x0A02,
GL_ORDER = 0x0A01,
 
/* Hints */
GL_FOG_HINT = 0x0C54,
GL_LINE_SMOOTH_HINT = 0x0C52,
GL_PERSPECTIVE_CORRECTION_HINT = 0x0C50,
GL_POINT_SMOOTH_HINT = 0x0C51,
GL_POLYGON_SMOOTH_HINT = 0x0C53,
GL_DONT_CARE = 0x1100,
GL_FASTEST = 0x1101,
GL_NICEST = 0x1102,
 
/* Scissor box */
GL_SCISSOR_TEST = 0x0C11,
GL_SCISSOR_BOX = 0x0C10,
 
/* Pixel Mode / Transfer */
GL_MAP_COLOR = 0x0D10,
GL_MAP_STENCIL = 0x0D11,
GL_INDEX_SHIFT = 0x0D12,
GL_INDEX_OFFSET = 0x0D13,
GL_RED_SCALE = 0x0D14,
GL_RED_BIAS = 0x0D15,
GL_GREEN_SCALE = 0x0D18,
GL_GREEN_BIAS = 0x0D19,
GL_BLUE_SCALE = 0x0D1A,
GL_BLUE_BIAS = 0x0D1B,
GL_ALPHA_SCALE = 0x0D1C,
GL_ALPHA_BIAS = 0x0D1D,
GL_DEPTH_SCALE = 0x0D1E,
GL_DEPTH_BIAS = 0x0D1F,
GL_PIXEL_MAP_S_TO_S_SIZE = 0x0CB1,
GL_PIXEL_MAP_I_TO_I_SIZE = 0x0CB0,
GL_PIXEL_MAP_I_TO_R_SIZE = 0x0CB2,
GL_PIXEL_MAP_I_TO_G_SIZE = 0x0CB3,
GL_PIXEL_MAP_I_TO_B_SIZE = 0x0CB4,
GL_PIXEL_MAP_I_TO_A_SIZE = 0x0CB5,
GL_PIXEL_MAP_R_TO_R_SIZE = 0x0CB6,
GL_PIXEL_MAP_G_TO_G_SIZE = 0x0CB7,
GL_PIXEL_MAP_B_TO_B_SIZE = 0x0CB8,
GL_PIXEL_MAP_A_TO_A_SIZE = 0x0CB9,
GL_PIXEL_MAP_S_TO_S = 0x0C71,
GL_PIXEL_MAP_I_TO_I = 0x0C70,
GL_PIXEL_MAP_I_TO_R = 0x0C72,
GL_PIXEL_MAP_I_TO_G = 0x0C73,
GL_PIXEL_MAP_I_TO_B = 0x0C74,
GL_PIXEL_MAP_I_TO_A = 0x0C75,
GL_PIXEL_MAP_R_TO_R = 0x0C76,
GL_PIXEL_MAP_G_TO_G = 0x0C77,
GL_PIXEL_MAP_B_TO_B = 0x0C78,
GL_PIXEL_MAP_A_TO_A = 0x0C79,
GL_PACK_ALIGNMENT = 0x0D05,
GL_PACK_LSB_FIRST = 0x0D01,
GL_PACK_ROW_LENGTH = 0x0D02,
GL_PACK_SKIP_PIXELS = 0x0D04,
GL_PACK_SKIP_ROWS = 0x0D03,
GL_PACK_SWAP_BYTES = 0x0D00,
GL_UNPACK_ALIGNMENT = 0x0CF5,
GL_UNPACK_LSB_FIRST = 0x0CF1,
GL_UNPACK_ROW_LENGTH = 0x0CF2,
GL_UNPACK_SKIP_PIXELS = 0x0CF4,
GL_UNPACK_SKIP_ROWS = 0x0CF3,
GL_UNPACK_SWAP_BYTES = 0x0CF0,
GL_ZOOM_X = 0x0D16,
GL_ZOOM_Y = 0x0D17,
 
/* Texture mapping */
GL_TEXTURE_ENV = 0x2300,
GL_TEXTURE_ENV_MODE = 0x2200,
GL_TEXTURE_1D = 0x0DE0,
GL_TEXTURE_2D = 0x0DE1,
GL_TEXTURE_WRAP_S = 0x2802,
GL_TEXTURE_WRAP_T = 0x2803,
GL_TEXTURE_MAG_FILTER = 0x2800,
GL_TEXTURE_MIN_FILTER = 0x2801,
GL_TEXTURE_ENV_COLOR = 0x2201,
GL_TEXTURE_GEN_S = 0x0C60,
GL_TEXTURE_GEN_T = 0x0C61,
GL_TEXTURE_GEN_MODE = 0x2500,
GL_TEXTURE_BORDER_COLOR = 0x1004,
GL_TEXTURE_WIDTH = 0x1000,
GL_TEXTURE_HEIGHT = 0x1001,
GL_TEXTURE_BORDER = 0x1005,
GL_TEXTURE_COMPONENTS = 0x1003,
GL_NEAREST_MIPMAP_NEAREST = 0x2700,
GL_NEAREST_MIPMAP_LINEAR = 0x2702,
GL_LINEAR_MIPMAP_NEAREST = 0x2701,
GL_LINEAR_MIPMAP_LINEAR = 0x2703,
GL_OBJECT_LINEAR = 0x2401,
GL_OBJECT_PLANE = 0x2501,
GL_EYE_LINEAR = 0x2400,
GL_EYE_PLANE = 0x2502,
GL_SPHERE_MAP = 0x2402,
GL_DECAL = 0x2101,
GL_MODULATE = 0x2100,
GL_NEAREST = 0x2600,
GL_REPEAT = 0x2901,
GL_CLAMP = 0x2900,
GL_S = 0x2000,
GL_T = 0x2001,
GL_R = 0x2002,
GL_Q = 0x2003,
GL_TEXTURE_GEN_R = 0x0C62,
GL_TEXTURE_GEN_Q = 0x0C63,
 
GL_PROXY_TEXTURE_1D = 0x8063,
GL_PROXY_TEXTURE_2D = 0x8064,
GL_TEXTURE_PRIORITY = 0x8066,
GL_TEXTURE_RESIDENT = 0x8067,
GL_TEXTURE_1D_BINDING = 0x8068,
GL_TEXTURE_2D_BINDING = 0x8069,
 
/* Internal texture formats */
GL_ALPHA4 = 0x803B,
GL_ALPHA8 = 0x803C,
GL_ALPHA12 = 0x803D,
GL_ALPHA16 = 0x803E,
GL_LUMINANCE4 = 0x803F,
GL_LUMINANCE8 = 0x8040,
GL_LUMINANCE12 = 0x8041,
GL_LUMINANCE16 = 0x8042,
GL_LUMINANCE4_ALPHA4 = 0x8043,
GL_LUMINANCE6_ALPHA2 = 0x8044,
GL_LUMINANCE8_ALPHA8 = 0x8045,
GL_LUMINANCE12_ALPHA4 = 0x8046,
GL_LUMINANCE12_ALPHA12 = 0x8047,
GL_LUMINANCE16_ALPHA16 = 0x8048,
GL_INTENSITY = 0x8049,
GL_INTENSITY4 = 0x804A,
GL_INTENSITY8 = 0x804B,
GL_INTENSITY12 = 0x804C,
GL_INTENSITY16 = 0x804D,
GL_R3_G3_B2 = 0x2A10,
GL_RGB4 = 0x804F,
GL_RGB5 = 0x8050,
GL_RGB8 = 0x8051,
GL_RGB10 = 0x8052,
GL_RGB12 = 0x8053,
GL_RGB16 = 0x8054,
GL_RGBA2 = 0x8055,
GL_RGBA4 = 0x8056,
GL_RGB5_A1 = 0x8057,
GL_RGBA8 = 0x8058,
GL_RGB10_A2 = 0x8059,
GL_RGBA12 = 0x805A,
GL_RGBA16 = 0x805B,
 
/* Utility */
GL_VENDOR = 0x1F00,
GL_RENDERER = 0x1F01,
GL_VERSION = 0x1F02,
GL_EXTENSIONS = 0x1F03,
 
/* Errors */
GL_INVALID_VALUE = 0x0501,
GL_INVALID_ENUM = 0x0500,
GL_INVALID_OPERATION = 0x0502,
GL_STACK_OVERFLOW = 0x0503,
GL_STACK_UNDERFLOW = 0x0504,
GL_OUT_OF_MEMORY = 0x0505,
 
/*
* 1.0 Extensions
*/
/* GL_EXT_blend_minmax and GL_EXT_blend_color */
GL_CONSTANT_COLOR_EXT = 0x8001,
GL_ONE_MINUS_CONSTANT_COLOR_EXT = 0x8002,
GL_CONSTANT_ALPHA_EXT = 0x8003,
GL_ONE_MINUS_CONSTANT_ALPHA_EXT = 0x8004,
GL_BLEND_EQUATION_EXT = 0x8009,
GL_MIN_EXT = 0x8007,
GL_MAX_EXT = 0x8008,
GL_FUNC_ADD_EXT = 0x8006,
GL_FUNC_SUBTRACT_EXT = 0x800A,
GL_FUNC_REVERSE_SUBTRACT_EXT = 0x800B,
GL_BLEND_COLOR_EXT = 0x8005,
 
/* GL_EXT_polygon_offset */
GL_POLYGON_OFFSET_EXT = 0x8037,
GL_POLYGON_OFFSET_FACTOR_EXT = 0x8038,
GL_POLYGON_OFFSET_BIAS_EXT = 0x8039,
 
/* GL_EXT_vertex_array */
GL_VERTEX_ARRAY_EXT = 0x8074,
GL_NORMAL_ARRAY_EXT = 0x8075,
GL_COLOR_ARRAY_EXT = 0x8076,
GL_INDEX_ARRAY_EXT = 0x8077,
GL_TEXTURE_COORD_ARRAY_EXT = 0x8078,
GL_EDGE_FLAG_ARRAY_EXT = 0x8079,
GL_VERTEX_ARRAY_SIZE_EXT = 0x807A,
GL_VERTEX_ARRAY_TYPE_EXT = 0x807B,
GL_VERTEX_ARRAY_STRIDE_EXT = 0x807C,
GL_VERTEX_ARRAY_COUNT_EXT = 0x807D,
GL_NORMAL_ARRAY_TYPE_EXT = 0x807E,
GL_NORMAL_ARRAY_STRIDE_EXT = 0x807F,
GL_NORMAL_ARRAY_COUNT_EXT = 0x8080,
GL_COLOR_ARRAY_SIZE_EXT = 0x8081,
GL_COLOR_ARRAY_TYPE_EXT = 0x8082,
GL_COLOR_ARRAY_STRIDE_EXT = 0x8083,
GL_COLOR_ARRAY_COUNT_EXT = 0x8084,
GL_INDEX_ARRAY_TYPE_EXT = 0x8085,
GL_INDEX_ARRAY_STRIDE_EXT = 0x8086,
GL_INDEX_ARRAY_COUNT_EXT = 0x8087,
GL_TEXTURE_COORD_ARRAY_SIZE_EXT = 0x8088,
GL_TEXTURE_COORD_ARRAY_TYPE_EXT = 0x8089,
GL_TEXTURE_COORD_ARRAY_STRIDE_EXT= 0x808A,
GL_TEXTURE_COORD_ARRAY_COUNT_EXT= 0x808B,
GL_EDGE_FLAG_ARRAY_STRIDE_EXT = 0x808C,
GL_EDGE_FLAG_ARRAY_COUNT_EXT = 0x808D,
GL_VERTEX_ARRAY_POINTER_EXT = 0x808E,
GL_NORMAL_ARRAY_POINTER_EXT = 0x808F,
GL_COLOR_ARRAY_POINTER_EXT = 0x8090,
GL_INDEX_ARRAY_POINTER_EXT = 0x8091,
GL_TEXTURE_COORD_ARRAY_POINTER_EXT= 0x8092,
GL_EDGE_FLAG_ARRAY_POINTER_EXT = 0x8093
 
};
 
enum {
GL_CURRENT_BIT = 0x00000001,
GL_POINT_BIT = 0x00000002,
GL_LINE_BIT = 0x00000004,
GL_POLYGON_BIT = 0x00000008,
GL_POLYGON_STIPPLE_BIT = 0x00000010,
GL_PIXEL_MODE_BIT = 0x00000020,
GL_LIGHTING_BIT = 0x00000040,
GL_FOG_BIT = 0x00000080,
GL_DEPTH_BUFFER_BIT = 0x00000100,
GL_ACCUM_BUFFER_BIT = 0x00000200,
GL_STENCIL_BUFFER_BIT = 0x00000400,
GL_VIEWPORT_BIT = 0x00000800,
GL_TRANSFORM_BIT = 0x00001000,
GL_ENABLE_BIT = 0x00002000,
GL_COLOR_BUFFER_BIT = 0x00004000,
GL_HINT_BIT = 0x00008000,
GL_EVAL_BIT = 0x00010000,
GL_LIST_BIT = 0x00020000,
GL_TEXTURE_BIT = 0x00040000,
GL_SCISSOR_BIT = 0x00080000,
GL_ALL_ATTRIB_BITS = 0x000fffff
};
 
/* some types */
 
typedef int GLenum;
typedef void GLvoid;
typedef unsigned char GLboolean;
typedef signed char GLbyte; /* 1-byte signed */
typedef short GLshort; /* 2-byte signed */
typedef int GLint; /* 4-byte signed */
typedef unsigned char GLubyte; /* 1-byte unsigned */
typedef unsigned short GLushort; /* 2-byte unsigned */
typedef unsigned int GLuint; /* 4-byte unsigned */
typedef float GLfloat; /* single precision float */
typedef double GLdouble; /* double precision float */
typedef int GLsizei;
 
/* functions */
 
void glEnable(int code);
void glDisable(int code);
 
void glShadeModel(int mode);
void glCullFace(int mode);
void glPolygonMode(int face,int mode);
 
void glBegin(int type);
void glEnd(void);
 
#define PROTO_GL1(name) \
void gl ## name ## 1f(float); \
void gl ## name ## 1d(double); \
void gl ## name ## 1fv(float *); \
void gl ## name ## 1dv(double *);
 
#define PROTO_GL2(name) \
void gl ## name ## 2f(float ,float); \
void gl ## name ## 2d(double ,double); \
void gl ## name ## 2fv(float *); \
void gl ## name ## 2dv(double *);
 
#define PROTO_GL3(name) \
void gl ## name ## 3f(float ,float ,float); \
void gl ## name ## 3d(double ,double ,double); \
void gl ## name ## 3fv(float *); \
void gl ## name ## 3dv(double *);
 
#define PROTO_GL4(name) \
void gl ## name ## 4f(float ,float ,float, float ); \
void gl ## name ## 4d(double ,double ,double, double ); \
void gl ## name ## 4fv(float *); \
void gl ## name ## 4dv(double *);
 
PROTO_GL2(Vertex)
PROTO_GL3(Vertex)
PROTO_GL4(Vertex)
 
PROTO_GL3(Color)
PROTO_GL4(Color)
 
PROTO_GL3(Normal)
 
PROTO_GL1(TexCoord)
PROTO_GL2(TexCoord)
PROTO_GL3(TexCoord)
PROTO_GL4(TexCoord)
 
void glEdgeFlag(int flag);
 
/* matrix */
void glMatrixMode(int mode);
void glLoadMatrixf(const float *m);
void glLoadIdentity(void);
void glMultMatrixf(const float *m);
void glPushMatrix(void);
void glPopMatrix(void);
void glRotatef(float angle,float x,float y,float z);
void glTranslatef(float x,float y,float z);
void glScalef(float x,float y,float z);
 
void glViewport(int x,int y,int width,int height);
void glFrustum(double left,double right,double bottom,double top,
double near_,double far_);
 
/* lists */
unsigned int glGenLists(int range);
int glIsList(unsigned int list);
void glNewList(unsigned int list,int mode);
void glEndList(void);
void glCallList(unsigned int list);
 
/* clear */
void glClear(int mask);
void glClearColor(float r,float g,float b,float a);
void glClearDepth(double depth);
 
/* selection */
int glRenderMode(int mode);
void glSelectBuffer(int size,unsigned int *buf);
 
void glInitNames(void);
void glPushName(unsigned int name);
void glPopName(void);
void glLoadName(unsigned int name);
 
/* textures */
void glGenTextures(int n, unsigned int *textures);
void glDeleteTextures(int n, const unsigned int *textures);
void glBindTexture(int target,int texture);
void glTexImage2D( int target, int level, int components,
int width, int height, int border,
int format, int type, void *pixels);
void glTexEnvi(int target,int pname,int param);
void glTexParameteri(int target,int pname,int param);
void glPixelStorei(int pname,int param);
 
/* lighting */
 
void glMaterialfv(int mode,int type,float *v);
void glMaterialf(int mode,int type,float v);
void glColorMaterial(int mode,int type);
 
void glLightfv(int light,int type,float *v);
void glLightf(int light,int type,float v);
void glLightModeli(int pname,int param);
void glLightModelfv(int pname,float *param);
 
/* misc */
 
void glFlush(void);
void glHint(int target,int mode);
void glGetIntegerv(int pname,int *params);
void glGetFloatv(int pname, float *v);
void glFrontFace(int mode);
 
/* opengl 1.2 arrays */
void glEnableClientState(GLenum array);
void glDisableClientState(GLenum array);
void glArrayElement(GLint i);
void glVertexPointer(GLint size, GLenum type, GLsizei stride,
const GLvoid *pointer);
void glColorPointer(GLint size, GLenum type, GLsizei stride,
const GLvoid *pointer);
void glNormalPointer(GLenum type, GLsizei stride,
const GLvoid *pointer);
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride,
const GLvoid *pointer);
 
/* opengl 1.2 polygon offset */
void glPolygonOffset(GLfloat factor, GLfloat units);
 
/* not implemented, just added to compile */
/*
inline void glPointSize(float) {}
inline void glLineWidth(float) {}
inline void glDeleteLists(int, int) {}
inline void glDepthFunc(int) {}
inline void glBlendFunc(int, int) {}
inline void glTexEnvf(int, int, int) {}
inline void glOrtho(float,float,float,float,float,float){}
inline void glVertex2i(int,int) {}
inline void glDepthMask(int) {}
inline void glFogi(int, int) {}
inline void glFogfv(int, const float*) {}
inline void glFogf(int, float) {}
inline void glRasterPos2f(float, float) {}
inline void glPolygonStipple(void*) {}
inline void glTexParameterf(int, int, int) {};
*/
/* non compatible functions */
 
void glDebug(int mode);
 
void glInit(void *zbuffer);
void glClose(void);
 
#ifdef __cplusplus
}
#endif
 
#endif
/programs/develop/ktcc/trunk/libc/include/tinygl/glu.h
0,0 → 1,44
 
#ifndef GLU_H
#define GLU_H
 
#ifdef __cplusplus
extern "C" {
#endif
 
void gluPerspective( GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar );
 
void
gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz);
 
 
void drawTorus(float rc, int numc, float rt, int numt);
 
 
 
typedef struct {
int draw_style;
} GLUquadricObj;
 
#define GLU_LINE 0
 
GLUquadricObj* gluNewQuadric(void);
void gluQuadricDrawStyle(GLUquadricObj *obj, int style);
 
void gluSphere(GLUquadricObj *qobj,
float radius,int slices,int stacks);
void gluCylinder( GLUquadricObj *qobj,
GLdouble baseRadius, GLdouble topRadius, GLdouble height,
GLint slices, GLint stacks );
void gluDisk( GLUquadricObj *qobj,
GLdouble innerRadius, GLdouble outerRadius,
GLint slices, GLint loops );
 
 
#ifdef __cplusplus
}
#endif
#endif
/programs/develop/ktcc/trunk/libc/include/tinygl/kosgl.h
0,0 → 1,28
#ifndef KOSGL_H
#define KOSGL_H
 
#include "gl.h"
#include "glu.h"
 
 
#ifdef __cplusplus
extern "C" {
#endif
 
typedef void *KOSGLContext;
 
extern KOSGLContext kosglCreateContext( KOSGLContext shareList, int flags );
 
extern void kosglDestroyContext( KOSGLContext ctx1 );
 
extern int kosglMakeCurrent( int win_x0, int win_y0,
int win_x, int win_y,
KOSGLContext ctx);
 
extern void kosglSwapBuffers();
 
#ifdef __cplusplus
}
#endif
 
#endif
/programs/develop/ktcc/trunk/libc/include/getopt.h
0,0 → 1,9
#ifndef GETOPT_H
#define GETOPT_H
 
extern int optind, opterr;
extern char *optarg;
 
int getopt(int argc, char *argv[], char *optstring);
 
#endif
/programs/develop/ktcc/trunk/libc/include/cryptal/aes.h
0,0 → 1,123
/*********************************************************************
* Filename: aes.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding AES implementation.
*********************************************************************/
 
#ifndef AES_H
#define AES_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define AES_BLOCK_SIZE 16 // AES operates on 16 bytes at a time
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
 
/*********************** FUNCTION DECLARATIONS **********************/
///////////////////
// AES
///////////////////
// Key setup must be done before any AES en/de-cryption functions can be used.
void aes_key_setup(const BYTE key[], // The key, must be 128, 192, or 256 bits
WORD w[], // Output key schedule to be used later
int keysize); // Bit length of the key, 128, 192, or 256
 
void aes_encrypt(const BYTE in[], // 16 bytes of plaintext
BYTE out[], // 16 bytes of ciphertext
const WORD key[], // From the key setup
int keysize); // Bit length of the key, 128, 192, or 256
 
void aes_decrypt(const BYTE in[], // 16 bytes of ciphertext
BYTE out[], // 16 bytes of plaintext
const WORD key[], // From the key setup
int keysize); // Bit length of the key, 128, 192, or 256
 
///////////////////
// AES - CBC
///////////////////
int aes_encrypt_cbc(const BYTE in[], // Plaintext
size_t in_len, // Must be a multiple of AES_BLOCK_SIZE
BYTE out[], // Ciphertext, same length as plaintext
const WORD key[], // From the key setup
int keysize, // Bit length of the key, 128, 192, or 256
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
 
// Only output the CBC-MAC of the input.
int aes_encrypt_cbc_mac(const BYTE in[], // plaintext
size_t in_len, // Must be a multiple of AES_BLOCK_SIZE
BYTE out[], // Output MAC
const WORD key[], // From the key setup
int keysize, // Bit length of the key, 128, 192, or 256
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
 
///////////////////
// AES - CTR
///////////////////
void increment_iv(BYTE iv[], // Must be a multiple of AES_BLOCK_SIZE
int counter_size); // Bytes of the IV used for counting (low end)
 
void aes_encrypt_ctr(const BYTE in[], // Plaintext
size_t in_len, // Any byte length
BYTE out[], // Ciphertext, same length as plaintext
const WORD key[], // From the key setup
int keysize, // Bit length of the key, 128, 192, or 256
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
 
void aes_decrypt_ctr(const BYTE in[], // Ciphertext
size_t in_len, // Any byte length
BYTE out[], // Plaintext, same length as ciphertext
const WORD key[], // From the key setup
int keysize, // Bit length of the key, 128, 192, or 256
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
 
///////////////////
// AES - CCM
///////////////////
// Returns True if the input parameters do not violate any constraint.
int aes_encrypt_ccm(const BYTE plaintext[], // IN - Plaintext.
WORD plaintext_len, // IN - Plaintext length.
const BYTE associated_data[], // IN - Associated Data included in authentication, but not encryption.
unsigned short associated_data_len, // IN - Associated Data length in bytes.
const BYTE nonce[], // IN - The Nonce to be used for encryption.
unsigned short nonce_len, // IN - Nonce length in bytes.
BYTE ciphertext[], // OUT - Ciphertext, a concatination of the plaintext and the MAC.
WORD *ciphertext_len, // OUT - The length of the ciphertext, always plaintext_len + mac_len.
WORD mac_len, // IN - The desired length of the MAC, must be 4, 6, 8, 10, 12, 14, or 16.
const BYTE key[], // IN - The AES key for encryption.
int keysize); // IN - The length of the key in bits. Valid values are 128, 192, 256.
 
// Returns True if the input parameters do not violate any constraint.
// Use mac_auth to ensure decryption/validation was preformed correctly.
// If authentication does not succeed, the plaintext is zeroed out. To overwride
// this, call with mac_auth = NULL. The proper proceedure is to decrypt with
// authentication enabled (mac_auth != NULL) and make a second call to that
// ignores authentication explicitly if the first call failes.
int aes_decrypt_ccm(const BYTE ciphertext[], // IN - Ciphertext, the concatination of encrypted plaintext and MAC.
WORD ciphertext_len, // IN - Ciphertext length in bytes.
const BYTE assoc[], // IN - The Associated Data, required for authentication.
unsigned short assoc_len, // IN - Associated Data length in bytes.
const BYTE nonce[], // IN - The Nonce to use for decryption, same one as for encryption.
unsigned short nonce_len, // IN - Nonce length in bytes.
BYTE plaintext[], // OUT - The plaintext that was decrypted. Will need to be large enough to hold ciphertext_len - mac_len.
WORD *plaintext_len, // OUT - Length in bytes of the output plaintext, always ciphertext_len - mac_len .
WORD mac_len, // IN - The length of the MAC that was calculated.
int *mac_auth, // OUT - TRUE if authentication succeeded, FALSE if it did not. NULL pointer will ignore the authentication.
const BYTE key[], // IN - The AES key for decryption.
int keysize); // IN - The length of the key in BITS. Valid values are 128, 192, 256.
 
///////////////////
// Test functions
///////////////////
int aes_test();
int aes_ecb_test();
int aes_cbc_test();
int aes_ctr_test();
int aes_ccm_test();
 
#endif // AES_H
/programs/develop/ktcc/trunk/libc/include/cryptal/arcfour.h
0,0 → 1,30
/*********************************************************************
* Filename: arcfour.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding ARCFOUR implementation.
*********************************************************************/
 
#ifndef ARCFOUR_H
#define ARCFOUR_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
 
/*********************** FUNCTION DECLARATIONS **********************/
// Input: state - the state used to generate the keystream
// key - Key to use to initialize the state
// len - length of key in bytes (valid lenth is 1 to 256)
void arcfour_key_setup(BYTE state[], const BYTE key[], int len);
 
// Pseudo-Random Generator Algorithm
// Input: state - the state used to generate the keystream
// out - Must be allocated to be of at least "len" length
// len - number of bytes to generate
void arcfour_generate_stream(BYTE state[], BYTE out[], size_t len);
 
#endif // ARCFOUR_H
/programs/develop/ktcc/trunk/libc/include/cryptal/base64.h
0,0 → 1,27
/*********************************************************************
* Filename: base64.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding Base64 implementation.
*********************************************************************/
 
#ifndef BASE64_H
#define BASE64_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
 
/*********************** FUNCTION DECLARATIONS **********************/
// Returns the size of the output. If called with out = NULL, will just return
// the size of what the output would have been (without a terminating NULL).
size_t base64_encode(const BYTE in[], BYTE out[], size_t len, int newline_flag);
 
// Returns the size of the output. If called with out = NULL, will just return
// the size of what the output would have been (without a terminating NULL).
size_t base64_decode(const BYTE in[], BYTE out[], size_t len);
 
#endif // BASE64_H
/programs/develop/ktcc/trunk/libc/include/cryptal/blowfish.h
0,0 → 1,32
/*********************************************************************
* Filename: blowfish.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding Blowfish implementation.
*********************************************************************/
 
#ifndef BLOWFISH_H
#define BLOWFISH_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define BLOWFISH_BLOCK_SIZE 8 // Blowfish operates on 8 bytes at a time
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
 
typedef struct {
WORD p[18];
WORD s[4][256];
} BLOWFISH_KEY;
 
/*********************** FUNCTION DECLARATIONS **********************/
void blowfish_key_setup(const BYTE user_key[], BLOWFISH_KEY *keystruct, size_t len);
void blowfish_encrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct);
void blowfish_decrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct);
 
#endif // BLOWFISH_H
/programs/develop/ktcc/trunk/libc/include/cryptal/des.h
0,0 → 1,37
/*********************************************************************
* Filename: des.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding DES implementation.
Note that encryption and decryption are defined by how
the key setup is performed, the actual en/de-cryption is
performed by the same function.
*********************************************************************/
 
#ifndef DES_H
#define DESH
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define DES_BLOCK_SIZE 8 // DES operates on 8 bytes at a time
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
 
typedef enum {
DES_ENCRYPT,
DES_DECRYPT
} DES_MODE;
 
/*********************** FUNCTION DECLARATIONS **********************/
void des_key_setup(const BYTE key[], BYTE schedule[][6], DES_MODE mode);
void des_crypt(const BYTE in[], BYTE out[], const BYTE key[][6]);
 
void three_des_key_setup(const BYTE key[], BYTE schedule[][16][6], DES_MODE mode);
void three_des_crypt(const BYTE in[], BYTE out[], const BYTE key[][16][6]);
 
#endif // DES_H
/programs/develop/ktcc/trunk/libc/include/cryptal/md2.h
0,0 → 1,33
/*********************************************************************
* Filename: md2.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding MD2 implementation.
*********************************************************************/
 
#ifndef MD2_H
#define MD2_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define MD2_BLOCK_SIZE 16
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
 
typedef struct {
BYTE data[16];
BYTE state[48];
BYTE checksum[16];
int len;
} MD2_CTX;
 
/*********************** FUNCTION DECLARATIONS **********************/
void md2_init(MD2_CTX *ctx);
void md2_update(MD2_CTX *ctx, const BYTE data[], size_t len);
void md2_final(MD2_CTX *ctx, BYTE hash[]); // size of hash must be MD2_BLOCK_SIZE
 
#endif // MD2_H
/programs/develop/ktcc/trunk/libc/include/cryptal/md5.h
0,0 → 1,34
/*********************************************************************
* Filename: md5.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding MD5 implementation.
*********************************************************************/
 
#ifndef MD5_H
#define MD5_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
 
typedef struct {
BYTE data[64];
WORD datalen;
unsigned long long bitlen;
WORD state[4];
} MD5_CTX;
 
/*********************** FUNCTION DECLARATIONS **********************/
void md5_init(MD5_CTX *ctx);
void md5_update(MD5_CTX *ctx, const BYTE data[], size_t len);
void md5_final(MD5_CTX *ctx, BYTE hash[]);
 
#endif // MD5_H
/programs/develop/ktcc/trunk/libc/include/cryptal/rot-13.h
0,0 → 1,20
/*********************************************************************
* Filename: rot-13.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding ROT-13 implementation.
*********************************************************************/
 
#ifndef ROT13_H
#define ROT13_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/*********************** FUNCTION DECLARATIONS **********************/
// Performs IN PLACE rotation of the input. Assumes input is NULL terminated.
// Preserves each charcter's case. Ignores non alphabetic characters.
void rot13(char str[]);
 
#endif // ROT13_H
/programs/develop/ktcc/trunk/libc/include/cryptal/sha1.h
0,0 → 1,35
/*********************************************************************
* Filename: sha1.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding SHA1 implementation.
*********************************************************************/
 
#ifndef SHA1_H
#define SHA1_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define SHA1_BLOCK_SIZE 20 // SHA1 outputs a 20 byte digest
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
 
typedef struct {
BYTE data[64];
WORD datalen;
unsigned long long bitlen;
WORD state[5];
WORD k[4];
} SHA1_CTX;
 
/*********************** FUNCTION DECLARATIONS **********************/
void sha1_init(SHA1_CTX *ctx);
void sha1_update(SHA1_CTX *ctx, const BYTE data[], size_t len);
void sha1_final(SHA1_CTX *ctx, BYTE hash[]);
 
#endif // SHA1_H
/programs/develop/ktcc/trunk/libc/include/cryptal/sha256.h
0,0 → 1,34
/*********************************************************************
* Filename: sha256.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding SHA1 implementation.
*********************************************************************/
 
#ifndef SHA256_H
#define SHA256_H
 
/*************************** HEADER FILES ***************************/
#include <stddef.h>
 
/****************************** MACROS ******************************/
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
 
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
 
typedef struct {
BYTE data[64];
WORD datalen;
unsigned long long bitlen;
WORD state[8];
} SHA256_CTX;
 
/*********************** FUNCTION DECLARATIONS **********************/
void sha256_init(SHA256_CTX *ctx);
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
 
#endif // SHA256_H
/programs/develop/ktcc/trunk/libc/include/memory.h
0,0 → 1,8
#ifndef _MEMORY_H
#define _MEMORY_H
 
#ifndef _STRING_H
#include <string.h>
#endif
#endif
/programs/develop/ktcc/trunk/libc/include/dir.h
0,0 → 1,35
#ifndef _DIR_H
#define _DIR_H
 
#include <stdbool.h>
 
#define rmfile(obj) rmdir(obj)
#define PATH_MAX 4096
#define T_FOLDER 16
#define T_FILE 0
#define FS_ERROR -1
 
typedef struct {
unsigned type;
char *name;
} short_file_info;
 
//Writes information about files in the "dir" folder to an struct array"list". Returns the number of files.
int lsdir(const char* dir, short_file_info **list);
 
// Get the path to the working directory(if buf is NULL, then memory will be allocated automatically)
char *getcwd(char *buf, unsigned size);
 
// Set path to working directory
void setcwd(const char* cwd);
 
// Delete empty folder (returns "true" if successful)
bool rmdir(const char* dir);
 
// Delete a file (returns "true" if successful)
bool rmfile(const char* name);
 
// Create a foldery (returns "true" if successful)
bool mkdir(const char* dir);
 
#endif
/programs/develop/ktcc/trunk/libc/include/libgen.h
0,0 → 1,7
#ifndef __KTCC_LIBGEN_H__
#define __KTCC_LIBGEN_H__
 
char *basename(char *path);
char *dirname(char *path);
 
#endif // __KTCC_LIBGEN_H__
/programs/develop/ktcc/trunk/libc/include/string.h
0,0 → 1,36
#ifndef string_h
#define string_h
typedef unsigned int size_t;
 
 
extern void* memchr(const void*,int,size_t);
extern void* memrchr(const void*,int,size_t);
extern int memcmp(const void*,const void*,size_t);
extern void* memcpy(void*,const void*,size_t);
extern void* memmove(void*,const void*,size_t);
extern void* memset(void*,int,size_t);
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 size_t strcspn(const char*,const char*);
extern int strlen(const char*);
extern char* strncat(char*,const char*,size_t);
extern int strncmp(const char*,const char*,size_t);
extern char* strncpy(char*,const char*,size_t);
extern char* strpbrk(const char*,const char*);
extern char* strrchr(const char*,int);
extern size_t 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*);
extern char* strrev(char *p);
char * strerror ( int errnum );
 
#ifndef NULL
# define NULL ((void*)0)
#endif
 
#endif
/programs/develop/ktcc/trunk/libc/include/dlfcn.h
0,0 → 1,14
#ifndef _DLFCN_H
#define _DLFCN_H
 
#define RTLD_LAZY 0x00001
#define RTLD_NOW 0x00002
#define RTLD_GLOBAL 0x00100
#define RTLD_LOCAL 0
 
int dlclose(void *handle);
char *dlerror(void);
void *dlopen(const char *name, int mode);
void *dlsym(void *restrict handle, const char *restrict name);
 
#endif
/programs/develop/ktcc/trunk/libc/include/stdlib.h
0,0 → 1,77
#ifndef stdlib_h
#define stdlib_h
#include "kolibrisys.h"
 
#define RAND_MAX 65535
#ifndef NULL
# define NULL ((void*)0)
#endif
 
#define abs(i) (((i)<0)?(-(i)):(i))
#define labs(li) abs(li)
 
#define min(a, b) ((a)<(b) ? (a) : (b))
#define max(a, b) ((a)>(b) ? (a) : (b))
 
 
extern int atoib(char *s,int b);
extern int atoi(char *s);
extern char *itoab(unsigned int n,char* s,int b);
extern char *__itoa(int n,char* s);
 
// function using KOS syscalls
extern void* stdcall sysmalloc(dword size);
extern void stdcall sysfree(void *pointer);
extern void* stdcall sysrealloc(void* pointer,dword size);
extern void* syscalloc (size_t num, size_t size);
 
// suballocator functions
extern void* wtmalloc(size_t size);
extern void wtfree(void *pointer);
extern void* wtrealloc(void* pointer, size_t size);
extern void* wtcalloc (size_t num, size_t size);
extern int wtmalloc_freelist_check();
extern int wtmalloc_poiner_check(void *ptr);
extern void wtmalloc_freelist_print();
 
#ifdef USESYSALLOC
#define malloc(x) sysmalloc(x)
#define free(x) sysfree(x)
#define realloc(x,y) sysrealloc(x,y)
#define calloc(x,y) syscalloc(x,y)
#else
#define malloc(x) wtmalloc(x)
#define free(x) wtfree(x)
#define realloc(x,y) wtrealloc(x,y)
#define calloc(x,y) wtcalloc(x,y)
#endif
 
 
extern int rand (void);
extern void srand (unsigned int seed);
 
double strtod (const char* str, char** endptr);
long double strtold (const char* str, char** endptr);
float strtof (const char* str, char** endptr);
long int strtol (const char* str, char** endptr, int base);
#define strtoul(s, ep, b) ((unsigned long int)strtol(s, ep, b))
 
 
void exit (int status); /* close console if was initialized, also stay window [finished] when status is error < 0 */
#define abort() exit(-1)
 
typedef struct {
int quot;
int rem;
} div_t;
 
typedef div_t ldiv_t;
 
div_t div (int numer, int denom);
#define ldiv(a, b) div(a, b)
#define atol(a) atoi(a)
#define atof(a) strtod(a, NULL)
 
 
 
#endif
/programs/develop/ktcc/trunk/libc/include/conio.h
0,0 → 1,203
/*
 
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 int 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
*/
 
extern int con_init_console_dll_param(dword wnd_width, dword wnd_height,
dword scr_width, dword scr_height, const char* title);
/* work as con_init_console_dll, but call con_init with params
*/
 
 
#endif
/programs/develop/ktcc/trunk/libc/include/ctype.h
0,0 → 1,41
#ifndef _CTYPE_H
#define _CTYPE_H
/*
** 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 unsigned short __is[129];
 
#define isalnum(c)(__is[c+1] & __ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */
#define isalpha(c)(__is[c+1] & __ALPHA ) /* 'a'-'z', 'A'-'Z' */
#define iscntrl(c)(__is[c+1] & __CNTRL ) /* 0-31, 127 */
#define isdigit(c)(__is[c+1] & __DIGIT ) /* '0'-'9' */
#define isgraph(c)(__is[c+1] & __GRAPH ) /* '!'-'~' */
#define islower(c)(__is[c+1] & __LOWER ) /* 'a'-'z' */
#define isprint(c)(__is[c+1] & __PRINT ) /* ' '-'~' */
#define ispunct(c)(__is[c+1] & __PUNCT ) /* !alnum && !cntrl && !space */
#define isspace(c)(__is[c+1] & __BLANK ) /* HT, LF, VT, FF, CR, ' ' */
#define isupper(c)(__is[c+1] & __UPPER ) /* 'A'-'Z' */
#define isxdigit(c)(__is[c+1] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */
 
#define isascii(c) (!((c)&(~0x7f)))
#define toascii(c) ((c)&0x7f)
 
extern unsigned char tolower(unsigned char c);
extern unsigned char toupper(unsigned char c);
 
#endif
/programs/develop/ktcc/trunk/libc/include/stdint.h
0,0 → 1,0
#include <stddef.h>
/programs/develop/ktcc/trunk/libc/include/assert.h
0,0 → 1,19
#ifndef __ASSERT_H
#define __ASSERT_H
 
#ifdef NDEBUG
# define assert(a) (void)0
#else
# define assert(a) ((a) ? (void)0 : __assert_func (__FILE__, __LINE__, #a))
#endif
 
#ifdef NDEBUG
# define TRACE(s) void(0)
#else
# define TRACE(s) (__trace_func (__FILE__, __LINE__, #s))
#endif
 
void __assert_func(char*,int,char*);
void __trace_func(char*,int,char*);
 
#endif
/programs/develop/ktcc/trunk/libc/include/time.h
0,0 → 1,29
#ifndef _TIME_H
#define _TIME_H
 
 
typedef unsigned long int clock_t;
typedef unsigned long int time_t;
#define clock() get_tick_count()
#define CLOCKS_PER_SEC 100
 
struct tm {
int tm_sec; /* seconds after the minute 0-61*/
int tm_min; /* minutes after the hour 0-59 */
int tm_hour; /* hours since midnight 0-23 */
int tm_mday; /* day of the month 1-31 */
int tm_mon; /* months since January 0-11 */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday 0-6 */
int tm_yday; /* days since January 1 0-365 */
int tm_isdst; /* Daylight Saving Time flag */
};
 
time_t mktime (struct tm * timeptr);
time_t time (time_t* timer);
struct tm * localtime (const time_t * timer); /* non-standard! ignore parameter and return just time now, not generate tm_isdst, tm_yday, tm_wday == -1 */
double difftime (time_t end, time_t beginning);
 
extern struct tm __buffertime;
 
#endif
/programs/develop/ktcc/trunk/libc/include/float.h
0,0 → 1,65
#ifndef _FLOAT_H_
#define _FLOAT_H_
 
#define FLT_RADIX 2
 
/* IEEE float */
#define FLT_MANT_DIG 24
#define FLT_DIG 6
#define FLT_ROUNDS 1
#define FLT_EPSILON 1.19209290e-07F
#define FLT_MIN_EXP (-125)
#define FLT_MIN 1.17549435e-38F
#define FLT_MIN_10_EXP (-37)
#define FLT_MAX_EXP 128
#define FLT_MAX 3.40282347e+38F
#define FLT_MAX_10_EXP 38
 
/* IEEE double */
#define DBL_MANT_DIG 53
#define DBL_DIG 15
#define DBL_EPSILON 2.2204460492503131e-16
#define DBL_MIN_EXP (-1021)
#define DBL_MIN 2.2250738585072014e-308
#define DBL_MIN_10_EXP (-307)
#define DBL_MAX_EXP 1024
#define DBL_MAX 1.7976931348623157e+308
#define DBL_MAX_10_EXP 308
 
/* horrible intel long double */
#if defined __i386__ || defined __x86_64__
 
#define LDBL_MANT_DIG 64
#define LDBL_DIG 18
#define LDBL_EPSILON 1.08420217248550443401e-19L
#define LDBL_MIN_EXP (-16381)
#define LDBL_MIN 3.36210314311209350626e-4932L
#define LDBL_MIN_10_EXP (-4931)
#define LDBL_MAX_EXP 16384
#define LDBL_MAX 1.18973149535723176502e+4932L
#define LDBL_MAX_10_EXP 4932
 
#else
 
/* same as IEEE double */
#define LDBL_MANT_DIG 53
#define LDBL_DIG 15
#define LDBL_EPSILON 2.2204460492503131e-16
#define LDBL_MIN_EXP (-1021)
#define LDBL_MIN 2.2250738585072014e-308
#define LDBL_MIN_10_EXP (-307)
#define LDBL_MAX_EXP 1024
#define LDBL_MAX 1.7976931348623157e+308
#define LDBL_MAX_10_EXP 308
 
#endif
 
#ifndef NAN
# define NAN (__nan__)
#endif
 
#ifndef INFINITY
# define INFINITY (__inf__)
#endif
 
#endif /* _FLOAT_H_ */
/programs/develop/ktcc/trunk/libc/include/stdarg.h
0,0 → 1,75
#ifndef _STDARG_H
#define _STDARG_H
 
#ifdef __x86_64__
#ifndef _WIN64
 
//This should be in sync with the declaration on our lib/libtcc1.c
/* GCC compatible definition of va_list. */
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
union {
unsigned int overflow_offset;
char *overflow_arg_area;
};
char *reg_save_area;
} __va_list_struct;
 
typedef __va_list_struct va_list[1];
 
void __va_start(__va_list_struct *ap, void *fp);
void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
 
#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
#define va_arg(ap, type) \
(*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
#define va_copy(dest, src) (*(dest) = *(src))
#define va_end(ap)
 
#else /* _WIN64 */
typedef char *va_list;
#define va_start(ap,last) __builtin_va_start(ap,last)
#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap)
#define va_copy(dest, src) ((dest) = (src))
#define va_end(ap)
#endif
 
#elif __arm__
typedef char *va_list;
#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
& ~(_tcc_alignof(type) - 1))
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
&~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
#define va_copy(dest, src) (dest) = (src)
#define va_end(ap)
 
#elif defined(__aarch64__)
typedef struct {
void *__stack;
void *__gr_top;
void *__vr_top;
int __gr_offs;
int __vr_offs;
} va_list;
#define va_start(ap, last) __va_start(ap, last)
#define va_arg(ap, type) __va_arg(ap, type)
#define va_end(ap)
#define va_copy(dest, src) ((dest) = (src))
 
#else /* __i386__ */
typedef char *va_list;
/* only correct for i386 */
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
#define va_copy(dest, src) (dest) = (src)
#define va_end(ap)
#endif
 
/* fix a buggy dependency on GCC in libio.h */
typedef va_list __gnuc_va_list;
#define _VA_LIST_DEFINED
 
#endif /* _STDARG_H */
/programs/develop/ktcc/trunk/libc/include/stdbool.h
0,0 → 1,11
#ifndef _STDBOOL_H
#define _STDBOOL_H
 
/* ISOC99 boolean */
 
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
 
#endif /* _STDBOOL_H */
/programs/develop/ktcc/trunk/libc/include/stddef.h
0,0 → 1,46
#ifndef _STDDEF_H
#define _STDDEF_H
 
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __WCHAR_TYPE__ wchar_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __PTRDIFF_TYPE__ intptr_t;
typedef __SIZE_TYPE__ uintptr_t;
 
#ifndef __int8_t_defined
#define __int8_t_defined
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed long long int int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
#endif
 
#ifndef NULL
#define NULL ((void*)0)
#endif
 
#define offsetof(type, field) ((size_t)&((type *)0)->field)
 
void *alloca(size_t size);
 
#endif
 
/* Older glibc require a wint_t from <stddef.h> (when requested
by __need_wint_t, as otherwise stddef.h isn't allowed to
define this type). Note that this must be outside the normal
_STDDEF_H guard, so that it works even when we've included the file
already (without requiring wint_t). Some other libs define _WINT_T
if they've already provided that type, so we can use that as guard.
TCC defines __WINT_TYPE__ for us. */
#if defined (__need_wint_t)
#ifndef _WINT_T
#define _WINT_T
typedef __WINT_TYPE__ wint_t;
#endif
#undef __need_wint_t
#endif
/programs/develop/ktcc/trunk/libc/include/varargs.h
0,0 → 1,12
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within this package.
*/
#ifndef _VARARGS_H
#define _VARARGS_H
 
#error "TinyCC no longer implements <varargs.h>."
#error "Revise your code to use <stdarg.h>."
 
#endif
/programs/develop/ktcc/trunk/libc/stdlib/assert.c
0,0 → 1,7
#include <stdio.h>
#include <stdlib.h>
 
void __assert_fail(const char *expr, const char *file, int line, const char *func){
fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
abort();
}
/programs/develop/ktcc/trunk/libc/stdlib/getopt.c
0,0 → 1,63
#include <stdio.h>
#include <string.h>
#include <getopt.h>
 
char *optarg = NULL; // global argument pointer
int optind = 0; // global argv index
 
int getopt(int argc, char *argv[], char *optstring) {
static char *next = NULL;
char c;
char *cp = NULL;
if (optind == 0)
next = NULL;
 
optarg = NULL;
 
if (next == NULL || *next == '\0') {
if (optind == 0)
optind++;
 
if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') {
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
 
if (strncmp(argv[optind], "--", 2) == 0) {
optind++;
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
 
next = argv[optind];
next++; // skip past -
optind++;
}
 
c = *next++;
cp = strchr(optstring, c);
 
if (cp == NULL || c == ':')
return '?';
 
cp++;
if (*cp == ':') {
if (*next != '\0') {
optarg = next;
next = NULL;
}
else if (optind < argc) {
optarg = argv[optind];
optind++;
}
else {
return '?';
}
}
return c;
}
/programs/develop/ktcc/trunk/libc/stdlib/time.c
0,0 → 1,86
#include <time.h>
#include <kolibrisys.h>
 
struct tm __buffertime;
 
 
 
struct tm * localtime (const time_t * timer)
/* non-standard! ignore parameter and return just time now */
{
int kos_date, kos_time;
kos_date = _ksys_get_date();
kos_time = _ksys_get_system_clock();
int bcd_day = (kos_date >> 16);
int bcd_mon = ((kos_date & 0xFF00) >> 8);
int bcd_year = (kos_date & 0xFF);
__buffertime.tm_mday = ((bcd_day & 0xF0)>>4)*10 + (bcd_day & 0x0F);
__buffertime.tm_mon = ((bcd_mon & 0xF0)>>4)*10 + (bcd_mon & 0x0F) - 1;
__buffertime.tm_year = ((bcd_year & 0xF0)>>4)*10 + (bcd_year & 0x0F) + 100;
__buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */
int bcd_sec = (kos_time >> 16);
int bcd_min = ((kos_time & 0xFF00) >> 8);
int bcd_hour = (kos_time & 0xFF);
 
__buffertime.tm_sec = ((bcd_sec & 0xF0)>>4)*10 + (bcd_sec & 0x0F);
__buffertime.tm_min = ((bcd_min & 0xF0)>>4)*10 + (bcd_min & 0x0F);
__buffertime.tm_hour = ((bcd_hour & 0xF0)>>4)*10 + (bcd_hour & 0x0F);
 
return &__buffertime;
}
 
time_t time (time_t* timer)
{
time_t t = mktime(localtime(0));
if (timer) *timer = t;
return t;
}
 
time_t mktime (struct tm * timeptr)
{
/*int y, m, d;
time_t t;
y = timeptr->tm_year + 1900;
m = timeptr->tm_mon + 1;
d = timeptr->tm_mday; // to -1 or not to -1?
if (m < 3) { m += 12; y -= 1; }
t = y * 365 + y / 4 + y /400 - y / 100; // years - > days
t += 30 * m + 3 * (m + 1) / 5 + d; // add month days
t -= 719561; // 01 jan 1970
t *= 86400;
t += 3600 * timeptr->tm_hour + 60 * timeptr->tm_min + timeptr->tm_sec;
 
return t;*/
 
int utcdiff = -3;
const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
unsigned long int tyears, tdays, leaps, utc_hrs;
int i;
tyears = timeptr->tm_year - 70 ;// tm->tm_year is from 1900.
leaps = (tyears + 2) / 4; // no of next two lines until year 2100.
i = (timeptr->tm_year - 100) / 100;
leaps -= ( (i/4)*3 + i%4 );
tdays = 0;
for (i=0; i < timeptr->tm_mon; i++) tdays += mon_days[i];
tdays += timeptr->tm_mday-1; // days of month passed.
tdays = tdays + (tyears * 365) + leaps;
 
utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
return (tdays * 86400) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
}
 
double difftime (time_t end, time_t beginning)
{
return end - beginning;
}
/programs/develop/ktcc/trunk/libc/stdlib/exit.c
0,0 → 1,11
#include <stdlib.h>
#include <conio.h>
#include <kolibrisys.h>
 
void exit (int status)
/* close console if was initialized, also stay window [finished] when status is error < 0 */
{
if (__console_initdll_status)
con_exit(status > 0);
_ksys_exit();
}
/programs/develop/ktcc/trunk/libc/stdlib/itoa.c
0,0 → 1,26
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
 
/*
** itoa(n,s) - Convert n to characters in s
*/
char* __itoa(int n,char* s)
{
int sign;
char *ptr;
ptr = s;
 
if(n == (int)0x80000000)
return strcpy(s, "-2147483648"); // overflowed -n
 
if ((sign = n) < 0) n = -n;
do {
*ptr++ = n % 10 + '0';
} while ((n = n / 10) > 0);
if (sign < 0) *ptr++ = '-';
*ptr = '\0';
return strrev(s);
}
 
/programs/develop/ktcc/trunk/libc/stdlib/itoab.c
0,0 → 1,25
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
 
/*
** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b.
** NOTE: This is a non-standard function.
*/
char* itoab(unsigned int n, char* s, int b)
{
char *ptr;
int lowbit;
ptr = s;
b >>= 1;
do {
lowbit = n & 1;
n = (n >> 1) & 0x7FFFFFFF;
*ptr = ((n % b) << 1) + lowbit;
if(*ptr < 10) *ptr += '0'; else *ptr += 55;
++ptr;
} while(n /= b);
*ptr = 0;
return strrev(s);
}
/programs/develop/ktcc/trunk/libc/stdlib/strtol.c
0,0 → 1,78
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
 
#define LONG_MIN (-2147483647L-1)
#define LONG_MAX (2147483647L)
#define ULONG_MAX (4294967295UL)
 
 
int getdigit(char ch, int base)
{
if (isdigit(ch)) ch-= '0';
else
if (isalpha(ch) && ch <= 'Z') ch = 10 + ch - 'A';
else
if (isalpha(ch)) ch = 10 + ch - 'a';
else
return -1;
if (ch / base != 0) return -1;
 
return ch;
}
 
 
long int strtol (const char* str, char** endptr, int base)
{
long int res = 0;
int sign = 1;
 
if (base > 36)
{
errno = EINVAL;
goto bye;
}
 
while (isspace(*str)) str++;
 
if (*str == '-') { sign = -1; str++; }
else
if (*str == '+') str++;
 
if (base == 0 || base == 16)
{
if (*str == '0' && (str[1] == 'x' || str[1] == 'X'))
{
base = 16;
str += 2;
}
}
 
if (base == 0 && *str == '0') base = 8;
 
if (base == 0) base = 10;
 
 
int digit;
while ((digit = getdigit(*str, base)) >= 0)
{
res = base * res + digit;
str++;
if (res < 0)
{
errno = ERANGE;
if (sign > 0)
res = LONG_MAX;
else
res = LONG_MIN;
}
}
 
bye:
if (endptr)
*endptr = (char*)str;
 
return res * sign;
}
 
/programs/develop/ktcc/trunk/libc/stdlib/div.c
0,0 → 1,10
#include <stdlib.h>
 
div_t div (int numer, int denom)
{
div_t res;
res.quot = numer / denom;
res.rem = numer % denom;
 
return res;
}
/programs/develop/ktcc/trunk/libc/stdlib/tolower.c
0,0 → 1,9
#include <stdlib.h>
/*
** 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,9
#include <stdlib.h>
/*
** 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/stdlib/strtod.c
0,0 → 1,70
#include <stdlib.h>
#include <ctype.h>
 
double strtod (const char* str, char** endptr)
{
double res = 0.0;
int pwr = 0, pwr1, esign = 1, sign = 1;
 
while (isspace(*str)) str++;
 
if (*str == '-') { sign = -1; str++; }
else
if (*str == '+') str++;
 
 
while (isdigit(*str))
{
res = 10 * res + (*str - '0');
str++;
}
 
if (*str =='.')
{
str++;
double div = 10.0;
while (isdigit(*str))
{
res += (*str - '0') / div;
str++;
div *= 10;
}
}
 
if (*str =='e' || *str =='E')
{
str++;
if (*str == '-') { esign = -1; str++; }
else
if (*str == '+') str++;
 
while (isdigit(*str))
{
pwr = 10.0 * pwr + (*str - '0');
str++;
}
 
// fck, i've no pow() yet
// res = res * pow(10, pwr);
for (pwr1 = pwr; pwr1 !=0; pwr1--)
if (esign == 1)
res *= 10;
else
res /= 10;
 
}
if (endptr)
*endptr = (char*)str;
 
return res * sign;
}
 
long double strtold (const char* str, char** endptr)
{
return (long double)strtod(str, endptr);
}
 
float strtof (const char* str, char** endptr)
{
return (float)strtod(str, endptr);
}
/programs/develop/ktcc/trunk/libc/stdlib/random.c
0,0 → 1,15
 
#include "stdlib.h"
 
unsigned int seed_o=1;
 
void srand (unsigned int seed)
{
seed_o=seed;
}
 
int rand (void)
{
seed_o=(seed_o*25173+13849) & (65535);
return(seed_o);
}
/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/fs/dir.c
0,0 → 1,108
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */
 
#include <stdlib.h>
#include <dir.h>
#include <stdbool.h>
 
#pragma pack(push,1)
typedef struct {
unsigned p00;
unsigned long long p04;
unsigned p12;
unsigned p16;
char p20;
char *p21;
} kol_struct70;
#pragma pack(pop)
 
int kol_file_70(kol_struct70 *k)
{
asm volatile ("int $0x40"::"a"(70), "b"(k));
}
 
bool dir_operations(unsigned char fun_num, char *path)
{
kol_struct70 inf;
inf.p00 = fun_num;
inf.p04 = 0;
inf.p12 = 0;
inf.p16 = 0;
inf.p20 = 0;
inf.p21 = path;
if(!kol_file_70(&inf)){
return true;
}
else {
return false;
}
}
 
int lsdir(const char* dir, short_file_info **list)
{
int num_of_file=0;
kol_struct70 inf;
inf.p00 = 1;
inf.p04 = 0;
inf.p12 = 2;
inf.p16 = (unsigned) malloc(32+inf.p12*560);
inf.p20 = 0;
inf.p21 = (char*)dir;
if(kol_file_70(&inf))
{
free((void*)inf.p16);
return FS_ERROR;
}
num_of_file = *(unsigned*)(inf.p16+8);
inf.p12 = num_of_file;
free((void*)inf.p16);
inf.p16 = (unsigned) malloc(32+inf.p12*560);
*list = (short_file_info*)malloc(num_of_file*sizeof(short_file_info));
if(kol_file_70(&inf))
{
free((void*)inf.p16);
return FS_ERROR;
}
for(int i=0; i<num_of_file; i++)
{
(*list)[i].type = *(unsigned*)(inf.p16+32+(264+40)*i);
(*list)[i].name =(char*)(inf.p16+32+40+(264+40)*i);
}
return num_of_file;
}
 
 
char *getcwd(char *buf, unsigned size)
{
if(buf == NULL){
if((buf = malloc(size))==NULL)
{
return NULL;
}
}
__asm__ __volatile__(
"int $0x40"
::"a"(30),"b"(2),"c"(buf), "d"(size));
return(buf);
}
 
void setcwd(const char* cwd)
{
__asm__ __volatile__(
"int $0x40"
::"a"(30),"b"(1),"c"(cwd));
}
 
bool rmdir(const char* dir)
{
return dir_operations(8, (char*)dir);
}
 
bool mkdir(const char* dir)
{
return dir_operations(9, (char*)dir);
}
/programs/develop/ktcc/trunk/libc/net/socket.c
0,0 → 1,103
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */
 
#include <net/socket.h>
 
int socket(int domain, int type, int protocol)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
);
}
 
int close(int socket)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(1), "c"(socket)
);
}
int bind(int socket, const struct sockaddr *addres, int addres_len)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
);
}
 
int listen(int socket, int backlog)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
);
}
 
int connect(int socket,const struct sockaddr* address, int socket_len)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
);
}
 
int accept(int socket, const struct sockaddr *address, int address_len)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
);
}
 
int send(int socket, const void *message, size_t msg_len, int flag)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
);
}
 
int recv(int socket, void *buffer, size_t buff_len, int flag)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
);
}
 
int setsockopt(int socket,const optstruct* opt)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(8), "c"(socket),"d"(opt)
);
}
 
int getsockopt(int socket, optstruct* opt)
{
asm volatile(
"int $0x40"
:"=b"(errno)
:"a"(75), "b"(9), "c"(socket),"d"(opt)
);
}
 
int socketpair(int *sock1, int *sock2)
{
asm volatile(
"int $0x40"
:"=b"(*sock2), "=a"(*sock1)
:"a"(75), "b"(10)
);
errno = *sock2;
return *sock1;
}
/programs/develop/ktcc/trunk/libc/stdio/debug.c
0,0 → 1,13
#include <stdarg.h>
#include <stdio.h>
#include <kolibrisys.h>
 
void debug_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_out_str(log_board);
}
/programs/develop/ktcc/trunk/libc/stdio/conio.c
0,0 → 1,102
#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", "con_set_title",
(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]);
con_set_title = _ksys_cofflib_getproc(exp, imports[20]);
}
 
 
int con_init_console_dll(void)
{
return con_init_console_dll_param(-1, -1, -1, -1, con_caption);
}
 
 
int con_init_console_dll_param(dword wnd_width, dword wnd_height,
dword scr_width, dword scr_height, const char* title)
/* work as con_init_console_dll, but call con_init with params
*/
{
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(wnd_width, wnd_height, scr_width, scr_height, title);
 
__console_initdll_status = 1;
 
return 0;
}
 
/programs/develop/ktcc/trunk/libc/stdio/fopen.c
0,0 → 1,142
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int errno = 0;
 
/*
// removed by Seiemargl 26-oct-2018
// use get_current_folder() from kos32sys.h instead
 
extern char __argv;
extern char __path;
 
// convert relative to program path ./file.txt to absolute
const char* getfullpath(const char *path){
 
int relpath_pos, localpath_size;
char *programpath;
char *newpath;
char *prgname;
 
if (path[0] == '/') //
{
return(strdup(path)); // dup need as free in fclose()
}
 
relpath_pos = 0;
if (path[0] == '.' && path[1] == '/')
{
//detected relative path, begins with ./
relpath_pos=2;
}
 
programpath=&__path;
 
//if we here than path is a relative or local
prgname = strrchr(programpath, '/');
if (!prgname) return strdup(path);
 
localpath_size = prgname - programpath + 1;
 
newpath = malloc(FILENAME_MAX);
if(!newpath)
{
errno = E_NOMEM;
return NULL;
}
//copy local path to the new path
strncpy(newpath, programpath, localpath_size);
newpath[localpath_size] = 0;
 
//copy filename to the new path
strcpy(newpath + localpath_size, path + relpath_pos);
 
return(newpath);
}
*/
 
 
FILE* fopen(const char* filename, const char *mode)
{
FILE* res;
int imode, sz = -1;
char *fullname;
 
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=='+')
{
imode|=FILE_OPEN_PLUS;
mode++;
}
if (*mode=='t')
{
imode|=FILE_OPEN_TEXT;
mode++;
}else if (*mode=='b')
mode++;
if (*mode=='+')
{
imode|=FILE_OPEN_PLUS;
mode++;
}
if (*mode!=0)
return NULL;
// fullname = (char*)getfullpath(filename);
fullname = strdup(filename);
if ((imode & 3) == FILE_OPEN_READ && fullname) /* check existense */
{
sz = _ksys_get_filesize(fullname);
if (sz < 0)
{
free(fullname);
errno = sz;
return NULL;
}
}
res = malloc(sizeof(FILE));
if (res)
{
res->buffer=malloc(BUFSIZ);
res->buffersize=BUFSIZ;
res->filesize=0;
res->filepos=0;
res->mode=imode;
res->filename=fullname;
res->ungetc_buf = EOF;
res->buffer_start = -1;
res->buffer_end = -1;
}
if(!res || !res->buffer || !res->filename)
{
errno = E_NOMEM;
return NULL;
}
 
if ((imode & 3) == FILE_OPEN_READ || (imode & 3) == FILE_OPEN_APPEND)
{
if (sz > 0) /*already got*/
res->filesize = sz;
else
res->filesize=_ksys_get_filesize(res->filename);
}
return res;
}
/programs/develop/ktcc/trunk/libc/stdio/fwrite.c
0,0 → 1,83
#include <stdio.h>
#include <kolibrisys.h>
 
// dont support return partial writing when fail
// only 32-bit filesize
int fwrite(void *buffer,int size,int count,FILE* file)
{
dword res;
dword fullsize;
 
if(!file || !buffer)
{
errno = E_INVALIDPTR;
return EOF;
}
 
 
if ((file->mode & 3)==FILE_OPEN_READ)
{
errno = E_ACCESS;
return 0;
}
 
if ((file->mode &3)==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);
 
}
*/
file->ungetc_buf = EOF;
if (file->filepos >= file->buffer_start && file->filepos < file->buffer_end) // drop buffer, if change his data
{
file->buffer_start = -1;
file->buffer_end = -1;
}
if ((file->mode &3)==FILE_OPEN_WRITE || (file->mode&3)==FILE_OPEN_APPEND) // always true, as read checked previous
{
if (file->filepos==0)
{ //file mot created yet
res=_ksys_rewritefile(file->filename,fullsize,buffer);
if (res==0)
{
file->filepos+=fullsize;
return(count);
} else
{
errno = -res;
return(0);
}
}
else
{
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
if (res==0)
{
file->filepos+=fullsize;
return(count);
} else
{
errno = -res;
return(0);
}
}
}
else return(0);
}
/programs/develop/ktcc/trunk/libc/stdio/fgetc.c
0,0 → 1,11
#include <stdio.h>
int fgetc(FILE* file)
{
int c = 0, rc;
rc = fread(&c, 1, 1, file);
 
if (rc < 1) return EOF;
 
return c;
}
/programs/develop/ktcc/trunk/libc/stdio/fgetpos.c
0,0 → 1,13
#include <stdio.h>
int fgetpos(FILE* file,fpos_t* pos)
{
if(!file || !pos)
{
errno = E_INVALIDPTR;
return EOF;
}
 
*pos=file->filepos;
return 0;
}
/programs/develop/ktcc/trunk/libc/stdio/fputc.c
0,0 → 1,10
#include <stdio.h>
int fputc(int c,FILE* file)
{
dword res;
res = fwrite(&c, 1, 1, file);
if (res < 1) return EOF;
return c;
}
/programs/develop/ktcc/trunk/libc/stdio/fread.c
0,0 → 1,94
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <kolibrisys.h>
 
int fread(void *buffer,int size,int count,FILE* file)
{
dword res, readbytes;
dword fullsize, read4cache, toread, readcount;
 
if(!file || !buffer)
{
errno = E_INVALIDPTR;
return 0;
}
 
if ((file->mode &3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS)==0)
{
errno = E_ACCESS;
return 0;
}
 
fullsize=count*size;
if (fullsize + file->filepos >= file->filesize)
{
fullsize=file->filesize - file->filepos;
if (fullsize <= 0) return 0;
}
 
/***** file buffering strategy, just read forward *****
if we read small part - read full buffer, but if buffer have this data - dont read again nothing (or partial read forward 4k pages)
any writes drops buffers as ungetc_buf */
read4cache = 0;
readcount = 0;
if (file->filepos >= file->buffer_start && file->filepos < file->buffer_end)
{
read4cache = min(file->buffer_end - file->filepos, fullsize);
memcpy(buffer, file->buffer + file->filepos - file->buffer_start, read4cache);
file->filepos += read4cache;
if (file->ungetc_buf != EOF) // subst ungetc byte
{
*((char*)buffer) = (char)file->ungetc_buf;
file->ungetc_buf = EOF;
}
buffer += read4cache; // ! advance
fullsize -= read4cache;
readcount = read4cache / size;
}
toread = max(fullsize, file->buffersize);
if (toread + file->filepos >= file->filesize)
{
toread = file->filesize - file->filepos;
}
if (fullsize <= 0 || toread <= 0)
res = 0; // already read or file end
else
{
file->buffer_start = file->filepos;
if (toread <= fullsize) // read to bigger buffer
{
res = _ksys_readfile(file->filename, file->filepos, toread, buffer, &readbytes);
read4cache = min(readbytes, file->buffersize);
memcpy(file->buffer, buffer, read4cache);
file->filepos += readbytes;
} else
{
res = _ksys_readfile(file->filename, file->filepos, toread, file->buffer, &readbytes);
read4cache = readbytes;
memcpy(buffer, file->buffer, min(fullsize, read4cache));
file->filepos += min(fullsize, read4cache);
}
file->buffer_end = file->buffer_start + read4cache;
if (readbytes >= fullsize)
readcount += fullsize / size;
else
readcount += readbytes / size;
}
 
if (file->ungetc_buf != EOF) // subst ungetc byte
{
*((char*)buffer) = (char)file->ungetc_buf;
file->ungetc_buf = EOF;
}
if (res != 0)
{
file->ungetc_buf = EOF;
errno = -res;
}
return readcount; // really full readed plus cached items
}
/programs/develop/ktcc/trunk/libc/stdio/fsetpos.c
0,0 → 1,18
#include <stdio.h>
int fsetpos(FILE* file,const fpos_t * pos)
{
if(!file || !pos)
{
errno = E_INVALIDPTR;
return errno;
}
 
if (*pos>=0)
{
file->filepos=*pos;
file->ungetc_buf = EOF;
return 0;
}
else
return EOF;
}
/programs/develop/ktcc/trunk/libc/stdio/rewind.c
0,0 → 1,12
#include <stdio.h>
void rewind(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return;
}
 
file->ungetc_buf = EOF;
file->filepos=0;
}
/programs/develop/ktcc/trunk/libc/stdio/ungetc.c
0,0 → 1,32
#include <stdio.h>
// non standard realization - support for virtually change ONLY ONE char
 
 
 
int ungetc(int c,FILE* file)
{
dword res;
 
if(!file)
{
errno = E_INVALIDPTR;
return EOF;
}
 
if ((file->mode & 3) != FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS) == 0)
{
errno = E_ACCESS;
return EOF;
}
 
if (file->filepos > file->filesize || file->filepos == 0 || c == EOF || file->ungetc_buf != EOF)
{
errno = E_EOF;
return EOF;
}
file->ungetc_buf = c;
file->filepos--;
 
return c;
}
/programs/develop/ktcc/trunk/libc/stdio/fclose.c
0,0 → 1,20
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int fclose(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return EOF;
}
 
if(file->buffer)
free(file->buffer);
if(file->filename)
free(file->filename);
free(file);
 
return 0;
}
/programs/develop/ktcc/trunk/libc/stdio/scanf.c
0,0 → 1,66
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
char *__scanf_buffer = 0;
 
int virtual_getc_con(void *sp, const void *obj)
// get next chat from string obj, save point is ptr to string char ptr
{
int ch;
const char**spc= (const char**)sp;
if (!spc) return EOF; // error
 
if (!*spc) *spc = __scanf_buffer; // first call, init savepoint
 
while (!**spc) // need to read more
{
if(!gets(__scanf_buffer)) return EOF;
*spc = __scanf_buffer;
strcat(__scanf_buffer,"\n"); // imitate delimiter
}
if (**spc == 26 || **spc == 3) // ^C ^Z end of scan, clear buffer
{
*spc = __scanf_buffer;
*__scanf_buffer = 0;
return EOF; // ^C ^Z
}
 
ch = **spc; (*spc)++ ;
 
//printf("getc '%c'[%d];", ch, ch);
return ch;
}
 
void virtual_ungetc_con(void *sp, int c, const void *obj)
// if can, one step back savepoint in s
{
const char**spc= (const char**)sp;
 
if (spc && *spc > __scanf_buffer) (*spc)--;
//printf("Ungetc '%c'[%d];", c, c);
}
 
 
int vscanf ( const char * format, va_list arg )
{
return format_scan(NULL, format, arg, &virtual_getc_con, &virtual_ungetc_con);
};
 
int scanf ( const char * format, ...)
{
va_list arg;
int n;
va_start(arg, format);
 
if(__scanf_buffer == NULL) __scanf_buffer = malloc(4096);
if(__scanf_buffer == NULL) return -3;
 
*__scanf_buffer = 0;
n = vscanf(format, arg);
 
va_end(arg);
return n;
}
 
 
/programs/develop/ktcc/trunk/libc/stdio/sprintf_tiny.c
0,0 → 1,97
/*
function for format output to the string. much lighter than standard sprintf
because of lesser formats supported
*/
 
 
#include <string.h>
//#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
 
char* __itoa(int n,char* s);
char* itoab(unsigned int n, char* s, int b);
 
int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args )
// support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align
// always zero-ended
{
char *fmt, *dest, buf[32];
fmt = (char*)format;
dest = s; dest[n - 1] = '\0';
int arg, len;
while (*fmt && (dest - s < n - 1))
{
if (*fmt != '%')
{
*dest++ = *fmt++;
continue;
}
if (fmt[1] == '%') // %%
{
*dest++ = '%';
fmt += 2;
continue;
}
arg = va_arg(args, int);
len = n - 1 - (dest - s);
switch (*++fmt)
{
case 'c':
*dest++ = (char)arg;
break;
case 's':
strncpy(dest, (char*)arg, len);
dest = strchr(dest, 0);
break;
case 'd':
__itoa(arg, buf);
strncpy(dest, buf, len);
dest = strchr(dest, 0);
break;
case 'x':
itoab((unsigned)arg, buf, 16);
strncpy(dest, buf, len);
dest = strchr(dest, 0);
break;
case 'u':
itoab((unsigned)arg, buf, 10);
strncpy(dest, buf, len);
dest = strchr(dest, 0);
break;
default:
*dest++ = *fmt;
}
fmt++;
}
*dest = '\0';
return dest - s;
}
 
 
int tiny_snprintf (char * s, size_t n, const char * format, ... )
{
va_list arg;
int rc;
va_start(arg, format);
 
rc = tiny_vsnprintf(s, n, format, arg);
 
va_end(arg);
return rc;
}
 
int tiny_sprintf (char * s, const char * format, ... )
{
va_list arg;
int rc;
va_start(arg, format);
 
rc = tiny_vsnprintf(s, 4096, format, arg);
 
va_end(arg);
return rc;
}
 
 
 
/programs/develop/ktcc/trunk/libc/stdio/clearerr.c
0,0 → 1,22
#include <stdio.h>
#include <string.h>
 
void clearerr ( FILE * stream )
{
errno = 0;
}
 
int ferror ( FILE * stream )
{
return errno;
}
 
void perror ( const char * str )
{
char *msg = strerror(errno);
 
if (str)
fprintf(stderr, "%s:%s\n", str, msg);
else
fprintf(stderr, "%s\n", msg);
}
/programs/develop/ktcc/trunk/libc/stdio/feof.c
0,0 → 1,11
#include <stdio.h>
int feof(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return EOF;
}
 
return file->filepos>=file->filesize;
}
/programs/develop/ktcc/trunk/libc/stdio/fflush.c
0,0 → 1,9
#include <stdio.h>
int fflush(FILE* file)
// file can be zero, as flush all
{
if (file && (file->mode & 3)==FILE_OPEN_READ)
return 0;
 
return(0); // always good, as no write buffering
}
/programs/develop/ktcc/trunk/libc/stdio/fgets.c
0,0 → 1,34
#include <stdio.h>
 
char * fgets ( char * str, int num, FILE * file )
// need to ignore \r\n in text mode
{
int rd = 0;
char c;
 
if(!file || !str)
{
errno = E_INVALIDPTR;
return NULL;
}
 
 
while (rd < num - 1)
{
c = fgetc(file);
if (EOF == c) break;
if ('\n' == c)
{
str[rd++] = c;
break;
}
else
str[rd++] = c;
}
if (0 == rd) return NULL;
else
{
str[rd] = '\0';
return str;
}
}
/programs/develop/ktcc/trunk/libc/stdio/format_print.c
0,0 → 1,639
/*
function for format output to the string
 
Siemargl update formats as http://www.cplusplus.com/reference/cstdio/printf/, no wchar though
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html is used too
%g explain https://support.microsoft.com/en-us/kb/43392
 
todo:
-fix precision in %g
-%u printed as signed, %x, %o also is promoted to long long
// FAIL 0x0FFFF7A7E as %x - signed long promotes sign, need %llx or %Lx and type conversion
-%a
-%n nothing printed
-%17.18f digits maximum format
-use %C as w_char L'x' (non standard extension)
-radix point always '.', no LOCALEs
*/
 
 
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stdarg.h>
 
enum flags_t
{
flag_unsigned = 0x02,
flag_register = 0x04,
flag_plus = 0x08,
flag_left_just = 0x10,
flag_lead_zeros = 0x20,
flag_space_plus = 0x40,
flag_hash_sign = 0x80,
flag_point = 0x100
};
int formatted_double_to_string(long double number, int format1, int format2, char *s, int flags);
int formatted_double_to_string_scientific(long double number, int format1, int format2, char *s, int flags);
int formatted_long_to_string(long long number, int format1, int prec, char *s, int flags);
int formatted_hex_to_string(unsigned long long number, int fmt1, int prec, char *s, int flags);
int formatted_octa_to_string(unsigned long long number, int fmt1, int prec, char *s, int flags);
 
 
int formatted_double_special(long double number, char *s)
// return 0 if no special values: NAN, INF. -0.0 ignored
// http://steve.hollasch.net/cgindex/coding/ieeefloat.html
{
struct IEEExp {
unsigned manl:32;
unsigned manh:32;
unsigned exp:15;
unsigned sign:1;
} *ip = (struct IEEExp *)&number;
 
if (ip->exp != 0x7fff) return 0;
 
if (ip->manh == 0x80000000 && ip->manl == 0) // Inf
{
if(ip->sign)
strcpy(s, "-INF");
else
strcpy(s, "+INF");
} else
if (ip->manh & ~0x7fffffff)
strcpy(s, "QNaN");
else
strcpy(s, "SNaN");
 
return 4;
}
 
int copy_and_align(char *dest, int width, char *src, int src_len, char sign, int flags)
// alingn number in buffer, put sign and fills additional places
// flags used only flag_left_just and flag_lead_zeros
// sign can be zero, 0, x, X, space, +, -
{
int rc = 0, sign_len;
char fill;
 
fill = (flags & flag_lead_zeros)&&((flags & flag_left_just)==0) ? '0' : ' ';
if(sign == 'x' || sign == 'X')
{
sign_len = 2;
} else
if (sign)
sign_len = 1;
else
sign_len = 0;
 
if ((flags & flag_left_just) || (src_len + sign_len >= width)) // left justify or no room
{
if (sign)
{
if(sign == 'x' || sign == 'X')
{
dest[0] = '0';
dest[1] = sign;
memcpy(dest + 2, src, src_len);
rc = src_len + 2;
} else
{ // single sign
dest[0] = sign;
memcpy(dest + 1, src, src_len);
rc = src_len + 1;
}
} else
{
memcpy(dest, src, src_len);
rc = src_len;
}
if (rc < width)
{
memset(dest + rc, fill, width - rc);
rc = width;
}
} else // right justify and fill
{
rc = width;
memcpy(dest + width - src_len, src, src_len);
memset(dest, fill, width - src_len);
if (flags & flag_lead_zeros)
{
if(sign == 'x' || sign == 'X')
{
dest[0] = '0';
dest[1] = sign;
} else
if (sign) dest[0] = sign;
} else
{
if(sign == 'x' || sign == 'X')
{
dest[width - src_len - 2] = '0';
dest[width - src_len - 1] = sign;
} else
if (sign) dest[width - src_len - 1] = sign;
}
}
return rc;
}
 
int formatted_double_to_string_scientific(long double number, int format1, int format2, char *s, int flags)
{
long double norm_digit;
long mul = 0;
char sign = 0;
char buf[50];
int len;
 
if((flags & flag_point) == 0) format2 = 6; // default prec if no point spec
 
len = formatted_double_special(number, buf);
if (len == 0)
{
if (number < 0) { sign = '-'; norm_digit = -number; }
else
{
norm_digit = number;
if (flags & flag_plus) sign = '+'; else
if (flags & flag_space_plus) sign = ' ';
}
// normalize
while (norm_digit < 1.0 && norm_digit > 0) { norm_digit *= 10; mul--; }
while (norm_digit >= 10.0) { norm_digit /= 10; mul++; }
 
len = formatted_double_to_string(norm_digit, 0, format2, buf, flags & ~(flag_plus | flag_space_plus));
 
if (flags & flag_register)
buf[len++] = 'E';
else
buf[len++] = 'e';
 
len += formatted_long_to_string(mul, 0, 3, buf + len, flag_plus | flag_lead_zeros);
}
else
flags &= ~flag_lead_zeros; // no need for INF, NAN
 
len = copy_and_align(s, format1, buf, len, sign, flags);
 
return len;
}
 
int formatted_double_to_string(long double number, int format1, int format2, char *s, int flags)
{
long double nafter, beforpointdigit;
long long intdigit, mul;
int div;
int i;
char sign = 0;
int fmt1;
int fmt2;
char buf[100], *pbuf = buf;
char buf_low[50], *pbuf_lo = buf_low;
 
if((flags & flag_point) == 0) format2 = 6; // default prec if no point spec
 
i = formatted_double_special(number, buf);
if (i == 0)
{
if (number < 0) {sign = '-'; number = -number; }
else
{
if (flags & flag_plus) sign = '+'; else
if (flags & flag_space_plus) sign = ' ';
}
 
fmt1 = 1;
fmt2 = format2;
if (fmt2 > 18) fmt2 = 18; //maximum size of long long type
 
beforpointdigit = floor(number + 0.00000000000001);
nafter = number - beforpointdigit;
 
//print part of number before point
mul = 1;
for(i = 0; i < sizeof buf - 1; i++)
{
mul *= 10;
if ((beforpointdigit/mul) < 1.0) { fmt1 = i + 1; break; }
}
if (i == sizeof buf - 1 || fmt1 > 17)
{
strcpy(s, "[too big number for %f, %a]");
return strlen(s);
}
 
mul /= 10;
while(mul > 1)
{
div = beforpointdigit / mul;
*pbuf++ = (char)div + '0';
beforpointdigit = beforpointdigit - div * mul;
mul /= 10;
}
*pbuf++=(char)beforpointdigit + '0';
 
//print part of number after point
mul = 1;
for(i = 0; i < fmt2; i++)
{
nafter = nafter*10;
mul *= 10;
}
 
intdigit = roundl(nafter);
 
mul /= 10;
for(i = 0; i < fmt2 - 1; i++)
{
div = intdigit / mul;
*pbuf_lo++=(char)div + '0';
intdigit = intdigit - div * mul;
mul /= 10;
if (mul == 1) break;
}
*pbuf_lo++ = (char)intdigit + '0';
 
// form full number
if (roundl(nafter) != 0 || fmt2 != 0)
{
*pbuf++ = '.';
memcpy(pbuf, buf_low, pbuf_lo - buf_low); pbuf += pbuf_lo - buf_low;
} else if (flags & flag_hash_sign)
*pbuf++ = '.';
}
else
{
flags &= ~flag_lead_zeros; // no need for INF, NAN
pbuf += i;
}
 
return copy_and_align(s, format1, buf, pbuf - buf, sign, flags);
}
 
int formatted_long_to_string(long long number, int format1, int prec, char *s, int flags)
{
int i;
int fmt;
char sign = 0;
long long digit;
long long mul;
int div;
char buf[100], *pbuf = buf;
 
if (number == -9223372036854775807LL - 1) // overflow all our math, cant minus this
{
strcpy(s, "-9223372036854775808");
return strlen(s);
}
 
if (flags & flag_point) flags &= ~flag_lead_zeros; // conflicting flags
 
if (number < 0) {sign = '-'; number = -number; }
else
{
if (flags & flag_plus) sign = '+'; else
if (flags & flag_space_plus) sign = ' ';
}
 
digit = number;
 
mul = (digit < 0) ? -1 : 1;
 
for(i = 0; i < sizeof buf - 2; i++)
{
if (digit / mul < 10) { fmt = i + 1; break; }
mul *= 10;
}
 
// add leading zeros by prec
for(i = 0; i < prec - fmt; i++) *pbuf++ = '0';
 
for(i = 0; i < fmt - 1; i++)
{
div = digit / mul;
*pbuf++ = (char)div + '0';
digit = digit - div * mul;
mul /= 10;
if (mul == 1 || mul == -1) break;
}
*pbuf++ = (char)digit + '0';
 
return copy_and_align(s, format1, buf, pbuf - buf, sign, flags);
}
 
int formatted_hex_to_string(unsigned long long number, int fmt1, int prec, char *s, int flags)
{
unsigned long long digit, mul;
int i, div, fmt;
char xdigs_lower[16]="0123456789abcdef";
char xdigs_upper[16]="0123456789ABCDEF";
char buf[50], *pbuf = buf, sign;
 
if (number == -9223372036854775807LL - 1) // overflow all our math, cant minus this
{
strcpy(buf, "FFFFFFFFFFFFFFFF");
pbuf += strlen(buf);
}
else
{
if (flags & flag_point) flags &= ~flag_lead_zeros; // conflicting flags
 
digit = number;
 
mul = (digit < 0) ? -1 : 1;
 
for(i = 0; i < sizeof buf - 2; i++)
{
if (digit / mul < 16) { fmt = i + 1; break; }
mul <<= 4;
}
 
// add leading zeros by prec
for(i = 0; i < prec - fmt; i++) *pbuf++ = '0';
 
for(i = 0; i < fmt - 1; i++)
{
div = digit / mul;
*pbuf++ = (flags & flag_register) ? xdigs_upper[div] : xdigs_lower[div];
digit = digit - div * mul;
mul >>= 4;
if (mul == 1 || mul == -1) break;
}
*pbuf++ = (flags & flag_register) ? xdigs_upper[digit] : xdigs_lower[digit];
}
 
sign = 0;
if(flags & flag_hash_sign)
sign = (flags & flag_register) ? 'X' : 'x';
 
return copy_and_align(s, fmt1, buf, pbuf - buf, sign, flags);
}
 
int formatted_octa_to_string(unsigned long long number, int fmt1, int prec, char *s, int flags)
{
unsigned long long digit, mul;
int i, div, fmt;
char xdigs_lower[16]="01234567";
char buf[50], *pbuf = buf;
 
if (number == -9223372036854775807LL - 1) // overflow all our math, cant minus this
{
strcpy(buf, "1777777777777777777777");
pbuf += strlen(buf);
}
else
{
if (flags & flag_point) flags &= ~flag_lead_zeros; // conflicting flags
 
digit = number;
 
mul = (digit < 0) ? -1 : 1;
 
for(i = 0; i < sizeof buf - 2; i++)
{
if (digit / mul < 8) { fmt = i + 1; break; }
mul <<= 3;
}
 
// add leading zeros by prec
for(i = 0; i < prec - fmt; i++) *pbuf++ = '0';
 
for(i = 0; i < fmt - 1; i++)
{
div = digit / mul;
*pbuf++ = xdigs_lower[div & 0x7];
digit = digit - div * mul;
mul >>= 3;
if (mul == 1 || mul == -1) break;
}
*pbuf++ = xdigs_lower[digit];
}
 
return copy_and_align(s, fmt1, buf, pbuf - buf, (flags & flag_hash_sign) ? '0' : 0, flags);
}
 
//int vsnprintf (char * s, size_t n, const char * format, va_list arg );
int format_print(char *dest, size_t maxlen, const char *fmt0, va_list argp)
{
int i;
int length;
int fmt1, fmt2; // width, precision
size_t pos, posc;
long long intdigit;
long double doubledigit;
const char *fmt, *fmtc; // first point to %, fmtc points to specifier
char *s; // pointer to current dest char
char *str;
char buf[200]; // buffer for current argument value print representation
int format_flag;
int flag_long; // 2 = long double or long long int or wchar
int *point_to_n = NULL;
int flags; // parsed flags
 
fmt = fmt0;
s = dest;
pos = 0;
while(pos < maxlen)
{
if (*fmt != '%') // usual char
{
if ('\0' == (*s++ = *fmt++)) break;
pos++;
continue;
}
 
if (*(fmt + 1) == '%') // %%
{
*s++ = '%'; pos++;
fmt += 2;
continue;
}
//checking to containg format in the string
fmtc = fmt;
posc = pos;
 
flags = 0;
format_flag = 0;
flag_long = 0; // 2 = long double or long long int or wchar
 
while(*fmtc != '\0' && !format_flag) // searching end of format
{
fmtc++; posc++;
switch( *fmtc )
{
case 'a':
format_flag = 1;
flags |= flag_unsigned;
break;
case 'A':
format_flag = 1;
flags |= flag_unsigned | flag_register;
break;
case 'c': case 'd': case 'i': case 'e': case 'f': case 'g': case 's': case 'n':
format_flag = 1;
break;
case 'E': case 'F': case 'G':
format_flag = 1;
flags |= flag_register;
break;
case 'l':
flag_long = flag_long ? 2 : 1; // ll.eq.L
break;
case 'L':
flag_long = 2;
break;
case 'o': case 'u': case 'x': case 'p':
format_flag = 1;
flags |= flag_unsigned;
break;
case 'X': case 'P':
format_flag = 1;
flags |= flag_unsigned | flag_register;
break;
case '+':
flags |= flag_plus;
break;
case '-':
flags |= flag_left_just;
break;
case ' ': // space
flags |= flag_space_plus;
break;
case '#':
flags |= flag_hash_sign;
break;
case '*': case '.': // just skip
break;
default:
if(isdigit(*fmtc)) break;
strncpy(dest, "print format error - in % invalid char found", maxlen);
return -1; // non format char found - user error
}
}
 
if (format_flag == 0)
{
strncpy(dest, "print format error - % without format specifier", maxlen);
return -1; // format char not found - user error
}
 
fmt1 = 0;
fmt2 = 0;
if (posc - pos > 1) // try to read width, precision
{
fmt++;
for(i = pos + 1; i < posc; i++)
{
switch(*fmt)
{
case '0':
if(fmt1 == 0 && (flags & flag_point) == 0) flags |= flag_lead_zeros;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if ((flags & flag_point) == 0)
fmt1 = fmt1 * 10 + (*fmt -'0');
else
fmt2 = fmt2 * 10 + (*fmt -'0');
break;
case '*':
if (flag_point == 0)
fmt1 = va_arg(argp, int);
else
fmt2 = va_arg(argp, int);
break;
case '.':
flags |= flag_point;
break;
case 'l': case 'L': case '+': // valid chars - skip
case '-': case ' ': case '#':
break;
default: // must be error
strncpy(dest, "print format error - %width.precision", maxlen);
return -1; // format char not found - user error
}
fmt++;
}
}
 
// do real work - format arguments values
length = 0;
switch(*fmtc)
{
case 'n':
point_to_n = va_arg(argp, int*);
break;
case 'c':
if (pos + 1 <= maxlen)
{
buf[0] = (char)va_arg(argp, int);
length = 1;
}
break;
case 's': // special case - without buf
str = va_arg(argp, char*);
length = strlen(str);
if ((flags & flag_point) && (length > fmt2)) length = fmt2; // cut by precision
if (pos + length > maxlen) length = maxlen - pos;
memcpy(s, str ,length);
s += length;
pos += length;
break;
case 'd': case 'i': case 'u': case 'U':
if (flag_long == 0) intdigit = va_arg(argp, int); else
if (flag_long == 1) intdigit = va_arg(argp, long); else
if (flag_long == 2) intdigit = va_arg(argp, long long);
length = formatted_long_to_string(intdigit, fmt1, fmt2, buf, flags);
break;
case 'o':
if (flag_long == 0) intdigit = va_arg(argp, int); else
if (flag_long == 1) intdigit = va_arg(argp, long); else
if (flag_long == 2) intdigit = va_arg(argp, long long);
length = formatted_octa_to_string(intdigit, fmt1, fmt2, buf, flags);
break;
case 'p': case 'P': case 'x': case 'X':
if (flag_long == 0) intdigit = va_arg(argp, int); else
if (flag_long == 1) intdigit = va_arg(argp, long); else
if (flag_long == 2) intdigit = va_arg(argp, long long);
length=formatted_hex_to_string(intdigit, fmt1, fmt2, buf, flags);
break;
case 'a': case 'A': case 'f': case 'F':
if (flag_long <= 1) doubledigit = va_arg(argp, double); else
if (flag_long == 2) doubledigit = va_arg(argp, long double);
length = formatted_double_to_string(doubledigit, fmt1, fmt2, buf, flags);
break;
case 'e': case 'E':
if (flag_long <= 1) doubledigit = va_arg(argp, double); else
if (flag_long == 2) doubledigit = va_arg(argp, long double);
length = formatted_double_to_string_scientific(doubledigit, fmt1, fmt2, buf, flags);
break;
case 'g': case 'G':
//prec special case, this is just workaround
if (flag_long <= 1) doubledigit = va_arg(argp, double); else
if (flag_long == 2) doubledigit = va_arg(argp, long double);
if (flags & flag_point)
length = formatted_double_to_string(doubledigit, fmt1, fmt2, buf, flags);
else
length = formatted_double_to_string(doubledigit, fmt1, 1, buf, flags | flag_point);
i = formatted_double_to_string_scientific(doubledigit, fmt1, fmt2, buf + sizeof buf / 2, flags);
if(length > i)
{
memcpy(buf, buf + sizeof buf / 2, i);
length = i;
}
break;
}
if (*fmtc != 's' && length > 0) // skip multiple string copying
{
if (pos + length > maxlen) length = maxlen - pos;
memcpy(s, buf, length);
s += length;
pos += length;
}
fmt = fmtc + 1;
}
 
if (point_to_n) *point_to_n = pos;
return(pos);
}
/programs/develop/ktcc/trunk/libc/stdio/format_scan.c
0,0 → 1,417
/*
function for format read from any source
 
Siemargl formats as http://www.cplusplus.com/reference/cstdio/scanf/, no wchar though
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html is used too
 
todo:
[characters], [^characters]
-%n nothing scanned, filled only if good result
-%d, i, u, o, x, p read similar - detect base by prefix 0 or 0x
-%a
-can overflow unsigned as signed
-radix point always '.', no LOCALEs
*/
 
 
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stdarg.h>
typedef int (*virtual_getc)(void *sp, const void *obj);
typedef void (*virtual_ungetc)(void *sp, int c, const void *obj);
 
enum flags_t
{
flag_unsigned = 0x02,
flag_register = 0x04,
flag_plus = 0x08,
flag_left_just = 0x10,
flag_lead_zeros = 0x20,
flag_space_plus = 0x40,
flag_hash_sign = 0x80,
flag_point = 0x100
};
 
int try_parse_real(long double *real, int ch, const void *src, void *save, virtual_getc vgetc, virtual_ungetc vungetc)
// returns 1 if OK, -1 == EOF, -2 parse broken
{
int sign = 1, have_digits = 0;
long long div;
 
if (ch == '+')
{
ch = vgetc(save, src);
if (ch == EOF) return EOF;
} else
if (ch == '-')
{
sign = -1;
ch = vgetc(save, src);
if (ch == EOF) return EOF;
};
*real = 0.0;
for (;;) // mantissa before point
{
// test ch is valid
if (isdigit(ch))
{
*real = *real * 10 + ch - '0';
have_digits++;
ch = vgetc(save, src);
if (ch == EOF || isspace(ch)) break; // ok, just finish num
} else
if (ch == '.' || ch == 'E' || ch == 'e')
{
break; // ok
}
else
{
vungetc(save, ch, src);
break;
}
}
if (ch != '.' && ch != 'E' && ch != 'e') // ok, just integer part
{
*real *= sign;
if (have_digits)
return 1;
else
return -2;
}
 
if(ch == '.')
{
ch = vgetc(save, src);
div = 10; // use as divisor
for (;;) // mantissa after point
{
// test ch is valid
if (isdigit(ch))
{
*real += (double)(ch - '0') / div;
div *= 10;
have_digits++;
ch = vgetc(save, src);
if (ch == EOF || isspace(ch)) break; // ok, just finish num
} else
if (ch == 'E' || ch == 'e')
{
break; // ok
}
else
{
vungetc(save, ch, src);
break;
}
}
if (ch != 'E' && ch != 'e') // ok, real as XX.YY
{
*real *= sign;
if (have_digits)
return 1;
else
return -2;
}
}
 
ch = vgetc(save, src);
*real *= sign;
// exponent
sign = 1;
if (ch == '+')
{
ch = vgetc(save, src);
if (ch == EOF) return EOF;
} else
if (ch == '-')
{
sign = -1;
ch = vgetc(save, src);
if (ch == EOF) return EOF;
};
div = 0;
for (;;)
{
// test ch is valid
if (isdigit(ch))
{
div = div * 10 + ch - '0';
ch = vgetc(save, src);
if (ch == EOF || isspace(ch)) break; // ok, just finish num
}
else
{
vungetc(save, ch, src);
break;
}
}
div *= sign;
*real *= pow(10, div);
 
return 1;
}
 
int try_parse_int(long long *digit, int ch, const void *src, void *save, virtual_getc vgetc, virtual_ungetc vungetc)
{
int sign = 1, base = 10, have_digits = 0;
 
if (ch == '+')
{
ch = vgetc(save, src);
if (ch == EOF) return EOF;
} else
if (ch == '-')
{
sign = -1;
ch = vgetc(save, src);
if (ch == EOF) return EOF;
};
 
if (ch == '0') // octal or hex, read next
{
base = 8;
ch = vgetc(save, src);
if (ch == EOF || isspace(ch))
have_digits++;
else
if (ch == 'x' || ch == 'X')
{
base = 16;
ch = vgetc(save, src);
if (ch == EOF) return EOF;
}
}
*digit = 0;
for (;;)
{
// test ch is valid
if ((isdigit(ch) && base == 10) ||
(isdigit(ch) && base == 8 && ch < '8') ||
(isxdigit(ch) && base == 16))
{
if (base == 16)
{
if (ch <= '9') ch-= '0';
else
if (ch <= 'F') ch = 10 + ch - 'A';
else
ch = 10 + ch - 'a';
}
else
ch -= '0';
*digit = *digit * base + ch;
have_digits++;
ch = vgetc(save, src);
if (ch == EOF || isspace(ch)) break; // ok, just finish num
}
else if (ch == EOF || isspace(ch))
break;
else
{
vungetc(save, ch, src);
break;
}
}
*digit *= sign;
if (have_digits)
return 1;
else
return -2;
}
 
 
 
int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc)
{
int i;
int length;
int fmt1, fmt2; // width, precision
size_t pos, posc;
const char *fmtc; // first point to %, fmtc points to specifier
int ch;
int format_flag;
int flag_long; // 2 = long double or long long int or wchar
int *point_to_n = NULL, nread = 0;
int flags; // parsed flags
int save = 0;
char *arg_str;
int *arg_int;
long *arg_long;
long long *arg_longlong;
float *arg_float;
double *arg_double;
long double *arg_longdouble;
long long digit;
long double real;
 
 
pos = 0;
while(*fmt)
{
while (*fmt && isspace(*fmt)) fmt++; // skip paces in format str
 
if (*fmt != '%') // usual char
{
ch = vgetc(&save, src);
if (ch != *fmt++) // char not match format
{
vungetc(&save, ch, src);
break;
}
pos++;
continue;
}
 
if (*(fmt + 1) == '%') // %%
{
ch = vgetc(&save, src);
if (ch != '%') // char not match format
{
vungetc(&save, ch, src);
break;
}
pos++;
fmt += 2;
continue;
}
//checking to containg format in the string
fmtc = fmt;
posc = pos;
 
flags = 0;
format_flag = 0;
flag_long = 0; // 2 = long double or long long int or wchar
 
while(*fmtc != '\0' && !format_flag) // searching end of format
{
fmtc++; posc++;
switch( *fmtc )
{
case 'a':
format_flag = 1;
flags |= flag_unsigned;
break;
case 'c': case 'd': case 'i': case 'e': case 'f': case 'g': case 's': case 'n':
format_flag = 1;
break;
case 'l':
flag_long = flag_long ? 2 : 1; // ll.eq.L
break;
case 'L':
flag_long = 2;
break;
case 'o': case 'u': case 'x': case 'p':
format_flag = 1;
flags |= flag_unsigned;
break;
case '*': case '.': // just skip
break;
default:
if(isdigit(*fmtc)) break;
goto exit_me; // non format char found - user error
}
}
 
if (format_flag == 0)
{
goto exit_me; // format char not found - user error
}
 
fmt1 = 0;
fmt2 = 0;
if (posc - pos > 1) // try to read width, precision
{
fmt++;
for(i = pos + 1; i < posc; i++)
{
switch(*fmt)
{
case '0':
if(fmt1 == 0 && (flags & flag_point) == 0) flags |= flag_lead_zeros;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if ((flags & flag_point) == 0)
fmt1 = fmt1 * 10 + (*fmt -'0');
else
fmt2 = fmt2 * 10 + (*fmt -'0');
break;
case '*': // ignoring
break;
case '.':
flags |= flag_point;
break;
case 'l': case 'L': // valid chars - skip
break;
default: // must be error
goto exit_me; // format char not found - user error
}
fmt++;
}
}
 
// do real work - format arguments values
// skip input spaces
do {
ch = vgetc(&save, src);
if (ch == EOF) goto exit_me;
} while (isspace(ch));
 
switch(*fmtc)
{
case 'n':
point_to_n = va_arg(argp, int*);
vungetc(&save, ch, src);
break;
case 'c': // read width chars, ever spaces
arg_str = va_arg(argp, char*);
if (fmt1 == 0) length = 1;
else length = fmt1;
for (i = 0; i < length;)
{
*arg_str++ = ch; i++;
ch = vgetc(&save, src);
if (ch == EOF) break;
}
if (i < length) goto exit_me; // not enough chars
break;
case 's':
arg_str = va_arg(argp, char*);
if (fmt1 == 0) length = 4095; // max string scan 4096
else length = fmt1;
for (i = 0; i < length; i++)
{
*arg_str++ = ch;
ch = vgetc(&save, src);
if (ch == EOF || isspace(ch)) break; // ok, just finish string
}
*arg_str++ = '\0';
break;
case 'd': case 'i': case 'u':
case 'o': case 'p': case 'x':
i = try_parse_int(&digit, ch, src, &save, vgetc, vungetc);
if (i < 0) goto exit_me;
 
if (flag_long == 0) { arg_int = va_arg(argp, int*); *arg_int = (int)digit; } else
if (flag_long == 1) { arg_long = va_arg(argp, long*); *arg_long = (long)digit; } else
if (flag_long == 2) { arg_longlong = va_arg(argp, long long*); *arg_longlong = digit; }
break;
case 'a': case 'A': case 'f': case 'F':
case 'e': case 'E':
case 'g': case 'G':
i = try_parse_real(&real, ch, src, &save, vgetc, vungetc);
if (i < 0) goto exit_me;
 
if (flag_long == 0) { arg_float = va_arg(argp, float*); *arg_float = (float)real; } else
if (flag_long == 1) { arg_double = va_arg(argp, double*); *arg_double = (double)real; } else
if (flag_long == 2) { arg_longdouble = va_arg(argp, long double*); *arg_longdouble = real; }
break;
}
 
fmt = fmtc + 1;
nread++;
}
exit_me:
if (point_to_n) *point_to_n = nread;
return nread;
}
/programs/develop/ktcc/trunk/libc/stdio/fprintf.c
0,0 → 1,44
#include <stdio.h>
#include <stdlib.h>
 
 
 
int fprintf(FILE* file, const char* format, ...)
{
va_list arg;
va_start (arg, format);
 
return vfprintf(file, format, arg);
 
}
 
int vfprintf ( FILE * file, const char * format, va_list arg )
{
char *buf;
int printed, rc = 0;
 
if(!file || !format)
{
errno = E_INVALIDPTR;
return errno;
}
 
buf=malloc(4096*2); //8kb max
if(!buf)
{
errno = E_NOMEM;
return errno;
}
 
printed=format_print(buf,8191, format,arg);
if (file == stderr)
debug_out_str(buf);
else
rc = fwrite(buf,printed,1,file);
free(buf);
 
if (rc < 0)
return rc;
else
return(printed);
}
/programs/develop/ktcc/trunk/libc/stdio/fputs.c
0,0 → 1,27
#include <stdio.h>
 
int fputs ( const char * str, FILE * file )
{
int rc;
 
if(!file || !str)
{
errno = E_INVALIDPTR;
return EOF;
}
 
if ((file->mode & 3)==FILE_OPEN_READ)
{
errno = E_ACCESS;
return EOF;
}
 
while(*str)
{
rc = fputc(*str, file);
if (rc < 0) return rc;
str++;
}
 
return 0;
}
/programs/develop/ktcc/trunk/libc/stdio/fseek.c
0,0 → 1,19
#include <stdio.h>
int fseek(FILE* file,long offset,int origin)
{
fpos_t pos;
if(!file)
{
errno = E_INVALIDPTR;
return errno;
}
 
if (origin==SEEK_CUR)
offset+=file->filepos;
else if (origin==SEEK_END)
offset+=file->filesize;
else if (origin!=SEEK_SET)
return EOF;
pos = offset;
return fsetpos(file, &pos);
}
/programs/develop/ktcc/trunk/libc/stdio/ftell.c
0,0 → 1,11
#include <stdio.h>
long ftell(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return -1L;
}
 
return file->filepos;
}
/programs/develop/ktcc/trunk/libc/stdio/printf.c
0,0 → 1,32
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <stdarg.h>
 
int printf(const char *format, ...)
{
va_list arg;
va_start(arg, format);
 
return vprintf(format, arg);
}
 
 
int vprintf ( const char * format, va_list arg )
{
int i = 0;
int printed_simbols = 0;
char *s;
 
i=con_init_console_dll();
 
if (i == 0)
{
s = malloc(4096);
printed_simbols = format_print(s, 4096, format, arg);
con_write_string(s, printed_simbols);
free(s);
}
 
return(printed_simbols);
}
/programs/develop/ktcc/trunk/libc/stdio/snprintf.c
0,0 → 1,15
#include <stdarg.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/vsnprintf.c
0,0 → 1,14
#include <kolibrisys.h>
#include <stdlib.h>
#include <stdio.h>
 
int vsnprintf(char *dest, size_t size, const char *format, va_list ap)
{
return format_print(dest,size, format, ap);
}
 
 
int vsprintf (char * dest, const char * format, va_list ap )
{
return format_print(dest, 4096, format, ap);
}
/programs/develop/ktcc/trunk/libc/stdio/fscanf.c
0,0 → 1,42
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
 
int virtual_getc_file(void *sp, const void *obj)
// get next chat from file obj, save point is ptr to string char ptr
{
FILE *f = (FILE *)obj;
int ch = fgetc(f);
 
//printf("getc '%c'[%d];", ch, ch);
 
return ch;
}
 
void virtual_ungetc_file(void *sp, int c, const void *obj)
// if can, one step back savepoint in s
{
FILE *f = (FILE *)obj;
 
if (f) ungetc(c, f);
}
 
 
int vfscanf ( FILE * stream, const char * format, va_list arg )
{
return format_scan(stream, format, arg, &virtual_getc_file, &virtual_ungetc_file);
};
 
int fscanf ( FILE * stream, const char * format, ...)
{
va_list arg;
int n;
va_start(arg, format);
 
n = vfscanf(stream, format, arg);
 
va_end(arg);
return n;
}
 
 
/programs/develop/ktcc/trunk/libc/stdio/sscanf.c
0,0 → 1,46
#include <stdio.h>
#include <stdarg.h>
 
int virtual_getc_str(void *sp, const void *obj)
// get next chat from string obj, save point is ptr to string char ptr
{
int ch;
const char *s = (const char *)obj;
const char**spc= (const char**)sp;
if (!s || !spc) return EOF; // error
 
if (!*spc) *spc = s; // first call, init savepoint
 
if (!**spc) return EOF; // EOS
 
ch = **spc; (*spc)++ ;
 
return ch;
}
 
void virtual_ungetc_str(void *sp, int c, const void *obj)
// if can, one step back savepoint in s
{
const char *s = (const char *)obj;
const char**spc= (const char**)sp;
 
if (s && spc && *spc > s) (*spc)--;
}
 
int vsscanf ( const char * s, const char * format, va_list arg )
{
return format_scan(s, format, arg, &virtual_getc_str, &virtual_ungetc_str);
};
 
int sscanf ( const char * s, const char * format, ...)
{
va_list arg;
int n;
va_start(arg, format);
 
n = vsscanf(s, format, arg);
 
va_end(arg);
return n;
}
 
/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/putchar.c
0,0 → 1,14
#include <conio.h>
 
int putchar ( int 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;
}
/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/string/strerror.c
0,0 → 1,105
#include <string.h>
#include <errno.h>
 
char* strerror(int err)
{
char *msg;
switch(err)
{
case E_SUCCESS:
msg = "Success";
break;
case -1:
msg = "End of file";
break;
case E_UNSUPPORTED:
msg = "Function is not supported for the given file system";
break;
case E_UNKNOWNFS:
msg = "Unknown file system";
break;
case E_NOTFOUND:
msg = "File not found";
break;
case E_EOF:
msg = "End of file, EOF";
break;
case E_INVALIDPTR:
msg = "Pointer lies outside of application memory";
break;
case E_DISKFULL:
msg = "Disk is full";
break;
case E_FSYSERROR:
msg = "Dile system error";
break;
case E_ACCESS:
msg = "Access denied";
break;
case E_HARDWARE:
msg = "Device error";
break;
case E_NOMEM:
msg = "File system requires more memory";
break;
case E_NOMEM2:
msg = "Not enough memory";
break;
case E_FILEFMT:
msg = "File is not executable";
break;
case E_TOOMANY:
msg = "Too many processes";
break;
/* Socket errors */
case ENOBUFS:
msg = "Broken buffer";
break;
case EINPROGRESS:
msg = "Operation now in progress";
break;
case EOPNOTSUPP:
msg = "Operation not supported on transport endpoint";
break;
case EWOULDBLOCK:
msg = "Operation would block";
break;
case ENOTCONN:
msg = "Transport endpoint is not connected";
break;
case EALREADY:
msg = "Operation already in progress";
break;
case EINVALUE:
msg = "Invalid argument";
break;
case EMSGSIZE:
msg = "Message too long";
break;
case ENOMEM:
msg = "Out of memory";
break;
case EADDRINUSE:
msg = "Address already in use";
break;
case ECONNREFUSED:
msg = "Connection refused";
break;
case ECONNRESET:
msg = "Connection reset by peer";
break;
case EISCONN:
msg = "Transport endpoint is already connected";
break;
case ETIMEDOUT:
msg = "Connection timed out";
break;
case ECONNABORTED:
msg = "Software caused connection abort";
break;
default:
msg = "Unknown error";
break;
}
return msg;
}
/programs/develop/ktcc/trunk/libc/string/memrchr.c
0,0 → 1,12
/* memrchr.c from musl
*/
 
#include <string.h>
 
void *memrchr(const void *m, int c, size_t n)
{
const unsigned char *s = m;
c = (unsigned char)c;
while (n--) if (s[n]==c) return (void *)(s+n);
return 0;
}
/programs/develop/ktcc/trunk/libc/string/memmove.asm
0,0 → 1,53
format ELF
 
section '.text' executable
include '../proc32.inc'
 
public memcpy
public memmove
 
proc memcpy c, to:dword,from:dword,count:dword
push esi
push edi
mov ecx,[count]
test ecx,ecx
jz no_copy_block
mov esi,[from]
mov edi,[to]
cld
rep movsb
no_copy_block:
 
pop edi
pop esi
mov eax, [to]
ret
endp
 
proc memmove c, to:dword,from:dword,count:dword
 
push esi
push edi
mov ecx,[count]
test ecx,ecx
jz no_copy_block_
mov esi,[from]
mov edi,[to]
cmp esi, edi
je no_copy_block_
jg copy_
add esi, ecx
add edi, ecx
dec esi
dec edi
std
copy_:
rep movsb
cld
no_copy_block_:
 
pop edi
pop esi
mov eax,[to]
ret
endp
/programs/develop/ktcc/trunk/libc/string/calloc.c
0,0 → 1,13
#include <stdlib.h>
#include <string.h>
 
void* syscalloc (size_t num, size_t size)
{
size_t bytes = num * size;
void *p = sysmalloc(bytes);
 
if(p)
memset(p, 0, bytes);
 
return p;
}
/programs/develop/ktcc/trunk/libc/string/memcmp.c
0,0 → 1,17
#include <string.h>
 
typedef unsigned char uc;
int memcmp(const void* buf1,const void* buf2,size_t count)
{
int i;
for (i=0;i<count;i++)
{
if (*(uc*)buf1<*(uc*)buf2)
return -1;
if (*(uc*)buf1>*(uc*)buf2)
return 1;
(uc*)buf1++;
(uc*)buf2++;
}
return 0;
}
/programs/develop/ktcc/trunk/libc/string/memchr.c
0,0 → 1,12
#include <string.h>
 
void* memchr(const void* buf,int c,size_t count)
{
int i;
for (i=0;i<count;i++)
if (*(char*)buf==(char)c)
return (void*)buf;
else
buf++;
return (void*)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:
mov eax, [esp+8]
pop edi
ret
/programs/develop/ktcc/trunk/libc/string/strcat.c
0,0 → 1,10
#include <string.h>
 
char* strcat(char* strDest, const char* strSource)
{
char* res;
res=strDest;
while (*strDest) strDest++;
while ((*strDest++ = *strSource++)) ;
return res;
}
/programs/develop/ktcc/trunk/libc/string/strchr.c
0,0 → 1,11
#include <string.h>
 
char* strchr(const char* string, int c)
{
do {
if (*string == (char)c)
return (char*)string;
} while (*string++);
 
return NULL;
}
/programs/develop/ktcc/trunk/libc/string/strcmp.c
0,0 → 1,16
#include <string.h>
 
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/strcpy.c
0,0 → 1,9
#include <string.h>
 
char* strcpy(char* strDest,const char* strSource)
{
char* res;
res=strDest;
while((*strDest++ = *strSource++)) ;
return res;
}
/programs/develop/ktcc/trunk/libc/string/strcspn.c
0,0 → 1,20
#include <string.h>
 
size_t strcspn(const char* string, const char* strCharSet)
{
const char* temp;
int i;
i=0;
while(*string)
{
temp=strCharSet;
while (*temp!='\0')
{
if (*string==*temp)
return i;
temp++;
}
i++;string++;
}
return i;
}
/programs/develop/ktcc/trunk/libc/string/strdup.c
0,0 → 1,13
#include <stdlib.h>
#include <string.h>
 
char* strdup(const char* str)
{
char* res;
int len;
len=strlen(str)+1;
res=malloc(len);
if(res)
memcpy(res,str,len);
return res;
}
/programs/develop/ktcc/trunk/libc/string/strnbrk.c
0,0 → 1,18
#include <string.h>
 
char* strpbrk(const char* string, const char* strCharSet)
{
const char* temp;
while (*string!='\0')
{
temp=strCharSet;
while (*temp!='\0')
{
if (*string==*temp)
return (char*)string;
temp++;
}
string++;
}
return (char*)0;
}
/programs/develop/ktcc/trunk/libc/string/strncat.c
0,0 → 1,15
#include <string.h>
 
char* strncat(char* strDest,const char* strSource,size_t count)
{
char* res;
res=strDest;
while (*strDest) 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,14
#include <string.h>
 
int strncmp(const char* string1, const char* string2, size_t count)
{
while(count>0 && (*string1==*string2))
{
if ('\0' == *string1) return 0;
++string1;
++string2;
--count;
}
if(count) return (*string1 - *string2);
return 0;
}
/programs/develop/ktcc/trunk/libc/string/strncpy.c
0,0 → 1,16
#include <string.h>
 
char* strncpy(char* strDest,const char* strSource,size_t count)
{
char* res;
res=strDest;
while (count>0)
{
*strDest=*strSource;
if (*strSource!='\0')
strSource++;
strDest++;
count--;
}
return res;
}
/programs/develop/ktcc/trunk/libc/string/strrchr.c
0,0 → 1,16
#include <string.h>
 
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/strrev.c
0,0 → 1,14
#include <string.h>
 
char* strrev(char *p)
{
char *q = p, *res = p, z;
while(q && *q) ++q; /* find eos */
for(--q; p < q; ++p, --q)
{
z = *p;
*p = *q;
*q = z;
}
return res;
}
/programs/develop/ktcc/trunk/libc/string/strspn.c
0,0 → 1,23
#include <string.h>
 
size_t 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;
temp++;
}
if (*temp=='\0')
break;
string++;
i++;
}
return i;
}
/programs/develop/ktcc/trunk/libc/string/strstr.c
0,0 → 1,14
#include <string.h>
 
char* strstr(const char* s, const char* find)
{
int len;
len=strlen(find);
while (1)
{
if (strncmp(s,find,len)==0) return (char*)s;
if (*s=='\0')
return (char*) 0;
s++;
}
}
/programs/develop/ktcc/trunk/libc/string/strtok.c
0,0 → 1,25
#include <string.h>
 
char* strtok(char* s,const char* delim)
// non reentrant
{
static char* savep;
char* res;
 
if(s)
savep = NULL;
else
s = savep;
 
if (*s == '\0')
return NULL;
s += strspn(s, delim);
if (*s == '\0')
return NULL;
res = s;
s += strcspn(s, delim);
savep = s + 1;
*s = '\0';
return res;
}
 
/programs/develop/ktcc/trunk/libc/string/is.c
0,0 → 1,20
#include <ctype.h>
unsigned short __is[129] = {
0, /* EOF */
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/strcoll.c
0,0 → 1,6
#include <string.h>
 
int strcoll(const char* string1,const char* string2)
{
return strcmp(string1,string2);
}
/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/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/kolibrisys/process.asm
0,0 → 1,24
format ELF
;include "public_stdcall.inc"
 
public _ksys_get_process_table
public _ksys_kill_process
 
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
 
_ksys_kill_process:
;arg - pid
mov eax, 18
mov ebx, 18
mov ecx,[esp+4]
int 0x40
ret 4
/programs/develop/ktcc/trunk/libc/kolibrisys/thread.asm
0,0 → 1,33
format ELF
include "public_stdcall.inc"
section '.text' executable
extrn sysmalloc
public_stdcall _ksys_start_thread,12
;arg1 - proc
;arg2 - stacksize
;arg3 - pid
push dword [esp+8]
call sysmalloc
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/_ksys_files_acces.asm
0,0 → 1,124
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
ret
 
error_for_file_size:
neg eax
 
ret
endp
 
 
align 4
proc _ksys_readfile stdcall,filename:dword,position:dword,sizeblock:dword,buffer:dword, preadbytes: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
 
mov esi, [preadbytes]
mov [esi], ebx
 
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/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,76
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]
; siemargl moved to post-check
; 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:
test al,al
jz exit_check_simbol
 
;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/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/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/sound.asm
0,0 → 1,65
format ELF
include "public_stdcall.inc"
section '.text' executable
public_stdcall _ksys_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 _ksys_sound_play_block,0
mov edx,ebx
mov eax,55
xor ebx,ebx
inc ebx
int 0x40
mov ebx,edx
ret
public_stdcall _ksys_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 _ksys_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 _ksys_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 _ksys_sound_speaker_play,4
;arg1 - data
mov edx,ebx
mov eax,55
mov ebx,55
mov esi,[esp+4]
int 0x40
mov ebx,edx
ret 4
/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/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/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/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/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/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,33
INCLUDE = include
LIBSFORBUILD = math
LIBNAME = libck.a
CC = ../bin/kos32-tcc
CFLAGS = -I$(INCLUDE) -m32 -nostdinc -nostdlib -DGNUC
DIRS := stdio memory kolibrisys string stdlib math dlfcn libgen fs net
 
##############################################################
#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 -rcs $(LIBNAME) $^
 
$(cfiles): $(INCLUDE)/*.h
 
$(asmfiles):
fasm $*.asm $*.o
 
clean:
$(doClean)
 
install:
cp $(LIBNAME) ../bin/lib
/programs/develop/ktcc/trunk/libc/build.bat
0,0 → 1,71
@echo off
echo ####################################################
echo # Melibc builder #
echo # usage: build [clean] #
echo ####################################################
rem #### CONFIG SECTION ####
set LIBNAME=libck.a
set INCLUDE=include
set CC=kos32-tcc
set CFLAGS=-c -nostdinc -DGNUC -I"%cd%\%INCLUDE%" -Wall
set AR=kos32-ar
set ASM=fasm
set dirs=stdio memory kolibrisys string stdlib math dlfcn libgen fs net
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
echo compile .c %1
%CC% %CFLAGS% %1 -o "%~dpn1.o"
if not %errorlevel%==0 goto Error_Failed
set objs=%objs% "%~dpn1.o"
goto :eof
 
:Compile_Asm
echo compile .asm %1
%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"
)
echo calling AR
%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/dlfcn/dlfcn.c
0,0 → 1,91
#include <kos32sys1.h>
 
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
 
typedef struct {
char *name;
void *ptr;
} KosExp;
 
typedef struct {
void **importNames;
char * libraryName;
} KosImp;
 
static int stdcall dll_Load(KosImp *importTableEntry);
 
static const char *__error;
 
static int stdcall dll_Load(KosImp *importTableEntry) {
for (; importTableEntry->importNames; importTableEntry++) {
char libPath[256] = "/sys/lib/";
KosExp *exports = NULL;
void **libImports = importTableEntry->importNames;
strcat(libPath, importTableEntry->libraryName);
if (!(exports = dlopen(libPath, 0))) { return 1; }
for (; *libImports; libImports++) {
if (!(*libImports = dlsym(exports, *libImports))) { return 1; }
}
}
return 0;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlopen.html
// Current implementation fully ignores "mode" parameter
void *dlopen(const char *name, int mode) {
KosExp *exports = NULL;
 
// load library using syscall
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(name));
if (!exports) {
char libPath[256] = "/sys/lib/";
 
strcat(libPath, name);
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(libPath));
if (!exports) {
__error = "Library not found in \"/sys/lib/\" nor current folder";
return NULL;
}
}
// call anything starting with "lib_"
for (KosExp *export = exports; export->name; export++) {
if (!memcmp(export->name, "lib_", 4)) {
asm volatile (
"call *%4" ::
"a"(sysmalloc),
"b"(sysfree),
"c"(sysrealloc),
"d"(dll_Load),
"r"(export->ptr));
}
}
return exports;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
void *dlsym(void *handle, const char *name) {
KosExp *exp = handle;
 
for (; exp->name; exp++) {
if (!strcmp(exp->name, name)) {
return exp->ptr;
}
}
__error = "Symbol not found";
return NULL;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlclose.html
int dlclose(void *handle) {
return 0;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlerror.html
char *dlerror(void) {
char *ret = __error ? strdup(__error) : NULL;
__error = NULL;
return ret;
}
/programs/develop/ktcc/trunk/libc/libgen/basename.c
0,0 → 1,23
/* Return the name-within-directory of a file name.
Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
 
#include <string.h>
 
char *
basename (const char *filename)
{
char *p = strrchr (filename, '/');
return p ? p + 1 : (char *) filename;
}
/programs/develop/ktcc/trunk/libc/libgen/dirname.c
0,0 → 1,67
/* dirname - return directory part of PATH.
Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
 
#include <libgen.h>
#include <string.h>
 
char *
dirname (char *path)
{
static const char dot[] = ".";
char *last_slash;
/* Find last '/'. */
last_slash = path != NULL ? strrchr (path, '/') : NULL;
if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
{
/* Determine whether all remaining characters are slashes. */
char *runp;
for (runp = last_slash; runp != path; --runp)
if (runp[-1] != '/')
break;
/* The '/' is the last character, we have to look further. */
if (runp != path)
last_slash = memrchr (path, '/', runp - path);
}
if (last_slash != NULL)
{
/* Determine whether all remaining characters are slashes. */
char *runp;
for (runp = last_slash; runp != path; --runp)
if (runp[-1] != '/')
break;
/* Terminate the path. */
if (runp == path)
{
/* The last slash is the first character in the string. We have to
return "/". As a special case we have to return "//" if there
are exactly two slashes at the beginning of the string. See
XBD 4.10 Path Name Resolution for more information. */
if (last_slash == path + 1)
++last_slash;
else
last_slash = path + 1;
}
else
last_slash = runp;
last_slash[0] = '\0';
}
else
/* This assignment is ill-designed but the XPG specs require to
return a string containing "." in any case no directory part is
found and so a static and constant string is required. */
path = (char *) dot;
return path;
}
/programs/develop/ktcc/trunk/libc/start/start.asm
0,0 → 1,220
format ELF
section '.text' executable
public start
public start as '_start'
;extrn mf_init
extrn main
;include 'debug2.inc'
include '..\..\..\..\..\proc32.inc'
include '..\..\..\..\..\macros.inc'
include '..\..\..\..\..\dll.inc'
__DEBUG__=0
 
;start_:
virtual at 0
db 'MENUET01' ; 1. Magic number (8 bytes)
dd 0x01 ; 2. Version of executable file
dd start ; 3. Start address
imgsz 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 'Start programm\n'
;init heap of memory
mov eax,68
mov ebx,11
int 0x40
 
mov [argc], 0
mov eax, [hparams]
test eax, eax
jz .without_path
mov eax, path
cmp word ptr eax, 32fh ; '/#3' UTF8
jne .without_path
mov word ptr eax, 12fh ; '/#1' fix to CP866
.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:
call load_imports
push argv
push [argc]
call main
.exit:
xor eax,eax
dec eax
int 0x40
dd -1
.crash:
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
;==============================
 
;==============================
load_imports:
;==============================
;parameters
; none
;description
; imports must be located at end of image (but before BSS sections)
; the address of end of imports (next byte after imports) is located in imgsz
; look at each import from that address up to illegal import
; legal import is such that:
; first pointer points to procedure name
; and is smaller than imgsz
; second pointer points lo library name, starting with 0x55, 0xAA
; and is smaller than imgsz
; each library should be initialized as appropriate, once
; so as library is initialized, its name will be replaced 0x00
mov ebx, [imgsz] ; byte after imports
.handle_next_import:
sub ebx, 4 ; ebx = pointer to pointer to library name
mov esi, dword[ebx] ; esi = pointer to library name
push ebx
push esi
call load_library ; eax = pointer to library exports
pop esi
pop ebx
test eax, eax
jz .done
sub ebx, 4 ; ebx = pointer to pointer to symbol name
push ebx
stdcall dll.GetProcAddress, eax, dword[ebx]
pop ebx
test eax, eax
jz .fail
mov dword[ebx], eax
jmp .handle_next_import
.done:
ret
.fail:
ret
;==============================
 
;==============================
load_library:
;==============================
;parameters
; ebx: library name address
;description
; each library should be initialized as appropriate, once
; so as library is initialized, its name will be replaced 0x00
; and 4 next bytes will be set to address of library
; first two bytes of library name must be 0x55, 0xAA (is like a magic)
cld ; move esi further, not back
cmp esi, [imgsz]
ja .fail
lodsb ; al = first byte of library name
cmp al, 0x55
jne .fail
lodsb ; al = second byte of library name
cmp al, 0xAA
jne .fail
lodsb ; al = third byte of library name (0x00 if the library is already loaded)
test al, al
jnz .load
lodsd ; if we here, then third byte is 0x00 => address of library is in next 4 bytes
; now eax contains address of library
ret
.load:
dec esi ; we checked on 0 before, let's go back
mov eax, 68
mov ebx, 19
mov ecx, esi
int 0x40 ; eax = address of exports
mov byte[esi], 0 ; library is loaded, let's place 0 in first byte of name
mov [esi + 1], eax ; now next 4 bytes of library name are replaced by address of library
; call lib_init
stdcall dll.GetProcAddress, eax, lib_init_str ; eax = address of lib_init
test eax, eax
jz .ret
stdcall dll.Init, eax
.ret:
mov eax, [esi + 1] ; put address of library into eax
ret
.fail:
mov eax, 0
ret
;==============================
 
lib_init_str db 'lib_init', 0
 
public argc as '__argc'
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/start.old.asm
0,0 → 1,143
format ELF
section '.text' executable
public start
public start as '_start'
;extrn mf_init
extrn main
;include 'debug2.inc'
__DEBUG__=0
 
;start_:
virtual at 0
db 'MENUET01' ; 1. Magic number (8 bytes)
dd 0x01 ; 2. Version of executable file
dd start ; 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 'Start programm\n'
;init heap of memory
mov eax,68
mov ebx,11
int 0x40
 
;DEBUGF ' path "%s"\n params "%s"\n', .path, .params
; check for overflow
;; that not work
; mov al, [path+buf_len-1]
; or al, [params+buf_len-1]
; jnz .crash
; check if path written by OS
mov [argc], 0
mov eax, [hparams]
test eax, eax
jz .without_path
mov eax, path
cmp word ptr eax, 32fh ; '/#3' UTF8
jne .without_path
mov word ptr eax, 12fh ; '/#1' fix to CP866
.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 'call main(%x, %x) with params:\n', [argc], argv
if __DEBUG__ = 1
mov ecx, [argc]
@@:
lea esi, [ecx * 4 + argv-4]
DEBUGF '0x%x) "%s"\n', cx, [esi]
loop @b
end if
push argv
push [argc]
call main
.exit:
;DEBUGF 'Exit from prog\n';
xor eax,eax
dec eax
int 0x40
dd -1
.crash:
;DEBUGF '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 argc as '__argc'
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
Property changes:
Added: svn:ignore
+*.o
+*.s
/programs/develop/ktcc/trunk/libc/math/acos.asm
0,0 → 1,23
format ELF
include '../proc32.inc'
section '.text' executable
 
public acos_ as "acos"
 
acos_:
 
; acos(x) = atan(sqrt((1-x*x)/(x*x)))
 
fld qword[esp+4]
fld st0 ;Duplicate X on tos.
fmul st0, st1 ;Compute X**2.
fld st0 ;Duplicate X**2 on tos.
fld1 ;Compute 1-X**2.
fsub st0, st1
fdiv st0, st1 ;Compute (1-x**2)/X**2.
fsqrt ;Compute sqrt((1-X**2)/X**2).
fld1 ;To compute full arctangent.
fpatan ;Compute atan of the above.
ret
 
/programs/develop/ktcc/trunk/libc/math/atan.asm
0,0 → 1,15
format ELF
include '../proc32.inc'
section '.text' executable
 
public atan_ as "atan"
 
atan_:
 
fld qword[esp+4]
fld1
fpatan
 
ret
 
/programs/develop/ktcc/trunk/libc/math/atan2.asm
0,0 → 1,15
format ELF
include '../proc32.inc'
section '.text' executable
public atan2_ as "atan2"
 
atan2_:
 
fld qword[esp+8]
fld qword[esp+4]
fpatan
 
ret
 
/programs/develop/ktcc/trunk/libc/math/ceil.asm
0,0 → 1,30
format ELF
include '../proc32.inc'
section '.text' executable
 
public ceil
 
ceil:
 
push ebp
mov ebp,esp
sub esp,8
 
fstcw [ebp-12]
mov dx,[ebp-12]
or dx,0x0800
and dx,0xfbff
mov word[ebp-16],dx
fldcw [ebp-16]
 
fld qword[ebp+8]
frndint
 
fldcw [ebp-12]
 
leave
 
ret
 
 
/programs/develop/ktcc/trunk/libc/math/ceilf.asm
0,0 → 1,30
format ELF
include '../proc32.inc'
section '.text' executable
 
public ceilf
 
ceilf:
 
push ebp
mov ebp,esp
sub esp,8
 
fstcw [ebp-12]
mov dx,[ebp-12]
or dx,0x0800
and dx,0xfbff
mov word[ebp-16],dx
fldcw [ebp-16]
 
fld dword[ebp+8]
frndint
 
fldcw [ebp-12]
 
leave
 
ret
 
 
/programs/develop/ktcc/trunk/libc/math/cos.asm
0,0 → 1,14
format ELF
include '../proc32.inc'
section '.text' executable
 
public cos_ as "cos"
 
cos_:
 
fld qword[esp+4]
fcos
 
ret
 
/programs/develop/ktcc/trunk/libc/math/exp.asm
0,0 → 1,60
format ELF
include '../proc32.inc'
section '.text' executable
public exp_ as "exp"
public exp2_ as "exp2"
 
SaveCW dw ?
MaskedCW dw ?
 
; 2**x = 2**int(x) * 2**frac(x).
; We can easily compute 2**int(x) with fscale and
; 2**frac(x) using f2xm1.
exp2_int:
fstcw [SaveCW]
 
; Modify the control word to truncate when rounding.
 
fstcw [MaskedCW]
or byte ptr MaskedCW + 1, 1100b
fldcw [MaskedCW]
 
fld st0 ;Duplicate tos.
fld st0
frndint ;Compute integer portion.
 
fxch ;Swap whole and int values.
fsub st0, st1 ;Compute fractional part.
 
f2xm1 ;Compute 2**frac(x)-1.
fld1
faddp st1, st0 ;Compute 2**frac(x).
 
fxch ;Get integer portion.
fld1 ;Compute 1*2**int(x).
fscale
fstp st1 ;Remove st(1) (which is 1).
 
fmulp st1, st0 ;Compute 2**int(x) * 2**frac(x).
fstp st1 ;Remove st1
 
fldcw [SaveCW] ;Restore rounding mode.
ret
 
exp_:
; exp(x) = 2**(x * lg(e))
 
fld qword[esp+4]
fldl2e ;Put lg(e) onto the stack.
fmulp st1, st0 ;Compute x*lg(e).
call exp2_int;Compute 2**(x * lg(e))
ret
 
exp2_:
fld qword[esp+4]
call exp2_int;Compute 2 ** x
ret
 
 
/programs/develop/ktcc/trunk/libc/math/fabs.asm
0,0 → 1,14
format ELF
include '../proc32.inc'
section '.text' executable
 
public fabs_ as "fabs"
 
fabs_:
 
fld qword[esp+4]
fabs
 
ret
 
/programs/develop/ktcc/trunk/libc/math/fabsf.asm
0,0 → 1,14
format ELF
include '../proc32.inc'
section '.text' executable
 
public fabsf
 
fabsf:
 
fld dword[esp+4]
fabs
 
ret
 
/programs/develop/ktcc/trunk/libc/math/floor.asm
0,0 → 1,29
format ELF
include '../proc32.inc'
section '.text' executable
 
public floor
 
floor:
 
push ebp
mov ebp,esp
sub esp,8
 
fstcw [ebp-12]
mov dx,word[ebp-12]
or dx,0x0400
and dx,0xf7ff
mov word[ebp-16],dx
fldcw [ebp-16]
 
fld qword[ebp+8]
frndint
 
fldcw [ebp-12]
 
leave
 
ret
 
/programs/develop/ktcc/trunk/libc/math/floorf.asm
0,0 → 1,29
format ELF
include '../proc32.inc'
section '.text' executable
 
public floorf
 
floorf:
 
push ebp
mov ebp,esp
sub esp,8
 
fstcw [ebp-12]
mov dx,word[ebp-12]
or dx,0x0400
and dx,0xf7ff
mov word[ebp-16],dx
fldcw [ebp-16]
 
fld dword[ebp+8]
frndint
 
fldcw [ebp-12]
 
leave
 
ret
 
/programs/develop/ktcc/trunk/libc/math/log.asm
0,0 → 1,18
format ELF
include '../proc32.inc'
section '.text' executable
 
public log_ as "log"
 
log_:
 
; ln(x) = lg(x)/lg(e).
 
fld qword[esp+4]
fld1
fxch
fyl2x ;Compute 1*lg(x).
fldl2e ;Load lg(e).
fdivp st1, st0 ;Compute lg(x)/lg(e).
ret
/programs/develop/ktcc/trunk/libc/math/log10.asm
0,0 → 1,18
format ELF
include '../proc32.inc'
section '.text' executable
 
public log10_ as "log10"
 
log10_:
 
; ln(x) = lg(x)/lg(e).
 
fld qword[esp+4]
fld1
fxch
fyl2x ;Compute 1*lg(x).
fldl2t ;Load lg(10).
fdivp st1, st0 ;Compute lg(x)/lg(10).
ret
/programs/develop/ktcc/trunk/libc/math/sin.asm
0,0 → 1,14
format ELF
include '../proc32.inc'
section '.text' executable
 
public sin_ as "sin"
 
sin_:
 
fld qword[esp+4]
fsin
 
ret
 
/programs/develop/ktcc/trunk/libc/math/sqrt.asm
0,0 → 1,14
format ELF
include '../proc32.inc'
section '.text' executable
 
public sqrt
 
sqrt:
 
fld qword[esp+4]
fsqrt
 
ret
 
/programs/develop/ktcc/trunk/libc/math/sqrtf.asm
0,0 → 1,14
format ELF
include '../proc32.inc'
section '.text' executable
 
public sqrtf
 
sqrtf:
 
fld dword[esp+4]
fsqrt
 
ret
 
/programs/develop/ktcc/trunk/libc/math/tan.asm
0,0 → 1,15
format ELF
include '../proc32.inc'
section '.text' executable
 
public tan_ as "tan"
 
tan_:
 
fld qword[esp+4]
fptan
fxch
 
ret
 
/programs/develop/ktcc/trunk/libc/math/fmod.c
0,0 → 1,86
#include <math.h>
 
double remainder(double numer, double denom)
{
double res;
asm("fldl %2;"
"fldl %1;"
"fprem1;"
"fstpl %0;"
"fstp %%st;"
: "=m"(res)
: "m"(numer), "m"(denom)
);
return res;
}
//remainder of 5.3 / 2 is -0.700000
//remainder of 18.5 / 4.2 is 1.700000
 
 
 
double fmod(double numer, double denom)
{
double res;
asm("fldl %2;"
"fldl %1;"
"fprem;"
"fstpl %0;"
"fstp %%st;"
: "=m"(res)
: "m"(numer), "m"(denom)
);
return res;
}
// fmod of 5.3 / 2 is 1.300000
// fmod of 18.5 / 4.2 is 1.700000
 
 
double modf(double x, double *intpart)
{
double res, intp;
asm("fldl %2;"
"fldl %2;"
"frndint;"
"fstl %1;"
"fxch;"
"fsubp %%st, %%st(1);"
"fstpl %0"
: "=m"(res), "=m"(intp)
: "m"(x)
);
*intpart = intp;
return res;
}
 
double ldexp (double x, int expon)
// = x * 2^expot
{
double res;
asm("fildl %2;"
"fldl %1;"
"fscale;"
"fstpl %0;"
"fstp %%st;"
: "=m"(res)
: "m"(x), "m"(expon)
);
 
return res;
}
 
double frexp (double x, int* expon)
{
double res;
asm("fldl %2;"
"fxtract;"
"fstpl %0;"
"fistpl %1;"
"fstp %%st;"
: "=m"(res), "=m"(*expon)
: "m"(x)
);
 
// *expon = (int)ex;
return res;
}
// 8.000000 = 0.500000 * 2^ 4
/programs/develop/ktcc/trunk/libc/math/asin.c
0,0 → 1,6
#include <math.h>
 
double asin(double x)
{
return atan(sqrt(x * x / (1.0 - x * x)));
}
/programs/develop/ktcc/trunk/libc/math/cosh.c
0,0 → 1,6
#include <math.h>
 
double cosh (double x)
{
return (exp(x) + exp(-x)) / 2;
}
/programs/develop/ktcc/trunk/libc/math/libtcc1.c
0,0 → 1,754
/* TCC runtime library.
Parts of this code are (c) 2002 Fabrice Bellard
 
Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
 
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
 
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
 
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
 
//#include <stdint.h>
#define TCC_TARGET_I386
 
#define W_TYPE_SIZE 32
#define BITS_PER_UNIT 8
 
typedef int Wtype;
typedef unsigned int UWtype;
typedef unsigned int USItype;
typedef long long DWtype;
typedef unsigned long long UDWtype;
 
struct DWstruct {
Wtype low, high;
};
 
typedef union
{
struct DWstruct s;
DWtype ll;
} DWunion;
 
typedef long double XFtype;
#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
 
/* the following deal with IEEE single-precision numbers */
#define EXCESS 126
#define SIGNBIT 0x80000000
#define HIDDEN (1 << 23)
#define SIGN(fp) ((fp) & SIGNBIT)
#define EXP(fp) (((fp) >> 23) & 0xFF)
#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN)
#define PACK(s,e,m) ((s) | ((e) << 23) | (m))
 
/* the following deal with IEEE double-precision numbers */
#define EXCESSD 1022
#define HIDDEND (1 << 20)
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \
(fp.l.lower >> 22))
#define HIDDEND_LL ((long long)1 << 52)
#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m))
 
/* the following deal with x86 long double-precision numbers */
#define EXCESSLD 16382
#define EXPLD(fp) (fp.l.upper & 0x7fff)
#define SIGNLD(fp) ((fp.l.upper) & 0x8000)
 
/* only for x86 */
union ldouble_long {
long double ld;
struct {
unsigned long long lower;
unsigned short upper;
} l;
};
 
union double_long {
double d;
#if 1
struct {
unsigned int lower;
int upper;
} l;
#else
struct {
int upper;
unsigned int lower;
} l;
#endif
long long ll;
};
 
union float_long {
float f;
unsigned int l;
};
 
/* XXX: we don't support several builtin supports for now */
#if !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM)
 
/* XXX: use gcc/tcc intrinsic ? */
#if defined(TCC_TARGET_I386)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
__asm__ ("subl %5,%1\n\tsbbl %3,%0" \
: "=r" ((USItype) (sh)), \
"=&r" ((USItype) (sl)) \
: "0" ((USItype) (ah)), \
"g" ((USItype) (bh)), \
"1" ((USItype) (al)), \
"g" ((USItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
__asm__ ("mull %3" \
: "=a" ((USItype) (w0)), \
"=d" ((USItype) (w1)) \
: "%0" ((USItype) (u)), \
"rm" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
__asm__ ("divl %4" \
: "=a" ((USItype) (q)), \
"=d" ((USItype) (r)) \
: "0" ((USItype) (n0)), \
"1" ((USItype) (n1)), \
"rm" ((USItype) (dv)))
#define count_leading_zeros(count, x) \
do { \
USItype __cbtmp; \
__asm__ ("bsrl %1,%0" \
: "=r" (__cbtmp) : "rm" ((USItype) (x))); \
(count) = __cbtmp ^ 31; \
} while (0)
#else
#error unsupported CPU type
#endif
 
/* most of this code is taken from libgcc2.c from gcc */
 
static UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
{
DWunion ww;
DWunion nn, dd;
DWunion rr;
UWtype d0, d1, n0, n1, n2;
UWtype q0, q1;
UWtype b, bm;
 
nn.ll = n;
dd.ll = d;
 
d0 = dd.s.low;
d1 = dd.s.high;
n0 = nn.s.low;
n1 = nn.s.high;
 
#if !defined(UDIV_NEEDS_NORMALIZATION)
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
 
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
 
/* Remainder in n0. */
}
else
{
/* qq = NN / 0d */
 
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
 
udiv_qrnnd (q1, n1, 0, n1, d0);
udiv_qrnnd (q0, n0, n1, n0, d0);
 
/* Remainder in n0. */
}
 
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = 0;
*rp = rr.ll;
}
}
 
#else /* UDIV_NEEDS_NORMALIZATION */
 
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
 
count_leading_zeros (bm, d0);
 
if (bm != 0)
{
/* Normalize, i.e. make the most significant bit of the
denominator set. */
 
d0 = d0 << bm;
n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
n0 = n0 << bm;
}
 
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
 
/* Remainder in n0 >> bm. */
}
else
{
/* qq = NN / 0d */
 
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
 
count_leading_zeros (bm, d0);
 
if (bm == 0)
{
/* From (n1 >= d0) /\ (the most significant bit of d0 is set),
conclude (the most significant bit of n1 is set) /\ (the
leading quotient digit q1 = 1).
 
This special case is necessary, not an optimization.
(Shifts counts of W_TYPE_SIZE are undefined.) */
 
n1 -= d0;
q1 = 1;
}
else
{
/* Normalize. */
 
b = W_TYPE_SIZE - bm;
 
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
 
udiv_qrnnd (q1, n1, n2, n1, d0);
}
 
/* n1 != d0... */
 
udiv_qrnnd (q0, n0, n1, n0, d0);
 
/* Remainder in n0 >> bm. */
}
 
if (rp != 0)
{
rr.s.low = n0 >> bm;
rr.s.high = 0;
*rp = rr.ll;
}
}
#endif /* UDIV_NEEDS_NORMALIZATION */
 
else
{
if (d1 > n1)
{
/* 00 = nn / DD */
 
q0 = 0;
q1 = 0;
 
/* Remainder in n1n0. */
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
/* 0q = NN / dd */
 
count_leading_zeros (bm, d1);
if (bm == 0)
{
/* From (n1 >= d1) /\ (the most significant bit of d1 is set),
conclude (the most significant bit of n1 is set) /\ (the
quotient digit q0 = 0 or 1).
 
This special case is necessary, not an optimization. */
 
/* The condition on the next line takes advantage of that
n1 >= d1 (true due to program flow). */
if (n1 > d1 || n0 >= d0)
{
q0 = 1;
sub_ddmmss (n1, n0, n1, n0, d1, d0);
}
else
q0 = 0;
 
q1 = 0;
 
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
UWtype m1, m0;
/* Normalize. */
 
b = W_TYPE_SIZE - bm;
 
d1 = (d1 << bm) | (d0 >> b);
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
 
udiv_qrnnd (q0, n1, n2, n1, d1);
umul_ppmm (m1, m0, q0, d0);
 
if (m1 > n1 || (m1 == n1 && m0 > n0))
{
q0--;
sub_ddmmss (m1, m0, m1, m0, d1, d0);
}
 
q1 = 0;
 
/* Remainder in (n1n0 - m1m0) >> bm. */
if (rp != 0)
{
sub_ddmmss (n1, n0, n1, n0, m1, m0);
rr.s.low = (n1 << b) | (n0 >> bm);
rr.s.high = n1 >> bm;
*rp = rr.ll;
}
}
}
}
 
ww.s.low = q0;
ww.s.high = q1;
return ww.ll;
}
 
#define __negdi2(a) (-(a))
 
long long __divdi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0) {
c = ~c;
vv.ll = __negdi2 (vv.ll);
}
w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
if (c)
w = __negdi2 (w);
return w;
}
 
long long __moddi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0)
vv.ll = __negdi2 (vv.ll);
__udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w);
if (c)
w = __negdi2 (w);
return w;
}
 
unsigned long long __udivdi3(unsigned long long u, unsigned long long v)
{
return __udivmoddi4 (u, v, (UDWtype *) 0);
}
 
unsigned long long __umoddi3(unsigned long long u, unsigned long long v)
{
UDWtype w;
__udivmoddi4 (u, v, &w);
return w;
}
 
/* XXX: fix tcc's code generator to do this instead */
long long __ashrdi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = u.s.high >> (b - 32);
u.s.high = u.s.high >> 31;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
 
/* XXX: fix tcc's code generator to do this instead */
unsigned long long __lshrdi3(unsigned long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = (unsigned)u.s.high >> (b - 32);
u.s.high = 0;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = (unsigned)u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
 
/* XXX: fix tcc's code generator to do this instead */
long long __ashldi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.high = (unsigned)u.s.low << (b - 32);
u.s.low = 0;
} else if (b != 0) {
u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b));
u.s.low = (unsigned)u.s.low << b;
}
return u.ll;
#else
return a << b;
#endif
}
 
#ifndef COMMIT_4ad186c5ef61_IS_FIXED
long long __tcc_cvt_ftol(long double x)
{
unsigned c0, c1;
long long ret;
__asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
c1 = c0 | 0x0C00;
__asm__ __volatile__ ("fldcw %0" : : "m" (c1));
__asm__ __volatile__ ("fistpll %0" : "=m" (ret));
__asm__ __volatile__ ("fldcw %0" : : "m" (c0));
return ret;
}
#endif
 
#endif /* !__x86_64__ */
 
/* XXX: fix tcc's code generator to do this instead */
float __floatundisf(unsigned long long a)
{
DWunion uu;
XFtype r;
 
uu.ll = a;
if (uu.s.high >= 0) {
return (float)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (float)r;
}
}
 
double __floatundidf(unsigned long long a)
{
DWunion uu;
XFtype r;
 
uu.ll = a;
if (uu.s.high >= 0) {
return (double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (double)r;
}
}
 
long double __floatundixf(unsigned long long a)
{
DWunion uu;
XFtype r;
 
uu.ll = a;
if (uu.s.high >= 0) {
return (long double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (long double)r;
}
}
 
unsigned long long __fixunssfdi (float a1)
{
register union float_long fl1;
register int exp;
register unsigned long l;
 
fl1.f = a1;
 
if (fl1.l == 0)
return (0);
 
exp = EXP (fl1.l) - EXCESS - 24;
 
l = MANT(fl1.l);
if (exp >= 41)
return (unsigned long long)-1;
else if (exp >= 0)
return (unsigned long long)l << exp;
else if (exp >= -23)
return l >> -exp;
else
return 0;
}
 
unsigned long long __fixunsdfdi (double a1)
{
register union double_long dl1;
register int exp;
register unsigned long long l;
 
dl1.d = a1;
 
if (dl1.ll == 0)
return (0);
 
exp = EXPD (dl1) - EXCESSD - 53;
 
l = MANTD_LL(dl1);
 
if (exp >= 12)
return (unsigned long long)-1;
else if (exp >= 0)
return l << exp;
else if (exp >= -52)
return l >> -exp;
else
return 0;
}
 
unsigned long long __fixunsxfdi (long double a1)
{
register union ldouble_long dl1;
register int exp;
register unsigned long long l;
 
dl1.ld = a1;
 
if (dl1.l.lower == 0 && dl1.l.upper == 0)
return (0);
 
exp = EXPLD (dl1) - EXCESSLD - 64;
 
l = dl1.l.lower;
 
if (exp > 0)
return (unsigned long long)-1;
else if (exp >= -63)
return l >> -exp;
else
return 0;
}
 
long long __fixsfdi (float a1)
{
long long ret; int s;
ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
 
long long __fixdfdi (double a1)
{
long long ret; int s;
ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
 
long long __fixxfdi (long double a1)
{
long long ret; int s;
ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
 
#if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
 
#ifndef __TINYC__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#else
/* Avoid including stdlib.h because it is not easily available when
cross compiling */
#include <stddef.h> /* size_t definition is needed for a x86_64-tcc to parse memset() */
extern void *malloc(unsigned long long);
extern void *memset(void *s, int c, size_t n);
extern void free(void*);
extern void abort(void);
#endif
 
enum __va_arg_type {
__va_gen_reg, __va_float_reg, __va_stack
};
 
//This should be in sync with the declaration on our include/stdarg.h
/* GCC compatible definition of va_list. */
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
union {
unsigned int overflow_offset;
char *overflow_arg_area;
};
char *reg_save_area;
} __va_list_struct;
 
#undef __va_start
#undef __va_arg
#undef __va_copy
#undef __va_end
 
void __va_start(__va_list_struct *ap, void *fp)
{
memset(ap, 0, sizeof(__va_list_struct));
*ap = *(__va_list_struct *)((char *)fp - 16);
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
ap->reg_save_area = (char *)fp - 176 - 16;
}
 
void *__va_arg(__va_list_struct *ap,
enum __va_arg_type arg_type,
int size, int align)
{
size = (size + 7) & ~7;
align = (align + 7) & ~7;
switch (arg_type) {
case __va_gen_reg:
if (ap->gp_offset + size <= 48) {
ap->gp_offset += size;
return ap->reg_save_area + ap->gp_offset - size;
}
goto use_overflow_area;
 
case __va_float_reg:
if (ap->fp_offset < 128 + 48) {
ap->fp_offset += 16;
return ap->reg_save_area + ap->fp_offset - 16;
}
size = 8;
goto use_overflow_area;
 
case __va_stack:
use_overflow_area:
ap->overflow_arg_area += size;
ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align);
return ap->overflow_arg_area - size;
 
default:
#ifndef __TINYC__
fprintf(stderr, "unknown ABI type for __va_arg\n");
#endif
abort();
}
}
 
#endif /* __x86_64__ */
 
/* Flushing for tccrun */
#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386)
 
void __clear_cache(void *beginning, void *end)
{
}
 
#elif defined(TCC_TARGET_ARM)
 
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
 
void __clear_cache(void *beginning, void *end)
{
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
* However, there is no ARM asm parser in tcc so we use it for now */
#if 1
syscall(__ARM_NR_cacheflush, beginning, end, 0);
#else
__asm__ ("push {r7}\n\t"
"mov r7, #0xf0002\n\t"
"mov r2, #0\n\t"
"swi 0\n\t"
"pop {r7}\n\t"
"ret");
#endif
}
 
#else
#warning __clear_cache not defined for this architecture, avoid using tcc -run
#endif
/programs/develop/ktcc/trunk/libc/math/pow.c
0,0 → 1,6
#include <math.h>
 
double pow(double x, double y)
{
return exp(y * log(x));
}
/programs/develop/ktcc/trunk/libc/math/round.c
0,0 → 1,9
#include <math.h>
 
double round (double x)
{
if (x > 0)
return floor(x + 0.5);
else
return ceil(x - 0.5);
}
/programs/develop/ktcc/trunk/libc/math/roundl.c
0,0 → 1,9
#include <math.h>
 
long double roundl (long double x)
{
if (x > 0)
return floor(x + 0.5);
else
return ceil(x - 0.5);
}
/programs/develop/ktcc/trunk/libc/math/sinh.c
0,0 → 1,6
#include <math.h>
 
double sinh (double x)
{
return (exp(x) - exp(-x)) / 2;
}
/programs/develop/ktcc/trunk/libc/math/tanh.c
0,0 → 1,8
#include <math.h>
 
double tanh (double x)
{
double ex = exp(x), exm = exp(-x);
 
return (ex - exm) / (ex + exm);
}
/programs/develop/ktcc/trunk/libc/memory/memalloc.asm
0,0 → 1,46
format ELF
 
;include "../proc32.inc"
section '.text' executable
public sysmalloc
public sysfree
public sysrealloc
 
align 4
sysmalloc:
push ebx
push ecx
mov eax,68
mov ebx,12
mov ecx,[esp+12] ;size
int 0x40
pop ecx
pop ebx
ret 4
 
align 4
sysfree:
push ebx
push ecx
mov eax,68
mov ebx,13
mov ecx,[esp+12]
int 0x40
pop ecx
pop ebx
ret 4
 
align 4
sysrealloc:
push ebx
push ecx
push edx
mov eax,68
mov ebx,20
mov ecx,[esp+20] ; size
mov edx,[esp+16] ; pointer
int 0x40
pop edx
pop ecx
pop ebx
ret 8
/programs/develop/ktcc/trunk/libc/memory/watermark.c
0,0 → 1,410
/*
* Easy and fast memory allocator from
* https://wiki.osdev.org/Memory_Allocation
* Coded by Siemargl, 2018
*
* No Garbage Collector
*/
 
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
 
#define UINT_MAX (4294967295U)
 
#ifndef NDEBUG
#include <stdio.h>
# ifdef __TINYC__
# include <kolibrisys.h>
# define TRACE1(s, a) { char buf[400]; sprintf(buf, s, a); debug_out_str(buf); }
# define TRACE2(s, a, b) { char buf[400]; sprintf(buf, s, a, b); debug_out_str(buf); }
# else
# define TRACE1(s, a) printf(s, a)
# define TRACE2(s, a, b) printf(s, a, b)
# endif
#else
# define TRACE1(s, a) (void)0
# define TRACE2(s, a, b) (void)0
#endif
 
 
 
 
// get address, fromwhere function was called
#define CALLEDFROM(param1) (*(int*)((char*)&param1-4)-5)
const uint32_t c_used = 0x44455355; //'USED'
const uint32_t c_free = 0x45455246; //'FREE'
 
struct hdrfree {
uint32_t mark; // 'FREE'
size_t size; // including header
struct hdrfree *prev;
struct hdrfree *next;
};
 
struct hdrused {
uint32_t mark; // 'USED'
size_t size;
};
 
 
static char *__freebase = NULL; // begin of free area
static char *__freetop = NULL; // after last byte of free area
static struct hdrfree *__firstfree = NULL; // ptr to first node in dual-link list
 
static struct {
uint32_t malloc_calls;
uint32_t malloc_max;
uint32_t malloc_sum;
uint32_t sysalloc_calls;
uint32_t sysalloc_max;
uint32_t sysalloc_sum;
uint32_t crtfreeblocks; // number of free blocks, checking corruptions
uint32_t freeblocks_sum;
} wtalloc_stat;
 
 
void *wtmalloc(size_t sz)
{
struct hdrfree *fndnode, *newnode;
sz = (sizeof(struct hdrused) + sz + 15) & ~15; // align 16bytes
//TRACE1("_call alloc(%d)\n", sz);
 
//statistics
wtalloc_stat.malloc_calls++;
if (sz > wtalloc_stat.malloc_max) wtalloc_stat.malloc_max = sz;
wtalloc_stat.malloc_sum += sz;
// try to find free block enough size
fndnode = __firstfree;
while(fndnode)
{
#ifndef NDEBUG
if (fndnode->mark != c_free)
{
TRACE2("heap free block list corrupt %x EIP@%x\n", fndnode, CALLEDFROM(sz));
assert(0);
}
#endif
if (fndnode->size >= sz) break;
fndnode = fndnode->next;
}
if (fndnode) // found free block
{
if (fndnode->size - sz > 15) // split smaller size, move free node
{
//TRACE2("alloc(%d) split (%x)\n", sz, fndnode);
wtalloc_stat.freeblocks_sum -= sz;
newnode = (struct hdrfree*)((char*)fndnode + sz);
newnode->mark = c_free;
newnode->size = fndnode->size - sz;
newnode->next = fndnode->next;
newnode->prev = fndnode->prev;
if (fndnode->next)
fndnode->next->prev = newnode;
//перед может быть не нода, а 1й указатель
if (fndnode->prev)
newnode->prev->next = newnode;
else
__firstfree = newnode;
} else // nothing to split, just exclude
{
//TRACE1("alloc(%d) remove freenode\n", sz);
 
wtalloc_stat.crtfreeblocks--;
wtalloc_stat.freeblocks_sum -= fndnode->size;
if (fndnode->next)
fndnode->next->prev = fndnode->prev;
//перед может быть не нода, а 1й указатель
if (fndnode->prev)
fndnode->prev->next = fndnode->next;
else
__firstfree = fndnode->next;
}
fndnode->mark = c_used;
fndnode->size = sz;
return (char*)fndnode + sizeof(struct hdrused);
}
char *ptr;
// free block not found, try to add @end
if (__freetop - __freebase < sz) // not enough memory - call system
{
if (sz > UINT_MAX - 16) return NULL; // check 32-bit heap overflow
// size_t new_heap_size = (__freetop - __freebase + sz + 4095) & ~4095;
size_t new_heap_size = (sz + sz / 5 + 4095) & ~4095; // 20% reserved
//statistics
wtalloc_stat.sysalloc_calls++;
if (new_heap_size > wtalloc_stat.malloc_max) wtalloc_stat.sysalloc_max = new_heap_size;
wtalloc_stat.sysalloc_sum += new_heap_size;
 
 
//хвост сунуть в свободные, а фритоп и базу перености на новый кусок
ptr = sysmalloc(new_heap_size); // rounded 4k
//TRACE2("call systemalloc(%d) returned %x\n", new_heap_size, ptr);
if (!ptr)
{
TRACE2("sysmalloc failed trying to allocate %u bytes EIP@%x\n", sz, CALLEDFROM(sz));
return NULL;
}
// add new free block in front of list
if (__freetop - __freebase > 15)
{
newnode = (struct hdrfree*)__freebase;
newnode->mark = c_free;
newnode->size = __freetop - __freebase;
newnode->next = __firstfree;
newnode->prev = NULL;
if (__firstfree)
__firstfree->prev = newnode;
__firstfree = newnode;
wtalloc_stat.crtfreeblocks++;
wtalloc_stat.freeblocks_sum += newnode->size;
//TRACE2("alloc(%d) add tail %d to freenode", sz, newnode->size);
//TRACE1(".tail [%x]\n", newnode);
}
// we don't save allocated block from system, so cant free them ltr
__freebase = ptr;
__freetop = __freebase + new_heap_size;
}
ptr = __freebase + sizeof(struct hdrused);
((struct hdrused*)__freebase)->mark = c_used;
((struct hdrused*)__freebase)->size = sz;
__freebase += sz;
//TRACE1("__freebase [%x]\n", __freebase);
 
 
// check list availability
/*
int maxfree = 0;
for (fndnode = __firstfree; fndnode; fndnode = fndnode->next)
{
if (fndnode->size > maxfree) maxfree = fndnode->size;
}
 
TRACE2("alloc(%d) from freebase, maxfree = %d,", sz, maxfree);
TRACE1(" freelist len = %u \n", wtalloc_stat.crtfreeblocks);
*/
return ptr;
}
 
void wtfree(void *ptr)
{
if (!ptr) return;
 
//TRACE1("free() to freenode, sized %d\n", ((struct hdrused*)((char*)ptr - 8))->size);
 
#ifndef NDEBUG
if (((struct hdrused*)((char*)ptr - 8))->mark != c_used)
{
TRACE2("try free unallocated block ptr = %x bytes EIP@%x\n", ptr, CALLEDFROM(ptr));
assert(0);
}
#endif
struct hdrfree *newnode = (struct hdrfree*)((char*)ptr - 8);
newnode->mark = c_free;
//size stays
newnode->next = NULL;
newnode->prev = NULL;
 
// experimental - try to merge, if adjanced from bottom is also freeblock
int reorganized = 0;
struct hdrfree *higher;
{
struct hdrfree *p1;
higher = NULL;
for (p1 = __firstfree; p1; p1 = p1->next)
{
higher = (struct hdrfree *)((char*)p1 + p1->size);
if (higher == newnode) break;
}
if (p1) // yes, it is
{
wtalloc_stat.freeblocks_sum += newnode->size;
p1->size += newnode->size;
// p1->prev, p1->next already OK
newnode->mark = 0; // for safety
newnode = p1; // continue optimization
//TRACE2("free block merged w/bottom sized %u bytes, list len %u\n", p1->size, wtalloc_stat.crtfreeblocks);
reorganized = 1;
}
}
 
 
/* removed, as very seldom succeeds */
// experimental - try to merge, if adjanced from top is also freeblock
higher = (struct hdrfree *)((char*)newnode + newnode->size);
// dont work - we try to read after our memory
// if ((char*)higher < (char*)__freetop && // saves from reading out of our memory
// higher->mark == c_free) // only suspisious, must be in list
{
struct hdrfree *p1;
for (p1 = __firstfree; p1 && p1 != higher; p1 = p1->next);
if (p1) // yes, it is
{
if (newnode->next || newnode->prev) // optimized 1st stage, must remove from list and readd later
{
wtalloc_stat.crtfreeblocks--;
wtalloc_stat.freeblocks_sum -= newnode->size;
if (newnode->next)
newnode->next->prev = newnode->prev;
if (newnode->prev)
newnode->prev->next = newnode->next;
else
__firstfree = newnode->next;
}
wtalloc_stat.freeblocks_sum += newnode->size;
newnode->size += higher->size;
newnode->prev = higher->prev;
newnode->next = higher->next;
higher->mark = 0; // for safety
if (higher->next)
higher->next->prev = newnode;
if (higher->prev)
higher->prev->next = newnode;
else
__firstfree = newnode;
//TRACE1("free block merged w/top\n", 0);
reorganized = 1;
}
}
 
if (reorganized) return; // experimental reorganized do all work
//TRACE1("free block added\n", 0);
wtalloc_stat.crtfreeblocks++;
wtalloc_stat.freeblocks_sum += newnode->size;
 
newnode->next = __firstfree;
newnode->prev = NULL;
if (__firstfree)
__firstfree->prev = newnode;
__firstfree = newnode;
}
 
 
void *wtrealloc(void *ptr, size_t sz)
{
if (!ptr) return wtmalloc(sz);
struct hdrused* oldptr = (struct hdrused*)((char*)ptr - 8);
 
#ifndef NDEBUG
if (oldptr->mark != c_used)
{
TRACE2("try realloc unallocated block ptr = %x EIP@%x\n", ptr, CALLEDFROM(ptr));
assert(0);
}
#endif
 
if (oldptr->size - 8 >= sz) return ptr; // enough room in this block, ex from freelist
/* experimental growth last block */
int growth = (oldptr->size + sz + 15) & ~15;
if ((char*)oldptr + oldptr->size == __freebase &&
__freetop - __freebase + oldptr->size >= growth ) // we at top, can grow up
{
wtalloc_stat.malloc_sum += growth - oldptr->size;
__freebase += growth - oldptr->size;
oldptr->size = growth;
return ptr;
}
void *newptr = wtmalloc(sz);
if (newptr)
{
memcpy(newptr, (char*)oldptr +8, oldptr->size -8); // why forgeting -8 dont fail test?!?
wtfree((char*)oldptr +8);
return newptr;
}
return NULL;
}
 
void* wtcalloc( size_t num, size_t size )
{
void *newptr = wtmalloc(num * size);
if (newptr)
memset(newptr, 0, num * size);
return newptr;
}
 
 
 
 
int wtmalloc_freelist_check()
//контроль целостности списка фри OK == 1
{
int cnt = 0;
struct hdrfree *ptr = __firstfree;
if(ptr && ptr->prev)
{
TRACE1("allocated memory freelist 1st block fail, ptr = %x\n", ptr);
return 0;
}
for(;ptr; ptr = ptr->next)
{
//TRACE1("(%x)", ptr);
 
cnt++;
if (ptr->mark != c_free)
{
TRACE1("allocated memory freelist check fail, ptr = %x\n", ptr);
return 0;
}
}
if (cnt != wtalloc_stat.crtfreeblocks)
{
TRACE2("allocated memory freelist check fail, length must be = %u but is %u\n", wtalloc_stat.crtfreeblocks, cnt);
return 0;
}
return 1;
}
 
void wtmalloc_freelist_print()
{
struct hdrfree *ptr = __firstfree;
for(;ptr; ptr = ptr->next)
{
TRACE2("(%x[%u])", ptr, ptr->size);
}
TRACE1("\n", 0);
}
 
int wtmalloc_poiner_check(void *ptr)
//контроль указателя - mark OK == 1
{
if (((struct hdrused*)((char*)ptr - 8))->mark != c_used)
{
TRACE2("pointer watermark check fail ptr = %x bytes EIP@%x\n", ptr, CALLEDFROM(ptr));
return 0;
}
return 1;
}
 
void wtdump_alloc_stats()
{
TRACE1("----Watermark allocator stats:----\n", 0);
TRACE2("allocated %u calls, max of %u bytes\n", wtalloc_stat.malloc_calls, wtalloc_stat.malloc_max);
TRACE2("total %u bytes, average call %u bytes\n", wtalloc_stat.malloc_sum, wtalloc_stat.malloc_sum / wtalloc_stat.malloc_calls);
TRACE1("SYSTEM:\n", 0);
TRACE2("allocated %u calls, max of %u bytes\n", wtalloc_stat.sysalloc_calls, wtalloc_stat.sysalloc_max);
TRACE2("total %u bytes, average call %u bytes\n", wtalloc_stat.sysalloc_sum, wtalloc_stat.sysalloc_sum / wtalloc_stat.sysalloc_calls);
TRACE2("free list %u bytes, length %u chunks\n", wtalloc_stat.freeblocks_sum, wtalloc_stat.crtfreeblocks);
}
/programs/develop/ktcc/trunk/libc/proc32.inc
0,0 → 1,301
 
; 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
{ local loc
loc = (localbytes+3) and (not 3)
parmbase@proc equ ebp+8
localbase@proc equ ebp-loc
if parmbytes | localbytes
push ebp
mov ebp,esp
if localbytes
sub esp,loc
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
retn
else
retn parmbytes
end if }
 
close@proc equ
 
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 \}
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 prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,parmbytes,localbytes,reglist \}
virtual at parmbase@proc
match =,args, params \{ defargs@proc args \}
match =args@proc args, args@proc params \{ defargs@proc args \}
parmbytes = $-(parmbase@proc)
end virtual
name # % = parmbytes/4
all@vars equ
current = 0
macro locals
\{ virtual at localbase@proc+current
macro label def \\{ match . type,def> \\\{ deflocal@proc .,label,<type \\\} \\}
struc db [val] \\{ \common deflocal@proc .,db,val \\}
struc du [val] \\{ \common deflocal@proc .,du,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,du,dw,dp,dd,dt,dq
restruc rb,rw,rp,rd,rt,rq
current = $-(localbase@proc)
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
match close:reglist, close@proc:<regs> \\{ close name,flag,parmbytes,localbytes,reglist \\}
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 qqword eq type
dd ?,?,?,?,?,?,?,?
else 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] { name def val }
 
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 =?, val \{ ..tmp equ \}
match any (=?), val \{ ..tmp equ \}
match =label, def \{ ..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 \} }
 
struc label type { label . type }
 
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*2
restore done@local \\}
match =QQWORD, vartype \\{ label varname qqword
rq count*4
restore done@local \\}
match =XWORD, vartype \\{ label varname xword
rq count*2
restore done@local \\}
match =YWORD, vartype \\{ label varname yword
rq count*4
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 =QQWORD, vartype \\{ label varname qqword
dq ?,?,?,?
restore done@local \\}
match =XWORD, vartype \\{ label varname xword
dq ?,?
restore done@local \\}
match =YWORD, vartype \\{ label varname yword
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/KOSfuncs_inc_status.txt
0,0 → 1,292
 
; KolibriOS system functions:
+SF_TERMINATE_PROCESS=-1 // kos_exit()
+SF_CREATE_WINDOW=0 ; define and draw the window //sys_create_window()
SF_PUT_PIXEL=1 ; draw pixel to the window
+SF_GET_KEY=2 ; get code of the pressed key
SF_GET_SYS_TIME=3
+SF_DRAW_TEXT=4 //draw_text_sys()
+SF_SLEEP=5 ; pause process // delay()
+SF_PUT_IMAGE=7 ; draw image to the window //draw_bitmap()
+SF_DEFINE_BUTTON=8 ; define/delete the button
+SF_THREAD_INFO=9 ; information on execution thread // get_proc_info()
+SF_WAIT_EVENT=10 ; wait for event // get_os_event()
+SF_CHECK_EVENT=11 ; check for event and return // check_os_event()
SF_REDRAW=12
+ SSF_BEGIN_DRAW=1
+ SSF_END_DRAW=2
+SF_DRAW_RECT=13 ; draw rectangle to the window // draw_bar()
SF_GET_SCREEN_SIZE=14 ; get screen resolution
SF_BACKGROUND_SET=15
SSF_SIZE_BG=1
SSF_PIXEL_BG=2
SSF_REDRAW_BG=3
SSF_MODE_BG=4
SSF_IMAGE_BG=5
SSF_MAP_BG=6 ; map background image to the address space of the process
SSF_UNMAP_BG=7
SSF_LAST_DRAW=8 ; get coordinates of the last draw to the background
SSF_REDRAW_RECT=9 ; redraws a rectangular part of the background
SF_RD_TO_FLOPPY=16 ; save ramdisk on the floppy
+SF_GET_BUTTON=17 ; get ID of the pressed button // get_os_button()
SF_SYSTEM=18
SSF_UNFOCUS_WINDOW=1 ; take focus from the window of the given thread
SSF_TERMINATE_THREAD=2 ; terminate process/thread by the slot number
+ SSF_FOCUS_WINDOW=3 ; give focus to the window of the given thread
SSF_GET_IDLE_COUNT=4 ; get counter of idle cycles per second
SSF_GET_CPU_REQUENCY=5 ; get CPU clock rate
SSF_RD_TO_HDD=6 ; save ramdisk to the file on hard disk
SSF_GET_ACTIVE_WINDOW=7 ; get slot number of the active window
SSF_SPEAKER=8
SSSF_GET_STATE=1
SSSF_TOGGLE=2
SSF_SHUTDOWN=9 ; system shutdown/reboot
SSF_MINIMIZE_WINDOW=10 ; minimize active window
SSF_INFO_DISC_SYS=11 ; get disk subsystem information
SSF_KERNEL_VERSION=13 ; get kernel version
SSF_WAIT_RETRACE=14 ; wait for screen retrace
SSF_CURSOR_CENTER=15 ; center mouse cursor on the screen
SSF_GET_FREE_RAM=16 ; get size of free RAM
SSF_GET_TOTAL_RAM=17 ; get total amount of RAM
SSF_TERMINATE_THREAD_ID=18 ; Terminate process/thread by the ID
SSF_MOUSE_SETTINGS=19
SSSF_GET_SPEED=0
SSSF_SET_SPEED=1
SSSF_GET_SPEEDUP=2
SSSF_SET_SPEEDUP=3 ; set mouse acceleration
SSSF_SET_POS=4 ; set mouse pointer position
SSSF_SET_BUTTON=5 ; simulate state of mouse buttons
SSSF_GET_DOUBLE_CLICK_DELAY=6
SSSF_SET_DOUBLE_CLICK_DELAY=7
SSF_GET_RAM_INFO=20 ; get information on RAM
+ SSF_GET_THREAD_SLOT=21 ; get slot number of process/thread by the ID
SSF_FOREIGN_WINDOW=22 ; operations with window of another thread by slot/ID
SSSF_MINIMIZE=0
SSSF_MINIMIZE_ID=1
SSSF_RESTORE=2
SSSF_RESTORE_ID=3
SSF_MINIMIZE_ALL=23
SSF_SET_SCREEN_LIMITS=24
SSF_WINDOW_BEHAVIOR=25 ; window focus relation with other windows
SSSF_GET_WB=1
SSSF_SET_WB=2
SF_MIDI=20
SSF_RESET=1
SSF_OUTPUT=2
SF_SYSTEM_SET=21
SSF_MPU_MIDI_BASE=1
SSF_KEYBOARD_LAYOUT=2
SSF_SYS_LANG=5
SSF_ACCESS_HD_LBA=11 ; setting of low-level access to HD
SSF_ACCESS_PCI=12 ; setting of low-level access to PCI
SF_SET_TIME_DATE=22
+SF_WAIT_EVENT_TIMEOUT=23; wait for event with timeout // wait_for_event()
SF_CD=24
SSF_EJECT_TRAY=4
SSF_INSERT_TRAY=5
SF_SCREEN_PUT_IMAGE=25 ; put image on the background layer
SF_SYSTEM_GET=26
; Same as SF_SYSTEM_SET, plus:
+ SSF_TIME_COUNT=9 // get_tick_count()
+ SSF_TIME_COUNT_PRO=10 ; get value of the high precision time counter // get_ns_count()
SF_GET_SYS_DATE=29
SF_CURRENT_FOLDER=30
+ SSF_SET_CF=1 ; set current folder for the thread // set_current_folder()
+ SSF_GET_CF=2 // get_current_folder()
SSF_ADD_SYS_FOLDER=3 ; install the add.system directory for the kernel
SF_GET_PIXEL_OWNER=34 ; get slot number of the screen pixel owner
SF_GET_PIXEL=35 ; read the screen pixel color
SF_GET_IMAGE=36 ; read the screen area
SF_MOUSE_GET=37
+ SSF_SCREEN_POSITION=0 // get_mouse_pos(POS_SCREEN)
+ SSF_WINDOW_POSITION=1 // get_mouse_pos(POS_WINDOW)
+ SSF_BUTTON=2 ; states of the mouse buttons //get_mouse_buttons()
+ SSF_BUTTON_EXT=3 ; states and events of the mouse buttons // get_mouse_eventstate()
+ SSF_LOAD_CURSOR=4
+ SSF_SET_CURSOR=5
+ SSF_DEL_CURSOR=6 // destroy_cursor()
+ SSF_SCROLL_DATA=7 //get_mouse_wheels()
+SF_DRAW_LINE=38
SF_BACKGROUND_GET=39
;SSF_SIZE_BG=1
;SSF_PIXEL_BG=2
;SSF_MODE_BG=4
+SF_SET_EVENTS_MASK=40 ; turn on/off desired events
SF_PORT_IN_OUT=43 ; input/output to a port
SF_SET_PORTS=46 ; reserve/free a group of input/output ports
+SF_DRAW_NUMBER=47 ; draw number to the window // draw_number_sys()
SF_STYLE_SETTINGS=48
SSF_APPLY=0 ; apply screen settings
SSF_SET_BUTTON_STYLE=1
SSF_SET_COLORS=2
+ SSF_GET_COLORS=3 ; get standard window colors // get_system_colors()
+ SSF_GET_SKIN_HEIGHT=4
SSF_GET_SCREEN_AREA=5 ; get screen working area
SSF_SET_SCREEN_AREA=6
SSF_GET_SKIN_MARGINS=7
SSF_SET_SKIN=8
SSF_GET_FONT_SMOOTH=9
SSF_SET_FONT_SMOOTH=10
SSF_GET_FONT_SIZE=11
SSF_SET_FONT_SIZE=12
SF_APM=49
SF_SET_WINDOW_SHAPE=50
+SF_CREATE_THREAD=51 // start_thread()
SF_CLIPBOARD=54
+ SSF_GET_SLOT_COUNT=0 ; get the number of slots in the clipboard // kol_clip_num()
+ SSF_READ_CB=1 // kol_clip_get()
+ SSF_WRITE_CB=2 // kol_clip_set()
+ SSF_DEL_SLOT=3 ; delete the last slot in the clipboard // kol_clip_pop()
+ SSF_UNLOCK_BUFFER=4 ; emergency buffer unlock // kol_clip_unlock()
SF_SPEAKER_PLAY=55
SF_PCI_BIOS=57
SF_IPC=60 ; Inter Process Communication
+ SSF_SET_AREA=1 ; set area for IPC receiving // ipc_set_area()
+ SSF_SEND_MESSAGE=2 // ipc_send_message()
SF_GET_GRAPHICAL_PARAMS=61
+ SSF_SCREEN_SIZE=1 // GetScreenSize()
SSF_BITS_PER_PIXEL=2
SSF_BYTES_PER_LINE=3
SF_PCI=62
SSF_GET_VERSION=0 ; get version of PCI-interface
SSF_GET_LAST_BUS=1 ; get number of the last PCI-bus
SSF_GET_ADRR_MODE=2 ; get addressing mode of the PCI configuration space
SSF_READ_BYTE=4
SSF_READ_WORD=5
SSF_READ_DWORD=6
SSF_WRITE_BYTE=8
SSF_WRITE_WORD=9
SSF_WRITE_DWORD=10
SF_BOARD=63
+ SSF_DEBUG_WRITE=1 // debug_board_write_byte()
SSF_DEBUG_READ=2
SF_MEMORY_RESIZE=64 ; resize total application memory
SF_PUT_IMAGE_EXT=65 ; draw image with palette to the window
SF_KEYBOARD=66
SSF_SET_INPUT_MODE=1
SSF_GET_INPUT_MODE=2
SSF_GET_CONTROL_KEYS=3; get status of control keys
SSF_SET_SYS_HOTKEY=4
SSF_DEL_SYS_HOTKEY=5
SSF_LOCK_INPUT=6 ; block normal input
SSF_UNLOCK_INPUT=7 ; restore normal input
SF_CHANGE_WINDOW=67 ; change position/sizes of the window
SF_SYS_MISC=68
SSF_GET_TASK_SWITCH_COUNT=0
+ SSF_SWITCH_TASK=1 //yield()
SSF_PERFORMANCE=2
SSSF_ALLOW_RDPMC=0
SSSF_CACHE_STATUS=1
SSSF_CACHE_ON=2
SSSF_CACHE_OFF=3
SSF_READ_MSR=3
SSF_WRITE_MSR=4
SSF_HEAP_INIT=11
+ SSF_MEM_ALLOC=12 // user_alloc()
+ SSF_MEM_FREE=13 // user_free()
SSF_WAIT_SIGNAL=14 ; wait for signal from another program/driver
+ SSF_LOAD_DRIVER=16 // get_service()
+ SSF_CONTROL_DRIVER=17 // call_service()
SSF_LOAD_DLL=19
+ SSF_MEM_REALLOC=20 //user_realloc()
SSF_LOAD_DRIVER_PE=21
+ SSF_MEM_OPEN=22 ; open named memory area // shm_open()
+ SSF_MEM_CLOSE=23 // shm_close()
SSF_SET_EXCEPTION_HANDLER=24
SSF_SET_EXCEPTION_STATE=25
+ SSF_MEM_FREE_EXT=26 // user_unmap()
+ SSF_LOAD_FILE=27
SF_DEBUG=69
SSF_SET_MESSAGE_AREA=0
SSF_GET_REGISTERS=1
SSF_SET_REGISTERS=2
SSF_DETACH=3
SSF_SUSPEND=4
SSF_RESUME=5
SSF_READ_MEMORY=6
SSF_WRITE_MEMORY=7
SSF_TERMINATE=8
SSF_DEFINE_BREAKPOINT=9
SF_FILE=70
SSF_READ_FILE=0
SSF_READ_FOLDER=1
SSF_CREATE_FILE=2
SSF_WRITE_FILE=3
SSF_SET_END=4
SSF_GET_INFO=5
SSF_SET_INFO=6
+ SSF_START_APP=7
SSF_DELETE=8
SSF_CREATE_FOLDER=9
SF_SET_CAPTION=71
SF_SEND_MESSAGE=72
+SF_BLITTER=73 //Blit()
SF_NETWORK_GET=74
SSF_DEVICE_COUNT=255 ; get number of active network devices
SSF_DEVICE_TYPE=0
SSF_DEVICE_NAME=1
SSF_RESET_DEVICE=2
SSF_STOP_DEVICE=3
SSF_DEVICE_POINER=4
SSF_TX_PACKET_COUNT=6
SSF_RX_PACKET_COUNT=7
SSF_TX_BYTE_COUNT=8
SSF_RX_BYTE_COUNT=9
SSF_LINK_STATUS=10
SF_NETWORK_SOCKET=75
SSF_OPEN=0
SSF_CLOSE=1
SSF_BIND=2
SSF_LISTEN=3
SSF_CONNECT=4
SSF_ACCEPT=5
SSF_SEND=6
SSF_RECEIVE=7
SSF_SET_OPTIONS=8
SSF_GET_OPTIONS=9
SSF_GET_PAIR=10
SF_NETWORK_PROTOCOL=76
SSF_ETHERNET_READ_MAC=0
SSF_IP4_PACKETS_SENT=10000h
SSF_IP4_PACKETS_RECEIVED=10001h
SSF_IP4_READ_IP=10002h
SSF_IP4_WRITE_IP=10003h
SSF_IP4_READ_DNS=10004h
SSF_IP4_WRITE_DNS=10005h
SSF_IP4_READ_SUBNET=10006h
SSF_IP4_WRITE_SUBNET=10007h
SSF_IP4_READ_GATEWAY=10008h
SSF_IP4_WRITE_GATEWAY=10009h
SSF_ICMP_PACKETS_SENT=20000h
SSF_ICMP_PACKETS_RECEIVED=20001h
SSF_ICMP_ECHO_REPLY=20003h
SSF_UDP_PACKETS_SENT=30000h
SSF_UDP_PACKETS_RECEIVED=30001h
SSF_TCP_PACKETS_SENT=40000h
SSF_TCP_PACKETS_RECEIVED=40001h
SSF_ARP_PACKETS_SENT=50000h
SSF_ARP_PACKETS_RECEIVED=50001h
SSF_ARP_GET_ENTRY_COUNT=50002h
SSF_ARP_READ_ENTRY=50003h
SSF_ARP_ADD_STATIC_ENTRY=50004h
SSF_ARP_DEL_ENTRY=50005h
SSF_ARP_SEND_ANNOUNCE=50006h
SSF_ARP_CONFLICTS_COUNT=50007h
SF_FUTEX=77
SSF_CREATE=0
SSF_DESTROY=1
SSF_WAIT=2
SSF_WAKE=3
 
; File system errors:
FSERR_SUCCESS=0
FSERR_UNSUPPORTED=2
FSERR_UNKNOWN=3
FSERR_FILE_NOT_FOUND=5
FSERR_END_OF_FILE=6
FSERR_INVALID_BUFFER=7
FSERR_DISK_FULL=8
FSERR_FAIL=9
FSERR_ACCESS_DENIED=10
FSERR_DEVICE_FAIL=11
FSERR_OUT_OF_MEMORY=12
/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