mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-11-24 09:49:41 +03:00
Some samples for metcc
git-svn-id: svn://kolibrios.org@249 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
62564c56b0
commit
c0f513c3db
74
programs/develop/metcc/trunk/samples/console/console.c
Normal file
74
programs/develop/metcc/trunk/samples/console/console.c
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
// Console dynamic link library. Sample by Ghost
|
||||
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "mesys.h"
|
||||
|
||||
char* dllname="/rd/1/console.obj";
|
||||
int i;
|
||||
|
||||
char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL};
|
||||
char* caption = "Console test - colors";
|
||||
|
||||
dword (* dll_start)(dword res);
|
||||
dword* dll_ver;
|
||||
void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title);
|
||||
void stdcall (* con_write_asciiz)(dword flags, const char* string);
|
||||
void cdecl (* con_printf)(dword flags, const char* format, ...);
|
||||
void stdcall (* con_exit)(dword bCloseWindow);
|
||||
|
||||
struct import{
|
||||
char *name;
|
||||
void *data;
|
||||
};
|
||||
|
||||
// â áèáëèîòåêå åñòü àíàëîãè÷íàÿ ôóíêöèÿ _msys_cofflib_getproc, íî ïîêà îíà ðàáîòàåò íå êîððåêòíî
|
||||
void* __msys_cofflib_getproc(struct import *lib, char *name){
|
||||
int i;
|
||||
for(i = 0; lib[i].name && strcmp(name, lib[i].name); i++);
|
||||
if(lib[i].name)return lib[i].data;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
void link(struct import *exp, char** imports){
|
||||
dll_start = (dword (*)(dword))
|
||||
__msys_cofflib_getproc(exp, imports[0]);
|
||||
dll_ver = (dword*)
|
||||
__msys_cofflib_getproc(exp, imports[1]);
|
||||
con_init = (void stdcall (*)(dword , dword, dword, dword, const char*))
|
||||
__msys_cofflib_getproc(exp, imports[2]);
|
||||
con_write_asciiz = (void stdcall (*)(dword, const char*))
|
||||
__msys_cofflib_getproc(exp, imports[3]);
|
||||
con_printf = (void cdecl (*)(dword, const char*, ...))
|
||||
__msys_cofflib_getproc(exp, imports[4]);
|
||||
con_exit = (void stdcall (*)(dword))
|
||||
__msys_cofflib_getproc(exp, imports[5]);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
struct import * hDll;
|
||||
|
||||
if((hDll = (struct import *)_msys_cofflib_load(dllname)) == 0){
|
||||
debug_out_str("can't load lib\n\r");
|
||||
return 1;
|
||||
}
|
||||
link(hDll, imports);
|
||||
debug_out_str("dll loaded\n\r");
|
||||
|
||||
if(dll_start(1) == 0){
|
||||
debug_out_str("dll_start failed\n\r");
|
||||
return 1;
|
||||
}
|
||||
|
||||
con_init(-1, -1, -1, -1, caption);
|
||||
for(i = 0; i < 256; i++){
|
||||
con_printf(7, "Color 0x%02X: ", i);
|
||||
con_write_asciiz(i, "Text sample.");
|
||||
|
||||
con_printf(i, " printf %s test %d\n", "small", i);
|
||||
}
|
||||
|
||||
con_exit(0);
|
||||
debug_out_str("all right's ;)\n\r");
|
||||
}
|
61
programs/develop/metcc/trunk/samples/simple/simple.c
Normal file
61
programs/develop/metcc/trunk/samples/simple/simple.c
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
// simple sample by Ghost
|
||||
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "mesys.h"
|
||||
|
||||
#define FONT0 0
|
||||
#define FONT1 0x10000000
|
||||
|
||||
#define BT_NORMAL 0
|
||||
#define BT_DEL 0x80000000
|
||||
#define BT_HIDE 0x40000000
|
||||
#define BT_NOFRAME 0x20000000
|
||||
|
||||
char header[]={" -= C demo programm. Compiled whith meTCC halyavin port =- "};
|
||||
|
||||
void rotate_str(char *str){
|
||||
char tmp;
|
||||
int i;
|
||||
tmp = str[0];
|
||||
for(i = 1; str[i]; i++)str[i - 1] = str[i];
|
||||
str[i - 1] = tmp;
|
||||
}
|
||||
|
||||
void draw_window(){
|
||||
static int offs = 0;
|
||||
static int fcolor = 0;
|
||||
static int col = 0;
|
||||
|
||||
_msys_window_redraw(1);
|
||||
_msys_draw_window(100, 100, 300, 120, 0xaabbcc, 2, 0x5080d0, 0, 0x5080d0);
|
||||
_msys_write_text(6 - offs, 8, fcolor | FONT0, header, strlen(header));
|
||||
_msys_draw_bar(1, 6, 5, 13, 0x05080d0);
|
||||
_msys_draw_bar(274, 6, 26, 13, 0x05080d0);
|
||||
_msys_make_button(300 - 19, 5, 12, 12, 1 | BT_NORMAL, 0x6688dd);
|
||||
_msys_window_redraw(2);
|
||||
|
||||
offs = (offs + 1) % 6;
|
||||
if(!offs)rotate_str(header);
|
||||
|
||||
fcolor += (col)?-0x80808:0x80808;
|
||||
if(fcolor > 0xf80000 || fcolor == 0)col = !col;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
while(!0){
|
||||
switch(_msys_wait_for_event(10)){
|
||||
case 2:return 0;
|
||||
|
||||
case 3:
|
||||
if(_msys_get_button_id() == 1)return 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
draw_window();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user