diff --git a/programs/develop/sdk/trunk/libGUI_SDK/README.txt b/programs/develop/sdk/trunk/libGUI_SDK/README.txt new file mode 100644 index 0000000000..748a7fbc4b --- /dev/null +++ b/programs/develop/sdk/trunk/libGUI_SDK/README.txt @@ -0,0 +1,2 @@ +C file compile by GCC. +asm file compile by FASM diff --git a/programs/develop/sdk/trunk/libGUI_SDK/cofflib.asm b/programs/develop/sdk/trunk/libGUI_SDK/cofflib.asm new file mode 100644 index 0000000000..bc3e61edc1 --- /dev/null +++ b/programs/develop/sdk/trunk/libGUI_SDK/cofflib.asm @@ -0,0 +1,73 @@ +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] + 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: + + ;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 + diff --git a/programs/develop/sdk/trunk/libGUI_SDK/kolibrisys.h b/programs/develop/sdk/trunk/libGUI_SDK/kolibrisys.h new file mode 100644 index 0000000000..aed4aed79b --- /dev/null +++ b/programs/develop/sdk/trunk/libGUI_SDK/kolibrisys.h @@ -0,0 +1,195 @@ +#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 unsigned int dword; +typedef unsigned char byte; +typedef unsigned short word; + +typedef unsigned int fpos_t; +typedef unsigned int size_t; + +typedef 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 +}__attribute__((packed)); + +//----------------------------------------------------------------------------------- +//------------------------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); +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_value(int bus,int dev,int fn,int reg,int value); +//-------------------------------------------------------------------------------------- + +//------------------------Process information-------------------------------------- +extern int stdcall _ksys_get_process_table(struct process_table_entry *proctab,int pid); //if pid=-1 than get info about him. +//--------------------------------------------------------------------------------- + +//-----------------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 char* stdcall _ksys_cofflib_getproc(void* exp,char* sz_name); +//--------------------------------------------------------------------------------- + +#endif diff --git a/programs/develop/sdk/trunk/libGUI_SDK/libGUI.c b/programs/develop/sdk/trunk/libGUI_SDK/libGUI.c new file mode 100644 index 0000000000..abfaef9a2e --- /dev/null +++ b/programs/develop/sdk/trunk/libGUI_SDK/libGUI.c @@ -0,0 +1,69 @@ + +#include "kolibrisys.h" +#include "libGUI.h" + +char* sys_libGUI_path="/sys/lib/libGUI.obj"; + +void link_libGUI(char *exp){ + + char name_DestroyControl[]={"DestroyControl"}; + char name_SendMessage[]={"SendMessage"}; + char name_Version[]={"Version"}; + char name_ResizeComponent[]={"ResizeComponent"}; + char name_MoveComponent[]={"MoveComponent"}; + char name_ActivateTrapForSpecializedMessage[]={"ActivateTrapForSpecializedMessage"}; + char name_CraeteButton[]={"CraeteButton"}; + char name_CraeteScroller[]={"CraeteScroller"}; + char name_CraeteBookmark[]={"CraeteBookmark"}; + char name_CraeteImage[]={"CraeteImage"}; + char name_CraeteText[]={"CraeteText"}; + char name_CraeteNumber[]={"CraeteNumber"}; + char name_CraeteCheckbox[]={"CraeteCheckbox"}; + char name_CraeteEditbox[]={"CraeteEditbox"}; + char name_CraeteProgressbar[]={"CraeteProgressbar"}; + + DestroyControl=(void stdcall (*)(void *control)) + _ksys_cofflib_getproc(exp,name_DestroyControl); + SendMessage=(void stdcall (*)(struct HEADER *Parend,struct MESSAGE *Message)) + _ksys_cofflib_getproc(exp,name_SendMessage); + Version=(int stdcall (*)(void)) + _ksys_cofflib_getproc(exp,name_Version); + ResizeComponent=(void stdcall(*)(void *Control,int new_sizex,int new_sizey)) + _ksys_cofflib_getproc(exp,name_ResizeComponent); + MoveComponent=(void stdcall(*)(void *Control,int new_x,int new_y)) + _ksys_cofflib_getproc(exp,name_MoveComponent); + ActivateTrapForSpecializedMessage=(void stdcall(*)(void *Control,int new_x,int new_y)) + _ksys_cofflib_getproc(exp,name_ActivateTrapForSpecializedMessage); + CraeteButton=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteButton); + CraeteScroller=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteScroller); + CraeteBookmark=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteBookmark); + CraeteImage=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteImage); + CraeteText=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteText); + CraeteNumber=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteNumber); + CraeteCheckbox=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteCheckbox); + CraeteEditbox=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteEditbox); + CraeteProgressbar=(void* stdcall (*)(struct HEADER *Parend,void *Control)) + _ksys_cofflib_getproc(exp,name_CraeteProgressbar); + +} + +int Init_libGUI(void) +{ + char *Export; + + Export=(char *)_ksys_cofflib_load(sys_libGUI_path); + if (Export==0) return CANNOT_LOAD_LIBGUI; + + link_libGUI(Export); + return(0); + +} + diff --git a/programs/develop/sdk/trunk/libGUI_SDK/libGUI.h b/programs/develop/sdk/trunk/libGUI_SDK/libGUI.h new file mode 100644 index 0000000000..ef95a2390d --- /dev/null +++ b/programs/develop/sdk/trunk/libGUI_SDK/libGUI.h @@ -0,0 +1,369 @@ +/* + structures for work with libGUI +*/ + +///////////////////////////////////////////////////////////////// + +#define CANNOT_LOAD_LIBGUI 100 +#define PAREND_SIZE 44 +#define MESSAGE_SIZE 16 + +#define MESSAGE_FULL_REDRAW_ALL 1 +#define MESSAGE_KEYS_EVENTS 2 +#define MESSAGE_SPECIALIZED 3 +#define MESSAGE_MOUSE_EVENTS 6 + +#define BUTTON_TYPE_2D_WITH_TEXT (1+128) +#define BUTTON_TYPE_2D_WITH_PICTURE (2+128) +#define BUTTON_TYPE_2D_WITH_TEXT_PICTURE (4+128) +#define BUTTON_TYPE_NO_DRAW (8+128) +#define BUTTON_TYPE_3D_WITH_TEXT (1+16+128) +#define BUTTON_TYPE_3D_WITH_PICTURE (2+16+128) +#define BUTTON_TYPE_3D_WITH_TEXT_PICTURE (4+16+128) + +#define TEXT_TYPE_NO_DRAW (1) +#define TEXT_TYPE_WITH_BACKGROUND (128+2) +#define TEXT_TYPE_SYSTEM_6X9 (128) + +#define NUMBER_NO_DRAW (1) +#define NUMBER_INTEGER (128) +#define NUMBER_FLOAT (128+2) + +#define IMAGE_TYPE_1 (128) + +#define PROGRESS_BAR_TYPE_1 (128) + +#define BOOKMARK_TYPE_1 (128) + +/////////////////////////////////////////////////////////////////// +#define BUTTON_STATE_CROSS (1) +#define BUTTON_STATE_CROSS_PRESS (3) + + +//////////////////////////////////////////////////////////////// +// header of control +//////////////////////////////////////////////////////////////// + +struct HEADER +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// message +//////////////////////////////////////////////////////////////// + +struct MESSAGE +{ + dword type; + dword arg1; + dword arg2; + dword arg3; +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// button +//////////////////////////////////////////////////////////////// + +struct ControlButton +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + + byte type; + byte flag; + word x; + word y; + word width; + word height; + dword image; + word imageX; + word imageY; + word imageSizeX; + word imageSizeY; + dword transparentColor; + dword text; + word textX; + word textY; + dword textcolor; + dword color1; + dword color2; + word mouseX; + word mouseY; +}__attribute__((packed)); + +typedef struct InfoForButton +{ + byte type; //0 + byte flag; //1 + word x; //2 + word y; //4 + word width; //6 + word height; //8 + dword image; //10 + word imageX; //14 + word imageY; //16 + word imageSizeX; //18 + word imageSizeY; //20 + dword transparentColor;//24 + dword text; //28 + word textX; //32 + word textY; //34 + dword textcolor; //36 + dword color1; //40 + dword color2; + word mouseX; + word mouseY; +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// scroller +//////////////////////////////////////////////////////////////// + +struct ControlScroller +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + + byte type; + word x; + word y; + word length; + dword color1; + float size; + float pos; + word buttons_flags; + dword ChildButton1; + dword ChildButton2; + word MouseX; + word MouseY; +}__attribute__((packed)); + +struct InfoForScroller +{ + byte type; + word x; + word y; + word length; + dword color1; + float size; + float pos; + word buttons_flags; + dword ChildButton1; + dword ChildButton2; + word MouseX; + word MouseY; +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// progressbar +//////////////////////////////////////////////////////////////// + +struct ControlProgressbar +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + + byte type; + byte flag; + dword color1; + dword color2; + dword x; + dword y; + dword sizex; + dword sizey; + float progress; + dword color3; +}__attribute__((packed)); + +struct InfoForProgressbar +{ + byte type; + byte flag; + dword color1; + dword color2; + dword x; + dword y; + dword sizex; + dword sizey; + float progress; + dword color3; +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// image +//////////////////////////////////////////////////////////////// + +struct ControlImage +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + + byte type; + byte flag; + dword color1; + dword x; + dword y; + dword sizex; + dword sizey; + dword pointer; +}__attribute__((packed)); + +struct InfoForImage +{ + byte type; + byte flag; + dword color1; + dword x; + dword y; + dword sizex; + dword sizey; + dword pointer; +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// text +//////////////////////////////////////////////////////////////// + +struct ControlText +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + + byte type; + byte flag; + dword color1; + dword x; + dword y; + dword length; + dword text; + dword background_color; +}__attribute__((packed)); + +struct InfoForText +{ + byte type; + byte flag; + dword color1; + dword x; + dword y; + dword length; + dword text; + dword background_color; +}__attribute__((packed)); + +//////////////////////////////////////////////////////////////// +// number +//////////////////////////////////////////////////////////////// + +struct ControlNumber +{ + dword ctrl_proc; + dword *ctrl_fd; + dword *ctrl_bk; + dword *child_fd; + dword *child_bk; + dword *parend; + dword ctrl_x; + dword ctrl_y; + dword ctrl_sizex; + dword ctrl_sizey; + dword ctrl_ID; + + byte type; + byte flag; + dword color1; + dword x; + dword y; + float number; + dword format; +}__attribute__((packed)); + +struct InfoForNumber +{ + byte type; + byte flag; + dword color1; + dword x; + dword y; + float number; + dword format; +}__attribute__((packed)); + + +///////////////////////////////////////////////////////////////// +// libGUI functions +///////////////////////////////////////////////////////////////// + +void stdcall (*DestroyControl)(void *control); +void stdcall (*SendMessage)(struct HEADER *Parend,struct MESSAGE *Message); +int stdcall (*Version)(void); +void stdcall (*ResizeComponent)(void *Control,int new_sizex,int new_sizey); +void stdcall (*MoveComponent)(void *Control,int new_x,int new_y); +void stdcall (*ActivateTrapForSpecializedMessage)(void *Control); +void* stdcall (*CraeteButton)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteScroller)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteBookmark)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteImage)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteText)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteNumber)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteCheckbox)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteEditbox)(struct HEADER *Parend,void *Control); +void* stdcall (*CraeteProgressbar)(struct HEADER *Parend,void *Control); + diff --git a/programs/develop/sdk/trunk/libGUI_SDK/proc32.inc b/programs/develop/sdk/trunk/libGUI_SDK/proc32.inc new file mode 100644 index 0000000000..98a1bd3342 --- /dev/null +++ b/programs/develop/sdk/trunk/libGUI_SDK/proc32.inc @@ -0,0 +1,268 @@ + +; 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, \{ prologue name,flag,parmbytes,localbytes,reglist \} + macro locals + \{ virtual at ebp-localbytes+current + macro label . \\{ deflocal@proc .,:, \\} + struc db [val] \\{ \common deflocal@proc .,db,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,dw,dp,dd,dt,dq + restruc rb,rw,rp,rd,rt,rq + restruc byte,word,dword,pword,tword,qword + current = $-(ebp-localbytes) + end virtual \} + macro ret operand + \{ match any, operand \\{ retn operand \\} + match , operand \\{ match epilogue:reglist, epilogue@proc: + \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} + macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 + 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 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] + { 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 =dup (=?), val \{ ..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 \} } + +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+count + 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 , done@local \\{ varname vartype + restore done@local \\} \} + match ,done@local + \{ var + restore done@local \} + common + endl }