From fe1a451ca0482528aaa606670be4333319f13119 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Thu, 15 Oct 2020 23:20:59 +0000 Subject: [PATCH] Added source code for libraries git-svn-id: svn://kolibrios.org@8102 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/ktcc/trunk/lib/libgb/Makefile | 9 + programs/develop/ktcc/trunk/lib/libgb/gb.c | 270 ++++++++++++++++++ programs/develop/ktcc/trunk/lib/libgb/gb.h | 19 ++ .../develop/ktcc/trunk/lib/libimg/Makefile | 5 + .../ktcc/trunk/lib/libimg/loadlibimg.asm | 87 ++++++ .../ktcc/trunk/lib/librasterworks/__lib__.asm | 9 + .../ktcc/trunk/lib/librasterworks/__lib__.inc | 2 + .../trunk/lib/librasterworks/charsFit.asm | 18 ++ .../trunk/lib/librasterworks/cntUTF-8.asm | 18 ++ .../trunk/lib/librasterworks/drawText.asm | 18 ++ .../ktcc/trunk/lib/librasterworks/make.bat | 7 + .../ktcc/trunk/lib/librasterworks/makefile | 9 + .../trunk/lib/librasterworks/strWidth.asm | 18 ++ 13 files changed, 489 insertions(+) create mode 100644 programs/develop/ktcc/trunk/lib/libgb/Makefile create mode 100644 programs/develop/ktcc/trunk/lib/libgb/gb.c create mode 100644 programs/develop/ktcc/trunk/lib/libgb/gb.h create mode 100644 programs/develop/ktcc/trunk/lib/libimg/Makefile create mode 100644 programs/develop/ktcc/trunk/lib/libimg/loadlibimg.asm create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/__lib__.asm create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/__lib__.inc create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/charsFit.asm create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/cntUTF-8.asm create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/drawText.asm create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/make.bat create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/makefile create mode 100644 programs/develop/ktcc/trunk/lib/librasterworks/strWidth.asm diff --git a/programs/develop/ktcc/trunk/lib/libgb/Makefile b/programs/develop/ktcc/trunk/lib/libgb/Makefile new file mode 100644 index 0000000000..93031d9cd4 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libgb/Makefile @@ -0,0 +1,9 @@ +# gcc not kos32-gcc +all: + gcc -c -O2 -nostdinc -nostdlib -m32 -march=i686 -fomit-frame-pointer -fno-builtin -fno-builtin-printf gb.c + ar -rcs libgb.a gb.o +clean: + rm -f *.o + rm -f *.a +install: + cp libgb.a ../../bin/lib diff --git a/programs/develop/ktcc/trunk/lib/libgb/gb.c b/programs/develop/ktcc/trunk/lib/libgb/gb.c new file mode 100644 index 0000000000..6f5f4a554f --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libgb/gb.c @@ -0,0 +1,270 @@ + +#include "gb.h" + +//========================= + +void gb_pixel_set(GB_BMP *b, int x, int y, unsigned c) +{ +// поставить точку + +unsigned s; + +if ((x+1 > b->w )||(y+1 > b->h)) + return; + +if ((x < 0)||(y < 0)) + return; + +s = 3*( y*(b->w) + x ); + +*( b -> bmp + s ) = c & 0xff; +*( b -> bmp + s + 1) = (c >> 8) & 0xff; +*( b -> bmp + s + 2) = (c >> 16)& 0xff; + +} + +//========================= + +int gb_pixel_get(GB_BMP *b, int x, int y, unsigned *c) +{ +// получить точку + +unsigned red, green, blue, s; + +if ((x < 0) || (y < 0)) + return 0; + +if ((x+1 > b->w )||(y+1 > b->h)) + return 0; + +s = 3*( y*(b->w) + x ); + +blue = *( b -> bmp + s ); +green = *( b -> bmp + s + 1); +red = *( b -> bmp + s + 2); + +*c = ((red << 16) & 0xff0000) | ((green << 8) & 0xff00) | (blue & 0xff); + +return 1; +} + +//========================= + +void gb_line(GB_BMP *b, int x1, int y1, int x2, int y2, unsigned c) +{ +// линия заданного цвета с использованием +// алгоpитма Брезенхэма + +int t, dist; +int xerr=0, yerr=0, delta_x, delta_y; +int incx, incy; + +// вычисление pасстояния в обоих напpавлениях +delta_x = x2 - x1; +delta_y = y2 - y1; + +// опpеделение напpавления шага, +// шаг вычисляется либо по веpтикальной, либо гоpизонтальной +// линии +if (delta_x > 0) + incx = 1; +else + if (0 == delta_x) + incx = 0; + else + incx = -1; + +if (delta_y > 0) + incy = 1; +else + if ( 0 == delta_y) + incy = 0; + else + incy = -1; + +// опpеделение наибольшего pасстояния +if (delta_x < 0) + delta_x *= -1; +if (delta_y < 0) + delta_y *= -1; + +if (delta_x > delta_y) + dist = delta_x; +else + dist = delta_y; + + +// вычеpчивание линии +for (t = 0; t <= dist+1; t++) + { + gb_pixel_set(b, x1, y1, c); + xerr+=delta_x; + yerr+=delta_y; + + if (xerr > dist) + { + xerr -= dist; + x1 += incx; + } + + if (yerr > dist) + { + yerr -= dist; + y1 += incy; + } + + } +} + +//========================= + +void gb_rect(GB_BMP *b, int x, int y, int w, int h, unsigned c) +{ +// прямоугольник + +gb_line (b, x, y, x+w-1, y, c); +gb_line (b, x, y+h-1, x+w-1, y+h-1, c); +gb_line (b, x, y, x, y+h-1, c); +gb_line (b, x+w-1, y, x+w-1, y+h-1, c); +} + +//========================= + +void gb_circle(GB_BMP *b, int x, int y, int r, unsigned c) +{ + +int _x; +int _y; +int d; + +_x = 0; +_y = r; +d = 3-2*r; +while( _y >= _x) + { + gb_pixel_set(b, _x + x, _y + y, c); + gb_pixel_set(b, _x + x, -_y + y, c); + gb_pixel_set(b, -_x + x, _y + y, c); + gb_pixel_set(b, -_x + x, -_y + y, c); + gb_pixel_set(b, _y + x, _x + y, c); + gb_pixel_set(b, _y + x, -_x + y, c); + gb_pixel_set(b, -_y + x, _x + y, c); + gb_pixel_set(b, -_y + x, -_x + y, c); + if( d<0 ) + d = d+4*_x+6; + else + { + d = d+4*(_x-_y)+10; + _y--; + } + _x++; + } + +} + +//========================= + +void gb_bar(GB_BMP *b, int x, int y, int w, int h, unsigned c) +{ +// закрашенный прямоугольник + +unsigned s; +int i, j; + +if ((x > b->w)||(y > b->h)) + return; + +for (j = 0; j < w; j++) +for (i = 0; i < h; i++) +// gb_pixel_set(b, x+j, y+i, c); + { + s = 3*( (y+i)*(b->w) + x + j ); + + *( b -> bmp + s ) = c & 0xff; + *( b -> bmp + s + 1) = (c >> 8) & 0xff; + *( b -> bmp + s + 2) = (c >> 16)& 0xff; + + } +} + +//========================= + +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) +{ +// вывод изображения + +int x, y; +unsigned d; + +if ((x_d > b_dest->w)||(y_d > b_dest->h)) + return; + +if ((x_s > b_src->w)||(y_s > b_src->h)) + return; + +for (y = 0; y < h; y++) + for (x = 0; x < w; x++) + if ( gb_pixel_get(b_src, x_s+x, y_s+y, &d) ) + gb_pixel_set(b_dest, x_d+x, y_d+y, d); + + +} + +//========================= + +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) +{ +// вывод изображения с прозрачным цветом + +int x, y; +unsigned d; + +if ((x_d > b_dest->w)||(y_d > b_dest->h)) + return; + +if ((x_s > b_src->w)||(y_s > b_src->h)) + return; + +for (y = 0; y < h; y++) + for (x = 0; x < w; x++) + if ( gb_pixel_get(b_src, x_s+x, y_s+y, &d) ) + if (c != d) + gb_pixel_set(b_dest, x_d+x, y_d+y, d); + + +} + +//========================= + +#define NULL ((void*)0) + +typedef struct +{ +void *name; +void *function; +} export_t; + +//========================= + +char szGb_pixel_set[] = "gb_pixel_set"; +char szGb_pixel_get[] = "gb_pixel_get"; +char szGb_line[] = "gb_line"; +char szGb_rect[] = "gb_rect"; +char szGb_bar[] = "gb_bar"; +char szGb_circle[] = "gb_circle"; +char szGb_image_set[] = "gb_image_set"; +char szGb_image_set_t[] = "gb_image_set_t"; + +export_t EXPORTS[] = +{ +{ szGb_pixel_set, (void*) gb_pixel_set}, +{ szGb_pixel_get, (void*) gb_pixel_get}, +{ szGb_line, (void*) gb_line}, +{ szGb_rect, (void*) gb_rect}, +{ szGb_bar, (void*) gb_bar}, +{ szGb_circle, (void*) gb_circle}, +{ szGb_image_set, (void*) gb_image_set}, +{ szGb_image_set_t, (void*) gb_image_set_t}, +{ NULL, NULL }, +}; + diff --git a/programs/develop/ktcc/trunk/lib/libgb/gb.h b/programs/develop/ktcc/trunk/lib/libgb/gb.h new file mode 100644 index 0000000000..7e0ae75bdb --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libgb/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); diff --git a/programs/develop/ktcc/trunk/lib/libimg/Makefile b/programs/develop/ktcc/trunk/lib/libimg/Makefile new file mode 100644 index 0000000000..98751b563a --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libimg/Makefile @@ -0,0 +1,5 @@ +all: + fasm loadlibimg.asm + ar -csr libimg.a loadlibimg.o +clean: + rm -f *.o *.a diff --git a/programs/develop/ktcc/trunk/lib/libimg/loadlibimg.asm b/programs/develop/ktcc/trunk/lib/libimg/loadlibimg.asm new file mode 100644 index 0000000000..1597d9674d --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/libimg/loadlibimg.asm @@ -0,0 +1,87 @@ +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' + +public libimg_init as 'libimg_init' +; public img_is_img as '_img_is_img' +;public img_info as '_img_info' +;public img_from_file as '_img_from_file' +;public img_to_file as '_img_to_file' +;public img_from_rgb as '_img_from_rgb' +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_lock_bits as '_img_lock_bits' +;public img_unlock_bits as '_img_unlock_bits' +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' diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/__lib__.asm b/programs/develop/ktcc/trunk/lib/librasterworks/__lib__.asm new file mode 100644 index 0000000000..eac1985673 --- /dev/null +++ b/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 diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/__lib__.inc b/programs/develop/ktcc/trunk/lib/librasterworks/__lib__.inc new file mode 100644 index 0000000000..c53f9e5523 --- /dev/null +++ b/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' diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/charsFit.asm b/programs/develop/ktcc/trunk/lib/librasterworks/charsFit.asm new file mode 100644 index 0000000000..97dc8a6a58 --- /dev/null +++ b/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 diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/cntUTF-8.asm b/programs/develop/ktcc/trunk/lib/librasterworks/cntUTF-8.asm new file mode 100644 index 0000000000..6720eac7c0 --- /dev/null +++ b/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 diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/drawText.asm b/programs/develop/ktcc/trunk/lib/librasterworks/drawText.asm new file mode 100644 index 0000000000..9662bc0372 --- /dev/null +++ b/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 diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/make.bat b/programs/develop/ktcc/trunk/lib/librasterworks/make.bat new file mode 100644 index 0000000000..c70d398a69 --- /dev/null +++ b/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 diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/makefile b/programs/develop/ktcc/trunk/lib/librasterworks/makefile new file mode 100644 index 0000000000..078c46ff73 --- /dev/null +++ b/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 diff --git a/programs/develop/ktcc/trunk/lib/librasterworks/strWidth.asm b/programs/develop/ktcc/trunk/lib/librasterworks/strWidth.asm new file mode 100644 index 0000000000..81a3d7e553 --- /dev/null +++ b/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