gblib src added
git-svn-id: svn://kolibrios.org@1879 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
0e98f2ea01
commit
2118401afb
4
programs/develop/libraries/gblib/compile.bat
Normal file
4
programs/develop/libraries/gblib/compile.bat
Normal file
@ -0,0 +1,4 @@
|
||||
del gblib.obj
|
||||
gcc -c -o gblib.obj gblib.c
|
||||
kpack gblib.obj
|
||||
pause
|
39
programs/develop/libraries/gblib/example/asm_code.asm
Normal file
39
programs/develop/libraries/gblib/example/asm_code.asm
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
format MS COFF
|
||||
|
||||
public Start
|
||||
public _hStack
|
||||
public _KOL_PATH
|
||||
public _KOL_PARAM
|
||||
|
||||
extrn Memory
|
||||
extrn hEnd
|
||||
|
||||
extrn _kol_main
|
||||
|
||||
section ".text" code
|
||||
db "MENUET01"
|
||||
dd 1, Start, hEnd, Memory, _hStack, _KOL_PARAM, _KOL_PATH
|
||||
|
||||
Start:
|
||||
|
||||
; èíèöèàëèçàöèÿ êó÷è
|
||||
mov eax, 68
|
||||
mov ebx, 11
|
||||
int 0x40
|
||||
|
||||
; âûçîâ ãëàâíîé ïðîöåäóðû
|
||||
mov eax, _kol_main
|
||||
call eax
|
||||
|
||||
; çàâåðøåíèå ðàáîòû ïðîãðàììû
|
||||
mov eax, -1
|
||||
int 0x40
|
||||
|
||||
section ".bss"
|
||||
|
||||
_KOL_PARAM rb 256
|
||||
_KOL_PATH rb 256
|
||||
|
||||
rb 16*1024
|
||||
_hStack:
|
12
programs/develop/libraries/gblib/example/compile.bat
Normal file
12
programs/develop/libraries/gblib/example/compile.bat
Normal file
@ -0,0 +1,12 @@
|
||||
del *.o
|
||||
del example.kex
|
||||
fasm asm_code.asm start.o
|
||||
gcc -c example.c
|
||||
gcc -c system/kolibri.c
|
||||
gcc -c system/stdlib.c
|
||||
gcc -c system/string.c
|
||||
ld -nostdlib -T kolibri.ld -o example.kex start.o kolibri.o stdlib.o string.o example.o
|
||||
objcopy example.kex -O binary
|
||||
kpack example.kex
|
||||
del *.o
|
||||
pause
|
73
programs/develop/libraries/gblib/example/example.c
Normal file
73
programs/develop/libraries/gblib/example/example.c
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
#include "system/kolibri.h"
|
||||
#include "system/stdlib.h"
|
||||
#include "system/string.h"
|
||||
|
||||
#include "gblib.h"
|
||||
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
void kol_main()
|
||||
{
|
||||
|
||||
GB_BMP b;
|
||||
kol_struct_import *imp_gblib;
|
||||
unsigned event;
|
||||
|
||||
imp_gblib = kol_cofflib_load("/sys/lib/gblib.obj");
|
||||
|
||||
gb_pixel_set = kol_cofflib_procload (imp_gblib, "gb_pixel_set");
|
||||
gb_pixel_get = kol_cofflib_procload (imp_gblib, "gb_pixel_get");
|
||||
gb_line = kol_cofflib_procload (imp_gblib, "gb_line");
|
||||
gb_rect = kol_cofflib_procload (imp_gblib, "gb_rect");
|
||||
gb_bar = kol_cofflib_procload (imp_gblib, "gb_bar");
|
||||
gb_circle = kol_cofflib_procload (imp_gblib, "gb_circle");
|
||||
gb_image_set = kol_cofflib_procload (imp_gblib, "gb_image_set");
|
||||
gb_image_set_t = kol_cofflib_procload (imp_gblib, "gb_image_set_t");
|
||||
|
||||
b.w = 300;
|
||||
b.h = 200;
|
||||
b.bmp = malloc (300*200*3);
|
||||
|
||||
gb_bar (&b, 4, 8, 4, 12, 0xff0000); // red
|
||||
gb_bar (&b, 10, 8, 4, 12, 0x00ff00); // green
|
||||
gb_bar (&b, 16, 8, 4, 12, 0x0000ff); // blue
|
||||
|
||||
gb_line(&b, 4, 30, 50, 30, 0xffffff); // white line
|
||||
gb_line(&b, 55, 4, 120, 60, 0xf0f033); // another line
|
||||
|
||||
gb_rect(&b, 65, 24, 100, 60, 0x2065ff); // rectangle
|
||||
|
||||
gb_circle(&b, 55, 95, 40, 0x20ff20); // circle
|
||||
|
||||
for (;;)
|
||||
{
|
||||
event = kol_event_wait();
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case 1:
|
||||
kol_paint_start();
|
||||
kol_wnd_define(50, 50, 350, 240, 0x34f0f0f0);
|
||||
kol_paint_image(3, 3, 300, 200, b.bmp);
|
||||
kol_paint_end();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
kol_key_get();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if ( 1 == (kol_btn_get() & 0xff00)>>8 )
|
||||
kol_exit();
|
||||
break;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// ===========================================================
|
18
programs/develop/libraries/gblib/example/gblib.h
Normal file
18
programs/develop/libraries/gblib/example/gblib.h
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int w __attribute__((packed));
|
||||
int h __attribute__((packed));
|
||||
char *bmp __attribute__((packed));
|
||||
char *alpha __attribute__((packed));
|
||||
} GB_BMP __attribute__((packed));
|
||||
|
||||
|
||||
void (* __stdcall gb_pixel_set)(GB_BMP *b, int x, int y, unsigned c);
|
||||
int (* __stdcall gb_pixel_get)(GB_BMP *b, int x, int y, unsigned *c);
|
||||
void (* __stdcall gb_line)(GB_BMP *b, int x1, int y1, int x2, int y2, unsigned c);
|
||||
void (* __stdcall gb_rect)(GB_BMP *b, int x, int y, int w, int h, unsigned c);
|
||||
void (* __stdcall gb_bar)(GB_BMP *b, int x, int y, int w, int h, unsigned c);
|
||||
void (* __stdcall gb_circle)(GB_BMP *b, int x, int y, int r, unsigned c);
|
||||
void (* __stdcall 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 (* __stdcall 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);
|
20
programs/develop/libraries/gblib/example/kolibri.ld
Normal file
20
programs/develop/libraries/gblib/example/kolibri.ld
Normal file
@ -0,0 +1,20 @@
|
||||
/*OUTPUT_FORMAT("binary")*/
|
||||
ENTRY(Start)
|
||||
SECTIONS
|
||||
{
|
||||
.text 0x000000:
|
||||
{
|
||||
*(.text)
|
||||
}
|
||||
|
||||
.data : {
|
||||
*(.data)
|
||||
hEnd = . ;
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(.bss)
|
||||
}
|
||||
Memory = . ;
|
||||
}
|
412
programs/develop/libraries/gblib/example/system/kolibri.c
Normal file
412
programs/develop/libraries/gblib/example/system/kolibri.c
Normal file
@ -0,0 +1,412 @@
|
||||
|
||||
#include "kolibri.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
extern char KOL_PATH[256];
|
||||
extern char KOL_PARAM[256];
|
||||
extern char KOL_DIR[256];
|
||||
|
||||
|
||||
void kol_exit()
|
||||
{
|
||||
asm ("int $0x40"::"a"(-1));
|
||||
}
|
||||
|
||||
|
||||
void kol_sleep(unsigned d)
|
||||
{
|
||||
asm ("int $0x40"::"a"(5), "b"(d));
|
||||
}
|
||||
|
||||
|
||||
void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
|
||||
{
|
||||
asm ("nop"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
|
||||
asm ("movl $0xffffff, %esi \n int $0x40");
|
||||
}
|
||||
|
||||
|
||||
void kol_wnd_move(unsigned x, unsigned y)
|
||||
{
|
||||
asm ("nop"::"a"(67), "b"(x), "c"(y));
|
||||
asm ("movl $-1, %edx \n movl $-1, %esi \n int $0x40");
|
||||
}
|
||||
|
||||
|
||||
void kol_event_mask(unsigned e)
|
||||
{
|
||||
asm ("int $0x40"::"a"(40), "b"(e));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_event_wait()
|
||||
{
|
||||
asm ("int $0x40"::"a"(10));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_event_wait_time(unsigned time)
|
||||
{
|
||||
asm ("int $0x40"::"a"(23), "b"(time));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_event_check()
|
||||
{
|
||||
asm ("int $0x40"::"a"(11));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_start()
|
||||
{
|
||||
asm ("int $0x40"::"a"(12), "b"(1));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_end()
|
||||
{
|
||||
asm ("int $0x40"::"a"(12), "b"(2));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_pixel(unsigned x, unsigned y, unsigned c)
|
||||
{
|
||||
asm ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
|
||||
{
|
||||
asm ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c)
|
||||
{
|
||||
asm ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c)
|
||||
{
|
||||
asm ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
|
||||
{
|
||||
asm ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
|
||||
}
|
||||
|
||||
|
||||
void kol_paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette)
|
||||
{
|
||||
asm ("nop"::"c"(w*65536+h), "d"(x*65536+y), "b"(d));
|
||||
asm ("nop"::"a"(palette));
|
||||
asm ("movl %eax, %edi");
|
||||
asm ("xor %eax, %eax");
|
||||
asm ("movl %eax, %ebp");
|
||||
asm ("pushl $8");
|
||||
asm ("popl %esi");
|
||||
asm ("int $0x40"::"a"(65));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_key_get()
|
||||
{
|
||||
asm ("int $0x40"::"a"(2));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_key_control()
|
||||
{
|
||||
asm ("int $0x40"::"a"(66), "b"(3));
|
||||
}
|
||||
|
||||
|
||||
void kol_key_lang_set(unsigned lang)
|
||||
{
|
||||
asm ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_key_lang_get()
|
||||
{
|
||||
asm ("int $0x40"::"a"(26), "b"(2), "c"(9));
|
||||
}
|
||||
|
||||
|
||||
void kol_key_mode_set(unsigned mode)
|
||||
{
|
||||
asm ("int $0x40"::"a"(66), "b"(1), "c"(mode));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_key_mode_get()
|
||||
{
|
||||
asm ("int $0x40"::"a"(66), "b"(2));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_btn_get()
|
||||
{
|
||||
asm ("int $0x40"::"a"(17));
|
||||
}
|
||||
|
||||
|
||||
void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c)
|
||||
{
|
||||
asm ("nop"::"b"(x*65536+w), "c"(y*65536+h), "d"(d));
|
||||
asm ("nop"::"a"(c));
|
||||
asm ("movl %eax, %esi");
|
||||
asm ("int $0x40"::"a"(8));
|
||||
}
|
||||
|
||||
|
||||
void kol_btn_type(unsigned t)
|
||||
{
|
||||
asm ("int $0x40"::"a"(48), "b"(1), "c"(t));
|
||||
}
|
||||
|
||||
|
||||
void kol_wnd_caption(char *s)
|
||||
{
|
||||
asm ("int $0x40"::"a"(71), "b"(1), "c"(s));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_mouse_pos()
|
||||
{
|
||||
asm ("int $0x40"::"a"(37), "b"(0));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_mouse_posw()
|
||||
{
|
||||
asm ("int $0x40"::"a"(37), "b"(1));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_mouse_btn()
|
||||
{
|
||||
asm ("int $0x40"::"a"(37), "b"(2));
|
||||
}
|
||||
|
||||
|
||||
void kol_board_putc(char c)
|
||||
{
|
||||
asm ("int $0x40"::"a"(63), "b"(1), "c"(c));
|
||||
}
|
||||
|
||||
|
||||
void kol_board_puts(char *s)
|
||||
{
|
||||
unsigned i;
|
||||
i = 0;
|
||||
while (*(s+i))
|
||||
{
|
||||
asm ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void kol_board_puti(int n)
|
||||
{
|
||||
char c;
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
c = n % 10 + '0';
|
||||
asm ("int $0x40"::"a"(63), "b"(1), "c"(c));
|
||||
i++;
|
||||
}
|
||||
while ((n /= 10) > 0);
|
||||
}
|
||||
|
||||
|
||||
int kol_file_70(kol_struct70 *k)
|
||||
{
|
||||
asm ("int $0x40"::"a"(70), "b"(k));
|
||||
}
|
||||
|
||||
|
||||
kol_struct_import* kol_cofflib_load(char *name)
|
||||
{
|
||||
asm ("int $0x40"::"a"(68), "b"(19), "c"(name));
|
||||
}
|
||||
|
||||
|
||||
void* kol_cofflib_procload (kol_struct_import *imp, char *name)
|
||||
{
|
||||
int i;
|
||||
for (i=0;;i++)
|
||||
if ( NULL == ((imp+i) -> name))
|
||||
break;
|
||||
else
|
||||
if ( 0 == strcmp(name, (imp+i)->name) )
|
||||
return (imp+i)->data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_cofflib_procnum (kol_struct_import *imp)
|
||||
{
|
||||
unsigned i, n;
|
||||
|
||||
for (i=n=0;;i++)
|
||||
if ( NULL == ((imp+i) -> name))
|
||||
break;
|
||||
else
|
||||
n++;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
|
||||
{
|
||||
unsigned i;
|
||||
*name = 0;
|
||||
|
||||
for (i=0;;i++)
|
||||
if ( NULL == ((imp+i) -> name))
|
||||
break;
|
||||
else
|
||||
if ( i == n )
|
||||
{
|
||||
strcpy(name, ((imp+i)->name));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_system_cpufreq()
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(5));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_system_mem()
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(17));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_system_memfree()
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(16));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_system_time_get()
|
||||
{
|
||||
asm ("int $0x40"::"a"(3));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_system_date_get()
|
||||
{
|
||||
asm ("int $0x40"::"a"(29));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_system_end(unsigned param)
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(9), "c"(param));
|
||||
}
|
||||
|
||||
|
||||
void kol_path_file2dir(char *dir, char *fname)
|
||||
{
|
||||
unsigned i;
|
||||
strcpy (dir, fname);
|
||||
for ( i = strlen(dir);; --i)
|
||||
if ( '/' == dir[i])
|
||||
{
|
||||
dir[i] = '\0';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void kol_path_full(char *full, char *fname)
|
||||
{
|
||||
char temp[256];
|
||||
|
||||
switch (*fname)
|
||||
{
|
||||
|
||||
case '/':
|
||||
strncpy(temp, fname+1, 2);
|
||||
temp[2]=0;
|
||||
if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) )
|
||||
strcpy (full, fname);
|
||||
break;
|
||||
|
||||
case '.':
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void kol_screen_wait_rr()
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(14));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void kol_screen_get_size(unsigned *w, unsigned *h)
|
||||
{
|
||||
unsigned size;
|
||||
asm ("int $0x40":"=a"(size):"a"(14));
|
||||
*w = size / 65536;
|
||||
*h = size % 65536;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned kol_skin_height()
|
||||
{
|
||||
asm ("int $0x40"::"a"(48), "b"(4));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_thread_start(unsigned start, unsigned stack)
|
||||
{
|
||||
asm ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_time_tick()
|
||||
{
|
||||
asm ("int $0x40"::"a"(26), "b"(9));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_sound_speaker(char data[])
|
||||
{
|
||||
asm ("movl %0, %%esi"::"a"(data));
|
||||
asm ("int $0x40"::"a"(55), "b"(55));
|
||||
}
|
||||
|
||||
|
||||
unsigned kol_process_info(unsigned slot, char buf1k[])
|
||||
{
|
||||
asm ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot));
|
||||
}
|
||||
|
||||
|
||||
int kol_process_kill_pid(unsigned process)
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(18), "c"(process));
|
||||
}
|
90
programs/develop/libraries/gblib/example/system/kolibri.h
Normal file
90
programs/develop/libraries/gblib/example/system/kolibri.h
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00 __attribute__((packed));
|
||||
unsigned p04 __attribute__((packed));
|
||||
unsigned p08 __attribute__((packed));
|
||||
unsigned p12 __attribute__((packed));
|
||||
unsigned p16 __attribute__((packed));
|
||||
char p20 __attribute__((packed));
|
||||
char *p21 __attribute__((packed));
|
||||
} kol_struct70 __attribute__((packed));
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00 __attribute__((packed));
|
||||
char p04 __attribute__((packed));
|
||||
char p05[3] __attribute__((packed));
|
||||
unsigned p08 __attribute__((packed));
|
||||
unsigned p12 __attribute__((packed));
|
||||
unsigned p16 __attribute__((packed));
|
||||
unsigned p20 __attribute__((packed));
|
||||
unsigned p24 __attribute__((packed));
|
||||
unsigned p28 __attribute__((packed));
|
||||
unsigned p32[2] __attribute__((packed));
|
||||
unsigned p40 __attribute__((packed));
|
||||
} kol_struct_BDVK __attribute__((packed));
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name __attribute__((packed));
|
||||
void *data __attribute__((packed));
|
||||
} kol_struct_import __attribute__((packed));
|
||||
|
||||
|
||||
void kol_exit();
|
||||
void kol_sleep(unsigned d);
|
||||
void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c);
|
||||
void kol_wnd_move(unsigned x, unsigned y);
|
||||
void kol_wnd_caption(char *s);
|
||||
void kol_event_mask(unsigned e);
|
||||
unsigned kol_event_wait();
|
||||
unsigned kol_event_wait_time(unsigned time);
|
||||
unsigned kol_event_check();
|
||||
void kol_paint_start();
|
||||
void kol_paint_end();
|
||||
void kol_paint_pixel(unsigned x, unsigned y, unsigned c);
|
||||
void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c);
|
||||
void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c);
|
||||
void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c);
|
||||
void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d);
|
||||
void kol_paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette);
|
||||
unsigned kol_key_get();
|
||||
unsigned kol_key_control();
|
||||
void kol_key_lang_set(unsigned lang);
|
||||
unsigned kol_key_lang_get();
|
||||
void kol_key_mode_set(unsigned mode);
|
||||
unsigned kol_key_mode_get();
|
||||
void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c);
|
||||
unsigned kol_btn_get();
|
||||
void kol_btn_type(unsigned t);
|
||||
unsigned kol_mouse_pos();
|
||||
unsigned kol_mouse_posw();
|
||||
unsigned kol_mouse_btn();
|
||||
void kol_board_putc(char c);
|
||||
void kol_board_puts(char *s);
|
||||
void kol_board_puti(int n);
|
||||
int kol_file_70(kol_struct70 *k);
|
||||
kol_struct_import* kol_cofflib_load(char *name);
|
||||
void* kol_cofflib_procload (kol_struct_import *imp, char *name);
|
||||
unsigned kol_cofflib_procnum (kol_struct_import *imp);
|
||||
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n);
|
||||
unsigned kol_system_end(unsigned param);
|
||||
unsigned kol_system_cpufreq();
|
||||
unsigned kol_system_mem();
|
||||
unsigned kol_system_memfree();
|
||||
unsigned kol_system_time_get();
|
||||
unsigned kol_system_date_get();
|
||||
void kol_path_file2dir(char *dir, char *fname);
|
||||
void kol_path_full(char *full, char *fname);
|
||||
void kol_screen_wait_rr();
|
||||
void kol_screen_get_size(unsigned *w, unsigned *h);
|
||||
unsigned kol_skin_height();
|
||||
unsigned kol_thread_start(unsigned start, unsigned stack);
|
||||
unsigned kol_time_tick();
|
||||
unsigned kol_sound_speaker(char data[]);
|
||||
unsigned kol_process_info(unsigned slot, char buf1k[]);
|
||||
int kol_process_kill_pid(unsigned process);
|
33
programs/develop/libraries/gblib/example/system/stdlib.c
Normal file
33
programs/develop/libraries/gblib/example/system/stdlib.c
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
unsigned int seed_o = 0x45168297;
|
||||
|
||||
|
||||
void srand (unsigned seed)
|
||||
{
|
||||
seed_o = seed;
|
||||
}
|
||||
|
||||
|
||||
int rand (void)
|
||||
{
|
||||
seed_o = seed_o * 0x15a4e35 + 1;
|
||||
return(seed_o >> 16);
|
||||
}
|
||||
|
||||
|
||||
void* malloc(unsigned s)
|
||||
{
|
||||
asm ("int $0x40"::"a"(68), "b"(12), "c"(s) );
|
||||
}
|
||||
|
||||
|
||||
void free(void *p)
|
||||
{
|
||||
asm ("int $0x40"::"a"(68), "b"(13), "c"(p) );
|
||||
}
|
||||
|
||||
|
||||
void* realloc(void *p, unsigned s)
|
||||
{
|
||||
asm ("int $0x40"::"a"(68), "b"(12), "c"(p), "d"(s) );
|
||||
}
|
14
programs/develop/libraries/gblib/example/system/stdlib.h
Normal file
14
programs/develop/libraries/gblib/example/system/stdlib.h
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#define RAND_MAX 0x7FFFU
|
||||
|
||||
#define isspace(c) ((c)==' ')
|
||||
#define abs(i) (((i)<0)?(-(i)):(i))
|
||||
|
||||
#define random(num) ((rand()*(num))/((RAND_MAX+1)))
|
||||
|
||||
void* malloc(unsigned size);
|
||||
void free(void *pointer);
|
||||
void* realloc(void* pointer, unsigned size);
|
||||
|
||||
void srand (unsigned seed);
|
||||
int rand (void);
|
124
programs/develop/libraries/gblib/example/system/string.c
Normal file
124
programs/develop/libraries/gblib/example/system/string.c
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
#include "string.h"
|
||||
|
||||
void* memset(void *mem, int c, unsigned size)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for ( i = 0; i < size; i++ )
|
||||
*((char *)mem+i) = (char) c;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void* memcpy(void *dst, const void *src, unsigned size)
|
||||
{
|
||||
|
||||
unsigned i;
|
||||
|
||||
for ( i = 0; i < size; i++)
|
||||
*(char *)(dst+i) = *(char *)(src+i);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int memcmp(const void* buf1, const void* buf2, int count)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
if (*(unsigned char*)buf1<*(unsigned char*)buf2)
|
||||
return -1;
|
||||
if (*(unsigned char*)buf1>*(unsigned char*)buf2)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void strcat(char strDest[], char strSource[])
|
||||
{
|
||||
|
||||
int i, j;
|
||||
|
||||
i = j = 0;
|
||||
while (strDest[i] != '\0')
|
||||
i++;
|
||||
|
||||
while ((strDest[i++] = strSource[j++]) != '\0')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void strcpy(char strDest[], const char strSource[])
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
i = 0;
|
||||
while ((strDest[i] = strSource[i]) != '\0')
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
char* strncpy(char *strDest, const char *strSource, unsigned n)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (! n )
|
||||
return strDest;
|
||||
|
||||
i = 0;
|
||||
while ((strDest[i] = strSource[i]) != '\0')
|
||||
if ( (n-1) == i )
|
||||
break;
|
||||
else
|
||||
i++;
|
||||
|
||||
return strDest;
|
||||
}
|
||||
|
||||
|
||||
int strlen(const char* string)
|
||||
{
|
||||
int i;
|
||||
|
||||
i=0;
|
||||
while (*string++) i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char* strchr(const char* string, int c)
|
||||
{
|
||||
while (*string)
|
||||
{
|
||||
if (*string==c)
|
||||
return (char*)string;
|
||||
string++;
|
||||
}
|
||||
return (char*)0;
|
||||
}
|
||||
|
15
programs/develop/libraries/gblib/example/system/string.h
Normal file
15
programs/develop/libraries/gblib/example/system/string.h
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
void* memset(void *mem, int c, unsigned size);
|
||||
void* memcpy(void *dst, const void *src, unsigned size);
|
||||
int memcmp(const void* buf1, const void* buf2, int count);
|
||||
|
||||
void strcat(char strDest[], char strSource[]);
|
||||
int strcmp(const char* string1, const char* string2);
|
||||
void strcpy(char strDest[], const char strSource[]);
|
||||
char* strncpy(char *strDest, const char *strSource, unsigned n);
|
||||
int strlen(const char* string);
|
||||
char *strchr(const char* string, int c);
|
270
programs/develop/libraries/gblib/gblib.c
Normal file
270
programs/develop/libraries/gblib/gblib.c
Normal file
@ -0,0 +1,270 @@
|
||||
|
||||
#include "gblib.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 },
|
||||
};
|
||||
|
25
programs/develop/libraries/gblib/gblib.h
Normal file
25
programs/develop/libraries/gblib/gblib.h
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int w __attribute__((packed));
|
||||
int h __attribute__((packed));
|
||||
char *bmp __attribute__((packed));
|
||||
char *alpha __attribute__((packed));
|
||||
} GB_BMP __attribute__((packed));
|
||||
|
||||
|
||||
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);
|
30
programs/develop/libraries/gblib/readme.txt
Normal file
30
programs/develop/libraries/gblib/readme.txt
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
Graphics Board Library
|
||||
version 0.5
|
||||
|
||||
4 апреля 2009 г.
|
||||
|
||||
======================
|
||||
|
||||
Графическая библиотека
|
||||
с буфером в режиме 24BPP.
|
||||
|
||||
======================
|
||||
|
||||
Реализованные функции:
|
||||
|
||||
gb_pixel_set - поставить точку
|
||||
gb_pixel_get - получить точку
|
||||
gb_line - линия
|
||||
gb_rect - прямоугольник
|
||||
gb_bar - закрашенный прямоугольник
|
||||
gb_circle - окружность
|
||||
gb_image_set - изображение
|
||||
gb_image_set_t - изображение с прозрачным
|
||||
цветом
|
||||
|
||||
======================
|
||||
|
||||
автор : А. Богомаз aka Albom
|
||||
e-mail: albom85@yandex.ru
|
||||
сайт : http://albom85.narod.ru
|
Loading…
Reference in New Issue
Block a user